1
# region.rb: draw curves-delimited fills
2
# copyright (c) 2010 by Vincent Fourmond
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details (in the COPYING file).
15
require 'ctioga2/utils'
20
Version::register_svn_info('$Revision: 159 $', '$Date: 2010-07-26 17:29:47 +0200 (Mon, 26 Jul 2010) $')
26
# A GradientRegion is an object that makes color gradient for
27
# the curves. Especially useful for a great number of curves,
28
# and when one doesn't want to compute...
32
# Like Region It is a fake container in the sense that all the
33
# elements are actually forwarded to the parent.
34
class GradientRegion < Container
39
# The curves which delimit the region
42
# The start and end colors
43
attr_accessor :start_color, :end_color
45
# Creates a new empty region
46
def initialize(parent = nil, root = nil)
49
# The curves whose color we should change
56
@start_color = Tioga::ColorConstants::Red
57
@end_color = Tioga::ColorConstants::Green
61
# Adds an element. Actually forwards it to the parent.
62
def add_element(element)
63
parent.add_element(element)
64
if element.respond_to?(:curve_style)
69
# Sets the various things from hash.
70
def set_from_hash(hash)
73
# Redirects to the parent's style
75
return parent.style(*a)
80
# Simply sets the color of the curves.
85
c.curve_style.line.color =
86
Utils::mix_objects(@end_color,@start_color, i/(nb - 1.0))