Class: Plushie::Canvas::Shape::CanvasImage

Inherits:
Data
  • Object
show all
Defined in:
lib/plushie/canvas/shape/canvas_image.rb

Overview

Canvas raster image shape with position, size, and optional rotation.

Examples:

CanvasImage.new(source: "icon.png", x: 10, y: 20, w: 64, h: 64)
CanvasImage.new(source: "photo.jpg", x: 0, y: 0, w: 200, h: 150, rotation: 0.5)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, x:, y:, w:, h:, rotation: nil, opacity: nil) ⇒ CanvasImage

Returns a new instance of CanvasImage.



12
13
14
# File 'lib/plushie/canvas/shape/canvas_image.rb', line 12

def initialize(source:, x:, y:, w:, h:, rotation: nil, opacity: nil)
  super
end

Instance Attribute Details

#hObject (readonly)

Returns the value of attribute h

Returns:

  • (Object)

    the current value of h



11
12
13
# File 'lib/plushie/canvas/shape/canvas_image.rb', line 11

def h
  @h
end

#opacityObject (readonly)

Returns the value of attribute opacity

Returns:

  • (Object)

    the current value of opacity



11
12
13
# File 'lib/plushie/canvas/shape/canvas_image.rb', line 11

def opacity
  @opacity
end

#rotationObject (readonly)

Returns the value of attribute rotation

Returns:

  • (Object)

    the current value of rotation



11
12
13
# File 'lib/plushie/canvas/shape/canvas_image.rb', line 11

def rotation
  @rotation
end

#sourceObject (readonly)

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



11
12
13
# File 'lib/plushie/canvas/shape/canvas_image.rb', line 11

def source
  @source
end

#wObject (readonly)

Returns the value of attribute w

Returns:

  • (Object)

    the current value of w



11
12
13
# File 'lib/plushie/canvas/shape/canvas_image.rb', line 11

def w
  @w
end

#xObject (readonly)

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



11
12
13
# File 'lib/plushie/canvas/shape/canvas_image.rb', line 11

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y

Returns:

  • (Object)

    the current value of y



11
12
13
# File 'lib/plushie/canvas/shape/canvas_image.rb', line 11

def y
  @y
end

Instance Method Details

#[](key) ⇒ Object

Backward-compatible hash-style access.



17
# File 'lib/plushie/canvas/shape/canvas_image.rb', line 17

def [](key) = to_wire[key]

#to_wireHash

Returns wire-ready shape map.

Returns:

  • (Hash)

    wire-ready shape map



20
21
22
23
24
25
# File 'lib/plushie/canvas/shape/canvas_image.rb', line 20

def to_wire
  h = {type: "image", source: source, x: x, y: y, w: w, h: self.h}
  h[:rotation] = rotation if rotation
  h[:opacity] = opacity if opacity
  h
end