File: tags.cpp

package info (click to toggle)
openmw 0.47.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 23,276 kB
  • sloc: cpp: 249,935; xml: 1,978; sh: 1,327; python: 63; makefile: 26
file content (59 lines) | stat: -rw-r--r-- 1,913 bytes parent folder | download | duplicates (3)
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
#include "tags.hpp"

#include <components/fallback/fallback.hpp>

#include <MyGUI_Colour.h>

namespace Gui
{

bool replaceTag(const MyGUI::UString& tag, MyGUI::UString& out)
{
    std::string fontcolour = "fontcolour=";
    size_t fontcolourLength = fontcolour.length();

    std::string fontcolourhtml = "fontcolourhtml=";
    size_t fontcolourhtmlLength = fontcolourhtml.length();

    if (tag.compare(0, fontcolourLength, fontcolour) == 0)
    {
        std::string fallbackName = "FontColor_color_" + tag.substr(fontcolourLength);
        std::string str = Fallback::Map::getString(fallbackName);
        if (str.empty())
            throw std::runtime_error("Unknown fallback name: " + fallbackName);

        std::string ret[3];
        unsigned int j=0;
        for(unsigned int i=0;i<str.length();++i)
        {
            if(str[i]==',') j++;
            else if (str[i] != ' ') ret[j]+=str[i];
        }
        MyGUI::Colour col (MyGUI::utility::parseInt(ret[0])/255.f,MyGUI::utility::parseInt(ret[1])/255.f,MyGUI::utility::parseInt(ret[2])/255.f);
        out = col.print();
        return true;
    }
    else if (tag.compare(0, fontcolourhtmlLength, fontcolourhtml) == 0)
    {
        std::string fallbackName = "FontColor_color_" + tag.substr(fontcolourhtmlLength);
        std::string str = Fallback::Map::getString(fallbackName);
        if (str.empty())
            throw std::runtime_error("Unknown fallback name: " + fallbackName);

        std::string ret[3];
        unsigned int j=0;
        for(unsigned int i=0;i<str.length();++i)
        {
            if(str[i]==',') j++;
            else if (str[i] != ' ') ret[j]+=str[i];
        }
        std::stringstream html;
        html << "#" << std::hex << MyGUI::utility::parseInt(ret[0]) << MyGUI::utility::parseInt(ret[1]) << MyGUI::utility::parseInt(ret[2]);
        out = html.str();
        return true;
    }
    return false;

}

}