allegro4r 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +58 -0
  3. data/README.txt +94 -0
  4. data/examples/exdbuf.rb +58 -0
  5. data/examples/exfixed.rb +46 -0
  6. data/examples/exflame.rb +200 -0
  7. data/examples/exflip.rb +87 -0
  8. data/examples/exfont.rb +70 -0
  9. data/examples/exhello.rb +46 -0
  10. data/examples/exjoy.rb +206 -0
  11. data/examples/exkeys.rb +216 -0
  12. data/examples/exmem.rb +50 -0
  13. data/examples/exmidi.rb +97 -0
  14. data/examples/exmouse.rb +149 -0
  15. data/examples/expal.rb +70 -0
  16. data/examples/expat.rb +62 -0
  17. data/examples/exsample.rb +89 -0
  18. data/examples/extimer.rb +84 -0
  19. data/examples/unifont.dat +0 -0
  20. data/ext/a4r_API_BITMAP.c +27 -0
  21. data/ext/a4r_API_DIGI_DRIVER.c +14 -0
  22. data/ext/a4r_API_GFX_DRIVER.c +14 -0
  23. data/ext/a4r_API_JOYSTICK_AXIS_INFO.c +53 -0
  24. data/ext/a4r_API_JOYSTICK_BUTTON_INFO.c +27 -0
  25. data/ext/a4r_API_JOYSTICK_DRIVER.c +14 -0
  26. data/ext/a4r_API_JOYSTICK_INFO.c +84 -0
  27. data/ext/a4r_API_JOYSTICK_STICK_INFO.c +62 -0
  28. data/ext/a4r_API_KEYBOARD_DRIVER.c +14 -0
  29. data/ext/a4r_API_MIDI_DRIVER.c +14 -0
  30. data/ext/a4r_API_MOUSE_DRIVER.c +14 -0
  31. data/ext/a4r_API_PALETTE.c +63 -0
  32. data/ext/a4r_API_RGB.c +118 -0
  33. data/ext/a4r_API_TIMER_DRIVER.c +14 -0
  34. data/ext/a4r_API_bitmap_objects.c +310 -0
  35. data/ext/a4r_API_blitting_and_sprites.c +86 -0
  36. data/ext/a4r_API_digital_sample_routines.c +83 -0
  37. data/ext/a4r_API_direct_access_to_video_memory.c +102 -0
  38. data/ext/a4r_API_drawing_primitives.c +114 -0
  39. data/ext/a4r_API_file_and_compression_routines.c +27 -0
  40. data/ext/a4r_API_fixed_point_math_routines.c +98 -0
  41. data/ext/a4r_API_fonts.c +147 -0
  42. data/ext/a4r_API_graphics_modes.c +155 -0
  43. data/ext/a4r_API_joystick_routines.c +213 -0
  44. data/ext/a4r_API_keyboard_routines.c +420 -0
  45. data/ext/a4r_API_misc.c +133 -0
  46. data/ext/a4r_API_mouse_routines.c +220 -0
  47. data/ext/a4r_API_music_routines_midi.c +147 -0
  48. data/ext/a4r_API_palette_routines.c +112 -0
  49. data/ext/a4r_API_sound_init_routines.c +29 -0
  50. data/ext/a4r_API_text_output.c +178 -0
  51. data/ext/a4r_API_timer_routines.c +250 -0
  52. data/ext/a4r_API_transparency_and_patterned_drawing.c +87 -0
  53. data/ext/a4r_API_truecolor_pixel_formats.c +44 -0
  54. data/ext/a4r_API_unicode_routines.c +53 -0
  55. data/ext/a4r_API_using_allegro.c +98 -0
  56. data/ext/allegro4r.c +866 -0
  57. data/ext/allegro4r.h +311 -0
  58. data/ext/extconf.rb +11 -0
  59. metadata +112 -0
@@ -0,0 +1,133 @@
1
+ #include "allegro4r.h"
2
+
3
+ /*
4
+ * call-seq:
5
+ * MIN(x, y) -> num
6
+ *
7
+ */
8
+ VALUE a4r_API_MIN(VALUE self, VALUE x, VALUE y)
9
+ {
10
+ return INT2NUM(MIN(NUM2INT(x), NUM2INT(y)));
11
+ }
12
+
13
+ /*
14
+ * call-seq:
15
+ * ABS(x) -> num
16
+ *
17
+ */
18
+ VALUE a4r_API_ABS(VALUE self, VALUE x)
19
+ {
20
+ return INT2NUM(ABS(NUM2INT(x)));
21
+ }
22
+
23
+ /*
24
+ * call-seq:
25
+ * AL_RAND -> num
26
+ *
27
+ * On platforms that require it, this macro does a simple shift transformation
28
+ * of the libc rand() function, in order to improve the perceived randomness of
29
+ * the output series in the lower 16 bits. Where not required, it directly
30
+ * translates into a rand() call.
31
+ */
32
+ VALUE a4r_API_AL_RAND(VALUE self)
33
+ {
34
+ return INT2NUM(AL_RAND());
35
+ }
36
+
37
+ /*
38
+ * call-seq:
39
+ * gfx_driver -> gfx_driver
40
+ *
41
+ * Global reference to the graphics driver.
42
+ */
43
+ VALUE a4r_API_gfx_driver(VALUE self)
44
+ {
45
+ // TODO: Convert to data struct or cached or hooked variable?
46
+ GFX_DRIVER *driver = gfx_driver;
47
+ VALUE obj = Data_Wrap_Struct(cAPI_GFX_DRIVER, 0, 0, driver);
48
+ return obj;
49
+ }
50
+
51
+ /*
52
+ * call-seq:
53
+ * mouse_driver -> mouse_driver
54
+ *
55
+ * Global reference to the mouse driver.
56
+ */
57
+ VALUE a4r_API_mouse_driver(VALUE self)
58
+ {
59
+ // TODO: Convert to data struct or cached or hooked variable?
60
+ MOUSE_DRIVER *driver = mouse_driver;
61
+ VALUE obj = Data_Wrap_Struct(cAPI_MOUSE_DRIVER, 0, 0, driver);
62
+ return obj;
63
+ }
64
+
65
+ /*
66
+ * call-seq:
67
+ * timer_driver -> timer_driver
68
+ *
69
+ * Global reference to the timer driver.
70
+ */
71
+ VALUE a4r_API_timer_driver(VALUE self)
72
+ {
73
+ // TODO: Convert to data struct or cached or hooked variable?
74
+ TIMER_DRIVER *driver = timer_driver;
75
+ VALUE obj = Data_Wrap_Struct(cAPI_TIMER_DRIVER, 0, 0, driver);
76
+ return obj;
77
+ }
78
+
79
+ /*
80
+ * call-seq:
81
+ * keyboard_driver -> keyboard_driver
82
+ *
83
+ * Global reference to the keyboard driver.
84
+ */
85
+ VALUE a4r_API_keyboard_driver(VALUE self)
86
+ {
87
+ // TODO: Convert to data struct or cached or hooked variable?
88
+ KEYBOARD_DRIVER *driver = keyboard_driver;
89
+ VALUE obj = Data_Wrap_Struct(cAPI_KEYBOARD_DRIVER, 0, 0, driver);
90
+ return obj;
91
+ }
92
+
93
+ /*
94
+ * call-seq:
95
+ * joystick_driver -> joystick_driver
96
+ *
97
+ * Global reference to the joystick driver.
98
+ */
99
+ VALUE a4r_API_joystick_driver(VALUE self)
100
+ {
101
+ // TODO: Convert to data struct or cached or hooked variable?
102
+ JOYSTICK_DRIVER *driver = joystick_driver;
103
+ VALUE obj = Data_Wrap_Struct(cAPI_JOYSTICK_DRIVER, 0, 0, driver);
104
+ return obj;
105
+ }
106
+
107
+ /*
108
+ * call-seq:
109
+ * digi_driver -> digi_driver
110
+ *
111
+ * Global reference to the digital driver.
112
+ */
113
+ VALUE a4r_API_digi_driver(VALUE self)
114
+ {
115
+ // TODO: Convert to data struct or cached or hooked variable?
116
+ DIGI_DRIVER *driver = digi_driver;
117
+ VALUE obj = Data_Wrap_Struct(cAPI_DIGI_DRIVER, 0, 0, driver);
118
+ return obj;
119
+ }
120
+
121
+ /*
122
+ * call-seq:
123
+ * midi_driver -> midi_driver
124
+ *
125
+ * Global reference to the MIDI driver.
126
+ */
127
+ VALUE a4r_API_midi_driver(VALUE self)
128
+ {
129
+ // TODO: Convert to data struct or cached or hooked variable?
130
+ MIDI_DRIVER *driver = midi_driver;
131
+ VALUE obj = Data_Wrap_Struct(cAPI_MIDI_DRIVER, 0, 0, driver);
132
+ return obj;
133
+ }
@@ -0,0 +1,220 @@
1
+ #include "allegro4r.h"
2
+
3
+ /*
4
+ * call-seq:
5
+ * install_mouse -> int
6
+ *
7
+ * Installs the Allegro mouse handler. You must do this before using any other
8
+ * mouse functions.
9
+ *
10
+ * Return value: Returns -1 on failure, zero if the mouse handler is already
11
+ * installed (in which case this function does nothing) and the number of
12
+ * buttons on the mouse if the mouse handler has successfully been installed
13
+ * (ie. this is the first time a handler is installed or you have removed the
14
+ * previous one).
15
+ *
16
+ * Note that the number of mouse buttons returned by this function is more an
17
+ * indication than a physical reality. With most devices there is no way of
18
+ * telling how many buttons there are, and any user can override the number of
19
+ * mouse buttons returned by this function with a custom configuration file and
20
+ * the variable num_buttons. Even if this value is overridden by the user, the
21
+ * global mouse variables will still report whatever the hardware is sending.
22
+ */
23
+ VALUE a4r_API_install_mouse(VALUE self)
24
+ {
25
+ return INT2FIX(install_mouse());
26
+ }
27
+
28
+ /*
29
+ * call-seq:
30
+ * poll_mouse -> int
31
+ *
32
+ * Wherever possible, Allegro will read the mouse input asynchronously (ie. from
33
+ * inside an interrupt handler), but on some platforms that may not be possible,
34
+ * in which case you must call this routine at regular intervals to update the
35
+ * mouse state variables. To help you test your mouse polling code even if you
36
+ * are programming on a platform that doesn't require it, after the first time
37
+ * that you call this function Allegro will switch into polling mode, so from
38
+ * that point onwards you will have to call this routine in order to get any
39
+ * mouse input at all, regardless of whether the current driver actually needs
40
+ * to be polled or not.
41
+ *
42
+ * Return value: Returns zero on success, or a negative number on failure (ie.
43
+ * no mouse driver installed).
44
+ */
45
+ VALUE a4r_API_poll_mouse(VALUE self)
46
+ {
47
+ return INT2FIX(poll_mouse());
48
+ }
49
+
50
+ /*
51
+ * call-seq:
52
+ * mouse_x -> int
53
+ *
54
+ * Global variables containing the current mouse position and button state.
55
+ * Wherever possible these values will be updated asynchronously, but if
56
+ * mouse_needs_poll returns true, you must manually call poll_mouse to update
57
+ * them with the current input state. The 'mouse_x' and 'mouse_y' positions are
58
+ * integers ranging from zero to the bottom right corner of the screen. The
59
+ * 'mouse_z' and 'mouse_w' variables hold the current vertical and horizontal
60
+ * wheel position, when using an input driver that supports wheel mice. The
61
+ * 'mouse_b' variable is a bitfield indicating the state of each button: bit 0
62
+ * is the left button, bit 1 the right, and bit 2 the middle button. Additional
63
+ * non standard mouse buttons might be available as higher bits in this
64
+ * variable. Usage example:
65
+ * printf("Left button is pressed\n") if (mouse_b & 1) > 0
66
+ *
67
+ * printf("Right button is not pressed\n") if (mouse_b & 2) != 0
68
+ *
69
+ * The 'mouse_pos' variable has the current X coordinate in the upper 16 bits
70
+ * and the Y in the lower 16 bits. This may be useful in tight polling loops
71
+ * where a mouse interrupt could occur between your reading of the two separate
72
+ * variables, since you can copy this value into a local variable with a single
73
+ * instruction and then split it up at your leisure. Example:
74
+ * pos = mouse_pos
75
+ * x = pos >> 16
76
+ * y = pos & 0x0000ffff
77
+ */
78
+ VALUE a4r_API_mouse_x(VALUE self)
79
+ {
80
+ return INT2FIX(mouse_x);
81
+ }
82
+
83
+ /*
84
+ * call-seq:
85
+ * mouse_y -> int
86
+ *
87
+ * See mouse_x.
88
+ */
89
+ VALUE a4r_API_mouse_y(VALUE self)
90
+ {
91
+ return INT2FIX(mouse_y);
92
+ }
93
+
94
+ /*
95
+ * call-seq:
96
+ * mouse_z -> int
97
+ *
98
+ * See mouse_x.
99
+ */
100
+ VALUE a4r_API_mouse_z(VALUE self)
101
+ {
102
+ return INT2FIX(mouse_z);
103
+ }
104
+
105
+ /*
106
+ * call-seq:
107
+ * mouse_w -> int
108
+ *
109
+ * See mouse_x.
110
+ */
111
+ VALUE a4r_API_mouse_w(VALUE self)
112
+ {
113
+ return INT2FIX(mouse_w);
114
+ }
115
+
116
+ /*
117
+ * call-seq:
118
+ * mouse_b -> int
119
+ *
120
+ * See mouse_x.
121
+ */
122
+ VALUE a4r_API_mouse_b(VALUE self)
123
+ {
124
+ return INT2FIX(mouse_b);
125
+ }
126
+
127
+ /*
128
+ * call-seq:
129
+ * show_mouse(bmp) -> nil
130
+ *
131
+ * Tells Allegro to display a mouse pointer on the screen. This will only work
132
+ * if the timer module has been installed. The mouse pointer will be drawn onto
133
+ * the specified bitmap, which should normally be 'screen' (see later for
134
+ * information about bitmaps). To hide the mouse pointer, call show_mouse(nil).
135
+ *
136
+ * Warning: if you draw anything onto the screen while the pointer is visible, a
137
+ * mouse movement interrupt could occur in the middle of your drawing operation.
138
+ * If this happens the mouse buffering and graphics drawing code will get
139
+ * confused and will leave 'mouse droppings' all over the screen. To prevent
140
+ * this, you must make sure you turn off the mouse pointer whenever you draw
141
+ * onto the screen. This is not needed if you are using a hardware cursor.
142
+ *
143
+ * Note: you must not be showing a mouse pointer on a bitmap at the time that
144
+ * the bitmap is destroyed with destroy_bitmap, e.g. call show_mouse(nil) before
145
+ * destroying the bitmap. This does not apply to 'screen' since you never
146
+ * destroy 'screen' with destroy_bitmap.
147
+ */
148
+ VALUE a4r_API_show_mouse(VALUE self, VALUE bmp)
149
+ {
150
+ BITMAP *b;
151
+ if (bmp == Qnil)
152
+ b = NULL;
153
+ else
154
+ Data_Get_Struct(bmp, BITMAP, b);
155
+ show_mouse(b);
156
+ return Qnil;
157
+ }
158
+
159
+ /*
160
+ * call_seq:
161
+ * get_mouse_mickeys -> [int_x, int_y]
162
+ *
163
+ * Measures how far the mouse has moved since the last call to this function.
164
+ * The values of mickeyx and mickeyy will become negative if the mouse is moved
165
+ * left or up, respectively. The mouse will continue to generate movement
166
+ * mickeys even when it reaches the edge of the screen, so this form of input
167
+ * can be useful for games that require an infinite range of mouse movement.
168
+ *
169
+ * Note that the infinite movement may not work in windowed mode, since under
170
+ * some platforms the mouse would leave the window, and may not work at all if
171
+ * the hardware cursor is in use.
172
+ *
173
+ * *** The Ruby method signature differs from the Allegro method signature. The
174
+ * Allegro signature take int_x and int_y by reference, but the Ruby signature
175
+ * returns an array containing the values of int_x and int_y.
176
+ */
177
+ VALUE a4r_API_get_mouse_mickeys(VALUE self)
178
+ {
179
+ int x, y;
180
+ get_mouse_mickeys(&x, &y);
181
+ return rb_ary_new3(2, INT2FIX(x), INT2FIX(y));
182
+ }
183
+
184
+ /*
185
+ * call-seq:
186
+ * set_mouse_sprite(bmp) -> nil
187
+ *
188
+ * You don't like Allegro's mouse pointer? No problem. Use this function to
189
+ * supply an alternative of your own. If you change the pointer and then want to
190
+ * get Allegro's lovely arrow back again, call set_mouse_sprite(nil).
191
+ *
192
+ * As a bonus, set_mouse_sprite(nil) uses the current palette in choosing colors
193
+ * for the arrow. So if your arrow mouse sprite looks ugly after changing the
194
+ * palette, call set_mouse_sprite(nil).
195
+ */
196
+ VALUE a4r_API_set_mouse_sprite(VALUE self, VALUE bmp)
197
+ {
198
+ BITMAP *b;
199
+ if (bmp == Qnil)
200
+ b = NULL;
201
+ else
202
+ Data_Get_Struct(bmp, BITMAP, b);
203
+ set_mouse_sprite(b);
204
+ return Qnil;
205
+ }
206
+
207
+ /*
208
+ * call-seq:
209
+ * set_mouse_sprite_focus(x, y) -> nil
210
+ *
211
+ * The mouse focus is the bit of the pointer that represents the actual mouse
212
+ * position, ie. the (mouse_x, mouse_y) position. By default this is the top
213
+ * left corner of the arrow, but if you are using a different mouse pointer you
214
+ * might need to alter it.
215
+ */
216
+ VALUE a4r_API_set_mouse_sprite_focus(VALUE self, VALUE x, VALUE y)
217
+ {
218
+ set_mouse_sprite_focus(FIX2INT(x), FIX2INT(y));
219
+ return Qnil;
220
+ }
@@ -0,0 +1,147 @@
1
+ #include "allegro4r.h"
2
+
3
+ /*
4
+ * call-seq:
5
+ * load_midi(filename) -> a_midi
6
+ *
7
+ * Loads a MIDI file (handles both format 0 and format 1). Example:
8
+ * music = load_midi("backmus.mid")
9
+ * abort_on_error("Couldn't load background music!") if music.nil?
10
+ *
11
+ * Return value: Returns a reference to a MIDI structure, or nil on error.
12
+ * Remember to free this MIDI file later to avoid memory leaks.
13
+ */
14
+ VALUE a4r_API_load_midi(VALUE self, VALUE filename)
15
+ {
16
+ MIDI *m = load_midi(StringValuePtr(filename));
17
+ if (m == NULL)
18
+ return Qnil;
19
+
20
+ VALUE obj = Data_Wrap_Struct(cAPI_MIDI, 0, 0, m);
21
+ return obj;
22
+ }
23
+
24
+ /*
25
+ * call-seq:
26
+ * destroy_midi(midi) -> nil
27
+ *
28
+ * Destroys a MIDI structure when you are done with it. It is safe to call this
29
+ * even when the MIDI file might be playing, because it checks and will kill it
30
+ * off if it is active. Use this to avoid memory leaks in your program.
31
+ */
32
+ VALUE a4r_API_destroy_midi(VALUE self, VALUE midi)
33
+ {
34
+ MIDI *m;
35
+ Data_Get_Struct(midi, MIDI, m);
36
+ destroy_midi(m);
37
+ return Qnil;
38
+ }
39
+
40
+ /*
41
+ * call-seq:
42
+ * play_midi(midi, loop) -> int
43
+ *
44
+ * Starts playing the specified MIDI file, first stopping whatever music was
45
+ * previously playing. If the loop flag is set to true, the data will be
46
+ * repeated until replaced with something else, otherwise it will stop at the
47
+ * end of the file. Passing a nil will stop whatever music is currently playing.
48
+ *
49
+ * Return value: Returns non-zero if an error occurs (this may happen if a
50
+ * patch-caching wavetable driver is unable to load the required samples, or at
51
+ * least it might in the future when somebody writes some patch-caching
52
+ * wavetable drivers :-)
53
+ */
54
+ VALUE a4r_API_play_midi(VALUE self, VALUE midi, VALUE loop)
55
+ {
56
+ MIDI *m;
57
+ if (midi == Qnil)
58
+ m = NULL;
59
+ else
60
+ Data_Get_Struct(midi, MIDI, m);
61
+
62
+ return INT2FIX(play_midi(m, RTEST(loop)));
63
+ }
64
+
65
+ /*
66
+ * call-seq:
67
+ * midi_pause -> nil
68
+ *
69
+ * Pauses the MIDI player.
70
+ */
71
+ VALUE a4r_API_midi_pause(VALUE self)
72
+ {
73
+ midi_pause();
74
+ return Qnil;
75
+ }
76
+
77
+ /*
78
+ * call-seq:
79
+ * midi_resume -> nil
80
+ *
81
+ * Resumes playback of a paused MIDI file.
82
+ */
83
+ VALUE a4r_API_midi_resume(VALUE self)
84
+ {
85
+ midi_resume();
86
+ return Qnil;
87
+ }
88
+
89
+ /*
90
+ * call-seq:
91
+ * get_midi_length(midi) -> int
92
+ *
93
+ * This function will simulate playing the given MIDI, from start to end, to
94
+ * determine how long it takes to play. After calling this function, midi_pos
95
+ * will contain the negative number of beats, and midi_time the length of the
96
+ * midi, in seconds.
97
+ *
98
+ * Note that any currently playing midi is stopped when you call this function.
99
+ * Usually you would call it before play_midi, to get the length of the midi to
100
+ * be played, like in this example:
101
+ * length = get_midi_length(my_midi)
102
+ * play_midi(my_midi)
103
+ * loop do
104
+ * pos = midi_time
105
+ * textprintf_ex(screen, font, 0, 0, c, -1, "%d:%02d / %d:%02d\n" %
106
+ * [pos / 60, pos % 60, length / 60, length % 60])
107
+ * rest(100)
108
+ * break unless pos <= length
109
+ * end
110
+ *
111
+ * Return value: Returns the value of midi_time, the length of the midi.
112
+ */
113
+ VALUE a4r_API_get_midi_length(VALUE self, VALUE midi)
114
+ {
115
+ MIDI *m;
116
+ Data_Get_Struct(midi, MIDI, m);
117
+ return INT2FIX(get_midi_length(m));
118
+ }
119
+
120
+ /*
121
+ * call-seq:
122
+ * midi_pos -> int
123
+ *
124
+ * Stores the current position (beat number) in the MIDI file, or contains a
125
+ * negative number if no music is currently playing. Useful for synchronising
126
+ * animations with the music, and for checking whether a MIDI file has finished
127
+ * playing.
128
+ */
129
+ VALUE a4r_API_midi_pos(VALUE self)
130
+ {
131
+ // TODO: Convert to data struct or cached or hooked variable?
132
+ return LONG2FIX(midi_pos);
133
+ }
134
+
135
+ /*
136
+ * call-seq:
137
+ * midi_time -> int
138
+ *
139
+ * Contains the position in seconds in the currently playing midi. This is
140
+ * useful if you want to display the current song position in seconds, not as
141
+ * beat number.
142
+ */
143
+ VALUE a4r_API_midi_time(VALUE self)
144
+ {
145
+ // TODO: Convert to data struct or cached or hooked variable?
146
+ return LONG2FIX(midi_time);
147
+ }