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

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2013年 4月 3日 (水) 12:23:33 JST


-------------------------
REMOTE_ADDR = 70.49.48.128
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-dancr-rbcatut-dwc
-------------------------
@@ -205,19 +205,58 @@
 
 
 {{br}}
-:Gradients example
+:Gradient example
     (12.3.2.1.2){{br}}
 
     {{br}}
     Gradients describe a progression of colors by setting a start and stop reference location and a series of "stops" along the way. Linear gradients are built from two points which pass through parallel lines to define the start and stop locations. Radial gradients are also built from two points, but each has an associated radius of the circle on which to define the start and stop locations. Stops are added to the gradient with cairo_add_color_stop_rgb() and cairo_add_color_stop_rgba() which take a color like cairo_set_source_rgb*(), as well as an offset to indicate where it lies between the reference locations. The colors between adjacent stops are averaged over space to form a smooth blend. Finally, the behavior beyond the reference locations can be controlled with cairo_set_extend().
 
-     radpat = cairo_pattern_create_radial (0.25, 0.25, 0.1,  0.5, 0.5, 0.5);
-     cairo_pattern_add_color_stop_rgb (radpat, 0,  1.0, 0.8, 0.8);
-     cairo_pattern_add_color_stop_rgb (radpat, 1,  0.9, 0.0, 0.0);
-     		o o o
 
+    {{image_right("1203-p10-81-setsrcgradient-nonGtkCr-120:120x120.png")}}
+
+# FILE:	1203-p10-81-00-00-00-setsrcgradient-nonGtkCr-dpl01.rb
+
+     #!/usr/bin/env ruby
+     $: << '~/work/HikiLib'
+     require 'hiki2-gtk-w-cairo.rb'
+     include HikiGtk
+     
+     # Create cairo context for image surface
+     surface = Cairo::ImageSurface.new(120, 120)
+     cr = Cairo::Context.new(surface)
+     cr.scale(120, 120)		# Examples are in 1x1 coordinate space
+     
+     # -- Your cairo code starts here -------------- -s-
+     radpat = Cairo::RadialPattern.new(0.25, 0.25, 0.1,  0.5, 0.5, 0.5)
+     radpat.add_color_stop_rgb(0,  1.0, 0.8, 0.8)
+     radpat.add_color_stop_rgb(1,  0.9, 0.0, 0.0)
+     
+     1.upto(9) do |i|
+       1.upto(9) do |j|
+         cr.rectangle(i/10.0 - 0.04, j/10.0 - 0.04, 0.08, 0.08)
+       end
+     end
+     cr.set_source(radpat)
+     cr.fill
+     
+     linpat = Cairo::LinearPattern.new(0.25, 0.35, 0.75, 0.65)
+     linpat.add_color_stop_rgba(0.00,  1, 1, 1, 0)
+     linpat.add_color_stop_rgba(0.25,  0, 1, 0, 0.5)
+     linpat.add_color_stop_rgba(0.50,  1, 1, 1, 0)
+     linpat.add_color_stop_rgba(0.75,  0, 0, 1, 0.5)
+     linpat.add_color_stop_rgba(1.00,  1, 1, 1, 0)
+     
+     cr.rectangle(0.0, 0.0, 1, 1)
+     cr.set_source(linpat)
+     cr.fill
+     
+     # -- Your cairo code ends here ---------------- -e-
+     cr.target.write_to_png("setsourcegradient-nonGtkCr-120:120x120.png")
+     puts "DEBUG: cr.target.class=#{cr.target.class}"	#=> Cairo::ImageSurface
+
     {{br}}
     Images include both surfaces loaded from existing files with cairo_image_surface_create_from_png() and surfaces created from within cairo as an earlier destination. As of cairo 1.2, the easiest way to make and use an earlier destination as a source is with cairo_push_group() and either cairo_pop_group() or cairo_pop_group_to_source(). Use cairo_pop_group_to_source() to use it just until you select a new source, and cairo_pop_group() when you want to save it so you can select it over and over again with cairo_set_source().
+
 
 
 




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