gosu 0.7.10.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING.txt +29 -0
- data/Gosu/Async.hpp +48 -0
- data/Gosu/Audio.hpp +145 -0
- data/Gosu/AutoLink.hpp +16 -0
- data/Gosu/Bitmap.hpp +85 -0
- data/Gosu/ButtonsMac.hpp +114 -0
- data/Gosu/ButtonsWin.hpp +111 -0
- data/Gosu/ButtonsX.hpp +115 -0
- data/Gosu/Color.hpp +172 -0
- data/Gosu/Directories.hpp +36 -0
- data/Gosu/Font.hpp +59 -0
- data/Gosu/Fwd.hpp +31 -0
- data/Gosu/Gosu.hpp +26 -0
- data/Gosu/Graphics.hpp +86 -0
- data/Gosu/GraphicsBase.hpp +45 -0
- data/Gosu/IO.hpp +255 -0
- data/Gosu/Image.hpp +148 -0
- data/Gosu/ImageData.hpp +45 -0
- data/Gosu/Input.hpp +116 -0
- data/Gosu/Math.hpp +95 -0
- data/Gosu/Platform.hpp +61 -0
- data/Gosu/RotFlip.hpp +116 -0
- data/Gosu/Sockets.hpp +129 -0
- data/Gosu/Text.hpp +47 -0
- data/Gosu/TextInput.hpp +57 -0
- data/Gosu/Timing.hpp +16 -0
- data/Gosu/Utility.hpp +24 -0
- data/Gosu/WinUtility.hpp +76 -0
- data/Gosu/Window.hpp +84 -0
- data/GosuImpl/Async.cpp +37 -0
- data/GosuImpl/AudioFmod.cpp +417 -0
- data/GosuImpl/AudioSDL.cpp +255 -0
- data/GosuImpl/DirectoriesMac.mm +38 -0
- data/GosuImpl/DirectoriesUnix.cpp +48 -0
- data/GosuImpl/DirectoriesWin.cpp +42 -0
- data/GosuImpl/FileUnix.cpp +100 -0
- data/GosuImpl/FileWin.cpp +83 -0
- data/GosuImpl/Graphics/Bitmap.cpp +116 -0
- data/GosuImpl/Graphics/BitmapBMP.cpp +232 -0
- data/GosuImpl/Graphics/BitmapColorKey.cpp +39 -0
- data/GosuImpl/Graphics/BitmapPNG.cpp +276 -0
- data/GosuImpl/Graphics/BitmapUtils.cpp +67 -0
- data/GosuImpl/Graphics/BlockAllocator.cpp +127 -0
- data/GosuImpl/Graphics/BlockAllocator.hpp +34 -0
- data/GosuImpl/Graphics/Color.cpp +126 -0
- data/GosuImpl/Graphics/Common.hpp +21 -0
- data/GosuImpl/Graphics/DrawOp.hpp +154 -0
- data/GosuImpl/Graphics/Font.cpp +110 -0
- data/GosuImpl/Graphics/Graphics.cpp +295 -0
- data/GosuImpl/Graphics/Image.cpp +159 -0
- data/GosuImpl/Graphics/LargeImageData.cpp +115 -0
- data/GosuImpl/Graphics/LargeImageData.hpp +37 -0
- data/GosuImpl/Graphics/RotFlip.cpp +184 -0
- data/GosuImpl/Graphics/TexChunk.cpp +77 -0
- data/GosuImpl/Graphics/TexChunk.hpp +40 -0
- data/GosuImpl/Graphics/Text.cpp +223 -0
- data/GosuImpl/Graphics/TextMac.cpp +242 -0
- data/GosuImpl/Graphics/TextPangoFT.cpp +186 -0
- data/GosuImpl/Graphics/TextWin.cpp +172 -0
- data/GosuImpl/Graphics/Texture.cpp +104 -0
- data/GosuImpl/Graphics/Texture.hpp +34 -0
- data/GosuImpl/IO.cpp +48 -0
- data/GosuImpl/InputMac.mm +677 -0
- data/GosuImpl/InputWin.cpp +444 -0
- data/GosuImpl/InputX.cpp +158 -0
- data/GosuImpl/MacUtility.hpp +48 -0
- data/GosuImpl/Math.cpp +49 -0
- data/GosuImpl/RubyGosu.swg +474 -0
- data/GosuImpl/RubyGosuStub.mm +17 -0
- data/GosuImpl/RubyGosu_DllMain.cxx +30 -0
- data/GosuImpl/RubyGosu_wrap.cxx +8521 -0
- data/GosuImpl/RubyGosu_wrap.h +31 -0
- data/GosuImpl/Sockets/CommSocket.cpp +304 -0
- data/GosuImpl/Sockets/ListenerSocket.cpp +60 -0
- data/GosuImpl/Sockets/MessageSocket.cpp +136 -0
- data/GosuImpl/Sockets/Socket.cpp +145 -0
- data/GosuImpl/Sockets/Sockets.hpp +66 -0
- data/GosuImpl/TextInputMac.mm +207 -0
- data/GosuImpl/TextInputWin.cpp +197 -0
- data/GosuImpl/TextInputX.cpp +201 -0
- data/GosuImpl/TextTTFWin.cpp +247 -0
- data/GosuImpl/TimingUnix.cpp +17 -0
- data/GosuImpl/TimingWin.cpp +28 -0
- data/GosuImpl/Utility.cpp +140 -0
- data/GosuImpl/WinMain.cpp +69 -0
- data/GosuImpl/WinUtility.cpp +137 -0
- data/GosuImpl/WindowMac.mm +466 -0
- data/GosuImpl/WindowWin.cpp +447 -0
- data/GosuImpl/WindowX.cpp +392 -0
- data/GosuImpl/X11vroot.h +118 -0
- data/README.txt +13 -0
- data/Rakefile +178 -0
- data/examples/ChipmunkIntegration.rb +275 -0
- data/examples/CptnRuby.rb +231 -0
- data/examples/MoreChipmunkAndRMagick.rb +155 -0
- data/examples/OpenGLIntegration.rb +232 -0
- data/examples/RMagickIntegration.rb +449 -0
- data/examples/TextInput.cpp +170 -0
- data/examples/TextInput.rb +139 -0
- data/examples/Tutorial.cpp +215 -0
- data/examples/Tutorial.rb +137 -0
- data/examples/media/Beep.wav +0 -0
- data/examples/media/CptnRuby Gem.png +0 -0
- data/examples/media/CptnRuby Map.txt +25 -0
- data/examples/media/CptnRuby Tileset.png +0 -0
- data/examples/media/CptnRuby.png +0 -0
- data/examples/media/Cursor.png +0 -0
- data/examples/media/Earth.png +0 -0
- data/examples/media/Explosion.wav +0 -0
- data/examples/media/LargeStar.png +0 -0
- data/examples/media/Sky.jpg +0 -0
- data/examples/media/Smoke.png +0 -0
- data/examples/media/Soldier.png +0 -0
- data/examples/media/Space.png +0 -0
- data/examples/media/Star.png +0 -0
- data/examples/media/Starfighter.bmp +0 -0
- data/linux/Makefile.in +98 -0
- data/linux/configure +5658 -0
- data/linux/configure.ac +126 -0
- data/linux/extconf.rb +11 -0
- data/mac/English.lproj/InfoPlist.strings +0 -0
- data/mac/Gosu-Info.plist +26 -0
- data/mac/Gosu.xcodeproj/project.pbxproj +1194 -0
- data/mac/RubyGosu Template-Info.plist +26 -0
- data/mac/libboost_thread_1_34_1_universal.a +0 -0
- data/mac/libboost_thread_d_1_34_1_universal.a +0 -0
- data/mac/libfmod_universal.a +0 -0
- data/mac/libpng_universal.a +0 -0
- data/mac/libz_universal.a +0 -0
- data/reference/Async_8hpp-source.html +70 -0
- data/reference/Audio_8hpp-source.html +114 -0
- data/reference/Audio_8hpp.html +50 -0
- data/reference/AutoLink_8hpp-source.html +38 -0
- data/reference/AutoLink_8hpp.html +34 -0
- data/reference/Bitmap_8hpp-source.html +85 -0
- data/reference/Bitmap_8hpp.html +58 -0
- data/reference/ButtonsMac_8hpp-source.html +133 -0
- data/reference/ButtonsWin_8hpp-source.html +133 -0
- data/reference/ButtonsX_8hpp-source.html +134 -0
- data/reference/Color_8hpp-source.html +169 -0
- data/reference/Color_8hpp.html +85 -0
- data/reference/Directories_8hpp-source.html +42 -0
- data/reference/Directories_8hpp.html +46 -0
- data/reference/Font_8hpp-source.html +65 -0
- data/reference/Font_8hpp.html +41 -0
- data/reference/Fwd_8hpp-source.html +52 -0
- data/reference/Fwd_8hpp.html +37 -0
- data/reference/Gosu_8hpp-source.html +48 -0
- data/reference/Gosu_8hpp.html +34 -0
- data/reference/GraphicsBase_8hpp-source.html +57 -0
- data/reference/GraphicsBase_8hpp.html +56 -0
- data/reference/Graphics_8hpp-source.html +96 -0
- data/reference/Graphics_8hpp.html +53 -0
- data/reference/IO_8hpp-source.html +255 -0
- data/reference/IO_8hpp.html +74 -0
- data/reference/ImageData_8hpp-source.html +62 -0
- data/reference/ImageData_8hpp.html +43 -0
- data/reference/Image_8hpp-source.html +126 -0
- data/reference/Image_8hpp.html +48 -0
- data/reference/Input_8hpp-source.html +118 -0
- data/reference/Input_8hpp.html +50 -0
- data/reference/Math_8hpp-source.html +92 -0
- data/reference/Math_8hpp.html +74 -0
- data/reference/Platform_8hpp-source.html +83 -0
- data/reference/Platform_8hpp.html +73 -0
- data/reference/RotFlip_8hpp-source.html +138 -0
- data/reference/RotFlip_8hpp.html +77 -0
- data/reference/Sockets_8hpp-source.html +130 -0
- data/reference/Sockets_8hpp.html +66 -0
- data/reference/TextInput_8hpp-source.html +64 -0
- data/reference/TextInput_8hpp.html +41 -0
- data/reference/Text_8hpp-source.html +51 -0
- data/reference/Text_8hpp.html +46 -0
- data/reference/Timing_8hpp-source.html +36 -0
- data/reference/Timing_8hpp.html +42 -0
- data/reference/Utility_8hpp-source.html +44 -0
- data/reference/Utility_8hpp.html +48 -0
- data/reference/WinUtility_8hpp-source.html +79 -0
- data/reference/WinUtility_8hpp.html +64 -0
- data/reference/Window_8hpp-source.html +91 -0
- data/reference/Window_8hpp.html +41 -0
- data/reference/annotated.html +51 -0
- data/reference/classGosu_1_1Audio-members.html +34 -0
- data/reference/classGosu_1_1Audio.html +46 -0
- data/reference/classGosu_1_1Bitmap-members.html +44 -0
- data/reference/classGosu_1_1Bitmap.html +263 -0
- data/reference/classGosu_1_1Buffer-members.html +44 -0
- data/reference/classGosu_1_1Buffer.html +78 -0
- data/reference/classGosu_1_1Buffer.png +0 -0
- data/reference/classGosu_1_1Button-members.html +36 -0
- data/reference/classGosu_1_1Button.html +143 -0
- data/reference/classGosu_1_1Color-members.html +56 -0
- data/reference/classGosu_1_1Color.html +387 -0
- data/reference/classGosu_1_1File-members.html +41 -0
- data/reference/classGosu_1_1File.html +69 -0
- data/reference/classGosu_1_1File.png +0 -0
- data/reference/classGosu_1_1Font-members.html +39 -0
- data/reference/classGosu_1_1Font.html +309 -0
- data/reference/classGosu_1_1Graphics-members.html +50 -0
- data/reference/classGosu_1_1Graphics.html +234 -0
- data/reference/classGosu_1_1Image-members.html +45 -0
- data/reference/classGosu_1_1Image.html +518 -0
- data/reference/classGosu_1_1ImageData-members.html +37 -0
- data/reference/classGosu_1_1ImageData.html +60 -0
- data/reference/classGosu_1_1Input-members.html +44 -0
- data/reference/classGosu_1_1Input.html +223 -0
- data/reference/classGosu_1_1MessageSocket-members.html +40 -0
- data/reference/classGosu_1_1MessageSocket.html +233 -0
- data/reference/classGosu_1_1Resource-members.html +39 -0
- data/reference/classGosu_1_1Resource.html +116 -0
- data/reference/classGosu_1_1Resource.png +0 -0
- data/reference/classGosu_1_1Sample-members.html +37 -0
- data/reference/classGosu_1_1Sample.html +200 -0
- data/reference/classGosu_1_1SampleInstance-members.html +38 -0
- data/reference/classGosu_1_1SampleInstance.html +169 -0
- data/reference/classGosu_1_1Song-members.html +43 -0
- data/reference/classGosu_1_1Song.html +260 -0
- data/reference/classGosu_1_1TextInput-members.html +38 -0
- data/reference/classGosu_1_1TextInput.html +121 -0
- data/reference/classGosu_1_1Window-members.html +50 -0
- data/reference/classGosu_1_1Window.html +271 -0
- data/reference/doxyfile +233 -0
- data/reference/doxygen.css +433 -0
- data/reference/doxygen.png +0 -0
- data/reference/files.html +54 -0
- data/reference/functions.html +236 -0
- data/reference/functions_enum.html +45 -0
- data/reference/functions_func.html +227 -0
- data/reference/functions_vars.html +47 -0
- data/reference/hierarchy.html +53 -0
- data/reference/index.html +26 -0
- data/reference/namespaceGosu.html +2890 -0
- data/reference/namespaceGosu_1_1Colors.html +70 -0
- data/reference/namespaceGosu_1_1Win.html +275 -0
- data/reference/namespacemembers.html +216 -0
- data/reference/namespacemembers_enum.html +52 -0
- data/reference/namespacemembers_eval.html +54 -0
- data/reference/namespacemembers_func.html +185 -0
- data/reference/namespacemembers_type.html +46 -0
- data/reference/namespacemembers_vars.html +46 -0
- data/reference/namespaces.html +35 -0
- data/reference/tab_b.gif +0 -0
- data/reference/tab_l.gif +0 -0
- data/reference/tab_r.gif +0 -0
- data/reference/tabs.css +102 -0
- data/windows/Gosu.sln +29 -0
- data/windows/Gosu.vcproj +553 -0
- data/windows/RubyGosu.vcproj +138 -0
- metadata +305 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
#ifndef GOSU_MACUTILITY_HPP
|
2
|
+
#define GOSU_MACUTILITY_HPP
|
3
|
+
|
4
|
+
#ifdef __OBJC__
|
5
|
+
#import <objc/objc.h>
|
6
|
+
#import <stdexcept>
|
7
|
+
#import <boost/utility.hpp>
|
8
|
+
namespace Gosu
|
9
|
+
{
|
10
|
+
template<typename T>
|
11
|
+
class ObjRef : boost::noncopyable
|
12
|
+
{
|
13
|
+
T* ptr;
|
14
|
+
public:
|
15
|
+
ObjRef(T* ptr = nil)
|
16
|
+
: ptr(ptr)
|
17
|
+
{
|
18
|
+
}
|
19
|
+
|
20
|
+
~ObjRef()
|
21
|
+
{
|
22
|
+
if (ptr)
|
23
|
+
[ptr release];
|
24
|
+
}
|
25
|
+
|
26
|
+
void reset(T* newPtr = nil)
|
27
|
+
{
|
28
|
+
if (ptr)
|
29
|
+
[ptr release];
|
30
|
+
ptr = newPtr;
|
31
|
+
}
|
32
|
+
|
33
|
+
T* get() const
|
34
|
+
{
|
35
|
+
return ptr;
|
36
|
+
}
|
37
|
+
|
38
|
+
T* obj() const
|
39
|
+
{
|
40
|
+
if (!ptr)
|
41
|
+
throw std::logic_error("Tried dereferencing nil");
|
42
|
+
return ptr;
|
43
|
+
}
|
44
|
+
};
|
45
|
+
}
|
46
|
+
#endif
|
47
|
+
|
48
|
+
#endif
|
data/GosuImpl/Math.cpp
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#include <Gosu/Math.hpp>
|
2
|
+
#include <cmath>
|
3
|
+
#include <cstdlib>
|
4
|
+
|
5
|
+
double Gosu::random(double min, double max)
|
6
|
+
{
|
7
|
+
double rnd = std::rand();
|
8
|
+
return rnd / RAND_MAX * (max - min) + min;
|
9
|
+
}
|
10
|
+
|
11
|
+
double Gosu::offsetX(double angle, double radius)
|
12
|
+
{
|
13
|
+
return +std::sin(angle / 180 * pi) * radius;
|
14
|
+
}
|
15
|
+
|
16
|
+
double Gosu::offsetY(double angle, double radius)
|
17
|
+
{
|
18
|
+
return -std::cos(angle / 180 * pi) * radius;
|
19
|
+
}
|
20
|
+
|
21
|
+
double Gosu::angle(double fromX, double fromY, double toX, double toY,
|
22
|
+
double def)
|
23
|
+
{
|
24
|
+
double distX = toX - fromX;
|
25
|
+
double distY = toY - fromY;
|
26
|
+
|
27
|
+
if (distX == 0 && distY == 0)
|
28
|
+
return def;
|
29
|
+
else
|
30
|
+
return std::atan2(distY, distX) / pi * 180 + 90;
|
31
|
+
}
|
32
|
+
|
33
|
+
double Gosu::angleDiff(double from, double to)
|
34
|
+
{
|
35
|
+
return normalizeAngle(std::fmod(to - from + 180, 360) - 180);
|
36
|
+
}
|
37
|
+
|
38
|
+
double Gosu::normalizeAngle(double angle)
|
39
|
+
{
|
40
|
+
double result = std::fmod(angle, 360);
|
41
|
+
if (result < 0)
|
42
|
+
result += 360;
|
43
|
+
return result;
|
44
|
+
}
|
45
|
+
|
46
|
+
double Gosu::distance(double x1, double y1, double x2, double y2)
|
47
|
+
{
|
48
|
+
return std::sqrt(distanceSqr(x1, y1, x2, y2));
|
49
|
+
}
|
@@ -0,0 +1,474 @@
|
|
1
|
+
// Mini Swig Style Improvement List:
|
2
|
+
// - %predicate instead of %rename
|
3
|
+
// - use Python names for op overloading
|
4
|
+
|
5
|
+
%trackobjects;
|
6
|
+
%include exception.i
|
7
|
+
|
8
|
+
// Don't complain about ignored operators.
|
9
|
+
#pragma SWIG nowarn=378
|
10
|
+
|
11
|
+
// The docs make it seem like this is a generally good idea.
|
12
|
+
%feature("compactdefaultargs");
|
13
|
+
|
14
|
+
// Overriding virtuals is only necessary in Gosu::Window.
|
15
|
+
%feature("director") Gosu::Window;
|
16
|
+
|
17
|
+
// Resolve typedefs that SWIG doesn't recognize.
|
18
|
+
%apply unsigned char { boost::uint8_t };
|
19
|
+
%apply unsigned long { boost::uint32_t };
|
20
|
+
|
21
|
+
// Custom typemaps for wchar/wstring.
|
22
|
+
#pragma SWIG nowarn=-490,-319
|
23
|
+
%typemap(in) wchar_t {
|
24
|
+
VALUE localTemporary = rb_obj_as_string($input);
|
25
|
+
std::wstring localTemporary2 = Gosu::utf8ToWstring(StringValueCStr(localTemporary));
|
26
|
+
$1 = localTemporary2.empty() ? 0 : localTemporary2.at(0);
|
27
|
+
}
|
28
|
+
%typemap(out) wchar_t {
|
29
|
+
$result = rb_str_new2(Gosu::wstringToUTF8(std::wstring(1, $1)).c_str());
|
30
|
+
}
|
31
|
+
%typemap(in) const std::wstring& (std::wstring temp) {
|
32
|
+
VALUE localTemporary = rb_obj_as_string($input);
|
33
|
+
temp = Gosu::utf8ToWstring(StringValueCStr(localTemporary));
|
34
|
+
$1 = &temp;
|
35
|
+
}
|
36
|
+
%apply const std::wstring& { std::wstring, const std::string };
|
37
|
+
%typemap(out) std::wstring {
|
38
|
+
$result = rb_str_new2(Gosu::wstringToUTF8($1).c_str());
|
39
|
+
}
|
40
|
+
|
41
|
+
%typemap(in) Gosu::Button {
|
42
|
+
$1 = Gosu::Button(NUM2LONG($input));
|
43
|
+
}
|
44
|
+
%typemap(out) Gosu::Button {
|
45
|
+
$result = LONG2NUM($1.getId());
|
46
|
+
}
|
47
|
+
%typemap(directorin) Gosu::Button {
|
48
|
+
$input = LONG2NUM($1.getId());
|
49
|
+
}
|
50
|
+
|
51
|
+
// Typemaps for enums that should be given in as symbols.
|
52
|
+
%typemap(in) Gosu::AlphaMode {
|
53
|
+
VALUE localTemporary = rb_obj_as_string($input);
|
54
|
+
if (!strcmp(StringValueCStr(localTemporary), "default"))
|
55
|
+
$1 = Gosu::amDefault;
|
56
|
+
else if (!strcmp(StringValueCStr(localTemporary), "additive"))
|
57
|
+
$1 = Gosu::amAdditive;
|
58
|
+
else
|
59
|
+
SWIG_exception_fail(SWIG_ValueError, "invalid alpha mode");
|
60
|
+
}
|
61
|
+
%typemap(in) Gosu::TextAlign {
|
62
|
+
VALUE localTemporary = rb_obj_as_string($input);
|
63
|
+
if (!strcmp(StringValueCStr(localTemporary), "left"))
|
64
|
+
$1 = Gosu::taLeft;
|
65
|
+
else if (!strcmp(StringValueCStr(localTemporary), "center"))
|
66
|
+
$1 = Gosu::taCenter;
|
67
|
+
else if (!strcmp(StringValueCStr(localTemporary), "right"))
|
68
|
+
$1 = Gosu::taRight;
|
69
|
+
else if (!strcmp(StringValueCStr(localTemporary), "justify"))
|
70
|
+
$1 = Gosu::taJustify;
|
71
|
+
else
|
72
|
+
SWIG_exception_fail(SWIG_ValueError, "invalid text align");
|
73
|
+
}
|
74
|
+
%typemap(in) Gosu::Song::Type {
|
75
|
+
VALUE localTemporary = rb_obj_as_string($input);
|
76
|
+
if (!strcmp(StringValueCStr(localTemporary), "stream"))
|
77
|
+
$1 = Gosu::Song::stStream;
|
78
|
+
else if (!strcmp(StringValueCStr(localTemporary), "module"))
|
79
|
+
$1 = Gosu::Song::stModule;
|
80
|
+
else
|
81
|
+
SWIG_exception_fail(SWIG_ValueError, "invalid song type");
|
82
|
+
}
|
83
|
+
|
84
|
+
// Allow integral constants to be passed in place of Color values.
|
85
|
+
%typemap(in) Gosu::Color {
|
86
|
+
void* ptr;
|
87
|
+
int res = SWIG_ConvertPtr($input, &ptr, SWIGTYPE_p_Gosu__Color, 0);
|
88
|
+
if (!SWIG_IsOK(res))
|
89
|
+
// TODO: error checking
|
90
|
+
$1 = Gosu::Color(NUM2UINT($input));
|
91
|
+
else if (!ptr)
|
92
|
+
SWIG_exception_fail(SWIG_ValueError, "invalid null reference of type Gosu::Color");
|
93
|
+
else
|
94
|
+
$1 = *reinterpret_cast<Gosu::Color*>(ptr);
|
95
|
+
}
|
96
|
+
|
97
|
+
// Header inclusion (order irrelevant)
|
98
|
+
%module(directors="1") gosu
|
99
|
+
%{
|
100
|
+
// Avoid Ruby Macro Hell on Windows...
|
101
|
+
#undef write
|
102
|
+
#undef close
|
103
|
+
#undef read
|
104
|
+
#undef sleep
|
105
|
+
#undef Sleep
|
106
|
+
|
107
|
+
//#ifndef WIN32
|
108
|
+
//#include <Gosu/Async.hpp>
|
109
|
+
//#endif
|
110
|
+
|
111
|
+
#include <Gosu/Audio.hpp>
|
112
|
+
#include <Gosu/Color.hpp>
|
113
|
+
#include <Gosu/Font.hpp>
|
114
|
+
#include <Gosu/GraphicsBase.hpp>
|
115
|
+
#include <Gosu/Graphics.hpp>
|
116
|
+
#include <Gosu/Image.hpp>
|
117
|
+
#include <Gosu/ImageData.hpp>
|
118
|
+
#include <Gosu/Input.hpp>
|
119
|
+
#include <Gosu/IO.hpp>
|
120
|
+
#include <Gosu/Math.hpp>
|
121
|
+
#include <Gosu/Text.hpp>
|
122
|
+
#include <Gosu/TextInput.hpp>
|
123
|
+
#include <Gosu/Timing.hpp>
|
124
|
+
#include <Gosu/Utility.hpp>
|
125
|
+
#include <Gosu/Window.hpp>
|
126
|
+
|
127
|
+
#include <sstream>
|
128
|
+
|
129
|
+
// New Ruby 1.9 syntax (for compilation with Ruby 1.8)
|
130
|
+
#ifndef RSTRING_LEN
|
131
|
+
# define RSTRING_LEN(x) RSTRING(x)->len
|
132
|
+
#endif
|
133
|
+
#ifndef RSTRING_PTR
|
134
|
+
# define RSTRING_PTR(x) RSTRING(x)->ptr
|
135
|
+
#endif
|
136
|
+
#ifndef RARRAY_LEN
|
137
|
+
# define RARRAY_LEN(x) RARRAY(x)->len
|
138
|
+
#endif
|
139
|
+
#ifndef RARRAY_PTR
|
140
|
+
# define RARRAY_PTR(x) RARRAY(x)->ptr
|
141
|
+
#endif
|
142
|
+
|
143
|
+
namespace GosusDarkSide
|
144
|
+
{
|
145
|
+
// TODO: Find a way for this to fit into Gosu's design.
|
146
|
+
// This can point to a function that wants to be called every
|
147
|
+
// frame, e.g. rb_thread_schedule.
|
148
|
+
typedef void (*HookOfHorror)();
|
149
|
+
extern HookOfHorror oncePerTick;
|
150
|
+
|
151
|
+
void yieldToOtherRubyThreads()
|
152
|
+
{
|
153
|
+
rb_thread_schedule();
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
// Allow filenames and RMagick Images to be passed where Bitmaps are needed.
|
158
|
+
namespace Gosu
|
159
|
+
{
|
160
|
+
Gosu::Bitmap loadBitmap(VALUE val)
|
161
|
+
{
|
162
|
+
// Try to treat as filename first.
|
163
|
+
if (rb_respond_to(val, rb_intern("to_str")))
|
164
|
+
{
|
165
|
+
const char* filename = STR2CSTR(rb_funcall(val, rb_intern("to_str"), 0));
|
166
|
+
return quickLoadBitmap(Gosu::utf8ToWstring(filename));
|
167
|
+
}
|
168
|
+
|
169
|
+
// Otherwise, try to call .to_blob on it.
|
170
|
+
// (Works with RMagick).
|
171
|
+
VALUE conversion = rb_str_new2("to_blob { self.format = 'RGBA'; self.depth = 8 }");
|
172
|
+
VALUE blob = rb_obj_instance_eval(1, &conversion, val);
|
173
|
+
Check_SafeStr(blob);
|
174
|
+
unsigned width = NUM2UINT(rb_funcall(val, rb_intern("columns"), 0));
|
175
|
+
unsigned height = NUM2UINT(rb_funcall(val, rb_intern("rows"), 0));
|
176
|
+
|
177
|
+
if (width * height * 4 != RSTRING_LEN(blob))
|
178
|
+
throw std::logic_error("Blob length mismatch!");
|
179
|
+
Bitmap result;
|
180
|
+
result.resize(width, height);
|
181
|
+
const unsigned* rgbaIter = reinterpret_cast<const unsigned*>(RSTRING_PTR(blob));
|
182
|
+
for (unsigned y = 0; y < height; ++y)
|
183
|
+
for (unsigned x = 0; x < width; ++x)
|
184
|
+
{
|
185
|
+
unsigned rgba = *rgbaIter;
|
186
|
+
result.setPixel(x, y, Gosu::Color(rgba).abgr()); // swap R and B
|
187
|
+
++rgbaIter;
|
188
|
+
}
|
189
|
+
return result;
|
190
|
+
}
|
191
|
+
}
|
192
|
+
%}
|
193
|
+
|
194
|
+
// Exception wrapping
|
195
|
+
%exception {
|
196
|
+
try {
|
197
|
+
$action
|
198
|
+
} catch(const std::runtime_error& e) {
|
199
|
+
SWIG_exception(SWIG_RuntimeError, e.what());
|
200
|
+
}
|
201
|
+
}
|
202
|
+
|
203
|
+
// Miscellaneous functions (timing, math)
|
204
|
+
%ignore Gosu::sleep;
|
205
|
+
%include "../Gosu/Timing.hpp"
|
206
|
+
%ignore Gosu::pi;
|
207
|
+
%include "../Gosu/Math.hpp"
|
208
|
+
%ignore Gosu::textWidth;
|
209
|
+
%ignore Gosu::createText;
|
210
|
+
%ignore Gosu::textHeight;
|
211
|
+
%ignore Gosu::drawText;
|
212
|
+
%include "../Gosu/Text.hpp"
|
213
|
+
|
214
|
+
|
215
|
+
// Graphics:
|
216
|
+
|
217
|
+
// ZPos, AlphaMode, FontFlags, TextAlign
|
218
|
+
%include "../Gosu/GraphicsBase.hpp"
|
219
|
+
|
220
|
+
// Color
|
221
|
+
%rename("alpha=") setAlpha;
|
222
|
+
%rename("red=") setRed;
|
223
|
+
%rename("green=") setGreen;
|
224
|
+
%rename("blue=") setBlue;
|
225
|
+
%rename("hue=") setHue;
|
226
|
+
%rename("saturation=") setSaturation;
|
227
|
+
%rename("value=") setValue;
|
228
|
+
%include "std_string.i"
|
229
|
+
%include "../Gosu/Color.hpp"
|
230
|
+
%extend Gosu::Color {
|
231
|
+
std::string toS() const {
|
232
|
+
std::ostringstream stream;
|
233
|
+
stream << "(" << static_cast<int>($self->alpha())
|
234
|
+
<< "," << static_cast<int>($self->red())
|
235
|
+
<< "," << static_cast<int>($self->green())
|
236
|
+
<< "," << static_cast<int>($self->blue()) << ")";
|
237
|
+
return stream.str();
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
// Font
|
242
|
+
// Hackishly allow the user to pass Window& instead of Graphics&.
|
243
|
+
%ignore Gosu::Font::Font(Graphics& graphics, const std::wstring& fontName, unsigned height);
|
244
|
+
%include "../Gosu/Font.hpp"
|
245
|
+
%extend Gosu::Font {
|
246
|
+
Font(Gosu::Window& window, const std::wstring& fontName, unsigned height) {
|
247
|
+
return new Gosu::Font(window.graphics(), fontName, height);
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
// AsyncResult
|
252
|
+
|
253
|
+
//#ifndef WIN32
|
254
|
+
//%ignore Gosu::asyncNewImage;
|
255
|
+
//%ignore Gosu::asyncNewImage_Impl;
|
256
|
+
//%ignore Gosu::AsyncResult::takeValue;
|
257
|
+
//%include "../Gosu/Async.hpp"
|
258
|
+
//%extend Gosu::AsyncResult {
|
259
|
+
// %newobject value;
|
260
|
+
// Gosu::Image* value() {
|
261
|
+
// return $self->takeValue().release();
|
262
|
+
// }
|
263
|
+
//}
|
264
|
+
//%template(AsyncImageResult) Gosu::AsyncResult<Gosu::Image>;
|
265
|
+
//#endif
|
266
|
+
|
267
|
+
%ignore Gosu::ImageData;
|
268
|
+
%rename("tex_name") texName;
|
269
|
+
%include "../Gosu/ImageData.hpp"
|
270
|
+
|
271
|
+
// Image
|
272
|
+
// Hackishly allow the user to pass Window& instead of Graphics&.
|
273
|
+
// Also, provide convenience functions.
|
274
|
+
|
275
|
+
// Typemap to return an array of images (for loadTiles)
|
276
|
+
%typemap(out) std::vector<Gosu::Image*> {
|
277
|
+
$result = rb_ary_new2($1.size());
|
278
|
+
for (unsigned i = 0; i < $1.size(); i++) {
|
279
|
+
VALUE curImg = SWIG_NewPointerObj(SWIG_as_voidptr((*&$1)[i]), SWIGTYPE_p_Gosu__Image, SWIG_POINTER_OWN);
|
280
|
+
rb_ary_store($result, i, curImg);
|
281
|
+
}
|
282
|
+
}
|
283
|
+
|
284
|
+
%ignore Gosu::Image::Image(Graphics& graphics, const std::wstring& filename, bool hardBorders = false);
|
285
|
+
%ignore Gosu::Image::Image(Graphics& graphics, const std::wstring& filename, unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight, bool hardBorders = false);
|
286
|
+
%ignore Gosu::Image::Image(Graphics& graphics, const Bitmap& source, bool hardBorders = false);
|
287
|
+
%ignore Gosu::Image::Image(Graphics& graphics, const Bitmap& source, unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight, bool hardBorders = false);
|
288
|
+
%include "../Gosu/Image.hpp"
|
289
|
+
%extend Gosu::Image {
|
290
|
+
Image(Gosu::Window& window, VALUE source, bool hardBorders = false) {
|
291
|
+
return new Gosu::Image(window.graphics(), Gosu::loadBitmap(source), hardBorders);
|
292
|
+
}
|
293
|
+
Image(Gosu::Window& window, VALUE source, bool hardBorders,
|
294
|
+
unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight) {
|
295
|
+
return new Gosu::Image(window.graphics(), Gosu::loadBitmap(source),
|
296
|
+
srcX, srcY, srcWidth, srcHeight, hardBorders);
|
297
|
+
}
|
298
|
+
#ifndef WIN32
|
299
|
+
// %newobject asyncNew;
|
300
|
+
// static Gosu::AsyncResult<Gosu::Image>* asyncNew(Gosu::Window& window, const std::wstring& filename) {
|
301
|
+
// return new Gosu::AsyncResult<Gosu::Image>(Gosu::asyncNewImage(window, filename));
|
302
|
+
// }
|
303
|
+
#endif
|
304
|
+
void drawAsQuad(double x1, double y1, Color c1,
|
305
|
+
double x2, double y2, Color c2,
|
306
|
+
double x3, double y3, Color c3,
|
307
|
+
double x4, double y4, Color c4,
|
308
|
+
ZPos z, AlphaMode mode = Gosu::amDefault) {
|
309
|
+
$self->getData().draw(x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z, mode);
|
310
|
+
}
|
311
|
+
%newobject glTexInfo;
|
312
|
+
Gosu::GLTexInfo* glTexInfo() const {
|
313
|
+
boost::optional<Gosu::GLTexInfo> info = $self->getData().glTexInfo();
|
314
|
+
if (info)
|
315
|
+
return new Gosu::GLTexInfo(*info);
|
316
|
+
else
|
317
|
+
return 0;
|
318
|
+
}
|
319
|
+
%newobject fromText;
|
320
|
+
static Gosu::Image* fromText(Gosu::Window& window, const std::wstring& text,
|
321
|
+
const std::wstring& fontName, unsigned fontHeight,
|
322
|
+
unsigned lineSpacing, unsigned maxWidth, TextAlign align) {
|
323
|
+
Gosu::Bitmap bmp = Gosu::createText(text, fontName, fontHeight, lineSpacing, maxWidth, align);
|
324
|
+
return new Gosu::Image(window.graphics(), bmp);
|
325
|
+
}
|
326
|
+
static std::vector<Gosu::Image*> loadTiles(Gosu::Window& window, VALUE source,
|
327
|
+
int tileWidth, int tileHeight, bool hardBorders) {
|
328
|
+
std::vector<Gosu::Image*> vec;
|
329
|
+
// TODO: const correctness (<- did I mean exception safety?)
|
330
|
+
Gosu::imagesFromTiledBitmap(window.graphics(), Gosu::loadBitmap(source),
|
331
|
+
tileWidth, tileHeight, hardBorders, vec);
|
332
|
+
return vec;
|
333
|
+
}
|
334
|
+
}
|
335
|
+
|
336
|
+
// Audio:
|
337
|
+
|
338
|
+
%ignore Gosu::Audio;
|
339
|
+
%ignore Gosu::Sample::Sample(Audio& audio, const std::wstring& filename);
|
340
|
+
%ignore Gosu::Sample::Sample(Audio& audio, Reader reader);
|
341
|
+
%ignore Gosu::Song::Song(Audio& audio, const std::wstring& filename);
|
342
|
+
%ignore Gosu::Song::Song(Audio& audio, Type type, Reader reader);
|
343
|
+
%rename("playing?") playing;
|
344
|
+
%rename("volume=") changeVolume;
|
345
|
+
%rename("pan=") changePan;
|
346
|
+
%rename("speed=") changeSpeed;
|
347
|
+
%include "../Gosu/Audio.hpp"
|
348
|
+
%extend Gosu::Sample {
|
349
|
+
Sample(Gosu::Window& window, const std::string& filename) {
|
350
|
+
return new Gosu::Sample(window.audio(), Gosu::utf8ToWstring(filename));
|
351
|
+
}
|
352
|
+
}
|
353
|
+
%extend Gosu::Song {
|
354
|
+
Song(Gosu::Window& window, const std::string& filename) {
|
355
|
+
return new Gosu::Song(window.audio(), Gosu::utf8ToWstring(filename));
|
356
|
+
}
|
357
|
+
}
|
358
|
+
|
359
|
+
|
360
|
+
// Input and Window:
|
361
|
+
|
362
|
+
// Button ID constants
|
363
|
+
%include "../Gosu/ButtonsMac.hpp"
|
364
|
+
%init %{
|
365
|
+
// Backwards compatibility: import the constants into Gosu::Button.
|
366
|
+
rb_eval_string("module Gosu::Button; Gosu.constants.each { |c| const_set(c, Gosu.const_get(c)) }; end");
|
367
|
+
|
368
|
+
// Extend Numeric with simple angle conversion methods.
|
369
|
+
// IMPR: Maybe faster in C?
|
370
|
+
rb_eval_string("class Numeric;"
|
371
|
+
" def gosu_to_radians; (self - 90) * Math::PI / 180.0; end;"
|
372
|
+
" def radians_to_gosu; self * 180.0 / Math::PI + 90; end;"
|
373
|
+
"end");
|
374
|
+
|
375
|
+
GosusDarkSide::oncePerTick = GosusDarkSide::yieldToOtherRubyThreads;
|
376
|
+
%}
|
377
|
+
|
378
|
+
// TextInput
|
379
|
+
%ignore Gosu::TextInput::feedNSEvent(void*);
|
380
|
+
%ignore Gosu::TextInput::feedMessage(unsigned long, unsigned long, unsigned long);
|
381
|
+
%ignore Gosu::TextInput::feedButtonId(unsigned);
|
382
|
+
%ignore Gosu::TextInput::caretPos() const;
|
383
|
+
%ignore Gosu::TextInput::selectionStart() const;
|
384
|
+
%rename("text=") setText;
|
385
|
+
%include "../Gosu/TextInput.hpp"
|
386
|
+
%extend Gosu::TextInput {
|
387
|
+
// Fix indices into UTF-8 string
|
388
|
+
unsigned caret_pos() const {
|
389
|
+
return Gosu::wstringToUTF8($self->text().substr(0, $self->caretPos())).size();
|
390
|
+
}
|
391
|
+
unsigned selection_start() const {
|
392
|
+
return Gosu::wstringToUTF8($self->text().substr(0, $self->selectionStart())).size();
|
393
|
+
}
|
394
|
+
};
|
395
|
+
|
396
|
+
// Window
|
397
|
+
%rename("caption=") setCaption;
|
398
|
+
%rename("button_down?") isButtonDown;
|
399
|
+
%rename("text_input=") setTextInput;
|
400
|
+
%markfunc Gosu::Window "markWindow";
|
401
|
+
%include "../Gosu/Window.hpp"
|
402
|
+
|
403
|
+
%header %{
|
404
|
+
static void markWindow(void* window) {
|
405
|
+
Gosu::TextInput* ti = static_cast<Gosu::Window*>(window)->input().textInput();
|
406
|
+
if (VALUE ti_value = SWIG_RubyInstanceFor(ti))
|
407
|
+
rb_gc_mark(ti_value);
|
408
|
+
}
|
409
|
+
%}
|
410
|
+
|
411
|
+
%extend Gosu::Window {
|
412
|
+
void drawLine(double x1, double y1, Gosu::Color c1,
|
413
|
+
double x2, double y2, Gosu::Color c2,
|
414
|
+
Gosu::ZPos z = 0, Gosu::AlphaMode mode = Gosu::amDefault) {
|
415
|
+
$self->graphics().drawLine(x1, y1, c1, x2, y2, c2,
|
416
|
+
z, mode);
|
417
|
+
}
|
418
|
+
void drawTriangle(double x1, double y1, Gosu::Color c1,
|
419
|
+
double x2, double y2, Gosu::Color c2,
|
420
|
+
double x3, double y3, Gosu::Color c3,
|
421
|
+
Gosu::ZPos z = 0, Gosu::AlphaMode mode = Gosu::amDefault) {
|
422
|
+
$self->graphics().drawTriangle(x1, y1, c1, x2, y2, c2, x3, y3, c3,
|
423
|
+
z, mode);
|
424
|
+
}
|
425
|
+
void drawQuad(double x1, double y1, Gosu::Color c1,
|
426
|
+
double x2, double y2, Gosu::Color c2,
|
427
|
+
double x3, double y3, Gosu::Color c3,
|
428
|
+
double x4, double y4, Gosu::Color c4,
|
429
|
+
Gosu::ZPos z = 0, Gosu::AlphaMode mode = Gosu::amDefault) {
|
430
|
+
$self->graphics().drawQuad(x1, y1, c1, x2, y2, c2,
|
431
|
+
x3, y3, c3, x4, y4, c4,
|
432
|
+
z, mode);
|
433
|
+
}
|
434
|
+
bool isButtonDown(Gosu::Button btn) const {
|
435
|
+
return $self->input().down(btn);
|
436
|
+
}
|
437
|
+
Gosu::Button charToButtonId(wchar_t ch) {
|
438
|
+
return $self->input().charToId(ch);
|
439
|
+
}
|
440
|
+
wchar_t buttonIdToChar(Gosu::Button btn) {
|
441
|
+
return $self->input().idToChar(btn);
|
442
|
+
}
|
443
|
+
|
444
|
+
TextInput* textInput() const {
|
445
|
+
return $self->input().textInput();
|
446
|
+
}
|
447
|
+
|
448
|
+
void setTextInput(TextInput* ti) {
|
449
|
+
$self->input().setTextInput(ti);
|
450
|
+
}
|
451
|
+
|
452
|
+
double mouseX() const {
|
453
|
+
return $self->input().mouseX();
|
454
|
+
}
|
455
|
+
double mouseY() const {
|
456
|
+
return $self->input().mouseY();
|
457
|
+
}
|
458
|
+
int width() const {
|
459
|
+
return $self->graphics().width();
|
460
|
+
}
|
461
|
+
int height() const {
|
462
|
+
return $self->graphics().height();
|
463
|
+
}
|
464
|
+
void gl() {
|
465
|
+
$self->graphics().beginGL();
|
466
|
+
rb_yield(Qnil);
|
467
|
+
$self->graphics().endGL();
|
468
|
+
}
|
469
|
+
void clipTo(int x, int y, unsigned width, unsigned height) {
|
470
|
+
$self->graphics().beginClipping(x, y, width, height);
|
471
|
+
rb_yield(Qnil);
|
472
|
+
$self->graphics().endClipping();
|
473
|
+
}
|
474
|
+
};
|