@@ 299,7 299,6 @@ proc injectColor(picture: Picture, color: Color) =
)
picture.add(change)
picture.apply(change)
- picture.selection.setLen(0)
proc addColor(picture: Picture, color: Color) =
## Adds the given color to all selected pixels.
@@ 319,7 318,6 @@ proc addColor(picture: Picture, color: Color) =
)
picture.add(change)
picture.apply(change)
- picture.selection.setLen(0)
proc clickPixel(picture: Picture, target: Vec, mode: Mode, tool: Tool, color: Color) =
## Reacts to clicking the image at the given point or pressing spacebar with the cursor on it.
@@ 513,6 511,15 @@ proc swapColors(app: App) =
swap(app.selectedPaletteIndex, app.secondaryColorPos.palette)
app.selectedPalette.cursor = cursor
+proc clearSelection(picture: Picture) =
+ picture.selection.setLen(0)
+
+proc clearSelection(app: App) =
+ app.selectedPicture.clearSelection()
+
+proc activeSelection(app: App): bool =
+ app.mode == mSelect and app.selectedPicture.selection.len != 0
+
proc copy(app: App) =
let selection = app.selectedPicture.selection
let xMin = selection.mapIt(it.x).min()
@@ 521,7 528,6 @@ proc copy(app: App) =
collect:
for pixel in selection:
PixelChange(pos: pixel - (xMin, yMin), newColor: app.selectedPicture[pixel])
- app.selectedPicture.selection.setLen(0)
proc paste(app: App) =
let picture = app.selectedPicture
@@ 628,12 634,14 @@ proc processKeyboard(app: App) =
app.command.add(Rune(ch))
else:
if isKeyPressed(Escape):
- app.selectedPicture.selection.setLen(0)
+ if app.activeSelection:
+ app.selectedPicture.selection.setLen(0)
if isKeyPressed(A):
- if app.selectedPicture.selection.len == 0:
- app.mode = mAdd
- else:
+ if app.activeSelection:
app.selectedPicture.addColor(app.color)
+ app.clearSelection()
+ else:
+ app.mode = mAdd
if isKeyPressed(B):
app.tool = Tool(kind: tBrush)
if isKeyPressed(C):
@@ 657,10 665,11 @@ proc processKeyboard(app: App) =
if isKeyPressed(F):
app.tool = Tool(kind: tFlood)
if isKeyPressed(I):
- if app.selectedPicture.selection.len == 0:
- app.mode = mInject
- else:
+ if app.activeSelection:
app.selectedPicture.injectColor(app.color)
+ app.clearSelection()
+ else:
+ app.mode = mInject
if isKeyPressed(P):
app.paste()
if isKeyPressed(Q):
@@ 688,10 697,11 @@ proc processKeyboard(app: App) =
if isKeyPressed(X):
app.swapColors()
if isKeyPressed(Y):
- if app.selectedPicture.selection.len == 0:
- app.color = app.selectedPicture.colorAtCursor
- else:
+ if app.activeSelection:
app.copy()
+ app.clearSelection()
+ else:
+ app.color = app.selectedPicture.colorAtCursor
if isKeyPressed(Semicolon):
app.mode = mCommand
app.command = ""
@@ 1,2 0,0 @@
-Copyright (c) 2015-2023, Renzhi Li (aka. Belleve Invis, belleve@typeof.net)
-SPDX-License-Identifier: OFL-1.1