summaryrefslogtreecommitdiff
path: root/libtemplate/templatefunction.h
blob: e63850ebe02079aac01699d09920b799049788f4 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#ifndef __TEMPLATEFUNCTION_H
#define __TEMPLATEFUNCTION_H

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <sstream>

#include "globals.h"
#include "parameter.h"

using namespace std;

// --- cTemplateFunction -------------------------------------------------------------

enum eFuncType {
    ftOsd,
    ftView,
    ftViewElement,
    ftViewList,
    ftPixmap,
    ftPixmapScroll,
    ftLoop,
    ftFill,
    ftDrawText,
    ftDrawTextBox,
    ftDrawTextVertical,
    ftDrawImage,
    ftDrawRectangle,
    ftDrawEllipse,
    ftDrawSlope,
    ftNone
};

enum eParamType {
    ptCond,
    ptName,
    ptX,
    ptY,
    ptWidth,
    ptHeight,
    ptMenuItemWidth,
    ptFadeTime,
    ptDelay,
    ptImageType,
    ptPath,
    ptColor,
    ptFont,
    ptFontSize,
    ptText,
    ptLayer,
    ptTransparency,
    ptQuadrant,
    ptType,
    ptAlign,
    ptValign,
    ptScrollMode,
    ptScrollSpeed,
    ptOrientation,
    ptNumElements,
    ptScrollElement,
    ptScrollHeight,
    ptFloat,
    ptFloatWidth,
    ptFloatHeight,
    ptMaxLines,
    ptColumnWidth,
    ptRowHeight,
    ptOverflow,
    ptScaleTvX,
    ptScaleTvY,
    ptScaleTvWidth,
    ptScaleTvHeight,
    ptCache,
    ptDeterminateFont,
    ptNone
};

enum eImageType {
    itChannelLogo,
    itSepLogo,
    itSkinPart,
    itMenuIcon,
    itIcon,
    itImage
};

enum eFloatType {
    flNone,
    flTopLeft,
    flTopRight
};

enum eOverflowType {
    otNone,
    otWrap,
    otCut
};

class cTemplateFunction {
protected:
    eFuncType type;
    bool debug;
    int containerX;                                                       //X of parent container
    int containerY;                                                       //Y of parent container
    int containerWidth;                                                   //width of parent container
    int containerHeight;                                                  //height of parent container
    int columnWidth;                                                      //if func is executed in a loop, width of loop column
    int rowHeight;                                                        //if func is executed in a loop, height of loop row
    cGlobals *globals;                                                    //globals
    map< eParamType, string > nativeParameters;                           //native parameters directly from xml 
    map< eParamType, int > numericParameters;                             //sucessfully parsed numeric parameters
    map< eParamType, string > numericDynamicParameters;                   //numeric parameters with dynamic tokens
    bool parsedCompletely;
    bool updated;
    map< eParamType, tColor > colorParameters;
    cConditionalParameter *condParam;
    //drawimage parameters
    string imgPath;
    //drawtext parameters
    string fontName;
    vector<cTextToken> textTokens;
    string parsedText;
    int parsedTextWidth;
    string cuttedText;
    bool alreadyCutted;
    //drawtextbox parameters
    int textboxHeight;
    //dynamic tokens
    map < string, string > *stringTokens;
    map < string, int > *intTokens;
    //private functions
    bool SetCondition(string cond);
    bool SetNumericParameter(eParamType type, string value);
    bool SetAlign(eParamType type, string value);
    bool SetFont(eParamType type, string value);
    bool SetImageType(eParamType type, string value);
    bool SetColor(eParamType type, string value);
    bool SetTextTokens(string value);
    void ParseTextToken(string &value, size_t start, size_t end);
    void ParseConditionalTextToken(string &value, size_t start, size_t end);
    void ParsePrintfTextToken(string &value, size_t start, size_t end);
    bool SetScrollMode(string value);
    bool SetScrollSpeed(string value);
    bool SetOrientation(string value);
    bool SetFloating(string value);
    bool SetOverflow(string value);
    void ParseStringParameters(void);
    void ParseNumericalParameters(void);
    void CalculateAlign(int elementWidth, int elementHeight);
    int CalculateTextBoxHeight(void);
    int ReplaceIntToken(string intTok);
public:
    cTemplateFunction(eFuncType type);
    virtual ~cTemplateFunction(void);
    //Setter Functions
    void SetParameters(vector<pair<string, string> > params);
    void SetParameter(eParamType type, string value);
    void SetContainer(int x, int y, int w, int h);
    void SetLoopContainer(int columnWidth, int rowHeight);
    void SetWidthManually(string width);
    void SetHeightManually(string height);
    void SetXManually(int newX);
    void SetYManually(int newY);
    void SetMaxTextWidth(int maxWidth);
    void SetTextboxHeight(int boxHeight);
    void SetGlobals(cGlobals *globals) { this->globals = globals; };
    void SetTranslatedText(string translation);
    //PreCache Parameters 
    bool CalculateParameters(void);
    //Complete Parameters 
    bool ReCalculateParameters(void);
    void CompleteParameters(void);
    //Set and Unset Dynamic Tokens from view
    void SetStringTokens(map < string, string > *tok) { stringTokens = tok; };
    void SetIntTokens(map < string, int > *tok) { intTokens = tok; };
    void UnsetIntTokens(void) { intTokens = NULL; };
    void UnsetStringTokens(void) { stringTokens = NULL; };
    //Clear dynamically parameters
    void ClearDynamicParameters(void);
    //Parse parameters with dynamically set Tokens
    bool ParseParameters(void);
    //Getter Functions
    eFuncType GetType(void) { return type; };
    bool DoDebug(void) { return debug; };
    string GetParameter(eParamType type);
    int GetNumericParameter(eParamType type);
    string GetText(bool cut = true);
    string GetImagePath(void) { return imgPath; };
    tColor GetColorParameter(eParamType type);
    string GetFontName(void) { return fontName; };
    string GetFuncName(void);
    string GetParamName(eParamType pt);
    //Dynamic width or height parameter
    int GetWidth(bool cutted = true);
    int GetHeight(void);
    int GetContainerWidth(void) { return containerWidth; };
    int GetContainerHeight(void) { return containerHeight; };
    void GetNeededWidths(multimap<eParamType,string> *widths);
    void GetNeededHeights(multimap<eParamType,string> *heights);
    void GetNeededPosX(multimap<eParamType,string> *posXs);
    void GetNeededPosY(multimap<eParamType,string> *posYs);
    void SetWidth(eParamType type, string label, int funcWidth);
    void SetHeight(eParamType type, string label, int funcHeight);
    void SetX(eParamType type, string label, int funcX);
    void SetY(eParamType type, string label, int funcY);
    //Status Functions
    bool ParsedCompletely(void) { return parsedCompletely; };
    bool DoExecute(void);
    bool Updated(void) { return updated; };
    //Debug
    void Debug(void);
};

#endif //__TEMPLATEFUNCTION_H