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/>.
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"
30 using namespace NLMISC
;
39 NLMISC_REGISTER_OBJECT(CViewBase
, CGroupFrame
, std::string
, "frame");
41 // ***************************************************************************
42 vector
<CGroupFrame::SDisplayType
> CGroupFrame::_DispTypes
;
44 // ***************************************************************************
45 CGroupFrame::CGroupFrame(const TCtorParam
¶m
)
46 : CInterfaceGroup(param
)
49 _Color
= CRGBA(255,255,255,255);
51 _DisplayFrameDefined
= false;
53 _DispTypeDefined
= false;
56 std::string
CGroupFrame::getProperty( const std::string
&name
) const
58 if( name
== "display" )
60 return toString( _DisplayFrame
);
65 return toString( _Color
);
68 if( name
== "options" )
73 return CInterfaceGroup::getProperty( name
);
76 void CGroupFrame::setProperty( const std::string
&name
, const std::string
&value
)
78 if( name
== "display" )
81 if( fromString( value
, b
) )
89 if( fromString( value
, c
) )
94 if( name
== "options" )
101 CInterfaceGroup::setProperty( name
, value
);
104 xmlNodePtr
CGroupFrame::serialize( xmlNodePtr parentNode
, const char *type
) const
106 xmlNodePtr node
= CInterfaceGroup::serialize( parentNode
, type
);
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() );
118 // ***************************************************************************
119 bool CGroupFrame::parse (xmlNodePtr cur
, CInterfaceGroup
*parentGroup
)
121 if(!CInterfaceGroup::parse(cur
, parentGroup
))
125 CXMLAutoPtr
ptr((const char*) xmlGetProp (cur
, (xmlChar
*)"display"));
126 _DisplayFrame
= true;
127 _DisplayFrameDefined
= false;
130 _DisplayFrame
= convertBool (ptr
);
131 _DisplayFrameDefined
= true;
135 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"color" );
136 _Color
= CRGBA(255,255,255,255);
137 _ColorDefined
= false;
140 _Color
= convertColor (ptr
);
144 // Get the borders texture
145 _DispTypeDefined
= false;
146 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
148 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"options" );
151 _Options
= std::string( (const char*)ptr
);
154 // The first type in display type struct is the default display type
155 if (_DispTypes
.empty())
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");
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");
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");
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
);
183 // ***************************************************************************
184 void CGroupFrame::draw ()
188 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
192 if(getModulateGlobalColor())
193 col
.modulateFromColor( _Color
, CWidgetManager::getInstance()->getGlobalColor() );
197 // draw the background
198 sint xId
= 0, yId
= 0;
199 for (yId
= 0; yId
< 3; yId
++)
201 for (xId
= 0; xId
< 3; xId
++)
209 y
+= _HReal
-_DispTypes
[_DispType
].TopBorder
;
210 h
= _DispTypes
[_DispType
].TopBorder
;
215 y
+= _DispTypes
[_DispType
].BottomBorder
;
216 h
= _HReal
-_DispTypes
[_DispType
].TopBorder
-_DispTypes
[_DispType
].BottomBorder
;
221 h
= _DispTypes
[_DispType
].BottomBorder
;
227 w
= _DispTypes
[_DispType
].LeftBorder
;
231 x
+= _DispTypes
[_DispType
].LeftBorder
;
232 w
= _WReal
-_DispTypes
[_DispType
].LeftBorder
-_DispTypes
[_DispType
].RightBorder
;
236 x
+= _WReal
-_DispTypes
[_DispType
].RightBorder
;
237 w
= _DispTypes
[_DispType
].RightBorder
;
241 uint8 tile
= _DispTypes
[_DispType
].TileBorder
[yId
*3+xId
];
243 rVR
.drawRotFlipBitmap (_RenderLayer
, x
, y
, w
, h
, 0, false, _DispTypes
[_DispType
].BorderIds
[yId
*3+xId
], col
);
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
;
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
);
277 _DispTypeDefined
= true;
279 // Look if we find the type...
281 for (i
= 0; i
< _DispTypes
.size(); ++i
)
282 if (_DispTypes
[i
].Name
== _Options
)
285 if (i
== _DispTypes
.size())
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"));
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"));
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"));
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");
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
;
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
);