1 /*
2  * Copyright (C) 2012-2020 by the Widelands Development Team
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (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, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  *
18  */
19 
20 #ifndef WL_EDITOR_TOOLS_TOOL_ACTION_H
21 #define WL_EDITOR_TOOLS_TOOL_ACTION_H
22 
23 #include "editor/tools/action_args.h"
24 #include "logic/widelands_geometry.h"
25 
26 class EditorTool;
27 
28 /// Class to save an action done by an editor tool
29 // implementations in editor_history.cc
30 struct EditorToolAction {
31 	EditorTool& tool;
32 
33 	uint32_t i;
34 	Widelands::Map& map;
35 	Widelands::NodeAndTriangle<> center;
36 	EditorInteractive& parent;
37 
38 	EditorActionArgs* args;
39 
EditorToolActionEditorToolAction40 	EditorToolAction(EditorTool& t,
41 	                 uint32_t ind,
42 	                 Widelands::Map& m,
43 	                 Widelands::NodeAndTriangle<> c,
44 	                 EditorInteractive& p,
45 	                 const EditorActionArgs& nargs)
46 	   : tool(t), i(ind), map(m), center(c), parent(p) {
47 		args = new EditorActionArgs(parent);
48 		*args = nargs;
49 		args->refcount++;
50 	}
51 
~EditorToolActionEditorToolAction52 	~EditorToolAction() {
53 		if (args->refcount <= 1)
54 			delete args;
55 		else
56 			args->refcount--;
57 	}
58 
EditorToolActionEditorToolAction59 	EditorToolAction(const EditorToolAction& b)
60 	   : tool(b.tool), i(b.i), map(b.map), center(b.center), parent(b.parent), args(b.args) {
61 		args->refcount++;
62 	}
63 };
64 
65 #endif  // end of include guard: WL_EDITOR_TOOLS_TOOL_ACTION_H
66