Skip to content

Commit

Permalink
fix(PaintControls): when clicking transparent eraser palette swatch
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Sep 12, 2023
1 parent e65dc5e commit fcd92e2
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 FF 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 fcd92e2

Please sign in to comment.