gosu 1.1.0 → 1.1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/COPYING +1 -1
- data/ext/gosu/extconf.rb +5 -1
- data/include/Gosu/Font.hpp +3 -5
- data/include/Gosu/Text.hpp +4 -4
- data/include/Gosu/Version.hpp +1 -1
- data/src/Macro.cpp +98 -141
- data/src/Resolution.cpp +107 -59
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 444c045288619f5db21634cb5bbdd24bf16c93799d16dc84147cab982282804b
|
4
|
+
data.tar.gz: cab4e8823a7b19893cfd3f5b280176ed2b99f76c76278859fe5957bec8aa283a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4c1168ca82b6e0c969ca8943469010d1eeadc32908ac3b78fc4b61567e0905076dedc2e4509bb55abedccf9ba4f3ccf79ae900093f1de996112548bc0fbad31
|
7
|
+
data.tar.gz: 6f7b1cea866fecc2b8bde836790f684fff6990dc89844a66f7a304f7f405625a33200bb6ffe2db987444ecc53e7a8ddee26cb75f7e77f7891393fd564e2ae81b
|
data/COPYING
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (C) 2001-
|
1
|
+
Copyright (C) 2001-2021 Julian Raschke, Jan Lücker and all contributors.
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a
|
4
4
|
copy of this software and associated documentation files (the "Software"),
|
data/ext/gosu/extconf.rb
CHANGED
@@ -51,7 +51,7 @@ if windows
|
|
51
51
|
else
|
52
52
|
$LDFLAGS << " -L../../dependencies/al_soft/x86 -L../../dependencies/SDL/lib/x86"
|
53
53
|
end
|
54
|
-
$LDFLAGS << " -lgdi32 -lwinmm -lOpenGL32 -lOpenAL32 -lSDL2"
|
54
|
+
$LDFLAGS << " -lgdi32 -lwinmm -ldwmapi -lOpenGL32 -lOpenAL32 -lSDL2"
|
55
55
|
# Link libstdc++ statically to avoid having another DLL dependency when using Ocra.
|
56
56
|
$LDFLAGS << " -static-libstdc++"
|
57
57
|
elsif macos
|
@@ -62,6 +62,10 @@ elsif macos
|
|
62
62
|
# rvm will sometimes try to override this:
|
63
63
|
# https://github.com/shawn42/gamebox/issues/96
|
64
64
|
$CXXFLAGS << " -stdlib=libc++"
|
65
|
+
|
66
|
+
# Disable an error that is disabled by default and prevents Gosu from building with universal Ruby:
|
67
|
+
# https://trac.macports.org/ticket/58255 / https://github.com/gosu/gosu/issues/424
|
68
|
+
$CXXFLAGS << " -Wno-reserved-user-defined-literal"
|
65
69
|
|
66
70
|
# Dependencies.
|
67
71
|
$CFLAGS << " #{`sdl2-config --cflags`.chomp}"
|
data/include/Gosu/Font.hpp
CHANGED
@@ -22,11 +22,9 @@ namespace Gosu
|
|
22
22
|
|
23
23
|
public:
|
24
24
|
//! Constructs a font that can be drawn onto the graphics object.
|
25
|
-
//! \param
|
26
|
-
//!
|
27
|
-
//! \param
|
28
|
-
//! \param font_flags Flags used to render individual characters of
|
29
|
-
//! the font.
|
25
|
+
//! \param name Name of a system font, or a filename to a TTF file.
|
26
|
+
//! \param height Height of the font, in pixels.
|
27
|
+
//! \param flags Flags used to render individual characters of the font.
|
30
28
|
Font(int height, const std::string& name = default_font_name(), unsigned flags = 0);
|
31
29
|
|
32
30
|
//! Returns the name of the font that was used to create it.
|
data/include/Gosu/Text.hpp
CHANGED
@@ -20,7 +20,7 @@ namespace Gosu
|
|
20
20
|
double text_width(const std::u32string& text, const std::string& font_name, double font_height,
|
21
21
|
unsigned font_flags = 0);
|
22
22
|
|
23
|
-
//! Draws a line of
|
23
|
+
//! Draws a line of plain text on a bitmap. This is a low-level function that does not
|
24
24
|
//! understand any of Gosu's HTML-like markup.
|
25
25
|
//! \param text A UCS-4 string, normalization: NFC.
|
26
26
|
//! \param font_name Name of a system font, or filename of a TTF file (must contain '/' or '.').
|
@@ -29,9 +29,9 @@ namespace Gosu
|
|
29
29
|
double draw_text(Bitmap& bitmap, double x, double y, Color c, const std::u32string& text,
|
30
30
|
const std::string& font_name, double font_height, unsigned font_flags = 0);
|
31
31
|
|
32
|
-
//! Creates a bitmap that is filled with the
|
32
|
+
//! Creates a bitmap that is filled with the plain text given to the function.
|
33
33
|
//! The line can contain line breaks and HTML-like markup.
|
34
|
-
//! \param text
|
34
|
+
//! \param text Plain text.
|
35
35
|
//! \param font_name Name of a system font, or filename of a TTF file (must contain '/' or '.').
|
36
36
|
//! \param font_height Height of the font in pixels.
|
37
37
|
//! \param line_spacing Spacing between two lines of text in pixels. Can be negative to make
|
@@ -48,7 +48,7 @@ namespace Gosu
|
|
48
48
|
|
49
49
|
//! Creates a bitmap that is filled with the formatted text given to the function.
|
50
50
|
//! The line can contain line breaks and HTML-like markup.
|
51
|
-
//! \param
|
51
|
+
//! \param markup Formatted text.
|
52
52
|
//! \param font_name Name of a system font, or filename of a TTF file (must contain '/' or '.').
|
53
53
|
//! \param font_height Height of the font in pixels.
|
54
54
|
//! \param line_spacing Spacing between two lines of text in pixels. Can be negative to make
|
data/include/Gosu/Version.hpp
CHANGED
data/src/Macro.cpp
CHANGED
@@ -1,168 +1,125 @@
|
|
1
1
|
#include "Macro.hpp"
|
2
2
|
#include "DrawOpQueue.hpp"
|
3
3
|
#include <Gosu/Image.hpp>
|
4
|
-
#include <cmath>
|
5
|
-
#include <algorithm>
|
6
|
-
#include <functional>
|
7
|
-
#include <memory>
|
8
4
|
#include <stdexcept>
|
9
5
|
using namespace std;
|
10
6
|
|
11
7
|
struct Gosu::Macro::Impl
|
12
8
|
{
|
13
|
-
typedef double Float;
|
14
|
-
|
15
9
|
VertexArrays vertex_arrays;
|
16
10
|
int width, height;
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
|
12
|
+
// Solves the 2x2 linear system for x:
|
13
|
+
// (a11 a12) (x1) = (b1)
|
14
|
+
// (a21 a22) (x2) = (b2)
|
15
|
+
// x1, x2 are output parameters. Returns false if the matrix is singular.
|
16
|
+
static bool solve_2x2(double a11, double a12, double a21, double a22, double b1, double b2,
|
17
|
+
double& x1, double& x2)
|
18
|
+
{
|
19
|
+
const double det = a11 * a22 - a21 * a12;
|
20
|
+
if (det == 0) return false;
|
21
|
+
x1 = (a22 * b1 - a12 * b2) / det;
|
22
|
+
x2 = (a11 * b2 - a21 * b1) / det;
|
23
|
+
return true;
|
24
|
+
}
|
25
|
+
|
26
|
+
Transform find_transform_for_target(double x1, double y1, double x2, double y2,
|
27
|
+
double x3, double y3, double x4, double y4) const
|
20
28
|
{
|
21
29
|
// Transformation logic follows a discussion on the ImageMagick mailing
|
22
30
|
// list (on which ImageMagick's perspective_transform.pl is based).
|
23
|
-
|
31
|
+
|
24
32
|
// To draw a macro at an arbitrary position, we solve the following system:
|
25
|
-
|
26
|
-
// 0, 0, 1, 0, 0, 0,
|
27
|
-
// 0, 0, 0, 0, 0, 1,
|
28
|
-
// w, 0, 1, 0, 0, 0, -
|
29
|
-
// 0, 0, 0, w, 0, 1, -
|
30
|
-
// 0, h, 1, 0, 0, 0,
|
31
|
-
// 0, 0, 0, 0, h, 1,
|
32
|
-
// w, h, 1, 0, 0, 0, -
|
33
|
-
// 0, 0, 0, w, h, 1, -
|
34
|
-
|
33
|
+
|
34
|
+
// 0, 0, 1, 0, 0, 0, 0, 0 | x1
|
35
|
+
// 0, 0, 0, 0, 0, 1, 0, 0 | y1
|
36
|
+
// w, 0, 1, 0, 0, 0, -x2 w, 0 | x2
|
37
|
+
// 0, 0, 0, w, 0, 1, -y2 w, 0 | y2
|
38
|
+
// 0, h, 1, 0, 0, 0, 0, -x3 h | x3
|
39
|
+
// 0, 0, 0, 0, h, 1, 0, -y3 h | y3
|
40
|
+
// w, h, 1, 0, 0, 0, -x4 w, -x4 h | x4
|
41
|
+
// 0, 0, 0, w, h, 1, -y4 w, -y4 h | y4
|
42
|
+
|
35
43
|
// Equivalent:
|
36
|
-
|
37
|
-
// 0, 0, 1, 0, 0, 0,
|
38
|
-
// 0, 0, 0, 0, 0, 1,
|
39
|
-
// w, 0, 0, 0, 0, 0, -
|
40
|
-
// 0, 0, 0, w, 0, 0, -
|
41
|
-
// 0, h, 0, 0, 0, 0,
|
42
|
-
// 0, 0, 0, 0, h, 0,
|
43
|
-
// 0, 0, 0, 0, 0, 0, (x2-x4)w, (x3-x4)h | x1-x2-x3+x4
|
44
|
-
// 0, 0, 0, 0, 0, 0, (y2-y4)w, (y3-y4)h | y1-y2-y3+y4
|
45
|
-
|
46
|
-
//
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
//
|
44
|
+
|
45
|
+
// 0, 0, 1, 0, 0, 0, 0, 0 | x1
|
46
|
+
// 0, 0, 0, 0, 0, 1, 0, 0 | y1
|
47
|
+
// w, 0, 0, 0, 0, 0, -x2 w, 0 | x2-x1
|
48
|
+
// 0, 0, 0, w, 0, 0, -y2 w, 0 | y2-y1
|
49
|
+
// 0, h, 0, 0, 0, 0, 0, -x3 h | x3-x1
|
50
|
+
// 0, 0, 0, 0, h, 0, 0, -y3 h | y3-y1
|
51
|
+
// 0, 0, 0, 0, 0, 0, (x2-x4) w, (x3-x4) h | x1-x2-x3+x4
|
52
|
+
// 0, 0, 0, 0, 0, 0, (y2-y4) w, (y3-y4) h | y1-y2-y3+y4
|
53
|
+
|
54
|
+
// The last two rows only involve the last two variables.
|
55
|
+
// We can directly solve this as a separate 2x2 linear system.
|
56
|
+
|
57
|
+
// Set up 2x2 linear system of the lower right corner entries.
|
58
|
+
const double a11 = (x2 - x4) * width;
|
59
|
+
const double a12 = (x3 - x4) * height;
|
60
|
+
const double a21 = (y2 - y4) * width;
|
61
|
+
const double a22 = (y3 - y4) * height;
|
62
|
+
const double b1 = x1 - x2 - x3 + x4;
|
63
|
+
const double b2 = y1 - y2 - y3 + y4;
|
64
|
+
|
65
|
+
// Solve:
|
66
|
+
double qx, qy;
|
67
|
+
if (!solve_2x2(a11, a12, a21, a22, b1, b2, qx, qy)) return Transform{{0}};
|
68
|
+
|
69
|
+
// Updating the last two rows with the computed solution yields
|
70
|
+
|
71
|
+
// 0, 0, 1, 0, 0, 0, 0, 0 | x1
|
72
|
+
// 0, 0, 0, 0, 0, 1, 0, 0 | y1
|
73
|
+
// w, 0, 0, 0, 0, 0, -x2 w, 0 | x2-x1
|
74
|
+
// 0, 0, 0, w, 0, 0, -y2 w, 0 | y2-y1
|
75
|
+
// 0, h, 0, 0, 0, 0, 0, -x3 h | x3-x1
|
76
|
+
// 0, 0, 0, 0, h, 0, 0, -y3 h | y3-y1
|
77
|
+
// 0, 0, 0, 0, 0, 0, 1, 0 | qx
|
78
|
+
// 0, 0, 0, 0, 0, 0, 0, 1 | qy
|
79
|
+
|
80
|
+
// We can use the last two rows to eliminate entries in rows 3, 4, 5, and 6:
|
81
|
+
|
82
|
+
// 0, 0, 1, 0, 0, 0, 0, 0 | x1
|
83
|
+
// 0, 0, 0, 0, 0, 1, 0, 0 | y1
|
84
|
+
// w, 0, 0, 0, 0, 0, 0, 0 | x2-x1 + qx x2 w
|
85
|
+
// 0, 0, 0, w, 0, 0, 0, 0 | y2-y1 + qx y2 w
|
86
|
+
// 0, h, 0, 0, 0, 0, 0, 0 | x3-x1 + qy x3 h
|
87
|
+
// 0, 0, 0, 0, h, 0, 0, 0 | y3-y1 + qy y3 h
|
88
|
+
// 0, 0, 0, 0, 0, 0, 1, 0 | qx
|
89
|
+
// 0, 0, 0, 0, 0, 0, 0, 1 | qy
|
90
|
+
|
91
|
+
// Normalize and reorder rows so we can read off the solution:
|
92
|
+
|
93
|
+
// 1, 0, 0, 0, 0, 0, 0, 0 | (x2-x1) / w + qx x2
|
94
|
+
// 0, 1, 0, 0, 0, 0, 0, 0 | (x3-x1) / h + qy x3
|
95
|
+
// 0, 0, 1, 0, 0, 0, 0, 0 | x1
|
96
|
+
// 0, 0, 0, 1, 0, 0, 0, 0 | (y2-y1) / w + qx y2
|
97
|
+
// 0, 0, 0, 0, 1, 0, 0, 0 | (y3-y1) / h + qy y3
|
98
|
+
// 0, 0, 0, 0, 0, 1, 0, 0 | y1
|
99
|
+
// 0, 0, 0, 0, 0, 0, 1, 0 | qx
|
100
|
+
// 0, 0, 0, 0, 0, 0, 0, 1 | qy
|
101
|
+
|
102
|
+
double c[8];
|
103
|
+
c[0] = (x2 - x1) / width + qx * x2;
|
104
|
+
c[1] = (x3 - x1) / height + qy * x3;
|
62
105
|
c[2] = x1;
|
106
|
+
c[3] = (y2 - y1) / width + qx * y2;
|
107
|
+
c[4] = (y3 - y1) / height + qy * y3;
|
63
108
|
c[5] = y1;
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
// If x2 == x4, we need to exchange rows 7 and 8.
|
68
|
-
|
69
|
-
// TODO: x2==x4 is the normal case where an image is
|
70
|
-
// drawn upright; the code should rather swap in the rare case that x3==x4!
|
71
|
-
|
72
|
-
Float left_cell7 = (x2 - x4) * width;
|
73
|
-
Float right_cell7 = (x3 - x4) * height;
|
74
|
-
Float orig_right_side7 = (x1 - x2 - x3 + x4);
|
75
|
-
Float left_cell8 = (y2 - y4) * width;
|
76
|
-
Float right_cell8 = (y3 - y4) * height;
|
77
|
-
Float orig_right_side8 = (y1 - y2 - y3 + y4);
|
78
|
-
|
79
|
-
bool swap_rows78 = x2 == x4;
|
80
|
-
if (swap_rows78) {
|
81
|
-
swap(left_cell7, left_cell8);
|
82
|
-
swap(right_cell7, right_cell8);
|
83
|
-
swap(orig_right_side7, orig_right_side8);
|
84
|
-
}
|
85
|
-
|
86
|
-
// 0, 0, 1, 0, 0, 0, 0, 0 | x1
|
87
|
-
// 0, 0, 0, 0, 0, 1, 0, 0 | y1
|
88
|
-
// w, 0, 0, 0, 0, 0, -x2w, 0 | x2-x1
|
89
|
-
// 0, 0, 0, w, 0, 0, -y2w, 0 | y2-y1
|
90
|
-
// 0, h, 0, 0, 0, 0, 0, -x3h | x3-x1
|
91
|
-
// 0, 0, 0, 0, h, 0, 0, -y3h | y3-y1
|
92
|
-
// 0, 0, 0, 0, 0, 0, left_cell7, right_cell7 | orig_right_side7
|
93
|
-
// 0, 0, 0, 0, 0, 0, left_cell8, right_cell8 | orig_right_side8
|
94
|
-
|
95
|
-
// Use row 7 to eliminate the left cell in row 8
|
96
|
-
// Row8 = Row8 - factor78 * Row7
|
97
|
-
Float factor78 = left_cell8 / left_cell7;
|
98
|
-
Float rem_cell8 = right_cell8 - right_cell7 * factor78;
|
99
|
-
Float right_side8 = orig_right_side8 - orig_right_side7 * factor78;
|
100
|
-
c[7] = right_side8 / rem_cell8;
|
101
|
-
|
102
|
-
// 0, 0, 1, 0, 0, 0, 0, 0 | x1
|
103
|
-
// 0, 0, 0, 0, 0, 1, 0, 0 | y1
|
104
|
-
// w, 0, 0, 0, 0, 0, -x2w, 0 | x2-x1
|
105
|
-
// 0, 0, 0, w, 0, 0, -y2w, 0 | y2-y1
|
106
|
-
// 0, h, 0, 0, 0, 0, 0, -x3h | x3-x1
|
107
|
-
// 0, 0, 0, 0, h, 0, 0, -y3h | y3-y1
|
108
|
-
// 0, 0, 0, 0, 0, 0, left_cell7, right_cell7 | orig_right_side7
|
109
|
-
// 0, 0, 0, 0, 0, 0, 0, rem_cell8 | right_side8
|
110
|
-
|
111
|
-
// Use the remaining value in row 8 to eliminate the right value in row 7.
|
112
|
-
// Row7 = Row7 - factor87 * Row8
|
113
|
-
Float factor87 = right_cell7 / rem_cell8;
|
114
|
-
Float rem_cell7 = left_cell7;
|
115
|
-
Float right_side7 = orig_right_side7 - right_side8 * factor87;
|
116
|
-
c[6] = right_side7 / rem_cell7;
|
117
|
-
|
118
|
-
// 0, 0, 1, 0, 0, 0, 0, 0 | x1
|
119
|
-
// 0, 0, 0, 0, 0, 1, 0, 0 | y1
|
120
|
-
// w, 0, 0, 0, 0, 0, -x2w, 0 | x2-x1
|
121
|
-
// 0, 0, 0, w, 0, 0, -y2w, 0 | y2-y1
|
122
|
-
// 0, h, 0, 0, 0, 0, 0, -x3h | x3-x1
|
123
|
-
// 0, 0, 0, 0, h, 0, 0, -y3h | y3-y1
|
124
|
-
// 0, 0, 0, 0, 0, 0, rem_cell7, 0 | right_side7
|
125
|
-
// 0, 0, 0, 0, 0, 0, 0, rem_cell8 | right_side8
|
126
|
-
|
127
|
-
// Use the new rows 7 and 8 to calculate c0, c1, c3 & c4.
|
128
|
-
// Row3 = Row3 - factor73 * Row7
|
129
|
-
Float factor73 = -x2 * width / rem_cell7;
|
130
|
-
Float rem_cell3 = width;
|
131
|
-
Float right_side3 = (x2 - x1) - right_side7 * factor73;
|
132
|
-
c[0] = right_side3 / rem_cell3;
|
133
|
-
// Row4 = Row4 - factor74 * Row7
|
134
|
-
Float factor74 = -y2 * width / rem_cell7;
|
135
|
-
Float rem_cell4 = width;
|
136
|
-
Float right_side4 = (y2 - y1) - right_side7 * factor74;
|
137
|
-
c[3] = right_side4 / rem_cell4;
|
138
|
-
// Row5 = Row5 - factor85 * Row7
|
139
|
-
Float factor85 = -x3 * height / rem_cell8;
|
140
|
-
Float rem_cell5 = height;
|
141
|
-
Float right_side5 = (x3 - x1) - right_side8 * factor85;
|
142
|
-
c[1] = right_side5 / rem_cell5;
|
143
|
-
// Row6 = Row6 - factor86 * Row8
|
144
|
-
Float factor86 = -y3 * height / rem_cell8;
|
145
|
-
Float rem_cell6 = height;
|
146
|
-
Float right_side6 = (y3 - y1) - right_side8 * factor86;
|
147
|
-
c[4] = right_side6 / rem_cell6;
|
148
|
-
|
149
|
-
if (swap_rows78) {
|
150
|
-
swap(c[6], c[7]);
|
151
|
-
}
|
152
|
-
|
153
|
-
// Let's hope I never have to debug/understand this again! :D
|
154
|
-
|
109
|
+
c[6] = qx;
|
110
|
+
c[7] = qy;
|
111
|
+
|
155
112
|
Transform result = {{
|
156
113
|
c[0], c[3], 0, c[6],
|
157
114
|
c[1], c[4], 0, c[7],
|
158
|
-
0,
|
115
|
+
0, 0, 1, 0,
|
159
116
|
c[2], c[5], 0, 1
|
160
117
|
}};
|
161
118
|
return result;
|
162
119
|
}
|
163
|
-
|
164
|
-
void draw_vertex_arrays(
|
165
|
-
|
120
|
+
|
121
|
+
void draw_vertex_arrays(double x1, double y1, double x2, double y2, double x3, double y3,
|
122
|
+
double x4, double y4) const
|
166
123
|
{
|
167
124
|
// TODO: Macros should not be split up just because they have different transforms.
|
168
125
|
// They should be premultiplied and have the same transform by definition. Then the
|
data/src/Resolution.cpp
CHANGED
@@ -11,7 +11,7 @@ static SDL_DisplayMode display_mode(Gosu::Window* window)
|
|
11
11
|
VideoSubsystem() { SDL_InitSubSystem(SDL_INIT_VIDEO); };
|
12
12
|
~VideoSubsystem() { SDL_QuitSubSystem(SDL_INIT_VIDEO); };
|
13
13
|
} subsystem;
|
14
|
-
|
14
|
+
|
15
15
|
int index = window ? SDL_GetWindowDisplayIndex(Gosu::shared_window()) : 0;
|
16
16
|
SDL_DisplayMode result;
|
17
17
|
SDL_GetDesktopDisplayMode(index, &result);
|
@@ -31,88 +31,136 @@ int Gosu::screen_height(Window* window)
|
|
31
31
|
#ifdef GOSU_IS_MAC
|
32
32
|
#import <AppKit/AppKit.h>
|
33
33
|
|
34
|
-
static
|
34
|
+
static SDL_Rect max_window_size(Gosu::Window* window)
|
35
35
|
{
|
36
|
-
//
|
37
|
-
|
36
|
+
// The extra size that a window needs depends on its style.
|
37
|
+
// This logic must be kept in sync with SDL_cocoawindow.m to be 100% accurate.
|
38
|
+
NSUInteger style;
|
39
|
+
if (window && window->borderless()) {
|
40
|
+
style = NSWindowStyleMaskBorderless;
|
41
|
+
}
|
42
|
+
else {
|
43
|
+
style = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable;
|
44
|
+
}
|
45
|
+
if (window && window->resizable()) {
|
46
|
+
style |= NSWindowStyleMaskResizable;
|
47
|
+
}
|
38
48
|
|
39
49
|
auto index = window ? SDL_GetWindowDisplayIndex(Gosu::shared_window()) : 0;
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
int Gosu::available_height(Window* window)
|
50
|
-
{
|
51
|
-
return max_window_size(window).height;
|
50
|
+
NSRect screen_frame = NSScreen.screens[index].visibleFrame;
|
51
|
+
NSRect content_rect = [NSWindow contentRectForFrameRect:screen_frame styleMask:style];
|
52
|
+
|
53
|
+
SDL_Rect result;
|
54
|
+
result.x = 0;
|
55
|
+
result.y = 0;
|
56
|
+
result.w = content_rect.size.width;
|
57
|
+
result.h = content_rect.size.height;
|
58
|
+
return result;
|
52
59
|
}
|
53
60
|
#endif
|
54
61
|
|
62
|
+
// TODO: Remove this implementation and remove ifdef for GOSU_IS_X once WIN_GetWindowBordersSize is patched
|
55
63
|
#ifdef GOSU_IS_WIN
|
56
64
|
#include <windows.h>
|
57
65
|
#include <SDL_syswm.h>
|
66
|
+
#include <dwmapi.h>
|
67
|
+
#pragma comment (lib, "Dwmapi.lib")
|
58
68
|
|
59
|
-
static
|
69
|
+
static SDL_Rect max_window_size(Gosu::Window* window)
|
60
70
|
{
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
71
|
+
// Replicate SDL's WIN_GetWindowBordersSize implementation (https://github.com/libsdl-org/SDL/blob/9f71a809e9bd6fbb5fa401a45c1537fc26abc1b4/src/video/windows/SDL_windowswindow.c#L514-L554)
|
72
|
+
// until it's patched to ignore the window drop shadow (window border is 1px but with drop shadow it's reported as 8px)
|
73
|
+
// REF: https://github.com/libsdl-org/SDL/issues/3835
|
74
|
+
|
75
|
+
static struct VideoSubsystem {
|
76
|
+
VideoSubsystem() { SDL_InitSubSystem(SDL_INIT_VIDEO); };
|
77
|
+
~VideoSubsystem() { SDL_QuitSubSystem(SDL_INIT_VIDEO); };
|
78
|
+
} subsystem;
|
79
|
+
|
80
|
+
int index = window ? SDL_GetWindowDisplayIndex(Gosu::shared_window()) : 0;
|
81
|
+
SDL_Rect rect;
|
82
|
+
SDL_GetDisplayUsableBounds(index, &rect);
|
83
|
+
|
84
|
+
if (window) {
|
85
|
+
SDL_SysWMinfo info;
|
86
|
+
SDL_VERSION(&info.version);
|
87
|
+
SDL_GetWindowWMInfo(Gosu::shared_window(), &info);
|
88
|
+
HWND hwnd = info.info.win.window;
|
89
|
+
|
90
|
+
RECT rcClient, rcWindow;
|
91
|
+
POINT ptDiff;
|
92
|
+
int top = 0, left = 0, bottom = 0, right = 0;
|
93
|
+
|
94
|
+
/* rcClient stores the size of the inner window, while rcWindow stores the outer size relative to the top-left
|
95
|
+
* screen position; so the top/left values of rcClient are always {0,0} and bottom/right are {height,width} */
|
96
|
+
GetClientRect(hwnd, &rcClient);
|
97
|
+
DwmGetWindowAttribute(hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, &rcWindow, sizeof(rcWindow));
|
98
|
+
|
99
|
+
/* convert the top/left values to make them relative to
|
100
|
+
* the window; they will end up being slightly negative */
|
101
|
+
ptDiff.y = rcWindow.top;
|
102
|
+
ptDiff.x = rcWindow.left;
|
103
|
+
|
104
|
+
ScreenToClient(hwnd, &ptDiff);
|
105
|
+
|
106
|
+
rcWindow.top = ptDiff.y;
|
107
|
+
rcWindow.left = ptDiff.x;
|
108
|
+
|
109
|
+
/* convert the bottom/right values to make them relative to the window,
|
110
|
+
* these will be slightly bigger than the inner width/height */
|
111
|
+
ptDiff.y = rcWindow.bottom;
|
112
|
+
ptDiff.x = rcWindow.right;
|
113
|
+
|
114
|
+
ScreenToClient(hwnd, &ptDiff);
|
115
|
+
|
116
|
+
rcWindow.bottom = ptDiff.y;
|
117
|
+
rcWindow.right = ptDiff.x;
|
118
|
+
|
119
|
+
/* Now that both the inner and outer rects use the same coordinate system we can substract them to get the border size.
|
120
|
+
* Keep in mind that the top/left coordinates of rcWindow are negative because the border lies slightly before {0,0},
|
121
|
+
* so switch them around because SDL2 wants them in positive. */
|
122
|
+
top = rcClient.top - rcWindow.top;
|
123
|
+
left = rcClient.left - rcWindow.left;
|
124
|
+
bottom = rcWindow.bottom - rcClient.bottom;
|
125
|
+
right = rcWindow.right - rcClient.right;
|
126
|
+
|
127
|
+
rect.w -= left + right;
|
128
|
+
rect.h -= top + bottom;
|
78
129
|
}
|
79
|
-
|
80
|
-
RECT window_size = work_area;
|
81
|
-
// Keep in sync with STYLE_NORMAL in SDL_windowswindow.c.
|
82
|
-
DWORD style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
|
83
|
-
AdjustWindowRectEx(&window_size, style, FALSE, 0);
|
84
|
-
|
85
|
-
// Because AdjustWindowRectEx will make our rect larger, not smaller, we need to perform some
|
86
|
-
// unintuitive math here.
|
87
|
-
SIZE size;
|
88
|
-
size.cx = 2 * (work_area.right - work_area.left) - (window_size.right - window_size.left);
|
89
|
-
size.cy = 2 * (work_area.bottom - work_area.top) - (window_size.bottom - window_size.top);
|
90
|
-
return size;
|
91
|
-
}
|
92
130
|
|
93
|
-
|
94
|
-
|
95
|
-
return max_window_size(window).cx;
|
131
|
+
// Return a rect to have one less Gosu::available_width/height implementation.
|
132
|
+
return rect;
|
96
133
|
}
|
134
|
+
#endif
|
97
135
|
|
98
|
-
|
136
|
+
#ifdef GOSU_IS_X
|
137
|
+
static SDL_Rect max_window_size(Gosu::Window* window)
|
99
138
|
{
|
100
|
-
|
139
|
+
static struct VideoSubsystem {
|
140
|
+
VideoSubsystem() { SDL_InitSubSystem(SDL_INIT_VIDEO); };
|
141
|
+
~VideoSubsystem() { SDL_QuitSubSystem(SDL_INIT_VIDEO); };
|
142
|
+
} subsystem;
|
143
|
+
|
144
|
+
int index = window ? SDL_GetWindowDisplayIndex(Gosu::shared_window()) : 0;
|
145
|
+
SDL_Rect rect;
|
146
|
+
int top, left, bottom, right;
|
147
|
+
SDL_GetDisplayUsableBounds(index, &rect);
|
148
|
+
SDL_GetWindowBordersSize(Gosu::shared_window(), &top, &left, &bottom, &right);
|
149
|
+
|
150
|
+
rect.w -= left + right;
|
151
|
+
rect.h -= top + bottom;
|
152
|
+
|
153
|
+
return rect;
|
101
154
|
}
|
102
155
|
#endif
|
103
156
|
|
104
|
-
#ifdef GOSU_IS_X
|
105
|
-
// Pessimistic fallback implementation for available_width / available_height.
|
106
|
-
// TODO: Look at this NET_WORKAREA based implementation: https://github.com/glfw/glfw/pull/989/files
|
107
157
|
int Gosu::available_width(Window* window)
|
108
158
|
{
|
109
|
-
return
|
159
|
+
return max_window_size(window).w;
|
110
160
|
}
|
111
161
|
|
112
162
|
int Gosu::available_height(Window* window)
|
113
163
|
{
|
114
|
-
return
|
164
|
+
return max_window_size(window).h;
|
115
165
|
}
|
116
166
|
#endif
|
117
|
-
|
118
|
-
#endif
|
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.1.
|
4
|
+
version: 1.1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Raschke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
2D game development library.
|
@@ -316,7 +316,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
316
316
|
- !ruby/object:Gem::Version
|
317
317
|
version: '0'
|
318
318
|
requirements: []
|
319
|
-
rubygems_version: 3.
|
319
|
+
rubygems_version: 3.1.4
|
320
320
|
signing_key:
|
321
321
|
specification_version: 4
|
322
322
|
summary: 2D game development library.
|