Class: Browser::Canvas::Data
- Includes:
- Native::Wrapper
- Defined in:
- opal/browser/canvas/data.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
- #[](index) ⇒ Object
- #[]=(index, value) ⇒ Object
-
#initialize(canvas, x, y, width, height) ⇒ Data
constructor
A new instance of Data.
- #length ⇒ Object (also: #size)
- #save(x = nil, y = nil) ⇒ Object
- #save_to(canvas, x = nil, y = nil) ⇒ Object
Constructor Details
#initialize(canvas, x, y, width, height) ⇒ Data
Returns a new instance of Data.
25 26 27 28 29 30 31 32 33 |
# File 'opal/browser/canvas/data.rb', line 25 def initialize(canvas, x, y, width, height) @canvas = canvas.to_n @x = x @y = y @width = width @height = height super(`#@canvas.getImageData(x, y, width, height)`) end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
23 24 25 |
# File 'opal/browser/canvas/data.rb', line 23 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
23 24 25 |
# File 'opal/browser/canvas/data.rb', line 23 def width @width end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
23 24 25 |
# File 'opal/browser/canvas/data.rb', line 23 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
23 24 25 |
# File 'opal/browser/canvas/data.rb', line 23 def y @y end |
Class Method Details
.create(canvas, width, height) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'opal/browser/canvas/data.rb', line 5 def self.create(canvas, width, height) data = allocate data.instance_eval { @canvas = canvas.to_a @x = 0 @y = 0 @width = width @height = height @native = `#{canvas.to_n}.createImageData(width, height)` } data end |
Instance Method Details
#[](index) ⇒ Object
39 40 41 |
# File 'opal/browser/canvas/data.rb', line 39 def [](index) `#@native.data[index]` end |
#[]=(index, value) ⇒ Object
43 44 45 |
# File 'opal/browser/canvas/data.rb', line 43 def []=(index, value) `#@native.data[index] = value` end |
#length ⇒ Object Also known as: size
35 36 37 |
# File 'opal/browser/canvas/data.rb', line 35 def length `#@native.data.length` end |
#save(x = nil, y = nil) ⇒ Object
47 48 49 50 51 52 |
# File 'opal/browser/canvas/data.rb', line 47 def save(x = nil, y = nil) x ||= 0 y ||= 0 `#@canvas.putImageData(#@native, x, y)` end |
#save_to(canvas, x = nil, y = nil) ⇒ Object
54 55 56 57 58 59 |
# File 'opal/browser/canvas/data.rb', line 54 def save_to(canvas, x = nil, y = nil) x ||= 0 y ||= 0 `#{canvas.to_n}.putImageData(#@native, x, y)` end |