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

Update windows and inputs #76

Merged
merged 33 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e738c41
rename pollAndRender
elcritch Jan 23, 2025
7416c83
rename thread effects
elcritch Jan 23, 2025
0948243
rename thread effects
elcritch Jan 23, 2025
1cdfbe9
rename thread effects
elcritch Jan 23, 2025
764abdc
rename thread effects
elcritch Jan 23, 2025
7252f66
rename thread effects
elcritch Jan 23, 2025
d0c4366
rename thread effects
elcritch Jan 23, 2025
dd025d4
rename thread effects
elcritch Jan 23, 2025
d25fce0
refactor
elcritch Jan 23, 2025
9f4f0d7
refactor
elcritch Jan 23, 2025
f29dfa4
refactor
elcritch Jan 23, 2025
6e3a631
refactor
elcritch Jan 23, 2025
b874913
refactor
elcritch Jan 23, 2025
18b2d32
refactor
elcritch Jan 23, 2025
816a64b
refactor
elcritch Jan 23, 2025
2b4544a
refactor
elcritch Jan 23, 2025
1a3e845
refactor
elcritch Jan 23, 2025
1cec5d4
refactor
elcritch Jan 23, 2025
18be690
refactor
elcritch Jan 23, 2025
53dea74
refactor
elcritch Jan 23, 2025
86278f9
refactor
elcritch Jan 23, 2025
6a64d4f
adding render commands
elcritch Jan 23, 2025
6592c82
adding render commands
elcritch Jan 23, 2025
068f268
adding render commands
elcritch Jan 23, 2025
d71dfe8
adding render commands
elcritch Jan 23, 2025
f47a160
adding render commands
elcritch Jan 23, 2025
17356af
adding render commands
elcritch Jan 23, 2025
b9c05f8
adding render commands
elcritch Jan 23, 2025
c76f5a1
adding render commands
elcritch Jan 23, 2025
c5f050f
adding render commands
elcritch Jan 23, 2025
222b877
adding render commands
elcritch Jan 23, 2025
ac99867
adding render commands
elcritch Jan 23, 2025
b9eedf9
adding render commands
elcritch Jan 23, 2025
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
1 change: 0 additions & 1 deletion config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ switch("styleCheck", "hint")

--d:windyNoHttp
--d:printDebugTimings
# --d:nimStrictDelete
--deepcopy:on
--debugger:native
--debugInfo
Expand Down
21 changes: 11 additions & 10 deletions src/figuro/common/fontutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ proc generateGlyphImage(arrangement: GlyphArrangement) =
## Font Glyphs are generated with Bottom vAlign and Center hAlign
## this puts the glyphs in the right position
## so that the renderer doesn't need to figure out adjustments
runtimeThreads:
MainThread
threadEffects:
AppMainThread

for glyph in arrangement.glyphs():
if unicode.isWhiteSpace(glyph.rune):
Expand Down Expand Up @@ -148,8 +148,8 @@ proc readTypefaceImpl(name, data: string, kind: TypeFaceKinds): Typeface {.raise

proc getTypefaceImpl*(name: string): FontId =
## loads a font from a file and adds it to the font index
runtimeThreads:
MainThread
threadEffects:
AppMainThread

let
typefacePath = DataDirPath.string / name
Expand All @@ -161,8 +161,8 @@ proc getTypefaceImpl*(name: string): FontId =

proc getTypefaceImpl*(name, data: string, kind: TypeFaceKinds): FontId =
## loads a font from buffer and adds it to the font index
runtimeThreads:
MainThread
threadEffects:
AppMainThread

let
typeface = readTypefaceImpl(name, data, kind)
Expand All @@ -174,8 +174,9 @@ proc getTypefaceImpl*(name, data: string, kind: TypeFaceKinds): FontId =
proc convertFont*(font: UiFont): (FontId, Font) =
## does the typesetting using pixie, then converts to Figuro's internal
## types
runtimeThreads:
MainThread
threadEffects:
AppMainThread

let
id = font.getId()
typeface = typefaceTable[font.typefaceId]
Expand Down Expand Up @@ -212,8 +213,8 @@ proc getTypesetImpl*(
## does the typesetting using pixie, then converts the typeseet results
## into Figuro's own internal types
## Primarily done for thread safety
runtimeThreads:
MainThread
threadEffects:
AppMainThread

var
wh = box.scaled().wh
Expand Down
249 changes: 22 additions & 227 deletions src/figuro/common/inputs.nim
Original file line number Diff line number Diff line change
@@ -1,191 +1,20 @@
import std/[unicode, sequtils]
import pkg/vmath
import pkg/patty

import nodes/basics
import uimaths
export uimaths

when defined(nimscript):
{.pragma: runtimeVar, compileTime.}
else:
{.pragma: runtimeVar, global.}
import nodes/render
import uimaths, keys
export uimaths, keys

type
KeyState* = enum
Empty
Up
Down
Repeat
Press # Used for text input

MouseCursorStyle* = enum
Default
Pointer
Grab
NSResize

Mouse* = object
pos*: Position
prev*: Position
delta*: Position
wheelDelta*: Position
consumed*: bool ## Consumed - need to prevent default action.

Keyboard* = object
consumed*: bool ## Consumed - need to prevent default action.
rune*: Option[Rune]
textCursor*: int ## At which character in the input string are we
selectionCursor*: int ## To which character are we selecting to

EventKinds* {.size: sizeof(int8).} = enum
evClick
evClickOut
evHover
evOverlapped
evPress
evDown
evRelease
evScroll
evDrag
evDragEnd
evKeyboardInput
evKeyPress

EventKind* = enum
Exit
Enter

EventFlags* = set[EventKinds]

UiButton* = enum
ButtonUnknown
MouseLeft
MouseRight
MouseMiddle
MouseButton4
MouseButton5
DoubleClick
TripleClick
QuadrupleClick
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 # :
KeyApostrophe # '
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 # +
NumpadSubtract # -
NumpadMultiply # *
NumpadDivide # /
NumpadEqual # =

UiButtonView* = set[UiButton]
KeyRange* = KeyA .. NumpadEqual
FrameStyle* {.pure.} = enum
DecoratedResizable, DecoratedFixedSized, Undecorated, Transparent

const
MouseButtons* = {
MouseLeft, MouseRight, MouseMiddle, MouseButton4, MouseButton5, DoubleClick,
TripleClick, QuadrupleClick,
}

ModifierButtons* = {
KeyLeftControl, KeyRightControl, KeyLeftSuper, KeyRightSuper, KeyLeftAlt,
KeyRightAlt, KeyLeftShift, KeyRightShift, KeyMenu,
}
variantp RenderCommands:
RenderQuit
RenderUpdate(n: Renders)
RenderSetTitle(name: string)

type AppInputs* = object
empty*: bool
Expand All @@ -199,55 +28,21 @@ type AppInputs* = object

windowSize*: Option[Box]

var uxInputs* {.runtimeVar.} = AppInputs()

when not defined(nimscript):
import threading/channels
export channels

type ModifierKeys* = enum
KNone
KMeta
KControl
KAlt
KShift
KMenu

proc defaultKeyConfigs(): array[ModifierKeys, UiButtonView] =
result[KNone] = {}
result[KMeta] =
when defined(macosx):
{KeyLeftSuper, KeyRightSuper}
else:
{KeyLeftControl, KeyRightControl}
result[KAlt] = {KeyLeftAlt, KeyRightAlt}
result[KShift] = {KeyLeftShift, KeyRightShift}
result[KMenu] = {KeyMenu}

var keyConfig* {.runtimeVar.}: array[ModifierKeys, UiButtonView] = defaultKeyConfigs()

proc `==`*(keys: UiButtonView, commands: ModifierKeys): bool =
let ck = keys * ModifierButtons
if ck == {} and keyConfig[commands] == {}:
return true
else:
ck != {} and ck < keyConfig[commands]

proc click*(mouse: Mouse): bool =
proc click*(inputs: AppInputs): bool =
when defined(clickOnDown):
return MouseButtons * uxInputs.buttonDown != {}
return MouseButtons * inputs.buttonDown != {}
else:
return MouseButtons * uxInputs.buttonRelease != {}
return MouseButtons * inputs.buttonRelease != {}

proc down*(mouse: Mouse): bool =
return MouseButtons * uxInputs.buttonDown != {}
proc down*(inputs: AppInputs): bool =
return MouseButtons * inputs.buttonDown != {}

proc release*(mouse: Mouse): bool =
return MouseButtons * uxInputs.buttonRelease != {}
proc release*(inputs: AppInputs): bool =
return MouseButtons * inputs.buttonRelease != {}

proc scrolled*(mouse: Mouse): bool =
mouse.wheelDelta.x != 0.0'ui
proc scrolled*(inputs: AppInputs): bool =
inputs.mouse.wheelDelta.x != 0.0'ui

proc dragging*(mouse: Mouse): bool =
return MouseButtons * uxInputs.buttonDown != {}
return MouseButtons * uxInputs.buttonRelease != {}
proc dragging*(inputs: AppInputs): bool =
return MouseButtons * inputs.buttonDown != {}
return MouseButtons * inputs.buttonRelease != {}
Loading
Loading