Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
202 andreas 1
/*
258 andreas 2
 * Copyright (C) 2022, 2023 by Andreas Theofilu <andreas@theosys.at>
202 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 __TPAGEINTERFACE_H__
20
#define __TPAGEINTERFACE_H__
21
 
211 andreas 22
#include <functional>
23
 
202 andreas 24
#include "tfont.h"
25
#include "tbutton.h"
266 andreas 26
#include "tsystembutton.h"
202 andreas 27
 
206 andreas 28
#define REGULAR_PAGE_START              0
29
#define REGULAR_SUBPAGE_START           500
30
 
31
#define SYSTEM_PAGE_START               5000
32
#define SYSTEM_SUBPAGE_START            5500
33
 
208 andreas 34
#define SYSTEM_PAGE_LOGGING             5001
35
#define SYSTEM_PAGE_LOG_TXLOGFILE       22
36
#define SYSTEM_PAGE_LOG_BTRESET         23
37
#define SYSTEM_PAGE_LOG_BTFILE          24
38
 
206 andreas 39
#define SYSTEM_PAGE_CONTROLLER          5002
40
#define SYSTEM_PAGE_CTRL_SURFACE        23
41
#define SYSTEM_PAGE_CTRL_DOWNLOAD       27
42
#define SYSTEM_SUBPAGE_SURFACE          5502
43
 
44
#define SYSTEM_PAGE_SOUND               5005
45
#define SYSTEM_PAGE_SOUND_TXSYSSOUND    10
46
#define SYSTEM_PAGE_SOUND_TXSINGLEBEEP  12
47
#define SYSTEM_PAGE_SOUND_TXDOUBLEBEEP  14
48
#define SYSTEM_SUBPAGE_SYSTEMSOUND      5503
49
#define SYSTEM_SUBPAGE_SINGLEBEEP       5504
50
#define SYSTEM_SUBPAGE_DOUBLEBEEP       5505
51
 
52
#define SYSTEM_LIST_SURFACE             2023
53
#define SYSTEM_LIST_SYSTEMSOUND         2024
54
#define SYSTEM_LIST_SINGLEBEEP          2025
55
#define SYSTEM_LIST_DOUBLEBEEP          2026
56
 
57
#define SYSTEM_ITEM_SYSGAIN             6
58
#define SYSTEM_ITEM_CONNSTATE           8
59
#define SYSTEM_ITEM_SYSVOLUME           9
60
#define SYSTEM_ITEM_SOUNDSWITCH         17
61
#define SYSTEM_ITEM_FTPSURFACE          25
62
#define SYSTEM_ITEM_SETUPPAGE           73
63
#define SYSTEM_ITEM_SHUTDOWN            80
64
#define SYSTEM_ITEM_CONNSTRENGTH        81
209 andreas 65
#define SYSTEM_ITEM_NETLINX_IP          122
66
#define SYSTEM_ITEM_NETLINX_CHANNEL     123
67
#define SYSTEM_ITEM_NETLINX_PORT        124
68
 
206 andreas 69
#define SYSTEM_ITEM_STANDARDTIME        141
70
#define SYSTEM_ITEM_TIMEAMPM            142
71
#define SYSTEM_ITEM_TIME24              143
72
#define SYSTEM_ITEM_NETLINXPORT         144
73
#define SYSTEM_ITEM_DATEWEEKDAY         151
74
#define SYSTEM_ITEM_DATEMMDD            152
75
#define SYSTEM_ITEM_DATEDDMM            153
76
#define SYSTEM_ITEM_DATEMMDDYYYY        154
77
#define SYSTEM_ITEM_DATEDDMMYYYY        155
78
#define SYSTEM_ITEM_DATEMONDDYYYY       156
79
#define SYSTEM_ITEM_DATEDDMONYYYY       157
80
#define SYSTEM_ITEM_DATEYYYYMMDD        158
81
#define SYSTEM_ITEM_SOUNDPLAYTESTSOUND  159
82
#define SYSTEM_ITEM_VOLUMEUP            171
83
#define SYSTEM_ITEM_VOLUMEDOWN          172
84
#define SYSTEM_ITEM_VOLUMEMUTE          173
209 andreas 85
 
86
#define SYSTEM_ITEM_NETLINX_PTYPE       199
87
 
206 andreas 88
#define SYSTEM_ITEM_BATTERYCHARGING     234
89
#define SYSTEM_ITEM_BATTERYLEVEL        242
209 andreas 90
 
91
#define SYSTEM_ITEM_SINGLEBEEP          404
92
#define SYSTEM_ITEM_DOUBLEBEEP          405
93
 
206 andreas 94
#define SYSTEM_ITEM_BTSAVESETTINGS      412
95
#define SYSTEM_ITEM_BTCANCELSETTINGS    413
96
#define SYSTEM_ITEM_SIPENABLE           416
209 andreas 97
#define SYSTEM_ITEM_SIPPROXY            418
98
#define SYSTEM_ITEM_SIPPORT             419
99
#define SYSTEM_ITEM_SIPSTUN             420
100
#define SYSTEM_ITEM_SIPDOMAIN           421
101
#define SYSTEM_ITEM_SIPUSER             422
102
#define SYSTEM_ITEM_SIPPASSWORD         423
206 andreas 103
 
209 andreas 104
#define SYSTEM_ITEM_SYSTEMSOUND         1143
105
 
206 andreas 106
#define SYSTEM_ITEM_DEBUGINFO           2000
107
#define SYSTEM_ITEM_DEBUGWARNING        2001
108
#define SYSTEM_ITEM_DEBUGERROR          2002
109
#define SYSTEM_ITEM_DEBUGTRACE          2003
110
#define SYSTEM_ITEM_DEBUGDEBUG          2004
111
#define SYSTEM_ITEM_DEBUGPROTOCOL       2005
112
#define SYSTEM_ITEM_DEBUGALL            2006
113
#define SYSTEM_ITEM_DEBUGPROFILE        2007
114
#define SYSTEM_ITEM_DEBUGLONG           2008
208 andreas 115
#define SYSTEM_ITEM_LOGLOGFILE          2009
116
#define SYSTEM_ITEM_LOGRESET            2010
117
#define SYSTEM_ITEM_LOGFILEOPEN         2011
118
 
209 andreas 119
#define SYSTEM_ITEM_FTPUSER             2020
120
#define SYSTEM_ITEM_FTPPASSWORD         2021
206 andreas 121
#define SYSTEM_ITEM_FTPDOWNLOAD         2030
122
#define SYSTEM_ITEM_FTPPASSIVE          2031
123
 
124
#define SYSTEM_ITEM_SOUNDPLAYSYSSOUND   2050
125
#define SYSTEM_ITEM_SOUNDPLAYBEEP       2051
126
#define SYSTEM_ITEM_SOUNDPLAYDBEEP      2052
127
#define SYSTEM_ITEM_SIPIPV4             2060
128
#define SYSTEM_ITEM_SIPIPV6             2061
129
#define SYSTEM_ITEM_SIPIPHONE           2062
130
#define SYSTEM_ITEM_VIEWSCALEFIT        2070
131
#define SYSTEM_ITEM_VIEWBANNER          2071
132
#define SYSTEM_ITEM_VIEWNOTOOLBAR       2072
133
#define SYSTEM_ITEM_VIEWTOOLBAR         2073
134
#define SYSTEM_ITEM_VIEWROTATE          2074
135
 
279 andreas 136
class TSubPage;
137
 
202 andreas 138
enum SHOWEFFECT
139
{
140
    SE_NONE,
141
    SE_FADE,
142
    SE_SLIDE_LEFT,
143
    SE_SLIDE_RIGHT,
144
    SE_SLIDE_TOP,
145
    SE_SLIDE_BOTTOM,
146
    SE_SLIDE_LEFT_FADE,
147
    SE_SLIDE_RIGHT_FADE,
148
    SE_SLIDE_TOP_FADE,
149
    SE_SLIDE_BOTTOM_FADE
150
};
151
 
152
typedef SHOWEFFECT SHOWEFFECT_t;
153
 
154
typedef struct ANIMATION_t
155
{
156
    SHOWEFFECT_t showEffect{SE_NONE};
157
    int showTime{0};
158
    SHOWEFFECT_t hideEffect{SE_NONE};
159
    int hideTime{0};
160
}ANIMATION_t;
161
 
162
typedef struct PAGE_T
163
{
164
    std::string popupType;                  // The type of the popup (popup only)
165
    int pageID{0};                          // Unique ID of popup/page
166
    std::string name;                       // The name of the popup/page
167
    int left{0};                            // Left position of popup (always 0 for pages)
168
    int top{0};                             // Top position of popup (always 0 for pages)
169
    int width{0};                           // Width of popup
170
    int height{0};                          // Height of popup
171
    int modal{0};                           // 0 = Popup/Page = non modal
172
    std::string group;                      // Name of the group the popup belongs (popup only)
173
    int timeout{0};                         // Time after the popup hides in 1/10 seconds (popup only)
174
    SHOWEFFECT showEffect{SE_NONE};         // The effect when the popup is shown (popup only)
175
    int showTime{0};                        // The time reserved for the show effect (popup only)
176
    int showX{0};                           // End of show effect position (by default "left+width"); (popup only)
177
    int showY{0};                           // End of show effect position (by default "top+height"); (popup only)
178
    SHOWEFFECT hideEffect{SE_NONE};         // The effect when the popup hides (popup only)
179
    int hideTime{0};                        // The time reserved for the hide effect (popup only)
180
    int hideX{0};                           // End of hide effect position (by default "left"); (popup only)
181
    int hideY{0};                           // End of hide effect position (by default "top"); (popup only)
182
    std::vector<Button::SR_T> sr;           // Page/Popup description
183
}PAGE_T;
184
 
185
/**
186
 * This class in an interface to manage pages and subpages. Both classes of
187
 * TPage and TSubpage have a lot of identical functions. This functions are
188
 * in this class.
189
 */
266 andreas 190
class TPageInterface : public TSystemButton
202 andreas 191
{
192
    public:
206 andreas 193
        virtual ~TPageInterface() {}
194
 
202 andreas 195
        bool drawText(PAGE_T& pinfo, SkBitmap *img);
258 andreas 196
        bool drawFrame(PAGE_T& pinfo, SkBitmap* bm);
262 andreas 197
#ifdef _OPAQUE_SKIA_
258 andreas 198
        bool setOpacity(SkBitmap *bm, int oo);
262 andreas 199
#endif
202 andreas 200
        virtual int getNumber() = 0;
201
        virtual std::string& getName() = 0;
202
        virtual void show() = 0;
203
        virtual void drop() = 0;
300 andreas 204
        virtual SkBitmap& getBgImage() = 0;
205
        virtual std::string getFillColor() = 0;
202 andreas 206
 
207
        void setButtons(Button::BUTTONS_T *bt) { mButtons = bt; }
208
        Button::BUTTONS_T *getButtons() { return mButtons; }
203 andreas 209
        Button::BUTTONS_T *addButton(Button::TButton* button);
210
        Button::TButton *getButton(int id);
211
        std::vector<Button::TButton *> getButtons(int ap, int ad);
212
        std::vector<Button::TButton *> getAllButtons();
213
        bool hasButton(int id);
214
        bool sortButtons();
215
        Button::TButton *getFirstButton();
216
        Button::TButton *getNextButton();
217
        Button::TButton *getLastButton();
218
        Button::TButton *getPreviousButton();
202 andreas 219
 
220
        void setSR(std::vector<Button::SR_T>& s) { sr = s; }
221
        std::vector<Button::SR_T>& getSR() { return sr; }
222
 
289 andreas 223
        void setFonts(TFont *f);
202 andreas 224
        TFont *getFonts() { return mFonts; }
225
 
205 andreas 226
        void setSelectedRow(ulong handle, int row);
227
        int getSelectedRow(ulong handle);
228
        std::string getSelectedItem(ulong handle);
229
 
204 andreas 230
        template<typename T>
231
        inline void registerListCallback(Button::TButton *button, T *pg)
232
        {
233
            if (!button || !pg)
234
                return;
202 andreas 235
 
211 andreas 236
            button->regCallListContent(std::bind(&TPageInterface::getListContent, pg, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6));
237
            button->regCallListRow(std::bind(&TPageInterface::getListRow, pg, std::placeholders::_1, std::placeholders::_2));
238
            button->regCallGlobalSettings(std::bind(&TPageInterface::setGlobalSettings, pg, std::placeholders::_1));
204 andreas 239
        }
240
 
206 andreas 241
        static bool isSystemPage(int ID) { return ID >= SYSTEM_PAGE_START && ID < SYSTEM_SUBPAGE_START; }
242
        static bool isSystemSubPage(int ID) { return ID >= SYSTEM_SUBPAGE_START; }
243
        static bool isRegularPage(int ID) { return ID > REGULAR_PAGE_START && ID < REGULAR_SUBPAGE_START; }
244
        static bool isRegularSubPage(int ID) { return ID >= REGULAR_SUBPAGE_START && ID < SYSTEM_PAGE_START; }
245
 
202 andreas 246
    protected:
247
        typedef struct LIST_t
248
        {
205 andreas 249
            ulong handle{0};
250
            int ap{0};
251
            int ta{0};
252
            int ti{0};
253
            int rows{0};
254
            int columns{0};
255
            int selected{-1};
202 andreas 256
            std::vector<std::string> list;
257
        }LIST_t;
258
 
204 andreas 259
        std::vector<std::string> getListContent(ulong handle, int ap, int ta, int ti, int rows, int columns);
260
        std::string getListRow(int ti, int row);
261
        void setGlobalSettings(Button::TButton *button);
262
 
202 andreas 263
    private:
203 andreas 264
        Button::POSITION_t calcImagePosition(PAGE_T *page, int width, int height, Button::CENTER_CODE cc, int line);
204 andreas 265
        int calcLineHeight(const std::string& text, SkFont& font);
266
        int numberLines(const std::string& str);
205 andreas 267
        int getSystemSelection(int ta, std::vector<std::string>& list);
258 andreas 268
        SkBitmap retrieveBorderImage(const std::string& pa, const std::string& pb, SkColor color, SkColor bgColor);
269
        bool retrieveImage(const std::string& path, SkBitmap* image);
270
        SkBitmap colorImage(SkBitmap& base, SkBitmap& alpha, SkColor col, SkColor bg, bool useBG);
271
        bool stretchImageWidth(SkBitmap *bm, int width);
272
        bool stretchImageHeight(SkBitmap *bm, int height);
203 andreas 273
 
279 andreas 274
        Button::BUTTONS_T *mButtons{nullptr};   // Chain of buttons
275
        int mLastButton{0};                     // Internal counter for iterating through button chain.
276
        std::vector<Button::SR_T> sr;           // Button instances
277
        TFont *mFonts{nullptr};                 // Holds the class with the font list
278
        std::vector<LIST_t> mLists;             // Lists of page
202 andreas 279
};
280
 
281
#endif