Class: Magick::Image::View::Rows
- Inherits:
-
Object
- Object
- Magick::Image::View::Rows
- Includes:
- Observable
- Defined in:
- lib/RMagick.rb
Overview
Magick::Image::View::Rows
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #[]=(*args) ⇒ Object
-
#initialize(view, width, height, rows) ⇒ Rows
constructor
A new instance of Rows.
-
#update(pixel) ⇒ Object
A pixel has been modified.
Constructor Details
#initialize(view, width, height, rows) ⇒ Rows
Returns a new instance of Rows.
1027 1028 1029 1030 1031 1032 |
# File 'lib/RMagick.rb', line 1027 def initialize(view, width, height, rows) @view = view @width = width @height = height @rows = rows end |
Instance Method Details
#[](*args) ⇒ Object
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 |
# File 'lib/RMagick.rb', line 1034 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
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 |
# File 'lib/RMagick.rb', line 1052 def []=(*args) rv = args.delete_at(-1) # get rvalue if ! 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) nil end |
#update(pixel) ⇒ Object
A pixel has been modified. Tell the view.
1069 1070 1071 1072 1073 1074 |
# File 'lib/RMagick.rb', line 1069 def update(pixel) changed notify_observers(self) pixel.delete_observer(self) # Don't need to hear again. nil end |