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;
31 WSelectList::~WSelectList()
36 void WSelectList::clear()
38 for (int i = 0; i < numOptions; i++)
46 numOptionsDisplayable = 0;
49 void WSelectList::hintSetCurrent(int index)
51 selectedOption = index;
52 if (selectedOption >= numOptions) selectedOption = numOptions - 1;
55 void WSelectList::hintSetTop(int index)
60 int WSelectList::addOption(char* text, int selected)
62 int thisNewOption = numOptions;
63 int length = strlen(text);
64 options[thisNewOption] = new char[length + 1];
65 strcpy(options[thisNewOption], text);
66 if (selected) selectedOption = thisNewOption;
71 void WSelectList::draw()
73 int fontHeight = surface->getFontHeight();
74 int ySeperation = fontHeight + 1;
76 numOptionsDisplayable = (height - 5) / ySeperation;
78 if (selectedOption == (topOption + numOptionsDisplayable)) topOption++;
79 if (selectedOption == (topOption - 1)) topOption--;
80 // if still not visible...
81 if ((selectedOption < topOption) || (selectedOption > (topOption + numOptionsDisplayable)))
83 topOption = selectedOption - (numOptionsDisplayable / 2);
86 if (topOption < 0) topOption = 0;
90 fillColour(Colour::VIEWBACKGROUND);
93 for (int i = topOption; i < (topOption + numOptionsDisplayable); i++)
95 if (i == numOptions) return;
96 if ((ypos + ySeperation) > height) break;
98 if (i == selectedOption)
100 rectangle(0, ypos, width, fontHeight, Colour::SELECTHIGHLIGHT);
101 drawText(options[i], 5, ypos, Colour::DARKTEXT);
105 drawText(options[i], 5, ypos, Colour::LIGHTTEXT);
111 void WSelectList::up()
113 if (selectedOption > 0)
119 selectedOption = numOptions - 1;
123 void WSelectList::down()
125 if (selectedOption < numOptions - 1)
135 void WSelectList::pageUp()
137 topOption -= numOptionsDisplayable;
138 if (topOption < 0) topOption = 0;
140 selectedOption = topOption;
143 void WSelectList::pageDown()
145 if ((topOption + numOptionsDisplayable) >= numOptions) return;
147 topOption += numOptionsDisplayable;
148 selectedOption = topOption;
151 int WSelectList::getTopOption()
156 int WSelectList::getNumOptions()
161 int WSelectList::getBottomOption()
163 int retval = topOption + numOptionsDisplayable;
164 if (retval > numOptions) return numOptions;
168 int WSelectList::getCurrentOption()
170 return selectedOption;