Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

univers.cpp

Go to the documentation of this file.
00001 /* *************************************************************************************
00002         Writer:         Sebastien Bloc
00003         Copyright:      2003-2004
00004         eMail:          sebastien.bloc@free.fr
00005         URL:            http://mignonsoft.free.fr
00006 
00007         This program is free software; you can redistribute it and/or
00008         modify it under the terms of the GNU General Public License
00009         as published by the Free Software Foundation; either version 2
00010         of the License, or (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016         http://www.gnu.org/copyleft/gpl.html
00017 ************************************************************************************* */
00018 
00019 #include "3d.h"
00020 #include "input.h"
00021 #include "controlEngine.h"
00022 #include "univers.h"
00023 #include "mylist.h"
00024 #include "polygonMode.h"
00025 #include "valueEditor.h"
00026 #include "msgBox.h"
00027 #include "tip.h"
00028 
00029 extern ControlEngine ce;
00030 
00031 // ********************************************************************************
00032 
00033 Univers::Univers()
00034 {
00035         // init des variables
00036         isOnMenu=FALSE;
00037         isMenuUsing=FALSE;
00038         name="Univers";
00039         tipKey=NULL;
00040 
00041         // gestion des evenements
00042         onControl.key.down.connect(this,OnKeyDown);
00043         onControl.key.up.connect(this,OnKeyUp);
00044         onControl.mouse.move.connect(this,OnMouseMove);
00045         onControl.mouse.wheel.connect(this,OnMouseWheel);
00046         onControl.mouse.left.down.connect(this,OnLButtonDown);
00047         onControl.mouse.left.up.connect(this,OnLButtonUp);
00048         onControl.mouse.mid.down.connect(this,OnMButtonDown);
00049         onControl.mouse.mid.up.connect(this,OnMButtonUp);
00050         onControl.over.in.connect(this,OnOverIn);
00051         onControl.over.out.connect(this,OnOverOut);
00052 }
00053 
00054 Univers::~Univers()
00055 {
00056         ce.timerRefresh.onTimer.disconnect(this);
00057 }
00058 
00059 // ********************************************************************************
00060 
00061 void Univers::Create()
00062 {       // creation graphics
00063         SetParent();
00064         faceNode = ce.primitive.AddFace(name,id,-1,FALSE,0,0,0,0,0,0,1,0,1);
00065 }
00066 
00067 // ********************************************************************************
00068 
00069 int Univers::OnKeyDown (StateKey *key,int face)
00070 {
00071         DebugKey2("Univers::OnKeyDown",key,face);
00072         if (isOnMenu)
00073         {
00074                 isMenuUsing=TRUE;
00075                 switch (key->code)
00076                 {
00077                 case 'C': ce.primitive.ViewDebug(); UpdateTip(); return 1;
00078                 case 'D': ShowWindow(CreateDialogParam(ce.hInst,MAKEINTRESOURCE(IDD_DEBUG_STRUCT),NULL,(DLGPROC)DebugStructProc,NULL),SW_SHOW); return 1;
00079                 case 'R': ce.screenMain.region.enable^=1; UpdateTip(); return 1;
00080                 case 'F': ce.screenMain.enableFullScreen^=1 ; ce.screenMain.Update(TRUE); UpdateTip(); return 1;
00081                 case 'T': ce.screenMain.enableTitle^=1; ce.screenMain.Update(TRUE); UpdateTip(); return 1;
00082                 //case 'F': ce.screenMain.enableFullScreen=!ce.screenMain.enableFullScreen ; ce.Refresh(FALSE); ce.screenMain.ApplySize(); UpdateTip(); return 1;
00083                 //case 'T': ce.screenMain.enableTitle=!ce.screenMain.enableTitle; ce.Refresh(TRUE); ce.screenMain.ApplySize(); UpdateTip(); return 1;
00084                 case 'L': ce.enableLightView^=1; UpdateTip(); return 1;
00085                 case 'B': ce.enableBackGround^=1; UpdateTip(); return 1;
00086                 case 'A': ce.enableAntiAliasing^=1; UpdateTip(); return 1;
00087                 case 'P': ce.enablePicking^=1; UpdateTip(); return 1;
00088                 case 'E': ce.enableRepere^=1; UpdateTip(); return 1; // lettre 'R' deja pris !
00089                 case 'S': ce.enableFPS^=1; UpdateTip(); return 1;
00090                 case 'M': 
00091                         {
00092                                 // ordre des differents modes
00093                                 PolygonModeType *mode,modes[]= {
00094                                         fill,fill, 
00095                                         line,line, 
00096                                         point,point, 
00097                                         fill,line, 
00098                                         fill,point, 
00099                                         line,fill, 
00100                                         line,point, 
00101                                         point,fill, 
00102                                         point,line};
00103                                 mode = modes;
00104                                 int i;
00105                                 for (i=0;i<9;i++)
00106                                 {
00107                                         if (mode[0]==ce.polygonMode.front && mode[1]==ce.polygonMode.back) break;
00108                                         mode+=2;
00109                                 }
00110                                 if (i==9) mode= modes;
00111                                 else mode+=2;
00112                                 ce.polygonMode.Use(mode[0],mode[1]);
00113                                 UpdateTip(); 
00114                         }
00115                         return 1;
00116                 default:
00117                         isOnMenu=FALSE;
00118                         isMenuUsing=FALSE;
00119                 }
00120         }
00121         BOOL shift = StateKey::GetState(VK_SHIFT);
00122         if (shift)
00123         {
00124                 switch(key->code)
00125                 {
00126                 case VK_LEFT:   RotateQuaternion(90/4.0,0,0);   return 1;
00127                 case VK_RIGHT:  RotateQuaternion(-90/4.0,0,0);  return 1;
00128                 case VK_UP:             RotateQuaternion(0,90/4.0,0);   return 1;
00129                 case VK_DOWN:   RotateQuaternion(0,-90/4.0,0);  return 1;
00130                 //case VK_LEFT: Rotate(0,-90/4.0);      return 1;
00131                 //case VK_RIGHT:        Rotate(0,90/4.0);       return 1;
00132                 //case VK_UP:           Rotate(-90/4.0,0);      return 1;
00133                 //case VK_DOWN: Rotate(90/4.0,0);       return 1;
00134                 }
00135         }
00136         else
00137         {
00138                 switch(key->code)
00139                 {
00140                 //case VK_UP:           Move(0,15,0);   break;
00141                 //case VK_DOWN: Move(0,-15,0);  break;
00142                 //case VK_LEFT: Move(-15,0,0); break;
00143                 //case VK_RIGHT:        Move(15,0,0);   break;
00144                 //case VK_PRIOR:        Move(0,0,-15);  break;
00145                 //case VK_NEXT: Move(0,0,15);   break;
00146 
00147                 case VK_F11: 
00148                         isOnMenu=TRUE; 
00149                         isMenuUsing=FALSE;
00150                         break;
00151                 }
00152         }
00153         return 0;
00154 }
00155 
00156 // ********************************************************************************
00157 
00158 void Univers::ExitQuestion()
00159 {
00160         MsgBox *msgBox = new MsgBox;
00161         ce.Push(ce.masterContainer);
00162                 msgBox->Create();
00163                 msgBox->XDockCenter(160);
00164                 msgBox->YDockCenter(100);
00165                 msgBox->Move(0,0,100);
00166                 msgBox->txtInfo.SetText("Do you realy want to exit");
00167                 msgBox->btnCancel.SetText("No");
00168                 msgBox->btnOk.SetText("Yes");
00169                 msgBox->btnOk.onButton.click.connect(this,OnExit);
00170         ce.Pop();
00171 }
00172 
00173 int Univers::OnExit ()
00174 {
00175         Debug0Param("Univers::OnExit");
00176         ce.timerRefresh.onTimer.connect(this,OnApplyExit);
00177         return 1;
00178 }
00179 
00180 int Univers::OnApplyExit(Timer *)
00181 {
00182         Debug0Param("Univers::OnApplyExit");
00183         ce.timerRefresh.onTimer.disconnect(this);
00184         ce.Stop(); 
00185         return 1;
00186 }
00187 
00188 int Univers::OnKeyUp (StateKey *key,int face)
00189 {
00190         DebugKey2("Univers::OnKeyUp",key,face);
00191         switch (key->code)
00192         {
00193         case VK_ESCAPE: ExitQuestion(); return 1;
00194         case VK_F1: ce.ScreenShot(ssRGB); return 1;
00195         case VK_F2: ce.ScreenShot(ssDepth); return 1;
00196         case VK_F3: ce.ScreenShot(ssLuminance); return 1;
00197         case VK_F4: ce.ScreenShot(ssBlending); return 1;
00198         case VK_HOME: HomePosition(); return 1;
00199         case VK_F11: 
00200                 if (isOnMenu)
00201                 {               
00202                         isOnMenu=FALSE;
00203                         if (!isMenuUsing)
00204                         {
00205                                 if (!tipKey)
00206                                 {
00207                                         tipKey = new Tip;
00208                                         ce.Push(ce.masterContainer);
00209                                         tipKey->Create();
00210                                         tipKey->XDockRight(10,220);
00211                                         tipKey->YDockCenter(300);
00212                                         tipKey->text.SetAlign(align_begin,align_center);
00213                                         UpdateTip();
00214                                         ce.Pop();
00215                                         //ou MessageBox(ce.screenMain.hWnd,temp,"ShortCutKey - Help",0);
00216                                 }
00217                                 else 
00218                                 {
00219                                         delete tipKey;
00220                                         tipKey=NULL;
00221                                 }
00222                                 return 1;
00223                         }
00224                 }
00225                 break;
00226         }
00227         return 0;
00228 }
00229 
00230 void Univers::UpdateTip()
00231 {
00232         if (!tipKey) return;
00233         MyString temp;
00234         MyString sTrue ("True\n");
00235         MyString sFalse("False\n");
00236         temp<<"System Key - Help\n\n";
00237         temp<<"F11+R:\tRegion\t\t"<<(ce.screenMain.region.enable?sTrue:sFalse);
00238         temp<<"F11+F:\tFull screen\t"<<(ce.screenMain.enableFullScreen?sTrue:sFalse);
00239         temp<<"F11+T:\tTitle screen\t"<<(ce.screenMain.enableTitle?sTrue:sFalse);
00240         temp<<"F11+L:\tLightView\t\t"<<(ce.enableLightView?sTrue:sFalse);
00241         temp<<"F11+B:\tBackground\t"<<(ce.enableBackGround?sTrue:sFalse);
00242         temp<<"F11+A:\tAntialiasing\t"<<(ce.enableAntiAliasing?sTrue:sFalse);
00243         temp<<"F11+P:\tPicking\t\t"<<(ce.enablePicking?sTrue:sFalse);
00244         temp<<"F11+E:\tRepere\t\t"<<(ce.enableRepere?sTrue:sFalse);
00245         temp<<"F11+S:\tFPS\t\t"<<(ce.enableFPS?sTrue:sFalse);
00246         temp<<"F11+M:\tMode Polygone\t\n       ";ce.polygonMode.ToString(temp); temp<<"\n";
00247         temp<<"F11+D:\tDebuger\n";
00248         temp<<"F11+C:\tArborecence debug";
00249         tipKey->text.SetText(temp);
00250 }
00251 
00252 void Univers::HomePosition()
00253 {
00254         faceNode->elem->angle.Zero();
00255         faceNode->elem->position.Zero();
00256 }
00257 
00258 int Univers::OnMouseMove(StateMouse *mouse,int deltaX,int deltaY,int face)
00259 {
00260         //DebugMouse2("Univers::OnMouseMove",mouse,face);
00261 
00262         if (mouse->GetNbButtonPush()==1)
00263         {
00264                 if (mouse->midBtn) RotateQuaternion(deltaX,deltaY,0);
00265                 if (mouse->leftBtn) Move(-deltaX,deltaY,0);
00266                 if (mouse->midBtn||mouse->leftBtn) return 1;
00267         }
00268         return 0;
00269 }
00270 
00271 int Univers::OnMouseWheel(StateMouse *mouse,int face)
00272 {
00273         DebugMouse2("Univers::OnWheel",mouse,face);
00274         Move(0,0,-mouse->wheelDelta/10.0);
00275         return 1;
00276 }
00277 
00278 int Univers::OnLButtonDown(StateMouse *mouse,int face)
00279 {
00280         DebugMouse2("Univers::OnLButtonDown",mouse,face);
00281         oldMouse=*mouse;
00282         ce.cursor.ApplyTypes(cursorMoving,cursorArrow);
00283         return 0;
00284 }
00285 
00286 int Univers::OnLButtonUp(StateMouse *mouse,int face)
00287 {
00288         DebugMouse2("Univers::OnLButtonU",mouse,face);
00289         if (ce.cursor.curType==cursorMoving) ce.cursor.curType=cursorArrow;
00290         ce.cursor.leftType=cursorMoving;
00291         ce.cursor.ApplyTypes();
00292         return 0;
00293 }
00294 int Univers::OnMButtonDown(StateMouse *mouse,int face)
00295 {
00296         DebugMouse2("Univers::OnMButtonDown",mouse,face);
00297         oldMouse=*mouse;
00298         ce.cursor.ApplyTypes(cursorRepere,cursorNoChange,cursorArrow);
00299 /*      RECT rect; // clip le curseur 
00300         rect.left=mouse->pos.x-10;
00301         rect.top=mouse->pos.y-10;
00302         rect.right=mouse->pos.x+10;
00303         rect.bottom=mouse->pos.y+10;
00304         ClipCursor(&rect);*/
00305         return 0;
00306 }
00307 
00308 int Univers::OnMButtonUp(StateMouse *mouse,int face)
00309 {
00310         DebugMouse2("Univers::OnMButtonUp",mouse,face);
00311         ClipCursor(NULL);
00312         if (ce.cursor.curType==cursorRepere) ce.cursor.curType=cursorArrow;
00313         ce.cursor.midType=cursorRepere;
00314         ce.cursor.ApplyTypes();
00315         return 0;
00316 }
00317 
00319 int Univers::OnRefresh(Timer *timer)
00320 {
00321         //Debug0Param("Univers::OnRefresh");
00322         if (!StateKey::GetState(VK_SHIFT))
00323         {
00324                 double delta = timer->GetDeltaTime(TRUE)*500.0; // but 20 texel / seconde
00325                 double x=0,y=0,z=0;
00326                 if (StateKey::GetState(VK_UP))          y+=delta;
00327                 if (StateKey::GetState(VK_DOWN))        y-=delta;
00328                 if (StateKey::GetState(VK_LEFT))        x-=delta;
00329                 if (StateKey::GetState(VK_RIGHT))       x+=delta;
00330                 if (StateKey::GetState(VK_PRIOR))       z-=delta;
00331                 if (StateKey::GetState(VK_NEXT))        z+=delta;
00332                 if (x||y||z) Move(x,y,z);
00333         }
00334         return 0;
00335 }
00336 
00337 int Univers::OnOverIn(Control *oldControl,int face)
00338 {
00339         Debug2Param("Univers::OnOverIn(oldCtrl:%s,face:%d)",(char*)oldControl->name,face);
00340         ce.timerRefresh.onTimer.connect(this,OnRefresh);
00341         ce.cursor.ApplyTypes(cursorArrow,cursorMoving,cursorRepere,cursorNothing);
00342         return 0;
00343 }
00344 
00345 int Univers::OnOverOut(Control *newControl,int face)
00346 {
00347         Debug2Param("Univers::OnOverOut(newCtrl:%s,face:%d)",(char*)newControl->name,face);
00348         ce.timerRefresh.onTimer.disconnect(this);
00349         return 0;
00350 }
00351 
00352 // ********************************************************************************
00353 
00354 void Univers::ToString(MyString &str)
00355 {
00356         str.AddFormat("name: %s",name);
00357 }
00358 
00359 // ********************************************************************************

Generated on Fri Aug 20 19:19:51 2004 for 3d Controls by doxygen 1.3.6