summaryrefslogtreecommitdiff
path: root/glcdskin/function.h
blob: 16bcfb7f4efc390a13532532e3820c5a55439ea5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * GraphLCD skin library
 *
 * function.h  -  skin functions class
 *
 * This file is released under the GNU General Public License. Refer
 * to the COPYING file distributed with this package.
 *
 * based on text2skin
 *
 */

#ifndef _GLCDSKIN_FUNCTION_H_
#define _GLCDSKIN_FUNCTION_H_

#include <stdint.h>

#include <string>

#include "type.h"
#include "string.h"

namespace GLCD
{

#define STRING    0x01000000
#define NUMBER    0x02000000
#define INTERNAL  0x04000000
#define VARIABLE  0x08000000

#define MAXPARAMETERS 512

class cSkinObject;
class cSkin;

class cSkinFunction
{
public:
    enum eType
    {
        undefined_function,

        string = STRING,
        number = NUMBER,
        variable = VARIABLE,

        fun_not = INTERNAL,
        fun_and,
        fun_or,
        fun_equal,
        fun_eq,
        fun_gt,
        fun_lt,
        fun_ge,
        fun_le,
        fun_ne,
        fun_file,
        fun_trans,

        funAdd,
        funSub,
        funMul,
        funDiv,

        funFontTotalWidth,
        funFontTotalHeight,
        funFontTotalAscent,
        funFontSpaceBetween,
        funFontLineHeight,
        funFontTextWidth,
        funFontTextHeight,

        funImageWidth,
        funImageHeight,

        funQueryFeature
    };

private:
    cSkinObject   * mObject;
    cSkin         * mSkin;
    eType           mType;
    cSkinString     mString;
    int             mNumber;
    std::string     mVariableId;
    cSkinFunction * mParams[MAXPARAMETERS];
    uint32_t        mNumParams;

protected:
    cType FunFile  (const cType &Param) const;
    cType FunPlugin(const cType &Param) const;
    cType FunFont  (eType Function, const cType &Param1, const cType &Param2) const;
    cType FunImage (eType Function, const cType &Param) const;
public:
    cSkinFunction(cSkinObject *Parent);
    cSkinFunction(const cSkinString &String);
    cSkinFunction(const cSkinFunction &Src);
    ~cSkinFunction();

    bool Parse(const std::string &Text, bool reparse = false);
    cType Evaluate(void) const;

    void SetListIndex(int MaxItems, int Index);
};

inline void cSkinFunction::SetListIndex(int MaxItems, int Index)
{
    mString.SetListIndex(MaxItems, Index);
    for (uint32_t i = 0; i < mNumParams; i++)
        mParams[i]->SetListIndex(MaxItems, Index);
}

} // end of namespace

#endif