allegro4r 0.0.1-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +59 -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/allegro4r.so +0 -0
  59. data/ext/extconf.rb +11 -0
  60. metadata +113 -0
@@ -0,0 +1,62 @@
1
+ #include "allegro4r.h"
2
+
3
+ /*
4
+ * call-seq:
5
+ * jsi.flags -> int
6
+ *
7
+ * Status flags for this input
8
+ */
9
+ VALUE a4r_API_JOYSTICK_STICK_INFO_flags(VALUE self)
10
+ {
11
+ JOYSTICK_STICK_INFO *jsi;
12
+ Data_Get_Struct(self, JOYSTICK_STICK_INFO, jsi);
13
+ return INT2NUM(jsi->flags);
14
+ }
15
+
16
+ /*
17
+ * call-seq:
18
+ * jsi.num_axis -> int
19
+ *
20
+ * How many axes do we have? (note the misspelling)
21
+ */
22
+ VALUE a4r_API_JOYSTICK_STICK_INFO_num_axis(VALUE self)
23
+ {
24
+ JOYSTICK_STICK_INFO *jsi;
25
+ Data_Get_Struct(self, JOYSTICK_STICK_INFO, jsi);
26
+ return INT2FIX(jsi->num_axis);
27
+ }
28
+
29
+ /*
30
+ * call-seq:
31
+ * jsi.axis -> ary
32
+ *
33
+ * Axis state information
34
+ */
35
+ VALUE a4r_API_JOYSTICK_STICK_INFO_axis(VALUE self)
36
+ {
37
+ JOYSTICK_STICK_INFO *jsi;
38
+ Data_Get_Struct(self, JOYSTICK_STICK_INFO, jsi);
39
+
40
+ VALUE ret = rb_ary_new2(jsi->num_axis);
41
+ long x;
42
+ for (x = 0; x < jsi->num_axis; x++)
43
+ {
44
+ VALUE obj = Data_Wrap_Struct(cAPI_JOYSTICK_AXIS_INFO, 0, 0, &(jsi->axis[x]));
45
+ rb_ary_store(ret, x, obj);
46
+ }
47
+
48
+ return ret;
49
+ }
50
+
51
+ /*
52
+ * call-seq:
53
+ * jsi.name -> str
54
+ *
55
+ * Description of this input
56
+ */
57
+ VALUE a4r_API_JOYSTICK_STICK_INFO_name(VALUE self)
58
+ {
59
+ JOYSTICK_STICK_INFO *jsi;
60
+ Data_Get_Struct(self, JOYSTICK_STICK_INFO, jsi);
61
+ return rb_str_new2(jsi->name);
62
+ }
@@ -0,0 +1,14 @@
1
+ #include "allegro4r.h"
2
+
3
+ /*
4
+ * call-seq:
5
+ * driver.name -> str
6
+ *
7
+ * Returns the name of the keyboard driver.
8
+ */
9
+ VALUE a4r_API_KEYBOARD_DRIVER_name_get(VALUE self)
10
+ {
11
+ KEYBOARD_DRIVER *driver;
12
+ Data_Get_Struct(self, KEYBOARD_DRIVER, driver);
13
+ return rb_str_new2(driver->name);
14
+ }
@@ -0,0 +1,14 @@
1
+ #include "allegro4r.h"
2
+
3
+ /*
4
+ * call-seq:
5
+ * driver.name -> str
6
+ *
7
+ * Driver name
8
+ */
9
+ VALUE a4r_API_MIDI_DRIVER_name_get(VALUE self)
10
+ {
11
+ MIDI_DRIVER *driver;
12
+ Data_Get_Struct(self, MIDI_DRIVER, driver);
13
+ return rb_str_new2(driver->name);
14
+ }
@@ -0,0 +1,14 @@
1
+ #include "allegro4r.h"
2
+
3
+ /*
4
+ * call-seq:
5
+ * driver.name -> str
6
+ *
7
+ * Returns the name of the mouse driver.
8
+ */
9
+ VALUE a4r_API_MOUSE_DRIVER_name_get(VALUE self)
10
+ {
11
+ MOUSE_DRIVER *driver;
12
+ Data_Get_Struct(self, MOUSE_DRIVER, driver);
13
+ return rb_str_new2(driver->name);
14
+ }
@@ -0,0 +1,63 @@
1
+ #include "allegro4r.h"
2
+
3
+ void a4r_API_PALETTE_free(void *palette)
4
+ {
5
+ free((PALETTE*)palette);
6
+ }
7
+
8
+ /* :nodoc: */
9
+ VALUE a4r_API_PALETTE_alloc(VALUE klass)
10
+ {
11
+ PALETTE *palette;
12
+ VALUE obj = Data_Make_Struct(klass, PALETTE, 0, a4r_API_PALETTE_free, palette);
13
+ return obj;
14
+ }
15
+
16
+ /* :nodoc: */
17
+ VALUE a4r_API_PALETTE_initialize_copy(VALUE copy, VALUE orig)
18
+ {
19
+ if (copy == orig)
20
+ return copy;
21
+
22
+ if (TYPE(orig) != T_DATA || RDATA(orig)->dfree != (RUBY_DATA_FUNC)a4r_API_PALETTE_free)
23
+ rb_raise(rb_eTypeError, "wrong argument type");
24
+
25
+ PALETTE *orig_pal, *copy_pal;
26
+ Data_Get_Struct(orig, PALETTE, orig_pal);
27
+ Data_Get_Struct(copy, PALETTE, copy_pal);
28
+ MEMCPY(copy_pal, orig_pal, PALETTE, 1);
29
+ return copy;
30
+ }
31
+
32
+ /*
33
+ * call-seq:
34
+ * palette[index] -> an_rgb
35
+ *
36
+ * Returns the RGB element at the specified index.
37
+ */
38
+ VALUE a4r_API_PALETTE_getter(VALUE self, VALUE index)
39
+ {
40
+ // TODO: Index validation && converting to "array" of RGBs
41
+ PALETTE *palette;
42
+ Data_Get_Struct(self, PALETTE, palette);
43
+ RGB *rgb = &((*palette)[FIX2INT(index)]);
44
+ VALUE obj = Data_Wrap_Struct(cAPI_RGB, 0, 0, rgb);
45
+ return obj;
46
+ }
47
+
48
+ /*
49
+ * call-seq:
50
+ * palette[index] = an_rgb -> an_rgb
51
+ *
52
+ * Sets the element at index to the specified RGB element.
53
+ */
54
+ VALUE a4r_API_PALETTE_setter(VALUE self, VALUE index, VALUE val)
55
+ {
56
+ // TODO: Index validation, val validation && converting to "array" of RGBs
57
+ PALETTE *palette;
58
+ Data_Get_Struct(self, PALETTE, palette);
59
+ RGB *rgb;
60
+ Data_Get_Struct(val, RGB, rgb);
61
+ (*palette)[FIX2INT(index)] = *rgb;
62
+ return val;
63
+ }
data/ext/a4r_API_RGB.c ADDED
@@ -0,0 +1,118 @@
1
+ #include "allegro4r.h"
2
+
3
+ void a4r_API_RGB_free(void *rgb)
4
+ {
5
+ free((RGB*)rgb);
6
+ }
7
+
8
+ /* :nodoc: */
9
+ VALUE a4r_API_RGB_alloc(VALUE klass)
10
+ {
11
+ RGB *rgb;
12
+ VALUE obj = Data_Make_Struct(klass, RGB, 0, a4r_API_RGB_free, rgb);
13
+ return obj;
14
+ }
15
+
16
+ /* :nodoc: */
17
+ VALUE a4r_API_RGB_initialize_copy(VALUE copy, VALUE orig)
18
+ {
19
+ if (copy == orig)
20
+ return copy;
21
+
22
+ // TODO: Bring back this check. We do Data_Wrap_Structs in other places,
23
+ // which is causing this to have two structs with different free methods
24
+ /*
25
+ if (TYPE(orig) != T_DATA || RDATA(orig)->dfree != (RUBY_DATA_FUNC)a4r_API_RGB_free)
26
+ rb_raise(rb_eTypeError, "wrong argument type");
27
+ */
28
+
29
+ RGB *orig_rgb, *copy_rgb;
30
+ Data_Get_Struct(orig, RGB, orig_rgb);
31
+ Data_Get_Struct(copy, RGB, copy_rgb);
32
+ MEMCPY(copy_rgb, orig_rgb, RGB, 1);
33
+ return copy;
34
+ }
35
+
36
+ /*
37
+ * call-seq:
38
+ * rgb.r -> int
39
+ *
40
+ * Returns the red value of the RGB.
41
+ */
42
+ VALUE a4r_API_RGB_r_get(VALUE self)
43
+ {
44
+ RGB *rgb;
45
+ Data_Get_Struct(self, RGB, rgb);
46
+ return CHR2FIX(rgb->r);
47
+ }
48
+
49
+ /*
50
+ * call-seq:
51
+ * rgb.r = int -> int
52
+ *
53
+ * Sets the red value of the RGB. The value must be in the range 0-255.
54
+ */
55
+ VALUE a4r_API_RGB_r_set(VALUE self, VALUE val)
56
+ {
57
+ // TODO: val validation
58
+ RGB *rgb;
59
+ Data_Get_Struct(self, RGB, rgb);
60
+ rgb->r = NUM2CHR(val);
61
+ return val;
62
+ }
63
+
64
+ /*
65
+ * call-seq:
66
+ * rgb.g -> int
67
+ *
68
+ * Returns the green value of the RGB.
69
+ */
70
+ VALUE a4r_API_RGB_g_get(VALUE self)
71
+ {
72
+ RGB *rgb;
73
+ Data_Get_Struct(self, RGB, rgb);
74
+ return CHR2FIX(rgb->g);
75
+ }
76
+
77
+ /*
78
+ * call-seq:
79
+ * rgb.g = int -> int
80
+ *
81
+ * Sets the green value of the RGB. The value must be in the range 0-255.
82
+ */
83
+ VALUE a4r_API_RGB_g_set(VALUE self, VALUE val)
84
+ {
85
+ // TODO: val validation
86
+ RGB *rgb;
87
+ Data_Get_Struct(self, RGB, rgb);
88
+ rgb->g = NUM2CHR(val);
89
+ return val;
90
+ }
91
+
92
+ /*
93
+ * call-seq:
94
+ * rgb.b -> int
95
+ *
96
+ * Returns the blue value of the RGB.
97
+ */
98
+ VALUE a4r_API_RGB_b_get(VALUE self)
99
+ {
100
+ RGB *rgb;
101
+ Data_Get_Struct(self, RGB, rgb);
102
+ return CHR2FIX(rgb->b);
103
+ }
104
+
105
+ /*
106
+ * call-seq:
107
+ * rgb.b = int -> int
108
+ *
109
+ * Sets the blue value of the RGB. The value must be in the range 0-255.
110
+ */
111
+ VALUE a4r_API_RGB_b_set(VALUE self, VALUE val)
112
+ {
113
+ // TODO: val validation
114
+ RGB *rgb;
115
+ Data_Get_Struct(self, RGB, rgb);
116
+ rgb->b = NUM2CHR(val);
117
+ return val;
118
+ }
@@ -0,0 +1,14 @@
1
+ #include "allegro4r.h"
2
+
3
+ /*
4
+ * call-seq:
5
+ * driver.name -> str
6
+ *
7
+ * Returns the name of the timer driver.
8
+ */
9
+ VALUE a4r_API_TIMER_DRIVER_name_get(VALUE self)
10
+ {
11
+ TIMER_DRIVER *driver;
12
+ Data_Get_Struct(self, TIMER_DRIVER, driver);
13
+ return rb_str_new2(driver->name);
14
+ }
@@ -0,0 +1,310 @@
1
+ #include "allegro4r.h"
2
+
3
+ /*
4
+ * call-seq:
5
+ * screen -> a_bmp
6
+ *
7
+ * Global reference to a bitmap, sized VIRTUAL_W x VIRTUAL_H. This is created by
8
+ * set_gfx_mode, and represents the hardware video memory. Only a part of this
9
+ * bitmap will actually be visible, sized SCREEN_W x SCREEN_H. Normally this is
10
+ * the top left corner of the larger virtual screen, so you can ignore the extra
11
+ * invisible virtual size of the bitmap if you aren't interested in hardware
12
+ * scrolling or page flipping. To move the visible window to other parts of the
13
+ * screen bitmap, call scroll_screen. Initially the clipping rectangle will be
14
+ * limited to the physical screen size, so if you want to draw onto a larger
15
+ * virtual screen space outside this rectangle, you will need to adjust the
16
+ * clipping.
17
+ *
18
+ * For example, to draw a pixel onto the screen you would write:
19
+ * putpixel(screen, x, y, color)
20
+ *
21
+ * Or to implement a double-buffered system:
22
+ * # Make a bitmap in RAM.
23
+ * bmp = create_bitmap(320, 200)
24
+ * # Clean the memory bitmap.
25
+ * clear_bitmap(bmp)
26
+ * # Draw onto the memory bitmap.
27
+ * putpixel(bmp, x, y, color)
28
+ * # Copy it to the screen.
29
+ * blit(bmp, screen, 0, 0, 0, 0, 320, 200)
30
+ *
31
+ * Warning: be very careful when using this reference at the same time as any
32
+ * bitmaps created by the create_video_bitmap function (see the description of
33
+ * this function for more detailed information). And never try to destroy it
34
+ * with destroy_bitmap.
35
+ */
36
+ VALUE a4r_API_screen(VALUE self)
37
+ {
38
+ // TODO: Convert to data struct or cached or hooked variable?
39
+ BITMAP *bmp = screen;
40
+ VALUE obj = Data_Wrap_Struct(cAPI_BITMAP, 0, 0, bmp);
41
+ return obj;
42
+ }
43
+
44
+ /*
45
+ * call-seq:
46
+ * SCREEN_W -> int
47
+ *
48
+ * Global defines that return the width and height of the screen, or zero if the
49
+ * screen has not been initialised yet. Example:
50
+ * buf = "\0" * 100
51
+ * uszprintf(buf, buf.length, "The screen size is %d x %d pixels" %
52
+ * [SCREEN_W, SCREEN_H])
53
+ */
54
+ VALUE a4r_API_SCREEN_W(VALUE self)
55
+ {
56
+ // TODO: Convert to hooked or virtual variable?
57
+ return INT2FIX(SCREEN_W);
58
+ }
59
+
60
+ /*
61
+ * call-seq:
62
+ * SCREEN_H -> int
63
+ *
64
+ * See SCREEN_W.
65
+ */
66
+ VALUE a4r_API_SCREEN_H(VALUE self)
67
+ {
68
+ // TODO: Convert to hooked or virtual variable?
69
+ return INT2FIX(SCREEN_H);
70
+ }
71
+
72
+ /*
73
+ * call-seq:
74
+ * create_bitmap(width, height) -> a_bmp or nil
75
+ *
76
+ * Creates a memory bitmap sized width by height. The bitmap will have clipping
77
+ * turned on, and the clipping rectangle set to the full size of the bitmap. The
78
+ * image memory will not be cleared, so it will probably contain garbage: you
79
+ * should clear the bitmap before using it. This routine always uses the global
80
+ * pixel format, as specified by calling set_color_depth. The minimum height of
81
+ * the BITMAP must be 1 and width can't be negative. Example:
82
+ * # Create a 10 pixel tall bitmap, as wide as the screen.
83
+ * bmp = create_bitmap(SCREEN_W, 10)
84
+ * abort_on_error("Couldn't create bitmap!") if bmp.nil?
85
+ * # Use the bitmap.
86
+ * ...
87
+ * # Destroy it when we don't need it any more.
88
+ * destroy_bitmap(bmp)
89
+ *
90
+ * Return value: Returns a reference to the created bitmap, or nil if the bitmap
91
+ * could not be created. Remember to free this bitmap later to avoid memory
92
+ * leaks.
93
+ */
94
+ VALUE a4r_API_create_bitmap(VALUE self, VALUE width, VALUE height)
95
+ {
96
+ // TODO: Change to call destroy_bitmap on free?
97
+ BITMAP *bmp = create_bitmap(FIX2INT(width), FIX2INT(height));
98
+ if (bmp == NULL)
99
+ return Qnil;
100
+ VALUE obj = Data_Wrap_Struct(cAPI_BITMAP, 0, 0, bmp);
101
+ return obj;
102
+ }
103
+
104
+ /*
105
+ * call-seq:
106
+ * create_sub_bitmap(parent, x, y, width, height) -> a_bmp or nil
107
+ *
108
+ * Creates a sub-bitmap, ie. a bitmap sharing drawing memory with a pre-existing
109
+ * bitmap, but possibly with a different size and clipping settings. When
110
+ * creating a sub-bitmap of the mode-X screen, the x position must be a multiple
111
+ * of four. The sub-bitmap width and height can extend beyond the right and
112
+ * bottom edges of the parent (they will be clipped), but the origin point must
113
+ * lie within the parent region.
114
+ *
115
+ * Return value: Returns a reference to the created sub bitmap, or nil if the
116
+ * sub bitmap could not be created. Remember to free the sub bitmap before
117
+ * freeing the parent bitmap to avoid memory leaks and potential crashes
118
+ * accessing memory which has been freed.
119
+ */
120
+ VALUE a4r_API_create_sub_bitmap(VALUE self, VALUE parent, VALUE x, VALUE y, VALUE width, VALUE height)
121
+ {
122
+ BITMAP *bmp;
123
+ Data_Get_Struct(parent, BITMAP, bmp);
124
+ BITMAP *ret = create_sub_bitmap(bmp, FIX2INT(x), FIX2INT(y), FIX2INT(width), FIX2INT(height));
125
+ if (ret == NULL)
126
+ return Qnil;
127
+ VALUE obj = Data_Wrap_Struct(cAPI_BITMAP, 0, 0, ret);
128
+ return obj;
129
+ }
130
+
131
+ /*
132
+ * call-seq:
133
+ * create_video_bitmap(width, height) -> a_bmp or nil
134
+ *
135
+ * Allocates a video memory bitmap of the specified size. This can be used to
136
+ * allocate offscreen video memory for storing source graphics ready for a
137
+ * hardware accelerated blitting operation, or to create multiple video memory
138
+ * pages which can then be displayed by calling show_video_bitmap. Read the
139
+ * introduction of this chapter for a comparison with other types of bitmaps and
140
+ * other specific details.
141
+ *
142
+ * Warning: video memory bitmaps are usually allocated from the same space as
143
+ * the screen bitmap, so they may overlap with it; it is therefore not a good
144
+ * idea to use the global screen at the same time as any surfaces returned by
145
+ * this function.
146
+ *
147
+ * Return value: Returns a reference to the bitmap on success, or nil if you
148
+ * have run out of video ram. Remember to destroy this bitmap before any
149
+ * subsequent call to set_gfx_mode.
150
+ */
151
+ VALUE a4r_API_create_video_bitmap(VALUE self, VALUE width, VALUE height)
152
+ {
153
+ // TODO: Change to call destroy_bitmap on free?
154
+ BITMAP *bmp = create_video_bitmap(FIX2INT(width), FIX2INT(height));
155
+ if (bmp == NULL)
156
+ return Qnil;
157
+ VALUE obj = Data_Wrap_Struct(cAPI_BITMAP, 0, 0, bmp);
158
+ return obj;
159
+ }
160
+
161
+ /*
162
+ * call-seq:
163
+ * destroy_bitmap(bitmap) -> nil
164
+ *
165
+ * Destroys a memory bitmap, sub-bitmap, video memory bitmap, or system bitmap
166
+ * when you are finished with it. If you pass a nil this function won't do
167
+ * anything. See above for the restrictions as to when you are allowed to
168
+ * destroy the various types of bitmaps.
169
+ *
170
+ * The bitmap must not have a mouse cursor shown on it at the time it is
171
+ * destroyed.
172
+ */
173
+ VALUE a4r_API_destroy_bitmap(VALUE self, VALUE bitmap)
174
+ {
175
+ BITMAP *bmp;
176
+ if (bitmap == Qnil)
177
+ bmp = NULL;
178
+ else
179
+ Data_Get_Struct(bitmap, BITMAP, bmp);
180
+ destroy_bitmap(bmp);
181
+ return Qnil;
182
+ }
183
+
184
+ /*
185
+ * call-seq:
186
+ * bitmap_mask_color(bmp) -> int
187
+ *
188
+ * Returns the mask color for the specified bitmap (the value which is skipped
189
+ * when drawing sprites). For 256-color bitmaps this is zero, and for truecolor
190
+ * bitmaps it is bright pink (maximum red and blue, zero green). A frequent use
191
+ * of this function is to clear a bitmap with the mask color so you can later
192
+ * use this bitmap with masked_blit or draw_sprite after drawing other stuff on
193
+ * it. Example:
194
+ * # Replace mask color with another color.
195
+ * (0...bmp.h).each do |y|
196
+ * (0...bmp.w).each do |x|
197
+ * if (getpixel(bmp, x, y) == bitmap_mask_color(bmp))
198
+ * putpixel(bmp, x, y, another_color)
199
+ * end
200
+ * end
201
+ * end
202
+ */
203
+ VALUE a4r_API_bitmap_mask_color(VALUE self, VALUE bmp)
204
+ {
205
+ BITMAP *bitmap;
206
+ Data_Get_Struct(bmp, BITMAP, bitmap);
207
+ return INT2FIX(bitmap_mask_color(bitmap));
208
+ }
209
+
210
+ /*
211
+ * call-seq:
212
+ * acquire_bitmap(bmp) -> nil
213
+ *
214
+ * Acquires the specified video bitmap prior to drawing onto it. You never need
215
+ * to call the function explicitly as it is low level, and will only give you a
216
+ * speed up if you know what you are doing. Using it wrongly may cause slowdown,
217
+ * or even lock up your program.
218
+ *
219
+ * Note: You do never need to use acquire_bitmap on a memory bitmap, i.e. a
220
+ * normal bitmap created with create_bitmap. It will simply do nothing in that
221
+ * case.
222
+ *
223
+ * It still can be useful, because e.g. under the current DirectDraw driver of
224
+ * Allegro, most drawing functions need to lock a video bitmap before drawing to
225
+ * it. But doing this is very slow, so you will get much better performance if
226
+ * you acquire the screen just once at the start of your main redraw function,
227
+ * then call multiple drawing operations which need the bitmap locked, and only
228
+ * release it when done.
229
+ *
230
+ * Multiple acquire calls may be nested, but you must make sure to match up the
231
+ * acquire_bitmap and release_bitmap calls. Be warned that DirectX and X11
232
+ * programs activate a mutex lock whenever a surface is locked, which prevents
233
+ * them from getting any input messages, so you must be sure to release all your
234
+ * bitmaps before using any timer, keyboard, or other non-graphics routines!
235
+ *
236
+ * Note that if you are using hardware accelerated VRAM->VRAM functions, you
237
+ * should not call acquire_bitmap. Such functions need an unlocked target bitmap
238
+ * under DirectX, so there is now just the opposite case from before - if the
239
+ * bitmap is already locked with acquire_bitmap, the drawing operation has to
240
+ * unlock it.
241
+ *
242
+ * Note: For backwards compatibility, the unlocking behavior of such functions
243
+ * is permanent. That is, if you call acquire_bitmap first, then call e.g. an
244
+ * accelerated blit, the DirectX bitmap will be unlocked internally (it won't
245
+ * affect the nesting counter of acquire/release calls).
246
+ *
247
+ * There is no clear cross-platform way in this Allegro version to know which
248
+ * drawing operations need a locked/unlocked state. For example a normal
249
+ * rectfill most probably is accelerated under DirectX, and therefore needs the
250
+ * screen unlocked, but an XOR rectfill, or one with blending activated, most
251
+ * probably is not, and therefore locks the screen. And while the DirectX driver
252
+ * will do automatic unlocking, there is no such thing under X11, where the
253
+ * function is used to synchronize X11 calls from different threads. Your best
254
+ * bet is to never use acquire_bitmap - changes are you are doing something in
255
+ * the wrong way if you think you need it.
256
+ *
257
+ * Warning: This function can be very dangerous to use, since the whole program
258
+ * may get locked while the bitmap is locked. So the lock should only be held
259
+ * for a short time, and you should not call anything but drawing operations
260
+ * onto the locked video bitmap while a lock is in place. Especially don't call
261
+ * things like show_mouse (or scare_mouse which calls that) or readkey, since it
262
+ * will most likely deadlock your entire program.
263
+ */
264
+ VALUE a4r_API_acquire_bitmap(VALUE self, VALUE bmp)
265
+ {
266
+ BITMAP *bitmap;
267
+ Data_Get_Struct(bmp, BITMAP, bitmap);
268
+ acquire_bitmap(bitmap);
269
+ return Qnil;
270
+ }
271
+
272
+ /*
273
+ * call-seq:
274
+ * release_bitmap(bmp) -> nil
275
+ *
276
+ * Releases a bitmap that was previously locked by calling acquire_bitmap. If
277
+ * the bitmap was locked multiple times, you must release it the same number of
278
+ * times before it will truly be unlocked.
279
+ */
280
+ VALUE a4r_API_release_bitmap(VALUE self, VALUE bmp)
281
+ {
282
+ BITMAP *bitmap;
283
+ Data_Get_Struct(bmp, BITMAP, bitmap);
284
+ release_bitmap(bitmap);
285
+ return Qnil;
286
+ }
287
+
288
+ /*
289
+ * call-seq:
290
+ * acquire_screen -> nil
291
+ *
292
+ * Shortcut version of acquire_bitmap(screen)
293
+ */
294
+ VALUE a4r_API_acquire_screen(VALUE self)
295
+ {
296
+ acquire_screen();
297
+ return Qnil;
298
+ }
299
+
300
+ /*
301
+ * call-seq:
302
+ * release_screen -> nil
303
+ *
304
+ * Shortcut version of release_bitmap(screen)
305
+ */
306
+ VALUE a4r_API_release_screen(VALUE self)
307
+ {
308
+ release_screen();
309
+ return Qnil;
310
+ }
@@ -0,0 +1,86 @@
1
+ #include "allegro4r.h"
2
+
3
+ /*
4
+ * call-seq:
5
+ * blit(source, dest, source_x, source_y, dest_x, dest_y, width, height) -> nil
6
+ *
7
+ * Copies a rectangular area of the source bitmap to the destination bitmap. The
8
+ * source_x and source_y parameters are the top left corner of the area to copy
9
+ * from the source bitmap, and dest_x and dest_y are the corresponding position
10
+ * in the destination bitmap. This routine respects the destination clipping
11
+ * rectangle, and it will also clip if you try to blit from areas outside the
12
+ * source bitmap. Example:
13
+ * # Blit src on the screen.
14
+ * blit(bmp, screen, 0, 0, 0, 0, bmp.w, bmp.h)
15
+ *
16
+ * # Now copy a chunk to a corner, slightly outside.
17
+ * blit(screen, screen, 100, 100, -10, -10, 25, 30)
18
+ *
19
+ * You can blit between any parts of any two bitmaps, even if the two memory
20
+ * areas overlap (ie. source and dest are the same, or one is sub-bitmap of the
21
+ * other). You should be aware, however, that a lot of SVGA cards don't provide
22
+ * separate read and write banks, which means that blitting from one part of the
23
+ * screen to another requires the use of a temporary bitmap in memory, and is
24
+ * therefore extremely slow. As a general rule you should avoid blitting from
25
+ * the screen onto itself in SVGA modes.
26
+ *
27
+ * In mode-X, on the other hand, blitting from one part of the screen to another
28
+ * can be significantly faster than blitting from memory onto the screen, as
29
+ * long as the source and destination are correctly aligned with each other.
30
+ * Copying between overlapping screen rectangles is slow, but if the areas
31
+ * don't overlap, and if they have the same plane alignment (ie. (source_x%4) ==
32
+ * (dest_x%4)), the VGA latch registers can be used for a very fast data
33
+ * transfer. To take advantage of this, in mode-X it is often worth storing
34
+ * tile graphics in a hidden area of video memory (using a large virtual
35
+ * screen), and blitting them from there onto the visible part of the screen.
36
+ *
37
+ * If the GFX_HW_VRAM_BLIT bit in the gfx_capabilities flag is set, the current
38
+ * driver supports hardware accelerated blits from one part of the screen onto
39
+ * another. This is extremely fast, so when this flag is set it may be worth
40
+ * storing some of your more frequently used graphics in an offscreen portion of
41
+ * the video memory.
42
+ *
43
+ * Unlike most of the graphics routines, blit allows the source and destination
44
+ * bitmaps to be of different color depths, so it can be used to convert images
45
+ * from one pixel format to another. In this case, the behavior is affected by
46
+ * the COLORCONV_KEEP_TRANS and COLORCONV_DITHER* flags of the current color
47
+ * conversion mode: see set_color_conversion for more information.
48
+ */
49
+ VALUE a4r_API_blit(VALUE self, VALUE source, VALUE dest, VALUE source_x, VALUE source_y, VALUE dest_x, VALUE dest_y, VALUE width, VALUE height)
50
+ {
51
+ BITMAP *bmp_source, *bmp_dest;
52
+ Data_Get_Struct(source, BITMAP, bmp_source);
53
+ Data_Get_Struct(dest, BITMAP, bmp_dest);
54
+ blit(bmp_source, bmp_dest, FIX2INT(source_x), FIX2INT(source_y), FIX2INT(dest_x), FIX2INT(dest_y), FIX2INT(width), FIX2INT(height));
55
+ return Qnil;
56
+ }
57
+
58
+ /*
59
+ * call-seq:
60
+ * masked_blit(source, dest, source_x, source_y, dest_x, dest_y, width, height) -> nil
61
+ *
62
+ * Like blit, but skips transparent pixels, which are marked by a zero in
63
+ * 256-color modes or bright pink for truecolor data (maximum red and blue, zero
64
+ * green), and requires the source and destination bitmaps to be of the same
65
+ * color depth. The source and destination regions must not overlap. Example:
66
+ * # Paint hud overlay on the screen.
67
+ * masked_blit(hud_overlay, screen, 0, 0, 0, 0, hud_overlay.w, hud_overlay.h)
68
+ *
69
+ * If the GFX_HW_VRAM_BLIT_MASKED bit in the gfx_capabilities flag is set, the
70
+ * current driver supports hardware accelerated masked blits from one part of
71
+ * the screen onto another. This is extremely fast, so when this flag is set it
72
+ * may be worth storing some of your more frequently used sprites in an
73
+ * offscreen portion of the video memory.
74
+ *
75
+ * Warning: if the hardware acceleration flag is not set, masked_blit will not
76
+ * work correctly when used with a source image in system or video memory so the
77
+ * latter must be a memory bitmap.
78
+ */
79
+ VALUE a4r_API_masked_blit(VALUE self, VALUE source, VALUE dest, VALUE source_x, VALUE source_y, VALUE dest_x, VALUE dest_y, VALUE width, VALUE height)
80
+ {
81
+ BITMAP *bmp_source, *bmp_dest;
82
+ Data_Get_Struct(source, BITMAP, bmp_source);
83
+ Data_Get_Struct(dest, BITMAP, bmp_dest);
84
+ masked_blit(bmp_source, bmp_dest, FIX2INT(source_x), FIX2INT(source_y), FIX2INT(dest_x), FIX2INT(dest_y), FIX2INT(width), FIX2INT(height));
85
+ return Qnil;
86
+ }