Class: Processing::Window::Canvas

Inherits:
Object
  • Object
show all
Defined in:
lib/processing/window.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window) ⇒ Canvas



192
193
194
195
196
197
198
# File 'lib/processing/window.rb', line 192

def initialize(window)
  @image   = nil
  @painter = window.painter

  resize 1, 1
  painter.miter_limit = 10
end

Instance Attribute Details

#imageObject (readonly)

Returns the value of attribute image.



190
191
192
# File 'lib/processing/window.rb', line 190

def image
  @image
end

#painterObject (readonly)

Returns the value of attribute painter.



190
191
192
# File 'lib/processing/window.rb', line 190

def painter
  @painter
end

Instance Method Details

#resize(width, height, pixel_density = nil) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/processing/window.rb', line 200

def resize(width, height, pixel_density = nil)
  return false if width <= 0 || height <= 0

  return false if
    width         == @image&.width  &&
    height        == @image&.height &&
    pixel_density == @painter.pixel_density

  old_image   = @image
  old_painter = @painter
  cs          = old_image&.color_space || Rays::RGBA
  pd          = pixel_density || old_painter.pixel_density

  @image   = Rays::Image.new width, height, cs, pd
  @painter = @image.painter

  @painter.paint {image old_image} if old_image
  copy_painter old_painter, @painter

  GC.start
  return true
end