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

ExCInterface.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: ExCInterface.cpp,v 1.6 2002/11/24 11:59:00 data Exp $
00021  *
00022  */
00023 
00024 #include "ExCInterface.h"
00025 
00026 ExCInterface::ExCInterface(void)
00027 {
00028 Guard(ExCInterface::ExCInterface(void))
00029         m_ShowRegion=true;
00030         m_State=true;
00031         SetName("ExCInterface");
00032         SetType(typeid(this).name());
00033 UnGuard
00034 }
00035 
00036 ExCInterface::ExCInterface(std::string FileName)
00037 {
00038 Guard(ExCInterface::ExCInterface(std::string FileName))
00039         m_ShowRegion=true;
00040         m_State=true;
00041         LoadFile(FileName);
00042 UnGuard
00043 }
00044 
00045 ExCInterface::~ExCInterface(void)
00046 {
00047 Guard(ExCInterface::~ExCInterface(void))
00048 UnGuard
00049 }
00050 
00051 bool ExCInterface::LoadFile(std::string FileName)
00052 {
00053 Guard(bool ExCInterface::LoadFile(std::string FileName))
00054         char                    buffer[255];
00055 #ifdef UNIX_SRC
00056         sprintf(buffer, PREFIX "/ExNihilo/Data/Interface/%s", FileName.data());
00057 #else
00058         sprintf(buffer, "../Data/Interface/%s", FileName.data());
00059 #endif
00060         std::ifstream fin;
00061         std::string buffstring;
00062         char b[256];
00063         fin.open(buffer,std::ios::in);
00064         if(fin.is_open())
00065         {
00066                 try
00067                 {
00068                         //----Read image
00069                         memset(b,0,255);
00070                         fin.getline(b,256,'\n');
00071                         m_Texture=ExNihilo::ExtracValueFromSring(b,"<Image>","<#Image>");
00072                         //----Read mask
00073             memset(b,0,255);
00074                         fin.getline(b,256,'\n');                        
00075                         m_TextureMask=ExNihilo::ExtracValueFromSring(b,"<Mask>","<#Mask>");
00076                         //----Read resolution
00077             memset(b,0,255);
00078                         fin.getline(b,256,'\n');                        
00079                         buffstring=ExNihilo::ExtracValueFromSring(b,"<Mask>","<#Mask>");
00080                         m_DefaultResolutionX=ExNihilo::ExtractIntValueFromSring(buffstring,"<X>","<#X>");
00081                         m_DefaultResolutionY=ExNihilo::ExtractIntValueFromSring(buffstring,"<Y>","<#Y>");
00082                         //----Read all command
00083                         do
00084                         {
00085                                 memset(b,0,255);
00086                                 fin.getline(b,256,'\n');
00087                                 try
00088                                 {
00089                                         ActionCommand actcmd;
00090                                         buffstring=ExNihilo::ExtracValueFromSring(b,"<Interface_Action>","<#Interface_Action>");
00091                                         actcmd.m_Action=ExNihilo::ExtractIntValueFromSring(buffstring,"<Action>","<#Action>");
00092                                         actcmd.m_Command=ExNihilo::ExtractIntValueFromSring(buffstring,"<Command>","<#Command>");
00093                                         actcmd.m_Param=ExNihilo::ExtracValueFromSring(buffstring,"<Param>","<#Param>");
00094                                         actcmd.m_MouseXup=ExNihilo::ExtractIntValueFromSring(buffstring,"<TopX>","<#TopX>");
00095                                         actcmd.m_MouseYup=ExNihilo::ExtractIntValueFromSring(buffstring,"<TopY>","<#TopY>");
00096                                         actcmd.m_MouseXdown=ExNihilo::ExtractIntValueFromSring(buffstring,"<BottomX>","<#BottomX>");
00097                                         actcmd.m_MouseYdown=ExNihilo::ExtractIntValueFromSring(buffstring,"<BottomY>","<#BottomY>");
00098                                         m_VecActionCommand.push_back(actcmd);
00099                                 }catch(ExCExpStringNotFound){}
00100                         }while(!fin.eof());
00101                         fin.close();
00102                 }catch(...){throw ExCExpFileReadError();}
00103         }else throw   ExCExpFileNotFound();
00104         ManagerTexture->Add(m_Texture);
00105         ManagerTexture->Add(m_TextureMask);
00106         return true;
00107 UnGuard
00108 }
00109 
00110 void ExCInterface::Draw(void)
00111 {
00112 Guard(void ExCInterface::Draw(void))
00113     glPushMatrix();
00114         ExNihilo::EnterOrthoMode();
00115         
00116         glEnable(GL_TEXTURE_2D);
00117         glDisable(GL_LIGHTING);
00118         glColor4f(1, 1, 1, 1);
00119         glDisable(GL_DEPTH_TEST);
00120         glBlendFunc(GL_DST_COLOR,GL_ZERO);
00121         glEnable(GL_BLEND);                                                                                     
00122         
00123         ManagerTexture->SetCurrentObject(m_TextureMask);
00124         
00125         glBegin(GL_QUADS);
00126                 glTexCoord2f(0.0f, 1.0f);       glVertex2f(0, 0);
00127                 glTexCoord2f(0.0f, 0.0f);       glVertex2f(0,glutGet(GLUT_WINDOW_HEIGHT));
00128                 glTexCoord2f(1.0f, 0.0f);       glVertex2f(glutGet(GLUT_WINDOW_WIDTH),glutGet(GLUT_WINDOW_HEIGHT));
00129                 glTexCoord2f(1.0f, 1.0f);       glVertex2f(glutGet(GLUT_WINDOW_WIDTH), 0);
00130         glEnd();        
00131 
00132         glBlendFunc(GL_ONE,GL_ONE);
00133         ManagerTexture->SetCurrentObject(m_Texture);
00134         
00135         glBegin(GL_QUADS);
00136                 glTexCoord2f(0.0f, 1.0f);       glVertex2f(0, 0);
00137                 glTexCoord2f(0.0f, 0.0f);       glVertex2f(0,glutGet(GLUT_WINDOW_HEIGHT));
00138                 glTexCoord2f(1.0f, 0.0f);       glVertex2f(glutGet(GLUT_WINDOW_WIDTH),glutGet(GLUT_WINDOW_HEIGHT));
00139                 glTexCoord2f(1.0f, 1.0f);       glVertex2f(glutGet(GLUT_WINDOW_WIDTH), 0);
00140     glEnd();    
00141         
00142         glDisable(GL_BLEND);
00143         glDisable(GL_TEXTURE_2D);
00144         glEnable(GL_DEPTH_TEST);
00145         
00146         /*
00147         if(m_ShowRegion)
00148         {
00149                 int i=0;
00150                 for(m_ItVecActionCommand=m_VecActionCommand.begin();m_ItVecActionCommand!=m_VecActionCommand.end();m_ItVecActionCommand++,i++)
00151                 {
00152                         
00153                         double Xup,Yup,Xdo,Ydo,cofx=1,cofy=1;
00154                         //Xup=((double)m_ItVecActionCommand->m_MouseXup/m_DefaultResolutionX)*ManagerWindow->GetResolutionX();
00155                         //Yup=((double)m_ItVecActionCommand->m_MouseYup/m_DefaultResolutionY)*ManagerWindow->GetResolutionY();
00156                         //Xdo=((double)m_ItVecActionCommand->m_MouseXdown/m_DefaultResolutionX)*ManagerWindow->GetResolutionX();
00157                         //Ydo=((double)m_ItVecActionCommand->m_MouseYdown/m_DefaultResolutionY)*ManagerWindow->GetResolutionY();
00158                         
00159                         
00160                         
00161                         //cout<<"Current resolution X:"<<ManagerWindow->GetResolutionX()<<endl;
00162                         //cout<<"Current resolution Y:"<<ManagerWindow->GetResolutionY()<<endl;
00163                         //cout<<"Default X:"<<m_DefaultResolutionX<<endl;
00164                         //cout<<"Default Y:"<<m_DefaultResolutionY<<endl;
00165                         if(cofx==0)cofx=1;
00166                         if(cofy==0)cofy=1;
00167                         cofx=(ManagerWindow->GetResolutionX()/m_DefaultResolutionX);            
00168                         cofy=(ManagerWindow->GetResolutionY()/m_DefaultResolutionY);
00169                         //cout<<"cofx :"<<cofx<<endl;
00170                         //cout<<"cofy :"<<cofy<<endl;
00171                         
00172 
00173                         
00174                         
00175                         Xup=(m_ItVecActionCommand->m_MouseXup)*cofx;
00176                         Yup=(m_ItVecActionCommand->m_MouseYup)*cofy;
00177                         Xdo=(m_ItVecActionCommand->m_MouseXdown)*cofx;
00178                         Ydo=(m_ItVecActionCommand->m_MouseYdown)*cofy;
00179                         
00180                         if(i%1==0){glColor3f((float)i/10,1.0f-((float)i/10),1.0f);}
00181                         if(i%2==0){glColor3f(1.0f,1.0f-((float)i/10),(float)1/10);}
00182                         if(i%3==0){glColor3f(1.0f-((float)i/10),1.0f,(float)1/10);}
00183                         glBegin(GL_LINE_LOOP);
00184                                 glVertex2f(Xdo,Ydo);
00185                                 glVertex2f(Xdo,Yup);
00186                                 glVertex2f(Xup,Yup);
00187                                 glVertex2f(Xup,Ydo);
00188                         glEnd();
00189                 }
00190         }
00191         glEnable(GL_LIGHTING);*/
00192         ExNihilo::LeaveOrthoMode();
00193         glPopMatrix();
00194 UnGuard
00195 }
00196 
00197 ExCAction ExCInterface::InputCommand(int command,int mousex,int mousey)
00198 {
00199 Guard(ExCAction ExCInterface::InputCommand(int command,int mousex,int mousey))
00200         int CntAct=0;
00201         ExCAction RetAct;
00202         
00203         for(m_ItVecActionCommand=m_VecActionCommand.begin();m_ItVecActionCommand!=m_VecActionCommand.end();m_ItVecActionCommand++)
00204         {
00205                 if(m_ItVecActionCommand->m_Command==command)
00206                 {
00207                         if(m_ItVecActionCommand->m_MouseXup<0)
00208                         {
00209                                 if(CntAct>0)
00210                                 {
00211                                         ExCAction       *RecursifActA;
00212                                         ExCAction       *RecursifActB;
00213                                         RecursifActA=&RetAct;
00214                                         for(int i=0;i<CntAct;i++)
00215                                         {
00216                                                 if(RecursifActA->m_NextAction==NULL)
00217                                                 {
00218                                                         RecursifActA->m_NextAction=new ExCAction;
00219                                                         RecursifActB=RecursifActA->m_NextAction;
00220                                                         RecursifActB->m_Action=m_ItVecActionCommand->m_Action;
00221                                                         RecursifActB->SetParam(m_ItVecActionCommand->m_Param);
00222                                                 }
00223                                                 RecursifActA=RecursifActA->m_NextAction;
00224                                         }
00225                                         CntAct++;
00226                                 }else
00227                                 {
00228                                         RetAct.m_Action=m_ItVecActionCommand->m_Action;
00229                                         RetAct.SetParam(m_ItVecActionCommand->m_Param);
00230                                         CntAct++;
00231                                 }
00232                         }else
00233                         {
00234                                 double Xup,Yup,Xdo,Ydo,Mx,My;
00235                                 Xup=((double)m_ItVecActionCommand->m_MouseXup/ManagerWindow->GetResolutionX());
00236                                 Yup=((double)m_ItVecActionCommand->m_MouseYup/ManagerWindow->GetResolutionY());
00237                                 Xdo=((double)m_ItVecActionCommand->m_MouseXdown/ManagerWindow->GetResolutionX());
00238                                 Ydo=((double)m_ItVecActionCommand->m_MouseYdown/ManagerWindow->GetResolutionY());
00239                                 Mx=((double)mousex/ManagerWindow->GetResolutionX());
00240                                 My=((double)mousey/ManagerWindow->GetResolutionY());
00241 
00242                                 /*cout<<"Resolution "<<ManagerWindow->GetResolutionX()<<" "<<ManagerWindow->GetResolutionY()<<endl;
00243                                 cout<<"Xup :"<<Xup<<endl;
00244                                 cout<<"Yup :"<<Yup<<endl;
00245                                 cout<<"Xdo :"<<Xdo<<endl;
00246                                 cout<<"Ydo :"<<Ydo<<endl;
00247                                 cout<<"Mx  :"<<Mx<<endl;
00248                                 cout<<"My  :"<<My<<endl;
00249                                 */
00250                                 
00251                                 if((Xup>Mx)&&(Xdo<Mx)&&(Ydo<My)&&(Yup>My))
00252                                 {
00253                                         std::cout<<"clik dedans"<<std::endl;
00254                                         if(CntAct>0)
00255                                         {
00256                                                 ExCAction       *RecursifActA;
00257                                                 ExCAction       *RecursifActB;
00258                                                 RecursifActA=&RetAct;
00259                                                 for(int i=0;i<CntAct;i++)
00260                                                 {
00261                                                         if(RecursifActA->m_NextAction==NULL)
00262                                                         {
00263                                                                 RecursifActA->m_NextAction=new ExCAction;
00264                                                                 RecursifActB=RecursifActA->m_NextAction;
00265                                                                 RecursifActB->m_Action=m_ItVecActionCommand->m_Action;
00266                                                                 RecursifActB->SetParam(m_ItVecActionCommand->m_Param);
00267                                                         }
00268                                                         RecursifActA=RecursifActA->m_NextAction;
00269                                                 }
00270                                                 CntAct++;
00271                                         }else
00272                                         {
00273                                                 RetAct.m_Action=m_ItVecActionCommand->m_Action;
00274                                                 RetAct.SetParam(m_ItVecActionCommand->m_Param);
00275                                                 CntAct++;
00276                                         }
00277                                 }else
00278                                 {
00279                                         std::cout<<"click hors coordonée"<<std::endl;
00280                                 }
00281                         }
00282                 }
00283         }
00284         if(CntAct==0)
00285         {
00286                 RetAct.m_Action=NOTHING;
00287                 RetAct.SetParam("NULL");
00288         }
00289 
00290         return RetAct;
00291 UnGuard
00292 }

Generated on Tue Dec 10 18:20:03 2002 for ExNihilo by doxygen1.3-rc1