Skip to content

Commit

Permalink
KOTOR: Implement highlightable buttons.
Browse files Browse the repository at this point in the history
The difficult buttons now highlight on mouseover.
I also made the highlightable getter protected, as I don't
see any special cases where the gui needs to control it (for now).
  • Loading branch information
ImperatorPrime committed Aug 8, 2013
1 parent a6f4485 commit 74282f8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/engines/kotor/gui/widgets/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ void WidgetButton::load(const Aurora::GFFStruct &gff) {
if(getTextHighlightableComponent() != NULL) {
setDefaultHighlighting(getTextHighlightableComponent());
}
if(getQuadHighlightableComponent() != NULL) {
setDefaultHighlighting(getQuadHighlightableComponent());
}
}

void WidgetButton::mouseUp(uint8 state, float x, float y) {
Expand All @@ -73,6 +76,14 @@ void WidgetButton::enter() {
_text->setColor(r, g, b, a);
_text->setHighlighted(true);
}

if(getQuadHighlightableComponent() && getQuadHighlightableComponent()->isHighlightable()) {
_quad->getColor(_unselectedR, _unselectedG, _unselectedB, _unselectedA);
getQuadHighlightableComponent()->getHighlightedLowerBound(r, g, b, a);
_quad->setColor(r, g, b, a);
getQuadHighlightableComponent()->setHighlighted(true);
}

}

void WidgetButton::leave() {
Expand All @@ -81,6 +92,10 @@ void WidgetButton::leave() {
_text->setHighlighted(false);
_text->setColor(_unselectedR, _unselectedG, _unselectedB, _unselectedA);
}
if(getQuadHighlightableComponent() && getQuadHighlightableComponent()->isHighlightable()) {
getQuadHighlightableComponent()->setHighlighted(false);
_quad->setColor(_unselectedR, _unselectedG, _unselectedB, _unselectedA);
}
}

void WidgetButton::setDefaultHighlighting(Graphics::Aurora::Highlightable *highlightable) {
Expand Down
2 changes: 1 addition & 1 deletion src/engines/kotor/gui/widgets/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class WidgetButton : public KotORWidget {
WidgetButton(::Engines::GUI &gui, const Common::UString &tag);
~WidgetButton();

void load(const Aurora::GFFStruct &gff);
virtual void load(const Aurora::GFFStruct &gff);

void mouseUp(uint8 state, float x, float y);

Expand Down
12 changes: 11 additions & 1 deletion src/engines/kotor/gui/widgets/kotorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "graphics/aurora/guiquad.h"
#include "graphics/aurora/text.h"
#include "graphics/aurora/highlightabletext.h"
#include "graphics/aurora/highlightableguiquad.h"

#include "engines/kotor/gui/widgets/kotorwidget.h"

Expand Down Expand Up @@ -164,7 +165,12 @@ void KotORWidget::load(const Aurora::GFFStruct &gff) {

Border border = createBorder(gff);

_quad = new Graphics::Aurora::GUIQuad(border.fill, 0.0, 0.0, extend.w, extend.h);
if(!border.fill.empty()) {
_quad = new Graphics::Aurora::HighlightableGUIQuad(border.fill, 0.0, 0.0, extend.w, extend.h);
} else {
_quad = new Graphics::Aurora::GUIQuad(border.fill, 0.0, 0.0, extend.w, extend.h);
}

_quad->setPosition(extend.x, extend.y, 0.0);
_quad->setTag(getTag());
_quad->setClickable(true);
Expand Down Expand Up @@ -286,6 +292,10 @@ Graphics::Aurora::Highlightable* KotORWidget::getTextHighlightableComponent() co
return static_cast<Graphics::Aurora::Highlightable*>(_text);
}

Graphics::Aurora::Highlightable* KotORWidget::getQuadHighlightableComponent() const {
return dynamic_cast<Graphics::Aurora::Highlightable*>(_quad);
}

} // End of namespace KotOR

} // End of namespace Engines
5 changes: 3 additions & 2 deletions src/engines/kotor/gui/widgets/kotorwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ class KotORWidget : public Widget {
void setColor(float r, float g, float b, float a);
void setText(const Common::UString &text);

Graphics::Aurora::Highlightable *getTextHighlightableComponent() const;

protected:
struct Extend {
float x;
Expand Down Expand Up @@ -108,6 +106,9 @@ class KotORWidget : public Widget {

Text();
};

Graphics::Aurora::Highlightable *getTextHighlightableComponent() const;
Graphics::Aurora::Highlightable *getQuadHighlightableComponent() const;

float _width;
float _height;
Expand Down

0 comments on commit 74282f8

Please sign in to comment.