Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
446 andreas 1
/*
2
 * Copyright (C) 2020 to 2023 by Andreas Theofilu <andreas@theosys.at>
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 __TPAGE_H__
20
#define __TPAGE_H__
21
 
22
#include <string>
23
#include <vector>
24
#include "tvalidatefile.h"
25
#include "tsubpage.h"
26
#include "tpalette.h"
27
#include "tpageinterface.h"
28
 
29
#define ZORDER_INVALID      -1
30
#define MAX_PAGE_ID         500
31
 
32
class TBitmap;
33
 
34
typedef struct PAGECHAIN_T
35
{
36
    int pgNumber{0};
37
    int zOrder{-1};
38
    TSubPage *subpage{nullptr}; // Ponter to subpage
39
//    PAGECHAIN_T *prev{nullptr}; // Pointer to previous element
40
//    PAGECHAIN_T *next{nullptr}; // Pointer to next element
41
}PAGECHAIN_T;
42
 
43
class TPage : public TValidateFile, public TPageInterface
44
{
45
    public:
46
        TPage() {}
47
        TPage(const std::string& name);
48
        ~TPage();
49
 
50
        void initialize(const std::string& name);
51
        void setPalette(TPalette *pal) { mPalette = pal; }
52
 
53
        int getWidth() { return mPage.width; }
54
        int getHeight() { return mPage.height; }
55
        void setName(const std::string& n) { mPage.name = n; }
56
        std::string& getName() { return mPage.name; }
57
        int getNumber() { return mPage.pageID; }
58
        bool isVisilble() { return mVisible; }
59
        ulong getHandle() { return (mPage.pageID << 16) & 0xffff0000; }
60
        std::string getFillColor() { return mPage.sr[0].cf; }
61
        SkBitmap& getBgImage();
62
 
63
        bool addSubPage(TSubPage *pg);
64
        TSubPage *getSubPage(int pageID);
65
        TSubPage *getSubPage(const std::string& name);
66
        TSubPage *getFirstSubPage();
67
        TSubPage *getNextSubPage();
68
        TSubPage *getPrevSubPage();
69
        TSubPage *getLastSubPage();
70
        bool removeSubPage(int ID);
71
        bool removeSubPage(const std::string& nm);
72
        int getActZOrder() { return mZOrder; }
73
        int getNextZOrder();
74
        int decZOrder();
75
        void resetZOrder() { mZOrder = ZORDER_INVALID; }
76
#ifdef _OPAQUE_SKIA_
77
        void registerCallback(std::function<void (ulong handle, TBitmap image, int width, int height, ulong color)> setBackground) { _setBackground = setBackground; }
78
#else
79
        void registerCallback(std::function<void (ulong handle, TBitmap image, int width, int height, ulong color, int opacity)> setBackground) { _setBackground = setBackground; }
80
#endif
81
        void registerCallbackDB(std::function<void(ulong handle, ulong parent, TBitmap buffer, int width, int height, int left, int top, bool passthrough, int marqtype, int marq)> displayButton) { _displayButton = displayButton; }
82
        void regCallDropPage(std::function<void (ulong handle)> callDropPage) { _callDropPage = callDropPage; }
83
        void regCallDropSubPage(std::function<void (ulong handle, ulong parent)> callDropSubPage) { _callDropSubPage = callDropSubPage; }
84
        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; };
85
 
86
        void show();
87
        void drop();
88
        void sortSubpages();
89
        std::map<int, TSubPage *>& getSortedSubpages(bool force=false);
90
 
91
    protected:
92
//        bool sortButtons();
93
#ifdef _SCALE_SKIA_
94
        void calcPosition(int im_width, int im_height, int *left, int *top, bool scale=false);
95
#else
96
        void calcPosition(int im_width, int im_height, int *left, int *top);
97
#endif
98
    private:
99
        void addProgress();
100
#ifdef _OPAQUE_SKIA_
101
        std::function<void (ulong handle, TBitmap image, int width, int height, ulong color)> _setBackground{nullptr};
102
#else
103
        std::function<void (ulong handle, TBitmap image, int width, int height, ulong color, int opacity)> _setBackground{nullptr};
104
#endif
105
        std::function<void (ulong handle, ulong parent, TBitmap buffer, int width, int height, int left, int top, bool passthrough, int marqtype, int marq)> _displayButton{nullptr};
106
        std::function<void (ulong handle)> _callDropPage{nullptr};
107
        std::function<void (ulong handle, ulong parent)> _callDropSubPage{nullptr};
108
        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};
109
 
110
        std::string mPath;              // Path and name of the XML file
111
        PAGE_T mPage;                   // Definitions of page
112
        std::vector<Button::SR_T> sr;   // Background details
113
        std::string mFile;              // The name of the file where the page is defined.
114
        bool mVisible{false};           // true = Page is visible
115
        TPalette *mPalette{nullptr};    // The color palette
116
 
117
        std::map<int, TSubPage *> mSubPages;        // Subpages related to this page
118
        std::map<int, TSubPage *> mSubPagesSorted;  // Sorted subpages with a Z-order >= 0
119
        int mLastSubPage{0};            // Stores the number of the last subpage
120
        int mZOrder{ZORDER_INVALID};    // The Z-Order of the subpages
121
        std::vector<LIST_t> mLists;     // Lists of page
122
        SkBitmap mBgImage;              // The background image, if one
123
};
124
 
125
 
126
 
127
#endif // _TPAGE_H