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/>.
21 #include "nel/3d/u_driver.h"
22 #include "interfaces_manager.h"
23 #include "scroll_bar.h"
24 #include "scrollable_control.h"
27 #include "interf_list.h"
33 extern NL3D::UDriver
*Driver
;
39 CScrollBar::CScrollBar(uint id
)
48 CScrollBar::CScrollBar(uint id
, float x
, float y
, float x_pixel
, float y_pixel
, float w
, float h
, float w_pixel
, float h_pixel
, bool vertical
, CScrollableControl
*ctrl
)
49 : CControl(id
, x
, y
, x_pixel
, y_pixel
, w
, h
, w_pixel
, h_pixel
)
57 CInterfMngr::getWindowSize( wndW
, wndH
);
61 _ButtonDisplaySize
= 0;
66 _ButtonDisplaySize
= float(w_pixel
) / wndH
+ w
* _H_Ref
; // h_button = w_control
68 _ButtonDisplaySize
= float(h_pixel
) / wndH
+ h
* _W_Ref
; // w_button = h_control
72 void CScrollBar::init()
88 _ColorOn
= CRGBA(255,255,255,255);
89 _ColorDisable
= CRGBA(100,100,100,255);
99 void CScrollBar::display()
101 // If the control is hide -> return
108 Driver
->drawBitmap( _X_Display
, _Y_Display
, _W_Display
, _H_Display
, *CInterfMngr::getTexture(_TextureOn
), true, _ColorOn
);
113 Driver
->drawBitmap( _X_Display
, _Y_Display
, _W_Display
, _ButtonDisplaySize
, *CInterfMngr::getTexture( _DownTextureOn
), true, _ColorOn
);
115 Driver
->drawBitmap( _X_Display
, _Y_Display
+ _H_Display
- _ButtonDisplaySize
, _W_Display
, _ButtonDisplaySize
, *CInterfMngr::getTexture( _UpTextureOn
), true, _ColorOn
);
121 Driver
->drawBitmap( _X_Display
, _Y_Display
, _ButtonDisplaySize
, _H_Display
, *CInterfMngr::getTexture( _LeftTextureOn
), true, _ColorOn
);
123 Driver
->drawBitmap( _X_Display
+ _W_Display
- _ButtonDisplaySize
, _Y_Display
, _ButtonDisplaySize
, _H_Display
, *CInterfMngr::getTexture( _RightTextureOn
), true, _ColorOn
);
130 Driver
->drawBitmap( _X_Display
, _Y_Display
, _W_Display
, _H_Display
, *CInterfMngr::getTexture(_TextureDisable
), true, _ColorDisable
);
135 Driver
->drawBitmap( _X_Display
, _Y_Display
, _W_Display
, _ButtonDisplaySize
, *CInterfMngr::getTexture( _DownTextureOff
), true, _ColorDisable
);
137 Driver
->drawBitmap( _X_Display
, _Y_Display
+ _H_Display
- _ButtonDisplaySize
, _W_Display
, _ButtonDisplaySize
, *CInterfMngr::getTexture( _UpTextureOff
), true, _ColorDisable
);
143 Driver
->drawBitmap( _X_Display
, _Y_Display
, _ButtonDisplaySize
, _H_Display
, *CInterfMngr::getTexture( _LeftTextureOff
), true, _ColorDisable
);
145 Driver
->drawBitmap( _X_Display
+ _W_Display
- _ButtonDisplaySize
, _Y_Display
, _ButtonDisplaySize
, _H_Display
, *CInterfMngr::getTexture( _RightTextureOff
), true, _ColorDisable
);
149 // draw the scroll bar body (arrows + bar)
160 void CScrollBar::click(float x
, float y
, bool &taken
)
163 if( _Enable
&& (!taken
))
165 // click into the control
166 if ( (x
>= _X_Display
) && ( x
<= (_X_Display
+ _W_Display
) ) && (y
>= _Y_Display
) && (y
<= (_Y_Display
+_H_Display
) ) )
168 if ( _Vertical
== true)
170 // click into the upper arrow
171 if ( y
>= (_Y_Display
+ _H_Display
- _ButtonDisplaySize
) )
173 dynamic_cast<CScrollableControl
*> (_Parent
)->scrollV( 1 );
176 // click into the down arrow
177 if ( y
<= (_Y_Display
+ _ButtonDisplaySize
) )
179 dynamic_cast<CScrollableControl
*> (_Parent
)->scrollV( -1 );
188 // click into the right arrow
189 if ( x
>= (_X_Display
+ _W_Display
- _ButtonDisplaySize
) )
191 dynamic_cast<CScrollableControl
*> (_Parent
)->scrollH( 1 );
194 // click into the left arrow
195 if ( x
<= (_X_Display
+ _ButtonDisplaySize
) )
197 dynamic_cast<CScrollableControl
*> (_Parent
)->scrollH( -1 );
213 void CScrollBar::textureOn(uint32 texture
)
215 _TextureOn
= texture
;
222 void CScrollBar::textureDisable(uint32 texture
)
224 _TextureDisable
= texture
;
225 }// textureDisable //
231 void CScrollBar::colorOn(const NLMISC::CRGBA
&color
)
239 void CScrollBar::colorDisable(const NLMISC::CRGBA
&color
)
241 _ColorDisable
= color
;
248 bool CScrollBar::enable()
256 void CScrollBar::enable(bool e
)
266 float CScrollBar::size() const