Extracting parts of the formatting method into configuration and an options helper...
[cslatevm.git] / src / plugins / old / windows.slate
blob2079454b92c0eff0dc61aae0bccf8c6a96bf58ce
1 lobby ensureNamespace: #Windows &delegate: True.
3 Windows define: #Lib
4   &builder: [ExternalInterface newForLibrary: 'sdl-windows' primitives: #{
5       {#Void. #init. {}}.
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}}
20   }].
22 Windows Lib enable.
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
31 [| event |
32   event: entry prototype copy.
33   entry constructors do: [| :name | event construct: name].
34   event
37 event@(Event traits) construct: _@#osWindow
39   event addSlot: #osWindow valued: Windows Lib primitives getEventWindow do.
42 event@(Event traits) construct: _@#mouseButtonPosition
44   event position:
45     Windows Lib primitives getEventMouseButtonX do ,
46     Windows Lib primitives getEventMouseButtonY do.
49 event@(Event traits) construct: _@#mouseMotionPosition
51   event position:
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.
65 [| :spec |
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}}.
96     "#FIXME. "
97     "162 -> #{#MouseMotionEvent.                    {#osWindow.  #mouseMotionPosition}}."
101 w@Windows constructEvent
103   w eventTable at: w Lib primitives getEventType do
104                ifPresent:
105                  [| :entry event |
106                   event: entry construct.
107                   "(event is: MouseMotionEvent) ifFalse: [lobby inform: event printString]."
108                   w Lib primitives popEvent do.
109                   event]
110                ifAbsent: [w Lib primitives popEvent do. Nil]
113 w@Windows getEvent
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
124 [| newW |
125   newW: (w cloneSettingSlots: #{#osWindow. #sceneElement} to:
126     {Windows Lib primitives createWindow applyTo: {width. height}.
127      sceneElement}).
128   windows at: newW osWindow put: newW.
129   newW
132 _@Nil dispatchEvent
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}.
149   window
152 Windows Lib primitives init do.