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

trackButton.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 "myList.h"
00023 #include "texture.h"
00024 #include "button.h"
00025 #include "trackButton.h"
00026 
00027 extern ControlEngine ce;
00028 
00029 TrackButton::TrackButton()      
00030 {
00031         // init variable
00032         name="TrackButton";
00033         orientation=(DockPos)0;
00034         onControl.over.out.connect(this,OnOverOut);
00035         SetResizeAndRotate(FALSE,FALSE);
00036         isMoving=FALSE;
00037 
00038         // gestion des evenements
00039 }
00040 
00041 TrackButton::~TrackButton()
00042 {
00043 }
00044 
00045 // ********************************************************************************
00046 
00047 BOOL TrackButton::Create(double depth)
00048 {
00049         // si pas de mouvement de liberté possible ==> pas de trackBar
00050         if (!canResize&&!canRotate) return FALSE; 
00051         SetParent();
00052 
00053         // init general
00054         faceNode = ce.primitive.AddBox(name,id,depth,TRUE); 
00055         faceNode->elem->material.SetDS(0.4f,0.4f,0.4f);
00056         SetAlphaBlending(0.7f);
00057         ApplyMode();
00058         return TRUE;
00059 }
00060 
00061 void TrackButton::SetResizeAndRotate(BOOL resize,BOOL rotate)
00062 {
00063         canResize = resize;
00064         canRotate = rotate;
00065 }
00066 
00067 void TrackButton::SetMode(DockPos newOrientation)
00068 {
00069         if (orientation!=newOrientation)
00070         {
00071                 orientation = newOrientation;
00072                 ApplyMode();
00073         }
00074 }
00075 
00077 
00078 void TrackButton::ApplyMode()
00079 {
00080         ce.Push(this);
00081 
00082         switch(orientation)
00083         {
00084         case left|top:          Config(OnClickLeftTop,&ce.texture.arrowOblique,0); break;
00085         case left|bottom:       Config(OnClickLeftBottom,&ce.texture.arrowOblique,90); break;
00086         case right|top:         Config(OnClickRightTop,&ce.texture.arrowOblique,-90); break;
00087         case right|bottom:      Config(OnClickRightBottom,&ce.texture.arrowOblique,180); break;
00088         case left:                      Config(OnClickLeft,&ce.texture.arrow,0); break;
00089         case right:                     Config(OnClickRight,&ce.texture.arrow,180); break;
00090         case top:                       Config(OnClickTop,&ce.texture.arrow,-90);       break;
00091         case bottom:            Config(OnClickBottom,&ce.texture.arrow,90); break;
00092         }
00093         ce.Pop();
00094 }
00095 
00096 void TrackButton::Config(int (TrackButton::*onClickFace)(StateMouse *,int),Texture *texture,double angleZ)
00097 {
00098         if (!faceNode) return;
00099         for (int i=0;i<6;i++) faceNode->Elems(i)->texture=texture;
00100         RotateTo(0,0,angleZ);
00101         onControl.mouse.left.click.disconnect_all();
00102         if (canRotate) onControl.mouse.left.click.connect(this,onClickFace);
00103         onControl.mouse.move.disconnect_all();
00104         if (canResize) onControl.mouse.move.connect(this,OnMouseMove);
00105 }
00106 
00107 int TrackButton::OnClickLeft(StateMouse *mouse,int face)
00108 {
00109         DebugMouse2("TrackButton::OnClickLeft",mouse,face);
00110         if (!isMoving&&parent) parent->Rotate(0,-90,0);
00111         return 1;
00112 }
00113 
00114 int TrackButton::OnClickRight(StateMouse *mouse,int face)
00115 {
00116         DebugMouse2("TrackButton::OnClickRight",mouse,face);
00117         if (!isMoving&&parent) parent->Rotate(0,90,0);
00118         return 1;
00119 }
00120 
00121 int TrackButton::OnClickTop(StateMouse *mouse,int face)
00122 {
00123         DebugMouse2("TrackButton::OnClickTop",mouse,face);
00124         if (!isMoving&&parent) parent->Rotate(-90,0,0);
00125         return 1;
00126 }
00127 
00128 int TrackButton::OnClickBottom(StateMouse *mouse,int face)
00129 {
00130         DebugMouse2("TrackButton::OnClickBottom",mouse,face);
00131         if (!isMoving&&parent) parent->Rotate(90,0,0);
00132         return 1;
00133 }
00134 
00135 int TrackButton::OnClickLeftTop(StateMouse *mouse,int face)
00136 {
00137         DebugMouse2("TrackButton::OnClickLeftTop",mouse,face);
00138         if (!isMoving&&parent) parent->Rotate(-90,-90,0);
00139         return 1;
00140 }
00141 
00142 int TrackButton::OnClickLeftBottom(StateMouse *mouse,int face)
00143 {
00144         DebugMouse2("TrackButton::OnClickLeftBottom",mouse,face);
00145         if (!isMoving&&parent) parent->Rotate(90,-90,0);
00146         return 1;
00147 }
00148 
00149 int TrackButton::OnClickRightTop(StateMouse *mouse,int face)
00150 {
00151         DebugMouse2("TrackButton::OnClickRightTop",mouse,face);
00152         if (!isMoving&&parent) parent->Rotate(-90,90,0);
00153         return 1;
00154 }
00155 
00156 int TrackButton::OnClickRightBottom(StateMouse *mouse,int face)
00157 {
00158         DebugMouse2("TrackButton::OnClickRightBottom",mouse,face);
00159         if (!isMoving&&parent) parent->Rotate(-90,90,0);
00160         return 1;
00161 }
00162 
00167 int TrackButton::OnMouseMove(StateMouse *mouse,int deltaX,int deltaY,int face)
00168 {
00169         //DebugMouse2("TrackButton::OnMouseMove",mouse,face);
00170         if (!parent) return 0;
00171         isMoving=FALSE;
00172         if (mouse->leftBtn) 
00173         {
00174                 isMoving=TRUE;
00175                 switch(orientation)
00176                 {
00177                 case left|top:          parent->ReSize(deltaX*2,deltaY*2); break;
00178                 case left|bottom:       parent->ReSize(deltaX*2,-deltaY*2); break;
00179                 case right|top:         parent->ReSize(-deltaX*2,deltaY*2); break;
00180                 case right|bottom:      parent->ReSize(-deltaX*2,-deltaY*2); break;
00181                 case left:                      parent->ReSize(deltaX*2,0); break;
00182                 case right:                     parent->ReSize(-deltaX*2,0); break;
00183                 case top:                       parent->ReSize(0,deltaY*2); break;
00184                 case bottom:            parent->ReSize(0,-deltaY*2); break;
00185                 }
00186         }
00187         if (mouse->rightBtn) 
00188         {
00189                 isMoving=TRUE;
00190                 switch(orientation)
00191                 {
00192                 case left|top:          
00193                 case left|bottom:       
00194                 case right|top:         
00195                 case right|bottom:      
00196                         parent->Move(-deltaX,deltaY,0); break;
00197                 case left:                      
00198                 case right:                     
00199                         parent->Move(-deltaX,0,0); break;
00200                 case top:                       
00201                 case bottom:            
00202                         parent->Move(0,deltaY,0); break;
00203                 }
00204         }
00205         return 0; // heritage au parent pour mouvement du control eventuel
00206 }
00207 
00208 int TrackButton::OnOverOut(Control *newControl,int face)
00209 {
00210         Debug2Param("TrackButton::OnOverOut(newCtrl:%s,%d)",(char *)newControl->name,face);
00211         orientation=(DockPos)0;
00212         isMoving = FALSE;
00213         return 0;
00214 }
00215 
00216 void TrackButton::ToString(MyString &str)
00217 {
00218         str.AddFormat("name: %s",name);
00219 }
00220 
00221 // ********************************************************************************

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