Class: RubySketch::Window
- Inherits:
-
Reflex::Window
- Object
- Reflex::Window
- RubySketch::Window
- Defined in:
- lib/rubysketch/window.rb
Instance Attribute Summary collapse
-
#auto_resize ⇒ Object
Returns the value of attribute auto_resize.
-
#canvas ⇒ Object
readonly
Returns the value of attribute canvas.
-
#canvas_painter ⇒ Object
readonly
Returns the value of attribute canvas_painter.
-
#draw ⇒ Object
Returns the value of attribute draw.
-
#key ⇒ Object
Returns the value of attribute key.
-
#motion ⇒ Object
Returns the value of attribute motion.
-
#pointer_down ⇒ Object
Returns the value of attribute pointer_down.
-
#pointer_drag ⇒ Object
Returns the value of attribute pointer_drag.
-
#pointer_move ⇒ Object
Returns the value of attribute pointer_move.
-
#pointer_up ⇒ Object
Returns the value of attribute pointer_up.
-
#resize ⇒ Object
Returns the value of attribute resize.
-
#setup ⇒ Object
Returns the value of attribute setup.
-
#update ⇒ Object
Returns the value of attribute update.
Instance Method Summary collapse
- #event ⇒ Object
-
#initialize(width = 500, height = 500, *args, &block) ⇒ Window
constructor
A new instance of Window.
- #on_draw(e) ⇒ Object
- #on_key(e) ⇒ Object
- #on_motion(e) ⇒ Object
- #on_pointer(e) ⇒ Object
- #on_resize(e) ⇒ Object
- #on_setup ⇒ Object
- #on_update(e) ⇒ Object
- #start(&block) ⇒ Object
Constructor Details
#initialize(width = 500, height = 500, *args, &block) ⇒ Window
Returns a new instance of Window.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rubysketch/window.rb', line 13 def initialize (width = 500, height = 500, *args, &block) @events = [] @auto_resize = true @error = nil reset_canvas 1, 1 super *args, size: [width, height] do |_| start &block if block end end |
Instance Attribute Details
#auto_resize ⇒ Object
Returns the value of attribute auto_resize.
9 10 11 |
# File 'lib/rubysketch/window.rb', line 9 def auto_resize @auto_resize end |
#canvas ⇒ Object (readonly)
Returns the value of attribute canvas.
11 12 13 |
# File 'lib/rubysketch/window.rb', line 11 def canvas @canvas end |
#canvas_painter ⇒ Object (readonly)
Returns the value of attribute canvas_painter.
11 12 13 |
# File 'lib/rubysketch/window.rb', line 11 def canvas_painter @canvas_painter end |
#draw ⇒ Object
Returns the value of attribute draw.
6 7 8 |
# File 'lib/rubysketch/window.rb', line 6 def draw @draw end |
#key ⇒ Object
Returns the value of attribute key.
6 7 8 |
# File 'lib/rubysketch/window.rb', line 6 def key @key end |
#motion ⇒ Object
Returns the value of attribute motion.
6 7 8 |
# File 'lib/rubysketch/window.rb', line 6 def motion @motion end |
#pointer_down ⇒ Object
Returns the value of attribute pointer_down.
6 7 8 |
# File 'lib/rubysketch/window.rb', line 6 def pointer_down @pointer_down end |
#pointer_drag ⇒ Object
Returns the value of attribute pointer_drag.
6 7 8 |
# File 'lib/rubysketch/window.rb', line 6 def pointer_drag @pointer_drag end |
#pointer_move ⇒ Object
Returns the value of attribute pointer_move.
6 7 8 |
# File 'lib/rubysketch/window.rb', line 6 def pointer_move @pointer_move end |
#pointer_up ⇒ Object
Returns the value of attribute pointer_up.
6 7 8 |
# File 'lib/rubysketch/window.rb', line 6 def pointer_up @pointer_up end |
#resize ⇒ Object
Returns the value of attribute resize.
6 7 8 |
# File 'lib/rubysketch/window.rb', line 6 def resize @resize end |
#setup ⇒ Object
Returns the value of attribute setup.
6 7 8 |
# File 'lib/rubysketch/window.rb', line 6 def setup @setup end |
#update ⇒ Object
Returns the value of attribute update.
6 7 8 |
# File 'lib/rubysketch/window.rb', line 6 def update @update end |
Instance Method Details
#event ⇒ Object
32 33 34 |
# File 'lib/rubysketch/window.rb', line 32 def event () @events.last end |
#on_draw(e) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/rubysketch/window.rb', line 45 def on_draw (e) @canvas_painter.paint do |painter| call_block @draw, e, painter end e.painter.image @canvas end |
#on_key(e) ⇒ Object
52 53 54 |
# File 'lib/rubysketch/window.rb', line 52 def on_key (e) call_block @key, e end |
#on_motion(e) ⇒ Object
65 66 67 |
# File 'lib/rubysketch/window.rb', line 65 def on_motion (e) call_block @motion, e end |
#on_pointer(e) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/rubysketch/window.rb', line 56 def on_pointer (e) block = case e.type when :down then @pointer_down when :up then @pointer_up when :move then e.drag? ? @pointer_drag : @pointer_move end call_block block, e if block end |
#on_resize(e) ⇒ Object
69 70 71 72 |
# File 'lib/rubysketch/window.rb', line 69 def on_resize (e) reset_canvas e.width, e.height if @auto_resize call_block @resize, e end |
#on_setup ⇒ Object
36 37 38 |
# File 'lib/rubysketch/window.rb', line 36 def on_setup () call_block @setup, nil end |
#on_update(e) ⇒ Object
40 41 42 43 |
# File 'lib/rubysketch/window.rb', line 40 def on_update (e) call_block @update, e redraw end |
#start(&block) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/rubysketch/window.rb', line 25 def start (&block) @canvas_painter.paint do |_| block.call if block on_setup end end |