1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
4 // This file is part of Scorched3D.
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 #include <GLW/GLWSelector.h>
22 #include <GLW/GLWSelectorPart.h>
23 #include <GLEXT/GLViewPort.h>
24 #include <client/ScorchedClient.h>
25 #include <common/Defines.h>
26 #include <graph/OptionsDisplay.h>
28 GLWSelectorEntry::GLWSelectorEntry(const LangString
&text
,
33 const std::string
&dataText
) :
40 color_(1.0f
, 1.0f
, 1.0f
),
47 GLWSelector
*GLWSelector::instance_
= 0;
49 GLWSelector
*GLWSelector::instance()
53 instance_
= new GLWSelector();
58 GLWSelector::GLWSelector() :
59 GLWWindow("", 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0, ""),
66 GLWSelector::~GLWSelector()
70 void GLWSelector::showSelector(GLWSelectorI
*user
,
72 std::list
<GLWSelectorEntry
> &entries
,
73 unsigned int showState
,
79 showState_
= showState
;
87 std::list
<GLWSelectorEntry
> partEntries
;
88 std::list
<GLWSelectorEntry
>::iterator itor
;
89 for (itor
= entries
.begin();
90 itor
!= entries
.end();
93 partEntries
.push_back(*itor
);
94 if ((int) partEntries
.size() * 20 >= GLViewPort::getHeight() - 40)
96 GLWSelectorPart
*part
= new GLWSelectorPart(
102 left
+= part
->getSelectedWidth() + 10.0f
;
104 basePosition
+= (int) partEntries
.size();
108 if (partEntries
.size() > 0)
110 GLWSelectorPart
*part
= new GLWSelectorPart(
120 void GLWSelector::hideSelector()
127 while (!parts_
.empty())
129 GLWSelectorPart
*part
= parts_
.front();
135 void GLWSelector::addPart(GLWSelectorPart
*part
)
137 parts_
.push_back(part
);
140 void GLWSelector::rmPart(GLWSelectorPart
*part
)
142 if (part
->getChild()) rmPart(part
->getChild());
147 void GLWSelector::draw()
149 if (!visible_
) return;
151 if (showState_
!= 0 &&
152 ScorchedClient::instance()->getGameState().getState() != showState_
)
154 if (user_
) user_
->noItemSelected();
159 unsigned int state
= 0;
160 if (OptionsDisplay::instance()->getSmoothLines())
162 state
|= GLState::BLEND_ON
;
163 glEnable(GL_LINE_SMOOTH
);
165 GLState
currentState(state
);
167 std::list
<GLWSelectorPart
*>::iterator itor
;
168 for (itor
= parts_
.begin();
169 itor
!= parts_
.end();
172 GLWSelectorPart
*part
= (*itor
);
176 if (OptionsDisplay::instance()->getSmoothLines())
178 glDisable(GL_LINE_SMOOTH
);
182 void GLWSelector::mouseDown(int button
, float mouseX
, float mouseY
, bool &hitMenu
)
184 // Override default window behaviour
185 if (!visible_
) return;
189 if ((showState_
!= 0) &&
190 (ScorchedClient::instance()->getGameState().getState() != showState_
))
192 if (user_
) user_
->noItemSelected();
198 std::list
<GLWSelectorPart
*>::reverse_iterator itor
;
199 for (itor
= parts_
.rbegin();
200 itor
!= parts_
.rend();
203 GLWSelectorPart
*part
= (*itor
);
204 part
->mouseDown(mouseX
, mouseY
, hit
);
208 if (!hit
&& user_
) user_
->noItemSelected();
213 void GLWSelector::mouseUp(int button
, float x
, float y
, bool &skipRest
)
215 // Override and disable default window behaviour
218 void GLWSelector::mouseDrag(int button
, float mx
, float my
, float x
, float y
, bool &skipRest
)
220 // Override and disable default window behaviour
223 void GLWSelector::keyDown(char *buffer
, unsigned int keyState
,
224 KeyboardHistory::HistoryElement
*history
, int hisCount
,
227 // Override and disable default window behaviour