module EZDraw
Constants
- Black
- Blue
- Brown
- Cyan
- Gray
- Green
- Magenta
- None
- Red
- White
- Yellow
Public Class Methods
cleanup()
click to toggle source
# File lib/ezdraw.rb, line 69 def self.cleanup requires_init Font.cleanup Image.cleanup Window.cleanup SDL2.SDL_Quit @@inited = false nil end
default_font()
click to toggle source
# File lib/ezdraw.rb, line 56 def self.default_font requires_init @@default_font end
delay(msec)
click to toggle source
# File lib/ezdraw.rb, line 79 def self.delay(msec) requires_init SDL2.SDL_Delay(msec) nil end
init()
click to toggle source
# File lib/ezdraw.rb, line 38 def self.init return if inited if SDL2.SDL_WasInit(SDL2::SDL_INIT_VIDEO) == 0 err = SDL2.SDL_Init(SDL2::SDL_INIT_VIDEO) raise "SDL_Init: ${SDL2.SDL_GetError}" if err != 0 end Image.init Font.init @@inited = true # TODO: set font size more dynamically? @@default_font = EZDraw::Font.new(gem_relative_path("res/AnonymousPro-Regular.ttf"), 20) nil end
inited()
click to toggle source
# File lib/ezdraw.rb, line 61 def self.inited @@inited == true end
logger()
click to toggle source
# File lib/ezdraw.rb, line 24 def self.logger @@logger end
requires_init()
click to toggle source
# File lib/ezdraw.rb, line 65 def self.requires_init raise "EZDraw is not initialized. first call EZDraw.init" if not inited end
waitkey()
click to toggle source
this version cherry-picks keyboard events from the queue
# File lib/ezdraw.rb, line 96 def self.waitkey requires_init ev_p = FFI::MemoryPointer.new SDL2::SDL_Event, 1, false ev = SDL2::SDL_Event.new ev_p #cev = SDL2::SDL_CommonEvent.new ev_p loop do nev = SDL2.SDL_PeepEvents(ev_p, 1, SDL2::SDL_GETEVENT, SDL2::SDL_KEYDOWN, SDL2::SDL_KEYUP) raise "error: peepevents" if nev < 0 if nev == 0 SDL2.SDL_PumpEvents delay 1 next end #EZDraw.logger.debug("0x#{ev[:common][:type].to_s(16)}") if ev[:common][:type] == SDL2::SDL_KEYDOWN return SDL2.SDL_GetKeyName(ev[:key][:keysym][:keycode]).to_s end end end
Private Class Methods
gem_relative_path(path)
click to toggle source
auto-handles path sep
# File lib/ezdraw.rb, line 29 def self.gem_relative_path(path) gem_root = File.expand_path('..', File.dirname(__FILE__)) path = File.join(*(path.split("/"))) File.join(gem_root, path) end