]> git.vomp.tv Git - vompclient.git/blob - wselectlist.cc
Demuxer::scanForVideo()
[vompclient.git] / wselectlist.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
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.
10
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.
15
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
19 */
20
21 #include "wselectlist.h"
22
23 WSelectList::WSelectList()
24 {
25   selectedOption = 0;
26   topOption = 0;
27   numOptionsDisplayable = 0;
28   numColumns = 0;
29   noLoop = 0;
30   gap = 1;
31 }
32
33 WSelectList::~WSelectList()
34 {
35   clear();
36 }
37
38 void WSelectList::clear()
39 {
40   int vsize = options.size();
41   for (int i = 0; i < vsize; i++)
42   {
43     delete[] options[i].text;
44   }
45   options.clear();
46
47   selectedOption = 0;
48   topOption = 0;
49   numOptionsDisplayable = 0;
50   numColumns = 0;
51 }
52
53 void WSelectList::setNoLoop()
54 {
55   noLoop = 1;
56 }
57
58 void WSelectList::hintSetCurrent(int idx)
59 {
60   selectedOption = idx;
61   if (selectedOption >= options.size()) selectedOption = options.size() - 1;
62 }
63
64 void WSelectList::hintSetTop(int idx)
65 {
66   topOption = idx;
67 }
68
69 int WSelectList::addOption(char* text, ULONG data, int selected)
70 {
71   int thisNewOption = options.size();
72
73   wsloption wslo;
74   wslo.text = new char[strlen(text) + 1];
75   strcpy(wslo.text, text);
76   wslo.data = data;
77   options.push_back(wslo);
78   if (selected) selectedOption = thisNewOption;
79   return thisNewOption;
80 }
81
82 void WSelectList::draw()
83 {
84   int fontHeight = surface->getFontHeight();
85   int ySeperation = fontHeight + gap;
86
87   numOptionsDisplayable = (area.h - 5) / ySeperation;
88
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)))
93   {
94     topOption = selectedOption - (numOptionsDisplayable / 2);
95   }
96
97   if (topOption < 0) topOption = 0;
98
99
100
101   fillColour(backgroundColour);
102
103   UINT ypos = 5;
104   for (UINT i = topOption; i < (topOption + numOptionsDisplayable); i++)
105   {
106     if (i == options.size()) return;
107     if ((ypos + ySeperation) > area.h) break;
108
109     if (i == selectedOption)
110     {
111       rectangle(0, ypos, area.w, fontHeight, Colour::SELECTHIGHLIGHT);
112       drawOptionLine(options[i].text, 5, ypos, Colour::DARKTEXT);
113     }
114     else
115     {
116       drawOptionLine(options[i].text, 5, ypos, Colour::LIGHTTEXT);
117     }
118     ypos += ySeperation;
119   }
120 }
121
122 void WSelectList::addColumn(int x)
123 {
124   if (numColumns == 10) return;
125   columns[numColumns++] = x;
126 }
127
128 void WSelectList::drawOptionLine(char* text, int xpos, int ypos, Colour& colour)
129 {
130   if (!numColumns)
131   {
132     drawText(text, xpos, ypos, colour);
133   }
134   else
135   {
136     char buffer[200];
137     strncpy(buffer, text, 199);
138     int currentColumn = 0;
139     char* pointer;
140
141     pointer = strtok(buffer, "\t");
142     while(pointer)
143     {
144       drawText(pointer, xpos + columns[currentColumn], ypos, colour);
145       currentColumn++;
146       if (currentColumn == 10) return;
147       pointer = strtok(NULL, "\t");
148     }
149   }
150 }
151
152
153 void WSelectList::up()
154 {
155   if (selectedOption > 0)
156   {
157     selectedOption--;
158   }
159   else
160   {
161     if (!noLoop) selectedOption = options.size() - 1;
162   }
163 }
164
165 void WSelectList::down()
166 {
167   if (selectedOption < options.size() - 1)
168   {
169     selectedOption++;
170   }
171   else
172   {
173     if (!noLoop) selectedOption = 0;
174   }
175 }
176
177 void WSelectList::pageUp()
178 {
179   topOption -= numOptionsDisplayable;
180   if (topOption < 0) topOption = 0;
181
182   selectedOption = topOption;
183 }
184
185 void WSelectList::pageDown()
186 {
187   if ((topOption + numOptionsDisplayable) >= options.size())
188   {
189     selectedOption = options.size() - 1;
190   }
191   else
192   {
193     topOption += numOptionsDisplayable;
194     selectedOption = topOption;
195   }
196 }
197
198 int WSelectList::getTopOption()
199 {
200   return topOption;
201 }
202
203 int WSelectList::getNumOptions()
204 {
205   return options.size();
206 }
207
208 int WSelectList::getBottomOption()
209 {
210   UINT retval = topOption + numOptionsDisplayable;
211   if (retval > options.size()) return options.size();
212   else return retval;
213 }
214
215 int WSelectList::getCurrentOption()
216 {
217   return selectedOption;
218 }
219
220 ULONG WSelectList::getCurrentOptionData()
221 {
222   return options[selectedOption].data;
223 }