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.



890
891
892
893
894
895
# File 'lib/RMagick.rb', line 890

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

Instance Method Details

#[](*args) ⇒ Object



897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
# File 'lib/RMagick.rb', line 897

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



915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
# File 'lib/RMagick.rb', line 915

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
            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.



932
933
934
935
936
937
# File 'lib/RMagick.rb', line 932

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