1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
26 #include "nel/misc/time_nl.h"
28 #include "nel/3d/u_driver.h"
29 #include "nel/3d/u_text_context.h"
31 #include "progress_bar.h"
32 #include "interfaces_manager.h"
41 using namespace NLMISC
;
47 extern UDriver
*Driver
;
48 extern UTextContext
*TextContext
;
51 //-----------------------------------------------
54 //-----------------------------------------------
55 CProgressBar::CProgressBar(uint id
, float x
, float y
, float x_pixel
, float y_pixel
, float w
, float h
, float w_pixel
, float h_pixel
, uint range
)
56 :CControl(id
, x
, y
, x_pixel
, y_pixel
, w
, h
, w_pixel
, h_pixel
)
62 //-----------------------------------------------
64 //-----------------------------------------------
65 void CProgressBar::init( uint32 range
)
73 _SmoothFillRate
= 50; // 1 unit / 50ms
74 _LastUpdateSmooth
= ryzomGetLocalTime ();
78 //-----------------------------------------------
80 //-----------------------------------------------
81 uint32
CProgressBar::setRange( uint32 range
)
86 if (_CurrentPos
> _Range
)
96 //-----------------------------------------------
98 //-----------------------------------------------
99 uint32
CProgressBar::setStep( uint32 step
)
101 uint32 old
= _StepInc
;
107 //-----------------------------------------------
109 //-----------------------------------------------
110 uint32
CProgressBar::setPos( uint32 pos
)
112 uint32 old
= _CurrentPos
;
115 if (_CurrentPos
> _Range
)
117 _CurrentPos
= _Range
;
122 _TempPos
= _CurrentPos
;
129 //-----------------------------------------------
131 //-----------------------------------------------
132 void CProgressBar::display()
134 // compute the temp pos if in smooth mode
137 uint32 nbUnit
= (uint32
)(ryzomGetLocalTime () - _LastUpdateSmooth
) / _SmoothFillRate
;
140 _LastUpdateSmooth
= ryzomGetLocalTime ();
142 uint32 diff
= abs( _TempPos
- _CurrentPos
);
146 if ( _TempPos
< _CurrentPos
)
154 nlassert( _TempPos
== _CurrentPos
);
157 // If the control is hide -> return
163 UTextureFile
*utexture
= CInterfMngr::getTexture( _BackgroundTexture
);
166 Driver
->drawBitmap(_X_Display
, _Y_Display
, _W_Display
, _H_Display
, *utexture
, true, _BackgroundColor
);
169 // calculate _W_Display of the progress bar
170 const float wBar
= _W_Display
* ( static_cast<float>(_TempPos
) / static_cast<float>(_Range
) );
172 // Backup scissor and create the new scissor to clip the bar correctly.
173 CScissor oldScissor
= Driver
->getScissor();
176 float scisX
, scisY
, scisWidth
, scisHeight
;
177 scisX
= oldScissor
.X
;
178 scisY
= oldScissor
.Y
;
179 scisWidth
= oldScissor
.Width
;
180 scisHeight
= oldScissor
.Height
;
182 float xtmp
= _X_Display
+ wBar
;
183 float ytmp
= _Y_Display
+ _H_Display
;
184 float xscistmp
= scisX
+ scisWidth
;
185 float yscistmp
= scisY
+ scisHeight
;
186 if( _X_Display
> scisX
)
188 if( _Y_Display
> scisY
)
190 if( xtmp
< xscistmp
)
191 scisWidth
= xtmp
- scisX
;
193 scisWidth
= xscistmp
- scisX
;
194 if( ytmp
< yscistmp
)
195 scisHeight
= ytmp
- scisY
;
197 scisHeight
= yscistmp
- scisY
;
199 scissor
.init(scisX
, scisY
, scisWidth
, scisHeight
);
200 Driver
->setScissor(scissor
);
202 // display progress bar
203 utexture
= CInterfMngr::getTexture( _ProgressBarTexture
);
204 Driver
->drawBitmap(_X_Display
, _Y_Display
, _W_Display
, _H_Display
, *utexture
, true, _ProgressBarColor
);
206 // restore old scissor
207 Driver
->setScissor(oldScissor
);
210 if ( ! _Text
.empty() )
212 TextContext
->setShaded(_Shadow
);
213 TextContext
->setHotSpot(NL3D::UTextContext::THotSpot::MiddleMiddle
);
214 TextContext
->setColor(_Color
);
215 TextContext
->setFontSize(_FontSize
);
216 TextContext
->printAt(_X_Display
+ _W_Display
/2, _Y_Display
+ _H_Display
/2, _Text
);