ruby-****@sourc*****
ruby-****@sourc*****
2013年 4月 5日 (金) 21:42:40 JST
------------------------- REMOTE_ADDR = 70.49.48.128 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-dancr-rbcatut-dwc ------------------------- @@ -217,7 +217,7 @@ Before we continue, lets remind ourselves that Ruby Gtk/Cairo implementation does not support the gradients. We have to fall back to the 'rcairo' and ((*require 'cairo'*)) module. We have already mentioned this in section 12.3.1.2.5 ((<Mask Method|tut-gtk2-dancr-rbcatut-crdrmd#Mask Method>)) and in its subsection (12.3.1.2.5.A1) "Ruby Gtk-Cairo Library Fails To Support Gradient Patterns", where we explain the difference between Ruby Gtk programming environment and non-GUI character based terminal programming environment utilizing Cairo library, a.k.a. '((<rcairo|URL:http://cairo.rubyforge.org/doc/en/>))', directly. {{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|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-create-linear>)) are built from two points which pass through parallel lines to define the start and stop locations. ((<Radial gradients|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-create-radial>)) 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()|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-add-color-stop-rgb>)) and ((<cairo_add_color_stop_rgba()|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-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()|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-set-extend>)). + Gradients describe a progression of colors by setting a start and stop reference location and a series of "stops" along the way. ((<Linear gradients|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-create-linear>)) are built from two points that define a line segment (a.k.a. extension axis) which perpendicularly passes through parallel lines which in turn define the start and stop locations for gradient effect. ((<Radial gradients|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-create-radial>)) 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()|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-add-color-stop-rgb>)) and ((<cairo_add_color_stop_rgba()|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-add-c olor-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()|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-set-extend>)). {{image_right("1203-p10-81-setsrcgradient-nonGtkCr-120_120x120.png")}} @@ -263,13 +263,14 @@ puts "DEBUG: cr.target.class=#{cr.target.class}" #=> Cairo::ImageSurface + :Extension Axis Of Cairo Gradients (12.3.2.1.2.A1){{br}} - The API documentation for cairo pattern constructors tell us that a new linear gradient cairo pattern will be created along the line defined by (x0, y0) and (x1, y1), or that a new radial gradient cairo_pattern_t between the two circles defined by (cx0, cy0, radius0) and (cx1, cy1, radius1). What do these two statements actually mean one can only be sure, after some practical experimenting is done. This subsection is designed to speed up your understanding. Here, we will base our investigation of this issue, by looking at the ((<Cairo: :LinearPattern.new(x0,y0,x1,y1)|URL:http://cairo.rubyforge.org/doc/en/cairo-linear-pattern.html#label-3>)) constructor (for which unfortunately the only reasonable documentation can currently be found on ((<cairo_pattern_create_linear ()|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-create-linear>)).) After that you should have no trouble understanding the documentation for ((<cairo_pattern_create_rad ial ()|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-create-radial>)) which too, applies to its Ruby counterpart found and also, hopefully soon, documented at ((<Cairo: :RadialPattern.new(cx1,cy1,r1,cx2,cy2,r2)|URL:http://cairo.rubyforge.org/doc/en/cairo-radial-pattern.html#label-3>)). + The API documentation for cairo pattern constructors tell us that "a new linear gradient cairo pattern will be created along the line defined by (x0, y0) and (x1, y1)", and that "a new radial gradient pattern will be created between the two circles defined by (cx0, cy0, radius0) and (cx1, cy1, radius1)". What do these two statements actually mean one can only be sure, after some practical experimenting is done. This subsection is designed to speed up your understanding. Here, we will base our investigation of this issue, by looking only at the ((<Cairo: :LinearPattern.new(x0,y0,x1,y1)|URL:http://cairo.rubyforge.org/doc/en/cairo-linear-pattern.html#label-3>)) constructor (for which unfortunately the only reasonable documentation can currently be found on ((<cairo_pattern_create_linear ()|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-create-linear>)).) After that you should have no trouble understanding the documentation for ((<cairo_ pattern_create_radial ()|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-create-radial>)) which too, applies to its Ruby counterpart found and also, hopefully soon, documented at ((<Cairo: :RadialPattern.new(cx1,cy1,r1,cx2,cy2,r2)|URL:http://cairo.rubyforge.org/doc/en/cairo-radial-pattern.html#label-3>)). - As you can see, in the above example, the following "Cairo: :LinearPattern.new(x1,y1,x2,y2)" constructor is used. Obviously, the four parameters to the constructor define that line (or as I prefer to call it((*the extensin axis*)) of cairo gradients) along which the API documentation, tells us the 'linear gradient cairo pattern' will be created. This extension axis is the black line on the image on the right side next to the code segment with the constructor: + As you can see, in the above program example, the following "Cairo: :LinearPattern.new(x1,y1,x2,y2)" constructor is used. Obviously, the four parameters to the constructor define the line (or as I prefer to call it((*the extension axis*)) of cairo gradients) along which, the API documentation tells us, the 'linear gradient cairo pattern' will be created. This 'extension axis' is shown on the image below, on the right side next to the code segment with the constructor, as the black line: {{image_right("1203-p10-82-LinearPattern-axis-orig-s2.png")}} @@ -285,14 +286,16 @@ However, neither of these two images reveal very much about the extensions of cairo gradients, particularly, if you are interested to understand what the cairo extend mode constants defined in ((<Cairo:_:Extend module|URL:http://cairo.rubyforge.org/doc/en/cairo-extend.html#label-0>)), and explained in ((<enum cairo_extend_t|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-extend-t>)), do. As the title of this subsection (Extension Axis Of Cairo Gradients) announces we are concerned with the extension of the cairo gradient pattern. - We know, that according to the API documentation, the linear gradient cairo pattern is created along the line which the last two images above exposed, and which, conveniently, I prefer to call 'the extension axis'. + {{br}} {{image_right("1203-p10-83-diff-CrExtends-4-diff-lin-patts-axis-s2.png")}} + + We know, that according to the API documentation, the linear gradient cairo pattern is created along the line (extension axis) which the last two images above exposed. The just mentioned constants from the ((<Cairo:_:Extend module|URL:http://cairo.rubyforge.org/doc/en/cairo-extend.html#label-0>)), on the other hand, are concerned how this pattern behaves beyond its extent, i.e, before and after the endpoints of the 'extension axis'. Now, if this axis stretches across the area of entire drawing, the behaviour these constants define will not be visible. + + To help us better understand this, I wrote the following cairo gradients testing program, which allows us to easily change the defining end-points for the 'extension axis'. Since the cairo gradient patterns are defined for the entire drawing surface (i.e. all the shapes you draw in a particular cario context at any one time are governed by the same extension axis), it would be rather tricky, though not impossible, relaying on the knowledge we acquired about using cairo library so far, to define different gradient patterns for different shapes on the same drawing. In fact, even for this simple testing program, I had to resort to some tricks we have not yet learned about, to draw one shape set to different 'cairo extend modes', defined by the ((<Cairo:_:Extend module|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-extend-t>)) constants, at a different locations on the same drawing surface for each iteration in which 'set_extend' method is calle d with a different extend mode constant. In the code you will find three such places with methods ((*cr.save, cr.translate*)) and((*cr.restore,*)) we are not yet familiar with, and which we will not explain here, but rather a few sections later. So, please ignore these method calls which help us positioning the square shape and its cairo gradient extension axes, as well as the current gradient's area of influence, and concentrate on the rest of the program (the lines with yet to be explained methods in the code are accompanied with the comment to that effect.) Ignoring just mentioned lines will not hamper your understanding of the rest of the code, which deals with what really matters in this subsection. - The just mentioned constants from the ((<Cairo:_:Extend module|URL:http://cairo.rubyforge.org/doc/en/cairo-extend.html#label-0>)), on the other hand, are concerned how this pattern behaves beyond its extent, i.e, before and after the endpoints of the 'extension axis'. Now, if this axis stretches across the area of entire drawing, the behaviour these constants define will not be visible. - To help us better understand this, I wrote the following cairo gradients testing program, which allows us to easily change the defining end-points for the 'extension axis'. Since the cairo gradient patterns are defined for the entire drawing surface (i.e. all the shapes you draw in a particular cario context at any one time are governed by the same extension axis), it would be rather tricky, though not impossible, relaying on the knowledge we acquired about using cairo library so far, to define different gradient patterns for different shapes on the same drawing. In fact, I had to resort to some tricks we have not yet learned about, to draw one shape set to different 'cairo extend modes', defined by the ((<Cairo:_:Extend::...constants|URL:http://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-extend-t>)), at a different locations on the same drawing surface for each iteration in which 'set_extend' method is called with a different ((<Cairo:_:Extend...|U RL:http://cairo.rubyforge.org/doc/en/cairo-extend.html#label-0>)) constant. There are three such places utilizing methods ((*cr.save, cr.translate*)) and((*cr.restore,*)) we are not yet familiar with, and which we will not explain here, but, not to clutter this already bloated section, a few sections later. So, please ignore these method calls which help us positioning the square shape and its cairo gradient extension axes, as well as the current gradient's area of influence, and concentrate on the rest of the program (the relevant lines in the code are accompanied with the comment to that effect.) Doing so will not hamper your understanding of the rest of the code, which deals with what is the subject of this subsection. - # FILE: 1203-p10-81-01-50-03-ssradnt-multi-LINEARs-trOK-GtkCr-dpl01.rb {{br}} #!/usr/bin/env ruby