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
data/Gosu/Text.hpp
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
//! \file Text.hpp
|
2
|
+
//! Functions to output text on bitmaps.
|
3
|
+
|
4
|
+
#ifndef GOSU_TEXT_HPP
|
5
|
+
#define GOSU_TEXT_HPP
|
6
|
+
|
7
|
+
#include <Gosu/Fwd.hpp>
|
8
|
+
#include <Gosu/GraphicsBase.hpp>
|
9
|
+
#include <string>
|
10
|
+
|
11
|
+
namespace Gosu
|
12
|
+
{
|
13
|
+
//! Returns the name of a neutral font that is available on the current
|
14
|
+
//! platform.
|
15
|
+
std::wstring defaultFontName();
|
16
|
+
|
17
|
+
//! Returns the width a text would span on a bitmap if it were drawn
|
18
|
+
//! using drawText with the same arguments.
|
19
|
+
//! \param fontName Name of a system font, or a filename to a TTF file (must contain '/').
|
20
|
+
unsigned textWidth(const std::wstring& text,
|
21
|
+
const std::wstring& fontName, unsigned fontHeight,
|
22
|
+
unsigned fontFlags = 0);
|
23
|
+
|
24
|
+
//! Draws a line of text on a bitmap.
|
25
|
+
//! \param fontName Name of a system font, or a filename to a TTF file (must contain '/').
|
26
|
+
//! \param fontHeight Height, in pixels, of the text.
|
27
|
+
//! \param fontFlags Binary combination of members of the FontFlags
|
28
|
+
//! enum.
|
29
|
+
void drawText(Bitmap& bitmap, const std::wstring& text, int x, int y,
|
30
|
+
Color c, const std::wstring& fontName, unsigned fontHeight,
|
31
|
+
unsigned fontFlags = 0);
|
32
|
+
|
33
|
+
//! Creates a bitmap that is filled with the text given to the function.
|
34
|
+
//! The text may contain line breaks.
|
35
|
+
//! \param fontName Name of a system font, or a filename to a TTF file (must contain '/').
|
36
|
+
//! \param fontHeight Height of the font in pixels.
|
37
|
+
//! \param lineSpacing Spacing between two lines of text in pixels.
|
38
|
+
//! \param maxWidth Maximal width of the bitmap that will be returned. Text
|
39
|
+
//! will be split into multiple lines to avoid drawing over the right
|
40
|
+
//! border. When a single word is too long, it will be truncated.
|
41
|
+
Bitmap createText(const std::wstring& text,
|
42
|
+
const std::wstring& fontName, unsigned fontHeight,
|
43
|
+
unsigned lineSpacing, unsigned maxWidth, TextAlign align,
|
44
|
+
unsigned fontFlags = 0);
|
45
|
+
}
|
46
|
+
|
47
|
+
#endif
|
data/Gosu/TextInput.hpp
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
//! \file TextInput.hpp
|
2
|
+
//! Interface of the TextInput class.
|
3
|
+
|
4
|
+
#ifndef GOSU_TEXTINPUT_HPP
|
5
|
+
#define GOSU_TEXTINPUT_HPP
|
6
|
+
|
7
|
+
#include <Gosu/Fwd.hpp>
|
8
|
+
#include <Gosu/Platform.hpp>
|
9
|
+
#include <boost/scoped_ptr.hpp>
|
10
|
+
#include <string>
|
11
|
+
|
12
|
+
namespace Gosu
|
13
|
+
{
|
14
|
+
//! TextInput instances are invisible objects that build a text string from input,
|
15
|
+
//! using the current operating system's keyboard layout.
|
16
|
+
//! At its most basic form, you only need to create a new TextInput instance and
|
17
|
+
//! pass it to your window via setTextInput. Until you call this function again,
|
18
|
+
//! passing 0, the TextInput object will build a text that can be accessed via
|
19
|
+
//! TextInput::text().
|
20
|
+
//! A TextInput object is purely abstract, though; drawing the input field is left
|
21
|
+
//! to the user. As with most of Gosu, how this is handled is completely left open.
|
22
|
+
//! TextInput only aims to provide enough code for your own GUIs to build upon.
|
23
|
+
class TextInput
|
24
|
+
{
|
25
|
+
struct Impl;
|
26
|
+
boost::scoped_ptr<Impl> pimpl;
|
27
|
+
|
28
|
+
public:
|
29
|
+
TextInput();
|
30
|
+
~TextInput();
|
31
|
+
|
32
|
+
std::wstring text() const;
|
33
|
+
|
34
|
+
//! Replaces the current text by the given string and positions the cursor
|
35
|
+
//! at the end of the text, with an empty selection.
|
36
|
+
void setText(const std::wstring& text);
|
37
|
+
|
38
|
+
//! Position of the caret as the index of the character that it's left to.
|
39
|
+
unsigned caretPos() const;
|
40
|
+
|
41
|
+
//! If there is a selection, the selectionStart() member yields its beginning,
|
42
|
+
//! using the same indexing scheme as caretPos. If there is no selection,
|
43
|
+
//! selectionStart() is equal to caretPos().
|
44
|
+
unsigned selectionStart() const;
|
45
|
+
|
46
|
+
// Platform-specific communication with Gosu::Input.
|
47
|
+
#if defined(GOSU_IS_MAC)
|
48
|
+
bool feedNSEvent(void* event);
|
49
|
+
#elif defined(GOSU_IS_WIN)
|
50
|
+
bool feedMessage(unsigned long message, unsigned long wparam, unsigned long lparam);
|
51
|
+
#elif defined(GOSU_IS_X)
|
52
|
+
bool feedXEvent(void* display, void* event);
|
53
|
+
#endif
|
54
|
+
};
|
55
|
+
}
|
56
|
+
|
57
|
+
#endif
|
data/Gosu/Timing.hpp
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
//! \file Timing.hpp
|
2
|
+
//! Functions for timing.
|
3
|
+
|
4
|
+
#ifndef GOSU_TIMING_HPP
|
5
|
+
#define GOSU_TIMING_HPP
|
6
|
+
|
7
|
+
namespace Gosu
|
8
|
+
{
|
9
|
+
//! Freezes the current thread for at least the specified time.
|
10
|
+
void sleep(unsigned milliseconds);
|
11
|
+
|
12
|
+
//! Incrementing, possibly wrapping millisecond timer.
|
13
|
+
unsigned long milliseconds();
|
14
|
+
}
|
15
|
+
|
16
|
+
#endif
|
data/Gosu/Utility.hpp
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
//! \file Utility.hpp
|
2
|
+
//! General purpose utility functions.
|
3
|
+
|
4
|
+
// REDESIGN: Rename to StringConversion.hpp?
|
5
|
+
|
6
|
+
#ifndef GOSU_UTILITY_HPP
|
7
|
+
#define GOSU_UTILITY_HPP
|
8
|
+
|
9
|
+
#include <string>
|
10
|
+
#include <vector>
|
11
|
+
|
12
|
+
namespace Gosu
|
13
|
+
{
|
14
|
+
//! Converts an std::string into an std::wstring.
|
15
|
+
std::wstring widen(const std::string& s);
|
16
|
+
//! Converts an std::wstring into an std::string.
|
17
|
+
std::string narrow(const std::wstring& ws);
|
18
|
+
|
19
|
+
// Undocumented, temporary: Please ignore. ;)
|
20
|
+
std::wstring utf8ToWstring(const std::string& utf8);
|
21
|
+
std::string wstringToUTF8(const std::wstring& ws);
|
22
|
+
}
|
23
|
+
|
24
|
+
#endif
|
data/Gosu/WinUtility.hpp
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
//! \file WinUtility.hpp
|
2
|
+
//! Contains some functions which are used to implement Gosu on Windows and
|
3
|
+
//! might be useful for advanced users who try to integrate Gosu in a Win32
|
4
|
+
//! application.
|
5
|
+
|
6
|
+
#ifndef GOSU_WINUTILITY_HPP
|
7
|
+
#define GOSU_WINUTILITY_HPP
|
8
|
+
|
9
|
+
#include <windows.h>
|
10
|
+
#include <Gosu/Platform.hpp>
|
11
|
+
#include <boost/function.hpp>
|
12
|
+
#include <boost/shared_ptr.hpp>
|
13
|
+
#include <string>
|
14
|
+
|
15
|
+
namespace Gosu
|
16
|
+
{
|
17
|
+
//! Implementation helpers for the Windows platform.
|
18
|
+
namespace Win
|
19
|
+
{
|
20
|
+
//! Returns the instance handle of the application.
|
21
|
+
HINSTANCE instance();
|
22
|
+
|
23
|
+
//! Blocking function which waits for the next message, processes it,
|
24
|
+
//! then returns.
|
25
|
+
void handleMessage();
|
26
|
+
|
27
|
+
//! Non-blocking function which processes all waiting messages but does
|
28
|
+
//! not wait for further incoming messages.
|
29
|
+
void processMessages();
|
30
|
+
|
31
|
+
//! Registers a function to be called by handleMessage and
|
32
|
+
//! processMessages. Every message is passed to the hooks and not
|
33
|
+
//! processed further if any hook function returns true.
|
34
|
+
void registerMessageHook(const boost::function<bool (MSG&)>& hook);
|
35
|
+
|
36
|
+
//! Throws an exception according to the error which GetLastError()
|
37
|
+
//! returns, optionally prefixed with "While <action>, the following
|
38
|
+
//! error occured: ".
|
39
|
+
GOSU_NORETURN void throwLastError(const std::string& action = "");
|
40
|
+
|
41
|
+
//! Small helper function that throws an exception whenever the value
|
42
|
+
//! passed through is false. Note that this doesn't make sense for all
|
43
|
+
//! Windows API functions, but for most of them.
|
44
|
+
template<typename T>
|
45
|
+
inline T check(T valToCheck, const std::string& action = "")
|
46
|
+
{
|
47
|
+
if (!valToCheck)
|
48
|
+
throwLastError(action);
|
49
|
+
return valToCheck;
|
50
|
+
}
|
51
|
+
|
52
|
+
// IMPR: Why can't I use mem_fn for releasing objects even though it is
|
53
|
+
// shown like that in the shared_ptr documentation?
|
54
|
+
template<typename T>
|
55
|
+
void releaseComPtr(T* ptr)
|
56
|
+
{
|
57
|
+
ptr->Release();
|
58
|
+
}
|
59
|
+
|
60
|
+
//! Small helper function that transfers ownership of a COM interface
|
61
|
+
//! to a boost::shared_ptr.
|
62
|
+
template<typename T>
|
63
|
+
inline boost::shared_ptr<T> shareComPtr(T* ptr)
|
64
|
+
{
|
65
|
+
return boost::shared_ptr<T>(ptr, releaseComPtr<T>);
|
66
|
+
}
|
67
|
+
|
68
|
+
//! Returns the executable's filename.
|
69
|
+
std::wstring appFilename();
|
70
|
+
|
71
|
+
//! Returns the executable's containing directory.
|
72
|
+
std::wstring appDirectory();
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
#endif
|
data/Gosu/Window.hpp
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
//! \file Window.hpp
|
2
|
+
//! Interface of the Window class.
|
3
|
+
|
4
|
+
#ifndef GOSU_WINDOW_HPP
|
5
|
+
#define GOSU_WINDOW_HPP
|
6
|
+
|
7
|
+
#include <Gosu/Fwd.hpp>
|
8
|
+
#include <Gosu/Platform.hpp>
|
9
|
+
#include <Gosu/Input.hpp>
|
10
|
+
#include <boost/scoped_ptr.hpp>
|
11
|
+
#include <boost/shared_ptr.hpp>
|
12
|
+
#include <boost/function.hpp>
|
13
|
+
#include <string>
|
14
|
+
|
15
|
+
#ifdef GOSU_IS_WIN
|
16
|
+
#include <windows.h>
|
17
|
+
#endif
|
18
|
+
|
19
|
+
namespace Gosu
|
20
|
+
{
|
21
|
+
//! Convenient all-in-one class that serves as the foundation of a standard
|
22
|
+
//! Gosu application. Manages initialization of all of Gosu's core components
|
23
|
+
//! and provides timing functionality.
|
24
|
+
class Window
|
25
|
+
{
|
26
|
+
struct Impl;
|
27
|
+
boost::scoped_ptr<Impl> pimpl;
|
28
|
+
|
29
|
+
public:
|
30
|
+
//! Constructs a Window.
|
31
|
+
//! \param updateInterval Interval in milliseconds between two calls
|
32
|
+
//! to the update member function.
|
33
|
+
Window(unsigned width, unsigned height, bool fullscreen,
|
34
|
+
double updateInterval = 16.666666);
|
35
|
+
virtual ~Window();
|
36
|
+
|
37
|
+
std::wstring caption() const;
|
38
|
+
void setCaption(const std::wstring& caption);
|
39
|
+
|
40
|
+
//! Starts the main event loop.
|
41
|
+
void show();
|
42
|
+
//! Closes the window if it is currently shown.
|
43
|
+
void close();
|
44
|
+
|
45
|
+
//! Called every updateInterval milliseconds while the window is being
|
46
|
+
//! shown. Your application's main game logic goes here.
|
47
|
+
virtual void update() {}
|
48
|
+
//! Called after every update and when the OS wants the window to
|
49
|
+
//! repaint itself. Your application's rendering code goes here.
|
50
|
+
virtual void draw() {}
|
51
|
+
|
52
|
+
//! Called before update when the user pressed a button while the
|
53
|
+
//! window had the focus.
|
54
|
+
virtual void buttonDown(Gosu::Button) {}
|
55
|
+
//! Same as buttonDown. Called then the user released a button.
|
56
|
+
virtual void buttonUp(Gosu::Button) {}
|
57
|
+
|
58
|
+
// Ignore when SWIG is wrapping this class for Ruby/Gosu.
|
59
|
+
#ifndef SWIG
|
60
|
+
const Graphics& graphics() const;
|
61
|
+
Graphics& graphics();
|
62
|
+
|
63
|
+
const Audio& audio() const;
|
64
|
+
Audio& audio();
|
65
|
+
|
66
|
+
const Input& input() const;
|
67
|
+
Input& input();
|
68
|
+
|
69
|
+
#ifdef GOSU_IS_WIN
|
70
|
+
// Only on Windows.
|
71
|
+
HWND handle() const;
|
72
|
+
virtual LRESULT handleMessage(UINT message, WPARAM wparam,
|
73
|
+
LPARAM lparam);
|
74
|
+
#else
|
75
|
+
// Only on Unices (so far).
|
76
|
+
typedef boost::shared_ptr<boost::function<void()> > SharedContext;
|
77
|
+
SharedContext createSharedContext();
|
78
|
+
#endif
|
79
|
+
|
80
|
+
#endif
|
81
|
+
};
|
82
|
+
}
|
83
|
+
|
84
|
+
#endif
|
data/GosuImpl/Async.cpp
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#include <Gosu/Async.hpp>
|
2
|
+
#include <Gosu/Graphics.hpp>
|
3
|
+
#include <Gosu/Image.hpp>
|
4
|
+
#include <Gosu/Window.hpp>
|
5
|
+
#include <boost/bind.hpp>
|
6
|
+
|
7
|
+
using namespace boost;
|
8
|
+
|
9
|
+
namespace Gosu
|
10
|
+
{
|
11
|
+
namespace
|
12
|
+
{
|
13
|
+
void asyncNewImage_Impl(Window& window, std::wstring filename,
|
14
|
+
Window::SharedContext context,
|
15
|
+
shared_ptr<try_mutex> mutex,
|
16
|
+
shared_ptr<std::auto_ptr<Image> > result)
|
17
|
+
{
|
18
|
+
try_mutex::scoped_lock lock(*mutex);
|
19
|
+
(*context)();
|
20
|
+
result->reset(new Image(window.graphics(), filename));
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
Gosu::AsyncResult<Gosu::Image>
|
26
|
+
Gosu::asyncNewImage(Window& window, const std::wstring& filename)
|
27
|
+
{
|
28
|
+
shared_ptr<try_mutex> mutex(new try_mutex);
|
29
|
+
shared_ptr<std::auto_ptr<Image> > image(new std::auto_ptr<Image>);
|
30
|
+
thread thread(bind(asyncNewImage_Impl,
|
31
|
+
ref(window),
|
32
|
+
filename,
|
33
|
+
window.createSharedContext(),
|
34
|
+
mutex,
|
35
|
+
image));
|
36
|
+
return AsyncResult<Image>(mutex, image);
|
37
|
+
}
|
@@ -0,0 +1,417 @@
|
|
1
|
+
#include <Gosu/Audio.hpp>
|
2
|
+
#include <Gosu/Math.hpp>
|
3
|
+
#include <Gosu/IO.hpp>
|
4
|
+
#include <Gosu/Utility.hpp>
|
5
|
+
#include <boost/algorithm/string.hpp>
|
6
|
+
#include <cassert>
|
7
|
+
#include <cstdlib>
|
8
|
+
#include <algorithm>
|
9
|
+
#include <stdexcept>
|
10
|
+
#include <vector>
|
11
|
+
|
12
|
+
#include <fmod.h>
|
13
|
+
#include <fmod_errors.h>
|
14
|
+
|
15
|
+
namespace Gosu
|
16
|
+
{
|
17
|
+
namespace
|
18
|
+
{
|
19
|
+
GOSU_NORETURN void throwLastFMODError()
|
20
|
+
{
|
21
|
+
throw std::runtime_error(FMOD_ErrorString(FSOUND_GetError()));
|
22
|
+
}
|
23
|
+
|
24
|
+
inline unsigned char fmodCheck(unsigned char retVal)
|
25
|
+
{
|
26
|
+
if (retVal == 0 && FSOUND_GetError() != FMOD_ERR_NONE)
|
27
|
+
throwLastFMODError();
|
28
|
+
|
29
|
+
return retVal;
|
30
|
+
}
|
31
|
+
|
32
|
+
bool fmodInitialized = false;
|
33
|
+
Song* curSong = 0;
|
34
|
+
|
35
|
+
#ifdef GOSU_IS_WIN
|
36
|
+
bool setWindow(HWND window)
|
37
|
+
{
|
38
|
+
// Copied and pasted from MSDN.
|
39
|
+
#define FACILITY_VISUALCPP ((LONG)0x6d)
|
40
|
+
#define VcppException(sev,err) ((sev) | (FACILITY_VISUALCPP<<16) | err)
|
41
|
+
#define BAD_MOD VcppException(ERROR_SEVERITY_ERROR, ERROR_MOD_NOT_FOUND)
|
42
|
+
|
43
|
+
// Try to call the first function from fmod.dll, which is lazily
|
44
|
+
// linked. With this guard, we can raise a catchable C++ exception
|
45
|
+
// if the library is not found, instead of crashing the game.
|
46
|
+
__try
|
47
|
+
{
|
48
|
+
FSOUND_SetHWND(reinterpret_cast<void*>(window));
|
49
|
+
}
|
50
|
+
__except ((GetExceptionCode() == BAD_MOD) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
|
51
|
+
{
|
52
|
+
return false;
|
53
|
+
}
|
54
|
+
return true;
|
55
|
+
|
56
|
+
#undef BAD_MOD
|
57
|
+
#undef VcppException
|
58
|
+
#undef FACILITY_VISUALCPP
|
59
|
+
}
|
60
|
+
#endif
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
#ifdef GOSU_IS_WIN
|
65
|
+
Gosu::Audio::Audio(HWND window)
|
66
|
+
{
|
67
|
+
if (!setWindow(window))
|
68
|
+
throw std::runtime_error("Could not load fmod.dll");
|
69
|
+
#else
|
70
|
+
Gosu::Audio::Audio()
|
71
|
+
{
|
72
|
+
#endif
|
73
|
+
|
74
|
+
if (fmodInitialized)
|
75
|
+
throw std::logic_error("Multiple Gosu::Audio instances not supported");
|
76
|
+
|
77
|
+
fmodCheck(FSOUND_Init(44100, 32, 0));
|
78
|
+
fmodInitialized = true;
|
79
|
+
}
|
80
|
+
|
81
|
+
Gosu::Audio::~Audio()
|
82
|
+
{
|
83
|
+
assert(fmodInitialized);
|
84
|
+
|
85
|
+
FSOUND_Close();
|
86
|
+
fmodInitialized = false;
|
87
|
+
}
|
88
|
+
|
89
|
+
Gosu::SampleInstance::SampleInstance(int handle, int extra)
|
90
|
+
: handle(handle), extra(extra)
|
91
|
+
{
|
92
|
+
}
|
93
|
+
|
94
|
+
bool Gosu::SampleInstance::playing() const
|
95
|
+
{
|
96
|
+
return FSOUND_IsPlaying(handle);
|
97
|
+
}
|
98
|
+
|
99
|
+
void Gosu::SampleInstance::stop()
|
100
|
+
{
|
101
|
+
FSOUND_StopSound(handle);
|
102
|
+
}
|
103
|
+
|
104
|
+
void Gosu::SampleInstance::changeVolume(double volume)
|
105
|
+
{
|
106
|
+
FSOUND_SetVolume(handle, clamp<int>(volume * 255, 0, 255));
|
107
|
+
}
|
108
|
+
|
109
|
+
void Gosu::SampleInstance::changePan(double pan)
|
110
|
+
{
|
111
|
+
FSOUND_SetPan(handle, clamp<int>(pan * 127 + 127, 0, 255));
|
112
|
+
}
|
113
|
+
|
114
|
+
void Gosu::SampleInstance::changeSpeed(double speed)
|
115
|
+
{
|
116
|
+
FSOUND_SetFrequency(handle, clamp<int>(speed * extra, 100, 705600));
|
117
|
+
}
|
118
|
+
|
119
|
+
struct Gosu::Sample::SampleData : boost::noncopyable
|
120
|
+
{
|
121
|
+
FSOUND_SAMPLE* rep;
|
122
|
+
|
123
|
+
SampleData()
|
124
|
+
: rep(0)
|
125
|
+
{
|
126
|
+
}
|
127
|
+
|
128
|
+
~SampleData()
|
129
|
+
{
|
130
|
+
// Should be checked for earlier, as play would crash too.
|
131
|
+
// This is just because it's hard to free things in the right
|
132
|
+
// order in Ruby/Gosu.
|
133
|
+
|
134
|
+
if (!fmodInitialized)
|
135
|
+
return;
|
136
|
+
|
137
|
+
if (rep != 0)
|
138
|
+
FSOUND_Sample_Free(rep);
|
139
|
+
}
|
140
|
+
};
|
141
|
+
|
142
|
+
Gosu::Sample::Sample(Audio& audio, const std::wstring& filename)
|
143
|
+
{
|
144
|
+
Buffer buf;
|
145
|
+
loadFile(buf, filename);
|
146
|
+
|
147
|
+
// Forward.
|
148
|
+
Sample(audio, buf.frontReader()).data.swap(data);
|
149
|
+
}
|
150
|
+
|
151
|
+
Gosu::Sample::Sample(Audio& audio, Reader reader)
|
152
|
+
{
|
153
|
+
std::vector<char> buffer(reader.resource().size() - reader.position());
|
154
|
+
reader.read(&buffer.front(), buffer.size());
|
155
|
+
|
156
|
+
data.reset(new SampleData);
|
157
|
+
data->rep = FSOUND_Sample_Load(FSOUND_FREE | FSOUND_UNMANAGED,
|
158
|
+
&buffer.front(), FSOUND_NORMAL | FSOUND_LOADMEMORY, 0, buffer.size());
|
159
|
+
if (data->rep == 0)
|
160
|
+
throwLastFMODError();
|
161
|
+
}
|
162
|
+
|
163
|
+
Gosu::Sample::~Sample()
|
164
|
+
{
|
165
|
+
}
|
166
|
+
|
167
|
+
Gosu::SampleInstance Gosu::Sample::play(double volume, double speed) const
|
168
|
+
{
|
169
|
+
int handle = FSOUND_PlaySound(FSOUND_FREE, data->rep);
|
170
|
+
int freq;
|
171
|
+
if (handle > 0)
|
172
|
+
{
|
173
|
+
freq = FSOUND_GetFrequency(handle);
|
174
|
+
FSOUND_SetPan(handle, FSOUND_STEREOPAN);
|
175
|
+
}
|
176
|
+
|
177
|
+
SampleInstance result(handle, freq);
|
178
|
+
result.changeVolume(volume);
|
179
|
+
result.changeSpeed(speed);
|
180
|
+
return result;
|
181
|
+
}
|
182
|
+
|
183
|
+
Gosu::SampleInstance Gosu::Sample::playPan(double pan, double volume, double speed) const
|
184
|
+
{
|
185
|
+
int handle = FSOUND_PlaySound(FSOUND_FREE, data->rep);
|
186
|
+
int freq;
|
187
|
+
if (handle > 0)
|
188
|
+
{
|
189
|
+
freq = FSOUND_GetFrequency(handle);
|
190
|
+
}
|
191
|
+
|
192
|
+
SampleInstance result(handle, freq);
|
193
|
+
result.changeVolume(volume);
|
194
|
+
result.changePan(pan);
|
195
|
+
result.changeSpeed(speed);
|
196
|
+
return result;
|
197
|
+
}
|
198
|
+
|
199
|
+
class Gosu::Song::BaseData : boost::noncopyable
|
200
|
+
{
|
201
|
+
double volume_;
|
202
|
+
|
203
|
+
protected:
|
204
|
+
BaseData() : volume_(1) {}
|
205
|
+
virtual void applyVolume() = 0;
|
206
|
+
|
207
|
+
public:
|
208
|
+
virtual ~BaseData() {}
|
209
|
+
|
210
|
+
virtual void play() = 0;
|
211
|
+
virtual void stop() = 0;
|
212
|
+
|
213
|
+
double volume() const
|
214
|
+
{
|
215
|
+
return volume_;
|
216
|
+
}
|
217
|
+
|
218
|
+
void changeVolume(double volume)
|
219
|
+
{
|
220
|
+
volume_ = clamp(volume, 0.0, 1.0);
|
221
|
+
applyVolume();
|
222
|
+
}
|
223
|
+
};
|
224
|
+
|
225
|
+
class Gosu::Song::StreamData : public BaseData
|
226
|
+
{
|
227
|
+
FSOUND_STREAM* stream;
|
228
|
+
int handle;
|
229
|
+
std::vector<char> buffer;
|
230
|
+
|
231
|
+
static signed char F_CALLBACKAPI endSongCallback(FSOUND_STREAM*, void*,
|
232
|
+
int, void* self)
|
233
|
+
{
|
234
|
+
curSong = 0;
|
235
|
+
static_cast<StreamData*>(self)->handle = -1;
|
236
|
+
return 0;
|
237
|
+
}
|
238
|
+
|
239
|
+
public:
|
240
|
+
StreamData(Gosu::Reader reader)
|
241
|
+
: stream(0), handle(-1)
|
242
|
+
{
|
243
|
+
buffer.resize(reader.resource().size() - reader.position());
|
244
|
+
reader.read(&buffer[0], buffer.size());
|
245
|
+
|
246
|
+
// Disabled for licensing reasons.
|
247
|
+
// If you have a license to play MP3 files, compile with GOSU_ALLOW_MP3.
|
248
|
+
#ifndef GOSU_ALLOW_MP3
|
249
|
+
if (buffer.size() > 2 &&
|
250
|
+
((buffer[0] == '\xff' && (buffer[1] & 0xfe) == '\xfa') ||
|
251
|
+
(buffer[0] == 'I' && buffer[1] == 'D' && buffer[2] == '3')))
|
252
|
+
{
|
253
|
+
throw std::runtime_error("MP3 file playback not allowed");
|
254
|
+
}
|
255
|
+
#endif
|
256
|
+
|
257
|
+
stream = FSOUND_Stream_Open(&buffer[0], FSOUND_LOADMEMORY, 0,
|
258
|
+
buffer.size());
|
259
|
+
if (stream == 0)
|
260
|
+
throwLastFMODError();
|
261
|
+
|
262
|
+
FSOUND_Stream_SetEndCallback(stream, endSongCallback, this);
|
263
|
+
}
|
264
|
+
|
265
|
+
~StreamData()
|
266
|
+
{
|
267
|
+
// TODO: Should be checked for earlier, as play would crash too.
|
268
|
+
// This is just because Ruby's GC will free objects in a weird
|
269
|
+
// order.
|
270
|
+
if (!fmodInitialized)
|
271
|
+
return;
|
272
|
+
|
273
|
+
if (stream != 0)
|
274
|
+
FSOUND_Stream_Close(stream);
|
275
|
+
}
|
276
|
+
|
277
|
+
void play()
|
278
|
+
{
|
279
|
+
handle = FSOUND_Stream_Play(FSOUND_FREE, stream);
|
280
|
+
applyVolume();
|
281
|
+
}
|
282
|
+
|
283
|
+
void stop()
|
284
|
+
{
|
285
|
+
fmodCheck(FSOUND_Stream_Stop(stream));
|
286
|
+
}
|
287
|
+
|
288
|
+
void applyVolume()
|
289
|
+
{
|
290
|
+
if (handle != -1)
|
291
|
+
FSOUND_SetVolume(handle, static_cast<int>(volume() * 255));
|
292
|
+
}
|
293
|
+
};
|
294
|
+
|
295
|
+
class Gosu::Song::ModuleData : public Gosu::Song::BaseData
|
296
|
+
{
|
297
|
+
FMUSIC_MODULE* module_;
|
298
|
+
|
299
|
+
public:
|
300
|
+
ModuleData(Reader reader)
|
301
|
+
: module_(0)
|
302
|
+
{
|
303
|
+
std::vector<char> buffer(reader.resource().size() - reader.position());
|
304
|
+
reader.read(&buffer[0], buffer.size());
|
305
|
+
|
306
|
+
module_ = FMUSIC_LoadSongEx(&buffer[0], 0, buffer.size(),
|
307
|
+
FSOUND_LOADMEMORY | FSOUND_LOOP_OFF, 0, 0);
|
308
|
+
if (module_ == 0)
|
309
|
+
throwLastFMODError();
|
310
|
+
}
|
311
|
+
|
312
|
+
~ModuleData()
|
313
|
+
{
|
314
|
+
// TODO: Should be checked for earlier, as play would crash too.
|
315
|
+
// This is just because Ruby's GC will free objects in a weird
|
316
|
+
// order.
|
317
|
+
if (!fmodInitialized)
|
318
|
+
return;
|
319
|
+
|
320
|
+
if (module_ != 0)
|
321
|
+
FMUSIC_FreeSong(module_);
|
322
|
+
}
|
323
|
+
|
324
|
+
void play()
|
325
|
+
{
|
326
|
+
FMUSIC_PlaySong(module_);
|
327
|
+
applyVolume();
|
328
|
+
}
|
329
|
+
|
330
|
+
void stop()
|
331
|
+
{
|
332
|
+
fmodCheck(FMUSIC_StopSong(module_));
|
333
|
+
}
|
334
|
+
|
335
|
+
void applyVolume()
|
336
|
+
{
|
337
|
+
// Weird as it may seem, the FMOD doc really says volume can
|
338
|
+
// be 0 to 256, *inclusive*, for this function.
|
339
|
+
FMUSIC_SetMasterVolume(module_, static_cast<int>(volume() * 256.0));
|
340
|
+
}
|
341
|
+
};
|
342
|
+
|
343
|
+
Gosu::Song::Song(Audio& audio, const std::wstring& filename)
|
344
|
+
{
|
345
|
+
Buffer buf;
|
346
|
+
loadFile(buf, filename);
|
347
|
+
Type type = stStream;
|
348
|
+
|
349
|
+
using boost::iends_with;
|
350
|
+
if (iends_with(filename, ".mod") || iends_with(filename, ".mid") ||
|
351
|
+
iends_with(filename, ".s3m") || iends_with(filename, ".it") ||
|
352
|
+
iends_with(filename, ".xm"))
|
353
|
+
{
|
354
|
+
type = stModule;
|
355
|
+
}
|
356
|
+
|
357
|
+
// Forward.
|
358
|
+
Song(audio, type, buf.frontReader()).data.swap(data);
|
359
|
+
}
|
360
|
+
|
361
|
+
Gosu::Song::Song(Audio& audio, Type type, Reader reader)
|
362
|
+
{
|
363
|
+
switch (type)
|
364
|
+
{
|
365
|
+
case stStream:
|
366
|
+
data.reset(new StreamData(reader));
|
367
|
+
break;
|
368
|
+
|
369
|
+
case stModule:
|
370
|
+
data.reset(new ModuleData(reader));
|
371
|
+
break;
|
372
|
+
|
373
|
+
default:
|
374
|
+
throw std::logic_error("Invalid song type");
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
378
|
+
Gosu::Song::~Song()
|
379
|
+
{
|
380
|
+
if (fmodInitialized)
|
381
|
+
stop();
|
382
|
+
}
|
383
|
+
|
384
|
+
void Gosu::Song::play()
|
385
|
+
{
|
386
|
+
if (curSong)
|
387
|
+
curSong->stop();
|
388
|
+
|
389
|
+
assert(curSong == 0);
|
390
|
+
|
391
|
+
data->play();
|
392
|
+
curSong = this;
|
393
|
+
}
|
394
|
+
|
395
|
+
void Gosu::Song::stop()
|
396
|
+
{
|
397
|
+
if (playing())
|
398
|
+
{
|
399
|
+
data->stop();
|
400
|
+
curSong = 0;
|
401
|
+
}
|
402
|
+
}
|
403
|
+
|
404
|
+
bool Gosu::Song::playing() const
|
405
|
+
{
|
406
|
+
return curSong == this;
|
407
|
+
}
|
408
|
+
|
409
|
+
double Gosu::Song::volume() const
|
410
|
+
{
|
411
|
+
return data->volume();
|
412
|
+
}
|
413
|
+
|
414
|
+
void Gosu::Song::changeVolume(double volume)
|
415
|
+
{
|
416
|
+
data->changeVolume(volume);
|
417
|
+
}
|