gosu 0.10.9.pre1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/Gosu/Audio.hpp +35 -66
  3. data/Gosu/AutoLink.hpp +14 -16
  4. data/Gosu/Bitmap.hpp +50 -37
  5. data/Gosu/Buttons.hpp +246 -265
  6. data/Gosu/Color.hpp +32 -76
  7. data/Gosu/Directories.hpp +14 -17
  8. data/Gosu/Font.hpp +28 -34
  9. data/Gosu/Fwd.hpp +27 -31
  10. data/Gosu/Gosu.hpp +2 -5
  11. data/Gosu/Graphics.hpp +31 -48
  12. data/Gosu/GraphicsBase.hpp +27 -58
  13. data/Gosu/IO.hpp +44 -56
  14. data/Gosu/Image.hpp +29 -73
  15. data/Gosu/ImageData.hpp +13 -17
  16. data/Gosu/Input.hpp +42 -57
  17. data/Gosu/Inspection.hpp +2 -6
  18. data/Gosu/Math.hpp +32 -38
  19. data/Gosu/Platform.hpp +10 -29
  20. data/Gosu/Text.hpp +30 -39
  21. data/Gosu/TextInput.hpp +29 -36
  22. data/Gosu/Timing.hpp +14 -16
  23. data/Gosu/Utility.hpp +10 -15
  24. data/Gosu/Version.hpp +13 -14
  25. data/Gosu/Window.hpp +53 -68
  26. data/README.md +23 -11
  27. data/ext/gosu/extconf.rb +31 -81
  28. data/lib/gosu/patches.rb +35 -19
  29. data/lib/gosu/run.rb +13 -4
  30. data/rdoc/gosu.rb +24 -20
  31. data/src/ALChannelManagement.hpp +119 -0
  32. data/src/{Audio/Audio.cpp → Audio.cpp} +177 -211
  33. data/src/AudioFile.hpp +57 -0
  34. data/src/AudioToolboxFile.hpp +214 -0
  35. data/src/Bitmap.cpp +159 -0
  36. data/src/BitmapIO.cpp +141 -0
  37. data/src/BlockAllocator.cpp +133 -0
  38. data/src/{Graphics/BlockAllocator.hpp → BlockAllocator.hpp} +34 -35
  39. data/src/ClipRectStack.hpp +87 -0
  40. data/src/{Graphics/Color.cpp → Color.cpp} +30 -28
  41. data/src/DirectoriesApple.cpp +68 -0
  42. data/src/DirectoriesUnix.cpp +20 -18
  43. data/src/DirectoriesWin.cpp +40 -41
  44. data/src/DrawOp.hpp +168 -0
  45. data/src/DrawOpQueue.hpp +190 -0
  46. data/src/FileUnix.cpp +40 -46
  47. data/src/FileWin.cpp +42 -38
  48. data/src/Font.cpp +165 -0
  49. data/src/{Text/FormattedString.hpp → FormattedString.hpp} +114 -114
  50. data/src/GosuAppDelegate.cpp +30 -0
  51. data/src/{UIKit/GosuAppDelegate.h → GosuAppDelegate.h} +0 -0
  52. data/src/{UIKit/GosuGLView.mm → GosuGLView.cpp} +22 -17
  53. data/src/{UIKit/GosuGLView.h → GosuGLView.h} +0 -0
  54. data/src/GosuViewController.cpp +231 -0
  55. data/src/{UIKit/GosuViewController.h → GosuViewController.h} +0 -0
  56. data/src/Graphics.cpp +464 -0
  57. data/src/{Graphics/Common.hpp → GraphicsImpl.hpp} +29 -32
  58. data/src/IO.cpp +17 -16
  59. data/src/Iconv.hpp +13 -22
  60. data/src/Image.cpp +142 -0
  61. data/src/Input.cpp +459 -0
  62. data/src/InputUIKit.cpp +197 -0
  63. data/src/Inspection.cpp +4 -5
  64. data/src/LargeImageData.cpp +151 -0
  65. data/src/LargeImageData.hpp +43 -0
  66. data/src/{Graphics/Macro.cpp → Macro.cpp} +77 -78
  67. data/src/Macro.hpp +30 -0
  68. data/src/Math.cpp +17 -29
  69. data/src/{Audio/OggFile.hpp → OggFile.hpp} +19 -24
  70. data/src/RenderState.hpp +205 -0
  71. data/src/Resolution.cpp +86 -0
  72. data/src/ResolutionApple.cpp +25 -0
  73. data/{ext/gosu/gosu_wrap.cxx → src/RubyGosu.cxx} +2256 -1707
  74. data/{ext/gosu/gosu_wrap.h → src/RubyGosu.h} +9 -9
  75. data/src/{Audio/SndFile.hpp → SndFile.hpp} +54 -43
  76. data/src/TexChunk.cpp +117 -0
  77. data/src/{Graphics/TexChunk.hpp → TexChunk.hpp} +13 -18
  78. data/src/Text.cpp +371 -0
  79. data/src/TextApple.cpp +209 -0
  80. data/src/TextInput.cpp +278 -0
  81. data/src/TextTTFWin.cpp +251 -0
  82. data/src/{Text/TextUnix.cpp → TextUnix.cpp} +96 -92
  83. data/src/TextWin.cpp +194 -0
  84. data/src/{Graphics/Texture.cpp → Texture.cpp} +35 -38
  85. data/src/{Graphics/Texture.hpp → Texture.hpp} +9 -13
  86. data/src/TimingApple.cpp +11 -7
  87. data/src/TimingUnix.cpp +13 -7
  88. data/src/TimingWin.cpp +6 -1
  89. data/src/{Graphics/Transform.cpp → Transform.cpp} +17 -12
  90. data/src/{Graphics/TransformStack.hpp → TransformStack.hpp} +24 -25
  91. data/src/Utility.cpp +29 -70
  92. data/src/UtilityApple.cpp +52 -0
  93. data/src/UtilityWin.cpp +7 -4
  94. data/src/Version.cpp +22 -0
  95. data/src/WinMain.cpp +30 -33
  96. data/src/WinUtility.cpp +24 -22
  97. data/src/WinUtility.hpp +11 -20
  98. data/src/Window.cpp +142 -112
  99. data/src/WindowUIKit.cpp +155 -0
  100. data/src/stb_image.h +384 -173
  101. data/src/stb_vorbis.c +20 -18
  102. metadata +60 -62
  103. data/Gosu/TR1.hpp +0 -56
  104. data/src/AppleUtility.hpp +0 -66
  105. data/src/Audio/ALChannelManagement.hpp +0 -114
  106. data/src/Audio/Audio.mm +0 -1
  107. data/src/Audio/AudioFile.hpp +0 -53
  108. data/src/Audio/AudioToolboxFile.hpp +0 -207
  109. data/src/Bitmap/Bitmap.cpp +0 -183
  110. data/src/Bitmap/BitmapIO.cpp +0 -176
  111. data/src/DirectoriesApple.mm +0 -71
  112. data/src/Graphics/BlockAllocator.cpp +0 -142
  113. data/src/Graphics/ClipRectStack.hpp +0 -93
  114. data/src/Graphics/DrawOp.hpp +0 -175
  115. data/src/Graphics/DrawOpQueue.hpp +0 -188
  116. data/src/Graphics/Graphics.cpp +0 -478
  117. data/src/Graphics/Image.cpp +0 -193
  118. data/src/Graphics/LargeImageData.cpp +0 -133
  119. data/src/Graphics/LargeImageData.hpp +0 -46
  120. data/src/Graphics/Macro.hpp +0 -36
  121. data/src/Graphics/RenderState.hpp +0 -211
  122. data/src/Graphics/Resolution.cpp +0 -91
  123. data/src/Graphics/ResolutionApple.mm +0 -19
  124. data/src/Graphics/TexChunk.cpp +0 -112
  125. data/src/Input/Input.cpp +0 -463
  126. data/src/Input/InputUIKit.mm +0 -190
  127. data/src/Input/TextInput.cpp +0 -261
  128. data/src/Text/Font.cpp +0 -175
  129. data/src/Text/Text.cpp +0 -391
  130. data/src/Text/TextApple.mm +0 -227
  131. data/src/Text/TextTTFWin.cpp +0 -249
  132. data/src/Text/TextWin.cpp +0 -186
  133. data/src/UIKit/GosuAppDelegate.mm +0 -24
  134. data/src/UIKit/GosuViewController.mm +0 -211
  135. data/src/UtilityApple.mm +0 -63
  136. data/src/WindowUIKit.mm +0 -139
@@ -1,190 +0,0 @@
1
- #include <Gosu/Input.hpp>
2
- #include <Gosu/TextInput.hpp>
3
-
4
- #include "AppleUtility.hpp"
5
- #import <UIKit/UIKit.h>
6
-
7
- struct Gosu::TextInput::Impl {};
8
- Gosu::TextInput::TextInput() {}
9
- Gosu::TextInput::~TextInput() {}
10
- std::wstring Gosu::TextInput::text() const { return L""; }
11
- void Gosu::TextInput::setText(const std::wstring& text) {}
12
- unsigned Gosu::TextInput::caretPos() const { return 0; }
13
- unsigned Gosu::TextInput::selectionStart() const { return 0; }
14
-
15
- struct Gosu::Input::Impl
16
- {
17
- UIView *view;
18
- float mouseX, mouseY;
19
- float factorX, factorY;
20
- float updateInterval;
21
-
22
- NSMutableSet *currentTouchesSet;
23
- std::unique_ptr<Gosu::Touches> currentTouchesVector;
24
-
25
- Touch translateTouch(UITouch *uiTouch)
26
- {
27
- CGPoint point = [uiTouch locationInView:view];
28
-
29
- return (Touch) {
30
- .id = (__bridge void *)uiTouch,
31
- .x = (float) point.x * factorX,
32
- .y = (float) point.y * factorY,
33
- };
34
- }
35
- };
36
-
37
- Gosu::Input::Input(void* view, float updateInterval)
38
- : pimpl(new Impl)
39
- {
40
- pimpl->view = (__bridge UIView *)view;
41
- pimpl->updateInterval = updateInterval;
42
- pimpl->currentTouchesSet = [NSMutableSet new];
43
- pimpl->mouseX = pimpl->mouseY = -1000;
44
- setMouseFactors(1, 1);
45
- }
46
-
47
- Gosu::Input::~Input()
48
- {
49
- }
50
-
51
- void Gosu::Input::feedTouchEvent(int type, void *touches)
52
- {
53
- NSSet *uiTouches = (__bridge NSSet *)touches;
54
-
55
- pimpl->currentTouchesVector.reset();
56
-
57
- std::tr1::function<void (Touch)>* callback = nullptr;
58
-
59
- if (type == 0) {
60
- [pimpl->currentTouchesSet unionSet:uiTouches];
61
- callback = &onTouchBegan;
62
- }
63
- else if (type == 1) {
64
- callback = &onTouchMoved;
65
- }
66
- else if (type == 2) {
67
- [pimpl->currentTouchesSet minusSet:uiTouches];
68
- callback = &onTouchEnded;
69
- }
70
- else if (type == 3) {
71
- [pimpl->currentTouchesSet minusSet:uiTouches];
72
- callback = &onTouchCancelled;
73
- }
74
-
75
- if (callback && *callback) {
76
- for (UITouch *uiTouch in uiTouches) {
77
- (*callback)(pimpl->translateTouch(uiTouch));
78
- }
79
- }
80
- }
81
-
82
- wchar_t Gosu::Input::idToChar(Button btn)
83
- {
84
- return 0;
85
- }
86
-
87
- Gosu::Button Gosu::Input::charToId(wchar_t ch)
88
- {
89
- return noButton;
90
- }
91
-
92
- bool Gosu::Input::down(Button btn)
93
- {
94
- return false;
95
- }
96
-
97
- double Gosu::Input::mouseX() const
98
- {
99
- return pimpl->mouseX;
100
- }
101
-
102
- double Gosu::Input::mouseY() const
103
- {
104
- return pimpl->mouseY;
105
- }
106
-
107
- void Gosu::Input::setMousePosition(double x, double y) {
108
- pimpl->mouseX = x;
109
- pimpl->mouseY = y;
110
- }
111
-
112
- void Gosu::Input::setMouseFactors(double factorX, double factorY, double offsetX, double offsetY) {
113
- pimpl->factorX = factorX;
114
- pimpl->factorY = factorY;
115
-
116
- // TODO - use offset
117
- }
118
-
119
- const Gosu::Touches& Gosu::Input::currentTouches() const
120
- {
121
- if (!pimpl->currentTouchesVector.get()) {
122
- pimpl->currentTouchesVector.reset(new Gosu::Touches);
123
- for (UITouch* uiTouch in pimpl->currentTouchesSet) {
124
- pimpl->currentTouchesVector->push_back(pimpl->translateTouch(uiTouch));
125
- }
126
- }
127
- return *pimpl->currentTouchesVector;
128
- }
129
-
130
- double Gosu::Input::accelerometerX() const
131
- {
132
- return 0;
133
- }
134
-
135
- double Gosu::Input::accelerometerY() const
136
- {
137
- return 0;
138
- }
139
-
140
- double Gosu::Input::accelerometerZ() const
141
- {
142
- return 0;
143
- }
144
-
145
- void Gosu::Input::update()
146
- {
147
- // Check for dead touches and remove from vector if
148
- // necessary
149
-
150
- NSMutableSet *deadTouches = nil;
151
-
152
- for (UITouch *touch in pimpl->currentTouchesSet)
153
- {
154
- UITouchPhase phase = [touch phase];
155
- if (phase == UITouchPhaseBegan ||
156
- phase == UITouchPhaseMoved ||
157
- phase == UITouchPhaseStationary) {
158
- continue;
159
- }
160
-
161
- // Something was deleted, we will need the set.
162
- if (!deadTouches) {
163
- deadTouches = [NSMutableSet new];
164
- }
165
- [deadTouches addObject:touch];
166
- }
167
-
168
- // Has something been deleted?
169
- if (deadTouches)
170
- {
171
- pimpl->currentTouchesVector.reset();
172
- [pimpl->currentTouchesSet minusSet: deadTouches];
173
-
174
- if (onTouchEnded) {
175
- for (UITouch *uiTouch in deadTouches) {
176
- onTouchEnded(pimpl->translateTouch(uiTouch));
177
- }
178
- }
179
- }
180
- }
181
-
182
- Gosu::TextInput* Gosu::Input::textInput() const
183
- {
184
- return 0;
185
- }
186
-
187
- void Gosu::Input::setTextInput(TextInput* input)
188
- {
189
- throw "NYI";
190
- }
@@ -1,261 +0,0 @@
1
- #include <Gosu/TextInput.hpp>
2
- #include <Gosu/Input.hpp>
3
- #include <Gosu/Platform.hpp>
4
- #include <Gosu/Utility.hpp>
5
- #include <SDL.h>
6
- #include <cwctype>
7
-
8
- struct Gosu::TextInput::Impl
9
- {
10
- // These two strings contain UTF-8 data.
11
- // See this Wiki page for an overview of what is going on here:
12
- // http://wiki.libsdl.org/Tutorials/TextInput#CandidateList
13
- std::wstring text, composition;
14
- unsigned caretPos, selectionStart;
15
-
16
- Impl()
17
- : caretPos(0), selectionStart(0)
18
- {
19
- }
20
-
21
- void insertText(const std::wstring& newText)
22
- {
23
- // Stop IME composition.
24
- composition.clear();
25
-
26
- // Delete (overwrite) previous selection.
27
- if (caretPos != selectionStart) {
28
- unsigned min = std::min(caretPos, selectionStart);
29
- unsigned max = std::max(caretPos, selectionStart);
30
- text.erase(text.begin() + min, text.begin() + max);
31
- caretPos = selectionStart = min;
32
- }
33
-
34
- text.insert(text.begin() + caretPos, newText.begin(), newText.end());
35
- caretPos += newText.size();
36
- selectionStart = caretPos;
37
- }
38
-
39
- void moveLeft(bool modifySelection)
40
- {
41
- if (caretPos > 0)
42
- caretPos -= 1;
43
-
44
- if (modifySelection)
45
- selectionStart = caretPos;
46
- }
47
-
48
- void moveRight(bool modifySelection)
49
- {
50
- if (caretPos < text.length())
51
- caretPos += 1;
52
-
53
- if (modifySelection)
54
- selectionStart = caretPos;
55
- }
56
-
57
- void moveWordLeft(bool modifySelection)
58
- {
59
- if (caretPos == text.length())
60
- --caretPos;
61
-
62
- while (caretPos > 0 && std::iswspace(text.at(caretPos - 1)))
63
- --caretPos;
64
-
65
- while (caretPos > 0 && !std::iswspace(text.at(caretPos - 1)))
66
- --caretPos;
67
-
68
- if (modifySelection)
69
- selectionStart = caretPos;
70
- }
71
-
72
- void moveWordRight(bool modifySelection)
73
- {
74
- while (caretPos < text.length() && std::iswspace(text.at(caretPos)))
75
- ++caretPos;
76
-
77
- while (caretPos < text.length() && !std::iswspace(text.at(caretPos)))
78
- ++caretPos;
79
-
80
- if (modifySelection)
81
- selectionStart = caretPos;
82
- }
83
-
84
- void moveToBeginningOfLine(bool modifySelection)
85
- {
86
- caretPos = 0;
87
-
88
- if (modifySelection)
89
- selectionStart = caretPos;
90
- }
91
-
92
- void moveToEndOfLine(bool modifySelection)
93
- {
94
- caretPos = static_cast<unsigned>(text.length());
95
-
96
- if (modifySelection)
97
- selectionStart = caretPos;
98
- }
99
-
100
- void deleteBackward()
101
- {
102
- if (selectionStart != caretPos) {
103
- unsigned min = std::min(caretPos, selectionStart);
104
- unsigned max = std::max(caretPos, selectionStart);
105
- text.erase(text.begin() + min, text.begin() + max);
106
- selectionStart = caretPos = min;
107
- }
108
- else if (caretPos > 0) {
109
- unsigned oldCaret = caretPos;
110
- caretPos -= 1;
111
- text.erase(text.begin() + caretPos, text.begin() + oldCaret);
112
- selectionStart = caretPos;
113
- }
114
- }
115
-
116
- void deleteForward()
117
- {
118
- if (selectionStart != caretPos) {
119
- unsigned min = std::min(caretPos, selectionStart);
120
- unsigned max = std::max(caretPos, selectionStart);
121
- text.erase(text.begin() + min, text.begin() + max);
122
- selectionStart = caretPos = min;
123
- }
124
- else if (caretPos < text.length()) {
125
- unsigned oldCaret = caretPos;
126
- caretPos += 1;
127
- text.erase(text.begin() + oldCaret, text.begin() + caretPos);
128
- selectionStart = caretPos = oldCaret;
129
- }
130
-
131
- }
132
- };
133
-
134
- Gosu::TextInput::TextInput()
135
- : pimpl(new Impl)
136
- {
137
- }
138
-
139
- Gosu::TextInput::~TextInput()
140
- {
141
- }
142
-
143
- std::wstring Gosu::TextInput::text() const
144
- {
145
- std::wstring composedText = pimpl->text;
146
- if (! pimpl->composition.empty()) {
147
- composedText.insert(pimpl->caretPos, pimpl->composition);
148
- }
149
- return composedText;
150
- }
151
-
152
- void Gosu::TextInput::setText(const std::wstring& text)
153
- {
154
- pimpl->text = text;
155
- pimpl->composition.clear();
156
- pimpl->caretPos = pimpl->selectionStart = static_cast<unsigned>(text.length());
157
- }
158
-
159
- unsigned Gosu::TextInput::caretPos() const
160
- {
161
- return static_cast<unsigned>(pimpl->caretPos);
162
- }
163
-
164
- void Gosu::TextInput::setCaretPos(unsigned pos)
165
- {
166
- pimpl->caretPos = pos;
167
- }
168
-
169
- unsigned Gosu::TextInput::selectionStart() const
170
- {
171
- return static_cast<unsigned>(pimpl->selectionStart);
172
- }
173
-
174
- void Gosu::TextInput::setSelectionStart(unsigned pos)
175
- {
176
- pimpl->selectionStart = pos;
177
- }
178
-
179
- bool Gosu::TextInput::feedSDLEvent(void* event)
180
- {
181
- const SDL_Event* e = static_cast<SDL_Event*>(event);
182
-
183
- switch (e->type) {
184
- // Direct text input, and sent after IME composition completes.
185
- case SDL_TEXTINPUT: {
186
- std::wstring textToInsert = utf8ToWstring(e->text.text);
187
- textToInsert = filter(textToInsert);
188
- pimpl->insertText(textToInsert);
189
- return true;
190
- }
191
- // IME composition in progress.
192
- case SDL_TEXTEDITING: {
193
- pimpl->composition = utf8ToWstring(e->edit.text);
194
- return true;
195
- }
196
- // Emulate "standard" Windows/X11 keyboard behavior.
197
- case SDL_KEYDOWN: {
198
- // ...but not if the IME is currently compositing.
199
- if (! pimpl->composition.empty()) {
200
- return false;
201
- }
202
-
203
- #ifdef GOSU_IS_MAC
204
- bool words = (e->key.keysym.mod & (KMOD_LALT | KMOD_RALT));
205
- bool commandDown = (e->key.keysym.mod & (KMOD_LGUI | KMOD_RGUI));
206
- #else
207
- bool words = (e->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL));
208
- #endif
209
- bool shiftDown = (e->key.keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT));
210
- SDL_Keycode key = e->key.keysym.sym;
211
-
212
- switch (key) {
213
- case SDLK_LEFT:
214
- #ifdef GOSU_IS_MAC
215
- if (commandDown)
216
- pimpl->moveToBeginningOfLine(! shiftDown);
217
- else
218
- #endif
219
- if (words)
220
- pimpl->moveWordLeft(! shiftDown);
221
- else
222
- pimpl->moveLeft(! shiftDown);
223
- return true;
224
- case SDLK_RIGHT:
225
- #ifdef GOSU_IS_MAC
226
- if (commandDown)
227
- pimpl->moveToEndOfLine(! shiftDown);
228
- else
229
- #endif
230
- if (words)
231
- pimpl->moveWordRight(! shiftDown);
232
- else
233
- pimpl->moveRight(! shiftDown);
234
- return true;
235
- #ifdef GOSU_IS_MAC
236
- case SDLK_UP:
237
- #endif
238
- case SDLK_HOME:
239
- pimpl->moveToBeginningOfLine(! shiftDown);
240
- return true;
241
- #ifdef GOSU_IS_MAC
242
- case SDLK_DOWN:
243
- #endif
244
- case SDLK_END:
245
- pimpl->moveToEndOfLine(! shiftDown);
246
- return true;
247
- case SDLK_BACKSPACE:
248
- pimpl->deleteBackward();
249
- return true;
250
- case SDLK_DELETE:
251
- pimpl->deleteForward();
252
- return true;
253
- }
254
- break;
255
- }
256
-
257
- // TODO: Handle copy & paste.
258
- }
259
-
260
- return false;
261
- }