Mercurial > octave-nkf
comparison src/graphics.cc @ 6563:7a65c1a09ec3
[project @ 2007-04-23 19:26:17 by jwe]
author | jwe |
---|---|
date | Mon, 23 Apr 2007 19:26:17 +0000 |
parents | 84f2d0253aea |
children | efa1716abd4c |
comparison
equal
deleted
inserted
replaced
6562:82d0132889e4 | 6563:7a65c1a09ec3 |
---|---|
61 // --------------------------------------------------------------------- | 61 // --------------------------------------------------------------------- |
62 | 62 |
63 class color_property | 63 class color_property |
64 { | 64 { |
65 public: | 65 public: |
66 color_property (double r = 0, double g = 0, double b = 1) | 66 color_property (double r = 0, double g = 0, double b = 1, double a = 1) |
67 : red (r), green (g), blue (b) | 67 { |
68 { | 68 rgba[0] = r; |
69 rgba[1] = g; | |
70 rgba[2] = b; | |
71 rgba[3] = a; | |
72 | |
69 validate (); | 73 validate (); |
70 } | 74 } |
71 | 75 |
76 color_property (char c) | |
77 { | |
78 c2rgba (c); | |
79 } | |
80 | |
72 color_property (const octave_value& val) | 81 color_property (const octave_value& val) |
73 : red (), green (), blue () | |
74 { | 82 { |
75 // FIXME -- need some error checking here. | 83 // FIXME -- need some error checking here. |
76 | 84 |
77 Matrix m = val.matrix_value (); | 85 Matrix m = val.matrix_value (); |
78 | 86 |
79 if (! error_state && m.numel () == 3) | 87 if (! error_state && m.numel () >= 3 && m.numel () <= 4) |
80 { | 88 { |
81 red = m(0); | 89 for (int i = 0; i < m.numel (); i++) |
82 green = m(1); | 90 rgba[i] = m(i); |
83 blue = m(2); | |
84 | 91 |
85 validate (); | 92 validate (); |
86 } | 93 } |
87 else | 94 else |
88 error ("invalid RGB color specification"); | 95 { |
96 std::string c = val.string_value (); | |
97 | |
98 if (! error_state && c.length () == 1) | |
99 c2rgb(c[0]); | |
100 else | |
101 error ("invalid color specification"); | |
102 } | |
89 } | 103 } |
90 | 104 |
91 void validate (void) const | 105 void validate (void) const |
92 { | 106 { |
93 if (red < 0 || red > 1 || green < 0 || green > 1 || blue < 0 || blue > 1) | 107 for (int i = 0; i < 4; i++) |
94 error ("invalid RGB color specification"); | 108 { |
109 if (rgba[i] < 0 || rgba[i] > 1) | |
110 { | |
111 error ("invalid RGB color specification"); | |
112 break; | |
113 } | |
114 } | |
95 } | 115 } |
96 | 116 |
97 operator octave_value (void) const | 117 operator octave_value (void) const |
98 { | 118 { |
99 Matrix retval (1, 3); | 119 Matrix retval (1, 4); |
100 | 120 |
101 retval(0) = red; | 121 for (int i = 0; i < 4 ; i++) |
102 retval(1) = green; | 122 retval(i) = rgba[i]; |
103 retval(2) = blue; | |
104 | 123 |
105 return retval; | 124 return retval; |
106 } | 125 } |
107 | 126 |
127 const double* rgba (void) const | |
128 { | |
129 return rgba; | |
130 } | |
131 | |
108 private: | 132 private: |
109 double red; | 133 double rgba[4]; |
110 double green; | 134 |
111 double blue; | 135 void c2rgba (char c) |
136 { | |
137 double tmp_rgba[4] = {0,0,0,1}; | |
138 | |
139 switch(c) | |
140 { | |
141 case 'r': | |
142 tmp_rgb[0] = 1; | |
143 break; | |
144 | |
145 case 'g': | |
146 tmp_rgb[1] = 1; | |
147 break; | |
148 | |
149 case 'b': | |
150 tmp_rgb[2] = 1; | |
151 break; | |
152 | |
153 case 'c': | |
154 tmp_rgb[1] = tmp_rgb[2] = 1; | |
155 break; | |
156 | |
157 case 'm': | |
158 tmp_rgb[0] = tmp_rgb[2] = 1; | |
159 break; | |
160 | |
161 case 'y': | |
162 tmp_rgb[0] = tmp_rgb[1] = 1; | |
163 break; | |
164 | |
165 case 'w': | |
166 tmp_rgb[0] = tmp_rgb[1] = tmp_rgb[2] = 1; | |
167 break; | |
168 | |
169 default: | |
170 error ("invalid color specification"); | |
171 } | |
172 | |
173 if (! error_state) | |
174 { | |
175 for (int i = 0; i < 4; i++) | |
176 rgba[i] = tmp_rgba[i]; | |
177 } | |
178 } | |
112 }; | 179 }; |
113 | 180 |
114 class colormap_property | 181 class colormap_property |
115 { | 182 { |
116 public: | 183 public: |