Forráskód Böngészése

buttons shows when ever the cursor is in the button

Remco 9 éve
szülő
commit
1ec3c8f346
3 módosított fájl, 17 hozzáadás és 5 törlés
  1. 13 3
      Button.cpp
  2. 2 0
      Button.h
  3. 2 2
      CrystalPoint.cpp

+ 13 - 3
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)

+ 2 - 0
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();

+ 2 - 2
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();