summaryrefslogtreecommitdiff
path: root/libtemplate/templateviewelement.c
blob: 5b18de2866af2336e73e633c2b1b65a1ab71ad6f (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
#include "templateviewelement.h"
#include "../config.h"

cTemplateViewElement::cTemplateViewElement(void) {
    debugTokens = false;
    parameters = NULL;
    containerX = 0;
    containerY = 0;
    containerWidth = 0;
    containerHeight = 0;
    pixOffset = -1;
}

cTemplateViewElement::~cTemplateViewElement(void) {
    if (parameters)
        delete parameters;
    for (vector<cTemplatePixmap*>::iterator it = viewPixmaps.begin(); it != viewPixmaps.end(); it++) {
        delete (*it);
    }
}

void cTemplateViewElement::SetContainer(int x, int y, int width, int height) { 
    containerX = x;
    containerY = y;
    containerWidth = width; 
    containerHeight = height; 
}

void cTemplateViewElement::SetGlobals(cGlobals *globals) { 
    this->globals = globals;
    for (vector<cTemplatePixmap*>::iterator pix = viewPixmaps.begin(); pix != viewPixmaps.end(); pix++) {
        (*pix)->SetGlobals(globals);
    }
}

void cTemplateViewElement::SetParameters(vector<pair<string, string> > &params) {
    parameters = new cTemplateFunction(ftViewElement);
    parameters->SetGlobals(globals);
    parameters->SetParameters(params);
}

bool cTemplateViewElement::CalculateParameters(void) {
    if (!parameters)
        return true;
    bool paramsValid = true;
    parameters->SetContainer(containerX, containerY, containerWidth, containerHeight);
    parameters->SetGlobals(globals);
    paramsValid = parameters->CalculateParameters();
    parameters->ParseParameters();
    return paramsValid;
}

bool cTemplateViewElement::CalculatePixmapParameters(void) {
    bool paramsValid = true;
    for (vector<cTemplatePixmap*>::iterator pix = viewPixmaps.begin(); pix != viewPixmaps.end(); pix++) {
        (*pix)->SetContainer(containerX, containerY, containerWidth, containerHeight);
        (*pix)->SetGlobals(globals);
        paramsValid = paramsValid && (*pix)->CalculateParameters();
    }
    return paramsValid;
}

bool cTemplateViewElement::CalculatePixmapParametersList(int orientation, int numElements) {
    bool paramsValid = true;
    for (vector<cTemplatePixmap*>::iterator pix = viewPixmaps.begin(); pix != viewPixmaps.end(); pix++) {
        (*pix)->SetContainer(containerX, containerY, containerWidth, containerHeight);
        (*pix)->SetGlobals(globals);
        if (orientation == orHorizontal) {
            if (numElements > 0) {
                int width = containerWidth / numElements;
                (*pix)->SetWidth(width);
            }
        } else if (orientation == orVertical) {
            if (numElements > 0) {
                int height = containerHeight / numElements;
                (*pix)->SetHeight(height);
            }
        } 
        paramsValid = paramsValid && (*pix)->CalculateParameters();
    }
    return paramsValid;
}

int cTemplateViewElement::GetNumericParameter(eParamType type) {
    if (!parameters)
        return -1;
    return parameters->GetNumericParameter(type);
}

void cTemplateViewElement::InitIterator(void) {
    pixIterator = viewPixmaps.begin();
}

cTemplatePixmap *cTemplateViewElement::GetNextPixmap(void) {
    if (pixIterator == viewPixmaps.end())
        return NULL;
    cTemplatePixmap *pix = *pixIterator;
    pixIterator++;
    return pix; 
}

cTemplateFunction *cTemplateViewElement::GetFunction(string name) {
    InitIterator();
    cTemplatePixmap *pix = NULL;
    while (pix = GetNextPixmap()) {
        pix->InitIterator();
        cTemplateFunction *func = NULL;
        while(func = pix->GetNextFunction()) {
            if (func->GetType() == ftDrawText) {
                string funcName = func->GetParameter(ptName);
                if (!funcName.compare(name))
                    return func;
            } else {
                continue;
            }
        }
    }
    return NULL;
}

bool cTemplateViewElement::Execute(void) {
    if (!parameters)
        return true;
    return parameters->DoExecute();
}

bool cTemplateViewElement::Detach(void) {
    if (!parameters)
        return false;
    int detached = parameters->GetNumericParameter(ptDetached);
    if (detached == 1)
        return true;
    return false;
}

string cTemplateViewElement::GetMode(void) {
    if (!parameters)
        return "";
    return parameters->GetParameter(ptMode);
}

bool cTemplateViewElement::DebugTokens(void) {
    if (!parameters)
        return false;
    return parameters->DoDebug();
}


void cTemplateViewElement::Debug(void) {
    esyslog("skindesigner: viewelement container size x: %d, y: %d, width: %d, height %d", containerX, containerY, containerWidth, containerHeight);
    if (parameters)
        parameters->Debug();
    return;
    for (vector<cTemplatePixmap*>::iterator it = viewPixmaps.begin(); it != viewPixmaps.end(); it++) {
        (*it)->Debug();
    }
}