1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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>
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/>.
28 #include "contextual_cursor.h"
29 #include "interface_v3/interface_manager.h"
35 using namespace NLMISC
;
50 //-----------------------------------------------
51 // CContextualCursor :
53 //-----------------------------------------------
54 CContextualCursor::CContextualCursor()
56 }// CContextualCursor //
59 //-----------------------------------------------
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();
75 //-----------------------------------------------
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
);
92 //-----------------------------------------------
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
)
100 // Replace the old associated texture if needed.
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
));
116 //-----------------------------------------------
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())
129 //-----------------------------------------------
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())
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
)
144 // Change the context name.
145 _Context
= contextName
;
146 // Change the cursor.
147 CInterfaceManager
*IM
= CInterfaceManager::getInstance();
150 CViewPointer
*cursor
= static_cast< CViewPointer
* >( CWidgetManager::getInstance()->getPointer() );
153 if (!functions
.isString
)
155 // Is not a string cursor
156 cursor
->setStringMode(false);
157 cursor
->setCursor(functions
.cursor
);
161 // Is a string cursor
162 cursor
->setStringMode(true);
164 cursor
->setString(CI18N::get(functions
.cursor
));
166 cursor
->setString(cursName
);
173 //-----------------------------------------------
174 void CContextualCursor::release()