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