Button.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "Button.h"
  2. #include <string>
  3. #include "Util.h"
  4. #include "Vector.h"
  5. Button::Button(const std::string & text, Vec2f position, float width, float height) : Text(text,position)
  6. {
  7. this->width = width;
  8. this->height = height;
  9. this->planePosition = position;
  10. background = Vec3f(10, 10, 10);
  11. //foreground = Vec3f(255, 255, 255);
  12. this->setColor(Vec3f(255, 255, 255));
  13. this->position.x += width / 2 - textWidth / 2;
  14. this->position.y += height / 2 - textHeight / 2;
  15. }
  16. Button::~Button()
  17. {
  18. }
  19. void Button::draw(void)
  20. {
  21. glColor4f(background.x/255.0f, background.y / 255.0f, background.z / 255.0f, 1.0f);
  22. glBegin(GL_QUADS);
  23. glVertex2f(planePosition.x, planePosition.y);
  24. glVertex2f(planePosition.x, planePosition.y + height);
  25. glVertex2f(planePosition.x + width, planePosition.y + height);
  26. glVertex2f(planePosition.x + width, planePosition.y);
  27. glEnd();
  28. /*glColor4f(foreground.x / 255.0f, foreground.y / 255.0f, foreground.z / 255.0f, 1.0f);
  29. Util::glutBitmapString(text, position.x, position.y+height/2+14/2);*/
  30. Text::draw();
  31. }
  32. void Button::update(int x, int y)
  33. {
  34. //Nothing
  35. }
  36. void Button::setForeground(Vec3f color)
  37. {
  38. this->setColor(color);
  39. }
  40. void Button::setBackground(Vec3f color)
  41. {
  42. background = color;
  43. }