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++)
43 delete[] options[i].text;
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, ULONG data, int selected)
71 int thisNewOption = options.size();
74 wslo.text = new char[strlen(text) + 1];
75 strcpy(wslo.text, text);
77 options.push_back(wslo);
78 if (selected) selectedOption = thisNewOption;
82 void WSelectList::draw()
84 int fontHeight = surface->getFontHeight();
85 int ySeperation = fontHeight + gap;
87 numOptionsDisplayable = (area.h - 5) / ySeperation;
89 if (selectedOption == (topOption + numOptionsDisplayable)) topOption++;
90 if (selectedOption == ((UINT)topOption - 1)) topOption--;
91 // if still not visible...
92 if ((selectedOption < (UINT)topOption) || (selectedOption > (topOption + numOptionsDisplayable)))
94 topOption = selectedOption - (numOptionsDisplayable / 2);
97 if (topOption < 0) topOption = 0;
101 fillColour(Colour::VIEWBACKGROUND);
104 for (UINT i = topOption; i < (topOption + numOptionsDisplayable); i++)
106 if (i == options.size()) return;
107 if ((ypos + ySeperation) > area.h) break;
109 if (i == selectedOption)
111 rectangle(0, ypos, area.w, fontHeight, Colour::SELECTHIGHLIGHT);
112 drawOptionLine(options[i].text, 5, ypos, Colour::DARKTEXT);
116 drawOptionLine(options[i].text, 5, ypos, Colour::LIGHTTEXT);
122 void WSelectList::addColumn(int x)
124 if (numColumns == 10) return;
125 columns[numColumns++] = x;
128 void WSelectList::drawOptionLine(char* text, int xpos, int ypos, Colour& colour)
132 drawText(text, xpos, ypos, colour);
137 strncpy(buffer, text, 199);
138 int currentColumn = 0;
141 pointer = strtok(buffer, "\t");
144 drawText(pointer, xpos + columns[currentColumn], ypos, colour);
146 if (currentColumn == 10) return;
147 pointer = strtok(NULL, "\t");
153 void WSelectList::up()
155 if (selectedOption > 0)
161 if (!noLoop) selectedOption = options.size() - 1;
165 void WSelectList::down()
167 if (selectedOption < options.size() - 1)
173 if (!noLoop) selectedOption = 0;
177 void WSelectList::pageUp()
179 topOption -= numOptionsDisplayable;
180 if (topOption < 0) topOption = 0;
182 selectedOption = topOption;
185 void WSelectList::pageDown()
187 if ((topOption + numOptionsDisplayable) >= options.size())
189 selectedOption = options.size() - 1;
193 topOption += numOptionsDisplayable;
194 selectedOption = topOption;
198 int WSelectList::getTopOption()
203 int WSelectList::getNumOptions()
205 return options.size();
208 int WSelectList::getBottomOption()
210 UINT retval = topOption + numOptionsDisplayable;
211 if (retval > options.size()) return options.size();
215 int WSelectList::getCurrentOption()
217 return selectedOption;
220 ULONG WSelectList::getCurrentOptionData()
222 return options[selectedOption].data;