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>
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/>.
22 #include "nel/gui/group_modal.h"
23 #include "nel/gui/interface_element.h"
24 #include "nel/misc/xml_auto_ptr.h"
25 #include "nel/gui/view_renderer.h"
26 #include "nel/misc/i_xml.h"
37 NLMISC_REGISTER_OBJECT(CViewBase
, CGroupModal
, std::string
, "modal");
39 // ***************************************************************************
40 CGroupModal::CGroupModal(const TCtorParam
¶m
)
43 SpawnOnMousePos
= true;
47 ExitKeyPushed
= false;
48 ForceInsideScreen
= false;
49 SpawnMouseX
= SpawnMouseY
= 0;
50 _MouseDeltaX
= _MouseDeltaY
= 0;
51 //By default, modal are escapable
56 std::string
CGroupModal::getProperty( const std::string
&name
) const
58 if( name
== "mouse_pos" )
60 return NLMISC::toString( SpawnOnMousePos
);
63 if( name
== "exit_click_out" )
65 return NLMISC::toString( ExitClickOut
);
68 if( name
== "exit_click_l" )
70 return NLMISC::toString( ExitClickL
);
73 if( name
== "exit_click_r" )
75 return NLMISC::toString( ExitClickR
);
78 if( name
== "exit_click_b" )
80 if( ExitClickL
== ExitClickR
)
81 return NLMISC::toString( ExitClickL
);
86 if( name
== "force_inside_screen" )
88 return NLMISC::toString( ForceInsideScreen
);
91 if( name
== "category" )
96 if( name
== "onclick_out" )
101 if( name
== "onclick_out_params" )
103 return OnClickOutParams
;
106 if( name
== "onpostclick_out" )
108 return OnPostClickOut
;
111 if( name
== "onpostclick_out_params" )
113 return OnPostClickOutParams
;
116 if( name
== "exit_key_pushed" )
118 return NLMISC::toString( ExitKeyPushed
);
121 return CGroupFrame::getProperty( name
);
124 void CGroupModal::setProperty( const std::string
&name
, const std::string
&value
)
126 if( name
== "mouse_pos" )
129 if( NLMISC::fromString( value
, b
) )
134 if( name
== "exit_click_out" )
137 if( NLMISC::fromString( value
, b
) )
142 if( name
== "exit_click_l" )
145 if( NLMISC::fromString( value
, b
) )
150 if( name
== "exit_click_r" )
153 if( NLMISC::fromString( value
, b
) )
158 if( name
== "exit_click_b" )
161 if( NLMISC::fromString( value
, b
) )
163 ExitClickL
= ExitClickR
= b
;
168 if( name
== "force_inside_screen" )
171 if( NLMISC::fromString( value
, b
) )
172 ForceInsideScreen
= b
;
176 if( name
== "category" )
182 if( name
== "onclick_out" )
188 if( name
== "onclick_out_params" )
190 OnClickOutParams
= value
;
194 if( name
== "onpostclick_out" )
196 OnPostClickOut
= value
;
200 if( name
== "onpostclick_out_params" )
202 OnPostClickOutParams
= value
;
206 if( name
== "exit_key_pushed" )
209 if( NLMISC::fromString( value
, b
) )
214 CGroupFrame::setProperty( name
, value
);
219 xmlNodePtr
CGroupModal::serialize( xmlNodePtr parentNode
, const char *type
) const
221 xmlNodePtr node
= CGroupFrame::serialize( parentNode
, type
);
225 xmlSetProp( node
, BAD_CAST
"type", BAD_CAST
"modal" );
226 xmlSetProp( node
, BAD_CAST
"mouse_pos", BAD_CAST
NLMISC::toString( SpawnOnMousePos
).c_str() );
227 xmlSetProp( node
, BAD_CAST
"exit_click_out", BAD_CAST
NLMISC::toString( ExitClickOut
).c_str() );
228 xmlSetProp( node
, BAD_CAST
"exit_click_l", BAD_CAST
NLMISC::toString( ExitClickL
).c_str() );
229 xmlSetProp( node
, BAD_CAST
"exit_click_r", BAD_CAST
NLMISC::toString( ExitClickR
).c_str() );
231 if( ExitClickL
== ExitClickR
)
232 xmlSetProp( node
, BAD_CAST
"exit_click_b", BAD_CAST
NLMISC::toString( ExitClickL
).c_str() );
234 xmlSetProp( node
, BAD_CAST
"force_inside_screen", BAD_CAST
NLMISC::toString( ForceInsideScreen
).c_str() );
235 xmlSetProp( node
, BAD_CAST
"category", BAD_CAST Category
.c_str() );
236 xmlSetProp( node
, BAD_CAST
"onclick_out", BAD_CAST OnClickOut
.c_str() );
237 xmlSetProp( node
, BAD_CAST
"onclick_out_params", BAD_CAST OnClickOutParams
.c_str() );
238 xmlSetProp( node
, BAD_CAST
"onpostclick_out", BAD_CAST OnPostClickOut
.c_str() );
239 xmlSetProp( node
, BAD_CAST
"onpostclick_out_params", BAD_CAST OnPostClickOutParams
.c_str() );
240 xmlSetProp( node
, BAD_CAST
"exit_key_pushed", BAD_CAST
NLMISC::toString( ExitKeyPushed
).c_str() );
245 // ***************************************************************************
246 bool CGroupModal::parse (xmlNodePtr cur
, CInterfaceGroup
*parentGroup
)
248 if(!CGroupFrame::parse(cur
, parentGroup
))
253 prop
= xmlGetProp (cur
, (xmlChar
*)"mouse_pos");
254 if (prop
) SpawnOnMousePos
= convertBool(prop
);
255 prop
= xmlGetProp (cur
, (xmlChar
*)"exit_click_out");
256 if (prop
) ExitClickOut
= convertBool(prop
);
257 prop
= xmlGetProp (cur
, (xmlChar
*)"exit_click_l");
258 if (prop
) ExitClickL
= convertBool(prop
);
259 prop
= xmlGetProp (cur
, (xmlChar
*)"exit_click_r");
260 if (prop
) ExitClickR
= convertBool(prop
);
261 prop
= xmlGetProp (cur
, (xmlChar
*)"exit_click_b");
262 if (prop
) ExitClickR
= ExitClickL
= convertBool(prop
);
263 prop
= xmlGetProp (cur
, (xmlChar
*)"force_inside_screen");
264 if (prop
) ForceInsideScreen
= convertBool(prop
);
265 prop
= xmlGetProp (cur
, (xmlChar
*)"category");
266 if (prop
) Category
= (const char *) prop
;
267 prop
= xmlGetProp (cur
, (xmlChar
*)"onclick_out");
268 if (prop
) OnClickOut
= (const char *) prop
;
269 prop
= xmlGetProp (cur
, (xmlChar
*)"onclick_out_params");
270 if (prop
) OnClickOutParams
= (const char *) prop
;
271 prop
= xmlGetProp (cur
, (xmlChar
*)"onpostclick_out");
272 if (prop
) OnPostClickOut
= (const char *) prop
;
273 prop
= xmlGetProp (cur
, (xmlChar
*)"onpostclick_out_params");
274 if (prop
) OnPostClickOutParams
= (const char *) prop
;
275 prop
= xmlGetProp (cur
, (xmlChar
*)"exit_key_pushed");
276 if (prop
) ExitKeyPushed
= convertBool(prop
);
278 // Force parent hotspot for spawn on mouse
280 setParentPosRef(Hotspot_BL
);
282 // bkup x/y as the deltas.
283 _MouseDeltaX
= getX();
284 _MouseDeltaY
= getY();
286 // Modals are disabled by default
292 // ***************************************************************************
293 void CGroupModal::updateCoords ()
295 // if snap to mouse pos.
298 // Special for menu for instance: If the size is bigger or equal to the screen, keep 0, because will be clipped just after
299 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
301 rVR
.getScreenSize(w
,h
);
302 if(_W
>=(sint32
)w
&& _H
>=(sint32
)h
)
309 _X
= SpawnMouseX
+_MouseDeltaX
;
310 _Y
= SpawnMouseY
+_MouseDeltaY
;
315 CGroupFrame::updateCoords();
317 // if snap to mouse pos or ForceInsideScreen
318 if(SpawnOnMousePos
|| ForceInsideScreen
)
320 bool clipped
= false;
321 // repos the group according to real size. clip against screen
329 if (!SpawnOnMousePos
)
333 if(_XReal
+_WReal
>_Parent
->getW())
335 _X
-= _XReal
+_WReal
-_Parent
->getW();
340 if ((!SpawnOnMousePos
) && (_XReal
>=0))
351 if (!SpawnOnMousePos
)
355 if(_YReal
+_HReal
>_Parent
->getH())
357 _Y
-= _YReal
+_HReal
-_Parent
->getH();
362 if ((!SpawnOnMousePos
) && (_YReal
>=0))
368 CGroupFrame::updateCoords();