Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / client / src / interfaces_manager / brick_receptacle.cpp
blob9ec31b1b83065ef737fbd0699ca2732e94cf4ce0
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"
22 /////////////
23 // Include //
24 /////////////
25 // Client
26 #include "brick_receptacle.h"
27 // 3D Interface.
28 #include "nel/3d/u_text_context.h"
31 ///////////
32 // Using //
33 ///////////
34 using namespace NL3D;
36 /////////////
37 // Externs //
38 /////////////
39 extern UTextContext *TextContext;
40 extern UTextContext *TextContext;
41 extern TMapIdToFamily FamiliesMap;
43 //---------------------------------------------------
44 // Constructor :
45 //---------------------------------------------------
46 CBrickReceptacle::CBrickReceptacle(uint id)
48 init();
49 } // Constructor //
52 //---------------------------------------------------
53 // Constructor :
54 //---------------------------------------------------
55 CBrickReceptacle::CBrickReceptacle(uint id, float x, float y, float x_pixel, float y_pixel, float w, float h, float w_pixel, float h_pixel,
56 uint texture, const CRGBA &rgba, uint16 family, uint numFunc )
57 :CControl(id, x, y, x_pixel, y_pixel, w, h, w_pixel, h_pixel), CBitmapBase( texture, rgba)
59 init( family, numFunc );
61 TMapIdToFamily::iterator it = FamiliesMap.find( family );
62 if (it != FamiliesMap.end() )
63 this->texture( (*it).second->TextureId );
67 //---------------------------------------------------
68 // Destructor :
69 //---------------------------------------------------
70 CBrickReceptacle::~CBrickReceptacle()
72 clear();
73 } // Destructor //
77 //---------------------------------------------------
78 // init :
79 //---------------------------------------------------
80 void CBrickReceptacle::init(uint16 family, uint numFunc)
82 _Family = family;
83 _Brick = NULL;
84 _Locked = false;
85 _RGBA = CRGBA(128,128,128,255);
86 _NumFuncLeftClick = numFunc;
87 } // init //
90 //---------------------------------------------------
91 // init :
92 //---------------------------------------------------
93 void CBrickReceptacle::clear()
95 if (_Brick != NULL)
97 delete _Brick;
98 _Brick = NULL;
100 } // clear //
103 //---------------------------------------------------
104 // brick :
105 //---------------------------------------------------
106 bool CBrickReceptacle::brick( CBrickControl *brick)
108 if (_Locked )
109 return false;
111 // nlassert( brick );
112 if ( !brick )
114 nlwarning("<CBrickReceptacle::brick> : param in NULL, abort");
115 return false;
118 if (brick->getAssociatedBrick()->Family == _Family)
120 clear();
122 _Brick = new CBrickControl( *brick );
124 _Brick->ref( _X_Ref, _Y_Ref, _W_Ref, _H_Ref );
125 _Brick->hotSpot(THotSpot::HS_MM);
126 _Brick->origin(THotSpot::HS_MM);
128 return true;
130 else
131 return false;
133 } // brick //
137 //---------------------------------------------------
138 // family :
139 //---------------------------------------------------
140 bool CBrickReceptacle::family( uint16 family)
142 if (_Brick != NULL)
143 return false;
144 else
146 _Family = family;
147 return true;
150 TMapIdToFamily::iterator it = FamiliesMap.find( family );
151 if (it != FamiliesMap.end() )
152 texture( (*it).second->TextureId );
153 } // family //
156 //-----------------------------------------------
157 // ref :
158 // Set some references for the display.
159 //-----------------------------------------------
160 void CBrickReceptacle::ref(float x, float y, float w, float h)
162 _X_Ref = x;
163 _Y_Ref = y;
164 _W_Ref = w;
165 _H_Ref = h;
167 calculateDisplay();
169 // Update chidren.
170 for(TListControl::iterator it = _Children.begin(); it != _Children.end(); ++it)
172 if((*it)->parent() == this)
174 float x, y;
175 calculateOrigin(x, y, (*it)->origin());
176 (*it)->ref(x, y, _W_Ref, _H_Ref);
180 // update brick
181 if ( _Brick != NULL )
183 _Brick->ref( x, y, w, h);
189 //---------------------------------------------------
190 // display :
191 //---------------------------------------------------
192 void CBrickReceptacle::display()
194 if (!_Show)
195 return;
197 // draw the brick control if any
198 if (_Brick != NULL)
200 _Brick->setPosition(_X + _W/2, _Y + _H/2, _X_Pixel + _W_Pixel/2, _Y_Pixel + _H_Pixel/2 );
201 _Brick->display();
203 else
205 // draw the slot background
206 if( _Texture )
208 Driver->drawBitmap(_X_Display, _Y_Display, _W_Display, _H_Display, *_Texture, true, _RGBA);
210 else
212 // Draw a quad
213 Driver->drawQuad(_X_Display, _Y_Display, _X_Display+_W_Display, _Y_Display+_H_Display, CRGBA(255,0,255));
214 // Draw the debug msg.
215 TextContext->setShaded(true);
216 TextContext->setFontSize(10);
217 TextContext->setColor(CRGBA(255,255,255));
218 TextContext->setHotSpot(UTextContext::BottomLeft);
219 TextContext->printfAt(_X_Display, _Y_Display, "%d Miss", texture);
222 } // display //
226 //-----------------------------------------------
227 // click :
228 // Manage the click of the mouse for the control.
229 //-----------------------------------------------
230 void CBrickReceptacle::click(float x, float y, bool &taken)
232 // If the button is enabled and taken is false
233 if( taken == true || _Show == false || _Locked == true )
234 return;
236 // test click ccordinates
237 if(x>=_X_Display && x<=(_X_Display+_W_Display) && y>=_Y_Display && y<=(_Y_Display+_H_Display))
239 if ( _NumFuncLeftClick != 0)
241 CInterfMngr::runFuncCtrl( _NumFuncLeftClick, id(), this);
243 else
245 clear();
247 taken = true;
249 }// click //