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