toolbox.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 TYPE_CHECKING
  17. from flexlay.gui.icon import Icon
  18. if TYPE_CHECKING:
  19. from flexlay.gui_manager import GUIManager
  20. from supertux.gui import SuperTuxGUI
  21. class SuperTuxToolbox:
  22. """A for selecting tools."""
  23. def __init__(self, gui_manager: 'GUIManager', editor: 'SuperTuxGUI') -> None:
  24. """
  25. :param gui_manager: a flexlay.GuiManager
  26. :param editor: a SuperTuxGui
  27. """
  28. # Create Toolbox
  29. self.toolbox = gui_manager.create_button_panel(False)
  30. self.toolbox.add_separator()
  31. self.object_icon = self.toolbox.add_icon(SuperTuxToolbox.icon_path("move"),
  32. editor.set_objmap_select_tool, hover="Select Tool")
  33. self.paint_icon = self.toolbox.add_icon(SuperTuxToolbox.icon_path("tiles", 24),
  34. editor.set_tilemap_paint_tool, hover="Pencil Tool")
  35. self.fill_icon = self.toolbox.add_icon(SuperTuxToolbox.icon_path("fill", 24),
  36. editor.set_tilemap_fill_tool, hover="Fill Tool")
  37. self.replace_icon = self.toolbox.add_icon(SuperTuxToolbox.icon_path("replace", 24),
  38. editor.set_tilemap_replace_tool, hover="Replace Tool")
  39. self.select_icon = self.toolbox.add_icon(SuperTuxToolbox.icon_path("rect-select"),
  40. editor.set_tilemap_select_tool, hover="Rectangle Select Tool")
  41. self.toolbox.add_separator()
  42. self.zoom_icon = self.toolbox.add_icon(SuperTuxToolbox.icon_path("zoom"),
  43. editor.set_zoom_tool, hover="Zoom Tool")
  44. self.icons = [self.paint_icon, self.fill_icon, self.replace_icon,
  45. self.select_icon, self.object_icon, self.zoom_icon]
  46. def set_down(self, rhs: Icon) -> None:
  47. for icon in self.icons:
  48. if icon == rhs:
  49. icon.set_down()
  50. else:
  51. icon.set_up()
  52. @staticmethod
  53. def icon_path(tool_name: str, size: int = 22) -> str:
  54. return "data/images/tools/stock-tool-%s-%s.png" % (tool_name, size)
  55. # EOF #