gosu 0.14.6.pre1 → 1.0.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/COPYING +1 -1
- data/dependencies/SDL/include/SDL.h +138 -0
- data/dependencies/SDL/include/SDL_assert.h +293 -0
- data/dependencies/SDL/include/SDL_atomic.h +295 -0
- data/dependencies/SDL/include/SDL_audio.h +859 -0
- data/dependencies/SDL/include/SDL_bits.h +121 -0
- data/dependencies/SDL/include/SDL_blendmode.h +123 -0
- data/dependencies/SDL/include/SDL_clipboard.h +71 -0
- data/dependencies/SDL/include/SDL_config.h +55 -0
- data/dependencies/SDL/include/SDL_config_android.h +182 -0
- data/dependencies/SDL/include/SDL_config_iphoneos.h +207 -0
- data/dependencies/SDL/include/SDL_config_macosx.h +266 -0
- data/dependencies/SDL/include/SDL_config_minimal.h +85 -0
- data/dependencies/SDL/include/SDL_config_os2.h +188 -0
- data/dependencies/SDL/include/SDL_config_pandora.h +135 -0
- data/dependencies/SDL/include/SDL_config_psp.h +165 -0
- data/dependencies/SDL/include/SDL_config_windows.h +288 -0
- data/dependencies/SDL/include/SDL_config_winrt.h +243 -0
- data/dependencies/SDL/include/SDL_config_wiz.h +149 -0
- data/dependencies/SDL/include/SDL_copying.h +20 -0
- data/dependencies/SDL/include/SDL_cpuinfo.h +299 -0
- data/dependencies/SDL/include/SDL_egl.h +1676 -0
- data/dependencies/SDL/include/SDL_endian.h +263 -0
- data/dependencies/SDL/include/SDL_error.h +112 -0
- data/dependencies/SDL/include/SDL_events.h +827 -0
- data/dependencies/SDL/include/SDL_filesystem.h +136 -0
- data/dependencies/SDL/include/SDL_gamecontroller.h +541 -0
- data/dependencies/SDL/include/SDL_gesture.h +87 -0
- data/dependencies/SDL/include/SDL_haptic.h +1247 -0
- data/dependencies/SDL/include/SDL_hints.h +1578 -0
- data/dependencies/SDL/include/SDL_joystick.h +499 -0
- data/dependencies/SDL/include/SDL_keyboard.h +217 -0
- data/dependencies/SDL/include/SDL_keycode.h +351 -0
- data/dependencies/SDL/include/SDL_loadso.h +81 -0
- data/dependencies/SDL/include/SDL_locale.h +101 -0
- data/dependencies/SDL/include/SDL_log.h +211 -0
- data/dependencies/SDL/include/SDL_main.h +180 -0
- data/dependencies/SDL/include/SDL_messagebox.h +146 -0
- data/dependencies/SDL/include/SDL_metal.h +117 -0
- data/dependencies/SDL/include/SDL_misc.h +75 -0
- data/dependencies/SDL/include/SDL_mouse.h +302 -0
- data/dependencies/SDL/include/SDL_mutex.h +251 -0
- data/dependencies/SDL/include/SDL_name.h +33 -0
- data/dependencies/SDL/include/SDL_opengl.h +2183 -0
- data/dependencies/SDL/include/SDL_opengl_glext.h +11180 -0
- data/dependencies/SDL/include/SDL_opengles.h +39 -0
- data/dependencies/SDL/include/SDL_opengles2.h +52 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2.h +621 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2ext.h +2050 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2platform.h +30 -0
- data/dependencies/SDL/include/SDL_opengles2_khrplatform.h +282 -0
- data/dependencies/SDL/include/SDL_pixels.h +479 -0
- data/dependencies/SDL/include/SDL_platform.h +198 -0
- data/dependencies/SDL/include/SDL_power.h +75 -0
- data/dependencies/SDL/include/SDL_quit.h +58 -0
- data/dependencies/SDL/include/SDL_rect.h +174 -0
- data/dependencies/SDL/include/SDL_render.h +1158 -0
- data/dependencies/SDL/include/SDL_revision.h +2 -0
- data/dependencies/SDL/include/SDL_rwops.h +283 -0
- data/dependencies/SDL/include/SDL_scancode.h +413 -0
- data/dependencies/SDL/include/SDL_sensor.h +267 -0
- data/dependencies/SDL/include/SDL_shape.h +144 -0
- data/dependencies/SDL/include/SDL_stdinc.h +647 -0
- data/dependencies/SDL/include/SDL_surface.h +563 -0
- data/dependencies/SDL/include/SDL_system.h +325 -0
- data/dependencies/SDL/include/SDL_syswm.h +354 -0
- data/dependencies/SDL/include/SDL_test.h +69 -0
- data/dependencies/SDL/include/SDL_test_assert.h +105 -0
- data/dependencies/SDL/include/SDL_test_common.h +218 -0
- data/dependencies/SDL/include/SDL_test_compare.h +69 -0
- data/dependencies/SDL/include/SDL_test_crc32.h +124 -0
- data/dependencies/SDL/include/SDL_test_font.h +81 -0
- data/dependencies/SDL/include/SDL_test_fuzzer.h +384 -0
- data/dependencies/SDL/include/SDL_test_harness.h +134 -0
- data/dependencies/SDL/include/SDL_test_images.h +78 -0
- data/dependencies/SDL/include/SDL_test_log.h +67 -0
- data/dependencies/SDL/include/SDL_test_md5.h +129 -0
- data/dependencies/SDL/include/SDL_test_memory.h +63 -0
- data/dependencies/SDL/include/SDL_test_random.h +115 -0
- data/dependencies/SDL/include/SDL_thread.h +366 -0
- data/dependencies/SDL/include/SDL_timer.h +115 -0
- data/dependencies/SDL/include/SDL_touch.h +102 -0
- data/dependencies/SDL/include/SDL_types.h +29 -0
- data/dependencies/SDL/include/SDL_version.h +162 -0
- data/dependencies/SDL/include/SDL_video.h +1282 -0
- data/dependencies/SDL/include/SDL_vulkan.h +276 -0
- data/dependencies/SDL/include/begin_code.h +166 -0
- data/dependencies/SDL/include/close_code.h +40 -0
- data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
- data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
- data/dependencies/SDL_sound/SDL_sound.c +795 -0
- data/dependencies/SDL_sound/SDL_sound.h +725 -0
- data/dependencies/SDL_sound/SDL_sound_aiff.c +537 -0
- data/dependencies/SDL_sound/SDL_sound_au.c +352 -0
- data/dependencies/SDL_sound/SDL_sound_coreaudio.c +747 -0
- data/dependencies/SDL_sound/SDL_sound_flac.c +182 -0
- data/dependencies/SDL_sound/SDL_sound_internal.h +304 -0
- data/dependencies/SDL_sound/SDL_sound_modplug.c +228 -0
- data/dependencies/SDL_sound/SDL_sound_mp3.c +184 -0
- data/dependencies/SDL_sound/SDL_sound_raw.c +164 -0
- data/dependencies/SDL_sound/SDL_sound_shn.c +1309 -0
- data/dependencies/SDL_sound/SDL_sound_voc.c +550 -0
- data/dependencies/SDL_sound/SDL_sound_vorbis.c +223 -0
- data/dependencies/SDL_sound/SDL_sound_wav.c +783 -0
- data/dependencies/SDL_sound/dr_flac.h +5906 -0
- data/dependencies/SDL_sound/dr_mp3.h +2832 -0
- data/dependencies/SDL_sound/libmodplug/fastmix.c +1748 -0
- data/dependencies/SDL_sound/libmodplug/libmodplug.h +1001 -0
- data/dependencies/SDL_sound/libmodplug/load_669.c +188 -0
- data/dependencies/SDL_sound/libmodplug/load_abc.c +4725 -0
- data/dependencies/SDL_sound/libmodplug/load_amf.c +403 -0
- data/dependencies/SDL_sound/libmodplug/load_ams.c +587 -0
- data/dependencies/SDL_sound/libmodplug/load_dbm.c +357 -0
- data/dependencies/SDL_sound/libmodplug/load_dmf.c +531 -0
- data/dependencies/SDL_sound/libmodplug/load_dsm.c +232 -0
- data/dependencies/SDL_sound/libmodplug/load_far.c +253 -0
- data/dependencies/SDL_sound/libmodplug/load_it.c +796 -0
- data/dependencies/SDL_sound/libmodplug/load_mdl.c +488 -0
- data/dependencies/SDL_sound/libmodplug/load_med.c +757 -0
- data/dependencies/SDL_sound/libmodplug/load_mid.c +1405 -0
- data/dependencies/SDL_sound/libmodplug/load_mod.c +269 -0
- data/dependencies/SDL_sound/libmodplug/load_mt2.c +546 -0
- data/dependencies/SDL_sound/libmodplug/load_mtm.c +142 -0
- data/dependencies/SDL_sound/libmodplug/load_okt.c +192 -0
- data/dependencies/SDL_sound/libmodplug/load_pat.c +1143 -0
- data/dependencies/SDL_sound/libmodplug/load_pat.h +25 -0
- data/dependencies/SDL_sound/libmodplug/load_psm.c +350 -0
- data/dependencies/SDL_sound/libmodplug/load_ptm.c +204 -0
- data/dependencies/SDL_sound/libmodplug/load_s3m.c +325 -0
- data/dependencies/SDL_sound/libmodplug/load_stm.c +180 -0
- data/dependencies/SDL_sound/libmodplug/load_ult.c +206 -0
- data/dependencies/SDL_sound/libmodplug/load_umx.c +51 -0
- data/dependencies/SDL_sound/libmodplug/load_xm.c +554 -0
- data/dependencies/SDL_sound/libmodplug/mmcmp.c +382 -0
- data/dependencies/SDL_sound/libmodplug/modplug.c +170 -0
- data/dependencies/SDL_sound/libmodplug/modplug.h +90 -0
- data/dependencies/SDL_sound/libmodplug/snd_dsp.c +301 -0
- data/dependencies/SDL_sound/libmodplug/snd_flt.c +63 -0
- data/dependencies/SDL_sound/libmodplug/snd_fx.c +2350 -0
- data/dependencies/SDL_sound/libmodplug/sndfile.c +1169 -0
- data/dependencies/SDL_sound/libmodplug/sndmix.c +1034 -0
- data/dependencies/SDL_sound/libmodplug/tables.h +371 -0
- data/{src/stb_vorbis.c → dependencies/SDL_sound/stb_vorbis.h} +128 -23
- data/dependencies/al_soft/AL/al.h +655 -0
- data/dependencies/al_soft/AL/alc.h +270 -0
- data/dependencies/al_soft/AL/alext.h +585 -0
- data/dependencies/al_soft/AL/efx-creative.h +3 -0
- data/dependencies/al_soft/AL/efx-presets.h +402 -0
- data/dependencies/al_soft/AL/efx.h +762 -0
- data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
- data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
- data/{src → dependencies/stb}/stb_image.h +476 -176
- data/{src → dependencies/stb}/stb_image_write.h +253 -131
- data/{src → dependencies/stb}/stb_truetype.h +262 -104
- data/{src → dependencies/utf8proc}/utf8proc.c +47 -29
- data/{src → dependencies/utf8proc}/utf8proc.h +46 -24
- data/{src → dependencies/utf8proc}/utf8proc_data.h +10043 -9609
- data/ext/gosu/extconf.rb +53 -39
- data/{Gosu → include/Gosu}/Audio.hpp +6 -8
- data/include/Gosu/Bitmap.hpp +100 -0
- data/{Gosu → include/Gosu}/Buttons.hpp +104 -44
- data/include/Gosu/Channel.h +25 -0
- data/include/Gosu/Color.h +38 -0
- data/{Gosu → include/Gosu}/Color.hpp +0 -0
- data/{Gosu → include/Gosu}/Directories.hpp +0 -0
- data/include/Gosu/Font.h +36 -0
- data/{Gosu → include/Gosu}/Font.hpp +0 -0
- data/{Gosu → include/Gosu}/Fwd.hpp +0 -5
- data/include/Gosu/Gosu.h +82 -0
- data/{Gosu → include/Gosu}/Gosu.hpp +0 -0
- data/{Gosu → include/Gosu}/Graphics.hpp +0 -0
- data/{Gosu → include/Gosu}/GraphicsBase.hpp +0 -0
- data/{Gosu → include/Gosu}/IO.hpp +0 -0
- data/include/Gosu/Image.h +54 -0
- data/{Gosu → include/Gosu}/Image.hpp +7 -6
- data/{Gosu → include/Gosu}/ImageData.hpp +0 -0
- data/{Gosu → include/Gosu}/Input.hpp +39 -51
- data/{Gosu → include/Gosu}/Inspection.hpp +0 -0
- data/{Gosu → include/Gosu}/Math.hpp +0 -0
- data/{Gosu → include/Gosu}/Platform.hpp +0 -0
- data/include/Gosu/Sample.h +19 -0
- data/include/Gosu/Song.h +24 -0
- data/{Gosu → include/Gosu}/Text.hpp +0 -0
- data/include/Gosu/TextInput.h +30 -0
- data/{Gosu → include/Gosu}/TextInput.hpp +0 -0
- data/{Gosu → include/Gosu}/Timing.hpp +0 -0
- data/{Gosu → include/Gosu}/Utility.hpp +15 -4
- data/{Gosu → include/Gosu}/Version.hpp +3 -3
- data/include/Gosu/Window.h +63 -0
- data/{Gosu → include/Gosu}/Window.hpp +23 -25
- data/lib/OpenAL32.dll +0 -0
- data/lib/SDL2.dll +0 -0
- data/lib/gosu.rb +0 -3
- data/lib/gosu/compat.rb +9 -4
- data/lib/gosu/patches.rb +8 -11
- data/lib/gosu/swig_patches.rb +13 -6
- data/lib64/OpenAL32.dll +0 -0
- data/lib64/SDL2.dll +0 -0
- data/rdoc/gosu.rb +114 -21
- data/src/Audio.cpp +50 -224
- data/src/AudioFile.hpp +20 -37
- data/src/AudioFileAudioToolbox.cpp +237 -0
- data/src/AudioFileSDLSound.cpp +147 -0
- data/src/AudioImpl.cpp +3 -12
- data/src/AudioImpl.hpp +3 -1
- data/src/Bitmap.cpp +85 -83
- data/src/BitmapIO.cpp +52 -58
- data/src/ChannelWrapper.cpp +50 -0
- data/src/ColorWrapper.cpp +126 -0
- data/src/Constants.cpp +338 -0
- data/src/Font.cpp +4 -1
- data/src/FontWrapper.cpp +74 -0
- data/src/GosuWrapper.cpp +251 -0
- data/src/Graphics.cpp +11 -5
- data/src/GraphicsImpl.hpp +0 -1
- data/src/Image.cpp +13 -16
- data/src/ImageWrapper.cpp +168 -0
- data/src/Input.cpp +412 -164
- data/src/LargeImageData.cpp +2 -1
- data/src/MarkupParser.cpp +13 -4
- data/src/RubyGosu.cxx +502 -219
- data/src/RubyGosu.h +4 -2
- data/src/SampleWrapper.cpp +30 -0
- data/src/SongWrapper.cpp +52 -0
- data/src/TexChunk.cpp +29 -19
- data/src/Text.cpp +2 -0
- data/src/TextBuilder.cpp +6 -4
- data/src/TextInputWrapper.cpp +101 -0
- data/src/Texture.cpp +1 -1
- data/src/TrueTypeFont.cpp +2 -1
- data/src/Utility.cpp +11 -7
- data/src/Window.cpp +30 -39
- data/src/WindowWrapper.cpp +317 -0
- metadata +212 -42
- data/Gosu/AutoLink.hpp +0 -14
- data/Gosu/Bitmap.hpp +0 -113
- data/src/AudioToolboxFile.hpp +0 -210
- data/src/OggFile.hpp +0 -92
- data/src/SndFile.hpp +0 -174
- data/src/WinMain.cpp +0 -64
data/src/RubyGosu.h
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/* ----------------------------------------------------------------------------
|
2
2
|
* This file was automatically generated by SWIG (http://www.swig.org).
|
3
|
-
* Version
|
3
|
+
* Version 4.1.0
|
4
4
|
*
|
5
5
|
* This file is not intended to be easily readable and contains a number of
|
6
6
|
* coding conventions designed to improve portability and efficiency. Do not make
|
@@ -28,7 +28,7 @@ public:
|
|
28
28
|
class SwigDirector_Window : public Gosu::Window, public Swig::Director {
|
29
29
|
|
30
30
|
public:
|
31
|
-
SwigDirector_Window(VALUE self,
|
31
|
+
SwigDirector_Window(VALUE self,unsigned int width,unsigned int height,bool fullscreen=false,double update_interval=16.666666,bool resizable=false);
|
32
32
|
virtual ~SwigDirector_Window();
|
33
33
|
virtual void show();
|
34
34
|
virtual bool tick();
|
@@ -41,6 +41,8 @@ public:
|
|
41
41
|
virtual void release_memory();
|
42
42
|
virtual void button_down(Gosu::Button arg0);
|
43
43
|
virtual void button_up(Gosu::Button arg0);
|
44
|
+
virtual void gamepad_connected(int index);
|
45
|
+
virtual void gamepad_disconnected(int index);
|
44
46
|
virtual void drop(std::string const &filename);
|
45
47
|
};
|
46
48
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#include <Gosu/Audio.hpp>
|
2
|
+
#include <Gosu/Sample.h>
|
3
|
+
|
4
|
+
extern "C" {
|
5
|
+
|
6
|
+
Gosu_Sample *Gosu_Sample_create(const char *filename)
|
7
|
+
{
|
8
|
+
return reinterpret_cast<Gosu_Sample *>( new Gosu::Sample(filename) );
|
9
|
+
}
|
10
|
+
|
11
|
+
void Gosu_Sample_destroy(Gosu_Sample *sample)
|
12
|
+
{
|
13
|
+
delete( reinterpret_cast<Gosu::Sample *>( sample ) );
|
14
|
+
}
|
15
|
+
|
16
|
+
Gosu_Channel *Gosu_Sample_play(Gosu_Sample *sample, double volume, double speed, bool looping)
|
17
|
+
{
|
18
|
+
Gosu::Channel channel = reinterpret_cast<Gosu::Sample *>( sample )->play(volume, speed, looping);
|
19
|
+
|
20
|
+
return reinterpret_cast<Gosu_Channel *>( new Gosu::Channel(channel) );
|
21
|
+
}
|
22
|
+
|
23
|
+
Gosu_Channel *Gosu_Sample_play_pan(Gosu_Sample *sample, double pan, double volume, double speed, bool looping)
|
24
|
+
{
|
25
|
+
Gosu::Channel channel = reinterpret_cast<Gosu::Sample *>( sample )->play_pan(pan, volume, speed, looping);
|
26
|
+
|
27
|
+
return reinterpret_cast<Gosu_Channel *>( new Gosu::Channel(channel) );
|
28
|
+
}
|
29
|
+
|
30
|
+
}
|
data/src/SongWrapper.cpp
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#include <Gosu/Audio.hpp>
|
2
|
+
#include <Gosu/Song.h>
|
3
|
+
|
4
|
+
extern "C" {
|
5
|
+
Gosu_Song* Gosu_Song_create(const char* filename)
|
6
|
+
{
|
7
|
+
return reinterpret_cast<Gosu_Song*>( new Gosu::Song(filename) );
|
8
|
+
}
|
9
|
+
|
10
|
+
void Gosu_Song_destroy(Gosu_Song* song)
|
11
|
+
{
|
12
|
+
delete( reinterpret_cast<Gosu::Song*>( song ));
|
13
|
+
}
|
14
|
+
|
15
|
+
void Gosu_Song_play(Gosu_Song* song, bool looping)
|
16
|
+
{
|
17
|
+
reinterpret_cast<Gosu::Song*>( song )->play(looping);
|
18
|
+
}
|
19
|
+
|
20
|
+
bool Gosu_Song_playing(Gosu_Song* song)
|
21
|
+
{
|
22
|
+
return reinterpret_cast<Gosu::Song*>( song )->playing();
|
23
|
+
}
|
24
|
+
|
25
|
+
void Gosu_Song_pause(Gosu_Song* song)
|
26
|
+
{
|
27
|
+
reinterpret_cast<Gosu::Song*>( song )->pause();
|
28
|
+
}
|
29
|
+
|
30
|
+
bool Gosu_Song_paused(Gosu_Song* song)
|
31
|
+
{
|
32
|
+
return reinterpret_cast<Gosu::Song*>( song )->paused();
|
33
|
+
}
|
34
|
+
|
35
|
+
void Gosu_Song_stop(Gosu_Song* song)
|
36
|
+
{
|
37
|
+
reinterpret_cast<Gosu::Song*>( song )->stop();
|
38
|
+
}
|
39
|
+
|
40
|
+
double Gosu_Song_volume(Gosu_Song* song){
|
41
|
+
return reinterpret_cast<Gosu::Song*>( song )->volume();
|
42
|
+
}
|
43
|
+
|
44
|
+
void Gosu_Song_set_volume(Gosu_Song* song, double volume){
|
45
|
+
return reinterpret_cast<Gosu::Song*>( song )->set_volume(volume);
|
46
|
+
}
|
47
|
+
|
48
|
+
Gosu_Song* Gosu_Song_current_song()
|
49
|
+
{
|
50
|
+
return reinterpret_cast<Gosu_Song*>(Gosu::Song::current_song());
|
51
|
+
}
|
52
|
+
}
|
data/src/TexChunk.cpp
CHANGED
@@ -82,39 +82,49 @@ Gosu::Bitmap Gosu::TexChunk::to_bitmap() const
|
|
82
82
|
return texture->to_bitmap(x, y, w, h);
|
83
83
|
}
|
84
84
|
|
85
|
-
void Gosu::TexChunk::insert(const Bitmap&
|
85
|
+
void Gosu::TexChunk::insert(const Bitmap& original_bitmap, int x, int y)
|
86
86
|
{
|
87
|
-
Bitmap
|
88
|
-
const Bitmap* bitmap = &
|
87
|
+
Bitmap clipped_bitmap;
|
88
|
+
const Bitmap* bitmap = &original_bitmap;
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
// If inserting the bitmap at the given position exceeds the boundaries of the space allocated
|
91
|
+
// for this image on the texture, we need to clip the bitmap and insert the clipped version
|
92
|
+
// instead.
|
93
|
+
if (x < 0 || y < 0 || x + original_bitmap.width() > w || y + original_bitmap.height() > h) {
|
94
|
+
// How many pixels to remove at the top and left sides.
|
95
|
+
int clip_left = 0, clip_top = 0;
|
96
|
+
// How large the clipped version needs to be.
|
97
|
+
int clipped_width = original_bitmap.width(), clipped_height = original_bitmap.height();
|
98
|
+
|
99
|
+
// Clip away pixels on the left side, if necessary.
|
93
100
|
if (x < 0) {
|
94
|
-
|
95
|
-
|
101
|
+
clip_left = -x;
|
102
|
+
clipped_width -= -x;
|
96
103
|
x = 0;
|
97
104
|
}
|
105
|
+
// Clip away pixels at the top, if necessary.
|
98
106
|
if (y < 0) {
|
99
|
-
|
100
|
-
|
107
|
+
clip_top = -y;
|
108
|
+
clipped_height -= -y;
|
101
109
|
y = 0;
|
102
110
|
}
|
103
|
-
|
104
|
-
|
111
|
+
// Clip away pixels on the right side, if necessary.
|
112
|
+
if (x + clipped_width > w) {
|
113
|
+
clipped_width = (w - x);
|
105
114
|
}
|
106
|
-
|
107
|
-
|
115
|
+
// Clip away pixels on the bottom, if necessary.
|
116
|
+
if (y + clipped_height > h) {
|
117
|
+
clipped_height = (h - y);
|
108
118
|
}
|
109
119
|
|
110
|
-
if (
|
120
|
+
if (clipped_width <= 0 || clipped_height <= 0) return;
|
111
121
|
|
112
|
-
|
113
|
-
|
114
|
-
bitmap = &
|
122
|
+
clipped_bitmap.resize(clipped_width, clipped_height);
|
123
|
+
clipped_bitmap.insert(-clip_left, -clip_top, original_bitmap);
|
124
|
+
bitmap = &clipped_bitmap;
|
115
125
|
}
|
116
126
|
|
117
127
|
glBindTexture(GL_TEXTURE_2D, tex_name());
|
118
128
|
glTexSubImage2D(GL_TEXTURE_2D, 0, this->x + x, this->y + y, bitmap->width(), bitmap->height(),
|
119
|
-
|
129
|
+
Color::GL_FORMAT, GL_UNSIGNED_BYTE, bitmap->data());
|
120
130
|
}
|
data/src/Text.cpp
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
#include <cmath>
|
8
8
|
#include <algorithm>
|
9
9
|
#include <vector>
|
10
|
+
#include <stdexcept>
|
10
11
|
using namespace std;
|
11
12
|
|
12
13
|
double Gosu::text_width(const u32string& text,
|
@@ -33,6 +34,7 @@ Gosu::Bitmap Gosu::layout_text(const string& text, const string& font_name,
|
|
33
34
|
double font_height, double line_spacing,
|
34
35
|
int width, Alignment align, unsigned font_flags)
|
35
36
|
{
|
37
|
+
// Escape all markup and delegate to layout_markup.
|
36
38
|
return layout_markup(escape_markup(text), font_name,
|
37
39
|
font_height, line_spacing,
|
38
40
|
width, align, font_flags);
|
data/src/TextBuilder.cpp
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
#include "TextBuilder.hpp"
|
2
2
|
#include <Gosu/Text.hpp>
|
3
|
+
|
4
|
+
#include <utf8proc.h>
|
5
|
+
|
3
6
|
#include <cassert>
|
4
7
|
#include <cmath>
|
5
|
-
#include "utf8proc.h"
|
6
8
|
using namespace std;
|
7
9
|
|
8
10
|
Gosu::WordInfo::WordInfo(const string& font_name, double font_height, vector<FormattedString> parts)
|
@@ -58,7 +60,7 @@ void Gosu::TextBuilder::flush_current_line(EndOfLineReason reason)
|
|
58
60
|
}
|
59
61
|
|
60
62
|
double whitespace_factor = 1.0;
|
61
|
-
if (align == AL_JUSTIFY && reason == LINE_TOO_LONG) {
|
63
|
+
if (align == AL_JUSTIFY && whitespace_width != 0 && reason == LINE_TOO_LONG) {
|
62
64
|
whitespace_factor = (result.width() - words_width) / whitespace_width;
|
63
65
|
}
|
64
66
|
|
@@ -132,7 +134,7 @@ void Gosu::TextBuilder::feed_word(vector<FormattedString>&& word)
|
|
132
134
|
current_line.emplace_back(new_word);
|
133
135
|
current_line_width += new_word.width;
|
134
136
|
|
135
|
-
if (
|
136
|
-
flush_current_line(
|
137
|
+
if (new_word.is_end_of_line) {
|
138
|
+
flush_current_line(END_OF_PARAGRAPH);
|
137
139
|
}
|
138
140
|
}
|
@@ -0,0 +1,101 @@
|
|
1
|
+
#include <Gosu/Gosu.hpp>
|
2
|
+
|
3
|
+
namespace Gosu
|
4
|
+
{
|
5
|
+
class TextInputForWrapper : public Gosu::TextInput
|
6
|
+
{
|
7
|
+
public:
|
8
|
+
TextInputForWrapper();
|
9
|
+
std::string filter(std::string text) const override;
|
10
|
+
std::function<void (const char *text)> filter_callback;
|
11
|
+
std::string filter_result = "";
|
12
|
+
};
|
13
|
+
} // namespace Gosu
|
14
|
+
|
15
|
+
Gosu::TextInputForWrapper::TextInputForWrapper() : Gosu::TextInput()
|
16
|
+
{
|
17
|
+
}
|
18
|
+
|
19
|
+
std::string Gosu::TextInputForWrapper::filter(std::string text) const
|
20
|
+
{
|
21
|
+
if (filter_callback != nullptr) {
|
22
|
+
filter_callback(text.c_str());
|
23
|
+
return filter_result;
|
24
|
+
}
|
25
|
+
else {
|
26
|
+
return text;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
extern "C" {
|
31
|
+
#include <Gosu/TextInput.h>
|
32
|
+
|
33
|
+
Gosu_TextInput *Gosu_TextInput_create()
|
34
|
+
{
|
35
|
+
return reinterpret_cast<Gosu_TextInput *>(new Gosu::TextInputForWrapper());
|
36
|
+
}
|
37
|
+
|
38
|
+
const char *Gosu_TextInput_text(Gosu_TextInput *text_input)
|
39
|
+
{
|
40
|
+
thread_local std::string string;
|
41
|
+
string = reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->text();
|
42
|
+
|
43
|
+
return string.c_str();
|
44
|
+
}
|
45
|
+
|
46
|
+
void Gosu_TextInput_set_text(Gosu_TextInput *text_input, const char *text)
|
47
|
+
{
|
48
|
+
reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->set_text(text);
|
49
|
+
}
|
50
|
+
|
51
|
+
unsigned Gosu_TextInput_caret_pos(Gosu_TextInput *text_input)
|
52
|
+
{
|
53
|
+
return reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->caret_pos();
|
54
|
+
}
|
55
|
+
|
56
|
+
void Gosu_TextInput_set_caret_pos(Gosu_TextInput *text_input, unsigned pos)
|
57
|
+
{
|
58
|
+
return reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->set_caret_pos(pos);
|
59
|
+
}
|
60
|
+
|
61
|
+
unsigned Gosu_TextInput_selection_start(Gosu_TextInput *text_input)
|
62
|
+
{
|
63
|
+
return reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->selection_start();
|
64
|
+
}
|
65
|
+
|
66
|
+
void Gosu_TextInput_set_selection_start(Gosu_TextInput *text_input, unsigned pos)
|
67
|
+
{
|
68
|
+
return reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->set_selection_start(pos);
|
69
|
+
}
|
70
|
+
|
71
|
+
void Gosu_TextInput_set_filter(Gosu_TextInput *text_input, void function(void *data, const char *text), void *data)
|
72
|
+
{
|
73
|
+
reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->filter_callback = [=](const char *text) { function(data, text); };
|
74
|
+
}
|
75
|
+
|
76
|
+
void Gosu_TextInput_set_filter_result(Gosu_TextInput *text_input, const char *result)
|
77
|
+
{
|
78
|
+
reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->filter_result = result;
|
79
|
+
}
|
80
|
+
|
81
|
+
void Gosu_TextInput_insert_text(Gosu_TextInput *text_input, const char *text)
|
82
|
+
{
|
83
|
+
reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->insert_text(text);
|
84
|
+
}
|
85
|
+
|
86
|
+
void Gosu_TextInput_delete_backward(Gosu_TextInput *text_input)
|
87
|
+
{
|
88
|
+
reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->delete_backward();
|
89
|
+
}
|
90
|
+
|
91
|
+
void Gosu_TextInput_delete_forward(Gosu_TextInput *text_input)
|
92
|
+
{
|
93
|
+
reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->delete_forward();
|
94
|
+
}
|
95
|
+
|
96
|
+
void Gosu_TextInput_destroy(Gosu_TextInput *text_input)
|
97
|
+
{
|
98
|
+
delete (reinterpret_cast<Gosu::TextInputForWrapper *>(text_input));
|
99
|
+
}
|
100
|
+
|
101
|
+
}
|
data/src/Texture.cpp
CHANGED
@@ -124,7 +124,7 @@ Gosu::Bitmap Gosu::Texture::to_bitmap(unsigned x, unsigned y, unsigned width, un
|
|
124
124
|
// TODO: There are ways to retrieve only part of a texture, which we should use sooner or later.
|
125
125
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, full_texture.data());
|
126
126
|
Bitmap bitmap(width, height);
|
127
|
-
bitmap.insert(
|
127
|
+
bitmap.insert(-int(x), -int(y), full_texture);
|
128
128
|
|
129
129
|
return bitmap;
|
130
130
|
#endif
|
data/src/TrueTypeFont.cpp
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#include "TrueTypeFont.hpp"
|
2
2
|
#include <Gosu/IO.hpp>
|
3
3
|
#include <Gosu/Text.hpp>
|
4
|
+
#include <stdexcept>
|
4
5
|
|
5
6
|
// Disable comma warnings in stb headers.
|
6
7
|
#ifdef __GNUC__
|
@@ -9,7 +10,7 @@
|
|
9
10
|
#endif
|
10
11
|
|
11
12
|
#define STB_TRUETYPE_IMPLEMENTATION
|
12
|
-
#include
|
13
|
+
#include <stb_truetype.h>
|
13
14
|
|
14
15
|
#ifdef __GNUC__
|
15
16
|
#pragma GCC diagnostic pop
|
data/src/Utility.cpp
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#include <Gosu/Utility.hpp>
|
2
2
|
#include <Gosu/Platform.hpp>
|
3
3
|
|
4
|
-
#include
|
4
|
+
#include <utf8proc.h>
|
5
5
|
|
6
6
|
#include <cstring>
|
7
7
|
#include <stdexcept>
|
@@ -45,17 +45,20 @@ u32string Gosu::utf8_to_composed_utc4(const string& utf8)
|
|
45
45
|
return utc4;
|
46
46
|
}
|
47
47
|
|
48
|
-
bool Gosu::has_extension(
|
48
|
+
bool Gosu::has_extension(string_view filename, string_view extension)
|
49
49
|
{
|
50
|
-
size_t ext_len =
|
50
|
+
size_t ext_len = extension.length();
|
51
51
|
if (ext_len > filename.length()) {
|
52
52
|
return false;
|
53
53
|
}
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
string_view::iterator filename_iter = filename.end();
|
56
|
+
string_view::iterator ext_iter = extension.end();
|
57
57
|
while (ext_len--) {
|
58
|
-
|
58
|
+
--filename_iter;
|
59
|
+
--ext_iter;
|
60
|
+
|
61
|
+
if (tolower((int) *filename_iter) != tolower((int) *ext_iter)) {
|
59
62
|
return false;
|
60
63
|
}
|
61
64
|
}
|
@@ -66,6 +69,7 @@ bool Gosu::has_extension(const string& filename, const char* extension)
|
|
66
69
|
#if defined(GOSU_IS_UNIX) && !defined(GOSU_IS_MAC)
|
67
70
|
string Gosu::language()
|
68
71
|
{
|
69
|
-
|
72
|
+
const char* env = getenv("LANG");
|
73
|
+
return env ? env : "en_US";
|
70
74
|
}
|
71
75
|
#endif
|
data/src/Window.cpp
CHANGED
@@ -22,8 +22,6 @@ namespace Gosu
|
|
22
22
|
throw runtime_error(operation + ": " + (error ? error : "(unknown error)"));
|
23
23
|
}
|
24
24
|
|
25
|
-
static void cleanup();
|
26
|
-
|
27
25
|
SDL_Window* shared_window()
|
28
26
|
{
|
29
27
|
static SDL_Window* window = nullptr;
|
@@ -32,14 +30,12 @@ namespace Gosu
|
|
32
30
|
throw_sdl_error("Could not initialize SDL Video");
|
33
31
|
}
|
34
32
|
|
35
|
-
atexit(cleanup);
|
36
|
-
|
37
33
|
Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN;
|
38
|
-
|
34
|
+
|
39
35
|
#if SDL_VERSION_ATLEAST(2, 0, 1)
|
40
36
|
flags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
41
37
|
#endif
|
42
|
-
|
38
|
+
|
43
39
|
window =
|
44
40
|
SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 64, 64, flags);
|
45
41
|
if (window == nullptr) {
|
@@ -58,27 +54,20 @@ namespace Gosu
|
|
58
54
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
|
59
55
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
60
56
|
#endif
|
61
|
-
|
57
|
+
|
62
58
|
context = SDL_GL_CreateContext(shared_window());
|
63
|
-
|
59
|
+
|
64
60
|
if (context == nullptr) {
|
65
61
|
throw_sdl_error("Could not create OpenGL context");
|
66
62
|
}
|
67
63
|
}
|
68
64
|
return context;
|
69
65
|
}
|
70
|
-
|
66
|
+
|
71
67
|
void ensure_current_context()
|
72
68
|
{
|
73
69
|
SDL_GL_MakeCurrent(shared_window(), shared_gl_context());
|
74
70
|
}
|
75
|
-
|
76
|
-
static void cleanup()
|
77
|
-
{
|
78
|
-
SDL_GL_DeleteContext(shared_gl_context());
|
79
|
-
SDL_DestroyWindow(shared_window());
|
80
|
-
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
81
|
-
}
|
82
71
|
}
|
83
72
|
|
84
73
|
struct Gosu::Window::Impl
|
@@ -123,6 +112,8 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen, double up
|
|
123
112
|
|
124
113
|
input().on_button_down = [this](Button button) { button_down(button); };
|
125
114
|
input().on_button_up = [this](Button button) { button_up(button); };
|
115
|
+
input().on_gamepad_connected = [this](int index) { gamepad_connected(index); };
|
116
|
+
input().on_gamepad_disconnected = [this](int index) { gamepad_disconnected(index); };
|
126
117
|
}
|
127
118
|
|
128
119
|
Gosu::Window::~Window()
|
@@ -153,17 +144,17 @@ bool Gosu::Window::resizable() const
|
|
153
144
|
void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
|
154
145
|
{
|
155
146
|
pimpl->fullscreen = fullscreen;
|
156
|
-
|
147
|
+
|
157
148
|
int actual_width = width;
|
158
149
|
int actual_height = height;
|
159
150
|
double scale_factor = 1.0;
|
160
151
|
double black_bar_width = 0;
|
161
152
|
double black_bar_height = 0;
|
162
|
-
|
153
|
+
|
163
154
|
if (fullscreen) {
|
164
155
|
actual_width = Gosu::screen_width(this);
|
165
156
|
actual_height = Gosu::screen_height(this);
|
166
|
-
|
157
|
+
|
167
158
|
if (resizable()) {
|
168
159
|
// Resizable fullscreen windows stubbornly follow the desktop resolution.
|
169
160
|
width = actual_width;
|
@@ -186,7 +177,7 @@ void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
|
|
186
177
|
else {
|
187
178
|
unsigned max_width = Gosu::available_width(this);
|
188
179
|
unsigned max_height = Gosu::available_height(this);
|
189
|
-
|
180
|
+
|
190
181
|
if (resizable()) {
|
191
182
|
// If the window is resizable, limit its size, without preserving the aspect ratio.
|
192
183
|
width = actual_width = min(width, max_width);
|
@@ -199,18 +190,18 @@ void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
|
|
199
190
|
actual_height = height * scale_factor;
|
200
191
|
}
|
201
192
|
}
|
202
|
-
|
193
|
+
|
203
194
|
SDL_SetWindowFullscreen(shared_window(), fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
204
195
|
if (!pimpl->resizing) {
|
205
196
|
SDL_SetWindowSize(shared_window(), actual_width, actual_height);
|
206
197
|
}
|
207
|
-
|
198
|
+
|
208
199
|
#if SDL_VERSION_ATLEAST(2, 0, 1)
|
209
200
|
SDL_GL_GetDrawableSize(shared_window(), &actual_width, &actual_height);
|
210
201
|
#endif
|
211
|
-
|
202
|
+
|
212
203
|
ensure_current_context();
|
213
|
-
|
204
|
+
|
214
205
|
if (!pimpl->graphics) {
|
215
206
|
pimpl->graphics.reset(new Graphics(actual_width, actual_height));
|
216
207
|
}
|
@@ -218,7 +209,7 @@ void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
|
|
218
209
|
pimpl->graphics->set_physical_resolution(actual_width, actual_height);
|
219
210
|
}
|
220
211
|
pimpl->graphics->set_resolution(width, height, black_bar_width, black_bar_height);
|
221
|
-
|
212
|
+
|
222
213
|
if (!pimpl->input) {
|
223
214
|
pimpl->input.reset(new Input(shared_window()));
|
224
215
|
}
|
@@ -250,17 +241,17 @@ void Gosu::Window::set_caption(const string& caption)
|
|
250
241
|
void Gosu::Window::show()
|
251
242
|
{
|
252
243
|
unsigned long time_before_tick = milliseconds();
|
253
|
-
|
244
|
+
|
254
245
|
while (tick()) {
|
255
246
|
// Sleep to keep this loop from eating 100% CPU.
|
256
247
|
unsigned long tick_time = milliseconds() - time_before_tick;
|
257
248
|
if (tick_time < update_interval()) {
|
258
249
|
sleep(update_interval() - tick_time);
|
259
250
|
}
|
260
|
-
|
251
|
+
|
261
252
|
time_before_tick = milliseconds();
|
262
253
|
}
|
263
|
-
|
254
|
+
|
264
255
|
pimpl->state = Impl::CLOSED;
|
265
256
|
}
|
266
257
|
|
@@ -270,7 +261,7 @@ bool Gosu::Window::tick()
|
|
270
261
|
pimpl->state = Impl::CLOSED;
|
271
262
|
return false;
|
272
263
|
}
|
273
|
-
|
264
|
+
|
274
265
|
if (pimpl->state == Impl::CLOSED) {
|
275
266
|
SDL_ShowWindow(shared_window());
|
276
267
|
pimpl->state = Impl::OPEN;
|
@@ -282,7 +273,7 @@ bool Gosu::Window::tick()
|
|
282
273
|
SDL_GL_GetDrawableSize(shared_window(), &width, &height);
|
283
274
|
graphics().set_physical_resolution(width, height);
|
284
275
|
}
|
285
|
-
|
276
|
+
|
286
277
|
SDL_Event e;
|
287
278
|
while (SDL_PollEvent(&e)) {
|
288
279
|
|
@@ -320,29 +311,29 @@ bool Gosu::Window::tick()
|
|
320
311
|
}
|
321
312
|
}
|
322
313
|
}
|
323
|
-
|
314
|
+
|
324
315
|
Song::update();
|
325
|
-
|
316
|
+
|
326
317
|
input().update();
|
327
|
-
|
318
|
+
|
328
319
|
update();
|
329
|
-
|
320
|
+
|
330
321
|
SDL_ShowCursor(needs_cursor());
|
331
|
-
|
322
|
+
|
332
323
|
if (needs_redraw()) {
|
333
324
|
ensure_current_context();
|
334
325
|
graphics().frame([&] {
|
335
326
|
draw();
|
336
327
|
FPS::register_frame();
|
337
328
|
});
|
338
|
-
|
329
|
+
|
339
330
|
SDL_GL_SwapWindow(shared_window());
|
340
331
|
}
|
341
|
-
|
332
|
+
|
342
333
|
if (pimpl->state == Impl::CLOSING) {
|
343
334
|
pimpl->state = Impl::CLOSED;
|
344
335
|
}
|
345
|
-
|
336
|
+
|
346
337
|
return pimpl->state == Impl::OPEN;
|
347
338
|
}
|
348
339
|
|
@@ -357,7 +348,7 @@ void Gosu::Window::button_down(Button button)
|
|
357
348
|
bool toggle_fullscreen;
|
358
349
|
|
359
350
|
// Default shortcuts for toggling fullscreen mode, see: https://github.com/gosu/gosu/issues/361
|
360
|
-
|
351
|
+
|
361
352
|
#ifdef GOSU_IS_MAC
|
362
353
|
// cmd+F and cmd+ctrl+F are both common shortcuts for toggling fullscreen mode on macOS.
|
363
354
|
toggle_fullscreen = button == KB_F &&
|