Class: SDL2::Application
- Inherits:
-
Engine::Engines
- Object
- Engine
- Engine::Engines
- SDL2::Application
- Defined in:
- lib/sdl2/application.rb
Instance Attribute Summary collapse
-
#loop_count_limit ⇒ Object
Returns the value of attribute loop_count_limit.
-
#poll_count_limit ⇒ Object
Returns the value of attribute poll_count_limit.
-
#window ⇒ Object
Returns the value of attribute window.
Attributes inherited from Engine::Engines
Attributes inherited from Engine
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Application
constructor
A new instance of Application.
- #loop(cnt = loop_count_limit, opts = {}) ⇒ Object
-
#poll(cnt = poll_count_limit) ⇒ Object
What makes an engine an “Application” is that it takes control of event polling.
- #quit ⇒ Object
Methods inherited from Engine::Engines
#current_engine, #handle_event, #paint_to
Methods inherited from Engine
#handle_event, #on, #on_handlers, #paint_to
Constructor Details
#initialize(opts = {}) ⇒ Application
Returns a new instance of Application.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sdl2/application.rb', line 13 def initialize(opts = {}) super(opts) title = opts[:title] || self.to_s x = opts[:x] || :CENTERED y = opts[:y] || :CENTERED w = opts[:w] || 640 h = opts[:h] || 480 flags = opts[:flags] || :SHOWN @window = Window.create(title, x, y, w, h, flags) @window.surface.fill_rect(@window.surface.rect, [0,0,0,SDL2::ALPHA_OPAQUE]) # Default ON handler for :QUIT events: self.on({type: :QUIT}) do |event| @quit_loop = true end end |
Instance Attribute Details
#loop_count_limit ⇒ Object
Returns the value of attribute loop_count_limit.
53 54 55 |
# File 'lib/sdl2/application.rb', line 53 def loop_count_limit @loop_count_limit end |
#poll_count_limit ⇒ Object
Returns the value of attribute poll_count_limit.
38 39 40 |
# File 'lib/sdl2/application.rb', line 38 def poll_count_limit @poll_count_limit end |
#window ⇒ Object
Returns the value of attribute window.
11 12 13 |
# File 'lib/sdl2/application.rb', line 11 def window @window end |
Instance Method Details
#loop(cnt = loop_count_limit, opts = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/sdl2/application.rb', line 55 def loop(cnt = loop_count_limit, opts ={}) @quit_loop = false times = 0 while (cnt.nil?) or ((times+=1) <= cnt) puts ">>> Loop##{times}" if SDL2::PrintDebug poll # Process input break if @quit_loop # Update the surface when we are painted to @window.update_surface if paint_to(@window.surface) puts "<<< Loop##{times}" if SDL2::PrintDebug delay(opts[:delay]) if opts.has_key? :delay end end |
#poll(cnt = poll_count_limit) ⇒ Object
What makes an engine an “Application” is that it takes control of event polling. There should only ever be one “Application”
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sdl2/application.rb', line 42 def poll(cnt = poll_count_limit) puts "Poll Start" if SDL2::PrintDebug times = 0 while (event = Event.poll()) and (cnt.nil? or (times+=1 < cnt)) puts "GOT: #{event.type}"if SDL2::PrintDebug handle_event(event) end puts "Poll End"if SDL2::PrintDebug end |
#quit ⇒ Object
33 34 35 36 |
# File 'lib/sdl2/application.rb', line 33 def quit() @window.free super() end |