Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyboard press, release, unicode input #16

Merged
merged 5 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions examples/basic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ proc display() =
bxy.endFrame()
window.swapBuffers()

var running = true

window.onCloseRequest = proc() =
running = false
window.close()

window.visible = true

while running:
while not window.closeRequested:
display()
pollEvents()
9 changes: 3 additions & 6 deletions examples/callbacks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ proc display() =
bxy.endFrame()
window.swapBuffers()

var running = true

window.onCloseRequest = proc() =
echo "onCloseRequest"
running = false
window.close()

window.onMove = proc() =
echo "onMove ", window.pos
Expand Down Expand Up @@ -51,9 +47,10 @@ window.onButtonPress = proc(button: Button) =
window.onButtonRelease = proc(button: Button) =
echo "onButtonRelease ", button

window.visible = true
window.onRune = proc(rune: Rune) =
echo "onRune ", rune

while running:
while not window.closeRequested:
if window.minimized or not window.visible:
sleep(10)
else:
Expand Down
4 changes: 2 additions & 2 deletions src/windy.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import vmath, windy/common
import unicode, vmath, windy/common

export common, vmath
export common, unicode, vmath

when defined(windows):
import windy/platforms/win32/platform
Expand Down
111 changes: 110 additions & 1 deletion src/windy/common.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import unicode

type
WindyError* = object of ValueError

Expand All @@ -6,8 +8,115 @@ type

Callback* = proc()
ButtonCallback* = proc(button: Button)
RuneCallback* = proc(rune: Rune)

Button* = enum
ButtonUnknown
MouseLeft
MouseRight
MouseMidde
MouseMiddle
Key0
Key1
Key2
Key3
Key4
Key5
Key6
Key7
Key8
Key9
KeyA
KeyB
KeyC
KeyD
KeyE
KeyF
KeyG
KeyH
KeyI
KeyJ
KeyK
KeyL
KeyM
KeyN
KeyO
KeyP
KeyQ
KeyR
KeyS
KeyT
KeyU
KeyV
KeyW
KeyX
KeyY
KeyZ
KeyBacktick
KeyMinus
KeyEqual
KeyBackspace
KeyTab
KeyLeftBracket
KeyRightBracket
KeyBackslash
KeyCapsLock
KeySemicolon
KeyApostraphe
KeyEnter
KeyLeftShift
KeyComma
KeyPeriod
KeySlash
KeyRightShift
KeyLeftControl
KeyLeftSuper
KeyLeftAlt
KeySpace
KeyRightAlt
KeyRightSuper
KeyMenu
KeyRightControl
KeyDelete
KeyHome
KeyEnd
KeyInsert
KeyPageUp
KeyPageDown
KeyEscape
KeyUp
KeyDown
KeyLeft
KeyRight
KeyPrintScreen
KeyScrollLock
KeyPause
KeyF1
KeyF2
KeyF3
KeyF4
KeyF5
KeyF6
KeyF7
KeyF8
KeyF9
KeyF10
KeyF11
KeyF12
KeyNumLock
Numpad0
Numpad1
Numpad2
Numpad3
Numpad4
Numpad5
Numpad6
Numpad7
Numpad8
Numpad9
NumpadDecimal
NumpadEnter
NumpadAdd
NumbadSubtract
NumpadMultiply
NumpadDivide
NumpadEqual
Loading