Merge branch '138-toggle-free-look-with-hotkey' into main/gingo-test
[ryzomcore.git] / ryzom / client / src / r2 / tool_pick.h
blob44cf7ce9243b38b638db921e81c56f9a964e0a1e
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // 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 Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef R2_TOOL_PICK
18 #define R2_TOOL_PICK
20 #include "tool.h"
21 #include "editor.h"
23 #include "nel/misc/smart_ptr.h"
25 namespace R2
28 /** Tool to select an instance in scene / in the component feature list / in the world map
29 * The tool can possibly select a position in scene if there's not entity
30 * under the mouse.
32 class CToolPick : public CTool
34 public:
35 // build a new pick tool with the given CPicker interface (should not be NULL or assert)
36 CToolPick(
37 const std::string &cursCanPickInstance = "r2ed_tool_can_pick.tga",
38 const std::string &cursCannotPickInstance = "curs_stop.tga",
39 const std::string &cursCanPickPos = "r2ed_tool_pick.tga",
40 const std::string &cursCannotPickPos = "r2ed_tool_pick.tga",
41 bool wantMouseUp = false
44 // from CTool
45 virtual const char *getToolUIName() const { return ""; } // by default, no associated icon in the ui
46 virtual bool isCreationTool() const { return false; }
47 virtual bool isPickTool() const { return true; }
48 virtual void updateAfterRender();
49 virtual bool onMouseRightButtonClicked();
50 virtual bool onMouseLeftButtonDown();
51 virtual bool onMouseLeftButtonClicked();
52 virtual void cancel() {}
54 void setIgnoreInstances(const std::string & ignoreInstances);
56 //////////////////
57 // FOR DERIVERS //
58 //////////////////
60 // Called by the picker tool when an instance has been selected
61 virtual void pick(CInstance &instance) = 0;
62 // Called by the picker tool when a position has been selecte
63 virtual void pick(const NLMISC::CVector &pos) = 0;
64 /** Called when the picking action has been canceled.
65 * Default behaviour is to restore the default tool
67 virtual void cancelPick() { getEditor().setCurrentTool(NULL); }
68 // Test to see if an instance is 'pickable' (default is yes)
69 virtual bool canPick(const CInstance &/* instance */) const { return true; }
71 // lua exports
72 /** Export the pick method to lua.
73 * We need to expose this to lua, because there's no way
74 * to route user events of the ui to the current editor tool.
75 * So to maintain UI abstraction we use 2 steps :
76 * CTool::checkInstanceUnderMouse() is called -> if no collision is found in scene or in world map, a call
77 * is made into lua to retrieve ui instance over which the mouse is. Then the mouse cursor is updated ifthat instance is 'pickable'
78 * On a mouse button click, lua check that the current tool is a picking tool. If so, then
79 * lua code call the 'pick' method exported below to do the selection.
81 int luaPick(CLuaState &ls);
82 int luaCanPick(CLuaState &ls);
84 REFLECT_EXPORT_START(R2::CToolPick, R2::CTool)
85 REFLECT_LUA_METHOD("pick", luaPick);
86 REFLECT_LUA_METHOD("canPick", luaCanPick); // return true if the curent instance under the mouse can be selected
87 REFLECT_EXPORT_END
89 private:
90 std::string _CursCanPickPos;
91 std::string _CursCannotPickPos;
92 std::string _CursCanPickInstance;
93 std::string _CursCannotPickInstance;
94 CInstance::TRefPtr _CandidateInstance;
95 NLMISC::CVector _Intersection;
96 bool _ValidPos;
97 bool _WantMouseUp;
98 std::vector<std::string> _IgnoreInstances;
99 private:
100 bool validate();
106 } // R2
110 #endif