00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "guicontainer.h"
00021
00022 #include "texture.h"
00023
00024 GLuint GUIContainer::_uiTexture = 0;
00025 GLuint GUIContainer::_uiNumberContainer = 0;
00026
00027
00028 GUIContainer::GUIContainer(
00029 const int & rciX,
00030 const int & rciY,
00031 const uint & rcuiW,
00032 const uint & rcuiH )
00033 {
00034 OPENCITY_DEBUG( "New GUI container" );
00035
00036 SDL_Surface* pScreen = SDL_GetVideoSurface();
00037 this->uiWinWidth = pScreen->w;
00038 this->uiWinHeight = pScreen->h;
00039
00040 this->iX = rciX;
00041 this->iY = rciY;
00042 this->uiWidth = rcuiW;
00043 this->uiHeight = rcuiH;
00044
00045 ++GUIContainer::_uiNumberContainer;
00046
00047
00048
00049
00050 }
00051
00052
00053
00054 GUIContainer::~GUIContainer()
00055 {
00056 OPENCITY_DEBUG( "GUI container deleted" );
00057
00058 std::vector<GUIMain*>::size_type stvector;
00059 GUIMain* pguimain;
00060
00061
00062 for ( stvector = 0; stvector < this->vectorpguimain.size(); stvector++ ) {
00063 if ( (pguimain = vectorpguimain[ stvector ]) != NULL )
00064 pguimain->SetContainer( NULL );
00065 }
00066
00067
00068
00069 this->vectorpguimain.clear();
00070
00071
00072 if (GUIContainer::_uiNumberContainer-- == 1) {
00073
00074 if (glIsTexture( GUIContainer::_uiTexture ) == GL_TRUE) {
00075 glDeleteTextures( 1, &GUIContainer::_uiTexture );
00076 GUIContainer::_uiTexture = 0;
00077 }
00078 }
00079 }
00080
00081
00082
00083 const uint
00084 GUIContainer::Add(
00085 GUIMain* const pguimain )
00086 {
00087
00088 pguimain->SetContainer( this );
00089 this->vectorpguimain.push_back( pguimain );
00090
00091
00092 return this->vectorpguimain.size();
00093 }
00094
00095
00096
00097 const uint
00098 GUIContainer::GetNumber() const
00099 {
00100 return this->vectorpguimain.size();
00101 }
00102
00103
00104
00105 void
00106 GUIContainer::GetWinWH(
00107 int & riWinW,
00108 int & riWinH ) const
00109 {
00110 riWinW = this->uiWinWidth;
00111 riWinH = this->uiWinHeight;
00112 }
00113
00114
00115
00116 const uint
00117 GUIContainer::GetClick() const
00118 {
00119 static std::vector<GUIMain*>::size_type stvector;
00120 static GUIMain* pguimain;
00121
00122
00123 if ( IsSet( OC_GUIMAIN_VISIBLE ) == false )
00124 return 0;
00125
00126
00127
00128 for ( stvector = 0; stvector < this->vectorpguimain.size(); stvector++ ) {
00129 if ( (pguimain = vectorpguimain[ stvector ]) != NULL )
00130 if ( pguimain->IsSet( OC_GUIMAIN_CLICKED | OC_GUIMAIN_MOUSEOVER ) == true )
00131 return ++stvector;
00132 }
00133
00134
00135 return 0;
00136 }
00137
00138
00139
00140 void
00141 GUIContainer::Set(
00142 const uint & rcuiIndex,
00143 const OC_UBYTE & rcubAttribute ) const
00144 {
00145 assert( rcuiIndex <= vectorpguimain.size() );
00146
00147 vectorpguimain[ rcuiIndex-1 ]->Set( rcubAttribute );
00148 }
00149
00150
00151
00152 void
00153 GUIContainer::ResetAttribute(
00154 const OC_UBYTE & rcubAttr ) const
00155 {
00156 std::vector<GUIMain*>::size_type stvector;
00157 GUIMain* pguimain;
00158
00159
00160 for ( stvector = 0; stvector < this->vectorpguimain.size(); stvector++ ) {
00161 if ( (pguimain = vectorpguimain[ stvector ]) != NULL )
00162 pguimain->Unset( rcubAttr );
00163 }
00164 }
00165
00166
00167
00168 void
00169 GUIContainer::Display() const
00170 {
00171 static std::vector<GUIMain*>::size_type stvector;
00172 static GUIMain* pguimain;
00173
00174
00175 if ( IsSet( OC_GUIMAIN_VISIBLE ) == false )
00176 return;
00177
00178
00179 glMatrixMode( GL_PROJECTION );
00180 glPushMatrix();
00181 glLoadIdentity();
00182
00183 gluOrtho2D( 0, uiWinWidth-1, 0, uiWinHeight-1 );
00184
00185
00186 glMatrixMode( GL_MODELVIEW );
00187 glPushMatrix();
00188 glLoadIdentity();
00189 glTranslatef( iX, iY, 0.0 );
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 for ( stvector = 0; stvector < this->vectorpguimain.size(); stvector++ ) {
00211 if ( (pguimain = vectorpguimain[ stvector ]) != NULL )
00212 pguimain->Display();
00213 }
00214
00215 glPopMatrix();
00216 glMatrixMode( GL_PROJECTION );
00217 glPopMatrix();
00218 glMatrixMode( GL_MODELVIEW );
00219 }
00220
00221
00222
00223 void
00224 GUIContainer::uiKeyboard( const SDL_KeyboardEvent & rcsSDLKeyboardEvent )
00225 {}
00226
00227
00228
00229 void
00230 GUIContainer::uiMouseMotion( const SDL_MouseMotionEvent & rcsSDLMouseMotionEvent )
00231 {
00232 static std::vector<GUIMain*>::size_type stvector;
00233 static GUIMain* pguimain;
00234
00235
00236 if ( IsSet( OC_GUIMAIN_VISIBLE ) == false )
00237 return;
00238
00239
00240 for ( stvector = 0; stvector < this->vectorpguimain.size(); stvector++ ) {
00241 if ( (pguimain = vectorpguimain[ stvector ]) != NULL )
00242 pguimain->uiMouseMotion( rcsSDLMouseMotionEvent );
00243 }
00244 }
00245
00246
00247
00248 void
00249 GUIContainer::uiMouseButton( const SDL_MouseButtonEvent & rcsSDLMouseButtonEvent )
00250 {
00251 static std::vector<GUIMain*>::size_type stvector;
00252 static GUIMain* pguimain;
00253
00254
00255 if ( IsSet( OC_GUIMAIN_VISIBLE ) == false )
00256 return;
00257
00258
00259 for ( stvector = 0; stvector < this->vectorpguimain.size(); stvector++ ) {
00260 if ( (pguimain = vectorpguimain[ stvector ]) != NULL )
00261 pguimain->uiMouseButton( rcsSDLMouseButtonEvent );
00262 }
00263 }
00264
00265
00266
00267 void
00268 GUIContainer::uiExpose( const SDL_ExposeEvent & rcsSDLExposeEvent )
00269 {
00270 this->Display();
00271 }
00272
00273
00274
00275 void
00276 GUIContainer::uiResize( const SDL_ResizeEvent & rcsSDLResizeEvent )
00277 {
00278 this->uiWinWidth = rcsSDLResizeEvent.w;
00279 this->uiWinHeight = rcsSDLResizeEvent.h;
00280 }
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315