[ruby-gnome2-doc-cvs] [Ruby-GNOME2 Project Website] update - tut-gtk2-dancr-rbcatut

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2013年 3月 27日 (水) 13:43:37 JST


-------------------------
REMOTE_ADDR = 70.49.48.128
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-dancr-rbcatut
-------------------------
@@ -497,6 +497,88 @@
 
     {{image_right("123-07-paint.png")}}
 
+    The ((<cairo_paint()|URL:http://www.cairographics.org/manual/cairo-cairo-t.html#cairo-paint>)) operation uses a mask that transfers the entire source to the destination. Some people consider this an infinitely large mask, and others consider it no mask; the result is the same. The related operation ((<cairo_paint_with_alpha()|URL:http://www.cairographics.org/manual/cairo-cairo-t.html#cairo-paint-with-alpha>)) similarly allows transfer of the full source to destination, but it transfers only the provided percentage of the color.
+
+     # Your code goes between the two dashed lines:
+     # -- your code - start ----------------------------------------- -s-
+     cr.set_source_rgb(0, 0, 0.9)
+     cr.paint(0.2)
+     # -- your code - end ------------------------------------------- -e-
+
+    :Paint In Ruby Cairo library
+        (12.3.1.2.4.A1){{br}}
+        In Ruby both cairo_paint() and cairo_paint_with_alpha() functions were replaced with a single cairo context's method ((*cr.paint(alpha=nil).*)) Invoking this method without the argument gives you the behaviour of "cairo_paint()", with the parameter you get the "cairo_paint_with_alpha()" behaviour. 
+
+        The above example is not a very interesting one. It merely paints the background, a.k.a. cairo drawing surface with a transparent light blue colour. You cannot even see the effect of this colour transparency. In Cairo library, you can use a transparent pen or paint-brush (i.e. source) by specifying the alpha foreground colour by setting it via cairo context's ((*set_source_rgba(red, green, blue, alpha)*)) rather than ((*set_source_rgb(red, green, blue)*)) method. 
+
+        Now, that you you know a bit about the transparency in Cairo, let's make the above example program a bit more interesting. We are going to write three versions. The first (1), without using the paint section. Second (2), by painting the background with transparent light blue colour, ant third (3), by painting the background transparently light greenish.
+
+        1. White background:
+         # Your code goes between the two dashed lines:
+         # -- your code - start ----------------------------------------- -s-
+         ### cr.set_source_rgb(0, 0, 0.9) # ......... commented out!
+         ### cr.paint(0.2) # ........................ commented out!
+         # -- your code - end ------------------------------------------- -e-
+
+        2. Transparent light blue background
+         # Your code goes between the two dashed lines:
+         # -- your code - start ----------------------------------------- -s-
+         cr.set_source_rgb(0, 0, 0.9)
+         cr.paint(0.2)
+         # -- your code - end ------------------------------------------- -e-
+
+        3. Transparent light green background
+         # Your code goes between the two dashed lines:
+         # -- your code - start ----------------------------------------- -s-
+         cr.set_source_rgb(0, 1, 0)
+         cr.paint(0.2)
+         # -- your code - end ------------------------------------------- -e-
+
+        Following is the entire program. Indeed, you have to write three versions, by modifying the paint sections as described above: 
+
+        {{image_right("1203-p7-paint-w-alpha-s1.png")}}
+
+         #!/usr/bin/env ruby
+         $: << '~/work/HikiLib'
+         require 'hiki2-gtk-w-cairo.rb'
+         include HikiGtk
+         class PaintTransparencyDemo < CairoWindow
+           def draw(cr, da)
+             #width, height = da.window.size
+
+             # making the example program more interesting ----- -s-
+             cr.scale(120, 120)
+             cr.set_source_rgba(1, 0, 1, 0.5)
+             cr.rectangle(0.25, 0.25, 0.5, 0.5)
+             cr.fill
+
+             cr.line_width = 0.05
+             cr.set_source_rgb(0, 1, 0)
+             cr.move_to(0, 0)
+             cr.rel_line_to(1.2, 1.2)
+             cr.stroke
+
+             cr.set_source_rgba(1, 0, 1, 0.5)
+             cr.rectangle(0.25+0.1, 0.25+0.3, 0.5, 0.5)
+             cr.fill
+             # making the example program more interesting ----- -e-
+
+             # Your code goes between the two dashed lines:
+             # -- your code - start ----------------------------------------- -s-    
+             cr.set_source_rgb(0, 0, 0.9)
+             cr.paint(0.2)
+             # -- your code - end ------------------------------------------- -e-
+           end
+         end # // EndOf class PaintTransparencyDemo
+         window = PaintTransparencyDemo.new("TextExtends Tut. Example")
+         window.show_all
+         Gtk.main
+
+
+
+
+
+
 {{br}}
 :Mask
     (12.3.1.2.5){{br}}




ruby-gnome2-cvs メーリングリストの案内
Back to archive index