lib/rubysketch/processing.rb in rubysketch-0.3.16 vs lib/rubysketch/processing.rb in rubysketch-0.3.17

- old
+ new

@@ -706,27 +706,27 @@ # Touch object. # class Touch + # Identifier of each touch + # + attr_reader :id + # Horizontal position of touch # attr_reader :x # Vertical position of touch # attr_reader :y # @private - def initialize(x, y) - @x, @y = x, y + def initialize(id, x, y) + @id, @x, @y = id, x, y end - def id() - raise NotImplementedError - end - end# Touch # Camera object. # @@ -1589,11 +1589,11 @@ # # @return [nil] nil # def copy(img = nil, sx, sy, sw, sh, dx, dy, dw, dh) assertDrawing__ - src = img&.getInternal__ || @window__.canvas + src = img&.getInternal__ || @window__.canvas_image @painter__.image src, sx, sy, sw, sh, dx, dy, dw, dh end # Applies translation matrix to current transformation matrix. # @@ -1815,11 +1815,13 @@ @@context__ = self tmpdir__.tap {|dir| FileUtils.rm_r dir.to_s if dir.directory?} @window__ = window - init__ @window__.canvas, @window__.canvas_painter.paint {background 0.8} + init__( + @window__.canvas_image, + @window__.canvas_painter.paint {background 0.8}) @loop__ = true @redraw__ = false @frameCount__ = 0 @key__ = nil @@ -1827,16 +1829,17 @@ @keysPressed__ = Set.new @pointerPos__ = @pointerPrevPos__ = [0, 0] @pointersPressed__ = Set.new @touches__ = [] + @motionGravity__ = createVector 0, 0 @window__.before_draw = proc {beginDraw__} @window__.after_draw = proc {endDraw__} drawFrame = -> { - updateCanvas__ @window__.canvas, @window__.canvas_painter + updateCanvas__ @window__.canvas_image, @window__.canvas_painter begin push @drawBlock__.call if @drawBlock__ ensure pop @@ -1861,21 +1864,21 @@ end } updatePointerStates = -> event, pressed = nil { @pointerPos__ = event.pos.to_a - @touches__ = event.positions.map {|pos| Touch.new(*pos.to_a)} + @touches__ = event.pointers.map {|p| Touch.new(p.id, *p.pos.to_a)} if pressed != nil - set, type = @pointersPressed__, event.pointer_type + set, type = @pointersPressed__, event.type pressed ? set.add(type) : set.delete(type) end } @window__.key_down = proc do |e| updateKeyStates.call e, true @keyPressedBlock__&.call - @keyTypedBlock__&.call unless @key__.empty? + @keyTypedBlock__&.call if @key__ && !@key__.empty? end @window__.key_up = proc do |e| updateKeyStates.call e, false @keyReleasedBlock__&.call @@ -2043,10 +2046,10 @@ def resizeCanvas__(name, width, height, pixelDensity) raise '#{name}() must be called on startup or setup block' if @started__ @painter__.__send__ :end_paint @window__.__send__ :resize_canvas, width, height, pixelDensity - updateCanvas__ @window__.canvas, @window__.canvas_painter + updateCanvas__ @window__.canvas_image, @window__.canvas_painter @painter__.__send__ :begin_paint @window__.auto_resize = false end