Subversion Repositories tpanel

Rev

Rev 77 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 77 Rev 137
Line 17... Line 17...
17
 */
17
 */
18
 
18
 
19
#include "tpalette.h"
19
#include "tpalette.h"
20
#include "terror.h"
20
#include "terror.h"
21
#include "tconfig.h"
21
#include "tconfig.h"
-
 
22
#include "tresources.h"
22
#include "texpat++.h"
23
#include "texpat++.h"
23
 
24
 
24
using std::string;
25
using std::string;
25
using std::vector;
26
using std::vector;
26
using std::map;
27
using std::map;
Line 54... Line 55...
54
        path = getFileName();
55
        path = getFileName();
55
 
56
 
56
    TExpat xml(path);
57
    TExpat xml(path);
57
    xml.setEncoding(ENC_CP1250);
58
    xml.setEncoding(ENC_CP1250);
58
 
59
 
59
    if (!xml.parse())
60
    if (!xml.parse(false))
60
        return;
61
        return;
61
 
62
 
62
    int depth = 0;
63
    int depth = 0;
63
    size_t index = 0;
64
    size_t index = 0;
64
 
65
 
Line 74... Line 75...
74
 
75
 
75
    if (havePalette(palName))
76
    if (havePalette(palName))
76
        return;
77
        return;
77
 
78
 
78
    string name, content;
79
    string name, content;
79
    index++;
-
 
80
 
80
 
81
    while ((index = xml.getNextElementFromIndex(index, &name, &content, &attrs)) != TExpat::npos)
81
    while ((index = xml.getNextElementFromIndex(index, &name, &content, &attrs)) != TExpat::npos)
82
    {
82
    {
83
        PDATA_T pal;
83
        PDATA_T pal;
84
 
84
 
Line 96... Line 96...
96
        {
96
        {
97
            string sCol = "0x" + color.substr(1);
97
            string sCol = "0x" + color.substr(1);
98
            pal.color = strtoul(sCol.c_str(), 0, 16);
98
            pal.color = strtoul(sCol.c_str(), 0, 16);
99
        }
99
        }
100
 
100
 
101
        if (mColors.find(pal.name) != mColors.end())    // Don't insert color if it's already in list
101
        if (pal.name.length() > 0)
102
        {
102
        {
-
 
103
            if (mColors.find(pal.name) != mColors.end())    // Don't insert color if it's already in list
-
 
104
            {
103
            MSG_TRACE("Ignoring color " << pal.name << " because it was read before!");
105
                MSG_TRACE("Ignoring color " << pal.name << " because it was read before!");
104
            pal.clear();
106
                pal.clear();
105
            continue;
107
                continue;
-
 
108
            }
-
 
109
 
-
 
110
            // Insert color into list and get next child if there is one.
-
 
111
            mColors.insert(pair<string, PDATA_T>(pal.name, pal));
106
        }
112
        }
107
 
113
 
108
        // Insert color into list and get next child if there is one.
-
 
109
        mColors.insert(pair<string, PDATA_T>(pal.name, pal));
-
 
110
        pal.clear();
114
        pal.clear();
111
    }
115
    }
-
 
116
 
-
 
117
    if (mColors.empty())
-
 
118
        addSystemColors();
-
 
119
 
-
 
120
    mPaletteNames.push_back(palName);
112
}
121
}
113
 
122
 
114
void TPalette::reset()
123
void TPalette::reset()
115
{
124
{
116
    DECL_TRACER("TPalette::reset()");
125
    DECL_TRACER("TPalette::reset()");
Line 121... Line 130...
121
 
130
 
122
PDATA_T TPalette::findColor(const std::string& name)
131
PDATA_T TPalette::findColor(const std::string& name)
123
{
132
{
124
    DECL_TRACER("TPalette::findColor(const std::string& name)");
133
    DECL_TRACER("TPalette::findColor(const std::string& name)");
125
 
134
 
-
 
135
    if (mColors.empty())
-
 
136
    {
-
 
137
        MSG_WARNING("Have no colors in internal table!");
-
 
138
        return PDATA_T();
-
 
139
    }
-
 
140
 
126
    map<string, PDATA_T>::iterator iter;
141
    map<string, PDATA_T>::iterator iter;
127
 
142
 
128
    if ((iter = mColors.find(name)) == mColors.end())
143
    if ((iter = mColors.find(name)) == mColors.end())
129
        return PDATA_T();
144
        return PDATA_T();
130
 
145
 
Line 158... Line 173...
158
            return true;
173
            return true;
159
    }
174
    }
160
 
175
 
161
    return false;
176
    return false;
162
}
177
}
-
 
178
 
-
 
179
void TPalette::addSystemColors()
-
 
180
{
-
 
181
    DECL_TRACER("TPalette::addSystemColors()");
-
 
182
 
-
 
183
    vector<PDATA_T>::iterator iter;
-
 
184
    vector<PDATA_T> palArr = {
-
 
185
        {  0, "VeryLightRed",    0xff0000ff },
-
 
186
        {  1, "LightRed",        0xdf0000ff },
-
 
187
        {  2, "Red",             0xbf0000ff },
-
 
188
        {  3, "MediumRed",       0x9f0000ff },
-
 
189
        {  4, "DarkRed",         0x7f0000ff },
-
 
190
        {  5, "VeryDarkRed",     0x5f0000ff },
-
 
191
        {  6, "VeryLightOrange", 0xff8000ff },
-
 
192
        {  7, "LightOrange",     0xdf7000ff },
-
 
193
        {  8, "Orange",          0xbf6000ff },
-
 
194
        {  9, "MediumOrange",    0x9f5000ff },
-
 
195
        { 10, "DarkOrange",      0x7f4000ff },
-
 
196
        { 11, "VeryDarkOrange",  0x5f3000ff },
-
 
197
        { 12, "VeryLightYellow", 0xffff00ff },
-
 
198
        { 13, "LightYellow",     0xdfdf00ff },
-
 
199
        { 14, "Yellow",          0xbfbf00ff },
-
 
200
        { 15, "MediumYellow",    0x9f9f00ff },
-
 
201
        { 16, "DarkYellow",      0x7f7f00ff },
-
 
202
        { 17, "VeryDarkYellow",  0x5f5f00ff },
-
 
203
        { 18, "VeryLightLime",   0x80ff00ff },
-
 
204
        { 19, "LightLime",       0x70df00ff },
-
 
205
        { 20, "Lime",            0x60bf00ff },
-
 
206
        { 21, "MediumLime",      0x509f00ff },
-
 
207
        { 22, "DarkLime",        0x407f00ff },
-
 
208
        { 23, "VeryDarkLime",    0x304f00ff },
-
 
209
        { 24, "VeryLightGreen",  0x00ff00ff },
-
 
210
        { 25, "LightGreen",      0x00df00ff },
-
 
211
        { 26, "Green",           0x00bf00ff },
-
 
212
        { 27, "MediumGreen",     0x009f00ff },
-
 
213
        { 28, "DarkGreen",       0x007f00ff },
-
 
214
        { 29, "VeryDarkGreen",   0x005f00ff },
-
 
215
        { 30, "VeryLightMint",   0x00ff80ff },
-
 
216
        { 31, "LightMint",       0x00df70ff },
-
 
217
        { 32, "Mint",            0x00bf60ff },
-
 
218
        { 33, "MediumMint",      0x009f50ff },
-
 
219
        { 34, "DarkMint",        0x007f40ff },
-
 
220
        { 35, "VeryDarkMint",    0x005f10ff },
-
 
221
        { 36, "VeryLightCyan",   0x00ffffff },
-
 
222
        { 37, "LightCyan",       0x00dfdfff },
-
 
223
        { 38, "Cyan",            0x00bfbfff },
-
 
224
        { 39, "MediumCyan",      0x009f9fff },
-
 
225
        { 40, "DarkCyan",        0x007f7fff },
-
 
226
        { 41, "VeryDarkCyan",    0x005f5fff },
-
 
227
        { 42, "VeryLightAqua",   0x0080ffff },
-
 
228
        { 43, "LightAqua",       0x0070dfff },
-
 
229
        { 44, "Aqua",            0x0060bfff },
-
 
230
        { 45, "MediumAqua",      0x00509fff },
-
 
231
        { 46, "DarkAqua",        0x00407fff },
-
 
232
        { 47, "VeryDarkAqua",    0x00305fff },
-
 
233
        { 48, "VeryLightBlue",   0x0000ffff },
-
 
234
        { 49, "LightBlue",       0x0000dfff },
-
 
235
        { 50, "Blue",            0x0000bfff },
-
 
236
        { 51, "MediumBlue",      0x00009fff },
-
 
237
        { 52, "DarkBlue",        0x00007fff },
-
 
238
        { 53, "VeryDarkBlue",    0x00005fff },
-
 
239
        { 54, "VeryLightPurple", 0x8000ffff },
-
 
240
        { 55, "LightPurple",     0x7000dfff },
-
 
241
        { 56, "Purple",          0x6000bfff },
-
 
242
        { 57, "MediumPurple",    0x50009fff },
-
 
243
        { 58, "DarkPurple",      0x40007fff },
-
 
244
        { 59, "VeryDarkPurple",  0x30005fff },
-
 
245
        { 60, "VeryLightMagenta",0xff00ffff },
-
 
246
        { 61, "LightMagenta",    0xdf00dfff },
-
 
247
        { 62, "Magenta",         0xbf00bfff },
-
 
248
        { 63, "MediumMagenta",   0x9f009fff },
-
 
249
        { 64, "DarkMagenta",     0x7f007fff },
-
 
250
        { 65, "VeryDarkMagenta", 0x5f005fff },
-
 
251
        { 66, "VeryLightPink",   0xff0080ff },
-
 
252
        { 67, "LightPink",       0xdf0070ff },
-
 
253
        { 68, "Pink",            0xbf0060ff },
-
 
254
        { 69, "MediumPink",      0x9f0050ff },
-
 
255
        { 70, "DarkPink",        0x7f0040ff },
-
 
256
        { 71, "VeryDarkPink",    0x5f0030ff },
-
 
257
        { 72, "White",           0xffffffff },
-
 
258
        { 73, "Grey1",           0xeeeeeeff },
-
 
259
        { 74, "Grey3",           0xccccccff },
-
 
260
        { 75, "Grey5",           0xaaaaaaff },
-
 
261
        { 76, "Grey7",           0x888888ff },
-
 
262
        { 77, "Grey9",           0x666666ff },
-
 
263
        { 78, "Grey4",           0xbbbbbbff },
-
 
264
        { 79, "Grey6",           0x999999ff },
-
 
265
        { 80, "Grey8",           0x777777ff },
-
 
266
        { 81, "Grey10",          0x555555ff },
-
 
267
        { 82, "Grey12",          0x333333ff },
-
 
268
        { 83, "Grey13",          0x222222ff },
-
 
269
        { 84, "Grey2",           0xddddddff },
-
 
270
        { 85, "Grey11",          0x444444ff },
-
 
271
        { 86, "Grey14",          0x111111ff },
-
 
272
        { 87, "Black",           0x000000ff },
-
 
273
        { 255, "Transparent",    0x63356300 }
-
 
274
    };
-
 
275
 
-
 
276
    for (iter = palArr.begin(); iter != palArr.end(); ++iter)
-
 
277
        mColors.insert(pair<string, PDATA_T>(iter->name, *iter));
-
 
278
}