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"
28 WOptionBox::WOptionBox()
37 textbox.setPosition(20, 0);
38 textbox.setSize(10, surface->getFontHeight());
39 textbox.setParaMode(false);
40 textbox.setTextPos(0, 0);
43 leftArrow.setPosition(0, 2);
44 leftArrow.nextSymbol = WSymbol::LEFTARROW;
47 rightArrow.setPosition(0, 2);
48 rightArrow.nextSymbol = WSymbol::RIGHTARROW;
52 WOptionBox::~WOptionBox()
56 for(UINT i = 0; i < numOptions; i++) delete[] options[i];
60 void WOptionBox::setSize(UINT w, UINT h)
63 textbox.setSize(w - 40, surface->getFontHeight());
64 rightArrow.setPosition(w - 18, 2);
67 void WOptionBox::setActive(UCHAR tactive)
73 void WOptionBox::setData()
75 // set colours, set text
79 textbox.setForegroundColour(Colour::DARKTEXT);
80 textbox.setBackgroundColour(Colour::SELECTHIGHLIGHT);
81 leftArrow.nextColour = Colour::SELECTHIGHLIGHT;
82 rightArrow.nextColour = Colour::SELECTHIGHLIGHT;
86 textbox.setForegroundColour(Colour::LIGHTTEXT);
87 textbox.setBackgroundColour(Colour::BUTTONBACKGROUND);
88 leftArrow.nextColour = Colour::BUTTONBACKGROUND;
89 rightArrow.nextColour = Colour::BUTTONBACKGROUND;
91 textbox.setText(options[currentOption]);
95 void WOptionBox::addOption(const char* takeText)
97 int length = strlen(takeText);
98 char* newOption = new char[length + 1];
99 strcpy(newOption, takeText);
100 options = (char**)realloc(options, (numOptions+1) * sizeof(char*));
101 options[numOptions] = newOption;
106 void WOptionBox::left()
108 if (currentOption == 0) return;
113 void WOptionBox::right()
115 if (currentOption == (numOptions - 1)) return;
120 void WOptionBox::cycle()
122 if (currentOption == (numOptions - 1))
133 void WOptionBox::setSelected(const char* toSelect)
135 for(UINT i = 0; i < numOptions; i++)
137 if (!strcmp(toSelect, options[i]))
148 int WOptionBox::getSelectedIndex()
150 if (mode == MODE_TEXT)
152 return currentOption;
156 return atoi(options[currentOption]);
160 void WOptionBox::setIntMode(int startInt, int setNumOptions)
167 for (cInt = startInt; cInt < (startInt + setNumOptions); cInt++)
169 sprintf(buffer, "%i", cInt);
174 void WOptionBox::setSelected(int toSelect)
176 for(UINT i = 0; i < numOptions; i++)
178 if (atoi(options[i]) == toSelect)
189 bool WOptionBox::mouseMove(int x, int y)
192 if ((x-getRootBoxOffsetX())>=0 && (y-getRootBoxOffsetY())>=0
193 && (x-getRootBoxOffsetX())<=(int)area.w && (y-getRootBoxOffsetY())<=(int)area.h && !active)
202 bool WOptionBox::mouseLBDOWN(int x, int y)
205 if ((x-getRootBoxOffsetX())>=0 && (y-getRootBoxOffsetY())>=0
206 && (x-getRootBoxOffsetX())<=(int)area.w && (y-getRootBoxOffsetY())<=(int)area.h && active)