Button.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef GUI3DS_BUTTON_HPP
  2. #define GUI3DS_BUTTON_HPP
  3. #include <functional>
  4. #include <cpp3ds/Graphics/Text.hpp>
  5. #include <cpp3ds/Graphics/RectangleShape.hpp>
  6. #include <cpp3ds/Window/Event.hpp>
  7. #include "NinePatch.hpp"
  8. #include "../TweenObjects.hpp"
  9. namespace gui3ds {
  10. class Button : public util3ds::TweenNinePatch {
  11. public:
  12. static const int COLOR_RGB = 11;
  13. static const int COLOR_ALPHA = 12;
  14. static const int CONTENT_X = 13;
  15. static const int TEXTCOLOR_ALPHA = 14;
  16. Button();
  17. bool processEvent(const cpp3ds::Event& event);
  18. void setTextOffset(const cpp3ds::Vector2f& offset);
  19. const cpp3ds::Vector2f& getTextOffset() const;
  20. void autoSize();
  21. void setContentSize(const cpp3ds::Vector2f& size);
  22. void setContentSize(float width, float height);
  23. const cpp3ds::Vector2f& getContentSize() const;
  24. const cpp3ds::Vector2f& getSize() const;
  25. void setString(const cpp3ds::String& string);
  26. const cpp3ds::String& getString() const;
  27. cpp3ds::Text& getText() const;
  28. void setTextColor(const cpp3ds::Color& color);
  29. const cpp3ds::Color& getTextColor() const;
  30. void setTextActiveColor(const cpp3ds::Color& color);
  31. const cpp3ds::Color& getTextActiveColor() const;
  32. void setColor(const cpp3ds::Color& color);
  33. const cpp3ds::Color& getColor() const;
  34. void setActiveColor(const cpp3ds::Color& color);
  35. const cpp3ds::Color& getActiveColor() const;
  36. void onClick(const std::function<void()>& callback);
  37. protected:
  38. virtual int getValues(int tweenType, float *returnValues);
  39. virtual void setValues(int tweenType, float *newValues);
  40. virtual void draw(cpp3ds::RenderTarget& target, cpp3ds::RenderStates states) const;
  41. void ensureUpdate() const;
  42. private:
  43. mutable cpp3ds::Vector2f m_size;
  44. mutable cpp3ds::FloatRect m_rect;
  45. mutable cpp3ds::Text m_text;
  46. cpp3ds::Vector2f m_textOffset;
  47. cpp3ds::Color m_textColor;
  48. cpp3ds::Color m_textActiveColor;
  49. cpp3ds::Color m_backgroundColor;
  50. cpp3ds::Color m_backgroundActiveColor;
  51. std::function<void()> m_clickFunction;
  52. mutable bool m_needsUpdate;
  53. bool m_autoSize;
  54. bool m_active;
  55. };
  56. } // namespace gui3ds
  57. #endif // GUI3DS_BUTTON_HPP