Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / client / src / interfaces_manager / casting_bar.cpp
blob5e46b416de70eba1fb4fac72b8900936b0ffe2b1
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 //////////////
22 // Includes //
23 //////////////
24 // 3D Interface.
25 #include "nel/3d/u_driver.h"
26 #include "nel/3d/u_text_context.h"
27 // Client
28 #include "interfaces_manager.h"
29 #include "casting_bar.h"
33 ///////////
34 // Using //
35 ///////////
36 using namespace std;
37 using namespace NLMISC;
38 using namespace NL3D;
40 /////////////
41 // Externs //
42 /////////////
43 extern UDriver *Driver;
44 extern UTextContext *TextContext;
47 //-----------------------------------------------
48 // display :
49 //-----------------------------------------------
50 void CCastingBar::display()
52 _Time = ryzomGetLocalTime ();
54 if (_Running)
56 // compute the pos
57 const uint32 diff = (uint32)(_Time - _LastChangePosTime)/100; // we works in 1/10e s (10 units = 1s) and T1 is in 1/1000 s
59 if (diff != 0)
61 // set the new pos
62 if (diff < _CurrentPos )
63 setPos( _CurrentPos - diff );
64 else
65 setPos(0);
67 _LastChangePosTime = _Time;
70 else
72 _LastChangePosTime = _Time;
75 // compute the temp pos if in smooth mode
76 if (_Smooth)
78 uint32 nbUnit = (uint32)(_Time - _LastUpdateSmooth) / _SmoothFillRate;
79 if (nbUnit > 0)
81 _LastUpdateSmooth = _Time;
83 uint32 diff = abs( _TempPos - _CurrentPos );
84 if (diff < nbUnit)
85 nbUnit = diff;
87 if ( _TempPos < _CurrentPos )
88 _TempPos += nbUnit;
89 else
90 _TempPos -= nbUnit;
93 else
95 nlassert( _TempPos == _CurrentPos );
98 // check auto hide
99 if (_AutoHide && _TempPos == 0)
101 show( false );
102 stop();
105 // If the control is hide -> return
106 if(!_Show)
107 return;
110 // draw background
111 UTextureFile *utexture = CInterfMngr::getTexture( _BackgroundTexture );
112 if(utexture)
114 Driver->drawBitmap(_X_Display, _Y_Display, _W_Display, _H_Display, *utexture, true, _BackgroundColor);
117 // calculate _W_Display of the progress bar
118 const float wBar = _W_Display * ( static_cast<float>(_TempPos) / static_cast<float>(_Range) );
120 // Backup scissor and create the new scissor to clip the bar correctly.
121 CScissor oldScissor = Driver->getScissor();
122 CScissor scissor;
124 float scisX, scisY, scisWidth, scisHeight;
125 scisX = oldScissor.X;
126 scisY = oldScissor.Y;
127 scisWidth = oldScissor.Width;
128 scisHeight = oldScissor.Height;
130 float xtmp = _X_Display + wBar;
131 float ytmp = _Y_Display + _H_Display;
132 float xscistmp = scisX + scisWidth;
133 float yscistmp = scisY + scisHeight;
134 if( _X_Display > scisX )
135 scisX = _X_Display;
136 if( _Y_Display > scisY )
137 scisY = _Y_Display;
138 if( xtmp < xscistmp )
139 scisWidth = xtmp - scisX;
140 else
141 scisWidth = xscistmp - scisX;
142 if( ytmp < yscistmp )
143 scisHeight = ytmp - scisY;
144 else
145 scisHeight = yscistmp - scisY;
147 scissor.init(scisX, scisY, scisWidth, scisHeight);
148 Driver->setScissor(scissor);
150 // display progress bar
151 utexture = CInterfMngr::getTexture( _ProgressBarTexture );
152 Driver->drawBitmap(_X_Display, _Y_Display, _W_Display, _H_Display, *utexture, true, _ProgressBarColor);
154 // restore old scissor
155 Driver->setScissor(oldScissor);
157 // display text
158 if ( ! _Text.empty() )
160 TextContext->setShaded(_Shadow);
161 TextContext->setHotSpot(NL3D::UTextContext::THotSpot::MiddleMiddle);
162 TextContext->setColor(_Color);
163 TextContext->setFontSize(_FontSize);
164 TextContext->printAt(_X_Display + _W_Display/2, _Y_Display + _H_Display/2, _Text);
168 }// display //