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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "woptionbox.h"
26 WOptionBox::WOptionBox()
35 textbox.setPosition(20, 0);
36 textbox.setSize(10, surface->getFontHeight());
37 textbox.setParaMode(false);
38 textbox.setTextPos(0, 0);
41 leftArrow.setPosition(0, 2);
42 leftArrow.nextSymbol = WSymbol::LEFTARROW;
45 rightArrow.setPosition(0, 2);
46 rightArrow.nextSymbol = WSymbol::RIGHTARROW;
50 WOptionBox::~WOptionBox()
54 for(UINT i = 0; i < numOptions; i++) delete[] options[i];
58 void WOptionBox::setSize(UINT w, UINT h)
61 textbox.setSize(w - 40, surface->getFontHeight());
62 rightArrow.setPosition(w - 18, 2);
65 void WOptionBox::setActive(UCHAR tactive)
71 void WOptionBox::setData()
73 // set colours, set text
77 textbox.setForegroundColour(Colour::DARKTEXT);
78 textbox.setBackgroundColour(Colour::SELECTHIGHLIGHT);
79 leftArrow.nextColour = Colour::SELECTHIGHLIGHT;
80 rightArrow.nextColour = Colour::SELECTHIGHLIGHT;
84 textbox.setForegroundColour(Colour::LIGHTTEXT);
85 textbox.setBackgroundColour(Colour::BUTTONBACKGROUND);
86 leftArrow.nextColour = Colour::BUTTONBACKGROUND;
87 rightArrow.nextColour = Colour::BUTTONBACKGROUND;
89 textbox.setText(options[currentOption]);
93 void WOptionBox::addOption(const char* takeText)
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;
104 void WOptionBox::left()
106 if (currentOption == 0) return;
111 void WOptionBox::right()
113 if (currentOption == (numOptions - 1)) return;
118 void WOptionBox::cycle()
120 if (currentOption == (numOptions - 1))
131 void WOptionBox::setSelected(const char* toSelect)
133 for(UINT i = 0; i < numOptions; i++)
135 if (!strcmp(toSelect, options[i]))
146 int WOptionBox::getSelectedIndex()
148 if (mode == MODE_TEXT)
150 return currentOption;
154 return atoi(options[currentOption]);
158 void WOptionBox::setIntMode(int startInt, int setNumOptions)
165 for (cInt = startInt; cInt < (startInt + setNumOptions); cInt++)
167 sprintf(buffer, "%i", cInt);
172 void WOptionBox::setSelected(int toSelect)
174 for(UINT i = 0; i < numOptions; i++)
176 if (atoi(options[i]) == toSelect)
187 bool WOptionBox::mouseMove(int x, int y)
190 if ((x-offsetX)>=area.x && (y-offsetY)>=area.y
191 && (x-offsetX)<=area.w && (y-offsetY)<=area.h && !active)
200 bool WOptionBox::mouseLBDOWN(int x, int y)
203 if ((x-offsetX)>=area.x && (y-offsetY)>=area.y
204 && (x-offsetX)<=area.w && (y-offsetY)<=area.h && active)