Class: Browser::Canvas::Data

Inherits:
Object
  • Object
show all
Includes:
Native::Wrapper
Defined in:
opal/browser/canvas/data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(canvas, x, y, width, height) ⇒ Data

Returns a new instance of Data.


24
25
26
27
28
29
30
31
32
# File 'opal/browser/canvas/data.rb', line 24

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

#heightObject (readonly)

Returns the value of attribute height


22
23
24
# File 'opal/browser/canvas/data.rb', line 22

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width


22
23
24
# File 'opal/browser/canvas/data.rb', line 22

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x


22
23
24
# File 'opal/browser/canvas/data.rb', line 22

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y


22
23
24
# File 'opal/browser/canvas/data.rb', line 22

def y
  @y
end

Class Method Details

.create(canvas, width, height) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'opal/browser/canvas/data.rb', line 4

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


38
39
40
# File 'opal/browser/canvas/data.rb', line 38

def [](index)
  `#@native.data[index]`
end

#[]=(index, value) ⇒ Object


42
43
44
# File 'opal/browser/canvas/data.rb', line 42

def []=(index, value)
  `#@native.data[index] = value`
end

#lengthObject Also known as: size


34
35
36
# File 'opal/browser/canvas/data.rb', line 34

def length
  `#@native.data.length`
end

#save(x = nil, y = nil) ⇒ Object


46
47
48
49
50
51
# File 'opal/browser/canvas/data.rb', line 46

def save(x = nil, y = nil)
  x ||= 0
  y ||= 0

  `#@canvas.putImageData(#@native, x, y)`
end

#save_to(canvas, x = nil, y = nil) ⇒ Object


53
54
55
56
57
58
# File 'opal/browser/canvas/data.rb', line 53

def save_to(canvas, x = nil, y = nil)
  x ||= 0
  y ||= 0

  `#{canvas.to_n}.putImageData(#@native, x, y)`
end