Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

Camera3DAnchorControl.h

Go to the documentation of this file.
00001 /*
00002 12345678901234567890123456789012345678901234567890123456789012345678901234567890
00003 */
00004 #ifndef OglGui_Camera3DAnchorControl_h
00005 #define OglGui_Camera3DAnchorControl_h
00006 
00007 #ifndef OglGui_Button_h
00008 #include "OglGui/Button.h"
00009 #endif
00010 
00011 #ifndef OglGui_TextEdit_h
00012 #include "OglGui/TextEdit.h"
00013 #endif
00014 
00015 namespace OglGui
00016 {
00017 
00018 
00019 class Camera3DAnchorControl : public Window, ButtonListener, WindowListener
00020 {
00021 public:
00022     static const int cNrOfAnchors    = 8;
00023 
00024     struct Anchor3DInfo
00025     {
00026         float   x, y, z;
00027         float   tX, tY, tZ;
00028         float   uX, uY, uZ;
00029         float   rX, rY, rZ;
00030     };
00031 
00032     Camera3DAnchorControl(Window* parent, int x, int y, int w, int h,
00033                           Window* target=0) :
00034         Window(parent, x, y, w, h)
00035     {
00036         Init(w, h, target);
00037     }
00038 
00039     static void PreferredSize(int& w, int &h)
00040     {
00041         w = 200;
00042         h = 200;
00043     }
00044 
00045     std::string GetAnchorString(int ind)
00046     {
00047         if (ind < 0 || ind >= cNrOfAnchors)
00048             ind = 0;
00049         return mStrings[ind]->GetText();
00050     }
00051     void SetAnchorString(int ind, strconst str)
00052     {
00053         if (ind < 0 || ind >= cNrOfAnchors)
00054             return;
00055         mStrings[ind]->SetText(str);
00056     }
00057 
00058     Anchor3DInfo GetAnchor3DInfo(int ind)
00059     {
00060         if (ind < 0 || ind >= cNrOfAnchors)
00061             ind = 0;
00062         return mAnchors[ind];
00063     }
00064 
00065     Button* GoToBtn()           { return mGotoButton; }
00066     Button* AnchorBtn()         { return mAnchorButton; }
00067 
00068     TextEdit* AnchorEdit(int idx)
00069     {
00070         if (idx>=0 && idx<cNrOfAnchors)
00071             return mStrings[idx];
00072     }
00073 
00074     void SetAnchor3DInfo(int index,
00075                    float x,  float y,  float z,
00076                    float tX, float tY, float tZ,
00077                    float uX, float uY, float uZ,
00078                    float rX, float rY, float rZ)
00079     {
00080         if (index < 0 || index >= cNrOfAnchors)
00081             return;
00082         Anchor3DInfo a;
00083         a.x = x;   a.y = y;   a.z = z;
00084         a.tX = tX; a.tY = tY; a.tZ = tZ;
00085         a.uX = uX; a.uY = uY; a.uZ = uZ;
00086         a.rX = rX; a.rY = rY; a.rZ = rZ;
00087         mAnchors[index] = a;
00088     }
00089 
00090     virtual void ButtonSelectionEvent(Button *src, void* userData)
00091     {
00092         if (!mTarget)
00093             return;
00094         SCENE3D* cam = (SCENE3D*) mTarget->GetOGLWND()->sceneInfo;
00095 
00096         if (src == mGotoButton)
00097         {
00098             Anchor3DInfo a = mAnchors[mIndex];
00099             cam->camX = a.x;  cam->camY = a.y;  cam->camZ = a.z;
00100             cam->tX   = a.tX; cam->tY   = a.tY; cam->tZ   = a.tZ;
00101             cam->uX   = a.uX; cam->uY   = a.uY; cam->uZ   = a.uZ;
00102             cam->rX   = a.rX; cam->rY   = a.rY; cam->rZ   = a.rZ;
00103         }
00104         if (src == mAnchorButton)
00105         {
00106             Anchor3DInfo a;
00107             a.x  = cam->camX; a.y  = cam->camY; a.z  = cam->camZ;
00108             a.tX = cam->tX;   a.tY = cam->tY;   a.tZ = cam->tZ;
00109             a.uX = cam->uX;   a.uY = cam->uY;   a.uZ = cam->uZ;
00110             a.rX = cam->rX;   a.rY = cam->rY;   a.rZ = cam->rZ;
00111             mAnchors[mIndex] = a;
00112         }
00113     }
00114 
00115     virtual void
00116     WindowMouseEvent(Window *src, int msg, int but, int state,
00117                      int x, int y, void* userData )
00118     {
00119         if (msg != oglMouseDown)
00120             return;
00121         mIndex = (long long) userData;
00122         for (int i=0; i<cNrOfAnchors; i++)
00123             mStrings[i]->SetBorderBackground(i==mIndex ? 0x80ffaaaa : oglTrWHITE);
00124     }
00125 
00126 private:
00127     void Init(int w, int h, Window* target)
00128     {
00129         mTarget = target;
00130 
00131         int prefW, prefH;
00132         PreferredSize(prefW, prefH);
00133         SetDimensions(prefW, prefH);
00134 
00135         SetBorderType(BEV_ETCHED);
00136         mIndex = 0;
00137 
00138         for (int i=0; i<cNrOfAnchors; i++)
00139         {
00140             char    buf[100];
00141             sprintf(buf, "Anchor %d info string", cNrOfAnchors-i);
00142             mStrings[i] = new TextEdit(this, 4, 4+i*21, W()-8, 21, buf, 0);
00143             mStrings[i]->SetBackground(0);
00144             mStrings[i]->SetBorderBackground(oglTrWHITE);
00145             mStrings[i]->SingleLine(true);
00146             mStrings[i]->SetWindowListener(this, (void*)i);
00147             mAnchors[i].rX = 1;
00148             mAnchors[i].tZ = -1;
00149             mAnchors[i].uY = 1;
00150         }
00151 
00152         int btnY = 6 + cNrOfAnchors*21;
00153         mGotoButton = new Button(this, 4, btnY, 34, 22, "To");
00154         mGotoButton->SetButtonListener(this);
00155 
00156         mAnchorButton = new Button(this, 40, btnY, 64, 22, "Anchor");
00157         mAnchorButton->SetButtonListener(this);
00158 
00159         ScaleChildren();
00160         SetAllowChildScaling(false);
00161         SetDimensions(w,h);
00162     }
00163 
00164     Window*             mTarget;
00165 
00166     Button*             mGotoButton;
00167     Button*             mAnchorButton;
00168     int                 mIndex;
00169     TextEdit*           mStrings[cNrOfAnchors];
00170     Anchor3DInfo        mAnchors[cNrOfAnchors];
00171 };
00172 
00173 } // namespace OglGui
00174 #endif

Generated on Fri Mar 19 09:31:33 2010 for ImpalaSrc by  doxygen 1.5.1