Subversion Repositories tpanel

Rev

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

Rev 23 Rev 77
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 "treadxml.h"
22
#include "texpat++.h"
23
 
23
 
24
using std::string;
24
using std::string;
25
using std::vector;
25
using std::vector;
26
using std::map;
26
using std::map;
27
using std::pair;
27
using std::pair;
-
 
28
using namespace Expat;
28
 
29
 
29
TPalette::TPalette()
30
TPalette::TPalette()
30
{
31
{
31
    DECL_TRACER("TPalette::TPalette()");
32
    DECL_TRACER("TPalette::TPalette()");
32
}
33
}
Line 50... Line 51...
50
    string path;
51
    string path;
51
 
52
 
52
    if (isValidFile())
53
    if (isValidFile())
53
        path = getFileName();
54
        path = getFileName();
54
 
55
 
55
    TReadXML reader(path);
56
    TExpat xml(path);
-
 
57
    xml.setEncoding(ENC_CP1250);
56
 
58
 
57
    if (TError::isError())
59
    if (!xml.parse())
58
        return;
60
        return;
59
 
61
 
-
 
62
    int depth = 0;
60
    reader.findElement("paletteData", "name");
63
    size_t index = 0;
61
 
64
 
62
    if (!reader.success())
65
    if ((index = xml.getElementIndex("paletteData", &depth)) == TExpat::npos)
63
    {
66
    {
64
        MSG_ERROR("Error reading palatte file " << file << "!");
67
        MSG_ERROR("Element \"paletteData\" was not found!");
65
        TError::setError();
68
        TError::setError();
66
        return;
69
        return;
67
    }
70
    }
68
 
71
 
-
 
72
    vector<ATTRIBUTE_t> attrs = xml.getAttributes();
69
    string palName = reader.getAttribute("name");
73
    string palName = xml.getAttribute("name", attrs);
70
 
74
 
71
    if (havePalette(palName))
75
    if (havePalette(palName))
72
        return;
76
        return;
73
 
77
 
74
    mxml_node_t *node = reader.getFirstChild();
78
    string name, content;
-
 
79
    index++;
75
 
80
 
76
    while (node)
81
    while ((index = xml.getNextElementFromIndex(index, &name, &content, &attrs)) != TExpat::npos)
77
    {
82
    {
78
        PDATA_T pal;
83
        PDATA_T pal;
79
        string e = reader.getElementName(node);
-
 
80
 
84
 
81
        if (e.compare("color") != 0)
85
        if (name.compare("color") != 0)
82
        {
86
        {
83
            node = reader.getNextChild();
-
 
84
            pal.clear();
87
            pal.clear();
85
            continue;
88
            continue;
86
        }
89
        }
87
 
90
 
88
        pal.index = atoi(reader.getAttributeFromNode(node, "index").c_str());
91
        pal.index = xml.getAttributeInt("index", attrs);
89
        pal.name = reader.getAttributeFromNode(node, "name");
92
        pal.name = xml.getAttribute("name", attrs);
90
        string color = reader.getTextFromNode(node);
93
        string color = content;
91
 
94
 
92
        if (color.at(0) == '#')     // Do we have a valid color value?
95
        if (color.at(0) == '#')     // Do we have a valid color value?
93
        {
96
        {
94
            string sCol = "0x" + color.substr(1);
97
            string sCol = "0x" + color.substr(1);
95
            pal.color = strtoul(sCol.c_str(), 0, 16);
98
            pal.color = strtoul(sCol.c_str(), 0, 16);
96
        }
99
        }
97
 
100
 
98
        if (mColors.find(pal.name) != mColors.end())    // Don't insert color if it's already in list
101
        if (mColors.find(pal.name) != mColors.end())    // Don't insert color if it's already in list
99
        {
102
        {
100
            MSG_TRACE("Ignoring color " << pal.name << " because it was read before!");
103
            MSG_TRACE("Ignoring color " << pal.name << " because it was read before!");
101
            node = reader.getNextChild();
-
 
102
            pal.clear();
104
            pal.clear();
103
            continue;
105
            continue;
104
        }
106
        }
105
 
107
 
106
        // Insert color into list and get next child if there is one.
108
        // Insert color into list and get next child if there is one.
107
        mColors.insert(pair<string, PDATA_T>(pal.name, pal));
109
        mColors.insert(pair<string, PDATA_T>(pal.name, pal));
108
        pal.clear();
110
        pal.clear();
109
        node = reader.getNextChild();
-
 
110
    }
111
    }
111
}
112
}
112
 
113
 
113
void TPalette::reset()
114
void TPalette::reset()
114
{
115
{