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