From 1ec3c8f346e5f498cc092bb200260b817194a460 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 20 Jun 2016 12:50:51 +0200 Subject: [PATCH] buttons shows when ever the cursor is in the button --- Button.cpp | 16 +++++++++++++--- Button.h | 2 ++ CrystalPoint.cpp | 4 ++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Button.cpp b/Button.cpp index 7154605..004820c 100644 --- a/Button.cpp +++ b/Button.cpp @@ -9,6 +9,8 @@ Button::Button(const std::string & text, Vec2f position, float width, float heig this->height = height; this->planePosition = position; + cursorOnButton = false; + alfa = 0.5f; background = Vec3f(10, 10, 10); //foreground = Vec3f(255, 255, 255); this->setColor(Vec3f(255, 255, 255)); @@ -24,7 +26,7 @@ Button::~Button() 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); glVertex2f(planePosition.x, planePosition.y); @@ -39,8 +41,16 @@ void Button::draw(void) } 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) diff --git a/Button.h b/Button.h index 8da9023..ebb6a93 100644 --- a/Button.h +++ b/Button.h @@ -7,6 +7,8 @@ private: float width, height; Vec3f background; Vec2f planePosition; + bool cursorOnButton; + float alfa; public: Button(const std::string &text, Vec2f position, float width, float height); ~Button(); diff --git a/CrystalPoint.cpp b/CrystalPoint.cpp index bac936d..7c115f8 100644 --- a/CrystalPoint.cpp +++ b/CrystalPoint.cpp @@ -88,9 +88,9 @@ void CrystalPoint::update() if (!worldhandler->isPlayerPositionValid()) 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); menu->update();