Permalink
Browse files

layer\!, clip\!, and transparent\! now all respect margins

  • Loading branch information...
1 parent 13e54dd commit 1b621db919dcd0dcd27b709c5591f7eae14d865d @austintaylor committed Feb 17, 2009
Showing with 13 additions and 58 deletions.
  1. +13 −58 lib/cairo_tools.rb
View
@@ -127,15 +127,16 @@ def load_image_and_scale(path, width, height)
def layer!
surface = @surface
+ t, r, b, l = @top_margin, @right_margin, @bottom_margin, @left_margin
dimensions @canvas_width, @canvas_height
- margin @top_margin, @right_margin, @bottom_margin, @left_margin
+ margin t, r, b, l
surface
end
- def paint_layer(layer)
+ def paint_layer(layer, a=1)
transform Cairo::Matrix.identity do
cr.set_source(Cairo::SurfacePattern.new(layer))
- cr.paint
+ cr.paint_with_alpha(a)
end
end
@@ -158,33 +159,17 @@ def draw_image(image, x=0, y=0, a=1)
end
def clip!
- i = self.class.new
- w, h = width, height
- pattern = Cairo::SurfacePattern.new(@surface)
clip = cr.copy_path
- i.instance_eval do
- dimensions w, h
- cr.append_path clip
- cr.clip
- cr.set_source(pattern)
- cr.paint
- end
- dimensions w, h
- cr.set_source(Cairo::SurfacePattern.new(i.surface))
- cr.paint
+ original = layer!
+ cr.append_path clip
+ cr.clip
+ paint_layer original
+ cr.reset_clip
end
- def transparent!(alpha)
- i = self.class.new
- w, h = width, height
- pattern = Cairo::SurfacePattern.new(@surface)
- i.instance_eval do
- dimensions w, h
- cr.set_source(pattern)
- cr.paint_with_alpha(alpha)
- end
- @surface = i.surface
- @cr = i.cr
+ def transparent!(a)
+ original = layer!
+ paint_layer original, a
end
def shadow(radius=3, alpha=1)
@@ -212,37 +197,7 @@ def load_image(path, x=0, y=0)
cr.set_source_pixbuf(image)
cr.source.matrix = Cairo::Matrix.identity.translate(x, y)
end
-
- def clip!
- i = self.class.new
- w, h = @canvas_width, @canvas_height
- pattern = Cairo::SurfacePattern.new(@surface)
- clip = cr.copy_path
- i.instance_eval do
- dimensions w, h
- cr.append_path clip
- cr.clip
- cr.set_source(pattern)
- cr.paint
- end
- dimensions w, h
- cr.set_source(Cairo::SurfacePattern.new(i.surface))
- cr.paint
- end
-
- def transparent!(alpha)
- i = self.class.new
- w, h = @canvas_width, @canvas_height
- pattern = Cairo::SurfacePattern.new(@surface)
- i.instance_eval do
- dimensions w, h
- cr.set_source(pattern)
- cr.paint_with_alpha(alpha)
- end
- @surface = i.surface
- @cr = i.cr
- end
-
+
def draw_image(image, x=0, y=0, a=1)
i = self.class.new
i.instance_eval do

0 comments on commit 1b621db

Please sign in to comment.