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

# ExCWindow.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 "ExCWindow.h"
    00024 //--------------------------------
    00025 // Constructor // Destructor
    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
    00070 /*
    00071         ExCWindowLabel *Label;
    00072         Label = new ExCWindowLabel(ExCVec2D(100,22),ExCVec2D(10,10));
    00073         m_Window.AddObjectControl(Label);
    00074
    00075
    00076         ExCWindowEditLabel *EditLAbel;
    00077         EditLAbel = new ExCWindowEditLabel(ExCVec2D(100,22),ExCVec2D(10,50));
    00078         m_Window.AddObjectControl(EditLAbel);
    00079 */
    00080
    00081 UnGuard
    00082 }
    00083
    00084 void ExCWindow::Init(void)
    00085 {
    00086 Guard(void ExCWindow::Init(void))
    00087         ExCWindowObject::Init();
    00088         SetName("ExCWindow");
    00089         SetType(typeid(this).name());
    00090         SetTitleBarSize(24);
    00091         m_BeClosed=false;
    00092         m_CloseButton= new ExCWindowButton;
    00093         m_MaximizeButton= new ExCWindowButton;
    00094         m_MinimizeButton= new ExCWindowButton;
    00095         m_MinimizeToBarButton= new ExCWindowButton;
    00096         //-----------------------------
    00097         //Create Bar
    00098         //-----------------------------
    00099         m_TitleBar.SetName("BarWindow"+GetWindowTitle());
    00100         m_TitleBar.ShowWindowTitle(true);
    00101         m_TitleBar.SetWindowTitle(GetWindowTitle());
    00102         m_TitleBar.SetWindowTitleColor(ExCVec3D(0.5f,0.0f,0.0f));
    00103         m_TitleBar.SetBackroundTexturing1(true,"bar");
    00104         m_TitleBar.SetBackroundTexturing2(true,"back3");
    00105         m_TitleBar.SetTextureIsMouving(true);
    00106         m_TitleBar.SetTextureMouvingVec(ExCVec2D(0.0001f,0.0f));
    00107         m_TitleBar.SetBackroundColor(ExCVec3D(1.0f,1.0f,1.0f));
    00108         m_TitleBar.SetCanMouve(true);
    00109         m_TitleBar.SetBorderColor(ExCVec3D(0.5f,0.5f,0.5f));
    00110         m_TitleBar.AddObjectControl(m_CloseButton);
    00111         m_TitleBar.AddObjectControl(m_MaximizeButton);
    00112         m_TitleBar.AddObjectControl(m_MinimizeButton);
    00113         m_TitleBar.AddObjectControl(m_MinimizeToBarButton);
    00114         //------------------------------
    00115         m_CloseButton->SetName("CloseButton");
    00116         m_CloseButton->SetBackroundTexturing1(true,"ButtClose.bmp");
    00117         m_CloseButton->SetBackroundTexturing2(false,"NONE");
    00118         m_CloseButton->SetBackroundColor(ExCVec3D(0.5f,0.5f,0.5f));
    00119         m_CloseButton->AddActionCommand(ExCAction(CLOSE_OBJECT_WINDOW),ExCCommand(MOUSE_LEFT_BUTTON_DOWN));
    00120         //------------------------------
    00121         m_MaximizeButton->SetName("ButtMax");
    00122         m_MaximizeButton->SetBackroundTexturing1(true,"ButtMax.bmp");
    00123         m_MaximizeButton->SetBackroundTexturing2(false,"NONE");
    00124         m_MaximizeButton->SetBackroundColor(ExCVec3D(0.5f,0.5f,0.5f));
    00125         m_MaximizeButton->AddActionCommand(ExCAction(MAXIMIZE_OBJECT_WINDOW),ExCCommand(MOUSE_LEFT_BUTTON_DOWN));
    00126         //------------------------------
    00127         m_MinimizeButton->SetName("ButtMin");
    00128         m_MinimizeButton->SetBackroundTexturing1(true,"ButtMin.bmp");
    00129         m_MinimizeButton->SetBackroundTexturing2(false,"NONE");
    00130         m_MinimizeButton->SetBackroundColor(ExCVec3D(0.5f,0.5f,0.5f));
    00131         m_MinimizeButton->AddActionCommand(ExCAction(MINIMIZE_OBJECT_WINDOW),ExCCommand(MOUSE_LEFT_BUTTON_DOWN));
    00132         //------------------------------
    00133         m_MinimizeToBarButton->SetName("ButtBar");
    00134         m_MinimizeToBarButton->SetBackroundTexturing1(true,"ButtBar.bmp");
    00135         m_MinimizeToBarButton->SetBackroundTexturing2(false,"NONE");
    00136         m_MinimizeToBarButton->SetBackroundColor(ExCVec3D(0.5f,0.5f,0.5f));
    00137         m_MinimizeToBarButton->AddActionCommand(ExCAction(MINIMIZE_TO_BAR_OBJECT_WINDOW),ExCCommand(MOUSE_LEFT_BUTTON_DOWN));
    00138         //------------------------------
    00139         //Create window
    00140         //------------------------------
    00141         m_Window.SetName("MainWindow"+GetWindowTitle());
    00142         m_Window.SetBackroundTexturing1(false,"back");
    00143         m_Window.SetBackroundTexturing2(false,"fire");
    00144         m_Window.SetBackroundColor(ExCVec3D(1.0f,1.0f,1.0f));
    00145         m_Window.SetCanMouve(false);
    00146
    00147 UnGuard
    00148 }
    00149
    00150 ExCWindow::~ExCWindow(void)
    00151 {
    00152 }
    00153
    00154 //--------------------------------
    00155 // Methode
    00156 //--------------------------------
    00157 void ExCWindow::Draw(void)
    00158 {
    00159 Guard(void ExCWindow::Draw(void))
    00160         //std::cout<<"Draw windows"<<std::endl;
    00161         ExNihilo::EnterOrthoMode();
    00162         glPushAttrib(GL_ALL_ATTRIB_BITS);
    00163                 glDisable(GL_LIGHTING);
    00164                 //Draw TitleBar
    00165                 m_TitleBar.Draw();
    00166                 //Draw Window
    00167                 //if(m_Window.IsShowWindow())
    00168                 m_Window.Draw();
    00169         glPopAttrib();
    00170         ExNihilo::LeaveOrthoMode();
    00171 UnGuard
    00172 }
    00173
    00174
    00175
    00176 ExCAction ExCWindow::InputCommand(ExCCommand Command)
    00177 {
    00178 Guard(ExCAction ExCWindow::InputCommand(ExCCommand Command))
    00179         //std::cout<<"ExCWindow::Input Command window:"<<Command.m_Command<<std::endl;
    00180         /*switch(Command.m_Command)
    00181         {
    00182         default :*/
    00183                 if(m_TitleBar.PointInWindow(ExCVec2D(Command.m_MousePosx,Command.m_MousePosy)))
    00184                 {
    00185                         //std::cout<<"Dans la bar"<<std::endl;
    00186                         return InputAction(m_TitleBar.InputCommand(Command));
    00187                 }
    00188                 if(m_Window.PointInWindow(ExCVec2D(Command.m_MousePosx,Command.m_MousePosy)))
    00189                 {
    00190                         //std::cout<<"Dans la fenetre"<<std::endl;
    00191                         return InputAction(m_Window.InputCommand(Command));
    00192                 }
    00193 /*
    00194                 break;
    00195         }*/
    00196
    00197         return NOTHING;
    00198 UnGuard
    00199 }
    00200
    00201 ExCAction ExCWindow::InputAction(ExCAction Action)
    00202 {
    00203 Guard(ExCAction ExCWindow::InputAction(ExCAction Action))
    00204         /*switch(Action.m_Action)
    00205         {
    00206         default:
    00207                 return Action;
    00208         }
    00209         if(Action.m_NextAction){return *Action.m_NextAction;}
    00210         else{return NOTHING;}*/
    00211         return Action;
    00212 UnGuard
    00213 }
    00214
    00215 void ExCWindow::SetManagerTexture(ExManagerTexture * Texture)
    00216 {
    00217 Guard(void ExCWindow::SetManagerTexture(ExManagerTexture * Texture))
    00218         ManagerTexture = Texture;
    00219         m_TitleBar.SetManagerTexture(ManagerTexture);
    00220         m_Window.SetManagerTexture(ManagerTexture);
    00221 UnGuard
    00222 }
    00223
    00224 void ExCWindow::RefreshPosotion(void)
    00225 {
    00226 Guard(void ExCWindow::RefreshPosotion(void))
    00227         //std::cout<<"Refresh pos"<<std::endl;
    00228         m_TitleBar.SetPosition(ExCVec2D(m_Position.GetX(),m_Position.GetY()));
    00229         m_Window.SetPosition(ExCVec2D(m_Position.GetX(),(m_Position.GetY()+m_TitleBarSize)));
    00230         m_CloseButton->SetPosition(ExCVec2D(m_TitleBar.GetPosition().GetX()+m_WindowSize.GetX()-m_TitleBarSize,m_TitleBar.GetPosition().GetY()+2));
    00231         m_MaximizeButton->SetPosition(ExCVec2D(m_TitleBar.GetPosition().GetX()+m_WindowSize.GetX()-m_TitleBarSize*2,m_TitleBar.GetPosition().GetY()+2));
    00232         m_MinimizeButton->SetPosition(ExCVec2D(m_TitleBar.GetPosition().GetX()+m_WindowSize.GetX()-m_TitleBarSize*3,m_TitleBar.GetPosition().GetY()+2));
    00233         m_MinimizeToBarButton->SetPosition(ExCVec2D(m_TitleBar.GetPosition().GetX()+m_WindowSize.GetX()-m_TitleBarSize*4,m_TitleBar.GetPosition().GetY()+2));
    00234         for(unsigned int i=0;i<m_Window.GetVecWindowObject()->size();i++)
    00235         {
    00236                 m_Window.GetVecWindowObject()->at(i)->SetPosition(
    00237                         ExCVec2D(m_Window.GetPosition()+(m_Window.GetVecWindowObject()->at(i)->GetPosition()-m_Window.GetOldPosition())));
    00238         }
    00239 UnGuard
    00240 }
    00241 void ExCWindow::RefreshSize(void)
    00242 {
    00243 Guard(void ExCWindow::RefreshSize(void))
    00244         m_TitleBar.SetWindowSize(ExCVec2D(m_WindowSize.GetX(),m_TitleBarSize));
    00245         m_Window.SetWindowSize(ExCVec2D(m_WindowSize.GetX(),m_WindowSize.GetY()-m_TitleBarSize));
    00246         m_CloseButton->SetWindowSize(ExCVec2D(m_TitleBarSize-3,m_TitleBarSize-4));
    00247         m_MaximizeButton->SetWindowSize(ExCVec2D(m_TitleBarSize-3,m_TitleBarSize-4));
    00248         m_MinimizeButton->SetWindowSize(ExCVec2D(m_TitleBarSize-3,m_TitleBarSize-4));
    00249         m_MinimizeToBarButton->SetWindowSize(ExCVec2D(m_TitleBarSize-3,m_TitleBarSize-4));
    00250 UnGuard
    00251 }
    00252
    00253 void ExCWindow::SetWindowSize(ExCVec2D vec)
    00254 {
    00255 Guard(void ExCWindow::SetWindowSize(ExCVec2D vec))
    00256         m_WindowSize=vec;
    00257         RefreshSize();
    00258 UnGuard
    00259 }
    00260 void ExCWindow::SetOldWindowSize(ExCVec2D vec)
    00261 {
    00262 Guard(void ExCWindow::SetOldWindowSize(ExCVec2D vec))
    00263         m_OldSize=vec;
    00264 UnGuard
    00265 }
    00266
    00267 void ExCWindow::SetWindowPosition(ExCVec2D vec)
    00268 {
    00269 Guard(void ExCWindow::SetWindowPosition(ExCVec2D vec))
    00270         SetOldPosition(GetPosition());
    00271         SetPosition(vec);
    00272         RefreshPosotion();
    00273         RefreshSize();
    00274
    00275 UnGuard
    00276 }
    00277
    00278 void ExCWindow::SetOldPosition(ExCVec2D vec)
    00279 {
    00280 Guard(void ExCWindow::SetOldPosition(ExCVec2D vec))
    00281         m_OldPosition=vec;
    00282 UnGuard
    00283 }
    00284 void ExCWindow::SetTitleBarSize(float size)
    00285 {
    00286 Guard(void ExCWindow::SetTitleBarSize(float size))
    00287         m_TitleBarSize=size;
    00288         m_TitleBar.SetWindowSize(ExCVec2D(m_WindowSize.GetX(),m_TitleBarSize));
    00289 UnGuard
    00290 }
    00291
    00292 void ExCWindow::SetWindowTitle(std::string Title)
    00293 {
    00294         m_WindowTitle=Title;
    00295         m_TitleBar.SetWindowTitle(Title);
    00296 }
    00297 std::string  ExCWindow::GetWindowTitle(void)
    00298 {
    00299         return m_TitleBar.GetWindowTitle();
    00300 }
    00301 void ExCWindow::SetWindowOldTitle(std::string Title)
    00302 {
    00303         m_WindowOldTitle=Title;
    00304         m_TitleBar.SetWindowOldTitle(Title);
    00305 }
    00306 std::string  ExCWindow::GetWindowOldTitle(void)
    00307 {
    00308         return m_TitleBar.GetWindowOldTitle();
    00309 }
    00310 void ExCWindow::SetWindowTitleColor(ExCVec3D Color)
    00311 {
    00312         m_WindowTitleColor=Color;
    00313         m_TitleBar.SetWindowTitleColor(Color);
    00314 }
    00315 ExCVec3D ExCWindow::GetWindowTitleColor(void)
    00316 {
    00317         return m_TitleBar.GetWindowTitleColor();
    00318 }
    00319
    00320 bool ExCWindow::PointInWindow(ExCVec2D point)
    00321 {
    00322         if(ExCWindowObject::PointInWindow(point))
    00323         {
    00324                 if(m_TitleBar.PointInWindow(point))return true;
    00325                 if(m_Window.PointInWindow(point))
    00326                 {
    00327                         if(m_Window.IsShowWindow())return true;
    00328                         else return false;
    00329                 }
    00330
    00331         }
    00332         return false;
    00333
    00334 }