Class: RubySketch::Window

Inherits:
Reflex::Window
  • Object
show all
Defined in:
lib/rubysketch/window.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width = 500, height = 500, *args, &block) ⇒ Window

Returns a new instance of Window



14
15
16
17
18
19
20
21
22
# File 'lib/rubysketch/window.rb', line 14

def initialize (width = 500, height = 500, *args, &block)
  @events      = []
  @auto_resize = true
  @error       = nil

  reset_canvas 1, 1

  super *args, size: [width, height], &block
end

Instance Attribute Details

#after_drawObject

Returns the value of attribute after_draw



6
7
8
# File 'lib/rubysketch/window.rb', line 6

def after_draw
  @after_draw
end

#auto_resizeObject

Returns the value of attribute auto_resize



10
11
12
# File 'lib/rubysketch/window.rb', line 10

def auto_resize
  @auto_resize
end

#before_drawObject

Returns the value of attribute before_draw



6
7
8
# File 'lib/rubysketch/window.rb', line 6

def before_draw
  @before_draw
end

#canvasObject (readonly)

Returns the value of attribute canvas



12
13
14
# File 'lib/rubysketch/window.rb', line 12

def canvas
  @canvas
end

#canvas_painterObject (readonly)

Returns the value of attribute canvas_painter



12
13
14
# File 'lib/rubysketch/window.rb', line 12

def canvas_painter
  @canvas_painter
end

#drawObject

Returns the value of attribute draw



6
7
8
# File 'lib/rubysketch/window.rb', line 6

def draw
  @draw
end

#keyObject

Returns the value of attribute key



6
7
8
# File 'lib/rubysketch/window.rb', line 6

def key
  @key
end

#motionObject

Returns the value of attribute motion



6
7
8
# File 'lib/rubysketch/window.rb', line 6

def motion
  @motion
end

#pointer_downObject

Returns the value of attribute pointer_down



6
7
8
# File 'lib/rubysketch/window.rb', line 6

def pointer_down
  @pointer_down
end

#pointer_dragObject

Returns the value of attribute pointer_drag



6
7
8
# File 'lib/rubysketch/window.rb', line 6

def pointer_drag
  @pointer_drag
end

#pointer_moveObject

Returns the value of attribute pointer_move



6
7
8
# File 'lib/rubysketch/window.rb', line 6

def pointer_move
  @pointer_move
end

#pointer_upObject

Returns the value of attribute pointer_up



6
7
8
# File 'lib/rubysketch/window.rb', line 6

def pointer_up
  @pointer_up
end

#resizeObject

Returns the value of attribute resize



6
7
8
# File 'lib/rubysketch/window.rb', line 6

def resize
  @resize
end

#setupObject

Returns the value of attribute setup



6
7
8
# File 'lib/rubysketch/window.rb', line 6

def setup
  @setup
end

#updateObject

Returns the value of attribute update



6
7
8
# File 'lib/rubysketch/window.rb', line 6

def update
  @update
end

Instance Method Details

#eventObject



31
32
33
# File 'lib/rubysketch/window.rb', line 31

def event ()
  @events.last
end

#on_draw(e) ⇒ Object



44
45
46
47
# File 'lib/rubysketch/window.rb', line 44

def on_draw (e)
  draw_canvas {call_block @draw, e} if @draw
  e.painter.image @canvas
end

#on_key(e) ⇒ Object



49
50
51
# File 'lib/rubysketch/window.rb', line 49

def on_key (e)
  draw_canvas {call_block @key, e} if @key
end

#on_motion(e) ⇒ Object



62
63
64
# File 'lib/rubysketch/window.rb', line 62

def on_motion (e)
  draw_canvas {call_block @motion, e} if @motion
end

#on_pointer(e) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/rubysketch/window.rb', line 53

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
  draw_canvas {call_block block, e} if block
end

#on_resize(e) ⇒ Object



66
67
68
69
# File 'lib/rubysketch/window.rb', line 66

def on_resize (e)
  reset_canvas e.width, e.height if @auto_resize
  draw_canvas {call_block @resize, e} if @resize
end

#on_setupObject



35
36
37
# File 'lib/rubysketch/window.rb', line 35

def on_setup ()
  call_block @setup, nil
end

#on_update(e) ⇒ Object



39
40
41
42
# File 'lib/rubysketch/window.rb', line 39

def on_update (e)
  call_block @update, e
  redraw
end

#start(&block) ⇒ Object



24
25
26
27
28
29
# File 'lib/rubysketch/window.rb', line 24

def start (&block)
  draw_canvas do
    block.call if block
    on_setup
  end
end