]> git.vomp.tv Git - vompclient.git/blob - woptionpane.cc
Fix text corruption in channel number display on live tv
[vompclient.git] / woptionpane.cc
1 /*
2     Copyright 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "woptionpane.h"
22 #include "wtextbox.h"
23 #include "i18n.h"
24 #include "woptionbox.h"
25 #include "log.h"
26 #include "vdr.h"
27 #include "remote.h"
28 #include "option.h"
29
30 WOptionPane::WOptionPane()
31 {
32   numOptions = 0;
33   selectedOption = -1;
34 }
35
36 WOptionPane::~WOptionPane()
37 {
38   for(int i = 0; i < numOptions; i++)
39   {
40     delete textBoxes[i];
41     delete optionBoxes[i];
42   }
43 }
44
45 void WOptionPane::draw()
46 {
47   Boxx::draw();
48   drawText(tr("Press back to exit, <, > or [ok] to change"), 10, area.h - 30, DrawStyle::LIGHTTEXT);
49 }
50
51 void WOptionPane::saveOpts()
52 {
53   // Due to the way the pane is constructed, options[0] corresponds to textBoxes[0] and optionBoxes[0] etc
54   
55   for(int i = 0; i < numOptions; i++)
56   {
57     options[i]->userSetChoice = optionBoxes[i]->getSelectedIndex();
58   }
59 }
60
61 void WOptionPane::addOptionLine(Option* option)
62 {
63   int fontHeight = getFontHeight();
64
65
66   options.resize(numOptions+1);
67   options[numOptions] = option;
68
69   WTextbox* tb = new WTextbox();
70   tb->setPosition(4, 4 + (numOptions * 30));
71   tb->setSize(300, fontHeight + 6);
72   tb->setText(tr(option->displayText));
73   tb->setTextPos(0, 0);
74   add(tb);
75
76   textBoxes.resize(numOptions+1);
77   textBoxes[numOptions] = tb;
78
79   WOptionBox* ob = new WOptionBox();
80   ob->setPosition(310, 4 + (numOptions * 30));
81   ob->setSize(190, fontHeight);  
82   add(ob);
83
84   optionBoxes.resize(numOptions+1);
85   optionBoxes[numOptions] = ob;
86
87   if (option->optionType == Option::TYPE_TEXT ||
88       option->optionType == Option::TYPE_KEYED_TEXT)
89   {
90     for (UINT j = 0; j < option->numChoices; j++)
91     {
92       Log::getInstance()->log("Options", Log::DEBUG, "Add option: %s", option->options[j]);
93       ob->addOption(tr(option->options[j]));
94     }
95
96     // Set the selected choice
97     ob->setSelected(tr(option->options[option->configChoice]));
98   }
99   else
100   {
101     // int mode
102     ob->setIntMode(option->startInt, option->numChoices);
103     ob->setSelected(option->configChoice);
104   }
105
106   numOptions++;
107   
108 }
109
110 void WOptionPane::deactivateAllControls()
111 {
112     if (selectedOption >= 0) {
113         optionBoxes[selectedOption]->setActive(0);
114         selectedOption = -1;
115     }
116 }
117
118
119 int WOptionPane::handleCommand(int command)
120 {
121   switch(command)
122   {
123     case Remote::DF_UP:
124     case Remote::UP:
125     {
126       if (selectedOption > 0)
127       {
128         optionBoxes[selectedOption]->setActive(0);
129         --selectedOption;
130         optionBoxes[selectedOption]->setActive(1);
131         return 1;
132       }
133       else
134       {
135         optionBoxes[selectedOption--]->setActive(0);
136         return 4; // Signal return control to parent
137       }
138     }
139     case Remote::DF_DOWN:
140     case Remote::DOWN:
141     {
142       if (selectedOption < (numOptions - 1))
143       {
144         if (selectedOption != -1) optionBoxes[selectedOption]->setActive(0);
145         ++selectedOption;
146         optionBoxes[selectedOption]->setActive(1);
147         return 1;
148       }
149       else if (selectedOption == (numOptions - 1))
150       {
151         optionBoxes[selectedOption]->setActive(0);
152         selectedOption = -1;
153         return 4; // Signal return control to parent
154       }
155     }
156     case Remote::DF_LEFT:
157     case Remote::LEFT:
158     {
159       optionBoxes[selectedOption]->left();
160       return 1;
161     }
162     case Remote::DF_RIGHT:
163     case Remote::RIGHT:
164     {
165       optionBoxes[selectedOption]->right();
166       return 1;
167     }
168     case Remote::OK:
169     {
170       optionBoxes[selectedOption]->cycle();
171       return 1;
172     }
173   }
174
175   return 0;
176 }
177
178 bool WOptionPane::mouseMove(int x, int y)
179 {
180     UINT i;
181     for (i=0;i<optionBoxes.size();i++) {
182         if (optionBoxes[i]->mouseMove(x,y)) {
183             if ( selectedOption!=(int)i) {
184                 if (selectedOption != -1 ) optionBoxes[selectedOption]->setActive(0);
185                 selectedOption=i;
186                 return true;
187             } else {
188                 return false;
189             }
190         }
191     }
192
193     return false;
194 }
195
196 bool WOptionPane::mouseLBDOWN(int x, int y)
197 {
198     UINT i;
199     for (i=0;i<optionBoxes.size();i++) {
200         if (optionBoxes[i]->mouseLBDOWN(x,y)) {
201             if ( selectedOption==(int)i) {
202                 optionBoxes[selectedOption]->cycle();
203                 return true;
204             } else {
205                 return false;
206             }
207         }
208     }
209     return false;
210 }
211
212
213
214