mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 12:36:17 +02:00
Made strtorgba into a factory method of RGBAColor
The method is RGBAColor::fromString.
This commit is contained in:
parent
950518f3a7
commit
5f454a8569
@ -830,7 +830,8 @@ void GMenu2X::setSkin(const string &skin, bool setWallpaper) {
|
||||
if (value.length()>1 && value.at(0)=='"' && value.at(value.length()-1)=='"')
|
||||
skinConfStr[name] = value.substr(1,value.length()-2);
|
||||
else if (value.at(0) == '#')
|
||||
skinConfColors[stringToColor(name)] = strtorgba( value.substr(1,value.length()) );
|
||||
skinConfColors[stringToColor(name)] =
|
||||
RGBAColor::fromString(value.substr(1, value.length()));
|
||||
else
|
||||
skinConfInt[name] = atoi(value.c_str());
|
||||
}
|
||||
|
@ -31,13 +31,17 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
RGBAColor strtorgba(const string &strColor) {
|
||||
RGBAColor c = {0,0,0,255};
|
||||
c.r = constrain( strtol( strColor.substr(0,2).c_str(), NULL, 16 ), 0, 255 );
|
||||
c.g = constrain( strtol( strColor.substr(2,2).c_str(), NULL, 16 ), 0, 255 );
|
||||
c.b = constrain( strtol( strColor.substr(4,2).c_str(), NULL, 16 ), 0, 255 );
|
||||
c.a = constrain( strtol( strColor.substr(6,2).c_str(), NULL, 16 ), 0, 255 );
|
||||
return c;
|
||||
RGBAColor RGBAColor::fromString(const string &strColor) {
|
||||
return {
|
||||
uint8_t(constrain(strtol(strColor.substr(0, 2).c_str(), nullptr, 16),
|
||||
0, 255)),
|
||||
uint8_t(constrain(strtol(strColor.substr(2, 2).c_str(), nullptr, 16),
|
||||
0, 255)),
|
||||
uint8_t(constrain(strtol(strColor.substr(4, 2).c_str(), nullptr, 16),
|
||||
0, 255)),
|
||||
uint8_t(constrain(strtol(strColor.substr(6, 2).c_str(), nullptr, 16),
|
||||
0, 255)),
|
||||
};
|
||||
}
|
||||
|
||||
Surface *Surface::openOutputSurface(int width, int height, int bitsperpixel) {
|
||||
|
@ -29,10 +29,9 @@
|
||||
|
||||
struct RGBAColor {
|
||||
uint8_t r, g, b, a;
|
||||
static RGBAColor fromString(std::string const& strColor);
|
||||
};
|
||||
|
||||
RGBAColor strtorgba(const std::string &strColor);
|
||||
|
||||
/**
|
||||
Wrapper around SDL_Surface
|
||||
@author Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
|
||||
|
Loading…
Reference in New Issue
Block a user