Add ability for buttons to have highlights on touch

This commit is contained in:
Dees_Troy
2012-10-19 13:13:15 -04:00
parent 5fcd8f981f
commit 4d12f969b8
4 changed files with 66 additions and 4 deletions
+25 -2
View File
@@ -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);
}
+9 -1
View File
@@ -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;
}
+9
View File
@@ -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
+23 -1
View File
@@ -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");
@@ -65,6 +76,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;
}
}
@@ -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);