00001 #ifndef OglGui_CameraRotateControl_h
00002 #define OglGui_CameraRotateControl_h
00003
00004 #ifndef OglGui_CrossControl_h
00005 #include "OglGui/CrossControl.h"
00006 #endif
00007
00008 namespace OglGui
00009 {
00010 class CameraRotateControl : public CrossControl, WindowListener
00011 {
00012 public:
00013
00014 CameraRotateControl(int x, int y, int w, int h, Window* targetWnd=0) :
00015 CrossControl(x, y, w, h, targetWnd, CAMROT_FW, "Rotate Cam",true)
00016 {
00017 Init(w, h, targetWnd);
00018 }
00019
00020 CameraRotateControl(Window *parent, int w, int h, Window* targetWnd=0) :
00021 CrossControl(parent, w, h, targetWnd, CAMROT_FW, "Rotate Cam",true)
00022 {
00023 Init(w, h, targetWnd);
00024 }
00025
00026 CameraRotateControl(Window *parent, int x, int y, int w, int h,
00027 Window* targetWnd=0) :
00028 CrossControl(parent,x,y,w,h,targetWnd,CAMROT_FW,"Rotate Cam",true)
00029 {
00030 Init(w, h, targetWnd);
00031 }
00032
00033 enum {
00034 CAMROT_FW,
00035 CAMROT_BW,
00036 CAMROT_LEFT,
00037 CAMROT_RIGHT,
00038 CAMROT_UP,
00039 CAMROT_DOWN
00040 };
00041
00042
00043
00044 virtual void
00045 ButtonSelectionEvent(Button *src, void* userData)
00046 {
00047 if (!mTargetWnd)
00048 return;
00049 OGLWND* oglWnd = mTargetWnd->GetOGLWND();
00050 if (userData == (void*)CAMROT_FW)
00051 view3DSys.KeyFunc(oglWnd, oglCTRL('z'),
00052 oglControl | (mCamRotate?oglShift:0));
00053 if (userData == (void*)CAMROT_BW)
00054 view3DSys.KeyFunc(oglWnd, oglCTRL('z'),
00055 oglControl | (mCamRotate?0:oglShift));
00056 if (userData == (void*)CAMROT_LEFT)
00057 view3DSys.KeyFunc(oglWnd, mCamRotate?oglLEFT:oglRIGHT,
00058 oglControl|oglShift);
00059 if (userData == (void*)CAMROT_RIGHT)
00060 view3DSys.KeyFunc(oglWnd, mCamRotate?oglRIGHT:oglLEFT,
00061 oglControl|oglShift);
00062 if (userData == (void*)CAMROT_UP)
00063 view3DSys.KeyFunc(oglWnd, mCamRotate?oglUP:oglDOWN,
00064 oglControl|oglShift);
00065 if (userData == (void*)CAMROT_DOWN)
00066 view3DSys.KeyFunc(oglWnd, mCamRotate?oglDOWN:oglUP,
00067 oglControl|oglShift);
00068
00069 if (src==mResetButton)
00070 view3DSys.KeyFunc(oglWnd, oglHOME, oglControl|oglShift);
00071 }
00072
00073 virtual void
00074 WindowMouseEvent(Window *src, int msg, int but, int state,
00075 int x, int y, void* listenerData)
00076 {
00077 if (src==mButtonGroup && msg == oglMouseDblClick)
00078 mCamRotate = !mCamRotate;
00079 }
00080
00081 virtual void SetTargetWindow(Window* targetWnd)
00082 {
00083 CrossControl::SetTargetWindow(targetWnd);
00084 mCamModelInitialized = false;
00085 }
00086
00087 virtual void
00088 DisplayFunc()
00089 {
00090 char buf[30];
00091 SCENE3D* cam;
00092
00093 if (mTargetWnd && mTargetWnd->GetOGLWND())
00094 {
00095 cam = (SCENE3D *) mTargetWnd->GetOGLWND()->sceneInfo;
00096 if (!mCamModelInitialized)
00097 {
00098 cam->rotateModel = CAM_ROT;
00099 mCamModelInitialized = true;
00100 }
00101 sprintf(buf, "%s %s", mCamRotate ? "Rotate Cam" : "Rotate Scene",
00102 ((cam->rotateModel == SCENE_ROT)) ? "(#)" : "(*)");
00103 mButtonGroup->SetText(buf);
00104 }
00105 Window::DisplayFunc();
00106 }
00107
00108
00109 private:
00110 bool mCamModelInitialized;
00111 bool mCamRotate;
00112
00113 void Init(int w, int h, Window* targetWnd)
00114 {
00115
00116 mCamRotate = true;
00117 mCamModelInitialized = false;
00118 mButtonCross->SetTexts("Z-", "Z+", "Y", "Y", "X", "X");
00119 mButtonGroup->SetWindowListener(this);
00120 }
00121 };
00122
00123 }
00124
00125 #endif