Page principale | Liste des namespaces | Hiérarchie des classes | Liste par ordre alphabétique | Liste des composants | Liste des fichiers | Membres des namespaces | Composants | Déclarations

ExCWindowObject.cpp

Aller à la documentation de ce fichier.
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  *
00021  */
00022 
00023 #include "ExCWindowObject.h"
00024 //--------------------------------
00025 // Constructor // Destructor
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         //Manager Pointer
00082         ManagerTexture=NULL;
00083         ManagerWindow=NULL;
00084         //Parent
00085         m_Parent=NULL;
00086         //Title
00087         m_ShowWindowTitle=false;
00088         m_WindowTitle="ExCWindowObject";
00089         m_WindowOldTitle="ExCWindowObject";
00090         m_WindowTitleColor.SetValue(0.1f,0.1f,0.1f);
00091         //Size and position
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         //Color and blending
00099         m_Blending=false;
00100         m_BackroundBlending=0.5f;
00101         m_BackroundColor.SetValue(1.0f,1.0f,1.0f);
00102         //Border 
00103         m_BorderColor.SetValue(0.6f,0.6f,0.6f);
00104         m_BorderSize=1.0f;
00105         m_ShowBorder=true;
00106         //Texturing
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         //Window state
00114         m_CanMouve=false;
00115         m_Mouving=false;
00116         m_Reduced=false;
00117         m_Maximized=false;
00118         m_ShowWindow=true;
00119         m_Active=false;                 //if windows is the active windows
00120 
00121         m_RequestFocus=false;
00122         m_LastObjectFocus=NULL;
00123         m_CurrentObjectFocus=NULL;
00124         m_ObjectRequestFocus=NULL;
00125         //std::cout<<"ExCWindowObject"<<std::endl;
00126 UnGuard
00127 }
00128 //--------------------------------
00129 // Methode
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                         //Draw window content
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                         //glColor3f(1.0f,1.0f,1.0f);
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                         //DrawBorder
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                         //Draw all Child
00224                         //------------------------------
00225                         for(unsigned int i=0;i<m_VecWindowObject.size();i++)
00226                         {
00227                                 //m_VecWindowObject.at(i).SetParrent(this);     
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 void ExCWindowObject::RefreshPosotion(void)
00257 {
00258 Guard(void ExCWindowObject::RefreshPosotion(void))
00259         for(unsigned int i=0;i<m_VecWindowObject.size();i++)
00260         {
00261                 //m_VecWindowObject.at(i)->SetPosition();       
00262         }
00263 UnGuard
00264 }
00265 
00266 void ExCWindowObject::RefreshSize(void)
00267 {
00268 Guard(void ExCWindowObject::RefreshSize(void))
00269         for(unsigned int i=0;i<m_VecWindowObject.size();i++)
00270         {
00271                 //m_VecWindowObject.at(i)->Draw();      
00272         }
00273 UnGuard
00274 }
00275 */
00276 ExCAction ExCWindowObject::InputCommand(ExCCommand Command)
00277 {
00278 Guard(ExCAction ExCWindowObject::InputCommand(ExCCommand Command))
00279         //std::cout<<"ExCWindowObject::Input Command window:"<<Command.m_Command<<std::endl;
00280         //find the good control to send message (one control can not be on other) the first is selected
00281         for(unsigned int i=0;i<m_VecWindowObject.size();i++)
00282         {
00283                 //transfrom position to object position
00284                 ExCVec2D ObjPos(Command.m_MousePosx,Command.m_MousePosy);
00285                 //ObjPos=ObjPos-m_Position;
00286                 //std::cout<<"Window Object name:"<<m_VecWindowObject.at(i)->GetName()<<std::endl;
00287                 //std::cout<<"Window try to routing command :"<<Command.m_Command<<std::endl;
00288                 //std::cout<<"Mouse position:"<<ObjPos<<std::endl;
00289                 //std::cout<<"Object position:"<<m_VecWindowObject.at(i)->GetPosition()<<std::endl;
00290 
00291                 /*if(m_ObjectRequestFocus!=NULL)
00292                 {
00293                         return InputAction(m_ObjectRequestFocus->InputCommand(Command));        
00294                 }*/
00295                 if(m_VecWindowObject.at(i)->PointInWindow(ExCVec2D(Command.m_MousePosx,Command.m_MousePosy)))
00296                 {
00297                         /*std::cout<<"Point in "<<m_VecWindowObject.at(i)->GetName()<<std::endl;
00298                         ExCAction tmpaction;
00299                         tmpaction=m_VecWindowObject.at(i)->InputCommand(Command);       
00300                         std::cout<<"ExCWindowObject routing action :"<<tmpaction<<std::endl;
00301                         return tmpaction;*/
00302                         /*if(m_VecWindowObject.at(i)!=m_LastObjectFocus)
00303                         {
00304                                 m_LastObjectFocus=m_CurrentObjectFocus;
00305                                 m_CurrentObjectFocus=m_VecWindowObject.at(i);
00306                                 if(m_LastObjectFocus!=NULL)
00307                                 {
00308                                         m_LastObjectFocus->InputCommand(ExCCommand(WINDOW_LOSE_FOCUS));
00309                                         m_LastObjectFocus->SetActive(false);
00310                                 }
00311                                 if(m_CurrentObjectFocus!=NULL)
00312                                 {
00313                                         m_CurrentObjectFocus->InputCommand(ExCCommand(WINDOW_GET_FOCUS));
00314                                         m_CurrentObjectFocus->SetActive(true);
00315                                 }
00316                         }*/
00317                         //if(m_ObjectRequestFocus)
00318 
00319                         return InputAction(m_VecWindowObject.at(i)->InputCommand(Command));     
00320                 }
00321                 
00322         }
00323         //Point isnt in any control 
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 }

Généré le Tue Oct 28 12:43:34 2003 pour ExNihilo par doxygen 1.3.4