2 Copyright 2004-2020 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, see <https://www.gnu.org/licenses/>.
26 #include "woptionbox.h"
28 WOptionBox::WOptionBox()
36 textbox.setPosition(20, 0);
37 textbox.setSize(10, getFontHeight());
38 textbox.setParaMode(false);
39 textbox.setTextPos(0, 0);
42 leftArrow.setPosition(0, 2);
43 leftArrow.nextSymbol = WSymbol::LEFTARROW;
46 rightArrow.setPosition(0, 2);
47 rightArrow.nextSymbol = WSymbol::RIGHTARROW;
51 WOptionBox::~WOptionBox()
55 for(UINT i = 0; i < numOptions; i++) delete[] options[i];
59 void WOptionBox::setSize(UINT w, UINT h)
62 textbox.setSize(w - 40, getFontHeight());
63 rightArrow.setPosition(w - 18, 2);
66 void WOptionBox::setActive(UCHAR tactive)
72 void WOptionBox::setData()
74 // set colours, set text
78 textbox.setForegroundColour(DrawStyle::DARKTEXT);
79 textbox.setBackgroundColour(DrawStyle::SELECTHIGHLIGHT);
80 leftArrow.nextColour = DrawStyle::SELECTHIGHLIGHT;
81 rightArrow.nextColour = DrawStyle::SELECTHIGHLIGHT;
85 textbox.setForegroundColour(DrawStyle::LIGHTTEXT);
86 textbox.setBackgroundColour(DrawStyle::BUTTONBACKGROUND);
87 leftArrow.nextColour = DrawStyle::BUTTONBACKGROUND;
88 rightArrow.nextColour = DrawStyle::BUTTONBACKGROUND;
90 textbox.setText(options[currentOption]);
94 void WOptionBox::addOption(const char* takeText)
96 int length = strlen(takeText);
97 char* newOption = new char[length + 1];
98 strcpy(newOption, takeText);
99 options = static_cast<char**>(realloc(options, (numOptions+1) * sizeof(char*)));
100 options[numOptions] = newOption;
105 void WOptionBox::left()
107 if (currentOption == 0) return;
112 void WOptionBox::right()
114 if (currentOption == (numOptions - 1)) return;
119 void WOptionBox::cycle()
121 if (currentOption == (numOptions - 1))
132 void WOptionBox::setSelected(const char* toSelect)
134 for(UINT i = 0; i < numOptions; i++)
136 if (!strcmp(toSelect, options[i]))
147 int WOptionBox::getSelectedIndex()
149 if (mode == MODE_TEXT)
151 return currentOption;
155 return atoi(options[currentOption]);
159 void WOptionBox::setIntMode(int startInt, int setNumOptions)
166 for (cInt = startInt; cInt < (startInt + setNumOptions); cInt++)
168 sprintf(buffer, "%i", cInt);
173 void WOptionBox::setSelected(int toSelect)
175 for(UINT i = 0; i < numOptions; i++)
177 if (atoi(options[i]) == toSelect)
188 bool WOptionBox::mouseMove(int x, int y)
190 if ( (x - getRootBoxOffsetX()) >= 0
191 && (y - getRootBoxOffsetY()) >= 0
192 && (x - getRootBoxOffsetX()) <= static_cast<int>(area.w)
193 && (y - getRootBoxOffsetY()) <= static_cast<int>(area.h)
204 bool WOptionBox::mouseLBDOWN(int x, int y)
206 if ( (x - getRootBoxOffsetX()) >= 0
207 && (y - getRootBoxOffsetY()) >= 0
208 && (x - getRootBoxOffsetX()) <= static_cast<int>(area.w)
209 && (y - getRootBoxOffsetY()) <= static_cast<int>(area.h)