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/Gosu/Image.hpp
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
//! \file Image.hpp
|
2
2
|
//! Interface of the Image class and helper functions.
|
3
3
|
|
4
|
-
#
|
5
|
-
#define GOSU_IMAGE_HPP
|
4
|
+
#pragma once
|
6
5
|
|
7
6
|
#include <Gosu/Fwd.hpp>
|
8
7
|
#include <Gosu/Color.hpp>
|
9
8
|
#include <Gosu/GraphicsBase.hpp>
|
10
|
-
#include <Gosu/TR1.hpp>
|
11
9
|
#include <memory>
|
12
10
|
#include <vector>
|
13
11
|
|
@@ -16,116 +14,74 @@ namespace Gosu
|
|
16
14
|
//! Provides functionality for drawing rectangular images.
|
17
15
|
class Image
|
18
16
|
{
|
19
|
-
std::
|
17
|
+
std::shared_ptr<ImageData> data_;
|
20
18
|
|
21
19
|
public:
|
22
20
|
//! Loads an image from a given filename.
|
23
21
|
//!
|
24
22
|
//! A color key of #ff00ff is automatically applied to BMP image files.
|
25
23
|
//! For more flexibility, use the corresponding constructor that uses a Bitmap object.
|
26
|
-
explicit Image(const std::
|
27
|
-
unsigned imageFlags = ifSmooth);
|
24
|
+
explicit Image(const std::string& filename, unsigned image_flags = IF_SMOOTH);
|
28
25
|
|
29
26
|
//! Loads a portion of the the image at the given filename..
|
30
27
|
//!
|
31
28
|
//! A color key of #ff00ff is automatically applied to BMP image files.
|
32
29
|
//! For more flexibility, use the corresponding constructor that uses a Bitmap object.
|
33
|
-
Image(const std::
|
34
|
-
|
35
|
-
unsigned imageFlags = ifSmooth);
|
30
|
+
Image(const std::string& filename, unsigned src_x, unsigned src_y,
|
31
|
+
unsigned src_width, unsigned src_height, unsigned image_flags = IF_SMOOTH);
|
36
32
|
|
37
33
|
//! Converts the given bitmap into an image.
|
38
|
-
explicit Image(const Bitmap& source,
|
39
|
-
unsigned imageFlags = ifSmooth);
|
34
|
+
explicit Image(const Bitmap& source, unsigned image_flags = IF_SMOOTH);
|
40
35
|
|
41
36
|
//! Converts a portion of the given bitmap into an image.
|
42
|
-
Image(const Bitmap& source, unsigned
|
43
|
-
unsigned
|
44
|
-
unsigned imageFlags = ifSmooth);
|
37
|
+
Image(const Bitmap& source, unsigned src_x, unsigned src_y, unsigned src_width,
|
38
|
+
unsigned src_height, unsigned image_flags = IF_SMOOTH);
|
45
39
|
|
46
40
|
//! Creates an Image from a user-supplied instance of the ImageData interface.
|
47
|
-
explicit Image(
|
41
|
+
explicit Image(std::unique_ptr<ImageData>&& data);
|
48
42
|
|
49
43
|
unsigned width() const;
|
50
44
|
unsigned height() const;
|
51
45
|
|
52
46
|
//! Draws the image so its upper left corner is at (x; y).
|
53
|
-
void draw(double x, double y, ZPos z,
|
54
|
-
|
55
|
-
Color c = Color::WHITE,
|
56
|
-
AlphaMode mode = amDefault) const;
|
47
|
+
void draw(double x, double y, ZPos z, double scale_x = 1, double scale_y = 1,
|
48
|
+
Color c = Color::WHITE, AlphaMode mode = AM_DEFAULT) const;
|
57
49
|
//! Like draw(), but with modulation colors for all four corners.
|
58
|
-
|
59
|
-
|
60
|
-
double factorX, double factorY,
|
61
|
-
Color c1, Color c2, Color c3, Color c4,
|
62
|
-
AlphaMode mode = amDefault) const;
|
50
|
+
void draw_mod(double x, double y, ZPos z, double scale_x, double scale_y,
|
51
|
+
Color c1, Color c2, Color c3, Color c4, AlphaMode mode = AM_DEFAULT) const;
|
63
52
|
|
64
53
|
//! Draws the image rotated by the given angle so that its rotation
|
65
54
|
//! center is at (x; y). Note that this is different from how all the
|
66
55
|
//! other drawing functions work!
|
67
56
|
//! \param angle See Math.hpp for an explanation of how Gosu interprets
|
68
57
|
//! angles.
|
69
|
-
//! \param
|
58
|
+
//! \param center_x Relative horizontal position of the rotation center
|
70
59
|
//! on the image. 0 is the left border, 1 is the right border, 0.5 is
|
71
60
|
//! the center (and default).
|
72
|
-
//! \param
|
73
|
-
void
|
74
|
-
double
|
75
|
-
|
76
|
-
Color c = Color::WHITE,
|
77
|
-
AlphaMode mode = amDefault) const;
|
61
|
+
//! \param center_y See center_x.
|
62
|
+
void draw_rot(double x, double y, ZPos z, double angle,
|
63
|
+
double center_x = 0.5, double center_y = 0.5, double scale_x = 1, double scale_y = 1,
|
64
|
+
Color c = Color::WHITE, AlphaMode mode = AM_DEFAULT) const;
|
78
65
|
|
79
66
|
#ifndef SWIG
|
80
67
|
//! Provides access to the underlying image data object.
|
81
|
-
ImageData&
|
82
|
-
|
83
|
-
GOSU_DEPRECATED Image(Graphics& graphics, const std::wstring& filename,
|
84
|
-
bool tileable = false);
|
85
|
-
GOSU_DEPRECATED Image(Graphics& graphics, const std::wstring& filename, unsigned srcX,
|
86
|
-
unsigned srcY, unsigned srcWidth, unsigned srcHeight,
|
87
|
-
bool tileable = false);
|
88
|
-
GOSU_DEPRECATED Image(Graphics& graphics, const Bitmap& source,
|
89
|
-
bool tileable = false);
|
90
|
-
GOSU_DEPRECATED Image(Graphics& graphics, const Bitmap& source, unsigned srcX,
|
91
|
-
unsigned srcY, unsigned srcWidth, unsigned srcHeight,
|
92
|
-
bool tileable = false);
|
68
|
+
ImageData& data() const;
|
93
69
|
#endif
|
94
70
|
};
|
95
71
|
|
96
72
|
#ifndef SWIG
|
97
73
|
//! Convenience function that slices an image file into a grid and creates images from them.
|
98
|
-
//! \param
|
99
|
-
//! If negative, the bitmap is divided into -
|
100
|
-
//! \param
|
101
|
-
std::vector<Gosu::Image>
|
102
|
-
int
|
74
|
+
//! \param tile_width If positive, specifies the width of one tile in pixels.
|
75
|
+
//! If negative, the bitmap is divided into -tile_width rows.
|
76
|
+
//! \param tile_height See tile_width.
|
77
|
+
std::vector<Gosu::Image> load_tiles(const Bitmap& bmp,
|
78
|
+
int tile_width, int tile_height, unsigned image_flags = IF_SMOOTH);
|
103
79
|
|
104
80
|
//! Convenience function that slices a bitmap into a grid and creates images from them.
|
105
|
-
//! \param
|
106
|
-
//! If negative, the bitmap is divided into -
|
107
|
-
//! \param
|
108
|
-
std::vector<Gosu::Image>
|
109
|
-
int
|
110
|
-
|
111
|
-
GOSU_DEPRECATED std::vector<Gosu::Image> loadTiles(Graphics& graphics, const Bitmap& bmp, int tileWidth, int tileHeight, bool tileable);
|
112
|
-
GOSU_DEPRECATED std::vector<Gosu::Image> loadTiles(Graphics& graphics, const std::wstring& bmp, int tileWidth, int tileHeight, bool tileable);
|
113
|
-
template<typename Container>
|
114
|
-
GOSU_DEPRECATED void imagesFromTiledBitmap(Graphics& graphics, const std::wstring& filename, int tileWidth, int tileHeight, bool tileable, Container& appendTo)
|
115
|
-
{
|
116
|
-
std::vector<Gosu::Image> tiles = loadTiles(graphics, filename, tileWidth, tileHeight, tileable);
|
117
|
-
for (int i = 0, num = tiles.size(); i < num; ++i)
|
118
|
-
appendTo.push_back(typename Container::value_type(new Gosu::Image(tiles[i])));
|
119
|
-
}
|
120
|
-
template<typename Container>
|
121
|
-
GOSU_DEPRECATED void imagesFromTiledBitmap(Graphics& graphics, const Bitmap& bmp,
|
122
|
-
int tileWidth, int tileHeight, bool tileable, Container& appendTo)
|
123
|
-
{
|
124
|
-
std::vector<Gosu::Image> tiles = loadTiles(graphics, bmp, tileWidth, tileHeight, tileable);
|
125
|
-
for (int i = 0, num = tiles.size(); i < num; ++i)
|
126
|
-
appendTo.push_back(typename Container::value_type(new Gosu::Image(tiles[i])));
|
127
|
-
}
|
81
|
+
//! \param tile_width If positive, specifies the width of one tile in pixels.
|
82
|
+
//! If negative, the bitmap is divided into -tile_width rows.
|
83
|
+
//! \param tile_height See tile_width.
|
84
|
+
std::vector<Gosu::Image> load_tiles(const std::string& filename,
|
85
|
+
int tile_width, int tile_height, unsigned image_flags = IF_SMOOTH);
|
128
86
|
#endif
|
129
87
|
}
|
130
|
-
|
131
|
-
#endif
|
data/Gosu/ImageData.hpp
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
//! \file ImageData.hpp
|
2
2
|
//! Interface of the ImageData class.
|
3
3
|
|
4
|
-
#
|
5
|
-
#define GOSU_IMAGEDATA_HPP
|
4
|
+
#pragma once
|
6
5
|
|
6
|
+
#include <Gosu/Fwd.hpp>
|
7
7
|
#include <Gosu/Color.hpp>
|
8
8
|
#include <Gosu/GraphicsBase.hpp>
|
9
|
-
#include <Gosu/Fwd.hpp>
|
10
9
|
#include <Gosu/Platform.hpp>
|
10
|
+
#include <memory>
|
11
11
|
|
12
12
|
namespace Gosu
|
13
13
|
{
|
@@ -16,13 +16,13 @@ namespace Gosu
|
|
16
16
|
//! to use them in OpenGL operations.
|
17
17
|
struct GLTexInfo
|
18
18
|
{
|
19
|
-
int
|
19
|
+
int tex_name;
|
20
20
|
float left, right, top, bottom;
|
21
21
|
};
|
22
22
|
|
23
23
|
//! The ImageData class is an abstract base class for drawable images.
|
24
24
|
//! Instances of classes derived by ImageData are usually returned by
|
25
|
-
//! Graphics::
|
25
|
+
//! Graphics::create_image and usually only used to implement drawing
|
26
26
|
//! primitives like Image, which then provide a more specialized and
|
27
27
|
//! intuitive drawing interface.
|
28
28
|
class ImageData
|
@@ -32,15 +32,12 @@ namespace Gosu
|
|
32
32
|
ImageData& operator=(const ImageData&);
|
33
33
|
|
34
34
|
public:
|
35
|
-
ImageData()
|
36
|
-
{
|
37
|
-
}
|
35
|
+
ImageData() {}
|
38
36
|
|
39
|
-
virtual ~ImageData()
|
40
|
-
{
|
41
|
-
}
|
37
|
+
virtual ~ImageData() {}
|
42
38
|
|
43
39
|
virtual int width() const = 0;
|
40
|
+
|
44
41
|
virtual int height() const = 0;
|
45
42
|
|
46
43
|
virtual void draw(double x1, double y1, Color c1,
|
@@ -48,14 +45,13 @@ namespace Gosu
|
|
48
45
|
double x3, double y3, Color c3,
|
49
46
|
double x4, double y4, Color c4,
|
50
47
|
ZPos z, AlphaMode mode) const = 0;
|
51
|
-
|
52
|
-
virtual const GLTexInfo*
|
53
|
-
|
48
|
+
|
49
|
+
virtual const GLTexInfo* gl_tex_info() const = 0;
|
50
|
+
|
51
|
+
virtual Bitmap to_bitmap() const = 0;
|
54
52
|
|
55
|
-
virtual
|
53
|
+
virtual std::unique_ptr<ImageData> subimage(int x, int y, int width, int height) const = 0;
|
56
54
|
|
57
55
|
virtual void insert(const Bitmap& bitmap, int x, int y) = 0;
|
58
56
|
};
|
59
57
|
}
|
60
|
-
|
61
|
-
#endif
|
data/Gosu/Input.hpp
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
//! \file Input.hpp
|
2
2
|
//! Interface of the Input class.
|
3
3
|
|
4
|
-
#
|
5
|
-
#define GOSU_INPUT_HPP
|
4
|
+
#pragma once
|
6
5
|
|
7
6
|
#include <Gosu/Fwd.hpp>
|
8
|
-
#include <Gosu/Platform.hpp>
|
9
7
|
#include <Gosu/Buttons.hpp>
|
10
|
-
#include <Gosu/
|
11
|
-
|
8
|
+
#include <Gosu/Platform.hpp>
|
9
|
+
#include <functional>
|
10
|
+
#include <memory>
|
12
11
|
#include <vector>
|
13
12
|
|
14
13
|
namespace Gosu
|
@@ -24,26 +23,17 @@ namespace Gosu
|
|
24
23
|
//! For internal use.
|
25
24
|
unsigned id() const { return id_; }
|
26
25
|
|
27
|
-
//! Default constructor; ==
|
28
|
-
Button() : id_(
|
26
|
+
//! Default constructor; == no_button.
|
27
|
+
Button() : id_(NO_BUTTON) {}
|
29
28
|
|
30
29
|
//! Conversion from ButtonName constants.
|
31
30
|
Button(ButtonName name) : id_(name) {}
|
32
31
|
};
|
33
32
|
|
34
33
|
//! Tests whether two Buttons identify the same physical button.
|
35
|
-
inline bool operator==(Button lhs, Button rhs)
|
36
|
-
{
|
37
|
-
|
38
|
-
}
|
39
|
-
inline bool operator!=(Button lhs, Button rhs)
|
40
|
-
{
|
41
|
-
return !(lhs == rhs);
|
42
|
-
}
|
43
|
-
inline bool operator<(Button lhs, Button rhs)
|
44
|
-
{
|
45
|
-
return lhs.id() < rhs.id();
|
46
|
-
}
|
34
|
+
inline bool operator==(Button lhs, Button rhs) { return lhs.id() == rhs.id(); }
|
35
|
+
inline bool operator!=(Button lhs, Button rhs) { return !(lhs == rhs); }
|
36
|
+
inline bool operator<(Button lhs, Button rhs) { return lhs.id() < rhs.id(); }
|
47
37
|
|
48
38
|
//! Struct that saves information about a touch on the surface of a multi-
|
49
39
|
//! touch device.
|
@@ -63,31 +53,26 @@ namespace Gosu
|
|
63
53
|
class Input
|
64
54
|
{
|
65
55
|
struct Impl;
|
66
|
-
const
|
67
|
-
|
68
|
-
// explicitly forbid copying and moving
|
69
|
-
Input(Input&&) = delete;
|
70
|
-
Input& operator=(Input&&) = delete;
|
71
|
-
Input(const Input&) = delete;
|
72
|
-
Input& operator=(const Input&) = delete;
|
73
|
-
#endif
|
56
|
+
// Non-movable (const) to avoid dangling internal references.
|
57
|
+
const std::unique_ptr<Impl> pimpl;
|
74
58
|
|
75
59
|
public:
|
76
60
|
#ifdef GOSU_IS_IPHONE
|
77
|
-
Input(void* view, float
|
78
|
-
void
|
61
|
+
Input(void* view, float update_interval);
|
62
|
+
void feed_touch_event(int type, void* touches);
|
79
63
|
#else
|
80
64
|
Input(void* window);
|
81
|
-
bool
|
65
|
+
bool feed_sdl_event(void* event);
|
82
66
|
#endif
|
83
67
|
|
84
68
|
~Input();
|
85
69
|
|
86
|
-
//! Returns the character a button usually produces
|
87
|
-
|
88
|
-
|
89
|
-
//! given character
|
90
|
-
|
70
|
+
//! Returns the character (as a UTF-8 encoded string) that a button usually produces.
|
71
|
+
//! Returns the empty string if nothing can be found.
|
72
|
+
static std::string id_to_char(Button btn);
|
73
|
+
//! Returns the button that has to be pressed to produce the given character (as a UTF-8
|
74
|
+
//! encoded string), or NO_BUTTON.
|
75
|
+
static Button char_to_id(std::string ch);
|
91
76
|
|
92
77
|
//! Returns true if a button is currently pressed.
|
93
78
|
//! Updated every tick.
|
@@ -95,44 +80,44 @@ namespace Gosu
|
|
95
80
|
|
96
81
|
//! Returns the horizontal position of the mouse relative to the top
|
97
82
|
//! left corner of the window given to Input's constructor.
|
98
|
-
double
|
99
|
-
//! See
|
100
|
-
double
|
83
|
+
double mouse_x() const;
|
84
|
+
//! See mouse_x.
|
85
|
+
double mouse_y() const;
|
101
86
|
|
102
87
|
//! Immediately moves the mouse as far towards the desired position
|
103
|
-
//! as possible. x and y are relative to the window, just as in
|
104
|
-
//! and
|
105
|
-
void
|
88
|
+
//! as possible. x and y are relative to the window, just as in mouse_x()
|
89
|
+
//! and mouse_y(), so (0, 0) is the top left corner of the window..
|
90
|
+
void set_mouse_position(double x, double y);
|
106
91
|
|
107
|
-
// Undocumented for the moment. Also applies to
|
108
|
-
void
|
92
|
+
// Undocumented for the moment. Also applies to current_touches().
|
93
|
+
void set_mouse_factors(double factor_x, double factor_y,
|
94
|
+
double offset_x = 0, double offset_y = 0);
|
109
95
|
|
110
96
|
//! Currently known touches.
|
111
|
-
const Touches&
|
97
|
+
const Touches& current_touches() const;
|
112
98
|
|
113
99
|
//! Accelerometer positions in all three dimensions (smoothened).
|
114
|
-
//! Note: Not really deprecated
|
115
|
-
GOSU_DEPRECATED double
|
116
|
-
GOSU_DEPRECATED double
|
117
|
-
GOSU_DEPRECATED double
|
100
|
+
//! Note: Not really deprecated, but temporarily defunct.
|
101
|
+
GOSU_DEPRECATED double accelerometer_x() const;
|
102
|
+
GOSU_DEPRECATED double accelerometer_y() const;
|
103
|
+
GOSU_DEPRECATED double accelerometer_z() const;
|
118
104
|
|
119
105
|
//! Collects new information about which buttons are pressed, where the
|
120
|
-
//! mouse is and calls
|
106
|
+
//! mouse is and calls on_button_up/on_button_down, if assigned.
|
121
107
|
void update();
|
122
108
|
|
123
109
|
//! Assignable events that are called by update. You can bind these to your own functions.
|
124
110
|
//! If you use the Window class, it will assign these to its own methods.
|
125
|
-
std::
|
111
|
+
std::function<void (Button)> on_button_down, on_button_up;
|
126
112
|
|
127
113
|
//! Assignable events that are called by update. You can bind these to your own functions.
|
128
114
|
//! If you use the Window class, it will assign these to its own methods.
|
129
|
-
std::
|
115
|
+
std::function<void (Touch)> on_touch_began, on_touch_moved, on_touch_ended,
|
116
|
+
on_touch_cancelled;
|
130
117
|
|
131
|
-
//! Returns the currently active TextInput instance, or
|
132
|
-
TextInput*
|
133
|
-
//! Sets the currently active TextInput, or
|
134
|
-
void
|
118
|
+
//! Returns the currently active TextInput instance, or nullptr.
|
119
|
+
TextInput* text_input() const;
|
120
|
+
//! Sets the currently active TextInput, or resets it to the nullptr.
|
121
|
+
void set_text_input(TextInput* input);
|
135
122
|
};
|
136
123
|
}
|
137
|
-
|
138
|
-
#endif
|
data/Gosu/Inspection.hpp
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
//! \file Inspection.hpp
|
2
2
|
//! A special set of functions designed for tuning Gosu games.
|
3
3
|
|
4
|
-
#
|
5
|
-
#define GOSU_INSPECTION_HPP
|
4
|
+
#pragma once
|
6
5
|
|
7
6
|
namespace Gosu
|
8
7
|
{
|
9
|
-
//! Returns the current framerate
|
10
|
-
//! horrible algorithm.
|
8
|
+
//! Returns the current framerate.
|
11
9
|
int fps();
|
12
10
|
}
|
13
|
-
|
14
|
-
#endif
|
data/Gosu/Math.hpp
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
//! \file Math.hpp
|
2
2
|
//! Contains simple math functionality.
|
3
3
|
|
4
|
-
#
|
5
|
-
|
4
|
+
#pragma once
|
5
|
+
|
6
|
+
#include <cmath>
|
7
|
+
|
8
|
+
// Portability: Define M_PI, which MSVC's <cmath> does not do by default.
|
9
|
+
#ifndef M_PI
|
10
|
+
#define M_PI 3.14159265358979323846264338327950288
|
11
|
+
#endif
|
6
12
|
|
7
13
|
namespace Gosu
|
8
14
|
{
|
9
|
-
//! Pi.
|
10
|
-
const double pi = 3.1415926536;
|
11
|
-
|
12
15
|
//! Truncates the fractional part of a real value. Equivalent to
|
13
16
|
//! static_cast<long>.
|
14
17
|
inline long trunc(double value)
|
@@ -19,61 +22,62 @@ namespace Gosu
|
|
19
22
|
//! Rounds a real value towards the next integer.
|
20
23
|
inline long round(double value)
|
21
24
|
{
|
22
|
-
if (value >= 0)
|
25
|
+
if (value >= 0) {
|
23
26
|
return static_cast<long>(value + 0.5);
|
24
|
-
|
27
|
+
}
|
28
|
+
else {
|
25
29
|
return static_cast<long>(value - 0.5);
|
30
|
+
}
|
26
31
|
}
|
27
32
|
|
28
33
|
//! Returns a real value between min (inclusive) and max (exclusive).
|
29
34
|
//! Uses std::rand, so you should call std::srand before using it.
|
30
35
|
double random(double min, double max);
|
31
36
|
|
32
|
-
//! Translates between Gosu's angle system (where 0
|
37
|
+
//! Translates between Gosu's angle system (where 0 is at the top)
|
33
38
|
//! and radians (where 0 is at the right).
|
34
|
-
inline double
|
39
|
+
inline double gosu_to_radians(double angle)
|
35
40
|
{
|
36
|
-
return (angle - 90) *
|
41
|
+
return (angle - 90) * M_PI / 180;
|
37
42
|
}
|
38
|
-
//! Translates between Gosu's angle system (where 0
|
43
|
+
//! Translates between Gosu's angle system (where 0 is at the top)
|
39
44
|
//! and radians (where 0 is at the right).
|
40
|
-
inline double
|
45
|
+
inline double radians_to_gosu(double angle)
|
41
46
|
{
|
42
|
-
return angle * 180 /
|
47
|
+
return angle * 180 / M_PI + 90;
|
43
48
|
}
|
44
49
|
|
45
50
|
//! Translates between degrees (used by Gosu) and radians, i.e. it
|
46
51
|
//! does not change the 'origin' of the angle system.
|
47
|
-
inline double
|
52
|
+
inline double degrees_to_radians(double angle)
|
48
53
|
{
|
49
|
-
return angle *
|
54
|
+
return angle * M_PI / 180;
|
50
55
|
}
|
51
56
|
//! Translates between degrees (used by Gosu) and radians, i.e. it
|
52
57
|
//! does not change the 'origin' of the angle system.
|
53
|
-
inline double
|
58
|
+
inline double radians_to_degrees(double angle)
|
54
59
|
{
|
55
|
-
return angle * 180 /
|
60
|
+
return angle * 180 / M_PI;
|
56
61
|
}
|
57
62
|
|
58
63
|
//! Returns the horizontal distance between the origin and the point to
|
59
64
|
//! which you would get if you moved radius pixels in the direction
|
60
65
|
//! specified by angle.
|
61
66
|
//! \param angle Angle in degrees where 0.0 means upwards.
|
62
|
-
double
|
67
|
+
double offset_x(double angle, double radius);
|
63
68
|
//! Returns the vertical distance between the origin and the point to
|
64
69
|
//! which you would get if you moved radius pixels in the direction
|
65
70
|
//! specified by angle.
|
66
71
|
//! \param angle Angle in degrees where 0.0 means upwards.
|
67
|
-
double
|
72
|
+
double offset_y(double angle, double radius);
|
68
73
|
//! Returns the angle from point 1 to point 2 in degrees, where 0.0 means
|
69
74
|
//! upwards. Returns def if both points are equal.
|
70
|
-
double angle(double
|
71
|
-
double def = 0);
|
75
|
+
double angle(double from_x, double from_y, double to_x, double to_y, double def = 0);
|
72
76
|
//! Returns the smallest angle that can be added to angle1 to get to
|
73
77
|
//! angle2 (can be negative if counter-clockwise movement is shorter).
|
74
|
-
double
|
78
|
+
double angle_diff(double angle1, double angle2);
|
75
79
|
//! Normalizes an angle to fit into the range [0; 360[.
|
76
|
-
double
|
80
|
+
double normalize_angle(double angle);
|
77
81
|
|
78
82
|
//! Returns value * value.
|
79
83
|
template<typename T>
|
@@ -87,20 +91,11 @@ namespace Gosu
|
|
87
91
|
template<typename T>
|
88
92
|
T clamp(T value, T min, T max)
|
89
93
|
{
|
90
|
-
if (value < min)
|
91
|
-
|
92
|
-
if (value > max)
|
93
|
-
return max;
|
94
|
+
if (value < min) return min;
|
95
|
+
if (value > max) return max;
|
94
96
|
return value;
|
95
97
|
}
|
96
98
|
|
97
|
-
// Backward compatibility with 0.7.x
|
98
|
-
template<typename T>
|
99
|
-
T boundBy(T value, T min, T max)
|
100
|
-
{
|
101
|
-
return clamp(value, min, max);
|
102
|
-
}
|
103
|
-
|
104
99
|
//! Returns (value-min) % (max-min) + min, where % always has a positive
|
105
100
|
//! result for max > min. The results are undefined for max <= min.
|
106
101
|
//! Note: This means that max is exclusive.
|
@@ -115,7 +110,7 @@ namespace Gosu
|
|
115
110
|
double wrap(double value, double min, double max);
|
116
111
|
|
117
112
|
//! Returns the square of the distance between two points.
|
118
|
-
inline double
|
113
|
+
inline double distance_sqr(double x1, double y1, double x2, double y2)
|
119
114
|
{
|
120
115
|
return square(x1 - x2) + square(y1 - y2);
|
121
116
|
}
|
@@ -124,12 +119,11 @@ namespace Gosu
|
|
124
119
|
double distance(double x1, double y1, double x2, double y2);
|
125
120
|
|
126
121
|
//! Interpolates a value between a and b, weight being the bias towards the second value.
|
127
|
-
//! Examples: interpolate(0, 10, 0.5) == 5, interpolate(-10, 10, 0.25) == 5,
|
122
|
+
//! Examples: interpolate(0, 10, 0.5) == 5, interpolate(-10, 10, 0.25) == 5,
|
123
|
+
//! interpolate(0, 10, -0.5) == -5.
|
128
124
|
template<typename T>
|
129
125
|
T interpolate(T a, T b, double weight = 0.5)
|
130
126
|
{
|
131
127
|
return a * (1.0 - weight) + b * weight;
|
132
128
|
}
|
133
129
|
}
|
134
|
-
|
135
|
-
#endif
|