gosu 0.7.39-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/COPYING +34 -0
  2. data/Gosu/Async.hpp +50 -0
  3. data/Gosu/Audio.hpp +163 -0
  4. data/Gosu/AutoLink.hpp +16 -0
  5. data/Gosu/Bitmap.hpp +96 -0
  6. data/Gosu/ButtonsMac.hpp +140 -0
  7. data/Gosu/ButtonsWin.hpp +140 -0
  8. data/Gosu/ButtonsX.hpp +141 -0
  9. data/Gosu/Color.hpp +204 -0
  10. data/Gosu/Directories.hpp +36 -0
  11. data/Gosu/Font.hpp +83 -0
  12. data/Gosu/Fwd.hpp +31 -0
  13. data/Gosu/Gosu.hpp +34 -0
  14. data/Gosu/Graphics.hpp +120 -0
  15. data/Gosu/GraphicsBase.hpp +66 -0
  16. data/Gosu/IO.hpp +259 -0
  17. data/Gosu/Image.hpp +138 -0
  18. data/Gosu/ImageData.hpp +58 -0
  19. data/Gosu/Input.hpp +161 -0
  20. data/Gosu/Inspection.hpp +14 -0
  21. data/Gosu/Math.hpp +135 -0
  22. data/Gosu/Platform.hpp +73 -0
  23. data/Gosu/Sockets.hpp +137 -0
  24. data/Gosu/TR1.hpp +44 -0
  25. data/Gosu/Text.hpp +71 -0
  26. data/Gosu/TextInput.hpp +70 -0
  27. data/Gosu/Timing.hpp +16 -0
  28. data/Gosu/Utility.hpp +28 -0
  29. data/Gosu/Version.hpp +526 -0
  30. data/Gosu/WinUtility.hpp +75 -0
  31. data/Gosu/Window.hpp +124 -0
  32. data/README.txt +25 -0
  33. data/examples/ChipmunkIntegration.rb +275 -0
  34. data/examples/CptnRuby.rb +223 -0
  35. data/examples/MoreChipmunkAndRMagick.rb +155 -0
  36. data/examples/OpenGLIntegration.rb +226 -0
  37. data/examples/RMagickIntegration.rb +417 -0
  38. data/examples/TextInput.rb +154 -0
  39. data/examples/Tutorial.rb +131 -0
  40. data/examples/media/Beep.wav +0 -0
  41. data/examples/media/CptnRuby Gem.png +0 -0
  42. data/examples/media/CptnRuby Map.txt +25 -0
  43. data/examples/media/CptnRuby Tileset.png +0 -0
  44. data/examples/media/CptnRuby.png +0 -0
  45. data/examples/media/Cursor.png +0 -0
  46. data/examples/media/Earth.png +0 -0
  47. data/examples/media/Explosion.wav +0 -0
  48. data/examples/media/Landscape.svg +10 -0
  49. data/examples/media/LargeStar.png +0 -0
  50. data/examples/media/Smoke.png +0 -0
  51. data/examples/media/Soldier.png +0 -0
  52. data/examples/media/Space.png +0 -0
  53. data/examples/media/Star.png +0 -0
  54. data/examples/media/Starfighter.bmp +0 -0
  55. data/lib/FreeImage.dll +0 -0
  56. data/lib/OpenAL32.dll +0 -0
  57. data/lib/gosu.for_1_8.so +0 -0
  58. data/lib/gosu.for_1_9.so +0 -0
  59. data/lib/gosu.rb +17 -0
  60. data/lib/gosu/patches.rb +75 -0
  61. data/lib/gosu/preview.rb +121 -0
  62. data/lib/gosu/run.rb +11 -0
  63. data/lib/gosu/swig_patches.rb +48 -0
  64. data/lib/gosu/zen.rb +28 -0
  65. data/lib/libsndfile.dll +0 -0
  66. metadata +138 -0
data/Gosu/Image.hpp ADDED
@@ -0,0 +1,138 @@
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/Bitmap.hpp>
9
+ #include <Gosu/TR1.hpp>
10
+ #include <memory>
11
+
12
+ namespace Gosu
13
+ {
14
+ //! Provides functionality for drawing rectangular images.
15
+ class Image
16
+ {
17
+ std::tr1::shared_ptr<ImageData> data;
18
+
19
+ public:
20
+ //! Loads an image from a given filename that can be drawn onto
21
+ //! graphics.
22
+ //! This constructor can handle PNG and BMP images. A color key of #ff00ff is
23
+ //! automatically applied to BMP type images. For more flexibility, use the
24
+ //! corresponding constructor that uses a Bitmap object.
25
+ Image(Graphics& graphics, const std::wstring& filename,
26
+ bool tileable = false);
27
+ //! Loads a portion of the the image at the given filename that can be
28
+ //! drawn onto graphics.
29
+ //! This constructor can handle PNG and BMP images. A color key of #ff00ff is
30
+ //! automatically applied to BMP type images. For more flexibility, use the
31
+ //! corresponding constructor that uses a Bitmap object.
32
+ Image(Graphics& graphics, const std::wstring& filename, unsigned srcX,
33
+ unsigned srcY, unsigned srcWidth, unsigned srcHeight,
34
+ bool tileable = false);
35
+
36
+ //! Converts the given bitmap into an image that can be drawn onto
37
+ //! graphics.
38
+ Image(Graphics& graphics, const Bitmap& source,
39
+ bool tileable = false);
40
+ //! Converts a portion of the given bitmap into an image that can be
41
+ //! drawn onto graphics.
42
+ Image(Graphics& graphics, const Bitmap& source, unsigned srcX,
43
+ unsigned srcY, unsigned srcWidth, unsigned srcHeight,
44
+ bool tileable = false);
45
+
46
+ //! Creates an Image from a user-supplied instance of the ImageData interface.
47
+ explicit Image(std::auto_ptr<ImageData> data);
48
+
49
+ unsigned width() const;
50
+ unsigned height() const;
51
+
52
+ //! Draws the image so its upper left corner is at (x; y).
53
+ void draw(double x, double y, ZPos z,
54
+ double factorX = 1, double factorY = 1,
55
+ Color c = Color::WHITE,
56
+ AlphaMode mode = amDefault) const;
57
+ //! Like draw(), but allows to give modulation colors for all four
58
+ //! corners.
59
+ void drawMod(double x, double y, ZPos z,
60
+ double factorX, double factorY,
61
+ Color c1, Color c2, Color c3, Color c4,
62
+ AlphaMode mode = amDefault) const;
63
+
64
+ //! Draws the image rotated by the given angle so that its rotation
65
+ //! center is at (x; y). Note that this is different from how all the
66
+ //! other drawing functions work!
67
+ //! \param angle See Math.hpp for an explanation of how Gosu interprets
68
+ //! angles.
69
+ //! \param centerX Relative horizontal position of the rotation center
70
+ //! on the image. 0 is the left border, 1 is the right border, 0.5 is
71
+ //! the center (and default).
72
+ //! \param centerY See centerX.
73
+ void drawRot(double x, double y, ZPos z,
74
+ double angle, double centerX = 0.5, double centerY = 0.5,
75
+ double factorX = 1, double factorY = 1,
76
+ Color c = Color::WHITE,
77
+ AlphaMode mode = amDefault) const;
78
+
79
+ //! Provides access to the underlying image data object.
80
+ ImageData& getData() const;
81
+ };
82
+
83
+ //! Convenience function that splits a BMP or PNG file into an array
84
+ //! of small rectangles and creates images from them.
85
+ //! \param tileWidth If positive, specifies the width of one tile in
86
+ //! pixels. If negative, the bitmap is divided into -tileWidth rows.
87
+ //! \param tileHeight See tileWidth.
88
+ //! \param appendTo STL container to which the images will be appended.
89
+ //! Must provide a push_back member function; vector<tr1::shared_ptr<Image>>
90
+ //! or boost::ptr_vector<Image> are good choices.
91
+ template<typename Container>
92
+ void imagesFromTiledBitmap(Graphics& graphics, const std::wstring& filename,
93
+ int tileWidth, int tileHeight, bool tileable, Container& appendTo)
94
+ {
95
+ Bitmap bmp;
96
+ loadImageFile(bmp, filename);
97
+ imagesFromTiledBitmap(graphics, bmp, tileWidth, tileHeight, tileable, appendTo);
98
+ }
99
+
100
+ //! Convenience function that splits a bitmap into an area of array
101
+ //! rectangles and creates images from them.
102
+ //! \param tileWidth If positive, specifies the width of one tile in
103
+ //! pixels. If negative, the bitmap is divided into -tileWidth rows.
104
+ //! \param tileHeight See tileWidth.
105
+ //! \param appendTo STL container to which the images will be appended.
106
+ //! Must provide a push_back member function; std::vector<std::tr1::shared_ptr<Image>>
107
+ //! or boost::ptr_vector<Image> are good choices.
108
+ template<typename Container>
109
+ void imagesFromTiledBitmap(Graphics& graphics, const Bitmap& bmp,
110
+ int tileWidth, int tileHeight, bool tileable, Container& appendTo)
111
+ {
112
+ int tilesX, tilesY;
113
+
114
+ if (tileWidth > 0)
115
+ tilesX = bmp.width() / tileWidth;
116
+ else
117
+ {
118
+ tilesX = -tileWidth;
119
+ tileWidth = bmp.width() / tilesX;
120
+ }
121
+
122
+ if (tileHeight > 0)
123
+ tilesY = bmp.height() / tileHeight;
124
+ else
125
+ {
126
+ tilesY = -tileHeight;
127
+ tileHeight = bmp.height() / tilesY;
128
+ }
129
+
130
+ for (int y = 0; y < tilesY; ++y)
131
+ for (int x = 0; x < tilesX; ++x)
132
+ appendTo.push_back(typename Container::value_type(new Image(graphics, bmp,
133
+ x * tileWidth, y * tileHeight, tileWidth, tileHeight,
134
+ tileable)));
135
+ }
136
+ }
137
+
138
+ #endif
@@ -0,0 +1,58 @@
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
+
10
+ namespace Gosu
11
+ {
12
+ //! Contains information about the underlying OpenGL texture and the
13
+ //! u/v space used for image data. Can be retrieved from some images
14
+ //! to use them in OpenGL operations.
15
+ struct GLTexInfo
16
+ {
17
+ int texName;
18
+ float left, right, top, bottom;
19
+ };
20
+
21
+ //! The ImageData class is an abstract base class for drawable images.
22
+ //! Instances of classes derived by ImageData are usually returned by
23
+ //! Graphics::createImage and usually only used to implement drawing
24
+ //! primitives like Image, which then provide a more specialized and
25
+ //! intuitive drawing interface.
26
+ class ImageData
27
+ {
28
+ // Non-copyable
29
+ ImageData(const ImageData&);
30
+ ImageData& operator=(const ImageData&);
31
+
32
+ public:
33
+ ImageData()
34
+ {
35
+ }
36
+
37
+ virtual ~ImageData()
38
+ {
39
+ }
40
+
41
+ virtual int width() const = 0;
42
+ virtual int height() const = 0;
43
+
44
+ virtual void draw(double x1, double y1, Color c1,
45
+ double x2, double y2, Color c2,
46
+ double x3, double y3, Color c3,
47
+ double x4, double y4, Color c4,
48
+ ZPos z, AlphaMode mode) const = 0;
49
+
50
+ virtual const GLTexInfo* glTexInfo() const = 0;
51
+ virtual Bitmap toBitmap() const = 0;
52
+
53
+ //! Experimental and undocumented for now.
54
+ virtual void insert(const Bitmap& bitmap, int x, int y) = 0;
55
+ };
56
+ }
57
+
58
+ #endif
data/Gosu/Input.hpp ADDED
@@ -0,0 +1,161 @@
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
+
10
+ #ifdef GOSU_IS_WIN
11
+ #include <Gosu/ButtonsWin.hpp>
12
+ #ifndef NOMINMAX
13
+ #define NOMINMAX
14
+ #endif
15
+ #include <windows.h>
16
+ #endif
17
+
18
+ #ifdef GOSU_IS_MAC
19
+ #include <Gosu/ButtonsMac.hpp>
20
+ #endif
21
+
22
+ #ifdef GOSU_IS_X
23
+ #include <X11/Xlib.h>
24
+ #include <X11/Xutil.h>
25
+ #include <X11/keysym.h>
26
+ #include <Gosu/ButtonsX.hpp>
27
+ #endif
28
+
29
+ #include <Gosu/Platform.hpp>
30
+ #include <Gosu/Fwd.hpp>
31
+ #include <Gosu/TR1.hpp>
32
+ #include <vector>
33
+
34
+ namespace Gosu
35
+ {
36
+ //! Very lightweight class that identifies a button (keyboard, mouse or other device).
37
+ class Button
38
+ {
39
+ unsigned id_;
40
+
41
+ public:
42
+ //! For internal use.
43
+ explicit Button(unsigned id) : id_(id) {}
44
+ //! For internal use.
45
+ unsigned id() const { return id_; }
46
+
47
+ //! Default constructor; == noButton.
48
+ Button() : id_(noButton) {}
49
+
50
+ //! Conversion from ButtonName constants.
51
+ Button(ButtonName name) : id_(name) {}
52
+ };
53
+
54
+ //! Tests whether two Buttons identify the same physical button.
55
+ inline bool operator==(Button lhs, Button rhs)
56
+ {
57
+ return lhs.id() == rhs.id();
58
+ }
59
+ inline bool operator!=(Button lhs, Button rhs)
60
+ {
61
+ return !(lhs == rhs);
62
+ }
63
+ inline bool operator<(Button lhs, Button rhs)
64
+ {
65
+ return lhs.id() < rhs.id();
66
+ }
67
+
68
+ //! Struct that saves information about a touch on the surface of a multi-
69
+ //! touch device.
70
+ //! Available even on non-iPhone platforms to make it easier to compile the
71
+ //! same source for multiple platforms.
72
+ struct Touch
73
+ {
74
+ //! Allows for identification of a touch across calls.
75
+ void* id;
76
+ //! Position of a touch on the touch screen.
77
+ float x, y;
78
+ };
79
+ typedef std::vector<Touch> Touches;
80
+
81
+ //! Manages initialization and shutdown of the input system. Only one Input
82
+ //! instance can exist per application.
83
+ class Input
84
+ {
85
+ struct Impl;
86
+ const std::auto_ptr<Impl> pimpl;
87
+
88
+ public:
89
+ #ifdef GOSU_IS_WIN
90
+ Input(HWND window);
91
+ #endif
92
+
93
+ #ifdef GOSU_IS_MAC
94
+ #ifdef GOSU_IS_IPHONE
95
+ Input(void* view, float updateInterval);
96
+ void feedTouchEvent(int type, void* touches);
97
+ #else
98
+ Input(void* window);
99
+ bool feedNSEvent(void* event);
100
+ #endif
101
+ #endif
102
+
103
+ #ifdef GOSU_IS_X
104
+ Input(::Display* display, ::Window window);
105
+ bool feedXEvent(::XEvent& event);
106
+ #endif
107
+
108
+ ~Input();
109
+
110
+ //! Returns the character a button usually produces, or 0.
111
+ static wchar_t idToChar(Button btn);
112
+ //! Returns the button that has to be pressed to produce the
113
+ //! given character, or noButton.
114
+ static Button charToId(wchar_t ch);
115
+
116
+ //! Returns true if a button is currently pressed.
117
+ //! Updated every tick.
118
+ bool down(Button btn) const;
119
+
120
+ //! Returns the horizontal position of the mouse relative to the top
121
+ //! left corner of the window given to Input's constructor.
122
+ double mouseX() const;
123
+ //! See mouseX.
124
+ double mouseY() const;
125
+
126
+ //! Immediately moves the mouse as far towards the desired position
127
+ //! as possible. x and y are relativ to the window just as in the mouse
128
+ //! position accessors.
129
+ void setMousePosition(double x, double y);
130
+
131
+ // Undocumented for the moment. Also applies to currentTouches().
132
+ void setMouseFactors(double factorX, double factorY);
133
+
134
+ //! Currently known touches.
135
+ const Touches& currentTouches() const;
136
+
137
+ //! Accelerometer positions in all three dimensions (smoothened).
138
+ double accelerometerX() const;
139
+ double accelerometerY() const;
140
+ double accelerometerZ() const;
141
+
142
+ //! Collects new information about which buttons are pressed, where the
143
+ //! mouse is and calls onButtonUp/onButtonDown, if assigned.
144
+ void update();
145
+
146
+ //! Assignable events that are called by update. You can bind these to your own functions.
147
+ //! If you use the Window class, it will assign forward these to its own methods.
148
+ std::tr1::function<void (Button)> onButtonDown, onButtonUp;
149
+
150
+ //! Assignable events that are called by update. You can bind these to your own functions.
151
+ //! If you use the Window class, it will assign forward these to its own methods.
152
+ std::tr1::function<void (Touch)> onTouchBegan, onTouchMoved, onTouchEnded;
153
+
154
+ //! Returns the currently active TextInput instance, or 0.
155
+ TextInput* textInput() const;
156
+ //! Sets the currently active TextInput, or clears it (input = 0).
157
+ void setTextInput(TextInput* input);
158
+ };
159
+ }
160
+
161
+ #endif
@@ -0,0 +1,14 @@
1
+ //! \file Inspection.hpp
2
+ //! A special set of functions designed for tuning Gosu games.
3
+
4
+ #ifndef GOSU_INSPECTION_HPP
5
+ #define GOSU_INSPECTION_HPP
6
+
7
+ namespace Gosu
8
+ {
9
+ //! Returns the current framerate, as determined by an unspecified and possibly
10
+ //! horrible algorithm.
11
+ int fps();
12
+ }
13
+
14
+ #endif
data/Gosu/Math.hpp ADDED
@@ -0,0 +1,135 @@
1
+ //! \file Math.hpp
2
+ //! Contains simple math functionality.
3
+
4
+ #ifndef GOSU_MATH_HPP
5
+ #define GOSU_MATH_HPP
6
+
7
+ namespace Gosu
8
+ {
9
+ //! Pi.
10
+ const double pi = 3.1415926536;
11
+
12
+ //! Truncates the fractional part of a real value. Equivalent to
13
+ //! static_cast<long>.
14
+ inline long trunc(double value)
15
+ {
16
+ return static_cast<long>(value);
17
+ }
18
+
19
+ //! Rounds a real value towards the next integer.
20
+ inline long round(double value)
21
+ {
22
+ if (value >= 0)
23
+ return static_cast<long>(value + 0.5);
24
+ else
25
+ return static_cast<long>(value - 0.5);
26
+ }
27
+
28
+ //! Returns a real value between min (inclusive) and max (exclusive).
29
+ //! Uses std::rand, so you should call std::srand before using it.
30
+ double random(double min, double max);
31
+
32
+ //! Translates between Gosu's angle system (where 0� is at the top)
33
+ //! and radians (where 0 is at the right).
34
+ inline double gosuToRadians(double angle)
35
+ {
36
+ return (angle - 90) * pi / 180;
37
+ }
38
+ //! Translates between Gosu's angle system (where 0� is at the top)
39
+ //! and radians (where 0 is at the right).
40
+ inline double radiansToGosu(double angle)
41
+ {
42
+ return angle * 180 / pi + 90;
43
+ }
44
+
45
+ //! Translates between degrees (used by Gosu) and radians, i.e. it
46
+ //! does not change the 'origin' of the angle system.
47
+ inline double degreesToRadians(double angle)
48
+ {
49
+ return angle * pi / 180;
50
+ }
51
+ //! Translates between degrees (used by Gosu) and radians, i.e. it
52
+ //! does not change the 'origin' of the angle system.
53
+ inline double radiansToDegrees(double angle)
54
+ {
55
+ return angle * 180 / pi;
56
+ }
57
+
58
+ //! Returns the horizontal distance between the origin and the point to
59
+ //! which you would get if you moved radius pixels in the direction
60
+ //! specified by angle.
61
+ //! \param angle Angle in degrees where 0.0 means upwards.
62
+ double offsetX(double angle, double radius);
63
+ //! Returns the vertical distance between the origin and the point to
64
+ //! which you would get if you moved radius pixels in the direction
65
+ //! specified by angle.
66
+ //! \param angle Angle in degrees where 0.0 means upwards.
67
+ double offsetY(double angle, double radius);
68
+ //! Returns the angle from point 1 to point 2 in degrees, where 0.0 means
69
+ //! upwards. Returns def if both points are equal.
70
+ double angle(double fromX, double fromY, double toX, double toY,
71
+ double def = 0);
72
+ //! Returns the smallest angle that can be added to angle1 to get to
73
+ //! angle2 (can be negative if counter-clockwise movement is shorter).
74
+ double angleDiff(double angle1, double angle2);
75
+ //! Normalizes an angle to fit into the range [0; 360[.
76
+ double normalizeAngle(double angle);
77
+
78
+ //! Returns value * value.
79
+ template<typename T>
80
+ T square(T value)
81
+ {
82
+ return value * value;
83
+ }
84
+
85
+ //! Returns min if value is smaller than min, max if value is larger than
86
+ //! max and value otherwise.
87
+ template<typename T>
88
+ T clamp(T value, T min, T max)
89
+ {
90
+ if (value < min)
91
+ return min;
92
+ if (value > max)
93
+ return max;
94
+ return value;
95
+ }
96
+
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
+ //! Returns (value-min) % (max-min) + min, where % always has a positive
105
+ //! result for max > min. The results are undefined for max <= min.
106
+ //! Note: This means that max is exclusive.
107
+ int wrap(int value, int min, int max);
108
+ //! Returns (value-min) % (max-min) + min, where % always has a positive
109
+ //! result for max > min. The results are undefined for max <= min.
110
+ //! Note: This means that max is exclusive.
111
+ float wrap(float value, float min, float max);
112
+ //! Returns (value-min) % (max-min) + min, where % always has a positive
113
+ //! result for max > min. The results are undefined for max <= min.
114
+ //! Note: This means that max is exclusive.
115
+ double wrap(double value, double min, double max);
116
+
117
+ //! Returns the square of the distance between two points.
118
+ inline double distanceSqr(double x1, double y1, double x2, double y2)
119
+ {
120
+ return square(x1 - x2) + square(y1 - y2);
121
+ }
122
+
123
+ //! Returns the distance between two points.
124
+ double distance(double x1, double y1, double x2, double y2);
125
+
126
+ //! 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, interpolate(0, 10, -0.5) == -5.
128
+ template<typename T>
129
+ T interpolate(T a, T b, double weight = 0.5)
130
+ {
131
+ return a * (1.0 - weight) + b * weight;
132
+ }
133
+ }
134
+
135
+ #endif