Module Rubygame
In: lib/rubygame/main.rb
lib/rubygame/ftor.rb
lib/rubygame/clock.rb
lib/rubygame/constants.rb
lib/rubygame/color/models/rgb.rb
lib/rubygame/color/models/hsl.rb
lib/rubygame/color/models/hsv.rb
lib/rubygame/color/models/base.rb
lib/rubygame/color/palettes/css.rb
lib/rubygame/color/palettes/x11.rb
lib/rubygame/event.rb
lib/rubygame/events.rb
lib/rubygame/rect.rb
lib/rubygame/mediabag.rb
lib/rubygame/color.rb
lib/rubygame/sprite.rb
lib/rubygame/named_resource.rb
lib/rubygame/hotspot.rb
lib/rubygame/sfont.rb
lib/rubygame/queue.rb
lib/rubygame/shared.rb
lib/rubygame/audio.rb
lib/rubygame/event_hook.rb
lib/rubygame/events/keyboard_events.rb
lib/rubygame/events/joystick_events.rb
lib/rubygame/events/misc_events.rb
lib/rubygame/events/mouse_events.rb
lib/rubygame/events/clock_events.rb

Ftor (“Fake vecTOR”), a vector-like class for 2D position/movement.


Hotspot, a mixin module to extend an object with custom, named, relative position offsets.


Common / utility methods.


Methods

Classes and Modules

Module Rubygame::Color
Module Rubygame::EventActions
Module Rubygame::EventTriggers
Module Rubygame::Events
Module Rubygame::GL
Module Rubygame::Hotspot
Module Rubygame::Key
Module Rubygame::MailQueue
Module Rubygame::Mixer
Module Rubygame::Mouse
Module Rubygame::NamedResource
Module Rubygame::Sprites
Class Rubygame::ActiveEvent
Class Rubygame::Clock
Class Rubygame::Event
Class Rubygame::EventHandler
Class Rubygame::EventHook
Class Rubygame::EventQueue
Class Rubygame::ExposeEvent
Class Rubygame::Ftor
Class Rubygame::JoyAxisEvent
Class Rubygame::JoyBallEvent
Class Rubygame::JoyDownEvent
Class Rubygame::JoyHatEvent
Class Rubygame::JoyUpEvent
Class Rubygame::Joystick
Class Rubygame::KeyDownEvent
Class Rubygame::KeyUpEvent
Class Rubygame::MediaBag
Class Rubygame::MouseDownEvent
Class Rubygame::MouseMotionEvent
Class Rubygame::MouseUpEvent
Class Rubygame::Music
Class Rubygame::QuitEvent
Class Rubygame::Rect
Class Rubygame::ResizeEvent
Class Rubygame::SDLError
Class Rubygame::SFont
Class Rubygame::Screen
Class Rubygame::Sound
Class Rubygame::Surface
Class Rubygame::TTF

Constants

VERSIONS = { :rubygame => [2, 5, 3], :sdl => SDL.Linked_Version().to_ary }
SWSURFACE = SDL::SWSURFACE
HWSURFACE = SDL::HWSURFACE
ASYNCBLIT = SDL::ASYNCBLIT
ANYFORMAT = SDL::ANYFORMAT
HWPALETTE = SDL::HWPALETTE
HWACCEL = SDL::HWACCEL
SRCCOLORKEY = SDL::SRCCOLORKEY
RLEACCELOK = SDL::RLEACCELOK
RLEACCEL = SDL::RLEACCEL
SRCALPHA = SDL::SRCALPHA
PREALLOC = SDL::PREALLOC
DOUBLEBUF = SDL::DOUBLEBUF
FULLSCREEN = SDL::FULLSCREEN
OPENGL = SDL::OPENGL
OPENGLBLIT = SDL::OPENGLBLIT
RESIZABLE = SDL::RESIZABLE
NOFRAME = SDL::NOFRAME
NOEVENT = SDL::NOEVENT   Event constants
ACTIVEEVENT = SDL::ACTIVEEVENT
KEYDOWN = SDL::KEYDOWN
KEYUP = SDL::KEYUP
MOUSEMOTION = SDL::MOUSEMOTION
MOUSEBUTTONDOWN = SDL::MOUSEBUTTONDOWN
MOUSEBUTTONUP = SDL::MOUSEBUTTONUP
JOYAXISMOTION = SDL::JOYAXISMOTION
JOYBALLMOTION = SDL::JOYBALLMOTION
JOYHATMOTION = SDL::JOYHATMOTION
JOYBUTTONDOWN = SDL::JOYBUTTONDOWN
JOYBUTTONUP = SDL::JOYBUTTONUP
QUIT = SDL::QUIT
SYSWMEVENT = SDL::SYSWMEVENT
VIDEORESIZE = SDL::VIDEORESIZE
VIDEOEXPOSE = SDL::VIDEOEXPOSE
USEREVENT = SDL::USEREVENT
HAT_CENTERED = SDL::HAT_CENTERED   Joystick constants
HAT_UP = SDL::HAT_UP
HAT_RIGHT = SDL::HAT_RIGHT
HAT_DOWN = SDL::HAT_DOWN
HAT_LEFT = SDL::HAT_LEFT
HAT_RIGHTUP = SDL::HAT_RIGHTUP
HAT_RIGHTDOWN = SDL::HAT_RIGHTDOWN
HAT_LEFTUP = SDL::HAT_LEFTUP
HAT_LEFTDOWN = SDL::HAT_LEFTDOWN
MOUSE_LEFT = SDL::BUTTON_LEFT   Mouse constants
MOUSE_MIDDLE = SDL::BUTTON_MIDDLE
MOUSE_RIGHT = SDL::BUTTON_RIGHT
MOUSE_LMASK = SDL::BUTTON_LMASK
MOUSE_MMASK = SDL::BUTTON_MMASK
MOUSE_RMASK = SDL::BUTTON_RMASK
K_UNKNOWN = SDL::K_UNKNOWN   ASCII key symbols
K_FIRST = SDL::K_FIRST
K_BACKSPACE = SDL::K_BACKSPACE
K_TAB = SDL::K_TAB
K_CLEAR = SDL::K_CLEAR
K_RETURN = SDL::K_RETURN
K_PAUSE = SDL::K_PAUSE
K_ESCAPE = SDL::K_ESCAPE
K_SPACE = SDL::K_SPACE
K_EXCLAIM = SDL::K_EXCLAIM
K_QUOTEDBL = SDL::K_QUOTEDBL
K_HASH = SDL::K_HASH
K_DOLLAR = SDL::K_DOLLAR
K_AMPERSAND = SDL::K_AMPERSAND
K_QUOTE = SDL::K_QUOTE
K_LEFTPAREN = SDL::K_LEFTPAREN
K_RIGHTPAREN = SDL::K_RIGHTPAREN
K_ASTERISK = SDL::K_ASTERISK
K_PLUS = SDL::K_PLUS
K_COMMA = SDL::K_COMMA
K_MINUS = SDL::K_MINUS
K_PERIOD = SDL::K_PERIOD
K_SLASH = SDL::K_SLASH
K_0 = SDL::K_0
K_1 = SDL::K_1
K_2 = SDL::K_2
K_3 = SDL::K_3
K_4 = SDL::K_4
K_5 = SDL::K_5
K_6 = SDL::K_6
K_7 = SDL::K_7
K_8 = SDL::K_8
K_9 = SDL::K_9
K_COLON = SDL::K_COLON
K_SEMICOLON = SDL::K_SEMICOLON
K_LESS = SDL::K_LESS
K_EQUALS = SDL::K_EQUALS
K_GREATER = SDL::K_GREATER
K_QUESTION = SDL::K_QUESTION
K_AT = SDL::K_AT
K_LEFTBRACKET = SDL::K_LEFTBRACKET
K_BACKSLASH = SDL::K_BACKSLASH
K_RIGHTBRACKET = SDL::K_RIGHTBRACKET
K_CARET = SDL::K_CARET
K_UNDERSCORE = SDL::K_UNDERSCORE
K_BACKQUOTE = SDL::K_BACKQUOTE
K_A = SDL::K_a
K_B = SDL::K_b
K_C = SDL::K_c
K_D = SDL::K_d
K_E = SDL::K_e
K_F = SDL::K_f
K_G = SDL::K_g
K_H = SDL::K_h
K_I = SDL::K_i
K_J = SDL::K_j
K_K = SDL::K_k
K_L = SDL::K_l
K_M = SDL::K_m
K_N = SDL::K_n
K_O = SDL::K_o
K_P = SDL::K_p
K_Q = SDL::K_q
K_R = SDL::K_r
K_S = SDL::K_s
K_T = SDL::K_t
K_U = SDL::K_u
K_V = SDL::K_v
K_W = SDL::K_w
K_X = SDL::K_x
K_Y = SDL::K_y
K_Z = SDL::K_z
K_DELETE = SDL::K_DELETE
K_WORLD_0 = SDL::K_WORLD_0   International keyboard symbols
K_WORLD_1 = SDL::K_WORLD_1
K_WORLD_2 = SDL::K_WORLD_2
K_WORLD_3 = SDL::K_WORLD_3
K_WORLD_4 = SDL::K_WORLD_4
K_WORLD_5 = SDL::K_WORLD_5
K_WORLD_6 = SDL::K_WORLD_6
K_WORLD_7 = SDL::K_WORLD_7
K_WORLD_8 = SDL::K_WORLD_8
K_WORLD_9 = SDL::K_WORLD_9
K_WORLD_10 = SDL::K_WORLD_10
K_WORLD_11 = SDL::K_WORLD_11
K_WORLD_12 = SDL::K_WORLD_12
K_WORLD_13 = SDL::K_WORLD_13
K_WORLD_14 = SDL::K_WORLD_14
K_WORLD_15 = SDL::K_WORLD_15
K_WORLD_16 = SDL::K_WORLD_16
K_WORLD_17 = SDL::K_WORLD_17
K_WORLD_18 = SDL::K_WORLD_18
K_WORLD_19 = SDL::K_WORLD_19
K_WORLD_20 = SDL::K_WORLD_20
K_WORLD_21 = SDL::K_WORLD_21
K_WORLD_22 = SDL::K_WORLD_22
K_WORLD_23 = SDL::K_WORLD_23
K_WORLD_24 = SDL::K_WORLD_24
K_WORLD_25 = SDL::K_WORLD_25
K_WORLD_26 = SDL::K_WORLD_26
K_WORLD_27 = SDL::K_WORLD_27
K_WORLD_28 = SDL::K_WORLD_28
K_WORLD_29 = SDL::K_WORLD_29
K_WORLD_30 = SDL::K_WORLD_30
K_WORLD_31 = SDL::K_WORLD_31
K_WORLD_32 = SDL::K_WORLD_32
K_WORLD_33 = SDL::K_WORLD_33
K_WORLD_34 = SDL::K_WORLD_34
K_WORLD_35 = SDL::K_WORLD_35
K_WORLD_36 = SDL::K_WORLD_36
K_WORLD_37 = SDL::K_WORLD_37
K_WORLD_38 = SDL::K_WORLD_38
K_WORLD_39 = SDL::K_WORLD_39
K_WORLD_40 = SDL::K_WORLD_40
K_WORLD_41 = SDL::K_WORLD_41
K_WORLD_42 = SDL::K_WORLD_42
K_WORLD_43 = SDL::K_WORLD_43
K_WORLD_44 = SDL::K_WORLD_44
K_WORLD_45 = SDL::K_WORLD_45
K_WORLD_46 = SDL::K_WORLD_46
K_WORLD_47 = SDL::K_WORLD_47
K_WORLD_48 = SDL::K_WORLD_48
K_WORLD_49 = SDL::K_WORLD_49
K_WORLD_50 = SDL::K_WORLD_50
K_WORLD_51 = SDL::K_WORLD_51
K_WORLD_52 = SDL::K_WORLD_52
K_WORLD_53 = SDL::K_WORLD_53
K_WORLD_54 = SDL::K_WORLD_54
K_WORLD_55 = SDL::K_WORLD_55
K_WORLD_56 = SDL::K_WORLD_56
K_WORLD_57 = SDL::K_WORLD_57
K_WORLD_58 = SDL::K_WORLD_58
K_WORLD_59 = SDL::K_WORLD_59
K_WORLD_60 = SDL::K_WORLD_60
K_WORLD_61 = SDL::K_WORLD_61
K_WORLD_62 = SDL::K_WORLD_62
K_WORLD_63 = SDL::K_WORLD_63
K_WORLD_64 = SDL::K_WORLD_64
K_WORLD_65 = SDL::K_WORLD_65
K_WORLD_66 = SDL::K_WORLD_66
K_WORLD_67 = SDL::K_WORLD_67
K_WORLD_68 = SDL::K_WORLD_68
K_WORLD_69 = SDL::K_WORLD_69
K_WORLD_70 = SDL::K_WORLD_70
K_WORLD_71 = SDL::K_WORLD_71
K_WORLD_72 = SDL::K_WORLD_72
K_WORLD_73 = SDL::K_WORLD_73
K_WORLD_74 = SDL::K_WORLD_74
K_WORLD_75 = SDL::K_WORLD_75
K_WORLD_76 = SDL::K_WORLD_76
K_WORLD_77 = SDL::K_WORLD_77
K_WORLD_78 = SDL::K_WORLD_78
K_WORLD_79 = SDL::K_WORLD_79
K_WORLD_80 = SDL::K_WORLD_80
K_WORLD_81 = SDL::K_WORLD_81
K_WORLD_82 = SDL::K_WORLD_82
K_WORLD_83 = SDL::K_WORLD_83
K_WORLD_84 = SDL::K_WORLD_84
K_WORLD_85 = SDL::K_WORLD_85
K_WORLD_86 = SDL::K_WORLD_86
K_WORLD_87 = SDL::K_WORLD_87
K_WORLD_88 = SDL::K_WORLD_88
K_WORLD_89 = SDL::K_WORLD_89
K_WORLD_90 = SDL::K_WORLD_90
K_WORLD_91 = SDL::K_WORLD_91
K_WORLD_92 = SDL::K_WORLD_92
K_WORLD_93 = SDL::K_WORLD_93
K_WORLD_94 = SDL::K_WORLD_94
K_WORLD_95 = SDL::K_WORLD_95
K_KP0 = SDL::K_KP0   Numeric keypad symbols
K_KP1 = SDL::K_KP1
K_KP2 = SDL::K_KP2
K_KP3 = SDL::K_KP3
K_KP4 = SDL::K_KP4
K_KP5 = SDL::K_KP5
K_KP6 = SDL::K_KP6
K_KP7 = SDL::K_KP7
K_KP8 = SDL::K_KP8
K_KP9 = SDL::K_KP9
K_KP_PERIOD = SDL::K_KP_PERIOD
K_KP_DIVIDE = SDL::K_KP_DIVIDE
K_KP_MULTIPLY = SDL::K_KP_MULTIPLY
K_KP_MINUS = SDL::K_KP_MINUS
K_KP_PLUS = SDL::K_KP_PLUS
K_KP_ENTER = SDL::K_KP_ENTER
K_KP_EQUALS = SDL::K_KP_EQUALS
K_UP = SDL::K_UP   Arrows + Home/End pad
K_DOWN = SDL::K_DOWN
K_RIGHT = SDL::K_RIGHT
K_LEFT = SDL::K_LEFT
K_INSERT = SDL::K_INSERT
K_HOME = SDL::K_HOME
K_END = SDL::K_END
K_PAGEUP = SDL::K_PAGEUP
K_PAGEDOWN = SDL::K_PAGEDOWN
K_F1 = SDL::K_F1   Function keys
K_F2 = SDL::K_F2
K_F3 = SDL::K_F3
K_F4 = SDL::K_F4
K_F5 = SDL::K_F5
K_F6 = SDL::K_F6
K_F7 = SDL::K_F7
K_F8 = SDL::K_F8
K_F9 = SDL::K_F9
K_F10 = SDL::K_F10
K_F11 = SDL::K_F11
K_F12 = SDL::K_F12
K_F13 = SDL::K_F13
K_F14 = SDL::K_F14
K_F15 = SDL::K_F15
K_NUMLOCK = SDL::K_NUMLOCK   Key state modifier keys
K_CAPSLOCK = SDL::K_CAPSLOCK
K_SCROLLOCK = SDL::K_SCROLLOCK
K_RSHIFT = SDL::K_RSHIFT
K_LSHIFT = SDL::K_LSHIFT
K_RCTRL = SDL::K_RCTRL
K_LCTRL = SDL::K_LCTRL
K_RALT = SDL::K_RALT
K_LALT = SDL::K_LALT
K_RMETA = SDL::K_RMETA
K_LMETA = SDL::K_LMETA
K_LSUPER = SDL::K_LSUPER
K_RSUPER = SDL::K_RSUPER
K_MODE = SDL::K_MODE
K_HELP = SDL::K_HELP   Miscellaneous keys
K_PRINT = SDL::K_PRINT
K_SYSREQ = SDL::K_SYSREQ
K_BREAK = SDL::K_BREAK
K_MENU = SDL::K_MENU
K_POWER = SDL::K_POWER
K_EURO = SDL::K_EURO
K_LAST = SDL::K_LAST
SDL_EVENTS = [ActiveEvent, KeyDownEvent, KeyUpEvent,\ MouseMotionEvent,MouseDownEvent,MouseUpEvent,JoyAxisEvent,\ JoyBallEvent, JoyHatEvent,JoyDownEvent, JoyUpEvent,\ ResizeEvent, QuitEvent]   List of all Rubygame hardware event classes. *Do not modify!*

Public Class methods

Returns the name of the audio driver that SDL is using. This method opens the audio device if it is not open already.

May raise an SDLError if the audio device could not be opened.

[Source]

# File lib/rubygame/audio.rb, line 142
  def self.audio_driver
    open_audio
    return SDL.AudioDriverName
  end

Deinitializes and closes the audio device. If audio was not open, this method does nothing, and returns false. See also open_audio().

NOTE: The audio will be automatically closed when the program exits. You only need to close audio manually if you want to call open_audio with different settings.

Returns:true if the audio was open before this action.

[Source]

# File lib/rubygame/audio.rb, line 122
  def self.close_audio
    if audio_open?
      SDL::Mixer.CloseAudio()
      return true
    else
      return false
    end
  end

Disable key repeat, undoing the effect of enable_key_repeat.

[Source]

# File lib/rubygame/events.rb, line 74
  def self.disable_key_repeat
    result = SDL.EnableKeyRepeat( 0, 0 )

    if result != 0
      raise( Rubygame::SDLError,
             "Could not disable key repeat: #{SDL.GetError()}" )
    end

    return nil
  end

Enable key repeat, so that additional keyboard release and press events are automatically generated for as long as the key is held down. See also disable_key_repeat.

delay:how many seconds to wait before starting to repeat. Default is 0.5 seconds. (Numeric or :default, optional)
interval:how many seconds to wait in between repetitions after the first one. Default is 0.03 seconds. (Numeric or :default, optional)

[Source]

# File lib/rubygame/events.rb, line 37
  def self.enable_key_repeat( delay=:default, interval=:default )

    delay = if delay == :default
              SDL::DEFAULT_REPEAT_DELAY
            else
              delay.to_f
            end

    interval = if interval == :default
                 SDL::DEFAULT_REPEAT_INTERVAL
               else
                 interval.to_f
               end

    if delay < 0.001
      raise( ArgumentError,
             "delay must be at least 0.001 sec (got #{delay})" )
    end

    if interval < 0.001
      raise( ArgumentError,
             "interval must be at least 0.001 sec (got #{interval})" )
    end

    result = SDL.EnableKeyRepeat( (delay * 1000).to_i, (interval * 1000).to_i )

    if result != 0
      raise( Rubygame::SDLError,
             "Could not enable key repeat: #{SDL.GetError()}" )
    end

    return nil
  end

Retrieves all pending events from SDL’s event stack and converts them into Rubygame Event objects. Returns an Array of all the events, in the order they were read.

This method is used by the EventQueue class, so don’t call it if you are using EventQueue for event management! If you do, the EventQueue will not receive all the events, because they will have been removed from SDL’s event stack by this method.

However, if you aren’t using EventQueue, you can safely use this method to make your own event management system.

[Source]

# File lib/rubygame/event.rb, line 36
    def fetch_sdl_events
      deprecated("Rubygame.fetch_sdl_events", "3.0")
      events = []
      until( ( event = SDL::PollEvent() ).nil? )
        events << _convert_sdlevent(event)
      end
      return events
    end

Initialize Rubygame. This should be called soon after you require Rubygame, so that everything will work properly.

[Source]

# File lib/rubygame/main.rb, line 36
  def self.init
    if( SDL.Init(SDL::INIT_EVERYTHING) == 0 )
      SDL.EnableUNICODE(1)
    else
      raise Rubygame::SDLError, "Could not initialize SDL: #{SDL.GetError()}"
    end
  end

Converts a keyboard symbol (keysym) into a human-readable text string. If either Shift key was being pressed, alphanumeric or punctuation keys will be made uppercase or alternate, based on U.S. keyboard layout. E.g. “a” becomes “A”, “1” becomes “!”, and “/” becomes “?”.

[Source]

# File lib/rubygame/event.rb, line 140
        def Rubygame.key2str( sym, mods )
                if (mods.include? K_LSHIFT) or (mods.include? K_RSHIFT)
                        return (Rubygame::Key::KEY2UPPER[sym]\
                                or Rubygame::Key::KEY2ASCII[sym] or "")
                else
                        return (Rubygame::Key::KEY2LOWER[sym]\
                                or Rubygame::Key::KEY2ASCII[sym] or "")
                end
        end

Initializes the audio device using the given settings.

NOTE: Audio will be automatically opened when Rubygame::Sound or Rubygame::Music are first used. You only need to open audio manually if you want settings different from the default, or if you are using the older, deprecated Music and Sample classes from the Rubygame::Mixer module.

If audio is already open, this method has no effect, and returns false. If you want to change audio settings, you must close_audio() and then open it again.

options:A Hash of any of the following options. (Hash, optional)
   :frequency::  output sample rate in audio samples per second
                 (Hz). Affects the quality of the sound output, at
                 the expense of CPU usage. If omitted, the default
                 (22050) is used. The default is recommended for
                 most games.

   :channels::   output sound channels. Use 2 for stereo, 1 for mono.
                 If omitted, the default (2) is used.

   :buffer::     size of the sound buffer, in bytes. Must be a
                 power of 2 (e.g. 512, 1024, 2048). If omitted,
                 the default (1024) is used. If your game is
                 fast-paced, you may want to use a smaller value
                 to reduce audio delay, the time between when you
                 play a sound and when it is heard.
Returns:true if the audio was newly opened by this action, or false if it was already open before this action.
May raise:SDLError, if initialization fails. ArgumentError, if an invalid value is given for any option.

[Source]

# File lib/rubygame/audio.rb, line 63
  def self.open_audio( options={} )
    return false if audio_open?

    unless options.kind_of? Hash
      raise TypeError, "invalid options Hash: #{options.inspect}"
    end

    buff = (options[:buffer] or 1024)
    chan = (options[:channels] or 2)
    freq = (options[:frequency] or SDL::Mixer::DEFAULT_FREQUENCY)

    # In general, format should always be the default.
    frmt = SDL::Mixer::DEFAULT_FORMAT


    buff = if( buff <= 0 )
             raise ArgumentError, "buffer size must be positive (got #{buff})"
           elsif( buff & (buff - 1) != 0 )
             raise( ArgumentError, "buffer size must be a power of 2 "+
                    "(e.g. 512, 1024) (got #{buff})" )
           else
             buff.to_i
           end


    chan = if( chan != 1 && chan != 2 )
             raise( ArgumentError, 
                    "channels must be 1 (mono) or 2 (stereo) (got #{chan})" )
           else
             chan.to_i
           end


    freq = if( freq <= 0 )
             raise ArgumentError, "frequency must be positive (got #{freq})"
           else
             freq.to_i
           end

    result = SDL::Mixer.OpenAudio(freq, frmt, chan, buff)

    if( result < 0 )
      raise Rubygame::SDLError, "Could not open audio: #{SDL.GetError()}"
    end

    return true
  end

Quit Rubygame. This should be used before your program terminates, especially if you have been using a fullscreen Screen! (Otherwise, the desktop resolution might not revert to its previous setting on some platforms, and your users will be frustrated and confused!)

[Source]

# File lib/rubygame/main.rb, line 50
  def self.quit
    SDL.Quit
  end

[Validate]