1 lobby ensureNamespace: #Windows &delegate: True.
4 &builder: [ExternalInterface newForLibrary: 'sdl-windows' primitives: #{
6 {#Void. #shutdown. {}}.
7 {#Int. #haveEvent. {}}.
8 {#Int. #waitForEvent. {}}.
9 {#Void. #popEvent. {}}.
10 {#Pointer. #createWindow. {#Int. #Int}}.
11 {#Int. #getEventType. {}}.
12 {#Pointer. #getEventWindow. {}}.
13 {#Int. #getEventMouseMotionX. {}}.
14 {#Int. #getEventMouseMotionY. {}}.
15 {#Int. #getEventMouseButtonX. {}}.
16 {#Int. #getEventMouseButtonY. {}}.
17 {#Int. #getKeyboardKey. {}}.
18 {#Int. #getKeyboardMod. {}}.
19 {#Void. #blit. {#Pointer. #Int. #Int. #Int. #Int. #Pointer. #Int. #Int. #Int. #Int. #Int}}
24 Windows define: #EventTableEntry &slots: {#prototype. #constructors}.
26 entry@(Windows EventTableEntry traits) newPrototype: prototype constructors: constructors
27 [entry cloneSettingSlots: #{#prototype. #constructors}
28 to: {prototype. constructors}].
30 entry@(Windows EventTableEntry traits) construct
32 event: entry prototype copy.
33 entry constructors do: [| :name | event construct: name].
37 event@(Event traits) construct: _@#osWindow
39 event addSlot: #osWindow valued: Windows Lib primitives getEventWindow do.
42 event@(Event traits) construct: _@#mouseButtonPosition
45 Windows Lib primitives getEventMouseButtonX do ,
46 Windows Lib primitives getEventMouseButtonY do.
49 event@(Event traits) construct: _@#mouseMotionPosition
52 Windows Lib primitives getEventMouseMotionX do ,
53 Windows Lib primitives getEventMouseMotionY do.
56 event@(Event traits) construct: _@#keyboardKey
58 event key: Windows Lib primitives getKeyboardKey do.
59 event modifiers: Windows Lib primitives getKeyboardMod do.
63 Windows addSlot: #eventTable valued: Dictionary new.
66 Windows eventTable at: spec key put:
67 (Windows EventTableEntry
68 newPrototype: (events atSlotNamed: spec value first)
69 constructors: spec value second)] for: {
70 100 -> #{#LeftMouseButtonPressEvent. {#osWindow. #mouseButtonPosition}}.
71 101 -> #{#LeftMouseButtonReleaseEvent. {#osWindow. #mouseButtonPosition}}.
72 102 -> #{#LeftMouseButtonDoubleClickEvent. {#osWindow. #mouseButtonPosition}}.
74 110 -> #{#RightMouseButtonPressEvent. {#osWindow. #mouseButtonPosition}}.
75 111 -> #{#RightMouseButtonReleaseEvent. {#osWindow. #mouseButtonPosition}}.
76 112 -> #{#RightMouseButtonDoubleClickEvent. {#osWindow. #mouseButtonPosition}}.
78 120 -> #{#MiddleMouseButtonPressEvent. {#osWindow. #mouseButtonPosition}}.
79 121 -> #{#MiddleMouseButtonReleaseEvent. {#osWindow. #mouseButtonPosition}}.
80 122 -> #{#MiddleMouseButtonDoubleClickEvent. {#osWindow. #mouseButtonPosition}}.
82 130 -> #{#X1MouseButtonPressEvent. {#osWindow. #mouseButtonPosition}}.
83 131 -> #{#X1MouseButtonReleaseEvent. {#osWindow. #mouseButtonPosition}}.
84 132 -> #{#X1MouseButtonDoubleClickEvent. {#osWindow. #mouseButtonPosition}}.
86 140 -> #{#X2MouseButtonPressEvent. {#osWindow. #mouseButtonPosition}}.
87 141 -> #{#X2MouseButtonReleaseEvent. {#osWindow. #mouseButtonPosition}}.
88 142 -> #{#X2MouseButtonDoubleClickEvent. {#osWindow. #mouseButtonPosition}}.
90 150 -> #{#MouseMotionEvent. {#osWindow. #mouseMotionPosition}}.
91 151 -> #{#MouseEnterEvent. {#osWindow. #mouseMotionPosition}}.
92 152 -> #{#MouseLeaveEvent. {#osWindow. #mouseMotionPosition}}.
94 160 -> #{#KeyboardPressEvent. {#osWindow. #keyboardKey}}.
95 161 -> #{#KeyboardReleaseEvent. {#osWindow. #keyboardKey}}.
97 "162 -> #{#MouseMotionEvent. {#osWindow. #mouseMotionPosition}}."
101 w@Windows constructEvent
103 w eventTable at: w Lib primitives getEventType do
106 event: entry construct.
107 "(event is: MouseMotionEvent) ifFalse: [lobby inform: event printString]."
108 w Lib primitives popEvent do.
110 ifAbsent: [w Lib primitives popEvent do. Nil]
114 [w Lib primitives haveEvent do == 0 ifFalse: [Windows constructEvent]].
116 w@Windows waitForEvent
117 [w Lib primitives waitForEvent do == 0 ifFalse: [Windows constructEvent]].
119 Windows define: #Window &slots: {#osWindow. #sceneElement}.
121 Windows addSlot: #windows valued: Dictionary new.
123 w@(Window traits) newWidth: width height: height sceneElement: sceneElement
125 newW: (w cloneSettingSlots: #{#osWindow. #sceneElement} to:
126 {Windows Lib primitives createWindow applyTo: {width. height}.
128 windows at: newW osWindow put: newW.
136 event@(Event traits) dispatchEvent
138 windows at: event osWindow ifPresent:
139 [| :window | window sceneElement handle: event].
142 window@(Window traits) blit: form@(Form traits) dest: dest@(Rectangle traits) src: src@(Rectangle traits)
143 "Careful! bad arguments can clobber memory; TODO: add checking"
145 form depth == 32 ifFalse: [onlyDepth32CurrentlySupported].
146 Windows Lib primitives blit applyTo:
147 {window osWindow. dest left. dest top. dest width. dest height.
148 form bits bytes address. src left. src top. src width. src height. form width * 4}.
152 Windows Lib primitives init do.