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 <utility>
8 #include <vector>
9 using namespace std;
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 
77 {
78  public:
81  uint m_textTag {0};
82  uint m_fontTag {0}; // system font
83  uint m_edgeType {k708AttrEdgeNone};
84  bool m_underline {false};
85  bool m_italics {false};
86  bool m_boldface {false};
87 
88  uint m_fgColor {k708AttrColorWhite}; // will be overridden
89  uint m_fgOpacity {k708AttrOpacitySolid}; // solid
90  uint m_bgColor {k708AttrColorBlack};
91  uint m_bgOpacity {k708AttrOpacitySolid};
92  uint m_edgeColor {k708AttrColorBlack};
93 
94  QColor m_actualFgColor; // if !isValid(), then convert m_fgColor
95 
96  explicit CC708CharacterAttribute(bool isItalic = false,
97  bool isBold = false,
98  bool isUnderline = false,
99  QColor fgColor = QColor()) :
100  m_underline(isUnderline),
101  m_italics(isItalic),
102  m_boldface(isBold),
103  m_actualFgColor(std::move(fgColor))
104  {
105  }
106 
107  static QColor ConvertToQColor(uint eia708color);
108  QColor GetFGColor(void) const
109  {
110  QColor fg = (m_actualFgColor.isValid() ?
111  m_actualFgColor : ConvertToQColor(m_fgColor));
112  fg.setAlpha(GetFGAlpha());
113  return fg;
114  }
115  QColor GetBGColor(void) const
116  {
117  QColor bg = ConvertToQColor(m_bgColor);
118  bg.setAlpha(GetBGAlpha());
119  return bg;
120  }
121  QColor GetEdgeColor(void) const { return ConvertToQColor(m_edgeColor); }
122 
123  uint GetFGAlpha(void) const
124  {
125  //SOLID=0, FLASH=1, TRANSLUCENT=2, and TRANSPARENT=3.
126  static uint alpha[4] = { 0xff, 0xff, 0x7f, 0x00, };
127  return alpha[m_fgOpacity & 0x3];
128  }
129 
130  uint GetBGAlpha(void) const
131  {
132  //SOLID=0, FLASH=1, TRANSLUCENT=2, and TRANSPARENT=3.
133  static uint alpha[4] = { 0xff, 0xff, 0x7f, 0x00, };
134  return alpha[m_bgOpacity & 0x3];
135  }
136 
137  bool operator==(const CC708CharacterAttribute &other) const;
138  bool operator!=(const CC708CharacterAttribute &other) const
139  { return !(*this == other); }
140 };
141 
142 class CC708Pen
143 {
144  public:
145  CC708Pen() = default;
146  void SetPenStyle(uint style);
147  void SetAttributes(int pen_size,
148  int offset, int text_tag, int font_tag,
149  int edge_type, int underline, int italics)
150  {
151  m_attr.m_penSize = pen_size;
152  m_attr.m_offset = offset;
153  m_attr.m_textTag = text_tag;
154  m_attr.m_fontTag = font_tag;
155  m_attr.m_edgeType = edge_type;
156  m_attr.m_underline = (underline != 0);
157  m_attr.m_italics = (italics != 0);
158  m_attr.m_boldface = false;
159  }
160  public:
162 
163  uint m_row {0};
164  uint m_column {0};
165 };
166 
167 class CC708Window;
169 {
170  public:
171  CC708Character() = default;
172  explicit CC708Character(const CC708Window &win);
174  QChar m_character {' '};
175 };
176 
178 {
179  public:
180  uint m_x {0};
181  uint m_y {0};
182  QString m_str;
184 };
185 
187 {
188  public:
189  CC708Window() = default;
190  ~CC708Window();
191 
192  void DefineWindow(int priority, bool visible,
193  int anchor_point, int relative_pos,
194  int anchor_vertical, int anchor_horizontal,
195  int row_count, int column_count,
196  int row_lock, int column_lock,
197  int pen_style, int window_style);
198  void Resize(uint new_rows, uint new_columns);
199  void Clear(void);
200  void SetWindowStyle(uint style);
201 
202  void AddChar(QChar ch);
203  void IncrPenLocation(void);
204  void DecrPenLocation(void);
205  void SetPenLocation(uint row, uint column);
206  void LimitPenLocation(void);
207 
208  bool IsPenValid(void) const
209  {
210  return ((m_pen.m_row < m_true_row_count) &&
211  (m_pen.m_column < m_true_column_count));
212  }
213  CC708Character &GetCCChar(void) const;
214  vector<CC708String*> GetStrings(void) const;
215  static void DisposeStrings(vector<CC708String*> &strings);
216  QColor GetFillColor(void) const
217  {
218  QColor fill = CC708CharacterAttribute::ConvertToQColor(m_fill_color);
219  fill.setAlpha(GetFillAlpha());
220  return fill;
221  }
222  uint GetFillAlpha(void) const
223  {
224  //SOLID=0, FLASH=1, TRANSLUCENT=2, and TRANSPARENT=3.
225  static uint alpha[4] = { 0xff, 0xff, 0x7f, 0x00, };
226  return alpha[m_fill_opacity & 0x3];
227  }
228 
229  private:
230  void Scroll(int row, int col);
231 
232  public:
233  uint m_priority {0};
234  private:
235  bool m_visible {false};
236  public:
237  enum {
238  kAnchorUpperLeft = 0, kAnchorUpperCenter, kAnchorUpperRight,
239  kAnchorCenterLeft = 3, kAnchorCenter, kAnchorCenterRight,
240  kAnchorLowerLeft = 6, kAnchorLowerCenter, kAnchorLowerRight,
241  };
242  uint m_anchor_point {0};
243  uint m_relative_pos {0};
244  uint m_anchor_vertical {0};
245  uint m_anchor_horizontal {0};
246  uint m_row_count {0};
247  uint m_column_count {0};
248  uint m_row_lock {0};
249  uint m_column_lock {0};
250 // uint m_pen_style {0};
251 // uint m_window_style {0};
252 
253  uint m_fill_color {0};
254  uint m_fill_opacity {0};
255  uint m_border_color {0};
256  uint m_border_type {0};
257  uint m_scroll_dir {0};
258  uint m_print_dir {0};
259  uint m_effect_dir {0};
260  uint m_display_effect {0};
261  uint m_effect_speed {0};
262  uint m_justify {0};
263  uint m_word_wrap {0};
264 
265  // These are akin to the capacity of a vector, which is always >=
266  // the current size.
267  uint m_true_row_count {0};
268  uint m_true_column_count {0};
269 
270  CC708Character *m_text {nullptr};
272 
273  private:
275  bool m_exists {false};
276  bool m_changed {true};
277 
278  public:
279  bool GetExists(void) const { return m_exists; }
280  bool GetVisible(void) const { return m_visible; }
281  bool GetChanged(void) const { return m_changed; }
282  void SetExists(bool value)
283  {
284  if (m_exists != value)
285  SetChanged();
286  m_exists = value;
287  }
288  void SetVisible(bool value)
289  {
290  if (m_visible != value)
291  SetChanged();
292  m_visible = value;
293  }
294  void SetChanged(void)
295  {
296  m_changed = true;
297  }
298  void ResetChanged(void)
299  {
300  m_changed = false;
301  }
302  mutable QMutex m_lock {QMutex::Recursive};
303 };
304 
306 {
307  public:
308  CC708Service() = default;
309 
310  public:
311  uint m_currentWindow {0};
313 };
314 
315 #endif // CC708_WINDOW_H
void SetVisible(bool value)
Definition: cc708window.h:288
bool operator!=(const CC708CharacterAttribute &other) const
Definition: cc708window.h:138
const uint k708AttrOffsetSubscript
Definition: cc708window.cpp:81
const uint k708AttrOpacitySolid
const uint k708AttrFontMonospacedSansSerif
Definition: cc708window.cpp:88
CC708CharacterAttribute m_attr
Definition: cc708window.h:173
const uint k708AttrEdgeRaised
Definition: cc708window.cpp:95
const uint k708AttrFontProportionalSerif
Definition: cc708window.cpp:87
const uint k708AttrEdgeNone
Definition: cc708window.cpp:94
QColor GetEdgeColor(void) const
Definition: cc708window.h:121
const uint k708JustifyRight
Definition: cc708window.cpp:57
bool operator==(MusicMetadata &a, MusicMetadata &b)
const uint k708AttrSizeSmall
Definition: cc708window.cpp:77
const int k708MaxRows
Definition: cc708window.h:73
CC708CharacterAttribute(bool isItalic=false, bool isBold=false, bool isUnderline=false, QColor fgColor=QColor())
Definition: cc708window.h:96
const uint k708DirRightToLeft
Definition: cc708window.cpp:73
const uint k708AttrColorWhite
void SetAttributes(int pen_size, int offset, int text_tag, int font_tag, int edge_type, int underline, int italics)
Definition: cc708window.h:147
const uint k708EffectWipe
Definition: cc708window.cpp:63
const uint k708EffectSnap
Definition: cc708window.cpp:61
const uint k708AttrFontDefault
Definition: cc708window.cpp:85
const uint k708AttrFontSmallCaps
Definition: cc708window.cpp:92
void SetExists(bool value)
Definition: cc708window.h:282
const uint k708AttrEdgeUniform
Definition: cc708window.cpp:97
const uint k708BorderUniform
Definition: cc708window.cpp:68
#define MTV_PUBLIC
Definition: mythtvexp.h:15
const uint k708AttrSizeLarge
Definition: cc708window.cpp:79
const uint k708AttrOffsetSuperscript
Definition: cc708window.cpp:83
const uint k708BorderDepressed
Definition: cc708window.cpp:67
const uint k708DirLeftToRight
Definition: cc708window.cpp:72
const uint k708DirTopToBottom
Definition: cc708window.cpp:74
const uint k708BorderShadowRight
Definition: cc708window.cpp:70
bool GetVisible(void) const
Definition: cc708window.h:280
const uint k708AttrFontCursive
Definition: cc708window.cpp:91
uint GetFGAlpha(void) const
Definition: cc708window.h:123
QString m_str
Definition: cc708window.h:182
static QColor ConvertToQColor(uint eia708color)
unsigned int uint
Definition: compat.h:140
const uint k708BorderNone
Definition: cc708window.cpp:65
QColor GetFGColor(void) const
Definition: cc708window.h:108
const uint k708AttrOpacityFlash
void SetChanged(void)
Definition: cc708window.h:294
bool GetChanged(void) const
Definition: cc708window.h:281
uint GetBGAlpha(void) const
Definition: cc708window.h:130
const uint k708AttrFontCasual
Definition: cc708window.cpp:90
const int k708MaxColumns
Definition: cc708window.h:74
const uint k708EffectFade
Definition: cc708window.cpp:62
const uint k708JustifyCenter
Definition: cc708window.cpp:58
CC708CharacterAttribute m_attr
Definition: cc708window.h:183
const uint k708BorderShadowLeft
Definition: cc708window.cpp:69
const uint k708BorderRaised
Definition: cc708window.cpp:66
const uint k708AttrOffsetNormal
Definition: cc708window.cpp:82
QColor GetBGColor(void) const
Definition: cc708window.h:115
const uint k708JustifyLeft
Definition: cc708window.cpp:56
const uint k708AttrEdgeLeftDropShadow
Definition: cc708window.cpp:98
bool IsPenValid(void) const
Definition: cc708window.h:208
const uint k708AttrSizeStandard
Definition: cc708window.cpp:78
const uint k708AttrColorBlack
const uint k708JustifyFull
Definition: cc708window.cpp:59
const uint k708AttrEdgeRightDropShadow
Definition: cc708window.cpp:99
const int k708MaxWindows
Definition: cc708window.h:72
CC708CharacterAttribute m_attr
Definition: cc708window.h:161
bool GetExists(void) const
Definition: cc708window.h:279
#define Clear(a)
const uint k708DirBottomToTop
Definition: cc708window.cpp:75
QColor GetFillColor(void) const
Definition: cc708window.h:216
void ResetChanged(void)
Definition: cc708window.h:298
uint GetFillAlpha(void) const
Definition: cc708window.h:222
const uint k708AttrOpacityTransparent
CC708Pen m_pen
Definition: cc708window.h:271
const uint k708AttrOpacityTranslucent
const uint k708AttrFontProportionalSansSerif
Definition: cc708window.cpp:89
const uint k708AttrFontMonospacedSerif
Definition: cc708window.cpp:86
const uint k708AttrEdgeDepressed
Definition: cc708window.cpp:96