class Cairo::Context

Public Instance Methods

shadow_mp(x, y, width, height, size, sd=nil) click to toggle source
# File lib/etti/monkeys/cairo-context.rb, line 5
def shadow_mp x, y, width, height, size, sd=nil
    sides = 0
    if sd.nil?
        sides = 15
    else
        sides += 1 if sd.include? 'l'
        sides += 2 if sd.include? 'r'
        sides += 4 if sd.include? 't'
        sides += 8 if sd.include? 'b'
    end

    # borders #
    # left
    if sides & 1 > 0
        pat = Cairo::LinearPattern.new x, y, x - size, y
        shadow_pattern_add_stopps pat
        self.rectangle x - size, y, size, height
        self.set_source pat
        self.fill
    end

    # right
    if sides & 2 > 0
        pat = Cairo::LinearPattern.new x + width, y, x + width + size, y
        shadow_pattern_add_stopps pat
        self.rectangle x + width, y, x + width + size, height
        self.set_source pat
        self.fill
    end

    # top
    if sides & 4 > 0
        pat = Cairo::LinearPattern.new x, y, x, y - size
        shadow_pattern_add_stopps pat
        self.rectangle x, y - size, width, size
        self.set_source pat
        self.fill
    end

    # bottom
    if sides & 8 > 0
        pat = Cairo::LinearPattern.new x, y + height, x, y + height + size
        shadow_pattern_add_stopps pat
        self.rectangle x, y + height, width, y + height + size
        self.set_source pat
        self.fill
    end

    # corners #
    # top left
    if sides & 5 > 0
        pat = Cairo::RadialPattern.new x, y, 0, x, y, size
        shadow_pattern_add_stopps pat
        self.rectangle x - size, y - size, size, size
        self.set_source(pat).fill
    end

    # top right
    if sides & 6 > 0
        pat = Cairo::RadialPattern.new x + width, y, 0, x + width, y, size
        shadow_pattern_add_stopps pat
        self.rectangle x + width, y - size, size, size
        self.set_source(pat).fill
    end

    # bottom left
    if sides & 9 > 0
        pat = Cairo::RadialPattern.new x, y + height, 0, x, y + height, size
        shadow_pattern_add_stopps pat
        self.rectangle x - size, y + height, size, size
        self.set_source(pat).fill
    end

    # bottom right
    if sides & 10 > 0
        pat = Cairo::RadialPattern.new x + width, y + height, 0, x + width, y + height, size
        shadow_pattern_add_stopps pat
        self.rectangle x + width, y + height, size, size
        self.set_source(pat).fill
    end
end

Private Instance Methods

shadow_pattern_add_stopps(pat) click to toggle source
# File lib/etti/monkeys/cairo-context.rb, line 88
def shadow_pattern_add_stopps pat
    pat.add_color_stop_rgba 0.0, 0.4, 0.4, 0.4, 0.6
    pat.add_color_stop_rgba 1.0, 1, 1, 1, 0
end