Skip to content

Commit

Permalink
toggler pixel brush uses data from computed/adjusted spectrum pixels …
Browse files Browse the repository at this point in the history
…if no manual pixel data is not available
  • Loading branch information
arttu76 committed Dec 2, 2023
1 parent 56122c1 commit cb0dd27
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/components/Help.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export const Help = () => {
<br /><br />
<i>"Editing ink/paper pixels is annoying!"</i><br />
Click "using attributes" icon (or press X) to toggle attributes on or off - if attributes are turned off, it is
easier to see is some pixel is ink or paper, so you know which brush to use.
easier to see is some pixel is ink or paper, so you know which brush to use. Another trip: You don't even have to know
if a pixel is ink or paper if you just want to toggle them: use the 1x1 brush that automatically toggles between ink/paper.
<br /><br />
<i>"When editing attributes the brush does not seem to do anything."</i><br />
Make sure you have selected the correct attribute brush type (all, ink, paper, bright or eraser).
Expand Down
11 changes: 8 additions & 3 deletions src/components/Screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getGrowableGridData, setGrowableGridData } from '../utils/growableGridM
import { isMaskSet, setMask } from '../utils/maskManager';
import { drawSpectrumMemoryToImageDatas, getDefaultColor, getInvertedAttributes, getInvertedBitmap, getSpectrumMemoryAttribute, getSpectrumMemoryAttributeByte, setSpectrumMemoryAttribute, setSpectrumMemoryPixel } from '../utils/spectrumHardware';
import { addAttributeGridUi, addMaskUiToLayer, addMouseCursor, getBackgroundValue, getCoordinatesCoveredByCursor, getCoordinatesCoveredByCursorInSourceImageCoordinates, replaceEmptyWithBackground } from '../utils/uiPixelOperations';
import { applyRange2DExclusive, booleanOrNull, clamp8Bit, getInitialized2DArray, getWindow } from "../utils/utils";
import { applyRange2DExclusive, clamp8Bit, getInitialized2DArray, getWindow } from "../utils/utils";
import { Icon } from './Icon';

const win = getWindow();
Expand Down Expand Up @@ -170,7 +170,7 @@ export const Screen = () => {
&& layer.pixelate !== PixelationType.none
&& pixelIsUnmasked
) {
pixel = booleanOrNull(win[Keys.adjustedSpectrumPixels]?.[layer.id]?.[y][x]);
pixel = win[Keys.adjustedSpectrumPixels]?.[layer.id]?.[y][x];
if (pixel !== null && topmostAdjustedPixelFromThisLayer) {
topmostAdjustedPixel = null;
}
Expand Down Expand Up @@ -413,11 +413,16 @@ export const Screen = () => {
|| previousTogglerCoordinates.current.y !== xy.y
)
) {
const oldManualPixelValue = getGrowableGridData(win[Keys.manualPixels]?.[layer.id], xy.x, xy.y);
// if we have no manually set pixels, get the value from the adjusted spectrum pixels
const sourceValue = oldManualPixelValue !== null
? oldManualPixelValue
: !!win[Keys.adjustedSpectrumPixels]?.[layer.id]?.[xy.y][xy.x];
win[Keys.manualPixels][layer.id] = setGrowableGridData(
win[Keys.manualPixels]?.[layer.id],
xy.x,
xy.y,
!getGrowableGridData(win[Keys.manualPixels]?.[layer.id], xy.x, xy.y)
!sourceValue
);
previousTogglerCoordinates.current = xy;
}
Expand Down
2 changes: 0 additions & 2 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,3 @@ export const getLayerXYFromScreenCoordinates = (layer: Layer, x: SpectrumPixelCo
y: Math.round(safeZero(layer.height) / 2 + dy)
}
}

export const booleanOrNull = (value: Nullable<boolean>): boolean | null => value === null ? null : value;

0 comments on commit cb0dd27

Please sign in to comment.