allegro4r 0.0.1
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.
- data/History.txt +4 -0
- data/Manifest.txt +58 -0
- data/README.txt +94 -0
- data/examples/exdbuf.rb +58 -0
- data/examples/exfixed.rb +46 -0
- data/examples/exflame.rb +200 -0
- data/examples/exflip.rb +87 -0
- data/examples/exfont.rb +70 -0
- data/examples/exhello.rb +46 -0
- data/examples/exjoy.rb +206 -0
- data/examples/exkeys.rb +216 -0
- data/examples/exmem.rb +50 -0
- data/examples/exmidi.rb +97 -0
- data/examples/exmouse.rb +149 -0
- data/examples/expal.rb +70 -0
- data/examples/expat.rb +62 -0
- data/examples/exsample.rb +89 -0
- data/examples/extimer.rb +84 -0
- data/examples/unifont.dat +0 -0
- data/ext/a4r_API_BITMAP.c +27 -0
- data/ext/a4r_API_DIGI_DRIVER.c +14 -0
- data/ext/a4r_API_GFX_DRIVER.c +14 -0
- data/ext/a4r_API_JOYSTICK_AXIS_INFO.c +53 -0
- data/ext/a4r_API_JOYSTICK_BUTTON_INFO.c +27 -0
- data/ext/a4r_API_JOYSTICK_DRIVER.c +14 -0
- data/ext/a4r_API_JOYSTICK_INFO.c +84 -0
- data/ext/a4r_API_JOYSTICK_STICK_INFO.c +62 -0
- data/ext/a4r_API_KEYBOARD_DRIVER.c +14 -0
- data/ext/a4r_API_MIDI_DRIVER.c +14 -0
- data/ext/a4r_API_MOUSE_DRIVER.c +14 -0
- data/ext/a4r_API_PALETTE.c +63 -0
- data/ext/a4r_API_RGB.c +118 -0
- data/ext/a4r_API_TIMER_DRIVER.c +14 -0
- data/ext/a4r_API_bitmap_objects.c +310 -0
- data/ext/a4r_API_blitting_and_sprites.c +86 -0
- data/ext/a4r_API_digital_sample_routines.c +83 -0
- data/ext/a4r_API_direct_access_to_video_memory.c +102 -0
- data/ext/a4r_API_drawing_primitives.c +114 -0
- data/ext/a4r_API_file_and_compression_routines.c +27 -0
- data/ext/a4r_API_fixed_point_math_routines.c +98 -0
- data/ext/a4r_API_fonts.c +147 -0
- data/ext/a4r_API_graphics_modes.c +155 -0
- data/ext/a4r_API_joystick_routines.c +213 -0
- data/ext/a4r_API_keyboard_routines.c +420 -0
- data/ext/a4r_API_misc.c +133 -0
- data/ext/a4r_API_mouse_routines.c +220 -0
- data/ext/a4r_API_music_routines_midi.c +147 -0
- data/ext/a4r_API_palette_routines.c +112 -0
- data/ext/a4r_API_sound_init_routines.c +29 -0
- data/ext/a4r_API_text_output.c +178 -0
- data/ext/a4r_API_timer_routines.c +250 -0
- data/ext/a4r_API_transparency_and_patterned_drawing.c +87 -0
- data/ext/a4r_API_truecolor_pixel_formats.c +44 -0
- data/ext/a4r_API_unicode_routines.c +53 -0
- data/ext/a4r_API_using_allegro.c +98 -0
- data/ext/allegro4r.c +866 -0
- data/ext/allegro4r.h +311 -0
- data/ext/extconf.rb +11 -0
- metadata +112 -0
data/examples/extimer.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
#
|
2
|
+
# Example program (C Version) for the Allegro library, by Shawn Hargreaves.
|
3
|
+
# (Ruby port by Jason Frey)
|
4
|
+
#
|
5
|
+
# This program demonstrates how to use the timer routines.
|
6
|
+
# These can be a bit of a pain, because you have to be sure
|
7
|
+
# you lock all the memory that is used inside your interrupt
|
8
|
+
# handlers. The first part of the example shows a basic use of
|
9
|
+
# timing using the blocking function rest(). The second part
|
10
|
+
# shows how to use three timers with different frequencies in
|
11
|
+
# a non blocking way.
|
12
|
+
#
|
13
|
+
# JF - Counters based on timer interrupts cannot be done directly though Ruby,
|
14
|
+
# so instead, we can use predefined timer counters. They can be installed by
|
15
|
+
# name with install_int or install_int_ex. The values can be retrieved through
|
16
|
+
# timer_counter_get.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'rubygems'
|
20
|
+
require 'allegro4r'
|
21
|
+
include Allegro4r::API
|
22
|
+
|
23
|
+
exit 1 if allegro_init != 0
|
24
|
+
install_keyboard
|
25
|
+
install_timer
|
26
|
+
|
27
|
+
if set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0
|
28
|
+
if set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0
|
29
|
+
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0)
|
30
|
+
allegro_message("Unable to set any graphic mode\n%s\n" % allegro_error)
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
set_palette(desktop_palette)
|
36
|
+
clear_to_color(screen, makecol(255, 255, 255))
|
37
|
+
|
38
|
+
textprintf_centre_ex(screen, font, SCREEN_W()/2, 8, makecol(0, 0, 0), makecol(255, 255, 255), "Driver: %s" % timer_driver.name)
|
39
|
+
|
40
|
+
# use rest to delay for a specified number of milliseconds
|
41
|
+
textprintf_centre_ex(screen, font, SCREEN_W()/2, 48, makecol(0, 0, 0), makecol(255, 255, 255), "Timing five seconds:")
|
42
|
+
|
43
|
+
(1..5).each do |c|
|
44
|
+
textprintf_centre_ex(screen, font, SCREEN_W()/2, 62 + c * 10, makecol(0, 0, 0), makecol(255, 255, 255), "%d" % c)
|
45
|
+
rest(1000)
|
46
|
+
end
|
47
|
+
|
48
|
+
textprintf_centre_ex(screen, font, SCREEN_W()/2, 142, makecol(0, 0, 0), makecol(255, 255, 255), "Press a key to set up interrupts")
|
49
|
+
readkey
|
50
|
+
|
51
|
+
# JF - Since we are using predefined timer routines, LOCK_VARIABLE and
|
52
|
+
# LOCK_FUNCTION do nothing, and are here simply for API consistency. They will
|
53
|
+
# raise warnings if the Ruby script is run with -w.
|
54
|
+
|
55
|
+
# all variables and code used inside interrupt handlers must be locked
|
56
|
+
LOCK_VARIABLE(:x)
|
57
|
+
LOCK_VARIABLE(:y)
|
58
|
+
LOCK_VARIABLE(:z)
|
59
|
+
LOCK_FUNCTION(:inc_x)
|
60
|
+
LOCK_FUNCTION(:inc_y)
|
61
|
+
LOCK_FUNCTION(:inc_z)
|
62
|
+
|
63
|
+
# JF - install_int and install_int_ex take a name as their first parameter
|
64
|
+
# which can then be used to subsequent calls to timer_counter_get.
|
65
|
+
|
66
|
+
# the speed can be specified in milliseconds (this is once a second)
|
67
|
+
install_int(:inc_x, 1000)
|
68
|
+
|
69
|
+
# or in beats per second (this is 10 ticks a second)
|
70
|
+
install_int_ex(:inc_y, BPS_TO_TIMER(10))
|
71
|
+
|
72
|
+
# or in seconds (this is 10 seconds a tick)
|
73
|
+
install_int_ex(:inc_z, SECS_TO_TIMER(10))
|
74
|
+
|
75
|
+
# the interrupts are now active...
|
76
|
+
while !keypressed
|
77
|
+
# JF - Get the values from the timer interrupt counters with
|
78
|
+
# timer_counter_get
|
79
|
+
x = timer_counter_get(:inc_x)
|
80
|
+
y = timer_counter_get(:inc_y)
|
81
|
+
z = timer_counter_get(:inc_z)
|
82
|
+
|
83
|
+
textprintf_centre_ex(screen, font, SCREEN_W()/2, 176, makecol(0, 0, 0), makecol(255, 255, 255), "x=%d, y=%d, z=%d" % [x, y, z])
|
84
|
+
end
|
Binary file
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* bmp.h -> int
|
6
|
+
*
|
7
|
+
* Returns the height of the BITMAP in pixels.
|
8
|
+
*/
|
9
|
+
VALUE a4r_API_BITMAP_h_get(VALUE self)
|
10
|
+
{
|
11
|
+
BITMAP *bitmap;
|
12
|
+
Data_Get_Struct(self, BITMAP, bitmap);
|
13
|
+
return INT2FIX(bitmap->h);
|
14
|
+
}
|
15
|
+
|
16
|
+
/*
|
17
|
+
* call-seq:
|
18
|
+
* bmp.w -> int
|
19
|
+
*
|
20
|
+
* Returns the width of the BITMAP in pixels.
|
21
|
+
*/
|
22
|
+
VALUE a4r_API_BITMAP_w_get(VALUE self)
|
23
|
+
{
|
24
|
+
BITMAP *bitmap;
|
25
|
+
Data_Get_Struct(self, BITMAP, bitmap);
|
26
|
+
return INT2FIX(bitmap->w);
|
27
|
+
}
|
@@ -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_DIGI_DRIVER_name_get(VALUE self)
|
10
|
+
{
|
11
|
+
DIGI_DRIVER *driver;
|
12
|
+
Data_Get_Struct(self, DIGI_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 graphics driver.
|
8
|
+
*/
|
9
|
+
VALUE a4r_API_GFX_DRIVER_name_get(VALUE self)
|
10
|
+
{
|
11
|
+
GFX_DRIVER *driver;
|
12
|
+
Data_Get_Struct(self, GFX_DRIVER, driver);
|
13
|
+
return rb_str_new2(driver->name);
|
14
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* jai.pos -> int
|
6
|
+
*
|
7
|
+
* Analogue axis position
|
8
|
+
*/
|
9
|
+
VALUE a4r_API_JOYSTICK_AXIS_INFO_pos(VALUE self)
|
10
|
+
{
|
11
|
+
JOYSTICK_AXIS_INFO *jai;
|
12
|
+
Data_Get_Struct(self, JOYSTICK_AXIS_INFO, jai);
|
13
|
+
return INT2FIX(jai->pos);
|
14
|
+
}
|
15
|
+
|
16
|
+
/*
|
17
|
+
* call-seq:
|
18
|
+
* jai.d1 -> true or false
|
19
|
+
*
|
20
|
+
* Digital axis position
|
21
|
+
*/
|
22
|
+
VALUE a4r_API_JOYSTICK_AXIS_INFO_d1(VALUE self)
|
23
|
+
{
|
24
|
+
JOYSTICK_AXIS_INFO *jai;
|
25
|
+
Data_Get_Struct(self, JOYSTICK_AXIS_INFO, jai);
|
26
|
+
return jai->d1 ? Qtrue : Qfalse;
|
27
|
+
}
|
28
|
+
|
29
|
+
/*
|
30
|
+
* call-seq:
|
31
|
+
* jai.d2 -> true or false
|
32
|
+
*
|
33
|
+
* Digital axis position
|
34
|
+
*/
|
35
|
+
VALUE a4r_API_JOYSTICK_AXIS_INFO_d2(VALUE self)
|
36
|
+
{
|
37
|
+
JOYSTICK_AXIS_INFO *jai;
|
38
|
+
Data_Get_Struct(self, JOYSTICK_AXIS_INFO, jai);
|
39
|
+
return jai->d2 ? Qtrue : Qfalse;
|
40
|
+
}
|
41
|
+
|
42
|
+
/*
|
43
|
+
* call-seq:
|
44
|
+
* jai.name -> int
|
45
|
+
*
|
46
|
+
* Description of this axis
|
47
|
+
*/
|
48
|
+
VALUE a4r_API_JOYSTICK_AXIS_INFO_name(VALUE self)
|
49
|
+
{
|
50
|
+
JOYSTICK_AXIS_INFO *jai;
|
51
|
+
Data_Get_Struct(self, JOYSTICK_AXIS_INFO, jai);
|
52
|
+
return rb_str_new2(jai->name);
|
53
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* jbi.b -> true or false
|
6
|
+
*
|
7
|
+
* Boolean on/off flag
|
8
|
+
*/
|
9
|
+
VALUE a4r_API_JOYSTICK_BUTTON_INFO_b(VALUE self)
|
10
|
+
{
|
11
|
+
JOYSTICK_BUTTON_INFO *jbi;
|
12
|
+
Data_Get_Struct(self, JOYSTICK_BUTTON_INFO, jbi);
|
13
|
+
return jbi->b ? Qtrue : Qfalse;
|
14
|
+
}
|
15
|
+
|
16
|
+
/*
|
17
|
+
* call-seq:
|
18
|
+
* jbi.name -> str
|
19
|
+
*
|
20
|
+
* Description of this button
|
21
|
+
*/
|
22
|
+
VALUE a4r_API_JOYSTICK_BUTTON_INFO_name(VALUE self)
|
23
|
+
{
|
24
|
+
JOYSTICK_BUTTON_INFO *jbi;
|
25
|
+
Data_Get_Struct(self, JOYSTICK_BUTTON_INFO, jbi);
|
26
|
+
return rb_str_new2(jbi->name);
|
27
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* driver.name -> str
|
6
|
+
*
|
7
|
+
* Returns the name of the joystick driver.
|
8
|
+
*/
|
9
|
+
VALUE a4r_API_JOYSTICK_DRIVER_name_get(VALUE self)
|
10
|
+
{
|
11
|
+
JOYSTICK_DRIVER *driver;
|
12
|
+
Data_Get_Struct(self, JOYSTICK_DRIVER, driver);
|
13
|
+
return rb_str_new2(driver->name);
|
14
|
+
}
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* ji.flags -> int
|
6
|
+
*
|
7
|
+
* Status flags for this joystick
|
8
|
+
*/
|
9
|
+
VALUE a4r_API_JOYSTICK_INFO_flags(VALUE self)
|
10
|
+
{
|
11
|
+
JOYSTICK_INFO *ji;
|
12
|
+
Data_Get_Struct(self, JOYSTICK_INFO, ji);
|
13
|
+
return INT2NUM(ji->flags);
|
14
|
+
}
|
15
|
+
|
16
|
+
/*
|
17
|
+
* call-seq:
|
18
|
+
* ji.num_sticks -> int
|
19
|
+
*
|
20
|
+
* How many stick inputs?
|
21
|
+
*/
|
22
|
+
VALUE a4r_API_JOYSTICK_INFO_num_sticks(VALUE self)
|
23
|
+
{
|
24
|
+
JOYSTICK_INFO *ji;
|
25
|
+
Data_Get_Struct(self, JOYSTICK_INFO, ji);
|
26
|
+
return INT2FIX(ji->num_sticks);
|
27
|
+
}
|
28
|
+
|
29
|
+
/*
|
30
|
+
* call-seq:
|
31
|
+
* ji.num_buttons -> int
|
32
|
+
*
|
33
|
+
* How many buttons?
|
34
|
+
*/
|
35
|
+
VALUE a4r_API_JOYSTICK_INFO_num_buttons(VALUE self)
|
36
|
+
{
|
37
|
+
JOYSTICK_INFO *ji;
|
38
|
+
Data_Get_Struct(self, JOYSTICK_INFO, ji);
|
39
|
+
return INT2FIX(ji->num_buttons);
|
40
|
+
}
|
41
|
+
|
42
|
+
/*
|
43
|
+
* call-seq:
|
44
|
+
* ji.stick -> ary
|
45
|
+
*
|
46
|
+
* Stick state information
|
47
|
+
*/
|
48
|
+
VALUE a4r_API_JOYSTICK_INFO_stick(VALUE self)
|
49
|
+
{
|
50
|
+
JOYSTICK_INFO *ji;
|
51
|
+
Data_Get_Struct(self, JOYSTICK_INFO, ji);
|
52
|
+
|
53
|
+
VALUE ret = rb_ary_new2(ji->num_sticks);
|
54
|
+
long x;
|
55
|
+
for (x = 0; x < ji->num_sticks; x++)
|
56
|
+
{
|
57
|
+
VALUE obj = Data_Wrap_Struct(cAPI_JOYSTICK_STICK_INFO, 0, 0, &(ji->stick[x]));
|
58
|
+
rb_ary_store(ret, x, obj);
|
59
|
+
}
|
60
|
+
|
61
|
+
return ret;
|
62
|
+
}
|
63
|
+
|
64
|
+
/*
|
65
|
+
* call-seq:
|
66
|
+
* ji.button -> ary
|
67
|
+
*
|
68
|
+
* Button state information
|
69
|
+
*/
|
70
|
+
VALUE a4r_API_JOYSTICK_INFO_button(VALUE self)
|
71
|
+
{
|
72
|
+
JOYSTICK_INFO *ji;
|
73
|
+
Data_Get_Struct(self, JOYSTICK_INFO, ji);
|
74
|
+
|
75
|
+
VALUE ret = rb_ary_new2(ji->num_buttons);
|
76
|
+
long x;
|
77
|
+
for (x = 0; x < ji->num_buttons; x++)
|
78
|
+
{
|
79
|
+
VALUE obj = Data_Wrap_Struct(cAPI_JOYSTICK_BUTTON_INFO, 0, 0, &(ji->button[x]));
|
80
|
+
rb_ary_store(ret, x, obj);
|
81
|
+
}
|
82
|
+
|
83
|
+
return ret;
|
84
|
+
}
|
@@ -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
|
+
}
|