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.



1138
1139
1140
1141
1142
1143
# File 'lib/rmagick_internal.rb', line 1138

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

Instance Method Details

#[](*args) ⇒ Object



1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
# File 'lib/rmagick_internal.rb', line 1145

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



1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
# File 'lib/rmagick_internal.rb', line 1163

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.



1179
1180
1181
1182
1183
1184
# File 'lib/rmagick_internal.rb', line 1179

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