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;
31 WSelectList::~WSelectList()
36 void WSelectList::clear()
38 int vsize = options.size();
39 for (int i = 0; i < vsize; i++)
47 numOptionsDisplayable = 0;
51 void WSelectList::hintSetCurrent(int index)
53 selectedOption = index;
54 if (selectedOption >= options.size()) selectedOption = options.size() - 1;
57 void WSelectList::hintSetTop(int index)
62 int WSelectList::addOption(char* text, int selected)
64 int thisNewOption = options.size();
65 int length = strlen(text);
66 options.push_back(new char[length + 1]);
67 strcpy(options[thisNewOption], text);
68 if (selected) selectedOption = thisNewOption;
72 void WSelectList::draw()
74 int fontHeight = surface->getFontHeight();
75 int ySeperation = fontHeight + 1;
77 numOptionsDisplayable = (height - 5) / ySeperation;
79 if (selectedOption == (topOption + numOptionsDisplayable)) topOption++;
80 if (selectedOption == (topOption - 1)) topOption--;
81 // if still not visible...
82 if ((selectedOption < topOption) || (selectedOption > (topOption + numOptionsDisplayable)))
84 topOption = selectedOption - (numOptionsDisplayable / 2);
87 if (topOption < 0) topOption = 0;
91 fillColour(Colour::VIEWBACKGROUND);
94 for (UINT i = topOption; i < (topOption + numOptionsDisplayable); i++)
96 if (i == options.size()) return;
97 if ((ypos + ySeperation) > height) break;
99 if (i == selectedOption)
101 rectangle(0, ypos, width, fontHeight, Colour::SELECTHIGHLIGHT);
102 drawOptionLine(options[i], 5, ypos, Colour::DARKTEXT);
106 drawOptionLine(options[i], 5, ypos, Colour::LIGHTTEXT);
112 void WSelectList::addColumn(int x)
114 if (numColumns == 10) return;
115 columns[numColumns++] = x;
118 void WSelectList::drawOptionLine(char* text, int xpos, int ypos, Colour& colour)
122 drawText(text, xpos, ypos, colour);
127 strncpy(buffer, text, 199);
128 int currentColumn = 0;
131 pointer = strtok(buffer, "\t");
134 drawText(pointer, xpos + columns[currentColumn], ypos, colour);
136 if (currentColumn == 10) return;
137 pointer = strtok(NULL, "\t");
143 void WSelectList::up()
145 if (selectedOption > 0)
151 selectedOption = options.size() - 1;
155 void WSelectList::down()
157 if (selectedOption < options.size() - 1)
167 void WSelectList::pageUp()
169 topOption -= numOptionsDisplayable;
170 if (topOption < 0) topOption = 0;
172 selectedOption = topOption;
175 void WSelectList::pageDown()
177 if ((topOption + numOptionsDisplayable) >= options.size()) return;
179 topOption += numOptionsDisplayable;
180 selectedOption = topOption;
183 int WSelectList::getTopOption()
188 int WSelectList::getNumOptions()
190 return options.size();
193 int WSelectList::getBottomOption()
195 UINT retval = topOption + numOptionsDisplayable;
196 if (retval > options.size()) return options.size();
200 int WSelectList::getCurrentOption()
202 return selectedOption;