Subversion Repositories tpanel

Rev

Rev 28 | Blame | Last modification | View Log | RSS feed

/*
 * Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 */

#ifndef __TPAGE_H__
#define __TPAGE_H__

#include <string>
#include <vector>
#include "tvalidatefile.h"
#include "tpagelist.h"
#include "tsubpage.h"
#include "tconfig.h"
#include "terror.h"
#include "tpalette.h"
#include "tfont.h"

#define ZORDER_INVALID      -1

typedef struct PAGECHAIN_T
{
    TSubPage *subpage{nullptr}; // Ponter to subpage
    PAGECHAIN_T *next{nullptr}; // Pointer to next element
}PAGECHAIN_T;

class TPage : public TValidateFile
{
    public:
        TPage() {}
        TPage(const std::string& name);
        ~TPage();

        void initialize(const std::string& name);
        void setPalette(TPalette *pal) { mPalette = pal; }
        void setFonts(TFont *ft) { mFonts = ft; }

        int getWidth() { return width; }
        int getHeight() { return height; }
        void setName(const std::string& n) { name = n; }
        std::string& getName() { return name; }
        int getNumber() { return pageID; }
        bool isVisilble() { return mVisible; }
        bool hasButton(int id);
        Button::TButton *getButton(int id);
        std::vector<Button::TButton *> getButtons(int ap, int ad);

        PAGECHAIN_T *addSubPage(TSubPage *pg);
        TSubPage *getSubPage(int pageID);
        TSubPage *getSubPage(const std::string& name);
        TSubPage *getFirstSubPage();
        TSubPage *getNextSubPage();
        bool removeSubPage(int ID);
        bool removeSubPage(const std::string& nm);
        int getActZOrder() { return mZOrder; }
        int getNextZOrder() { mZOrder++; return mZOrder; }
        int decZOrder() { if (mZOrder > 0) mZOrder--; return mZOrder; }
        void resetZOrder() { mZOrder = ZORDER_INVALID; }

        Button::BUTTONS_T *addButton(Button::TButton *button);

        void registerCallback(std::function<void (ulong handle, unsigned char *image, size_t size, size_t rowBytes, ulong color)> setBackground) { _setBackground = setBackground; }
        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)
        { _setText = setText; }
        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; }
        void regCallDropPage(std::function<void (ulong handle)> callDropPage) { _callDropPage = callDropPage; }
        void regCallDropSubPage(std::function<void (ulong handle)> callDropSubPage) { _callDropSubPage = callDropSubPage; }
        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; };

        void show();
        void drop();

    protected:
        bool sortButtons();
        void calcPosition(int im_width, int im_height, int *left, int *top, bool scale=false);

    private:
        std::function<void (ulong handle, unsigned char *image, size_t size, size_t rowBytes, ulong color)> _setBackground{nullptr};
        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};
        std::function<void (ulong handle, ulong parent, unsigned char *buffer, int width, int height, int pixline, int left, int top)> _displayButton{nullptr};
        std::function<void (ulong handle)> _callDropPage{nullptr};
        std::function<void (ulong handle)> _callDropSubPage{nullptr};
        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};

        std::string mPath;              // Path and name of the XML file
        std::string name;               // Name of the page
        int pageID{0};                  // Number of the page
        int width;                      // Width of the page
        int height;                     // height of the page
        Button::BUTTONS_T *mButtons{nullptr};    // Chain of buttons
        std::vector<Button::SR_T> sr;   // Background details
        std::string mFile;              // The name of the file where the page is defined.
        bool mVisible{false};           // true = Page is visible
        TPalette *mPalette{nullptr};    // The color palette

        PAGECHAIN_T *mSubPages{nullptr};// Subpages related to this page
        int mLastSubPage{0};            // Stores the number of the last subpage
        TFont *mFonts{nullptr};         // Holds the class with the font list
        int mZOrder{ZORDER_INVALID};    // The Z-Order of the subpages
};



#endif // _TPAGE_H