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 "brick_receptacle.h"
28 #include "nel/3d/u_text_context.h"
39 extern UTextContext
*TextContext
;
40 extern UTextContext
*TextContext
;
41 extern TMapIdToFamily FamiliesMap
;
43 //---------------------------------------------------
45 //---------------------------------------------------
46 CBrickReceptacle::CBrickReceptacle(uint id
)
52 //---------------------------------------------------
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 //---------------------------------------------------
69 //---------------------------------------------------
70 CBrickReceptacle::~CBrickReceptacle()
77 //---------------------------------------------------
79 //---------------------------------------------------
80 void CBrickReceptacle::init(uint16 family
, uint numFunc
)
85 _RGBA
= CRGBA(128,128,128,255);
86 _NumFuncLeftClick
= numFunc
;
90 //---------------------------------------------------
92 //---------------------------------------------------
93 void CBrickReceptacle::clear()
103 //---------------------------------------------------
105 //---------------------------------------------------
106 bool CBrickReceptacle::brick( CBrickControl
*brick
)
111 // nlassert( brick );
114 nlwarning("<CBrickReceptacle::brick> : param in NULL, abort");
118 if (brick
->getAssociatedBrick()->Family
== _Family
)
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
);
137 //---------------------------------------------------
139 //---------------------------------------------------
140 bool CBrickReceptacle::family( uint16 family
)
150 TMapIdToFamily::iterator it
= FamiliesMap
.find( family
);
151 if (it
!= FamiliesMap
.end() )
152 texture( (*it
).second
->TextureId
);
156 //-----------------------------------------------
158 // Set some references for the display.
159 //-----------------------------------------------
160 void CBrickReceptacle::ref(float x
, float y
, float w
, float h
)
170 for(TListControl::iterator it
= _Children
.begin(); it
!= _Children
.end(); ++it
)
172 if((*it
)->parent() == this)
175 calculateOrigin(x
, y
, (*it
)->origin());
176 (*it
)->ref(x
, y
, _W_Ref
, _H_Ref
);
181 if ( _Brick
!= NULL
)
183 _Brick
->ref( x
, y
, w
, h
);
189 //---------------------------------------------------
191 //---------------------------------------------------
192 void CBrickReceptacle::display()
197 // draw the brick control if any
200 _Brick
->setPosition(_X
+ _W
/2, _Y
+ _H
/2, _X_Pixel
+ _W_Pixel
/2, _Y_Pixel
+ _H_Pixel
/2 );
205 // draw the slot background
208 Driver
->drawBitmap(_X_Display
, _Y_Display
, _W_Display
, _H_Display
, *_Texture
, true, _RGBA
);
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
);
226 //-----------------------------------------------
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 )
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);