Module: EZDraw
- Defined in:
- lib/ezdraw.rb
Defined Under Namespace
Modules: DSL
Classes: Font, Image, Window
Constant Summary
collapse
- White =
[0xff, 0xff, 0xff, 0xff].freeze
- Black =
[0x00, 0x00, 0x00, 0xff].freeze
- Gray =
[0x88, 0x88, 0x88, 0xff].freeze
- Red =
[0xff, 0x00, 0x00, 0xff].freeze
- Green =
[0x00, 0xff, 0x00, 0xff].freeze
- Blue =
[0x00, 0x00, 0xff, 0xff].freeze
- Yellow =
[0xff, 0xff, 0x00, 0xff].freeze
- Magenta =
[0xff, 0x00, 0xff, 0xff].freeze
- Cyan =
[0x00, 0xff, 0xff, 0xff].freeze
- Brown =
[0xa5, 0x2a, 0x2a, 0xff].freeze
- None =
[0x00, 0x00, 0x00, 0x00].freeze
- @@logger =
Logger.new(STDERR)
- @@inited =
false
Class Method Summary
collapse
Class Method Details
.default_font ⇒ Object
56
57
58
59
|
# File 'lib/ezdraw.rb', line 56
def self.default_font
requires_init
@@default_font
end
|
.delay(msec) ⇒ Object
79
80
81
82
83
|
# File 'lib/ezdraw.rb', line 79
def self.delay(msec)
requires_init
SDL2.SDL_Delay(msec)
nil
end
|
.init ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# 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
@@default_font = EZDraw::Font.new(gem_relative_path("res/AnonymousPro-Regular.ttf"), 20)
nil
end
|
.inited ⇒ Object
61
62
63
|
# File 'lib/ezdraw.rb', line 61
def self.inited
@@inited == true
end
|
.logger ⇒ Object
24
25
26
|
# File 'lib/ezdraw.rb', line 24
def self.logger
@@logger
end
|
.requires_init ⇒ Object
65
66
67
|
# File 'lib/ezdraw.rb', line 65
def self.requires_init
raise "EZDraw is not initialized. first call EZDraw.init" if not inited
end
|
.waitkey ⇒ Object
this version cherry-picks keyboard events from the queue
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# 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
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
if ev[:common][:type] == SDL2::SDL_KEYDOWN
return SDL2.SDL_GetKeyName(ev[:key][:keysym][:keycode]).to_s
end
end
end
|