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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "wselectlist.h"
28 WSelectList::WSelectList():
29 backgroundColour(DrawStyle::VIEWBACKGROUND)
33 numOptionsDisplayable = 0;
38 darkseloption = false;
43 WSelectList::~WSelectList()
48 void WSelectList::clear()
50 int vsize = options.size();
51 for (int i = 0; i < vsize; i++)
53 delete[] options[i].text;
54 if (options[i].pict) delete options[i].pict;
60 numOptionsDisplayable = 0;
64 void WSelectList::setNoLoop()
69 void WSelectList::setBackgroundColour(const DrawStyle& colour)
71 backgroundColour = colour;
74 void WSelectList::hintSetCurrent(int idx)
77 if (selectedOption >= options.size()) selectedOption = options.size() - 1;
80 void WSelectList::hintSetTop(int idx)
85 int WSelectList::addOption(const char* text, ULONG data, int selected, TVMediaInfo * pict)
87 int thisNewOption = options.size();
90 wslo.text = new char[strlen(text) + 1];
91 strcpy(wslo.text, text);
94 options.push_back(wslo);
95 if (selected) selectedOption = thisNewOption;
99 void WSelectList::draw()
101 int fontHeight = getFontHeight();
102 int ySeperation = fontHeight * linesPerOption + gap;
104 numOptionsDisplayable = (area.h - 5) / ySeperation;
106 if (selectedOption == (topOption + numOptionsDisplayable)) topOption++;
107 if (selectedOption == ((UINT)topOption - 1)) topOption--;
108 // if still not visible...
109 if ((selectedOption < (UINT)topOption) || (selectedOption > (topOption + numOptionsDisplayable)))
111 topOption = selectedOption - (numOptionsDisplayable / 2);
114 if (topOption < 0) topOption = 0;
117 fillColour(backgroundColour);
120 for (UINT i = topOption; i < (topOption + numOptionsDisplayable); i++)
122 if (i == options.size()) return;
123 if ((ypos + ySeperation) > area.h) break;
125 if (i == selectedOption && showseloption)
128 rectangle(0, ypos, area.w, fontHeight * linesPerOption, darkseloption ? DrawStyle::SELECTDARKHIGHLIGHT: DrawStyle::SELECTHIGHLIGHT);
130 drawOptionLine(options[i].text, 5, ypos, area.w - 5, DrawStyle::DARKTEXT, options[i].pict);
135 drawOptionLine(options[i].text, 5, ypos, area.w - 5, DrawStyle::LIGHTTEXT, options[i].pict);
142 void WSelectList::addColumn(int x)
144 if (numColumns == 10) return;
145 columns[numColumns++] = x;
148 int WSelectList::getColumn(int x)
150 if (x>= numColumns) return 0;
154 void WSelectList::drawOptionLine(char* text, int xpos, int ypos, int width, const DrawStyle& colour, TVMediaInfo* pict)
158 int fontHeight = getFontHeight();
159 float ypos_mod= ypos + (linesPerOption-floor(linesPerOption))*((float)fontHeight)*0.5f;
163 drawTVMedia(*pict, xpos,ypos,0,fontHeight*linesPerOption,TopLeft);
167 if (!numColumns && linesPerOption == 1)
170 drawText(text, xpos, ypos, width, colour);
175 strncpy(buffer, text, 199);
176 int currentColumn = taboffset;
179 pointer = strtok(buffer, "\t\n");
182 drawText(pointer, xpos + columns[currentColumn], ypos_mod + curline * fontHeight, width - columns[currentColumn], colour);
184 pointer = strtok(NULL, "\t\n");
186 char delimiter = text[pointer - buffer-1];
187 if (delimiter == '\t') currentColumn++;
188 else if (delimiter == '\n' ){
189 currentColumn = taboffset;
193 if (curline >= linesPerOption) return;
195 if (currentColumn == 10) return;
200 void WSelectList::up()
202 if (selectedOption > 0)
208 if (!noLoop) selectedOption = options.size() - 1;
212 void WSelectList::down()
214 if (selectedOption < options.size() - 1)
220 if (!noLoop) selectedOption = 0;
224 void WSelectList::pageUp()
226 topOption -= numOptionsDisplayable;
227 if (topOption < 0) topOption = 0;
229 selectedOption = topOption;
232 void WSelectList::pageDown()
234 if ((topOption + numOptionsDisplayable) >= options.size())
236 selectedOption = options.size() - 1;
240 topOption += numOptionsDisplayable;
241 selectedOption = topOption;
245 int WSelectList::getTopOption()
250 int WSelectList::getNumOptions()
252 return options.size();
255 int WSelectList::getBottomOption()
257 UINT retval = topOption + numOptionsDisplayable;
258 if (retval > options.size()) return options.size();
262 int WSelectList::getCurrentOption()
264 return selectedOption;
267 ULONG WSelectList::getCurrentOptionData()
269 if (!options.size()) return 0;
270 return options[selectedOption].data;
273 int WSelectList::getNumOptionsDisplayable()
275 return numOptionsDisplayable;
278 bool WSelectList::mouseAndroidScroll(int x, int y,int sx, int sy)
280 /* int fontHeight = getFontHeight();
281 int movelines= sy/fontHeight;
283 int seloption=selectedOption+movelines;
284 if (seloption<0) seloption=0;
285 else if (seloption>options.size()-1) seloption=options.size()-1;
286 selectedOption=seloption;*/
291 bool WSelectList::mouseMove(int x, int y)
293 int ml = getMouseLine(x-getRootBoxOffsetX(), y-getRootBoxOffsetY());
294 if (ml>=0 && ml!=(int)selectedOption)
302 bool WSelectList::mouseLBDOWN(int x, int y)
304 int ml = getMouseLine(x-getRootBoxOffsetX(), y-getRootBoxOffsetY());
305 if (ml == (int)selectedOption)
307 /* caller should generate a OK message*/
313 int WSelectList::getMouseLine(int x,int y)
315 int fontHeight = getFontHeight();
316 int ySeperation = fontHeight + gap;
319 if (x<0 || x>(int)area.w) return -1;
320 if (y>(int)(10+numOptionsDisplayable*ySeperation)) return -1;
324 int selected=cy/ySeperation;
325 if (y<5) selected=-1;
326 if (selected> ((int)numOptionsDisplayable)) return -1;
327 /* Important: should be the same algorithm used in draw! */
328 if (selectedOption == (topOption + numOptionsDisplayable)) topOption++;
329 if (selectedOption == ((UINT)topOption - 1)) topOption--;
330 // if still not visible...
331 if ((selectedOption < (UINT)topOption) || (selectedOption > (topOption + numOptionsDisplayable)))
333 topOption = selectedOption - (numOptionsDisplayable / 2);
336 if (topOption < 0) topOption = 0;
338 if ((selected+topOption >= (int) options.size()) ||
339 (selected + topOption < 0)) return -1;
341 return selected + topOption;