proj home

Files   Classes   Functions   Hierarchy  

menusystemtest02.cpp

Go to the documentation of this file.
00001 #include <string>
00002 #include <cstdlib>
00003 using namespace std;
00004 
00005 #include <graphmisc.h>
00006 #include <menusystemtest02.h>
00007 #include <zpr.h>
00008 
00009 string menusystemtest02::doc[] =
00010 { 
00011   "",
00012   "Basic simulation of an application menu"
00013 };
00014 
00015 menusystem * menusystemtest02::root = 0;
00016 
00017 class menusystemtest02Main : public menusystem
00018 {
00019 public:
00020 
00021   menusystemtest02Main();
00022 
00023   static string menu[];
00024   static GLint menulen[];
00025   static uint menusize;
00026   static point2<int> origin;
00027   static GLint columnchange;
00028 
00029 
00030 protected:
00031 
00032   void readImmediate(charc ch);
00033   
00034 };
00035 
00036 string menusystemtest02Main::menu[] = { "Skype", "File", "Edit", "View", "Account", "Contact" }; 
00037 GLint menusystemtest02Main::menulen[] = { 50,40,40,40,60,40 };
00038 uint menusystemtest02Main::menusize=6;
00039 point2<GLint> menusystemtest02Main::origin(60,50);
00040 GLint menusystemtest02Main::columnchange=20;
00041 
00042 
00043 class menusystemtest02Skype : public menusystem
00044 {
00045 public:
00046   menusystemtest02Skype();
00047 
00048 protected:
00049 
00050   void readImmediate(charc ch);
00051 
00052   void draw() { drawparents(); menusystem::draw(); };
00053   
00054 };
00055 
00056 class menusystemtest02Services : public menusystem
00057 {
00058 public:
00059   menusystemtest02Services();
00060 
00061 protected:
00062 
00063   void readImmediate(charc ch);
00064 
00065   void draw() { drawparents(); menusystem::draw(); };
00066 };
00067 
00068 class menusystemtest02File : public menusystem
00069 {
00070 public:
00071   menusystemtest02File();
00072 
00073 protected:
00074 
00075   void readImmediate(charc ch);
00076 
00077   void draw() { drawparents(); menusystem::draw(); };
00078 };
00079   
00080 
00081 
00082 void menusystemtest02Main::readImmediate(charc ch)
00083 {
00084   switch (ch)
00085   {
00086     case 's': transfercontroltosubmenu(0); break; 
00087     case 'f': transfercontroltosubmenu(1); break; 
00088   }
00089 }
00090 
00091 // Unusual problem - could not find error with X variable not being
00092 //   able to be written to.  Used gdb but still could not work it out.
00093 //   Added addfont(string,point2<GLint> const &) as an alternative.
00094 menusystemtest02Main::menusystemtest02Main() : 
00095   //menusystem(this,0,true,point2<int>(60,30),20)
00096   menusystem(this,0,true,origin,columnchange) 
00097 {
00098 
00099   string key[] = { "[s]", "[f]", "[e]", "[v]", "[a]", "[c]" };
00100   //string menu[] = { "Skype", "File", "Edit", "View", "Account", "Contact" }; 
00101   //string menu[] = { "Skype", "File", "", "", "", "" }; 
00102   //GLint menulen[] = { 40,30,30,30,50,30 };
00103 //  GLint menulen[] = { 50,40,40,40,60,40 };
00104 //  uint menusize=6;
00105 
00106 //cout << "***" << endl;
00107   point2<GLint> X2(X);
00108   
00109   visibleGraphics.push( new gobjglColor4ub(255,215,0,200) );
00110   for (uint i=0; i<menusize; ++i)
00111   {
00112     addfont12(key[i],X2);
00113     X2.x += menulen[i];
00114 //cout << SHOW(X2) << endl;
00115     
00116     //visibleGraphics.push( new gobjglColor4ub(255,215,0,200) );
00117 //    addfont12(key[i],0);
00118     //X.x += 14;
00119     //X.x += 34;
00120     //X.x += key[i].length()*8;
00121 //    X.x = (X.x + key[i].length()*8);
00122 //cout << "*" << SHOW(X) << " " << key[i].length()*8 <<  endl;
00123 /*
00124     visibleGraphics.push( new gobjglColor4f(1.0,0.0,0.0,0.8) );
00125     addfont12(menu[i],0);
00126     //X.x += len[i];
00127     X.x += menu[i].length()*9;
00128 */
00129   }
00130 
00131   X2=X;
00132   X2.x += 13;
00133   visibleGraphics.push( new gobjglColor4f(1.0,0.0,0.0,0.8) );
00134   for (uint i=0; i<menusize; ++i)
00135   {
00136     addfont12(menu[i],X2);
00137     X2.x += menulen[i];
00138   }
00139 }
00140 
00141 
00142 
00143 menusystemtest02Skype::menusystemtest02Skype() : 
00144 //  menusystem(point2<int>(60,50),20)
00145   menusystem
00146   (
00147     menusystemtest02Main::origin,
00148     menusystemtest02Main::columnchange
00149   )
00150 {
00151   visibleGraphics.push( new gobjglColor4f(1.0,0.0,0.0,0.8) );
00152 
00153   addnewline();
00154   addfont12("[a] About Skype",1);
00155 
00156   addfont12("[p] Preferences...",1);
00157   addfont12("[u] Check for Update",1);
00158   addfont12("[e] Services >",1);
00159   addfont12("[h] Hide Skype",1);
00160   addfont12("[o] Hide Others",1);
00161   addfont12("[s] Show All",2);
00162 
00163   addfont12("[q] Quit",0);
00164 
00165 }
00166 
00167 void menusystemtest02Skype::readImmediate(char ch)
00168 {
00169   switch (ch)
00170   {
00171     case 'q': exit(0); break;
00172     case 'e': transfercontroltosubmenu(0); break;
00173 
00174     default:
00175       transfercontroltoroot(); 
00176   }
00177 }
00178 
00179 menusystemtest02Services::menusystemtest02Services() : 
00180   //menusystem(point2<int>(135,110),20)
00181   menusystem
00182   (
00183     menusystemtest02Main::origin + point2<GLint>(75,60),
00184     menusystemtest02Main::columnchange
00185   )
00186 {
00187   visibleGraphics.push( new gobjglColor4f(1.0,0.0,0.0,0.8) );
00188 
00189   addnewline();
00190   addfont12("[c] ChineseTextConnverter >",1);
00191   addfont12("[d] Disk Utility >",1);
00192   addfont12("[f] Finder >",1);
00193   addfont12("[b] Font Book >",1);
00194   addfont12("[g] Grab >",1);
00195   addfont12("[i] Import Image",1);
00196   addfont12("[l] Look Up in Dictionary",1);
00197   addfont12("[m] Mail >",1);
00198   addfont12("[n] Make New Stick Note",1);
00199 }
00200 
00201 void menusystemtest02Services::readImmediate(char ch)
00202 {
00203   switch (ch)
00204   {
00205     default:
00206       transfercontroltoroot(); 
00207   }
00208 }
00209 
00210 
00211 menusystemtest02File::menusystemtest02File() : 
00212   //menusystem(point2<int>(110,50),20)
00213   menusystem
00214   (
00215     menusystemtest02Main::origin + point2<GLint>(menusystemtest02Main::menulen[0],0),
00216     menusystemtest02Main::columnchange
00217   )
00218 {
00219   visibleGraphics.push( new gobjglColor4f(1.0,0.0,0.0,0.8) );
00220 
00221   addnewline();
00222   addfont12("[w] Close Window",1);
00223   addfont12("[c] Close Chat",1);
00224   addfont12("[s] Save as...",0);
00225 }
00226 
00227 void menusystemtest02File::readImmediate(char ch)
00228 {
00229   switch (ch)
00230   {
00231 //    case 'q': exit(0); break;
00232 //    case 'e': transfercontroltosubmenu(0); break;
00233 
00234     default:
00235       transfercontroltoroot(); 
00236   }
00237 }
00238 
00239 
00240 menusystemtest02::menusystemtest02(int argc, char** argv)
00241 {
00242   glutInit(&argc,argv);
00243   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00244   glutInitWindowSize(800,600);
00245   glutCreateWindow("");
00246   glutDisplayFunc(display);
00247   glutKeyboardFunc(keyboard);
00248 
00249   OpenGLinitialisation();
00250 
00251   glEnable(GL_DEPTH_TEST);
00252   glEnable(GL_CULL_FACE);
00253   glEnable(GL_NORMALIZE);
00254 
00255   xGraphics.set();
00256 
00257   //current = 
00258   //  new menusystem(0,0,true,point2<GLint>(60,50),10);
00259   //gobjpush(current);
00260   //current->fontcolor = point4<float>(1.0,0.0,0.0,0.8);
00261   //current->lightingdisable();
00262   //
00263 
00264 
00265   root = new menusystemtest02Main();
00266   root->fontcolor = point4<float>(1.0,0.0,0.0,0.8);
00267 //  root->lightingdisable();
00268 
00269 
00270   menusystem * m;
00271   m = new menusystemtest02Skype();
00272 //  m->lightingdisable();
00273   menusystem * m2 = new menusystemtest02Services();
00274   m->addsubmenu(m2);
00275   root->addsubmenu(m);
00276 
00277   m = new menusystemtest02File();
00278   root->addsubmenu(m);
00279   
00280   gobjpush(new gobjglDisable(GL_LIGHTING));
00281   gobjpush(root);
00282 
00283 /*
00284   menusystem * mainmenu = 
00285     new menusystem(0,0,true,point2<GLint>(250,70),10);
00286   mainmenu->fontcolor = point4<float>(240/255.0,192/255.0,10.0/255.0,0.8);
00287   mainmenu->addfont12("menusystem test",2);
00288   mainmenu->addfont10("m    - print a message.",1);
00289   mainmenu->addfont10("M    - print a paragraph(no user returns in string).",1);
00290   mainmenu->addfont10("space",1);
00291   mainmenu->addfont10("a    - print a block(user returns in string).",1);
00292   gobjpush(mainmenu);
00293 
00294  
00295   //current->addfont12start("The first message.",1);
00296 */
00297 
00298   zpr zz;
00299 
00300   zz.update();
00301   glutMainLoop();
00302 }
00303 
00304 void menusystemtest02::display()
00305 { 
00306   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00307 
00308   gobj::global->draw();
00309 
00310   glerrordisplay();
00311   
00312   glutSwapBuffers();
00313 }
00314 
00315 void menusystemtest02::keyboard
00316 (
00317   unsigned char key, 
00318   int x, 
00319   int y
00320 )
00321 {
00322   assert(root!=0);
00323   root->read(key);
00324 }
00325 
00326 

Generated on Fri Mar 4 00:49:29 2011 for Chelton Evans Source by  doxygen 1.5.8