Module: SDL2

Extended by:
FFI::Library
Defined in:
lib/sdl2.rb,
lib/sdl2/log.rb,
lib/sdl2/ttf.rb,
lib/sdl2/init.rb,
lib/sdl2/rect.rb,
lib/sdl2/audio.rb,
lib/sdl2/color.rb,
lib/sdl2/error.rb,
lib/sdl2/hints.rb,
lib/sdl2/image.rb,
lib/sdl2/mouse.rb,
lib/sdl2/point.rb,
lib/sdl2/power.rb,
lib/sdl2/rwops.rb,
lib/sdl2/syswm.rb,
lib/sdl2/timer.rb,
lib/sdl2/touch.rb,
lib/sdl2/video.rb,
lib/sdl2/assert.rb,
lib/sdl2/events.rb,
lib/sdl2/haptic.rb,
lib/sdl2/pixels.rb,
lib/sdl2/render.rb,
lib/sdl2/window.rb,
lib/sdl2/cpuinfo.rb,
lib/sdl2/display.rb,
lib/sdl2/gesture.rb,
lib/sdl2/keycode.rb,
lib/sdl2/palette.rb,
lib/sdl2/surface.rb,
lib/sdl2/texture.rb,
lib/sdl2/version.rb,
lib/sdl2/joystick.rb,
lib/sdl2/keyboard.rb,
lib/sdl2/renderer.rb,
lib/sdl2/scancode.rb,
lib/sdl2/clipboard.rb,
lib/sdl2/syswm/msg.rb,
lib/sdl2/sdl_module.rb,
lib/sdl2/syswm/info.rb,
lib/sdl2/gem_version.rb,
lib/sdl2/display/mode.rb,
lib/sdl2/pixel_format.rb,
lib/sdl2/display/modes.rb,
lib/sdl2/renderer_info.rb,
lib/sdl2/gamecontroller.rb,
lib/sdl2/ttf/sdl_ttf_module.rb,
lib/sdl2/image/sdl_image_module.rb

Overview

SDL_syswm.h

Defined Under Namespace

Modules: Audio, Clipboard, Image, Mouse, SysWM, TTF Classes: BlendModeStruct, Color, CommonEvent, ControllerAxisEvent, ControllerButtonEvent, ControllerDeviceEvent, Cursor, Display, DollarGestureEvent, DropEvent, Event, EventFilterStruct, Finger, FloatPointer, GameController, Haptic, Hint, IntStruct, JoyAxisEvent, JoyBallEvent, JoyButtonEvent, JoyDeviceEvent, JoyHatEvent, Joystick, JoystickGUID, KeyboardEvent, Keysym, Log, ManagedStruct, MouseButtonEvent, MouseMotionEvent, MouseWheelEvent, MultiGestureEvent, OSEvent, Palette, PixelFormat, Point, QuitEvent, RWops, Rect, Renderer, RendererInfo, Struct, Surface, SysWMEvent, TextEditingEvent, TextInputEvent, Texture, TouchFingerEvent, TypedPointer, UInt16Struct, UInt32Struct, UInt8Struct, UserEvent, Version, Window, WindowEvent

Constant Summary collapse

TRUE_WHEN_ZERO =

Filter Proc, True when arg equals zero

Proc.new do |result|
  result == 0
end
TRUE_WHEN_NOT_NULL =

Filter Proc, True when arg not null?

Proc.new do |result|
  (!result.null?)
end
INIT_TIMER =

SDL Constants, for OR’ing them

0x00000001
INIT_AUDIO =
0x00000010
INIT_VIDEO =
0x00000020
INIT_JOYSTICK =
0x00000200
INIT_HAPTIC =
0x00001000
INIT_GAMECONTROLLER =
0x00002000
INIT_EVENTS =
0x00004000
INIT_NOPARACHUTE =
0x00100000
INIT_EVERYTHING =
INIT_TIMER | INIT_AUDIO | INIT_VIDEO |
INIT_EVENTS | INIT_JOYSTICK | INIT_HAPTIC |
INIT_GAMECONTROLLER
MIX_MAXVOLUME =
128
Colour =

Because SDL does it

Color
HINT_FRAMEBUFFER_ACCELERATION =
"SDL_FRAMEBUFFER_ACCELERATION"
HINT_RENDER_DRIVER =
"SDL_RENDER_DRIVER"
HINT_RENDER_OPENGL_SHADERS =
"SDL_RENDER_OPENGL_SHADERS"
HINT_RENDER_SCALE_QUALITY =
"SDL_RENDER_SCALE_QUALITY"
HINT_RENDER_VSYNC =
"SDL_RENDER_VSYNC"
HINT_VIDEO_X11_XVIDMODE =
"SDL_VIDEO_X11_XVIDMODE"
HINT_VIDEO_X11_XINERAMA =
"SDL_VIDEO_X11_XINERAMA"
HINT_VIDEO_X11_XRANDR =
"SDL_VIDEO_X11_XRANDR"
HINT_GRAB_KEYBOARD =
"SDL_GRAB_KEYBOARD"
HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS =
"SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS"
HINT_IDLE_TIMER_DISABLED =
"SDL_IOS_IDLE_TIMER_DISABLED"
HINT_ORIENTATIONS =
"SDL_IOS_ORIENTATIONS"
HINT_XINPUT_ENABLED =
"SDL_XINPUT_ENABLED"
HINT_GAMECONTROLLERCONFIG =
"SDL_GAMECONTROLLERCONFIG"
HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS =
"SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS"
HINT_ALLOW_TOPMOST =
"SDL_ALLOW_TOPMOST"
HINT_TIMER_RESOLUTION =
"SDL_TIMER_RESOLUTION"
IMG =

Alias to follow IMG_xxx convention

Image
Powerstate =
enum :powerstate, [:UNKOWN, :ON_BATTERY, :NO_BATTERY, :CHARGING, :CHARGED]
SYSWM =

Because I don’t care about case.

SysWM
TOUCH_MOUSEID =
-1
RELEASED =
0
PRESSED =
1
COMMON_EVENT_LAYOUT =
[:type, :uint32, :timestamp, :uint32]
QUERY =
-1
IGNORE =
0
DISABLE =
0
ENABLE =
1
ALPHA_OPAQUE =
255
ALPHA_TRANSPARENT =
0
PIXELTYPE =
Enum.new :PIXELTYPE, {
  UNKNOWN: 0,
  INDEX1: 1,
  INDEX4: 2,
  INDEX8: 3,
  PACKED8: 4,
  PACKED16: 5,
  PACKED32: 6,
  ARRAYU8: 7,
  ARRAYU16: 8,
  ARRAYU32: 9,
  ARRAYF16: 10,
  ARRAYF32: 11
}
BITMAPORDER =
Enum.new :BITMAPORDER, {
  NONE: 0,
  _4321: 1,
  _1234: 2
}
PACKEDORDER =
Enum.new :PACKEDORDER, {
  NONE: 0,
  XRGB: 1,
  RGBX: 2,
  ARGB: 3,
  RGBA: 4,
  XBGR: 5,
  BGRX: 6,
  ABGR: 7,
  BGRA: 8
}
ARRAYORDER =
Enum.new :ARRAYORDER, {
  NONE: 0,
  RGB: 1,
  RGBA: 2,
  ARGB: 3,
  BGR: 4,
  BGRA: 5,
  ABGR: 6
}
PACKEDLAYOUT =
Enum.new :PACKEDLAYOUT, {
  NONE: 0,
  _332: 1,
  _4444: 2,
  _1555: 3,
  _5551: 4,
  _565: 5,
  _8888: 6,
  _2101010: 7,
  _1010102: 8
}
PIXELFORMAT =
Enum.new(:PIXELFORMAT, {
  UNKNOWN: 0,
  INDEX1LSB:
  define_pixelformat(PIXELTYPE.INDEX1, BITMAPORDER._4321, 0,
  1, 0),
  INDEX1MSB:
  define_pixelformat(PIXELTYPE.INDEX1, BITMAPORDER._1234, 0,
  1, 0),
  INDEX4LSB:
  define_pixelformat(PIXELTYPE.INDEX4, BITMAPORDER._4321, 0,
  4, 0),
  INDEX4MSB:
  define_pixelformat(PIXELTYPE.INDEX4, BITMAPORDER._1234, 0,
  4, 0),
  INDEX8:
  define_pixelformat(PIXELTYPE.INDEX8, 0, 0, 8, 1),
  RGB332:
  define_pixelformat(PIXELTYPE.PACKED8, PACKEDORDER.XRGB,
  PACKEDLAYOUT._332, 8, 1),
  RGB444:
  define_pixelformat(PIXELTYPE.PACKED16, PACKEDORDER.XRGB,
  PACKEDLAYOUT._4444, 12, 2),
  RGB555:
  define_pixelformat(PIXELTYPE.PACKED16, PACKEDORDER.XRGB,
  PACKEDLAYOUT._1555, 15, 2),
  BGR555:
  define_pixelformat(PIXELTYPE.PACKED16, PACKEDORDER.XBGR,
  PACKEDLAYOUT._1555, 15, 2),
  ARGB4444:
  define_pixelformat(PIXELTYPE.PACKED16, PACKEDORDER.ARGB,
  PACKEDLAYOUT._4444, 16, 2),
  RGBA4444:
  define_pixelformat(PIXELTYPE.PACKED16, PACKEDORDER.RGBA,
  PACKEDLAYOUT._4444, 16, 2),
  ABGR4444:
  define_pixelformat(PIXELTYPE.PACKED16, PACKEDORDER.ABGR,
  PACKEDLAYOUT._4444, 16, 2),
  BGRA4444:
  define_pixelformat(PIXELTYPE.PACKED16, PACKEDORDER.BGRA,
  PACKEDLAYOUT._4444, 16, 2),
  ARGB1555:
  define_pixelformat(PIXELTYPE.PACKED16, PACKEDORDER.ARGB,
  PACKEDLAYOUT._1555, 16, 2),
  RGBA5551:
  define_pixelformat(PIXELTYPE.PACKED16, PACKEDORDER.RGBA,
  PACKEDLAYOUT._5551, 16, 2),
  ABGR1555:
  define_pixelformat(PIXELTYPE.PACKED16, PACKEDORDER.ABGR,
  PACKEDLAYOUT._1555, 16, 2),
  BGRA5551:
  define_pixelformat(PIXELTYPE.PACKED16, PACKEDORDER.BGRA,
  PACKEDLAYOUT._5551, 16, 2),
  RGB565:
  define_pixelformat(PIXELTYPE.PACKED16, PACKEDORDER.XRGB,
  PACKEDLAYOUT._565, 16, 2),
  BGR565:
  define_pixelformat(PIXELTYPE.PACKED16, PACKEDORDER.XBGR,
  PACKEDLAYOUT._565, 16, 2),
  RGB24:
  define_pixelformat(PIXELTYPE.ARRAYU8, ARRAYORDER.RGB, 0,
  24, 3),
  BGR24:
  define_pixelformat(PIXELTYPE.ARRAYU8, ARRAYORDER.BGR, 0,
  24, 3),
  RGB888:
  define_pixelformat(PIXELTYPE.PACKED32, PACKEDORDER.XRGB,
  PACKEDLAYOUT._8888, 24, 4),
  RGBX8888:
  define_pixelformat(PIXELTYPE.PACKED32, PACKEDORDER.RGBX,
  PACKEDLAYOUT._8888, 24, 4),
  BGR888:
  define_pixelformat(PIXELTYPE.PACKED32, PACKEDORDER.XBGR,
  PACKEDLAYOUT._8888, 24, 4),
  BGRX8888:
  define_pixelformat(PIXELTYPE.PACKED32, PACKEDORDER.BGRX,
  PACKEDLAYOUT._8888, 24, 4),
  ARGB8888:
  define_pixelformat(PIXELTYPE.PACKED32, PACKEDORDER.ARGB,
  PACKEDLAYOUT._8888, 32, 4),
  RGBA8888:
  define_pixelformat(PIXELTYPE.PACKED32, PACKEDORDER.RGBA,
  PACKEDLAYOUT._8888, 32, 4),
  ABGR8888:
  define_pixelformat(PIXELTYPE.PACKED32, PACKEDORDER.ABGR,
  PACKEDLAYOUT._8888, 32, 4),
  BGRA8888:
  define_pixelformat(PIXELTYPE.PACKED32, PACKEDORDER.BGRA,
  PACKEDLAYOUT._8888, 32, 4),
  ARGB2101010:
  define_pixelformat(PIXELTYPE.PACKED32, PACKEDORDER.ARGB,
  PACKEDLAYOUT._2101010, 32, 4),

  YV12:
  define_pixelfourcc('Y', 'V', '1', '2'),
  IYUV:
  define_pixelfourcc('I', 'Y', 'U', 'V'),
  YUY2:
  define_pixelfourcc('Y', 'U', 'Y', '2'),
  UYVY:
  define_pixelfourcc('U', 'Y', 'V', 'Y'),
  YVYU:
  define_pixelfourcc('Y', 'V', 'Y', 'U')
})
CACHELINE_SIZE =
128
SCANCODE_MASK =

TODO: Review if I translated lines 44~45 right.

1<<30
Keycode =
Enum.new(:KEYCODE, {
  :UNKNOWN => 0,

  :RETURN => '\r',
  :ESCAPE => '\033',
  :BACKSPACE => '\b',
  :TAB => '\t',
  :SPACE => ' ',
  :EXCLAIM => '!',
  :QUOTEDBL => '"',
  :HASH => '#',
  :PERCENT => '%',
  :DOLLAR => '$',
  :AMPERSAND => '&',
  :QUOTE => '\'',
  :LEFTPAREN => '(',
  :RIGHTPAREN => ')',
  :ASTERISK => '*',
  :PLUS => '+',
  :COMMA => ',',
  :MINUS => '-',
  :PERIOD => '.',
  :SLASH => '/',
  :'0' => '0',
  :'1' => '1',
  :'2' => '2',
  :'3' => '3',
  :'4' => '4',
  :'5' => '5',
  :'6' => '6',
  :'7' => '7',
  :'8' => '8',
  :'9' => '9',
  :COLON => ':',
  :SEMICOLON => ';',
  :LESS => '<',
  :EQUALS => '=',
  :GREATER => '>',
  :QUESTION => '?',
  :AT => '@',

  :LEFTBRACKET => '[',
  :BACKSLASH => '\\',
  :RIGHTBRACKET => ']',
  :CARET => '^',
  :UNDERSCORE => '_',
  :BACKQUOTE => '`',
  :a => 'a',
  :b => 'b',
  :c => 'c',
  :d => 'd',
  :e => 'e',
  :f => 'f',
  :g => 'g',
  :h => 'h',
  :i => 'i',
  :j => 'j',
  :k => 'k',
  :l => 'l',
  :m => 'm',
  :n => 'n',
  :o => 'o',
  :p => 'p',
  :q => 'q',
  :r => 'r',
  :s => 's',
  :t => 't',
  :u => 'u',
  :v => 'v',
  :w => 'w',
  :x => 'x',
  :y => 'y',
  :z => 'z',

  :CAPSLOCK => scancode_to_keycode(Scancode.CAPSLOCK),

  :F1 => scancode_to_keycode(Scancode.F1),
  :F2 => scancode_to_keycode(Scancode.F2),
  :F3 => scancode_to_keycode(Scancode.F3),
  :F4 => scancode_to_keycode(Scancode.F4),
  :F5 => scancode_to_keycode(Scancode.F5),
  :F6 => scancode_to_keycode(Scancode.F6),
  :F7 => scancode_to_keycode(Scancode.F7),
  :F8 => scancode_to_keycode(Scancode.F8),
  :F9 => scancode_to_keycode(Scancode.F9),
  :F10 => scancode_to_keycode(Scancode.F10),
  :F11 => scancode_to_keycode(Scancode.F11),
  :F12 => scancode_to_keycode(Scancode.F12),

  :PRINTSCREEN => scancode_to_keycode(Scancode.PRINTSCREEN),
  :SCROLLLOCK => scancode_to_keycode(Scancode.SCROLLLOCK),
  :PAUSE => scancode_to_keycode(Scancode.PAUSE),
  :INSERT => scancode_to_keycode(Scancode.INSERT),
  :HOME => scancode_to_keycode(Scancode.HOME),
  :PAGEUP => scancode_to_keycode(Scancode.PAGEUP),
  :DELETE => '\177',
  :END => scancode_to_keycode(Scancode.END),
  :PAGEDOWN => scancode_to_keycode(Scancode.PAGEDOWN),
  :RIGHT => scancode_to_keycode(Scancode.RIGHT),
  :LEFT => scancode_to_keycode(Scancode.LEFT),
  :DOWN => scancode_to_keycode(Scancode.DOWN),
  :UP => scancode_to_keycode(Scancode.UP),

  :NUMLOCKCLEAR => scancode_to_keycode(Scancode.NUMLOCKCLEAR),
  :KP_DIVIDE => scancode_to_keycode(Scancode.KP_DIVIDE),
  :KP_MULTIPLY => scancode_to_keycode(Scancode.KP_MULTIPLY),
  :KP_MINUS => scancode_to_keycode(Scancode.KP_MINUS),
  :KP_PLUS => scancode_to_keycode(Scancode.KP_PLUS),
  :KP_ENTER => scancode_to_keycode(Scancode.KP_ENTER),
  :KP_1 => scancode_to_keycode(Scancode.KP_1),
  :KP_2 => scancode_to_keycode(Scancode.KP_2),
  :KP_3 => scancode_to_keycode(Scancode.KP_3),
  :KP_4 => scancode_to_keycode(Scancode.KP_4),
  :KP_5 => scancode_to_keycode(Scancode.KP_5),
  :KP_6 => scancode_to_keycode(Scancode.KP_6),
  :KP_7 => scancode_to_keycode(Scancode.KP_7),
  :KP_8 => scancode_to_keycode(Scancode.KP_8),
  :KP_9 => scancode_to_keycode(Scancode.KP_9),
  :KP_0 => scancode_to_keycode(Scancode.KP_0),
  :KP_PERIOD => scancode_to_keycode(Scancode.KP_PERIOD),

  :APPLICATION => scancode_to_keycode(Scancode.APPLICATION),
  :POWER => scancode_to_keycode(Scancode.POWER),
  :KP_EQUALS => scancode_to_keycode(Scancode.KP_EQUALS),
  :F13 => scancode_to_keycode(Scancode.F13),
  :F14 => scancode_to_keycode(Scancode.F14),
  :F15 => scancode_to_keycode(Scancode.F15),
  :F16 => scancode_to_keycode(Scancode.F16),
  :F17 => scancode_to_keycode(Scancode.F17),
  :F18 => scancode_to_keycode(Scancode.F18),
  :F19 => scancode_to_keycode(Scancode.F19),
  :F20 => scancode_to_keycode(Scancode.F20),
  :F21 => scancode_to_keycode(Scancode.F21),
  :F22 => scancode_to_keycode(Scancode.F22),
  :F23 => scancode_to_keycode(Scancode.F23),
  :F24 => scancode_to_keycode(Scancode.F24),
  :EXECUTE => scancode_to_keycode(Scancode.EXECUTE),
  :HELP => scancode_to_keycode(Scancode.HELP),
  :MENU => scancode_to_keycode(Scancode.MENU),
  :SELECT => scancode_to_keycode(Scancode.SELECT),
  :STOP => scancode_to_keycode(Scancode.STOP),
  :AGAIN => scancode_to_keycode(Scancode.AGAIN),
  :UNDO => scancode_to_keycode(Scancode.UNDO),
  :CUT => scancode_to_keycode(Scancode.CUT),
  :COPY => scancode_to_keycode(Scancode.COPY),
  :PASTE => scancode_to_keycode(Scancode.PASTE),
  :FIND => scancode_to_keycode(Scancode.FIND),
  :MUTE => scancode_to_keycode(Scancode.MUTE),
  :VOLUMEUP => scancode_to_keycode(Scancode.VOLUMEUP),
  :VOLUMEDOWN => scancode_to_keycode(Scancode.VOLUMEDOWN),
  :KP_COMMA => scancode_to_keycode(Scancode.KP_COMMA),
  :KP_EQUALSAS400 => scancode_to_keycode(Scancode.KP_EQUALSAS400),

  :ALTERASE => scancode_to_keycode(Scancode.ALTERASE),
  :SYSREQ => scancode_to_keycode(Scancode.SYSREQ),
  :CANCEL => scancode_to_keycode(Scancode.CANCEL),
  :CLEAR => scancode_to_keycode(Scancode.CLEAR),
  :PRIOR => scancode_to_keycode(Scancode.PRIOR),
  :RETURN2 => scancode_to_keycode(Scancode.RETURN2),
  :SEPARATOR => scancode_to_keycode(Scancode.SEPARATOR),
  :OUT => scancode_to_keycode(Scancode.OUT),
  :OPER => scancode_to_keycode(Scancode.OPER),
  :CLEARAGAIN => scancode_to_keycode(Scancode.CLEARAGAIN),
  :CRSEL => scancode_to_keycode(Scancode.CRSEL),
  :EXSEL => scancode_to_keycode(Scancode.EXSEL),

  :KP_00 => scancode_to_keycode(Scancode.KP_00),
  :KP_000 => scancode_to_keycode(Scancode.KP_000),
  :THOUSANDSSEPARATOR => scancode_to_keycode(Scancode.THOUSANDSSEPARATOR),
  :DECIMALSEPARATOR => scancode_to_keycode(Scancode.DECIMALSEPARATOR),
  :CURRENCYUNIT => scancode_to_keycode(Scancode.CURRENCYUNIT),
  :CURRENCYSUBUNIT => scancode_to_keycode(Scancode.CURRENCYSUBUNIT),
  :KP_LEFTPAREN => scancode_to_keycode(Scancode.KP_LEFTPAREN),
  :KP_RIGHTPAREN => scancode_to_keycode(Scancode.KP_RIGHTPAREN),
  :KP_LEFTBRACE => scancode_to_keycode(Scancode.KP_LEFTBRACE),
  :KP_RIGHTBRACE => scancode_to_keycode(Scancode.KP_RIGHTBRACE),
  :KP_TAB => scancode_to_keycode(Scancode.KP_TAB),
  :KP_BACKSPACE => scancode_to_keycode(Scancode.KP_BACKSPACE),
  :KP_A => scancode_to_keycode(Scancode.KP_A),
  :KP_B => scancode_to_keycode(Scancode.KP_B),
  :KP_C => scancode_to_keycode(Scancode.KP_C),
  :KP_D => scancode_to_keycode(Scancode.KP_D),
  :KP_E => scancode_to_keycode(Scancode.KP_E),
  :KP_F => scancode_to_keycode(Scancode.KP_F),
  :KP_XOR => scancode_to_keycode(Scancode.KP_XOR),
  :KP_POWER => scancode_to_keycode(Scancode.KP_POWER),
  :KP_PERCENT => scancode_to_keycode(Scancode.KP_PERCENT),
  :KP_LESS => scancode_to_keycode(Scancode.KP_LESS),
  :KP_GREATER => scancode_to_keycode(Scancode.KP_GREATER),
  :KP_AMPERSAND => scancode_to_keycode(Scancode.KP_AMPERSAND),
  :KP_DBLAMPERSAND => scancode_to_keycode(Scancode.KP_DBLAMPERSAND),
  :KP_VERTICALBAR => scancode_to_keycode(Scancode.KP_VERTICALBAR),
  :KP_DBLVERTICALBAR => scancode_to_keycode(Scancode.KP_DBLVERTICALBAR),
  :KP_COLON => scancode_to_keycode(Scancode.KP_COLON),
  :KP_HASH => scancode_to_keycode(Scancode.KP_HASH),
  :KP_SPACE => scancode_to_keycode(Scancode.KP_SPACE),
  :KP_AT => scancode_to_keycode(Scancode.KP_AT),
  :KP_EXCLAM => scancode_to_keycode(Scancode.KP_EXCLAM),
  :KP_MEMSTORE => scancode_to_keycode(Scancode.KP_MEMSTORE),
  :KP_MEMRECALL => scancode_to_keycode(Scancode.KP_MEMRECALL),
  :KP_MEMCLEAR => scancode_to_keycode(Scancode.KP_MEMCLEAR),
  :KP_MEMADD => scancode_to_keycode(Scancode.KP_MEMADD),
  :KP_MEMSUBTRACT =>        scancode_to_keycode(Scancode.KP_MEMSUBTRACT),
  :KP_MEMMULTIPLY =>        scancode_to_keycode(Scancode.KP_MEMMULTIPLY),
  :KP_MEMDIVIDE => scancode_to_keycode(Scancode.KP_MEMDIVIDE),
  :KP_PLUSMINUS => scancode_to_keycode(Scancode.KP_PLUSMINUS),
  :KP_CLEAR => scancode_to_keycode(Scancode.KP_CLEAR),
  :KP_CLEARENTRY => scancode_to_keycode(Scancode.KP_CLEARENTRY),
  :KP_BINARY => scancode_to_keycode(Scancode.KP_BINARY),
  :KP_OCTAL => scancode_to_keycode(Scancode.KP_OCTAL),
  :KP_DECIMAL => scancode_to_keycode(Scancode.KP_DECIMAL),
  :KP_HEXADECIMAL =>        scancode_to_keycode(Scancode.KP_HEXADECIMAL),

  :LCTRL => scancode_to_keycode(Scancode.LCTRL),
  :LSHIFT => scancode_to_keycode(Scancode.LSHIFT),
  :LALT => scancode_to_keycode(Scancode.LALT),
  :LGUI => scancode_to_keycode(Scancode.LGUI),
  :RCTRL => scancode_to_keycode(Scancode.RCTRL),
  :RSHIFT => scancode_to_keycode(Scancode.RSHIFT),
  :RALT => scancode_to_keycode(Scancode.RALT),
  :RGUI => scancode_to_keycode(Scancode.RGUI),

  :MODE => scancode_to_keycode(Scancode.MODE),

  :AUDIONEXT => scancode_to_keycode(Scancode.AUDIONEXT),
  :AUDIOPREV => scancode_to_keycode(Scancode.AUDIOPREV),
  :AUDIOSTOP => scancode_to_keycode(Scancode.AUDIOSTOP),
  :AUDIOPLAY => scancode_to_keycode(Scancode.AUDIOPLAY),
  :AUDIOMUTE => scancode_to_keycode(Scancode.AUDIOMUTE),
  :MEDIASELECT => scancode_to_keycode(Scancode.MEDIASELECT),
  :WWW => scancode_to_keycode(Scancode.WWW),
  :MAIL => scancode_to_keycode(Scancode.MAIL),
  :CALCULATOR => scancode_to_keycode(Scancode.CALCULATOR),
  :COMPUTER => scancode_to_keycode(Scancode.COMPUTER),
  :AC_SEARCH => scancode_to_keycode(Scancode.AC_SEARCH),
  :AC_HOME => scancode_to_keycode(Scancode.AC_HOME),
  :AC_BACK => scancode_to_keycode(Scancode.AC_BACK),
  :AC_FORWARD => scancode_to_keycode(Scancode.AC_FORWARD),
  :AC_STOP => scancode_to_keycode(Scancode.AC_STOP),
  :AC_REFRESH => scancode_to_keycode(Scancode.AC_REFRESH),
  :AC_BOOKMARKS => scancode_to_keycode(Scancode.AC_BOOKMARKS),

  :BRIGHTNESSDOWN =>        scancode_to_keycode(Scancode.BRIGHTNESSDOWN),
  :BRIGHTNESSUP => scancode_to_keycode(Scancode.BRIGHTNESSUP),
  :DISPLAYSWITCH => scancode_to_keycode(Scancode.DISPLAYSWITCH),
  :KBDILLUMTOGGLE =>        scancode_to_keycode(Scancode.KBDILLUMTOGGLE),
  :KBDILLUMDOWN => scancode_to_keycode(Scancode.KBDILLUMDOWN),
  :KBDILLUMUP => scancode_to_keycode(Scancode.KBDILLUMUP),
  :EJECT => scancode_to_keycode(Scancode.EJECT),
  :SLEEP => scancode_to_keycode(Scancode.SLEEP)
})
KEYMOD_HASH =
{
  :NONE =>   0x0000,
  :LSHIFT =>   0x0001,
  :RSHIFT =>   0x0002,
  :LCTRL =>  0x0040,
  :RCTRL =>  0x0080,
  :LALT =>   0x0100,
  :RALT =>   0x0200,
  :LGUI =>   0x0400,
  :RGUI =>   0x0800,
  :NUM  =>   0x1000,
  :CAPS =>  0x2000,
  :MODE =>  0x4000,
  :RESERVED =>   0x8000
}
Keymod =
Enum.new( :KEYMOD, KEYMOD_HASH)
HAT_HASH =
{
  :CENTERED => 0x00,
  :UP => 0x01,
  :RIGHT =>  0x02,
  :DOWN => 0x04,
  :LEFT => 0x08
}
Hat =
Enum.new(:JOYSTICK_HAT, HAT_HASH)
NUM_SCANCODES =
512
Scancode =
Enum.new(:SCANCODE, {
  :A => 4,
  :B => 5,
  :C => 6,
  :D => 7,
  :E => 8,
  :F => 9,
  :G => 10,
  :H => 11,
  :I => 12,
  :J => 13,
  :K => 14,
  :L => 15,
  :M => 16,
  :N => 17,
  :O => 18,
  :P => 19,
  :Q => 20,
  :R => 21,
  :S => 22,
  :T => 23,
  :U => 24,
  :V => 25,
  :W => 26,
  :X => 27,
  :Y => 28,
  :Z => 29,

  :'1' => 30,
  :'2' => 31,
  :'3' => 32,
  :'4' => 33,
  :'5' => 34,
  :'6' => 35,
  :'7' => 36,
  :'8' => 37,
  :'9' => 38,
  :'0' => 39,

  :RETURN => 40,
  :ESCAPE => 41,
  :BACKSPACE => 42,
  :TAB => 43,
  :SPACE => 44,

  :MINUS => 45,
  :EQUALS => 46,
  :LEFTBRACKET => 47,
  :RIGHTBRACKET => 48,
  :BACKSLASH => 49,
  :NONUSHASH => 50,
  :SEMICOLON => 51,
  :APOSTROPHE => 52,
  :GRAVE => 53,
  :COMMA => 54,
  :PERIOD => 55,
  :SLASH => 56,

  :CAPSLOCK => 57,

  :F1 => 58,
  :F2 => 59,
  :F3 => 60,
  :F4 => 61,
  :F5 => 62,
  :F6 => 63,
  :F7 => 64,
  :F8 => 65,
  :F9 => 66,
  :F10 => 67,
  :F11 => 68,
  :F12 => 69,

  :PRINTSCREEN => 70,
  :SCROLLLOCK => 71,
  :PAUSE => 72,
  :INSERT => 73,

  :HOME => 74,
  :PAGEUP => 75,
  :DELETE => 76,
  :END => 77,
  :PAGEDOWN => 78,
  :RIGHT => 79,
  :LEFT => 80,
  :DOWN => 81,
  :UP => 82,

  :NUMLOCKCLEAR => 83,

  :KP_DIVIDE => 84,
  :KP_MULTIPLY => 85,
  :KP_MINUS => 86,
  :KP_PLUS => 87,
  :KP_ENTER => 88,
  :KP_1 => 89,
  :KP_2 => 90,
  :KP_3 => 91,
  :KP_4 => 92,
  :KP_5 => 93,
  :KP_6 => 94,
  :KP_7 => 95,
  :KP_8 => 96,
  :KP_9 => 97,
  :KP_0 => 98,
  :KP_PERIOD => 99,

  :NONUSBACKSLASH => 100,

  :APPLICATION => 101,
  :POWER => 102,

  :KP_EQUALS => 103,
  :F13 => 104,
  :F14 => 105,
  :F15 => 106,
  :F16 => 107,
  :F17 => 108,
  :F18 => 109,
  :F19 => 110,
  :F20 => 111,
  :F21 => 112,
  :F22 => 113,
  :F23 => 114,
  :F24 => 115,
  :EXECUTE => 116,
  :HELP => 117,
  :MENU => 118,
  :SELECT => 119,
  :STOP => 120,
  :AGAIN => 121,
  :UNDO => 122,
  :CUT => 123,
  :COPY => 124,
  :PASTE => 125,
  :FIND => 126,
  :MUTE => 127,
  :VOLUMEUP => 128,
  :VOLUMEDOWN => 129,

  :KP_COMMA => 133,
  :KP_EQUALSAS400 => 134,

  :INTERNATIONAL1 => 135,

  :INTERNATIONAL2 => 136,
  :INTERNATIONAL3 => 137,
  :INTERNATIONAL4 => 138,
  :INTERNATIONAL5 => 139,
  :INTERNATIONAL6 => 140,
  :INTERNATIONAL7 => 141,
  :INTERNATIONAL8 => 142,
  :INTERNATIONAL9 => 143,
  :LANG1 => 144,
  :LANG2 => 145,
  :LANG3 => 146,
  :LANG4 => 147,
  :LANG5 => 148,
  :LANG6 => 149,
  :LANG7 => 150,
  :LANG8 => 151,
  :LANG9 => 152,

  :ALTERASE => 153,
  :SYSREQ => 154,
  :CANCEL => 155,
  :CLEAR => 156,
  :PRIOR => 157,
  :RETURN2 => 158,
  :SEPARATOR => 159,
  :OUT => 160,
  :OPER => 161,
  :CLEARAGAIN => 162,
  :CRSEL => 163,
  :EXSEL => 164,

  :KP_00 => 176,
  :KP_000 => 177,
  :THOUSANDSSEPARATOR => 178,
  :DECIMALSEPARATOR => 179,
  :CURRENCYUNIT => 180,
  :CURRENCYSUBUNIT => 181,
  :KP_LEFTPAREN => 182,
  :KP_RIGHTPAREN => 183,
  :KP_LEFTBRACE => 184,
  :KP_RIGHTBRACE => 185,
  :KP_TAB => 186,
  :KP_BACKSPACE => 187,
  :KP_A => 188,
  :KP_B => 189,
  :KP_C => 190,
  :KP_D => 191,
  :KP_E => 192,
  :KP_F => 193,
  :KP_XOR => 194,
  :KP_POWER => 195,
  :KP_PERCENT => 196,
  :KP_LESS => 197,
  :KP_GREATER => 198,
  :KP_AMPERSAND => 199,
  :KP_DBLAMPERSAND => 200,
  :KP_VERTICALBAR => 201,
  :KP_DBLVERTICALBAR => 202,
  :KP_COLON => 203,
  :KP_HASH => 204,
  :KP_SPACE => 205,
  :KP_AT => 206,
  :KP_EXCLAM => 207,
  :KP_MEMSTORE => 208,
  :KP_MEMRECALL => 209,
  :KP_MEMCLEAR => 210,
  :KP_MEMADD => 211,
  :KP_MEMSUBTRACT => 212,
  :KP_MEMMULTIPLY => 213,
  :KP_MEMDIVIDE => 214,
  :KP_PLUSMINUS => 215,
  :KP_CLEAR => 216,
  :KP_CLEARENTRY => 217,
  :KP_BINARY => 218,
  :KP_OCTAL => 219,
  :KP_DECIMAL => 220,
  :KP_HEXADECIMAL => 221,

  :LCTRL => 224,
  :LSHIFT => 225,
  :LALT => 226,
  :LGUI => 227,
  :RCTRL => 228,
  :RSHIFT => 229,
  :RALT => 230,
  :RGUI => 231,

  :MODE => 257,

  :AUDIONEXT => 258,
  :AUDIOPREV => 259,
  :AUDIOSTOP => 260,
  :AUDIOPLAY => 261,
  :AUDIOMUTE => 262,
  :MEDIASELECT => 263,
  :WWW => 264,
  :MAIL => 265,
  :CALCULATOR => 266,
  :COMPUTER => 267,
  :AC_SEARCH => 268,
  :AC_HOME => 269,
  :AC_BACK => 270,
  :AC_FORWARD => 271,
  :AC_STOP => 272,
  :AC_REFRESH => 273,
  :AC_BOOKMARKS => 274,

  :BRIGHTNESSDOWN => 275,
  :BRIGHTNESSUP => 276,
  :DISPLAYSWITCH => 277,

  :KBDILLUMTOGGLE => 278,
  :KBDILLUMDOWN => 279,
  :KBDILLUMUP => 280,
  :EJECT => 281,
  :SLEEP => 282,

  :APP1 => 283,
  :APP2 => 284
})
SDL_MODULE =

Default load-path. To modify what library this RubyGem loads: 1) require ‘sdl2/sdl_module’ before anything else.

2) Modify the SDL2::SDL_MODULE array. 3) require any of the rest of the SDL2 module: require ‘sdl2/video’, etc

['libSDL2','/usr/local/lib/libSDL2.so']
GEM_VERSION =
"0.0.3"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.api(func_name, args, type, options = {}) ⇒ Object

This converts the SDL Function Prototype name “SDL_XxxYyyyyZzz” to ruby’s “xxx_yyyy_zzz” convetion



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sdl2.rb', line 26

def self.api(func_name, args, type, options = {})

  options = {
    :error => false,
    :filter => TRUE_WHEN_ZERO
  }.merge(options)

  camelCaseName = func_name.to_s.gsub('SDL_','')
  methodName = ActiveSupport::Inflector.underscore(camelCaseName).to_sym

  self.attach_function methodName, func_name, args, type

  if options[:error]
    returns_error(methodName, options[:filter])
  end

  if type == :bool
    boolean?(methodName)
  end

  return methodName
end

.bitsperpixel(x) ⇒ Object

MACRO: SDL_BITSPERPIXEL(X) (((X) >> 8) & 0xFF)



94
# File 'lib/sdl2/pixels.rb', line 94

def self.bitsperpixel(x);   (((x) >> 8) & 0xFF); end

.blit_scaled(src, srcrect, dst, dstrect) ⇒ Object



177
178
179
# File 'lib/sdl2/surface.rb', line 177

def self.blit_scaled(src, srcrect, dst, dstrect)
  upper_blit_scaled(src, srcrect, dst, dstrect)
end

.blit_surface(src, srcrect, dst, dstrect) ⇒ Object



169
170
171
# File 'lib/sdl2/surface.rb', line 169

def self.blit_surface(src, srcrect, dst, dstrect)
  upper_blit(src, srcrect, dst, dstrect)
end

.boolean?(methodName) ⇒ Boolean

Generates an alternative version of methodName that will return Ruby’s true if the method named returns SDL_true/:true enum value. The alternative method has the same name with a question mark (“?”) appended, to indicate its boolean nature.

Returns:

  • (Boolean)


75
76
77
78
79
80
81
# File 'lib/sdl2.rb', line 75

def self.boolean?(methodName)
  metaclass.instance_eval do
    define_method("#{methodName}?".to_sym) do |*args|
      self.send(methodName, *args) == :true
    end
  end
end

.bytesperpixel(x) ⇒ Object

MACRO: SDL_BYTESPERPIXEL(X) \

(SDL_ISPIXELFORMAT_FOURCC(X) ? \
    ((((X) == SDL_PIXELFORMAT_YUY2) || \
      ((X) == SDL_PIXELFORMAT_UYVY) || \
      ((X) == SDL_PIXELFORMAT_YVYU)) ? 2 : 1) : (((X) >> 0) & 0xFF))


101
102
103
104
105
106
# File 'lib/sdl2/pixels.rb', line 101

def self.bytesperpixel(x)
  (ispixelformat_fourcc(x) ?
  ((( x == PIXELFORMAT.YUV2 ) ||
  ( x == PIXELFORMAT.UYVY ) ||
  ( x == PIXELFORMAT.YVYU )) ? 2 : 1) : ((x >> 0) & 0xFF))
end

.define_pixelformat(type, order, layout, bits, bytes) ⇒ Object

MACRO: SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \

((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
 ((bits) << 8) | ((bytes) << 0))


77
78
79
# File 'lib/sdl2/pixels.rb', line 77

def self.define_pixelformat(type, order, layout, bits, bytes)
  ((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | ((bits) << 8) | ((bytes) << 0))
end

.define_pixelfourcc(a, b, c, d) ⇒ Object

MACRO: SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D)



72
# File 'lib/sdl2/pixels.rb', line 72

def self.define_pixelfourcc(a,b,c,d); SDL2.fourcc(a,b,c,d); end

.fourcc(*args) ⇒ Object

Define a four character code as a Uint32 MACRO: SDL_FOURCC(A, B, C, D) \

((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
 (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
 (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
 (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))


89
90
91
92
93
94
95
96
97
98
# File 'lib/sdl2.rb', line 89

def self.fourcc(*args)
  bit_cnt = 0
  result = 0
  args.each do |arg|
    arg = arg.codepoints[0] if arg.kind_of? String
    result = result | (arg << bit_cnt)
    bit_cnt += 8
  end
  return result
end

.ispixelformat_alpha(format) ⇒ Object

MACRO: SDL_ISPIXELFORMAT_ALPHA(format) \ (!SDL_ISPIXELFORMAT_FOURCC(format) && \ ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \ (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \ (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \ (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA)))



126
127
128
129
130
131
132
# File 'lib/sdl2/pixels.rb', line 126

def self.ispixelformat_alpha(format)
  (!pixelformat_fourcc(format) &&
  ((pixelorder(format) == PACKEDORDER.ARGB) ||
  (pixelorder(format) == PACKEDORDER.RGBA) ||
  (pixelorder(format) == PACKEDORDER.ABGR) ||
  (pixelorder(format) == PACKEDORDER.BGRA)))
end

.ispixelformat_fourcc(format) ⇒ Object

MACRO: SDL_ISPIXELFORMAT_FOURCC(format) \ ((format) && (SDL_PIXELFLAG(format) != 1))



136
137
138
# File 'lib/sdl2/pixels.rb', line 136

def self.ispixelformat_fourcc(format)
  ((format) && (pixelflag(format) != 1))
end

.ispixelformat_indexed(format) ⇒ Object

MACRO: SDL_ISPIXELFORMAT_INDEXED(format) \ (!SDL_ISPIXELFORMAT_FOURCC(format) && \ ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))



113
114
115
116
117
118
# File 'lib/sdl2/pixels.rb', line 113

def self.ispixelformat_indexed(format)
  (!ispixelformat_fourcc(format) &&
  ((pixeltype(format) == PIXELTYPE.INDEX1) ||
  (pixeltype(format) == PIXELTYPE.INDEX4) ||
  (pixeltype(format) == PIXELTYPE.INDEX8)))
end

.load_bmp(file) ⇒ Object

Redefine SDL_LoadBMP macro:



141
142
143
# File 'lib/sdl2/surface.rb', line 141

def self.load_bmp(file)
  SDL2.load_bmp_rw(RWops.from_file(file, 'rb'), 1)
end

.load_wav(file, spec, audio_buf, audio_len) ⇒ Object



118
119
120
# File 'lib/sdl2/audio.rb', line 118

def self.load_wav(file, spec, audio_buf, audio_len)
  load_wav_rw(rw_from_file)
end

.metaclassObject

Returns the ‘singleton class’ so we can define class-level methods on the fly. There may be a better place to put this.



52
53
54
55
# File 'lib/sdl2.rb', line 52

def self.metaclass

  class << self; self; end
end

.pixelflag(x) ⇒ Object

MACRO: SDL_PIXELFLAG(X) (((X) >> 28) & 0x0F)



82
# File 'lib/sdl2/pixels.rb', line 82

def self.pixelflag(x);      (((x) >> 28) & 0x0F); end

.pixellayout(x) ⇒ Object

MACRO: SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F)



91
# File 'lib/sdl2/pixels.rb', line 91

def self.pixellayout(x);    (((x) >> 16) & 0x0F); end

.pixelorder(x) ⇒ Object

MACRO: SDL_PIXELORDER(X) (((X) >> 20) & 0x0F)



88
# File 'lib/sdl2/pixels.rb', line 88

def self.pixelorder(x);     (((x) >> 20) & 0x0F); end

.pixeltype(x) ⇒ Object

MACRO: SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F)



85
# File 'lib/sdl2/pixels.rb', line 85

def self.pixeltype(x);      (((x) >> 24) & 0x0F); end

.raise_errorObject

Raise the current error value as a RuntimeException



155
156
157
# File 'lib/sdl2.rb', line 155

def self.raise_error
  raise "SDL Error: #{SDL2.get_error()}"
end

.raise_error_if(condition) ⇒ Object

Conditionally raise an error, unless false



165
166
167
# File 'lib/sdl2.rb', line 165

def self.raise_error_if(condition)
  raise_error if condition
end

.raise_error_unless(condition) ⇒ Object

Conditionally raise an error, unless true



160
161
162
# File 'lib/sdl2.rb', line 160

def self.raise_error_unless(condition)
  raise_error unless condition
end

.returns_error(methodName, filter) ⇒ Object

Generates an alternative version of methodName that will raise a SDL Error when the return value fails the filter test. The alternative version has the same name, but with an exclamation mark (“!”) at the end, indicating the danger.



61
62
63
64
65
66
67
68
69
# File 'lib/sdl2.rb', line 61

def self.returns_error(methodName, filter)
  metaclass.instance_eval do
    define_method "#{methodName}!".to_sym do |*args|
      result = self.send(methodName, *args)
      raise_error_unless filter.call(result)
      result
    end
  end
end

.save_bmp(file) ⇒ Object



147
148
149
# File 'lib/sdl2/surface.rb', line 147

def self.save_bmp(file)
  SDL2.save_bmp_rw(RWops.from_file(file, 'wb'), 1)
end

.scancode_to_keycode(scancode) ⇒ Object



13
14
15
# File 'lib/sdl2/keycode.rb', line 13

def self.scancode_to_keycode(scancode)
  scancode | SCANCODE_MASK
end

Instance Method Details

#get_event_state(type) ⇒ Object



353
354
355
# File 'lib/sdl2/events.rb', line 353

def get_event_state(type)
  event_state(type, QUERY)
end

#init_sub_system!(flags) ⇒ Object



42
43
44
45
46
47
# File 'lib/sdl2/init.rb', line 42

def init_sub_system!(flags)
  error_code = init_sub_system(flags)
  if (error_code != 0)
    throw get_error
  end
end