summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gui/button.cpp27
-rw-r--r--gui/image.cpp10
-rw-r--r--gui/objects.hpp9
-rw-r--r--gui/text.cpp24
4 files changed, 66 insertions, 4 deletions
diff --git a/gui/button.cpp b/gui/button.cpp
index 72e2fe905..b9d1b52dc 100644
--- a/gui/button.cpp
+++ b/gui/button.cpp
@@ -107,7 +107,7 @@ int GUIButton::Update(void)
int ret = 0, ret2 = 0;
- if (mButtonImg) ret = mButtonImg->Update();
+ if (mButtonImg) ret = mButtonImg->Update();
if (ret < 0) return ret;
if (ret == 0)
@@ -188,7 +188,30 @@ int GUIButton::SetRenderPos(int x, int y, int w, int h)
int GUIButton::NotifyTouch(TOUCH_STATE state, int x, int y)
{
- if (!isConditionTrue()) return -1;
+ static int last_state = 0;
+
+ if (!isConditionTrue()) return -1;
+ if (x < mRenderX || x - mRenderX > mRenderW || y < mRenderY || y - mRenderY > mRenderH || state == TOUCH_RELEASE) {
+ if (last_state == 1) {
+ last_state = 0;
+ if (mButtonLabel != NULL)
+ mButtonLabel->isHighlighted = false;
+ if (mButtonImg != NULL)
+ mButtonImg->isHighlighted = false;
+ mRendered = false;
+ }
+ } else {
+ if (last_state == 0) {
+ last_state = 1;
+ if (mButtonLabel != NULL)
+ mButtonLabel->isHighlighted = true;
+ if (mButtonImg != NULL)
+ mButtonImg->isHighlighted = true;
+ mRendered = false;
+ }
+ }
+ if (x < mRenderX || x - mRenderX > mRenderW || y < mRenderY || y - mRenderY > mRenderH)
+ return 0;
return (mAction ? mAction->NotifyTouch(state, x, y) : 1);
}
diff --git a/gui/image.cpp b/gui/image.cpp
index 44400e626..05e517867 100644
--- a/gui/image.cpp
+++ b/gui/image.cpp
@@ -32,6 +32,8 @@ GUIImage::GUIImage(xml_node<>* node)
xml_node<>* child;
mImage = NULL;
+ mHighlightImage = NULL;
+ isHighlighted = false;
if (!node)
return;
@@ -42,6 +44,9 @@ GUIImage::GUIImage(xml_node<>* node)
attr = child->first_attribute("resource");
if (attr)
mImage = PageManager::FindResource(attr->value());
+ attr = child->first_attribute("highlightresource");
+ if (attr)
+ mHighlightImage = PageManager::FindResource(attr->value());
}
// Load the placement
@@ -75,7 +80,10 @@ GUIImage::GUIImage(xml_node<>* node)
int GUIImage::Render(void)
{
- if (!mImage || !mImage->GetResource()) return -1;
+ if (isHighlighted && mHighlightImage && mHighlightImage->GetResource()) {
+ gr_blit(mHighlightImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
+ return 0;
+ } else if (!mImage || !mImage->GetResource()) return -1;
gr_blit(mImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
return 0;
}
diff --git a/gui/objects.hpp b/gui/objects.hpp
index 1f3f11a90..8f7823663 100644
--- a/gui/objects.hpp
+++ b/gui/objects.hpp
@@ -174,16 +174,21 @@ public:
// Set number of characters to skip (for scrolling)
virtual int SkipCharCount(unsigned skip);
+public:
+ bool isHighlighted;
+
protected:
std::string mText;
std::string mLastValue;
COLOR mColor;
+ COLOR mHighlightColor;
Resource* mFont;
int mIsStatic;
int mVarChanged;
int mFontHeight;
unsigned maxWidth;
unsigned charSkip;
+ bool hasHighlightColor;
protected:
std::string parseText(void);
@@ -204,8 +209,12 @@ public:
// Return 0 on success, <0 on error
virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
+public:
+ bool isHighlighted;
+
protected:
Resource* mImage;
+ Resource* mHighlightImage;
};
// GUIFill - Used for fill colors
diff --git a/gui/text.cpp b/gui/text.cpp
index 90482fef3..dc7a2d119 100644
--- a/gui/text.cpp
+++ b/gui/text.cpp
@@ -38,12 +38,16 @@ GUIText::GUIText(xml_node<>* node)
mFontHeight = 0;
maxWidth = 0;
charSkip = 0;
+ isHighlighted = false;
+ hasHighlightColor = false;
if (!node) return;
// Initialize color to solid black
memset(&mColor, 0, sizeof(COLOR));
mColor.alpha = 255;
+ memset(&mHighlightColor, 0, sizeof(COLOR));
+ mHighlightColor.alpha = 255;
attr = node->first_attribute("color");
if (attr)
@@ -51,6 +55,13 @@ GUIText::GUIText(xml_node<>* node)
std::string color = attr->value();
ConvertStrToColor(color, &mColor);
}
+ attr = node->first_attribute("highlightcolor");
+ if (attr)
+ {
+ std::string color = attr->value();
+ ConvertStrToColor(color, &mHighlightColor);
+ hasHighlightColor = true;
+ }
// Load the font, and possibly override the color
child = node->first_node("font");
@@ -66,6 +77,14 @@ GUIText::GUIText(xml_node<>* node)
std::string color = attr->value();
ConvertStrToColor(color, &mColor);
}
+
+ attr = child->first_attribute("highlightcolor");
+ if (attr)
+ {
+ std::string color = attr->value();
+ ConvertStrToColor(color, &mHighlightColor);
+ hasHighlightColor = true;
+ }
}
// Load the placement
@@ -117,7 +136,10 @@ int GUIText::Render(void)
y -= mFontHeight;
}
- gr_color(mColor.red, mColor.green, mColor.blue, mColor.alpha);
+ if (hasHighlightColor && isHighlighted)
+ gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha);
+ else
+ gr_color(mColor.red, mColor.green, mColor.blue, mColor.alpha);
if (maxWidth)
gr_textExW(x, y, displayValue.c_str(), fontResource, maxWidth + x);