File: class.ImlibColorRange.php

package info (click to toggle)
php-imlib 0.3-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 572 kB
  • ctags: 430
  • sloc: ansic: 1,287; php: 626; sh: 94; makefile: 66
file content (141 lines) | stat: -rw-r--r-- 3,092 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php

/**
* All functions relevant to creating and displaying color ranges
*
* @version 0.3
* @author  Matt McClanahan <cardinal@dodds.net>
* @package Imlib
* @access public
*/
class ImlibColorRange extends ImlibCliprect
{
   /**
   * Resource id# of the current color range
   *
   * @access private
   */
   var $cr;

   /**
   * Resource id# of the image to draw on
   *
   * @access private
   */
   var $im;

   /**
   * ImlibColorRange constructor
   *
   * @access public
   */
   function ImlibColorRange()
   {
      $this->cr = 0;
      $this->im = 0;
   }

   /**
   * Add a color to the color range at distance $x.
   *
   * A distance of 0 will center it between the previous color and the end.
   * $x is ignored for the first color.
   *
   * @param int Distance from the previous color
   * @param int Red
   * @param int Blue
   * @param int Green
   * @param int Alpha
   * @access public
   */
   function add_color($x,$r,$g,$b,$a)
   {
      if (!is_resource($this->cr))
         return false;

      imlib_add_color_to_color_range($this->cr,$x,$r,$g,$b,$a);
   }

   /**
   * Add a color to the color range at distance $x.
   *
   * A distance of 0 will center it between the previous color and the end.
   * $x is ignored for the first color.
   *
   * @param int Distance from the previous color
   * @param array Color array (r,g,b,a)
   * @access public
   */
   function add_color_array($x,$arr)
   {
      list($r,$g,$b,$a) = $arr;
      $this->add_color($x,$r,$g,$b,$a);
   }

   /**
   * Create a new color range
   *
   * @return int Resource id# of the new color range
   * @access public
   */
   function create()
   {
      if (is_resource($this->cr))
         return false;

      return $this->cr = imlib_create_color_range();
   }

   /**
   * Free the current color range
   *
   * @access public
   */
   function free()
   {
      if (!is_resource($this->cr))
         return false;

      imlib_free_color_range($this->cr);
      unset($this->cr);
   }

   /**
   * Fill the current image with a rectangle using the current color range
   *
   * The color range will be filled in the specified box at angle $angle
   *
   * @param int Upper-left X coordinate of the box
   * @param int Upper-left Y coordinate of the box
   * @param int Width of the box
   * @param int Height of the box
   * @param int Angle to rotate the color range (degrees)
   * @access public
   */
   function fill_rectangle($x,$y,$w,$h,$angle)
   {
      if (!is_resource($this->im) || !is_resource($this->cr))
         return false;

      if ($this->cliprect_inuse)
         return imlib_image_fill_color_range_rectangle($this->im,$this->cr,
                      $x,$y,$w,$h,$angle,$this->get_cliprect_array());
      else
         return imlib_image_fill_color_range_rectangle($this->im,$this->cr,
                      $x,$y,$w,$h,$angle);
   }

   /**
   * Set the image to draw the color range on
   *
   * @param int Resource id# of the image
   * @access public
   */
   function set_image($im)
   {
      if (is_resource($im))
         $this->im = $im;
   }
};

?>