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 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
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/>.
23 #include "nel/gui/dbgroup_select_number.h"
24 #include "nel/gui/view_text.h"
25 #include "nel/gui/view_bitmap.h"
26 #include "nel/gui/ctrl_button.h"
27 #include "nel/gui/interface_property.h"
28 #include "nel/gui/action_handler.h"
32 using namespace NLMISC
;
40 NLMISC_REGISTER_OBJECT(CViewBase
, CDBGroupSelectNumber
, std::string
, "select_number");
42 void force_link_dbgroup_select_number_cpp() { }
44 // ***************************************************************************
45 CDBGroupSelectNumber::CDBGroupSelectNumber(const TCtorParam
¶m
) :
46 CInterfaceGroup(param
)
58 // ***************************************************************************
59 CDBGroupSelectNumber::~CDBGroupSelectNumber()
63 std::string
CDBGroupSelectNumber::getProperty( const std::string
&name
) const
67 if( _Number
.getNodePtr() != NULL
)
68 return _Number
.getNodePtr()->getFullName();
75 return toString( _LoopMode
);
80 return toString( _MinValue
);
85 return toString( _MaxValue
);
90 return toString( _DeltaMultiplier
);
93 return CInterfaceGroup::getProperty( name
);
96 void CDBGroupSelectNumber::setProperty( const std::string
&name
, const std::string
&value
)
100 _Number
.link( value
.c_str() );
107 if( fromString( value
, b
) )
115 if( fromString( value
, i
) )
123 if( fromString( value
, i
) )
128 if( name
== "delta" )
131 if( fromString( value
, i
) )
132 _DeltaMultiplier
= i
;
136 CInterfaceGroup::setProperty( name
, value
);
139 xmlNodePtr
CDBGroupSelectNumber::serialize( xmlNodePtr parentNode
, const char *type
) const
141 xmlNodePtr node
= CInterfaceGroup::serialize( parentNode
, type
);
145 xmlSetProp( node
, BAD_CAST
"type", BAD_CAST
"select_number" );
147 if( _Number
.getNodePtr() != NULL
)
148 xmlSetProp( node
, BAD_CAST
"value", BAD_CAST _Number
.getNodePtr()->getFullName().c_str() );
150 xmlSetProp( node
, BAD_CAST
"value", BAD_CAST
"" );
152 xmlSetProp( node
, BAD_CAST
"loop", BAD_CAST
toString( _LoopMode
).c_str() );
153 xmlSetProp( node
, BAD_CAST
"min", BAD_CAST
toString( _MinValue
).c_str() );
154 xmlSetProp( node
, BAD_CAST
"max", BAD_CAST
toString( _MaxValue
).c_str() );
155 xmlSetProp( node
, BAD_CAST
"delta", BAD_CAST
toString( _DeltaMultiplier
).c_str() );
160 // ***************************************************************************
161 bool CDBGroupSelectNumber::parse (xmlNodePtr cur
, CInterfaceGroup
*parentGroup
)
163 if(!CInterfaceGroup::parse(cur
, parentGroup
))
168 ptr
= xmlGetProp (cur
, (xmlChar
*)"value");
170 _Number
.link ( ptr
);
173 nlinfo ("no value in %s", _Id
.c_str());
179 ptr
= xmlGetProp (cur
, (xmlChar
*)"loop");
180 if(ptr
) _LoopMode
= convertBool(ptr
);
182 ptr
= xmlGetProp (cur
, (xmlChar
*)"min");
183 if(ptr
) fromString((const char*)ptr
, _MinValue
);
185 ptr
= xmlGetProp (cur
, (xmlChar
*)"max");
186 if(ptr
) fromString((const char*)ptr
, _MaxValue
);
187 ptr
= xmlGetProp (cur
, (xmlChar
*)"delta");
188 if(ptr
) fromString((const char*)ptr
, _DeltaMultiplier
);
191 _Number
.setSInt32(_MinValue
);
196 // ***************************************************************************
197 void CDBGroupSelectNumber::setup()
199 if (_SlotNumber
!= NULL
)
202 // bind to the controls.
203 _SlotNumber
= dynamic_cast<CViewBitmap
*>(CInterfaceGroup::getView("slot_number"));
204 _TextNumber
= dynamic_cast<CViewText
*>(CInterfaceGroup::getView("number"));
205 _ButtonUp
= dynamic_cast<CCtrlBaseButton
*>(CInterfaceGroup::getCtrl("arrow_up"));
206 _ButtonDown
= dynamic_cast<CCtrlBaseButton
*>(CInterfaceGroup::getCtrl("arrow_down"));
209 if(_SlotNumber
==NULL
)
210 nlwarning("Interface: SelectNumberGroup: bitmap 'slot_number' missing or bad type");
211 if(_TextNumber
==NULL
)
212 nlwarning("Interface: SelectNumberGroup: text view 'number' missing or bad type");
214 nlwarning("Interface: SelectNumberGroup: button 'arrow_up' missing or bad type");
215 if(_ButtonDown
==NULL
)
216 nlwarning("Interface: SelectNumberGroup: button 'arrow_down' missing or bad type");
217 if(_SlotNumber
==NULL
|| _TextNumber
==NULL
|| _ButtonUp
==NULL
|| _ButtonDown
==NULL
)
221 _ButtonUp
->setActionOnLeftClick("sn_up");
222 _ButtonDown
->setActionOnLeftClick("sn_down");
226 // ***************************************************************************
227 void CDBGroupSelectNumber::updateCoords ()
230 CInterfaceGroup::updateCoords();
235 void CDBGroupSelectNumber::checkCoords()
238 _TextNumber
->setText( toString(_Number
.getSInt32()) );
239 CInterfaceGroup::checkCoords();
242 // ***************************************************************************
243 void CDBGroupSelectNumber::draw ()
245 CInterfaceGroup::draw();
248 // ***************************************************************************
249 void CDBGroupSelectNumber::clearViews ()
251 CInterfaceGroup::clearViews();
254 // ***************************************************************************
255 bool CDBGroupSelectNumber::handleEvent (const NLGUI::CEventDescriptor
&event
)
257 if (event
.getType() == NLGUI::CEventDescriptor::mouse
)
259 const NLGUI::CEventDescriptorMouse
&eventDesc
= (const NLGUI::CEventDescriptorMouse
&)event
;
260 if (isIn(eventDesc
.getX(), eventDesc
.getY()))
262 if (eventDesc
.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mousewheel
)
264 changeValue (eventDesc
.getWheel());
269 if (CInterfaceGroup::handleEvent(event
)) return true;
274 // ***************************************************************************
275 void CDBGroupSelectNumber::changeValue(sint delta
)
277 delta
*= _DeltaMultiplier
;
280 sint32 val
= _Number
.getSInt32();
286 sint32 dval
= _MaxValue
+1 - _MinValue
;
293 val
= val
% dval
; val
= (val
+dval
)% dval
;
298 clamp(val
, _MinValue
, _MaxValue
);
302 _Number
.setSInt32(val
);
304 _TextNumber
->setText( toString(_Number
.getSInt32()) );
308 // ***************************************************************************
309 // ***************************************************************************
311 // ***************************************************************************
312 // ***************************************************************************
315 // ***************************************************************************
316 class CSNUp
: public IActionHandler
319 virtual void execute (CCtrlBase
*pCaller
, const std::string
&/* Params */)
321 CDBGroupSelectNumber
*pSN
= dynamic_cast<CDBGroupSelectNumber
*>(pCaller
->getParent());
322 if (pSN
== NULL
) return;
323 pSN
->changeValue(+1);
326 REGISTER_ACTION_HANDLER (CSNUp
, "sn_up");
328 // ***************************************************************************
329 class CSNDown
: public IActionHandler
332 virtual void execute (CCtrlBase
*pCaller
, const std::string
&/* Params */)
334 CDBGroupSelectNumber
*pSN
= dynamic_cast<CDBGroupSelectNumber
*>(pCaller
->getParent());
335 if (pSN
== NULL
) return;
336 pSN
->changeValue(-1);
339 REGISTER_ACTION_HANDLER (CSNDown
, "sn_down");