FINAL CUT
fvtermattribute.h
1 /***********************************************************************
2 * fvtermattribute.h - Manipulation of FChar colors and attributes *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2021-2023 Markus Gans *
7 * *
8 * FINAL CUT is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation; either version 3 of *
11 * the License, or (at your option) any later version. *
12 * *
13 * FINAL CUT is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this program. If not, see *
20 * <http://www.gnu.org/licenses/>. *
21 ***********************************************************************/
22 
23 /* Standalone class
24  * ════════════════
25  *
26  * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
27  * ▕ FVTermAttribute ▏
28  * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
29  */
30 
31 #ifndef FVTERMATTRIBUTE_H
32 #define FVTERMATTRIBUTE_H
33 
34 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
35  #error "Only <final/final.h> can be included directly."
36 #endif
37 
38 #include "final/ftypes.h"
39 #include "final/util/fstring.h"
40 #include "final/vterm/fcolorpair.h"
41 
42 namespace finalcut
43 {
44 
45 // class forward declaration
46 class FColorPair;
47 class FStyle;
48 
49 //----------------------------------------------------------------------
50 // class FVTermAttribute
51 //----------------------------------------------------------------------
52 
54 {
55  public:
56  // Constructors
58 
59  // Disable copy constructor
60  FVTermAttribute (const FVTermAttribute&) = delete;
61 
62  // Disable move constructor
63  FVTermAttribute (FVTermAttribute&&) noexcept = delete;
64 
65  // Destructor
66  virtual ~FVTermAttribute() noexcept;
67 
68  // Disable copy assignment operator (=)
69  auto operator = (const FVTermAttribute&) -> FVTermAttribute& = delete;
70 
71  // Disable move assignment operator (=)
72  auto operator = (FVTermAttribute&&) noexcept -> FVTermAttribute& = delete;
73 
74  // Accessors
75  virtual auto getClassName() const -> FString;
76  static auto getTermForegroundColor() -> FColor;
77  static auto getTermBackgroundColor() -> FColor;
78  static auto getAttribute() -> FChar&;
79 
80  // Mutators
81  static void setColor (FColor, FColor);
82  static void setColor (const FColorPair&);
83  static void setNormal();
84  static void setBold (bool = true);
85  static void unsetBold();
86  static void setDim (bool = true);
87  static void unsetDim();
88  static void setItalic (bool = true);
89  static void unsetItalic();
90  static void setUnderline (bool = true);
91  static void unsetUnderline();
92  static void setBlink (bool = true);
93  static void unsetBlink();
94  static void setReverse (bool = true);
95  static void unsetReverse();
96  static void setStandout (bool = true);
97  static void unsetStandout();
98  static void setInvisible (bool = true);
99  static void unsetInvisible();
100  static void setProtected (bool = true);
101  static void unsetProtected();
102  static void setCrossedOut (bool = true);
103  static void unsetCrossedOut();
104  static void setDoubleUnderline (bool = true);
105  static void unsetDoubleUnderline();
106  static void setAltCharset (bool = true);
107  static void unsetAltCharset();
108  static void setPCcharset (bool = true);
109  static void unsetPCcharset();
110  static void setTransparent (bool = true);
111  static void unsetTransparent();
112  static void setColorOverlay (bool = true);
113  static void unsetColorOverlay();
114  static void setInheritBackground (bool = true);
115  static void unsetInheritBackground();
116 
117  // Inquiries
118  static auto isBold() -> bool;
119  static auto isDim() -> bool;
120  static auto isItalic() -> bool;
121  static auto isUnderline() -> bool;
122  static auto isBlink() -> bool;
123  static auto isReverse() -> bool;
124  static auto isStandout() -> bool;
125  static auto isInvisible() -> bool;
126  static auto isProtected() -> bool;
127  static auto isCrossedOut() -> bool;
128  static auto isDoubleUnderline() -> bool;
129  static auto isAltCharset() -> bool;
130  static auto isPCcharset() -> bool;
131  static auto isTransparent() -> bool;
132  static auto isColorOverlay() -> bool;
133  static auto isInheritBackground() -> bool;
134 
135  // Methods
136  static void initAttribute();
137  static void print (const FStyle&);
138  static void print (const FColorPair&);
139 
140  private:
141  // Data members
142  static FChar next_attribute;
143 };
144 
145 
146 // FVTermAttribute inline functions
147 //----------------------------------------------------------------------
148 inline auto FVTermAttribute::getClassName() const -> FString
149 { return "FVTermAttribute"; }
150 
151 //----------------------------------------------------------------------
152 inline auto FVTermAttribute::getTermForegroundColor() -> FColor
153 { return next_attribute.fg_color; }
154 
155 //----------------------------------------------------------------------
156 inline auto FVTermAttribute::getTermBackgroundColor() -> FColor
157 { return next_attribute.bg_color; }
158 
159 //----------------------------------------------------------------------
160 inline auto FVTermAttribute::getAttribute() -> FChar&
161 { return next_attribute; }
162 
163 //----------------------------------------------------------------------
164 inline void FVTermAttribute::setColor (FColor fg, FColor bg)
165 {
166  // Changes colors
167  next_attribute.fg_color = fg;
168  next_attribute.bg_color = bg;
169 }
170 
171 //----------------------------------------------------------------------
172 inline void FVTermAttribute::setColor (const FColorPair& pair)
173 {
174  setColor (pair.getForegroundColor(), pair.getBackgroundColor());
175 }
176 
177 //----------------------------------------------------------------------
178 inline void FVTermAttribute::setNormal()
179 {
180  // Reset all character attributes
181  next_attribute.attr.byte[0] = 0;
182  next_attribute.attr.byte[1] = 0;
183  next_attribute.attr.bit.no_changes = false;
184  next_attribute.fg_color = FColor::Default;
185  next_attribute.bg_color = FColor::Default;
186 }
187 
188 //----------------------------------------------------------------------
189 inline void FVTermAttribute::setBold (bool enable)
190 { next_attribute.attr.bit.bold = enable; }
191 
192 //----------------------------------------------------------------------
193 inline void FVTermAttribute::unsetBold()
194 { setBold(false); }
195 
196 //----------------------------------------------------------------------
197 inline void FVTermAttribute::setDim (bool enable)
198 { next_attribute.attr.bit.dim = enable; }
199 
200 //----------------------------------------------------------------------
201 inline void FVTermAttribute::unsetDim()
202 { setDim(false); }
203 
204 //----------------------------------------------------------------------
205 inline void FVTermAttribute::setItalic (bool enable)
206 { next_attribute.attr.bit.italic = enable; }
207 
208 //----------------------------------------------------------------------
209 inline void FVTermAttribute::unsetItalic()
210 { setItalic(false); }
211 
212 //----------------------------------------------------------------------
213 inline void FVTermAttribute::setUnderline (bool enable)
214 { next_attribute.attr.bit.underline = enable; }
215 
216 //----------------------------------------------------------------------
217 inline void FVTermAttribute::unsetUnderline()
218 { setUnderline(false); }
219 
220 //----------------------------------------------------------------------
221 inline void FVTermAttribute::setBlink (bool enable)
222 { next_attribute.attr.bit.blink = enable; }
223 
224 //----------------------------------------------------------------------
225 inline void FVTermAttribute::unsetBlink()
226 { setBlink(false); }
227 
228 //----------------------------------------------------------------------
229 inline void FVTermAttribute::setReverse (bool enable)
230 { next_attribute.attr.bit.reverse = enable; }
231 
232 //----------------------------------------------------------------------
233 inline void FVTermAttribute::unsetReverse()
234 { setReverse(false); }
235 
236 //----------------------------------------------------------------------
237 inline void FVTermAttribute::setStandout (bool enable)
238 { next_attribute.attr.bit.standout = enable; }
239 
240 //----------------------------------------------------------------------
241 inline void FVTermAttribute::unsetStandout()
242 { setStandout(false); }
243 
244 //----------------------------------------------------------------------
245 inline void FVTermAttribute::setInvisible (bool enable)
246 { next_attribute.attr.bit.invisible = enable; }
247 
248 //----------------------------------------------------------------------
249 inline void FVTermAttribute::unsetInvisible()
250 { setInvisible(false); }
251 
252 //----------------------------------------------------------------------
253 inline void FVTermAttribute::setProtected (bool enable)
254 { next_attribute.attr.bit.protect = enable; }
255 
256 //----------------------------------------------------------------------
257 inline void FVTermAttribute::unsetProtected()
258 { setProtected(false); }
259 
260 //----------------------------------------------------------------------
261 inline void FVTermAttribute::setCrossedOut (bool enable)
262 { next_attribute.attr.bit.crossed_out = enable; }
263 
264 //----------------------------------------------------------------------
265 inline void FVTermAttribute::unsetCrossedOut()
266 { setCrossedOut(false); }
267 
268 //----------------------------------------------------------------------
269 inline void FVTermAttribute::setDoubleUnderline (bool enable)
270 { next_attribute.attr.bit.dbl_underline = enable; }
271 
272 //----------------------------------------------------------------------
273 inline void FVTermAttribute::unsetDoubleUnderline()
274 { setDoubleUnderline(false); }
275 
276 //----------------------------------------------------------------------
277 inline void FVTermAttribute::setAltCharset (bool enable)
278 { next_attribute.attr.bit.alt_charset = enable; }
279 
280 //----------------------------------------------------------------------
281 inline void FVTermAttribute::unsetAltCharset()
282 { setAltCharset(false); }
283 
284 //----------------------------------------------------------------------
285 inline void FVTermAttribute::setPCcharset (bool enable)
286 { next_attribute.attr.bit.pc_charset = enable; }
287 
288 //----------------------------------------------------------------------
289 inline void FVTermAttribute::unsetPCcharset()
290 { setPCcharset(false); }
291 
292 //----------------------------------------------------------------------
293 inline void FVTermAttribute::setTransparent (bool enable)
294 { next_attribute.attr.bit.transparent = enable; }
295 
296 //----------------------------------------------------------------------
297 inline void FVTermAttribute::unsetTransparent()
298 { setTransparent(false); }
299 
300 //----------------------------------------------------------------------
301 inline void FVTermAttribute::setColorOverlay (bool enable)
302 { next_attribute.attr.bit.color_overlay = enable; }
303 
304 //----------------------------------------------------------------------
305 inline void FVTermAttribute::unsetColorOverlay()
306 { setColorOverlay(false); }
307 
308 //----------------------------------------------------------------------
309 inline void FVTermAttribute::setInheritBackground (bool enable)
310 { next_attribute.attr.bit.inherit_background = enable; }
311 
312 //----------------------------------------------------------------------
313 inline void FVTermAttribute::unsetInheritBackground()
314 { setInheritBackground(false); }
315 
316 //----------------------------------------------------------------------
317 inline auto FVTermAttribute::isBold() -> bool
318 { return next_attribute.attr.bit.bold; }
319 
320 //----------------------------------------------------------------------
321 inline auto FVTermAttribute::isDim() -> bool
322 { return next_attribute.attr.bit.dim; }
323 
324 //----------------------------------------------------------------------
325 inline auto FVTermAttribute::isItalic() -> bool
326 { return next_attribute.attr.bit.italic; }
327 
328 //----------------------------------------------------------------------
329 inline auto FVTermAttribute::isUnderline() -> bool
330 { return next_attribute.attr.bit.underline; }
331 
332 //----------------------------------------------------------------------
333 inline auto FVTermAttribute::isBlink() -> bool
334 { return next_attribute.attr.bit.blink; }
335 
336 //----------------------------------------------------------------------
337 inline auto FVTermAttribute::isReverse() -> bool
338 { return next_attribute.attr.bit.reverse; }
339 
340 //----------------------------------------------------------------------
341 inline auto FVTermAttribute::isStandout() -> bool
342 { return next_attribute.attr.bit.standout; }
343 
344 //----------------------------------------------------------------------
345 inline auto FVTermAttribute::isInvisible() -> bool
346 { return next_attribute.attr.bit.invisible; }
347 
348 //----------------------------------------------------------------------
349 inline auto FVTermAttribute::isProtected() -> bool
350 { return next_attribute.attr.bit.protect; }
351 
352 //----------------------------------------------------------------------
353 inline auto FVTermAttribute::isCrossedOut() -> bool
354 { return next_attribute.attr.bit.crossed_out; }
355 
356 //----------------------------------------------------------------------
357 inline auto FVTermAttribute::isDoubleUnderline() -> bool
358 { return next_attribute.attr.bit.dbl_underline; }
359 
360 //----------------------------------------------------------------------
361 inline auto FVTermAttribute::isAltCharset() -> bool
362 { return next_attribute.attr.bit.alt_charset; }
363 
364 //----------------------------------------------------------------------
365 inline auto FVTermAttribute::isPCcharset() -> bool
366 { return next_attribute.attr.bit.pc_charset; }
367 
368 //----------------------------------------------------------------------
369 inline auto FVTermAttribute::isTransparent() -> bool
370 { return next_attribute.attr.bit.transparent; }
371 
372 //----------------------------------------------------------------------
373 inline auto FVTermAttribute::isColorOverlay() -> bool
374 { return next_attribute.attr.bit.color_overlay; }
375 
376 //----------------------------------------------------------------------
377 inline auto FVTermAttribute::isInheritBackground() -> bool
378 { return next_attribute.attr.bit.inherit_background; }
379 
380 } // namespace finalcut
381 
382 #endif // FVTERMATTRIBUTE_H
Definition: class_template.cpp:25
Definition: ftypes.h:423
Definition: fstring.h:79
Definition: fstyle.h:49
Definition: fcolorpair.h:49
Definition: fvtermattribute.h:53