forked from nspire-emus/firebird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lcdwidget.cpp
79 lines (65 loc) · 1.88 KB
/
lcdwidget.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
#include "lcdwidget.h"
#include "core/keypad.h"
#include "qtkeypadbridge.h"
#include "qmlbridge.h"
#include "qtframebuffer.h"
LCDWidget::LCDWidget(QWidget *parent)
: QWidget(parent)
{
connect(&refresh_timer, SIGNAL(timeout()), this, SLOT(update()));
refresh_timer.setInterval(1000 / 60); // 60 fps
refresh_timer.start();
}
void LCDWidget::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::RightButton)
touchpad_down = touchpad_contact = true;
else
touchpad_contact = true;
if(event->x() >= 0 && event->x() < 320
&& event->y() >= 0 && event->y() < 240)
{
touchpad_x = event->x() * TOUCHPAD_X_MAX/width();
touchpad_y = TOUCHPAD_Y_MAX - (event->y() * TOUCHPAD_Y_MAX/height());
}
notifyTouchpadStateChanged();
kpc.gpio_int_active |= 0x800;
keypad_int_check();
}
void LCDWidget::mouseReleaseEvent(QMouseEvent *event)
{
if(event->button() == Qt::RightButton)
touchpad_down = touchpad_contact = false;
else
touchpad_contact = false;
notifyTouchpadStateChanged();
kpc.gpio_int_active |= 0x800;
keypad_int_check();
}
void LCDWidget::mouseMoveEvent(QMouseEvent *event)
{
int new_x = event->x() * TOUCHPAD_X_MAX/width(),
new_y = TOUCHPAD_Y_MAX - (event->y() * TOUCHPAD_Y_MAX/height());
if(new_x < 0)
new_x = 0;
if(new_x > TOUCHPAD_X_MAX)
new_x = TOUCHPAD_X_MAX;
if(new_y < 0)
new_y = 0;
if(new_y > TOUCHPAD_Y_MAX)
new_y = TOUCHPAD_Y_MAX;
int vel_x = new_x - touchpad_x;
int vel_y = new_y - touchpad_y;
touchpad_vel_x = vel_x;
touchpad_vel_y = vel_y;
touchpad_x = new_x;
touchpad_y = new_y;
notifyTouchpadStateChanged();
kpc.gpio_int_active |= 0x800;
keypad_int_check();
}
void LCDWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
paintFramebuffer(&painter);
}