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;
33 WSelectList::~WSelectList()
38 void WSelectList::clear()
40 int vsize = options.size();
41 for (int i = 0; i < vsize; i++)
49 numOptionsDisplayable = 0;
53 void WSelectList::setNoLoop()
58 void WSelectList::hintSetCurrent(int idx)
61 if (selectedOption >= options.size()) selectedOption = options.size() - 1;
64 void WSelectList::hintSetTop(int idx)
69 int WSelectList::addOption(char* text, int selected)
71 int thisNewOption = options.size();
72 int length = strlen(text);
73 options.push_back(new char[length + 1]);
74 strcpy(options[thisNewOption], text);
75 if (selected) selectedOption = thisNewOption;
79 void WSelectList::draw()
81 int fontHeight = surface->getFontHeight();
82 int ySeperation = fontHeight + gap;
84 numOptionsDisplayable = (area.h - 5) / ySeperation;
86 if (selectedOption == (topOption + numOptionsDisplayable)) topOption++;
87 if (selectedOption == ((UINT)topOption - 1)) topOption--;
88 // if still not visible...
89 if ((selectedOption < (UINT)topOption) || (selectedOption > (topOption + numOptionsDisplayable)))
91 topOption = selectedOption - (numOptionsDisplayable / 2);
94 if (topOption < 0) topOption = 0;
98 fillColour(Colour::VIEWBACKGROUND);
101 for (UINT i = topOption; i < (topOption + numOptionsDisplayable); i++)
103 if (i == options.size()) return;
104 if ((ypos + ySeperation) > area.h) break;
106 if (i == selectedOption)
108 rectangle(0, ypos, area.w, fontHeight, Colour::SELECTHIGHLIGHT);
109 drawOptionLine(options[i], 5, ypos, Colour::DARKTEXT);
113 drawOptionLine(options[i], 5, ypos, Colour::LIGHTTEXT);
119 void WSelectList::addColumn(int x)
121 if (numColumns == 10) return;
122 columns[numColumns++] = x;
125 void WSelectList::drawOptionLine(char* text, int xpos, int ypos, Colour& colour)
129 drawText(text, xpos, ypos, colour);
134 strncpy(buffer, text, 199);
135 int currentColumn = 0;
138 pointer = strtok(buffer, "\t");
141 drawText(pointer, xpos + columns[currentColumn], ypos, colour);
143 if (currentColumn == 10) return;
144 pointer = strtok(NULL, "\t");
150 void WSelectList::up()
152 if (selectedOption > 0)
158 if (!noLoop) selectedOption = options.size() - 1;
162 void WSelectList::down()
164 if (selectedOption < options.size() - 1)
170 if (!noLoop) selectedOption = 0;
174 void WSelectList::pageUp()
176 topOption -= numOptionsDisplayable;
177 if (topOption < 0) topOption = 0;
179 selectedOption = topOption;
182 void WSelectList::pageDown()
184 if ((topOption + numOptionsDisplayable) >= options.size()) return;
186 topOption += numOptionsDisplayable;
187 selectedOption = topOption;
190 int WSelectList::getTopOption()
195 int WSelectList::getNumOptions()
197 return options.size();
200 int WSelectList::getBottomOption()
202 UINT retval = topOption + numOptionsDisplayable;
203 if (retval > options.size()) return options.size();
207 int WSelectList::getCurrentOption()
209 return selectedOption;