Module: SDL2
- Defined in:
- main.c,
lib/sdl2/version.rb,
main.c
Overview
Namespace module for Ruby/SDL2.
Defined Under Namespace
Modules: BlendMode, Clipboard, GL, Hints, IMG, Key, MessageBox, Mixer, Mouse, ScreenSaver, TextInput Classes: Display, Error, Event, GameController, Joystick, PixelFormat, Point, Rect, Renderer, Surface, TTF, Texture, Window
Constant Summary collapse
- VERSION =
Returns Version string of Ruby/SDL2.
"0.3.6"- VERSION_NUMBER =
Returns Version of Ruby/SDL2, [major, minor, patch level].
VERSION.split(".").map(&:to_i)
- LIBSDL_VERSION =
Returns SDL’s version string.
libsdl_version()
- LIBSDL_VERSION_NUMBER =
Returns SDL’s version array of numbers.
libsdl_version_number()
- LIBSDL_REVISION =
Returns SDL’s revision (from VCS) string.
libsdl_revision()
- LIBSDL_REVISION_NUMBER =
Deprecated.
Returns always 0.
INT2NUM(0)
- LIBSDL_IMAGE_VERSION =
Returns SDL_image’s version string, only available if SDL_image is linked.
SDL_version_to_String(version)
- LIBSDL_IMAGE_VERSION_NUMBER =
Returns SDL_image’s version array of numbers.
SDL_version_to_Array(version)
- LIBSDL_TTF_VERSION =
Returns SDL_ttf’s version string, only available if SDL_ttf is linked.
SDL_version_to_String(version)
- LIBSDL_TTF_VERSION_NUMBER =
Returns SDL_ttf’s version array of numbers.
SDL_version_to_Array(version)
- LIBSDL_MIXER_VERSION =
Returns SDL_mixer’s version string , only available if SDL_mixer is linked.
SDL_version_to_String(version)
- LIBSDL_MIXER_VERSION_NUMBER =
Returns SDL_mixer’s version array of numbers.
SDL_version_to_Array(version)
Class Method Summary collapse
-
.base_path ⇒ String
Get the directory where the application was run from.
-
.current_video_driver ⇒ String?
Get the name of current video driver.
-
.delay(ms) ⇒ nil
Wait a specified milliseconds.
-
.get_performance_counter ⇒ Integer
Return the current value of the high resolution counter.
-
.get_performance_frequency ⇒ Integer
Return the frequency (count per second) of the high resolution counter.
-
.get_ticks ⇒ Integer
Return the number of milliseconds since SDL2.init is called.
-
.init(flags) ⇒ nil
Initialize SDL.
-
.preference_path(org, app) ⇒ String
Get the “pref dir”.
-
.video_drivers ⇒ Array<String>
Get the names of all video drivers.
-
.video_init(driver_name) ⇒ nil
Initialize the video subsystem, specifying a video driver.
Class Method Details
.base_path ⇒ String
This method is available since SDL 2.0.1.
Get the directory where the application was run from.
In almost all cases, using this method, you will get the directory where ruby executable is in. Probably what you hope is $0 or FILE.
15 16 17 18 19 20 21 22 23 24 |
# File 'filesystem.c', line 15
static VALUE SDL2_s_base_path(VALUE self)
{
char* path = SDL_GetBasePath();
VALUE str;
if (!path)
SDL_ERROR();
str = utf8str_new_cstr(path);
SDL_free(path);
return str;
}
|
.current_video_driver ⇒ String?
Get the name of current video driver
332 333 334 335 336 337 338 339 |
# File 'video.c', line 332
static VALUE SDL2_s_current_video_driver(VALUE self)
{
const char* name = SDL_GetCurrentVideoDriver();
if (name)
return utf8str_new_cstr(name);
else
return Qnil;
}
|
.delay(ms) ⇒ nil
Wait a specified milliseconds.
This function stops all ruby threads. If you want to keep running other threads, you should use Kernel.sleep instead of this function.
15 16 17 18 19 |
# File 'timer.c', line 15
static VALUE SDL_s_delay(VALUE self, VALUE ms)
{
SDL_Delay(NUM2UINT(ms));
return Qnil;
}
|
.get_performance_counter ⇒ Integer
Return the current value of the high resolution counter.
This method is typically used for profiling.
39 40 41 42 |
# File 'timer.c', line 39
static VALUE SDL_s_get_performance_counter(VALUE self)
{
return ULL2NUM(SDL_GetPerformanceCounter());
}
|
.get_performance_frequency ⇒ Integer
Return the frequency (count per second) of the high resolution counter.
50 51 52 53 |
# File 'timer.c', line 50
static VALUE SDL_s_get_performance_frequency(VALUE self)
{
return ULL2NUM(SDL_GetPerformanceFrequency());
}
|
.get_ticks ⇒ Integer
Return the number of milliseconds since init is called.
26 27 28 29 |
# File 'timer.c', line 26
static VALUE SDL_s_get_ticks(VALUE self)
{
return UINT2NUM(SDL_GetTicks());
}
|
.init(flags) ⇒ nil
Initialize SDL. You must call this function before using any other Ruby/SDL2 methods.
You can specify initialized subsystem by flags which is bitwise OR of the following constants:
-
SDL2::INIT_TIMER - timer subsystem
-
SDL2::INIT_AUDIO - audio subsystem
-
SDL2::INIT_VIDEO - video subsystem
-
SDL2::INIT_JOYSTICK - joystick subsystem
-
SDL2::INIT_HAPTIC - haptic (force feedback) subsystem (interface is not implemented yet)
-
SDL2::INIT_GAMECONTROLLER - controller subsystem
-
SDL2::INIT_EVENTS - events subsystem
-
SDL2::INIT_EVERYTHING - all of the above flags
-
SDL2::INIT_NOPARACHUTE - this flag is ignored; for compatibility
116 117 118 119 120 121 122 |
# File 'main.c', line 116
static VALUE SDL2_s_init(VALUE self, VALUE flags)
{
SDL_SetMainReady();
HANDLE_ERROR(SDL_Init(NUM2UINT(flags)));
state = INITIALIZDED;
return Qnil;
}
|
.preference_path(org, app) ⇒ String
43 44 45 46 47 48 49 50 51 52 |
# File 'filesystem.c', line 43
static VALUE SDL2_s_preference_path(VALUE self, VALUE org, VALUE app)
{
char* path = SDL_GetPrefPath(StringValueCStr(org), StringValueCStr(app));
VALUE str;
if (!path)
SDL_ERROR();
str = utf8str_new_cstr(path);
SDL_free(path);
return str;
}
|
.video_drivers ⇒ Array<String>
Get the names of all video drivers.
You can use the name as an argument of video_init.
316 317 318 319 320 321 322 323 324 |
# File 'video.c', line 316
static VALUE SDL2_s_video_drivers(VALUE self)
{
int num_drivers = HANDLE_ERROR(SDL_GetNumVideoDrivers());
int i;
VALUE drivers = rb_ary_new();
for (i=0; i<num_drivers; ++i)
rb_ary_push(drivers, rb_usascii_str_new_cstr(SDL_GetVideoDriver(i)));
return drivers;
}
|
.video_init(driver_name) ⇒ nil
353 354 355 356 357 |
# File 'video.c', line 353
static VALUE SDL2_s_video_init(VALUE self, VALUE driver_name)
{
HANDLE_ERROR(SDL_VideoInit(StringValueCStr(driver_name)));
return Qnil;
}
|