2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP 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 VOMP 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 VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "wselectlist.h"
23 WSelectList::WSelectList()
27 numOptionsDisplayable = 0;
32 WSelectList::~WSelectList()
37 void WSelectList::clear()
39 int vsize = options.size();
40 for (int i = 0; i < vsize; i++)
48 numOptionsDisplayable = 0;
52 void WSelectList::setNoLoop()
57 void WSelectList::hintSetCurrent(int index)
59 selectedOption = index;
60 if (selectedOption >= options.size()) selectedOption = options.size() - 1;
63 void WSelectList::hintSetTop(int index)
68 int WSelectList::addOption(char* text, int selected)
70 int thisNewOption = options.size();
71 int length = strlen(text);
72 options.push_back(new char[length + 1]);
73 strcpy(options[thisNewOption], text);
74 if (selected) selectedOption = thisNewOption;
78 void WSelectList::draw()
80 int fontHeight = surface->getFontHeight();
81 int ySeperation = fontHeight + 1;
83 numOptionsDisplayable = (height - 5) / ySeperation;
85 if (selectedOption == (topOption + numOptionsDisplayable)) topOption++;
86 if (selectedOption == ((UINT)topOption - 1)) topOption--;
87 // if still not visible...
88 if ((selectedOption < (UINT)topOption) || (selectedOption > (topOption + numOptionsDisplayable)))
90 topOption = selectedOption - (numOptionsDisplayable / 2);
93 if (topOption < 0) topOption = 0;
97 fillColour(Colour::VIEWBACKGROUND);
100 for (UINT i = topOption; i < (topOption + numOptionsDisplayable); i++)
102 if (i == options.size()) return;
103 if ((ypos + ySeperation) > height) break;
105 if (i == selectedOption)
107 rectangle(0, ypos, width, fontHeight, Colour::SELECTHIGHLIGHT);
108 drawOptionLine(options[i], 5, ypos, Colour::DARKTEXT);
112 drawOptionLine(options[i], 5, ypos, Colour::LIGHTTEXT);
118 void WSelectList::addColumn(int x)
120 if (numColumns == 10) return;
121 columns[numColumns++] = x;
124 void WSelectList::drawOptionLine(char* text, int xpos, int ypos, Colour& colour)
128 drawText(text, xpos, ypos, colour);
133 strncpy(buffer, text, 199);
134 int currentColumn = 0;
137 pointer = strtok(buffer, "\t");
140 drawText(pointer, xpos + columns[currentColumn], ypos, colour);
142 if (currentColumn == 10) return;
143 pointer = strtok(NULL, "\t");
149 void WSelectList::up()
151 if (selectedOption > 0)
157 if (!noLoop) selectedOption = options.size() - 1;
161 void WSelectList::down()
163 if (selectedOption < options.size() - 1)
169 if (!noLoop) selectedOption = 0;
173 void WSelectList::pageUp()
175 topOption -= numOptionsDisplayable;
176 if (topOption < 0) topOption = 0;
178 selectedOption = topOption;
181 void WSelectList::pageDown()
183 if ((topOption + numOptionsDisplayable) >= options.size()) return;
185 topOption += numOptionsDisplayable;
186 selectedOption = topOption;
189 int WSelectList::getTopOption()
194 int WSelectList::getNumOptions()
196 return options.size();
199 int WSelectList::getBottomOption()
201 UINT retval = topOption + numOptionsDisplayable;
202 if (retval > options.size()) return options.size();
206 int WSelectList::getCurrentOption()
208 return selectedOption;