Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

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