Date:2014-07-17 19:27:39 (3 months 3 days ago)
Author:Maarten ter Huurne
Commit:5f454a856991737da96de872c7fc68589e99e930
Message:Made strtorgba into a factory method of RGBAColor

The method is RGBAColor::fromString.
Files: src/gmenu2x.cpp (1 diff)
src/surface.cpp (1 diff)
src/surface.h (1 diff)

Change Details

src/gmenu2x.cpp
830830                    if (value.length()>1 && value.at(0)=='"' && value.at(value.length()-1)=='"')
831831                        skinConfStr[name] = value.substr(1,value.length()-2);
832832                    else if (value.at(0) == '#')
833                        skinConfColors[stringToColor(name)] = strtorgba( value.substr(1,value.length()) );
833                        skinConfColors[stringToColor(name)] =
834                            RGBAColor::fromString(value.substr(1, value.length()));
834835                    else
835836                        skinConfInt[name] = atoi(value.c_str());
836837                }
src/surface.cpp
3131
3232using namespace std;
3333
34RGBAColor strtorgba(const string &strColor) {
35    RGBAColor c = {0,0,0,255};
36    c.r = constrain( strtol( strColor.substr(0,2).c_str(), NULL, 16 ), 0, 255 );
37    c.g = constrain( strtol( strColor.substr(2,2).c_str(), NULL, 16 ), 0, 255 );
38    c.b = constrain( strtol( strColor.substr(4,2).c_str(), NULL, 16 ), 0, 255 );
39    c.a = constrain( strtol( strColor.substr(6,2).c_str(), NULL, 16 ), 0, 255 );
40    return c;
34RGBAColor RGBAColor::fromString(const string &strColor) {
35    return {
36        uint8_t(constrain(strtol(strColor.substr(0, 2).c_str(), nullptr, 16),
37                          0, 255)),
38        uint8_t(constrain(strtol(strColor.substr(2, 2).c_str(), nullptr, 16),
39                          0, 255)),
40        uint8_t(constrain(strtol(strColor.substr(4, 2).c_str(), nullptr, 16),
41                          0, 255)),
42        uint8_t(constrain(strtol(strColor.substr(6, 2).c_str(), nullptr, 16),
43                          0, 255)),
44    };
4145}
4246
4347Surface *Surface::openOutputSurface(int width, int height, int bitsperpixel) {
src/surface.h
2929
3030struct RGBAColor {
3131    uint8_t r, g, b, a;
32    static RGBAColor fromString(std::string const& strColor);
3233};
3334
34RGBAColor strtorgba(const std::string &strColor);
35
3635/**
3736    Wrapper around SDL_Surface
3837    @author Massimiliano Torromeo <massimiliano.torromeo@gmail.com>

Archive Download the corresponding diff file



interactive