Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / src / gui / interface_options.cpp
blob27b7ebbb589a93b4bdbd604c832e6bcefa93cf6c
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) 2014-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/>.
22 #include "stdpch.h"
23 #include "nel/gui/interface_options.h"
25 #include "nel/gui/interface_element.h"
26 #include "nel/gui/view_renderer.h"
27 #include "nel/misc/factory.h"
28 #include <string>
30 using namespace std;
31 using namespace NLMISC;
33 #ifdef DEBUG_NEW
34 #define new DEBUG_NEW
35 #endif
37 namespace NLGUI
40 const CInterfaceOptionValue CInterfaceOptionValue::NullValue;
42 // ***************************************************************************
43 void CInterfaceOptionValue::init(const std::string &str)
45 _Str= str;
46 fromString(str, _Int);
47 fromString(str, _Float);
48 _Color= CInterfaceElement::convertColor (str.c_str());
49 _Boolean= CInterfaceElement::convertBool(str.c_str());
53 // ----------------------------------------------------------------------------
54 // CInterfaceOptions
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
58 CInterfaceOptions::CInterfaceOptions( const TCtorParam &/* param */ )
62 // ----------------------------------------------------------------------------
63 CInterfaceOptions::~CInterfaceOptions()
67 // ----------------------------------------------------------------------------
68 bool CInterfaceOptions::parse (xmlNodePtr cur)
70 cur = cur->children;
71 bool ok = true;
72 while (cur)
74 if ( !stricmp((char*)cur->name,"param") )
76 CXMLAutoPtr ptr, val;
77 ptr = xmlGetProp (cur, (xmlChar*)"name");
78 val = xmlGetProp (cur, (xmlChar*)"value");
79 if (!ptr || !val)
81 nlinfo("param with no name or no value");
82 ok = false;
84 else
86 string name = NLMISC::toLowerAscii(string((const char*)ptr));
87 string value = (string((const char*)val));
88 _ParamValue[name].init(value);
91 cur = cur->next;
93 return ok;
96 xmlNodePtr CInterfaceOptions::serialize( xmlNodePtr parentNode, const std::string &name ) const
98 if( parentNode == NULL )
99 return NULL;
101 if( name.empty() )
102 return NULL;
104 xmlNodePtr node = xmlNewNode( NULL, BAD_CAST "options" );
105 if( node == NULL )
106 return NULL;
108 xmlSetProp( node, BAD_CAST "name", BAD_CAST name.c_str() );
109 xmlAddChild( parentNode, node );
111 std::map< std::string, CInterfaceOptionValue >::const_iterator itr;
112 for( itr = _ParamValue.begin(); itr != _ParamValue.end(); ++itr )
114 xmlNodePtr n = xmlNewNode( NULL, BAD_CAST "param" );
115 if( n == NULL )
117 xmlFreeNode( node );
118 return NULL;
121 xmlSetProp( n, BAD_CAST "name", BAD_CAST itr->first.c_str() );
122 xmlSetProp( n, BAD_CAST "value", BAD_CAST itr->second.getValStr().c_str() );
123 xmlAddChild( node, n );
126 return node;
129 // ***************************************************************************
130 void CInterfaceOptions::copyBasicMap(const CInterfaceOptions &other)
132 _ParamValue= other._ParamValue;
135 // ***************************************************************************
136 const CInterfaceOptionValue &CInterfaceOptions::getValue(const string &sParamName) const
138 std::map<std::string, CInterfaceOptionValue>::const_iterator it = _ParamValue.find (toLowerAscii(sParamName));
139 if (it != _ParamValue.end())
140 return it->second;
141 else
142 return CInterfaceOptionValue::NullValue;
145 // ***************************************************************************
146 const std::string &CInterfaceOptions::getValStr(const std::string &sParamName) const
148 return getValue(sParamName).getValStr();
150 // ***************************************************************************
151 sint32 CInterfaceOptions::getValSInt32(const std::string &sParamName) const
153 return getValue(sParamName).getValSInt32();
155 // ***************************************************************************
156 float CInterfaceOptions::getValFloat(const std::string &sParamName) const
158 return getValue(sParamName).getValFloat();
160 // ***************************************************************************
161 NLMISC::CRGBA CInterfaceOptions::getValColor(const std::string &sParamName) const
163 return getValue(sParamName).getValColor();
165 // ***************************************************************************
166 bool CInterfaceOptions::getValBool(const std::string &sParamName) const
168 return getValue(sParamName).getValBool();
173 // ----------------------------------------------------------------------------
174 // CInterfaceLayer
175 // ----------------------------------------------------------------------------
177 // ----------------------------------------------------------------------------
178 NLMISC_REGISTER_OBJECT(CInterfaceOptions, COptionsLayer, std::string, "layer");
179 COptionsLayer::COptionsLayer( const TCtorParam &param ) :
180 CInterfaceOptions( param )
182 TxId_TL = TxId_T = TxId_TR = TxId_L = TxId_R = TxId_Blank = TxId_BL = TxId_B = -2;
183 TxId_BR = TxId_BL_Open = TxId_B_Open = TxId_BR_Open = TxId_EL_Open = TxId_EM_Open = TxId_ER_Open =-2;
184 Tile_Blank = 0;
185 Tile_M_Header = Tile_M_Scrollbar = 0;
186 Tile_T = Tile_B = Tile_L = Tile_R = 0;
187 Tile_B_Open = Tile_EM_Open = Tile_M_Open = 0;
188 Scrollbar_Offset_X = 4;
189 Scrollbar_W = 8;
192 // ----------------------------------------------------------------------------
193 COptionsLayer::~COptionsLayer()
197 xmlNodePtr COptionsLayer::serialize( xmlNodePtr parentNode, const std::string &name ) const
199 xmlNodePtr node = CInterfaceOptions::serialize( parentNode, name );
200 if( node == NULL )
201 return NULL;
203 xmlSetProp( node, BAD_CAST "type", BAD_CAST "layer" );
205 return node;
208 // ----------------------------------------------------------------------------
209 bool COptionsLayer::parse (xmlNodePtr cur)
211 if (!CInterfaceOptions::parse (cur))
212 return false;
214 CViewRenderer &rVR = *CViewRenderer::getInstance();
216 Tile_Blank = getValSInt32("tile_blank");
217 Tile_M_Header = getValSInt32("tile_m_header");
218 Tile_M_Scrollbar = getValSInt32("tile_m_scrollbar");
219 Tile_T = getValSInt32("tile_t");
220 Tile_B = getValSInt32("tile_b");
221 Tile_L = getValSInt32("tile_l");
222 Tile_R = getValSInt32("tile_r");
223 Tile_B_Open = getValSInt32("tile_b_open");
224 Tile_EM_Open = getValSInt32("tile_em_open");
225 Tile_M_Open = getValSInt32("tile_m_open");
227 Scrollbar_Offset_X = getValSInt32("scrollbar_offset_x");
228 Scrollbar_W = getValSInt32("scrollbar_size_w");
229 TxId_B_Scrollbar = rVR.getTextureIdFromName (getValStr("scrollbar_tx_b"));
230 rVR.getTextureSizeFromId(TxId_B_Scrollbar, W_B_Scrollbar, H_B_Scrollbar);
231 TxId_M_Scrollbar = rVR.getTextureIdFromName (getValStr("scrollbar_tx_m"));
232 rVR.getTextureSizeFromId(TxId_M_Scrollbar, W_M_Scrollbar, H_M_Scrollbar);
233 TxId_T_Scrollbar = rVR.getTextureIdFromName (getValStr("scrollbar_tx_t"));
234 rVR.getTextureSizeFromId(TxId_T_Scrollbar, W_T_Scrollbar, H_T_Scrollbar);
236 TxId_L_Header = rVR.getTextureIdFromName (getValStr("tx_l_header"));
237 rVR.getTextureSizeFromId(TxId_L_Header, W_L_Header, H_L_Header);
238 TxId_M_Header = rVR.getTextureIdFromName (getValStr("tx_m_header"));
239 rVR.getTextureSizeFromId(TxId_M_Header, W_M_Header, H_M_Header);
240 TxId_R_Header = rVR.getTextureIdFromName (getValStr("tx_r_header"));
241 rVR.getTextureSizeFromId(TxId_R_Header, W_R_Header, H_R_Header);
243 TxId_TL = rVR.getTextureIdFromName (getValStr("tx_tl"));
244 rVR.getTextureSizeFromId(TxId_TL, W_TL, H_TL);
245 TxId_T = rVR.getTextureIdFromName (getValStr("tx_t"));
246 rVR.getTextureSizeFromId(TxId_T, W_T, H_T);
247 TxId_TR = rVR.getTextureIdFromName (getValStr("tx_tr"));
248 rVR.getTextureSizeFromId(TxId_TR, W_TR, H_TR);
249 TxId_L = rVR.getTextureIdFromName (getValStr("tx_l"));
250 rVR.getTextureSizeFromId(TxId_L, W_L, H_L);
251 TxId_R = rVR.getTextureIdFromName (getValStr("tx_r"));
252 rVR.getTextureSizeFromId(TxId_R, W_R, H_R);
253 TxId_Blank = rVR.getTextureIdFromName (getValStr("tx_blank"));
254 rVR.getTextureSizeFromId(TxId_Blank, W_Blank, H_Blank);
255 TxId_BL = rVR.getTextureIdFromName (getValStr("tx_bl"));
256 rVR.getTextureSizeFromId(TxId_BL, W_BL, H_BL);
257 TxId_B = rVR.getTextureIdFromName (getValStr("tx_b"));
258 rVR.getTextureSizeFromId(TxId_B, W_B, H_B);
259 TxId_BR = rVR.getTextureIdFromName (getValStr("tx_br"));
260 rVR.getTextureSizeFromId(TxId_BR, W_BR, H_BR);
262 TxId_BL_Open = rVR.getTextureIdFromName (getValStr("tx_bl_open"));
263 rVR.getTextureSizeFromId(TxId_BL_Open, W_BL_Open, H_BL_Open);
264 TxId_B_Open = rVR.getTextureIdFromName (getValStr("tx_b_open"));
265 rVR.getTextureSizeFromId(TxId_B_Open, W_B_Open, H_B_Open);
266 TxId_BR_Open = rVR.getTextureIdFromName (getValStr("tx_br_open"));
267 rVR.getTextureSizeFromId(TxId_BR_Open, W_BR_Open, H_BR_Open);
268 TxId_EL_Open = rVR.getTextureIdFromName (getValStr("tx_el_open"));
269 rVR.getTextureSizeFromId(TxId_EL_Open, W_EL_Open, H_EL_Open);
270 TxId_EM_Open = rVR.getTextureIdFromName (getValStr("tx_em_open"));
271 rVR.getTextureSizeFromId(TxId_EM_Open, W_EM_Open, H_EM_Open);
272 TxId_ER_Open = rVR.getTextureIdFromName (getValStr("tx_er_open"));
273 rVR.getTextureSizeFromId(TxId_ER_Open, W_ER_Open, H_ER_Open);
274 TxId_M_Open = rVR.getTextureIdFromName (getValStr("tx_m_open"));
275 rVR.getTextureSizeFromId(TxId_M_Open, W_M_Open, H_M_Open);
276 TxId_E_Open = rVR.getTextureIdFromName (getValStr("tx_e_open"));
277 rVR.getTextureSizeFromId(TxId_E_Open, W_E_Open, H_E_Open);
280 TxId_TL_HighLight = rVR.getTextureIdFromName (getValStr("tx_tl_highlight"));
281 rVR.getTextureSizeFromId(TxId_TL_HighLight, W_TL_HighLight, H_TL_HighLight);
282 TxId_T_HighLight = rVR.getTextureIdFromName (getValStr("tx_t_highlight"));
283 rVR.getTextureSizeFromId(TxId_T_HighLight, W_T_HighLight, H_T_HighLight);
284 TxId_TR_HighLight = rVR.getTextureIdFromName (getValStr("tx_tr_highlight"));
285 rVR.getTextureSizeFromId(TxId_TR_HighLight, W_TR_HighLight, H_TR_HighLight);
286 TxId_L_HighLight = rVR.getTextureIdFromName (getValStr("tx_l_highlight"));
287 rVR.getTextureSizeFromId(TxId_L_HighLight, W_L_HighLight, H_L_HighLight);
288 TxId_R_HighLight = rVR.getTextureIdFromName (getValStr("tx_r_highlight"));
289 rVR.getTextureSizeFromId(TxId_R_HighLight, W_R_HighLight, H_R_HighLight);
290 TxId_BL_HighLight = rVR.getTextureIdFromName (getValStr("tx_bl_highlight"));
291 rVR.getTextureSizeFromId(TxId_BL_HighLight, W_BL_HighLight, H_BL_HighLight);
292 TxId_B_HighLight = rVR.getTextureIdFromName (getValStr("tx_b_highlight"));
293 rVR.getTextureSizeFromId(TxId_B_HighLight, W_B_HighLight, H_B_HighLight);
294 TxId_BR_HighLight = rVR.getTextureIdFromName (getValStr("tx_br_highlight"));
295 rVR.getTextureSizeFromId(TxId_BR_HighLight, W_BR_HighLight, H_BR_HighLight);
298 HeaderH = getValSInt32("header_h");
299 InsetT = getValSInt32("inset_t");
301 return true;
304 // ----------------------------------------------------------------------------
305 NLMISC_REGISTER_OBJECT(CInterfaceOptions, COptionsContainerInsertion, std::string, "container_insertion_opt");
306 COptionsContainerInsertion::COptionsContainerInsertion( const TCtorParam &param ) :
307 CInterfaceOptions( param )
309 TxId_R_Arrow = -2;
310 TxId_L_Arrow = -2;
311 TxId_T_Arrow = -2;
312 TxId_B_Arrow = -2;
313 TxId_InsertionBar = -2;
316 xmlNodePtr COptionsContainerInsertion::serialize( xmlNodePtr parentNode, const std::string &name ) const
318 xmlNodePtr node = CInterfaceOptions::serialize( parentNode, name );
319 if( node == NULL )
320 return NULL;
322 xmlSetProp( node, BAD_CAST "type", BAD_CAST "container_insertion_opt" );
324 return node;
327 // ----------------------------------------------------------------------------
328 bool COptionsContainerInsertion::parse(xmlNodePtr cur)
330 if (!CInterfaceOptions::parse (cur))
331 return false;
333 CViewRenderer &rVR = *CViewRenderer::getInstance();
334 TxId_T_Arrow = rVR.getTextureIdFromName (getValStr("arrow_top"));
335 TxId_B_Arrow = rVR.getTextureIdFromName (getValStr("arrow_down"));
336 TxId_L_Arrow = rVR.getTextureIdFromName (getValStr("arrow_left"));
337 TxId_R_Arrow = rVR.getTextureIdFromName (getValStr("arrow_right"));
338 TxId_InsertionBar = rVR.getTextureIdFromName (getValStr("insertion_bar"));
340 return true;
344 // ***************************************************************************
345 NLMISC_REGISTER_OBJECT(CInterfaceOptions, COptionsContainerMove, std::string, "container_move_opt");
346 COptionsContainerMove::COptionsContainerMove( const TCtorParam &param ) :
347 CInterfaceOptions( param )
349 TrackW = -8;
350 TrackH = 22;
351 TrackY = -4;
352 TrackYWithTopResizer = -8;
353 TrackHWithTopResizer = 18;
354 ResizerSize = 8;
357 xmlNodePtr COptionsContainerMove::serialize( xmlNodePtr parentNode, const std::string &name ) const
359 xmlNodePtr node = CInterfaceOptions::serialize( parentNode, name );
360 if( node == NULL )
361 return NULL;
363 xmlSetProp( node, BAD_CAST "type", BAD_CAST "container_move_opt" );
365 return node;
368 // ***************************************************************************
369 bool COptionsContainerMove::parse(xmlNodePtr cur)
371 if (!CInterfaceOptions::parse (cur))
372 return false;
373 fromString(getValStr("track_w"), TrackW);
374 fromString(getValStr("track_h"), TrackH);
375 fromString(getValStr("track_y"), TrackY);
376 fromString(getValStr("track_y_with_top_resizer"), TrackYWithTopResizer);
377 fromString(getValStr("track_h_with_top_resizer"), TrackHWithTopResizer);
378 fromString(getValStr("resizer_size"), ResizerSize);
379 return true;
382 // ***************************************************************************
383 NLMISC_REGISTER_OBJECT(CInterfaceOptions, COptionsList, std::string, "list");
384 COptionsList::COptionsList( const TCtorParam &param ) :
385 CInterfaceOptions( param )
387 _NumParams= 0;
391 xmlNodePtr COptionsList::serialize( xmlNodePtr parentNode, const std::string &name ) const
393 if( parentNode == NULL )
394 return NULL;
396 if( name.empty() )
397 return NULL;
399 xmlNodePtr node = xmlNewNode( NULL, BAD_CAST "options" );
400 if( node == NULL )
401 return NULL;
403 xmlSetProp( node, BAD_CAST "name", BAD_CAST name.c_str() );
404 xmlSetProp( node, BAD_CAST "type", BAD_CAST "list" );
405 xmlAddChild( parentNode, node );
407 std::map< std::string, CInterfaceOptionValue >::const_iterator itr;
408 for( itr = _ParamValue.begin(); itr != _ParamValue.end(); ++itr )
410 xmlNodePtr n = xmlNewNode( NULL, BAD_CAST "param" );
411 if( n == NULL )
413 xmlFreeNode( node );
414 return NULL;
416 xmlSetProp( n, BAD_CAST "value", BAD_CAST itr->second.getValStr().c_str() );
417 xmlAddChild( node, n );
420 return node;
423 // ***************************************************************************
424 bool COptionsList::parse (xmlNodePtr cur)
426 cur = cur->children;
427 bool ok = true;
428 uint id= 0;
429 while (cur)
431 if ( !stricmp((char*)cur->name,"param") )
433 CXMLAutoPtr ptr, val;
434 val = xmlGetProp (cur, (xmlChar*)"value");
435 if (!val)
437 nlinfo("param with no name or no value");
438 ok = false;
440 else
442 string value = (string((const char*)val));
443 _ParamValue[toString(id)].init(value);
444 id++;
447 cur = cur->next;
450 _NumParams= id;
452 return ok;
456 // ***************************************************************************
457 const CInterfaceOptionValue &COptionsList::getValue(uint paramId) const
459 return CInterfaceOptions::getValue(toString(paramId));