MythTV  master
cc708window.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 // Copyright (c) 2003-2005, Daniel Kristjansson
3 
4 #ifndef CC708_WINDOW_H
5 #define CC708_WINDOW_H
6 
7 #include <array>
8 #include <utility>
9 #include <vector>
10 
11 // Qt headers
12 #include <QString>
13 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
14 #include <QMutex>
15 #else
16 #include <QRecursiveMutex>
17 #endif
18 #include <QColor>
19 
20 // MythTV headers
21 #include "mythtvexp.h"
22 
23 extern const uint k708JustifyLeft;
24 extern const uint k708JustifyRight;
25 extern const uint k708JustifyCenter;
26 extern const uint k708JustifyFull;
27 
28 extern const uint k708EffectSnap;
29 extern const uint k708EffectFade;
30 extern const uint k708EffectWipe;
31 
32 extern const uint k708BorderNone;
33 extern const uint k708BorderRaised;
34 extern const uint k708BorderDepressed;
35 extern const uint k708BorderUniform;
36 extern const uint k708BorderShadowLeft;
37 extern const uint k708BorderShadowRight;
38 
39 extern const uint k708DirLeftToRight;
40 extern const uint k708DirRightToLeft;
41 extern const uint k708DirTopToBottom;
42 extern const uint k708DirBottomToTop;
43 
44 extern const uint k708AttrSizeSmall;
45 extern const uint k708AttrSizeStandard;
46 extern const uint k708AttrSizeLarge;
47 
48 extern const uint k708AttrOffsetSubscript;
49 extern const uint k708AttrOffsetNormal;
50 extern const uint k708AttrOffsetSuperscript;
51 
52 extern const uint k708AttrFontDefault;
57 extern const uint k708AttrFontCasual;
58 extern const uint k708AttrFontCursive;
59 extern const uint k708AttrFontSmallCaps;
60 
61 extern const uint k708AttrEdgeNone;
62 extern const uint k708AttrEdgeRaised;
63 extern const uint k708AttrEdgeDepressed;
64 extern const uint k708AttrEdgeUniform;
65 extern const uint k708AttrEdgeLeftDropShadow;
67 
68 extern const uint k708AttrColorBlack;
69 extern const uint k708AttrColorWhite;
70 
71 extern const uint k708AttrOpacitySolid;
72 extern const uint k708AttrOpacityFlash;
73 extern const uint k708AttrOpacityTranslucent;
74 extern const uint k708AttrOpacityTransparent;
75 
76 const int k708MaxWindows = 8;
77 const int k708MaxRows = 16; // 4-bit field in DefineWindow
78 const int k708MaxColumns = 64; // 6-bit field in DefineWindow
79 
80 // Weird clang-tidy error from cc708window.cpp:212 that the attribute
81 // assignment is using zero allocated memory. Changing that code to
82 // explicitly copy each field of the structure, and then changing the
83 // first copy statement to assign a constant instead, shows that the
84 // warning is about the left side of the assignment statement. That
85 // should overwrite any zero-allocated memory, not reference it.
86 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDelete)
88 {
89  public:
93  uint m_fontTag {0}; // system font
95  bool m_underline {false};
96  bool m_italics {false};
97  bool m_boldface {false};
98 
99  uint m_fgColor {k708AttrColorWhite}; // will be overridden
104 
105  QColor m_actualFgColor; // if !isValid(), then convert m_fgColor
106 
107  explicit CC708CharacterAttribute(bool isItalic = false,
108  bool isBold = false,
109  bool isUnderline = false,
110  QColor fgColor = QColor()) :
111  m_underline(isUnderline),
112  m_italics(isItalic),
113  m_boldface(isBold),
114  // NOLINTNEXTLINE(performance-move-const-arg)
115  m_actualFgColor(std::move(fgColor))
116  {
117  }
118 
119  static QColor ConvertToQColor(uint eia708color);
120  QColor GetFGColor(void) const
121  {
122  QColor fg = (m_actualFgColor.isValid() ?
124  fg.setAlpha(GetFGAlpha());
125  return fg;
126  }
127  QColor GetBGColor(void) const
128  {
129  QColor bg = ConvertToQColor(m_bgColor);
130  bg.setAlpha(GetBGAlpha());
131  return bg;
132  }
133  QColor GetEdgeColor(void) const { return ConvertToQColor(m_edgeColor); }
134 
135  uint GetFGAlpha(void) const
136  {
137  //SOLID=0, FLASH=1, TRANSLUCENT=2, and TRANSPARENT=3.
138  static constexpr std::array<const uint,4> alpha = { 0xff, 0xff, 0x7f, 0x00, };
139  return alpha[m_fgOpacity & 0x3];
140  }
141 
142  uint GetBGAlpha(void) const
143  {
144  //SOLID=0, FLASH=1, TRANSLUCENT=2, and TRANSPARENT=3.
145  static constexpr std::array<const uint,4> alpha = { 0xff, 0xff, 0x7f, 0x00, };
146  return alpha[m_bgOpacity & 0x3];
147  }
148 
149  bool operator==(const CC708CharacterAttribute &other) const;
150  bool operator!=(const CC708CharacterAttribute &other) const
151  { return !(*this == other); }
152 };
153 
154 class CC708Pen
155 {
156  public:
157  CC708Pen() = default;
158  void SetPenStyle(uint style);
159  void SetAttributes(int pen_size,
160  int offset, int text_tag, int font_tag,
161  int edge_type, int underline, int italics)
162  {
163  m_attr.m_penSize = pen_size;
164  m_attr.m_offset = offset;
165  m_attr.m_textTag = text_tag;
166  m_attr.m_fontTag = font_tag;
167  m_attr.m_edgeType = edge_type;
168  m_attr.m_underline = (underline != 0);
169  m_attr.m_italics = (italics != 0);
170  m_attr.m_boldface = false;
171  }
172  public:
174 
175  uint m_row {0};
177 };
178 
179 class CC708Window;
181 {
182  public:
183  CC708Character() = default;
184  explicit CC708Character(const CC708Window &win);
186  QChar m_character {' '};
187 };
188 
190 {
191  public:
192  uint m_x {0};
193  uint m_y {0};
194  QString m_str;
196 };
197 
199 {
200  public:
201  CC708Window() = default;
202  ~CC708Window();
203 
204  void DefineWindow(int priority, bool visible,
205  int anchor_point, int relative_pos,
206  int anchor_vertical, int anchor_horizontal,
207  int row_count, int column_count,
208  int row_lock, int column_lock,
209  int pen_style, int window_style);
210  void Resize(uint new_rows, uint new_columns);
211  void Clear(void);
212  void SetWindowStyle(uint style);
213 
214  void AddChar(QChar ch);
215  void IncrPenLocation(void);
216  void DecrPenLocation(void);
217  void SetPenLocation(uint row, uint column);
218  void LimitPenLocation(void);
219 
220  bool IsPenValid(void) const
221  {
222  return ((m_pen.m_row < m_true_row_count) &&
223  (m_pen.m_column < m_true_column_count));
224  }
225  CC708Character &GetCCChar(void) const;
226  std::vector<CC708String*> GetStrings(void) const;
227  static void DisposeStrings(std::vector<CC708String*> &strings);
228  QColor GetFillColor(void) const
229  {
230  QColor fill = CC708CharacterAttribute::ConvertToQColor(m_fill_color);
231  fill.setAlpha(GetFillAlpha());
232  return fill;
233  }
234  uint GetFillAlpha(void) const
235  {
236  //SOLID=0, FLASH=1, TRANSLUCENT=2, and TRANSPARENT=3.
237  static constexpr std::array<const uint,4> alpha = { 0xff, 0xff, 0x7f, 0x00, };
238  return alpha[m_fill_opacity & 0x3];
239  }
240 
241  private:
242  void Scroll(int row, int col);
243 
244  public:
245  uint m_priority {0};
246  private:
247  bool m_visible {false};
248  public:
249  enum {
250  kAnchorUpperLeft = 0, kAnchorUpperCenter, kAnchorUpperRight,
251  kAnchorCenterLeft = 3, kAnchorCenter, kAnchorCenterRight,
252  kAnchorLowerLeft = 6, kAnchorLowerCenter, kAnchorLowerRight,
253  };
254  uint m_anchor_point {0};
255  uint m_relative_pos {0};
256  uint m_anchor_vertical {0};
257  uint m_anchor_horizontal {0};
258  uint m_row_count {0};
259  uint m_column_count {0};
260  uint m_row_lock {0};
261  uint m_column_lock {0};
262 // uint m_pen_style {0};
263 // uint m_window_style {0};
264 
265  uint m_fill_color {0};
266  uint m_fill_opacity {0};
267  uint m_border_color {0};
268  uint m_border_type {0};
269  uint m_scroll_dir {0};
270  uint m_print_dir {0};
271  uint m_effect_dir {0};
272  uint m_display_effect {0};
273  uint m_effect_speed {0};
274  uint m_justify {0};
275  uint m_word_wrap {0};
276 
277  // These are akin to the capacity of a vector, which is always >=
278  // the current size.
279  uint m_true_row_count {0};
280  uint m_true_column_count {0};
281 
282  CC708Character *m_text {nullptr};
283  CC708Pen m_pen {};
284 
285  private:
287  bool m_exists {false};
288  bool m_changed {true};
289 
290  public:
291  bool GetExists(void) const { return m_exists; }
292  bool GetVisible(void) const { return m_visible; }
293  bool GetChanged(void) const { return m_changed; }
294  void SetExists(bool value)
295  {
296  if (m_exists != value)
297  SetChanged();
298  m_exists = value;
299  }
300  void SetVisible(bool value)
301  {
302  if (m_visible != value)
303  SetChanged();
304  m_visible = value;
305  }
306  void SetChanged(void)
307  {
308  m_changed = true;
309  }
310  void ResetChanged(void)
311  {
312  m_changed = false;
313  }
314 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
315  mutable QMutex m_lock {QMutex::Recursive};
316 #else
317  mutable QRecursiveMutex m_lock;
318 #endif
319 };
320 
322 {
323  public:
324  CC708Service() = default;
325 
326  public:
328  std::array<CC708Window,k708MaxWindows> m_windows;
329 };
330 
331 #endif // CC708_WINDOW_H
k708JustifyCenter
const uint k708JustifyCenter
Definition: cc708window.cpp:57
k708AttrEdgeDepressed
const uint k708AttrEdgeDepressed
Definition: cc708window.cpp:95
CC708Pen::m_attr
CC708CharacterAttribute m_attr
Definition: cc708window.h:173
k708AttrSizeStandard
const uint k708AttrSizeStandard
Definition: cc708window.cpp:77
CC708Window::kAnchorLowerRight
@ kAnchorLowerRight
Definition: cc708window.h:252
k708AttrOffsetSubscript
const uint k708AttrOffsetSubscript
Definition: cc708window.cpp:80
CC708Window::kAnchorUpperRight
@ kAnchorUpperRight
Definition: cc708window.h:250
CC708CharacterAttribute::GetEdgeColor
QColor GetEdgeColor(void) const
Definition: cc708window.h:133
CC708Pen::m_column
uint m_column
Definition: cc708window.h:176
k708AttrOpacityFlash
const uint k708AttrOpacityFlash
Definition: cc708window.cpp:104
k708BorderDepressed
const uint k708BorderDepressed
Definition: cc708window.cpp:66
CC708Service::m_currentWindow
uint m_currentWindow
Definition: cc708window.h:327
CC708CharacterAttribute::operator==
bool operator==(const CC708CharacterAttribute &other) const
Definition: cc708window.cpp:679
CC708Pen::SetAttributes
void SetAttributes(int pen_size, int offset, int text_tag, int font_tag, int edge_type, int underline, int italics)
Definition: cc708window.h:159
CC708Service::m_windows
std::array< CC708Window, k708MaxWindows > m_windows
Definition: cc708window.h:328
CC708Service::CC708Service
CC708Service()=default
CC708CharacterAttribute::m_edgeType
uint m_edgeType
Definition: cc708window.h:94
k708EffectFade
const uint k708EffectFade
Definition: cc708window.cpp:61
CC708Window::m_lock
QRecursiveMutex m_lock
Definition: cc708window.h:317
CC708CharacterAttribute::CC708CharacterAttribute
CC708CharacterAttribute(bool isItalic=false, bool isBold=false, bool isUnderline=false, QColor fgColor=QColor())
Definition: cc708window.h:107
k708AttrOpacityTranslucent
const uint k708AttrOpacityTranslucent
Definition: cc708window.cpp:105
k708DirBottomToTop
const uint k708DirBottomToTop
Definition: cc708window.cpp:74
k708AttrEdgeLeftDropShadow
const uint k708AttrEdgeLeftDropShadow
Definition: cc708window.cpp:97
k708MaxColumns
const int k708MaxColumns
Definition: cc708window.h:78
CC708CharacterAttribute::m_penSize
uint m_penSize
Definition: cc708window.h:90
CC708Window
Definition: cc708window.h:198
CC708CharacterAttribute::m_edgeColor
uint m_edgeColor
Definition: cc708window.h:103
k708DirRightToLeft
const uint k708DirRightToLeft
Definition: cc708window.cpp:72
mythtvexp.h
CC708CharacterAttribute::m_fontTag
uint m_fontTag
Definition: cc708window.h:93
k708JustifyFull
const uint k708JustifyFull
Definition: cc708window.cpp:58
k708AttrOffsetNormal
const uint k708AttrOffsetNormal
Definition: cc708window.cpp:81
k708AttrFontCursive
const uint k708AttrFontCursive
Definition: cc708window.cpp:90
CC708CharacterAttribute
Definition: cc708window.h:87
CC708CharacterAttribute::m_fgOpacity
uint m_fgOpacity
Definition: cc708window.h:100
k708AttrEdgeRaised
const uint k708AttrEdgeRaised
Definition: cc708window.cpp:94
CC708Character::m_character
QChar m_character
Definition: cc708window.h:186
CC708CharacterAttribute::m_bgOpacity
uint m_bgOpacity
Definition: cc708window.h:102
CC708Pen
Definition: cc708window.h:154
k708AttrOffsetSuperscript
const uint k708AttrOffsetSuperscript
Definition: cc708window.cpp:82
k708EffectWipe
const uint k708EffectWipe
Definition: cc708window.cpp:62
CC708CharacterAttribute::m_actualFgColor
QColor m_actualFgColor
Definition: cc708window.h:105
k708AttrFontSmallCaps
const uint k708AttrFontSmallCaps
Definition: cc708window.cpp:91
k708AttrEdgeUniform
const uint k708AttrEdgeUniform
Definition: cc708window.cpp:96
CC708Window::GetVisible
bool GetVisible(void) const
Definition: cc708window.h:292
CC708String
Definition: cc708window.h:189
CC708CharacterAttribute::m_boldface
bool m_boldface
Definition: cc708window.h:97
CC708Character
Definition: cc708window.h:180
k708BorderNone
const uint k708BorderNone
Definition: cc708window.cpp:64
CC708Character::m_attr
CC708CharacterAttribute m_attr
Definition: cc708window.h:185
CC708CharacterAttribute::GetFGColor
QColor GetFGColor(void) const
Definition: cc708window.h:120
k708AttrOpacityTransparent
const uint k708AttrOpacityTransparent
Definition: cc708window.cpp:106
CC708Service
Definition: cc708window.h:321
k708BorderRaised
const uint k708BorderRaised
Definition: cc708window.cpp:65
CC708CharacterAttribute::GetFGAlpha
uint GetFGAlpha(void) const
Definition: cc708window.h:135
CC708CharacterAttribute::ConvertToQColor
static QColor ConvertToQColor(uint eia708color)
Definition: cc708window.cpp:696
k708AttrEdgeRightDropShadow
const uint k708AttrEdgeRightDropShadow
Definition: cc708window.cpp:98
k708MaxRows
const int k708MaxRows
Definition: cc708window.h:77
k708JustifyLeft
const uint k708JustifyLeft
Definition: cc708window.cpp:55
CC708Window::SetExists
void SetExists(bool value)
Definition: cc708window.h:294
k708BorderShadowLeft
const uint k708BorderShadowLeft
Definition: cc708window.cpp:68
k708AttrFontProportionalSansSerif
const uint k708AttrFontProportionalSansSerif
Definition: cc708window.cpp:88
k708AttrFontMonospacedSerif
const uint k708AttrFontMonospacedSerif
Definition: cc708window.cpp:85
k708AttrFontProportionalSerif
const uint k708AttrFontProportionalSerif
Definition: cc708window.cpp:86
uint
unsigned int uint
Definition: compat.h:144
CC708CharacterAttribute::GetBGColor
QColor GetBGColor(void) const
Definition: cc708window.h:127
CC708CharacterAttribute::GetBGAlpha
uint GetBGAlpha(void) const
Definition: cc708window.h:142
k708MaxWindows
const int k708MaxWindows
Definition: cc708window.h:76
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
k708AttrFontMonospacedSansSerif
const uint k708AttrFontMonospacedSansSerif
Definition: cc708window.cpp:87
k708AttrOpacitySolid
const uint k708AttrOpacitySolid
Definition: cc708window.cpp:103
CC708String::m_y
uint m_y
Definition: cc708window.h:193
k708AttrColorWhite
const uint k708AttrColorWhite
Definition: cc708window.cpp:101
CC708String::m_str
QString m_str
Definition: cc708window.h:194
CC708Window::SetChanged
void SetChanged(void)
Definition: cc708window.h:306
CC708Window::GetChanged
bool GetChanged(void) const
Definition: cc708window.h:293
CC708Pen::SetPenStyle
void SetPenStyle(uint style)
Definition: cc708window.cpp:650
CC708String::m_x
uint m_x
Definition: cc708window.h:192
Clear
#define Clear(a)
Definition: audiooutputopensles.cpp:46
k708AttrEdgeNone
const uint k708AttrEdgeNone
Definition: cc708window.cpp:93
k708EffectSnap
const uint k708EffectSnap
Definition: cc708window.cpp:60
CC708Pen::CC708Pen
CC708Pen()=default
k708AttrColorBlack
const uint k708AttrColorBlack
Definition: cc708window.cpp:100
std
Definition: mythchrono.h:23
k708DirTopToBottom
const uint k708DirTopToBottom
Definition: cc708window.cpp:73
CC708Window::kAnchorCenterRight
@ kAnchorCenterRight
Definition: cc708window.h:251
CC708CharacterAttribute::m_textTag
uint m_textTag
Definition: cc708window.h:92
k708AttrFontCasual
const uint k708AttrFontCasual
Definition: cc708window.cpp:89
CC708Window::GetFillAlpha
uint GetFillAlpha(void) const
Definition: cc708window.h:234
CC708CharacterAttribute::m_offset
uint m_offset
Definition: cc708window.h:91
k708DirLeftToRight
const uint k708DirLeftToRight
Definition: cc708window.cpp:71
CC708Character::CC708Character
CC708Character()=default
CC708Window::ResetChanged
void ResetChanged(void)
Definition: cc708window.h:310
k708BorderUniform
const uint k708BorderUniform
Definition: cc708window.cpp:67
k708AttrSizeSmall
const uint k708AttrSizeSmall
Definition: cc708window.cpp:76
CC708Pen::m_row
uint m_row
Definition: cc708window.h:175
CC708String::m_attr
CC708CharacterAttribute m_attr
Definition: cc708window.h:195
CC708Window::GetFillColor
QColor GetFillColor(void) const
Definition: cc708window.h:228
CC708CharacterAttribute::m_italics
bool m_italics
Definition: cc708window.h:96
CC708Window::SetVisible
void SetVisible(bool value)
Definition: cc708window.h:300
CC708CharacterAttribute::m_bgColor
uint m_bgColor
Definition: cc708window.h:101
k708BorderShadowRight
const uint k708BorderShadowRight
Definition: cc708window.cpp:69
k708JustifyRight
const uint k708JustifyRight
Definition: cc708window.cpp:56
k708AttrFontDefault
const uint k708AttrFontDefault
Definition: cc708window.cpp:84
CC708Window::IsPenValid
bool IsPenValid(void) const
Definition: cc708window.h:220
CC708CharacterAttribute::m_fgColor
uint m_fgColor
Definition: cc708window.h:99
CC708CharacterAttribute::m_underline
bool m_underline
Definition: cc708window.h:95
CC708Window::GetExists
bool GetExists(void) const
Definition: cc708window.h:291
CC708CharacterAttribute::operator!=
bool operator!=(const CC708CharacterAttribute &other) const
Definition: cc708window.h:150
k708AttrSizeLarge
const uint k708AttrSizeLarge
Definition: cc708window.cpp:78