gosu 0.8.0.pre3 → 0.8.0.pre4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/Gosu/Buttons.hpp +13 -11
  3. data/{linux → ext/gosu}/extconf.rb +25 -47
  4. data/{GosuImpl/RubyGosu_wrap.cxx → ext/gosu/gosu_wrap.cxx} +3 -2
  5. data/{GosuImpl/RubyGosu_wrap.h → ext/gosu/gosu_wrap.h} +0 -0
  6. data/lib/gosu.rb +6 -7
  7. data/lib/gosu/zen.rb +12 -0
  8. data/{GosuImpl → src}/Audio/ALChannelManagement.hpp +0 -0
  9. data/{GosuImpl → src}/Audio/AudioFile.hpp +0 -0
  10. data/{GosuImpl → src}/Audio/AudioOpenAL.cpp +0 -0
  11. data/{GosuImpl → src}/Audio/AudioOpenAL.mm +0 -0
  12. data/{GosuImpl → src}/Audio/AudioToolboxFile.hpp +0 -0
  13. data/{GosuImpl → src}/Audio/OggFile.hpp +0 -0
  14. data/{GosuImpl → src}/Audio/SndFile.hpp +0 -0
  15. data/{GosuImpl/Graphics → src/Bitmap}/Bitmap.cpp +2 -0
  16. data/{GosuImpl/Graphics → src/Bitmap}/BitmapApple.mm +0 -0
  17. data/{GosuImpl/Graphics → src/Bitmap}/BitmapBMP.cpp +0 -0
  18. data/{GosuImpl/Graphics → src/Bitmap}/BitmapColorKey.cpp +0 -0
  19. data/{GosuImpl/Graphics → src/Bitmap}/BitmapFreeImage.cpp +0 -0
  20. data/{GosuImpl/Graphics → src/Bitmap}/BitmapGDIplus.cpp +0 -0
  21. data/{GosuImpl/Graphics → src/Bitmap}/BitmapUtils.cpp +0 -0
  22. data/{GosuImpl → src}/DirectoriesMac.mm +0 -0
  23. data/{GosuImpl → src}/DirectoriesTouch.mm +0 -0
  24. data/{GosuImpl → src}/DirectoriesUnix.cpp +0 -0
  25. data/{GosuImpl → src}/DirectoriesWin.cpp +0 -0
  26. data/{GosuImpl → src}/FileUnix.cpp +0 -0
  27. data/{GosuImpl → src}/FileWin.cpp +0 -0
  28. data/{GosuImpl/Graphics → src}/GosuView.hpp +0 -0
  29. data/{GosuImpl/Graphics → src}/GosuView.mm +0 -0
  30. data/{GosuImpl → src}/Graphics/BlockAllocator.cpp +0 -0
  31. data/{GosuImpl → src}/Graphics/BlockAllocator.hpp +0 -0
  32. data/{GosuImpl → src}/Graphics/ClipRectStack.hpp +0 -0
  33. data/{GosuImpl → src}/Graphics/Color.cpp +0 -0
  34. data/{GosuImpl → src}/Graphics/Common.hpp +0 -0
  35. data/{GosuImpl → src}/Graphics/DrawOp.hpp +0 -0
  36. data/{GosuImpl → src}/Graphics/DrawOpQueue.hpp +0 -0
  37. data/{GosuImpl → src}/Graphics/Graphics.cpp +0 -0
  38. data/{GosuImpl → src}/Graphics/Image.cpp +0 -0
  39. data/{GosuImpl → src}/Graphics/LargeImageData.cpp +0 -0
  40. data/{GosuImpl → src}/Graphics/LargeImageData.hpp +0 -0
  41. data/{GosuImpl → src}/Graphics/Macro.hpp +0 -0
  42. data/{GosuImpl → src}/Graphics/RenderState.hpp +0 -0
  43. data/{GosuImpl → src}/Graphics/TexChunk.cpp +0 -0
  44. data/{GosuImpl → src}/Graphics/TexChunk.hpp +0 -0
  45. data/{GosuImpl → src}/Graphics/Texture.cpp +0 -0
  46. data/{GosuImpl → src}/Graphics/Texture.hpp +0 -0
  47. data/{GosuImpl → src}/Graphics/Transform.cpp +0 -0
  48. data/{GosuImpl → src}/Graphics/TransformStack.hpp +0 -0
  49. data/{GosuImpl → src}/IO.cpp +0 -0
  50. data/{GosuImpl → src}/Iconv.hpp +0 -0
  51. data/{GosuImpl → src}/Input/AccelerometerReader.hpp +0 -0
  52. data/{GosuImpl → src}/Input/AccelerometerReader.mm +0 -0
  53. data/{GosuImpl → src/Input}/Input.cpp +0 -0
  54. data/{GosuImpl → src/Input}/InputTouch.mm +0 -0
  55. data/{GosuImpl → src/Input}/TextInput.cpp +0 -0
  56. data/{GosuImpl → src/Input}/TextInputMac.mm +0 -0
  57. data/{GosuImpl → src}/Inspection.cpp +0 -0
  58. data/{GosuImpl → src}/MacUtility.hpp +0 -0
  59. data/{GosuImpl → src}/Math.cpp +0 -0
  60. data/{GosuImpl → src}/Sockets/CommSocket.cpp +0 -0
  61. data/{GosuImpl → src}/Sockets/ListenerSocket.cpp +0 -0
  62. data/{GosuImpl → src}/Sockets/MessageSocket.cpp +0 -0
  63. data/{GosuImpl → src}/Sockets/Socket.cpp +0 -0
  64. data/{GosuImpl → src}/Sockets/Socket.hpp +0 -0
  65. data/{GosuImpl/Graphics → src/Text}/Font.cpp +1 -1
  66. data/{GosuImpl/Graphics → src/Text}/FormattedString.hpp +0 -0
  67. data/{GosuImpl/Graphics → src/Text}/Text.cpp +1 -1
  68. data/{GosuImpl/Graphics/TextTouch.mm → src/Text/TextApple.mm} +0 -0
  69. data/{GosuImpl/Graphics → src/Text}/TextMac.cpp +1 -1
  70. data/{GosuImpl/Graphics → src/Text}/TextTTFWin.cpp +0 -0
  71. data/{GosuImpl/Graphics → src/Text}/TextUnix.cpp +0 -0
  72. data/{GosuImpl/Graphics → src/Text}/TextWin.cpp +0 -0
  73. data/{GosuImpl → src}/TimingApple.cpp +0 -0
  74. data/{GosuImpl → src}/TimingUnix.cpp +0 -0
  75. data/{GosuImpl → src}/TimingWin.cpp +0 -0
  76. data/{GosuImpl → src}/Utility.cpp +0 -0
  77. data/{GosuImpl → src}/UtilityApple.mm +0 -0
  78. data/{GosuImpl → src}/UtilityWin.cpp +0 -0
  79. data/{GosuImpl → src}/WinMain.cpp +0 -0
  80. data/{GosuImpl → src}/WinUtility.cpp +0 -0
  81. data/{GosuImpl → src}/Window.cpp +0 -0
  82. data/{GosuImpl → src}/WindowTouch.mm +0 -0
  83. data/{GosuImpl → src}/X11vroot.h +0 -0
  84. metadata +97 -193
  85. data/.yardopts +0 -1
  86. data/COPYING +0 -29
  87. data/GosuImpl/InputMac.mm +0 -733
  88. data/GosuImpl/InputWin.cpp +0 -483
  89. data/GosuImpl/InputX.cpp +0 -243
  90. data/GosuImpl/RubyGosu.swg +0 -821
  91. data/GosuImpl/RubyGosu_SWIG_GC_PATCH.patch +0 -126
  92. data/GosuImpl/RubyGosu_SWIG_RENAME_PATCH.patch +0 -62
  93. data/GosuImpl/TextInputWin.cpp +0 -211
  94. data/GosuImpl/TextInputX.cpp +0 -217
  95. data/GosuImpl/WindowWin.cpp +0 -534
  96. data/GosuImpl/WindowX.cpp +0 -458
  97. data/README.txt +0 -25
  98. data/dependencies/libogg/AUTHORS +0 -4
  99. data/dependencies/libogg/CHANGES +0 -70
  100. data/dependencies/libogg/COPYING +0 -28
  101. data/dependencies/libogg/include/ogg/ogg.h +0 -209
  102. data/dependencies/libogg/include/ogg/os_types.h +0 -147
  103. data/dependencies/libogg/src/bitwise.c +0 -857
  104. data/dependencies/libogg/src/framing.c +0 -2089
  105. data/dependencies/libvorbis/AUTHORS +0 -3
  106. data/dependencies/libvorbis/CHANGES +0 -126
  107. data/dependencies/libvorbis/COPYING +0 -28
  108. data/dependencies/libvorbis/include/vorbis/codec.h +0 -243
  109. data/dependencies/libvorbis/include/vorbis/vorbisenc.h +0 -436
  110. data/dependencies/libvorbis/include/vorbis/vorbisfile.h +0 -206
  111. data/dependencies/libvorbis/lib/analysis.c +0 -120
  112. data/dependencies/libvorbis/lib/backends.h +0 -144
  113. data/dependencies/libvorbis/lib/barkmel.c +0 -64
  114. data/dependencies/libvorbis/lib/bitrate.c +0 -253
  115. data/dependencies/libvorbis/lib/bitrate.h +0 -59
  116. data/dependencies/libvorbis/lib/block.c +0 -1046
  117. data/dependencies/libvorbis/lib/books/coupled/res_books_51.h +0 -12257
  118. data/dependencies/libvorbis/lib/books/coupled/res_books_stereo.h +0 -15783
  119. data/dependencies/libvorbis/lib/books/floor/floor_books.h +0 -1547
  120. data/dependencies/libvorbis/lib/books/uncoupled/res_books_uncoupled.h +0 -7758
  121. data/dependencies/libvorbis/lib/codebook.c +0 -479
  122. data/dependencies/libvorbis/lib/codebook.h +0 -119
  123. data/dependencies/libvorbis/lib/codec_internal.h +0 -167
  124. data/dependencies/libvorbis/lib/envelope.c +0 -375
  125. data/dependencies/libvorbis/lib/envelope.h +0 -80
  126. data/dependencies/libvorbis/lib/floor0.c +0 -222
  127. data/dependencies/libvorbis/lib/floor1.c +0 -1099
  128. data/dependencies/libvorbis/lib/highlevel.h +0 -58
  129. data/dependencies/libvorbis/lib/info.c +0 -664
  130. data/dependencies/libvorbis/lib/lookup.c +0 -94
  131. data/dependencies/libvorbis/lib/lookup.h +0 -32
  132. data/dependencies/libvorbis/lib/lookup_data.h +0 -192
  133. data/dependencies/libvorbis/lib/lpc.c +0 -160
  134. data/dependencies/libvorbis/lib/lpc.h +0 -29
  135. data/dependencies/libvorbis/lib/lsp.c +0 -456
  136. data/dependencies/libvorbis/lib/lsp.h +0 -28
  137. data/dependencies/libvorbis/lib/mapping0.c +0 -816
  138. data/dependencies/libvorbis/lib/masking.h +0 -785
  139. data/dependencies/libvorbis/lib/mdct.c +0 -563
  140. data/dependencies/libvorbis/lib/mdct.h +0 -71
  141. data/dependencies/libvorbis/lib/misc.h +0 -57
  142. data/dependencies/libvorbis/lib/modes/floor_all.h +0 -260
  143. data/dependencies/libvorbis/lib/modes/psych_11.h +0 -51
  144. data/dependencies/libvorbis/lib/modes/psych_16.h +0 -133
  145. data/dependencies/libvorbis/lib/modes/psych_44.h +0 -642
  146. data/dependencies/libvorbis/lib/modes/psych_8.h +0 -101
  147. data/dependencies/libvorbis/lib/modes/residue_16.h +0 -163
  148. data/dependencies/libvorbis/lib/modes/residue_44.h +0 -292
  149. data/dependencies/libvorbis/lib/modes/residue_44p51.h +0 -451
  150. data/dependencies/libvorbis/lib/modes/residue_44u.h +0 -318
  151. data/dependencies/libvorbis/lib/modes/residue_8.h +0 -109
  152. data/dependencies/libvorbis/lib/modes/setup_11.h +0 -143
  153. data/dependencies/libvorbis/lib/modes/setup_16.h +0 -153
  154. data/dependencies/libvorbis/lib/modes/setup_22.h +0 -128
  155. data/dependencies/libvorbis/lib/modes/setup_32.h +0 -132
  156. data/dependencies/libvorbis/lib/modes/setup_44.h +0 -117
  157. data/dependencies/libvorbis/lib/modes/setup_44p51.h +0 -74
  158. data/dependencies/libvorbis/lib/modes/setup_44u.h +0 -74
  159. data/dependencies/libvorbis/lib/modes/setup_8.h +0 -149
  160. data/dependencies/libvorbis/lib/modes/setup_X.h +0 -225
  161. data/dependencies/libvorbis/lib/os.h +0 -186
  162. data/dependencies/libvorbis/lib/psy.c +0 -1203
  163. data/dependencies/libvorbis/lib/psy.h +0 -154
  164. data/dependencies/libvorbis/lib/psytune.c +0 -524
  165. data/dependencies/libvorbis/lib/registry.c +0 -45
  166. data/dependencies/libvorbis/lib/registry.h +0 -32
  167. data/dependencies/libvorbis/lib/res0.c +0 -889
  168. data/dependencies/libvorbis/lib/scales.h +0 -90
  169. data/dependencies/libvorbis/lib/sharedbook.c +0 -579
  170. data/dependencies/libvorbis/lib/smallft.c +0 -1255
  171. data/dependencies/libvorbis/lib/smallft.h +0 -34
  172. data/dependencies/libvorbis/lib/synthesis.c +0 -184
  173. data/dependencies/libvorbis/lib/tone.c +0 -54
  174. data/dependencies/libvorbis/lib/vorbisenc.c +0 -1215
  175. data/dependencies/libvorbis/lib/vorbisfile.c +0 -2337
  176. data/dependencies/libvorbis/lib/window.c +0 -2135
  177. data/dependencies/libvorbis/lib/window.h +0 -26
  178. data/dependencies/ogg_vorbis.license +0 -28
  179. data/reference/gosu.rb +0 -1284
@@ -1,483 +0,0 @@
1
- #include <Gosu/Input.hpp>
2
- #include <Gosu/Platform.hpp>
3
- #include <Gosu/TR1.hpp>
4
- #include <Gosu/WinUtility.hpp>
5
- #include <cwchar>
6
- #include <iomanip>
7
- #include <sstream>
8
- #include <stdexcept>
9
- #include <vector>
10
-
11
- #ifndef DIRECTINPUT_VERSION
12
- #define DIRECTINPUT_VERSION 0x0800
13
- #endif
14
- #include <dinput.h>
15
-
16
- namespace {
17
- std::tr1::array<bool, Gosu::numButtons> buttons;
18
- }
19
-
20
- struct Gosu::Input::Impl
21
- {
22
- TextInput* textInput;
23
- Impl() : textInput(0) {}
24
-
25
- HWND window;
26
- std::tr1::shared_ptr<IDirectInput8> input;
27
-
28
- typedef std::tr1::shared_ptr<IDirectInputDevice8> Device;
29
- Device keyboard, mouse;
30
- std::vector<Device> gamepads;
31
-
32
- double mouseX, mouseY;
33
- double mouseFactorX, mouseFactorY;
34
- bool swapMouse;
35
-
36
- struct EventInfo
37
- {
38
- enum { buttonUp, buttonDown } action;
39
- unsigned id;
40
- };
41
- typedef std::vector<EventInfo> Events;
42
- Events events;
43
-
44
- static const unsigned inputBufferSize = 32;
45
- static const int stickRange = 500;
46
- static const int stickThreshold = 250;
47
-
48
- // For devices with buffered data.
49
- void forceButton(unsigned id, bool down, bool collectEvent)
50
- {
51
- buttons.at(id) = down;
52
-
53
- if (!collectEvent)
54
- return;
55
-
56
- EventInfo newEvent;
57
- if (down)
58
- newEvent.action = EventInfo::buttonDown;
59
- else
60
- newEvent.action = EventInfo::buttonUp;
61
- newEvent.id = id;
62
- events.push_back(newEvent);
63
- }
64
-
65
- // For polled devices, or when there's no data.
66
- void setButton(unsigned id, bool down, bool collectEvent)
67
- {
68
- if (buttons.at(id) != down)
69
- forceButton(id, down, collectEvent);
70
- }
71
-
72
- static void throwError(const char* action, HRESULT hr)
73
- {
74
- std::ostringstream stream;
75
- stream << "While " << action << ", the following DirectInput "
76
- << "error occured: " << std::hex << std::setw(8) << hr;
77
- throw std::runtime_error(stream.str());
78
- // IMPR: Error string!
79
- }
80
-
81
- static inline HRESULT check(const char* action, HRESULT hr)
82
- {
83
- if (FAILED(hr))
84
- throwError(action, hr);
85
-
86
- return hr;
87
- }
88
-
89
- // Callback that adjusts all found axes to [-stickRange, +stickRange].
90
- static BOOL CALLBACK axisCallback(LPCDIDEVICEOBJECTINSTANCE instance,
91
- LPVOID userData)
92
- {
93
- IDirectInputDevice8* dev = static_cast<IDirectInputDevice8*>(userData);
94
-
95
- DIPROPRANGE range;
96
- range.diph.dwSize = sizeof(DIPROPRANGE);
97
- range.diph.dwHeaderSize = sizeof(DIPROPHEADER);
98
- range.diph.dwHow = DIPH_BYID;
99
- range.diph.dwObj = instance->dwType;
100
- range.lMin = -stickRange;
101
- range.lMax = +stickRange;
102
- dev->SetProperty(DIPROP_RANGE, &range.diph);
103
-
104
- return DIENUM_CONTINUE;
105
- }
106
-
107
- // Callback that lists all gamepads.
108
- static BOOL CALLBACK gamepadCallback(LPCDIDEVICEINSTANCE device,
109
- LPVOID userData)
110
- {
111
- Impl* pimpl = static_cast<Impl*>(userData);
112
-
113
- IDirectInputDevice8* gamepad;
114
- if (FAILED(pimpl->input->CreateDevice(device->guidInstance,
115
- &gamepad, 0)))
116
- {
117
- return DIENUM_CONTINUE;
118
- }
119
-
120
- if (FAILED(gamepad->SetDataFormat(&c_dfDIJoystick)) ||
121
- FAILED(gamepad->SetCooperativeLevel(pimpl->window,
122
- DISCL_EXCLUSIVE | DISCL_FOREGROUND)) ||
123
- FAILED(gamepad->EnumObjects(axisCallback, gamepad, DIDFT_AXIS)))
124
- {
125
- gamepad->Release();
126
- return DIENUM_CONTINUE;
127
- }
128
-
129
- pimpl->gamepads.push_back(Win::shareComPtr(gamepad));
130
-
131
- return DIENUM_CONTINUE;
132
- }
133
-
134
- void updateMousePos()
135
- {
136
- POINT pos;
137
- if (!::GetCursorPos(&pos))
138
- return;
139
-
140
- Win::check(::ScreenToClient(window, &pos));
141
-
142
- mouseX = pos.x;
143
- mouseY = pos.y;
144
- }
145
-
146
- void updateButtons(bool collectEvents)
147
- {
148
- DIDEVICEOBJECTDATA data[inputBufferSize];
149
- DWORD inOut;
150
- HRESULT hr;
151
-
152
- RECT rect;
153
- ::GetClientRect(window, &rect);
154
- bool ignoreClicks = mouseX < 0 || mouseX > rect.right || mouseY < 0 || mouseY > rect.bottom;
155
-
156
- inOut = inputBufferSize;
157
- hr = mouse->GetDeviceData(sizeof data[0], data, &inOut, 0);
158
- switch(hr)
159
- {
160
- case DI_OK:
161
- case DI_BUFFEROVERFLOW:
162
- {
163
- // Everything's ok: Update buttons and fire events.
164
- for (unsigned i = 0; i < inOut; ++i)
165
- {
166
- bool down = (data[i].dwData & 0x80) != 0 && !ignoreClicks;
167
-
168
- // No switch statement here because it breaks compilation with MinGW.
169
- if (data[i].dwOfs == DIMOFS_BUTTON0)
170
- {
171
- unsigned id = swapMouse ? msRight : msLeft;
172
- setButton(id, down, collectEvents);
173
- }
174
- else if (data[i].dwOfs == DIMOFS_BUTTON1)
175
- {
176
- unsigned id = swapMouse ? msLeft : msRight;
177
- setButton(id, down, collectEvents);
178
- }
179
- else if (data[i].dwOfs == DIMOFS_BUTTON2)
180
- {
181
- setButton(msMiddle, down, collectEvents);
182
- }
183
- else if (data[i].dwOfs == DIMOFS_Z &&
184
- collectEvents && data[i].dwData)
185
- {
186
- EventInfo event;
187
- event.action = EventInfo::buttonDown;
188
- if (int(data[i].dwData) < 0)
189
- event.id = msWheelDown;
190
- else
191
- event.id = msWheelUp;
192
- events.push_back(event);
193
- event.action = EventInfo::buttonUp;
194
- events.push_back(event);
195
- }
196
- }
197
- break;
198
- }
199
-
200
- case DIERR_NOTACQUIRED:
201
- case DIERR_INPUTLOST:
202
- {
203
- // Cannot fetch new events: Release all buttons.
204
- for (unsigned id = msRangeBegin; id <= msRangeEnd; ++id)
205
- setButton(id, false, collectEvents);
206
- mouse->Acquire();
207
- break;
208
- }
209
- }
210
-
211
- inOut = inputBufferSize;
212
- hr = keyboard->GetDeviceData(sizeof data[0], data, &inOut, 0);
213
- switch (hr)
214
- {
215
- case DI_OK:
216
- case DI_BUFFEROVERFLOW:
217
- {
218
- for (unsigned i = 0; i < inOut; ++i)
219
- forceButton(data[i].dwOfs, (data[i].dwData & 0x80) != 0, collectEvents);
220
- break;
221
- }
222
-
223
- case DIERR_NOTACQUIRED:
224
- case DIERR_INPUTLOST:
225
- {
226
- for (unsigned id = kbRangeBegin; id <= kbRangeEnd; ++id)
227
- setButton(id, false, collectEvents);
228
- keyboard->Acquire();
229
- break;
230
- }
231
- }
232
-
233
- std::tr1::array<bool, gpNum> gpBuffer = { false };
234
- for (unsigned gp = 0; gp < gamepads.size() && gp < numGamepads; ++gp)
235
- {
236
- gamepads[gp]->Poll();
237
-
238
- int rangeOffset = (gp + 1) * gpNumPerGamepad - gpRangeBegin;
239
-
240
- DIJOYSTATE joy;
241
- hr = gamepads[gp]->GetDeviceState(sizeof joy, &joy);
242
- switch (hr)
243
- {
244
- case DI_OK:
245
- {
246
- if (joy.lX < -stickThreshold)
247
- gpBuffer[gpLeft + rangeOffset] = true;
248
- else if (joy.lX > stickThreshold)
249
- gpBuffer[gpRight + rangeOffset] = true;
250
-
251
- if (joy.lY < -stickThreshold)
252
- gpBuffer[gpUp + rangeOffset] = true;
253
- else if (joy.lY > stickThreshold)
254
- gpBuffer[gpDown + rangeOffset] = true;
255
-
256
- for (unsigned id = gpButton0; id <= gpButton15; ++id)
257
- if (joy.rgbButtons[id - gpButton0])
258
- gpBuffer[id + rangeOffset] = true;
259
-
260
- break;
261
- }
262
-
263
- case DIERR_NOTACQUIRED:
264
- case DIERR_INPUTLOST:
265
- {
266
- gamepads[gp]->Acquire();
267
-
268
- break;
269
- }
270
- }
271
-
272
- // Merge these results into the area for "all gamepads OR'ed together"
273
- for (int index = 0; index < gpNumPerGamepad; ++index)
274
- gpBuffer[index] = (gpBuffer[index] || gpBuffer[index + (gp + 1) * gpNumPerGamepad]);
275
- }
276
-
277
- for (unsigned id = gpRangeBegin; id <= gpRangeEnd; ++id)
278
- setButton(id, gpBuffer[id - gpRangeBegin], collectEvents);
279
- }
280
- };
281
-
282
- Gosu::Input::Input(HWND window)
283
- : pimpl(new Impl)
284
- {
285
- pimpl->window = window;
286
- pimpl->mouseFactorX = pimpl->mouseFactorY = 1.0;
287
-
288
- // Create the main input object (only necessary for setup).
289
-
290
- IDirectInput8* inputRaw;
291
- Impl::check("creating the main DirectInput object",
292
- ::DirectInput8Create(Win::instance(), DIRECTINPUT_VERSION,
293
- IID_IDirectInput8, reinterpret_cast<void**>(&inputRaw), 0));
294
- pimpl->input = Win::shareComPtr(inputRaw);
295
-
296
-
297
- // Prepare property struct for setting the amount of data to buffer.
298
-
299
- DIPROPDWORD bufferSize;
300
- bufferSize.diph.dwSize = sizeof(DIPROPDWORD);
301
- bufferSize.diph.dwHeaderSize = sizeof(DIPROPHEADER);
302
- bufferSize.diph.dwHow = DIPH_DEVICE;
303
- bufferSize.diph.dwObj = 0;
304
- bufferSize.dwData = Impl::inputBufferSize;
305
-
306
-
307
- // Set up the system keyboard.
308
-
309
- IDirectInputDevice8* kbRaw;
310
- Impl::check("creating the keyboard device object",
311
- pimpl->input->CreateDevice(GUID_SysKeyboard, &kbRaw, 0));
312
- pimpl->keyboard = Win::shareComPtr(kbRaw);
313
-
314
- Impl::check("setting the keyboard's data format",
315
- kbRaw->SetDataFormat(&c_dfDIKeyboard));
316
- Impl::check("setting the keyboard's cooperative level",
317
- kbRaw->SetCooperativeLevel(window,
318
- DISCL_FOREGROUND | DISCL_NONEXCLUSIVE));
319
- Impl::check("setting the keyboard's buffer size",
320
- kbRaw->SetProperty(DIPROP_BUFFERSIZE, &bufferSize.diph));
321
-
322
- kbRaw->Acquire();
323
-
324
-
325
- // Set up the system mouse.
326
-
327
- IDirectInputDevice8* mouseRaw;
328
- Impl::check("creating the mouse device object",
329
- pimpl->input->CreateDevice(GUID_SysMouse, &mouseRaw, 0));
330
- pimpl->mouse = Win::shareComPtr(mouseRaw);
331
-
332
- Impl::check("setting the mouse's data format",
333
- mouseRaw->SetDataFormat(&c_dfDIMouse));
334
- Impl::check("setting the mouse's cooperative level",
335
- mouseRaw->SetCooperativeLevel(window,
336
- DISCL_FOREGROUND | DISCL_NONEXCLUSIVE));
337
- Impl::check("setting the mouse's buffer size",
338
- mouseRaw->SetProperty(DIPROP_BUFFERSIZE, &bufferSize.diph));
339
-
340
- mouseRaw->Acquire();
341
-
342
- pimpl->swapMouse = ::GetSystemMetrics(SM_SWAPBUTTON) != 0;
343
-
344
-
345
- // Set up all gamepads.
346
-
347
- pimpl->input->EnumDevices(DI8DEVCLASS_GAMECTRL, Impl::gamepadCallback,
348
- pimpl.get(), DIEDFL_ATTACHEDONLY);
349
-
350
-
351
- // Get into a usable default state.
352
-
353
- pimpl->mouseX = pimpl->mouseY = 0;
354
- pimpl->updateMousePos();
355
- buttons.assign(false);
356
- }
357
-
358
- Gosu::Input::~Input()
359
- {
360
- }
361
-
362
- Gosu::Button Gosu::Input::charToId(wchar_t ch)
363
- {
364
- SHORT vkey = ::VkKeyScan(/*std::*/towlower(ch));
365
-
366
- // No key found?
367
- if (HIBYTE(vkey) == static_cast<unsigned char>(-1) &&
368
- LOBYTE(vkey) == static_cast<unsigned char>(-1))
369
- {
370
- return noButton;
371
- }
372
-
373
- // Key needs special modifier keys?
374
- if (HIBYTE(vkey) != 0)
375
- return noButton;
376
-
377
- // Now try to translate the virtual key code into a scan code.
378
- return Button(::MapVirtualKey(vkey, 0));
379
- }
380
-
381
- wchar_t Gosu::Input::idToChar(Gosu::Button btn)
382
- {
383
- // Only translate keyboard ids.
384
- if (btn.id() > 255)
385
- return 0;
386
-
387
- // Special case...?
388
- if (btn.id() == kbSpace)
389
- return L' ';
390
-
391
- // Try to get the key name.
392
- // (Three elements so too-long names will make GKNT return 3 and we'll know.)
393
- wchar_t buf[3];
394
- if (::GetKeyNameText(btn.id() << 16, buf, 3) == 1)
395
- return /*std::*/towlower(buf[0]);
396
-
397
- return 0;
398
- }
399
-
400
- bool Gosu::Input::down(Button btn) const
401
- {
402
- // The invalid button is never pressed (but can be passed to this function).
403
- if (btn == noButton || btn.id() >= numButtons)
404
- return false;
405
-
406
- return buttons.at(btn.id());
407
- }
408
-
409
- double Gosu::Input::mouseX() const
410
- {
411
- return pimpl->mouseX * pimpl->mouseFactorX;
412
- }
413
-
414
- double Gosu::Input::mouseY() const
415
- {
416
- return pimpl->mouseY * pimpl->mouseFactorY;
417
- }
418
-
419
- void Gosu::Input::setMousePosition(double x, double y)
420
- {
421
- POINT pos = { x / pimpl->mouseFactorX, y / pimpl->mouseFactorY };
422
- ::ClientToScreen(pimpl->window, &pos);
423
- ::SetCursorPos(pos.x, pos.y);
424
- pimpl->updateMousePos();
425
- }
426
-
427
- void Gosu::Input::setMouseFactors(double factorX, double factorY)
428
- {
429
- pimpl->mouseFactorX = factorX;
430
- pimpl->mouseFactorY = factorY;
431
- }
432
-
433
- const Gosu::Touches& Gosu::Input::currentTouches() const
434
- {
435
- static Gosu::Touches none;
436
- return none;
437
- }
438
-
439
- double Gosu::Input::accelerometerX() const
440
- {
441
- return 0.0;
442
- }
443
-
444
- double Gosu::Input::accelerometerY() const
445
- {
446
- return 0.0;
447
- }
448
-
449
- double Gosu::Input::accelerometerZ() const
450
- {
451
- return 0.0;
452
- }
453
-
454
- void Gosu::Input::update()
455
- {
456
- pimpl->updateMousePos();
457
- pimpl->updateButtons(true);
458
- Impl::Events events;
459
- events.swap(pimpl->events);
460
- for (unsigned i = 0; i < events.size(); ++i)
461
- {
462
- if (events[i].action == Impl::EventInfo::buttonDown)
463
- {
464
- if (onButtonDown)
465
- onButtonDown(Button(events[i].id));
466
- }
467
- else
468
- {
469
- if (onButtonUp)
470
- onButtonUp(Button(events[i].id));
471
- }
472
- }
473
- }
474
-
475
- Gosu::TextInput* Gosu::Input::textInput() const
476
- {
477
- return pimpl->textInput;
478
- }
479
-
480
- void Gosu::Input::setTextInput(TextInput* textInput)
481
- {
482
- pimpl->textInput = textInput;
483
- }