Debian Codegraph @

source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PikeElevation.cpp

raw
1 /* Copyright (C) 2025 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. 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 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. 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 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "precompiled.h"
19
20 #include "tools/atlas/AtlasUI/General/AtlasWindowCommandProc.h"
21 #include "tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h"
22 #include "tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Brushes.h"
23 #include "tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h"
24 #include "tools/atlas/GameInterface/MessagePasser.h"
25 #include "tools/atlas/GameInterface/Messages.h"
26 #include "tools/atlas/GameInterface/SharedTypes.h"
27
28 #include <wx/defs.h>
29 #include <wx/event.h>
30 #include <wx/gdicmn.h>
31 #include <wx/object.h>
32
33 using AtlasMessage::Position;
34
35 class PikeElevation : public StateDrivenTool<PikeElevation>
36 {
37 DECLARE_DYNAMIC_CLASS(PikeElevation);
38
39 int m_Direction; // +1 = raise, -1 = lower
40 Position m_Pos;
41
42 public:
43 PikeElevation()
44 {
45 SetState(&Waiting);
46 }
47
48
49 void OnEnable()
50 {
51 g_Brush_Elevation.MakeActive();
52 }
53
54 void OnDisable()
55 {
56 POST_MESSAGE(BrushPreview, (false, Position()));
57 }
58
59
60 struct sWaiting : public State
61 {
62 bool OnMouse(PikeElevation* obj, wxMouseEvent& evt)
63 {
64 if (evt.LeftDown())
65 {
66 obj->m_Pos = Position(evt.GetPosition());
67 SET_STATE(PikeRaising);
68 return true;
69 }
70 else if (evt.RightDown())
71 {
72 obj->m_Pos = Position(evt.GetPosition());
73 SET_STATE(PikeLowering);
74 return true;
75 }
76 else if (evt.Moving())
77 {
78 POST_MESSAGE(BrushPreview, (true, Position(evt.GetPosition())));
79 return true;
80 }
81 else
82 {
83 return false;
84 }
85 }
86 }
87 Waiting;
88
89
90 struct sPiking : public State
91 {
92 void OnEnter(PikeElevation* obj)
93 {
94 POST_MESSAGE(BrushPreview, (true, obj->m_Pos));
95 }
96
97 void OnLeave(PikeElevation*)
98 {
99 ScenarioEditor::GetCommandProc().FinaliseLastCommand();
100 }
101
102 bool OnMouse(PikeElevation* obj, wxMouseEvent& evt)
103 {
104 if (IsMouseUp(evt))
105 {
106 SET_STATE(Waiting);
107 return true;
108 }
109 else if (evt.Dragging())
110 {
111 wxPoint pos = evt.GetPosition();
112 obj->m_Pos = Position(pos);
113 POST_MESSAGE(BrushPreview, (true, obj->m_Pos));
114 return true;
115 }
116 else
117 {
118 return false;
119 }
120 }
121
122 void OnTick(PikeElevation* obj, float dt)
123 {
124 POST_COMMAND(PikeElevation, (obj->m_Pos, dt*g_Brush_Elevation.STRENGTH_MULTIPLIER*GetDirection()*g_Brush_Elevation.GetStrength()));
125 obj->m_Pos = Position::Unchanged();
126 }
127
128 virtual bool IsMouseUp(wxMouseEvent& evt) = 0;
129 virtual int GetDirection() = 0;
130 };
131
132 struct sPikeRaising : public sPiking
133 {
134 bool IsMouseUp(wxMouseEvent& evt) { return evt.LeftUp(); }
135 int GetDirection() { return +1; }
136 }
137 PikeRaising;
138
139 struct sPikeLowering : public sPiking
140 {
141 bool IsMouseUp(wxMouseEvent& evt) { return evt.RightUp(); }
142 int GetDirection() { return -1; }
143 }
144 PikeLowering;
145 };
146
147 IMPLEMENT_DYNAMIC_CLASS(PikeElevation, StateDrivenTool<PikeElevation>);