MapTool.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. FinalSun/FinalAlert 2 Mission Editor
  3. Copyright (C) 1999-2024 Electronic Arts, Inc.
  4. Authored by Matthias Wagner
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include <cstdint>
  18. #include "structs.h"
  19. #include <winnt.h>
  20. class CMapData;
  21. class CIsoView;
  22. enum class MapToolMouseFlags
  23. {
  24. DEFAULT = 0,
  25. LBUTTON = 1,
  26. MBUTTON = 2,
  27. RBUTTON = 4,
  28. SHIFT = 8
  29. };
  30. DEFINE_ENUM_FLAG_OPERATORS(MapToolMouseFlags);
  31. inline MapToolMouseFlags MapToolMouseFlagsFromWin32(UINT nFlags) {
  32. MapToolMouseFlags flags = MapToolMouseFlags::DEFAULT;
  33. if ((nFlags & MK_LBUTTON) == MK_LBUTTON)
  34. flags |= MapToolMouseFlags::LBUTTON;
  35. if ((nFlags & MK_MBUTTON) == MK_MBUTTON)
  36. flags |= MapToolMouseFlags::MBUTTON;
  37. if ((nFlags & MK_RBUTTON) == MK_RBUTTON)
  38. flags |= MapToolMouseFlags::RBUTTON;
  39. if ((nFlags & MK_SHIFT) == MK_SHIFT)
  40. flags |= MapToolMouseFlags::SHIFT;
  41. return flags;
  42. }
  43. class MapTool
  44. {
  45. public:
  46. virtual ~MapTool() = default;
  47. // return false if tool has not handled this call (or doesn't want to override any caller behavior)
  48. virtual bool onRButtonUp(const ProjectedCoords& projCoords, const MapCoords& mapCoords3d, MapToolMouseFlags flags)
  49. {
  50. return false;
  51. };
  52. virtual void onLButtonDblClick(const ProjectedCoords& projCoords, const MapCoords& mapCoords3d, MapToolMouseFlags flags) {};
  53. virtual void onLButtonUp(const ProjectedCoords& projCoords, const MapCoords& mapCoords3d, MapToolMouseFlags flags) {};
  54. virtual void onMouseMove(const ProjectedCoords& projCoords, const MapCoords& mapCoords3d, MapToolMouseFlags flags) {};
  55. virtual void render() {};
  56. protected:
  57. MapTool(CMapData& map, CIsoView& view) : m_map(map), m_view(view) {};
  58. MapTool& operator=(const MapTool& other) = delete;
  59. CMapData& getMap() { return m_map; }
  60. const CMapData& getMap() const { return m_map; }
  61. CIsoView& getView() { return m_view; }
  62. const CIsoView& getView() const { return m_view; }
  63. private:
  64. CMapData& m_map;
  65. CIsoView& m_view;
  66. };