Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 andreas 1
/*
21 andreas 2
 * Copyright (C) 2020, 2021 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 "tpagelist.h"
26
#include "tsubpage.h"
27
#include "tconfig.h"
2 andreas 28
#include "terror.h"
4 andreas 29
#include "tpalette.h"
7 andreas 30
#include "tfont.h"
2 andreas 31
 
14 andreas 32
#define ZORDER_INVALID      -1
33
 
3 andreas 34
typedef struct PAGECHAIN_T
2 andreas 35
{
3 andreas 36
    TSubPage *subpage{nullptr}; // Ponter to subpage
14 andreas 37
    PAGECHAIN_T *next{nullptr}; // Pointer to next element
3 andreas 38
}PAGECHAIN_T;
39
 
40
class TPage : public TValidateFile
41
{
2 andreas 42
    public:
43
        TPage() {}
3 andreas 44
        TPage(const std::string& name);
45
        ~TPage();
2 andreas 46
 
3 andreas 47
        void initialize(const std::string& name);
4 andreas 48
        void setPalette(TPalette *pal) { mPalette = pal; }
7 andreas 49
        void setFonts(TFont *ft) { mFonts = ft; }
3 andreas 50
 
16 andreas 51
        int getWidth() { return width; }
52
        int getHeight() { return height; }
3 andreas 53
        void setName(const std::string& n) { name = n; }
54
        std::string& getName() { return name; }
55
        int getNumber() { return pageID; }
2 andreas 56
        bool isVisilble() { return mVisible; }
14 andreas 57
        bool hasButton(int id);
58
        Button::TButton *getButton(int id);
16 andreas 59
        std::vector<Button::TButton *> getButtons(int ap, int ad);
51 andreas 60
        std::vector<Button::TButton *> getAllButtons();
40 andreas 61
        Button::TButton *getFirstButton();
62
        Button::TButton *getNextButton();
2 andreas 63
 
3 andreas 64
        PAGECHAIN_T *addSubPage(TSubPage *pg);
4 andreas 65
        TSubPage *getSubPage(int pageID);
66
        TSubPage *getSubPage(const std::string& name);
67
        TSubPage *getFirstSubPage();
68
        TSubPage *getNextSubPage();
3 andreas 69
        bool removeSubPage(int ID);
70
        bool removeSubPage(const std::string& nm);
14 andreas 71
        int getActZOrder() { return mZOrder; }
72
        int getNextZOrder() { mZOrder++; return mZOrder; }
73
        int decZOrder() { if (mZOrder > 0) mZOrder--; return mZOrder; }
74
        void resetZOrder() { mZOrder = ZORDER_INVALID; }
3 andreas 75
 
76
        Button::BUTTONS_T *addButton(Button::TButton *button);
77
 
38 andreas 78
        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; }
7 andreas 79
        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; }
12 andreas 80
        void regCallDropPage(std::function<void (ulong handle)> callDropPage) { _callDropPage = callDropPage; }
81
        void regCallDropSubPage(std::function<void (ulong handle)> callDropSubPage) { _callDropSubPage = callDropSubPage; }
21 andreas 82
        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 83
 
84
        void show();
12 andreas 85
        void drop();
5 andreas 86
 
3 andreas 87
    protected:
88
        bool sortButtons();
43 andreas 89
#ifdef _SCALE_SKIA_
31 andreas 90
        void calcPosition(int im_width, int im_height, int *left, int *top, bool scale=false);
43 andreas 91
#else
92
        void calcPosition(int im_width, int im_height, int *left, int *top);
93
#endif
94
    private:
95
        void addProgress();
55 andreas 96
        bool drawText(SkBitmap *img);
97
        Button::POSITION_t calcImagePosition(int width, int height, Button::CENTER_CODE cc, int line);
98
        int calcLineHeight(std::string text, SkFont& font);
99
        int numberLines(const std::string& str);
3 andreas 100
 
38 andreas 101
        std::function<void (ulong handle, unsigned char *image, size_t size, size_t rowBytes, int width, int height, ulong color)> _setBackground{nullptr};
7 andreas 102
        std::function<void (ulong handle, ulong parent, unsigned char *buffer, int width, int height, int pixline, int left, int top)> _displayButton{nullptr};
12 andreas 103
        std::function<void (ulong handle)> _callDropPage{nullptr};
104
        std::function<void (ulong handle)> _callDropSubPage{nullptr};
21 andreas 105
        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 106
 
3 andreas 107
        std::string mPath;              // Path and name of the XML file
108
        std::string name;               // Name of the page
109
        int pageID{0};                  // Number of the page
110
        int width;                      // Width of the page
111
        int height;                     // height of the page
112
        Button::BUTTONS_T *mButtons{nullptr};    // Chain of buttons
40 andreas 113
        int mLastButton{0};             // Internal counter for iterating through button chain.
3 andreas 114
        std::vector<Button::SR_T> sr;   // Background details
115
        std::string mFile;              // The name of the file where the page is defined.
116
        bool mVisible{false};           // true = Page is visible
4 andreas 117
        TPalette *mPalette{nullptr};    // The color palette
2 andreas 118
 
3 andreas 119
        PAGECHAIN_T *mSubPages{nullptr};// Subpages related to this page
4 andreas 120
        int mLastSubPage{0};            // Stores the number of the last subpage
7 andreas 121
        TFont *mFonts{nullptr};         // Holds the class with the font list
14 andreas 122
        int mZOrder{ZORDER_INVALID};    // The Z-Order of the subpages
2 andreas 123
};
124
 
125
 
126
 
3 andreas 127
#endif // _TPAGE_H