forked from vdr-projects/vdr-plugin-skinflatplus
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcomplexcontent.h
More file actions
217 lines (181 loc) · 6.86 KB
/
complexcontent.h
File metadata and controls
217 lines (181 loc) · 6.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
* Skin flatPlus: A plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id$
*/
#pragma once
#include <vdr/osd.h>
#include <vdr/font.h>
#include <vdr/tools.h>
#include <memory>
#include <string>
#include <vector>
#include "./flat.h"
enum eContentType {
CT_Text,
CT_TextMultiline,
CT_Image,
CT_Rect,
CT_None
};
enum eContentImageAlignment {
CIP_Right
};
class cSimpleContent {
private:
int m_ContentType {CT_None}; // Added to avoid compiler warning
cRect m_Position {0, 0, 0, 0};
int m_TextWidth {0}, m_TextHeight {0}, m_TextAlignment {0};
tColor m_ColorFg {0}, m_ColorBg {0};
cString m_Text {""};
cImage *m_Image {nullptr};
cFont *m_Font {nullptr};
void DrawMultilineText(cPixmap *Pixmap) const {
cTextFloatingWrapper Wrapper;
Wrapper.Set(*m_Text, m_Font, m_Position.Width());
std::string Line;
Line.reserve(128);
const int Lines {Wrapper.Lines()};
const int FontHeight {m_Font->Height()};
for (int i {0}; i < Lines; ++i) {
Line = Wrapper.GetLine(i);
if (Config.MenuEventRecordingViewJustify == 1 && i < (Lines - 1)) {
JustifyLine(Line, m_Font, m_Position.Width());
}
Pixmap->DrawText(cPoint(m_Position.Left(), m_Position.Top() + (i * FontHeight)),
Line.c_str(), m_ColorFg, m_ColorBg, m_Font,
m_TextWidth, m_TextHeight, m_TextAlignment);
}
}
public:
cSimpleContent() {
}
cSimpleContent(const cSimpleContent& rhs) { // Added to avoid compiler warning
m_ContentType = rhs.m_ContentType;
m_Position = rhs.m_Position;
m_TextWidth = rhs.m_TextWidth;
m_TextHeight = rhs.m_TextHeight;
m_TextAlignment = rhs.m_TextAlignment;
m_ColorFg = rhs.m_ColorFg;
m_ColorBg = rhs.m_ColorBg;
m_Text = rhs.m_Text;
m_Image = rhs.m_Image;
m_Font = rhs.m_Font;
}
~cSimpleContent() {
}
cSimpleContent& operator=(const cSimpleContent& other) {
if (this != &other) {
this->m_ContentType = other.m_ContentType;
this->m_Position = other.m_Position;
this->m_TextWidth = other.m_TextWidth;
this->m_TextHeight = other.m_TextHeight;
this->m_TextAlignment = other.m_TextAlignment;
this->m_ColorFg = other.m_ColorFg;
this->m_ColorBg = other.m_ColorBg;
this->m_Text = other.m_Text;
this->m_Image = other.m_Image;
this->m_Font = other.m_Font;
}
return *this;
}
void SetText(const char *Text, bool Multiline, const cRect &Position, tColor ColorFg, tColor ColorBg, cFont *Font,
int TextWidth = 0, int TextHeight = 0, int TextAlignment = taDefault) {
m_ContentType = (Multiline) ? CT_TextMultiline : CT_Text;
m_Position = Position;
m_Text = Text;
m_Font = Font;
m_TextWidth = TextWidth; m_TextHeight = TextHeight; m_TextAlignment = TextAlignment;
m_ColorFg = ColorFg; m_ColorBg = ColorBg;
}
void SetImage(cImage *image, const cRect &Position) {
if (!image) return;
m_ContentType = CT_Image;
m_Position = Position;
m_Image = image;
}
void SetRect(const cRect &Position, tColor ColorBg) {
m_ContentType = CT_Rect;
m_Position = Position;
m_ColorBg = ColorBg;
}
int GetContentType() const { return m_ContentType; }
int GetBottom() const {
switch (m_ContentType) {
case CT_Text:
// FontCache is returning different values for the same font
// const int FontHeight {FontCache.GetFontHeight(Setup.FontOsd, m_Font->Size())};
return m_Position.Top() + m_Font->Height();
case CT_TextMultiline:
{
cTextFloatingWrapper Wrapper;
Wrapper.Set(*m_Text, m_Font, m_Position.Width());
return m_Position.Top() + (Wrapper.Lines() * m_Font->Height());
}
case CT_Image: return m_Position.Top() + m_Image->Height();
case CT_Rect: return m_Position.Top() + m_Position.Height();
case CT_None:
default: return 0;
}
}
void Draw(cPixmap *Pixmap) const {
if (!Pixmap) return;
// if (!m_Font || !m_Text) return;
switch (m_ContentType) {
case CT_Text:
Pixmap->DrawText(m_Position.Point(), *m_Text, m_ColorFg, m_ColorBg, m_Font, m_TextWidth, m_TextHeight,
m_TextAlignment);
return;
case CT_TextMultiline: DrawMultilineText(Pixmap); return;
case CT_Rect: Pixmap->DrawRectangle(m_Position, m_ColorBg); return;
case CT_Image: Pixmap->DrawImage(m_Position.Point(), *m_Image); return;
}
}
};
class cComplexContent {
public:
cComplexContent();
cComplexContent(cOsd *osd, int ScrollSize);
~cComplexContent();
void SetOsd(cOsd *osd) { m_Osd = osd; }
void SetPosition(const cRect &Position) { m_Position = Position; }
void SetScrollSize(int ScrollSize) { m_ScrollSize = ScrollSize; }
void SetBGColor(tColor ColorBg) { m_ColorBg = ColorBg; }
void CreatePixmaps(bool FullFillBackground);
void Clear();
void AddText(const char *Text, bool Multiline, const cRect &Position, tColor ColorFg, tColor ColorBg, cFont *Font,
int TextWidth = 0, int TextHeight = 0, int TextAlignment = taDefault);
void AddImage(cImage *image, const cRect &Position);
void AddImageWithFloatedText(cImage *image, int imageAlignment, const char *Text, int Margin, const cRect &TextPos,
tColor ColorFg, tColor ColorBg, cFont *Font, int TextWidth = 0, int TextHeight = 0,
int TextAlignment = taDefault);
void AddRect(const cRect &Position, tColor ColorBg);
bool Scrollable(int height = 0);
int ScrollTotal() const;
int ScrollOffset() const;
int ScrollShown() const;
bool Scroll(bool Up, bool Page);
double ScrollbarSize() const;
void SetScrollingActive(bool active) { m_IsScrollingActive = active; }
int Height() const { return m_Position.Height(); }
int ContentHeight(bool Full);
int BottomContent() const;
int Top() const { return m_Position.Top(); }
void Draw();
bool IsShown() const { return m_IsShown; }
bool IsScrollingActive() const { return m_IsScrollingActive; }
private:
std::vector<cSimpleContent> Contents;
cOsd *m_Osd {nullptr};
cPixmap *Pixmap {nullptr}, *PixmapImage {nullptr};
cRect m_Position {0, 0, 0, 0};
tColor m_ColorBg {0};
bool m_FullFillBackground {false};
int m_DrawPortHeight {0};
int m_ScrollSize {0};
bool m_IsShown {false};
bool m_IsScrollingActive {true};
void CalculateDrawPortHeight();
};