2 Copyright 2004-2005 Chris Tallon
\r
4 This file is part of VOMP.
\r
6 VOMP is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 VOMP is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with VOMP; if not, write to the Free Software
\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
21 #include "wselectlist.h"
\r
26 WSelectList::WSelectList()
\r
30 numOptionsDisplayable = 0;
\r
34 showseloption = true;
\r
35 darkseloption = false;
\r
36 backgroundColour = Colour::VIEWBACKGROUND;
\r
39 WSelectList::~WSelectList()
\r
44 void WSelectList::clear()
\r
46 int vsize = options.size();
\r
47 for (int i = 0; i < vsize; i++)
\r
49 delete[] options[i].text;
\r
55 numOptionsDisplayable = 0;
\r
59 void WSelectList::setNoLoop()
\r
64 void WSelectList::setBackgroundColour(const Colour& colour)
\r
66 backgroundColour = colour;
\r
69 void WSelectList::hintSetCurrent(int idx)
\r
71 selectedOption = idx;
\r
72 if (selectedOption >= options.size()) selectedOption = options.size() - 1;
\r
75 void WSelectList::hintSetTop(int idx)
\r
80 int WSelectList::addOption(const char* text, ULONG data, int selected)
\r
82 int thisNewOption = options.size();
\r
85 wslo.text = new char[strlen(text) + 1];
\r
86 strcpy(wslo.text, text);
\r
88 options.push_back(wslo);
\r
89 if (selected) selectedOption = thisNewOption;
\r
90 return thisNewOption;
\r
93 void WSelectList::draw()
\r
95 int fontHeight = getFontHeight();
\r
96 int ySeperation = fontHeight + gap;
\r
98 numOptionsDisplayable = (area.h - 5) / ySeperation;
\r
100 if (selectedOption == (topOption + numOptionsDisplayable)) topOption++;
\r
101 if (selectedOption == ((UINT)topOption - 1)) topOption--;
\r
102 // if still not visible...
\r
103 if ((selectedOption < (UINT)topOption) || (selectedOption > (topOption + numOptionsDisplayable)))
\r
105 topOption = selectedOption - (numOptionsDisplayable / 2);
\r
108 if (topOption < 0) topOption = 0;
\r
111 fillColour(backgroundColour);
\r
114 for (UINT i = topOption; i < (topOption + numOptionsDisplayable); i++)
\r
116 if (i == options.size()) return;
\r
117 if ((ypos + ySeperation) > area.h) break;
\r
119 if (i == selectedOption && showseloption)
\r
122 rectangle(0, ypos, area.w, fontHeight, darkseloption ? Colour::SELECTDARKHIGHLIGHT: Colour::SELECTHIGHLIGHT);
\r
124 drawOptionLine(options[i].text, 5, ypos, area.w - 5, Colour::DARKTEXT);
\r
129 drawOptionLine(options[i].text, 5, ypos, area.w - 5, Colour::LIGHTTEXT);
\r
131 ypos += ySeperation;
\r
136 void WSelectList::addColumn(int x)
\r
138 if (numColumns == 10) return;
\r
139 columns[numColumns++] = x;
\r
142 void WSelectList::drawOptionLine(char* text, int xpos, int ypos, int width, const Colour& colour)
\r
147 drawText(text, xpos, ypos, width, colour);
\r
152 strncpy(buffer, text, 199);
\r
153 int currentColumn = 0;
\r
156 pointer = strtok(buffer, "\t");
\r
160 drawText(pointer, xpos + columns[currentColumn], ypos, width - columns[currentColumn], colour);
\r
163 if (currentColumn == 10) return;
\r
164 pointer = strtok(NULL, "\t");
\r
169 void WSelectList::up()
\r
171 if (selectedOption > 0)
\r
177 if (!noLoop) selectedOption = options.size() - 1;
\r
181 void WSelectList::down()
\r
183 if (selectedOption < options.size() - 1)
\r
189 if (!noLoop) selectedOption = 0;
\r
193 void WSelectList::pageUp()
\r
195 topOption -= numOptionsDisplayable;
\r
196 if (topOption < 0) topOption = 0;
\r
198 selectedOption = topOption;
\r
201 void WSelectList::pageDown()
\r
203 if ((topOption + numOptionsDisplayable) >= options.size())
\r
205 selectedOption = options.size() - 1;
\r
209 topOption += numOptionsDisplayable;
\r
210 selectedOption = topOption;
\r
214 int WSelectList::getTopOption()
\r
219 int WSelectList::getNumOptions()
\r
221 return options.size();
\r
224 int WSelectList::getBottomOption()
\r
226 UINT retval = topOption + numOptionsDisplayable;
\r
227 if (retval > options.size()) return options.size();
\r
228 else return retval;
\r
231 int WSelectList::getCurrentOption()
\r
233 return selectedOption;
\r
236 ULONG WSelectList::getCurrentOptionData()
\r
238 if (!options.size()) return 0;
\r
239 return options[selectedOption].data;
\r
242 bool WSelectList::mouseAndroidScroll(int x, int y,int sx, int sy)
\r
244 /* int fontHeight = getFontHeight();
\r
245 int movelines= sy/fontHeight;
\r
247 int seloption=selectedOption+movelines;
\r
248 if (seloption<0) seloption=0;
\r
249 else if (seloption>options.size()-1) seloption=options.size()-1;
\r
250 selectedOption=seloption;*/
\r
254 bool WSelectList::mouseMove(int x, int y)
\r
256 int ml = getMouseLine(x-getRootBoxOffsetX(), y-getRootBoxOffsetY());
\r
257 if (ml>=0 && ml!=(int)selectedOption)
\r
259 selectedOption = ml;
\r
265 bool WSelectList::mouseLBDOWN(int x, int y)
\r
267 int ml = getMouseLine(x-getRootBoxOffsetX(), y-getRootBoxOffsetY());
\r
268 if (ml == (int)selectedOption)
\r
270 /* caller should generate a OK message*/
\r
276 int WSelectList::getMouseLine(int x,int y)
\r
278 int fontHeight = getFontHeight();
\r
279 int ySeperation = fontHeight + gap;
\r
281 if (y<0) return -1;
\r
282 if (x<0 || x>(int)area.w) return -1;
\r
283 if (y>(int)(10+numOptionsDisplayable*ySeperation)) return -1;
\r
287 int selected=cy/ySeperation;
\r
288 if (y<5) selected=-1;
\r
289 if (selected> ((int)numOptionsDisplayable)) return -1;
\r
290 /* Important: should be the same algorithm used in draw! */
\r
291 if (selectedOption == (topOption + numOptionsDisplayable)) topOption++;
\r
292 if (selectedOption == ((UINT)topOption - 1)) topOption--;
\r
293 // if still not visible...
\r
294 if ((selectedOption < (UINT)topOption) || (selectedOption > (topOption + numOptionsDisplayable)))
\r
296 topOption = selectedOption - (numOptionsDisplayable / 2);
\r
299 if (topOption < 0) topOption = 0;
\r
301 if ((selected+topOption >= (int) options.size()) ||
\r
302 (selected + topOption < 0)) return -1;
\r
304 return selected + topOption;
\r