00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "ExCWindow.h"
00024
00025
00026
00027 ExCWindow::ExCWindow(void)
00028 {
00029 Guard(ExCWindow::ExCWindow(void))
00030 Init();
00031 UnGuard
00032 }
00033
00034 ExCWindow::ExCWindow(ExCVec2D Size)
00035 {
00036 Guard(ExCWindow::ExCWindow(ExCVec2D Size))
00037 Init();
00038 SetWindowSize(Size);
00039 SetOldWindowSize(Size);
00040 RefreshSize();
00041 RefreshPosotion();
00042 UnGuard
00043 }
00044
00045 ExCWindow::ExCWindow(ExCVec2D Size,ExCVec2D Position)
00046 {
00047 Guard(ExCWindow::ExCWindow(ExCVec2D Size,ExCVec2D Position))
00048 Init();
00049 SetPosition(Position);
00050 SetOldPosition(Position);
00051 SetWindowSize(Size);
00052 SetOldWindowSize(Size);
00053 RefreshSize();
00054 RefreshPosotion();
00055 UnGuard
00056 }
00057
00058 ExCWindow::ExCWindow(ExCVec2D Size,ExCVec2D Position,std::string Title)
00059 {
00060 Guard(ExCWindow::ExCWindow(ExCVec2D Size,ExCVec2D Position,std::string Title))
00061 Init();
00062 SetWindowTitle(Title);
00063 SetPosition(Position);
00064 SetOldPosition(Position);
00065 SetWindowSize(Size);
00066 SetOldWindowSize(Size);
00067 RefreshSize();
00068 RefreshPosotion();
00069 UnGuard
00070 }
00071
00072 void ExCWindow::Init(void)
00073 {
00074 Guard(void ExCWindow::Init(void))
00075 ExCWindowObject::Init();
00076 SetName("ExCWindow");
00077 SetType(typeid(this).name());
00078 m_Parent=NULL;
00079 m_BeClosed=false;
00080
00081
00082
00083 m_Window.SetName("MainWindow"+GetWindowTitle());
00084 m_Window.SetBackroundTexturing1(false,"back");
00085 m_Window.SetBackroundTexturing2(false,"fire");
00086 m_Window.SetBackroundColor(ExCVec3D(1.0f,1.0f,1.0f));
00087 m_Window.SetCanMouve(false);
00088
00089 UnGuard
00090 }
00091
00092 ExCWindow::~ExCWindow(void)
00093 {
00094 }
00095
00096
00097
00098
00099 void ExCWindow::Draw(void)
00100 {
00101 Guard(void ExCWindow::Draw(void))
00102
00103 ExNihilo::EnterOrthoMode();
00104 glPushAttrib(GL_ALL_ATTRIB_BITS);
00105 glPushMatrix();
00106 glDisable(GL_LIGHTING);
00107
00108 m_TitleBar.Draw();
00109
00110 m_Window.Draw();
00111 glPopMatrix();
00112 glPopAttrib();
00113 ExNihilo::LeaveOrthoMode();
00114 UnGuard
00115 }
00116
00117
00118
00119 ExCAction ExCWindow::InputCommand(ExCCommand Command)
00120 {
00121 Guard(ExCAction ExCWindow::InputCommand(ExCCommand Command))
00122 if(m_TitleBar.PointInWindow(ExCVec2D(Command.m_MousePosx,Command.m_MousePosy)))
00123 {
00124
00125 return InputAction(m_TitleBar.InputCommand(Command));
00126 }
00127 if(m_Window.PointInWindow(ExCVec2D(Command.m_MousePosx,Command.m_MousePosy)))
00128 {
00129
00130 return InputAction(m_Window.InputCommand(Command));
00131 }
00132 return NOTHING;
00133 UnGuard
00134 }
00135
00136 ExCAction ExCWindow::InputAction(ExCAction Action)
00137 {
00138 Guard(ExCAction ExCWindow::InputAction(ExCAction Action))
00139
00140
00141
00142
00143
00144
00145
00146 return Action;
00147 UnGuard
00148 }
00149
00150 void ExCWindow::SetManagerTexture(ExManagerTexture * Texture)
00151 {
00152 Guard(void ExCWindow::SetManagerTexture(ExManagerTexture * Texture))
00153 ManagerTexture = Texture;
00154 m_TitleBar.SetManagerTexture(ManagerTexture);
00155 m_Window.SetManagerTexture(ManagerTexture);
00156 UnGuard
00157 }
00158
00159 void ExCWindow::RefreshPosotion(void)
00160 {
00161 Guard(void ExCWindow::RefreshPosotion(void))
00162
00163 m_TitleBar.SetPosition(ExCVec2D(m_Position.GetX(),m_Position.GetY()));
00164 m_Window.SetPosition(ExCVec2D(m_Position.GetX(),(m_Position.GetY()+m_TitleBarSize)));
00165 for(unsigned int i=0;i<m_Window.GetVecWindowObject()->size();i++)
00166 {
00167 m_Window.GetVecWindowObject()->at(i)->SetPosition(
00168 ExCVec2D(m_Window.GetPosition()+(m_Window.GetVecWindowObject()->at(i)->GetPosition()-m_Window.GetOldPosition())));
00169 }
00170 UnGuard
00171 }
00172 void ExCWindow::RefreshSize(void)
00173 {
00174 Guard(void ExCWindow::RefreshSize(void))
00175 m_TitleBar.SetWindowSize(ExCVec2D(m_WindowSize.GetX(),m_TitleBarSize));
00176 m_Window.SetWindowSize(ExCVec2D(m_WindowSize.GetX(),m_WindowSize.GetY()-m_TitleBarSize));
00177 UnGuard
00178 }
00179
00180 void ExCWindow::SetWindowSize(ExCVec2D vec)
00181 {
00182 Guard(void ExCWindow::SetWindowSize(ExCVec2D vec))
00183 m_WindowSize=vec;
00184 RefreshSize();
00185 UnGuard
00186 }
00187 void ExCWindow::SetOldWindowSize(ExCVec2D vec)
00188 {
00189 Guard(void ExCWindow::SetOldWindowSize(ExCVec2D vec))
00190 m_OldSize=vec;
00191 UnGuard
00192 }
00193
00194 void ExCWindow::SetWindowPosition(ExCVec2D vec)
00195 {
00196 Guard(void ExCWindow::SetWindowPosition(ExCVec2D vec))
00197 SetOldPosition(GetPosition());
00198 SetPosition(vec);
00199 RefreshPosotion();
00200 RefreshSize();
00201
00202 UnGuard
00203 }
00204
00205 void ExCWindow::SetOldPosition(ExCVec2D vec)
00206 {
00207 Guard(void ExCWindow::SetOldPosition(ExCVec2D vec))
00208 m_OldPosition=vec;
00209 UnGuard
00210 }
00211 void ExCWindow::SetTitleBarSize(float size)
00212 {
00213 Guard(void ExCWindow::SetTitleBarSize(float size))
00214 m_TitleBarSize=size;
00215 m_TitleBar.SetWindowSize(ExCVec2D(m_WindowSize.GetX(),m_TitleBarSize));
00216 UnGuard
00217 }
00218
00219 void ExCWindow::SetWindowTitle(std::string Title)
00220 {
00221 m_WindowTitle=Title;
00222 m_TitleBar.SetWindowTitle(Title);
00223 }
00224 std::string ExCWindow::GetWindowTitle(void)
00225 {
00226 return m_TitleBar.GetWindowTitle();
00227 }
00228 void ExCWindow::SetWindowOldTitle(std::string Title)
00229 {
00230 m_WindowOldTitle=Title;
00231 m_TitleBar.SetWindowOldTitle(Title);
00232 }
00233 std::string ExCWindow::GetWindowOldTitle(void)
00234 {
00235 return m_TitleBar.GetWindowOldTitle();
00236 }
00237 void ExCWindow::SetWindowTitleColor(ExCVec3D Color)
00238 {
00239 m_WindowTitleColor=Color;
00240 m_TitleBar.SetWindowTitleColor(Color);
00241 }
00242 ExCVec3D ExCWindow::GetWindowTitleColor(void)
00243 {
00244 return m_TitleBar.GetWindowTitleColor();
00245 }
00246
00247 bool ExCWindow::PointInWindow(ExCVec2D point)
00248 {
00249 if(ExCWindowObject::PointInWindow(point))
00250 {
00251 if(m_TitleBar.PointInWindow(point))return true;
00252 if(m_Window.PointInWindow(point))
00253 {
00254 if(m_Window.IsShowWindow())return true;
00255 else return false;
00256 }
00257
00258 }
00259 return false;
00260
00261 }
00262
00263 bool ExCWindow::LoadFile(std::string FileName)
00264 {
00265 Guard(void ExCWindow::LoadFile(std::string FileName))
00266 char buffer[255],b[255];
00267 std::string buffstring;
00268 std::ifstream file,fileControl;
00269 #ifdef UNIX_SRC
00270 sprintf(buffer, PREFIX "/ExNihilo/Data/Window/%s", FileName.data());
00271 #else
00272 sprintf(buffer, "../Data/Window/%s", FileName.data());
00273 #endif
00274 file.open(buffer,std::ios::in);
00275 if(file.is_open())
00276 {
00277
00278 memset(b,0,255);file.getline(b,256,'\n');
00279 try
00280 {
00281
00282 ExNihilo::ExtracValueFromSring(b,"<WindowHeader>","<#WindowHeader>");
00283 Load(&file);
00284
00285
00286 memset(b,0,255);file.getline(b,256,'\n');
00287 buffstring=ExNihilo::ExtracValueFromSring(b,"<FileForWindow>","<#FileForWindow>");
00288 ReadWindowSubObject(this,buffstring);
00289
00290
00291
00292
00293
00294
00295 m_TitleBar.LoadFile(ExNihilo::ExtracValueFromSring(b,"<FileForBar>","<#FileForBar>"));
00296
00297 }catch(ExCExpStringNotFound){std::cout<<"Bad file type plok"<<buffer<<std::endl;}
00298 }else
00299 {
00300 std::cout<<"ExCExpFileNotFound:"<<buffer<<std::endl;
00301 throw ExCExpFileNotFound();
00302 }
00303 UnGuard
00304 }
00305
00306 void ExCWindow::ReadWindowSubObject(ExCWindow *win,std::string FileName)
00307 {
00308 Guard(void ExCWindow::ReadWindowSubObject(ExCWindow *win,std::string FileName))
00309 char buffer[255],b[255];
00310 std::string buffstring;
00311 std::ifstream file,fileButton,fileControl;
00312 #ifdef UNIX_SRC
00313 sprintf(buffer, PREFIX "/ExNihilo/Data/Window/%s", FileName.data());
00314 #else
00315 sprintf(buffer, "../Data/Window/%s", FileName.data());
00316 #endif
00317
00318 file.open(buffer,std::ios::in);
00319
00320 if(file.is_open())
00321 {
00322
00323 memset(b,0,255);file.getline(b,256,'\n');
00324 try
00325 {
00326 buffstring=ExNihilo::ExtracValueFromSring(b,"<WindowHeader>","<#WindowHeader>");
00327 if(strcmp(buffstring.data(),"WindowContent")==0)
00328 {
00329 m_Window.Load(&file);
00330
00331 memset(b,0,255);file.getline(b,256,'\n');
00332 int numberofcontrol=ExNihilo::ExtractIntValueFromSring(b,"<NumberOfControl>","<#NumberOfControl>");
00333 for(int i=0;i<numberofcontrol;i++)
00334 {
00335 memset(b,0,255);file.getline(b,256,'\n');
00336 ReadWindowControlObject(win->GetWindowContentPointer(),ExNihilo::ExtracValueFromSring(b,"<FileControl>","<#FileControl>"));
00337 }
00338 }
00339 if(strcmp(buffstring.data(),"BarContent")==0)
00340 {
00341 m_TitleBar.Load(&file);
00342
00343 memset(b,0,255);file.getline(b,256,'\n');
00344 buffstring=ExNihilo::ExtracValueFromSring(b,"<FileForButtonClose>","<#FileForButtonClose>");
00345 #ifdef UNIX_SRC
00346 sprintf(buffer, PREFIX "/ExNihilo/Data/Window/%s", buffstring.data());
00347 #else
00348 sprintf(buffer, "../Data/Window/%s", buffstring.data());
00349 #endif
00350 fileButton.open(buffer,std::ios::in);
00351 if(fileButton.is_open())
00352 {
00353 memset(b,0,255);fileButton.getline(b,256,'\n');
00354 buffstring=ExNihilo::ExtracValueFromSring(b,"<WindowHeader>","<#WindowHeader>");
00355 m_CloseButton->Load(&fileButton);
00356 m_CloseButton->SetBackroundColor(ExCVec3D(1.0f,1.0f,1.0f));
00357 }fileButton.close();
00358
00359 memset(b,0,255);file.getline(b,256,'\n');
00360 buffstring=ExNihilo::ExtracValueFromSring(b,"<FileForButtonMaximize>","<#FileForButtonMaximize>");
00361 #ifdef UNIX_SRC
00362 sprintf(buffer, PREFIX "/ExNihilo/Data/Window/%s", buffstring.data());
00363 #else
00364 sprintf(buffer, "../Data/Window/%s", buffstring.data());
00365 #endif
00366 fileButton.open(buffer,std::ios::in);
00367 if(fileButton.is_open())
00368 {
00369 memset(b,0,255);fileButton.getline(b,256,'\n');
00370 buffstring=ExNihilo::ExtracValueFromSring(b,"<WindowHeader>","<#WindowHeader>");
00371 m_MaximizeButton->Load(&fileButton);
00372 m_MaximizeButton->SetBackroundColor(ExCVec3D(1.0f,1.0f,1.0f));
00373 }fileButton.close();
00374
00375 memset(b,0,255);file.getline(b,256,'\n');
00376 buffstring=ExNihilo::ExtracValueFromSring(b,"<FileForButtonMinimize>","<#FileForButtonMinimize>");
00377 #ifdef UNIX_SRC
00378 sprintf(buffer, PREFIX "/ExNihilo/Data/Window/%s", buffstring.data());
00379 #else
00380 sprintf(buffer, "../Data/Window/%s", buffstring.data());
00381 #endif
00382 fileButton.open(buffer,std::ios::in);
00383 if(fileButton.is_open())
00384 {
00385 memset(b,0,255);fileButton.getline(b,256,'\n');
00386 buffstring=ExNihilo::ExtracValueFromSring(b,"<WindowHeader>","<#WindowHeader>");
00387 m_MinimizeButton->Load(&fileButton);
00388 m_MinimizeButton->SetBackroundColor(ExCVec3D(1.0f,1.0f,1.0f));
00389 }fileButton.close();
00390
00391 memset(b,0,255);file.getline(b,256,'\n');
00392 buffstring=ExNihilo::ExtracValueFromSring(b,"<FileForButtonMinimizeToBar>","<#FileForButtonMinimizeToBar>");
00393 #ifdef UNIX_SRC
00394 sprintf(buffer, PREFIX "/ExNihilo/Data/Window/%s", buffstring.data());
00395 #else
00396 sprintf(buffer, "../Data/Window/%s", buffstring.data());
00397 #endif
00398 fileButton.open(buffer,std::ios::in);
00399 if(fileButton.is_open())
00400 {
00401 memset(b,0,255);fileButton.getline(b,256,'\n');
00402 buffstring=ExNihilo::ExtracValueFromSring(b,"<WindowHeader>","<#WindowHeader>");
00403
00404 m_MinimizeToBarButton->Load(&fileButton);
00405 m_MinimizeToBarButton->SetBackroundColor(ExCVec3D(1.0f,1.0f,1.0f));
00406 }fileButton.close();
00407
00408 }
00409 }catch(ExCExpStringNotFound)
00410 {
00411 std::cout<<"ReadWindowSubObject::ExCExpStringNotFound";
00412 }
00413 }else throw ExCExpFileNotFound();
00414 file.close();
00415 UnGuard
00416 }
00417
00418 ExCWindowControl * ExCWindow::ReadWindowControlObject(ExCWindowObject *win,std::string FileName)
00419 {
00420 Guard(ExCWindowControl * ExCWindow::ReadWindowControlObject(ExCWindowObject *win,std::string FileName))
00421 char buffer[255],b[255];
00422 std::string buffstring;
00423 std::ifstream fileControl;
00424 #ifdef UNIX_SRC
00425 sprintf(buffer, PREFIX "/ExNihilo/Data/Window/%s", FileName.data());
00426 #else
00427 sprintf(buffer, "../Data/Window/%s", FileName.data());
00428 #endif
00429 fileControl.open(buffer,std::ios::in);
00430 if(fileControl.is_open())
00431 {
00432 memset(b,0,255);fileControl.getline(b,256,'\n');
00433 buffstring=ExNihilo::ExtracValueFromSring(b,"<WindowHeader>","<#WindowHeader>");
00434
00435 if(strcmp(buffstring.data(),"ExCWindowLabel")==0)
00436 {
00437 ExCWindowLabel *NewLabel;
00438 NewLabel= new ExCWindowLabel;
00439
00440 NewLabel->Load(&fileControl);
00441 win->AddObjectControl(NewLabel);
00442 }
00443
00444 if(strcmp(buffstring.data(),"ExCWindowEditLabel")==0)
00445 {
00446 ExCWindowEditLabel *NewEditLabel;
00447 NewEditLabel= new ExCWindowEditLabel;
00448
00449 NewEditLabel->Load(&fileControl);
00450 win->AddObjectControl(NewEditLabel);
00451 }
00452
00453 if(strcmp(buffstring.data(),"ExCWindowButton")==0)
00454 {
00455 ExCWindowButton *NewButton;
00456 NewButton= new ExCWindowButton;
00457
00458 NewButton->Load(&fileControl);
00459
00460 memset(b,0,255);fileControl.getline(b,256,'\n');
00461 buffstring=ExNihilo::ExtracValueFromSring(b,"<ActionCommand>","<#ActionCommand>");
00462 ExCAction Action=ExNihilo::ExtractIntValueFromSring(buffstring,"<Action>","<#Action>");
00463 ExCCommand Command=ExNihilo::ExtractIntValueFromSring(buffstring,"<Command>","<#Command>");
00464 Action.m_Param=ExNihilo::ExtracValueFromSring(buffstring,"<Param>","<#Param>");
00465 NewButton->AddActionCommand(Action,Command);
00466 win->AddObjectControl(NewButton);
00467 }
00468
00469 if(strcmp(buffstring.data(),"ExCWindowButtonSwitch")==0)
00470 {
00471 std::ifstream fileB1,fileB2;
00472 ExCWindowButtonSwitch *NewButton;
00473 NewButton= new ExCWindowButtonSwitch;
00474
00475 NewButton->Load(&fileControl);
00476 ExCWindowButton * Butt1,*Butt2;
00477 Butt1=new ExCWindowButton;
00478 Butt2=new ExCWindowButton;
00479
00480
00481 memset(b,0,255);fileControl.getline(b,256,'\n');
00482 buffstring=ExNihilo::ExtracValueFromSring(b,"<Button1>","<#Button1>");
00483
00484 NewButton->m_Butt1=Butt1;
00485
00486
00487
00488 memset(b,0,255);fileControl.getline(b,256,'\n');
00489 buffstring=ExNihilo::ExtracValueFromSring(b,"<Button2>","<#Button2>");
00490
00491 NewButton->m_Butt2=Butt2;
00492
00493
00494 memset(b,0,255);fileB1.getline(b,256,'\n');
00495 buffstring=ExNihilo::ExtracValueFromSring(b,"<ActionCommand>","<#ActionCommand>");
00496 ExCAction Action=ExNihilo::ExtractIntValueFromSring(buffstring,"<Action>","<#Action>");
00497 ExCCommand Command=ExNihilo::ExtractIntValueFromSring(buffstring,"<Command>","<#Command>");
00498 Action.m_Param=ExNihilo::ExtracValueFromSring(buffstring,"<Param>","<#Param>");
00499 Butt1->AddActionCommand(Action,Command);
00500 fileB1.close();
00501
00502
00503 memset(b,0,255);fileB2.getline(b,256,'\n');
00504 buffstring=ExNihilo::ExtracValueFromSring(b,"<ActionCommand>","<#ActionCommand>");
00505 Action=ExNihilo::ExtractIntValueFromSring(buffstring,"<Action>","<#Action>");
00506 Command=ExNihilo::ExtractIntValueFromSring(buffstring,"<Command>","<#Command>");
00507 Action.m_Param=ExNihilo::ExtracValueFromSring(buffstring,"<Param>","<#Param>");
00508 Butt2->AddActionCommand(Action,Command);
00509 fileB2.close();
00510
00511 NewButton->SwitchValue();
00512
00513 win->AddObjectControl(NewButton);
00514 }
00515
00516 if(strcmp(buffstring.data(),"ExCWindowButtonSwitchOnMouse")==0)
00517 {
00518 std::ifstream fileB1,fileB2;
00519 ExCWindowButtonSwitchOnMouse *NewButton;
00520 NewButton= new ExCWindowButtonSwitchOnMouse;
00521
00522 NewButton->Load(&fileControl);
00523 ExCWindowButton * Butt1,*Butt2;
00524 Butt1=new ExCWindowButton;
00525 Butt2=new ExCWindowButton;
00526
00527
00528 memset(b,0,255);fileControl.getline(b,256,'\n');
00529 buffstring=ExNihilo::ExtracValueFromSring(b,"<Button1>","<#Button1>");
00530
00531 NewButton->m_Butt1=Butt1;
00532
00533
00534
00535 memset(b,0,255);fileControl.getline(b,256,'\n');
00536 buffstring=ExNihilo::ExtracValueFromSring(b,"<Button2>","<#Button2>");
00537
00538 NewButton->m_Butt2=Butt2;
00539
00540
00541 memset(b,0,255);fileB1.getline(b,256,'\n');
00542 buffstring=ExNihilo::ExtracValueFromSring(b,"<ActionCommand>","<#ActionCommand>");
00543 ExCAction Action=ExNihilo::ExtractIntValueFromSring(buffstring,"<Action>","<#Action>");
00544 ExCCommand Command=ExNihilo::ExtractIntValueFromSring(buffstring,"<Command>","<#Command>");
00545 Action.m_Param=ExNihilo::ExtracValueFromSring(buffstring,"<Param>","<#Param>");
00546 Butt1->AddActionCommand(Action,Command);
00547 fileB1.close();
00548
00549
00550 memset(b,0,255);fileB2.getline(b,256,'\n');
00551 buffstring=ExNihilo::ExtracValueFromSring(b,"<ActionCommand>","<#ActionCommand>");
00552 Action=ExNihilo::ExtractIntValueFromSring(buffstring,"<Action>","<#Action>");
00553 Command=ExNihilo::ExtractIntValueFromSring(buffstring,"<Command>","<#Command>");
00554 Action.m_Param=ExNihilo::ExtracValueFromSring(buffstring,"<Param>","<#Param>");
00555 Butt2->AddActionCommand(Action,Command);
00556 fileB2.close();
00557
00558 NewButton->SwitchValue();
00559
00560 win->AddObjectControl(NewButton);
00561 }
00562 }
00563 fileControl.close();
00564 return NULL;
00565 UnGuard
00566 }