Class: RubySketch::Window
- Inherits:
-
Reflex::Window
- Object
- Reflex::Window
- RubySketch::Window
- Defined in:
- lib/rubysketch/window.rb
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.
-
#canvas_image ⇒ Object
readonly
Returns the value of attribute canvas_image.
-
#canvas_painter ⇒ Object
readonly
Returns the value of attribute canvas_painter.
-
#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.
Instance Method Summary collapse
- #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_draw(e) ⇒ Object
- #on_key(e) ⇒ Object
- #on_motion(e) ⇒ Object
- #on_resize(e) ⇒ Object
- #on_setup ⇒ Object
- #start(&block) ⇒ Object
Constructor Details
#initialize(width = 500, height = 500, *args, **kwargs, &block) ⇒ Window
Returns a new instance of Window.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/rubysketch/window.rb', line 165 def initialize(width = 500, height = 500, *args, **kwargs, &block) RubySketch.instance_variable_set :@window, self @canvas_image = @canvas_painter = nil @events = [] @auto_resize = true @error = nil painter.miter_limit = 10 resize_canvas 1, 1 @canvas_view = add Reflex::View.new {|v| v.on(:update) {|e| on_canvas_update e} v.on(:draw) {|e| on_canvas_draw e} v.on(:pointer) {|e| on_canvas_pointer e} v.on(:resize) {|e| on_canvas_resize e} } add VirtualKey::View.new super(*args, size: [width, height], **kwargs, &block) end |
Instance Attribute Details
#after_draw ⇒ Object
Returns the value of attribute after_draw.
156 157 158 |
# File 'lib/rubysketch/window.rb', line 156 def after_draw @after_draw end |
#auto_resize ⇒ Object
Returns the value of attribute auto_resize.
161 162 163 |
# File 'lib/rubysketch/window.rb', line 161 def auto_resize @auto_resize end |
#before_draw ⇒ Object
Returns the value of attribute before_draw.
156 157 158 |
# File 'lib/rubysketch/window.rb', line 156 def before_draw @before_draw end |
#canvas_image ⇒ Object (readonly)
Returns the value of attribute canvas_image.
163 164 165 |
# File 'lib/rubysketch/window.rb', line 163 def canvas_image @canvas_image end |
#canvas_painter ⇒ Object (readonly)
Returns the value of attribute canvas_painter.
163 164 165 |
# File 'lib/rubysketch/window.rb', line 163 def canvas_painter @canvas_painter end |
#draw ⇒ Object
Returns the value of attribute draw.
156 157 158 |
# File 'lib/rubysketch/window.rb', line 156 def draw @draw end |
#key_down ⇒ Object
Returns the value of attribute key_down.
156 157 158 |
# File 'lib/rubysketch/window.rb', line 156 def key_down @key_down end |
#key_up ⇒ Object
Returns the value of attribute key_up.
156 157 158 |
# File 'lib/rubysketch/window.rb', line 156 def key_up @key_up end |
#motion ⇒ Object
Returns the value of attribute motion.
156 157 158 |
# File 'lib/rubysketch/window.rb', line 156 def motion @motion end |
#pointer_down ⇒ Object
Returns the value of attribute pointer_down.
156 157 158 |
# File 'lib/rubysketch/window.rb', line 156 def pointer_down @pointer_down end |
#pointer_drag ⇒ Object
Returns the value of attribute pointer_drag.
156 157 158 |
# File 'lib/rubysketch/window.rb', line 156 def pointer_drag @pointer_drag end |
#pointer_move ⇒ Object
Returns the value of attribute pointer_move.
156 157 158 |
# File 'lib/rubysketch/window.rb', line 156 def pointer_move @pointer_move end |
#pointer_up ⇒ Object
Returns the value of attribute pointer_up.
156 157 158 |
# File 'lib/rubysketch/window.rb', line 156 def pointer_up @pointer_up end |
#resize ⇒ Object
Returns the value of attribute resize.
156 157 158 |
# File 'lib/rubysketch/window.rb', line 156 def resize @resize end |
#setup ⇒ Object
Returns the value of attribute setup.
156 157 158 |
# File 'lib/rubysketch/window.rb', line 156 def setup @setup end |
#update ⇒ Object
Returns the value of attribute update.
156 157 158 |
# File 'lib/rubysketch/window.rb', line 156 def update @update end |
Instance Method Details
#event ⇒ Object
196 197 198 |
# File 'lib/rubysketch/window.rb', line 196 def event() @events.last end |
#on_canvas_draw(e) ⇒ Object
229 230 231 232 |
# File 'lib/rubysketch/window.rb', line 229 def on_canvas_draw(e) draw_canvas {call_block @draw, e} if @draw e.painter.image @canvas_image end |
#on_canvas_pointer(e) ⇒ Object
234 235 236 237 238 239 240 241 |
# File 'lib/rubysketch/window.rb', line 234 def on_canvas_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_canvas_resize(e) ⇒ Object
243 244 245 246 |
# File 'lib/rubysketch/window.rb', line 243 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
224 225 226 227 |
# File 'lib/rubysketch/window.rb', line 224 def on_canvas_update(e) call_block @update, e @canvas_view.redraw end |
#on_draw(e) ⇒ Object
208 209 210 |
# File 'lib/rubysketch/window.rb', line 208 def on_draw(e) update_canvas_view end |
#on_key(e) ⇒ Object
212 213 214 215 216 217 218 |
# File 'lib/rubysketch/window.rb', line 212 def on_key(e) block = case e.type when :down then @key_down when :up then @key_up end draw_canvas {call_block block, e} if block end |
#on_motion(e) ⇒ Object
220 221 222 |
# File 'lib/rubysketch/window.rb', line 220 def on_motion(e) draw_canvas {call_block @motion, e} if @motion end |
#on_resize(e) ⇒ Object
204 205 206 |
# File 'lib/rubysketch/window.rb', line 204 def on_resize(e) on_canvas_resize e end |
#on_setup ⇒ Object
200 201 202 |
# File 'lib/rubysketch/window.rb', line 200 def on_setup() call_block @setup, nil end |
#start(&block) ⇒ Object
189 190 191 192 193 194 |
# File 'lib/rubysketch/window.rb', line 189 def start(&block) draw_canvas do block.call if block on_setup end end |