Module: SDL2

Extended by:
FFI::Library, 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/stdinc.rb,
lib/sdl2/window.rb,
lib/sdl2/cpuinfo.rb,
lib/sdl2/display.rb,
lib/sdl2/gesture.rb,
lib/sdl2/keycode.rb,
lib/sdl2/library.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/ttf/font.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: ARRAYORDER, Audio, BITMAPORDER, Clipboard, EVENTACTION, EVENTSTATE, EVENTTYPE, FLIP, GLattr, GLcontextFlag, GLprofile, HAT, HINT, INIT, Image, KEYCODE, KEYMOD, Library, Mouse, PACKEDLAYOUT, PACKEDORDER, PIXELFORMAT, PIXELTYPE, POWERSTATE, RENDERER, SCANCODE, StructHelper, SysWM, TEXTUREACCESS, TEXTUREMODULATE, TTF, WINDOW, WINDOWEVENT, WINDOWPOS Classes: AbstractEvent, 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, Union, UserEvent, Version, Window, WindowEvent

Constant Summary collapse

PrintDebug =
false
MIX_MAXVOLUME =
128
Colour =

Alternative spelling of Color

Color
IMG =

Alias to follow IMG_xxx convention

Image
SYSWM =

Because I don’t care about case.

SysWM
TOUCH_MOUSEID =
-1
RELEASED =
0
PRESSED =
1
ALPHA_OPAQUE =
255
ALPHA_TRANSPARENT =
0
TRUE_WHEN_ZERO =

Filter Proc, True when arg equals zero

Proc.new do |result|
  # Handles both Negative and Positive error values.
  result == 0
end
TRUE_WHEN_ONE =
Proc.new{|result| result == 1}
TRUE_WHEN_NOT_ZERO =
Proc.new do |result|
  result != 0
end
TRUE_WHEN_NOT_NULL =

Filter Proc, True when arg not null?

Proc.new do |result|
  # Anything but nil/null is considered valid.
  (!result.null?)
end
TRUE_WHEN_TRUE =
Proc.new do |result|
  result == true
end
CACHELINE_SIZE =
128
SCANCODE_MASK =

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

1<<30
NUM_SCANCODES =

Not a key, just marks the number of scancodes for array bounds

512
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.5"

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Library

api, boolean?, metaclass, raise_error, raise_error_if, raise_error_unless, returns_error

Class Method Details

.bitsperpixel(x) ⇒ Object

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



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

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

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

using upper_blit_scaled



243
244
245
# File 'lib/sdl2/surface.rb', line 243

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

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

using upper_blit



231
232
233
234
# File 'lib/sdl2/surface.rb', line 231

def self.blit_surface(src, srcrect, dst, dstrect)
  
  upper_blit(src, srcrect, dst, dstrect)
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))


117
118
119
120
121
122
# File 'lib/sdl2/pixels.rb', line 117

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))


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

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)



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

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))


14
15
16
17
18
19
20
21
22
23
# File 'lib/sdl2/stdinc.rb', line 14

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)))



142
143
144
145
146
147
148
# File 'lib/sdl2/pixels.rb', line 142

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))



152
153
154
# File 'lib/sdl2/pixels.rb', line 152

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)))



129
130
131
132
133
134
# File 'lib/sdl2/pixels.rb', line 129

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:



198
199
200
# File 'lib/sdl2/surface.rb', line 198

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



121
122
123
# File 'lib/sdl2/audio.rb', line 121

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

.pixelflag(x) ⇒ Object

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



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

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

.pixellayout(x) ⇒ Object

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



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

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

.pixelorder(x) ⇒ Object

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



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

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

.pixeltype(x) ⇒ Object

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



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

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

.save_bmp(surface, file) ⇒ Object



206
207
208
# File 'lib/sdl2/surface.rb', line 206

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

.scancode_to_keycode(scancode) ⇒ Object



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

def self.scancode_to_keycode(scancode)
  scancode | SCANCODE_MASK
end

Instance Method Details

#event_filterObject

callback event_filter #=> Proc.new do |pointer, event|; return int; end



484
# File 'lib/sdl2/events.rb', line 484

callback :event_filter, [:pointer, Event.by_ref], :int

#get_event_state(type) ⇒ Object



512
513
514
# File 'lib/sdl2/events.rb', line 512

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

#init_sub_system!(flags) ⇒ Object



30
31
32
33
34
35
# File 'lib/sdl2/init.rb', line 30

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