FINAL CUT
fstyle.h
1 /***********************************************************************
2 * fstyle.h - Style attribute of a character *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2020-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  * ▕ FStyle ▏
28  * ▕▁▁▁▁▁▁▁▁▏
29  */
30 
31 #ifndef FSTYLE_H
32 #define FSTYLE_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/fc.h"
39 #include "final/ftypes.h"
40 #include "final/util/fstring.h"
41 
42 namespace finalcut
43 {
44 
45 //----------------------------------------------------------------------
46 // class FStyle
47 //----------------------------------------------------------------------
48 
49 class FStyle
50 {
51  public:
52  // Constructors
53  explicit FStyle (Style attr = Style::None)
54  : attribute{attr}
55  { }
56 
57  // Accessor
58  auto getClassName() const -> FString
59  { return "FStyle"; }
60 
61  inline auto getStyle() const noexcept -> Style
62  { return attribute; }
63 
64  // Mutators
65  inline void setStyle (const FStyle& style) noexcept
66  { attribute = style.attribute & Style(ATTRIBUTE_MASK); }
67 
68  inline void setStyle (Style attr) noexcept
69  { attribute = attr & Style(ATTRIBUTE_MASK); }
70 
71  auto toFCharAttribute() const noexcept -> FCharAttribute
72  {
73  FCharAttribute fchar_attr{};
74  fchar_attr.bold = (attribute & Style::Bold) != Style::None;
75  fchar_attr.dim = (attribute & Style::Dim) != Style::None;
76  fchar_attr.italic = (attribute & Style::Italic) != Style::None;
77  fchar_attr.underline = (attribute & Style::Underline) != Style::None;
78  fchar_attr.blink = (attribute & Style::Blink) != Style::None;
79  fchar_attr.reverse = (attribute & Style::Reverse) != Style::None;
80  fchar_attr.standout = (attribute & Style::Standout) != Style::None;
81  fchar_attr.invisible = (attribute & Style::Invisible) != Style::None;
82  fchar_attr.protect = (attribute & Style::Protected) != Style::None;
83  fchar_attr.crossed_out = (attribute & Style::CrossedOut) != Style::None;
84  fchar_attr.dbl_underline = (attribute & Style::DoubleUnderline) != Style::None;
85  fchar_attr.transparent = (attribute & Style::Transparent) != Style::None;
86  fchar_attr.color_overlay = (attribute & Style::ColorOverlay) != Style::None;
87  fchar_attr.inherit_background = (attribute & Style::InheritBackground) != Style::None;
88  return fchar_attr;
89  }
90 
91  auto toFAttribute() const noexcept -> FAttribute
92  {
93  FCharAttribute fchar_attr{toFCharAttribute()};
94  FAttribute fattr{};
95  std::memcpy(&fattr, &fchar_attr, sizeof(fattr));
96  return fattr;
97  }
98 
99  private:
100  // Constant
101  static constexpr auto ATTRIBUTE_MASK = \
102  Style((uInt16(Style::InheritBackground) << 1) - 1);
103 
104  // Data members
105  Style attribute; // Save character attributes
106 };
107 
108 } // namespace finalcut
109 
110 #endif // FSTYLE_H
Definition: class_template.cpp:25
Definition: fstring.h:79
Definition: fstyle.h:49
Definition: ftypes.h:370
Definition: ftypes.h:274