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()
28 numOptionsDisplayable = 0;
32 WSelectList::~WSelectList()
37 void WSelectList::clear()
39 for (int i = 0; i < numOptions; i++)
47 numOptionsDisplayable = 0;
51 void WSelectList::hintSetCurrent(int index)
53 selectedOption = index;
54 if (selectedOption >= numOptions) selectedOption = numOptions - 1;
57 void WSelectList::hintSetTop(int index)
62 int WSelectList::addOption(char* text, int selected)
64 int thisNewOption = numOptions;
65 int length = strlen(text);
66 options[thisNewOption] = new char[length + 1];
67 strcpy(options[thisNewOption], text);
68 if (selected) selectedOption = thisNewOption;
73 void WSelectList::draw()
75 int fontHeight = surface->getFontHeight();
76 int ySeperation = fontHeight + 1;
78 numOptionsDisplayable = (height - 5) / ySeperation;
80 if (selectedOption == (topOption + numOptionsDisplayable)) topOption++;
81 if (selectedOption == (topOption - 1)) topOption--;
82 // if still not visible...
83 if ((selectedOption < topOption) || (selectedOption > (topOption + numOptionsDisplayable)))
85 topOption = selectedOption - (numOptionsDisplayable / 2);
88 if (topOption < 0) topOption = 0;
92 fillColour(Colour::VIEWBACKGROUND);
95 for (int i = topOption; i < (topOption + numOptionsDisplayable); i++)
97 if (i == numOptions) return;
98 if ((ypos + ySeperation) > height) break;
100 if (i == selectedOption)
102 rectangle(0, ypos, width, fontHeight, Colour::SELECTHIGHLIGHT);
103 drawOptionLine(options[i], 5, ypos, Colour::DARKTEXT);
107 drawOptionLine(options[i], 5, ypos, Colour::LIGHTTEXT);
113 void WSelectList::addColumn(int x)
115 if (numColumns == 10) return;
116 columns[numColumns++] = x;
119 void WSelectList::drawOptionLine(char* text, int xpos, int ypos, Colour& colour)
123 drawText(text, xpos, ypos, colour);
128 strncpy(buffer, text, 199);
129 int currentColumn = 0;
132 pointer = strtok(buffer, "\t");
135 drawText(pointer, xpos + columns[currentColumn], ypos, colour);
137 if (currentColumn == 10) return;
138 pointer = strtok(NULL, "\t");
144 void WSelectList::up()
146 if (selectedOption > 0)
152 selectedOption = numOptions - 1;
156 void WSelectList::down()
158 if (selectedOption < numOptions - 1)
168 void WSelectList::pageUp()
170 topOption -= numOptionsDisplayable;
171 if (topOption < 0) topOption = 0;
173 selectedOption = topOption;
176 void WSelectList::pageDown()
178 if ((topOption + numOptionsDisplayable) >= numOptions) return;
180 topOption += numOptionsDisplayable;
181 selectedOption = topOption;
184 int WSelectList::getTopOption()
189 int WSelectList::getNumOptions()
194 int WSelectList::getBottomOption()
196 int retval = topOption + numOptionsDisplayable;
197 if (retval > numOptions) return numOptions;
201 int WSelectList::getCurrentOption()
203 return selectedOption;