Merge branch '138-toggle-free-look-with-hotkey' into main/gingo-test
[ryzomcore.git] / ryzom / client / src / interface_v3 / view_bitmap_progress.cpp
blobf4f13698c318a96f55b6b1d7e5ba6ef90d15933e
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "stdpch.h"
21 #include "dbview_bar.h"
22 #include "interface_manager.h"
26 using namespace NL3D;
29 CDBViewBar::CDBViewBar : CViewBitmap()
33 /**
34 * parse an xml node and initialize the base view mambers. Must call CViewBase::parse
35 * \param cur : pointer to the xml node to be parsed
36 * \param parentGroup : the parent group of the view
37 * \partam id : a refence to the string that will receive the view ID
38 * \return true if success
40 bool CDBViewBar::parse(xmlNodePtr cur,CInterfaceGroup * parentGroup)
42 if (!CViewBitmap::parse(cur,parentGroup))
44 string tmp = "cannot parse view:"+getId()+", parent:"+parentGroup->getId();
45 nlinfo(tmp.c_str());
46 return false;
50 //try to get the NEEDED specific props
51 CXMLAutoPtr prop= (char*) xmlGetProp( cur, (xmlChar*)"range" );
52 if (prop)
54 _Range.readSInt32(prop,_Id+":range");
56 else
58 string tmp = "cannot getprop:range, view:"+getId()+", parent:"+parentGroup->getId();
59 nlinfo(tmp.c_str());
60 return false;
63 prop = (char*) xmlGetProp( cur, (xmlChar*)"rangemax" );
64 if (prop)
66 _RangeMax.readSInt32(prop,_Id+":rangemax");
68 else
70 string tmp = "cannot getprop:rangemax, view:"+getId()+", parent:"+parentGroup->getId();
71 nlinfo(tmp.c_str());
72 return false;
75 prop = (char*) xmlGetProp( cur, (xmlChar*)"vertical" );
76 if (prop)
77 _Vertical.readBool (prop, _Id+":vertical");
78 else
79 _Vertical.readBool ("false", _Id+":vertical");
81 return true;
84 /**
85 * draw the view
87 void CDBViewBar::draw ()
89 float wBar = (float)_WReal, hBar = (float)_HReal;
90 if (_Vertical.getBool())
92 if (_RangeMax.getSInt32())
93 hBar = _HReal * ( (float)_Range.getSInt32() / (float)_RangeMax.getSInt32() );
94 else
95 hBar = 0.0f;
97 else
99 if (_RangeMax.getSInt32())
100 wBar = _WReal * ( (float)_Range.getSInt32() / (float)_RangeMax.getSInt32() );
101 else
102 wBar = 0.0f;
105 // Backup scissor and create the new scissor to clip the bar correctly.
106 CInterfaceManager *pIM = CInterfaceManager::getInstance();
107 CViewRenderer &rVR = pIM->getViewRenderer();
109 sint32 oldScissorX, oldScissorY, oldScissorW, oldScissorH;
110 rVR.getClipWindow (oldScissorX, oldScissorY, oldScissorW, oldScissorH);
112 sint32 scisX, scisY, scisWidth, scisHeight;
113 scisX = oldScissorX;
114 scisY = oldScissorY;
115 scisWidth = oldScissorW;
116 scisHeight = oldScissorH;
118 //the previous scissor must be taken in account.
119 sint32 xabs = _XReal;
120 sint32 yabs = _YReal;
122 if( xabs > scisX )
123 scisX = xabs;
124 if( yabs > scisY )
125 scisY = yabs;
127 scisWidth = std::min(scisWidth + oldScissorX , (sint32)(xabs + wBar)) - scisX;
128 scisHeight = std::min(scisHeight + oldScissorY , (sint32)(yabs + hBar)) - scisY;
130 rVR.setClipWindow (scisX, scisY, scisWidth, scisHeight);
132 // display progress bitmap
133 //if (_TextureId == -2)
134 // _TextureId = rVR.getTextureIdFromName (_TextureName);
135 rVR.drawRotFlipBitmap (_RenderLayer, _XReal, _YReal,
136 _WReal, _HReal, (uint8)_Rot, _Flip,
137 _TextureId, _Color );
139 // restore old scissor
140 rVR.setClipWindow (oldScissorX, oldScissorY, oldScissorW, oldScissorH);