objmap_control_point.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Flexlay - A Generic 2D Game Editor
  2. # Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
  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. from typing import Any, Optional
  17. from flexlay.graphic_context import GraphicContext
  18. from flexlay.math import Pointf, Rectf, Origin, Sizef
  19. from flexlay.sprite import Sprite
  20. from flexlay.util.signal import Signal
  21. class ObjMapControlPoint:
  22. def __init__(self, sprite: Sprite, pos: Pointf, metadata: Optional[Any] = None) -> None:
  23. self.sprite = sprite
  24. self.pos = pos
  25. self.metadata = metadata
  26. self.sig_set_pos = Signal()
  27. def draw(self, gc: GraphicContext) -> None:
  28. self.sprite.draw(int(self.pos.x), int(self.pos.y), gc)
  29. def set_pos_raw(self, p: Pointf) -> None:
  30. self.pos = p
  31. def set_pos(self, p: Pointf) -> None:
  32. self.sig_set_pos(p)
  33. def get_pos(self) -> Pointf:
  34. return self.pos
  35. def get_bound_rect(self) -> Rectf:
  36. origin_enum, align_x, align_y = self.sprite.get_alignment()
  37. align_x = -align_x
  38. origin = Origin.calc_originf(origin_enum,
  39. Sizef(self.sprite.width,
  40. self.sprite.height))
  41. return Rectf.from_ps(self.pos.copy() - origin - Pointf(align_x, align_y),
  42. Sizef(self.sprite.width, self.sprite.height))
  43. # EOF #