2 Copyright 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "woptionpane.h"
24 #include "woptionbox.h"
30 WOptionPane::WOptionPane()
36 WOptionPane::~WOptionPane()
38 for(int i = 0; i < numOptions; i++)
41 delete optionBoxes[i];
45 void WOptionPane::draw()
48 drawText(tr("Press back to exit, <, > or [ok] to change"), 10, area.h - 30, DrawStyle::LIGHTTEXT);
51 void WOptionPane::saveOpts()
53 // Due to the way the pane is constructed, options[0] corresponds to textBoxes[0] and optionBoxes[0] etc
55 for(int i = 0; i < numOptions; i++)
57 options[i]->userSetChoice = optionBoxes[i]->getSelectedIndex();
61 void WOptionPane::addOptionLine(Option* option)
63 int fontHeight = getFontHeight();
66 options.resize(numOptions+1);
67 options[numOptions] = option;
69 WTextbox* tb = new WTextbox();
70 tb->setPosition(4, 4 + (numOptions * 30));
71 tb->setSize(300, fontHeight + 6);
72 tb->setText(tr(option->displayText));
76 textBoxes.resize(numOptions+1);
77 textBoxes[numOptions] = tb;
79 WOptionBox* ob = new WOptionBox();
80 ob->setPosition(310, 4 + (numOptions * 30));
81 ob->setSize(190, fontHeight);
84 optionBoxes.resize(numOptions+1);
85 optionBoxes[numOptions] = ob;
87 if (option->optionType == Option::TYPE_TEXT ||
88 option->optionType == Option::TYPE_KEYED_TEXT)
90 for (UINT j = 0; j < option->numChoices; j++)
92 Log::getInstance()->log("Options", Log::DEBUG, "Add option: %s", option->options[j]);
93 ob->addOption(tr(option->options[j]));
96 // Set the selected choice
97 ob->setSelected(tr(option->options[option->configChoice]));
102 ob->setIntMode(option->startInt, option->numChoices);
103 ob->setSelected(option->configChoice);
110 void WOptionPane::deactivateAllControls()
112 if (selectedOption >= 0) {
113 optionBoxes[selectedOption]->setActive(0);
119 int WOptionPane::handleCommand(int command)
126 if (selectedOption > 0)
128 optionBoxes[selectedOption]->setActive(0);
130 optionBoxes[selectedOption]->setActive(1);
133 else if (selectedOption == 0)
135 optionBoxes[selectedOption--]->setActive(0);
136 return 4; // Signal return control to parent
138 else if (selectedOption == -1) // Allow UP when inactive, start at the last optionBox
140 selectedOption = numOptions - 1;
141 optionBoxes[selectedOption]->setActive(1);
145 case Remote::DF_DOWN:
148 if (selectedOption < (numOptions - 1))
150 if (selectedOption != -1) optionBoxes[selectedOption]->setActive(0);
152 optionBoxes[selectedOption]->setActive(1);
155 else if (selectedOption == (numOptions - 1))
157 optionBoxes[selectedOption]->setActive(0);
159 return 4; // Signal return control to parent
162 case Remote::DF_LEFT:
165 optionBoxes[selectedOption]->left();
168 case Remote::DF_RIGHT:
171 optionBoxes[selectedOption]->right();
176 optionBoxes[selectedOption]->cycle();
184 bool WOptionPane::mouseMove(int x, int y)
187 for (i=0;i<optionBoxes.size();i++) {
188 if (optionBoxes[i]->mouseMove(x,y)) {
189 if ( selectedOption!=(int)i) {
190 if (selectedOption != -1 ) optionBoxes[selectedOption]->setActive(0);
202 bool WOptionPane::mouseLBDOWN(int x, int y)
205 for (i=0;i<optionBoxes.size();i++) {
206 if (optionBoxes[i]->mouseLBDOWN(x,y)) {
207 if ( selectedOption==(int)i) {
208 optionBoxes[selectedOption]->cycle();