GLMenu.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <GLEXT/GLMenu.h>
00022 #include <GLEXT/GLState.h>
00023 #include <GLEXT/GLViewPort.h>
00024 #include <GLEXT/GLMenuEntry.h>
00025 #include <GLW/GLWWindowManager.h>
00026 #include <client/ScorchedClient.h>
00027 #include <graph/OptionsDisplay.h>
00028 
00029 GLMenu::GLMenu() : GLWWindow("", 0.0f, 10.0f, 10000.0f, 32.0f, 0, "")
00030 {
00031         windowLevel_ = 20000;
00032 }
00033 
00034 GLMenu::~GLMenu()
00035 {
00036 }
00037 
00038 GLMenuEntry *GLMenu::getMenu(char *menuItem)
00039 {
00040         std::string menu(menuItem);
00041         std::map<std::string, GLMenuEntry *>::iterator itor = menuList_.find(menu);
00042         if (itor != menuList_.end())
00043         {
00044                 return itor->second;
00045         }
00046 
00047         return 0;
00048 }
00049 
00050 bool GLMenu::addMenu(
00051         const LangString &menuName,
00052         char *menuNameInternal, 
00053         const LangString &menuDescription,
00054         float width, 
00055         unsigned int state,
00056         GLMenuI *callback,
00057         Image *icon,
00058         unsigned int flags)
00059 {
00060         if (getMenu(menuNameInternal)) return false;
00061 
00062         GLMenuEntry *entry = new GLMenuEntry(
00063                 menuName, menuNameInternal, menuDescription,
00064                 width, state, 
00065                 callback, icon, flags);
00066         menuList_[std::string(menuNameInternal)] = entry;
00067         return true;
00068 }
00069 
00070 bool GLMenu::addMenuItem(char *menuName, const GLMenuItem item)
00071 {
00072         GLMenuEntry *entry = getMenu(menuName);
00073         if (!entry) return false;
00074 
00075         entry->addMenuItem((GLMenuItem &) item);
00076         return true;
00077 }
00078 
00079 void GLMenu::draw()
00080 {
00081         GLState currentDrawState(GLState::DEPTH_OFF | GLState::TEXTURE_OFF);
00082 
00083         float currentTop = (float) GLViewPort::getHeight();
00084         setY(currentTop - h_);
00085         int x = ScorchedClient::instance()->getGameState().getMouseX();
00086         int y = ScorchedClient::instance()->getGameState().getMouseY();
00087 
00088         unsigned int currentState =
00089                 ScorchedClient::instance()->getGameState().getState();
00090 
00091         bool selected = false;
00092         std::map<std::string, GLMenuEntry *>::iterator itor;
00093         for (itor = menuList_.begin();
00094                 itor != menuList_.end();
00095                 itor++)
00096         {
00097                 GLMenuEntry *entry = itor->second;
00098                 if (entry->getSelected())
00099                 {
00100                         selected = true;
00101                 }
00102                 else if (entry->inMenu(currentTop, x, y))
00103                 {
00104                         GLWToolTip::instance()->addToolTip(&entry->getToolTip(),
00105                                 entry->getX() - 10.0f, entry->getY() - 75, 
00106                                 entry->getW(), 75.0f);
00107                 }
00108         }       
00109 
00110         bool show = true;
00111         if (OptionsDisplay::instance()->getHideMenus())
00112         {
00113                 show = (selected || GLWWindowManager::instance()->getFocus(x, y) == getId());
00114         }
00115         if (show)
00116         {
00117                 GLfloat currentWidth = 0.0f;
00118                 std::map<std::string, GLMenuEntry *>::iterator itor;
00119                 for (itor = menuList_.begin();
00120                         itor != menuList_.end();
00121                         itor++)
00122                 {
00123                         GLMenuEntry *entry = itor->second;
00124                         if (!(entry->getFlags() & eMenuAlignRight))
00125                         {
00126                                 if (entry->getState() == 0 ||
00127                                         entry->getState() == currentState)
00128                                 {
00129                                         if (entry->getCallback()->getEnabled(entry->getNameInternal()))
00130                                         {
00131                                                 entry->draw(
00132                                                         currentTop - 1.0f, currentWidth);
00133                                                 currentWidth += entry->getW() + 1.0f;
00134                                         }
00135                                 }
00136                         }
00137                 }       
00138 
00139                 currentWidth = (float) GLViewPort::getWidth();
00140                 for (itor = menuList_.begin();
00141                         itor != menuList_.end();
00142                         itor++)
00143                 {
00144                         GLMenuEntry *entry = itor->second;
00145                         if (entry->getFlags() & eMenuAlignRight)
00146                         {
00147                                 if (entry->getState() == 0 ||
00148                                         entry->getState() == currentState)
00149                                 {
00150                                         if (entry->getCallback()->getEnabled(entry->getNameInternal()))
00151                                         {
00152                                                 currentWidth -= entry->getW() + 1.0f;
00153                                                 entry->draw(
00154                                                         currentTop - 1.0f, currentWidth);
00155                                         }
00156                                 }
00157                         }
00158                 }       
00159         }
00160 }
00161 
00162 void GLMenu::mouseDown(int button, float x, float y, bool &hitMenu)
00163 {
00164         hitMenu = false;
00165         float currentTop = (float) GLViewPort::getHeight();
00166 
00167         unsigned int currentState =
00168                 ScorchedClient::instance()->getGameState().getState();
00169 
00170         std::map<std::string, GLMenuEntry *>::iterator itor;
00171         for (itor = menuList_.begin();
00172                 itor != menuList_.end();
00173                 itor++)
00174         {
00175                 GLMenuEntry *entry = itor->second;
00176                 if (entry->getState() == 0 ||
00177                         entry->getState() == currentState)
00178                 {
00179                         if (entry->click(currentTop, int(x), int(y)))
00180                         {
00181                                 hitMenu = true;
00182                         }
00183                 }
00184         }
00185 }
00186 
00187 void GLMenu::mouseUp(int button, float x, float y, bool &skipRest)
00188 {
00189 
00190 }
00191 
00192 void GLMenu::mouseDrag(int button, float mx, float my, float x, float y, bool &skipRest)
00193 {
00194 
00195 }
00196 
00197 void GLMenu::keyDown(char *buffer, unsigned int keyState, 
00198                 KeyboardHistory::HistoryElement *history, int hisCount, 
00199                 bool &skipRest)
00200 {
00201 
00202 }

Generated on Mon Feb 16 15:14:44 2009 for Scorched3D by  doxygen 1.5.3