GLWSelector.h

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 #if !defined(__INCLUDE_GLWSelectorh_INCLUDE__)
00022 #define __INCLUDE_GLWSelectorh_INCLUDE__
00023 
00024 #include <GLW/GLWWindow.h>
00025 #include <GLW/GLWToolTip.h>
00026 #include <GLEXT/GLTexture.h>
00027 #include <lang/LangString.h>
00028 #include <string>
00029 #include <list>
00030 #include <map>
00031 
00032 /**
00033 Defines the contents of one row of the selection dialog.
00034 */
00035 class GLWSelectorEntry
00036 {
00037 public:
00038         GLWSelectorEntry(const LangString &text = LangString(), 
00039                 ToolTip *tooltip = 0, 
00040                 bool selected = false,
00041                 GLTexture *icon = 0,
00042                 void *userData = 0,
00043                 const std::string &dataText = "");
00044         
00045         LangString &getText() { return text_; }
00046         const char *getDataText() { return dataText_.c_str(); }
00047         ToolTip *getToolTip() { return tip_; }
00048         GLTexture *getIcon() { return icon_; }
00049         bool getSelected() { return selected_; }
00050         bool getSeperator() { return seperator_; }
00051         void setSeperator() { seperator_ = true; }
00052         void *getUserData() { return userData_; }
00053         Vector &getColor() { return color_; }
00054         int &getTextureWidth() { return textureWidth_; }
00055 
00056         std::list<GLWSelectorEntry> &getPopups() { return popups_; }
00057         
00058 protected:
00059         LangString text_;
00060         std::string dataText_;
00061         GLTexture *icon_;
00062         int textureWidth_;
00063         ToolTip *tip_;
00064         Vector color_;
00065         bool selected_, seperator_;
00066         void *userData_;
00067         std::list<GLWSelectorEntry> popups_;
00068 };
00069 
00070 /**
00071 The user interested in the chosen selection.
00072 */
00073 class GLWSelectorI
00074 {
00075 public:
00076         virtual void itemSelected(GLWSelectorEntry *entry, int position) = 0;
00077         virtual void noItemSelected() { };
00078 };
00079 
00080 /**
00081 A class that presents the user with an on screen menu and
00082 allows them to select one item.
00083 This class is used by other classes that throw up a selection
00084 window to the user.
00085 */
00086 class GLWSelectorPart;
00087 class GLWSelector : public GLWWindow
00088 {
00089 public:
00090     static GLWSelector *instance();
00091 
00092         // Show the selector as the specified position
00093         void showSelector(
00094                 GLWSelectorI *user,
00095                 float x, float y,
00096                 std::list<GLWSelectorEntry> &entries,
00097                 unsigned int showState = 0,
00098                 bool transparent = true);
00099         // Hide the selector
00100         void hideSelector();
00101 
00102         // Add/remove a popup
00103         GLWSelectorI *getUser() { return user_; }
00104         void addPart(GLWSelectorPart *part);
00105         void rmPart(GLWSelectorPart *part);
00106 
00107         // Inherited from GLWWindow
00108         virtual void draw();
00109         virtual void mouseDown(int button, float x, float y, bool &skipRest);
00110         virtual void mouseUp(int button, float x, float y, bool &skipRest);
00111         virtual void mouseDrag(int button, float mx, float my, float x, float y, bool &skipRest);
00112         virtual void keyDown(char *buffer, unsigned int keyState, 
00113                 KeyboardHistory::HistoryElement *history, int hisCount, 
00114                 bool &skipRest);
00115 
00116 protected:
00117         static GLWSelector *instance_;
00118         std::list<GLWSelectorPart *> parts_;
00119         unsigned int showState_;
00120         GLWSelectorI *user_;
00121 
00122 private:
00123         GLWSelector();
00124         virtual ~GLWSelector();
00125 
00126 };
00127 
00128 #endif

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