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