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/>.
25 #include "woptionbox.h"
27 WOptionBox::WOptionBox()
35 textbox.setPosition(20, 0);
36 textbox.setSize(10, 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, 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(DrawStyle::DARKTEXT);
78 textbox.setBackgroundColour(DrawStyle::SELECTHIGHLIGHT);
79 leftArrow.nextColour = DrawStyle::SELECTHIGHLIGHT;
80 rightArrow.nextColour = DrawStyle::SELECTHIGHLIGHT;
84 textbox.setForegroundColour(DrawStyle::LIGHTTEXT);
85 textbox.setBackgroundColour(DrawStyle::BUTTONBACKGROUND);
86 leftArrow.nextColour = DrawStyle::BUTTONBACKGROUND;
87 rightArrow.nextColour = DrawStyle::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 = static_cast<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)
189 if ( (x - getRootBoxOffsetX()) >= 0
190 && (y - getRootBoxOffsetY()) >= 0
191 && (x - getRootBoxOffsetX()) <= static_cast<int>(area.w)
192 && (y - getRootBoxOffsetY()) <= static_cast<int>(area.h)
203 bool WOptionBox::mouseLBDOWN(int x, int y)
205 if ( (x - getRootBoxOffsetX()) >= 0
206 && (y - getRootBoxOffsetY()) >= 0
207 && (x - getRootBoxOffsetX()) <= static_cast<int>(area.w)
208 && (y - getRootBoxOffsetY()) <= static_cast<int>(area.h)