gosu 1.0.0 → 1.1.1.1
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/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 +2 -2
- data/include/Gosu/Window.hpp +23 -9
- data/lib/gosu/swig_patches.rb +11 -10
- data/rdoc/gosu.rb +14 -1
- data/src/Input.cpp +1 -10
- data/src/Macro.cpp +98 -141
- data/src/Resolution.cpp +111 -63
- data/src/RubyGosu.cxx +144 -48
- data/src/RubyGosu.h +1 -1
- data/src/TrueTypeFontWin.cpp +3 -3
- data/src/Window.cpp +60 -31
- data/src/WindowUIKit.cpp +21 -9
- metadata +3 -23
- data/include/Gosu/Channel.h +0 -25
- data/include/Gosu/Color.h +0 -38
- data/include/Gosu/Font.h +0 -36
- data/include/Gosu/Gosu.h +0 -82
- data/include/Gosu/Image.h +0 -54
- data/include/Gosu/Sample.h +0 -19
- data/include/Gosu/Song.h +0 -24
- data/include/Gosu/TextInput.h +0 -30
- data/include/Gosu/Window.h +0 -63
- data/src/ChannelWrapper.cpp +0 -50
- data/src/ColorWrapper.cpp +0 -126
- data/src/Constants.cpp +0 -338
- data/src/FontWrapper.cpp +0 -74
- data/src/GosuWrapper.cpp +0 -251
- data/src/ImageWrapper.cpp +0 -168
- data/src/MPEGFile.hpp +0 -90
- data/src/SampleWrapper.cpp +0 -30
- data/src/SongWrapper.cpp +0 -52
- data/src/TextInputWrapper.cpp +0 -101
- data/src/WindowWrapper.cpp +0 -317
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/include/Gosu/Window.hpp
CHANGED
@@ -8,6 +8,14 @@
|
|
8
8
|
|
9
9
|
namespace Gosu
|
10
10
|
{
|
11
|
+
enum WindowFlags
|
12
|
+
{
|
13
|
+
WF_WINDOWED,
|
14
|
+
WF_FULLSCREEN = 1,
|
15
|
+
WF_RESIZABLE = 2,
|
16
|
+
WF_BORDERLESS = 4
|
17
|
+
};
|
18
|
+
|
11
19
|
//! Convenient all-in-one class that serves as the foundation of a standard Gosu application.
|
12
20
|
//! Manages initialization of all of Gosu's core components and provides timing functionality.
|
13
21
|
//! Note that you should really only use one instance of this class at the same time.
|
@@ -21,17 +29,23 @@ namespace Gosu
|
|
21
29
|
//! \param width Width of the window in points; that is, pixels on a normal display, and
|
22
30
|
//! 'points' on a high-resolution display.
|
23
31
|
//! \param height See width.
|
32
|
+
//! \param window_flags A bitmask of values from Gosu::WindowFlags.
|
24
33
|
//! \param update_interval Interval in milliseconds between two calls to the update member
|
25
34
|
//! function.
|
26
|
-
Window(
|
27
|
-
|
35
|
+
Window(int width, int height, unsigned window_flags = WF_WINDOWED,
|
36
|
+
double update_interval = 16.666666);
|
28
37
|
virtual ~Window();
|
29
38
|
|
30
|
-
|
31
|
-
|
39
|
+
int width() const;
|
40
|
+
int height() const;
|
32
41
|
bool fullscreen() const;
|
42
|
+
void resize(int width, int height, bool fullscreen);
|
43
|
+
|
33
44
|
bool resizable() const;
|
34
|
-
void
|
45
|
+
void set_resizable(bool resizable);
|
46
|
+
|
47
|
+
bool borderless() const;
|
48
|
+
void set_borderless(bool borderless);
|
35
49
|
|
36
50
|
double update_interval() const;
|
37
51
|
void set_update_interval(double update_interval);
|
@@ -129,22 +143,22 @@ namespace Gosu
|
|
129
143
|
//! Returns the width (in pixels) of a screen.
|
130
144
|
//! \param window The result describes the screen on which the window is shown, or the
|
131
145
|
//! primary screen if no window is given.
|
132
|
-
|
146
|
+
int screen_width(Window* window = nullptr);
|
133
147
|
|
134
148
|
//! Returns the height (in pixels) of the user's primary screen.
|
135
149
|
//! \param window The result describes the screen on which the window is shown, or the
|
136
150
|
//! primary screen if no window is given.
|
137
|
-
|
151
|
+
int screen_height(Window* window = nullptr);
|
138
152
|
|
139
153
|
//! Returns the maximum width (in 'points') that is available for a non-fullscreen Window.
|
140
154
|
//! All windows larger than this size will automatically be shrunk to fit.
|
141
155
|
//! \param window The result describes the screen on which the window is shown, or the
|
142
156
|
//! primary screen if no window is given.
|
143
|
-
|
157
|
+
int available_width(Window* window = nullptr);
|
144
158
|
|
145
159
|
//! Returns the maximum height (in 'points') that is available for a non-fullscreen Window.
|
146
160
|
//! All windows larger than this size will automatically be shrunk to fit.
|
147
161
|
//! \param window The result describes the screen on which the window is shown, or the
|
148
162
|
//! primary screen if no window is given.
|
149
|
-
|
163
|
+
int available_height(Window* window = nullptr);
|
150
164
|
}
|
data/lib/gosu/swig_patches.rb
CHANGED
@@ -3,19 +3,20 @@
|
|
3
3
|
# compatible, but I just call protected_update etc. in the Ruby wrapper so I can add this
|
4
4
|
# custom debugging help:
|
5
5
|
class Gosu::Window
|
6
|
-
alias_method :
|
6
|
+
alias_method :initialize_with_bitmask, :initialize
|
7
7
|
|
8
|
-
def initialize
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
def initialize(width, height, *args)
|
9
|
+
$gosu_gl_blocks = nil
|
10
|
+
|
11
|
+
if args.first.is_a? Hash
|
12
|
+
flags = 0
|
13
|
+
flags |= 1 if args.first[:fullscreen]
|
14
|
+
flags |= 2 if args.first[:resizable]
|
15
|
+
flags |= 4 if args.first[:borderless]
|
16
|
+
initialize_with_bitmask(width, height, flags, args.first[:update_interval] || 16.666666)
|
14
17
|
else
|
15
|
-
|
18
|
+
initialize_with_bitmask(width, height, args[0] ? 1 : 0, args[1] || 16.666666)
|
16
19
|
end
|
17
|
-
$gosu_gl_blocks = nil
|
18
|
-
initialize_without_hash width, height, !!fullscreen, update_interval || 16.666666, !!resizable
|
19
20
|
end
|
20
21
|
|
21
22
|
%w(update draw needs_redraw? needs_cursor?
|
data/rdoc/gosu.rb
CHANGED
@@ -811,6 +811,18 @@ module Gosu
|
|
811
811
|
# @return [true, false] whether this window is resizable.
|
812
812
|
def resizable?; end
|
813
813
|
|
814
|
+
##
|
815
|
+
# Toggles between resizable and fixed modes.
|
816
|
+
attr_writer :resizable
|
817
|
+
|
818
|
+
##
|
819
|
+
# @return [true, false] whether this window is borderless.
|
820
|
+
def borderless?; end
|
821
|
+
|
822
|
+
##
|
823
|
+
# Toggles between borderless mode and having window chrome.
|
824
|
+
attr_writer :borderless
|
825
|
+
|
814
826
|
##
|
815
827
|
# @return [Float] the interval between calls to {#update}, in milliseconds.
|
816
828
|
attr_accessor :update_interval
|
@@ -828,7 +840,8 @@ module Gosu
|
|
828
840
|
# @param height [Integer] the desired window height.
|
829
841
|
# @param [Hash] options
|
830
842
|
# @option options [true, false] :fullscreen (false) whether to present the window in fullscreen mode.
|
831
|
-
# @option options [true, false] :resizable (false) whether the window can be resized by the user.
|
843
|
+
# @option options [true, false] :resizable (false) whether the window can be resized by the user. Not useful if the window is either fullscreen or borderless.
|
844
|
+
# @option options [true, false] :borderless (false) whether the window should hide all its window chrome. Does not affect fullscreen windows.
|
832
845
|
# @option options [Float] :update_interval (16.666666) the interval between frames, in milliseconds.
|
833
846
|
def initialize(width, height, options); end
|
834
847
|
|
data/src/Input.cpp
CHANGED
@@ -78,20 +78,11 @@ struct Gosu::Input::Impl
|
|
78
78
|
|
79
79
|
void update_mouse_position()
|
80
80
|
{
|
81
|
-
#if SDL_VERSION_ATLEAST(2, 0, 5)
|
82
|
-
// SDL_GetGlobalMouseState was added in SDL 2.0.4, but it only started using the same
|
83
|
-
// coordinate system as SDL_GetWindowPosition on X11 in 2.0.5.
|
84
81
|
int x, y, window_x, window_y;
|
85
82
|
SDL_GetWindowPosition(window, &window_x, &window_y);
|
86
83
|
SDL_GetGlobalMouseState(&x, &y);
|
87
84
|
mouse_x = x - window_x;
|
88
85
|
mouse_y = y - window_y;
|
89
|
-
#else
|
90
|
-
int x, y;
|
91
|
-
SDL_GetMouseState(&x, &y);
|
92
|
-
mouse_x = x;
|
93
|
-
mouse_y = y;
|
94
|
-
#endif
|
95
86
|
}
|
96
87
|
|
97
88
|
void set_mouse_position(double x, double y)
|
@@ -100,7 +91,7 @@ struct Gosu::Input::Impl
|
|
100
91
|
static_cast<int>((x - mouse_offset_x) / mouse_scale_x),
|
101
92
|
static_cast<int>((y - mouse_offset_y) / mouse_scale_y));
|
102
93
|
|
103
|
-
#if
|
94
|
+
#if !defined(GOSU_IS_X)
|
104
95
|
// On systems where we have a working GetGlobalMouseState, we can warp the mouse and
|
105
96
|
// retrieve its position directly afterwards.
|
106
97
|
update_mouse_position();
|
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
|