Merge branch '138-toggle-free-look-with-hotkey' into main/gingo-test
[ryzomcore.git] / ryzom / client / src / interfaces_manager / scroll_bar.cpp
blob3c5f9b84f10a36bef801f3c80694bbe81950f319
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 "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"
30 /////////////
31 // Externs //
32 /////////////
33 extern NL3D::UDriver *Driver;
37 * default Constructor
39 CScrollBar::CScrollBar(uint id)
40 : CControl(id)
42 init();
46 * Constructor
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)
51 init();
53 _Vertical = vertical;
54 _Parent = ctrl;
56 uint32 wndW,wndH;
57 CInterfMngr::getWindowSize( wndW, wndH);
59 if (wndH == 0)
61 _ButtonDisplaySize = 0;
62 return;
65 if (_Vertical)
66 _ButtonDisplaySize = float(w_pixel) / wndH + w * _H_Ref; // h_button = w_control
67 else
68 _ButtonDisplaySize = float(h_pixel) / wndH + h * _W_Ref; // w_button = h_control
72 void CScrollBar::init()
74 _LeftTextureOn = 2;
75 _LeftTextureOff = 2;
77 _RightTextureOn = 2;
78 _RightTextureOff = 2;
80 _UpTextureOn = 2;
81 _UpTextureOff = 2;
83 _DownTextureOn = 2;
84 _DownTextureOff = 2;
86 _TextureOn = 0;
87 _TextureDisable = 0;
88 _ColorOn = CRGBA(255,255,255,255);
89 _ColorDisable = CRGBA(100,100,100,255);
90 _Enable = true;
91 _Show = false;
97 * display
99 void CScrollBar::display()
101 // If the control is hide -> return
102 if(!_Show)
103 return;
105 if(_Enable)
107 // body
108 Driver->drawBitmap( _X_Display, _Y_Display, _W_Display, _H_Display, *CInterfMngr::getTexture(_TextureOn), true, _ColorOn);
109 // buttons
110 if (_Vertical)
112 // down
113 Driver->drawBitmap( _X_Display, _Y_Display, _W_Display, _ButtonDisplaySize, *CInterfMngr::getTexture( _DownTextureOn ), true, _ColorOn);
114 // up
115 Driver->drawBitmap( _X_Display, _Y_Display + _H_Display - _ButtonDisplaySize, _W_Display, _ButtonDisplaySize , *CInterfMngr::getTexture( _UpTextureOn ), true, _ColorOn);
117 // horizontal
118 else
120 // left
121 Driver->drawBitmap( _X_Display, _Y_Display, _ButtonDisplaySize, _H_Display , *CInterfMngr::getTexture( _LeftTextureOn ), true, _ColorOn);
122 // right
123 Driver->drawBitmap( _X_Display + _W_Display - _ButtonDisplaySize, _Y_Display, _ButtonDisplaySize, _H_Display, *CInterfMngr::getTexture( _RightTextureOn ), true, _ColorOn);
126 //disable
127 else
129 // body
130 Driver->drawBitmap( _X_Display, _Y_Display, _W_Display, _H_Display, *CInterfMngr::getTexture(_TextureDisable), true, _ColorDisable);
131 // buttOffs
132 if (_Vertical)
134 // down
135 Driver->drawBitmap( _X_Display, _Y_Display, _W_Display, _ButtonDisplaySize, *CInterfMngr::getTexture( _DownTextureOff ), true, _ColorDisable);
136 // up
137 Driver->drawBitmap( _X_Display, _Y_Display + _H_Display - _ButtonDisplaySize, _W_Display, _ButtonDisplaySize , *CInterfMngr::getTexture( _UpTextureOff ), true, _ColorDisable);
139 // horizOfftal
140 else
142 // left
143 Driver->drawBitmap( _X_Display, _Y_Display, _ButtonDisplaySize, _H_Display , *CInterfMngr::getTexture( _LeftTextureOff ), true, _ColorDisable);
144 // right
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)
152 // draw the slider
153 // TO DO
158 * click
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 );
174 taken = true;
176 // click into the down arrow
177 if ( y <= (_Y_Display + _ButtonDisplaySize) )
179 dynamic_cast<CScrollableControl*> (_Parent)->scrollV( -1 );
180 taken = true;
183 // SLIDER : TO DO
185 // horizontal
186 else
188 // click into the right arrow
189 if ( x >= (_X_Display + _W_Display - _ButtonDisplaySize) )
191 dynamic_cast<CScrollableControl*> (_Parent)->scrollH( 1 );
192 taken = true;
194 // click into the left arrow
195 if ( x <= (_X_Display + _ButtonDisplaySize) )
197 dynamic_cast<CScrollableControl*> (_Parent)->scrollH( -1 );
198 taken = true;
201 // SLIDER : TO DO
211 * textureOn
213 void CScrollBar::textureOn(uint32 texture)
215 _TextureOn = texture;
216 }// textureOn //
220 * textureDisable
222 void CScrollBar::textureDisable(uint32 texture)
224 _TextureDisable = texture;
225 }// textureDisable //
229 * colorOn
231 void CScrollBar::colorOn(const NLMISC::CRGBA &color)
233 _ColorOn = color;
234 }// colorOn //
237 * colorDisable
239 void CScrollBar::colorDisable(const NLMISC::CRGBA &color)
241 _ColorDisable = color;
242 }// colorDisable //
246 * enable
248 bool CScrollBar::enable()
250 return _Enable;
251 }// enable //
254 * enable
256 void CScrollBar::enable(bool e)
258 _Enable = e;
259 }// enable //
264 * size
266 float CScrollBar::size() const
268 if (_Vertical)
269 return _W_Display;
270 else
271 return _H_Display;
272 }// size //