agg_ctrl.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //----------------------------------------------------------------------------
  2. // Anti-Grain Geometry - Version 2.4
  3. // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
  4. //
  5. // Permission to copy, use, modify, sell and distribute this software
  6. // is granted provided this copyright notice appears in all copies.
  7. // This software is provided "as is" without express or implied
  8. // warranty, and with no claim as to its suitability for any purpose.
  9. //
  10. //----------------------------------------------------------------------------
  11. // Contact: mcseem@antigrain.com
  12. // mcseemagg@yahoo.com
  13. // http://www.antigrain.com
  14. //----------------------------------------------------------------------------
  15. //
  16. // Function render_ctrl
  17. //
  18. //----------------------------------------------------------------------------
  19. #ifndef AGG_CTRL_INCLUDED
  20. #define AGG_CTRL_INCLUDED
  21. #include "agg_trans_affine.h"
  22. #include "agg_renderer_scanline.h"
  23. namespace agg
  24. {
  25. //--------------------------------------------------------------------ctrl
  26. class ctrl
  27. {
  28. public:
  29. //--------------------------------------------------------------------
  30. virtual ~ctrl() {}
  31. ctrl(double x1, double y1, double x2, double y2, bool flip_y) :
  32. m_x1(x1), m_y1(y1), m_x2(x2), m_y2(y2),
  33. m_flip_y(flip_y),
  34. m_mtx(0)
  35. {
  36. }
  37. //--------------------------------------------------------------------
  38. virtual bool in_rect(double x, double y) const = 0;
  39. virtual bool on_mouse_button_down(double x, double y) = 0;
  40. virtual bool on_mouse_button_up(double x, double y) = 0;
  41. virtual bool on_mouse_move(double x, double y, bool button_flag) = 0;
  42. virtual bool on_arrow_keys(bool left, bool right, bool down, bool up) = 0;
  43. //--------------------------------------------------------------------
  44. void transform(const trans_affine& mtx) { m_mtx = &mtx; }
  45. void no_transform() { m_mtx = 0; }
  46. //--------------------------------------------------------------------
  47. void transform_xy(double* x, double* y) const
  48. {
  49. if(m_flip_y) *y = m_y1 + m_y2 - *y;
  50. if(m_mtx) m_mtx->transform(x, y);
  51. }
  52. //--------------------------------------------------------------------
  53. void inverse_transform_xy(double* x, double* y) const
  54. {
  55. if(m_mtx) m_mtx->inverse_transform(x, y);
  56. if(m_flip_y) *y = m_y1 + m_y2 - *y;
  57. }
  58. //--------------------------------------------------------------------
  59. double scale() const { return m_mtx ? m_mtx->scale() : 1.0; }
  60. private:
  61. ctrl(const ctrl&);
  62. const ctrl& operator = (const ctrl&);
  63. protected:
  64. double m_x1;
  65. double m_y1;
  66. double m_x2;
  67. double m_y2;
  68. private:
  69. bool m_flip_y;
  70. const trans_affine* m_mtx;
  71. };
  72. //--------------------------------------------------------------------
  73. template<class Rasterizer, class Scanline, class Renderer, class Ctrl>
  74. void render_ctrl(Rasterizer& ras, Scanline& sl, Renderer& r, Ctrl& c)
  75. {
  76. unsigned i;
  77. for(i = 0; i < c.num_paths(); i++)
  78. {
  79. ras.reset();
  80. ras.add_path(c, i);
  81. render_scanlines_aa_solid(ras, sl, r, c.color(i));
  82. }
  83. }
  84. //--------------------------------------------------------------------
  85. template<class Rasterizer, class Scanline, class Renderer, class Ctrl>
  86. void render_ctrl_rs(Rasterizer& ras, Scanline& sl, Renderer& r, Ctrl& c)
  87. {
  88. unsigned i;
  89. for(i = 0; i < c.num_paths(); i++)
  90. {
  91. ras.reset();
  92. ras.add_path(c, i);
  93. r.color(c.color(i));
  94. render_scanlines(ras, sl, r);
  95. }
  96. }
  97. }
  98. #endif