Skip to content

Commit

Permalink
Merge pull request #415 from PaulHax/paint-alpah-fix
Browse files Browse the repository at this point in the history
fix(PaintControls): when clicking transparent eraser palette swatch
  • Loading branch information
floryst authored Sep 12, 2023
2 parents e65dc5e + 5db84c1 commit f07bbb4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/components/PaintControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ import { LABELMAP_PALETTE } from '../config';
import { usePaintToolStore } from '../store/tools/paint';
import { rgbaToHexa } from '../utils/color';
const HEXA_LENGTH = 9;
// generates both the swatches for v-color-picker and the color-to-value mapping
function convertToSwatches(
palette: typeof LABELMAP_PALETTE,
Expand Down Expand Up @@ -134,10 +136,14 @@ export default defineComponent({
});
const setBrushColor = (color: string) => {
const hexa = `${color}FF`.toUpperCase();
if (hexa in hexToValue) {
paintStore.setBrushValue(hexToValue[hexa]);
// Passthrough if #RRGGBBAA, add alpha if #RRGGBB
const withAlpha = color.length === HEXA_LENGTH ? color : `${color}FF`;
const hexa = withAlpha.toUpperCase();
const brushValue = hexToValue[hexa];
if (brushValue == null) {
throw new Error(`Brush value invalid`);
}
paintStore.setBrushValue(brushValue);
};
const brushSize = computed(() => paintStore.brushSize);
Expand Down

0 comments on commit f07bbb4

Please sign in to comment.