Class: Processing::Window
- Inherits:
-
Reflex::Window
- Object
- Reflex::Window
- Processing::Window
- Defined in:
- lib/processing/window.rb
Defined Under Namespace
Classes: Canvas, CanvasView
Instance Attribute Summary collapse
-
#after_draw ⇒ Object
Returns the value of attribute after_draw.
-
#auto_resize ⇒ Object
Returns the value of attribute auto_resize.
-
#before_draw ⇒ Object
Returns the value of attribute before_draw.
-
#draw ⇒ Object
Returns the value of attribute draw.
-
#key_down ⇒ Object
Returns the value of attribute key_down.
-
#key_up ⇒ Object
Returns the value of attribute key_up.
-
#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.
-
#update_canvas ⇒ Object
Returns the value of attribute update_canvas.
Instance Method Summary collapse
- #canvas_image ⇒ Object
- #canvas_painter ⇒ Object
- #event ⇒ Object
-
#initialize(width = 500, height = 500, *args, **kwargs, &block) ⇒ Window
constructor
A new instance of Window.
- #on_canvas_draw(e) ⇒ Object
- #on_canvas_pointer(e) ⇒ Object
- #on_canvas_resize(e) ⇒ Object
- #on_canvas_update(e) ⇒ Object
- #on_change_pixel_density(pixel_density) ⇒ Object
- #on_draw(e) ⇒ Object
- #on_key(e) ⇒ Object
- #on_motion(e) ⇒ Object
- #on_resize(e) ⇒ Object
- #on_setup ⇒ Object
- #resize_canvas(width, height, pixel_density = nil, window_pixel_density: nil) ⇒ Object
- #start(&block) ⇒ Object
- #window_painter ⇒ Object
Constructor Details
#initialize(width = 500, height = 500, *args, **kwargs, &block) ⇒ Window
Returns a new instance of Window.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/processing/window.rb', line 32 def initialize(width = 500, height = 500, *args, **kwargs, &block) Processing.instance_variable_set :@window, self @events = [] @error = nil @auto_resize = true @canvas = Canvas.new self @canvas_view = add CanvasView.new name: :canvas super(*args, size: [width, height], **kwargs, &block) end |
Instance Attribute Details
#after_draw ⇒ Object
Returns the value of attribute after_draw.
24 25 26 |
# File 'lib/processing/window.rb', line 24 def after_draw @after_draw end |
#auto_resize ⇒ Object
Returns the value of attribute auto_resize.
30 31 32 |
# File 'lib/processing/window.rb', line 30 def auto_resize @auto_resize end |
#before_draw ⇒ Object
Returns the value of attribute before_draw.
24 25 26 |
# File 'lib/processing/window.rb', line 24 def before_draw @before_draw end |
#draw ⇒ Object
Returns the value of attribute draw.
24 25 26 |
# File 'lib/processing/window.rb', line 24 def draw @draw end |
#key_down ⇒ Object
Returns the value of attribute key_down.
24 25 26 |
# File 'lib/processing/window.rb', line 24 def key_down @key_down end |
#key_up ⇒ Object
Returns the value of attribute key_up.
24 25 26 |
# File 'lib/processing/window.rb', line 24 def key_up @key_up end |
#motion ⇒ Object
Returns the value of attribute motion.
24 25 26 |
# File 'lib/processing/window.rb', line 24 def motion @motion end |
#pointer_down ⇒ Object
Returns the value of attribute pointer_down.
24 25 26 |
# File 'lib/processing/window.rb', line 24 def pointer_down @pointer_down end |
#pointer_drag ⇒ Object
Returns the value of attribute pointer_drag.
24 25 26 |
# File 'lib/processing/window.rb', line 24 def pointer_drag @pointer_drag end |
#pointer_move ⇒ Object
Returns the value of attribute pointer_move.
24 25 26 |
# File 'lib/processing/window.rb', line 24 def pointer_move @pointer_move end |
#pointer_up ⇒ Object
Returns the value of attribute pointer_up.
24 25 26 |
# File 'lib/processing/window.rb', line 24 def pointer_up @pointer_up end |
#resize ⇒ Object
Returns the value of attribute resize.
24 25 26 |
# File 'lib/processing/window.rb', line 24 def resize @resize end |
#setup ⇒ Object
Returns the value of attribute setup.
24 25 26 |
# File 'lib/processing/window.rb', line 24 def setup @setup end |
#update ⇒ Object
Returns the value of attribute update.
24 25 26 |
# File 'lib/processing/window.rb', line 24 def update @update end |
#update_canvas ⇒ Object
Returns the value of attribute update_canvas.
24 25 26 |
# File 'lib/processing/window.rb', line 24 def update_canvas @update_canvas end |
Instance Method Details
#canvas_image ⇒ Object
44 45 46 |
# File 'lib/processing/window.rb', line 44 def canvas_image() @canvas.image end |
#canvas_painter ⇒ Object
48 49 50 |
# File 'lib/processing/window.rb', line 48 def canvas_painter() @canvas.painter end |
#event ⇒ Object
56 57 58 |
# File 'lib/processing/window.rb', line 56 def event() @events.last end |
#on_canvas_draw(e) ⇒ Object
112 113 114 115 |
# File 'lib/processing/window.rb', line 112 def on_canvas_draw(e) draw_canvas {call_block @draw, e} if @draw draw_screen e.painter end |
#on_canvas_pointer(e) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/processing/window.rb', line 117 def on_canvas_pointer(e) block = case e.action when :down then @pointer_down when :up, :cancel then @pointer_up when :move then e.drag? ? @pointer_drag : @pointer_move end draw_canvas {call_block block, e} if block end |
#on_canvas_resize(e) ⇒ Object
126 127 128 129 |
# File 'lib/processing/window.rb', line 126 def on_canvas_resize(e) resize_canvas e.width, e.height if @auto_resize draw_canvas {call_block @resize, e} if @resize end |
#on_canvas_update(e) ⇒ Object
107 108 109 110 |
# File 'lib/processing/window.rb', line 107 def on_canvas_update(e) call_block @update, e @canvas_view.redraw end |
#on_change_pixel_density(pixel_density) ⇒ Object
83 84 85 |
# File 'lib/processing/window.rb', line 83 def on_change_pixel_density(pixel_density) resize_canvas width, height, window_pixel_density: pixel_density end |
#on_draw(e) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/processing/window.rb', line 87 def on_draw(e) window_painter.pixel_density.tap do |pd| prev, @prev_pixel_density = @prev_pixel_density, pd on_change_pixel_density pd if prev && pd != prev end update_canvas_view end |
#on_key(e) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/processing/window.rb', line 95 def on_key(e) block = case e.action when :down then @key_down when :up then @key_up end draw_canvas {call_block block, e} if block end |
#on_motion(e) ⇒ Object
103 104 105 |
# File 'lib/processing/window.rb', line 103 def on_motion(e) draw_canvas {call_block @motion, e} if @motion end |
#on_resize(e) ⇒ Object
79 80 81 |
# File 'lib/processing/window.rb', line 79 def on_resize(e) on_canvas_resize e end |
#on_setup ⇒ Object
75 76 77 |
# File 'lib/processing/window.rb', line 75 def on_setup() call_block @setup, nil end |
#resize_canvas(width, height, pixel_density = nil, window_pixel_density: nil) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/processing/window.rb', line 67 def resize_canvas(width, height, pixel_density = nil, window_pixel_density: nil) @pixel_density = pixel_density if pixel_density if @canvas.resize width, height, pixel_density || @pixel_density || window_pixel_density @update_canvas.call canvas_image, canvas_painter if @update_canvas size width, height end end |
#start(&block) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/processing/window.rb', line 60 def start(&block) draw_canvas do block.call if block on_setup end end |
#window_painter ⇒ Object
52 53 54 |
# File 'lib/processing/window.rb', line 52 def window_painter() self.painter end |