]> git.vomp.tv Git - vompclient.git/blob - wselectlist.cc
Un-hardcoded all the colours
[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   numOptions = 0;
26   selectedOption = 0;
27   topOption = 0;
28   numOptionsDisplayable = 0;
29 }
30
31 WSelectList::~WSelectList()
32 {
33   clear();
34 }
35
36 void WSelectList::clear()
37 {
38   for (int i = 0; i < numOptions; i++)
39   {
40     delete[] options[i];
41   }
42
43   numOptions = 0;
44   selectedOption = 0;
45   topOption = 0;
46   numOptionsDisplayable = 0;
47 }
48
49 void WSelectList::hintSetCurrent(int index)
50 {
51   selectedOption = index;
52   if (selectedOption >= numOptions) selectedOption = numOptions - 1;
53 }
54
55 void WSelectList::hintSetTop(int index)
56 {
57   topOption = index;
58 }
59
60 int WSelectList::addOption(char* text, int selected)
61 {
62   int thisNewOption = numOptions;
63   int length = strlen(text);
64   options[thisNewOption] = new char[length + 1];
65   strcpy(options[thisNewOption], text);
66   if (selected) selectedOption = thisNewOption;
67   numOptions++;
68   return thisNewOption;
69 }
70
71 void WSelectList::draw()
72 {
73   int fontHeight = surface->getFontHeight();
74   int ySeperation = fontHeight + 1;
75
76   numOptionsDisplayable = (height - 5) / ySeperation;
77
78   if (selectedOption == (topOption + numOptionsDisplayable)) topOption++;
79   if (selectedOption == (topOption - 1)) topOption--;
80   // if still not visible...
81   if ((selectedOption < topOption) || (selectedOption > (topOption + numOptionsDisplayable)))
82   {
83     topOption = selectedOption - (numOptionsDisplayable / 2);
84   }
85
86   if (topOption < 0) topOption = 0;
87
88
89
90   fillColour(Colour::VIEWBACKGROUND);
91
92   int ypos = 5;
93   for (int i = topOption; i < (topOption + numOptionsDisplayable); i++)
94   {
95     if (i == numOptions) return;
96     if ((ypos + ySeperation) > height) break;
97
98     if (i == selectedOption)
99     {
100       rectangle(0, ypos, width, fontHeight, Colour::SELECTHIGHLIGHT);
101       drawText(options[i], 5, ypos, Colour::DARKTEXT);
102     }
103     else
104     {
105       drawText(options[i], 5, ypos, Colour::LIGHTTEXT);
106     }
107     ypos += ySeperation;
108   }
109 }
110
111 void WSelectList::up()
112 {
113   if (selectedOption > 0)
114   {
115     selectedOption--;
116   }
117   else
118   {
119     selectedOption = numOptions - 1;
120   }
121 }
122
123 void WSelectList::down()
124 {
125   if (selectedOption < numOptions - 1)
126   {
127     selectedOption++;
128   }
129   else
130   {
131     selectedOption = 0;
132   }
133 }
134
135 void WSelectList::pageUp()
136 {
137   topOption -= numOptionsDisplayable;
138   if (topOption < 0) topOption = 0;
139
140   selectedOption = topOption;
141 }
142
143 void WSelectList::pageDown()
144 {
145   if ((topOption + numOptionsDisplayable) >= numOptions) return;
146
147   topOption += numOptionsDisplayable;
148   selectedOption = topOption;
149 }
150
151 int WSelectList::getTopOption()
152 {
153   return topOption;
154 }
155
156 int WSelectList::getNumOptions()
157 {
158   return numOptions;
159 }
160
161 int WSelectList::getBottomOption()
162 {
163   int retval = topOption + numOptionsDisplayable;
164   if (retval > numOptions) return numOptions;
165   else return retval;
166 }
167
168 int WSelectList::getCurrentOption()
169 {
170   return selectedOption;
171 }