lib/processing/window.rb in processing-0.5.13 vs lib/processing/window.rb in processing-0.5.14
- old
+ new
@@ -7,11 +7,11 @@
include Xot::Inspectable
attr_accessor :setup, :update, :draw, :resize,
:key_down, :key_up,
:pointer_down, :pointer_up, :pointer_move, :pointer_drag,
- :motion,
+ :move, :resize, :motion,
:before_draw, :after_draw, :update_canvas
attr_accessor :auto_resize
def initialize(width = 500, height = 500, *args, **kwargs, &block)
@@ -80,10 +80,18 @@
when :up then @key_up
end
draw_canvas {call_block block, e} if block
end
+ def on_move(e)
+ draw_canvas {call_block @move, e} if @move
+ end
+
+ def on_resize(e)
+ draw_canvas {call_block @resize, e} if @resize
+ end
+
def on_motion(e)
draw_canvas {call_block @motion, e} if @motion
end
def on_canvas_update(e)
@@ -109,12 +117,23 @@
resize_canvas e.width, e.height if @auto_resize
draw_canvas {call_block @resize, e} if @resize
end
def resize_canvas(width, height, pixel_density = nil, window_pixel_density: nil)
+ painting = canvas_painter.painting?
+ canvas_painter.__send__ :end_paint if painting
+
@pixel_density = pixel_density if pixel_density
- if @canvas.resize width, height, pixel_density || @pixel_density || window_pixel_density
+
+ resized =
+ begin
+ @canvas.resize width, height, @pixel_density || window_pixel_density
+ ensure
+ canvas_painter.__send__ :begin_paint if painting
+ end
+
+ if resized
@update_canvas.call canvas_image, canvas_painter if @update_canvas
size width, height
end
end
@@ -141,23 +160,28 @@
return 0, (wh - scaled_h) / 2, ww / cw
end
end
def draw_canvas(&block)
- begin_draw
+ drawing = self.drawing?
+ begin_draw unless drawing
block.call
ensure
- end_draw
+ end_draw unless drawing
end
def begin_draw()
canvas_painter.__send__ :begin_paint
@before_draw&.call
end
def end_draw()
@after_draw&.call
canvas_painter.__send__ :end_paint
+ end
+
+ def drawing?()
+ canvas_painter.painting?
end
def draw_screen(painter)
window_painter.image canvas_image
end