gosu 0.7.25-universal-darwin → 0.7.26-universal-darwin

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- Copyright (C) 2004-2010 Julian Raschke, Jan Lücker and all contributors.
1
+ Copyright (C) 2004-2011 Julian Raschke, Jan Lücker and all contributors.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a
4
4
  copy of this software and associated documentation files (the "Software"),
@@ -0,0 +1,48 @@
1
+ // Undocumented for the first few iterations. Interface may change rapidly.
2
+ // This is mainly a proof of concept. Stability will be the highest on OS X.
3
+
4
+ #ifndef GOSU_ASYNC_HPP
5
+ #define GOSU_ASYNC_HPP
6
+
7
+ #include <Gosu/Fwd.hpp>
8
+ #include <boost/shared_ptr.hpp>
9
+ #include <boost/thread.hpp>
10
+ #include <memory>
11
+ #include <string>
12
+
13
+ namespace Gosu
14
+ {
15
+ template<typename Result>
16
+ class AsyncResult
17
+ {
18
+ boost::shared_ptr<boost::try_mutex> mutex;
19
+ boost::shared_ptr<std::auto_ptr<Result> > result;
20
+
21
+ public:
22
+ AsyncResult(const boost::shared_ptr<boost::try_mutex>& mutex,
23
+ const boost::shared_ptr<std::auto_ptr<Result> >& result)
24
+ : mutex(mutex), result(result)
25
+ {
26
+ }
27
+
28
+ bool hasValue() const
29
+ {
30
+ boost::try_mutex::scoped_try_lock lock(*mutex);
31
+ return lock && result->get();
32
+ }
33
+
34
+ std::auto_ptr<Result> takeValue()
35
+ {
36
+ boost::try_mutex::scoped_lock lock(*mutex);
37
+ return *result;
38
+ }
39
+ };
40
+
41
+ // TODO: Will only work if the window doesn't die inbetween.
42
+ // TODO: More functions to come; or a general interface?
43
+
44
+ AsyncResult<Image>
45
+ asyncNewImage(Window& window, const std::wstring& filename);
46
+ }
47
+
48
+ #endif
@@ -0,0 +1,165 @@
1
+ //! \file Audio.hpp
2
+ //! Contains all the classes of Gosu's audio system.
3
+
4
+ #ifndef GOSU_AUDIO_HPP
5
+ #define GOSU_AUDIO_HPP
6
+
7
+ #ifdef WIN32
8
+ #ifndef NOMINMAX
9
+ #define NOMINMAX
10
+ #endif
11
+ #include <windows.h>
12
+ #endif
13
+ #include <Gosu/Fwd.hpp>
14
+ #include <Gosu/IO.hpp>
15
+ #include <Gosu/Platform.hpp>
16
+ #include <boost/scoped_ptr.hpp>
17
+ #include <boost/shared_ptr.hpp>
18
+ #include <string>
19
+
20
+ namespace Gosu
21
+ {
22
+ // Deprecated.
23
+ class Audio;
24
+
25
+ //! An instance of a Sample playing. Can be used to stop sounds dynamically,
26
+ //! or to check if they are finished.
27
+ //! It is recommended that you throw away sample instances if possible,
28
+ //! as they could accidentally refer to other sounds being played after
29
+ //! a very long time has passed.
30
+ class SampleInstance
31
+ {
32
+ int handle, extra;
33
+ bool alive() const;
34
+
35
+ public:
36
+ //! Called by Sample, do not use.
37
+ SampleInstance(int handle, int extra);
38
+
39
+ bool playing() const;
40
+ bool paused() const;
41
+ //! Pauses this instance to be resumed afterwards. It will still keep a channel filled while paused.
42
+ void pause();
43
+ void resume();
44
+ //! Stops this instance of a sound being played.
45
+ //! Calling this twice, or too late, does not do any harm.
46
+ void stop();
47
+
48
+ //! \param volume Can be anything from 0.0 (silence) to 1.0 (full
49
+ //! volume).
50
+ void changeVolume(double volume);
51
+ //! \param pan Can be anything from -1.0 (left) to 1.0 (right).
52
+ void changePan(double pan);
53
+ //! \param speed Playback speed is only limited by FMOD's
54
+ //! capabilities and can accept very high or low values. Use 1.0 for
55
+ //! normal playback speed.
56
+ void changeSpeed(double speed);
57
+ };
58
+
59
+ //! A sample is a short sound that is completely loaded in memory, can be
60
+ //! played multiple times at once and offers very flexible playback
61
+ //! parameters. Use samples for everything that's not music.
62
+ class Sample
63
+ {
64
+ struct SampleData;
65
+ boost::shared_ptr<SampleData> data;
66
+
67
+ public:
68
+ //! Constructs a sample that can be played on the specified audio
69
+ //! system and loads the sample from a file.
70
+ explicit Sample(const std::wstring& filename);
71
+
72
+ //! Constructs a sample that can be played on the specified audio
73
+ //! system and loads the sample data from a stream.
74
+ explicit Sample(Reader reader);
75
+
76
+ //! Plays the sample without panning.
77
+ //! \param volume Can be anything from 0.0 (silence) to 1.0 (full
78
+ //! volume).
79
+ //! \param speed Playback speed is only limited by the underlying audio library,
80
+ //! and can accept very high or low values. Use 1.0 for
81
+ //! normal playback speed.
82
+ SampleInstance play(double volume = 1, double speed = 1,
83
+ bool looping = false) const;
84
+
85
+ //! Plays the sample with panning. Even if pan is 0.0, the sample will
86
+ //! not be as loud as if it were played by calling play() due to the
87
+ //! way the panning works.
88
+ //! \param pan Can be anything from -1.0 (left) to 1.0 (right).
89
+ //! \param volume Can be anything from 0.0 (silence) to 1.0 (full
90
+ //! volume).
91
+ //! \param speed Playback speed is only limited by by the underlying audio library,
92
+ //! and can accept very high
93
+ //! or low values. Use 1.0 for normal playback speed.
94
+ SampleInstance playPan(double pan, double volume = 1, double speed = 1,
95
+ bool looping = false) const;
96
+
97
+
98
+ // Deprecated.
99
+ Sample(Audio& audio, const std::wstring& filename);
100
+ Sample(Audio& audio, Reader reader);
101
+ };
102
+
103
+ //! Songs are less flexible than samples in that they can only be played
104
+ //! one at a time and without panning or speed parameters.
105
+ class Song
106
+ {
107
+ class BaseData;
108
+ class ModuleData;
109
+ class StreamData;
110
+ boost::scoped_ptr<BaseData> data;
111
+
112
+ public:
113
+ //! There are two types of songs that can be loaded as a Song: Streamed
114
+ //! songs (like OGG) and modules (like MOD or XM).
115
+ enum Type
116
+ {
117
+ stStream,
118
+ stModule
119
+ };
120
+
121
+ //! Constructs a song that can be played on the provided audio system
122
+ //! and loads the song from a file. The type is determined from the
123
+ //! filename.
124
+ explicit Song(const std::wstring& filename);
125
+
126
+ //! Constructs a song of the specified type that can be played on the
127
+ //! provided audio system and loads the song data from a stream.
128
+ Song(Type type, Reader reader);
129
+
130
+ ~Song();
131
+
132
+ //! Returns the song currently being played or paused, or 0 if
133
+ //! no song has been played yet or the last song has finished
134
+ //! playing.
135
+ static Song* currentSong();
136
+
137
+ //! Starts or resumes playback of the song. This will stop all other
138
+ //! songs and set the current song to this object.
139
+ void play(bool looping = false);
140
+ //! Pauses playback of the song. It is not considered being played.
141
+ //! currentSong will stay the same.
142
+ void pause();
143
+ //! Returns true if the song is the current song, but in paused
144
+ //! mode.
145
+ bool paused() const;
146
+ //! Stops playback of this song if it is currently played or paused.
147
+ //! Afterwards, currentSong will return 0.
148
+ void stop();
149
+ //! Returns true if the song is currently playing.
150
+ bool playing() const;
151
+ //! Returns the current volume of the song.
152
+ double volume() const;
153
+ //! Changes the volume of the song.
154
+ void changeVolume(double volume);
155
+
156
+ //! Called every tick by Window for management purposes.
157
+ static void update();
158
+
159
+ // Deprecated.
160
+ Song(Audio&, const std::wstring& filename);
161
+ Song(Audio&, Type type, Reader reader);
162
+ };
163
+ }
164
+
165
+ #endif
@@ -0,0 +1,16 @@
1
+ //! \file AutoLink.hpp
2
+ //! Contains pragmas that make MSVC link against all the necessary libraries
3
+ //! automatically.
4
+
5
+ #ifdef _MSC_VER
6
+ #ifndef GOSU_AUTOLINK_HPP
7
+ #define GOSU_AUTOLINK_HPP
8
+
9
+ #ifdef NDEBUG
10
+ #pragma comment(lib, "Gosu.lib")
11
+ #else
12
+ #pragma comment(lib, "GosuDebug.lib")
13
+ #endif
14
+
15
+ #endif
16
+ #endif
@@ -0,0 +1,85 @@
1
+ //! \file Bitmap.hpp
2
+ //! Interface of the Bitmap class.
3
+
4
+ #ifndef GOSU_BITMAP_HPP
5
+ #define GOSU_BITMAP_HPP
6
+
7
+ #include <Gosu/Color.hpp>
8
+ #include <Gosu/Fwd.hpp>
9
+ #include <Gosu/GraphicsBase.hpp>
10
+ #include <boost/scoped_ptr.hpp>
11
+ #include <string>
12
+ #include <vector>
13
+
14
+ namespace Gosu
15
+ {
16
+ //! Rectangular area of pixels, each represented by a Color value. Provides
17
+ //! minimal drawing functionality and serves as a temporary holder for
18
+ //! graphical resources which are usually turned into Images later.
19
+ //! Has (expensive) value semantics.
20
+ class Bitmap
21
+ {
22
+ unsigned w, h;
23
+ std::vector<Color> pixels;
24
+
25
+ public:
26
+ Bitmap();
27
+
28
+ unsigned width() const { return w; }
29
+ unsigned height() const { return h; }
30
+
31
+ void swap(Bitmap& other);
32
+
33
+ void resize(unsigned width, unsigned height, Color c = Color::NONE);
34
+
35
+ void fill(Color c);
36
+ void replace(Color oldColor, Color newColor);
37
+
38
+ //! Returns the color at the specified position. x and y must be on the
39
+ //! bitmap.
40
+ Color getPixel(unsigned x, unsigned y) const { return pixels[y * w + x]; }
41
+
42
+ //! Sets the pixel at the specified position to a color. x and y must
43
+ //! be on the bitmap.
44
+ void setPixel(unsigned x, unsigned y, Color c) { pixels[y * w + x] = c; }
45
+
46
+ //! Inserts a bitmap at the given position. Parts of the inserted
47
+ //! bitmap that would be outside of the target bitmap will be
48
+ //! clipped away.
49
+ void insert(const Bitmap& source, int x, int y);
50
+
51
+ //! Inserts a portion of a bitmap at the given position. Parts of the
52
+ //! inserted bitmap that would be outside of the target bitmap will be
53
+ //! clipped away.
54
+ void insert(const Bitmap& source, int x, int y, unsigned srcX,
55
+ unsigned srcY, unsigned srcWidth, unsigned srcHeight);
56
+
57
+ //! Direct access to the array of color values. May be useful for optimized
58
+ //! OpenGL operations.
59
+ const unsigned* data() const { return reinterpret_cast<const unsigned*>(&pixels[0]); }
60
+ unsigned* data() { return reinterpret_cast<unsigned*>(&pixels[0]); }
61
+ };
62
+
63
+ //! Loads a Windows or OS/2 BMP file into the given bitmap.
64
+ Reader loadFromBMP(Bitmap& bmp, Reader reader);
65
+ //! Saves the contents of the given bitmap into windows BMP file data.
66
+ Writer saveToBMP(const Bitmap& bmp, Writer writer);
67
+ //! Loads a PNG file into the given bitmap.
68
+ Reader loadFromPNG(Bitmap& bmp, Reader reader);
69
+ //! Saves the contents of the given bitmap into PNG file data, 24 bits.
70
+ Writer saveToPNG(const Bitmap& bmp, Writer writer);
71
+
72
+ //! Set the alpha value of all pixels which are equal to the color key
73
+ //! to zero. Color values are adjusted so that no borders show up when
74
+ //! the image is stretched or rotated.
75
+ void applyColorKey(Bitmap& bitmap, Color key);
76
+
77
+ void applyBorderFlags(Bitmap& dest, const Bitmap& source,
78
+ unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
79
+ unsigned borderFlags);
80
+
81
+ // Still to be moved around & undocumented, beware! (TODO)
82
+ Bitmap quickLoadBitmap(const std::wstring& filename);
83
+ }
84
+
85
+ #endif
@@ -0,0 +1,140 @@
1
+ #ifndef GOSU_BUTTONSMAC_HPP
2
+ #define GOSU_BUTTONSMAC_HPP
3
+
4
+ namespace Gosu
5
+ {
6
+ //! List of button ids that can be used with Gosu::Input.
7
+ //! This enumeration contains ids for keyboard keys (kb*),
8
+ //! mouse buttons and mouse wheel (ms*) and gamepad buttons (gp*).
9
+ enum ButtonName
10
+ {
11
+ kbRangeBegin = 0x01,
12
+ kbEscape = 0x35,
13
+ kbF1 = 0x7a,
14
+ kbF2 = 0x78,
15
+ kbF3 = 0x63,
16
+ kbF4 = 0x76,
17
+ kbF5 = 0x60,
18
+ kbF6 = 0x61,
19
+ kbF7 = 0x62,
20
+ kbF8 = 0x64,
21
+ kbF9 = 0x65,
22
+ kbF10 = 0x6d,
23
+ kbF11 = 0x67,
24
+ kbF12 = 0x6f,
25
+ kb1 = 0x12,
26
+ kb2 = 0x13,
27
+ kb3 = 0x14,
28
+ kb4 = 0x15,
29
+ kb5 = 0x17,
30
+ kb6 = 0x16,
31
+ kb7 = 0x1a,
32
+ kb8 = 0x1c,
33
+ kb9 = 0x19,
34
+ kb0 = 0x1d,
35
+ kbA = 0x00,
36
+ kbB = 0x0b,
37
+ kbC = 0x08,
38
+ kbD = 0x02,
39
+ kbE = 0x0e,
40
+ kbF = 0x03,
41
+ kbG = 0x05,
42
+ kbH = 0x04,
43
+ kbI = 0x22,
44
+ kbJ = 0x26,
45
+ kbK = 0x28,
46
+ kbL = 0x25,
47
+ kbM = 0x2e,
48
+ kbN = 0x2d,
49
+ kbO = 0x1f,
50
+ kbP = 0x23,
51
+ kbQ = 0x0c,
52
+ kbR = 0x0f,
53
+ kbS = 0x01,
54
+ kbT = 0x11,
55
+ kbU = 0x20,
56
+ kbV = 0x09,
57
+ kbW = 0x0d,
58
+ kbX = 0x07,
59
+ kbY = 0x10,
60
+ kbZ = 0x06,
61
+ kbTab = 0x30,
62
+ kbReturn = 0x24,
63
+ kbSpace = 0x31,
64
+ kbLeftShift = 0x38,
65
+ kbRightShift = 0x3c,
66
+ kbLeftControl = 0x3b,
67
+ kbRightControl = 0x3e,
68
+ kbLeftAlt = 0x3a,
69
+ kbRightAlt = 0x3d,
70
+ kbLeftMeta = 0x37,
71
+ kbRightMeta = 0x36,
72
+ kbBackspace = 0x33,
73
+ kbLeft = 0x7b,
74
+ kbRight = 0x7c,
75
+ kbUp = 0x7e,
76
+ kbDown = 0x7d,
77
+ kbHome = 0x73,
78
+ kbEnd = 0x77,
79
+ kbInsert = 0x72,
80
+ kbDelete = 0x75,
81
+ kbPageUp = 0x74,
82
+ kbPageDown = 0x79,
83
+ kbEnter = 0x4c,
84
+ kbNumpad1 = 0x53,
85
+ kbNumpad2 = 0x54,
86
+ kbNumpad3 = 0x55,
87
+ kbNumpad4 = 0x56,
88
+ kbNumpad5 = 0x57,
89
+ kbNumpad6 = 0x58,
90
+ kbNumpad7 = 0x59,
91
+ kbNumpad8 = 0x5b,
92
+ kbNumpad9 = 0x5c,
93
+ kbNumpad0 = 0x52,
94
+ kbNumpadAdd = 0x45,
95
+ kbNumpadSubtract = 0x4e,
96
+ kbNumpadMultiply = 0x43,
97
+ kbNumpadDivide = 0x4b,
98
+ kbRangeEnd = 0xffff,
99
+
100
+ msRangeBegin,
101
+ msLeft = msRangeBegin,
102
+ msRight,
103
+ msMiddle,
104
+ msWheelUp,
105
+ msWheelDown,
106
+ msRangeEnd,
107
+
108
+ gpRangeBegin,
109
+ gpLeft = gpRangeBegin,
110
+ gpRight,
111
+ gpUp,
112
+ gpDown,
113
+ gpButton0,
114
+ gpButton1,
115
+ gpButton2,
116
+ gpButton3,
117
+ gpButton4,
118
+ gpButton5,
119
+ gpButton6,
120
+ gpButton7,
121
+ gpButton8,
122
+ gpButton9,
123
+ gpButton10,
124
+ gpButton11,
125
+ gpButton12,
126
+ gpButton13,
127
+ gpButton14,
128
+ gpButton15,
129
+ gpRangeEnd = gpButton15,
130
+
131
+ kbNum = kbRangeEnd - kbRangeBegin + 1,
132
+ msNum = msRangeEnd - msRangeBegin + 1,
133
+ gpNum = gpRangeEnd - gpRangeBegin + 1,
134
+
135
+ numButtons = gpRangeEnd + 1,
136
+ noButton = 0xffffffff
137
+ };
138
+ }
139
+
140
+ #endif