Add mouse wheel support to demo.
This commit is contained in:
parent
aa7f31ba78
commit
fcfcadc9dc
1 changed files with 9 additions and 2 deletions
|
@ -1,10 +1,12 @@
|
||||||
import opengl, pixie, staticglfw except Image
|
import opengl, pixie, staticglfw
|
||||||
|
export pixie, staticglfw
|
||||||
|
|
||||||
export pixie, staticglfw except Image
|
type Image = pixie.Image
|
||||||
|
|
||||||
var
|
var
|
||||||
screen* = newImage(800, 600)
|
screen* = newImage(800, 600)
|
||||||
window*: Window
|
window*: Window
|
||||||
|
mouseWheelDelta*: float32
|
||||||
|
|
||||||
proc getMousePos*(): Vec2 =
|
proc getMousePos*(): Vec2 =
|
||||||
## Get the mouse position.
|
## Get the mouse position.
|
||||||
|
@ -22,6 +24,9 @@ proc isKeyDown*(keyCode: int): bool =
|
||||||
## Examples: KEY_SPACE, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT
|
## Examples: KEY_SPACE, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT
|
||||||
getKey(window, keyCode.cint) == PRESS
|
getKey(window, keyCode.cint) == PRESS
|
||||||
|
|
||||||
|
proc onScroll(window: staticglfw.Window, xoffset, yoffset: float64) {.cdecl.} =
|
||||||
|
mouseWheelDelta += yoffset
|
||||||
|
|
||||||
proc tick*() =
|
proc tick*() =
|
||||||
## Called this every frame in a while loop.
|
## Called this every frame in a while loop.
|
||||||
|
|
||||||
|
@ -44,6 +49,7 @@ proc tick*() =
|
||||||
|
|
||||||
swapBuffers(window)
|
swapBuffers(window)
|
||||||
|
|
||||||
|
mouseWheelDelta = 0
|
||||||
pollEvents()
|
pollEvents()
|
||||||
|
|
||||||
if windowShouldClose(window) == 1:
|
if windowShouldClose(window) == 1:
|
||||||
|
@ -59,6 +65,7 @@ proc start*(title = "Demo") =
|
||||||
if window == nil:
|
if window == nil:
|
||||||
quit("Failed to create window.")
|
quit("Failed to create window.")
|
||||||
makeContextCurrent(window)
|
makeContextCurrent(window)
|
||||||
|
discard window.setScrollCallback(onScroll)
|
||||||
loadExtensions()
|
loadExtensions()
|
||||||
|
|
||||||
# Allocate a texture and bind it.
|
# Allocate a texture and bind it.
|
||||||
|
|
Loading…
Reference in a new issue