]> git.vomp.tv Git - vompclient.git/blob - wremoteconfig.cc
WIP [broken]
[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     Log::getInstance()->log("WRemoteConfig", Log::DEBUG, "%u", i);
70     const char* vompKeyName = InputMan::getVompKeyName(static_cast<UCHAR>(i));
71     if (vompKeyName != NULL)
72     {
73       std::string line;
74       line.reserve(150);
75       line += vompKeyName;
76       line += ":\t";
77     Log::getInstance()->log("WRemoteConfig", Log::DEBUG, "A");
78       line += inputMan->getHardCodedHardwareKeyNamesForVompKey(static_cast<UCHAR>(i));
79       line += '\t';
80     Log::getInstance()->log("WRemoteConfig", Log::DEBUG, "B");
81       line += inputMan->getAllHardwareKeyNamesAssignedToVompKey(static_cast<UCHAR>(i));
82     Log::getInstance()->log("WRemoteConfig", Log::DEBUG, "C");
83
84       sl.addOption(line.c_str(), i, 0);
85     }
86   }
87
88   if (!startup)
89   {
90     sl.hintSetCurrent(selection);
91     sl.hintSetTop(top);
92   }
93 }
94
95 void WRemoteConfig::setSize(UINT w, UINT h)
96 {
97   Boxx::setSize(w, h);
98   sl.setSize(area.w - 20, area.h - 70);
99 }
100
101 void WRemoteConfig::draw()
102 {
103   Boxx::draw();
104   
105   drawText(tr("Command"), 15, 4, DrawStyle::LIGHTTEXT);
106   drawText(tr("Hard wired"), 165, 4, DrawStyle::LIGHTTEXT);
107   drawText(tr("User assignable"), 315, 4, DrawStyle::LIGHTTEXT);
108
109   if (learnmode)
110   {
111     drawText(tr("Learning! Press any hardwired key to exit."), 15, area.h - 30, DrawStyle::SELECTHIGHLIGHT);
112   }
113   else
114   {
115     drawText(tr("Press [ok] for learning or MENU to reset to defaults."), 15, area.h - 30, DrawStyle::LIGHTTEXT);
116   }
117 }
118
119 bool WRemoteConfig::mouseLBDOWN(int x, int y)
120 {
121     if (sl.mouseLBDOWN(x,y))
122     {
123       BoxStack::getInstance()->handleCommand(Input::OK); //simulate OK press
124       return true;
125     }
126     return false;
127 }
128
129 bool WRemoteConfig::mouseMove(int x, int y) 
130 {
131     if (sl.mouseMove(x,y))
132     {
133       sl.setShowSelOption(true);
134       sl.draw();
135       return true;
136     }
137     return false;
138 }
139 /*
140 void WRemoteConfig::processMessage(Message* m)
141 {
142   Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
143
144   if (m->message == Message::MOUSE_MOVE)
145   {
146     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
147     {
148       sl.setShowSelOption(true);
149       sl.draw();
150       viewman->updateView(this);
151     }
152   }
153   else if (m->message == Message::MOUSE_LBDOWN)
154   {
155     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
156     {
157       ViewMan::getInstance()->handleCommand(Input::OK); //simulate OK press
158     }
159     else
160     {
161       //check if press is outside this view! then simulate cancel
162       int x=(m->parameter>>16)-getScreenX();
163       int y=(m->parameter&0xFFFF)-getScreenY();
164       if (x<0 || y <0 || x>getWidth() || y>getHeight())
165       {
166         ViewMan::getInstance()->handleCommand(Input::BACK); //simulate cancel press
167       }
168     }
169   }
170 }
171 */
172
173 /*
174 void WRemoteConfig::doSave()
175 {
176     Message* m = new Message();
177     m->message = Message::CHANGED_REMOTECONTROL;
178     m->to = parent;
179     m->parameter = 0;
180     //Command::getInstance()->postMessage(m);
181     
182 }
183 */
184
185 int WRemoteConfig::handleCommand(int command)
186 {
187   if (learnmode)
188   {
189     learnmode = false;
190     if (command == Input::NA_LEARN)
191     {
192       initSelectList(false);
193     }
194     return 1;
195   }
196   switch(command)
197   {
198     case Input::UP:
199     {
200       if (sl.getCurrentOption() != 0)
201       {
202         sl.up();
203         return 1;
204       }
205       else
206       {
207         sl.setShowSelOption(false);
208         active = false;
209         return 4; // return control to vopts
210       }
211     }
212     case Input::DOWN:
213     {
214       if (!active)
215       {
216         active = true;    
217         sl.setShowSelOption(true);
218       }
219       else
220       {
221         sl.down();
222       }
223       return 1;
224     }
225     case Input::SKIPBACK:
226     {
227       sl.pageUp();
228       return 1;
229     }
230     case Input::SKIPFORWARD:
231     {
232       sl.pageDown();
233       return 1;
234     }
235     case Input::OK:
236     {
237       learnmode = true;
238      // remote->EnterLearningMode(sl.getCurrentOptionData()); FIXME
239       return 1;
240     }
241     case Input::BACK:
242     {
243       return 0;
244 /*
245       doSave();
246
247       // Instead of returning 4 here which would delete this view
248       // before the doSave message is processed, let the message queue
249       // do the doSave then this close message. That will make the options menu
250       // disappear before this view
251
252       Message* m = new Message();
253       m->message = Message::CLOSE_ME;
254       m->from = this;
255       m->to = viewman;
256       //Command::getInstance()->postMessage(m);
257       return 2;
258 */      
259     }
260     case Input::MENU:
261     {
262    //   remote->ResetToDefault(); FIXME
263       initSelectList(false);
264       return 1;
265     }
266   }
267
268   return 0;
269 }
270
271