Button.cpp 1018 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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) : 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/255.0f, background.y / 255.0f, background.z / 255.0f, 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 / 255.0f, foreground.y / 255.0f, foreground.z / 255.0f, 1.0f);
  26. Util::glutBitmapString(text, position.x, position.y+height/2+18/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. }