]> git.vomp.tv Git - vompclient.git/blob - woptionbox.cc
Switch trunk code to new boxes
[vompclient.git] / woptionbox.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 "woptionbox.h"
22
23 #include "colour.h"
24 #include "unistd.h"
25
26 WOptionBox::WOptionBox()
27 {
28   numOptions = 0;
29   options = NULL;
30   active = 0;
31   currentOption = 0;
32
33   mode = MODE_TEXT;
34   
35   textbox.setPosition(20, 0);
36   textbox.setSize(10, surface->getFontHeight());
37   textbox.setParaMode(false);
38   textbox.setTextPos(0, 0);
39   add(&textbox);
40   
41   leftArrow.setPosition(0, 2);
42   leftArrow.nextSymbol = WSymbol::LEFTARROW;
43   add(&leftArrow);
44   
45   rightArrow.setPosition(0, 2);
46   rightArrow.nextSymbol = WSymbol::RIGHTARROW;
47   add(&rightArrow);
48 }
49
50 WOptionBox::~WOptionBox()
51 {
52   if (!options) return;
53
54   for(UINT i = 0; i < numOptions; i++) delete[] options[i];
55   free(options);
56 }
57
58 void WOptionBox::setSize(UINT w, UINT h)
59 {
60   Boxx::setSize(w, h);
61   textbox.setSize(w - 40, surface->getFontHeight());
62   rightArrow.setPosition(w - 18, 2);
63 }
64
65 void WOptionBox::setActive(UCHAR tactive)
66 {
67   active = tactive;
68   setData();
69 }
70
71 void WOptionBox::setData()
72 {
73   // set colours, set text
74
75   if (active)
76   {
77     textbox.setForegroundColour(Colour::DARKTEXT);
78     textbox.setBackgroundColour(Colour::SELECTHIGHLIGHT);
79     leftArrow.nextColour = Colour::SELECTHIGHLIGHT;
80     rightArrow.nextColour = Colour::SELECTHIGHLIGHT;
81   }
82   else
83   {
84     textbox.setForegroundColour(Colour::LIGHTTEXT);
85     textbox.setBackgroundColour(Colour::BUTTONBACKGROUND);
86     leftArrow.nextColour = Colour::BUTTONBACKGROUND;
87     rightArrow.nextColour = Colour::BUTTONBACKGROUND;
88   }
89   textbox.setText(options[currentOption]);
90
91 }
92
93 void WOptionBox::addOption(const char* takeText)
94 {
95   int length = strlen(takeText);
96   char* newOption = new char[length + 1];
97   strcpy(newOption, takeText);
98   options = (char**)realloc(options, (numOptions+1) * sizeof(char*));
99   options[numOptions] = newOption;
100   numOptions++;
101   setData();
102 }
103
104 void WOptionBox::left()
105 {
106   if (currentOption == 0) return;
107   --currentOption;
108   setData();
109 }
110
111 void WOptionBox::right()
112 {
113   if (currentOption == (numOptions - 1)) return;
114   ++currentOption;
115   setData();
116 }
117
118 void WOptionBox::cycle()
119 {
120   if (currentOption == (numOptions - 1))
121   {
122     currentOption = 0;
123   }
124   else
125   {
126     ++currentOption;
127   }
128   setData();
129 }
130
131 void WOptionBox::setSelected(const char* toSelect)
132 {
133   for(UINT i = 0; i < numOptions; i++)
134   {
135     if (!strcmp(toSelect, options[i]))
136     {
137       currentOption = i;
138       setData();
139       return;
140     }
141   }
142   currentOption = 0;
143   setData();
144 }
145
146 int WOptionBox::getSelectedIndex()
147 {
148   if (mode == MODE_TEXT)
149   {
150     return currentOption;
151   }
152   else
153   {
154     return atoi(options[currentOption]);
155   }
156 }
157
158 void WOptionBox::setIntMode(int startInt, int setNumOptions)
159 {
160   mode = MODE_INT;
161
162   int cInt;
163   char buffer[20];
164
165   for (cInt = startInt; cInt < (startInt + setNumOptions); cInt++)
166   {
167     sprintf(buffer, "%i", cInt);
168     addOption(buffer);
169   }
170 }
171
172 void WOptionBox::setSelected(int toSelect)
173 {
174   for(UINT i = 0; i < numOptions; i++)
175   {
176     if (atoi(options[i]) == toSelect)
177     {
178       currentOption = i;
179       setData();
180       return;
181     }
182   }
183   currentOption = 0;
184   setData();
185 }
186
187 bool WOptionBox::mouseMove(int x, int y)
188 {
189 /*
190   if ((x-offsetX)>=area.x && (y-offsetY)>=area.y
191     && (x-offsetX)<=area.w && (y-offsetY)<=area.h && !active)
192   {
193     setActive(1);
194     return true;
195   }
196   */
197   return false;
198 }
199
200 bool WOptionBox::mouseLBDOWN(int x, int y)
201 {
202 /*
203   if ((x-offsetX)>=area.x && (y-offsetY)>=area.y
204     && (x-offsetX)<=area.w && (y-offsetY)<=area.h && active)
205   {
206     return true;
207   }
208   */
209   return false;
210 }