Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / client / src / r2 / tool_pick.cpp
blobb6f6064a3c253912bb5704453321dcb0a2d42a68
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdpch.h"
22 #include "tool_pick.h"
23 #include "instance.h"
25 #include "nel/gui/lua_ihm.h"
27 #ifdef DEBUG_NEW
28 #define new DEBUG_NEW
29 #endif
31 using namespace NLMISC;
33 namespace R2
36 // **********************************************
37 CToolPick::CToolPick(const std::string &cursCanPickInstance,
38 const std::string &cursCannotPickInstance,
39 const std::string &cursCanPickPos,
40 const std::string &cursCannotPickPos,
41 bool wantMouseUp
44 _CursCanPickInstance = cursCanPickInstance;
45 _CursCannotPickInstance = cursCannotPickInstance;
46 _CursCanPickPos = cursCanPickPos;
47 _CursCannotPickPos = cursCannotPickPos;
48 _ValidPos = false;
49 _WantMouseUp = wantMouseUp;
52 // **********************************************
53 void CToolPick::setIgnoreInstances(const std::string & ignoreInstances)
55 //H_AUTO(R2_CToolPick_setIgnoreInstances)
56 string allKind = ignoreInstances;
57 while (!allKind.empty())
59 std::string::size_type e = allKind.find(',');
60 string tmp;
61 if (e == std::string::npos || e == 0)
63 tmp = allKind;
64 allKind.clear();
66 else
68 tmp = allKind.substr(0,e);
69 allKind = allKind.substr(e+1,allKind.size());
72 while(!tmp.empty() && tmp[0]==' ')
74 if(tmp.size()==1)
75 tmp.clear();
76 else
77 tmp = tmp.substr(1,tmp.size());
79 while(!tmp.empty() && tmp[tmp.size()]==' ')
81 if(tmp.size()==1)
82 tmp.clear();
83 else
84 tmp = tmp.substr(0,tmp.size()-1);
86 _IgnoreInstances.push_back(tmp);
90 // **********************************************
91 void CToolPick::updateAfterRender()
93 //H_AUTO(R2_CToolPick_updateAfterRender)
94 // See if the mouse is over a valid position
95 _ValidPos = false;
96 sint32 mouseX, mouseY;
97 getMousePos(mouseX, mouseY);
98 if (!isInScreen(mouseX, mouseY))
100 getEditor().setFocusedInstance(NULL);
101 setMouseCursor(_CursCannotPickPos);
102 return;
104 _CandidateInstance = NULL;
105 CInstance *instanceUnder = checkInstanceUnderMouse();
106 bool ignoreInstanceUnder = false;
107 if(instanceUnder && !_IgnoreInstances.empty())
109 for(uint i=0; i<_IgnoreInstances.size(); i++)
111 if(instanceUnder->isKindOf(_IgnoreInstances[i]))
113 ignoreInstanceUnder = true;
114 break;
118 if (!instanceUnder || ignoreInstanceUnder)
120 if (isMouseOnUI() && !isMouseOnContainer())
122 setMouseCursor(DEFAULT_CURSOR);
124 else
126 CTool::CWorldViewRay worldViewRay;
127 computeWorldViewRay(mouseX, mouseY, worldViewRay);
128 CVector inter;
129 _ValidPos = (ValidPacsPos == computeLandscapeRayIntersection(worldViewRay, _Intersection));
130 setMouseCursor(_ValidPos ? _CursCanPickPos : _CursCannotPickPos);
131 getEditor().setFocusedInstance(NULL);
133 return;
135 getEditor().setFocusedInstance(instanceUnder);
136 if (canPick(*instanceUnder))
138 _CandidateInstance = instanceUnder;
139 setMouseCursor(_CursCanPickInstance);
141 else
143 setMouseCursor(_CursCannotPickInstance);
147 // **********************************************
148 bool CToolPick::onMouseRightButtonClicked()
150 //H_AUTO(R2_CToolPick_onMouseRightButtonClicked)
151 TSmartPtr holdThis = this; // for safety, prevent real deletion of this before this method is exited
152 cancelPick();
153 return true;
156 // **********************************************
157 bool CToolPick::validate()
159 //H_AUTO(R2_CToolPick_validate)
160 if (!_CandidateInstance)
162 if (_ValidPos)
164 captureMouse();
165 pick(_Intersection);
166 return true;
168 return false; // ... else, do not handle, this allow to control the camera
170 if (!_WantMouseUp) captureMouse();
171 pick(*_CandidateInstance);
172 return true;
175 // **********************************************
176 bool CToolPick::onMouseLeftButtonDown()
178 //H_AUTO(R2_CToolPick_onMouseLeftButtonDown)
179 if (_WantMouseUp) return false;
180 return validate();
183 // **********************************************
184 bool CToolPick::onMouseLeftButtonClicked()
186 //H_AUTO(R2_CToolPick_onMouseLeftButtonClicked)
187 if (!_WantMouseUp) return false;
188 return validate();
191 // **********************************************
192 int CToolPick::luaPick(CLuaState &ls)
194 //H_AUTO(R2_CToolPick_luaPick)
195 CLuaIHM::checkArgCount(ls, "pick", 0);
196 validate();
197 return 0;
200 // **********************************************
201 int CToolPick::luaCanPick(CLuaState &ls)
203 //H_AUTO(R2_CToolPick_luaCanPick)
204 CLuaIHM::checkArgCount(ls, "canPick", 0);
205 if (_CandidateInstance) ls.push(canPick(*_CandidateInstance));
206 else ls.push(false);
207 return 1;
211 } // R2