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(void* tparent, const char* title, const OPTIONDATA* toptionData, const int tnumOptions)
25 viewman = ViewMan::getInstance();
28 optionData = toptionData;
29 numOptions = tnumOptions;
32 if (numOptions < 4) newHeight += (4 * 30);
33 else newHeight += (numOptions * 30);
35 create(530, newHeight);
37 setBackgroundColour(Colour::VIEWBACKGROUND);
39 setTitleBarColour(Colour::TITLEBARBACKGROUND);
42 int fontHeight = surface->getFontHeight();
44 optionBoxes = new WOptionBox[numOptions];
48 vdr = VDR::getInstance();
49 // After setup, save all current indexes
50 optionsAtStart = new int[numOptions];
52 for (i = 0; i < numOptions; i++)
54 optionBoxes[i].setSurface(surface);
55 optionBoxes[i].setSurfaceOffset(346, 45 + (i * 30));
56 optionBoxes[i].setDimensions(150, fontHeight);
58 if (optionData[i].optionType == OPTIONTYPE_TEXT)
60 for (j = 0; j < optionData[i].optionCount; j++)
62 Log::getInstance()->log("Options", Log::DEBUG, "Add option: %s", optionData[i].options[j]);
63 optionBoxes[i].addOption(tr((char*)optionData[i].options[j]));
66 // Set the built in default
67 optionBoxes[i].setSelected(tr((char*)optionData[i].options[optionData[i].defaultOption]));
72 optionBoxes[i].setIntMode(optionData[i].startInt, optionData[i].optionCount);
73 optionBoxes[i].setSelected(optionData[i].defaultOption);
76 // Now see if there is a config option for it
77 config = vdr->configLoad(optionData[i].configSection, optionData[i].configParam);
80 if (optionData[i].optionType == OPTIONTYPE_TEXT)
82 for (j = 0; j < optionData[i].optionCount; j++)
84 if (!STRCASECMP(config, optionData[i].options[j]))
86 optionBoxes[i].setSelected(tr((char*)optionData[i].options[j]));
92 optionBoxes[i].setSelected(atoi(config));
97 // After setup, save initial option
98 optionsAtStart[i] = optionBoxes[i].getSelectedIndex();
101 selectedOption = numOptions;
102 //optionBoxes[0].setActive(1);
105 if ((numOptions < 8) && (numOptions >= 4))
107 voff = (8 - numOptions) * 10;
109 else if (numOptions < 4)
111 voff = 40; //(4 * 10)
114 if (Video::getInstance()->getFormat() == Video::PAL)
116 setScreenPos(104, 130 + voff);
120 setScreenPos(94, 70 + voff);
123 if (!vdr->isConnected()) Command::getInstance()->connectionLost();
126 VOptions::~VOptions()
128 delete[] optionsAtStart;
129 delete[] optionBoxes;
132 void VOptions::draw()
139 drawText(tr("Press back to exit, <, > or [ok] to change"), 10, area.h - 30, Colour::LIGHTTEXT);
141 wsy.setSurface(surface);
142 UINT ystart=titleBarOn ? 45 : 15;
144 for (UINT i = 0; i < numOptions; i++)
146 drawText(tr(optionData[i].title), 10, ystart + i*30, Colour::LIGHTTEXT);
148 if (i == selectedOption) cl = Colour::SELECTHIGHLIGHT;
149 else cl = Colour::BUTTONBACKGROUND;
151 wsy.nextSymbol = WSymbol::LEFTARROW;
154 wsy.setSurfaceOffset(328, ystart + 2 + (i * 30));
156 wsy.nextSymbol = WSymbol::RIGHTARROW;
157 wsy.setSurfaceOffset(498, ystart + 2 + (i * 30));
159 optionBoxes[i].setSurfaceOffset(346, ystart + (i * 30));
160 optionBoxes[i].draw();
164 int VOptions::handleCommand(int command)
171 if (selectedOption > 0)
173 if (selectedOption < numOptions) optionBoxes[selectedOption].setActive(0);
175 optionBoxes[selectedOption].setActive(1);
177 viewman->updateView(this);
181 if (selectedOption < numOptions) optionBoxes[selectedOption].setActive(0);
182 selectedOption = numOptions;
183 return 0; //Control to tab view
187 case Remote::DF_DOWN:
190 if (selectedOption < (numOptions - 1))
192 if (selectedOption < numOptions) optionBoxes[selectedOption].setActive(0);
194 optionBoxes[selectedOption].setActive(1);
196 viewman->updateView(this);
198 else if (selectedOption == numOptions)
201 optionBoxes[selectedOption].setActive(1);
203 viewman->updateView(this);
207 case Remote::DF_LEFT:
210 if (selectedOption == numOptions) return 2;
211 optionBoxes[selectedOption].left();
213 viewman->updateView(this);
216 case Remote::DF_RIGHT:
219 if (selectedOption == numOptions) return 2;
220 optionBoxes[selectedOption].right();
222 viewman->updateView(this);
229 // Instead of returning 4 here which would delete this view
230 // before the doSave message is processed, let the message queue
231 // do the doSave then this close message. That will make the options menu
232 // disappear before this view
234 Message* m = new Message();
235 m->message = Message::CLOSE_ME;
238 Command::getInstance()->postMessageNoLock(m);
244 if (selectedOption == numOptions) return 2;
245 optionBoxes[selectedOption].cycle();
247 viewman->updateView(this);
254 void VOptions::doSave()
257 int* result = new int[numOptions];
259 for (i = 0; i < numOptions; i++)
261 result[i] = optionBoxes[i].getSelectedIndex();
263 if (result[i] != optionsAtStart[i])
265 Log::getInstance()->log("Options", Log::DEBUG, "Option %i has changed", i);
267 if (optionData[i].optionType == OPTIONTYPE_TEXT)
269 vdr->configSave(optionData[i].configSection, optionData[i].configParam,
270 optionData[i].options[result[i]]);
275 sprintf(buffer, "%i", result[i]);
276 vdr->configSave(optionData[i].configSection, optionData[i].configParam,
282 // Save a vector of option IDs that have changed
284 map<int, int>* optionChanges = new map<int, int>;
286 for (i = 0; i < numOptions; i++)
288 if (result[i] != optionsAtStart[i])
290 (*optionChanges)[optionData[i].id] = result[i];
296 // Send it to parent for changes to be applied
297 Message* m = new Message();
298 m->message = Message::CHANGED_OPTIONS;
300 m->parameter = (ULONG)optionChanges;
301 Command::getInstance()->postMessageNoLock(m);
304 void VOptions::processMessage(Message* m)
306 if (m->message == Message::MOUSE_MOVE)
308 int x=(m->parameter>>16)-getScreenX();
309 int y=(m->parameter&0xFFFF)-getScreenY();
311 for (i = 0; i < numOptions; i++)
313 if (optionBoxes[i].mouseMove(x,y))
315 if (selectedOption != numOptions) optionBoxes[selectedOption].setActive(0);
316 optionBoxes[i].setActive(1);
319 viewman->updateView(this);
324 else if (m->message == Message::MOUSE_LBDOWN)
326 int x=(m->parameter>>16)-getScreenX();
327 int y=(m->parameter&0xFFFF)-getScreenY();
330 for (i = 0; i < numOptions; i++)
332 if (optionBoxes[i].mouseLBDOWN(x,y))
334 ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
341 //check if press is outside this view! then simulate cancel
342 if (x<0 || y <0 || x>getWidth() || y>getHeight())
344 ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press