Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / Pastel / GradientStop.pm
CommitLineData
86530b38
AT
1package Pastel::GradientStop;
2@ISA = qw (Pastel::Mixin::Mixin);
3use Carp;
4use Pastel::Mixin::Mixin;
5
6use strict;
7
8# Perl module for Pastel::Color
9# Cared for by Malay<curiouser@ccmb.ap.nic.in>
10# Copyright 2001, Malay Kumar Basu
11# You may distribute this module under the same terms as perl itself
12
13=head1 NAME
14
15Pastel::GradientStop
16
17Each of these gradient paint classes holds several of GradientStop classes.
18The GradientStop classes represents the "stop" element under Linear
19or radialGradient element in SVG.
20
21=head1 DESCRIPTION
22
23There are only two fields in Pastel::GradientStop: "offset" and "color".
24The values of "offset" can vary from 0 to 100%, basically reflect at what
25point along the GradientVector the gradient stops. The "color" is supplied
26as Pastel::Color.
27
28=head1 SYNOPSIS
29
30 #Create a Gradient object
31 my $linearGradient = Pastel::LinearGradient->new(...);
32 my $color1 = Pastel::Color->red();
33
34
35 #Create the first stop
36 my $firstGradientStop = Pastel::GradientStop->new(-offset=>5,
37 -color=>$color1);
38
39 #the same thing
40 # my $firstGradientStop = Pastel::GradientStop->new(5, $color1);
41
42 # Add the stop to gradient
43 $linearGradient->add_stop($firstGradientStop);
44
45 # Set the gradient to graphics object
46 $graphics->set_paint($linearGradient);
47
48=head1 CONSTRUCTOR
49
50=head3 Pastel::GradientStop->new(-offset=>$int, -color=>$color)
51
52$int is integer between 0 and 100, $color is a Pastel::Color object.
53
54=head3 Pastel::GradientStop->new($int, $color)
55
56Orthodox parameter styles.
57
58=cut
59
60sub new {
61 my $class = shift;
62 my $self = {};
63 bless $self, ref($class) || $class;
64 $self->_init(@_);
65 return $self;
66}
67
68sub _init {
69 my ($self, @args) = @_;
70
71 if ( (@args < 2) || (@args >4)){
72 croak "Parameter problems in Pastel::GradientStop::new\n";
73 }
74
75 my ($offset, $color) = $self->_rearrange(["OFFSET","COLOR"],@args);
76
77 if(!defined($offset) || !defined($color) ){
78 croak "Parameter problem in Pastel::GradientStop::new\n";
79 }
80
81 if( ($offset <0) || ($offset >100)){
82 croak "Offset value in Pastel::GradientStop::new is out of range\n";
83 }
84
85 if (! $color->isa("Pastel::Color") ){
86 croak "Wrong color parameter in Pastel::GradientStop\n";
87 }
88
89 $self->{offset} = $offset;
90 $self->{color} = $color;
91
92 return $self;
93}
94
95sub to_svg {
96 my $self = shift;
97 my $s = "";
98 $s .= "<stop offset=\"". $self->get_offset()."\%\" stop-color=\"".
99 $self->get_color(). "\" stop-opacity=\"". $self->get_opacity(). "\" />";
100 return $s;
101}
102
103sub get_offset {
104 return $_[0]->{offset};
105}
106
107sub get_color {
108 return $_[0]->{color}->to_hex();
109}
110
111sub get_opacity {
112 if ( $_[0]->{color}->get_alpha() ){
113 return $_[0]->{color}->get_alpha();
114 } else {
115 return 1;
116 }
117}
118
1191;
120
121
122
123
124
125
126
127