Skip to content

Commit

Permalink
Fix mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
CardealRusso authored Oct 16, 2024
1 parent a0f11e0 commit 2b68833
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ while app.loop:
break
# Get mouse position and click state
let (mouseX, mouseY, clickStates, holdStates) = app.mouse
if clickStates[0] == 1:
echo "Clicked at: ", mouseX, "x", mouseY
if app.mouse.mclick[0] == 1:
echo "Clicked at: ", app.mouse.pos.x, "x", app.mouse.pos.y
# Adjust FPS
app.targetFps = 30
Expand Down Expand Up @@ -101,7 +100,7 @@ clear*(self: Fenster)
### Input Handling
```nim
keys*(self: Fenster): array[256, cint]
mouse*(self: Fenster): tuple[x, y: int, click: array[5, int], hold: array[3, int]]
mouse*(self: Fenster): tuple[pos: tuple[x, y: int], mclick: array[5, cint], mhold: array[3, cint]]
modkey*(self: Fenster): int
```
keys = Array of key states. Index corresponds to ASCII value (0-255), but arrows are 17..20.
Expand Down
2 changes: 1 addition & 1 deletion examples/interactive_julia_set.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ proc julia(x, y, cx, cy: float32, maxIter: int): int =
return 0

while app.loop and app.keys[27] == 0:
let (mouseX, mouseY, _, _) = app.mouse
let (mouseX, mouseY) = app.mouse.pos
if (mouseX, mouseY) != oldpos:
oldpos = (mouseX, mouseY)
cx = mouseX.float32 / app.width.float32 * 4 - 2
Expand Down
8 changes: 3 additions & 5 deletions examples/simple_mouse_drawing.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ while app.loop and app.keys[27] == 0:
if app.keys[ord('W')] == 1:
currentColor = rand(uint32)

let (mouseX, mouseY, clickStates, holdStates) = app.mouse

if clickStates[0] == 1:
let x = clamp(mouseX, 0, app.width)
let y = clamp(mouseY, 0, app.height)
if app.mouse.click[0] == 1:
let x = clamp(app.mouse.pos.x, 0, app.width)
let y = clamp(app.mouse.pos.y, 0, app.height)
app.pixel(x, y) = currentColor

0 comments on commit 2b68833

Please sign in to comment.