Made BaseButton class

Buttons now children of BaseButton
Buttons now render over and down modes
Text buttons now exist
Buttons render differently
This commit is contained in:
andreja6
2018-04-23 22:02:12 -07:00
parent 98d3358fd5
commit 55e890bdc1
8 changed files with 171 additions and 53 deletions

View File

@@ -18,9 +18,7 @@ bool centeredWithinBox;
std::string title;
G3D::GFontRef* font;
int textSize;
bool floatBottom;
bool floatRight;
bool floatCenter;
bool visible;
ButtonListener* buttonListener;
@@ -35,6 +33,7 @@ TextButtonInstance::TextButtonInstance(void)
textOutlineColor = Color4(0, 0, 0, 0);
boxColor = Color4(0.6F,0.6F,0.6F,0.4F);
boxOutlineColor = Color4(0, 0, 0, 0);
setAllColorsSame();
textSize = 12;
floatBottom = false;
floatRight = false;
@@ -43,6 +42,18 @@ TextButtonInstance::TextButtonInstance(void)
className = "TextButton";
}
void TextButtonInstance::setAllColorsSame()
{
textColorOvr = textColor;
textOutlineColorOvr = textOutlineColor;
boxColorOvr = boxColor;
boxOutlineColorOvr = boxOutlineColor;
textColorDn = textColor;
textOutlineColorDn = textOutlineColor;
boxColorDn = boxColor;
boxOutlineColorDn = boxOutlineColor;
}
TextButtonInstance::~TextButtonInstance(void)
{
delete buttonListener;
@@ -61,7 +72,7 @@ void TextButtonInstance::onClick()
}
}
void TextButtonInstance::drawObj(RenderDevice* rd)
void TextButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseDown)
{
Vector3 point1;
Vector3 point2;
@@ -76,8 +87,24 @@ void TextButtonInstance::drawObj(RenderDevice* rd)
point1 = Vector3(boxBegin.x, boxBegin.y,0);
point2 = Vector3(boxEnd.x, boxEnd.y,0);
}
Draw::box(Box(point1, point2), rd, boxColor, boxOutlineColor);
Vector2 RelativeTo = Vector2(point1.x + fontLocationRelativeTo.x, point1.y + fontLocationRelativeTo.y);
font->draw2D(rd, title, RelativeTo, textSize, textColor, textOutlineColor);
if(mouseInArea(point1.x, point1.y, point2.x, point2.y, mousePos.x, mousePos.y) && mouseDown)
{
Draw::box(Box(point1, point2), rd, boxColorDn, boxOutlineColorDn);
font->draw2D(rd, title, RelativeTo, textSize, textColorDn, textOutlineColorDn);
}
else if(mouseInArea(point1.x, point1.y, point2.x, point2.y, mousePos.x, mousePos.y))
{
Draw::box(Box(point1, point2), rd, boxColorOvr, boxOutlineColorOvr);
font->draw2D(rd, title, RelativeTo, textSize, textColorOvr, textOutlineColorOvr);
}
else
{
Draw::box(Box(point1, point2), rd, boxColor, boxOutlineColor);
font->draw2D(rd, title, RelativeTo, textSize, textColor, textOutlineColor);
}
}
void doNullCheck()
{
}