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

CxCheckBoxDrum.h

Go to the documentation of this file.
00001 #ifndef CxCheckBoxDrum_h
00002 #define CxCheckBoxDrum_h
00003 
00004 #ifndef CxWnd_h
00005 #include "Comp/GUI/CxWnd.h"
00006 #endif
00007 
00009 static char *cbdKeyCmd[] = {
00010                 "",             "",                                     // Empty string generates 6 pixel gap
00011                 "i",    "show/hide this information",
00012                 "",             "",                                     // Empty string generates 6 pixel gap
00013                 "PageUp/PageDown",      "Move camera forward/backward",
00014                 "",             "",                                     // Empty string generates 6 pixel gap
00015                 "ScrollWheel",  "Rotate drum",
00016                 "CTRL x / X", "Decrease/Increase Drum Rotation speed",
00017         "",     "",
00018                 "3",    "Toggle 3D Text",
00019         "",     "",
00020                 "#",    "Pauze/Continue",
00021                 "ESC",  "Reset Drum Rotation",
00022                 "@KEY", "@ACTION",
00023                 NULL,   NULL // The string array must end with a row of NULL.
00024 };
00025 
00026 extern "C" {
00027     static void PickDrawFunc( OGLWND *oglWnd, void *User1, void *User2 )
00028     {
00029             oglSys.InitDrawScene( oglWnd );
00030             oglSys.DrawScene( oglWnd );
00031     }
00032 };
00033 
00034 static void
00035 ShadeRect( int type, float x, float y, float w, float h )
00036 {
00037         float   x1 = x;
00038         float   y1 = y;
00039         float   x2 = x1 + w;
00040         float   y2 = y1 + h;
00041         ULONG   Col1, Col2;
00042 
00043         Col1 = type==BEV_SUNKEN ? oglDARKGREY : oglWHITE;
00044         Col2 = type==BEV_SUNKEN ?  oglWHITE : oglDARKGREY;
00045 
00046         if( type == BEV_LINE ) Col1 = Col2;
00047 
00048         SetSolidLineColor( Col1 );
00049         DrawLine( x1, y1, x1, y2 );
00050         DrawLine( x1, y2, x2, y2);
00051 
00052         SetSolidLineColor( Col2 );
00053         DrawLine( x1, y1, x2, y1 );
00054         DrawLine( x2, y1, x2, y2 );
00055 }
00056 
00057 class CheckBox3D
00058 {
00059 public:
00060 
00061     CheckBox3D(OGLWND *oglWnd, std::string str, float w, float h, bool checked=false)
00062     {
00063         Init(oglWnd, str, w, h, checked);
00064     }
00065 
00066     void
00067     SetSelected(bool checked)
00068     {
00069         mChecked = checked;
00070     }
00071 
00072     bool
00073     GetSelected()
00074     {
00075         return mChecked;
00076     }
00077 
00078     void
00079     SetText(std::string txt)
00080     {
00081         mText = txt;
00082     }
00083 
00084     void
00085     SetSize(float w, float h)
00086     {
00087         mWidth = w;
00088         mHeight = h;
00089     }
00090 
00091     void
00092     ChangeSize(float dW, float dH)
00093     {
00094         SetSize(mWidth+dW, mHeight+dH);
00095     }
00096 
00097     void
00098     SetFrameBorderType( int checked, int unChecked )
00099     {
00100         mCheckedBorderType = checked;
00101         mUnCheckedBorderType = unChecked;
00102     }
00103 
00104     void
00105     SetBoxBorderType( int checked, int unChecked )
00106     {
00107         mCheckedBoxType = checked;
00108         mUnCheckedBoxType = unChecked;
00109     }
00110 
00111     void
00112     Draw(int fontBase, bool drawText=true, bool hitDetect=false)
00113     {
00114         int     brdType;
00115         float   hW = mWidth/2.0f;
00116         float   hH = mHeight/2.0f;
00117         float   tX = -mWidth/2 + 0.65f * mHeight;
00118         float   tY = -0.12f;
00119         float   tZ = 0;
00120 
00121         if( hitDetect ){
00122             glLoadName( (int) this );
00123             SetSolidFillColor( oglGREEN );
00124             FillRectangle(-hW, -hH, mWidth, mHeight );
00125             return;
00126         }
00127 
00128         brdType = mChecked ? mCheckedBorderType : mUnCheckedBorderType;
00129         ShadeRect( brdType, -hW, -hH, mWidth, mHeight );
00130         if (mChecked)
00131         {
00132             SetFillColors( oglWHITE, 0xff60a060, 0xff004000, 0xff60a060, 0 );
00133             FillRectangle(-hW + 0.14f, -0.18f*mHeight, 0.36f*mHeight, 0.36f*mHeight );
00134         }
00135         brdType = mChecked ? mCheckedBoxType : mUnCheckedBoxType;
00136         ShadeRect( brdType, -hW + 0.12f, -0.2f*mHeight, 0.4f*mHeight, 0.4f*mHeight );
00137 
00138         glColor3f( 0.0f, 0.0f, 0.0f );
00139         if( !drawText )
00140             return;
00141 
00142         if (fontBase)
00143                 oglSys.Printf3D( fontBase, tX, tY, 0.01f, 0.4f, 0.4f, 0.02f, mText.c_str() );
00144         else
00145         {
00146             oglSys.Transform1Coord( 1, &tX, &tY, &tZ );
00147             oglSys.TopWndToVP(mOglWnd, &tX, &tY );
00148             if( mShadow2D )
00149                 oglSys.ShadowPrintf(mOglWnd, (int) tX, (int) tY, oglBLACK, oglWHITE,
00150                         "%s", mText.c_str() );
00151             else
00152                 oglSys.PosColPrintf(mOglWnd, (int) tX, (int) tY, oglBLACK,
00153                         "%s", mText.c_str() );
00154         }
00155 
00156     }
00157 
00158 private:
00159 
00160     std::string     mText;
00161     OGLWND*         mOglWnd;
00162     bool            mChecked;
00163     int             mCheckedBorderType;
00164     int             mUnCheckedBorderType;
00165     int             mCheckedBoxType;
00166     int             mUnCheckedBoxType;
00167     float           mWidth;
00168     float           mHeight;
00169     bool            mShadow2D;
00170 
00171     void
00172     Init(OGLWND *oglWnd, std::string str, float w, float h, bool checked)
00173     {
00174         mOglWnd = oglWnd;
00175         mText = str;
00176         mChecked = checked;
00177         mCheckedBorderType = BEV_SUNKEN;
00178         mUnCheckedBorderType = BEV_SUNKEN;
00179         mCheckedBoxType = BEV_SUNKEN;
00180         mUnCheckedBoxType = BEV_RAISED;
00181         mWidth = w;
00182         mHeight = h;
00183         mShadow2D = true;
00184     }
00185 };
00186 
00187 class CxCheckBoxDrum : public CxWnd
00188 {
00189 public:
00190 
00191     CxCheckBoxDrum(int x, int y, int w, int h, int nRow, int nCol) :
00192         CxWnd(x, y, w, h, false)
00193         {
00194                 Init(nRow,nCol);
00195         }
00196 
00197     CxCheckBoxDrum( CxWnd *parent, int w, int h, int nRow, int nCol) :
00198         CxWnd( parent, w, h, false )
00199         {
00200                 Init(nRow,nCol);
00201         }
00202 
00203     CxCheckBoxDrum(CxWnd *parent, int x, int y, int w, int h, int nRow, int nCol) :
00204         CxWnd( parent, x, y, w, h, false )
00205         {
00206                 Init(nRow,nCol);
00207         }
00208 
00209     CheckBox3D*
00210     AddCheckBox(strconst str, int colNr, int rowNr, bool checked=false)
00211     {
00212         return
00213         mCheckBoxes[rowNr * mNrColumns + colNr] =
00214                 new CheckBox3D( mOglWnd, str, mCbWidth, mCbHeight, checked );
00215     }
00216 
00217     void
00218     SetRadius(float radius)
00219     {
00220         mRadius = radius;
00221     }
00222 
00223     void
00224     SetPosition(float x, float y, float z)
00225     {
00226         mDrumX = x;
00227         mDrumY = y;
00228         mDrumZ = z;
00229     }
00230 
00231     void
00232     SetCheckBoxSize(float w, float h)
00233     {
00234         CheckBox3D  *cB;
00235         int n = mNrRows * mNrColumns;
00236 
00237         mCbWidth = w;
00238         mCbHeight = h;
00239         while (--n >= 0)
00240         {
00241             if (cB = mCheckBoxes[n])
00242                 cB->SetSize(w,h);
00243         }
00244     }
00245 
00246     void
00247     ChangeCheckBoxSize(float dW, float dH)
00248     {
00249         SetCheckBoxSize(mCbWidth+dW, mCbHeight+dH);
00250     }
00251 
00252     void
00253     SetText3D(bool mode=true)
00254     {
00255         mTxt3D = mode;
00256     }
00257 
00258     void
00259     HandleCategory(CheckBox3D *cB)
00260     {
00261         bool    mode = false;
00262         int     i;
00263 
00264         for (i=0; i<mNrRows; i++)
00265             if ( mode = (mCheckBoxes[i*mNrColumns] == cB) )
00266                 break;
00267         if( !mode )
00268             return;
00269 
00270         CheckBox3D *cbTarget;
00271         mode = cB->GetSelected();
00272 
00273 
00274         do {
00275             for (int j=1; j<mNrColumns; j++ )
00276                 if (cbTarget = mCheckBoxes[i*mNrColumns+j] )
00277                     cbTarget->SetSelected(mode);
00278                     i++;
00279         } while( i<mNrRows && !mCheckBoxes[i*mNrColumns] );
00280     }
00281 
00282         virtual void InitFunc()
00283         {
00284                 OGLWND *oglWnd = oglSys.GetTopOGLWND( mOglWnd );
00285 
00286         int font = 1;
00287 #ifndef OGL_USING_GLUT
00288                 font = (int) CreateFont( -12, 0, 0, 0, FW_NORMAL, 0, 0, 0,
00289                         ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
00290                         ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "Verdana" );
00291 #endif
00292                 // Transform MsWindows fonts to OpenGL fontBases
00293                 txtFontBase = oglSys.Create3DFont( mOglWnd, (int) font, 1, 0.6f, NULL );
00294 
00295 #ifndef OGL_USING_GLUT
00296                 // MsWindows font no longer needed
00297                 DeleteObject( (HFONT) font );
00298 #endif
00299                 CxWnd::InitFunc();
00300 
00301         DrumInfoBox = oglSys.InfoBoxStrArr( oglWnd, &cbdKeyCmd[0], 2, 20, 0x0080ff, oglRED, oglWHITE );
00302                 oglSys.AllowPicking( mOglWnd, 0, 0 );
00303         }
00304 
00305     virtual void
00306     ExitFunc()
00307     {
00308         oglSys.InfoBoxDestroy( DrumInfoBox );
00309     }
00310 
00311         virtual void
00312         KeyboardFunc( INT c, INT state )
00313         {
00314                 INT                     shiftDown = state & oglShift;
00315                 FLOAT           add = shiftDown ? -0.01f : 0.01f;
00316 
00317         if( c == 'W' || c == 'w' )
00318             ChangeCheckBoxSize( (c=='W') ? 0.04:-0.04f, 0.f);
00319         else if( c == 'H' || c == 'h' )
00320             ChangeCheckBoxSize( 0.f, (c=='H') ? 0.04:-0.04f);
00321         else
00322             CxWnd::KeyboardFunc( c, state );
00323 
00324         if( c == 'i' )
00325             mKeyInfo = !mKeyInfo;
00326 
00327                 if( c == 'R' || c == 'r' ) // Radius of Drum
00328                         mRadius += (c=='R') ? 0.2f : -0.2f;
00329 
00330                 if( c == oglESC ) // Reset: Set rotation and rotation speed to zero
00331                         mDrumRotDx = mDrumRotX  = 0.0f;
00332 
00333                 if( c == oglCTRL('x') && (mDrumRotDx += add) ) oglSys.SetAlwaysDraw( mOglWnd, 1 );
00334 
00335                 if( c == '3' ) mTxt3D = !mTxt3D;
00336 
00337                 if( c == '#' ) // Pauze/continue
00338             oglSys.SetAlwaysDraw( mOglWnd, !oglSys.GetAlwaysDraw(mOglWnd) );
00339 
00340                 oglSys.UpdateSceneFlag( mOglWnd, 1 );
00341         }
00342 
00343 
00344         virtual void
00345         DisplayFunc()
00346         {
00347         CheckBox3D*     checkBox;
00348             OGC                 myOGC;
00349                 int                     i, j;
00350                 int             angle, totAngle;
00351 
00352             OGCSave( &myOGC );
00353                 view3DSys.View3DCameraTransform( mOglWnd );
00354                 glTranslatef( mDrumX, mDrumY, mDrumZ );
00355                 glRotatef( mDrumRotX, 1.0f, 0.0f, 0.0f );       // Rotate X
00356         glNormal3f(0.f,0.f,1.f);
00357                 for( i=0; i<mNrColumns; i++)
00358                 {
00359                         glPushMatrix();
00360             glTranslatef( (-(mNrColumns/2) + i) * (mCbWidth+0.2f) , 0.0f, 0.0f );
00361 
00362                         for( j=0; j<mNrRows; j++)
00363                         {
00364                 angle = j * 360/mNrRows;
00365                 totAngle = ((int) mDrumRotX + angle) % 360;
00366                 totAngle = abs( totAngle );
00367                 if( totAngle > 70 &&  totAngle < 290 )
00368                     continue;
00369 
00370                                 glPushMatrix();
00371                                 glRotatef( (float) angle, 1.0f, 0.0f, 0.0f );
00372                                 glTranslatef( 0.0f, 0.0f, mRadius);
00373 
00374                 if( checkBox = mCheckBoxes[j*mNrColumns + i] )
00375                     checkBox->Draw(mTxt3D ? txtFontBase : 0,
00376                                     totAngle < 60 || totAngle > 300, mPicking );
00377                                 glPopMatrix();
00378                         }
00379                         glPopMatrix();
00380                 }
00381                 mDrumRotX += mDrumRotDx;
00382 
00383         if( !mPicking && mKeyInfo ){
00384                     oglSys.InfoBoxCenter( mOglWnd, DrumInfoBox );
00385                     oglSys.InfoBoxDraw( mOglWnd, DrumInfoBox );
00386             }
00387 
00388             OGCRestore( &myOGC );
00389         }
00390 
00391         virtual void
00392         MouseFunc( int msg, int but, int state, int x, int y )
00393         {
00394         if( msg == oglMouseDown && msg == oglLeftButton )
00395         {
00396             mPicking = true;
00397             int picked = (int) oglSys.StdPickObject( mOglWnd, (FLOAT) x, (FLOAT) y,
00398                           4.0f, 300.0f, PickDrawFunc, NULL, NULL );
00399             mPicking = false;
00400             if( picked ){
00401                 CheckBox3D* cB = (CheckBox3D *) picked;
00402                 cB->SetSelected( !cB->GetSelected() );
00403                 HandleCategory( cB );
00404             }
00405         }
00406                 if (msg == oglMouseWheelUp || msg == oglMouseWheelDown)
00407         {
00408             float   delta = ((msg == oglMouseWheelUp) ? -mWheelStep : mWheelStep);
00409             delta *= ((state & oglControl) ? 2 : 1);
00410             mDrumRotX += delta;
00411         }
00412         else
00413             CxWnd::MouseFunc(msg, but, state, x, y);
00414         }
00415 
00416 private:
00417 
00418     CheckBox3D** mCheckBoxes;
00419     int         mNrRows, mNrColumns;
00420 
00421         float           mDrumX, mDrumY, mDrumZ;
00422         float           mDrumRotX, mDrumRotDx;
00423     float       mWheelStep;
00424     bool        mTxt3D;
00425     bool        mPicking;
00426 
00427         float           mRadius;                                                        // Radius of Drum
00428     float       mCbWidth, mCbHeight;
00429 
00430         int                     txtFontBase;                                            // 3D font baes
00431     bool        mKeyInfo;
00432 
00433     INFOBOX     *DrumInfoBox;   // InfoBox for user instruction
00434 
00435         void Init( int nRow, int nColumn )
00436         {
00437         CheckBox3D  *cB;
00438         int     i, j;
00439         char    buf[100];
00440 
00441                 SetBackground( 0xfff0c0a0 );
00442                 oglSys.SetAllowCameraMove( mOglWnd, 1 );
00443 
00444                 mRadius = 5.0f;
00445         mCbWidth = 3.8f;
00446         mCbHeight = 1.0;
00447         mNrRows = nRow;
00448         mNrColumns = nColumn;
00449 
00450         mCheckBoxes = (CheckBox3D ** ) calloc( mNrRows * mNrColumns, sizeof( CheckBox3D * ) );
00451 
00452         for ( i=0 ; i<nColumn ; i++ )
00453         for ( j=0 ; j<nRow ; j++ )
00454         {
00455             if (i==0)
00456                 sprintf( buf, "Category %d", j );
00457             else
00458                 sprintf( buf, "Text %d, %d", i, j );
00459             if( !(j%3) && i==0)
00460                 continue;
00461             cB = AddCheckBox( buf, i, j, false );
00462             if (i==0)
00463             {
00464                 cB->SetFrameBorderType(BEV_RAISED, BEV_RAISED);
00465                 cB->SetBoxBorderType(BEV_SUNKEN, BEV_RAISED);
00466             }
00467         }
00468 
00469                 mDrumX = mDrumY = 0;
00470                 mDrumZ=-19;
00471                 mDrumRotX = mDrumRotDx = 0;
00472         mPicking = false;
00473         mTxt3D = true;
00474         mWheelStep = 4;
00475         }
00476 };
00477 
00478 #endif

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