summaryrefslogtreecommitdiff
path: root/glcdskin
diff options
context:
space:
mode:
authormrwastl <mrwastl@users.sourceforge.net>2011-05-16 00:26:23 +0200
committermrwastl <mrwastl@users.sourceforge.net>2011-05-16 00:26:23 +0200
commit4cd5223718a7f24ad31b2054263048e6af5dd1aa (patch)
treeb55ec97258ce269c5de7cb602217788a3c426aa6 /glcdskin
parent9a4532d4904088f9c5cde08542d85dc858b92e9b (diff)
downloadgraphlcd-base-4cd5223718a7f24ad31b2054263048e6af5dd1aa.tar.gz
graphlcd-base-4cd5223718a7f24ad31b2054263048e6af5dd1aa.tar.bz2
object colours (fore/background) are now evaluated at run time; minor clean up in class cColor, class member cColor::color is no longer public
Diffstat (limited to 'glcdskin')
-rw-r--r--glcdskin/object.c42
-rw-r--r--glcdskin/object.h29
2 files changed, 59 insertions, 12 deletions
diff --git a/glcdskin/object.c b/glcdskin/object.c
index 3a8162e..ead6197 100644
--- a/glcdskin/object.c
+++ b/glcdskin/object.c
@@ -34,8 +34,8 @@ cSkinObject::cSkinObject(cSkinDisplay * Parent)
mType((eType) __COUNT_OBJECT__),
mPos1(0, 0),
mPos2(-1, -1),
- mColor(cColor(cColor::Black)),
- mBackgroundColor(cColor(cColor::Transparent)),
+ mColor(this, cColor(cColor::Black)),
+ mBackgroundColor(this, cColor(cColor::Transparent)),
mFilled(false),
mRadius(0),
mArc(0),
@@ -64,8 +64,8 @@ cSkinObject::cSkinObject(cSkinDisplay * Parent)
mAction(""), // action (e.g. touchscreen action)
mObjects(NULL)
{
- mColor = Parent->Skin()->Config().GetDriver()->GetForegroundColor();
- mBackgroundColor = Parent->Skin()->Config().GetDriver()->GetBackgroundColor();
+ mColor.SetColor(Parent->Skin()->Config().GetDriver()->GetForegroundColor());
+ mBackgroundColor.SetColor(Parent->Skin()->Config().GetDriver()->GetBackgroundColor());
}
cSkinObject::cSkinObject(const cSkinObject & Src)
@@ -126,17 +126,28 @@ bool cSkinObject::ParseType(const std::string & Text)
return false;
}
-bool cSkinObject::ParseColor(const std::string & Text, cColor & ParamColor)
+bool cSkinObject::ParseColor(const std::string & Text, cSkinColor & ParamColor)
{
std::string text = (std::string) Text;
+ cColor color = cColor::ERRCOL;
if (text[0] == '#') {
cSkinVariable * variable = mSkin->GetVariable(text.substr(1));
if (variable) {
- text = variable->Value().String();
+ color = cColor::ParseColor(variable->Value().String());
+ if (color == cColor::ERRCOL) {
+ return false;
+ }
+ ParamColor.SetVarId(text.substr(1));
+ return true;
}
+ return false;
}
- ParamColor = cColor::ParseColor(text);
- return (ParamColor == cColor::ERRCOL) ? false : true;
+ color = cColor::ParseColor(text);
+ if (color == cColor::ERRCOL) {
+ return false;
+ }
+ ParamColor.SetColor(color);
+ return true;
}
bool cSkinObject::ParseCondition(const std::string & Text)
@@ -671,7 +682,7 @@ void cSkinObject::Render(GLCD::cBitmap * screen)
cSkinFont * skinFont = mSkin->GetFont(mFont.Evaluate());
if (mBackgroundColor == mColor || mBackgroundColor == cColor::Transparent)
- mBackgroundColor = cColor(mColor).Invert();
+ mBackgroundColor.SetColor( (cColor(mColor).Invert()) );
if (mRadius == 0)
screen->DrawRectangle(Pos().x, Pos().y, Pos().x + Size().w - 1, Pos().y + Size().h - 1, mBackgroundColor, true);
@@ -894,6 +905,19 @@ std::string cSkinObject::CheckAction(cGLCDEvent * ev)
}
+
+uint32_t cSkinColor::GetColor(void) {
+ if (mVarId != "") {
+ cSkinVariable * variable = mObject->Skin()->GetVariable(mVarId);
+ if (variable) {
+ return cColor::ParseColor(variable->Value().String());
+ }
+ return cColor::ERRCOL;
+ }
+ return (uint32_t) mColor;
+}
+
+
cSkinObjects::cSkinObjects(void)
{
}
diff --git a/glcdskin/object.h b/glcdskin/object.h
index 81fb139..cb5f35a 100644
--- a/glcdskin/object.h
+++ b/glcdskin/object.h
@@ -60,6 +60,29 @@ enum eTextVerticalAlignment
tvaBottom
};
+
+class cSkinColor
+{
+private:
+ cSkinObject * mObject;
+ uint32_t mColor;
+ std::string mVarId;
+public:
+ cSkinColor(cSkinObject *Parent, uint32_t color):mVarId("") { mObject = Parent; mColor = color; }
+ cSkinColor(cSkinObject *Parent, cColor color):mVarId("") { mObject = Parent; mColor = (uint32_t)color; }
+ cSkinColor(cSkinObject *Parent, const std::string varId) { mObject = Parent; mVarId = varId; }
+ ~cSkinColor() {};
+
+ void SetColor(uint32_t color) { mVarId = ""; mColor = color; }
+ void SetColor(cColor color) { mVarId = ""; mColor = (uint32_t)color; }
+ void SetVarId(const std::string varId) { mVarId = varId; }
+
+ uint32_t GetColor(void);
+
+ operator uint32_t(void) { return GetColor(); }
+};
+
+
class cSkinObject
{
friend bool StartElem(const std::string & name, std::map<std::string,std::string> & attrs);
@@ -92,8 +115,8 @@ private:
eType mType; // type of object, one of enum eType
tPoint mPos1;
tPoint mPos2;
- cColor mColor;
- cColor mBackgroundColor;
+ cSkinColor mColor;
+ cSkinColor mBackgroundColor;
bool mFilled;
int mRadius;
int mArc;
@@ -135,7 +158,7 @@ public:
~cSkinObject();
bool ParseType(const std::string &Text);
- bool ParseColor(const std::string &Text, cColor & ParamColor);
+ bool ParseColor(const std::string &Text, cSkinColor & ParamColor);
bool ParseCondition(const std::string &Text);
bool ParseAlignment(const std::string &Text);
bool ParseVerticalAlignment(const std::string &Text);