Class: Pixelflut::App
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- Pixelflut::App
- Defined in:
- lib/pixelflut/app.rb
Defined Under Namespace
Classes: Configuration
Class Method Summary collapse
Instance Method Summary collapse
- #button_down(id) ⇒ Object
- #close ⇒ Object
- #draw ⇒ Object
-
#initialize(configuration) ⇒ App
constructor
A new instance of App.
- #log(*args) ⇒ Object
- #needs_cursor? ⇒ Boolean
- #needs_redraw? ⇒ Boolean
- #reset! ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(configuration) ⇒ App
Returns a new instance of App.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pixelflut/app.rb', line 19 def initialize(configuration) if configuration.fullscreen super(configuration.width || Gosu.screen_width, configuration.height || Gosu.screen_height, fullscreen: true) else super(configuration.width || 800, configuration.height || 600) end Process.setproctitle('pxflut') @image = TextImage.new(width, height) @server = Server.new(@image, configuration.server) log(self.caption = "Pixelflut@#{configuration.server.host}:#{configuration.server.port}") log(configuration.server) reset! end |
Class Method Details
.run(configuration = Configuration.default) ⇒ Object
15 16 17 |
# File 'lib/pixelflut/app.rb', line 15 def self.run(configuration = Configuration.default) new(configuration).show end |
Instance Method Details
#button_down(id) ⇒ Object
57 58 59 60 61 |
# File 'lib/pixelflut/app.rb', line 57 def (id) return close! if Gosu::Button::KbEscape == id return reset! if Gosu::Button::KbSpace == id return log("connections: #{@server.connection_count}") if Gosu::Button::KbC == id end |
#close ⇒ Object
63 64 65 |
# File 'lib/pixelflut/app.rb', line 63 def close close! end |
#draw ⇒ Object
48 49 50 |
# File 'lib/pixelflut/app.rb', line 48 def draw (@draw_image ||= Gosu::Image.new(@image.changed, tileable: true, retro: true)).draw(0, 0, 0) end |
#log(*args) ⇒ Object
52 53 54 55 |
# File 'lib/pixelflut/app.rb', line 52 def log(*args) print("[#{Time.now}] ") puts(*args) end |
#needs_cursor? ⇒ Boolean
71 72 73 |
# File 'lib/pixelflut/app.rb', line 71 def needs_cursor? false end |
#needs_redraw? ⇒ Boolean
67 68 69 |
# File 'lib/pixelflut/app.rb', line 67 def needs_redraw? @draw_image.nil? end |
#reset! ⇒ Object
38 39 40 41 |
# File 'lib/pixelflut/app.rb', line 38 def reset! @image.clear log("clean image: #{@image.width}x#{@image.height}") end |
#show ⇒ Object
33 34 35 36 |
# File 'lib/pixelflut/app.rb', line 33 def show @server.run super end |
#update ⇒ Object
43 44 45 46 |
# File 'lib/pixelflut/app.rb', line 43 def update # self.caption = @image.changes @draw_image = nil unless @image.changes.zero? end |