~xigoi/vier

2c3661928547c380ebf943916f0a7b48b063c143 — Adam Blažek 8 months ago 6ff700d
Fixed major bug caused by the addition of select mode
3 files changed, 23 insertions(+), 15 deletions(-)

M src/vier.nim
D website/assets/fonts/Iosevka-Regular.ttf
D website/assets/fonts/Iosevka-Regular.ttf.license
M src/vier.nim => src/vier.nim +23 -13
@@ 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 = ""

D website/assets/fonts/Iosevka-Regular.ttf => website/assets/fonts/Iosevka-Regular.ttf +0 -0
D website/assets/fonts/Iosevka-Regular.ttf.license => website/assets/fonts/Iosevka-Regular.ttf.license +0 -2
@@ 1,2 0,0 @@
Copyright (c) 2015-2023, Renzhi Li (aka. Belleve Invis, belleve@typeof.net)
SPDX-License-Identifier: OFL-1.1