allegro4r 0.0.1-x86-mswin32-60
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 +59 -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/allegro4r.so +0 -0
- data/ext/extconf.rb +11 -0
- metadata +113 -0
@@ -0,0 +1,155 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* set_gfx_mode(card, w, h, v_w, v_h) -> int
|
6
|
+
*
|
7
|
+
* Switches into graphics mode. The card parameter should usually be one of the
|
8
|
+
* Allegro magic drivers (read introduction of chapter "Graphics modes") or see
|
9
|
+
* the platform specific documentation for a list of the available drivers. The
|
10
|
+
* w and h parameters specify what screen resolution you want. The color depth
|
11
|
+
* of the graphic mode has to be specified before calling this function with
|
12
|
+
* set_color_depth.
|
13
|
+
*
|
14
|
+
* The v_w and v_h parameters specify the minimum virtual screen size, in case
|
15
|
+
* you need a large virtual screen for hardware scrolling or page flipping. You
|
16
|
+
* should set them to zero if you don't care about the virtual screen size.
|
17
|
+
*
|
18
|
+
* When you call set_gfx_mode, the v_w and v_h parameters represent the minimum
|
19
|
+
* size of virtual screen that is acceptable for your program. The range of
|
20
|
+
* possible sizes is usually very restricted, and Allegro may end up creating a
|
21
|
+
* virtual screen much larger than the one you request. Allowed sizes are driver
|
22
|
+
* dependent and some drivers do not allow virtual screens that are larger than
|
23
|
+
* the visible screen at all: don't assume that whatever you pass will always
|
24
|
+
* work.
|
25
|
+
*
|
26
|
+
* In mode-X the virtual width can be any multiple of eight greater than or
|
27
|
+
* equal to the physical screen width, and the virtual height will be set
|
28
|
+
* accordingly (the VGA has 256k of vram, so the virtual height will be
|
29
|
+
* 256*1024/virtual_width).
|
30
|
+
*
|
31
|
+
* Currently, using a big virtual screen for page flipping is considered bad
|
32
|
+
* practice. There are platforms which don't support virtual screens bigger than
|
33
|
+
* the physical screen but can create different video pages to flip back and
|
34
|
+
* forth. This means that, if you want page flipping and aren't going to use
|
35
|
+
* hardware scrolling, you should call set_gfx_mode with (0,0) as the virtual
|
36
|
+
* screen size and later create the different video pages with
|
37
|
+
* create_video_bitmap. Otherwise your program will be limited to the platforms
|
38
|
+
* supporting hardware scrolling.
|
39
|
+
*
|
40
|
+
* After you select a graphics mode, the physical and virtual screen sizes can
|
41
|
+
* be checked with the macros SCREEN_W, SCREEN_H, VIRTUAL_W, and VIRTUAL_H.
|
42
|
+
*
|
43
|
+
* Return value: Returns zero on success. On failure returns a negative number
|
44
|
+
* and stores a description of the problem in allegro_error.
|
45
|
+
*/
|
46
|
+
VALUE a4r_API_set_gfx_mode(VALUE self, VALUE card, VALUE w, VALUE h, VALUE v_w, VALUE v_h)
|
47
|
+
{
|
48
|
+
return INT2FIX(set_gfx_mode(NUM2INT(card), FIX2INT(w), FIX2INT(h), FIX2INT(v_w), FIX2INT(v_h)));
|
49
|
+
}
|
50
|
+
|
51
|
+
/*
|
52
|
+
* call-seq:
|
53
|
+
* set_display_switch_mode(mode) -> int
|
54
|
+
*
|
55
|
+
* Sets how the program should handle being switched into the background, if the
|
56
|
+
* user tabs away from it. Not all of the possible modes will be supported by
|
57
|
+
* every graphics driver on every platform. The available modes are:
|
58
|
+
* SWITCH_NONE::
|
59
|
+
* Disables switching. This is the default in single-tasking systems like DOS.
|
60
|
+
* It may be supported on other platforms, but you should use it with caution,
|
61
|
+
* because your users won't be impressed if they want to switch away from your
|
62
|
+
* program, but you don't let them!
|
63
|
+
* SWITCH_PAUSE::
|
64
|
+
* Pauses the program whenever it is in the background. Execution will be
|
65
|
+
* resumed as soon as the user switches back to it. This is the default in
|
66
|
+
* most fullscreen multitasking environments, for example the Linux console,
|
67
|
+
* but not under Windows.
|
68
|
+
* SWITCH_AMNESIA::
|
69
|
+
* Like SWITCH_PAUSE, but this mode doesn't bother to remember the contents of
|
70
|
+
* video memory, so the screen, and any video bitmaps that you have created,
|
71
|
+
* will be erased after the user switches away and then back to your program.
|
72
|
+
* This is not a terribly useful mode to have, but it is the default for the
|
73
|
+
* fullscreen drivers under Windows because DirectDraw is too dumb to
|
74
|
+
* implement anything better.
|
75
|
+
* SWITCH_BACKGROUND::
|
76
|
+
* The program will carry on running in the background, with the screen bitmap
|
77
|
+
* temporarily being pointed at a memory buffer for the fullscreen drivers.
|
78
|
+
* You must take special care when using this mode, because bad things will
|
79
|
+
* happen if the screen bitmap gets changed around when your program isn't
|
80
|
+
* expecting it (see below).
|
81
|
+
* SWITCH_BACKAMNESIA::
|
82
|
+
* Like SWITCH_BACKGROUND, but this mode doesn't bother to remember the
|
83
|
+
* contents of video memory (see SWITCH_AMNESIA). It is again the only mode
|
84
|
+
* supported by the fullscreen drivers under Windows that lets the program
|
85
|
+
* keep running in the background.
|
86
|
+
*
|
87
|
+
* Note that you should be very careful when you are using graphics routines in
|
88
|
+
* the switching context: you must always call acquire_screen before the start
|
89
|
+
* of any drawing code onto the screen and not release it until you are
|
90
|
+
* completely finished, because the automatic locking mechanism may not be good
|
91
|
+
* enough to work when the program runs in the background or has just been
|
92
|
+
* raised in the foreground.
|
93
|
+
*
|
94
|
+
* Return value: Returns zero on success, invalidating at the same time all
|
95
|
+
* callbacks previously registered with set_display_switch_callback. Returns -1
|
96
|
+
* if the requested mode is not currently possible.
|
97
|
+
*/
|
98
|
+
VALUE a4r_API_set_display_switch_mode(VALUE self, VALUE mode)
|
99
|
+
{
|
100
|
+
return INT2FIX(set_display_switch_mode(FIX2INT(mode)));
|
101
|
+
}
|
102
|
+
|
103
|
+
/*
|
104
|
+
* call-seq:
|
105
|
+
* show_video_bitmap(bitmap) -> int
|
106
|
+
*
|
107
|
+
* Attempts to page flip the hardware screen to display the specified video
|
108
|
+
* bitmap object, which must be the same size as the physical screen, and should
|
109
|
+
* have been obtained by calling the create_video_bitmap function.
|
110
|
+
*
|
111
|
+
* Allegro will handle any necessary vertical retrace synchronisation when page
|
112
|
+
* flipping, so you don't need to call vsync before it. This means that
|
113
|
+
* show_video_bitmap has the same time delay effects as vsync by default. This
|
114
|
+
* can be adjusted with the "disable_vsync" config key in the [graphics] section
|
115
|
+
* of allegro.cfg. Example:
|
116
|
+
* video_page = Array.new
|
117
|
+
* ...
|
118
|
+
* # Create pages for page flipping
|
119
|
+
* video_page[0] = create_video_bitmap(SCREEN_W, SCREEN_H)
|
120
|
+
* video_page[1] = create_video_bitmap(SCREEN_W, SCREEN_H)
|
121
|
+
* current_page = 0
|
122
|
+
* ...
|
123
|
+
* # draw the screen and flip pages
|
124
|
+
* draw_screen(video_page[current_page])
|
125
|
+
* show_video_bitmap(video_page[current_page])
|
126
|
+
* current_page = (current_page + 1) % 2
|
127
|
+
* ...
|
128
|
+
*
|
129
|
+
* Return value: Returns zero on success and non-zero on failure.
|
130
|
+
*/
|
131
|
+
VALUE a4r_API_show_video_bitmap(VALUE self, VALUE bitmap)
|
132
|
+
{
|
133
|
+
BITMAP *bmp;
|
134
|
+
Data_Get_Struct(bitmap, BITMAP, bmp);
|
135
|
+
return INT2FIX(show_video_bitmap(bmp));
|
136
|
+
}
|
137
|
+
|
138
|
+
/*
|
139
|
+
* call-seq:
|
140
|
+
* vsync -> nil
|
141
|
+
*
|
142
|
+
* Waits for a vertical retrace to begin. The retrace happens when the electron
|
143
|
+
* beam in your monitor has reached the bottom of the screen and is moving back
|
144
|
+
* to the top ready for another scan. During this short period the graphics card
|
145
|
+
* isn't sending any data to the monitor, so you can do things to it that aren't
|
146
|
+
* possible at other times, such as altering the palette without causing
|
147
|
+
* flickering (snow). Allegro will automatically wait for a retrace before
|
148
|
+
* altering the palette or doing any hardware scrolling, though, so you don't
|
149
|
+
* normally need to bother with this function.
|
150
|
+
*/
|
151
|
+
VALUE a4r_API_vsync(VALUE self)
|
152
|
+
{
|
153
|
+
vsync();
|
154
|
+
return Qnil;
|
155
|
+
}
|
@@ -0,0 +1,213 @@
|
|
1
|
+
#include "allegro4r.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* install_joystick(type) -> int
|
6
|
+
*
|
7
|
+
* Installs Allegro's joystick handler, and calibrates the centre position
|
8
|
+
* values. The type parameter should usually be JOY_TYPE_AUTODETECT, or see the
|
9
|
+
* platform specific documentation for a list of the available drivers. You must
|
10
|
+
* call this routine before using any other joystick functions, and you should
|
11
|
+
* make sure that all joysticks are in the middle position at the time. Example:
|
12
|
+
* textout_centre_ex(screen, font,
|
13
|
+
* "Center the joystick and press a key",
|
14
|
+
* SCREEN_W()/2, SCREEN_H()/2, red_color, -1)
|
15
|
+
* readkey
|
16
|
+
* if install_joystick(JOY_TYPE_AUTODETECT) != 0
|
17
|
+
* abort_on_error("Error initialising joystick!")
|
18
|
+
* end
|
19
|
+
*
|
20
|
+
* Return value: Returns zero on success. As soon as you have installed the
|
21
|
+
* joystick module, you will be able to read the button state and digital
|
22
|
+
* (on/off toggle) direction information, which may be enough for some games. If
|
23
|
+
* you want to get full analogue input, though, you need to use the
|
24
|
+
* calibrate_joystick functions to measure the exact range of the inputs: see
|
25
|
+
* below.
|
26
|
+
*/
|
27
|
+
VALUE a4r_API_install_joystick(VALUE self, VALUE type)
|
28
|
+
{
|
29
|
+
return INT2FIX(install_joystick(FIX2INT(type)));
|
30
|
+
}
|
31
|
+
|
32
|
+
/*
|
33
|
+
* call-seq:
|
34
|
+
* poll_joystick -> int
|
35
|
+
*
|
36
|
+
* The joystick handler is not interrupt driven, so you need to call this
|
37
|
+
* function every now and again to update the global position values. Example:
|
38
|
+
* loop do
|
39
|
+
* # Get joystick input
|
40
|
+
* poll_joystick
|
41
|
+
*
|
42
|
+
* # Process input for the first joystick
|
43
|
+
* if joy[0].button[0].b
|
44
|
+
* first_button_pressed
|
45
|
+
* end
|
46
|
+
*
|
47
|
+
* if joy[0].button[1].b
|
48
|
+
* second_button_pressed
|
49
|
+
* end
|
50
|
+
* ...
|
51
|
+
* break if done
|
52
|
+
* end
|
53
|
+
*
|
54
|
+
* Return value: Returns zero on success or a negative number on failure
|
55
|
+
* (usually because no joystick driver was installed).
|
56
|
+
*/
|
57
|
+
VALUE a4r_API_poll_joystick(VALUE self)
|
58
|
+
{
|
59
|
+
return INT2FIX(poll_joystick());
|
60
|
+
}
|
61
|
+
|
62
|
+
/*
|
63
|
+
* call-seq:
|
64
|
+
* num_joysticks -> int
|
65
|
+
*
|
66
|
+
* Global variable containing the number of active joystick devices. The current
|
67
|
+
* drivers support a maximum of eight controllers.
|
68
|
+
*/
|
69
|
+
VALUE a4r_API_num_joysticks(VALUE self)
|
70
|
+
{
|
71
|
+
// TODO: Convert to data struct or cached or hooked variable?
|
72
|
+
return INT2FIX(num_joysticks);
|
73
|
+
}
|
74
|
+
|
75
|
+
/*
|
76
|
+
* call-seq:
|
77
|
+
* joy -> ary
|
78
|
+
*
|
79
|
+
* Global array of joystick state information, which is updated by the
|
80
|
+
* poll_joystick function. Only the first num_joysticks elements will contain
|
81
|
+
* meaningful information. Joystick info is described by the JOYSTICK_INFO
|
82
|
+
* class.
|
83
|
+
*
|
84
|
+
* The button status is stored in the JOYSTICK_BUTTON_INFO class.
|
85
|
+
*
|
86
|
+
* You may wish to display the button names as part of an input configuration
|
87
|
+
* screen to let the user choose what game function will be performed by each
|
88
|
+
* button, but in simpler situations you can safely assume that the first two
|
89
|
+
* elements in the button array will always be the main trigger controls.
|
90
|
+
*
|
91
|
+
* Each joystick will provide one or more stick inputs, of varying types. These
|
92
|
+
* can be digital controls which snap to specific positions (eg. a gamepad
|
93
|
+
* controller, the coolie hat on a Flightstick Pro or Wingman Extreme, or a
|
94
|
+
* normal joystick which hasn't yet been calibrated), or they can be full
|
95
|
+
* analogue inputs with a smooth range of motion. Sticks may also have different
|
96
|
+
* numbers of axes, for example a normal directional control has two, but the
|
97
|
+
* Flightstick Pro throttle is only a single axis, and it is possible that the
|
98
|
+
* system could be extended in the future to support full 3d controllers. A
|
99
|
+
* stick input is described by the JOYSTICK_STICK_INFO class.
|
100
|
+
*
|
101
|
+
* A single joystick may provide several different stick inputs, but you can
|
102
|
+
* safely assume that the first element in the stick array will always be the
|
103
|
+
* main directional controller.
|
104
|
+
*
|
105
|
+
* Information about each of the stick axis is stored in the subclass
|
106
|
+
* JOYSTICK_AXIS_INFO.
|
107
|
+
*
|
108
|
+
* This provides both analogue input in the pos field (ranging from -128 to 128
|
109
|
+
* or from 0 to 255, depending on the type of the control), and digital values
|
110
|
+
* in the d1 and d2 fields. For example, when describing the X-axis position,
|
111
|
+
* the pos field will hold the horizontal position of the joystick, d1 will be
|
112
|
+
* set if it is moved left, and d2 will be set if it is moved right. Allegro
|
113
|
+
* will fill in all these values regardless of whether it is using a digital or
|
114
|
+
* analogue joystick, emulating the pos field for digital inputs by snapping it
|
115
|
+
* to the min, middle, and maximum positions, and emulating the d1 and d2 values
|
116
|
+
* for an analogue stick by comparing the current position with the centre
|
117
|
+
* point.
|
118
|
+
*
|
119
|
+
* The joystick flags field may contain any combination of the bit flags:
|
120
|
+
*
|
121
|
+
* JOYFLAG_DIGITAL
|
122
|
+
* This control is currently providing digital input.
|
123
|
+
*
|
124
|
+
* JOYFLAG_ANALOGUE
|
125
|
+
* This control is currently providing analogue input.
|
126
|
+
*
|
127
|
+
* JOYFLAG_CALIB_DIGITAL
|
128
|
+
* This control will be capable of providing digital input once it has been
|
129
|
+
* calibrated, but is not doing this at the moment.
|
130
|
+
*
|
131
|
+
* JOYFLAG_CALIB_ANALOGUE
|
132
|
+
* This control will be capable of providing analogue input once it has been
|
133
|
+
* calibrated, but is not doing this at the moment.
|
134
|
+
*
|
135
|
+
* JOYFLAG_CALIBRATE
|
136
|
+
* Indicates that this control needs to be calibrated. Many devices require
|
137
|
+
* multiple calibration steps, so you should call the calibrate_joystick
|
138
|
+
* function from a loop until this flag is cleared.
|
139
|
+
*
|
140
|
+
* JOYFLAG_SIGNED
|
141
|
+
* Indicates that the analogue axis position is in signed format, ranging from
|
142
|
+
* -128 to 128. This is the case for all 2d directional controls.
|
143
|
+
*
|
144
|
+
* JOYFLAG_UNSIGNED
|
145
|
+
* Indicates that the analogue axis position is in unsigned format, ranging from
|
146
|
+
* 0 to 255. This is the case for all 1d throttle controls.
|
147
|
+
*
|
148
|
+
* Note for people who spell funny: in case you don't like having to type
|
149
|
+
* "analogue", there are some aliases h that will allow you to write "analog"
|
150
|
+
* instead.
|
151
|
+
*/
|
152
|
+
VALUE a4r_API_joy(VALUE self)
|
153
|
+
{
|
154
|
+
VALUE ret = rb_ary_new2(num_joysticks);
|
155
|
+
long x;
|
156
|
+
for (x = 0; x < num_joysticks; x++)
|
157
|
+
{
|
158
|
+
VALUE obj = Data_Wrap_Struct(cAPI_JOYSTICK_INFO, 0, 0, &(joy[x]));
|
159
|
+
rb_ary_store(ret, x, obj);
|
160
|
+
}
|
161
|
+
|
162
|
+
return ret;
|
163
|
+
}
|
164
|
+
|
165
|
+
/*
|
166
|
+
* call-seq:
|
167
|
+
* calibrate_joystick_name(n) -> str
|
168
|
+
*
|
169
|
+
* Pass the number of the joystick you want to calibrate as the parameter.
|
170
|
+
*
|
171
|
+
* Return value: Returns a text description for the next type of calibration
|
172
|
+
* that will be done on the specified joystick, or nil if no more calibration is
|
173
|
+
* required.
|
174
|
+
*/
|
175
|
+
VALUE a4r_API_calibrate_joystick_name(VALUE self, VALUE n)
|
176
|
+
{
|
177
|
+
const char *s = calibrate_joystick_name(FIX2INT(n));
|
178
|
+
if (s == NULL)
|
179
|
+
return Qnil;
|
180
|
+
else
|
181
|
+
return rb_str_new2(s);
|
182
|
+
}
|
183
|
+
|
184
|
+
/*
|
185
|
+
* call-seq:
|
186
|
+
* calibrate_joystick(n) -> int
|
187
|
+
*
|
188
|
+
* Most joysticks need to be calibrated before they can provide full analogue
|
189
|
+
* input. This function performs the next operation in the calibration series
|
190
|
+
* for the specified stick, assuming that the joystick has been positioned in
|
191
|
+
* the manner described by a previous call to calibrate_joystick_name, returning
|
192
|
+
* zero on success. For example, a simple routine to fully calibrate all the
|
193
|
+
* joysticks might look like:
|
194
|
+
* (0...num_joysticks).each do |i|
|
195
|
+
* while joy[i].flags & JOYFLAG_CALIBRATE != 0
|
196
|
+
* msg = calibrate_joystick_name(i)
|
197
|
+
* textprintf_ex(..., "%s, and press a key\n" % msg)
|
198
|
+
* readkey
|
199
|
+
* if calibrate_joystick(i) != 0
|
200
|
+
* textprintf_ex(..., "oops!\n")
|
201
|
+
* readkey
|
202
|
+
* exit 1
|
203
|
+
* end
|
204
|
+
* end
|
205
|
+
* end
|
206
|
+
*
|
207
|
+
* Return value: Returns zero on success, non-zero if the calibration could not
|
208
|
+
* be performed successfully.
|
209
|
+
*/
|
210
|
+
VALUE a4r_API_calibrate_joystick(VALUE self, VALUE n)
|
211
|
+
{
|
212
|
+
return INT2FIX(calibrate_joystick(FIX2INT(n)));
|
213
|
+
}
|