Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

glutm/menu.cpp

Go to the documentation of this file.
00001 #include "menu.h"
00002 
00007 #include <glutm/master.h>
00008 
00010 
00011 GlutMenu::GlutMenu(int button)
00012 : _button(button), _menuID(-1)
00013 {
00014 }
00015 
00016 GlutMenu::~GlutMenu()
00017 {
00018     reset();
00019 }
00020 
00021 GlutMenu &
00022 GlutMenu::subMenu()
00023 {
00024     _subMenu.push_back(new GlutMenu(_button));
00025     return *_subMenu.back();
00026 }
00027 
00028 void 
00029 GlutMenu::resetList()
00030 {
00031     for (std::list<GlutMenu *>::iterator i=_subMenu.begin(); i!=_subMenu.end(); i++)
00032         delete *i;
00033 
00034     _subMenu.clear();
00035 }
00036 
00037 #if !defined(GLUTM_SAVER)
00038 
00039 void 
00040 GlutMenu::addEntry(const std::string &name,int value)
00041 {
00042     if (_menuID==-1)
00043         _menuID = glutCreateMenu(GlutMaster::OnMenu);
00044 
00045     glutSetMenu(_menuID);
00046     glutAddMenuEntry(name.c_str(),value);
00047 }
00048 
00049 void 
00050 GlutMenu::addEntry(const std::string &name,GlutMenu &menu)
00051 {
00052     if (_menuID==-1)
00053         _menuID = glutCreateMenu(GlutMaster::OnMenu);
00054 
00055     glutSetMenu(_menuID);
00056     glutAddSubMenu(name.c_str(),menu._menuID);
00057 }
00058 
00059 void 
00060 GlutMenu::reset()
00061 {
00062     if (_menuID!=-1)
00063     {
00064         glutSetMenu(_menuID);
00065         int n = glutGet(GLenum(GLUT_MENU_NUM_ITEMS));
00066         for (int i=0; i<n; i++)
00067             glutRemoveMenuItem(1);
00068     }
00069 
00070     resetList();
00071 }
00072 
00073 void 
00074 GlutMenu::attach()
00075 {
00076     if (_menuID!=-1)
00077     {
00078         glutSetMenu(_menuID);
00079         glutAttachMenu(_button);
00080     }
00081 }
00082 
00083 void 
00084 GlutMenu::detach()
00085 {
00086     if (_menuID!=-1)
00087     {
00088         glutSetMenu(_menuID);
00089         glutDetachMenu(_button);
00090     }
00091 }
00092 
00093 #else
00094 
00095 void GlutMenu::addEntry(const std::string &name,int value)      {}
00096 void GlutMenu::addEntry(const std::string &name,GlutMenu &menu) {}
00097 void GlutMenu::attach() {}
00098 void GlutMenu::detach() {}
00099 
00100 void GlutMenu::reset() 
00101 {
00102     resetList();
00103 }
00104 
00105 #endif

Generated on Tue Nov 5 11:11:04 2002 for GLT by doxygen1.2.18