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

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

Overview

Magick::Image::View::Rows

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Rows.



1079
1080
1081
1082
1083
1084
# File 'lib/RMagick.rb', line 1079

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

Instance Method Details

#[](*args) ⇒ Object



1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
# File 'lib/RMagick.rb', line 1086

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



1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
# File 'lib/RMagick.rb', line 1104

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.



1121
1122
1123
1124
1125
1126
# File 'lib/RMagick.rb', line 1121

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