Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / nel / src / gui / group_frame.cpp
blobdcb159028836cb25bf05932fdbf4a872778c337c
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 //
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/>.
20 #include "stdpch.h"
21 #include "nel/gui/group_frame.h"
23 #include "nel/gui/widget_manager.h"
24 #include "nel/gui/interface_options.h"
25 #include "nel/gui/interface_element.h"
26 #include "nel/gui/view_renderer.h"
27 #include "nel/misc/xml_auto_ptr.h"
29 using namespace std;
30 using namespace NLMISC;
32 #ifdef DEBUG_NEW
33 #define new DEBUG_NEW
34 #endif
36 namespace NLGUI
39 NLMISC_REGISTER_OBJECT(CViewBase, CGroupFrame, std::string, "frame");
41 // ***************************************************************************
42 vector<CGroupFrame::SDisplayType> CGroupFrame::_DispTypes;
44 // ***************************************************************************
45 CGroupFrame::CGroupFrame(const TCtorParam &param)
46 : CInterfaceGroup(param)
48 _DisplayFrame = true;
49 _Color = CRGBA(255,255,255,255);
50 _DispType = 0;
51 _DisplayFrameDefined= false;
52 _ColorDefined= false;
53 _DispTypeDefined= false;
56 std::string CGroupFrame::getProperty( const std::string &name ) const
58 if( name == "display" )
60 return toString( _DisplayFrame );
62 else
63 if( name == "color" )
65 return toString( _Color );
67 else
68 if( name == "options" )
70 return _Options;
72 else
73 return CInterfaceGroup::getProperty( name );
76 void CGroupFrame::setProperty( const std::string &name, const std::string &value )
78 if( name == "display" )
80 bool b;
81 if( fromString( value, b ) )
82 _DisplayFrame = b;
83 return;
85 else
86 if( name == "color" )
88 CRGBA c;
89 if( fromString( value, c ) )
90 _Color = c;
91 return;
93 else
94 if( name == "options" )
96 _Options = value;
97 setupOptions();
98 return;
100 else
101 CInterfaceGroup::setProperty( name, value );
104 xmlNodePtr CGroupFrame::serialize( xmlNodePtr parentNode, const char *type ) const
106 xmlNodePtr node = CInterfaceGroup::serialize( parentNode, type );
107 if( node == NULL )
108 return NULL;
110 xmlSetProp( node, BAD_CAST "type", BAD_CAST "frame" );
111 xmlSetProp( node, BAD_CAST "display", BAD_CAST NLMISC::toString( _DisplayFrame ).c_str() );
112 xmlSetProp( node, BAD_CAST "color", BAD_CAST NLMISC::toString( _Color ).c_str() );
113 xmlSetProp( node, BAD_CAST "options", BAD_CAST _Options.c_str() );
115 return node;
118 // ***************************************************************************
119 bool CGroupFrame::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup)
121 if(!CInterfaceGroup::parse(cur, parentGroup))
122 return false;
124 // display
125 CXMLAutoPtr ptr((const char*) xmlGetProp (cur, (xmlChar*)"display"));
126 _DisplayFrame = true;
127 _DisplayFrameDefined= false;
128 if (ptr)
130 _DisplayFrame = convertBool (ptr);
131 _DisplayFrameDefined= true;
134 // color
135 ptr = (char*) xmlGetProp( cur, (xmlChar*)"color" );
136 _Color = CRGBA(255,255,255,255);
137 _ColorDefined= false;
138 if (ptr)
140 _Color = convertColor (ptr);
141 _ColorDefined= true;
144 // Get the borders texture
145 _DispTypeDefined= false;
146 CViewRenderer &rVR = *CViewRenderer::getInstance();
148 ptr = (char*) xmlGetProp( cur, (xmlChar*)"options" );
149 if (ptr)
151 _Options = std::string( (const char*)ptr );
154 // The first type in display type struct is the default display type
155 if (_DispTypes.empty())
157 SDisplayType dt;
158 dt.Name = "default";
159 // get texture ids.
160 dt.BorderIds[TextTL]= rVR.getTextureIdFromName ("w_modal_tl.tga");
161 dt.BorderIds[TextTM]= rVR.getTextureIdFromName ("w_modal_t.tga");
162 dt.BorderIds[TextTR]= rVR.getTextureIdFromName ("w_modal_tr.tga");
163 // middle
164 dt.BorderIds[TextML]= rVR.getTextureIdFromName ("w_modal_l.tga");
165 dt.BorderIds[TextMM]= rVR.getTextureIdFromName ("w_modal_blank.tga");
166 dt.BorderIds[TextMR]= rVR.getTextureIdFromName ("w_modal_r.tga");
167 // bottom
168 dt.BorderIds[TextBL]= rVR.getTextureIdFromName ("w_modal_bl.tga");
169 dt.BorderIds[TextBM]= rVR.getTextureIdFromName ("w_modal_b.tga");
170 dt.BorderIds[TextBR]= rVR.getTextureIdFromName ("w_modal_br.tga");
171 // get size
172 rVR.getTextureSizeFromId (dt.BorderIds[TextTL], dt.LeftBorder, dt.TopBorder);
173 rVR.getTextureSizeFromId (dt.BorderIds[TextBR], dt.RightBorder, dt.BottomBorder);
174 _DispTypes.push_back(dt);
177 setupOptions();
179 return true;
183 // ***************************************************************************
184 void CGroupFrame::draw ()
186 if (_DisplayFrame)
188 CViewRenderer &rVR = *CViewRenderer::getInstance();
190 // get global color
191 CRGBA col;
192 if(getModulateGlobalColor())
193 col.modulateFromColor( _Color, CWidgetManager::getInstance()->getGlobalColor() );
194 else
195 col= _Color;
197 // draw the background
198 sint xId = 0, yId = 0;
199 for (yId = 0; yId < 3; yId++)
201 for (xId = 0; xId < 3; xId++)
203 sint32 x = _XReal;
204 sint32 y = _YReal;
205 sint32 w, h;
206 // top
207 if (yId == 0)
209 y += _HReal-_DispTypes[_DispType].TopBorder;
210 h = _DispTypes[_DispType].TopBorder;
212 // Middle
213 else if (yId == 1)
215 y += _DispTypes[_DispType].BottomBorder;
216 h = _HReal-_DispTypes[_DispType].TopBorder-_DispTypes[_DispType].BottomBorder;
218 // Bottom
219 else
221 h = _DispTypes[_DispType].BottomBorder;
224 // Left
225 if (xId == 0)
227 w = _DispTypes[_DispType].LeftBorder;
229 else if (xId == 1)
231 x += _DispTypes[_DispType].LeftBorder;
232 w = _WReal-_DispTypes[_DispType].LeftBorder-_DispTypes[_DispType].RightBorder;
234 else
236 x += _WReal-_DispTypes[_DispType].RightBorder;
237 w = _DispTypes[_DispType].RightBorder;
240 // render
241 uint8 tile = _DispTypes[_DispType].TileBorder[yId*3+xId];
242 if (tile == 0)
243 rVR.drawRotFlipBitmap (_RenderLayer, x, y, w, h, 0, false, _DispTypes[_DispType].BorderIds[yId*3+xId], col);
244 else
245 rVR.drawRotFlipBitmapTiled (_RenderLayer, x, y, w, h, 0, false, _DispTypes[_DispType].BorderIds[yId*3+xId], tile-1, col);
250 // draw the components
251 CInterfaceGroup::draw();
254 // ***************************************************************************
255 void CGroupFrame::copyOptionFrom(const CGroupFrame &other)
257 CInterfaceGroup::copyOptionFrom(other);
259 // Copy option only if they were not explicitly defined in xml
260 if(!_DisplayFrameDefined)
261 _DisplayFrame = other._DisplayFrame;
262 if(!_ColorDefined)
263 _Color = other._Color;
264 if(!_DispTypeDefined)
265 _DispType = other._DispType;
268 void CGroupFrame::setupOptions()
270 CViewRenderer &rVR = *(CViewRenderer::getInstance());
272 CInterfaceOptions *pIO = NULL;
273 pIO = CWidgetManager::getInstance()->getOptions( _Options );
275 if( pIO != NULL )
277 _DispTypeDefined= true;
279 // Look if we find the type...
280 uint32 i;
281 for (i = 0; i < _DispTypes.size(); ++i)
282 if (_DispTypes[i].Name == _Options )
283 break;
285 if (i == _DispTypes.size())
287 SDisplayType dt;
288 dt.Name = _Options;
289 // get texture ids.
290 dt.BorderIds[TextTL]= rVR.getTextureIdFromName (pIO->getValStr("tx_tl"));
291 dt.BorderIds[TextTM]= rVR.getTextureIdFromName (pIO->getValStr("tx_t"));
292 dt.BorderIds[TextTR]= rVR.getTextureIdFromName (pIO->getValStr("tx_tr"));
293 // middle
294 dt.BorderIds[TextML]= rVR.getTextureIdFromName (pIO->getValStr("tx_l"));
295 dt.BorderIds[TextMM]= rVR.getTextureIdFromName (pIO->getValStr("tx_blank"));
296 dt.BorderIds[TextMR]= rVR.getTextureIdFromName (pIO->getValStr("tx_r"));
297 // bottom
298 dt.BorderIds[TextBL]= rVR.getTextureIdFromName (pIO->getValStr("tx_bl"));
299 dt.BorderIds[TextBM]= rVR.getTextureIdFromName (pIO->getValStr("tx_b"));
300 dt.BorderIds[TextBR]= rVR.getTextureIdFromName (pIO->getValStr("tx_br"));
302 // Tile
303 dt.TileBorder[TextTM] = (uint8)pIO->getValSInt32("tile_t");
304 dt.TileBorder[TextML] = (uint8)pIO->getValSInt32("tile_l");
305 dt.TileBorder[TextMM] = (uint8)pIO->getValSInt32("tile_blank");
306 dt.TileBorder[TextMR] = (uint8)pIO->getValSInt32("tile_r");
307 dt.TileBorder[TextBM] = (uint8)pIO->getValSInt32("tile_b");
309 // get size
310 rVR.getTextureSizeFromId (dt.BorderIds[TextTL], dt.LeftBorder, dt.TopBorder);
311 rVR.getTextureSizeFromId (dt.BorderIds[TextBR], dt.RightBorder, dt.BottomBorder);
312 _DispTypes.push_back(dt);
314 _DispType = (uint8)i;
316 else
318 _DispType = 0;
322 // ***************************************************************************
323 void CGroupFrame::setColorAsString(const string & col)
325 _Color = convertColor (col.c_str());
328 // ***************************************************************************
329 string CGroupFrame::getColorAsString() const
331 return NLMISC::toString(_Color.R) + " " + NLMISC::toString(_Color.G) + " " + NLMISC::toString(_Color.B) + " " + NLMISC::toString(_Color.A);