00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "ExCWindowObject.h"
00024
00025
00026
00027 ExCWindowObject::ExCWindowObject(void)
00028 {
00029 Guard(ExCWindowObject::ExCWindowObject(void))
00030 Init();
00031
00032 UnGuard
00033 }
00034
00035 ExCWindowObject::ExCWindowObject(ExCVec2D Size)
00036 {
00037 Guard(ExCWindowObject::ExCWindowObject(ExCVec2D Size))
00038 Init();
00039 SetWindowSize(Size);
00040 SetOldWindowSize(Size);
00041 UnGuard
00042 }
00043
00044 ExCWindowObject::ExCWindowObject(ExCVec2D Size,ExCVec2D Position)
00045 {
00046 Guard(ExCWindowObject::ExCWindowObject(ExCVec2D Size,ExCVec2D Position))
00047 Init();
00048 SetPosition(Position);
00049 SetOldPosition(Position);
00050 SetWindowSize(Size);
00051 SetOldWindowSize(Size);
00052 UnGuard
00053 }
00054
00055 ExCWindowObject::ExCWindowObject(ExCVec2D Size,ExCVec2D Position,std::string Title)
00056 {
00057 Guard(ExCWindowObject::ExCWindowObject(ExCVec2D Size,ExCVec2D Position,std::string Title))
00058 Init();
00059 SetWindowTitle(Title);
00060 SetPosition(Position);
00061 SetOldPosition(Position);
00062 SetWindowSize(Size);
00063 SetOldWindowSize(Size);
00064 UnGuard
00065 }
00066 ExCWindowObject::~ExCWindowObject(void)
00067 {
00068 }
00069
00070
00071 void ExCWindowObject::Init(void)
00072 {
00073 Guard(void ExCWindowObject::Init(void))
00074 SetName("ExCWindowObject");
00075 SetType(typeid(this).name());
00076 m_ShowWindow=true;
00077 m_Blending=false;
00078 m_RequestFocus=false;
00079 m_CurrentObjectFocus=NULL;
00080 m_LastObjectFocus=NULL;
00081
00082 ManagerTexture=NULL;
00083 ManagerWindow=NULL;
00084
00085 m_Parent=NULL;
00086
00087 m_ShowWindowTitle=false;
00088 m_WindowTitle="ExCWindowObject";
00089 m_WindowOldTitle="ExCWindowObject";
00090 m_WindowTitleColor.SetValue(0.1f,0.1f,0.1f);
00091
00092 m_WindowSize.SetValue(240,320);
00093 m_OldSize.SetValue(240,320);
00094 m_TitleBarSize=20;
00095 m_OldPosition.SetValue(0.0f,0.0f);
00096 m_OldMousePosition.SetValue(0,0);
00097 m_Position.SetValue(0,0);
00098
00099 m_Blending=false;
00100 m_BackroundBlending=0.5f;
00101 m_BackroundColor.SetValue(1.0f,1.0f,1.0f);
00102
00103 m_BorderColor.SetValue(0.6f,0.6f,0.6f);
00104 m_BorderSize=1.0f;
00105 m_ShowBorder=true;
00106
00107 m_BackroundIsTexturing1=false;
00108 m_BackroundTexture1="NONE";
00109 m_BackroundIsTexturing2=false;
00110 m_BackroundTexture2="NONE";
00111 m_TextureIsMouving=false;
00112 m_TextureMouvingVec.SetValue(0.0f,0.0f);
00113
00114 m_CanMouve=false;
00115 m_Mouving=false;
00116 m_Reduced=false;
00117 m_Maximized=false;
00118 m_ShowWindow=true;
00119 m_Active=false;
00120
00121 m_RequestFocus=false;
00122 m_LastObjectFocus=NULL;
00123 m_CurrentObjectFocus=NULL;
00124 m_ObjectRequestFocus=NULL;
00125
00126 UnGuard
00127 }
00128
00129
00130
00131
00132 void ExCWindowObject::Draw(void)
00133 {
00134 Guard(void ExCWindowObject::Draw(void))
00135 ExNihilo::EnterOrthoMode();
00136 glPushAttrib(GL_ALL_ATTRIB_BITS);
00137 glDisable(GL_LIGHTING);
00138 if(m_ShowWindow)
00139 {
00140
00141
00142
00143 float TabTextures[8],TabVertices[8];
00144
00145 TabTextures[0]=0;TabTextures[1]=1;
00146 TabTextures[2]=0;TabTextures[3]=0;
00147 TabTextures[4]=1;TabTextures[5]=0;
00148 TabTextures[6]=1;TabTextures[7]=1;
00149 if(m_Blending)
00150 {
00151 glDisable(GL_LIGHTING);
00152 glEnable(GL_BLEND);
00153 glEnable(GL_ALPHA);
00154 glBlendFunc(GL_ONE,GL_ONE);
00155 glEnable(GL_ALPHA_TEST);
00156 glAlphaFunc(GL_GREATER,0);
00157 glDisable(GL_DEPTH_TEST);
00158 glColor4f(m_BackroundColor.GetX(),m_BackroundColor.GetY(),m_BackroundColor.GetZ(),m_BackroundBlending);
00159 }else glColor3f(m_BackroundColor.GetX(),m_BackroundColor.GetY(),m_BackroundColor.GetZ());
00160
00161 TabVertices[0]=m_Position.GetX();TabVertices[1]=m_Position.GetY();
00162 TabVertices[2]=m_Position.GetX();TabVertices[3]=m_Position.GetY()+m_WindowSize.GetY();
00163 TabVertices[4]=m_Position.GetX()+m_WindowSize.GetX();TabVertices[5]=m_Position.GetY()+m_WindowSize.GetY();
00164 TabVertices[6]=m_Position.GetX()+m_WindowSize.GetX();TabVertices[7]=m_Position.GetY();
00165
00166 if(m_TextureIsMouving)
00167 {
00168 glMatrixMode(GL_TEXTURE);
00169 glTranslatef(m_TextureMouvingVec.GetX()*glutGet(GLUT_ELAPSED_TIME),m_TextureMouvingVec.GetY()*glutGet(GLUT_ELAPSED_TIME),0.0f);
00170 glMatrixMode(GL_MODELVIEW);
00171 }
00172
00173 if(m_BackroundIsTexturing1)
00174 {
00175 ManagerTexture->SetTexture(1,m_BackroundTexture1);
00176 glTexCoordPointer(2,GL_FLOAT,0,TabTextures);
00177 }
00178 if(m_BackroundIsTexturing2)
00179 {
00180 ManagerTexture->SetTexture(0,m_BackroundTexture2);
00181 glTexCoordPointer(2,GL_FLOAT,0,TabTextures);
00182 }
00183
00184 glColor3f(m_BackroundColor.GetX(),m_BackroundColor.GetY(),m_BackroundColor.GetZ());
00185 glEnableClientState(GL_VERTEX_ARRAY);
00186 glVertexPointer(2,GL_FLOAT,0,TabVertices);
00187 glDrawArrays( GL_QUADS, 0, 4 );
00188
00189 if(m_BackroundIsTexturing1)ManagerTexture->ResetMultitexture();
00190
00191 if(m_TextureIsMouving)
00192 {
00193 glMatrixMode(GL_TEXTURE);
00194 glLoadIdentity();
00195 glMatrixMode(GL_MODELVIEW);
00196 }
00197 if(m_Blending)
00198 {
00199 glDisable(GL_BLEND);
00200 glDisable(GL_ALPHA);
00201 glEnable(GL_DEPTH_TEST);
00202 }
00203
00204
00205
00206 if(m_ShowBorder)
00207 {
00208 glColor3f(m_BorderColor.GetX(),m_BorderColor.GetY(),m_BorderColor.GetZ());
00209 glBegin(GL_LINE_STRIP);
00210 glVertex2f(m_Position.GetX()-1,m_Position.GetY()+1);
00211 glVertex2f(m_Position.GetX()+m_WindowSize.GetX()+1,m_Position.GetY()+1);
00212 glVertex2f(m_Position.GetX()+m_WindowSize.GetX()+1,m_Position.GetY()+m_WindowSize.GetY());
00213 glVertex2f(m_Position.GetX()-1,m_Position.GetY()+m_WindowSize.GetY());
00214 glVertex2f(m_Position.GetX()-1,m_Position.GetY()+1);
00215 glEnd();
00216 }
00217 if(m_ShowWindowTitle)
00218 {
00219 glColor3f(m_WindowTitleColor.GetX(),m_WindowTitleColor.GetY(),m_WindowTitleColor.GetZ());
00220 ExNihilo::WriteToScreen(m_Position.GetX()+5,m_Position.GetY()+5+m_WindowSize.GetY()/2,m_WindowTitle);
00221 }
00222
00223
00224
00225 for(unsigned int i=0;i<m_VecWindowObject.size();i++)
00226 {
00227
00228 m_VecWindowObject.at(i)->Draw();
00229 }
00230 }
00231 glPopAttrib();
00232 ExNihilo::LeaveOrthoMode();
00233 UnGuard
00234 }
00235
00236 void ExCWindowObject::AddObjectControl(ExCWindowObject *object)
00237 {
00238 Guard(void ExCWindowObject::AddObjectControl(ExCWindowObject *object))
00239 object->SetParrent(this);
00240 object->SetManagerTexture(ManagerTexture);
00241 object->SetManagerWindow(ManagerWindow);
00242 object->SetPosition(m_Position+object->GetPosition());
00243 m_VecWindowObject.push_back(object);
00244 UnGuard
00245 }
00246
00247 void ExCWindowObject::SetPosition(ExCVec2D Position)
00248 {
00249 Guard(void ExCWindowObject::SetPosition(ExCVec2D Position))
00250 m_OldPosition=m_Position;
00251 m_Position=Position;
00252 UnGuard
00253 }
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 ExCAction ExCWindowObject::InputCommand(ExCCommand Command)
00277 {
00278 Guard(ExCAction ExCWindowObject::InputCommand(ExCCommand Command))
00279
00280
00281 for(unsigned int i=0;i<m_VecWindowObject.size();i++)
00282 {
00283
00284 ExCVec2D ObjPos(Command.m_MousePosx,Command.m_MousePosy);
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 if(m_VecWindowObject.at(i)->PointInWindow(ExCVec2D(Command.m_MousePosx,Command.m_MousePosy)))
00296 {
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 return InputAction(m_VecWindowObject.at(i)->InputCommand(Command));
00320 }
00321
00322 }
00323
00324 switch(Command.m_Command)
00325 {
00326 case MOUSE_LEFT_BUTTON_DOWN:
00327 if (m_CanMouve)
00328 {
00329 return MOUVE_OBJECT_WINDOW;
00330 }
00331 break;
00332 }
00333
00334 return NOTHING;
00335 UnGuard
00336 }
00337
00338 ExCAction ExCWindowObject::InputAction(ExCAction Action)
00339 {
00340 Guard(ExCAction ExCWindowObject::InputAction(ExCAction Action))
00341 switch(Action.m_Action)
00342 {
00343 case REQUEST_FOCUS_OBJECT_WINDOW:
00344 m_ObjectRequestFocus=m_CurrentObjectFocus;
00345 break;
00346 case RELEASE_FOCUS_OBJECT_WINDOW:
00347 m_ObjectRequestFocus=NULL;
00348 break;
00349 default :
00350 return Action;
00351 }
00352 if(Action.m_NextAction){return *Action.m_NextAction;}
00353 else{return NOTHING;}
00354 UnGuard
00355 }
00356
00357 bool ExCWindowObject::PointInWindow(ExCVec2D point)
00358 {
00359 Guard(bool ExCWindowObject::PointInWindow(ExCVec2D point))
00360 if(point.GetX()>=m_Position.GetX()&&point.GetX()<=m_Position.GetX()+m_WindowSize.GetX())
00361 {
00362 if(point.GetY()>=m_Position.GetY()&&point.GetY()<=m_Position.GetY()+m_WindowSize.GetY())
00363 return true;
00364 }
00365 return false;
00366 UnGuard
00367 }
00368
00369 void ExCWindowObject::SetManagerTexture(ExManagerTexture * Texture)
00370 {
00371 Guard(void ExCWindowObject::SetManagerTexture(ExManagerTexture * Texture))
00372 ManagerTexture = Texture;
00373 for(unsigned int i=0;i<m_VecWindowObject.size();i++)
00374 {
00375 m_VecWindowObject.at(i)->SetManagerTexture(ManagerTexture);
00376 }
00377 UnGuard
00378 }