]> git.vomp.tv Git - vompclient.git/blob - wselectlist.cc
Remove manual sync buttons
[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];
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, int selected)
70 {
71   int thisNewOption = options.size();
72   int length = strlen(text);
73   options.push_back(new char[length + 1]);
74   strcpy(options[thisNewOption], text);
75   if (selected) selectedOption = thisNewOption;
76   return thisNewOption;
77 }
78
79 void WSelectList::draw()
80 {
81   int fontHeight = surface->getFontHeight();
82   int ySeperation = fontHeight + gap;
83
84   numOptionsDisplayable = (area.h - 5) / ySeperation;
85
86   if (selectedOption == (topOption + numOptionsDisplayable)) topOption++;
87   if (selectedOption == ((UINT)topOption - 1)) topOption--;
88   // if still not visible...
89   if ((selectedOption < (UINT)topOption) || (selectedOption > (topOption + numOptionsDisplayable)))
90   {
91     topOption = selectedOption - (numOptionsDisplayable / 2);
92   }
93
94   if (topOption < 0) topOption = 0;
95
96
97
98   fillColour(Colour::VIEWBACKGROUND);
99
100   UINT ypos = 5;
101   for (UINT i = topOption; i < (topOption + numOptionsDisplayable); i++)
102   {
103     if (i == options.size()) return;
104     if ((ypos + ySeperation) > area.h) break;
105
106     if (i == selectedOption)
107     {
108       rectangle(0, ypos, area.w, fontHeight, Colour::SELECTHIGHLIGHT);
109       drawOptionLine(options[i], 5, ypos, Colour::DARKTEXT);
110     }
111     else
112     {
113       drawOptionLine(options[i], 5, ypos, Colour::LIGHTTEXT);
114     }
115     ypos += ySeperation;
116   }
117 }
118
119 void WSelectList::addColumn(int x)
120 {
121   if (numColumns == 10) return;
122   columns[numColumns++] = x;
123 }
124
125 void WSelectList::drawOptionLine(char* text, int xpos, int ypos, Colour& colour)
126 {
127   if (!numColumns)
128   {
129     drawText(text, xpos, ypos, colour);
130   }
131   else
132   {
133     char buffer[200];
134     strncpy(buffer, text, 199);
135     int currentColumn = 0;
136     char* pointer;
137
138     pointer = strtok(buffer, "\t");
139     while(pointer)
140     {
141       drawText(pointer, xpos + columns[currentColumn], ypos, colour);
142       currentColumn++;
143       if (currentColumn == 10) return;
144       pointer = strtok(NULL, "\t");
145     }
146   }
147 }
148
149
150 void WSelectList::up()
151 {
152   if (selectedOption > 0)
153   {
154     selectedOption--;
155   }
156   else
157   {
158     if (!noLoop) selectedOption = options.size() - 1;
159   }
160 }
161
162 void WSelectList::down()
163 {
164   if (selectedOption < options.size() - 1)
165   {
166     selectedOption++;
167   }
168   else
169   {
170     if (!noLoop) selectedOption = 0;
171   }
172 }
173
174 void WSelectList::pageUp()
175 {
176   topOption -= numOptionsDisplayable;
177   if (topOption < 0) topOption = 0;
178
179   selectedOption = topOption;
180 }
181
182 void WSelectList::pageDown()
183 {
184   if ((topOption + numOptionsDisplayable) >= options.size())
185   {
186     selectedOption = options.size() - 1;
187   }
188   else
189   {
190     topOption += numOptionsDisplayable;
191     selectedOption = topOption;
192   }
193 }
194
195 int WSelectList::getTopOption()
196 {
197   return topOption;
198 }
199
200 int WSelectList::getNumOptions()
201 {
202   return options.size();
203 }
204
205 int WSelectList::getBottomOption()
206 {
207   UINT retval = topOption + numOptionsDisplayable;
208   if (retval > options.size()) return options.size();
209   else return retval;
210 }
211
212 int WSelectList::getCurrentOption()
213 {
214   return selectedOption;
215 }