Module: Rubydraw

Defined in:
lib/rubydraw.rb,
lib/rubydraw/keys.rb,
lib/rubydraw/text.rb,
lib/rubydraw/color.rb,
lib/rubydraw/flags.rb,
lib/rubydraw/image.rb,
lib/rubydraw/point.rb,
lib/rubydraw/sound.rb,
lib/rubydraw/events.rb,
lib/rubydraw/window.rb,
lib/rubydraw/surface.rb,
lib/rubydraw/rectangle.rb,
lib/rubydraw/sdl_error.rb,
lib/rubydraw/event_queue.rb,
lib/rubydraw/mouse_state.rb

Overview

Rubydraw is a high level game/graphics library, like Gosu or Rubygame, and is written completely in Ruby. Its only dependency is ruby-sdl-ffi, which it uses to access SDL functions. Also, thanks, Rubygame, for documenting your code (which, completely by coninsidence, also uses ruby-sdl-ffi), otherwise I wouldn’t have the slightest idea on how to use the base library’s undocumented code! You have been very helpful. :)

NOTE: I can’t get ruby-sdl-ffi (the library Rubydraw uses to access SDL) to work with Ruby 1.9.2, so I don’t know if it even does. If it does work, and/or you know how to make it work, I would appreciate it if you notify me. So basically, I can’t test anything with 1.9.2. Sorry for the inconvenience!

Defined Under Namespace

Modules: Events, Flags, Key, Mouse Classes: Color, EventQueue, Image, MouseState, Point, Rectangle, SDLError, Sound, Surface, Text, Window

Constant Summary collapse

Rect =

Basically just an alias to Rubydraw::Rectangle.

Rectangle
Ms =

A sort of alias to Rubydraw::Mouse

Mouse

Class Method Summary collapse

Class Method Details

.disable_key_repeatObject

See Rubydraw.set_key_repeat.



95
96
97
# File 'lib/rubydraw.rb', line 95

def self.disable_key_repeat
  set_key_repeat(false)
end

.enable_key_repeatObject

See Rubydraw.set_key_repeat.



90
91
92
# File 'lib/rubydraw.rb', line 90

def self.enable_key_repeat
  set_key_repeat(true)
end

.infoObject

Returns the current mouse condition.



25
26
27
28
# File 'lib/rubydraw/mouse_state.rb', line 25

def self.info
  state = SDL.GetMouseState
  MouseState.new(state[0], Point[state[1], state[2]])
end

.initialize_sdlObject

Initialize SDL.



46
47
48
49
50
51
52
53
54
# File 'lib/rubydraw.rb', line 46

def self.initialize_sdl
  if SDL::Init(SDL::INIT_EVERYTHING) != 0
    raise SDLError "Failed to initialize SDL: #{SDL.GetError}"
  end
  # Initialize fonts.
  if (SDL::TTF.WasInit == 0 and not SDL::TTF.Init == 0)
    raise SDLError "Failed to initialize SDL TTF: #{SDL.GetError}"
  end
end

.key_repeatObject

Return if key_repeat is enabled or not.



100
101
102
# File 'lib/rubydraw.rb', line 100

def self.key_repeat
  @@key_repeat
end

.positionObject

Returns the current mouse position.



31
32
33
# File 'lib/rubydraw/mouse_state.rb', line 31

def self.position
  info.position
end

.screen_dimensionsObject

Returns the screen size.



73
74
75
# File 'lib/rubydraw.rb', line 73

def self.screen_dimensions
  Point[screen_width, screen_height]
end

.screen_heightObject

Returns the screen height.



68
69
70
# File 'lib/rubydraw.rb', line 68

def self.screen_height
  vinfo.current_h
end

.screen_widthObject

Returns the screen width.



63
64
65
# File 'lib/rubydraw.rb', line 63

def self.screen_width
  vinfo.current_w
end

.set_key_repeat(new) ⇒ Object

Enable/disable key repeating. After this method is called, instances of Rubydraw::Events::KeyPressed wil be continually created, until the key is released.

Couldn’t get SDL.EnableKeyRepeat to work, so I implemented my own for the time being. This should be temporary, but no guarentees…



82
83
84
85
86
87
# File 'lib/rubydraw.rb', line 82

def self.set_key_repeat(new)
  unless new.is_a?(TrueClass) or new.is_a?(FalseClass)
    raise ArgumentError, "'new' must be boolean"
  end
  @@key_repeat = new
end