Class: Magick::Image::View::Rows

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/rmagick_internal.rb

Overview

Magick::Image::View::Rows

Instance Method Summary collapse

Constructor Details

#initialize(view, width, height, rows) ⇒ Rows

Returns a new instance of Rows.



1099
1100
1101
1102
1103
1104
# File 'lib/rmagick_internal.rb', line 1099

def initialize(view, width, height, rows)
  @view = view
  @width = width
  @height = height
  @rows = rows
end

Instance Method Details

#[](*args) ⇒ Object



1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
# File 'lib/rmagick_internal.rb', line 1106

def [](*args)
  cols(args)

  # Both View::Pixels and Magick::Pixel implement Observable
  if @unique
    pixels = @view[@rows[0] * @width + @cols[0]]
    pixels.add_observer(self)
  else
    pixels = View::Pixels.new
    each do |x|
      p = @view[x]
      p.add_observer(self)
      pixels << p
    end
  end
  pixels
end

#[]=(*args) ⇒ Object



1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
# File 'lib/rmagick_internal.rb', line 1124

def []=(*args)
  rv = args.delete_at(-1) # get rvalue
  unless rv.is_a?(Pixel) # must be a Pixel or a color name
    begin
      rv = Pixel.from_color(rv)
    rescue TypeError
      Kernel.raise TypeError, "cannot convert #{rv.class} into Pixel"
    end
  end
  cols(args)
  each { |x| @view[x] = rv.dup }
  changed
  notify_observers(self)
end

#update(pixel) ⇒ Object

A pixel has been modified. Tell the view.



1140
1141
1142
1143
1144
1145
# File 'lib/rmagick_internal.rb', line 1140

def update(pixel)
  changed
  notify_observers(self)
  pixel.delete_observer(self) # Don't need to hear again.
  nil
end