Debian Codegraph @

lib/CharacterColor.h

raw symbols SCIP
1 /*
2 This file is part of Konsole, KDE's terminal.
3
4 Copyright 2007-2008 by Robert Knight <[email protected]>
5 Copyright 1997,1998 by Lars Doelle <[email protected]>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA.
21 */
22
23 #ifndef CHARACTERCOLOR_H
24 #define CHARACTERCOLOR_Hcxx . . $ `lib/CharacterColor.h:24:9`!
25
26 // Qt
27 #include <QColor>
28
29 //#include <kdemacros.h>
30 #define KDE_NO_EXPORTcxx . . $ `lib/CharacterColor.h:30:9`!
31
32 namespace Konsolecxx . . $ Konsole/
33 {
34
35 /**
36 * An entry in a terminal display's color palette.
37 *
38 * A color palette is an array of 16 ColorEntry instances which map
39 * system color indexes (from 0 to 15) into actual colors.
40 *
41 * Each entry can be set as bold, in which case any text
42 * drawn using the color should be drawn in bold.
43 *
44 * Each entry can also be transparent, in which case the terminal
45 * display should avoid drawing the background for any characters
46 * using the entry as a background.
47 */
48 class ColorEntrycxx . . $ Konsole/ColorEntry#
49 {
50 public:
51 /** Specifies the weight to use when drawing text with this color. */
52 enum FontWeightcxx . . $ Konsole/ColorEntry#FontWeight#
53 {
54 /** Always draw text in this color with a bold weight. */
55 Boldcxx . . $ Konsole/ColorEntry#Bold.,
56 /** Always draw text in this color with a normal weight. */
57 Normalcxx . . $ Konsole/ColorEntry#Normal.,
58 /**
59 * Use the current font weight set by the terminal application.
60 * This is the default behavior.
61 */
62 UseCurrentFormatcxx . . $ Konsole/ColorEntry#UseCurrentFormat.
63 };
64
65 /**
66 * Constructs a new color palette entry.
67 *
68 * @param c The color value for this entry.
69 * @param tr Specifies that the color should be transparent when used as a background color.
70 * @param weight Specifies the font weight to use when drawing text with this color.
71 */
72 ColorEntrycxx . . $ Konsole/ColorEntry#ColorEntry(357007224962ed03).(QColorcxx . . $ QColor# c, bool tr, FontWeightcxx . . $ Konsole/ColorEntry#FontWeight# weight = UseCurrentFormatcxx . . $ Konsole/ColorEntry#UseCurrentFormat.)
73 : colorcxx . . $ Konsole/ColorEntry#color.(c), transparentcxx . . $ Konsole/ColorEntry#transparent.(tr), fontWeightcxx . . $ Konsole/ColorEntry#fontWeight.(weight) {}
74
75 /**
76 * Constructs a new color palette entry with an undefined color, and
77 * with the transparent and bold flags set to false.
78 */
79 ColorEntrycxx . . $ Konsole/ColorEntry#ColorEntry(49f6e7a06ebc5aa8).() : transparentcxx . . $ Konsole/ColorEntry#transparent.(false), fontWeightcxx . . $ Konsole/ColorEntry#fontWeight.(UseCurrentFormatcxx . . $ Konsole/ColorEntry#UseCurrentFormat.) {}
80
81 /** The color value of this entry for display. */
82 QColorcxx . . $ QColor# colorcxx . . $ Konsole/ColorEntry#color.;
83
84 /**
85 * If true character backgrounds using this color should be transparent.
86 * This is not applicable when the color is used to render text.
87 */
88 bool transparentcxx . . $ Konsole/ColorEntry#transparent.;
89 /**
90 * Specifies the font weight to use when drawing text with this color.
91 * This is not applicable when the color is used to draw a character's background.
92 */
93 FontWeightcxx . . $ Konsole/ColorEntry#FontWeight# fontWeightcxx . . $ Konsole/ColorEntry#fontWeight.;
94 };
95
96
97 // Attributed Character Representations ///////////////////////////////
98
99 // Colors
100
101 #define BASE_COLORScxx . . $ `lib/CharacterColor.h:101:9`! (2+8)
102 #define INTENSITIEScxx . . $ `lib/CharacterColor.h:102:9`! 2
103 #define TABLE_COLORScxx . . $ `lib/CharacterColor.h:103:9`! (INTENSITIEScxx . . $ `lib/CharacterColor.h:102:9`!*BASE_COLORScxx . . $ `lib/CharacterColor.h:101:9`!)
104
105 #define DEFAULT_FORE_COLORcxx . . $ `lib/CharacterColor.h:105:9`! 0
106 #define DEFAULT_BACK_COLORcxx . . $ `lib/CharacterColor.h:106:9`! 1
107
108 //a standard set of colors using black text on a white background.
109 //defined in TerminalDisplay.cpp
110
111 extern const ColorEntrycxx . . $ Konsole/ColorEntry# base_color_tablecxx . . $ Konsole/base_color_table.[TABLE_COLORScxx . . $ `lib/CharacterColor.h:103:9`!] KDE_NO_EXPORTcxx . . $ `lib/CharacterColor.h:30:9`!;
112
113 /* CharacterColor is a union of the various color spaces.
114
115 Assignment is as follows:
116
117 Type - Space - Values
118
119 0 - Undefined - u: 0, v:0 w:0
120 1 - Default - u: 0..1 v:intense w:0
121 2 - System - u: 0..7 v:intense w:0
122 3 - Index(256) - u: 16..255 v:0 w:0
123 4 - RGB - u: 0..255 v:0..256 w:0..256
124
125 Default colour space has two separate colours, namely
126 default foreground and default background colour.
127 */
128
129 #define COLOR_SPACE_UNDEFINEDcxx . . $ `lib/CharacterColor.h:129:9`! 0
130 #define COLOR_SPACE_DEFAULTcxx . . $ `lib/CharacterColor.h:130:9`! 1
131 #define COLOR_SPACE_SYSTEMcxx . . $ `lib/CharacterColor.h:131:9`! 2
132 #define COLOR_SPACE_256cxx . . $ `lib/CharacterColor.h:132:9`! 3
133 #define COLOR_SPACE_RGBcxx . . $ `lib/CharacterColor.h:133:9`! 4
134
135 /**
136 * Describes the color of a single character in the terminal.
137 */
138 class CharacterColorcxx . . $ Konsole/CharacterColor#
139 {
140 friend class Charactercxx . . $ Konsole/Character#;
141
142 public:
143 /** Constructs a new CharacterColor whoose color and color space are undefined. */
144 CharacterColorcxx . . $ Konsole/CharacterColor#CharacterColor(49f6e7a06ebc5aa8).()
145 : _colorSpacecxx . . $ Konsole/CharacterColor#_colorSpace.(COLOR_SPACE_UNDEFINEDcxx . . $ `lib/CharacterColor.h:129:9`!),
146 _ucxx . . $ Konsole/CharacterColor#_u.(0),
147 _vcxx . . $ Konsole/CharacterColor#_v.(0),
148 _wcxx . . $ Konsole/CharacterColor#_w.(0)
149 {}
150
151 /**
152 * Constructs a new CharacterColor using the specified @p colorSpace and with
153 * color value @p co
154 *
155 * The meaning of @p co depends on the @p colorSpace used.
156 *
157 * TODO : Document how @p co relates to @p colorSpace
158 *
159 * TODO : Add documentation about available color spaces.
160 */
161 CharacterColorcxx . . $ Konsole/CharacterColor#CharacterColor(d5cb1b1d97598ec6).(quint8cxx . . $ quint8# colorSpace, int co)
162 : _colorSpacecxx . . $ Konsole/CharacterColor#_colorSpace.(colorSpace),
163 _ucxx . . $ Konsole/CharacterColor#_u.(0),
164 _vcxx . . $ Konsole/CharacterColor#_v.(0),
165 _wcxx . . $ Konsole/CharacterColor#_w.(0)
166 {
167 switch (colorSpace)
168 {
169 case COLOR_SPACE_DEFAULTcxx . . $ `lib/CharacterColor.h:130:9`!:
170 _ucxx . . $ Konsole/CharacterColor#_u. = co & 1;
171 break;
172 case COLOR_SPACE_SYSTEMcxx . . $ `lib/CharacterColor.h:131:9`!:
173 _ucxx . . $ Konsole/CharacterColor#_u. = co & 7;
174 _vcxx . . $ Konsole/CharacterColor#_v. = (co >> 3) & 1;
175 break;
176 case COLOR_SPACE_256cxx . . $ `lib/CharacterColor.h:132:9`!:
177 _ucxx . . $ Konsole/CharacterColor#_u. = co & 255;
178 break;
179 case COLOR_SPACE_RGBcxx . . $ `lib/CharacterColor.h:133:9`!:
180 _ucxx . . $ Konsole/CharacterColor#_u. = co >> 16;
181 _vcxx . . $ Konsole/CharacterColor#_v. = co >> 8;
182 _wcxx . . $ Konsole/CharacterColor#_w. = co;
183 break;
184 default:
185 _colorSpacecxx . . $ Konsole/CharacterColor#_colorSpace. = COLOR_SPACE_UNDEFINEDcxx . . $ `lib/CharacterColor.h:129:9`!;
186 }
187 }
188
189 /**
190 * Returns true if this character color entry is valid.
191 */
192 bool isValidcxx . . $ Konsole/CharacterColor#isValid(50ce9a9e25b4a850).() const
193 {
194 return _colorSpacecxx . . $ Konsole/CharacterColor#_colorSpace. != COLOR_SPACE_UNDEFINEDcxx . . $ `lib/CharacterColor.h:129:9`!;
195 }
196
197 /**
198 * Set the value of this color from a normal system color to the corresponding intensive
199 * system color if it's not already an intensive system color.
200 *
201 * This is only applicable if the color is using the COLOR_SPACE_DEFAULT or COLOR_SPACE_SYSTEM
202 * color spaces.
203 */
204 void setIntensivecxx . . $ Konsole/CharacterColor#setIntensive(49f6e7a06ebc5aa8).();
205
206 /**
207 * Returns the color within the specified color @p palette
208 *
209 * The @p palette is only used if this color is one of the 16 system colors, otherwise
210 * it is ignored.
211 */
212 QColorcxx . . $ QColor# colorcxx . . $ Konsole/CharacterColor#color(b83b316448997199).(const ColorEntrycxx . . $ Konsole/ColorEntry#* palette) const;
213
214 /**
215 * Compares two colors and returns true if they represent the same color value and
216 * use the same color space.
217 */
218 friend bool operatorcxx . . $ Konsole/`operator==`(40f11079b1efd097). == (const CharacterColorcxx . . $ Konsole/CharacterColor#& a, const CharacterColorcxx . . $ Konsole/CharacterColor#& b);
219 /**
220 * Compares two colors and returns true if they represent different color values
221 * or use different color spaces.
222 */
223 friend bool operatorcxx . . $ Konsole/`operator!=`(40f11079b1efd097). != (const CharacterColorcxx . . $ Konsole/CharacterColor#& a, const CharacterColorcxx . . $ Konsole/CharacterColor#& b);
224
225 private:
226 quint8cxx . . $ quint8# _colorSpacecxx . . $ Konsole/CharacterColor#_colorSpace.;
227
228 // bytes storing the character color
229 quint8cxx . . $ quint8# _ucxx . . $ Konsole/CharacterColor#_u.;
230 quint8cxx . . $ quint8# _vcxx . . $ Konsole/CharacterColor#_v.;
231 quint8cxx . . $ quint8# _wcxx . . $ Konsole/CharacterColor#_w.;
232 };
233
234 inline bool operatorcxx . . $ Konsole/`operator==`(40f11079b1efd097). == (const CharacterColorcxx . . $ Konsole/CharacterColor#& a, const CharacterColorcxx . . $ Konsole/CharacterColor#& b)
235 {
236 return a._colorSpacecxx . . $ Konsole/CharacterColor#_colorSpace. == b._colorSpacecxx . . $ Konsole/CharacterColor#_colorSpace. &&
237 a._ucxx . . $ Konsole/CharacterColor#_u. == b._ucxx . . $ Konsole/CharacterColor#_u. &&
238 a._vcxx . . $ Konsole/CharacterColor#_v. == b._vcxx . . $ Konsole/CharacterColor#_v. &&
239 a._wcxx . . $ Konsole/CharacterColor#_w. == b._wcxx . . $ Konsole/CharacterColor#_w.;
240 }
241 inline bool operatorcxx . . $ Konsole/`operator!=`(40f11079b1efd097). != (const CharacterColorcxx . . $ Konsole/CharacterColor#& a, const CharacterColorcxx . . $ Konsole/CharacterColor#& b)
242 {
243 return !operatorcxx . . $ Konsole/`operator==`(40f11079b1efd097).==(a,b);
244 }
245
246 inline const QColorcxx . . $ QColor# color256cxx . . $ Konsole/color256(d13a1fd293c01242).(quint8cxx . . $ quint8# u, const ColorEntrycxx . . $ Konsole/ColorEntry#* base)
247 {
248 // 0.. 16: system colors
249 if (u < 8) return basecxx . . $ QColor#QColor(c396aab421781ee8).[u+2 ].colorcxx . . $ Konsole/ColorEntry#color.;
250 u -= 8;
251 if (u < 8) return basecxx . . $ QColor#QColor(c396aab421781ee8).[u+2+BASE_COLORScxx . . $ `lib/CharacterColor.h:101:9`!].colorcxx . . $ Konsole/ColorEntry#color.;
252 u -= 8;
253
254 // 16..231: 6x6x6 rgb color cube
255 if (u < 216) return QColorcxx . . $ QColor#QColor(2261ffe5112eab06).(((u/36)%6) ? (40*((u/36)%6)+55) : 0,
256 ((u/ 6)%6) ? (40*((u/ 6)%6)+55) : 0,
257 ((u/ 1)%6) ? (40*((u/ 1)%6)+55) : 0);
258 u -= 216;
259
260 // 232..255: gray, leaving out black and white
261 int gray = u*10+8; return QColorcxx . . $ QColor#QColor(2261ffe5112eab06).(gray,gray,gray);
262 }
263
264 inline QColorcxx . . $ QColor# CharacterColorcxx . . $ Konsole/CharacterColor#::colorcxx . . $ Konsole/CharacterColor#color(b83b316448997199).(const ColorEntrycxx . . $ Konsole/ColorEntry#* base) const
265 {
266 switch (_colorSpacecxx . . $ Konsole/CharacterColor#_colorSpace.)
267 {
268 case COLOR_SPACE_DEFAULTcxx . . $ `lib/CharacterColor.h:130:9`!: return basecxx . . $ QColor#QColor(c396aab421781ee8).[_ucxx . . $ Konsole/CharacterColor#_u.+0+(_vcxx . . $ Konsole/CharacterColor#_v.?BASE_COLORScxx . . $ `lib/CharacterColor.h:101:9`!:0)].colorcxx . . $ Konsole/ColorEntry#color.;
269 case COLOR_SPACE_SYSTEMcxx . . $ `lib/CharacterColor.h:131:9`!: return basecxx . . $ QColor#QColor(c396aab421781ee8).[_ucxx . . $ Konsole/CharacterColor#_u.+2+(_vcxx . . $ Konsole/CharacterColor#_v.?BASE_COLORScxx . . $ `lib/CharacterColor.h:101:9`!:0)].colorcxx . . $ Konsole/ColorEntry#color.;
270 case COLOR_SPACE_256cxx . . $ `lib/CharacterColor.h:132:9`!: return color256cxx . . $ Konsole/color256(d13a1fd293c01242).(_ucxx . . $ Konsole/CharacterColor#_u.,base);
271 case COLOR_SPACE_RGBcxx . . $ `lib/CharacterColor.h:133:9`!: return {cxx . . $ QColor#QColor(2261ffe5112eab06)._ucxx . . $ Konsole/CharacterColor#_u.,_vcxx . . $ Konsole/CharacterColor#_v.,_wcxx . . $ Konsole/CharacterColor#_w.};
272 case COLOR_SPACE_UNDEFINEDcxx . . $ `lib/CharacterColor.h:129:9`!: return QColorcxx . . $ QColor#QColor(ced63f7c635d850d).();
273 }
274
275 Q_ASSERTcxx . . $ `<external>/15045578679651060896/qglobal.h:859:13`!(false); // invalid color space
276
277 return QColorcxx . . $ QColor#QColor(ced63f7c635d850d).();
278 }
279
280 inline void CharacterColorcxx . . $ Konsole/CharacterColor#::setIntensivecxx . . $ Konsole/CharacterColor#setIntensive(49f6e7a06ebc5aa8).()
281 {
282 if (_colorSpacecxx . . $ Konsole/CharacterColor#_colorSpace. == COLOR_SPACE_SYSTEMcxx . . $ `lib/CharacterColor.h:131:9`! || _colorSpacecxx . . $ Konsole/CharacterColor#_colorSpace. == COLOR_SPACE_DEFAULTcxx . . $ `lib/CharacterColor.h:130:9`!)
283 {
284 _vcxx . . $ Konsole/CharacterColor#_v. = 1;
285 }
286 }
287
288
289 }
290
291 #endif // CHARACTERCOLOR_H
292