gosu 0.13.3 → 0.14.0.pre2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/Gosu/Audio.hpp +15 -11
  3. data/Gosu/Font.hpp +24 -20
  4. data/Gosu/Fwd.hpp +1 -1
  5. data/Gosu/Graphics.hpp +8 -9
  6. data/Gosu/ImageData.hpp +1 -1
  7. data/Gosu/Input.hpp +1 -1
  8. data/Gosu/Math.hpp +0 -18
  9. data/Gosu/Text.hpp +22 -30
  10. data/Gosu/TextInput.hpp +13 -0
  11. data/Gosu/Utility.hpp +2 -0
  12. data/Gosu/Window.hpp +3 -3
  13. data/README.md +3 -4
  14. data/ext/gosu/extconf.rb +7 -9
  15. data/lib/gosu/swig_patches.rb +1 -4
  16. data/rdoc/gosu.rb +34 -9
  17. data/src/Audio.cpp +6 -6
  18. data/src/AudioImpl.cpp +2 -2
  19. data/src/Bitmap.cpp +1 -2
  20. data/src/BitmapIO.cpp +21 -2
  21. data/src/BlockAllocator.cpp +1 -1
  22. data/src/Channel.cpp +7 -1
  23. data/src/ClipRectStack.hpp +4 -1
  24. data/src/Color.cpp +2 -1
  25. data/src/DirectoriesWin.cpp +1 -1
  26. data/src/DrawOp.hpp +8 -4
  27. data/src/DrawOpQueue.hpp +13 -24
  28. data/src/FileUnix.cpp +3 -1
  29. data/src/Font.cpp +92 -96
  30. data/src/GosuGLView.cpp +59 -31
  31. data/src/GosuGLView.hpp +14 -0
  32. data/src/GosuViewController.cpp +21 -21
  33. data/src/{GosuViewController.h → GosuViewController.hpp} +2 -4
  34. data/src/Graphics.cpp +71 -38
  35. data/src/GraphicsImpl.hpp +12 -29
  36. data/src/Image.cpp +5 -7
  37. data/src/Input.cpp +7 -5
  38. data/src/InputUIKit.cpp +19 -37
  39. data/src/Macro.cpp +10 -2
  40. data/src/MarkupParser.cpp +241 -0
  41. data/src/MarkupParser.hpp +61 -0
  42. data/src/Math.cpp +1 -1
  43. data/src/OffScreenTarget.cpp +99 -0
  44. data/src/OffScreenTarget.hpp +23 -0
  45. data/src/OggFile.hpp +10 -0
  46. data/src/RenderState.hpp +0 -2
  47. data/src/Resolution.cpp +2 -2
  48. data/src/RubyGosu.cxx +457 -244
  49. data/src/TexChunk.cpp +8 -6
  50. data/src/Text.cpp +58 -345
  51. data/src/TextBuilder.cpp +138 -0
  52. data/src/TextBuilder.hpp +55 -0
  53. data/src/TextInput.cpp +27 -10
  54. data/src/Texture.cpp +22 -17
  55. data/src/Texture.hpp +19 -20
  56. data/src/TimingApple.cpp +5 -7
  57. data/src/TimingUnix.cpp +1 -4
  58. data/src/TimingWin.cpp +4 -1
  59. data/src/TrueTypeFont.cpp +282 -0
  60. data/src/TrueTypeFont.hpp +66 -0
  61. data/src/TrueTypeFontApple.cpp +65 -0
  62. data/src/TrueTypeFontUnix.cpp +91 -0
  63. data/src/TrueTypeFontWin.cpp +82 -0
  64. data/src/Utility.cpp +40 -0
  65. data/src/Window.cpp +7 -6
  66. data/src/WindowUIKit.cpp +9 -4
  67. data/src/stb_truetype.h +4589 -0
  68. data/src/utf8proc.c +755 -0
  69. data/src/utf8proc.h +699 -0
  70. data/src/utf8proc_data.h +14386 -0
  71. metadata +23 -16
  72. data/src/FormattedString.cpp +0 -237
  73. data/src/FormattedString.hpp +0 -47
  74. data/src/GosuAppDelegate.cpp +0 -30
  75. data/src/GosuAppDelegate.h +0 -8
  76. data/src/GosuGLView.h +0 -8
  77. data/src/TextApple.cpp +0 -212
  78. data/src/TextTTFWin.cpp +0 -197
  79. data/src/TextUnix.cpp +0 -280
  80. data/src/TextWin.cpp +0 -191
@@ -1,191 +0,0 @@
1
- #include <Gosu/Platform.hpp>
2
- #if defined(GOSU_IS_WIN)
3
-
4
- #define _WIN32_WINNT 0x0500
5
- #include <windows.h>
6
-
7
- #include "WinUtility.hpp"
8
- #include <Gosu/Bitmap.hpp>
9
- #include <Gosu/Text.hpp>
10
- #include <Gosu/Utility.hpp>
11
- #include <cstdlib>
12
- #include <cwchar>
13
- #include <algorithm>
14
- #include <map>
15
- #include <set>
16
- #include <stdexcept>
17
- using namespace std;
18
-
19
- string Gosu::default_font_name()
20
- {
21
- return "Arial";
22
- }
23
-
24
- namespace Gosu
25
- {
26
- string get_name_from_ttf_file(const string& filename);
27
-
28
- namespace
29
- {
30
- class WinBitmap
31
- {
32
- WinBitmap(const WinBitmap&);
33
- WinBitmap& operator=(const WinBitmap&);
34
-
35
- HDC dc;
36
- HBITMAP bitmap;
37
- char* pixels;
38
-
39
- public:
40
- WinBitmap(unsigned width, unsigned height)
41
- {
42
- dc = winapi_check(CreateCompatibleDC(0), "creating a device context");
43
-
44
- BITMAPCOREHEADER core_header;
45
- core_header.bcSize = sizeof core_header;
46
- core_header.bcWidth = width;
47
- core_header.bcHeight = height;
48
- core_header.bcPlanes = 1;
49
- core_header.bcBitCount = 24;
50
-
51
- bitmap = CreateDIBSection(dc, reinterpret_cast<BITMAPINFO*>(&core_header),
52
- DIB_RGB_COLORS, reinterpret_cast<VOID**>(&pixels), 0, 0);
53
- if (bitmap == 0) {
54
- DeleteDC(dc);
55
- throw_last_winapi_error("creating a bitmap");
56
- }
57
-
58
- SelectObject(dc, bitmap);
59
-
60
- HBRUSH brush = CreateSolidBrush(0x000000);
61
- RECT rc = { 0, 0, width, height };
62
- FillRect(dc, &rc, brush);
63
- DeleteObject(brush);
64
- }
65
-
66
- ~WinBitmap()
67
- {
68
- DeleteObject(bitmap);
69
- SelectObject(dc, GetStockObject(SYSTEM_FONT));
70
- DeleteDC(dc);
71
- }
72
-
73
- HDC context() const
74
- {
75
- return dc;
76
- }
77
-
78
- HBITMAP handle() const
79
- {
80
- return bitmap;
81
- }
82
-
83
- void select_font(string font_name, unsigned font_height, unsigned font_flags) const
84
- {
85
- // TODO for ASYNC support:
86
- // Use a lock on both maps.
87
-
88
- // Note:
89
- // The caching of opened fonts didn't really show improved text rendering
90
- // performance on my test system.
91
- // In case of trouble, it can be taken out without worrying too much.
92
-
93
- static map<string, string> custom_fonts;
94
-
95
- if (font_name.find("/") != font_name.npos) {
96
- if (custom_fonts.count(font_name) == 0) {
97
- AddFontResourceExW(utf8_to_wstring(font_name).c_str(), FR_PRIVATE, 0);
98
- font_name = custom_fonts[font_name] = get_name_from_ttf_file(font_name);
99
- }
100
- else {
101
- font_name = custom_fonts[font_name];
102
- }
103
- }
104
-
105
- static map<pair<string, unsigned>, HFONT> loaded_fonts;
106
-
107
- HFONT font;
108
- pair<string, unsigned> key = make_pair(font_name, font_height | font_flags << 16);
109
-
110
- if (loaded_fonts.count(key) == 0) {
111
- LOGFONT logfont = {
112
- font_height, 0, 0, 0,
113
- font_flags & FF_BOLD ? FW_BOLD : FW_NORMAL,
114
- font_flags & FF_ITALIC ? TRUE : FALSE,
115
- font_flags & FF_UNDERLINE ? TRUE : FALSE, FALSE, DEFAULT_CHARSET,
116
- OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
117
- DEFAULT_PITCH | FF_DONTCARE
118
- };
119
-
120
- wstring wfont_name = utf8_to_wstring(font_name);
121
- wcsncpy(logfont.lfFaceName, wfont_name.c_str(), LF_FACESIZE);
122
- logfont.lfFaceName[LF_FACESIZE - 1] = 0;
123
-
124
- font = loaded_fonts[key] = winapi_check(CreateFontIndirect(&logfont),
125
- "CreateFontIndirect for " + font_name);
126
- }
127
- else {
128
- font = loaded_fonts[key];
129
- }
130
-
131
- SelectObject(dc, font);
132
- }
133
- };
134
- }
135
- };
136
-
137
- unsigned Gosu::text_width(const string& text, const string& font_name,
138
- unsigned font_height, unsigned font_flags)
139
- {
140
- if (text.find_first_of("\r\n") != text.npos) {
141
- throw invalid_argument("the argument to text_width cannot contain line breaks");
142
- }
143
-
144
- WinBitmap helper(1, 1);
145
- helper.select_font(font_name, font_height, font_flags);
146
-
147
- wstring wtext = utf8_to_wstring(text);
148
- SIZE size;
149
- winapi_check(GetTextExtentPoint32W(helper.context(), wtext.c_str(), wtext.length(), &size),
150
- "calculating the width of a text");
151
-
152
- return size.cx;
153
- }
154
-
155
- void Gosu::draw_text(Bitmap& bitmap, const string& text, int x, int y, Color c,
156
- const string& font_name, unsigned font_height, unsigned font_flags)
157
- {
158
- if (text.find_first_of("\r\n") != text.npos) {
159
- throw invalid_argument("the argument to draw_text cannot contain line breaks");
160
- }
161
-
162
- unsigned width = text_width(text, font_name, font_height, font_flags);
163
-
164
- WinBitmap helper(width, font_height);
165
- helper.select_font(font_name, font_height, font_flags);
166
-
167
- winapi_check(SetTextColor(helper.context(), 0xffffff) != CLR_INVALID,
168
- "setting the text color");
169
-
170
- winapi_check(SetBkMode(helper.context(), TRANSPARENT),
171
- "setting a bitmap's background mode to TRANSPARENT");
172
-
173
- wstring wtext = utf8_to_wstring(text);
174
- ExtTextOutW(helper.context(), 0, 0, 0, 0, wtext.c_str(), wtext.length(), 0);
175
-
176
- for (unsigned rel_y = 0; rel_y < font_height; ++rel_y)
177
- for (unsigned rel_x = 0; rel_x < width; ++rel_x) {
178
- Color pixel = c;
179
- Color::Channel src_alpha = GetPixel(helper.context(), rel_x, rel_y) & 0xff;
180
-
181
- if (src_alpha == 0) continue;
182
-
183
- pixel = multiply(c, Color(src_alpha, 255, 255, 255));
184
- if (pixel != 0 && x + rel_x >= 0 && x + rel_x < bitmap.width() &&
185
- y + rel_y >= 0 && y + rel_y < bitmap.height()) {
186
- bitmap.set_pixel(x + rel_x, y + rel_y, pixel);
187
- }
188
- }
189
- }
190
-
191
- #endif