Use configured resolution for login/outgame/ingame
[ryzomcore.git] / ryzom / client / src / contextual_cursor.cpp
blob2a4d053d16ec5cf7c79182a59cffaf26b2d36c3d
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 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /////////////
25 // INCLUDE //
26 /////////////
27 #include "stdpch.h"
28 #include "contextual_cursor.h"
29 #include "interface_v3/interface_manager.h"
32 ///////////
33 // USING //
34 ///////////
35 using namespace NLMISC;
37 ////////////
38 // EXTERN //
39 ////////////
42 ////////////
43 // GLOBAL //
44 ////////////
47 ///////////////
48 // FUNCTIONS //
49 ///////////////
50 //-----------------------------------------------
51 // CContextualCursor :
52 // Constructor.
53 //-----------------------------------------------
54 CContextualCursor::CContextualCursor()
56 }// CContextualCursor //
59 //-----------------------------------------------
60 // check :
61 // Check if there is an entity under the cursor.
62 //-----------------------------------------------
63 void CContextualCursor::check()
65 // Call the function associated.
66 TContext::iterator it = _Contexts.find(_Context);
67 if(it != _Contexts.end())
69 TFunctions &functions = (*it).second;
70 if(functions.checkFunc)
71 functions.checkFunc();
73 }// check //
75 //-----------------------------------------------
76 // execute :
77 // Execute the Action according to the cursor state.
78 //-----------------------------------------------
79 void CContextualCursor::execute(bool rightClick, bool dblClick)
81 // Call the function associated.
82 TContext::iterator it = _Contexts.find(_Context);
83 if(it != _Contexts.end())
85 TFunctions &functions = (*it).second;
86 if(functions.execFunc)
87 functions.execFunc(rightClick, dblClick);
89 }// execute //
92 //-----------------------------------------------
93 // add :
94 // Insert a context and associate the function. If the context already exist -> replace the function if 'replace' = true.
95 //-----------------------------------------------
96 void CContextualCursor::add(bool isString, const std::string &contextName, const std::string &texture, float distMax, TFunc checkFunc, TFunc2 execFunc, bool replace)
98 TFunctions functions;
100 // Replace the old associated texture if needed.
101 if(replace)
102 del(contextName);
104 // Set the max distance for the context.
105 functions.distMax = distMax;
106 if(functions.distMax<0.f)
107 functions.distMax = 0.f;
109 functions.checkFunc = checkFunc;
110 functions.execFunc = execFunc;
111 functions.cursor = texture;
112 functions.isString = isString;
113 _Contexts.insert(TContext::value_type(contextName, functions));
114 }// add //
116 //-----------------------------------------------
117 // del :
118 // Remove a context.
119 //-----------------------------------------------
120 void CContextualCursor::del(const std::string &contextName)
122 // Delete the context.
123 TContext::iterator it = _Contexts.find(contextName);
124 if(it != _Contexts.end())
125 _Contexts.erase(it);
126 }// del //
129 //-----------------------------------------------
130 // context :
131 // Select a nex context.
132 //-----------------------------------------------
133 bool CContextualCursor::context(const std::string &contextName, float dist, const std::string &cursName)
135 // Delete the context.
136 TContext::iterator it = _Contexts.find(contextName);
137 if(it == _Contexts.end())
138 return false;
139 // Get a reference on the structure.
140 TFunctions &functions = (*it).second;
141 // Check the distance Max.
142 if(functions.distMax>0.0f && dist>functions.distMax)
143 return false;
144 // Change the context name.
145 _Context = contextName;
146 // Change the cursor.
147 CInterfaceManager *IM = CInterfaceManager::getInstance();
148 if(IM)
150 CViewPointer *cursor = static_cast< CViewPointer* >( CWidgetManager::getInstance()->getPointer() );
151 if(cursor)
153 if (!functions.isString)
155 // Is not a string cursor
156 cursor->setStringMode(false);
157 cursor->setCursor(functions.cursor);
159 else
161 // Is a string cursor
162 cursor->setStringMode(true);
163 if(cursName.empty())
164 cursor->setString(CI18N::get(functions.cursor));
165 else
166 cursor->setString(cursName);
170 return true;
171 }// context //
173 //-----------------------------------------------
174 void CContextualCursor::release()
176 _Contexts.clear ();
177 _Context.clear();