Shape.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // This may look like C code, but it's really -*- C++ -*-
  2. /*
  3. * Copyright (C) 2010 Emweb bvba, Heverlee, Belgium.
  4. *
  5. * See the LICENSE file for terms of use.
  6. */
  7. #ifndef SHAPE_H_
  8. #define SHAPE_H_
  9. #include <Wt/WPainter>
  10. #include <Wt/WColor>
  11. #include <Wt/WString>
  12. class ShapeColor : public Wt::WColor
  13. {
  14. public:
  15. ShapeColor(const Wt::WColor& color, const Wt::WString& colorName)
  16. : WColor(color),
  17. colorName_(colorName)
  18. { }
  19. Wt::WString colorName() {
  20. return colorName_;
  21. }
  22. private:
  23. Wt::WString colorName_;
  24. };
  25. class Shape
  26. {
  27. public:
  28. Shape(const Wt::WPointF& center, const ShapeColor& color, const double size)
  29. : center_(center),
  30. color_(color),
  31. size_(size)
  32. {}
  33. virtual ~Shape();
  34. virtual bool contains(const Wt::WPointF& point) const =0;
  35. virtual Wt::WString shapeName() const =0;
  36. virtual void paint(Wt::WPainter& painter) const =0;
  37. ShapeColor color() const {
  38. return color_;
  39. }
  40. double size() const {
  41. return size_;
  42. }
  43. protected:
  44. Wt::WPointF center() const {
  45. return center_;
  46. }
  47. private:
  48. Wt::WPointF center_;
  49. ShapeColor color_;
  50. double size_;
  51. };
  52. class Circle : public Shape
  53. {
  54. public:
  55. Circle(const Wt::WPointF& center,
  56. const ShapeColor& color,
  57. const double size);
  58. virtual bool contains(const Wt::WPointF& point) const;
  59. virtual Wt::WString shapeName() const;
  60. virtual void paint(Wt::WPainter& painter) const;
  61. private:
  62. double distanceTo(const double x1, const double y1,
  63. const double x2, const double y2) const;
  64. };
  65. class Rectangle : public Shape
  66. {
  67. public:
  68. Rectangle(const Wt::WPointF& center,
  69. const ShapeColor& color,
  70. const double size);
  71. virtual bool contains(const Wt::WPointF& point) const;
  72. virtual Wt::WString shapeName() const;
  73. virtual void paint(Wt::WPainter& painter) const;
  74. };
  75. #endif // SHAPE_H_