layer.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 "layer.hpp"
  17. #include "layer_impl.hpp"
  18. Layer::Layer() :
  19. impl()
  20. {
  21. }
  22. Layer::Layer(std::shared_ptr<LayerImpl> i)
  23. : impl(i)
  24. {
  25. }
  26. Layer::~Layer()
  27. {
  28. }
  29. void
  30. Layer::draw(const GraphicContextState& state, CL_GraphicContext* gc)
  31. {
  32. if (impl.get())
  33. {
  34. if (impl->pos.x != 0 || impl->pos.y != 0)
  35. {
  36. gc->push_modelview();
  37. gc->add_translate(impl->pos.x, impl->pos.y);
  38. impl->draw(state, gc);
  39. gc->pop_modelview();
  40. }
  41. else
  42. {
  43. impl->draw(state, gc);
  44. }
  45. }
  46. }
  47. bool
  48. Layer::has_bounding_rect() const
  49. {
  50. if (impl.get())
  51. return impl->has_bounding_rect();
  52. else
  53. return false;
  54. }
  55. CL_Rect
  56. Layer::get_bounding_rect()
  57. {
  58. CL_Rect rect;
  59. if (impl.get())
  60. {
  61. rect = impl->get_bounding_rect();
  62. rect.left += static_cast<int>(impl->pos.x);
  63. rect.top += static_cast<int>(impl->pos.y);
  64. rect.right += static_cast<int>(impl->pos.x);
  65. rect.bottom += static_cast<int>(impl->pos.y);
  66. }
  67. return rect;
  68. }
  69. MetaData
  70. Layer::get_metadata() const
  71. {
  72. if (impl.get())
  73. return impl->data;
  74. else
  75. return MetaData();
  76. }
  77. void
  78. Layer::set_metadata(MetaData data_)
  79. {
  80. if (impl.get())
  81. impl->data = data_;
  82. }
  83. void
  84. Layer::set_pos(const CL_Pointf& pos)
  85. {
  86. impl->pos = pos;
  87. }
  88. CL_Pointf
  89. Layer::get_pos() const
  90. {
  91. return impl->pos;
  92. }
  93. bool
  94. Layer::is_null() const
  95. {
  96. return impl.get() == 0;
  97. }
  98. /* EOF */