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.
- checksums.yaml +4 -4
- data/Gosu/Audio.hpp +15 -11
- data/Gosu/Font.hpp +24 -20
- data/Gosu/Fwd.hpp +1 -1
- data/Gosu/Graphics.hpp +8 -9
- data/Gosu/ImageData.hpp +1 -1
- data/Gosu/Input.hpp +1 -1
- data/Gosu/Math.hpp +0 -18
- data/Gosu/Text.hpp +22 -30
- data/Gosu/TextInput.hpp +13 -0
- data/Gosu/Utility.hpp +2 -0
- data/Gosu/Window.hpp +3 -3
- data/README.md +3 -4
- data/ext/gosu/extconf.rb +7 -9
- data/lib/gosu/swig_patches.rb +1 -4
- data/rdoc/gosu.rb +34 -9
- data/src/Audio.cpp +6 -6
- data/src/AudioImpl.cpp +2 -2
- data/src/Bitmap.cpp +1 -2
- data/src/BitmapIO.cpp +21 -2
- data/src/BlockAllocator.cpp +1 -1
- data/src/Channel.cpp +7 -1
- data/src/ClipRectStack.hpp +4 -1
- data/src/Color.cpp +2 -1
- data/src/DirectoriesWin.cpp +1 -1
- data/src/DrawOp.hpp +8 -4
- data/src/DrawOpQueue.hpp +13 -24
- data/src/FileUnix.cpp +3 -1
- data/src/Font.cpp +92 -96
- data/src/GosuGLView.cpp +59 -31
- data/src/GosuGLView.hpp +14 -0
- data/src/GosuViewController.cpp +21 -21
- data/src/{GosuViewController.h → GosuViewController.hpp} +2 -4
- data/src/Graphics.cpp +71 -38
- data/src/GraphicsImpl.hpp +12 -29
- data/src/Image.cpp +5 -7
- data/src/Input.cpp +7 -5
- data/src/InputUIKit.cpp +19 -37
- data/src/Macro.cpp +10 -2
- data/src/MarkupParser.cpp +241 -0
- data/src/MarkupParser.hpp +61 -0
- data/src/Math.cpp +1 -1
- data/src/OffScreenTarget.cpp +99 -0
- data/src/OffScreenTarget.hpp +23 -0
- data/src/OggFile.hpp +10 -0
- data/src/RenderState.hpp +0 -2
- data/src/Resolution.cpp +2 -2
- data/src/RubyGosu.cxx +457 -244
- data/src/TexChunk.cpp +8 -6
- data/src/Text.cpp +58 -345
- data/src/TextBuilder.cpp +138 -0
- data/src/TextBuilder.hpp +55 -0
- data/src/TextInput.cpp +27 -10
- data/src/Texture.cpp +22 -17
- data/src/Texture.hpp +19 -20
- data/src/TimingApple.cpp +5 -7
- data/src/TimingUnix.cpp +1 -4
- data/src/TimingWin.cpp +4 -1
- data/src/TrueTypeFont.cpp +282 -0
- data/src/TrueTypeFont.hpp +66 -0
- data/src/TrueTypeFontApple.cpp +65 -0
- data/src/TrueTypeFontUnix.cpp +91 -0
- data/src/TrueTypeFontWin.cpp +82 -0
- data/src/Utility.cpp +40 -0
- data/src/Window.cpp +7 -6
- data/src/WindowUIKit.cpp +9 -4
- data/src/stb_truetype.h +4589 -0
- data/src/utf8proc.c +755 -0
- data/src/utf8proc.h +699 -0
- data/src/utf8proc_data.h +14386 -0
- metadata +23 -16
- data/src/FormattedString.cpp +0 -237
- data/src/FormattedString.hpp +0 -47
- data/src/GosuAppDelegate.cpp +0 -30
- data/src/GosuAppDelegate.h +0 -8
- data/src/GosuGLView.h +0 -8
- data/src/TextApple.cpp +0 -212
- data/src/TextTTFWin.cpp +0 -197
- data/src/TextUnix.cpp +0 -280
- data/src/TextWin.cpp +0 -191
data/src/GosuGLView.cpp
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
#include <Gosu/Platform.hpp>
|
2
2
|
#if defined(GOSU_IS_IPHONE)
|
3
3
|
|
4
|
-
#import "GosuGLView.
|
4
|
+
#import "GosuGLView.hpp"
|
5
|
+
#import <Gosu/Input.hpp>
|
6
|
+
#import <Gosu/TextInput.hpp>
|
5
7
|
|
6
8
|
#import <OpenGLES/EAGL.h>
|
7
9
|
#import <OpenGLES/EAGLDrawable.h>
|
@@ -9,6 +11,7 @@
|
|
9
11
|
#import <OpenGLES/ES1/glext.h>
|
10
12
|
#import <QuartzCore/QuartzCore.h>
|
11
13
|
|
14
|
+
|
12
15
|
static EAGLContext __weak* globalContext;
|
13
16
|
|
14
17
|
namespace Gosu
|
@@ -28,7 +31,7 @@ namespace Gosu
|
|
28
31
|
@implementation GosuGLView
|
29
32
|
{
|
30
33
|
EAGLContext* _context;
|
31
|
-
|
34
|
+
|
32
35
|
GLint _backingWidth;
|
33
36
|
GLint _backingHeight;
|
34
37
|
|
@@ -36,41 +39,22 @@ namespace Gosu
|
|
36
39
|
GLuint _viewFramebuffer;
|
37
40
|
}
|
38
41
|
|
39
|
-
|
40
|
-
{
|
41
|
-
return [CAEAGLLayer class];
|
42
|
-
}
|
43
|
-
|
44
|
-
- (id)initWithFrame:(CGRect)frame
|
45
|
-
{
|
46
|
-
if ((self = [super initWithFrame:frame])) {
|
47
|
-
[self initializeGosuGLView];
|
48
|
-
}
|
49
|
-
|
50
|
-
return self;
|
51
|
-
}
|
52
|
-
|
53
|
-
- (id)initWithCoder:(NSCoder*)aDecoder
|
42
|
+
- (instancetype)initWithFrame:(CGRect)frame
|
54
43
|
{
|
55
|
-
if (
|
56
|
-
|
44
|
+
if (self = [super initWithFrame:frame]) {
|
45
|
+
CAEAGLLayer* layer = (CAEAGLLayer*)self.layer;
|
46
|
+
layer.opaque = YES;
|
47
|
+
|
48
|
+
globalContext = _context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
|
49
|
+
[EAGLContext setCurrentContext:_context];
|
50
|
+
|
51
|
+
self.exclusiveTouch = YES;
|
52
|
+
self.multipleTouchEnabled = YES;
|
57
53
|
}
|
58
54
|
|
59
55
|
return self;
|
60
56
|
}
|
61
57
|
|
62
|
-
- (void)initializeGosuGLView
|
63
|
-
{
|
64
|
-
CAEAGLLayer* layer = (CAEAGLLayer*)self.layer;
|
65
|
-
layer.opaque = YES;
|
66
|
-
|
67
|
-
globalContext = _context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
|
68
|
-
[EAGLContext setCurrentContext:_context];
|
69
|
-
|
70
|
-
self.exclusiveTouch = YES;
|
71
|
-
self.multipleTouchEnabled = YES;
|
72
|
-
}
|
73
|
-
|
74
58
|
- (void)dealloc
|
75
59
|
{
|
76
60
|
[EAGLContext setCurrentContext:nil];
|
@@ -93,6 +77,13 @@ namespace Gosu
|
|
93
77
|
[_context presentRenderbuffer:GL_RENDERBUFFER_OES];
|
94
78
|
}
|
95
79
|
|
80
|
+
#pragma mark - UIView
|
81
|
+
|
82
|
+
+ (Class)layerClass
|
83
|
+
{
|
84
|
+
return [CAEAGLLayer class];
|
85
|
+
}
|
86
|
+
|
96
87
|
- (void)layoutSubviews
|
97
88
|
{
|
98
89
|
[EAGLContext setCurrentContext:_context];
|
@@ -128,6 +119,43 @@ namespace Gosu
|
|
128
119
|
_viewRenderbuffer = 0;
|
129
120
|
}
|
130
121
|
|
122
|
+
#pragma mark - NSResponder / UIKeyInput / UITextInputTraits
|
123
|
+
|
124
|
+
- (BOOL)canBecomeFirstResponder
|
125
|
+
{
|
126
|
+
return _input && _input->text_input();
|
127
|
+
}
|
128
|
+
|
129
|
+
- (BOOL)hasText
|
130
|
+
{
|
131
|
+
return _input && _input->text_input() && !_input->text_input()->text().empty();
|
132
|
+
}
|
133
|
+
|
134
|
+
- (void)insertText:(NSString*)text
|
135
|
+
{
|
136
|
+
if (_input && _input->text_input()) {
|
137
|
+
auto filtered_text = _input->text_input()->filter(text.UTF8String ?: "");
|
138
|
+
_input->text_input()->insert_text(filtered_text);
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
- (void)deleteBackward
|
143
|
+
{
|
144
|
+
if (_input && _input->text_input()) {
|
145
|
+
_input->text_input()->delete_backward();
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
- (UITextAutocapitalizationType)autocapitalizationType
|
150
|
+
{
|
151
|
+
return UITextAutocapitalizationTypeNone;
|
152
|
+
}
|
153
|
+
|
154
|
+
- (UITextAutocorrectionType)autocorrectionType
|
155
|
+
{
|
156
|
+
return UITextAutocorrectionTypeNo;
|
157
|
+
}
|
158
|
+
|
131
159
|
@end
|
132
160
|
|
133
161
|
#endif
|
data/src/GosuGLView.hpp
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#import <UIKit/UIKit.h>
|
2
|
+
#import <Gosu/Fwd.hpp>
|
3
|
+
|
4
|
+
@interface GosuGLView : UIView <UIKeyInput>
|
5
|
+
|
6
|
+
- (instancetype)initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER;
|
7
|
+
- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
|
8
|
+
|
9
|
+
- (void)redrawGL:(void (^)())code;
|
10
|
+
|
11
|
+
// This property must be set in order for TextInput handling to work.
|
12
|
+
@property (nonatomic, assign) Gosu::Input* input;
|
13
|
+
|
14
|
+
@end
|
data/src/GosuViewController.cpp
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#include <Gosu/Platform.hpp>
|
2
2
|
#if defined(GOSU_IS_IPHONE)
|
3
3
|
|
4
|
-
#import "GosuGLView.
|
5
|
-
#import "GosuViewController.
|
4
|
+
#import "GosuGLView.hpp"
|
5
|
+
#import "GosuViewController.hpp"
|
6
6
|
#import "GraphicsImpl.hpp"
|
7
7
|
#import "AudioImpl.hpp"
|
8
8
|
#import <Gosu/Gosu.hpp>
|
@@ -52,21 +52,11 @@ static void handle_audio_interruption(void* unused, UInt32 inInterruptionState)
|
|
52
52
|
return YES;
|
53
53
|
}
|
54
54
|
|
55
|
-
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
56
|
-
{
|
57
|
-
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
|
58
|
-
}
|
59
|
-
|
60
55
|
- (NSUInteger)supportedInterfaceOrientations
|
61
56
|
{
|
62
57
|
return UIInterfaceOrientationMaskLandscape;
|
63
58
|
}
|
64
59
|
|
65
|
-
- (GosuGLView*)GLView
|
66
|
-
{
|
67
|
-
return (GosuGLView*)self.view;
|
68
|
-
}
|
69
|
-
|
70
60
|
- (Gosu::Window&)gosuWindowReference
|
71
61
|
{
|
72
62
|
NSAssert(self.gosuWindow, @"gosuWindow needs to be set before showing GosuViewController");
|
@@ -80,6 +70,7 @@ static void handle_audio_interruption(void* unused, UInt32 inInterruptionState)
|
|
80
70
|
{
|
81
71
|
[super viewDidLoad];
|
82
72
|
|
73
|
+
// TODO - replace with AVAudioSession https://stackoverflow.com/q/19710046
|
83
74
|
AudioSessionInitialize(nullptr, nullptr, handle_audio_interruption, nullptr);
|
84
75
|
|
85
76
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
@@ -151,15 +142,13 @@ static void handle_audio_interruption(void* unused, UInt32 inInterruptionState)
|
|
151
142
|
|
152
143
|
- (void)setupTimerOrDisplayLink
|
153
144
|
{
|
154
|
-
if (_timerOrDisplayLink)
|
155
|
-
return;
|
156
|
-
}
|
145
|
+
if (_timerOrDisplayLink) return;
|
157
146
|
|
158
147
|
NSInteger targetFPS = round(1000.0 / self.gosuWindowReference.update_interval());
|
159
148
|
|
160
149
|
if (60 % targetFPS != 0) {
|
161
150
|
NSTimeInterval interval = self.gosuWindowReference.update_interval() / 1000.0;
|
162
|
-
NSTimer* timer
|
151
|
+
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:interval
|
163
152
|
target:self
|
164
153
|
selector:@selector(updateAndDraw:)
|
165
154
|
userInfo:nil
|
@@ -188,7 +177,7 @@ static void handle_audio_interruption(void* unused, UInt32 inInterruptionState)
|
|
188
177
|
}
|
189
178
|
|
190
179
|
if (window.needs_redraw()) {
|
191
|
-
[self.
|
180
|
+
[(GosuGLView*)self.view redrawGL:^{
|
192
181
|
window.graphics().frame([&window] {
|
193
182
|
window.draw();
|
194
183
|
Gosu::FPS::register_frame();
|
@@ -199,26 +188,37 @@ static void handle_audio_interruption(void* unused, UInt32 inInterruptionState)
|
|
199
188
|
Gosu::Song::update();
|
200
189
|
}
|
201
190
|
|
191
|
+
#pragma mark - Input setup
|
192
|
+
|
193
|
+
- (void)trackTextInput:(Gosu::Input&)input
|
194
|
+
{
|
195
|
+
((GosuGLView*)self.view).input = &input;
|
196
|
+
}
|
197
|
+
|
202
198
|
#pragma mark - Touch forwarding
|
203
199
|
|
204
200
|
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
|
205
201
|
{
|
206
|
-
self.gosuWindowReference.input()
|
202
|
+
auto& input = self.gosuWindowReference.input();
|
203
|
+
input.feed_touch_event(input.on_touch_began, (__bridge void*)touches);
|
207
204
|
}
|
208
205
|
|
209
206
|
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
|
210
207
|
{
|
211
|
-
self.gosuWindowReference.input()
|
208
|
+
auto& input = self.gosuWindowReference.input();
|
209
|
+
input.feed_touch_event(input.on_touch_moved, (__bridge void*)touches);
|
212
210
|
}
|
213
211
|
|
214
212
|
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
|
215
213
|
{
|
216
|
-
self.gosuWindowReference.input()
|
214
|
+
auto& input = self.gosuWindowReference.input();
|
215
|
+
input.feed_touch_event(input.on_touch_ended, (__bridge void*)touches);
|
217
216
|
}
|
218
217
|
|
219
218
|
- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event
|
220
219
|
{
|
221
|
-
self.gosuWindowReference.input()
|
220
|
+
auto& input = self.gosuWindowReference.input();
|
221
|
+
input.feed_touch_event(input.on_touch_cancelled, (__bridge void*)touches);
|
222
222
|
}
|
223
223
|
|
224
224
|
@end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
#import <UIKit/UIKit.h>
|
2
|
-
|
3
|
-
|
4
|
-
@class GosuGLView;
|
2
|
+
#import <Gosu/Fwd.hpp>
|
5
3
|
|
6
4
|
|
7
5
|
@interface GosuViewController : UIViewController
|
8
6
|
|
9
|
-
- (
|
7
|
+
- (void)trackTextInput:(Gosu::Input&)input;
|
10
8
|
|
11
9
|
@property (nonatomic, assign) void *gosuWindow;
|
12
10
|
|
data/src/Graphics.cpp
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
#include "GraphicsImpl.hpp"
|
5
5
|
#include "LargeImageData.hpp"
|
6
6
|
#include "Macro.hpp"
|
7
|
-
#include "
|
7
|
+
#include "OffScreenTarget.hpp"
|
8
8
|
#include "Texture.hpp"
|
9
9
|
#include <Gosu/Bitmap.hpp>
|
10
10
|
#include <Gosu/Image.hpp>
|
@@ -26,7 +26,6 @@ namespace Gosu
|
|
26
26
|
if (current_graphics_pointer == nullptr) {
|
27
27
|
throw logic_error("Gosu::Graphics can only be drawn to while rendering");
|
28
28
|
}
|
29
|
-
|
30
29
|
return *current_graphics_pointer;
|
31
30
|
}
|
32
31
|
|
@@ -160,45 +159,44 @@ void Gosu::Graphics::frame(const function<void ()>& f)
|
|
160
159
|
}
|
161
160
|
else {
|
162
161
|
// Create default draw-op queue.
|
163
|
-
queues.
|
162
|
+
queues.emplace_back(QM_RENDER_TO_SCREEN);
|
164
163
|
}
|
165
164
|
|
166
165
|
queues.back().set_base_transform(pimpl->base_transform);
|
167
166
|
|
167
|
+
ensure_current_context();
|
168
168
|
glClearColor(0, 0, 0, 1);
|
169
|
-
glClear(GL_COLOR_BUFFER_BIT);
|
170
|
-
|
169
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
170
|
+
|
171
171
|
current_graphics_pointer = this;
|
172
172
|
|
173
173
|
f();
|
174
174
|
|
175
|
-
//
|
176
|
-
while (
|
177
|
-
queues.pop_back();
|
178
|
-
}
|
175
|
+
// Cancel all intermediate queues that have not been cleaned up.
|
176
|
+
while (queues.size() > 1) queues.pop_back();
|
179
177
|
|
180
178
|
flush();
|
181
179
|
|
182
180
|
if (pimpl->black_height || pimpl->black_width) {
|
183
181
|
if (pimpl->black_height) {
|
184
182
|
draw_quad(0, -pimpl->black_height, Color::BLACK,
|
185
|
-
|
186
|
-
|
187
|
-
|
183
|
+
width(), -pimpl->black_height, Color::BLACK,
|
184
|
+
0, 0, Color::BLACK,
|
185
|
+
width(), 0, Color::BLACK, 0);
|
188
186
|
draw_quad(0, height(), Color::BLACK,
|
189
|
-
|
190
|
-
|
191
|
-
|
187
|
+
width(), height(), Color::BLACK,
|
188
|
+
0, height() + pimpl->black_height, Color::BLACK,
|
189
|
+
width(), height() + pimpl->black_height, Color::BLACK, 0);
|
192
190
|
}
|
193
191
|
if (pimpl->black_width) {
|
194
192
|
draw_quad(-pimpl->black_width, 0, Color::BLACK,
|
195
|
-
|
196
|
-
|
197
|
-
|
193
|
+
0, 0, Color::BLACK,
|
194
|
+
-pimpl->black_width, height(), Color::BLACK,
|
195
|
+
0, height(), Color::BLACK, 0);
|
198
196
|
draw_quad(width(), 0, Color::BLACK,
|
199
|
-
|
200
|
-
|
201
|
-
|
197
|
+
width() + pimpl->black_width, 0, Color::BLACK,
|
198
|
+
width(), height(), Color::BLACK,
|
199
|
+
width() + pimpl->black_width, height(), Color::BLACK, 0);
|
202
200
|
}
|
203
201
|
flush();
|
204
202
|
}
|
@@ -219,13 +217,13 @@ void Gosu::Graphics::frame(const function<void ()>& f)
|
|
219
217
|
|
220
218
|
void Gosu::Graphics::flush()
|
221
219
|
{
|
222
|
-
current_queue().
|
220
|
+
current_queue().perform_draw_ops_and_code();
|
223
221
|
current_queue().clear_queue();
|
224
222
|
}
|
225
223
|
|
226
224
|
void Gosu::Graphics::gl(const function<void ()>& f)
|
227
225
|
{
|
228
|
-
if (current_queue().
|
226
|
+
if (current_queue().mode() == QM_RECORD_MACRO) {
|
229
227
|
throw logic_error("Custom OpenGL is not allowed while creating a macro");
|
230
228
|
}
|
231
229
|
|
@@ -267,17 +265,53 @@ void Gosu::Graphics::clip_to(double x, double y, double width, double height,
|
|
267
265
|
current_queue().end_clipping();
|
268
266
|
}
|
269
267
|
|
270
|
-
|
271
|
-
|
268
|
+
Gosu::Image Gosu::Graphics::render(int width, int height, const function<void ()>& f)
|
269
|
+
{
|
270
|
+
ensure_current_context();
|
271
|
+
|
272
|
+
// Prepare for rendering at the requested size, but save the previous matrix and viewport.
|
273
|
+
glMatrixMode(GL_PROJECTION);
|
274
|
+
glPushMatrix();
|
275
|
+
glLoadIdentity();
|
276
|
+
GLint prev_viewport[4];
|
277
|
+
glGetIntegerv(GL_VIEWPORT, prev_viewport);
|
278
|
+
glViewport(0, 0, width, height);
|
279
|
+
// Note the flipped vertical axis in the glOrtho call - this is so we don't have to vertically
|
280
|
+
// flip the texture afterwards.
|
281
|
+
#ifdef GOSU_IS_OPENGLES
|
282
|
+
glOrthof(0, width, 0, height, -1, 1);
|
283
|
+
#else
|
284
|
+
glOrtho(0, width, 0, height, -1, 1);
|
285
|
+
#endif
|
286
|
+
|
287
|
+
// This is the actual render-to-texture step.
|
288
|
+
Image result = OffScreenTarget(width, height).render([&] {
|
289
|
+
glClearColor(0, 0, 0, 0);
|
290
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
291
|
+
queues.emplace_back(QM_RENDER_TO_SCREEN);
|
292
|
+
f();
|
293
|
+
queues.back().perform_draw_ops_and_code();
|
294
|
+
queues.pop_back();
|
295
|
+
glFlush();
|
296
|
+
});
|
297
|
+
|
298
|
+
// Restore previous matrix and glViewport.
|
299
|
+
glMatrixMode(GL_PROJECTION);
|
300
|
+
glPopMatrix();
|
301
|
+
glViewport(prev_viewport[0], prev_viewport[1], prev_viewport[2], prev_viewport[3]);
|
302
|
+
|
303
|
+
return result;
|
304
|
+
}
|
305
|
+
|
306
|
+
Gosu::Image Gosu::Graphics::record(int width, int height, const function<void ()>& f)
|
272
307
|
{
|
273
|
-
queues.
|
274
|
-
current_queue().set_recording();
|
308
|
+
queues.emplace_back(QM_RECORD_MACRO);
|
275
309
|
|
276
310
|
f();
|
277
311
|
|
278
312
|
unique_ptr<ImageData> result(new Macro(current_queue(), width, height));
|
279
313
|
queues.pop_back();
|
280
|
-
return result;
|
314
|
+
return Image(move(result));
|
281
315
|
}
|
282
316
|
|
283
317
|
void Gosu::Graphics::transform(const Gosu::Transform& transform, const function<void ()>& f)
|
@@ -386,21 +420,21 @@ unique_ptr<Gosu::ImageData> Gosu::Graphics::create_image(const Bitmap& src,
|
|
386
420
|
src_width == src_height &&
|
387
421
|
(src_width & (src_width - 1)) == 0 &&
|
388
422
|
src_width >= 64 && src_width <= max_size) {
|
389
|
-
shared_ptr<Texture> texture(new Texture(src_width, wants_retro));
|
423
|
+
shared_ptr<Texture> texture(new Texture(src_width, src_height, wants_retro));
|
390
424
|
unique_ptr<ImageData> data;
|
391
425
|
|
392
426
|
// Use the source bitmap directly if the source area completely covers
|
393
427
|
// it.
|
394
428
|
if (src_x == 0 && src_width == src.width() && src_y == 0 && src_height == src.height()) {
|
395
|
-
data = texture->try_alloc(
|
429
|
+
data = texture->try_alloc(src, 0);
|
396
430
|
}
|
397
431
|
else {
|
398
432
|
Bitmap bmp(src_width, src_height);
|
399
433
|
bmp.insert(src, 0, 0, src_x, src_y, src_width, src_height);
|
400
|
-
data = texture->try_alloc(
|
434
|
+
data = texture->try_alloc(bmp, 0);
|
401
435
|
}
|
402
436
|
|
403
|
-
if (!data
|
437
|
+
if (!data) throw logic_error("Internal texture block allocation error");
|
404
438
|
return data;
|
405
439
|
}
|
406
440
|
|
@@ -417,22 +451,21 @@ unique_ptr<Gosu::ImageData> Gosu::Graphics::create_image(const Bitmap& src,
|
|
417
451
|
apply_border_flags(bmp, src, src_x, src_y, src_width, src_height, flags);
|
418
452
|
|
419
453
|
// Try to put the bitmap into one of the already allocated textures.
|
420
|
-
for (auto texture : textures) {
|
454
|
+
for (const auto& texture : textures) {
|
421
455
|
if (texture->retro() != wants_retro) continue;
|
422
456
|
|
423
|
-
unique_ptr<ImageData> data;
|
424
|
-
|
425
|
-
if (data.get()) return data;
|
457
|
+
unique_ptr<ImageData> data = texture->try_alloc(bmp, 1);
|
458
|
+
if (data) return data;
|
426
459
|
}
|
427
460
|
|
428
461
|
// All textures are full: Create a new one.
|
429
462
|
|
430
463
|
shared_ptr<Texture> texture;
|
431
|
-
texture.reset(new Texture(max_size, wants_retro));
|
464
|
+
texture.reset(new Texture(max_size, max_size, wants_retro));
|
432
465
|
textures.push_back(texture);
|
433
466
|
|
434
467
|
unique_ptr<ImageData> data;
|
435
|
-
data = texture->try_alloc(
|
468
|
+
data = texture->try_alloc(bmp, 1);
|
436
469
|
if (!data.get()) throw logic_error("Internal texture block allocation error");
|
437
470
|
return data;
|
438
471
|
}
|