Files Classes Functions Hierarchy
00001 00002 #include <cstdlib> 00003 using namespace std; 00004 00005 00006 00007 #include <gobj.h> 00008 #include <graphmisc.h> 00009 #include <menusystem.h> 00010 #include <menusystemtest.h> 00011 #include <primitivewindow.h> 00012 #include <zpr.h> 00013 00014 00015 menusystem * menusystemtest::current = 0; 00016 primitiveWindow * menusystemtest::pw = 0; 00017 00018 typedef point3<double> pt3; 00019 00020 class menu01 : public menusystem 00021 { 00022 public: 00023 00024 menu01(); 00025 00026 protected: 00027 00028 int state; 00029 00030 void readBufferedTerminationAction() 00031 { 00032 if (state==1) 00033 { 00034 cout << SHOW(readBufferedResult) << endl; 00035 state=0; 00036 } 00037 00038 } 00039 00040 void readImmediate(char const ch); 00041 00042 }; 00043 00044 00045 class menu02: public menusystemOneShot 00046 { 00047 public: 00048 00049 menu02() 00050 : menusystemOneShot(point2<int>(160,30),20,1,menusystemOneShot::drawmenuparents) 00051 { 00052 addfont12("Read a String Menu",1); 00053 addfont10("Input a string: "); 00054 } 00055 }; 00056 00057 00058 00059 class menu03 : public menusystem 00060 { 00061 public: 00062 00063 menu03(); 00064 00065 void draw(); 00066 00067 protected: 00068 void readImmediate(char const ch); 00069 }; 00070 00071 class menu04 : public menusystem 00072 { 00073 public: 00074 00075 menu04(); 00076 00077 void draw(); 00078 00079 protected: 00080 void readImmediate(char const ch); 00081 }; 00082 00083 00084 void menu01::readImmediate(char const ch) 00085 { 00086 switch (ch) 00087 { 00088 case '1': 00089 transfercontroltosubmenu(0); 00090 break; 00091 00092 case '2': 00093 readmodeimmediate=false; 00094 readBufferedSet(2); 00095 state=1; 00096 break; 00097 00098 case '3': 00099 transfercontroltosubmenu(1); 00100 break; 00101 00102 case 27: 00103 exit(0); 00104 break; 00105 } 00106 } 00107 00108 00109 menu01::menu01() : 00110 menusystem(this,0,true,point2<int>(60,30),20) 00111 { 00112 addfont12(" Main Menu",1); 00113 addfont10("1. Read a string in.",1); 00114 addfont10("2. Read a string in immediately: ",1); 00115 /* 00116 addfont10("2. Read a string in immediately: "); 00117 Xpush(); 00118 X.x += 120; 00119 addfont10(""); 00120 Xpop(); 00121 addnewline(); 00122 */ 00123 addfont10("3. Submenu",1); 00124 addfont10("ESC Quit"); 00125 } 00126 00127 void menu03::draw() 00128 { 00129 drawparent(); 00130 menusystem::draw(); 00131 } 00132 00133 00134 void menu03::readImmediate(char const ch) 00135 { 00136 switch (ch) 00137 { 00138 case '1': 00139 transfercontroltosubmenu(0); 00140 break; 00141 00142 case '3': transfercontroltoparent(); 00143 break; 00144 00145 case 27: 00146 exit(0); 00147 break; 00148 } 00149 } 00150 00151 menu03::menu03() : 00152 menusystem(this,0,true,point2<int>(120,30),20) 00153 { 00154 addnewline(3); 00155 addfont12(" Submenu Menu",1); 00156 addfont10("1. Documentation",1); 00157 addfont10("2.",1); 00158 addfont10("3. Back",1); 00159 addfont10("ESC Quit"); 00160 } 00161 00162 void menu04::readImmediate(char const ch) 00163 { 00164 //cout << "@@@" << endl; 00165 transfercontroltoparent(); 00166 } 00167 00168 menu04::menu04() : 00169 menusystem(this,0,true,point2<int>(210,30),20) 00170 { 00171 addnewline(4); 00172 addfont10("These menus are all slightly different to explore ",1); 00173 addfont10("how menus can be construted. The main menu has two",1); 00174 addfont10("ways to input a string, one vi a dedicated menu and",1); 00175 addfont10("the other at a point in the current menu.",2); 00176 addfont10("The submenu displays its parent. The menus do not",1); 00177 addfont10("by default display their parents. The documentation",1); 00178 addfont10("menu uses a function to do this.",2); 00179 00180 string para; 00181 para += "Behind the scenes there is a smart pointer working. "; 00182 para += "The client links the menus which are flat - no "; 00183 para += "imbedded crap for simplicity. An external ref "; 00184 para += "points to any one of the menus and the right display "; 00185 para += "and key catching is matched. "; 00186 00187 addfont10paragraph(para,40,2); 00188 00189 addfont10("Any Key Back"); 00190 00191 X0 = point2<int>(410,110); 00192 reset(); 00193 00194 para.clear(); 00195 para += "The class is in one of two modes - immediate or buffered. "; 00196 para += "In buffered mode characters are printed to the screen as they "; 00197 para += "are typed. In immediate mode characters are the commands and "; 00198 para += "each menu can catches and handles the command."; 00199 addfont10paragraph(para,40,1); 00200 para.clear(); 00201 00202 para += "These last few paragraphs were formatted by a little routine"; 00203 para += "All these menus are positioned by hand. Unlike a "; 00204 para += "modern menu system which manages alignment this is "; 00205 para += "a primitive menu system. But it is powerful enough"; 00206 para += "to do all that you would at the command line. "; 00207 addfont10paragraph(para,40); 00208 00209 } 00210 00211 void menu04::draw() 00212 { 00213 drawparents(); 00214 menusystem::draw(); 00215 } 00216 00217 class t01 00218 { 00219 public: 00220 ostream & print(ostream & os) const; 00221 00222 }; 00223 00224 00225 ostream & t01::print(ostream & os) const 00226 { 00227 os << "t01" << endl; 00228 os << "have fun" << endl; 00229 os << "The quick brown fox jumped over the lazy dog."; 00230 os << "life sux." << endl << endl; 00231 return os; 00232 } 00233 00234 ostream & operator << (ostream & os, t01 const & x) 00235 { 00236 return x.print(os); 00237 } 00238 00239 void menusystemtest::test01 00240 ( 00241 int & argc, 00242 char** & argv 00243 ) 00244 { 00245 glutInit(&argc,argv); 00246 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00247 glutInitWindowSize(800,600); 00248 glutCreateWindow(""); 00249 glutDisplayFunc(display01); 00250 glutKeyboardFunc(keyboard01); 00251 00252 OpenGLinitialisation(); 00253 00254 glEnable(GL_DEPTH_TEST); 00255 glEnable(GL_CULL_FACE); 00256 glEnable(GL_NORMALIZE); 00257 00258 xGraphics.set(); 00259 00260 menu01 * m1 = new menu01(); 00261 m1->addsubmenu( new menu02() ); 00262 menu03 * m3 = new menu03(); 00263 m1->addsubmenu( m3 ); 00264 m3->addsubmenu( new menu04() ); 00265 current = m1; 00266 00267 pw = new primitiveWindow( point3<double>(0.0,0.0,0.0), 0.1 ); 00268 00269 string tmp("cat \n mat"); 00270 00271 *pw << tmp; 00273 00274 t01 tmp2; 00275 // cout << tmp2 << endl; 00276 *pw << tmp2; 00277 //t01().print(*pw); 00278 00279 tmp = "The weather is very lovely if you like it hot. I have to write "; 00280 tmp += "some silly text and display it, though I am looking forward to "; 00281 tmp += "seeing this software in the product."; 00282 00283 pw->addparagraph(tmp,63); 00284 00285 pw->vg.push_back 00286 ( 00287 new gobjMyBitmapCharacter 00288 ( 00289 "be happy?", 00290 point3<double>(.2,.3,.7), 00291 GLUT_BITMAP_HELVETICA_18 00292 ) 00293 ); 00294 00295 zpr zz; 00296 00297 zz.update(); 00298 glutMainLoop(); 00299 } 00300 00301 00302 void menusystemtest::display01() 00303 { 00304 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00305 00306 //xGraphics.draw(); 00307 assert(current!=0); 00308 current->draw(); 00309 00310 pw->draw(); 00311 00312 glerrordisplay(); 00313 glutSwapBuffers(); 00314 } 00315 00316 void menusystemtest::keyboard01 00317 ( 00318 unsigned char key, 00319 int x, 00320 int y 00321 ) 00322 { 00323 assert(current!=0); 00324 current->read(key); 00325 } 00326 00327 void menusystemtest::display02() 00328 { 00329 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00330 00331 gobj::global->draw(); 00332 00333 glerrordisplay(); 00334 00335 glutSwapBuffers(); 00336 } 00337 00338 void menusystemtest::keyboard02 00339 ( 00340 unsigned char key, 00341 int x, 00342 int y 00343 ) 00344 { 00345 static uint messageid=1; 00346 00347 switch (key) 00348 { 00349 case 27: exit(0); break; 00350 case 'm': 00351 { 00352 stringstream ss; 00353 ss << messageid++; 00354 current->addfont12start(ss.str() + " message.",1); 00355 } 00356 break; 00357 00358 case ' ': current->scrolldown(); break; 00359 00360 case 'M': 00361 { 00362 string str = "This is some text. It has to be a paragraph. "; 00363 str += "Testing the paragraph writing in the message mode."; 00364 current->addfont10paragraphstart(str,40,1); 00365 } 00366 break; 00367 00368 case 'a': 00369 { 00370 string str = "1.Cabbage\n2.Tomatoes\n3.Pears"; 00371 current->addfont10blockstart(str,1); 00372 } 00373 break; 00374 00375 } 00376 00377 glutPostRedisplay(); 00378 } 00379 00380 void menusystemtest::test02 00381 ( 00382 int & argc, 00383 char** & argv 00384 ) 00385 { 00386 glutInit(&argc,argv); 00387 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00388 glutInitWindowSize(800,600); 00389 glutCreateWindow(""); 00390 glutDisplayFunc(display02); 00391 glutKeyboardFunc(keyboard02); 00392 00393 OpenGLinitialisation(); 00394 00395 glEnable(GL_DEPTH_TEST); 00396 glEnable(GL_CULL_FACE); 00397 glEnable(GL_NORMALIZE); 00398 00399 xGraphics.set(); 00400 00401 current = 00402 new menusystem(0,0,true,point2<GLint>(60,50),10); 00403 gobjpush(current); 00404 current->fontcolor = point4<float>(1.0,0.0,0.0,0.8); 00405 current->lightingdisable(); 00406 00407 menusystem * mainmenu = 00408 new menusystem(0,0,true,point2<GLint>(250,70),10); 00409 mainmenu->fontcolor = point4<float>(240.0/255.0,192.0/255.0,10.0/255.0,0.8); 00410 mainmenu->addfont12("menusystem test",2); 00411 mainmenu->addfont10("m - print a message.",1); 00412 mainmenu->addfont10("M - print a paragraph(no user returns in string).",1); 00413 mainmenu->addfont10("space",1); 00414 mainmenu->addfont10("a - print a block(user returns in string).",1); 00415 gobjpush(mainmenu); 00416 00417 00418 //current->addfont12start("The first message.",1); 00419 00420 zpr zz; 00421 00422 zz.update(); 00423 glutMainLoop(); 00424 } 00425 00426
1.5.8