Skip to content

Commit

Permalink
Update for latest nim-glfw
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnovak committed Jul 20, 2024
1 parent a63cefb commit 222ad19
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
38 changes: 22 additions & 16 deletions src/csdwindow.nim
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ type
resizeDir: WindowResizeDir
mx0, my0: float
posX0, posY0: int
size0: tuple[w, h: int32]
unmaximizedPos: tuple[x, y: int32]
unmaximizedSize: tuple[w, h: int32]
size0: tuple[w, h: int]
unmaximizedPos: tuple[x, y: int]
unmaximizedSize: tuple[w, h: int]

oldFocusCaptured, focusCaptured: bool

Expand Down Expand Up @@ -98,22 +98,25 @@ proc `title=`*(win; title: string) =
win.title = title
win.w.title = title

proc pos*(win): tuple[x, y: int32] =
proc pos*(win): tuple[x, y: int] =
win.w.pos

proc `pos=`*(win; pos: tuple[x, y: int32]) =
proc `pos=`*(win; pos: tuple[x, y: int]) =
win.w.pos = pos

proc size*(win): tuple[w, h: int32] =
proc size*(win): tuple[w, h: int] =
win.w.size

proc contentScale*(win): tuple[xScale, yScale: float] =
win.w.contentScale

proc canvasSize*(win): tuple[w, h: float] =
(koi.winWidth(), koi.winHeight())

proc `size=`*(win; size: tuple[w, h: int32]) =
proc `size=`*(win; size: tuple[w, h: int]) =
win.w.size = size

proc framebufferSize*(win): tuple[w, h: int32] =
proc framebufferSize*(win): tuple[w, h: int] =
win.w.framebufferSize

proc cursorPos*(win): tuple[x, y: float64] =
Expand All @@ -128,6 +131,9 @@ proc hide*(win) =
proc focus*(win) =
win.w.focus

proc requestAttention*(win) =
win.w.requestAttention

proc restore*(win) =
win.w.restore

Expand Down Expand Up @@ -161,7 +167,7 @@ proc workAreaRect(m: Monitor): Rect[int] =

# }}}
# {{{ findMonitorByCoord()
proc findMonitorByCoord(x, y: int32): Monitor =
proc findMonitorByCoord(x, y: int): Monitor =
for m in monitors():
let r = m.workAreaRect
if r.contains(x, y):
Expand Down Expand Up @@ -300,18 +306,18 @@ proc titleBarHeight*(win): float =

# }}}
# {{{ unmaximizedPos*
proc unmaximizedPos*(win): tuple[x, y: int32] =
proc unmaximizedPos*(win): tuple[x, y: int] =
win.unmaximizedPos

proc `unmaximizedPos=`*(win; pos: tuple[x, y: int32]) =
proc `unmaximizedPos=`*(win; pos: tuple[x, y: int]) =
win.unmaximizedPos = pos

# }}}
# {{{ unmaximizedSize*
proc unmaximizedSize*(win): tuple[w, h: int32] =
proc unmaximizedSize*(win): tuple[w, h: int] =
win.unmaximizedSize

proc `unmaximizedSize=`*(win; size: tuple[w, h: int32]) =
proc `unmaximizedSize=`*(win; size: tuple[w, h: int]) =
win.unmaximizedSize = size

# }}}
Expand Down Expand Up @@ -505,7 +511,7 @@ proc handleWindowDragEvents(win) =
let oldWidth = win.unmaximizedSize.w

# The restored window is centered horizontally around the cursor.
(win.posX0, win.posY0) = ((mx - oldWidth * 0.5).int32, 0)
(win.posX0, win.posY0) = ((mx - oldWidth * 0.5).int, 0)

# Fake the last horizontal cursor position to be at the middle of
# the restored window's width. This is needed so when we're in the
Expand Down Expand Up @@ -540,8 +546,8 @@ proc handleWindowDragEvents(win) =
of wdsResizing:
if koi.mbLeftDown():
let
dx = (mx - win.mx0).int32
dy = (my - win.my0).int32
dx = (mx - win.mx0).int
dy = (my - win.my0).int

var
(newX, newY) = (win.posX0, win.posY0)
Expand Down
12 changes: 6 additions & 6 deletions src/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ type
showToolsPane: bool
showThemeEditor: bool

windowPos: tuple[x, y: int32]
windowSize: tuple[w, h: int32]
windowPos: tuple[x, y: int]
windowSize: tuple[w, h: int]
maximized: bool
showTitleBar: bool

Expand Down Expand Up @@ -10252,7 +10252,7 @@ proc renderFrameSplash(a) =
(fbWidth, fbHeight) = s.win.framebufferSize
pxRatio = fbWidth.float / winWidth.float

glViewport(0, 0, fbWidth, fbHeight)
glViewport(0, 0, fbWidth.GLsizei, fbHeight.GLsizei)

glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT)

Expand Down Expand Up @@ -10373,8 +10373,8 @@ proc showSplash(a) =
alias(s, g_app.splash)

let (_, _, maxWidth, maxHeight) = g_app.win.findCurrentMonitor().workArea
let w = (maxWidth * 0.6).int32
let h = (w/s.logo.width * s.logo.height).int32
let w = (maxWidth * 0.6).int
let h = (w/s.logo.width * s.logo.height).int

s.win.size = (w, h)
s.win.pos = ((maxWidth - w) div 2, (maxHeight - h) div 2)
Expand Down Expand Up @@ -10839,7 +10839,7 @@ when not defined(DEBUG):

# {{{ handleFocusEvent()
proc handleFocusEvent(event: AppEvent; a) =
a.win.focus
a.win.requestAttention

# }}}
# {{{ handleOpenFileEvent()
Expand Down

0 comments on commit 222ad19

Please sign in to comment.