buttons shows when ever the cursor is in the button

This commit is contained in:
Remco
2016-06-20 12:50:51 +02:00
parent 8dcee70324
commit 1ec3c8f346
3 changed files with 17 additions and 5 deletions
+13 -3
View File
@@ -9,6 +9,8 @@ Button::Button(const std::string & text, Vec2f position, float width, float heig
this->height = height; this->height = height;
this->planePosition = position; this->planePosition = position;
cursorOnButton = false;
alfa = 0.5f;
background = Vec3f(10, 10, 10); background = Vec3f(10, 10, 10);
//foreground = Vec3f(255, 255, 255); //foreground = Vec3f(255, 255, 255);
this->setColor(Vec3f(255, 255, 255)); this->setColor(Vec3f(255, 255, 255));
@@ -24,7 +26,7 @@ Button::~Button()
void Button::draw(void) void Button::draw(void)
{ {
glColor4f(background.x/255.0f, background.y / 255.0f, background.z / 255.0f, 1.0f); glColor4f(background.x/255.0f, background.y / 255.0f, background.z / 255.0f, alfa);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glVertex2f(planePosition.x, planePosition.y); glVertex2f(planePosition.x, planePosition.y);
@@ -39,8 +41,16 @@ void Button::draw(void)
} }
void Button::update(int x, int y) void Button::update(int x, int y)
{ {
//Nothing cursorOnButton =
(x > planePosition.x && x < planePosition.x + width) &&
y > planePosition.y && y < planePosition.y + height;
if (cursorOnButton)
alfa = 1.0f;
else
alfa = 0.5f;
} }
void Button::setForeground(Vec3f color) void Button::setForeground(Vec3f color)
+2
View File
@@ -7,6 +7,8 @@ private:
float width, height; float width, height;
Vec3f background; Vec3f background;
Vec2f planePosition; Vec2f planePosition;
bool cursorOnButton;
float alfa;
public: public:
Button(const std::string &text, Vec2f position, float width, float height); Button(const std::string &text, Vec2f position, float width, float height);
~Button(); ~Button();
+2 -2
View File
@@ -88,9 +88,9 @@ void CrystalPoint::update()
if (!worldhandler->isPlayerPositionValid()) if (!worldhandler->isPlayerPositionValid())
player->position = oldPosition; player->position = oldPosition;
player->position.y = worldhandler->getHeight(player->position.x, player->position.z) + 1.7f; //player->position.y = worldhandler->getHeight(player->position.x, player->position.z) + 1.7f;
worldhandler->update(deltaTime); //worldhandler->update(deltaTime);
cursor->update(cursor->mousePosition + mouseOffset); cursor->update(cursor->mousePosition + mouseOffset);
menu->update(); menu->update();