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