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/>.
25 #include "nel/3d/u_driver.h"
26 #include "nel/3d/u_text_context.h"
28 #include "interfaces_manager.h"
29 #include "casting_bar.h"
37 using namespace NLMISC
;
43 extern UDriver
*Driver
;
44 extern UTextContext
*TextContext
;
47 //-----------------------------------------------
49 //-----------------------------------------------
50 void CCastingBar::display()
52 _Time
= ryzomGetLocalTime ();
57 const uint32 diff
= (uint32
)(_Time
- _LastChangePosTime
)/100; // we works in 1/10e s (10 units = 1s) and T1 is in 1/1000 s
62 if (diff
< _CurrentPos
)
63 setPos( _CurrentPos
- diff
);
67 _LastChangePosTime
= _Time
;
72 _LastChangePosTime
= _Time
;
75 // compute the temp pos if in smooth mode
78 uint32 nbUnit
= (uint32
)(_Time
- _LastUpdateSmooth
) / _SmoothFillRate
;
81 _LastUpdateSmooth
= _Time
;
83 uint32 diff
= abs( _TempPos
- _CurrentPos
);
87 if ( _TempPos
< _CurrentPos
)
95 nlassert( _TempPos
== _CurrentPos
);
99 if (_AutoHide
&& _TempPos
== 0)
105 // If the control is hide -> return
111 UTextureFile
*utexture
= CInterfMngr::getTexture( _BackgroundTexture
);
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();
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
)
136 if( _Y_Display
> scisY
)
138 if( xtmp
< xscistmp
)
139 scisWidth
= xtmp
- scisX
;
141 scisWidth
= xscistmp
- scisX
;
142 if( ytmp
< yscistmp
)
143 scisHeight
= ytmp
- scisY
;
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
);
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
);