Add ability to zoom in/out with keyboard.

My mouse wheel broke.
pull/120/merge
rexim 1 year ago
parent cc0f531119
commit fa6660fe44

@ -34,22 +34,22 @@ For additional Developer Capabilities compile the application with the following
$ nimble build -d:developer $ nimble build -d:developer
``` ```
This will enable reloading the shaders with `Ctrl+R`. The shader files (`frag.glsl` and `vert.glsl`) should be located in the same folder as `boomer.nim` for this feature to work. If the shader files not found the program won't even start. This will enable reloading the shaders with `Ctrl+R`. The shader files (`frag.glsl` and `vert.glsl`) should be located in the same folder as `boomer.nim` for this feature to work. If the shader files not found the program won't even start.
**Keep in mind that the developer build is not suitable for day-to-day usage because it creates the external dependency on the shader files. Compiling the program without `-d:developer` "bakes" the shaders into the executable and eliminates the dependency.** **Keep in mind that the developer build is not suitable for day-to-day usage because it creates the external dependency on the shader files. Compiling the program without `-d:developer` "bakes" the shaders into the executable and eliminates the dependency.**
## Controls ## Controls
| Control | Description | | Control | Description |
|--------------------------------|---------------------------------------------------------------| |-------------------------------------------|---------------------------------------------------------------|
| <kbd>0</kbd> | Reset the application state (position, scale, velocity, etc). | | <kbd>0</kbd> | Reset the application state (position, scale, velocity, etc). |
| <kbd>q</kbd> or <kbd>ESC</kbd> | Quit the application. | | <kbd>q</kbd> or <kbd>ESC</kbd> | Quit the application. |
| <kbd>r</kbd> | Reload configuration. | | <kbd>r</kbd> | Reload configuration. |
| <kbd>Ctrl</kbd> + <kbd>r</kbd> | Reload the shaders (only for Developer mode) | | <kbd>Ctrl</kbd> + <kbd>r</kbd> | Reload the shaders (only for Developer mode) |
| <kbd>f</kbd> | Toggle flashlight effect. | | <kbd>f</kbd> | Toggle flashlight effect. |
| Drag with left mouse button | Move the image around. | | Drag with left mouse button | Move the image around. |
| Scroll wheel | Zoom in/out. | | Scroll wheel or <kbd>=</kbd>/<kbd>-</kbd> | Zoom in/out. |
| <kbd>Ctrl</kbd> + Scroll wheel | Change the radious of the flaslight. | | <kbd>Ctrl</kbd> + Scroll wheel | Change the radious of the flaslight. |
## Configuration ## Configuration

@ -445,6 +445,21 @@ proc main() =
var xev: TXEvent var xev: TXEvent
while XPending(display) > 0: while XPending(display) > 0:
discard XNextEvent(display, addr xev) discard XNextEvent(display, addr xev)
proc scrollUp() =
if (xev.xkey.state and ControlMask) > 0.uint32 and flashlight.isEnabled:
flashlight.deltaRadius += INITIAL_FL_DELTA_RADIUS
else:
camera.deltaScale += config.scrollSpeed
camera.scalePivot = mouse.curr
proc scrollDown() =
if (xev.xkey.state and ControlMask) > 0.uint32 and flashlight.isEnabled:
flashlight.deltaRadius -= INITIAL_FL_DELTA_RADIUS
else:
camera.deltaScale -= config.scrollSpeed
camera.scalePivot = mouse.curr
case xev.theType case xev.theType
of Expose: of Expose:
discard discard
@ -470,6 +485,8 @@ proc main() =
of KeyPress: of KeyPress:
var key = XLookupKeysym(cast[PXKeyEvent](xev.addr), 0) var key = XLookupKeysym(cast[PXKeyEvent](xev.addr), 0)
case key case key
of XK_EQUAL: scrollUp()
of XK_MINUS: scrollDown()
of XK_0: of XK_0:
camera.scale = 1.0 camera.scale = 1.0
camera.deltaScale = 0.0 camera.deltaScale = 0.0
@ -507,21 +524,8 @@ proc main() =
mouse.prev = mouse.curr mouse.prev = mouse.curr
mouse.drag = true mouse.drag = true
camera.velocity = vec2(0.0, 0.0) camera.velocity = vec2(0.0, 0.0)
of Button4: scrollUp()
of Button4: # Scroll up of Button5: scrollDown()
if (xev.xkey.state and ControlMask) > 0.uint32 and flashlight.isEnabled:
flashlight.deltaRadius += INITIAL_FL_DELTA_RADIUS
else:
camera.deltaScale += config.scrollSpeed
camera.scalePivot = mouse.curr
of Button5: # Scoll down
if (xev.xkey.state and ControlMask) > 0.uint32 and flashlight.isEnabled:
flashlight.deltaRadius -= INITIAL_FL_DELTA_RADIUS
else:
camera.deltaScale -= config.scrollSpeed
camera.scalePivot = mouse.curr
else: else:
discard discard

Loading…
Cancel
Save