forked from nspire-emus/firebird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qmlbridge.cpp
133 lines (102 loc) · 2.84 KB
/
qmlbridge.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <iostream>
#include <cassert>
#include "qmlbridge.h"
#include "core/keypad.h"
QMLBridge::QMLBridge(QObject *parent) : QObject(parent)
{}
constexpr const int ROWS = 8, COLS = 11;
void QMLBridge::keypadStateChanged(int keymap_id, bool state)
{
int col = keymap_id % 11, row = keymap_id / 11;
assert(row < ROWS);
//assert(col < COLS); Not needed.
if(state)
key_map[row] |= 1 << col;
else
key_map[row] &= ~(1 << col);
}
static QObject *buttons[ROWS][COLS];
void QMLBridge::registerNButton(int keymap_id, QVariant button)
{
int col = keymap_id % COLS, row = keymap_id / COLS;
assert(row < ROWS);
//assert(col < COLS); Not needed.
if(buttons[row][col])
qWarning() << "Warning: Button " << keymap_id << " already registered as " << buttons[row][col] << "!";
else
buttons[row][col] = button.value<QObject*>();
}
void QMLBridge::touchpadStateChanged(qreal x, qreal y, bool state)
{
touchpad_down = touchpad_contact = state;
if(state)
{
touchpad_x = x * TOUCHPAD_X_MAX;
touchpad_y = (1.0f-y) * TOUCHPAD_Y_MAX;
}
kpc.gpio_int_active |= 0x800;
keypad_int_check();
}
static QObject *qml_touchpad;
void QMLBridge::registerTouchpad(QVariant touchpad)
{
qml_touchpad = touchpad.value<QObject*>();
}
#ifdef MOBILE_UI
bool QMLBridge::restart()
{
if(emu_thread.isRunning() && !emu_thread.stop())
return false;
QSettings settings;
emu_thread.boot1 = settings.value("boot1").toString().toStdString();
emu_thread.flash = settings.value("flash").toString().toStdString();
emu_thread.start();
return true;
}
void QMLBridge::setPaused(bool b)
{
emu_thread.setPaused(b);
}
void QMLBridge::reset()
{
emu_thread.reset();
}
bool QMLBridge::stop()
{
return emu_thread.stop();
}
#endif
void notifyKeypadStateChanged(int row, int col, bool state)
{
assert(row < ROWS);
assert(col < COLS);
if(!buttons[row][col])
{
qWarning() << "Warning: Button " << row*11+col << " not present in keypad!";
return;
}
QQmlProperty::write(buttons[row][col], "state", state);
}
QObject *qmlBridgeFactory(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return new QMLBridge();
}
void notifyTouchpadStateChanged(qreal x, qreal y, bool state)
{
if(!qml_touchpad)
{
qWarning("Warning: No touchpad registered!");
return;
}
QVariant ret;
if(state)
QMetaObject::invokeMethod(qml_touchpad, "showHighlight", Q_RETURN_ARG(QVariant, ret), Q_ARG(QVariant, QVariant(x)), Q_ARG(QVariant, QVariant(y)));
else
QMetaObject::invokeMethod(qml_touchpad, "hideHighlight");
}
void notifyTouchpadStateChanged()
{
notifyTouchpadStateChanged(float(touchpad_x)/TOUCHPAD_X_MAX, 1.0f-(float(touchpad_y)/TOUCHPAD_Y_MAX), touchpad_contact);
}