gosu 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/include/Gosu/Color.hpp +48 -100
- data/include/Gosu/Fwd.hpp +1 -1
- data/include/Gosu/Math.hpp +4 -16
- data/include/Gosu/Platform.hpp +1 -51
- data/include/Gosu/Text.hpp +37 -40
- data/include/Gosu/Version.hpp +1 -1
- data/include/Gosu/Window.hpp +2 -0
- data/lib/gosu/swig_patches.rb +31 -3
- data/rdoc/gosu.rb +9 -1
- data/src/Bitmap.cpp +13 -13
- data/src/Color.cpp +50 -46
- data/src/GosuViewController.cpp +2 -0
- data/src/LargeImageData.cpp +19 -19
- data/src/RubyGosu.cxx +386 -419
- data/src/RubyGosu.h +1 -0
- data/src/Text.cpp +31 -32
- data/src/TrueTypeFont.cpp +1 -1
- data/src/TrueTypeFontApple.cpp +0 -1
- data/src/Utility.cpp +31 -1
- data/src/WinUtility.hpp +2 -1
- data/src/Window.cpp +8 -0
- data/src/WindowUIKit.cpp +2 -2
- metadata +3 -3
data/src/RubyGosu.h
CHANGED
data/src/Text.cpp
CHANGED
@@ -1,36 +1,34 @@
|
|
1
|
+
#include "GraphicsImpl.hpp"
|
1
2
|
#include "MarkupParser.hpp"
|
2
3
|
#include "TextBuilder.hpp"
|
3
|
-
#include "GraphicsImpl.hpp"
|
4
4
|
#include "TrueTypeFont.hpp"
|
5
5
|
#include <Gosu/Text.hpp>
|
6
|
-
#include <cassert>
|
7
|
-
#include <cmath>
|
8
6
|
#include <algorithm>
|
9
|
-
#include <
|
7
|
+
#include <cmath>
|
10
8
|
#include <stdexcept>
|
11
|
-
|
9
|
+
#include <vector>
|
12
10
|
|
13
|
-
double Gosu::text_width(const u32string& text,
|
14
|
-
const string& font_name, double font_height, unsigned font_flags)
|
11
|
+
double Gosu::text_width(const std::u32string& text,
|
12
|
+
const std::string& font_name, double font_height, unsigned font_flags)
|
15
13
|
{
|
16
|
-
if (font_height <= 0) throw invalid_argument
|
17
|
-
if (font_flags >= FF_COMBINATIONS) throw invalid_argument
|
18
|
-
|
19
|
-
|
14
|
+
if (font_height <= 0) throw std::invalid_argument{"font_height must be > 0"};
|
15
|
+
if (font_flags >= FF_COMBINATIONS) throw std::invalid_argument{"Invalid font_flags"};
|
16
|
+
|
17
|
+
TrueTypeFont& font = font_by_name(font_name, font_flags);
|
20
18
|
return font.draw_text(text, font_height, nullptr, 0, 0, Gosu::Color::NONE);
|
21
19
|
}
|
22
20
|
|
23
|
-
double Gosu::draw_text(Bitmap& bitmap, double x, double y, Color c, const u32string& text,
|
24
|
-
const string& font_name, double font_height, unsigned font_flags)
|
21
|
+
double Gosu::draw_text(Bitmap& bitmap, double x, double y, Color c, const std::u32string& text,
|
22
|
+
const std::string& font_name, double font_height, unsigned font_flags)
|
25
23
|
{
|
26
|
-
if (font_height <= 0) throw invalid_argument("font_height must be > 0");
|
27
|
-
if (font_flags >= FF_COMBINATIONS) throw invalid_argument("Invalid font_flags");
|
24
|
+
if (font_height <= 0) throw std::invalid_argument("font_height must be > 0");
|
25
|
+
if (font_flags >= FF_COMBINATIONS) throw std::invalid_argument("Invalid font_flags");
|
28
26
|
|
29
|
-
|
27
|
+
TrueTypeFont& font = font_by_name(font_name, font_flags);
|
30
28
|
return font.draw_text(text, font_height, &bitmap, x, y, c);
|
31
29
|
}
|
32
30
|
|
33
|
-
Gosu::Bitmap Gosu::layout_text(const string& text, const string& font_name,
|
31
|
+
Gosu::Bitmap Gosu::layout_text(const std::string& text, const std::string& font_name,
|
34
32
|
double font_height, double line_spacing,
|
35
33
|
int width, Alignment align, unsigned font_flags)
|
36
34
|
{
|
@@ -40,55 +38,56 @@ Gosu::Bitmap Gosu::layout_text(const string& text, const string& font_name,
|
|
40
38
|
width, align, font_flags);
|
41
39
|
}
|
42
40
|
|
43
|
-
Gosu::Bitmap Gosu::layout_markup(const string& markup, const string& font_name,
|
41
|
+
Gosu::Bitmap Gosu::layout_markup(const std::string& markup, const std::string& font_name,
|
44
42
|
double font_height, double line_spacing,
|
45
43
|
int width, Alignment align, unsigned font_flags)
|
46
44
|
{
|
47
|
-
if (font_height <= 0) throw invalid_argument
|
48
|
-
if (line_spacing < -font_height) throw invalid_argument
|
49
|
-
if (font_flags >= FF_COMBINATIONS) throw invalid_argument
|
45
|
+
if (font_height <= 0) throw std::invalid_argument{"font_height must be > 0"};
|
46
|
+
if (line_spacing < -font_height) throw std::invalid_argument{"line_spacing must be ≥ -font_height"};
|
47
|
+
if (font_flags >= FF_COMBINATIONS) throw std::invalid_argument{"Invalid font_flags"};
|
50
48
|
|
51
49
|
if (width >= 0) {
|
52
|
-
TextBuilder text_builder
|
50
|
+
TextBuilder text_builder{font_name, static_cast<int>(font_height),
|
51
|
+
static_cast<int>(line_spacing), width, align};
|
53
52
|
|
54
53
|
// Feed all formatted substrings to the TextBuilder, which will construct the result.
|
55
54
|
// Split the input string into words, because this method implements word-wrapping.
|
56
|
-
MarkupParser parser
|
55
|
+
MarkupParser parser{font_flags, true, [&text_builder](std::vector<FormattedString> word) {
|
57
56
|
text_builder.feed_word(move(word));
|
58
|
-
}
|
57
|
+
}};
|
59
58
|
parser.parse(markup);
|
60
59
|
|
61
60
|
return text_builder.move_into_bitmap();
|
62
61
|
}
|
63
62
|
else {
|
64
|
-
vector<vector<FormattedString>> lines;
|
63
|
+
std::vector<std::vector<FormattedString>> lines;
|
65
64
|
|
66
65
|
// Split the text into lines (split_words = false) since this method does not wrap lines.
|
67
|
-
MarkupParser parser
|
66
|
+
MarkupParser parser{font_flags, false, [&lines](std::vector<FormattedString>&& line) {
|
68
67
|
// Remove trailing \n characters from each line to avoid errors from Gosu::text_width().
|
69
|
-
if (line.back().text.back() == '\n') {
|
68
|
+
if (!line.back().text.empty() && line.back().text.back() == '\n') {
|
70
69
|
line.back().text.pop_back();
|
71
70
|
}
|
72
71
|
|
73
72
|
lines.emplace_back(line);
|
74
|
-
}
|
73
|
+
}};
|
75
74
|
parser.parse(markup);
|
76
75
|
|
77
76
|
if (lines.empty()) return Bitmap();
|
78
77
|
|
79
78
|
// Measure every part of every line.
|
80
|
-
vector<double> line_widths;
|
79
|
+
std::vector<double> line_widths;
|
81
80
|
double max_width = 0;
|
82
81
|
for (auto& line : lines) {
|
83
82
|
line_widths.push_back(0);
|
84
83
|
for (auto& part : line) {
|
85
84
|
line_widths.back() += text_width(part.text, font_name, font_height, part.flags);
|
86
85
|
}
|
87
|
-
max_width = max(max_width, line_widths.back());
|
86
|
+
max_width = std::max(max_width, line_widths.back());
|
88
87
|
}
|
89
88
|
|
90
|
-
double height = lines.size() * font_height + (lines.size() - 1) * line_spacing;
|
91
|
-
Bitmap result(ceil(max_width), ceil(height));
|
89
|
+
double height = lines.size() * font_height + (lines.size() - 1.0) * line_spacing;
|
90
|
+
Bitmap result{static_cast<int>(std::ceil(max_width)), static_cast<int>(std::ceil(height))};
|
92
91
|
|
93
92
|
// Render every part of every line.
|
94
93
|
double y = 0;
|
data/src/TrueTypeFont.cpp
CHANGED
@@ -182,7 +182,7 @@ struct Gosu::TrueTypeFont::Impl
|
|
182
182
|
for (int rel_y = 0; rel_y < h; ++rel_y) {
|
183
183
|
for (int rel_x = 0; rel_x < w; ++rel_x) {
|
184
184
|
int pixel = pixels[(src_y + rel_y) * stride + src_x + rel_x];
|
185
|
-
Color c_with_alpha(pixel * c.alpha
|
185
|
+
Color c_with_alpha = c.with_alpha(pixel * c.alpha / 255);
|
186
186
|
bitmap.blend_pixel(x + rel_x, y + rel_y, c_with_alpha);
|
187
187
|
}
|
188
188
|
}
|
data/src/TrueTypeFontApple.cpp
CHANGED
data/src/Utility.cpp
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
#include <Gosu/Platform.hpp>
|
1
2
|
#include <Gosu/Utility.hpp>
|
2
3
|
|
3
|
-
#include <SDL.h>
|
4
4
|
#include <utf8proc.h>
|
5
5
|
|
6
6
|
#include <cstring>
|
@@ -66,7 +66,33 @@ bool Gosu::has_extension(std::string_view filename, std::string_view extension)
|
|
66
66
|
return true;
|
67
67
|
}
|
68
68
|
|
69
|
+
#ifdef GOSU_IS_IPHONE
|
70
|
+
#import <Foundation/Foundation.h>
|
71
|
+
#include <regex>
|
72
|
+
|
73
|
+
std::vector<std::string> Gosu::user_languages()
|
74
|
+
{
|
75
|
+
static const std::regex language_regex{"([a-z]{2})-([A-Z]{2})([^A-Z].*)?"};
|
76
|
+
|
77
|
+
std::vector<std::string> user_languages;
|
78
|
+
|
79
|
+
@autoreleasepool {
|
80
|
+
for (NSString* language in [NSLocale preferredLanguages]) {
|
81
|
+
std::string language_str = language.UTF8String;
|
82
|
+
std::smatch match;
|
83
|
+
if (std::regex_match(language_str, match, language_regex)) {
|
84
|
+
user_languages.push_back(match.str(1) + "_" + match.str(2));
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
return user_languages;
|
90
|
+
}
|
91
|
+
|
92
|
+
#else
|
93
|
+
#include <SDL.h>
|
69
94
|
#if SDL_VERSION_ATLEAST(2, 0, 14)
|
95
|
+
|
70
96
|
std::vector<std::string> Gosu::user_languages()
|
71
97
|
{
|
72
98
|
std::vector<std::string> user_languages;
|
@@ -85,6 +111,7 @@ std::vector<std::string> Gosu::user_languages()
|
|
85
111
|
|
86
112
|
return user_languages;
|
87
113
|
}
|
114
|
+
|
88
115
|
#else
|
89
116
|
#include <cstdlib>
|
90
117
|
#include <regex>
|
@@ -96,9 +123,12 @@ std::vector<std::string> Gosu::user_languages()
|
|
96
123
|
const char* locale = std::getenv("LANG");
|
97
124
|
|
98
125
|
if (locale && std::regex_match(locale, language_regex)) {
|
126
|
+
// Trim off anything after the language code.
|
99
127
|
return {std::string{locale, locale + 5}};
|
100
128
|
}
|
101
129
|
|
102
130
|
return {};
|
103
131
|
}
|
132
|
+
|
133
|
+
#endif
|
104
134
|
#endif
|
data/src/WinUtility.hpp
CHANGED
@@ -12,7 +12,8 @@ namespace Gosu
|
|
12
12
|
|
13
13
|
//! Throws an exception according to the error returned by GetLastError(), optionally prefixed
|
14
14
|
//! with "While (action), the following error occured: ".
|
15
|
-
|
15
|
+
[[noreturn]]
|
16
|
+
void throw_last_winapi_error(const std::string& action = "");
|
16
17
|
|
17
18
|
//! Small helper function that throws the last Windows error when val_to_check is false.
|
18
19
|
template<typename T>
|
data/src/Window.cpp
CHANGED
data/src/WindowUIKit.cpp
CHANGED
@@ -25,8 +25,8 @@ Gosu::Window::Window(int width, int height, unsigned window_flags, double update
|
|
25
25
|
pimpl->controller.gosuWindow = this;
|
26
26
|
pimpl->window.rootViewController = pimpl->controller;
|
27
27
|
|
28
|
-
// It is important to load the view before creating the Graphics instance.
|
29
|
-
[pimpl->controller
|
28
|
+
// It is important to (implicitly) load the view before creating the Graphics instance.
|
29
|
+
[pimpl->controller view];
|
30
30
|
|
31
31
|
pimpl->graphics.reset(new Graphics(screen_width(), screen_height()));
|
32
32
|
pimpl->graphics->set_resolution(width, height);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gosu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Raschke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
2D game development library.
|
@@ -314,7 +314,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
314
314
|
- !ruby/object:Gem::Version
|
315
315
|
version: '0'
|
316
316
|
requirements: []
|
317
|
-
rubygems_version: 3.
|
317
|
+
rubygems_version: 3.2.22
|
318
318
|
signing_key:
|
319
319
|
specification_version: 4
|
320
320
|
summary: 2D game development library.
|