Main Page Namespace List Class Hierarchy Alphabetical List Data Structures File List Namespace Members Data Fields Globals

# ExManagerWindow.cpp

Go to the documentation of this file.

    00001 /*
    00002  * ExNihilo 3D Engine
    00003  *
    00004  *  This program is free software; you can redistribute it and/or modify
    00005  *  it under the terms of the GNU General Public License as published by
    00006  *  the Free Software Foundation; either version 2 of the License, or
    00007  *  (at your option) any later version.
    00008  *
    00009  *  This program is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012  *  GNU Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU General Public License
    00015  *  along with this program; if not, write to the Free Software
    00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    00017  *
    00018  * Please read AUTHORS file !!!
    00019  *
    00020  * $Id: ExManagerWindow.cpp,v 1.21 2002/11/24 11:58:59 data Exp $
    00021  *
    00022  */
    00023
    00024 #include "ExManagerWindow.h"
    00025
    00026 bool ExManagerWindow::m_flag = false;
    00027 ExManagerWindow* ExManagerWindow::m_instance = NULL;
    00028
    00029 ExManagerWindow::ExManagerWindow(void){
    00030 Guard(ExManagerWindow::ExManagerWindow(void))
    00031         m_ShowGrille=false;
    00032
    00033 //      m_Antialliasing=true;
    00034
    00035         /*
    00036         options = new ExCOptions;
    00037
    00038         m_ShowFps = options->getWindowShowfps ();
    00039
    00040         m_WindowSizeX = options->getWindowResolutionX ();
    00041         m_WindowSizeY = options->getWindowResolutionY ();
    00042                 m_Bits = options->getWindowDepth ();
    00043         m_Rate = options->getWindowRate ();
    00044         m_FullScreen = options->getWindowFullscreen () ;
    00045         */
    00046         m_ShowFps = true;
    00047         m_WindowSizeX = 800;
    00048         m_WindowSizeY = 600;
    00049         m_WindowSizeXOld = m_WindowSizeX;
    00050         m_WindowSizeYOld = m_WindowSizeY;
    00051         m_WindowPosX=0;
    00052         m_WindowPosY=0;
    00053         m_Bits = 16;
    00054         m_Rate = 75;
    00055         m_FullScreen = true ;
    00056         m_OldMode=m_FullScreen;
    00057         m_Cursor=GLUT_CURSOR_CROSSHAIR;
    00058
    00059         m_Title=new char[strlen("ExNihilo Engine Version ")+20];
    00060         sprintf(m_Title,"ExNihilo Engine Version %s",VERSION);
    00061
    00062         m_IconTitle=new char[strlen("ExNihilo Engine Version ")+20];
    00063         sprintf(m_IconTitle,"ExNihilo Engine Version %s",VERSION);
    00064
    00065 UnGuard
    00066 }
    00067
    00068 ExManagerWindow::~ExManagerWindow(void)
    00069 {
    00070 Guard(ExManagerWindow::~ExManagerWindow(void))
    00071         m_flag=false;
    00072 UnGuard
    00073 }
    00074
    00075 ExManagerWindow* ExManagerWindow::CreateSingleton(void){
    00076 Guard(ExManagerWindow* ExManagerWindow::CreateSingleton(void))
    00077         if(!m_flag)
    00078         {
    00079                 m_flag = true; // We are creating the error log now, so set flag to true
    00080                 m_instance = new ExManagerWindow; // Create the error log
    00081         }else
    00082         {
    00083                 std::cout<<"Error singleton already created"<<std::endl;
    00084         }
    00085         return m_instance;
    00086 UnGuard
    00087 }
    00088
    00089 void ExManagerWindow::CreateNewWindow(int SizeX,int SizeY,int PosX,int PosY,char *argv){
    00090 Guard(ExManagerWindow::CreateNewWindow(int SizeX,int SizeY,int PosX,int PosY,char *argv))
    00091         m_WindowSizeX=SizeX;
    00092         m_WindowSizeY=SizeY;
    00093         m_WindowSizeXOld=SizeX;
    00094         m_WindowSizeYOld=SizeY;
    00095         m_WindowPosX=PosX;
    00096         m_WindowPosY=PosY;
    00097         glutInitWindowPosition(m_WindowPosX,m_WindowPosY);
    00098         glutInitWindowSize(m_WindowSizeX,m_WindowSizeY);
    00099         m_WindowHandler=glutCreateWindow(m_Title);
    00100         glutSetIconTitle(m_IconTitle);
    00101         SetCursor(m_Cursor);
    00102 UnGuard
    00103 }
    00104
    00105 void ExManagerWindow::CreateNewWindow(int SizeX,int SizeY,char *argv){
    00106 Guard(ExManagerWindow::CreateNewWindow(int SizeX,int SizeY,char *argv))
    00107         m_WindowSizeX=SizeX;
    00108         m_WindowSizeY=SizeY;
    00109         m_WindowSizeXOld=SizeX;
    00110         m_WindowSizeYOld=SizeY;
    00111         glutInitWindowPosition(m_WindowPosX,m_WindowPosY);
    00112         glutInitWindowSize(m_WindowSizeX,m_WindowSizeY);
    00113         m_WindowHandler=glutCreateWindow(m_Title);
    00114         glutSetIconTitle(m_IconTitle);
    00115         SetCursor(m_Cursor);
    00116 UnGuard
    00117 }
    00118
    00119 void ExManagerWindow::Move(int Posx,int Posy){
    00120 Guard(ExManagerWindow::Move(int Posx,int Posy))
    00121         m_WindowPosX=Posx;
    00122         m_WindowPosY=Posy;
    00123         glutPositionWindow(Posx,Posy);
    00124 UnGuard
    00125 }
    00126
    00127
    00128 void ExManagerWindow::SetResolution(int SizeX,int SizeY){
    00129 Guard(ExManagerWindow::SetResolution(int SizeX,int SizeY))
    00130         m_WindowSizeXOld=m_WindowSizeX;
    00131         m_WindowSizeYOld=m_WindowSizeY;
    00132         m_WindowSizeX=SizeX;
    00133         m_WindowSizeY=SizeY;
    00134 UnGuard
    00135 }
    00136
    00137 void ExManagerWindow::SetWindowTitle(char *Title){
    00138 Guard(ExManagerWindow::SetWindowTitle(char *Title))
    00139         m_Title = new char[strlen(Title)];
    00140         sprintf(m_Title,"%s",Title);
    00141         glutSetWindowTitle(m_Title);
    00142 UnGuard
    00143 }
    00144
    00145 void ExManagerWindow::SetIconTitle(char *Title){
    00146 Guard(ExManagerWindow::SetIconTitle(char *Title))
    00147         m_IconTitle=new char[strlen(Title)];
    00148         sprintf(m_IconTitle,"%s",Title);
    00149         glutSetIconTitle(m_IconTitle);
    00150 UnGuard
    00151 }
    00152
    00153 void ExManagerWindow::SetCursor(int Cursor){
    00154 Guard(ExManagerWindow::SetCursor(int Cursor))
    00155         glutSetCursor(Cursor);
    00156 UnGuard
    00157 }
    00158
    00159
    00160 void ExManagerWindow::Apply(void){
    00161 Guard(ExManagerWindow::Apply(void))
    00162         if(m_FullScreen)
    00163         {
    00164                 char *game;
    00165                 game=new char[15];
    00166                 sprintf(game,"%dx%d:%d@%d",m_WindowSizeX,m_WindowSizeY,m_Bits,m_Rate);
    00167                 if(m_OldMode)
    00168                 {
    00169                         glutDestroyWindow(m_WindowHandler);
    00170                 }
    00171
    00172                 glutGameModeString(game);
    00173
    00174                 if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE))
    00175                 {
    00176                         m_WindowHandler=glutEnterGameMode();
    00177                         GlutCallBack();
    00178                         glutSetWindow(m_WindowHandler);
    00179
    00180                 }else
    00181                 {
    00182                         std::cout << "Can not switch to fullscreen  error with your graphic card or glut lib " << std::endl;
    00183                 }
    00184         }else
    00185         {
    00186                 if(m_OldMode)
    00187                 {
    00188                         glutLeaveGameMode();
    00189                         glutInitWindowPosition(m_WindowPosX,m_WindowPosY);
    00190                         glutInitWindowSize(m_WindowSizeX,m_WindowSizeY);
    00191                         m_WindowHandler=glutCreateWindow(m_Title);
    00192                 }else
    00193                 {
    00194                         glutReshapeWindow(m_WindowSizeX,m_WindowSizeY);
    00195                 }
    00196         }
    00197 UnGuard
    00198 }
    00199
    00200 void ExManagerWindow::ShowFps(void)
    00201 {
    00202 Guard(void ExManagerWindow::ShowFps(void))
    00203         frame++;
    00204         timeframe=glutGet(GLUT_ELAPSED_TIME);
    00205         if (timeframe - timebase > 1000)
    00206         {
    00207                 sprintf(s,"FPS:%4.2f",frame*1000.0/(timeframe-timebase));
    00208                 timebase = timeframe;
    00209                 frame = 0;
    00210         }
    00211         char TimeSinceStart[30];
    00212         sprintf(TimeSinceStart,"Time since start:%f",(double)((double)glutGet(GLUT_ELAPSED_TIME)/1000));
    00213         ExNihilo::DrawCadre(15,10,165,50,0.2f,0.0f,0.6f,0.9f);
    00214         ExNihilo::WriteToScreen(18,25,1,1,1,m_Title);
    00215         ExNihilo::WriteToScreen(18,40,1,1,1,s);
    00216         ExNihilo::WriteToScreen(18,55,1,1,1,TimeSinceStart);
    00217
    00218 UnGuard
    00219 }
    00220
    00221 ExCAction ExManagerWindow::InputCommand(ExCCommand Command)
    00222 {
    00223 Guard(ExManagerWindow::InputCommand(ExCCommand Command))
    00224         return  NOTHING;
    00225 UnGuard
    00226 }
    00227
    00228 ExCAction ExManagerWindow::InputAction(ExCAction Action)
    00229 {
    00230 Guard(ExManagerWindow::InputAction(ExCAction Action))
    00231         switch(Action.m_Action)
    00232         {
    00233         case SET_RESOLUTION_800_600_16:
    00234                 SetResolution(800,600);
    00235                 SetBits(16);
    00236                 SetFullScreen(true);
    00237                 Apply();
    00238                 break;
    00239
    00240         case SET_RESOLUTION_800_600_24:
    00241                 SetResolution(800,600);
    00242                 SetBits(24);
    00243                 SetFullScreen(true);
    00244                 Apply();
    00245                 break;
    00246
    00247         case SET_RESOLUTION_800_600_32:
    00248                 SetResolution(800,600);
    00249                 SetBits(32);
    00250                 SetFullScreen(true);
    00251                 Apply();
    00252                 break;
    00253
    00254         case SET_RESOLUTION_1024_768_16:
    00255                 SetResolution(1024,768);
    00256                 SetBits(16);
    00257                 SetFullScreen(true);
    00258                 Apply();
    00259                 break;
    00260
    00261         case SET_RESOLUTION_1024_768_24:
    00262                 SetResolution(1024,768);
    00263                 SetBits(24);
    00264                 SetFullScreen(true);
    00265                 Apply();
    00266                 break;
    00267
    00268         case SET_RESOLUTION_1024_768_32:
    00269                 SetResolution(1024,768);
    00270                 SetBits(32);
    00271                 SetFullScreen(true);
    00272                 Apply();
    00273                 break;
    00274
    00275         case SET_RESOLUTION_1600_1200_16:
    00276                 SetResolution(1600,1200);
    00277                 SetBits(16);
    00278                 SetFullScreen(true);
    00279                 Apply();
    00280                 break;
    00281
    00282         case SET_RESOLUTION_1600_1200_24:
    00283                 SetResolution(1600,1200);
    00284                 SetBits(24);
    00285                 SetFullScreen(true);
    00286                 Apply();
    00287                 break;
    00288
    00289         case SET_RESOLUTION_1600_1200_32:
    00290                 SetResolution(1600,1200);
    00291                 SetBits(32);
    00292                 SetFullScreen(true);
    00293                 Apply();
    00294                 break;
    00295
    00296         case SHOW_FPS_STAT:
    00297                 SetFpsState(true);
    00298                 break;
    00299
    00300         case HIDE_FPS_STAT:
    00301                 SetFpsState(false);
    00302                 break;
    00303
    00304         case ENABLE_GRIDE:
    00305                 SetGrilleState(true);
    00306                 break;
    00307
    00308         case DISABLE_GRIDE:
    00309                 SetGrilleState(false);
    00310                 break;
    00311
    00312         case SWITCH_GRIDE:
    00313                 if(GetGrilleState())
    00314                 {
    00315                         InputAction(DISABLE_GRIDE);
    00316                 }else
    00317                 {
    00318                         InputAction(ENABLE_GRIDE);
    00319                 }
    00320                 break;
    00321         case SET_POLYGONMODE_POINTS:
    00322                 glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
    00323                 break;
    00324
    00325         case SET_POLYGONMODE_LINES:
    00326                 glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    00327                 break;
    00328
    00329         case SET_POLYGONMODE_FILL:
    00330                 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    00331                 break;
    00332
    00333         default: return NOTHING;
    00334         }
    00335         return  NOTHING;
    00336 UnGuard
    00337 }