2 Copyright 2007-2020 Chris Tallon, Marten Richter
4 This file is part of VOMP.
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.
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.
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/>.
28 #include "wremoteconfig.h"
32 WRemoteConfig::WRemoteConfig()
34 remote = InputMan::getInstance();
38 sl.setShowSelOption(false);
39 sl.setPosition(10, 30);
44 WRemoteConfig::~WRemoteConfig()
48 void WRemoteConfig::initSelectList(bool startup)
50 InputMan* inputMan = InputMan::getInstance();
57 selection = sl.getCurrentOption();
58 top = sl.getTopOption();
66 for (u4 i = 0; i < 256; i++)
68 const char* vompKeyName = InputMan::getVompKeyName(static_cast<u1>(i));
69 if (vompKeyName != NULL)
75 line += inputMan->getHardCodedHardwareKeyNamesForVompKey(static_cast<u1>(i));
76 line += " \t"; // FIXME extra spaces for braindead strtok. Ditch strtok.
77 line += inputMan->getAllHardwareKeyNamesAssignedToVompKey(static_cast<u1>(i));
78 sl.addOption(line, reinterpret_cast<void*>(i), 0);
84 sl.hintSetCurrent(selection);
89 void WRemoteConfig::setSize(u4 w, u4 h)
92 sl.setSize(area.w - 20, area.h - 70);
95 void WRemoteConfig::draw()
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);
105 drawText(tr("Learning! Press any hardwired key to exit."), 15, area.h - 30, DrawStyle::SELECTHIGHLIGHT);
109 drawText(tr("Press [ok] for learning or MENU to reset to defaults."), 15, area.h - 30, DrawStyle::LIGHTTEXT);
113 bool WRemoteConfig::mouseLBDOWN(int x, int y)
115 if (sl.mouseLBDOWN(x,y))
117 BoxStack::getInstance()->handleCommand(Input::OK); //simulate OK press
123 bool WRemoteConfig::mouseMove(int x, int y)
125 if (sl.mouseMove(x,y))
127 sl.setShowSelOption(true);
134 void WRemoteConfig::processMessage(Message* m)
136 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
138 if (m->message == Message::MOUSE_MOVE)
140 if (sl.mouseMove(m->parameter - getScreenX(), m->tag - getScreenY()))
142 sl.setShowSelOption(true);
144 viewman->updateView(this);
147 else if (m->message == Message::MOUSE_LBDOWN)
149 if (sl.mouseLBDOWN(m->parameter - getScreenX(), m->tag - getScreenY()))
151 ViewMan::getInstance()->handleCommand(Input::OK); //simulate OK press
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())
160 ViewMan::getInstance()->handleCommand(Input::BACK); //simulate cancel press
168 void WRemoteConfig::doSave()
170 Message* m = new Message();
171 m->message = Message::CHANGED_REMOTECONTROL;
174 //Control::getInstance()->postMessage(m);
179 int WRemoteConfig::handleCommand(int command)
184 if (command == Input::NA_LEARN)
186 initSelectList(false);
194 if (sl.getCurrentOption() != 0)
201 sl.setShowSelOption(false);
203 return 4; // return control to vopts
211 sl.setShowSelOption(true);
219 case Input::SKIPBACK:
224 case Input::SKIPFORWARD:
232 // Two casts to get from void* to u1. Wow. First reinterpret from void* to u4, then static to u1
233 InputMan::getInstance()->EnterLearningMode(
234 static_cast<u1>(reinterpret_cast<u4>(sl.getCurrentOptionData())));
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
248 Message* m = new Message();
249 m->message = Message::CLOSE_ME;
252 //Control::getInstance()->postMessage(m);
258 InputMan::getInstance()->ResetToDefault();
259 initSelectList(false);