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
00136 ExNihilo::EnterOrthoMode();
00137 glPushAttrib(GL_ALL_ATTRIB_BITS);
00138 glTranslatef(m_Position.GetX(),m_Position.GetY(),0.0f);
00139 glDisable(GL_LIGHTING);
00140 if(m_ShowWindow)
00141 {
00142
00143
00144
00145 float TabTextures[8],TabVertices[8];
00146
00147 TabTextures[0]=0;TabTextures[1]=1;
00148 TabTextures[2]=0;TabTextures[3]=0;
00149 TabTextures[4]=1;TabTextures[5]=0;
00150 TabTextures[6]=1;TabTextures[7]=1;
00151 if(m_Blending)
00152 {
00153 glDisable(GL_LIGHTING);
00154 glEnable(GL_BLEND);
00155 glEnable(GL_ALPHA);
00156 glBlendFunc(GL_ONE,GL_ONE);
00157 glEnable(GL_ALPHA_TEST);
00158 glAlphaFunc(GL_GREATER,0);
00159 glDisable(GL_DEPTH_TEST);
00160 glColor4f(m_BackroundColor.GetX(),m_BackroundColor.GetY(),m_BackroundColor.GetZ(),m_BackroundBlending);
00161 }else glColor3f(m_BackroundColor.GetX(),m_BackroundColor.GetY(),m_BackroundColor.GetZ());
00162
00163 TabVertices[0]=0;TabVertices[1]=0;
00164 TabVertices[2]=0;TabVertices[3]=0+m_WindowSize.GetY();
00165 TabVertices[4]=0+m_WindowSize.GetX();TabVertices[5]=0+m_WindowSize.GetY();
00166 TabVertices[6]=0+m_WindowSize.GetX();TabVertices[7]=0;
00167
00168 if(m_TextureIsMouving)
00169 {
00170 glMatrixMode(GL_TEXTURE);
00171 glTranslatef(m_TextureMouvingVec.GetX()*glutGet(GLUT_ELAPSED_TIME),m_TextureMouvingVec.GetY()*glutGet(GLUT_ELAPSED_TIME),0.0f);
00172 glMatrixMode(GL_MODELVIEW);
00173 }
00174
00175 if(m_BackroundIsTexturing1)
00176 {
00177 ManagerTexture->SetTexture(1,m_BackroundTexture1);
00178 glTexCoordPointer(2,GL_FLOAT,0,TabTextures);
00179 }
00180 if(m_BackroundIsTexturing2)
00181 {
00182 ManagerTexture->SetTexture(0,m_BackroundTexture2);
00183 glTexCoordPointer(2,GL_FLOAT,0,TabTextures);
00184 }
00185
00186 glColor3f(m_BackroundColor.GetX(),m_BackroundColor.GetY(),m_BackroundColor.GetZ());
00187 glEnableClientState(GL_VERTEX_ARRAY);
00188 glVertexPointer(2,GL_FLOAT,0,TabVertices);
00189 glDrawArrays( GL_QUADS, 0, 4 );
00190
00191 if(m_BackroundIsTexturing1)ManagerTexture->ResetMultitexture();
00192
00193 if(m_TextureIsMouving)
00194 {
00195 glMatrixMode(GL_TEXTURE);
00196 glLoadIdentity();
00197 glMatrixMode(GL_MODELVIEW);
00198 }
00199 if(m_Blending)
00200 {
00201 glDisable(GL_BLEND);
00202 glDisable(GL_ALPHA);
00203 glEnable(GL_DEPTH_TEST);
00204 }
00205
00206
00207
00208 if(m_ShowBorder)
00209 {
00210 glColor3f(m_BorderColor.GetX(),m_BorderColor.GetY(),m_BorderColor.GetZ());
00211 glBegin(GL_LINE_STRIP);
00212 glVertex2f(0-1,0+1);
00213 glVertex2f(0+m_WindowSize.GetX()+1,0+1);
00214 glVertex2f(0+m_WindowSize.GetX()+1,0+m_WindowSize.GetY());
00215 glVertex2f(0-1,0+m_WindowSize.GetY());
00216 glVertex2f(0-1,0+1);
00217 glEnd();
00218 }
00219 if(m_ShowWindowTitle)
00220 {
00221 glColor3f(m_WindowTitleColor.GetX(),m_WindowTitleColor.GetY(),m_WindowTitleColor.GetZ());
00222 ExNihilo::WriteToScreen(0+5,0+5+m_WindowSize.GetY()/2,m_WindowTitle);
00223 }
00224
00225
00226
00227 for(unsigned int i=0;i<m_VecWindowObject.size();i++)
00228 {
00229
00230 glPushMatrix();
00231 m_VecWindowObject.at(i)->Draw();
00232 glPopMatrix();
00233 }
00234 }
00235 glPopAttrib();
00236 ExNihilo::LeaveOrthoMode();
00237 UnGuard
00238 }
00239
00240 void ExCWindowObject::AddObjectControl(ExCWindowObject *object)
00241 {
00242 Guard(void ExCWindowObject::AddObjectControl(ExCWindowObject *object))
00243 object->SetParrent(this);
00244 object->SetManagerTexture(ManagerTexture);
00245 object->SetManagerWindow(ManagerWindow);
00246 object->SetPosition(m_Position+object->GetPosition());
00247 m_VecWindowObject.push_back(object);
00248 UnGuard
00249 }
00250
00251 void ExCWindowObject::SetPosition(ExCVec2D Position)
00252 {
00253 Guard(void ExCWindowObject::SetPosition(ExCVec2D Position))
00254 m_OldPosition=m_Position;
00255 m_Position=Position;
00256 UnGuard
00257 }
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 ExCAction ExCWindowObject::InputCommand(ExCCommand Command)
00281 {
00282 Guard(ExCAction ExCWindowObject::InputCommand(ExCCommand Command))
00283
00284
00285 for(unsigned int i=0;i<m_VecWindowObject.size();i++)
00286 {
00287
00288 ExCVec2D ObjPos(Command.m_MousePosx,Command.m_MousePosy);
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299 if(m_VecWindowObject.at(i)->PointInWindow(ExCVec2D(Command.m_MousePosx,Command.m_MousePosy)))
00300 {
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323 return InputAction(m_VecWindowObject.at(i)->InputCommand(Command));
00324 }
00325
00326 }
00327
00328 switch(Command.m_Command)
00329 {
00330 case MOUSE_LEFT_BUTTON_DOWN:
00331 if (m_CanMouve)
00332 {
00333 return MOUVE_OBJECT_WINDOW;
00334 }
00335 break;
00336 }
00337
00338 return NOTHING;
00339 UnGuard
00340 }
00341
00342 ExCAction ExCWindowObject::InputAction(ExCAction Action)
00343 {
00344 Guard(ExCAction ExCWindowObject::InputAction(ExCAction Action))
00345 switch(Action.m_Action)
00346 {
00347 case REQUEST_FOCUS_OBJECT_WINDOW:
00348 m_ObjectRequestFocus=m_CurrentObjectFocus;
00349 break;
00350 case RELEASE_FOCUS_OBJECT_WINDOW:
00351 m_ObjectRequestFocus=NULL;
00352 break;
00353 default :
00354 return Action;
00355 }
00356 if(Action.m_NextAction){return *Action.m_NextAction;}
00357 else{return NOTHING;}
00358 UnGuard
00359 }
00360
00361 bool ExCWindowObject::PointInWindow(ExCVec2D point)
00362 {
00363 Guard(bool ExCWindowObject::PointInWindow(ExCVec2D point))
00364 if(point.GetX()>=m_Position.GetX()&&point.GetX()<=m_Position.GetX()+m_WindowSize.GetX())
00365 {
00366 if(point.GetY()>=m_Position.GetY()&&point.GetY()<=m_Position.GetY()+m_WindowSize.GetY())
00367 return true;
00368 }
00369 return false;
00370 UnGuard
00371 }
00372
00373 void ExCWindowObject::SetManagerTexture(ExManagerTexture * Texture)
00374 {
00375 Guard(void ExCWindowObject::SetManagerTexture(ExManagerTexture * Texture))
00376 ManagerTexture = Texture;
00377 for(unsigned int i=0;i<m_VecWindowObject.size();i++)
00378 {
00379 m_VecWindowObject.at(i)->SetManagerTexture(ManagerTexture);
00380 }
00381 UnGuard
00382 }
00383
00384 std::string ExCWindowObject::Load(std::string FileName)
00385 {
00386 Guard(std::string ExCWindowObject::Load(std::string FileName))
00387 char buffer[255],b[255];
00388 std::string buffstring,returncontrolstring;
00389 std::ifstream file;
00390 #ifdef UNIX_SRC
00391 sprintf(buffer, PREFIX "/ExNihilo/Data/Window/%s", FileName.data());
00392 #else
00393 sprintf(buffer, "../Data/Window/%s", FileName.data());
00394 #endif
00395 file.open(buffer,std::ios::in);
00396 if(file.is_open())
00397 {
00398 memset(b,0,255);file.getline(b,256,'\n');
00399 returncontrolstring=ExNihilo::ExtracValueFromSring(b,"<WindowHeader>","<#WindowHeader>");
00401 Load(FileName);
00403 }
00404 file.close();
00405 return returncontrolstring;
00406 UnGuard
00407 }
00408
00409 void ExCWindowObject::Load(std::ifstream *file)
00410 {
00411 Guard(void ExCWindowObject::Load(std::ifstream *file))
00412 char b[255];
00413 std::string buffstring;
00414 try
00415 {
00416
00417 memset(b,0,255);file->getline(b,256,'\n');
00418 try
00419 {
00420 buffstring=ExNihilo::ExtracValueFromSring(b,"<WindowPosition>","<#WindowPosition>");
00421 SetPosition(ExCVec2D(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
00422 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>")));
00423 }catch(ExCExpStringNotFound){std::cout<<"Error Reading WindowPosition:"<<buffstring<<std::endl;}
00424
00425 memset(b,0,255);file->getline(b,256,'\n');
00426 try
00427 {
00428 buffstring=ExNihilo::ExtracValueFromSring(b,"<WindowSize>","<#WindowSize>");
00429 SetWindowSize(ExCVec2D(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
00430 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>")));
00431 }catch(ExCExpStringNotFound){std::cout<<"Error Reading WindowSize"<<std::endl;}
00432
00433 memset(b,0,255);file->getline(b,256,'\n');
00434 try
00435 {
00436 SetTitleBarSize(ExNihilo::ExtractFloatValueFromSring(b,"<TitleBarSize>","<#TitleBarSize>"));
00437 }catch(ExCExpStringNotFound){std::cout<<"Error Reading TitleBarSize"<<std::endl;}
00438
00439 memset(b,0,255);file->getline(b,256,'\n');
00440 try
00441 {
00442 SetWindowTitle(ExNihilo::ExtracValueFromSring(b,"<WindowTitle>","<#WindowTitle>"));
00443 }catch(ExCExpStringNotFound){std::cout<<"Error Reading WindowTitle"<<std::endl;}
00444
00445 memset(b,0,255);file->getline(b,256,'\n');
00446 try
00447 {
00448 buffstring=ExNihilo::ExtracValueFromSring(b,"<WindowTitleColor>","<#WindowTitleColor>");
00449 SetWindowTitleColor(ExCVec3D(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
00450 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
00451 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>")));
00452 }catch(ExCExpStringNotFound){std::cout<<"Error Reading WindowTitleColor"<<std::endl;}
00453
00454 memset(b,0,255);file->getline(b,256,'\n');
00455 try
00456 {
00457 if(0!=ExNihilo::ExtractIntValueFromSring(b,"<IsBackroundBlending>","<#IsBackroundBlending>"))
00458 {
00459 memset(b,0,255);file->getline(b,256,'\n');
00460 SetBackroundBlending(true,ExNihilo::ExtractFloatValueFromSring(b,"<BackroundBlendingValue>","<#BackroundBlendingValue>"));
00461 }else
00462 {
00463 memset(b,0,255);file->getline(b,256,'\n');
00464 SetBackroundBlending(false,ExNihilo::ExtractFloatValueFromSring(b,"<BackroundBlendingValue>","<#BackroundBlendingValue>"));
00465 }
00466 }catch(ExCExpStringNotFound){std::cout<<"Error Reading IsBackroundBlending"<<std::endl;}
00467
00468 memset(b,0,255);file->getline(b,256,'\n');
00469 try
00470 {
00471 buffstring=ExNihilo::ExtracValueFromSring(b,"<BackroundColor>","<#BackroundColor>");
00472 SetBackroundColor(ExCVec3D(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
00473 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
00474 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>")));
00475 }catch(ExCExpStringNotFound){std::cout<<"Error Reading BackroundColor"<<std::endl;}
00476
00477 memset(b,0,255);file->getline(b,256,'\n');
00478 try
00479 {
00480 if(0!=ExNihilo::ExtractIntValueFromSring(b,"<ShowBorder>","<#ShowBorder>"))
00481 {
00482 SetShowBorder(true);
00483 }else
00484 {
00485 SetShowBorder(false);
00486 }
00487 }catch(ExCExpStringNotFound){std::cout<<"Error Reading ShowBorder"<<std::endl;}
00488
00489 memset(b,0,255);file->getline(b,256,'\n');
00490 try
00491 {
00492 buffstring=ExNihilo::ExtracValueFromSring(b,"<BorderColor>","<#BorderColor>");
00493 SetBorderColor(ExCVec3D(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
00494 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
00495 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>")));
00496 }catch(ExCExpStringNotFound){std::cout<<"Error Reading BorderColor"<<std::endl;}
00497
00498 memset(b,0,255);file->getline(b,256,'\n');
00499 try
00500 {
00501 if(0!=ExNihilo::ExtractIntValueFromSring(b,"<BackroundIsTexturing1>","<#BackroundIsTexturing1>"))
00502 {
00503 memset(b,0,255);file->getline(b,256,'\n');
00504 SetBackroundTexturing1(true,ExNihilo::ExtracValueFromSring(b,"<BackroundTexture1>","<#BackroundTexture1>"));
00505 }else
00506 {
00507 memset(b,0,255);file->getline(b,256,'\n');
00508 SetBackroundTexturing1(false,ExNihilo::ExtracValueFromSring(b,"<BackroundTexture1>","<#BackroundTexture1>"));
00509 }
00510 }catch(ExCExpStringNotFound){std::cout<<"Error Reading BackroundIsTexturing1 :"<<buffstring<<std::endl;}
00511
00512 memset(b,0,255);file->getline(b,256,'\n');
00513 try
00514 {
00515 if(0!=ExNihilo::ExtractIntValueFromSring(b,"<BackroundIsTexturing2>","<#BackroundIsTexturing2>"))
00516 {
00517 memset(b,0,255);file->getline(b,256,'\n');
00518 SetBackroundTexturing2(true,ExNihilo::ExtracValueFromSring(b,"<BackroundTexture2>","<#BackroundTexture2>"));
00519 }else
00520 {
00521 memset(b,0,255);file->getline(b,256,'\n');
00522 SetBackroundTexturing2(false,ExNihilo::ExtracValueFromSring(b,"<BackroundTexture2>","<#BackroundTexture2>"));
00523 }
00524 }catch(ExCExpStringNotFound){std::cout<<"Error Reading BackroundIsTexturing2:"<<buffstring<<std::endl;}
00525
00526 memset(b,0,255);file->getline(b,256,'\n');
00527 try
00528 {
00529 if(0!=ExNihilo::ExtractIntValueFromSring(b,"<TextureIsMouving>","<#TextureIsMouving>"))
00530 {
00531 SetTextureIsMouving(true);
00532 }else
00533 {
00534 SetTextureIsMouving(false);
00535 }
00536 }catch(ExCExpStringNotFound){std::cout<<"Error Reading TextureIsMouving"<<std::endl;}
00537
00538 memset(b,0,255);file->getline(b,256,'\n');
00539 try
00540 {
00541 buffstring=ExNihilo::ExtracValueFromSring(b,"<TextureMouvingVec>","<#TextureMouvingVec>");
00542 SetTextureMouvingVec(ExCVec2D(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
00543 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>")));
00544 }catch(ExCExpStringNotFound){std::cout<<"Error Reading TextureMouvingVec:"<<buffstring<<std::endl;}
00545 }catch(...){throw ExCExpFileReadError();}
00546 UnGuard
00547 }
00548