3 |
andreas |
1 |
/*
|
21 |
andreas |
2 |
* Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
|
3 |
andreas |
3 |
*
|
|
|
4 |
* This program is free software; you can redistribute it and/or modify
|
|
|
5 |
* it under the terms of the GNU General Public License as published by
|
|
|
6 |
* the Free Software Foundation; either version 3 of the License, or
|
|
|
7 |
* (at your option) any later version.
|
|
|
8 |
*
|
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
* GNU General Public License for more details.
|
|
|
13 |
*
|
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
|
15 |
* along with this program; if not, write to the Free Software Foundation,
|
|
|
16 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
#ifndef __TSUBPAGE_H__
|
|
|
20 |
#define __TSUBPAGE_H__
|
|
|
21 |
|
|
|
22 |
#include <string>
|
|
|
23 |
#include <vector>
|
|
|
24 |
#include "tbutton.h"
|
|
|
25 |
#include "tvalidatefile.h"
|
4 |
andreas |
26 |
#include "tpalette.h"
|
7 |
andreas |
27 |
#include "tfont.h"
|
3 |
andreas |
28 |
|
|
|
29 |
enum SHOWEFFECT
|
|
|
30 |
{
|
|
|
31 |
SE_NONE,
|
|
|
32 |
SE_FADE,
|
|
|
33 |
SE_SLIDE_LEFT,
|
|
|
34 |
SE_SLIDE_RIGHT,
|
|
|
35 |
SE_SLIDE_TOP,
|
|
|
36 |
SE_SLIDE_BOTTOM,
|
|
|
37 |
SE_SLIDE_LEFT_FADE,
|
|
|
38 |
SE_SLIDE_RIGHT_FADE,
|
|
|
39 |
SE_SLIDE_TOP_FADE,
|
|
|
40 |
SE_SLIDE_BOTTOM_FADE
|
|
|
41 |
};
|
|
|
42 |
|
41 |
andreas |
43 |
typedef SHOWEFFECT SHOWEFFECT_t;
|
|
|
44 |
|
|
|
45 |
typedef struct ANIMATION_t
|
|
|
46 |
{
|
|
|
47 |
SHOWEFFECT_t showEffect{SE_NONE};
|
|
|
48 |
int showTime{0};
|
42 |
andreas |
49 |
SHOWEFFECT_t hideEffect{SE_NONE};
|
|
|
50 |
int hideTime{0};
|
41 |
andreas |
51 |
}ANIMATION_t;
|
|
|
52 |
|
3 |
andreas |
53 |
typedef struct SUBPAGE_T
|
|
|
54 |
{
|
|
|
55 |
std::string popupType; // The type of the popup
|
|
|
56 |
int pageID{0}; // Unique ID of popup/page
|
|
|
57 |
std::string name; // The name of the popup/page
|
|
|
58 |
int left{0}; // Left position of popup
|
|
|
59 |
int top{0}; // Top position of popup
|
|
|
60 |
int width{0}; // Width of popup
|
|
|
61 |
int height{0}; // Height of popup
|
|
|
62 |
int modal{0}; // 0 = Popup/Page = non modal
|
|
|
63 |
std::string group; // Name of the group the popup belongs
|
|
|
64 |
int timeout{0}; // Time after the popup hides in 1/10 seconds
|
|
|
65 |
SHOWEFFECT showEffect{SE_NONE}; // The effect when the popup is shown
|
|
|
66 |
int showTime{0}; // The time reserved for the show effect
|
15 |
andreas |
67 |
int showX{0}; // End of show effect position (by default "left+width");
|
|
|
68 |
int showY{0}; // End of show effect position (by default "top+height");
|
3 |
andreas |
69 |
SHOWEFFECT hideEffect{SE_NONE}; // The effect when the popup hides
|
|
|
70 |
int hideTime{0}; // The time reserved for the hide effect
|
15 |
andreas |
71 |
int hideX{0}; // End of hide effect position (by default "left");
|
|
|
72 |
int hideY{0}; // End of hide effect position (by default "top");
|
3 |
andreas |
73 |
std::vector<Button::SR_T> sr; // Page/Popup description
|
|
|
74 |
}SUBPAGE_T;
|
|
|
75 |
|
11 |
andreas |
76 |
typedef struct RECT_T
|
|
|
77 |
{
|
|
|
78 |
int left{0};
|
|
|
79 |
int top{0};
|
|
|
80 |
int width{0};
|
|
|
81 |
int height{0};
|
|
|
82 |
}RECT_T;
|
|
|
83 |
|
3 |
andreas |
84 |
class TSubPage : public TValidateFile
|
|
|
85 |
{
|
|
|
86 |
public:
|
|
|
87 |
TSubPage(const std::string& name);
|
|
|
88 |
~TSubPage();
|
|
|
89 |
|
4 |
andreas |
90 |
void setPalette(TPalette *pal) { mPalette = pal; }
|
7 |
andreas |
91 |
void setFonts(TFont *ft) { mFonts = ft; }
|
4 |
andreas |
92 |
|
3 |
andreas |
93 |
int getNumber() { return mSubpage.pageID; }
|
|
|
94 |
std::string& getName() { return mSubpage.name; }
|
|
|
95 |
SUBPAGE_T& getSubPage() { return mSubpage; }
|
11 |
andreas |
96 |
std::string& getGroupName() { return mSubpage.group; }
|
5 |
andreas |
97 |
int getLeft() { return mSubpage.left; }
|
15 |
andreas |
98 |
void setLeft(int l) { mSubpage.left = l; }
|
5 |
andreas |
99 |
int getTop() { return mSubpage.top; }
|
15 |
andreas |
100 |
void setTop(int t) { mSubpage.top = t; }
|
5 |
andreas |
101 |
int getWidth() { return mSubpage.width; }
|
15 |
andreas |
102 |
void setWidth(int w) { mSubpage.width = w; }
|
5 |
andreas |
103 |
int getHeight() { return mSubpage.height; }
|
15 |
andreas |
104 |
void setHeight(int h) { mSubpage.height = h; }
|
|
|
105 |
RECT_T getRegion();
|
14 |
andreas |
106 |
int getZOrder() { if (mVisible) return mZOrder; else return -1; }
|
|
|
107 |
void setZOrder(int z) { mZOrder = z; }
|
11 |
andreas |
108 |
void setGroup(const std::string& group) { mSubpage.group = group; }
|
12 |
andreas |
109 |
void setModal(int m) { mSubpage.modal = m; }
|
5 |
andreas |
110 |
bool isModal() { return (mSubpage.modal != 0); }
|
15 |
andreas |
111 |
SHOWEFFECT getShowEffect() { return mSubpage.showEffect; }
|
|
|
112 |
void setShowEffect(SHOWEFFECT se) { mSubpage.showEffect = se; }
|
|
|
113 |
int getShowTime() { return mSubpage.showTime; }
|
|
|
114 |
void setShowTime(int t) { mSubpage.showTime = t; }
|
|
|
115 |
void setShowEndPosition(int x, int y) { mSubpage.showX = x; mSubpage.showY = y; }
|
|
|
116 |
SHOWEFFECT getHideEffect() { return mSubpage.hideEffect; }
|
|
|
117 |
void setHideEffect(SHOWEFFECT he) { mSubpage.hideEffect = he; }
|
|
|
118 |
void setHideEndPosition(int x, int y) { mSubpage.hideX = x; mSubpage.hideY = y; }
|
|
|
119 |
int getHideTime() { return mSubpage.hideTime; }
|
|
|
120 |
void setHideTime(int t) { mSubpage.hideTime = t; }
|
|
|
121 |
int getTimeout() { return mSubpage.timeout; }
|
|
|
122 |
void setTimeout(int t) { mSubpage.timeout = t; }
|
11 |
andreas |
123 |
bool isVisible() { return mVisible; }
|
14 |
andreas |
124 |
bool hasButton(int id);
|
154 |
andreas |
125 |
ulong getHandle() { return ((mSubpage.pageID << 16) & 0xffff0000); }
|
14 |
andreas |
126 |
Button::TButton *getButton(int id);
|
16 |
andreas |
127 |
std::vector<Button::TButton *> getButtons(int ap, int ad);
|
51 |
andreas |
128 |
std::vector<Button::TButton *> getAllButtons();
|
6 |
andreas |
129 |
void show();
|
11 |
andreas |
130 |
void drop();
|
|
|
131 |
void doClick(int x, int y, bool pressed);
|
54 |
andreas |
132 |
void startTimer();
|
|
|
133 |
void stopTimer() { mTimerRunning = false; }
|
38 |
andreas |
134 |
void registerCallback(std::function<void (ulong handle, unsigned char *image, size_t size, size_t rowBytes, int width, int height, ulong color)> setBackground) { _setBackground = setBackground; }
|
6 |
andreas |
135 |
void registerCallbackDB(std::function<void(ulong handle, ulong parent, unsigned char *buffer, int width, int height, int pixline, int left, int top)> displayButton) { _displayButton = displayButton; }
|
11 |
andreas |
136 |
void regCallDropSubPage(std::function<void (ulong handle)> callDropSubPage) { _callDropSubPage = callDropSubPage; }
|
21 |
andreas |
137 |
void regCallPlayVideo(std::function<void (ulong handle, ulong parent, int left, int top, int width, int height, const std::string& url, const std::string& user, const std::string& pw)> playVideo) { _playVideo = playVideo; };
|
3 |
andreas |
138 |
|
|
|
139 |
protected:
|
|
|
140 |
void initialize();
|
|
|
141 |
Button::BUTTONS_T *addButton(Button::TButton* button);
|
53 |
andreas |
142 |
void runTimer();
|
3 |
andreas |
143 |
bool sortButtons();
|
43 |
andreas |
144 |
#ifdef _SCALE_SKIA_
|
31 |
andreas |
145 |
void calcPosition(int im_width, int im_height, int *left, int *top, bool scale = false);
|
43 |
andreas |
146 |
#else
|
|
|
147 |
void calcPosition(int im_width, int im_height, int *left, int *top);
|
|
|
148 |
#endif
|
3 |
andreas |
149 |
private:
|
38 |
andreas |
150 |
std::function<void (ulong handle, unsigned char *image, size_t size, size_t rowBytes, int width, int height, ulong color)> _setBackground{nullptr};
|
6 |
andreas |
151 |
std::function<void (ulong handle, ulong parent, unsigned char *buffer, int width, int height, int pixline, int left, int top)> _displayButton{nullptr};
|
11 |
andreas |
152 |
std::function<void (ulong handle)> _callDropSubPage{nullptr};
|
21 |
andreas |
153 |
std::function<void (ulong handle, ulong parent, int left, int top, int width, int height, const std::string& url, const std::string& user, const std::string& pw)> _playVideo{nullptr};
|
6 |
andreas |
154 |
|
54 |
andreas |
155 |
bool drawText(SkBitmap *img);
|
|
|
156 |
int numberLines(const std::string& str);
|
|
|
157 |
int calcLineHeight(std::string text, SkFont& font);
|
|
|
158 |
Button::POSITION_t calcImagePosition(int width, int height, Button::CENTER_CODE cc, int line);
|
|
|
159 |
|
14 |
andreas |
160 |
bool mVisible{false}; // TRUE = subpage is visible
|
|
|
161 |
std::string mFName; // The file name of the page
|
|
|
162 |
std::string mFile; // The path and file name of the page
|
|
|
163 |
TPalette *mPalette{nullptr}; // The color palette
|
|
|
164 |
SUBPAGE_T mSubpage; // Parameters of the subpage
|
|
|
165 |
Button::BUTTONS_T *mButtons{nullptr}; // The elements of the subpage
|
|
|
166 |
TFont *mFonts{nullptr}; // The font management
|
|
|
167 |
int mZOrder{-1}; // The Z-Order of the subpage if it is visible
|
53 |
andreas |
168 |
std::atomic<bool>mTimerRunning{false}; // TRUE= timer is running
|
|
|
169 |
std::thread mThreadTimer; // The thread started if a timeout is defined.
|
3 |
andreas |
170 |
};
|
|
|
171 |
|
|
|
172 |
#endif
|