git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / client / GLW / GLWSelector.h
blob8b3f90a06f91164b2083b4f78c17e6e17a35aef4
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #if !defined(__INCLUDE_GLWSelectorh_INCLUDE__)
22 #define __INCLUDE_GLWSelectorh_INCLUDE__
24 #include <GLW/GLWWindow.h>
25 #include <GLW/GLWToolTip.h>
26 #include <GLEXT/GLTexture.h>
27 #include <lang/LangString.h>
28 #include <string>
29 #include <list>
30 #include <map>
32 /**
33 Defines the contents of one row of the selection dialog.
35 class GLWSelectorEntry
37 public:
38 GLWSelectorEntry(const LangString &text = LangString(),
39 ToolTip *tooltip = 0,
40 bool selected = false,
41 GLTexture *icon = 0,
42 void *userData = 0,
43 const std::string &dataText = "");
45 LangString &getText() { return text_; }
46 const char *getDataText() { return dataText_.c_str(); }
47 ToolTip *getToolTip() { return tip_; }
48 GLTexture *getIcon() { return icon_; }
49 bool getSelected() { return selected_; }
50 bool getSeperator() { return seperator_; }
51 void setSeperator() { seperator_ = true; }
52 void *getUserData() { return userData_; }
53 Vector &getColor() { return color_; }
54 int &getTextureWidth() { return textureWidth_; }
56 std::list<GLWSelectorEntry> &getPopups() { return popups_; }
58 protected:
59 LangString text_;
60 std::string dataText_;
61 GLTexture *icon_;
62 int textureWidth_;
63 ToolTip *tip_;
64 Vector color_;
65 bool selected_, seperator_;
66 void *userData_;
67 std::list<GLWSelectorEntry> popups_;
70 /**
71 The user interested in the chosen selection.
73 class GLWSelectorI
75 public:
76 virtual void itemSelected(GLWSelectorEntry *entry, int position) = 0;
77 virtual void noItemSelected() { };
80 /**
81 A class that presents the user with an on screen menu and
82 allows them to select one item.
83 This class is used by other classes that throw up a selection
84 window to the user.
86 class GLWSelectorPart;
87 class GLWSelector : public GLWWindow
89 public:
90 static GLWSelector *instance();
92 // Show the selector as the specified position
93 void showSelector(
94 GLWSelectorI *user,
95 float x, float y,
96 std::list<GLWSelectorEntry> &entries,
97 unsigned int showState = 0,
98 bool transparent = true);
99 // Hide the selector
100 void hideSelector();
102 // Add/remove a popup
103 GLWSelectorI *getUser() { return user_; }
104 void addPart(GLWSelectorPart *part);
105 void rmPart(GLWSelectorPart *part);
107 // Inherited from GLWWindow
108 virtual void draw();
109 virtual void mouseDown(int button, float x, float y, bool &skipRest);
110 virtual void mouseUp(int button, float x, float y, bool &skipRest);
111 virtual void mouseDrag(int button, float mx, float my, float x, float y, bool &skipRest);
112 virtual void keyDown(char *buffer, unsigned int keyState,
113 KeyboardHistory::HistoryElement *history, int hisCount,
114 bool &skipRest);
116 protected:
117 static GLWSelector *instance_;
118 std::list<GLWSelectorPart *> parts_;
119 unsigned int showState_;
120 GLWSelectorI *user_;
122 private:
123 GLWSelector();
124 virtual ~GLWSelector();
128 #endif