00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "3d.h"
00020 #include "input.h"
00021 #include "controlEngine.h"
00022 #include "title.h"
00023 #include "mylist.h"
00024
00025 extern ControlEngine ce;
00026
00027
00028
00029 Title::Title()
00030 {
00031
00032 name="Title";
00033 focused=FALSE;
00034 state=original;
00035 container=NULL;
00036
00037 SetUses(TRUE,TRUE,TRUE,TRUE);
00038
00039 btnMax.name="btnMax";
00040 btnMin.name="btnMin";
00041 btnClose.name="btnClose";
00042 btnIcon.name="btnIcon";
00043
00044
00045 caption = &tipCaption.text;
00046 caption->Setup(ce.fontTexture,ft_texture);
00047 caption->SetAlign(align_center,align_center);
00048 caption->material.SetDS(1,1,1);
00049 caption->SetWrapping(FALSE,FALSE,FALSE);
00050
00051
00052 btnMin.onButton.click.connect(this,OnMin);
00053 btnMax.onButton.click.connect(this,OnMaxOrOriginal);
00054 btnClose.onButton.click.connect(this,OnClose);
00055 onControl.mouse.move.connect(this,OnMouseMove);
00056 onControl.mouse.left.down.connect(this,OnLButtonDown);
00057 onControl.mouse.mid.down.connect(this,OnMButtonDown);
00058 onControl.mouse.left.up.connect(this,OnLMButtonUp);
00059 onControl.mouse.mid.up.connect(this,OnLMButtonUp);
00060
00061 onControl.key.up.connect(this,OnKeyUp);
00062 onControl.key.down.connect(this,OnKeyDown);
00063 onControl.mouse.left.doubleClick.connect(this,OnMaxOrOriginal);
00064 onControl.mouse.wheel.connect(this,OnMouseWheel);
00065
00066 onControl.over.in.connect(this,OnOverIn);
00067 onControl.over.out.connect(this,OnOverOut);
00068 }
00069
00070
00071
00072 void Title::Create(Control *_container,double depth)
00073 {
00074 SetParent();
00075 container= _container;
00076 faceNode = ce.primitive.AddBox(name,id,depth,FALSE);
00077
00078 int xLeft=2;
00079 ce.Push(this);
00080 ce.primitive.GoTo(FACE_FRONT);
00081 if (useIcon)
00082 {
00083 btnIcon.Create();
00084 btnIcon.faceNode->Elems(FACE_FRONT)->texture=&ce.texture.iconBase;
00085 btnIcon.XDockLeft(2,16);
00086 btnIcon.YDockCenter(2,2);
00087 xLeft+=16;
00088 }
00089 int xRight=2;
00090 if (useClose)
00091 {
00092 btnClose.Create();
00093 btnClose.faceNode->Elems(FACE_FRONT)->texture=&ce.texture.close;
00094 btnClose.XDockRight(xRight,16);
00095 btnClose.YDockCenter(2,2);
00096 xRight+=18;
00097 }
00098 if (useMax)
00099 {
00100 btnMax.Create();
00101 btnMax.faceNode->Elems(FACE_FRONT)->texture=&ce.texture.max;
00102 btnMax.XDockRight(xRight,16);
00103 btnMax.YDockCenter(2,2);
00104 xRight+=18;
00105 }
00106 if (useMin)
00107 {
00108 btnMin.Create();
00109 btnMin.faceNode->Elems(FACE_FRONT)->texture=&ce.texture.min;
00110 btnMin.XDockRight(xRight,16);
00111 btnMin.YDockCenter(2,2);
00112 xRight+=18;
00113 }
00114 tipCaption.Create();
00115 tipCaption.XDockCenter(xLeft+2,xRight+2);
00116 tipCaption.YDockCenter(0,0);
00117 tipCaption.SetAlphaBlending(0);
00118 tipCaption.faceNode->elem->noPicking=TRUE;
00119 ce.Pop();
00120 GotFocus();
00121 }
00122
00123 Title::~Title()
00124 {
00125 ce.timerRefresh.onTimer.disconnect(this);
00126 }
00127
00129 int Title::OnRefresh(Timer *timer)
00130 {
00131
00132 if (!StateKey::GetState(VK_SHIFT))
00133 {
00134 double delta = timer->GetDeltaTime(TRUE)*500.0;
00135 double x=0,y=0,z=0;
00136 if (StateKey::GetState(VK_UP)) y+=delta;
00137 if (StateKey::GetState(VK_DOWN)) y-=delta;
00138 if (StateKey::GetState(VK_LEFT)) x-=delta;
00139 if (StateKey::GetState(VK_RIGHT)) x+=delta;
00140 if (StateKey::GetState(VK_PRIOR)) z-=delta;
00141 if (StateKey::GetState(VK_NEXT)) z+=delta;
00142 if (container&&(x||y||z)) container->Move(x,y,z);
00143 }
00144 return 0;
00145 }
00146
00147 int Title::OnOverIn(Control *oldControl,int face)
00148 {
00149 Debug2Param("Title::OnOverIn(oldCtlr:%s,face:%d",(char *)oldControl->name,face);
00150 ce.cursor.ApplyTypes(cursorArrow,cursorMoving,cursorRepere);
00151 ce.timerRefresh.onTimer.connect(this,OnRefresh);
00152 return 1;
00153 }
00154
00155 int Title::OnOverOut(Control *newControl,int face)
00156 {
00157 Debug2Param("Title::OnOverOut(newCtlr:%s,face:%d",(char *)newControl->name,face);
00158 ce.timerRefresh.onTimer.disconnect(this);
00159 return 1;
00160 }
00161
00162 void Title::SetUses(BOOL _useMin,BOOL _useMax,BOOL _useClose,BOOL _useIcon)
00163 {
00164 useMin=_useMin;
00165 useMax=_useMax;
00166 useClose=_useClose;
00167 useIcon=_useIcon;
00168 }
00169
00170 void Title::SetText(char *newCaption)
00171 {
00172 caption->SetText(newCaption);
00173 }
00174
00178 int Title::OnMaxOrOriginal(StateMouse *mouse,int face)
00179 {
00180 DebugMouse2("Title::OnMaxOrOriginal",mouse,face);
00181 switch (state)
00182 {
00183 case original: OnMax(); break;
00184 case maximize: OnOriginal(); break;
00185 }
00186 return 1;
00187 }
00188
00189 int Title::OnMaxOrOriginal()
00190 {
00191 Debug0Param("Title::OnMaxOrOriginal");
00192 switch (state)
00193 {
00194 case original: OnMax(); break;
00195 case maximize: OnOriginal(); break;
00196 }
00197 return 1;
00198 }
00199
00208 int Title::OnOriginal()
00209 {
00210 Debug0Param("Title::OnOriginal()");
00211 if (useMax) btnMax.faceNode->Elems(FACE_FRONT)->texture=&ce.texture.max;
00212 state=original;
00213 if (container)
00214 {
00215 container->faceNode->elem->angle = originalAngle;
00216 container->faceNode->elem->size= originalSize;
00217 container->faceNode->MoveTo(tempNode);
00218 }
00219 ce.taskWindow->Restore(this);
00220 return 1;
00221 }
00222
00226 int Title::OnMouseWheel(StateMouse *mouse,int face)
00227 {
00228 DebugMouse2("Title::OnMouseWheel",mouse,face);
00229 if (!container) return 0;
00230 container->Move(0,0,-mouse->wheelDelta/10.0);
00231 return 1;
00232 }
00233
00241 int Title::OnMin()
00242 {
00243 Debug0Param("Title::OnMin()");
00244 state=minimize;
00245 if (container)
00246 {
00247 originalAngle = container->faceNode->elem->angle;
00248 originalSize = container->faceNode->elem->size;
00249 tempNode=container->faceNode->parent;
00250 container->faceNode->MoveTo(ce.trash.GetRoot());
00251 ce.taskWindow->Add(this);
00252 }
00253 onTitle.minimize();
00254 return 1;
00255 }
00256
00262 int Title::OnMax()
00263 {
00264 Debug0Param("Title::OnMax()");
00265 state=maximize;
00266 if (useMax) btnMax.faceNode->Elems(FACE_FRONT)->texture=&ce.texture.maxAlternate;
00267 if (container)
00268 {
00269 originalAngle = container->faceNode->elem->angle;
00270 originalSize = container->faceNode->elem->size;
00271 tempNode=container->faceNode->parent;
00272 container->RotateTo(0,0,0);
00273 container->faceNode->elem->angle.Zero();
00274 container->faceNode->MoveTo(ce.primitive.tree.GetRoot());
00275 }
00276 onTitle.maximize();
00277 return 1;
00278 }
00279
00283 int Title::OnKeyUp(StateKey *key,int face)
00284 {
00285 DebugKey2("Title::OnKeyUp",key,face);
00286 switch(key->code)
00287 {
00288 case VK_ESCAPE: OnClose(); return 1;
00289 case VK_HOME:
00290 if (!container) return 0;
00291 container->RotateTo(0,0,0);
00292 return 1;
00293 }
00294 return 0;
00295 }
00296
00300 int Title::OnKeyDown(StateKey *key,int face)
00301 {
00302 DebugKey2("Title::OnKeyDown",key,face);
00303 if (!container) return 0;
00304 BOOL shift = StateKey::GetState(VK_SHIFT);
00305 if (shift)
00306 {
00307 switch(key->code)
00308 {
00309 case VK_UP: container->RotateQuaternion(0,90/4.0,FALSE); return 1;
00310 case VK_DOWN: container->RotateQuaternion(0,-90/4.0,FALSE); return 1;
00311 case VK_LEFT: container->RotateQuaternion(90/4.0,0,FALSE); return 1;
00312 case VK_RIGHT: container->RotateQuaternion(-90/4.0,0,FALSE); return 1;
00313 }
00314 }
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329 return 0;
00330 }
00331
00335 int Title::OnMouseMove(StateMouse *mouse,int deltaX,int deltaY,int face)
00336 {
00337
00338 if (!container) return 0;
00339
00340 if (face!=FACE_FRONT) return 0;
00341 if (mouse->GetNbButtonPush()==1)
00342 {
00343 if (mouse->leftBtn) container->Move(-deltaX,deltaY,0);
00344 if (mouse->midBtn) container->RotateQuaternion(deltaX,deltaY,0);
00345 if (mouse->leftBtn||mouse->midBtn) return 1;
00346 }
00347 return 0;
00348 }
00349
00350 int Title::OnLButtonDown(StateMouse *mouse,int face)
00351 {
00352 DebugMouse2("Title::OnLButtonDown",mouse,face);
00353 oldMouse=*mouse;
00354 GotFocus();
00355 ce.cursor.ApplyTypes(cursorMoving,cursorArrow,cursorRepere);
00356 return 1;
00357 }
00358
00359 int Title::OnMButtonDown(StateMouse *mouse,int face)
00360 {
00361 DebugMouse2("Title::OnMButtonDown",mouse,face);
00362 oldMouse=*mouse;
00363 GotFocus();
00364 ce.cursor.ApplyTypes(cursorRepere,cursorMoving,cursorArrow);
00365 return 1;
00366 }
00367
00368 int Title::OnLMButtonUp(StateMouse *mouse,int face)
00369 {
00370 DebugMouse2("Title::OnLMButtonUp",mouse,face);
00371 ce.cursor.ApplyTypes(cursorArrow,cursorMoving,cursorRepere);
00372 return 0;
00373 }
00374
00380 void Title::GotFocus()
00381 {
00382
00383
00384 Debug0Param("Title::GotFocus()");
00385 focused=TRUE;
00386 faceNode->Elems(FACE_FRONT)->texture=&ce.texture.degradeeFocus;
00387 faceNode->Elems(FACE_FRONT)->material.SetDS(1,1,1);
00388 faceNode->Elems(FACE_LEFT)->material.SetDS(10/256.0,36/256.0,106/256.0);
00389 faceNode->Elems(FACE_RIGHT)->material.SetDS(166/256.0,202/256.0,240/256.0);
00390 faceNode->Elems(FACE_TOP)->material.SetDS(0,0,0.4f);
00391 faceNode->Elems(FACE_BOTTOM)->material.SetDS(0,0,0.4f);
00392
00393 onTitle.gotFocus();
00394 }
00395
00399 void Title::LostFocus()
00400 {
00401 Debug0Param("Title::LostFocus()");
00402 focused=FALSE;
00403 faceNode->Elems(FACE_FRONT)->texture=&ce.texture.degradeeUnFocus;
00404 faceNode->Elems(FACE_FRONT)->material.SetDS(1,1,1,0);
00405 faceNode->Elems(FACE_LEFT)->material.SetDS(128/256.0,128/256.0,128/256.0,0);
00406 faceNode->Elems(FACE_RIGHT)->material.SetDS(192/256.0,192/256.0,192/256.0,0);
00407 faceNode->Elems(FACE_TOP)->material.SetDS(.5,.5,.5);
00408 faceNode->Elems(FACE_BOTTOM)->material.SetDS(.5,.5,.5);
00409
00410 onTitle.lostFocus();
00411 }
00412
00416 int Title::OnClose()
00417 {
00418 Debug0Param("Title::OnClose()");
00419
00420 onTitle.close();
00421 return 1;
00422 }
00423
00424
00425
00426 void Title::ToString(MyString &str)
00427 {
00428 str.AddFormat("name: %s caption:%s focused:%d",
00429 name,faceNode->Elems(FACE_FRONT)->text->GetText(),focused);
00430 }
00431
00432