ruby-sdl2 0.3.5 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +4 -1
- data/Gemfile +10 -0
- data/README.md +8 -3
- data/Rakefile +22 -2
- data/Steepfile +24 -0
- data/doc/DEVELOP.md +35 -0
- data/event.c +36 -32
- data/gamecontroller.c +31 -27
- data/gamecontroller.c.m4 +31 -27
- data/gl.c +63 -67
- data/gl.c.m4 +63 -67
- data/hint.c +3 -3
- data/joystick.c +16 -12
- data/joystick.c.m4 +16 -12
- data/key.c +21 -19
- data/key.c.m4 +21 -19
- data/lib/sdl2/version.rb +3 -3
- data/main.c +13 -16
- data/messagebox.c +7 -7
- data/mixer.c +54 -38
- data/mixer.c.m4 +54 -38
- data/mouse.c +3 -3
- data/rbs_collection.yaml +32 -0
- data/rubysdl2_internal.h +12 -1
- data/sample/test_read_pixels.rb +41 -0
- data/ttf.c +20 -17
- data/ttf.c.m4 +20 -17
- data/video.c +262 -143
- data/video.c.m4 +199 -112
- metadata +8 -6
data/mixer.c.m4
CHANGED
|
@@ -27,34 +27,40 @@ typedef struct Music {
|
|
|
27
27
|
|
|
28
28
|
static void Chunk_free(Chunk* c)
|
|
29
29
|
{
|
|
30
|
-
if (rubysdl2_is_active() && c->chunk)
|
|
30
|
+
if (rubysdl2_is_active() && c->chunk)
|
|
31
31
|
Mix_FreeChunk(c->chunk);
|
|
32
32
|
free(c);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
DEFINE_DATA_TYPE(Chunk, Chunk_free);
|
|
36
|
+
|
|
35
37
|
static VALUE Chunk_new(Mix_Chunk* chunk)
|
|
36
38
|
{
|
|
37
|
-
Chunk* c
|
|
39
|
+
Chunk* c;
|
|
40
|
+
VALUE obj = TypedData_Make_Struct(cChunk, Chunk, &Chunk_data_type, c);
|
|
38
41
|
c->chunk = chunk;
|
|
39
|
-
return
|
|
42
|
+
return obj;
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
DEFINE_WRAPPER(Mix_Chunk, Chunk, chunk, cChunk, "SDL2::Mixer::Chunk");
|
|
43
46
|
|
|
44
47
|
static void Music_free(Music* m)
|
|
45
48
|
{
|
|
46
|
-
if (rubysdl2_is_active() && m->music)
|
|
49
|
+
if (rubysdl2_is_active() && m->music)
|
|
47
50
|
Mix_FreeMusic(m->music);
|
|
48
51
|
free(m);
|
|
49
52
|
}
|
|
50
53
|
|
|
54
|
+
DEFINE_DATA_TYPE(Music, Music_free);
|
|
55
|
+
|
|
51
56
|
static VALUE Music_new(Mix_Music* music)
|
|
52
57
|
{
|
|
53
|
-
Music* c
|
|
58
|
+
Music* c;
|
|
59
|
+
VALUE obj = TypedData_Make_Struct(cMusic, Music, &Music_data_type, c);
|
|
54
60
|
c->music = music;
|
|
55
|
-
return
|
|
61
|
+
return obj;
|
|
56
62
|
}
|
|
57
|
-
|
|
63
|
+
|
|
58
64
|
DEFINE_WRAPPER(Mix_Music, Music, music, cMusic, "SDL2::Mixer::Music");
|
|
59
65
|
|
|
60
66
|
/*
|
|
@@ -135,7 +141,7 @@ static void check_channel(VALUE ch, int allow_minus_1)
|
|
|
135
141
|
int channel = NUM2INT(ch);
|
|
136
142
|
if (channel >= Mix_AllocateChannels(-1))
|
|
137
143
|
rb_raise(rb_eArgError, "too large number of channel (%d)", channel);
|
|
138
|
-
if (channel == -1 && !allow_minus_1 || channel < -1)
|
|
144
|
+
if ((channel == -1 && !allow_minus_1) || channel < -1)
|
|
139
145
|
rb_raise(rb_eArgError, "negative number of channel is not allowed");
|
|
140
146
|
}
|
|
141
147
|
|
|
@@ -193,7 +199,7 @@ static VALUE Mixer_s_close(VALUE self)
|
|
|
193
199
|
*
|
|
194
200
|
* This method returns the most suitable setting for {.open} the device.
|
|
195
201
|
*
|
|
196
|
-
* @return [
|
|
202
|
+
* @return [Array(Integer, Integer, Integer, Integer)]
|
|
197
203
|
* the suitable frequency in Hz, the suitable format,
|
|
198
204
|
* the suitable number of channels (1 for mono, 2 for stereo),
|
|
199
205
|
* and the number of call of {.open}.
|
|
@@ -456,6 +462,8 @@ static VALUE Channels_s_fade_out(VALUE self, VALUE channel, VALUE ms)
|
|
|
456
462
|
* Return true if a specified channel is playing.
|
|
457
463
|
*
|
|
458
464
|
* @param channel [Integer] channel to test
|
|
465
|
+
* @return [Boolean]
|
|
466
|
+
*
|
|
459
467
|
* @see .pause?
|
|
460
468
|
* @see .fading
|
|
461
469
|
*/
|
|
@@ -473,6 +481,7 @@ static VALUE Channels_s_play_p(VALUE self, VALUE channel)
|
|
|
473
481
|
* other halting methods.
|
|
474
482
|
*
|
|
475
483
|
* @param channel [Integer] channel to test
|
|
484
|
+
* @return [Boolean]
|
|
476
485
|
*
|
|
477
486
|
* @see .play?
|
|
478
487
|
* @see .fading
|
|
@@ -537,6 +546,8 @@ static VALUE Channels_s_playing_chunk(VALUE self, VALUE channel)
|
|
|
537
546
|
/*
|
|
538
547
|
* Initialize the channel with given **tag**.
|
|
539
548
|
*
|
|
549
|
+
* @param tag [Integer] channel indentifier
|
|
550
|
+
*
|
|
540
551
|
* Groups with a common tag are identified.
|
|
541
552
|
*/
|
|
542
553
|
static VALUE Group_initialize(VALUE self, VALUE tag)
|
|
@@ -575,7 +586,7 @@ inline static int Group_tag(VALUE group)
|
|
|
575
586
|
* **self** and **other** are considered to be same
|
|
576
587
|
* if they have the same tag.
|
|
577
588
|
*
|
|
578
|
-
* @param other [SDL2::Mixer::
|
|
589
|
+
* @param other [SDL2::Mixer::Channels::Group] a compared object
|
|
579
590
|
* @return [Boolean]
|
|
580
591
|
*/
|
|
581
592
|
static VALUE Group_eq(VALUE self, VALUE other)
|
|
@@ -749,7 +760,7 @@ static VALUE MusicChannel_s_volume(VALUE self)
|
|
|
749
760
|
*
|
|
750
761
|
* @param vol [Integer] the volume for mixing,
|
|
751
762
|
* from 0 to {SDL2::Mixer::MAX_VOLUME}(128).
|
|
752
|
-
* @return [
|
|
763
|
+
* @return [void]
|
|
753
764
|
*
|
|
754
765
|
* @see .volume
|
|
755
766
|
*/
|
|
@@ -822,6 +833,7 @@ static VALUE MusicChannel_s_halt(VALUE self)
|
|
|
822
833
|
* @overload fade_out(ms)
|
|
823
834
|
* Halt the music playback with fade-out effect.
|
|
824
835
|
*
|
|
836
|
+
* @param ms [Integer] milliseconds of fade-out effect
|
|
825
837
|
* @return [nil]
|
|
826
838
|
*/
|
|
827
839
|
static VALUE MusicChannel_s_fade_out(VALUE self, VALUE fade_out_ms)
|
|
@@ -831,6 +843,8 @@ static VALUE MusicChannel_s_fade_out(VALUE self, VALUE fade_out_ms)
|
|
|
831
843
|
|
|
832
844
|
/*
|
|
833
845
|
* Return true if a music is playing.
|
|
846
|
+
*
|
|
847
|
+
* @return [Boolean]
|
|
834
848
|
*/
|
|
835
849
|
static VALUE MusicChannel_s_play_p(VALUE self)
|
|
836
850
|
{
|
|
@@ -839,6 +853,8 @@ static VALUE MusicChannel_s_play_p(VALUE self)
|
|
|
839
853
|
|
|
840
854
|
/*
|
|
841
855
|
* Return true if a music playback is paused.
|
|
856
|
+
*
|
|
857
|
+
* @return [Boolean]
|
|
842
858
|
*/
|
|
843
859
|
static VALUE MusicChannel_s_pause_p(VALUE self)
|
|
844
860
|
{
|
|
@@ -960,7 +976,7 @@ static VALUE Chunk_volume(VALUE self)
|
|
|
960
976
|
* Set the volume of the sample.
|
|
961
977
|
*
|
|
962
978
|
* @param vol [Integer] the new volume
|
|
963
|
-
* @return [
|
|
979
|
+
* @return [void]
|
|
964
980
|
*
|
|
965
981
|
* @see #volume
|
|
966
982
|
*/
|
|
@@ -1067,58 +1083,58 @@ void rubysdl2_init_mixer(void)
|
|
|
1067
1083
|
rb_define_module_function(mMixer, "query", Mixer_s_query, 0);
|
|
1068
1084
|
|
|
1069
1085
|
/* define(`DEFINE_MIX_INIT',`rb_define_const(mMixer, "INIT_$1", UINT2NUM(MIX_INIT_$1))') */
|
|
1070
|
-
/*
|
|
1086
|
+
/* @return [Integer] bitmask which means initialization of Ogg flac loader */
|
|
1071
1087
|
DEFINE_MIX_INIT(FLAC);
|
|
1072
|
-
/*
|
|
1088
|
+
/* @return [Integer] bitmask which means initialization of MOD loader */
|
|
1073
1089
|
DEFINE_MIX_INIT(MOD);
|
|
1074
|
-
/*
|
|
1090
|
+
/* @return [Integer] bitmask which means initialization of MP3 loader */
|
|
1075
1091
|
DEFINE_MIX_INIT(MP3);
|
|
1076
|
-
/*
|
|
1092
|
+
/* @return [Integer] bitmask which means initialization of Ogg vorbis loader */
|
|
1077
1093
|
DEFINE_MIX_INIT(OGG);
|
|
1078
1094
|
|
|
1079
|
-
#
|
|
1080
|
-
/*
|
|
1095
|
+
#ifdef HAVE_CONST_MIX_INIT_MODPLUG
|
|
1096
|
+
/* @return [Integer] bitmask which means initialization of libmodplug */
|
|
1081
1097
|
DEFINE_MIX_INIT(MODPLUG);
|
|
1082
1098
|
#endif
|
|
1083
|
-
#
|
|
1084
|
-
/*
|
|
1099
|
+
#ifdef HAVE_CONST_MIX_INIT_FLUIDSYNTH
|
|
1100
|
+
/* @return [Integer] bitmask which means initialization of fluidsynth */
|
|
1085
1101
|
DEFINE_MIX_INIT(FLUIDSYNTH);
|
|
1086
1102
|
#endif
|
|
1087
|
-
#
|
|
1088
|
-
/*
|
|
1103
|
+
#ifdef HAVE_CONST_MIX_INIT_MID
|
|
1104
|
+
/* @return [Integer] bitmask which means initialization of mid */
|
|
1089
1105
|
DEFINE_MIX_INIT(MID);
|
|
1090
1106
|
#endif
|
|
1091
1107
|
|
|
1092
1108
|
/* define(`DEFINE_MIX_FORMAT',`rb_define_const(mMixer, "FORMAT_$1", UINT2NUM(AUDIO_$1))') */
|
|
1093
|
-
/* Unsiged 8-bit sample format. Used by {Mixer.open} */
|
|
1109
|
+
/* @return [Integer] the value representing Unsiged 8-bit sample format. Used by {Mixer.open} */
|
|
1094
1110
|
DEFINE_MIX_FORMAT(U8);
|
|
1095
|
-
/* Siged 8-bit sample format. Used by {Mixer.open} */
|
|
1111
|
+
/* @return [Integer] the value representing Siged 8-bit sample format. Used by {Mixer.open} */
|
|
1096
1112
|
DEFINE_MIX_FORMAT(S8);
|
|
1097
|
-
/* Unsiged 16-bit little-endian sample format. Used by {Mixer.open} */
|
|
1113
|
+
/* @return [Integer] the value representing Unsiged 16-bit little-endian sample format. Used by {Mixer.open} */
|
|
1098
1114
|
DEFINE_MIX_FORMAT(U16LSB);
|
|
1099
|
-
/* Siged 16-bit little-endian sample format. Used by {Mixer.open} */
|
|
1115
|
+
/* @return [Integer] the value representing Siged 16-bit little-endian sample format. Used by {Mixer.open} */
|
|
1100
1116
|
DEFINE_MIX_FORMAT(S16LSB);
|
|
1101
|
-
/* Unsiged 16-bit big-endian sample format. Used by {Mixer.open} */
|
|
1117
|
+
/* @return [Integer] the value representing Unsiged 16-bit big-endian sample format. Used by {Mixer.open} */
|
|
1102
1118
|
DEFINE_MIX_FORMAT(U16MSB);
|
|
1103
|
-
/* Unsiged 16-bit big-endian sample format. Used by {Mixer.open} */
|
|
1119
|
+
/* @return [Integer] the value representing Unsiged 16-bit big-endian sample format. Used by {Mixer.open} */
|
|
1104
1120
|
DEFINE_MIX_FORMAT(S16MSB);
|
|
1105
|
-
/* Unsiged 16-bit sample format. Endian is same as system byte order. Used by {Mixer.open} */
|
|
1121
|
+
/* @return [Integer] the value representing Unsiged 16-bit sample format. Endian is same as system byte order. Used by {Mixer.open} */
|
|
1106
1122
|
DEFINE_MIX_FORMAT(U16SYS);
|
|
1107
|
-
/* Siged 16-bit sample format. Endian is same as system byte order. Used by {Mixer.open} */
|
|
1123
|
+
/* @return [Integer] the value representing Siged 16-bit sample format. Endian is same as system byte order. Used by {Mixer.open} */
|
|
1108
1124
|
DEFINE_MIX_FORMAT(S16SYS);
|
|
1109
|
-
/* Default frequency. 22050 (Hz) */
|
|
1125
|
+
/* @return [Integer] Default frequency. 22050 (Hz) */
|
|
1110
1126
|
rb_define_const(mMixer, "DEFAULT_FREQUENCY", UINT2NUM(MIX_DEFAULT_FREQUENCY));
|
|
1111
|
-
/* Default sample format. Same as {Mixer
|
|
1127
|
+
/* @return [Integer] Default sample format. Same as {Mixer\:\:FORMAT_S16SYS}. */
|
|
1112
1128
|
rb_define_const(mMixer, "DEFAULT_FORMAT", UINT2NUM(MIX_DEFAULT_FORMAT));
|
|
1113
|
-
/* Default number of channels. 2. */
|
|
1129
|
+
/* @return [Integer] Default number of channels. 2. */
|
|
1114
1130
|
rb_define_const(mMixer, "DEFAULT_CHANNELS", INT2FIX(MIX_DEFAULT_CHANNELS));
|
|
1115
|
-
/* Max volume value. 128. */
|
|
1131
|
+
/* @return [Integer] Max volume value. 128. */
|
|
1116
1132
|
rb_define_const(mMixer, "MAX_VOLUME", INT2FIX(MIX_MAX_VOLUME));
|
|
1117
|
-
/*
|
|
1133
|
+
/* @return [Integer] the value represents that the channel is not fading in and fading out. */
|
|
1118
1134
|
rb_define_const(mMixer, "NO_FADING", INT2FIX(MIX_NO_FADING));
|
|
1119
|
-
/*
|
|
1135
|
+
/* @return [Integer] the value represents that the channel is fading out. */
|
|
1120
1136
|
rb_define_const(mMixer, "FADING_OUT", INT2FIX(MIX_FADING_OUT));
|
|
1121
|
-
/*
|
|
1137
|
+
/* @return [Integer] the value represents that the channel is fading in. */
|
|
1122
1138
|
rb_define_const(mMixer, "FADING_IN", INT2FIX(MIX_FADING_IN));
|
|
1123
1139
|
|
|
1124
1140
|
|
|
@@ -1154,7 +1170,7 @@ void rubysdl2_init_mixer(void)
|
|
|
1154
1170
|
rb_define_module_function(mChannels, "pause", Channels_s_pause, 1);
|
|
1155
1171
|
rb_define_module_function(mChannels, "resume", Channels_s_resume, 1);
|
|
1156
1172
|
rb_define_module_function(mChannels, "halt", Channels_s_halt, 1);
|
|
1157
|
-
rb_define_module_function(mChannels, "expire", Channels_s_expire,
|
|
1173
|
+
rb_define_module_function(mChannels, "expire", Channels_s_expire, 2);
|
|
1158
1174
|
rb_define_module_function(mChannels, "fade_out", Channels_s_fade_out, 2);
|
|
1159
1175
|
rb_define_module_function(mChannels, "play?", Channels_s_play_p, 1);
|
|
1160
1176
|
rb_define_module_function(mChannels, "pause?", Channels_s_pause_p, 1);
|
data/mouse.c
CHANGED
|
@@ -192,7 +192,7 @@ static VALUE Cursor_s_shown_p(VALUE self)
|
|
|
192
192
|
* @overload warp(window, x, y)
|
|
193
193
|
* Move the mouse cursor to the given position within the window.
|
|
194
194
|
*
|
|
195
|
-
* @param [
|
|
195
|
+
* @param [SDL2::Window] window the window to move the mouse cursor into
|
|
196
196
|
* @param [Integer] x the x coordinate within the window
|
|
197
197
|
* @param [Integer] y the y coordinate within the window
|
|
198
198
|
* @return [nil]
|
|
@@ -225,7 +225,7 @@ static VALUE Cursor_s_warp_globally(VALUE self, VALUE x, VALUE y)
|
|
|
225
225
|
* Return true a mouse button is pressed.
|
|
226
226
|
*
|
|
227
227
|
* @param [Integer] index the index of a mouse button, start at index 0
|
|
228
|
-
*
|
|
228
|
+
* @return [Boolean]
|
|
229
229
|
*/
|
|
230
230
|
static VALUE State_pressed_p(VALUE self, VALUE index)
|
|
231
231
|
{
|
|
@@ -273,7 +273,7 @@ void rubysdl2_init_mouse(void)
|
|
|
273
273
|
rb_define_singleton_method(cCursor, "shown?", Cursor_s_shown_p, 0);
|
|
274
274
|
rb_define_singleton_method(cCursor, "warp", Cursor_s_warp, 3);
|
|
275
275
|
#if SDL_VERSION_ATLEAST(2,0,4)
|
|
276
|
-
rb_define_singleton_method(cCursor, "warp_globally", Cursor_s_warp_globally,
|
|
276
|
+
rb_define_singleton_method(cCursor, "warp_globally", Cursor_s_warp_globally, 2);
|
|
277
277
|
#endif
|
|
278
278
|
|
|
279
279
|
|
data/rbs_collection.yaml
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Download sources
|
|
2
|
+
sources:
|
|
3
|
+
- type: git
|
|
4
|
+
name: ruby/gem_rbs_collection
|
|
5
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
6
|
+
revision: main
|
|
7
|
+
repo_dir: gems
|
|
8
|
+
|
|
9
|
+
# You can specify local directories as sources also.
|
|
10
|
+
# - type: local
|
|
11
|
+
# path: path/to/your/local/repository
|
|
12
|
+
|
|
13
|
+
# A directory to install the downloaded RBSs
|
|
14
|
+
path: .gem_rbs_collection
|
|
15
|
+
|
|
16
|
+
gems:
|
|
17
|
+
# Skip loading rbs gem's RBS.
|
|
18
|
+
# It's unnecessary if you don't use rbs as a library.
|
|
19
|
+
- name: rbs
|
|
20
|
+
ignore: true
|
|
21
|
+
- name: yard
|
|
22
|
+
ignore: true
|
|
23
|
+
- name: rake
|
|
24
|
+
ignore: true
|
|
25
|
+
- name: sord
|
|
26
|
+
ignore: true
|
|
27
|
+
- name: ast
|
|
28
|
+
ignore: true
|
|
29
|
+
- name: rainbow
|
|
30
|
+
ignore: true
|
|
31
|
+
- name: steep
|
|
32
|
+
ignore: true
|
data/rubysdl2_internal.h
CHANGED
|
@@ -71,6 +71,17 @@ void rubysdl2_init_gamecontorller(void);
|
|
|
71
71
|
#define UCHAR2NUM UINT2NUM
|
|
72
72
|
#define rb_str_export_to_utf8(str) rb_str_export_to_enc((str), rb_utf8_encoding())
|
|
73
73
|
|
|
74
|
+
/* Helper macro to define a rb_data_type_t for TypedData.
|
|
75
|
+
* Usage: DEFINE_DATA_TYPE(struct_name, free_func)
|
|
76
|
+
* Defines: static const rb_data_type_t struct_name##_data_type
|
|
77
|
+
*/
|
|
78
|
+
#define DEFINE_DATA_TYPE(struct_name, free_func) \
|
|
79
|
+
static const rb_data_type_t struct_name##_data_type = { \
|
|
80
|
+
"ruby-sdl2/" #struct_name, \
|
|
81
|
+
{ NULL, (void (*)(void*))(free_func), NULL }, \
|
|
82
|
+
NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY \
|
|
83
|
+
};
|
|
84
|
+
|
|
74
85
|
#define DEFINE_GETTER(scope, ctype, var_class, classname) \
|
|
75
86
|
scope ctype* Get_##ctype(VALUE obj) \
|
|
76
87
|
{ \
|
|
@@ -78,7 +89,7 @@ void rubysdl2_init_gamecontorller(void);
|
|
|
78
89
|
if (!rb_obj_is_kind_of(obj, var_class)) \
|
|
79
90
|
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)", \
|
|
80
91
|
rb_obj_classname(obj), classname); \
|
|
81
|
-
|
|
92
|
+
TypedData_Get_Struct(obj, ctype, &ctype##_data_type, s); \
|
|
82
93
|
\
|
|
83
94
|
return s; \
|
|
84
95
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require "sdl2"
|
|
2
|
+
|
|
3
|
+
SDL2.init(SDL2::INIT_VIDEO|SDL2::INIT_EVENTS)
|
|
4
|
+
|
|
5
|
+
window = SDL2::Window.create("read_pixels",
|
|
6
|
+
SDL2::Window::POS_CENTERED, SDL2::Window::POS_CENTERED,
|
|
7
|
+
320, 240, 0)
|
|
8
|
+
renderer = window.create_renderer(-1, 0)
|
|
9
|
+
|
|
10
|
+
# Draw something
|
|
11
|
+
renderer.draw_color = [0, 128, 255]
|
|
12
|
+
renderer.fill_rect(SDL2::Rect.new(60, 40, 200, 160))
|
|
13
|
+
renderer.draw_color = [255, 255, 0]
|
|
14
|
+
renderer.fill_rect(SDL2::Rect.new(110, 80, 100, 80))
|
|
15
|
+
|
|
16
|
+
# Capture pixels in ARGB8888 format
|
|
17
|
+
pixels = renderer.read_pixels(nil, SDL2::PixelFormat::ARGB8888)
|
|
18
|
+
|
|
19
|
+
renderer.present
|
|
20
|
+
|
|
21
|
+
# Save as BMP
|
|
22
|
+
width, height = 320, 240
|
|
23
|
+
row_size = width * 4
|
|
24
|
+
file_size = 54 + row_size * height
|
|
25
|
+
bmp = String.new(encoding: Encoding::BINARY)
|
|
26
|
+
bmp << ["BM", file_size, 0, 0, 54].pack("A2Vv2V")
|
|
27
|
+
bmp << [40, width, height, 1, 32, 0, 0, 0, 0, 0, 0].pack("VV2v2V6")
|
|
28
|
+
(height - 1).downto(0) {|y| bmp << pixels.byteslice(y * row_size, row_size) }
|
|
29
|
+
File.binwrite("screenshot.bmp", bmp)
|
|
30
|
+
puts "Saved screenshot.bmp (#{File.size("screenshot.bmp")} bytes)"
|
|
31
|
+
|
|
32
|
+
loop do
|
|
33
|
+
while ev = SDL2::Event.poll
|
|
34
|
+
if SDL2::Event::KeyDown === ev && ev.scancode == SDL2::Key::Scan::ESCAPE
|
|
35
|
+
exit
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
renderer.present
|
|
40
|
+
sleep 0.1
|
|
41
|
+
end
|
data/ttf.c
CHANGED
|
@@ -43,11 +43,14 @@ static void TTF_free(TTF* f)
|
|
|
43
43
|
free(f);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
DEFINE_DATA_TYPE(TTF, TTF_free);
|
|
47
|
+
|
|
46
48
|
static VALUE TTF_new(TTF_Font* font)
|
|
47
49
|
{
|
|
48
|
-
TTF* f
|
|
50
|
+
TTF* f;
|
|
51
|
+
VALUE obj = TypedData_Make_Struct(cTTF, TTF, &TTF_data_type, f);
|
|
49
52
|
f->font = font;
|
|
50
|
-
return
|
|
53
|
+
return obj;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
DEFINE_WRAPPER(TTF_Font, TTF, font, cTTF, "SDL2::TTF");
|
|
@@ -76,7 +79,7 @@ DEFINE_WRAPPER(TTF_Font, TTF, font, cTTF, "SDL2::TTF");
|
|
|
76
79
|
*
|
|
77
80
|
* @!attribute kerning
|
|
78
81
|
* True if kerning is enabled.
|
|
79
|
-
* @return [
|
|
82
|
+
* @return [boolean]
|
|
80
83
|
*
|
|
81
84
|
* @!attribute [r] height
|
|
82
85
|
* The maximum pixel height of all glyphs of the font.
|
|
@@ -193,7 +196,7 @@ TTF_ATTR_READER(face_style_name, FaceStyleName, utf8str_new_cstr);
|
|
|
193
196
|
*
|
|
194
197
|
* @param text [String] the string to size up
|
|
195
198
|
*
|
|
196
|
-
* @return [
|
|
199
|
+
* @return [Array(Integer, Integer)] a pair of width and height of the rendered surface
|
|
197
200
|
*
|
|
198
201
|
* @raise [SDL2::Error] It is raised when an error occurs, such as a glyph ins the
|
|
199
202
|
* string not being found.
|
|
@@ -237,7 +240,7 @@ static VALUE render(SDL_Surface* (*renderer)(TTF_Font*, const char*, SDL_Color,
|
|
|
237
240
|
* Solid mode rendering is quick but dirty.
|
|
238
241
|
*
|
|
239
242
|
* @param text [String] the text to render
|
|
240
|
-
* @param fg [
|
|
243
|
+
* @param fg [Array(Integer, Integer, Integer)]
|
|
241
244
|
* the color to render. An array of r, g, and b components.
|
|
242
245
|
*
|
|
243
246
|
* @return [SDL2::Surface]
|
|
@@ -258,9 +261,9 @@ static VALUE TTF_render_solid(VALUE self, VALUE text, VALUE fg)
|
|
|
258
261
|
* the background color.
|
|
259
262
|
*
|
|
260
263
|
* @param text [String] the text to render
|
|
261
|
-
* @param fg [
|
|
264
|
+
* @param fg [Array(Integer, Integer, Integer)]
|
|
262
265
|
* the color to render. An array of r, g, and b components.
|
|
263
|
-
* @param bg [
|
|
266
|
+
* @param bg [Array(Integer, Integer, Integer)]
|
|
264
267
|
* the background color. An array of r, g, and b components.
|
|
265
268
|
*
|
|
266
269
|
* @return [SDL2::Surface]
|
|
@@ -281,7 +284,7 @@ static VALUE TTF_render_shaded(VALUE self, VALUE text, VALUE fg, VALUE bg)
|
|
|
281
284
|
* The rendered surface has an alpha channel,
|
|
282
285
|
*
|
|
283
286
|
* @param text [String] the text to render
|
|
284
|
-
* @param fg [
|
|
287
|
+
* @param fg [Array(Integer, Integer, Integer)]
|
|
285
288
|
* the color to render. An array of r, g, and b components.
|
|
286
289
|
*
|
|
287
290
|
* @return [SDL2::Surface]
|
|
@@ -344,26 +347,26 @@ void rubysdl2_init_ttf(void)
|
|
|
344
347
|
|
|
345
348
|
mStyle = rb_define_module_under(cTTF, "Style");
|
|
346
349
|
/* */
|
|
347
|
-
/* normal style */
|
|
350
|
+
/* @return [Integer] integer representing normal style */
|
|
348
351
|
rb_define_const(mStyle, "NORMAL", INT2NUM((TTF_STYLE_NORMAL)));
|
|
349
|
-
/* bold style */
|
|
352
|
+
/* @return [Integer] integer representing bold style */
|
|
350
353
|
rb_define_const(mStyle, "BOLD", INT2NUM((TTF_STYLE_BOLD)));
|
|
351
|
-
/* italic style */
|
|
354
|
+
/* @return [Integer] integer representing italic style */
|
|
352
355
|
rb_define_const(mStyle, "ITALIC", INT2NUM((TTF_STYLE_ITALIC)));
|
|
353
|
-
/* underline style */
|
|
356
|
+
/* @return [Integer] integer representing underline style */
|
|
354
357
|
rb_define_const(mStyle, "UNDERLINE", INT2NUM((TTF_STYLE_UNDERLINE)));
|
|
355
|
-
/* strikethrough style */
|
|
358
|
+
/* @return [Integer] integer representing strikethrough style */
|
|
356
359
|
rb_define_const(mStyle, "STRIKETHROUGH", INT2NUM((TTF_STYLE_STRIKETHROUGH)));
|
|
357
360
|
|
|
358
361
|
mHinting = rb_define_module_under(cTTF, "Hinting");
|
|
359
362
|
/* */
|
|
360
|
-
/* normal hinting, default */
|
|
363
|
+
/* @return [Integer] integer representing normal hinting, default */
|
|
361
364
|
rb_define_const(mHinting, "NORMAL", INT2NUM((TTF_HINTING_NORMAL)));
|
|
362
|
-
/* lighter hinting for non-monochrome modes */
|
|
365
|
+
/* @return [Integer] integer representing lighter hinting for non-monochrome modes */
|
|
363
366
|
rb_define_const(mHinting, "LIGHT", INT2NUM((TTF_HINTING_LIGHT)));
|
|
364
|
-
/* strong hinting only used for monochrome output */
|
|
367
|
+
/* @return [Integer] integer representing strong hinting, only used for monochrome output */
|
|
365
368
|
rb_define_const(mHinting, "MONO", INT2NUM((TTF_HINTING_MONO)));
|
|
366
|
-
/* no hinting */
|
|
369
|
+
/* @return [Integer] integer representing no hinting */
|
|
367
370
|
rb_define_const(mHinting, "NONE", INT2NUM((TTF_HINTING_NONE)));
|
|
368
371
|
}
|
|
369
372
|
|
data/ttf.c.m4
CHANGED
|
@@ -43,11 +43,14 @@ static void TTF_free(TTF* f)
|
|
|
43
43
|
free(f);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
DEFINE_DATA_TYPE(TTF, TTF_free);
|
|
47
|
+
|
|
46
48
|
static VALUE TTF_new(TTF_Font* font)
|
|
47
49
|
{
|
|
48
|
-
TTF* f
|
|
50
|
+
TTF* f;
|
|
51
|
+
VALUE obj = TypedData_Make_Struct(cTTF, TTF, &TTF_data_type, f);
|
|
49
52
|
f->font = font;
|
|
50
|
-
return
|
|
53
|
+
return obj;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
DEFINE_WRAPPER(TTF_Font, TTF, font, cTTF, "SDL2::TTF");
|
|
@@ -76,7 +79,7 @@ DEFINE_WRAPPER(TTF_Font, TTF, font, cTTF, "SDL2::TTF");
|
|
|
76
79
|
*
|
|
77
80
|
* @!attribute kerning
|
|
78
81
|
* True if kerning is enabled.
|
|
79
|
-
* @return [
|
|
82
|
+
* @return [boolean]
|
|
80
83
|
*
|
|
81
84
|
* @!attribute [r] height
|
|
82
85
|
* The maximum pixel height of all glyphs of the font.
|
|
@@ -193,7 +196,7 @@ TTF_ATTR_READER(face_style_name, FaceStyleName, utf8str_new_cstr);
|
|
|
193
196
|
*
|
|
194
197
|
* @param text [String] the string to size up
|
|
195
198
|
*
|
|
196
|
-
* @return [
|
|
199
|
+
* @return [Array(Integer, Integer)] a pair of width and height of the rendered surface
|
|
197
200
|
*
|
|
198
201
|
* @raise [SDL2::Error] It is raised when an error occurs, such as a glyph ins the
|
|
199
202
|
* string not being found.
|
|
@@ -237,7 +240,7 @@ static VALUE render(SDL_Surface* (*renderer)(TTF_Font*, const char*, SDL_Color,
|
|
|
237
240
|
* Solid mode rendering is quick but dirty.
|
|
238
241
|
*
|
|
239
242
|
* @param text [String] the text to render
|
|
240
|
-
* @param fg [
|
|
243
|
+
* @param fg [Array(Integer, Integer, Integer)]
|
|
241
244
|
* the color to render. An array of r, g, and b components.
|
|
242
245
|
*
|
|
243
246
|
* @return [SDL2::Surface]
|
|
@@ -258,9 +261,9 @@ static VALUE TTF_render_solid(VALUE self, VALUE text, VALUE fg)
|
|
|
258
261
|
* the background color.
|
|
259
262
|
*
|
|
260
263
|
* @param text [String] the text to render
|
|
261
|
-
* @param fg [
|
|
264
|
+
* @param fg [Array(Integer, Integer, Integer)]
|
|
262
265
|
* the color to render. An array of r, g, and b components.
|
|
263
|
-
* @param bg [
|
|
266
|
+
* @param bg [Array(Integer, Integer, Integer)]
|
|
264
267
|
* the background color. An array of r, g, and b components.
|
|
265
268
|
*
|
|
266
269
|
* @return [SDL2::Surface]
|
|
@@ -281,7 +284,7 @@ static VALUE TTF_render_shaded(VALUE self, VALUE text, VALUE fg, VALUE bg)
|
|
|
281
284
|
* The rendered surface has an alpha channel,
|
|
282
285
|
*
|
|
283
286
|
* @param text [String] the text to render
|
|
284
|
-
* @param fg [
|
|
287
|
+
* @param fg [Array(Integer, Integer, Integer)]
|
|
285
288
|
* the color to render. An array of r, g, and b components.
|
|
286
289
|
*
|
|
287
290
|
* @return [SDL2::Surface]
|
|
@@ -344,26 +347,26 @@ void rubysdl2_init_ttf(void)
|
|
|
344
347
|
|
|
345
348
|
mStyle = rb_define_module_under(cTTF, "Style");
|
|
346
349
|
/* define(`DEFINE_TTF_STYLE_CONST',`rb_define_const(mStyle, "$1", INT2NUM((TTF_STYLE_$1)))') */
|
|
347
|
-
/* normal style */
|
|
350
|
+
/* @return [Integer] integer representing normal style */
|
|
348
351
|
DEFINE_TTF_STYLE_CONST(NORMAL);
|
|
349
|
-
/* bold style */
|
|
352
|
+
/* @return [Integer] integer representing bold style */
|
|
350
353
|
DEFINE_TTF_STYLE_CONST(BOLD);
|
|
351
|
-
/* italic style */
|
|
354
|
+
/* @return [Integer] integer representing italic style */
|
|
352
355
|
DEFINE_TTF_STYLE_CONST(ITALIC);
|
|
353
|
-
/* underline style */
|
|
356
|
+
/* @return [Integer] integer representing underline style */
|
|
354
357
|
DEFINE_TTF_STYLE_CONST(UNDERLINE);
|
|
355
|
-
/* strikethrough style */
|
|
358
|
+
/* @return [Integer] integer representing strikethrough style */
|
|
356
359
|
DEFINE_TTF_STYLE_CONST(STRIKETHROUGH);
|
|
357
360
|
|
|
358
361
|
mHinting = rb_define_module_under(cTTF, "Hinting");
|
|
359
362
|
/* define(`DEFINE_TTF_HINTING_CONST',`rb_define_const(mHinting, "$1", INT2NUM((TTF_HINTING_$1)))') */
|
|
360
|
-
/* normal hinting, default */
|
|
363
|
+
/* @return [Integer] integer representing normal hinting, default */
|
|
361
364
|
DEFINE_TTF_HINTING_CONST(NORMAL);
|
|
362
|
-
/* lighter hinting for non-monochrome modes */
|
|
365
|
+
/* @return [Integer] integer representing lighter hinting for non-monochrome modes */
|
|
363
366
|
DEFINE_TTF_HINTING_CONST(LIGHT);
|
|
364
|
-
/* strong hinting only used for monochrome output */
|
|
367
|
+
/* @return [Integer] integer representing strong hinting, only used for monochrome output */
|
|
365
368
|
DEFINE_TTF_HINTING_CONST(MONO);
|
|
366
|
-
/* no hinting */
|
|
369
|
+
/* @return [Integer] integer representing no hinting */
|
|
367
370
|
DEFINE_TTF_HINTING_CONST(NONE);
|
|
368
371
|
}
|
|
369
372
|
|