Skip to content

Commit

Permalink
GRAPHICS: Refactor highlighting logic into a class.
Browse files Browse the repository at this point in the history
  • Loading branch information
ImperatorPrime authored and DrMcCoy committed Mar 27, 2013
1 parent 3173e34 commit 57a8121
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 168 deletions.
2 changes: 2 additions & 0 deletions src/graphics/aurora/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ noinst_HEADERS = types.h \
abcfont.h \
ttffont.h \
fontman.h \
highlightable.h \
text.h \
highlightabletext.h \
fps.h \
Expand All @@ -36,6 +37,7 @@ libaurora_la_SOURCES = texture.cpp \
abcfont.cpp \
ttffont.cpp \
fontman.cpp \
highlightable.cpp \
text.cpp \
highlightabletext.cpp \
fps.cpp \
Expand Down
95 changes: 95 additions & 0 deletions src/graphics/aurora/highlightable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* xoreos - A reimplementation of BioWare's Aurora engine
*
* xoreos is the legal property of its developers, whose names can be
* found in the AUTHORS file distributed with this source
* distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*
* The Infinity, Aurora, Odyssey, Eclipse and Lycium engines, Copyright (c) BioWare corp.
* The Electron engine, Copyright (c) Obsidian Entertainment and BioWare corp.
*/

#include "graphics/aurora/highlightable.h"

namespace Graphics {

namespace Aurora {

Highlightable::Highlightable() {

}

Highlightable::~Highlightable() {

}

bool Highlightable::isHightlighted() {
return _isHighlighted;
}

void Highlightable::setHighlighted (bool hightlighted) {
_isHighlighted = hightlighted;
}

void Highlightable::setHighlightDelta (float r, float g, float b, float a) {
_deltaR = r;
_deltaG = g;
_deltaB = b;
_deltaA = a;
}

void Highlightable::setHighlightLowerBound (float r, float g, float b, float a) {
_lowerBoundR = r;
_lowerBoundG = g;
_lowerBoundB = b;
_lowerBoundA = a;
}

void Highlightable::setHighlightUpperBound (float r, float g, float b, float a) {
_upperBoundR = r;
_upperBoundG = g;
_upperBoundB = b;
_upperBoundA = a;
}

void Highlightable::flipHighlightDelta() {
_deltaR *= -1;
_deltaG *= -1;
_deltaB *= -1;
_deltaA *= -1;
}

void Highlightable::incrementColor(float initialR, float initialG, float initialB, float initialA, float &r, float &g, float &b, float &a) {
r = initialR + _deltaR;
g = initialG + _deltaG;
b = initialB + _deltaB;
a = initialA + _deltaA;

if(_upperBoundR < r || _upperBoundG < g || _upperBoundB < b || _upperBoundA < a ||
_lowerBoundR > r || _lowerBoundG > g || _lowerBoundB > b || _lowerBoundA > a) {
flipHighlightDelta();

r = initialR;
g = initialG;
b = initialB;
a = initialA;
}
}

} // End of namespace Aurora

} // End of namespace Graphics
81 changes: 81 additions & 0 deletions src/graphics/aurora/highlightable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* xoreos - A reimplementation of BioWare's Aurora engine
*
* xoreos is the legal property of its developers, whose names can be
* found in the AUTHORS file distributed with this source
* distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*
* The Infinity, Aurora, Odyssey, Eclipse and Lycium engines, Copyright (c) BioWare corp.
* The Electron engine, Copyright (c) Obsidian Entertainment and BioWare corp.
*/

#ifndef HIGHLIGHTABLE_H
#define HIGHLIGHTABLE_H

namespace Graphics {

namespace Aurora {

class Highlightable {

public:
Highlightable();
virtual ~Highlightable();


bool isHightlighted();
void setHighlighted(bool hightlighted);

// This is how much the quad changes per render. Positive number increment the color, negative numbers decrement it.
void setHighlightDelta(float r, float g, float b, float a);

//When any of the quad properties are greater than this bound, the signs of the delta floats will flip
void setHighlightUpperBound(float r, float g, float b, float a);

//When any of the quad properties are less than this bound, the signs of the delta floats will flip
void setHighlightLowerBound(float r, float g, float b, float a);

protected:
void flipHighlightDelta();

void incrementColor(float initialR, float initialG, float initialB, float initialA, float &r, float &g, float &b, float &a);


private:
bool _isHighlighted;

float _deltaR;
float _deltaG;
float _deltaB;
float _deltaA;

float _upperBoundR;
float _upperBoundG;
float _upperBoundB;
float _upperBoundA;

float _lowerBoundR;
float _lowerBoundG;
float _lowerBoundB;
float _lowerBoundA;
};

} // End of namespace Aurora

} // End of namespace Graphics

#endif // HIGHLIGHTABLE_H
55 changes: 4 additions & 51 deletions src/graphics/aurora/highlightableguiquad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,62 +38,15 @@ HighlightableGUIQuad::HighlightableGUIQuad (const Common::UString &texture,
HighlightableGUIQuad::~HighlightableGUIQuad() {
}

bool HighlightableGUIQuad::isHightlighted() {
return _isHighlighted;
}

void HighlightableGUIQuad::setHighlighted (bool hightlighted) {
_isHighlighted = hightlighted;
}

void HighlightableGUIQuad::render (RenderPass pass) {
if(_isHighlighted) {
_r += _deltaR;
_g += _deltaG;
_b += _deltaB;
_a += _deltaA;

if(_upperBoundR < _r || _upperBoundG < _g || _upperBoundB < _b || _upperBoundA < _a ||
_lowerBoundR > _r || _lowerBoundG > _g || _lowerBoundB > _b || _lowerBoundA > _a) {
flipHighlightDelta();

_r += _deltaR;
_g += _deltaG;
_b += _deltaB;
_a += _deltaA;
}
if(isHightlighted()) {
float r, g, b, a;
incrementColor(_r, _g, _b, _a, r, g, b, a);
setColor(r, g, b, a);
}
Graphics::Aurora::GUIQuad::render (pass);
}

void HighlightableGUIQuad::setHighlightDelta (float r, float g, float b, float a) {
_deltaR = r;
_deltaG = g;
_deltaB = b;
_deltaA = a;
}

void HighlightableGUIQuad::setHighlightLowerBound (float r, float g, float b, float a) {
_lowerBoundR = r;
_lowerBoundG = g;
_lowerBoundB = b;
_lowerBoundA = a;
}

void HighlightableGUIQuad::setHighlightUpperBound (float r, float g, float b, float a) {
_upperBoundR = r;
_upperBoundG = g;
_upperBoundB = b;
_upperBoundA = a;
}

void HighlightableGUIQuad::flipHighlightDelta() {
_deltaR *= -1;
_deltaG *= -1;
_deltaB *= -1;
_deltaA *= -1;
}

} // End of namespace Aurora

} // End of namespace Graphics
35 changes: 2 additions & 33 deletions src/graphics/aurora/highlightableguiquad.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
#define HIGHLIGHTABLE_GUI_QUAD_H

#include "graphics/aurora/guiquad.h"
#include "graphics/aurora/highlightable.h"

namespace Graphics {

namespace Aurora {

class HighlightableGUIQuad: public GUIQuad {
class HighlightableGUIQuad: public GUIQuad, public Highlightable {

public:
HighlightableGUIQuad(const Common::UString &texture,
Expand All @@ -41,38 +42,6 @@ class HighlightableGUIQuad: public GUIQuad {
~HighlightableGUIQuad();

void render (RenderPass pass);

bool isHightlighted();
void setHighlighted(bool hightlighted);

// This is how much the quad changes per render. Positive number increment the color, negative numbers decrement it.
void setHighlightDelta(float r, float g, float b, float a);

//When any of the quad properties are greater than this bound, the signs of the delta floats will flip
void setHighlightUpperBound(float r, float g, float b, float a);

//When any of the quad properties are less than this bound, the signs of the delta floats will flip
void setHighlightLowerBound(float r, float g, float b, float a);

private:
void flipHighlightDelta();

bool _isHighlighted;

float _deltaR;
float _deltaG;
float _deltaB;
float _deltaA;

float _upperBoundR;
float _upperBoundG;
float _upperBoundB;
float _upperBoundA;

float _lowerBoundR;
float _lowerBoundG;
float _lowerBoundB;
float _lowerBoundA;
};

} // End of namespace Aurora
Expand Down
56 changes: 4 additions & 52 deletions src/graphics/aurora/highlightabletext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,67 +35,19 @@ HighlightableText::HighlightableText (const FontHandle &font, const Common::UStr
HighlightableText::~HighlightableText() {
}

bool HighlightableText::isHightlighted() {
return _isHighlighted;
}

void HighlightableText::setHighlighted (bool hightlighted) {
_isHighlighted = hightlighted;
}

void HighlightableText::render (RenderPass pass) {
// Text objects should always be transparent
if (pass == kRenderPassOpaque)
return;

if(_isHighlighted) {
_r += _deltaR;
_g += _deltaG;
_b += _deltaB;
_a += _deltaA;

if(_upperBoundR < _r || _upperBoundG < _g || _upperBoundB < _b || _upperBoundA < _a ||
_lowerBoundR > _r || _lowerBoundG > _g || _lowerBoundB > _b || _lowerBoundA > _a) {
flipHighlightDelta();

_r += _deltaR;
_g += _deltaG;
_b += _deltaB;
_a += _deltaA;
}
if(isHightlighted()) {
float r, g, b, a;
incrementColor(_r, _g, _b, _a, r, g, b, a);
setColor(r, g, b, a);
}
Graphics::Aurora::Text::render (pass);
}

void HighlightableText::setHighlightDelta (float r, float g, float b, float a) {
_deltaR = r;
_deltaG = g;
_deltaB = b;
_deltaA = a;
}

void HighlightableText::setHighlightLowerBound (float r, float g, float b, float a) {
_lowerBoundR = r;
_lowerBoundG = g;
_lowerBoundB = b;
_lowerBoundA = a;
}

void HighlightableText::setHighlightUpperBound(float r, float g, float b, float a)
{
_upperBoundR = r;
_upperBoundG = g;
_upperBoundB = b;
_upperBoundA = a;
}

void HighlightableText::flipHighlightDelta() {
_deltaR *= -1;
_deltaG *= -1;
_deltaB *= -1;
_deltaA *= -1;
}

} // End of namespace Aurora

} // End of namespace Graphics

0 comments on commit 57a8121

Please sign in to comment.