]> git.vomp.tv Git - vompclient.git/blob - voptions.cc
New widescreen mode
[vompclient.git] / voptions.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
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.
10
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.
15
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
19 */
20
21 #include "voptions.h"
22
23 VOptions::VOptions()
24 {
25   create(500, 250);
26   if (Video::getInstance()->getFormat() == Video::PAL)
27   {
28     setScreenPos(120, 140);
29   }
30   else
31   {
32     setScreenPos(110, 110);
33   }
34
35   setBackgroundColour(Colour::VIEWBACKGROUND);
36   setTitleBarOn(1);
37   setTitleBarColour(Colour::TITLEBARBACKGROUND);
38   setTitleText("Options");
39
40   int fontHeight = surface->getFontHeight();
41
42   optionBox[0].setSurface(surface);
43   optionBox[0].setSurfaceOffset(330, 45);
44   optionBox[0].setDimensions(150, fontHeight);
45   optionBox[0].addOption("Old");
46   optionBox[0].addOption("New");
47
48   optionBox[1].setSurface(surface);
49   optionBox[1].setSurfaceOffset(330, 75);
50   optionBox[1].setDimensions(150, fontHeight);
51   optionBox[1].addOption("RGB+composite");
52   optionBox[1].addOption("S-Video");
53
54   optionBox[2].setSurface(surface);
55   optionBox[2].setSurfaceOffset(330, 105);
56   optionBox[2].setDimensions(150, fontHeight);
57   optionBox[2].addOption("4:3");
58   optionBox[2].addOption("16:9");
59
60   optionBox[3].setSurface(surface);
61   optionBox[3].setSurfaceOffset(330, 135);
62   optionBox[3].setDimensions(150, fontHeight);
63   optionBox[3].addOption("Chop sides");
64   optionBox[3].addOption("Letterbox");
65
66   optionBox[4].setSurface(surface);
67   optionBox[4].setSurfaceOffset(330, 165);
68   optionBox[4].setDimensions(150, fontHeight);
69   optionBox[4].addOption("On");
70   optionBox[4].addOption("Off");
71   optionBox[4].addOption("Last state");
72
73   optionBox[5].setSurface(surface);
74   optionBox[5].setSurfaceOffset(330, 195);
75   optionBox[5].setDimensions(150, fontHeight);
76   optionBox[5].addOption("All");
77   optionBox[5].addOption("FTA only");
78
79   char* config;
80   vdr = VDR::getInstance();
81
82
83   config = vdr->configLoad("General", "Remote type");
84   if (!config || strcasecmp(config, "New"))
85     optionBox[0].setSelected("Old");
86   else
87     optionBox[0].setSelected("New");
88   if (config) delete[] config;
89
90   config = vdr->configLoad("TV", "S-Video");
91   if (!config || strcasecmp(config, "Yes"))
92     optionBox[1].setSelected("RGB+composite");
93   else
94     optionBox[1].setSelected("S-Video");
95   if (config) delete[] config;
96
97   config = vdr->configLoad("TV", "Aspect");
98   if (!config || strcasecmp(config, "16:9"))
99     optionBox[2].setSelected("4:3");
100   else
101     optionBox[2].setSelected("16:9");
102   if (config) delete[] config;
103
104   config = vdr->configLoad("TV", "Widemode");
105   if (!config || strcasecmp(config, "Letterbox"))
106     optionBox[3].setSelected("Chop sides");
107   else
108     optionBox[3].setSelected("Letterbox");
109   if (config) delete[] config;
110
111   config = vdr->configLoad("General", "Power After Boot");
112   if (!config)
113     optionBox[4].setSelected("On");
114   else if (!strcasecmp(config, "Off"))
115     optionBox[4].setSelected("Off");
116   else if (!strcasecmp(config, "Last state"))
117     optionBox[4].setSelected("Last state");
118   else
119     optionBox[4].setSelected("On");
120   if (config) delete[] config;
121
122   config = vdr->configLoad("General", "Channels");
123   if (!config || strcasecmp(config, "FTA only"))
124     optionBox[5].setSelected("All");
125   else
126     optionBox[5].setSelected("FTA only");
127   if (config) delete[] config;
128
129   selectedOption = 0;
130   optionBox[0].setActive(1);
131 }
132
133 VOptions::~VOptions()
134 {
135 }
136
137 void VOptions::draw()
138 {
139   View::draw();
140
141   WSymbol wsy;
142   Colour cl;
143
144   drawText("Remote control type", 10, 45, Colour::LIGHTTEXT);
145   drawText("TV connection type", 10, 75, Colour::LIGHTTEXT);
146   drawText("TV aspect ratio", 10, 105, Colour::LIGHTTEXT);
147   drawText("16:9 on 4:3 display mode", 10, 135, Colour::LIGHTTEXT);
148   drawText("Power state after bootup", 10, 165, Colour::LIGHTTEXT);
149   drawText("Display channels", 10, 195, Colour::LIGHTTEXT);
150
151   drawText("Press back to exit, <, > or [ok] to change", 10, 220, Colour::LIGHTTEXT);
152
153   wsy.setSurface(surface);
154
155   for (UINT i = 0; i < numOptions; i++)
156   {
157     if (i == selectedOption) cl = Colour::SELECTHIGHLIGHT;
158     else cl = Colour::BUTTONBACKGROUND;
159
160     wsy.nextSymbol = WSymbol::LEFTARROW;
161     wsy.nextColour = cl;
162
163     wsy.setSurfaceOffset(312, 47 + (i * 30));
164     wsy.draw();
165     wsy.nextSymbol = WSymbol::RIGHTARROW;
166     wsy.setSurfaceOffset(482, 47 + (i * 30));
167     wsy.draw();
168     optionBox[i].draw();
169     optionBox[i].show();
170   }
171
172 }
173
174 int VOptions::handleCommand(int command)
175 {
176   switch(command)
177   {
178     case Remote::DF_UP:
179     case Remote::UP:
180     {
181       if (selectedOption > 0)
182       {
183         optionBox[selectedOption].setActive(0);
184         --selectedOption;
185         optionBox[selectedOption].setActive(1);
186         draw();
187         show();
188       }
189       return 2;
190     }
191     case Remote::DF_DOWN:
192     case Remote::DOWN:
193     {
194       if (selectedOption < (numOptions - 1))
195       {
196         optionBox[selectedOption].setActive(0);
197         ++selectedOption;
198         optionBox[selectedOption].setActive(1);
199         draw();
200         show();
201       }
202       return 2;
203     }
204     case Remote::DF_LEFT:
205     case Remote::LEFT:
206     {
207       optionBox[selectedOption].left();
208       draw();
209       show();
210       return 2;
211     }
212     case Remote::DF_RIGHT:
213     case Remote::RIGHT:
214     {
215       optionBox[selectedOption].right();
216       draw();
217       show();
218       return 2;
219     }
220     case Remote::BACK:
221     {
222       doSave();
223       return 4;
224     }
225     case Remote::OK:
226     {
227       optionBox[selectedOption].cycle();
228       draw();
229       show();
230     }
231   }
232
233   return 1;
234 }
235
236 void VOptions::doSave()
237 {
238   char* remoteType = optionBox[0].getSelected();
239   vdr->configSave("General", "Remote type", remoteType);
240
241   char* tvconnection = optionBox[1].getSelected();
242   if (!strcmp(tvconnection, "S-Video"))
243     vdr->configSave("TV", "S-Video", "Yes");
244   else
245     vdr->configSave("TV", "S-Video", "No");
246
247   char* aspect = optionBox[2].getSelected();
248   vdr->configSave("TV", "Aspect", aspect);
249
250   char* widemode = optionBox[3].getSelected();
251   vdr->configSave("TV", "Widemode", widemode);
252
253   char* powerState = optionBox[4].getSelected();
254   vdr->configSave("General", "Power After Boot", powerState);
255
256   char* channels = optionBox[5].getSelected();
257   vdr->configSave("General", "Channels", channels);
258
259   // Apply changes
260
261   if (!strcmp(remoteType, "New"))
262     Remote::getInstance()->setRemoteType(Remote::NEWREMOTE);
263   else
264     Remote::getInstance()->setRemoteType(Remote::OLDREMOTE);
265
266   Video* video = Video::getInstance();
267
268   if (!strcmp(tvconnection, "S-Video"))
269     video->setConnection(Video::SVIDEO);
270   else
271     video->setConnection(Video::COMPOSITERGB);
272
273   if (!strcmp(aspect, "16:9"))
274   {
275     Log::getInstance()->log("Options", Log::DEBUG, "Setting widescreen");
276     video->setTVsize(Video::ASPECT16X9);
277   }
278   else
279   {
280     Log::getInstance()->log("Options", Log::DEBUG, "Setting 4:3 screen");
281     video->setTVsize(Video::ASPECT4X3);
282   }
283
284   if (!strcmp(widemode, "Letterbox"))
285   {
286     Log::getInstance()->log("Options", Log::DEBUG, "Setting letterbox");
287     video->setMode(Video::LETTERBOX);
288   }
289   else
290   {
291     Log::getInstance()->log("Options", Log::DEBUG, "Setting chop-sides");
292     video->setMode(Video::NORMAL);
293   }
294 }