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.
- checksums.yaml +4 -4
- data/Gosu/Audio.hpp +35 -66
- data/Gosu/AutoLink.hpp +14 -16
- data/Gosu/Bitmap.hpp +50 -37
- data/Gosu/Buttons.hpp +246 -265
- data/Gosu/Color.hpp +32 -76
- data/Gosu/Directories.hpp +14 -17
- data/Gosu/Font.hpp +28 -34
- data/Gosu/Fwd.hpp +27 -31
- data/Gosu/Gosu.hpp +2 -5
- data/Gosu/Graphics.hpp +31 -48
- data/Gosu/GraphicsBase.hpp +27 -58
- data/Gosu/IO.hpp +44 -56
- data/Gosu/Image.hpp +29 -73
- data/Gosu/ImageData.hpp +13 -17
- data/Gosu/Input.hpp +42 -57
- data/Gosu/Inspection.hpp +2 -6
- data/Gosu/Math.hpp +32 -38
- data/Gosu/Platform.hpp +10 -29
- data/Gosu/Text.hpp +30 -39
- data/Gosu/TextInput.hpp +29 -36
- data/Gosu/Timing.hpp +14 -16
- data/Gosu/Utility.hpp +10 -15
- data/Gosu/Version.hpp +13 -14
- data/Gosu/Window.hpp +53 -68
- data/README.md +23 -11
- data/ext/gosu/extconf.rb +31 -81
- data/lib/gosu/patches.rb +35 -19
- data/lib/gosu/run.rb +13 -4
- data/rdoc/gosu.rb +24 -20
- data/src/ALChannelManagement.hpp +119 -0
- data/src/{Audio/Audio.cpp → Audio.cpp} +177 -211
- data/src/AudioFile.hpp +57 -0
- data/src/AudioToolboxFile.hpp +214 -0
- data/src/Bitmap.cpp +159 -0
- data/src/BitmapIO.cpp +141 -0
- data/src/BlockAllocator.cpp +133 -0
- data/src/{Graphics/BlockAllocator.hpp → BlockAllocator.hpp} +34 -35
- data/src/ClipRectStack.hpp +87 -0
- data/src/{Graphics/Color.cpp → Color.cpp} +30 -28
- data/src/DirectoriesApple.cpp +68 -0
- data/src/DirectoriesUnix.cpp +20 -18
- data/src/DirectoriesWin.cpp +40 -41
- data/src/DrawOp.hpp +168 -0
- data/src/DrawOpQueue.hpp +190 -0
- data/src/FileUnix.cpp +40 -46
- data/src/FileWin.cpp +42 -38
- data/src/Font.cpp +165 -0
- data/src/{Text/FormattedString.hpp → FormattedString.hpp} +114 -114
- data/src/GosuAppDelegate.cpp +30 -0
- data/src/{UIKit/GosuAppDelegate.h → GosuAppDelegate.h} +0 -0
- data/src/{UIKit/GosuGLView.mm → GosuGLView.cpp} +22 -17
- data/src/{UIKit/GosuGLView.h → GosuGLView.h} +0 -0
- data/src/GosuViewController.cpp +231 -0
- data/src/{UIKit/GosuViewController.h → GosuViewController.h} +0 -0
- data/src/Graphics.cpp +464 -0
- data/src/{Graphics/Common.hpp → GraphicsImpl.hpp} +29 -32
- data/src/IO.cpp +17 -16
- data/src/Iconv.hpp +13 -22
- data/src/Image.cpp +142 -0
- data/src/Input.cpp +459 -0
- data/src/InputUIKit.cpp +197 -0
- data/src/Inspection.cpp +4 -5
- data/src/LargeImageData.cpp +151 -0
- data/src/LargeImageData.hpp +43 -0
- data/src/{Graphics/Macro.cpp → Macro.cpp} +77 -78
- data/src/Macro.hpp +30 -0
- data/src/Math.cpp +17 -29
- data/src/{Audio/OggFile.hpp → OggFile.hpp} +19 -24
- data/src/RenderState.hpp +205 -0
- data/src/Resolution.cpp +86 -0
- data/src/ResolutionApple.cpp +25 -0
- data/{ext/gosu/gosu_wrap.cxx → src/RubyGosu.cxx} +2256 -1707
- data/{ext/gosu/gosu_wrap.h → src/RubyGosu.h} +9 -9
- data/src/{Audio/SndFile.hpp → SndFile.hpp} +54 -43
- data/src/TexChunk.cpp +117 -0
- data/src/{Graphics/TexChunk.hpp → TexChunk.hpp} +13 -18
- data/src/Text.cpp +371 -0
- data/src/TextApple.cpp +209 -0
- data/src/TextInput.cpp +278 -0
- data/src/TextTTFWin.cpp +251 -0
- data/src/{Text/TextUnix.cpp → TextUnix.cpp} +96 -92
- data/src/TextWin.cpp +194 -0
- data/src/{Graphics/Texture.cpp → Texture.cpp} +35 -38
- data/src/{Graphics/Texture.hpp → Texture.hpp} +9 -13
- data/src/TimingApple.cpp +11 -7
- data/src/TimingUnix.cpp +13 -7
- data/src/TimingWin.cpp +6 -1
- data/src/{Graphics/Transform.cpp → Transform.cpp} +17 -12
- data/src/{Graphics/TransformStack.hpp → TransformStack.hpp} +24 -25
- data/src/Utility.cpp +29 -70
- data/src/UtilityApple.cpp +52 -0
- data/src/UtilityWin.cpp +7 -4
- data/src/Version.cpp +22 -0
- data/src/WinMain.cpp +30 -33
- data/src/WinUtility.cpp +24 -22
- data/src/WinUtility.hpp +11 -20
- data/src/Window.cpp +142 -112
- data/src/WindowUIKit.cpp +155 -0
- data/src/stb_image.h +384 -173
- data/src/stb_vorbis.c +20 -18
- metadata +60 -62
- data/Gosu/TR1.hpp +0 -56
- data/src/AppleUtility.hpp +0 -66
- data/src/Audio/ALChannelManagement.hpp +0 -114
- data/src/Audio/Audio.mm +0 -1
- data/src/Audio/AudioFile.hpp +0 -53
- data/src/Audio/AudioToolboxFile.hpp +0 -207
- data/src/Bitmap/Bitmap.cpp +0 -183
- data/src/Bitmap/BitmapIO.cpp +0 -176
- data/src/DirectoriesApple.mm +0 -71
- data/src/Graphics/BlockAllocator.cpp +0 -142
- data/src/Graphics/ClipRectStack.hpp +0 -93
- data/src/Graphics/DrawOp.hpp +0 -175
- data/src/Graphics/DrawOpQueue.hpp +0 -188
- data/src/Graphics/Graphics.cpp +0 -478
- data/src/Graphics/Image.cpp +0 -193
- data/src/Graphics/LargeImageData.cpp +0 -133
- data/src/Graphics/LargeImageData.hpp +0 -46
- data/src/Graphics/Macro.hpp +0 -36
- data/src/Graphics/RenderState.hpp +0 -211
- data/src/Graphics/Resolution.cpp +0 -91
- data/src/Graphics/ResolutionApple.mm +0 -19
- data/src/Graphics/TexChunk.cpp +0 -112
- data/src/Input/Input.cpp +0 -463
- data/src/Input/InputUIKit.mm +0 -190
- data/src/Input/TextInput.cpp +0 -261
- data/src/Text/Font.cpp +0 -175
- data/src/Text/Text.cpp +0 -391
- data/src/Text/TextApple.mm +0 -227
- data/src/Text/TextTTFWin.cpp +0 -249
- data/src/Text/TextWin.cpp +0 -186
- data/src/UIKit/GosuAppDelegate.mm +0 -24
- data/src/UIKit/GosuViewController.mm +0 -211
- data/src/UtilityApple.mm +0 -63
- data/src/WindowUIKit.mm +0 -139
data/src/Macro.hpp
ADDED
@@ -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
|
+
};
|
data/src/Math.cpp
CHANGED
@@ -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::
|
10
|
+
double Gosu::offset_x(double angle, double radius)
|
12
11
|
{
|
13
|
-
return +std::sin(angle / 180 *
|
12
|
+
return +std::sin(angle / 180 * M_PI) * radius;
|
14
13
|
}
|
15
14
|
|
16
|
-
double Gosu::
|
15
|
+
double Gosu::offset_y(double angle, double radius)
|
17
16
|
{
|
18
|
-
return -std::cos(angle / 180 *
|
17
|
+
return -std::cos(angle / 180 * M_PI) * radius;
|
19
18
|
}
|
20
19
|
|
21
|
-
double Gosu::angle(double
|
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
|
25
|
-
double
|
22
|
+
double dist_x = to_x - from_x;
|
23
|
+
double dist_y = to_y - from_y;
|
26
24
|
|
27
|
-
if (
|
28
|
-
|
29
|
-
|
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::
|
30
|
+
double Gosu::angle_diff(double from, double to)
|
34
31
|
{
|
35
|
-
return Gosu::
|
32
|
+
return Gosu::normalize_angle(to - from + 180) - 180;
|
36
33
|
}
|
37
34
|
|
38
|
-
double Gosu::
|
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
|
-
|
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
|
-
|
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
|
-
|
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(
|
60
|
+
return std::sqrt(distance_sqr(x1, y1, x2, y2));
|
73
61
|
}
|
@@ -1,14 +1,13 @@
|
|
1
|
-
#
|
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 <
|
7
|
+
#include <string>
|
9
8
|
|
10
9
|
#define STB_VORBIS_HEADER_ONLY
|
11
|
-
#include "
|
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
|
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
|
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
|
-
|
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
|
-
|
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
|
67
|
+
ALuint sample_rate() const
|
71
68
|
{
|
72
|
-
return
|
69
|
+
return sample_rate_;
|
73
70
|
}
|
74
71
|
|
75
|
-
std::size_t
|
72
|
+
std::size_t read_data(void* dest, std::size_t length)
|
76
73
|
{
|
77
74
|
int samples = 0;
|
78
|
-
int
|
75
|
+
int max_samples = length / sizeof(short);
|
79
76
|
|
80
|
-
while (samples <
|
81
|
-
int
|
77
|
+
while (samples < max_samples) {
|
78
|
+
int samples_per_channel =
|
82
79
|
stb_vorbis_get_samples_short_interleaved(stream_, channels_,
|
83
|
-
|
80
|
+
static_cast<short*>(dest) + samples,
|
81
|
+
max_samples - samples);
|
84
82
|
|
85
|
-
if (
|
86
|
-
break;
|
83
|
+
if (samples_per_channel == 0) break;
|
87
84
|
|
88
|
-
samples +=
|
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
|
data/src/RenderState.hpp
ADDED
@@ -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
|
+
}
|
data/src/Resolution.cpp
ADDED
@@ -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, ¤t_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, ¤t_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
|