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
@@ -0,0 +1,30 @@
1
+ #pragma once
2
+
3
+ #include "GraphicsImpl.hpp"
4
+ #include <Gosu/Fwd.hpp>
5
+ #include <Gosu/ImageData.hpp>
6
+ #include <memory>
7
+
8
+ class Gosu::Macro : public Gosu::ImageData
9
+ {
10
+ struct Impl;
11
+ std::shared_ptr<Impl> pimpl;
12
+
13
+ public:
14
+ Macro(DrawOpQueue& queue, int width, int height);
15
+
16
+ int width() const override;
17
+ int height() const override;
18
+
19
+ void draw(double x1, double y1, Color c1, double x2, double y2, Color c2,
20
+ double x3, double y3, Color c3, double x4, double y4, Color c4, ZPos z,
21
+ AlphaMode mode) const;
22
+
23
+ const Gosu::GLTexInfo* gl_tex_info() const override;
24
+
25
+ Gosu::Bitmap to_bitmap() const override;
26
+
27
+ std::unique_ptr<ImageData> subimage(int x, int y, int width, int height) const override;
28
+
29
+ void insert(const Bitmap& bitmap, int x, int y) override;
30
+ };
@@ -1,5 +1,4 @@
1
1
  #include <Gosu/Math.hpp>
2
- #include <cmath>
3
2
  #include <cstdlib>
4
3
 
5
4
  double Gosu::random(double min, double max)
@@ -8,34 +7,32 @@ double Gosu::random(double min, double max)
8
7
  return rnd / (static_cast<double>(RAND_MAX) + 1) * (max - min) + min;
9
8
  }
10
9
 
11
- double Gosu::offsetX(double angle, double radius)
10
+ double Gosu::offset_x(double angle, double radius)
12
11
  {
13
- return +std::sin(angle / 180 * pi) * radius;
12
+ return +std::sin(angle / 180 * M_PI) * radius;
14
13
  }
15
14
 
16
- double Gosu::offsetY(double angle, double radius)
15
+ double Gosu::offset_y(double angle, double radius)
17
16
  {
18
- return -std::cos(angle / 180 * pi) * radius;
17
+ return -std::cos(angle / 180 * M_PI) * radius;
19
18
  }
20
19
 
21
- double Gosu::angle(double fromX, double fromY, double toX, double toY,
22
- double def)
20
+ double Gosu::angle(double from_x, double from_y, double to_x, double to_y, double def)
23
21
  {
24
- double distX = toX - fromX;
25
- double distY = toY - fromY;
22
+ double dist_x = to_x - from_x;
23
+ double dist_y = to_y - from_y;
26
24
 
27
- if (distX == 0 && distY == 0)
28
- return def;
29
- else
30
- return normalizeAngle(radiansToGosu(std::atan2(distY, distX)));
25
+ if (dist_x == 0 && dist_y == 0) return def;
26
+
27
+ return normalize_angle(radians_to_gosu(std::atan2(dist_y, dist_x)));
31
28
  }
32
29
 
33
- double Gosu::angleDiff(double from, double to)
30
+ double Gosu::angle_diff(double from, double to)
34
31
  {
35
- return Gosu::normalizeAngle(to - from + 180) - 180;
32
+ return Gosu::normalize_angle(to - from + 180) - 180;
36
33
  }
37
34
 
38
- double Gosu::normalizeAngle(double angle)
35
+ double Gosu::normalize_angle(double angle)
39
36
  {
40
37
  return wrap(angle, 0.0, 360.0);
41
38
  }
@@ -43,31 +40,22 @@ double Gosu::normalizeAngle(double angle)
43
40
  int Gosu::wrap(int value, int min, int max)
44
41
  {
45
42
  int result = (value - min) % (max - min);
46
- if (result < 0)
47
- return result + max;
48
- else
49
- return result + min;
43
+ return result < 0 ? result + max : result + min;
50
44
  }
51
45
 
52
46
  float Gosu::wrap(float value, float min, float max)
53
47
  {
54
48
  double result = std::fmod(value - min, max - min);
55
- if (result < 0)
56
- return result + max;
57
- else
58
- return result + min;
49
+ return result < 0 ? result + max : result + min;
59
50
  }
60
51
 
61
52
  double Gosu::wrap(double value, double min, double max)
62
53
  {
63
54
  double result = std::fmod(value - min, max - min);
64
- if (result < 0)
65
- return result + max;
66
- else
67
- return result + min;
55
+ return result < 0 ? result + max : result + min;
68
56
  }
69
57
 
70
58
  double Gosu::distance(double x1, double y1, double x2, double y2)
71
59
  {
72
- return std::sqrt(distanceSqr(x1, y1, x2, y2));
60
+ return std::sqrt(distance_sqr(x1, y1, x2, y2));
73
61
  }
@@ -1,14 +1,13 @@
1
- #ifndef GOSU_SRC_AUDIO_OGGFILE_HPP
2
- #define GOSU_SRC_AUDIO_OGGFILE_HPP
1
+ #pragma once
3
2
 
4
3
  #include "AudioFile.hpp"
5
4
  #include <Gosu/IO.hpp>
6
5
  #include <algorithm>
7
6
  #include <stdexcept>
8
- #include <sstream>
7
+ #include <string>
9
8
 
10
9
  #define STB_VORBIS_HEADER_ONLY
11
- #include "../stb_vorbis.c"
10
+ #include "stb_vorbis.c"
12
11
 
13
12
  // Based on the Drama Sound Engine for D
14
13
 
@@ -19,26 +18,24 @@ namespace Gosu
19
18
  Gosu::Buffer contents_;
20
19
  Gosu::Buffer buffer_;
21
20
  int channels_;
22
- ALenum sampleRate_;
21
+ ALenum sample_rate_;
23
22
  stb_vorbis* stream_;
24
23
 
25
24
  void open()
26
25
  {
27
26
  int error = 0;
28
27
 
29
- const unsigned char *mem = static_cast<const unsigned char*>(contents_.data());
28
+ const unsigned char* mem = static_cast<const unsigned char*>(contents_.data());
30
29
  stream_ = stb_vorbis_open_memory(mem, contents_.size(), &error, 0);
31
30
 
32
- if (stream_ == 0)
33
- {
34
- std::ostringstream message;
35
- message << "Cannot open Ogg Vorbis file, error code: " << error;
36
- throw std::runtime_error(message.str());
31
+ if (stream_ == 0) {
32
+ throw std::runtime_error("Cannot open Ogg Vorbis file, error code: " +
33
+ std::to_string(error));
37
34
  }
38
35
 
39
36
  stb_vorbis_info info = stb_vorbis_get_info(stream_);
40
37
  channels_ = info.channels;
41
- sampleRate_ = info.sample_rate;
38
+ sample_rate_ = info.sample_rate;
42
39
  buffer_.resize(info.temp_memory_required);
43
40
  }
44
41
 
@@ -67,25 +64,25 @@ namespace Gosu
67
64
  return (channels_ == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16);
68
65
  }
69
66
 
70
- ALuint sampleRate() const
67
+ ALuint sample_rate() const
71
68
  {
72
- return sampleRate_;
69
+ return sample_rate_;
73
70
  }
74
71
 
75
- std::size_t readData(void* dest, std::size_t length)
72
+ std::size_t read_data(void* dest, std::size_t length)
76
73
  {
77
74
  int samples = 0;
78
- int maxSamples = length / sizeof(short);
75
+ int max_samples = length / sizeof(short);
79
76
 
80
- while (samples < maxSamples) {
81
- int samplesPerChannel =
77
+ while (samples < max_samples) {
78
+ int samples_per_channel =
82
79
  stb_vorbis_get_samples_short_interleaved(stream_, channels_,
83
- static_cast<short*>(dest) + samples, maxSamples - samples);
80
+ static_cast<short*>(dest) + samples,
81
+ max_samples - samples);
84
82
 
85
- if (samplesPerChannel == 0)
86
- break;
83
+ if (samples_per_channel == 0) break;
87
84
 
88
- samples += samplesPerChannel * channels_;
85
+ samples += samples_per_channel * channels_;
89
86
  }
90
87
 
91
88
  return samples * sizeof(short);
@@ -97,5 +94,3 @@ namespace Gosu
97
94
  }
98
95
  };
99
96
  }
100
-
101
- #endif
@@ -0,0 +1,205 @@
1
+ #pragma once
2
+
3
+ #include "GraphicsImpl.hpp"
4
+ #include "Texture.hpp"
5
+
6
+ // Properties that potentially need to be changed between each draw operation.
7
+ // This does not include the color or vertex data of the actual quads.
8
+ struct Gosu::RenderState
9
+ {
10
+ std::shared_ptr<Texture> texture;
11
+ const Transform* transform;
12
+ ClipRect clip_rect;
13
+ AlphaMode mode;
14
+
15
+ RenderState()
16
+ : transform(0), mode(AM_DEFAULT)
17
+ {
18
+ clip_rect.width = NO_CLIPPING;
19
+ }
20
+
21
+ bool operator==(const RenderState& rhs) const
22
+ {
23
+ return texture == rhs.texture &&
24
+ transform == rhs.transform &&
25
+ clip_rect == rhs.clip_rect &&
26
+ mode == rhs.mode;
27
+ }
28
+
29
+ void apply_texture() const
30
+ {
31
+ if (texture) {
32
+ glEnable(GL_TEXTURE_2D);
33
+ glBindTexture(GL_TEXTURE_2D, texture->tex_name());
34
+ }
35
+ else {
36
+ glDisable(GL_TEXTURE_2D);
37
+ }
38
+ }
39
+
40
+ void apply_alpha_mode() const
41
+ {
42
+ if (mode == AM_ADD) {
43
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
44
+ }
45
+ else if (mode == AM_MULTIPLY) {
46
+ glBlendFunc(GL_DST_COLOR, GL_ZERO);
47
+ }
48
+ else {
49
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
50
+ }
51
+ }
52
+
53
+ void apply_clip_rect() const
54
+ {
55
+ if (clip_rect.width == NO_CLIPPING) {
56
+ glDisable(GL_SCISSOR_TEST);
57
+ }
58
+ else {
59
+ glEnable(GL_SCISSOR_TEST);
60
+ glScissor(clip_rect.x, clip_rect.y, clip_rect.width, clip_rect.height);
61
+ }
62
+ }
63
+
64
+ // Only used by Macro so far
65
+ #ifndef GOSU_IS_OPENGLES
66
+ void apply() const
67
+ {
68
+ apply_texture();
69
+ // TODO: No inner clip_rect yet - how would this work?!
70
+ apply_alpha_mode();
71
+ }
72
+ #endif
73
+ };
74
+
75
+ // Manages the OpenGL rendering state. It caches the current state, only forwarding the
76
+ // changes to OpenGL if the new state is really different.
77
+ class Gosu::RenderStateManager : private Gosu::RenderState
78
+ {
79
+ // Not copyable
80
+ RenderStateManager(const RenderStateManager&);
81
+ RenderStateManager& operator=(const RenderStateManager&);
82
+
83
+ void apply_transform() const
84
+ {
85
+ glMatrixMode(GL_MODELVIEW);
86
+ glLoadIdentity();
87
+
88
+ #ifndef GOSU_IS_OPENGLES
89
+ glMultMatrixd(&(*transform)[0]);
90
+ #else
91
+ // TODO: Ouch, should always use floats!
92
+ GLfloat matrix[16];
93
+ for (int i = 0; i < 16; ++i) {
94
+ matrix[i] = (*transform)[i];
95
+ }
96
+ glMultMatrixf(matrix);
97
+ #endif
98
+ }
99
+
100
+ public:
101
+ RenderStateManager()
102
+ {
103
+ apply_alpha_mode();
104
+ // Preserve previous MV matrix
105
+ glMatrixMode(GL_MODELVIEW);
106
+ glPushMatrix();
107
+ }
108
+
109
+ ~RenderStateManager()
110
+ {
111
+ ClipRect no_clipping;
112
+ no_clipping.width = NO_CLIPPING;
113
+ set_clip_rect(no_clipping);
114
+ set_texture(std::shared_ptr<Texture>());
115
+ // Return to previous MV matrix
116
+ glMatrixMode(GL_MODELVIEW);
117
+ glPopMatrix();
118
+ }
119
+
120
+ void set_render_state(const RenderState& rs)
121
+ {
122
+ set_texture(rs.texture);
123
+ set_transform(rs.transform);
124
+ set_clip_rect(rs.clip_rect);
125
+ set_alpha_mode(rs.mode);
126
+ }
127
+
128
+ void set_texture(std::shared_ptr<Texture> new_texture)
129
+ {
130
+ if (new_texture == texture) return;
131
+
132
+ if (new_texture) {
133
+ // New texture *is* really a texture - change to it.
134
+
135
+ if (!texture) {
136
+ glEnable(GL_TEXTURE_2D);
137
+ }
138
+ glBindTexture(GL_TEXTURE_2D, new_texture->tex_name());
139
+ }
140
+ else {
141
+ // New texture is NO_TEXTURE, disable texturing.
142
+ glDisable(GL_TEXTURE_2D);
143
+ }
144
+ texture = new_texture;
145
+ }
146
+
147
+ void set_transform(const Transform* new_transform)
148
+ {
149
+ if (new_transform == transform) return;
150
+
151
+ transform = new_transform;
152
+ apply_transform();
153
+ }
154
+
155
+ void set_clip_rect(const ClipRect& new_clip_rect)
156
+ {
157
+ if (new_clip_rect.width == NO_CLIPPING) {
158
+ // Disable clipping
159
+ if (clip_rect.width != NO_CLIPPING) {
160
+ glDisable(GL_SCISSOR_TEST);
161
+ clip_rect.width = NO_CLIPPING;
162
+ }
163
+ }
164
+ else {
165
+ // Enable clipping if off
166
+ if (clip_rect.width == NO_CLIPPING) {
167
+ glEnable(GL_SCISSOR_TEST);
168
+ clip_rect = new_clip_rect;
169
+ glScissor(clip_rect.x, clip_rect.y, clip_rect.width, clip_rect.height);
170
+ }
171
+ // Adjust clipping if necessary
172
+ else if (!(clip_rect == new_clip_rect)) {
173
+ clip_rect = new_clip_rect;
174
+ glScissor(clip_rect.x, clip_rect.y, clip_rect.width, clip_rect.height);
175
+ }
176
+ }
177
+ }
178
+
179
+ void set_alpha_mode(AlphaMode new_mode)
180
+ {
181
+ if (new_mode == mode) return;
182
+
183
+ mode = new_mode;
184
+ apply_alpha_mode();
185
+ }
186
+
187
+ // The cached values may have been messed with. Reset them again.
188
+ void enforce_after_untrusted_gL() const
189
+ {
190
+ apply_texture();
191
+ apply_transform();
192
+ apply_clip_rect();
193
+ apply_alpha_mode();
194
+ }
195
+ };
196
+
197
+ namespace Gosu
198
+ {
199
+ struct VertexArray
200
+ {
201
+ RenderState render_state;
202
+ std::vector<ArrayVertex> vertices;
203
+ };
204
+ typedef std::list<VertexArray> VertexArrays;
205
+ }
@@ -0,0 +1,86 @@
1
+ #include <Gosu/Gosu.hpp>
2
+
3
+ #ifdef GOSU_IS_WIN
4
+ #include <windows.h>
5
+
6
+ // On Windows, do not use the SDL 2 code below. It reports 2560x1920 in my Windows VM, which is
7
+ // running at 2560x1080. (SDL 2.0.3)
8
+
9
+ unsigned Gosu::screen_width()
10
+ {
11
+ return GetSystemMetrics(SM_CXSCREEN);
12
+ }
13
+
14
+ unsigned Gosu::screen_height()
15
+ {
16
+ return GetSystemMetrics(SM_CYSCREEN);
17
+ }
18
+
19
+ static SIZE calculate_available_size()
20
+ {
21
+ RECT work_area;
22
+ SystemParametersInfo(SPI_GETWORKAREA, 0, &work_area, 0);
23
+
24
+ RECT window_size = work_area;
25
+ // Note: This should be kept in sync with STYLE_NORMAL in SDL_windowswindow.c.
26
+ DWORD style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
27
+ AdjustWindowRectEx(&window_size, style, FALSE, 0);
28
+
29
+ SIZE size;
30
+ size.cx = 2 * (work_area.right - work_area.left) - (window_size.right - window_size.left);
31
+ size.cy = 2 * (work_area.bottom - work_area.top) - (window_size.bottom - window_size.top);
32
+ return size;
33
+ }
34
+
35
+ static SIZE available_size = calculate_available_size();
36
+
37
+ unsigned Gosu::available_width()
38
+ {
39
+ return available_size.cx;
40
+ }
41
+
42
+ unsigned Gosu::available_height()
43
+ {
44
+ return available_size.cy;
45
+ }
46
+ #elif !defined(GOSU_IS_IPHONE)
47
+ #include <SDL.h>
48
+
49
+ static SDL_DisplayMode current_display_mode = { 0, 0 };
50
+
51
+ unsigned Gosu::screen_width()
52
+ {
53
+ // TODO - not thread-safe
54
+ if (current_display_mode.w == 0) {
55
+ SDL_Init(SDL_INIT_VIDEO);
56
+ SDL_GetDisplayMode(0, 0, &current_display_mode);
57
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
58
+ }
59
+ return current_display_mode.w;
60
+ }
61
+
62
+ unsigned Gosu::screen_height()
63
+ {
64
+ // TODO - not thread-safe
65
+ if (current_display_mode.h == 0) {
66
+ SDL_Init(SDL_INIT_VIDEO);
67
+ SDL_GetDisplayMode(0, 0, &current_display_mode);
68
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
69
+ }
70
+ return current_display_mode.h;
71
+ }
72
+
73
+ // Pessimistic fallback implementation for available_width / available_height.
74
+
75
+ #if !defined(GOSU_IS_MAC)
76
+ unsigned Gosu::available_width()
77
+ {
78
+ return Gosu::screen_width() * 0.9;
79
+ }
80
+
81
+ unsigned Gosu::available_height()
82
+ {
83
+ return Gosu::screen_height() * 0.8;
84
+ }
85
+ #endif
86
+ #endif