Skip to content

Commit c5804ed

Browse files
committed
Fixed compilation errors on windows with avoidSDL
1 parent 62a0e09 commit c5804ed

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

nimx/cursor.nim

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ type
3333
ckNotAllowed
3434
ckHand
3535

36-
Cursor* = ref object
36+
Cursor* = ref CursorObj
37+
CursorObj = object
3738
when defined(js) or defined(emscripten) or defined(wasm):
3839
c: jsstring
3940
elif appKit:
@@ -76,7 +77,7 @@ elif appKit:
7677
of ckNotAllowed: operationNotAllowedCursor()
7778
of ckHand: pointingHandCursor()
7879

79-
proc finalizeCursor(c: Cursor) =
80+
proc finalizeCursorObj(c: CursorObj) =
8081
cast[NSCursor](c.c).release()
8182
elif not defined(nimxAvoidSdl):
8283
proc cursorKindToSdl(c: CursorKind): SystemCursor =
@@ -94,7 +95,7 @@ elif not defined(nimxAvoidSdl):
9495
of ckNotAllowed: SDL_SYSTEM_CURSOR_NO
9596
of ckHand: SDL_SYSTEM_CURSOR_HAND
9697

97-
proc finalizeCursor(c: Cursor) =
98+
proc finalizeCursorObj(c: CursorObj) =
9899
freeCursor(c.c)
99100
elif defined(linux):
100101
proc cursorKindToX(c: CursorKind): cuint =
@@ -112,7 +113,7 @@ elif defined(linux):
112113
of ckNotAllowed: XC_cross_reverse
113114
of ckHand: XC_hand1
114115

115-
proc finalizeCursor(c: Cursor) =
116+
proc finalizeCursorObj(c: CursorObj) =
116117
discard
117118
elif defined(windows):
118119
proc cursorKindToWinapi(c: CursorKind): LPTSTR =
@@ -130,15 +131,21 @@ elif defined(windows):
130131
of ckNotAllowed: IDC_NO
131132
of ckHand: IDC_HAND
132133

133-
proc finalizeCursor(c: Cursor) =
134+
proc finalizeCursorObj(c: CursorObj) =
134135
discard
135136

137+
proc finalizeCursor(c: Cursor) = finalizeCursorObj(c[])
138+
proc `=destroy`(c: var CursorObj) = finalizeCursorObj(c)
139+
136140
proc newCursor*(k: CursorKind): Cursor =
137141
when defined(js) or defined(emscripten) or defined(wasm):
138142
result.new()
139143
result.c = cursorKindToCSSName(k)
140144
else:
141-
result.new(finalizeCursor)
145+
when defined(gcDestructors):
146+
result.new()
147+
else:
148+
result.new(finalizeCursor)
142149
when appKit:
143150
result.c = NSCursorOfKind(k).retain()
144151
elif not defined(nimxAvoidSdl):

nimx/private/windows/winapi_window.nim

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@ type
8585

8686
proc SetProcessDpiAwareness(value: PROCESS_DPI_AWARENESS): HRESULT {.importc, stdcall, dynlib: "shcore".}
8787

88-
method init*(w: WinapiWindow, r: types.Rect) =
89-
procCall w.Window.init(r)
88+
method init*(w: WinapiWindow) =
89+
procCall w.Window.init()
9090
mainApplication().addWindow(w)
9191

92+
var r = newRect(0, 0, 800, 600)
93+
9294
discard SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE)
9395
registerWinApinClass()
9496

@@ -142,12 +144,12 @@ method onResize*(w: WinapiWindow, newSize: Size) =
142144

143145
proc newWinApiWindow(r: types.Rect): WinapiWindow =
144146
result.new()
145-
result.init(r)
147+
result.init()
146148

147149
proc getWindowFromHWND(hwnd: HWND): WinapiWindow {.inline.} =
148150
cast[WinapiWindow](GetWindowLongPtr(hwnd, GWLP_USERDATA))
149151

150-
proc getMouseEvent(win: Window, wparam: WPARAM, lparam: LPARAM, msg: UINT): Event=
152+
proc getMouseEvent(win: Window, wparam: WPARAM, lparam: LPARAM, msg: UINT): Event =
151153
let x = GET_X_LPARAM(lparam)
152154
let y = GET_Y_LPARAM(lparam)
153155
let pos = newPoint(x.Coord, y.Coord)

0 commit comments

Comments
 (0)