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
23 VOptions::VOptions(View* tparent, const char* title, const OPTIONDATA* toptionData, const int tnumOptions)
25 viewman = ViewMan::getInstance();
28 optionData = toptionData;
29 numOptions = tnumOptions;
31 create(530, 85 + (numOptions * 30));
33 setBackgroundColour(Colour::VIEWBACKGROUND);
35 setTitleBarColour(Colour::TITLEBARBACKGROUND);
38 int fontHeight = surface->getFontHeight();
40 optionBoxes = new WOptionBox[numOptions];
44 vdr = VDR::getInstance();
45 // After setup, save all current indexes
46 optionsAtStart = new int[numOptions];
48 for (i = 0; i < numOptions; i++)
50 optionBoxes[i].setSurface(surface);
51 optionBoxes[i].setSurfaceOffset(346, 45 + (i * 30));
52 optionBoxes[i].setDimensions(150, fontHeight);
54 if (optionData[i].optionType == OPTIONTYPE_TEXT)
56 for (j = 0; j < optionData[i].optionCount; j++)
58 Log::getInstance()->log("Options", Log::DEBUG, "Add option: %s", optionData[i].options[j]);
59 optionBoxes[i].addOption(tr((char*)optionData[i].options[j]));
62 // Set the built in default
63 optionBoxes[i].setSelected(tr((char*)optionData[i].options[optionData[i].defaultOption]));
68 optionBoxes[i].setIntMode(optionData[i].startInt, optionData[i].optionCount);
69 optionBoxes[i].setSelected(optionData[i].defaultOption);
72 // Now see if there is a config option for it
73 config = vdr->configLoad(optionData[i].configSection, optionData[i].configParam);
76 if (optionData[i].optionType == OPTIONTYPE_TEXT)
78 for (j = 0; j < optionData[i].optionCount; j++)
80 if (!strcasecmp(config, optionData[i].options[j]))
82 optionBoxes[i].setSelected(tr((char*)optionData[i].options[j]));
88 optionBoxes[i].setSelected(atoi(config));
93 // After setup, save initial option
94 optionsAtStart[i] = optionBoxes[i].getSelectedIndex();
98 optionBoxes[0].setActive(1);
101 if ((numOptions < 8) && (numOptions >= 4))
103 voff = (8 - numOptions) * 10;
105 else if (numOptions < 4)
107 voff = 40; //(4 * 10)
110 if (Video::getInstance()->getFormat() == Video::PAL)
112 setScreenPos(104, 130 + voff);
116 setScreenPos(94, 70 + voff);
120 VOptions::~VOptions()
122 delete[] optionsAtStart;
123 delete[] optionBoxes;
126 void VOptions::draw()
133 drawText(tr("Press back to exit, <, > or [ok] to change"), 10, 55+numOptions*30, Colour::LIGHTTEXT);
135 wsy.setSurface(surface);
137 for (UINT i = 0; i < numOptions; i++)
139 drawText(tr(optionData[i].title), 10, 45+i*30, Colour::LIGHTTEXT);
141 if (i == selectedOption) cl = Colour::SELECTHIGHLIGHT;
142 else cl = Colour::BUTTONBACKGROUND;
144 wsy.nextSymbol = WSymbol::LEFTARROW;
147 wsy.setSurfaceOffset(328, 47 + (i * 30));
149 wsy.nextSymbol = WSymbol::RIGHTARROW;
150 wsy.setSurfaceOffset(498, 47 + (i * 30));
152 optionBoxes[i].draw();
156 int VOptions::handleCommand(int command)
163 if (selectedOption > 0)
165 optionBoxes[selectedOption].setActive(0);
167 optionBoxes[selectedOption].setActive(1);
169 viewman->updateView(this);
173 case Remote::DF_DOWN:
176 if (selectedOption < (numOptions - 1))
178 optionBoxes[selectedOption].setActive(0);
180 optionBoxes[selectedOption].setActive(1);
182 viewman->updateView(this);
186 case Remote::DF_LEFT:
189 optionBoxes[selectedOption].left();
191 viewman->updateView(this);
194 case Remote::DF_RIGHT:
197 optionBoxes[selectedOption].right();
199 viewman->updateView(this);
206 // Instead of returning 4 here which would delete this view
207 // before the doSave message is processed, let the message queue
208 // do the doSave then this close message. That will make the options menu
209 // disappear before this view
211 Message* m = new Message();
212 m->message = Message::CLOSE_ME;
215 viewman->postMessage(m);
221 optionBoxes[selectedOption].cycle();
223 viewman->updateView(this);
230 void VOptions::doSave()
233 int result[numOptions];
235 for (i = 0; i < numOptions; i++)
237 result[i] = optionBoxes[i].getSelectedIndex();
239 if (result[i] != optionsAtStart[i])
241 Log::getInstance()->log("Options", Log::DEBUG, "Option %i has changed", i);
243 if (optionData[i].optionType == OPTIONTYPE_TEXT)
245 vdr->configSave(optionData[i].configSection, optionData[i].configParam,
246 optionData[i].options[result[i]]);
251 sprintf(buffer, "%i", result[i]);
252 vdr->configSave(optionData[i].configSection, optionData[i].configParam,
258 // Save a vector of option IDs that have changed
260 map<int, int>* optionChanges = new map<int, int>;
262 for (i = 0; i < numOptions; i++)
264 if (result[i] != optionsAtStart[i])
266 (*optionChanges)[optionData[i].id] = result[i];
270 // Send it to parent for changes to be applied
271 Message* m = new Message();
272 m->message = Message::CHANGED_OPTIONS;
274 m->parameter = (ULONG)optionChanges;
275 viewman->postMessage(m);