gosu 0.8.6-x86-mingw32 → 0.8.7-x86-mingw32
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 +171 -171
- data/Gosu/Bitmap.hpp +96 -96
- data/Gosu/Color.hpp +204 -204
- data/Gosu/Directories.hpp +36 -36
- data/Gosu/Font.hpp +83 -83
- data/Gosu/Gosu.hpp +34 -34
- data/Gosu/Graphics.hpp +115 -115
- data/Gosu/GraphicsBase.hpp +110 -110
- data/Gosu/IO.hpp +269 -269
- data/Gosu/Image.hpp +122 -122
- data/Gosu/ImageData.hpp +61 -61
- data/Gosu/Input.hpp +149 -149
- data/Gosu/Inspection.hpp +14 -14
- data/Gosu/Math.hpp +135 -135
- data/Gosu/Platform.hpp +93 -93
- data/Gosu/Sockets.hpp +156 -156
- data/Gosu/TR1.hpp +56 -56
- data/Gosu/Text.hpp +71 -71
- data/Gosu/TextInput.hpp +70 -70
- data/Gosu/Utility.hpp +28 -28
- data/Gosu/Version.hpp +19 -19
- data/Gosu/Window.hpp +145 -145
- data/examples/ChipmunkIntegration.rb +275 -275
- data/examples/CptnRuby.rb +223 -223
- data/examples/GosuZen.rb +68 -68
- data/examples/MoreChipmunkAndRMagick.rb +155 -155
- data/examples/OpenGLIntegration.rb +225 -225
- data/examples/RMagickIntegration.rb +417 -417
- data/examples/TextInput.rb +154 -154
- data/examples/Tutorial.rb +130 -130
- data/examples/media/Beep.wav +0 -0
- data/examples/media/CptnRuby Map.txt b/data/examples/media/CptnRuby → Map.txt +0 -0
- data/examples/media/Explosion.wav +0 -0
- data/examples/media/Landscape.svg +9 -9
- data/examples/media/Space.png +0 -0
- data/examples/media/Star.png +0 -0
- data/examples/media/Starfighter.bmp +0 -0
- data/lib/1.8/gosu.so +0 -0
- data/lib/1.9/gosu.so +0 -0
- data/lib/2.0/gosu.so +0 -0
- data/lib/2.1/gosu.so +0 -0
- data/lib/FreeImage.dll +0 -0
- data/lib/OpenAL32.dll +0 -0
- data/lib/gosu.rb +19 -16
- data/lib/gosu/patches.rb +81 -81
- data/lib/gosu/preview.rb +143 -139
- data/lib/gosu/run.rb +11 -11
- data/lib/gosu/swig_patches.rb +60 -60
- data/lib/gosu/zen.rb +89 -89
- metadata +5 -5
data/Gosu/Image.hpp
CHANGED
@@ -1,122 +1,122 @@
|
|
1
|
-
//! \file Image.hpp
|
2
|
-
//! Interface of the Image class and helper functions.
|
3
|
-
|
4
|
-
#ifndef GOSU_IMAGE_HPP
|
5
|
-
#define GOSU_IMAGE_HPP
|
6
|
-
|
7
|
-
#include <Gosu/Fwd.hpp>
|
8
|
-
#include <Gosu/Color.hpp>
|
9
|
-
#include <Gosu/GraphicsBase.hpp>
|
10
|
-
#include <Gosu/TR1.hpp>
|
11
|
-
#include <memory>
|
12
|
-
#include <vector>
|
13
|
-
|
14
|
-
namespace Gosu
|
15
|
-
{
|
16
|
-
//! Provides functionality for drawing rectangular images.
|
17
|
-
class Image
|
18
|
-
{
|
19
|
-
std::tr1::shared_ptr<ImageData> data;
|
20
|
-
|
21
|
-
public:
|
22
|
-
//! Loads an image from a given filename that can be drawn onto
|
23
|
-
//! graphics.
|
24
|
-
//! This constructor can handle PNG and BMP images. A color key of #ff00ff is
|
25
|
-
//! automatically applied to BMP type images. For more flexibility, use the
|
26
|
-
//! corresponding constructor that uses a Bitmap object.
|
27
|
-
Image(Graphics& graphics, const std::wstring& filename,
|
28
|
-
bool tileable = false);
|
29
|
-
//! Loads a portion of the the image at the given filename that can be
|
30
|
-
//! drawn onto graphics.
|
31
|
-
//! This constructor can handle PNG and BMP images. A color key of #ff00ff is
|
32
|
-
//! automatically applied to BMP type images. For more flexibility, use the
|
33
|
-
//! corresponding constructor that uses a Bitmap object.
|
34
|
-
Image(Graphics& graphics, const std::wstring& filename, unsigned srcX,
|
35
|
-
unsigned srcY, unsigned srcWidth, unsigned srcHeight,
|
36
|
-
bool tileable = false);
|
37
|
-
|
38
|
-
//! Converts the given bitmap into an image that can be drawn onto
|
39
|
-
//! graphics.
|
40
|
-
Image(Graphics& graphics, const Bitmap& source,
|
41
|
-
bool tileable = false);
|
42
|
-
//! Converts a portion of the given bitmap into an image that can be
|
43
|
-
//! drawn onto graphics.
|
44
|
-
Image(Graphics& graphics, const Bitmap& source, unsigned srcX,
|
45
|
-
unsigned srcY, unsigned srcWidth, unsigned srcHeight,
|
46
|
-
bool tileable = false);
|
47
|
-
|
48
|
-
//! Creates an Image from a user-supplied instance of the ImageData interface.
|
49
|
-
explicit Image(GOSU_UNIQUE_PTR<ImageData> data);
|
50
|
-
|
51
|
-
unsigned width() const;
|
52
|
-
unsigned height() const;
|
53
|
-
|
54
|
-
//! Draws the image so its upper left corner is at (x; y).
|
55
|
-
void draw(double x, double y, ZPos z,
|
56
|
-
double factorX = 1, double factorY = 1,
|
57
|
-
Color c = Color::WHITE,
|
58
|
-
AlphaMode mode = amDefault) const;
|
59
|
-
//! Like draw(), but allows to give modulation colors for all four
|
60
|
-
//! corners.
|
61
|
-
void drawMod(double x, double y, ZPos z,
|
62
|
-
double factorX, double factorY,
|
63
|
-
Color c1, Color c2, Color c3, Color c4,
|
64
|
-
AlphaMode mode = amDefault) const;
|
65
|
-
|
66
|
-
//! Draws the image rotated by the given angle so that its rotation
|
67
|
-
//! center is at (x; y). Note that this is different from how all the
|
68
|
-
//! other drawing functions work!
|
69
|
-
//! \param angle See Math.hpp for an explanation of how Gosu interprets
|
70
|
-
//! angles.
|
71
|
-
//! \param centerX Relative horizontal position of the rotation center
|
72
|
-
//! on the image. 0 is the left border, 1 is the right border, 0.5 is
|
73
|
-
//! the center (and default).
|
74
|
-
//! \param centerY See centerX.
|
75
|
-
void drawRot(double x, double y, ZPos z,
|
76
|
-
double angle, double centerX = 0.5, double centerY = 0.5,
|
77
|
-
double factorX = 1, double factorY = 1,
|
78
|
-
Color c = Color::WHITE,
|
79
|
-
AlphaMode mode = amDefault) const;
|
80
|
-
|
81
|
-
//! Provides access to the underlying image data object.
|
82
|
-
ImageData& getData() const;
|
83
|
-
};
|
84
|
-
|
85
|
-
std::vector<Gosu::Image> loadTiles(Graphics& graphics, const Bitmap& bmp, int tileWidth, int tileHeight, bool tileable);
|
86
|
-
std::vector<Gosu::Image> loadTiles(Graphics& graphics, const std::wstring& bmp, int tileWidth, int tileHeight, bool tileable);
|
87
|
-
|
88
|
-
//! Convenience function that splits a BMP or PNG file into an array
|
89
|
-
//! of small rectangles and creates images from them.
|
90
|
-
//! \param tileWidth If positive, specifies the width of one tile in
|
91
|
-
//! pixels. If negative, the bitmap is divided into -tileWidth rows.
|
92
|
-
//! \param tileHeight See tileWidth.
|
93
|
-
//! \param appendTo STL container to which the images will be appended.
|
94
|
-
//! Must provide a push_back member function; vector<tr1::shared_ptr<Image>>
|
95
|
-
//! or boost::ptr_vector<Image> are good choices.
|
96
|
-
template<typename Container>
|
97
|
-
void imagesFromTiledBitmap(Graphics& graphics, const std::wstring& filename, int tileWidth, int tileHeight, bool tileable, Container& appendTo)
|
98
|
-
{
|
99
|
-
std::vector<Gosu::Image> tiles = loadTiles(graphics, filename, tileWidth, tileHeight, tileable);
|
100
|
-
for (int i = 0, num = tiles.size(); i < num; ++i)
|
101
|
-
appendTo.push_back(typename Container::value_type(new Gosu::Image(tiles[i])));
|
102
|
-
}
|
103
|
-
|
104
|
-
//! Convenience function that splits a bitmap into an area of array
|
105
|
-
//! rectangles and creates images from them.
|
106
|
-
//! \param tileWidth If positive, specifies the width of one tile in
|
107
|
-
//! pixels. If negative, the bitmap is divided into -tileWidth rows.
|
108
|
-
//! \param tileHeight See tileWidth.
|
109
|
-
//! \param appendTo STL container to which the images will be appended.
|
110
|
-
//! Must provide a push_back member function; std::vector<std::tr1::shared_ptr<Image>>
|
111
|
-
//! or boost::ptr_vector<Image> are good choices.
|
112
|
-
template<typename Container>
|
113
|
-
void imagesFromTiledBitmap(Graphics& graphics, const Bitmap& bmp,
|
114
|
-
int tileWidth, int tileHeight, bool tileable, Container& appendTo)
|
115
|
-
{
|
116
|
-
std::vector<Gosu::Image> tiles = loadTiles(graphics, bmp, 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
|
-
}
|
121
|
-
|
122
|
-
#endif
|
1
|
+
//! \file Image.hpp
|
2
|
+
//! Interface of the Image class and helper functions.
|
3
|
+
|
4
|
+
#ifndef GOSU_IMAGE_HPP
|
5
|
+
#define GOSU_IMAGE_HPP
|
6
|
+
|
7
|
+
#include <Gosu/Fwd.hpp>
|
8
|
+
#include <Gosu/Color.hpp>
|
9
|
+
#include <Gosu/GraphicsBase.hpp>
|
10
|
+
#include <Gosu/TR1.hpp>
|
11
|
+
#include <memory>
|
12
|
+
#include <vector>
|
13
|
+
|
14
|
+
namespace Gosu
|
15
|
+
{
|
16
|
+
//! Provides functionality for drawing rectangular images.
|
17
|
+
class Image
|
18
|
+
{
|
19
|
+
std::tr1::shared_ptr<ImageData> data;
|
20
|
+
|
21
|
+
public:
|
22
|
+
//! Loads an image from a given filename that can be drawn onto
|
23
|
+
//! graphics.
|
24
|
+
//! This constructor can handle PNG and BMP images. A color key of #ff00ff is
|
25
|
+
//! automatically applied to BMP type images. For more flexibility, use the
|
26
|
+
//! corresponding constructor that uses a Bitmap object.
|
27
|
+
Image(Graphics& graphics, const std::wstring& filename,
|
28
|
+
bool tileable = false);
|
29
|
+
//! Loads a portion of the the image at the given filename that can be
|
30
|
+
//! drawn onto graphics.
|
31
|
+
//! This constructor can handle PNG and BMP images. A color key of #ff00ff is
|
32
|
+
//! automatically applied to BMP type images. For more flexibility, use the
|
33
|
+
//! corresponding constructor that uses a Bitmap object.
|
34
|
+
Image(Graphics& graphics, const std::wstring& filename, unsigned srcX,
|
35
|
+
unsigned srcY, unsigned srcWidth, unsigned srcHeight,
|
36
|
+
bool tileable = false);
|
37
|
+
|
38
|
+
//! Converts the given bitmap into an image that can be drawn onto
|
39
|
+
//! graphics.
|
40
|
+
Image(Graphics& graphics, const Bitmap& source,
|
41
|
+
bool tileable = false);
|
42
|
+
//! Converts a portion of the given bitmap into an image that can be
|
43
|
+
//! drawn onto graphics.
|
44
|
+
Image(Graphics& graphics, const Bitmap& source, unsigned srcX,
|
45
|
+
unsigned srcY, unsigned srcWidth, unsigned srcHeight,
|
46
|
+
bool tileable = false);
|
47
|
+
|
48
|
+
//! Creates an Image from a user-supplied instance of the ImageData interface.
|
49
|
+
explicit Image(GOSU_UNIQUE_PTR<ImageData> data);
|
50
|
+
|
51
|
+
unsigned width() const;
|
52
|
+
unsigned height() const;
|
53
|
+
|
54
|
+
//! Draws the image so its upper left corner is at (x; y).
|
55
|
+
void draw(double x, double y, ZPos z,
|
56
|
+
double factorX = 1, double factorY = 1,
|
57
|
+
Color c = Color::WHITE,
|
58
|
+
AlphaMode mode = amDefault) const;
|
59
|
+
//! Like draw(), but allows to give modulation colors for all four
|
60
|
+
//! corners.
|
61
|
+
void drawMod(double x, double y, ZPos z,
|
62
|
+
double factorX, double factorY,
|
63
|
+
Color c1, Color c2, Color c3, Color c4,
|
64
|
+
AlphaMode mode = amDefault) const;
|
65
|
+
|
66
|
+
//! Draws the image rotated by the given angle so that its rotation
|
67
|
+
//! center is at (x; y). Note that this is different from how all the
|
68
|
+
//! other drawing functions work!
|
69
|
+
//! \param angle See Math.hpp for an explanation of how Gosu interprets
|
70
|
+
//! angles.
|
71
|
+
//! \param centerX Relative horizontal position of the rotation center
|
72
|
+
//! on the image. 0 is the left border, 1 is the right border, 0.5 is
|
73
|
+
//! the center (and default).
|
74
|
+
//! \param centerY See centerX.
|
75
|
+
void drawRot(double x, double y, ZPos z,
|
76
|
+
double angle, double centerX = 0.5, double centerY = 0.5,
|
77
|
+
double factorX = 1, double factorY = 1,
|
78
|
+
Color c = Color::WHITE,
|
79
|
+
AlphaMode mode = amDefault) const;
|
80
|
+
|
81
|
+
//! Provides access to the underlying image data object.
|
82
|
+
ImageData& getData() const;
|
83
|
+
};
|
84
|
+
|
85
|
+
std::vector<Gosu::Image> loadTiles(Graphics& graphics, const Bitmap& bmp, int tileWidth, int tileHeight, bool tileable);
|
86
|
+
std::vector<Gosu::Image> loadTiles(Graphics& graphics, const std::wstring& bmp, int tileWidth, int tileHeight, bool tileable);
|
87
|
+
|
88
|
+
//! Convenience function that splits a BMP or PNG file into an array
|
89
|
+
//! of small rectangles and creates images from them.
|
90
|
+
//! \param tileWidth If positive, specifies the width of one tile in
|
91
|
+
//! pixels. If negative, the bitmap is divided into -tileWidth rows.
|
92
|
+
//! \param tileHeight See tileWidth.
|
93
|
+
//! \param appendTo STL container to which the images will be appended.
|
94
|
+
//! Must provide a push_back member function; vector<tr1::shared_ptr<Image>>
|
95
|
+
//! or boost::ptr_vector<Image> are good choices.
|
96
|
+
template<typename Container>
|
97
|
+
void imagesFromTiledBitmap(Graphics& graphics, const std::wstring& filename, int tileWidth, int tileHeight, bool tileable, Container& appendTo)
|
98
|
+
{
|
99
|
+
std::vector<Gosu::Image> tiles = loadTiles(graphics, filename, tileWidth, tileHeight, tileable);
|
100
|
+
for (int i = 0, num = tiles.size(); i < num; ++i)
|
101
|
+
appendTo.push_back(typename Container::value_type(new Gosu::Image(tiles[i])));
|
102
|
+
}
|
103
|
+
|
104
|
+
//! Convenience function that splits a bitmap into an area of array
|
105
|
+
//! rectangles and creates images from them.
|
106
|
+
//! \param tileWidth If positive, specifies the width of one tile in
|
107
|
+
//! pixels. If negative, the bitmap is divided into -tileWidth rows.
|
108
|
+
//! \param tileHeight See tileWidth.
|
109
|
+
//! \param appendTo STL container to which the images will be appended.
|
110
|
+
//! Must provide a push_back member function; std::vector<std::tr1::shared_ptr<Image>>
|
111
|
+
//! or boost::ptr_vector<Image> are good choices.
|
112
|
+
template<typename Container>
|
113
|
+
void imagesFromTiledBitmap(Graphics& graphics, const Bitmap& bmp,
|
114
|
+
int tileWidth, int tileHeight, bool tileable, Container& appendTo)
|
115
|
+
{
|
116
|
+
std::vector<Gosu::Image> tiles = loadTiles(graphics, bmp, 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
|
+
}
|
121
|
+
|
122
|
+
#endif
|
data/Gosu/ImageData.hpp
CHANGED
@@ -1,61 +1,61 @@
|
|
1
|
-
//! \file ImageData.hpp
|
2
|
-
//! Interface of the ImageData class.
|
3
|
-
|
4
|
-
#ifndef GOSU_IMAGEDATA_HPP
|
5
|
-
#define GOSU_IMAGEDATA_HPP
|
6
|
-
|
7
|
-
#include <Gosu/Color.hpp>
|
8
|
-
#include <Gosu/GraphicsBase.hpp>
|
9
|
-
#include <Gosu/Fwd.hpp>
|
10
|
-
#include <Gosu/Platform.hpp>
|
11
|
-
|
12
|
-
namespace Gosu
|
13
|
-
{
|
14
|
-
//! Contains information about the underlying OpenGL texture and the
|
15
|
-
//! u/v space used for image data. Can be retrieved from some images
|
16
|
-
//! to use them in OpenGL operations.
|
17
|
-
struct GLTexInfo
|
18
|
-
{
|
19
|
-
int texName;
|
20
|
-
float left, right, top, bottom;
|
21
|
-
};
|
22
|
-
|
23
|
-
//! The ImageData class is an abstract base class for drawable images.
|
24
|
-
//! Instances of classes derived by ImageData are usually returned by
|
25
|
-
//! Graphics::createImage and usually only used to implement drawing
|
26
|
-
//! primitives like Image, which then provide a more specialized and
|
27
|
-
//! intuitive drawing interface.
|
28
|
-
class ImageData
|
29
|
-
{
|
30
|
-
// Non-copyable
|
31
|
-
ImageData(const ImageData&);
|
32
|
-
ImageData& operator=(const ImageData&);
|
33
|
-
|
34
|
-
public:
|
35
|
-
ImageData()
|
36
|
-
{
|
37
|
-
}
|
38
|
-
|
39
|
-
virtual ~ImageData()
|
40
|
-
{
|
41
|
-
}
|
42
|
-
|
43
|
-
virtual int width() const = 0;
|
44
|
-
virtual int height() const = 0;
|
45
|
-
|
46
|
-
virtual void draw(double x1, double y1, Color c1,
|
47
|
-
double x2, double y2, Color c2,
|
48
|
-
double x3, double y3, Color c3,
|
49
|
-
double x4, double y4, Color c4,
|
50
|
-
ZPos z, AlphaMode mode) const = 0;
|
51
|
-
|
52
|
-
virtual const GLTexInfo* glTexInfo() const = 0;
|
53
|
-
virtual Bitmap toBitmap() const = 0;
|
54
|
-
|
55
|
-
virtual GOSU_UNIQUE_PTR<ImageData> subimage(int x, int y, int width, int height) const = 0;
|
56
|
-
|
57
|
-
virtual void insert(const Bitmap& bitmap, int x, int y) = 0;
|
58
|
-
};
|
59
|
-
}
|
60
|
-
|
61
|
-
#endif
|
1
|
+
//! \file ImageData.hpp
|
2
|
+
//! Interface of the ImageData class.
|
3
|
+
|
4
|
+
#ifndef GOSU_IMAGEDATA_HPP
|
5
|
+
#define GOSU_IMAGEDATA_HPP
|
6
|
+
|
7
|
+
#include <Gosu/Color.hpp>
|
8
|
+
#include <Gosu/GraphicsBase.hpp>
|
9
|
+
#include <Gosu/Fwd.hpp>
|
10
|
+
#include <Gosu/Platform.hpp>
|
11
|
+
|
12
|
+
namespace Gosu
|
13
|
+
{
|
14
|
+
//! Contains information about the underlying OpenGL texture and the
|
15
|
+
//! u/v space used for image data. Can be retrieved from some images
|
16
|
+
//! to use them in OpenGL operations.
|
17
|
+
struct GLTexInfo
|
18
|
+
{
|
19
|
+
int texName;
|
20
|
+
float left, right, top, bottom;
|
21
|
+
};
|
22
|
+
|
23
|
+
//! The ImageData class is an abstract base class for drawable images.
|
24
|
+
//! Instances of classes derived by ImageData are usually returned by
|
25
|
+
//! Graphics::createImage and usually only used to implement drawing
|
26
|
+
//! primitives like Image, which then provide a more specialized and
|
27
|
+
//! intuitive drawing interface.
|
28
|
+
class ImageData
|
29
|
+
{
|
30
|
+
// Non-copyable
|
31
|
+
ImageData(const ImageData&);
|
32
|
+
ImageData& operator=(const ImageData&);
|
33
|
+
|
34
|
+
public:
|
35
|
+
ImageData()
|
36
|
+
{
|
37
|
+
}
|
38
|
+
|
39
|
+
virtual ~ImageData()
|
40
|
+
{
|
41
|
+
}
|
42
|
+
|
43
|
+
virtual int width() const = 0;
|
44
|
+
virtual int height() const = 0;
|
45
|
+
|
46
|
+
virtual void draw(double x1, double y1, Color c1,
|
47
|
+
double x2, double y2, Color c2,
|
48
|
+
double x3, double y3, Color c3,
|
49
|
+
double x4, double y4, Color c4,
|
50
|
+
ZPos z, AlphaMode mode) const = 0;
|
51
|
+
|
52
|
+
virtual const GLTexInfo* glTexInfo() const = 0;
|
53
|
+
virtual Bitmap toBitmap() const = 0;
|
54
|
+
|
55
|
+
virtual GOSU_UNIQUE_PTR<ImageData> subimage(int x, int y, int width, int height) const = 0;
|
56
|
+
|
57
|
+
virtual void insert(const Bitmap& bitmap, int x, int y) = 0;
|
58
|
+
};
|
59
|
+
}
|
60
|
+
|
61
|
+
#endif
|
data/Gosu/Input.hpp
CHANGED
@@ -1,149 +1,149 @@
|
|
1
|
-
//! \file Input.hpp
|
2
|
-
//! Interface of the Input class.
|
3
|
-
|
4
|
-
#ifndef GOSU_INPUT_HPP
|
5
|
-
#define GOSU_INPUT_HPP
|
6
|
-
|
7
|
-
#include <Gosu/Fwd.hpp>
|
8
|
-
#include <Gosu/Platform.hpp>
|
9
|
-
#include <Gosu/Buttons.hpp>
|
10
|
-
#include <Gosu/TR1.hpp>
|
11
|
-
|
12
|
-
#ifdef GOSU_IS_WIN
|
13
|
-
#ifndef NOMINMAX
|
14
|
-
#define NOMINMAX
|
15
|
-
#endif
|
16
|
-
#include <windows.h>
|
17
|
-
#endif
|
18
|
-
|
19
|
-
#ifdef GOSU_IS_X
|
20
|
-
#include <X11/Xlib.h>
|
21
|
-
#include <X11/Xutil.h>
|
22
|
-
#endif
|
23
|
-
|
24
|
-
#include <vector>
|
25
|
-
|
26
|
-
namespace Gosu
|
27
|
-
{
|
28
|
-
//! Very lightweight class that identifies a button (keyboard, mouse or other device).
|
29
|
-
class Button
|
30
|
-
{
|
31
|
-
unsigned id_;
|
32
|
-
|
33
|
-
public:
|
34
|
-
//! For internal use.
|
35
|
-
explicit Button(unsigned id) : id_(id) {}
|
36
|
-
//! For internal use.
|
37
|
-
unsigned id() const { return id_; }
|
38
|
-
|
39
|
-
//! Default constructor; == noButton.
|
40
|
-
Button() : id_(noButton) {}
|
41
|
-
|
42
|
-
//! Conversion from ButtonName constants.
|
43
|
-
Button(ButtonName name) : id_(name) {}
|
44
|
-
};
|
45
|
-
|
46
|
-
//! Tests whether two Buttons identify the same physical button.
|
47
|
-
inline bool operator==(Button lhs, Button rhs)
|
48
|
-
{
|
49
|
-
return lhs.id() == rhs.id();
|
50
|
-
}
|
51
|
-
inline bool operator!=(Button lhs, Button rhs)
|
52
|
-
{
|
53
|
-
return !(lhs == rhs);
|
54
|
-
}
|
55
|
-
inline bool operator<(Button lhs, Button rhs)
|
56
|
-
{
|
57
|
-
return lhs.id() < rhs.id();
|
58
|
-
}
|
59
|
-
|
60
|
-
//! Struct that saves information about a touch on the surface of a multi-
|
61
|
-
//! touch device.
|
62
|
-
//! Available even on non-iPhone platforms to make it easier to compile the
|
63
|
-
//! same source for multiple platforms.
|
64
|
-
struct Touch
|
65
|
-
{
|
66
|
-
//! Allows for identification of a touch across calls.
|
67
|
-
void* id;
|
68
|
-
//! Position of a touch on the touch screen.
|
69
|
-
float x, y;
|
70
|
-
};
|
71
|
-
typedef std::vector<Touch> Touches;
|
72
|
-
|
73
|
-
//! Manages initialization and shutdown of the input system. Only one Input
|
74
|
-
//! instance can exist per application.
|
75
|
-
class Input
|
76
|
-
{
|
77
|
-
struct Impl;
|
78
|
-
const GOSU_UNIQUE_PTR<Impl> pimpl;
|
79
|
-
#if defined(GOSU_CPP11_ENABLED)
|
80
|
-
// explicitly forbid copying and moving
|
81
|
-
Input(Input&&) = delete;
|
82
|
-
Input& operator=(Input&&) = delete;
|
83
|
-
Input(const Input&) = delete;
|
84
|
-
Input& operator=(const Input&) = delete;
|
85
|
-
#endif
|
86
|
-
|
87
|
-
public:
|
88
|
-
#ifdef GOSU_IS_IPHONE
|
89
|
-
Input(void* view, float updateInterval);
|
90
|
-
void feedTouchEvent(int type, void* touches);
|
91
|
-
#else
|
92
|
-
Input();
|
93
|
-
bool feedSDLEvent(void* event);
|
94
|
-
#endif
|
95
|
-
|
96
|
-
~Input();
|
97
|
-
|
98
|
-
//! Returns the character a button usually produces, or 0.
|
99
|
-
static wchar_t idToChar(Button btn);
|
100
|
-
//! Returns the button that has to be pressed to produce the
|
101
|
-
//! given character, or noButton.
|
102
|
-
static Button charToId(wchar_t ch);
|
103
|
-
|
104
|
-
//! Returns true if a button is currently pressed.
|
105
|
-
//! Updated every tick.
|
106
|
-
bool down(Button btn) const;
|
107
|
-
|
108
|
-
//! Returns the horizontal position of the mouse relative to the top
|
109
|
-
//! left corner of the window given to Input's constructor.
|
110
|
-
double mouseX() const;
|
111
|
-
//! See mouseX.
|
112
|
-
double mouseY() const;
|
113
|
-
|
114
|
-
//! Immediately moves the mouse as far towards the desired position
|
115
|
-
//! as possible. x and y are relativ to the window just as in the mouse
|
116
|
-
//! position accessors.
|
117
|
-
void setMousePosition(double x, double y);
|
118
|
-
|
119
|
-
// Undocumented for the moment. Also applies to currentTouches().
|
120
|
-
void setMouseFactors(double factorX, double factorY, double offsetX = 0, double offsetY = 0);
|
121
|
-
|
122
|
-
//! Currently known touches.
|
123
|
-
const Touches& currentTouches() const;
|
124
|
-
|
125
|
-
//! Accelerometer positions in all three dimensions (smoothened).
|
126
|
-
double accelerometerX() const;
|
127
|
-
double accelerometerY() const;
|
128
|
-
double accelerometerZ() const;
|
129
|
-
|
130
|
-
//! Collects new information about which buttons are pressed, where the
|
131
|
-
//! mouse is and calls onButtonUp/onButtonDown, if assigned.
|
132
|
-
void update();
|
133
|
-
|
134
|
-
//! Assignable events that are called by update. You can bind these to your own functions.
|
135
|
-
//! If you use the Window class, it will assign forward these to its own methods.
|
136
|
-
std::tr1::function<void (Button)> onButtonDown, onButtonUp;
|
137
|
-
|
138
|
-
//! Assignable events that are called by update. You can bind these to your own functions.
|
139
|
-
//! If you use the Window class, it will assign forward these to its own methods.
|
140
|
-
std::tr1::function<void (Touch)> onTouchBegan, onTouchMoved, onTouchEnded;
|
141
|
-
|
142
|
-
//! Returns the currently active TextInput instance, or 0.
|
143
|
-
TextInput* textInput() const;
|
144
|
-
//! Sets the currently active TextInput, or clears it (input = 0).
|
145
|
-
void setTextInput(TextInput* input);
|
146
|
-
};
|
147
|
-
}
|
148
|
-
|
149
|
-
#endif
|
1
|
+
//! \file Input.hpp
|
2
|
+
//! Interface of the Input class.
|
3
|
+
|
4
|
+
#ifndef GOSU_INPUT_HPP
|
5
|
+
#define GOSU_INPUT_HPP
|
6
|
+
|
7
|
+
#include <Gosu/Fwd.hpp>
|
8
|
+
#include <Gosu/Platform.hpp>
|
9
|
+
#include <Gosu/Buttons.hpp>
|
10
|
+
#include <Gosu/TR1.hpp>
|
11
|
+
|
12
|
+
#ifdef GOSU_IS_WIN
|
13
|
+
#ifndef NOMINMAX
|
14
|
+
#define NOMINMAX
|
15
|
+
#endif
|
16
|
+
#include <windows.h>
|
17
|
+
#endif
|
18
|
+
|
19
|
+
#ifdef GOSU_IS_X
|
20
|
+
#include <X11/Xlib.h>
|
21
|
+
#include <X11/Xutil.h>
|
22
|
+
#endif
|
23
|
+
|
24
|
+
#include <vector>
|
25
|
+
|
26
|
+
namespace Gosu
|
27
|
+
{
|
28
|
+
//! Very lightweight class that identifies a button (keyboard, mouse or other device).
|
29
|
+
class Button
|
30
|
+
{
|
31
|
+
unsigned id_;
|
32
|
+
|
33
|
+
public:
|
34
|
+
//! For internal use.
|
35
|
+
explicit Button(unsigned id) : id_(id) {}
|
36
|
+
//! For internal use.
|
37
|
+
unsigned id() const { return id_; }
|
38
|
+
|
39
|
+
//! Default constructor; == noButton.
|
40
|
+
Button() : id_(noButton) {}
|
41
|
+
|
42
|
+
//! Conversion from ButtonName constants.
|
43
|
+
Button(ButtonName name) : id_(name) {}
|
44
|
+
};
|
45
|
+
|
46
|
+
//! Tests whether two Buttons identify the same physical button.
|
47
|
+
inline bool operator==(Button lhs, Button rhs)
|
48
|
+
{
|
49
|
+
return lhs.id() == rhs.id();
|
50
|
+
}
|
51
|
+
inline bool operator!=(Button lhs, Button rhs)
|
52
|
+
{
|
53
|
+
return !(lhs == rhs);
|
54
|
+
}
|
55
|
+
inline bool operator<(Button lhs, Button rhs)
|
56
|
+
{
|
57
|
+
return lhs.id() < rhs.id();
|
58
|
+
}
|
59
|
+
|
60
|
+
//! Struct that saves information about a touch on the surface of a multi-
|
61
|
+
//! touch device.
|
62
|
+
//! Available even on non-iPhone platforms to make it easier to compile the
|
63
|
+
//! same source for multiple platforms.
|
64
|
+
struct Touch
|
65
|
+
{
|
66
|
+
//! Allows for identification of a touch across calls.
|
67
|
+
void* id;
|
68
|
+
//! Position of a touch on the touch screen.
|
69
|
+
float x, y;
|
70
|
+
};
|
71
|
+
typedef std::vector<Touch> Touches;
|
72
|
+
|
73
|
+
//! Manages initialization and shutdown of the input system. Only one Input
|
74
|
+
//! instance can exist per application.
|
75
|
+
class Input
|
76
|
+
{
|
77
|
+
struct Impl;
|
78
|
+
const GOSU_UNIQUE_PTR<Impl> pimpl;
|
79
|
+
#if defined(GOSU_CPP11_ENABLED)
|
80
|
+
// explicitly forbid copying and moving
|
81
|
+
Input(Input&&) = delete;
|
82
|
+
Input& operator=(Input&&) = delete;
|
83
|
+
Input(const Input&) = delete;
|
84
|
+
Input& operator=(const Input&) = delete;
|
85
|
+
#endif
|
86
|
+
|
87
|
+
public:
|
88
|
+
#ifdef GOSU_IS_IPHONE
|
89
|
+
Input(void* view, float updateInterval);
|
90
|
+
void feedTouchEvent(int type, void* touches);
|
91
|
+
#else
|
92
|
+
Input();
|
93
|
+
bool feedSDLEvent(void* event);
|
94
|
+
#endif
|
95
|
+
|
96
|
+
~Input();
|
97
|
+
|
98
|
+
//! Returns the character a button usually produces, or 0.
|
99
|
+
static wchar_t idToChar(Button btn);
|
100
|
+
//! Returns the button that has to be pressed to produce the
|
101
|
+
//! given character, or noButton.
|
102
|
+
static Button charToId(wchar_t ch);
|
103
|
+
|
104
|
+
//! Returns true if a button is currently pressed.
|
105
|
+
//! Updated every tick.
|
106
|
+
bool down(Button btn) const;
|
107
|
+
|
108
|
+
//! Returns the horizontal position of the mouse relative to the top
|
109
|
+
//! left corner of the window given to Input's constructor.
|
110
|
+
double mouseX() const;
|
111
|
+
//! See mouseX.
|
112
|
+
double mouseY() const;
|
113
|
+
|
114
|
+
//! Immediately moves the mouse as far towards the desired position
|
115
|
+
//! as possible. x and y are relativ to the window just as in the mouse
|
116
|
+
//! position accessors.
|
117
|
+
void setMousePosition(double x, double y);
|
118
|
+
|
119
|
+
// Undocumented for the moment. Also applies to currentTouches().
|
120
|
+
void setMouseFactors(double factorX, double factorY, double offsetX = 0, double offsetY = 0);
|
121
|
+
|
122
|
+
//! Currently known touches.
|
123
|
+
const Touches& currentTouches() const;
|
124
|
+
|
125
|
+
//! Accelerometer positions in all three dimensions (smoothened).
|
126
|
+
double accelerometerX() const;
|
127
|
+
double accelerometerY() const;
|
128
|
+
double accelerometerZ() const;
|
129
|
+
|
130
|
+
//! Collects new information about which buttons are pressed, where the
|
131
|
+
//! mouse is and calls onButtonUp/onButtonDown, if assigned.
|
132
|
+
void update();
|
133
|
+
|
134
|
+
//! Assignable events that are called by update. You can bind these to your own functions.
|
135
|
+
//! If you use the Window class, it will assign forward these to its own methods.
|
136
|
+
std::tr1::function<void (Button)> onButtonDown, onButtonUp;
|
137
|
+
|
138
|
+
//! Assignable events that are called by update. You can bind these to your own functions.
|
139
|
+
//! If you use the Window class, it will assign forward these to its own methods.
|
140
|
+
std::tr1::function<void (Touch)> onTouchBegan, onTouchMoved, onTouchEnded;
|
141
|
+
|
142
|
+
//! Returns the currently active TextInput instance, or 0.
|
143
|
+
TextInput* textInput() const;
|
144
|
+
//! Sets the currently active TextInput, or clears it (input = 0).
|
145
|
+
void setTextInput(TextInput* input);
|
146
|
+
};
|
147
|
+
}
|
148
|
+
|
149
|
+
#endif
|