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