]> git.vomp.tv Git - vompclient.git/blob - wremoteconfig.cc
Fix black background for 16:9 live TV on 4:3 screen
[vompclient.git] / wremoteconfig.cc
1 /*
2     Copyright 2007-2020 Chris Tallon, Marten Richter
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, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include <string>
21
22 #include "log.h"
23 #include "input.h"
24 #include "inputman.h"
25 #include "wsymbol.h"
26 #include "colour.h"
27 #include "i18n.h"
28 #include "boxstack.h"
29 #include "wremoteconfig.h"
30
31
32
33 WRemoteConfig::WRemoteConfig()
34 {
35   remote = InputMan::getInstance();
36   learnmode = false;
37   active = false;
38
39   sl.setShowSelOption(false);
40   sl.setPosition(10, 30);
41   add(&sl);
42   initSelectList(true);
43 }
44
45 WRemoteConfig::~WRemoteConfig()
46 {
47 }
48
49 void WRemoteConfig::initSelectList(bool startup)
50 {
51   InputMan* inputMan = InputMan::getInstance();
52
53   ULONG selection = 0;
54   ULONG top = 0;
55
56   if (!startup)
57   {
58     selection = sl.getCurrentOption();
59     top = sl.getTopOption();
60   }
61
62   sl.clear();
63   sl.addColumn(0);
64   sl.addColumn(150);
65   sl.addColumn(300);
66   
67   for (UINT i = 0; i < 256; i++)
68   {
69     const char* vompKeyName = InputMan::getVompKeyName(static_cast<UCHAR>(i));
70     if (vompKeyName != NULL)
71     {
72       std::string line;
73       line.reserve(150);
74       line += vompKeyName;
75       line += ": \t";
76       line += inputMan->getHardCodedHardwareKeyNamesForVompKey(static_cast<UCHAR>(i));
77       line += " \t"; // FIXME extra spaces for braindead strtok. Ditch strtok.
78       line += inputMan->getAllHardwareKeyNamesAssignedToVompKey(static_cast<UCHAR>(i));
79       sl.addOption(line.c_str(), reinterpret_cast<void*>(i), 0);
80     }
81   }
82
83   if (!startup)
84   {
85     sl.hintSetCurrent(selection);
86     sl.hintSetTop(top);
87   }
88 }
89
90 void WRemoteConfig::setSize(UINT w, UINT h)
91 {
92   Boxx::setSize(w, h);
93   sl.setSize(area.w - 20, area.h - 70);
94 }
95
96 void WRemoteConfig::draw()
97 {
98   Boxx::draw();
99   
100   drawText(tr("Command"), 15, 4, DrawStyle::LIGHTTEXT);
101   drawText(tr("Hard wired"), 165, 4, DrawStyle::LIGHTTEXT);
102   drawText(tr("User assignable"), 315, 4, DrawStyle::LIGHTTEXT);
103
104   if (learnmode)
105   {
106     drawText(tr("Learning! Press any hardwired key to exit."), 15, area.h - 30, DrawStyle::SELECTHIGHLIGHT);
107   }
108   else
109   {
110     drawText(tr("Press [ok] for learning or MENU to reset to defaults."), 15, area.h - 30, DrawStyle::LIGHTTEXT);
111   }
112 }
113
114 bool WRemoteConfig::mouseLBDOWN(int x, int y)
115 {
116     if (sl.mouseLBDOWN(x,y))
117     {
118       BoxStack::getInstance()->handleCommand(Input::OK); //simulate OK press
119       return true;
120     }
121     return false;
122 }
123
124 bool WRemoteConfig::mouseMove(int x, int y) 
125 {
126     if (sl.mouseMove(x,y))
127     {
128       sl.setShowSelOption(true);
129       sl.draw();
130       return true;
131     }
132     return false;
133 }
134 /*
135 void WRemoteConfig::processMessage(Message* m)
136 {
137   Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
138
139   if (m->message == Message::MOUSE_MOVE)
140   {
141     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
142     {
143       sl.setShowSelOption(true);
144       sl.draw();
145       viewman->updateView(this);
146     }
147   }
148   else if (m->message == Message::MOUSE_LBDOWN)
149   {
150     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
151     {
152       ViewMan::getInstance()->handleCommand(Input::OK); //simulate OK press
153     }
154     else
155     {
156       //check if press is outside this view! then simulate cancel
157       int x=(m->parameter>>16)-getScreenX();
158       int y=(m->parameter&0xFFFF)-getScreenY();
159       if (x<0 || y <0 || x>getWidth() || y>getHeight())
160       {
161         ViewMan::getInstance()->handleCommand(Input::BACK); //simulate cancel press
162       }
163     }
164   }
165 }
166 */
167
168 /*
169 void WRemoteConfig::doSave()
170 {
171     Message* m = new Message();
172     m->message = Message::CHANGED_REMOTECONTROL;
173     m->to = parent;
174     m->parameter = 0;
175     //Command::getInstance()->postMessage(m);
176     
177 }
178 */
179
180 int WRemoteConfig::handleCommand(int command)
181 {
182   if (learnmode)
183   {
184     learnmode = false;
185     if (command == Input::NA_LEARN)
186     {
187       initSelectList(false);
188     }
189     return 1;
190   }
191   switch(command)
192   {
193     case Input::UP:
194     {
195       if (sl.getCurrentOption() != 0)
196       {
197         sl.up();
198         return 1;
199       }
200       else
201       {
202         sl.setShowSelOption(false);
203         active = false;
204         return 4; // return control to vopts
205       }
206     }
207     case Input::DOWN:
208     {
209       if (!active)
210       {
211         active = true;    
212         sl.setShowSelOption(true);
213       }
214       else
215       {
216         sl.down();
217       }
218       return 1;
219     }
220     case Input::SKIPBACK:
221     {
222       sl.pageUp();
223       return 1;
224     }
225     case Input::SKIPFORWARD:
226     {
227       sl.pageDown();
228       return 1;
229     }
230     case Input::OK:
231     {
232       learnmode = true;
233       InputMan::getInstance()->EnterLearningMode(reinterpret_cast<ULONG>(sl.getCurrentOptionData()));
234       return 1;
235     }
236     case Input::BACK:
237     {
238       return 0;
239 /*
240       doSave();
241
242       // Instead of returning 4 here which would delete this view
243       // before the doSave message is processed, let the message queue
244       // do the doSave then this close message. That will make the options menu
245       // disappear before this view
246
247       Message* m = new Message();
248       m->message = Message::CLOSE_ME;
249       m->from = this;
250       m->to = viewman;
251       //Command::getInstance()->postMessage(m);
252       return 2;
253 */      
254     }
255     case Input::MENU:
256     {
257       InputMan::getInstance()->ResetToDefault();
258       initSelectList(false);
259       return 1;
260     }
261   }
262
263   return 0;
264 }
265
266