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/InputUIKit.cpp
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
#include <Gosu/Platform.hpp>
|
2
|
+
#if defined(GOSU_IS_IPHONE)
|
3
|
+
|
4
|
+
#import <Gosu/Input.hpp>
|
5
|
+
#import <Gosu/TextInput.hpp>
|
6
|
+
#import <functional>
|
7
|
+
#import <UIKit/UIKit.h>
|
8
|
+
|
9
|
+
struct Gosu::TextInput::Impl {};
|
10
|
+
Gosu::TextInput::TextInput() {}
|
11
|
+
Gosu::TextInput::~TextInput() {}
|
12
|
+
std::string Gosu::TextInput::text() const { return ""; }
|
13
|
+
void Gosu::TextInput::set_text(const std::string& text) {}
|
14
|
+
unsigned Gosu::TextInput::caret_pos() const { return 0; }
|
15
|
+
void Gosu::TextInput::set_caret_pos(unsigned) {}
|
16
|
+
unsigned Gosu::TextInput::selection_start() const { return 0; }
|
17
|
+
void Gosu::TextInput::set_selection_start(unsigned) {}
|
18
|
+
|
19
|
+
struct Gosu::Input::Impl
|
20
|
+
{
|
21
|
+
UIView* view;
|
22
|
+
float mouse_x, mouse_y;
|
23
|
+
float scale_x, scale_y;
|
24
|
+
float update_interval;
|
25
|
+
|
26
|
+
NSMutableSet* current_touches_set;
|
27
|
+
std::unique_ptr<Gosu::Touches> current_touches_vector;
|
28
|
+
|
29
|
+
Touch translate_touch(UITouch* ui_touch)
|
30
|
+
{
|
31
|
+
CGPoint point = [ui_touch locationInView:view];
|
32
|
+
|
33
|
+
return (Touch) {
|
34
|
+
.id = (__bridge void*) ui_touch,
|
35
|
+
.x = (float)point.x * scale_x,
|
36
|
+
.y = (float)point.y * scale_y,
|
37
|
+
};
|
38
|
+
}
|
39
|
+
};
|
40
|
+
|
41
|
+
Gosu::Input::Input(void* view, float update_interval)
|
42
|
+
: pimpl(new Impl)
|
43
|
+
{
|
44
|
+
pimpl->view = (__bridge UIView*) view;
|
45
|
+
pimpl->update_interval = update_interval;
|
46
|
+
pimpl->current_touches_set = [NSMutableSet new];
|
47
|
+
pimpl->mouse_x = pimpl->mouse_y = -1000;
|
48
|
+
set_mouse_factors(1, 1);
|
49
|
+
}
|
50
|
+
|
51
|
+
Gosu::Input::~Input()
|
52
|
+
{
|
53
|
+
}
|
54
|
+
|
55
|
+
void Gosu::Input::feed_touch_event(int type, void* touches)
|
56
|
+
{
|
57
|
+
NSSet* ui_touches = (__bridge NSSet*) touches;
|
58
|
+
|
59
|
+
pimpl->current_touches_vector.reset();
|
60
|
+
|
61
|
+
std::function<void (Touch)>* callback = nullptr;
|
62
|
+
|
63
|
+
if (type == 0) {
|
64
|
+
[pimpl->current_touches_set unionSet:ui_touches];
|
65
|
+
callback = &on_touch_began;
|
66
|
+
}
|
67
|
+
else if (type == 1) {
|
68
|
+
callback = &on_touch_moved;
|
69
|
+
}
|
70
|
+
else if (type == 2) {
|
71
|
+
[pimpl->current_touches_set minusSet:ui_touches];
|
72
|
+
callback = &on_touch_ended;
|
73
|
+
}
|
74
|
+
else if (type == 3) {
|
75
|
+
[pimpl->current_touches_set minusSet:ui_touches];
|
76
|
+
callback = &on_touch_cancelled;
|
77
|
+
}
|
78
|
+
|
79
|
+
if (callback && *callback) {
|
80
|
+
for (UITouch* ui_touch in ui_touches) {
|
81
|
+
(*callback)(pimpl->translate_touch(ui_touch));
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
std::string Gosu::Input::id_to_char(Button btn)
|
87
|
+
{
|
88
|
+
return std::string();
|
89
|
+
}
|
90
|
+
|
91
|
+
Gosu::Button Gosu::Input::char_to_id(std::string ch)
|
92
|
+
{
|
93
|
+
return NO_BUTTON;
|
94
|
+
}
|
95
|
+
|
96
|
+
bool Gosu::Input::down(Button btn)
|
97
|
+
{
|
98
|
+
return false;
|
99
|
+
}
|
100
|
+
|
101
|
+
double Gosu::Input::mouse_x() const
|
102
|
+
{
|
103
|
+
return pimpl->mouse_x;
|
104
|
+
}
|
105
|
+
|
106
|
+
double Gosu::Input::mouse_y() const
|
107
|
+
{
|
108
|
+
return pimpl->mouse_y;
|
109
|
+
}
|
110
|
+
|
111
|
+
void Gosu::Input::set_mouse_position(double x, double y)
|
112
|
+
{
|
113
|
+
pimpl->mouse_x = x;
|
114
|
+
pimpl->mouse_y = y;
|
115
|
+
}
|
116
|
+
|
117
|
+
void Gosu::Input::set_mouse_factors(double scale_x, double scale_y, double offset_x,
|
118
|
+
double offset_y)
|
119
|
+
{
|
120
|
+
pimpl->scale_x = scale_x;
|
121
|
+
pimpl->scale_y = scale_y;
|
122
|
+
|
123
|
+
// TODO - use offset
|
124
|
+
}
|
125
|
+
|
126
|
+
const Gosu::Touches& Gosu::Input::current_touches() const
|
127
|
+
{
|
128
|
+
if (!pimpl->current_touches_vector.get()) {
|
129
|
+
pimpl->current_touches_vector.reset(new Gosu::Touches);
|
130
|
+
for (UITouch* ui_touch in pimpl->current_touches_set) {
|
131
|
+
pimpl->current_touches_vector->push_back(pimpl->translate_touch(ui_touch));
|
132
|
+
}
|
133
|
+
}
|
134
|
+
return *pimpl->current_touches_vector;
|
135
|
+
}
|
136
|
+
|
137
|
+
double Gosu::Input::accelerometer_x() const
|
138
|
+
{
|
139
|
+
return 0;
|
140
|
+
}
|
141
|
+
|
142
|
+
double Gosu::Input::accelerometer_y() const
|
143
|
+
{
|
144
|
+
return 0;
|
145
|
+
}
|
146
|
+
|
147
|
+
double Gosu::Input::accelerometer_z() const
|
148
|
+
{
|
149
|
+
return 0;
|
150
|
+
}
|
151
|
+
|
152
|
+
void Gosu::Input::update()
|
153
|
+
{
|
154
|
+
// Check for dead touches and remove from vector if
|
155
|
+
// necessary
|
156
|
+
|
157
|
+
NSMutableSet* dead_touches = nil;
|
158
|
+
|
159
|
+
for (UITouch* touch in pimpl->current_touches_set) {
|
160
|
+
UITouchPhase phase = [touch phase];
|
161
|
+
if (phase == UITouchPhaseBegan ||
|
162
|
+
phase == UITouchPhaseMoved ||
|
163
|
+
phase == UITouchPhaseStationary) {
|
164
|
+
continue;
|
165
|
+
}
|
166
|
+
|
167
|
+
// Something was deleted, we will need the set.
|
168
|
+
if (!dead_touches) {
|
169
|
+
dead_touches = [NSMutableSet new];
|
170
|
+
}
|
171
|
+
[dead_touches addObject:touch];
|
172
|
+
}
|
173
|
+
|
174
|
+
// Has something been deleted?
|
175
|
+
if (dead_touches) {
|
176
|
+
pimpl->current_touches_vector.reset();
|
177
|
+
[pimpl->current_touches_set minusSet:dead_touches];
|
178
|
+
|
179
|
+
if (on_touch_ended) {
|
180
|
+
for (UITouch* ui_touch in dead_touches) {
|
181
|
+
on_touch_ended(pimpl->translate_touch(ui_touch));
|
182
|
+
}
|
183
|
+
}
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
Gosu::TextInput* Gosu::Input::text_input() const
|
188
|
+
{
|
189
|
+
return nullptr;
|
190
|
+
}
|
191
|
+
|
192
|
+
void Gosu::Input::set_text_input(TextInput* input)
|
193
|
+
{
|
194
|
+
throw "NYI";
|
195
|
+
}
|
196
|
+
|
197
|
+
#endif
|
data/src/Inspection.cpp
CHANGED
@@ -8,13 +8,12 @@ namespace Gosu
|
|
8
8
|
int fps, accum;
|
9
9
|
unsigned long sec;
|
10
10
|
|
11
|
-
void
|
11
|
+
void register_frame()
|
12
12
|
{
|
13
13
|
++accum;
|
14
|
-
unsigned long
|
15
|
-
if (sec !=
|
16
|
-
|
17
|
-
sec = newSec;
|
14
|
+
unsigned long new_sec = Gosu::milliseconds() / 1000;
|
15
|
+
if (sec != new_sec) {
|
16
|
+
sec = new_sec;
|
18
17
|
fps = accum;
|
19
18
|
accum = 0;
|
20
19
|
}
|
@@ -0,0 +1,151 @@
|
|
1
|
+
#include "LargeImageData.hpp"
|
2
|
+
#include "GraphicsImpl.hpp"
|
3
|
+
#include <Gosu/Bitmap.hpp>
|
4
|
+
#include <Gosu/Graphics.hpp>
|
5
|
+
#include <Gosu/Math.hpp>
|
6
|
+
#include <cmath>
|
7
|
+
using namespace std;
|
8
|
+
|
9
|
+
Gosu::LargeImageData::LargeImageData(const Bitmap& source,
|
10
|
+
unsigned part_width, unsigned part_height, unsigned image_flags)
|
11
|
+
{
|
12
|
+
full_width = source.width();
|
13
|
+
full_height = source.height();
|
14
|
+
parts_x = static_cast<unsigned>(trunc(ceil(1.0 * source.width() / part_width)));
|
15
|
+
parts_y = static_cast<unsigned>(trunc(ceil(1.0 * source.height() / part_height)));
|
16
|
+
this->part_width = part_width;
|
17
|
+
this->part_height = part_height;
|
18
|
+
|
19
|
+
parts.resize(parts_x * parts_y);
|
20
|
+
|
21
|
+
for (unsigned y = 0; y < parts_y; ++y) {
|
22
|
+
for (unsigned x = 0; x < parts_x; ++x) {
|
23
|
+
// The right-most parts don't necessarily have the full width.
|
24
|
+
unsigned src_width = part_width;
|
25
|
+
if (x == parts_x - 1 && source.width() % part_width != 0) {
|
26
|
+
src_width = source.width() % part_width;
|
27
|
+
}
|
28
|
+
|
29
|
+
// Same for the parts on the bottom.
|
30
|
+
unsigned src_height = part_height;
|
31
|
+
if (y == parts_y - 1 && source.height() % part_height != 0) {
|
32
|
+
src_height = source.height() % part_height;
|
33
|
+
}
|
34
|
+
|
35
|
+
unsigned local_flags = IF_TILEABLE | image_flags;
|
36
|
+
|
37
|
+
// Left edge, only tileable if requested in image_flags.
|
38
|
+
if (x == 0) {
|
39
|
+
local_flags &= ~IF_TILEABLE_LEFT;
|
40
|
+
local_flags |= (image_flags & IF_TILEABLE_LEFT);
|
41
|
+
}
|
42
|
+
// Right edge, only tileable if requested in image_flags.
|
43
|
+
if (x == parts_x - 1) {
|
44
|
+
local_flags &= ~IF_TILEABLE_RIGHT;
|
45
|
+
local_flags |= (image_flags & IF_TILEABLE_RIGHT);
|
46
|
+
}
|
47
|
+
// Top edge, only tileable if requested in image_flags.
|
48
|
+
if (y == 0) {
|
49
|
+
local_flags &= ~IF_TILEABLE_TOP;
|
50
|
+
local_flags |= (image_flags & IF_TILEABLE_TOP);
|
51
|
+
}
|
52
|
+
// Bottom edge, only tileable if requested in image_flags.
|
53
|
+
if (y == parts_y - 1) {
|
54
|
+
local_flags &= ~IF_TILEABLE_BOTTOM;
|
55
|
+
local_flags |= (image_flags & IF_TILEABLE_BOTTOM);
|
56
|
+
}
|
57
|
+
|
58
|
+
parts[y * parts_x + x].reset(Graphics::create_image(source,
|
59
|
+
x * part_width, y * part_height,
|
60
|
+
src_width, src_height,
|
61
|
+
local_flags).release());
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
int Gosu::LargeImageData::width() const
|
67
|
+
{
|
68
|
+
return full_width;
|
69
|
+
}
|
70
|
+
|
71
|
+
int Gosu::LargeImageData::height() const
|
72
|
+
{
|
73
|
+
return full_height;
|
74
|
+
}
|
75
|
+
|
76
|
+
namespace
|
77
|
+
{
|
78
|
+
// Local interpolation helper functions. - TODO why not from Math.hpp?
|
79
|
+
|
80
|
+
double ipl(double a, double b, double ratio)
|
81
|
+
{
|
82
|
+
return a + (b - a) * ratio;
|
83
|
+
}
|
84
|
+
|
85
|
+
Gosu::Color ipl(Gosu::Color a, Gosu::Color b, double ratio)
|
86
|
+
{
|
87
|
+
Gosu::Color result;
|
88
|
+
result.set_alpha(Gosu::round(ipl(a.alpha(), b.alpha(), ratio)));
|
89
|
+
result.set_red (Gosu::round(ipl(a.red(), b.red(), ratio)));
|
90
|
+
result.set_green(Gosu::round(ipl(a.green(), b.green(), ratio)));
|
91
|
+
result.set_blue (Gosu::round(ipl(a.blue(), b.blue(), ratio)));
|
92
|
+
return result;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
void Gosu::LargeImageData::draw(double x1, double y1, Color c1, double x2, double y2, Color c2,
|
97
|
+
double x3, double y3, Color c3, double x4, double y4, Color c4, ZPos z, AlphaMode mode) const
|
98
|
+
{
|
99
|
+
if (parts.empty()) return;
|
100
|
+
|
101
|
+
normalize_coordinates(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4);
|
102
|
+
|
103
|
+
for (unsigned py = 0; py < parts_y; ++py) {
|
104
|
+
for (unsigned px = 0; px < parts_x; ++px) {
|
105
|
+
ImageData& part = *parts[py * parts_x + px];
|
106
|
+
|
107
|
+
double rel_x_l = static_cast<double>(px * part_width) / width();
|
108
|
+
double rel_x_r = static_cast<double>(px * part_width + part.width()) / width();
|
109
|
+
double rel_y_t = static_cast<double>(py * part_height) / height();
|
110
|
+
double rel_y_b = static_cast<double>(py * part_height + part.height()) / height();
|
111
|
+
|
112
|
+
double abs_x_t_l = ipl(ipl(x1, x3, rel_y_t), ipl(x2, x4, rel_y_t), rel_x_l);
|
113
|
+
double abs_x_t_r = ipl(ipl(x1, x3, rel_y_t), ipl(x2, x4, rel_y_t), rel_x_r);
|
114
|
+
double abs_x_b_l = ipl(ipl(x1, x3, rel_y_b), ipl(x2, x4, rel_y_b), rel_x_l);
|
115
|
+
double abs_x_b_r = ipl(ipl(x1, x3, rel_y_b), ipl(x2, x4, rel_y_b), rel_x_r);
|
116
|
+
|
117
|
+
double abs_y_t_l = ipl(ipl(y1, y3, rel_y_t), ipl(y2, y4, rel_y_t), rel_x_l);
|
118
|
+
double abs_y_t_r = ipl(ipl(y1, y3, rel_y_t), ipl(y2, y4, rel_y_t), rel_x_r);
|
119
|
+
double abs_y_b_l = ipl(ipl(y1, y3, rel_y_b), ipl(y2, y4, rel_y_b), rel_x_l);
|
120
|
+
double abs_y_b_r = ipl(ipl(y1, y3, rel_y_b), ipl(y2, y4, rel_y_b), rel_x_r);
|
121
|
+
|
122
|
+
Color abs_c_t_l = ipl(ipl(c1, c3, rel_y_t), ipl(c2, c4, rel_y_t), rel_x_l);
|
123
|
+
Color abs_c_t_r = ipl(ipl(c1, c3, rel_y_t), ipl(c2, c4, rel_y_t), rel_x_r);
|
124
|
+
Color abs_c_b_l = ipl(ipl(c1, c3, rel_y_b), ipl(c2, c4, rel_y_b), rel_x_l);
|
125
|
+
Color abs_c_b_r = ipl(ipl(c1, c3, rel_y_b), ipl(c2, c4, rel_y_b), rel_x_r);
|
126
|
+
|
127
|
+
part.draw(abs_x_t_l, abs_y_t_l, abs_c_t_l, abs_x_t_r, abs_y_t_r, abs_c_t_r,
|
128
|
+
abs_x_b_l, abs_y_b_l, abs_c_b_l, abs_x_b_r, abs_y_b_r, abs_c_b_r, z, mode);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
Gosu::Bitmap Gosu::LargeImageData::to_bitmap() const
|
134
|
+
{
|
135
|
+
Bitmap bitmap(width(), height());
|
136
|
+
for (int x = 0; x < parts_x; ++x) {
|
137
|
+
for (int y = 0; y < parts_y; ++y) {
|
138
|
+
bitmap.insert(parts[y * parts_x + x]->to_bitmap(), x * part_width, y * part_height);
|
139
|
+
}
|
140
|
+
}
|
141
|
+
return bitmap;
|
142
|
+
}
|
143
|
+
|
144
|
+
void Gosu::LargeImageData::insert(const Bitmap& bitmap, int at_x, int at_y)
|
145
|
+
{
|
146
|
+
for (int x = 0; x < parts_x; ++x) {
|
147
|
+
for (int y = 0; y < parts_y; ++y) {
|
148
|
+
parts[y * parts_x + x]->insert(bitmap, at_x - x * part_width, at_y - y * part_height);
|
149
|
+
}
|
150
|
+
}
|
151
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <Gosu/Fwd.hpp>
|
4
|
+
#include <Gosu/ImageData.hpp>
|
5
|
+
#include <Gosu/Platform.hpp>
|
6
|
+
#include <memory>
|
7
|
+
#include <vector>
|
8
|
+
|
9
|
+
namespace Gosu
|
10
|
+
{
|
11
|
+
class LargeImageData : public ImageData
|
12
|
+
{
|
13
|
+
unsigned full_width, full_height;
|
14
|
+
unsigned parts_x, parts_y;
|
15
|
+
unsigned part_width, part_height;
|
16
|
+
std::vector<std::shared_ptr<ImageData>> parts;
|
17
|
+
|
18
|
+
public:
|
19
|
+
LargeImageData(const Bitmap& source, unsigned part_width, unsigned part_height,
|
20
|
+
unsigned image_flags);
|
21
|
+
|
22
|
+
int width() const override;
|
23
|
+
int height() const override;
|
24
|
+
|
25
|
+
void draw(double x1, double y1, Color c1, double x2, double y2, Color c2,
|
26
|
+
double x3, double y3, Color c3, double x4, double y4, Color c4, ZPos z,
|
27
|
+
AlphaMode mode) const override;
|
28
|
+
|
29
|
+
const GLTexInfo* gl_tex_info() const override
|
30
|
+
{
|
31
|
+
return nullptr;
|
32
|
+
}
|
33
|
+
|
34
|
+
std::unique_ptr<ImageData> subimage(int x, int y, int w, int h) const override
|
35
|
+
{
|
36
|
+
return std::unique_ptr<ImageData>();
|
37
|
+
}
|
38
|
+
|
39
|
+
Bitmap to_bitmap() const override;
|
40
|
+
|
41
|
+
void insert(const Bitmap& bitmap, int x, int y) override;
|
42
|
+
};
|
43
|
+
}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
#include "DrawOpQueue.hpp"
|
3
3
|
#include <cmath>
|
4
4
|
#include <algorithm>
|
5
|
+
#include <functional>
|
5
6
|
#include <memory>
|
6
7
|
#include <stdexcept>
|
7
8
|
|
@@ -9,10 +10,11 @@ struct Gosu::Macro::Impl
|
|
9
10
|
{
|
10
11
|
typedef double Float;
|
11
12
|
|
12
|
-
VertexArrays
|
13
|
+
VertexArrays vertex_arrays;
|
13
14
|
int width, height;
|
14
15
|
|
15
|
-
Transform
|
16
|
+
Transform find_transform_for_target(Float x1, Float y1, Float x2, Float y2,
|
17
|
+
Float x3, Float y3, Float x4, Float y4) const
|
16
18
|
{
|
17
19
|
// Transformation logic follows a discussion on the ImageMagick mailing
|
18
20
|
// list (on which ImageMagick's perspective_transform.pl is based).
|
@@ -41,20 +43,16 @@ struct Gosu::Macro::Impl
|
|
41
43
|
|
42
44
|
// Since this matrix is relatively sparse, we unroll all three solving paths.
|
43
45
|
|
44
|
-
static const Transform
|
46
|
+
static const Transform null_transform = {{ 0 }};
|
45
47
|
|
46
48
|
// Row 7 is completely useless
|
47
|
-
if (x2 == x4 && x3 == x4)
|
48
|
-
return nullTransform;
|
49
|
+
if (x2 == x4 && x3 == x4) return null_transform;
|
49
50
|
// Row 8 is completely useless
|
50
|
-
if (y2 == y3 && y3 == y4)
|
51
|
-
return nullTransform;
|
51
|
+
if (y2 == y3 && y3 == y4) return null_transform;
|
52
52
|
// Col 7 is completely useless
|
53
|
-
if (x2 == x4 && y2 == y4)
|
54
|
-
return nullTransform;
|
53
|
+
if (x2 == x4 && y2 == y4) return null_transform;
|
55
54
|
// Col 8 is completely useless
|
56
|
-
if (x3 == x4 && y3 == y4)
|
57
|
-
return nullTransform;
|
55
|
+
if (x3 == x4 && y3 == y4) return null_transform;
|
58
56
|
|
59
57
|
Float c[8];
|
60
58
|
|
@@ -68,15 +66,18 @@ struct Gosu::Macro::Impl
|
|
68
66
|
// TODO: x2==x4 is the normal case where an image is
|
69
67
|
// drawn upright; the code should rather swap in the rare case that x3==x4!
|
70
68
|
|
71
|
-
Float
|
72
|
-
Float
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
69
|
+
Float left_cell7 = (x2 - x4) * width;
|
70
|
+
Float right_cell7 = (x3 - x4) * height;
|
71
|
+
Float orig_right_side7 = (x1 - x2 - x3 + x4);
|
72
|
+
Float left_cell8 = (y2 - y4) * width;
|
73
|
+
Float right_cell8 = (y3 - y4) * height;
|
74
|
+
Float orig_right_side8 = (y1 - y2 - y3 + y4);
|
75
|
+
|
76
|
+
bool swap_rows78 = x2 == x4;
|
77
|
+
if (swap_rows78) {
|
78
|
+
std::swap(left_cell7, left_cell8);
|
79
|
+
std::swap(right_cell7, right_cell8);
|
80
|
+
std::swap(orig_right_side7, orig_right_side8);
|
80
81
|
}
|
81
82
|
|
82
83
|
// 0, 0, 1, 0, 0, 0, 0, 0 | x1
|
@@ -85,15 +86,15 @@ struct Gosu::Macro::Impl
|
|
85
86
|
// 0, 0, 0, w, 0, 0, -y2w, 0 | y2-y1
|
86
87
|
// 0, h, 0, 0, 0, 0, 0, -x3h | x3-x1
|
87
88
|
// 0, 0, 0, 0, h, 0, 0, -y3h | y3-y1
|
88
|
-
// 0, 0, 0, 0, 0, 0,
|
89
|
-
// 0, 0, 0, 0, 0, 0,
|
89
|
+
// 0, 0, 0, 0, 0, 0, left_cell7, right_cell7 | orig_right_side7
|
90
|
+
// 0, 0, 0, 0, 0, 0, left_cell8, right_cell8 | orig_right_side8
|
90
91
|
|
91
92
|
// Use row 7 to eliminate the left cell in row 8
|
92
93
|
// Row8 = Row8 - factor78 * Row7
|
93
|
-
Float factor78 =
|
94
|
-
Float
|
95
|
-
Float
|
96
|
-
c[7] =
|
94
|
+
Float factor78 = left_cell8 / left_cell7;
|
95
|
+
Float rem_cell8 = right_cell8 - right_cell7 * factor78;
|
96
|
+
Float right_side8 = orig_right_side8 - orig_right_side7 * factor78;
|
97
|
+
c[7] = right_side8 / rem_cell8;
|
97
98
|
|
98
99
|
// 0, 0, 1, 0, 0, 0, 0, 0 | x1
|
99
100
|
// 0, 0, 0, 0, 0, 1, 0, 0 | y1
|
@@ -101,15 +102,15 @@ struct Gosu::Macro::Impl
|
|
101
102
|
// 0, 0, 0, w, 0, 0, -y2w, 0 | y2-y1
|
102
103
|
// 0, h, 0, 0, 0, 0, 0, -x3h | x3-x1
|
103
104
|
// 0, 0, 0, 0, h, 0, 0, -y3h | y3-y1
|
104
|
-
// 0, 0, 0, 0, 0, 0,
|
105
|
-
// 0, 0, 0, 0, 0, 0, 0,
|
105
|
+
// 0, 0, 0, 0, 0, 0, left_cell7, right_cell7 | orig_right_side7
|
106
|
+
// 0, 0, 0, 0, 0, 0, 0, rem_cell8 | right_side8
|
106
107
|
|
107
108
|
// Use the remaining value in row 8 to eliminate the right value in row 7.
|
108
109
|
// Row7 = Row7 - factor87 * Row8
|
109
|
-
Float factor87 =
|
110
|
-
Float
|
111
|
-
Float
|
112
|
-
c[6] =
|
110
|
+
Float factor87 = right_cell7 / rem_cell8;
|
111
|
+
Float rem_cell7 = left_cell7;
|
112
|
+
Float right_side7 = orig_right_side7 - right_side8 * factor87;
|
113
|
+
c[6] = right_side7 / rem_cell7;
|
113
114
|
|
114
115
|
// 0, 0, 1, 0, 0, 0, 0, 0 | x1
|
115
116
|
// 0, 0, 0, 0, 0, 1, 0, 0 | y1
|
@@ -117,33 +118,34 @@ struct Gosu::Macro::Impl
|
|
117
118
|
// 0, 0, 0, w, 0, 0, -y2w, 0 | y2-y1
|
118
119
|
// 0, h, 0, 0, 0, 0, 0, -x3h | x3-x1
|
119
120
|
// 0, 0, 0, 0, h, 0, 0, -y3h | y3-y1
|
120
|
-
// 0, 0, 0, 0, 0, 0,
|
121
|
-
// 0, 0, 0, 0, 0, 0, 0,
|
121
|
+
// 0, 0, 0, 0, 0, 0, rem_cell7, 0 | right_side7
|
122
|
+
// 0, 0, 0, 0, 0, 0, 0, rem_cell8 | right_side8
|
122
123
|
|
123
124
|
// Use the new rows 7 and 8 to calculate c0, c1, c3 & c4.
|
124
125
|
// Row3 = Row3 - factor73 * Row7
|
125
|
-
Float factor73 = -x2*width /
|
126
|
-
Float
|
127
|
-
Float
|
128
|
-
c[0] =
|
126
|
+
Float factor73 = -x2 * width / rem_cell7;
|
127
|
+
Float rem_cell3 = width;
|
128
|
+
Float right_side3 = (x2 - x1) - right_side7 * factor73;
|
129
|
+
c[0] = right_side3 / rem_cell3;
|
129
130
|
// Row4 = Row4 - factor74 * Row7
|
130
|
-
Float factor74 = -y2*width /
|
131
|
-
Float
|
132
|
-
Float
|
133
|
-
c[3] =
|
131
|
+
Float factor74 = -y2 * width / rem_cell7;
|
132
|
+
Float rem_cell4 = width;
|
133
|
+
Float right_side4 = (y2 - y1) - right_side7 * factor74;
|
134
|
+
c[3] = right_side4 / rem_cell4;
|
134
135
|
// Row5 = Row5 - factor85 * Row7
|
135
|
-
Float factor85 = -x3*height /
|
136
|
-
Float
|
137
|
-
Float
|
138
|
-
c[1] =
|
136
|
+
Float factor85 = -x3 * height / rem_cell8;
|
137
|
+
Float rem_cell5 = height;
|
138
|
+
Float right_side5 = (x3 - x1) - right_side8 * factor85;
|
139
|
+
c[1] = right_side5 / rem_cell5;
|
139
140
|
// Row6 = Row6 - factor86 * Row8
|
140
|
-
Float factor86 = -y3*height /
|
141
|
-
Float
|
142
|
-
Float
|
143
|
-
c[4] =
|
141
|
+
Float factor86 = -y3 * height / rem_cell8;
|
142
|
+
Float rem_cell6 = height;
|
143
|
+
Float right_side6 = (y3 - y1) - right_side8 * factor86;
|
144
|
+
c[4] = right_side6 / rem_cell6;
|
144
145
|
|
145
|
-
if (
|
146
|
+
if (swap_rows78) {
|
146
147
|
std::swap(c[6], c[7]);
|
148
|
+
}
|
147
149
|
|
148
150
|
// Let's hope I never have to debug/understand this again! :D
|
149
151
|
|
@@ -156,26 +158,25 @@ struct Gosu::Macro::Impl
|
|
156
158
|
return result;
|
157
159
|
}
|
158
160
|
|
159
|
-
void
|
161
|
+
void draw_vertex_arrays(Float x1, Float y1, Float x2, Float y2, Float x3, Float y3,
|
162
|
+
Float x4, Float y4) const
|
160
163
|
{
|
161
|
-
// TODO: Macros should not be split up just because they have different transforms
|
162
|
-
// They should be premultiplied and have the same transform by definition. Then the
|
163
|
-
// only has to be performed once.
|
164
|
+
// TODO: Macros should not be split up just because they have different transforms.
|
165
|
+
// They should be premultiplied and have the same transform by definition. Then the
|
166
|
+
// transformation only has to be performed once.
|
164
167
|
|
165
168
|
#ifndef GOSU_IS_OPENGLES
|
166
169
|
glEnable(GL_BLEND);
|
167
170
|
glMatrixMode(GL_MODELVIEW);
|
168
171
|
|
169
|
-
Transform transform =
|
170
|
-
findTransformForTarget(x1, y1, x2, y2, x3, y3, x4, y4);
|
172
|
+
Transform transform = find_transform_for_target(x1, y1, x2, y2, x3, y3, x4, y4);
|
171
173
|
|
172
|
-
for (
|
173
|
-
{
|
174
|
+
for (const auto& vertex_array : vertex_arrays) {
|
174
175
|
glPushMatrix();
|
175
|
-
|
176
|
+
vertex_array.render_state.apply();
|
176
177
|
glMultMatrixd(&transform[0]);
|
177
|
-
glInterleavedArrays(GL_T2F_C4UB_V3F, 0, &
|
178
|
-
glDrawArrays(GL_QUADS, 0, (GLsizei)
|
178
|
+
glInterleavedArrays(GL_T2F_C4UB_V3F, 0, &vertex_array.vertices[0]);
|
179
|
+
glDrawArrays(GL_QUADS, 0, (GLsizei) vertex_array.vertices.size());
|
179
180
|
glPopMatrix();
|
180
181
|
}
|
181
182
|
#endif
|
@@ -187,7 +188,7 @@ Gosu::Macro::Macro(DrawOpQueue& queue, int width, int height)
|
|
187
188
|
{
|
188
189
|
pimpl->width = width;
|
189
190
|
pimpl->height = height;
|
190
|
-
queue.
|
191
|
+
queue.compile_to(pimpl->vertex_arrays);
|
191
192
|
}
|
192
193
|
|
193
194
|
int Gosu::Macro::width() const
|
@@ -200,34 +201,32 @@ int Gosu::Macro::height() const
|
|
200
201
|
return pimpl->height;
|
201
202
|
}
|
202
203
|
|
203
|
-
void Gosu::Macro::draw(double x1, double y1, Color c1,
|
204
|
-
double
|
205
|
-
double x3, double y3, Color c3,
|
206
|
-
double x4, double y4, Color c4,
|
207
|
-
ZPos z, AlphaMode mode) const
|
204
|
+
void Gosu::Macro::draw(double x1, double y1, Color c1, double x2, double y2, Color c2,
|
205
|
+
double x3, double y3, Color c3, double x4, double y4, Color c4, ZPos z, AlphaMode mode) const
|
208
206
|
{
|
209
|
-
if (c1 != Color::WHITE || c2 != Color::WHITE || c3 != Color::WHITE || c4 != Color::WHITE)
|
210
|
-
throw std::invalid_argument("Macros cannot be tinted with colors
|
207
|
+
if (c1 != Color::WHITE || c2 != Color::WHITE || c3 != Color::WHITE || c4 != Color::WHITE) {
|
208
|
+
throw std::invalid_argument("Macros cannot be tinted with colors");
|
209
|
+
}
|
211
210
|
|
212
|
-
|
211
|
+
normalize_coordinates(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4);
|
213
212
|
|
214
|
-
std::
|
215
|
-
Gosu::Graphics::
|
213
|
+
std::function<void ()> f = [=] { pimpl->draw_vertex_arrays(x1, y1, x2, y2, x3, y3, x4, y4); };
|
214
|
+
Gosu::Graphics::gl(f, z);
|
216
215
|
}
|
217
216
|
|
218
|
-
const Gosu::GLTexInfo* Gosu::Macro::
|
217
|
+
const Gosu::GLTexInfo* Gosu::Macro::gl_tex_info() const
|
219
218
|
{
|
220
|
-
return
|
219
|
+
return nullptr;
|
221
220
|
}
|
222
221
|
|
223
|
-
Gosu::Bitmap Gosu::Macro::
|
222
|
+
Gosu::Bitmap Gosu::Macro::to_bitmap() const
|
224
223
|
{
|
225
224
|
throw std::logic_error("Gosu::Macro cannot be rendered as Gosu::Bitmap yet");
|
226
225
|
}
|
227
226
|
|
228
|
-
|
227
|
+
std::unique_ptr<Gosu::ImageData> Gosu::Macro::subimage(int x, int y, int width, int height) const
|
229
228
|
{
|
230
|
-
return
|
229
|
+
return std::unique_ptr<ImageData>();
|
231
230
|
}
|
232
231
|
|
233
232
|
void Gosu::Macro::insert(const Bitmap& bitmap, int x, int y)
|