khanat-opennel-code/code/nel/src/gui/group_frame.cpp

250 lines
7.8 KiB
C++
Raw Normal View History

2010-05-06 00:08:41 +00:00
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "nel/gui/group_frame.h"
#include "nel/gui/widget_manager.h"
#include "nel/gui/interface_options.h"
#include "nel/gui/interface_element.h"
#include "nel/gui/view_renderer.h"
#include "nel/misc/xml_auto_ptr.h"
2010-05-06 00:08:41 +00:00
using namespace std;
using namespace NLMISC;
NLMISC_REGISTER_OBJECT(CViewBase, CGroupFrame, std::string, "frame");
// ***************************************************************************
vector<CGroupFrame::SDisplayType> CGroupFrame::_DispTypes;
// ***************************************************************************
CGroupFrame::CGroupFrame(const TCtorParam &param)
: CInterfaceGroup(param)
{
_DisplayFrame = true;
_Color = CRGBA(255,255,255,255);
_DispType = 0;
_DisplayFrameDefined= false;
_ColorDefined= false;
_DispTypeDefined= false;
}
// ***************************************************************************
bool CGroupFrame::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup)
{
if(!CInterfaceGroup::parse(cur, parentGroup))
return false;
// display
CXMLAutoPtr ptr((const char*) xmlGetProp (cur, (xmlChar*)"display"));
_DisplayFrame = true;
_DisplayFrameDefined= false;
if (ptr)
{
_DisplayFrame = convertBool (ptr);
_DisplayFrameDefined= true;
}
// color
ptr = (char*) xmlGetProp( cur, (xmlChar*)"color" );
_Color = CRGBA(255,255,255,255);
_ColorDefined= false;
if (ptr)
{
_Color = convertColor (ptr);
_ColorDefined= true;
}
// Get the borders texture
_DispTypeDefined= false;
CViewRenderer &rVR = *CViewRenderer::getInstance();
2010-05-06 00:08:41 +00:00
ptr = (char*) xmlGetProp( cur, (xmlChar*)"options" );
CInterfaceOptions *pIO = NULL;
if (ptr)
pIO = CWidgetManager::getInstance()->getOptions(ptr);
2010-05-06 00:08:41 +00:00
// The first type in display type struct is the default display type
if (_DispTypes.size() == 0)
{
SDisplayType dt;
dt.Name = "default";
// get texture ids.
dt.BorderIds[TextTL]= rVR.getTextureIdFromName ("w_modal_tl.tga");
dt.BorderIds[TextTM]= rVR.getTextureIdFromName ("w_modal_t.tga");
dt.BorderIds[TextTR]= rVR.getTextureIdFromName ("w_modal_tr.tga");
// middle
dt.BorderIds[TextML]= rVR.getTextureIdFromName ("w_modal_l.tga");
dt.BorderIds[TextMM]= rVR.getTextureIdFromName ("w_modal_blank.tga");
dt.BorderIds[TextMR]= rVR.getTextureIdFromName ("w_modal_r.tga");
// bottom
dt.BorderIds[TextBL]= rVR.getTextureIdFromName ("w_modal_bl.tga");
dt.BorderIds[TextBM]= rVR.getTextureIdFromName ("w_modal_b.tga");
dt.BorderIds[TextBR]= rVR.getTextureIdFromName ("w_modal_br.tga");
// get size
rVR.getTextureSizeFromId (dt.BorderIds[TextTL], dt.LeftBorder, dt.TopBorder);
rVR.getTextureSizeFromId (dt.BorderIds[TextBR], dt.RightBorder, dt.BottomBorder);
_DispTypes.push_back(dt);
}
if (pIO != NULL)
{
_DispTypeDefined= true;
// Look if we find the type...
uint32 i;
for (i = 0; i < _DispTypes.size(); ++i)
if (_DispTypes[i].Name == string((const char*)ptr))
break;
if (i == _DispTypes.size())
{
SDisplayType dt;
dt.Name = string((const char*)ptr);
// get texture ids.
dt.BorderIds[TextTL]= rVR.getTextureIdFromName (pIO->getValStr("tx_tl"));
dt.BorderIds[TextTM]= rVR.getTextureIdFromName (pIO->getValStr("tx_t"));
dt.BorderIds[TextTR]= rVR.getTextureIdFromName (pIO->getValStr("tx_tr"));
// middle
dt.BorderIds[TextML]= rVR.getTextureIdFromName (pIO->getValStr("tx_l"));
dt.BorderIds[TextMM]= rVR.getTextureIdFromName (pIO->getValStr("tx_blank"));
dt.BorderIds[TextMR]= rVR.getTextureIdFromName (pIO->getValStr("tx_r"));
// bottom
dt.BorderIds[TextBL]= rVR.getTextureIdFromName (pIO->getValStr("tx_bl"));
dt.BorderIds[TextBM]= rVR.getTextureIdFromName (pIO->getValStr("tx_b"));
dt.BorderIds[TextBR]= rVR.getTextureIdFromName (pIO->getValStr("tx_br"));
// Tile
dt.TileBorder[TextTM] = (uint8)pIO->getValSInt32("tile_t");
dt.TileBorder[TextML] = (uint8)pIO->getValSInt32("tile_l");
dt.TileBorder[TextMM] = (uint8)pIO->getValSInt32("tile_blank");
dt.TileBorder[TextMR] = (uint8)pIO->getValSInt32("tile_r");
dt.TileBorder[TextBM] = (uint8)pIO->getValSInt32("tile_b");
// get size
rVR.getTextureSizeFromId (dt.BorderIds[TextTL], dt.LeftBorder, dt.TopBorder);
rVR.getTextureSizeFromId (dt.BorderIds[TextBR], dt.RightBorder, dt.BottomBorder);
_DispTypes.push_back(dt);
}
_DispType = (uint8)i;
}
else
{
_DispType = 0;
}
return true;
}
// ***************************************************************************
void CGroupFrame::draw ()
{
if (_DisplayFrame)
{
CViewRenderer &rVR = *CViewRenderer::getInstance();
2010-05-06 00:08:41 +00:00
// get global color
CRGBA col;
if(getModulateGlobalColor())
col.modulateFromColor( _Color, CWidgetManager::getInstance()->getGlobalColor() );
2010-05-06 00:08:41 +00:00
else
col= _Color;
// draw the background
sint xId = 0, yId = 0;
for (yId = 0; yId < 3; yId++)
{
for (xId = 0; xId < 3; xId++)
{
sint32 x = _XReal;
sint32 y = _YReal;
sint32 w, h;
// top
if (yId == 0)
{
y += _HReal-_DispTypes[_DispType].TopBorder;
h = _DispTypes[_DispType].TopBorder;
}
// Middle
else if (yId == 1)
{
y += _DispTypes[_DispType].BottomBorder;
h = _HReal-_DispTypes[_DispType].TopBorder-_DispTypes[_DispType].BottomBorder;
}
// Bottom
else
{
h = _DispTypes[_DispType].BottomBorder;
}
// Left
if (xId == 0)
{
w = _DispTypes[_DispType].LeftBorder;
}
else if (xId == 1)
{
x += _DispTypes[_DispType].LeftBorder;
w = _WReal-_DispTypes[_DispType].LeftBorder-_DispTypes[_DispType].RightBorder;
}
else
{
x += _WReal-_DispTypes[_DispType].RightBorder;
w = _DispTypes[_DispType].RightBorder;
}
// render
uint8 tile = _DispTypes[_DispType].TileBorder[yId*3+xId];
if (tile == 0)
rVR.drawRotFlipBitmap (_RenderLayer, x, y, w, h, 0, false, _DispTypes[_DispType].BorderIds[yId*3+xId], col);
else
rVR.drawRotFlipBitmapTiled (_RenderLayer, x, y, w, h, 0, false, _DispTypes[_DispType].BorderIds[yId*3+xId], tile-1, col);
}
}
}
// draw the components
CInterfaceGroup::draw();
}
// ***************************************************************************
void CGroupFrame::copyOptionFrom(const CGroupFrame &other)
{
CInterfaceGroup::copyOptionFrom(other);
// Copy option only if they were not explicitly defined in xml
if(!_DisplayFrameDefined)
_DisplayFrame = other._DisplayFrame;
if(!_ColorDefined)
_Color = other._Color;
if(!_DispTypeDefined)
_DispType = other._DispType;
}
// ***************************************************************************
void CGroupFrame::setColorAsString(const string & col)
{
_Color = convertColor (col.c_str());
}
// ***************************************************************************
string CGroupFrame::getColorAsString() const
{
return NLMISC::toString(_Color.R) + " " + NLMISC::toString(_Color.G) + " " + NLMISC::toString(_Color.B) + " " + NLMISC::toString(_Color.A);
}