put drawButton in its class, and not in main loop

This commit is contained in:
andreja6
2018-04-19 20:30:30 -07:00
parent 09fa95d4a0
commit bb3aac25c5
3 changed files with 27 additions and 21 deletions

View File

@@ -45,4 +45,25 @@ TextButtonInstance::TextButtonInstance(void)
TextButtonInstance::~TextButtonInstance(void) TextButtonInstance::~TextButtonInstance(void)
{ {
}
void TextButtonInstance::drawObj(RenderDevice* rd)
{
Vector3 point1;
Vector3 point2;
if(floatBottom)
{
point1 = Vector3(boxBegin.x, rd->getHeight() + boxBegin.y,0);
point2 = Vector3(boxEnd.x, rd->getHeight() + boxEnd.y,0);
}
else
{
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);
} }

View File

@@ -29,5 +29,6 @@ public:
bool floatRight; bool floatRight;
bool visible; bool visible;
int textSize; int textSize;
void drawObj(G3D::RenderDevice*);
};
};

View File

@@ -519,23 +519,7 @@ void drawButtons(RenderDevice* rd)
if(instance->className == "TextButton" && instance->parent == dataModel) if(instance->className == "TextButton" && instance->parent == dataModel)
{ {
TextButtonInstance* tbi = (TextButtonInstance*)instance; TextButtonInstance* tbi = (TextButtonInstance*)instance;
Vector3 point1; tbi->drawObj(rd);
Vector3 point2;
if(tbi->floatBottom)
{
point1 = Vector3(tbi->boxBegin.x, rd->getHeight() + tbi->boxBegin.y,0);
point2 = Vector3(tbi->boxEnd.x, rd->getHeight() + tbi->boxEnd.y,0);
}
else
{
point1 = Vector3(tbi->boxBegin.x, tbi->boxBegin.y,0);
point2 = Vector3(tbi->boxEnd.x, tbi->boxEnd.y,0);
}
Draw::box(Box(point1, point2), rd, tbi->boxColor, tbi->boxOutlineColor);
Vector2 RelativeTo = Vector2(point1.x + tbi->fontLocationRelativeTo.x, point1.y + tbi->fontLocationRelativeTo.y);
tbi->font->draw2D(rd, tbi->title, RelativeTo, tbi->textSize, tbi->textColor, tbi->textOutlineColor);
} }
} }
} }
@@ -666,9 +650,9 @@ void Demo::onGraphics(RenderDevice* rd) {
glTexCoord2d( 1.0,0.0 ); glTexCoord2d( 1.0,0.0 );
glVertex2f( 70, 0+offset ); glVertex2f( 70, 0+offset );
glTexCoord2d( 1.0,1.0 ); glTexCoord2d( 1.0,1.0 );
glVertex2f( 70, 65+offset ); glVertex2f( 70, 60+offset );
glTexCoord2d( 0.0,1.0 ); glTexCoord2d( 0.0,1.0 );
glVertex2f( 10, 65+offset ); glVertex2f( 10, 60+offset );
glEnd(); glEnd();
glDisable( GL_TEXTURE_2D ); glDisable( GL_TEXTURE_2D );