objmap_control_point.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #include "objmap_control_point.hpp"
  17. class ObjMapControlPointImpl
  18. {
  19. public:
  20. CL_Sprite sprite;
  21. CL_Pointf pos;
  22. MetaData data;
  23. void draw(CL_GraphicContext* gc);
  24. CL_Rect get_bound_rect() const;
  25. CL_Signal_v1<CL_Pointf> on_set_pos;
  26. };
  27. CL_Signal_v1<CL_Pointf>&
  28. ObjMapControlPoint::sig_set_pos()
  29. {
  30. return impl->on_set_pos;
  31. }
  32. ObjMapControlPoint::ObjMapControlPoint(CL_Sprite sprite_, CL_Pointf pos_, MetaData data_)
  33. : impl(new ObjMapControlPointImpl)
  34. {
  35. impl->sprite = sprite_;
  36. impl->pos = pos_;
  37. impl->data = data_;
  38. }
  39. void
  40. ObjMapControlPoint::draw(CL_GraphicContext* gc)
  41. {
  42. impl->draw(gc);
  43. }
  44. void
  45. ObjMapControlPointImpl::draw(CL_GraphicContext* gc)
  46. {
  47. sprite.draw(static_cast<int>(pos.x), static_cast<int>(pos.y), gc);
  48. }
  49. void
  50. ObjMapControlPoint::set_pos_raw(const CL_Pointf& p)
  51. {
  52. impl->pos = p;
  53. }
  54. void
  55. ObjMapControlPoint::set_pos(const CL_Pointf& p)
  56. {
  57. impl->on_set_pos(p);
  58. }
  59. CL_Pointf
  60. ObjMapControlPoint::get_pos() const
  61. {
  62. return impl->pos;
  63. }
  64. CL_Rect
  65. ObjMapControlPoint::get_bound_rect() const
  66. {
  67. return impl->get_bound_rect();
  68. }
  69. CL_Rect
  70. ObjMapControlPointImpl::get_bound_rect() const
  71. {
  72. CL_Point align = CL_Point(0, 0);
  73. CL_Origin origin_e;
  74. sprite.get_alignment(origin_e, align.x, align.y);
  75. CL_Point origin = calc_origin(origin_e, CL_Size(sprite.get_width(),
  76. sprite.get_height()));
  77. align.x = -align.x;
  78. return CL_Rect(CL_Point(pos) - origin - align,
  79. CL_Size(sprite.get_width(), sprite.get_height()));
  80. }
  81. /* EOF */