Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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 __TPAGEMANAGER_H__
20
#define __TPAGEMANAGER_H__
21
 
5 andreas 22
#include <functional>
11 andreas 23
#include <thread>
5 andreas 24
 
3 andreas 25
#include "tpagelist.h"
26
#include "tpage.h"
27
#include "tsubpage.h"
28
#include "tsettings.h"
4 andreas 29
#include "tpalette.h"
7 andreas 30
#include "tbutton.h"
31
#include "tfont.h"
11 andreas 32
#include "tamxnet.h"
33
#include "tamxcommands.h"
3 andreas 34
 
14 andreas 35
#define REG_CMD(func, name)     registerCommand(bind(&TPageManager::func, this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3),name)
3 andreas 36
 
8 andreas 37
class TIcons;
14 andreas 38
class TPageManager;
21 andreas 39
 
40
extern bool prg_stopped;
8 andreas 41
extern TIcons *gIcons;
42
extern TPrjResources *gPrjResources;
14 andreas 43
extern TPageManager *gPageManager;
8 andreas 44
 
11 andreas 45
class TPageManager : public TAmxCommands
3 andreas 46
{
47
    public:
48
        TPageManager();
49
        ~TPageManager();
50
 
51
        bool readPages();                           // Read all pages and subpages
52
        bool readPage(const std::string& name);     // Read only one page
53
        bool readPage(int ID);
54
        bool readSubPage(const std::string& name);  // Read only one subpage
55
        bool readSubPage(int ID);
56
 
57
        TPageList *getPageList() { return mPageList; }
58
        TSettings *getSettings() { return mTSettings; }
59
 
4 andreas 60
        TPage *getActualPage();
15 andreas 61
        int getActualPageNumber() { return mActualPage; }
62
        int getPreviousPageNumber() { return mPreviousPage; }
4 andreas 63
        TSubPage *getFirstSubPage();
64
        TSubPage *getNextSubPage();
11 andreas 65
        TSubPage *getFirstSubPageGroup(const std::string& group);
66
        TSubPage *getNextSubPageGroup();
67
        TSubPage *getNextSubPageGroup(const std::string& group, TSubPage *pg);
68
        TSubPage *getTopPage();
4 andreas 69
 
70
        TPage *getPage(int pageID);
71
        TPage *getPage(const std::string& name);
15 andreas 72
        bool setPage(int PageID);
73
        bool setPage(const std::string& name);
4 andreas 74
        TSubPage *getSubPage(int pageID);
75
        TSubPage *getSubPage(const std::string& name);
14 andreas 76
        bool havePage(const std::string& name);
77
        bool haveSubPage(const std::string& name);
78
        bool haveSubPage(int id);
79
        bool haveSubPage(const std::string& page, const std::string& name);
80
        bool haveSubPage(const std::string& page, int id);
4 andreas 81
 
6 andreas 82
        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; }
5 andreas 83
        void registerCallbackSP(std::function<void (ulong handle, int width, int height)> setPage) { _setPage = setPage; }
84
        void registerCallbackSSP(std::function<void (ulong handle, int left, int top, int width, int height)> setSubPage) { _setSubPage = setSubPage; }
85
        void registerCallbackSB(std::function<void (ulong handle, unsigned char *image, size_t size, size_t rowBytes, ulong color)> setBackground) {_setBackground = setBackground; }
26 andreas 86
        void deployCallbacks();
87
 
7 andreas 88
        /**
89
         * Call the frontend to write some text. The text must be written with
90
         * a given font and the defined style. The parameters are:
91
         *
14 andreas 92
         * @param handle
93
         * Handle that identifies the object the text belongs to
94
         * @param text
95
         * The text to draw
96
         * @param font
97
         * The path and name of the font to use. This is always a true type font.
98
         * @param size
99
         * The size in pixels. This is for the height.
100
         * @param color
101
         * The color the text should have
102
         * @param effectColor
103
         * The color the text effect should have.
104
         * @param ori
105
         * The text orientation
106
         * @param effect
107
         * The type of text effect
108
         * @param ww
109
         * TRUE = word wrap
7 andreas 110
         */
111
        void registerCallbackFT(std::function<void (ulong handle, const std::string& text, const std::string& font, const std::string& family, int size, int x, int y, ulong color, ulong effectColor, FONT_STYLE style, Button::TEXT_ORIENTATION ori, Button::TEXT_EFFECT effect, bool ww)> setText)
112
        { _setText = setText; }
4 andreas 113
 
11 andreas 114
        void regCallDropPage(std::function<void (ulong handle)> callDropPage) { _callDropPage = callDropPage; }
115
        void regCallDropSubPage(std::function<void (ulong handle)> callDropSubPage) { _callDropSubPage = callDropSubPage; }
21 andreas 116
        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)> callPlayVideo) { _callPlayVideo = callPlayVideo; };
11 andreas 117
 
118
        /**
119
         * The following function must be called to start non graphics part
120
         * of the panel simulator. If everything worked well, it returns TRUE.
121
         * otherwise a FALSE is returned and the program should be terminated.
122
         */
5 andreas 123
        bool run();
11 andreas 124
        /**
125
         * Set an X value to add to the coordinated reported by the mouse catch
126
         * event. In case the X coordinate reported by the event is not the real
127
         * X coordinate, it's possible to set an X coordinate to translate the
128
         * internal used coordinates.
129
         *
14 andreas 130
         * @param x
131
         * The left most pixel which correspond to X = 0
11 andreas 132
         */
10 andreas 133
        void setFirstLeftPixel(int x) { mFirstLeftPixel = x; }
11 andreas 134
        /**
135
         * Set an Y value to add to the coordinated reported by the mouse catch
136
         * event. In case the Y coordinate reported by the event is not the real
137
         * Y coordinate, it's possible to set an Y coordinate to translate the
138
         * internal used coordinates.
139
         *
14 andreas 140
         * @param y
141
         * The left most pixel which correspond to Y = 0
11 andreas 142
         */
10 andreas 143
        void setFirstTopPixel(int y) { mFirstTopPixel = y; }
11 andreas 144
        /**
145
         * This function must be called from a GUI whenever the left mouse
146
         * button was pressed or released. Also if there was a touch event
14 andreas 147
         * this function must be called in the same way. It's up to any GUI
11 andreas 148
         * to handle the mouse and or touch events.
149
         *
14 andreas 150
         * @param x
151
         * the X coordinate of the mouse/touch event
152
         *
153
         * @param y
154
         * the y coordinate if the mouse/touch event
155
         *
156
         * @return
11 andreas 157
         * pressed TRUE = button was pressed; FALSE = button was released
158
         */
10 andreas 159
        void mouseEvent(int x, int y, bool pressed);
5 andreas 160
 
14 andreas 161
        void dropAllSubPages();
162
        void closeGroup(const std::string& group);
163
        void showSubPage(const std::string& name);
164
        void hideSubPage(const std::string& name);
24 andreas 165
        void setScaleFactor(double scale) { mScaleFactor = scale; }
166
        double getScaleFactor() { return mScaleFactor; }
31 andreas 167
        void setScaleFactorWidth(double scale) { mScaleFactorWidth = scale; }
168
        double getScaleFactorWidth() { return mScaleFactorWidth; }
169
        void setScaleFactorHeight(double scale) { mScaleFactorHeight = scale; }
170
        double getScaleFactorHeight() { return mScaleFactorHeight; }
14 andreas 171
 
26 andreas 172
        std::function<void (ulong handle, ulong parent, unsigned char *buffer, int width, int height, int pixline, int left, int top)> getCallbackDB() { return _displayButton; }
173
        std::function<void (ulong handle, unsigned char *image, size_t size, size_t rowBytes, ulong color)> getCallbackBG() { return _setBackground; }
174
        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)> getCallbackPV() { return _callPlayVideo; }
175
 
3 andreas 176
    protected:
177
        PAGELIST_T findPage(const std::string& name);
178
        PAGELIST_T findPage(int ID);
179
        SUBPAGELIST_T findSubPage(const std::string& name);
180
        SUBPAGELIST_T findSubPage(int ID);
181
 
182
        bool addPage(TPage *pg);
183
        bool addSubPage(TSubPage *pg);
11 andreas 184
        TSubPage *getCoordMatch(int x, int y);
185
        void initialize();
186
        void dropAllPages();
3 andreas 187
 
188
    private:
6 andreas 189
        std::function<void (ulong handle, ulong parent, unsigned char *buffer, int width, int height, int pixline, int left, int top)> _displayButton{nullptr};
5 andreas 190
        std::function<void (ulong handle, int width, int height)> _setPage{nullptr};
191
        std::function<void (ulong handle, int left, int top, int width, int height)> _setSubPage{nullptr};
192
        std::function<void (ulong handle, unsigned char *image, size_t size, size_t rowBytes, ulong color)> _setBackground{nullptr};
7 andreas 193
        std::function<void (ulong handle, const std::string& text, const std::string& font, const std::string& family, int size, int x, int y, ulong color, ulong effectColor, FONT_STYLE style, Button::TEXT_ORIENTATION ori, Button::TEXT_EFFECT effect, bool ww)> _setText{nullptr};
11 andreas 194
        std::function<void (ulong handle)> _callDropPage{nullptr};
195
        std::function<void (ulong handle)> _callDropSubPage{nullptr};
21 andreas 196
        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)> _callPlayVideo{nullptr};
5 andreas 197
 
11 andreas 198
        bool doOverlap(RECT_T r1, RECT_T r2);
199
        /**
200
         * Callback function for the AMX controller part. This function must
201
         * be registered to the class TAmxNet and is called from this module
202
         * every time an event occured from the controller.
203
         * This method handles the commands comming from the controller and
204
         * draws the necessary elements before they are sent to the GUI.
205
         *
14 andreas 206
         * @param cmd
207
         * An ANET_COMMAND structure containing the received command.
11 andreas 208
         */
209
        void doCommand(const amx::ANET_COMMAND& cmd);
14 andreas 210
        /**
211
         * The following function is used internaly. It searches in the map
212
         * table for the button corresponding to the port and channel number
213
         * and puts the result into a chain of buttons. This chain is returned.
214
         *
215
         * If there are some pages not yet in memory, they will be created just
216
         * to be able to set the button(s).
217
         */
218
        std::vector<Button::TButton *> collectButtons(std::vector<MAP_T>& map);
15 andreas 219
        TPage *loadPage(PAGELIST_T& pl);
18 andreas 220
        void setButtonCallbacks(Button::TButton *bt);
11 andreas 221
 
222
        // List of command functions
23 andreas 223
        void doFTR(int port, std::vector<int>&, std::vector<std::string>& pars);
224
 
14 andreas 225
        void doON(int port, std::vector<int>& channels, std::vector<std::string>& pars);
226
        void doOFF(int port, std::vector<int>& channels, std::vector<std::string>& pars);
15 andreas 227
        void doLEVEL(int port, std::vector<int>& channels, std::vector<std::string>& pars);
228
        void doBLINK(int port, std::vector<int>& channels, std::vector<std::string>& pars);
14 andreas 229
 
11 andreas 230
        void doAPG(int port, std::vector<int>& channels, std::vector<std::string>& pars);
231
        void doCPG(int port, std::vector<int>& channels, std::vector<std::string>& pars);
232
        void doDPG(int port, std::vector<int>& channels, std::vector<std::string>& pars);
15 andreas 233
        void doPHE(int port, std::vector<int>& channels, std::vector<std::string>& pars);
234
        void doPHP(int port, std::vector<int>& channels, std::vector<std::string>& pars);
235
        void doPHT(int port, std::vector<int>& channels, std::vector<std::string>& pars);
11 andreas 236
        void doPPA(int port, std::vector<int>& channels, std::vector<std::string>& pars);
12 andreas 237
        void doPPF(int port, std::vector<int>& channels, std::vector<std::string>& pars);
238
        void doPPG(int port, std::vector<int>& channels, std::vector<std::string>& pars);
239
        void doPPK(int port, std::vector<int>& channels, std::vector<std::string>& pars);
240
        void doPPM(int port, std::vector<int>& channels, std::vector<std::string>& pars);
241
        void doPPN(int port, std::vector<int>& channels, std::vector<std::string>& pars);
15 andreas 242
        void doPPT(int port, std::vector<int>& channels, std::vector<std::string>& pars);
12 andreas 243
        void doPPX(int port, std::vector<int>& channels, std::vector<std::string>& pars);
15 andreas 244
        void doPSE(int port, std::vector<int>& channels, std::vector<std::string>& pars);
245
        void doPSP(int port, std::vector<int>& channels, std::vector<std::string>& pars);
246
        void doPST(int port, std::vector<int>& channels, std::vector<std::string>& pars);
12 andreas 247
        void doPAGE(int port, std::vector<int>& channels, std::vector<std::string>& pars);
11 andreas 248
 
15 andreas 249
        void doAPF(int port, std::vector<int>& channels, std::vector<std::string>& pars);
250
        void doBMP(int port, std::vector<int>& channels, std::vector<std::string>& pars);
16 andreas 251
        void doBOP(int port, std::vector<int>& channels, std::vector<std::string>& pars);
252
        void doBSP(int port, std::vector<int>& channels, std::vector<std::string>& pars);
253
        void doBWW(int port, std::vector<int>& channels, std::vector<std::string>& pars);
254
        void doCPF(int port, std::vector<int>& channels, std::vector<std::string>& pars);
255
        void doDPF(int port, std::vector<int>& channels, std::vector<std::string>& pars);
256
        void doENA(int port, std::vector<int>& channels, std::vector<std::string>& pars);
257
        void doFON(int port, std::vector<int>& channels, std::vector<std::string>& pars);
14 andreas 258
        void doICO(int port, std::vector<int>& channels, std::vector<std::string>& pars);
16 andreas 259
        void doSHO(int port, std::vector<int>& channels, std::vector<std::string>& pars);
14 andreas 260
        void doTXT(int port, std::vector<int>& channels, std::vector<std::string>& pars);
4 andreas 261
 
21 andreas 262
        void doBBR(int port, std::vector<int>& channels, std::vector<std::string>& pars);
263
        void doRMF(int port, std::vector<int>& channels, std::vector<std::string>& pars);
264
 
14 andreas 265
        int mActualPage{0};                             // The number of the actual visible page
15 andreas 266
        int mPreviousPage{0};                           // The number of the previous page
14 andreas 267
        int mFirstLeftPixel{0};                         // Pixels to add to left (x) mouse coordinate
268
        int mFirstTopPixel{0};                          // Pixels to add to top (y) mouse position
269
        std::string mActualGroupName;                   // The name of the actual group
270
        TSubPage *mActualGroupPage{nullptr};            // Pointer to subpage of a group whi is visible
271
 
272
        amx::TAmxNet *mAmxNet{nullptr};                 // Pointer to class TAmxNet; Handles the communication with the controller
273
        TPageList *mPageList{nullptr};                  // List of available pages and subpages
274
        PCHAIN_T *mPchain{nullptr};                     // Pointer to chain of pages in memory
275
        SPCHAIN_T *mSPchain{nullptr};                   // Pointer to chain of subpages in memory for the actual page
276
        TSettings *mTSettings{nullptr};                 // Pointer to basic settings for the panel
277
        TPalette *mPalette{nullptr};                    // Pointer to the color handler
278
        TFont *mFonts{nullptr};                         // Pointer to the font handler
279
        std::thread mThreadAmxNet;                      // The thread handle to the controler handler
280
        std::vector<amx::ANET_COMMAND> mCommands;       // Command queue of commands received from controller
281
        bool mBusy{false};                              // Internal used to block the command handler
282
        std::string mCmdBuffer;                         // Internal used buffer for commands who need more than one network package
24 andreas 283
        double mScaleFactor{1.0};                       // The scale factor to zoom or shrink all components
31 andreas 284
        double mScaleFactorWidth{1.0};                  // The individual scale factor for the width
285
        double mScaleFactorHeight{1.0};                 // The individual scale factor for the height
3 andreas 286
};
287
 
288
#endif