2 Copyright 2007-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/>.
22 #include "woptionbox.h"
27 #include "woptionpane.h"
29 WOptionPane::WOptionPane()
35 WOptionPane::~WOptionPane()
37 for(int i = 0; i < numOptions; i++)
40 delete optionBoxes[i];
44 void WOptionPane::draw()
47 drawText(tr("Press back to exit, <, > or [ok] to change"), 10, area.h - 30, DrawStyle::LIGHTTEXT);
50 void WOptionPane::saveOpts()
52 // Due to the way the pane is constructed, options[0] corresponds to textBoxes[0] and optionBoxes[0] etc
54 for(int i = 0; i < numOptions; i++)
56 options[i]->userSetChoice = optionBoxes[i]->getSelectedIndex();
60 void WOptionPane::addOptionLine(Option* option)
62 int fontHeight = getFontHeight();
64 options.resize(numOptions + 1);
65 options[numOptions] = option;
67 WTextbox* tb = new WTextbox();
68 tb->setPosition(4, 4 + (numOptions * 30));
69 tb->setSize(300, fontHeight + 6);
70 tb->setText(tr(option->displayText));
74 textBoxes.resize(numOptions + 1);
75 textBoxes[numOptions] = tb;
77 WOptionBox* ob = new WOptionBox();
78 ob->setPosition(310, 4 + (numOptions * 30));
79 ob->setSize(190, fontHeight);
82 optionBoxes.resize(numOptions + 1);
83 optionBoxes[numOptions] = ob;
85 if (option->optionType == Option::TYPE_TEXT ||
86 option->optionType == Option::TYPE_KEYED_TEXT)
88 for (UINT j = 0; j < option->numChoices; j++)
90 Log::getInstance()->log("Options", Log::DEBUG, "Add option: %s", option->options[j]);
91 ob->addOption(tr(option->options[j]));
94 // Set the selected choice
95 ob->setSelected(tr(option->options[option->configChoice]));
100 ob->setIntMode(option->startInt, option->numChoices);
101 ob->setSelected(option->configChoice);
107 void WOptionPane::deactivateAllControls()
109 if (selectedOption >= 0)
111 optionBoxes[selectedOption]->setActive(0);
116 int WOptionPane::handleCommand(int command)
122 if (selectedOption > 0)
124 optionBoxes[selectedOption]->setActive(0);
126 optionBoxes[selectedOption]->setActive(1);
129 else if (selectedOption == 0)
131 optionBoxes[selectedOption--]->setActive(0);
132 return 4; // Signal return control to parent
134 else if (selectedOption == -1) // Allow UP when inactive, start at the last optionBox
136 selectedOption = numOptions - 1;
137 optionBoxes[selectedOption]->setActive(1);
140 FALLTHROUGH // it doesn't really
144 if (selectedOption < (numOptions - 1))
146 if (selectedOption != -1) optionBoxes[selectedOption]->setActive(0);
148 optionBoxes[selectedOption]->setActive(1);
151 else if (selectedOption == (numOptions - 1))
153 optionBoxes[selectedOption]->setActive(0);
155 return 4; // Signal return control to parent
157 FALLTHROUGH // it doesn't really
161 optionBoxes[selectedOption]->left();
166 optionBoxes[selectedOption]->right();
171 optionBoxes[selectedOption]->cycle();
179 bool WOptionPane::mouseMove(int x, int y)
181 for (int i = 0; i < static_cast<int>(optionBoxes.size()); i++)
183 if (optionBoxes[i]->mouseMove(x, y))
185 if (selectedOption != i)
187 if (selectedOption != -1) optionBoxes[selectedOption]->setActive(0);
200 bool WOptionPane::mouseLBDOWN(int x, int y)
202 for (int i = 0; i < static_cast<int>(optionBoxes.size()); i++)
204 if (optionBoxes[i]->mouseLBDOWN(x, y))
206 if (selectedOption == i)
208 optionBoxes[selectedOption]->cycle();