stroke.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Flexlay - A Generic 2D Game Editor
  2. // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #ifndef HEADER_FLEXLAY_STROKE_HPP
  17. #define HEADER_FLEXLAY_STROKE_HPP
  18. #include <vector>
  19. #include <ClanLib/Core/Math/rect.h>
  20. #include <ClanLib/Core/System/system.h>
  21. #include <memory>
  22. class StrokeImpl;
  23. class StrokeDrawer;
  24. class CL_GraphicContext;
  25. /** A dab is basically an event send from the mouse to the drawing
  26. canvas, it consists of time, position, tilt, pressure and possible
  27. additional information that is needed */
  28. class Dab
  29. {
  30. public:
  31. /** Time at which the dot was placed */
  32. unsigned int time;
  33. /** Position at which the dot is placed */
  34. CL_Pointf pos;
  35. /** The pressure with which the dot was drawn (can be interpreted as
  36. size, opacity or similar things by the StrokeDrawer */
  37. float pressure;
  38. /** Tilting of the pen while painting the dot */
  39. CL_Pointf tilt;
  40. Dab()
  41. : time(CL_System::get_time()), pos(0, 0), pressure(1.0f), tilt(0, 0)
  42. {}
  43. Dab(float x, float y)
  44. : time(CL_System::get_time()), pos(x, y), pressure(1.0f), tilt(0.0f, 0.0f)
  45. {}
  46. Dab(float x_, float y_, float pressure_)
  47. : time(CL_System::get_time()), pos(x_, y_), pressure(pressure_), tilt(0.0f, 0.0f)
  48. {}
  49. };
  50. /** A Stroke is a series of Dabs */
  51. class Stroke
  52. {
  53. public:
  54. typedef std::vector<Dab> Dabs;
  55. Stroke();
  56. /** Return true if the Stroke doesn't contain any dabs */
  57. bool empty() const;
  58. void draw(CL_GraphicContext* gc) const;
  59. void set_drawer(const StrokeDrawer& drawer_);
  60. StrokeDrawer get_drawer();
  61. void add_dab(const Dab& dab);
  62. /** Returns the real dabs as recieved by the InputDevice */
  63. Dabs get_dabs() const;
  64. /** Returns interpolated dabs, meaning the holes in get_dabs() are
  65. closed with interpolated dabs so that all dabs are equally
  66. spread (ie. every dab is 'spacing' away from the next) */
  67. Dabs get_interpolated_dabs(float x_spacing, float y_spacing) const;
  68. int get_dab_count() const;
  69. CL_Rectf get_bounding_rect() const;
  70. private:
  71. std::shared_ptr<StrokeImpl> impl;
  72. };
  73. #endif
  74. /* EOF */