Button.cpp 971 B

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