Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Transparency Slider for Duotone parts #234

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions StreamAwesome/src/components/settings/GeneralOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function createFontAwesomeIconDisplayFromStyle(style: FontAwesomeStyle): FontAwe
unicode: fallBackIcon.unicode,
isBrandsIcon: fallBackIcon.isBrand(),
family: fallBackIcon.styles.free[0].family,
duotoneAlpha: 0.5,
style: style
}
} else {
Expand All @@ -41,8 +42,8 @@ function createFontAwesomeIconDisplayFromStyle(style: FontAwesomeStyle): FontAwe
const unicode = props.icon.fontAwesomeIcon.unicode
const isBrandsIcon = props.icon.fontAwesomeIcon.isBrandsIcon
const family = props.icon.fontAwesomeIcon.family

return { id, label, unicode, isBrandsIcon, family, style }
const duotoneAlpha = props.icon.fontAwesomeIcon.duotoneAlpha
return { id, label, unicode, isBrandsIcon, family, style, duotoneAlpha }
}
}

Expand All @@ -55,6 +56,7 @@ function createFontAwesomeIconDisplayFromFamily(family: FontAwesomeFamily): Font
unicode: fallBackIcon.unicode,
isBrandsIcon: fallBackIcon.isBrand(),
family: family,
duotoneAlpha: 0.5,
style: fallBackIcon.styles.free[0].style
}
} else {
Expand All @@ -63,8 +65,8 @@ function createFontAwesomeIconDisplayFromFamily(family: FontAwesomeFamily): Font
const unicode = props.icon.fontAwesomeIcon.unicode
const isBrandsIcon = props.icon.fontAwesomeIcon.isBrandsIcon
const style = props.icon.fontAwesomeIcon.style

return { id, label, unicode, isBrandsIcon, family, style }
const duotoneAlpha = props.icon.fontAwesomeIcon.duotoneAlpha
return { id, label, unicode, isBrandsIcon, family, style, duotoneAlpha }
}
}

Expand All @@ -80,6 +82,11 @@ function updateFamily(family: FontAwesomeFamily) {
function updateStyle(style: FontAwesomeStyle) {
currentIcon.fontAwesomeIcon.style = style
}

function updateAlpha(event: Event) {
const alpha = +(event.target as HTMLInputElement).value
currentIcon.fontAwesomeIcon.duotoneAlpha = alpha
}
</script>

<template>
Expand All @@ -98,6 +105,24 @@ function updateStyle(style: FontAwesomeStyle) {
/>
</div>

<div v-if="props.icon.fontAwesomeIcon.family.includes(DuotoneKeyword)">
<label
for="duotoneAlpha"
class="mb-[0.5] block text-sm font-medium text-gray-900 dark:text-white"
>Duotone Transparency:
</label>
<input
id="duotoneAlpha"
type="range"
:value="props.icon?.fontAwesomeIcon.duotoneAlpha ?? 0.5"
@input="(event) => updateAlpha(event)"
min="0"
max="1"
step="0.01"
class="mb-6 h-2 w-full cursor-pointer appearance-none rounded-lg bg-gray-200 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 dark:bg-gray-700"
/>
</div>

<section>
<label class="block text-sm font-medium text-gray-900 dark:text-white">Font Family: </label>
<div class="mt-1 flex rounded-md shadow-sm">
Expand Down
4 changes: 3 additions & 1 deletion StreamAwesome/src/logic/generator/iconGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ export default abstract class IconGenerator<T extends FontAwesomePreset> {
icon.fontAwesomeIcon.family.includes(DuotoneKeyword) &&
!icon.fontAwesomeIcon.isBrandsIcon
) {
this.renderingContext.fillStyle = this.getSecondaryFillStyle(icon)
this.renderingContext.fillStyle = this.getIconFillStyle(icon)

this.renderingContext.globalAlpha = icon.fontAwesomeIcon.duotoneAlpha
const secondaryIconCode = this.calculateSecondaryIcon(icon.fontAwesomeIcon.unicode)
this.renderingContext.fillText(secondaryIconCode, centerOfCanvas, centerOfCanvas)
this.renderingContext.globalAlpha = 1
}

this.renderingContext.fillStyle = this.getIconFillStyle(icon)
Expand Down
1 change: 1 addition & 0 deletions StreamAwesome/src/model/fontAwesomeIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export interface FontAwesomeIcon {
isBrandsIcon: boolean /* Only storing the brands information in the icon's style voids other styling information */
style: FontAwesomeStyle
family: FontAwesomeFamily
duotoneAlpha: number
}
3 changes: 2 additions & 1 deletion StreamAwesome/src/stores/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const useIconsStore = defineStore('icons', () => {
label: 'Gear',
isBrandsIcon: false,
style: 'solid',
unicode: 'f013'
unicode: 'f013',
duotoneAlpha: 0.5
}
})

Expand Down