55 lines
1.2 KiB
C++
55 lines
1.2 KiB
C++
|
#include "mywidget.h"
|
||
|
#include "ugfx/src/ginput/ginput_driver_mouse.h"
|
||
|
|
||
|
extern GMouse* qwidgetMouse;
|
||
|
extern coord_t qwidgetMouseX;
|
||
|
extern coord_t qwidgetMouseY;
|
||
|
extern coord_t qwidgetMouseZ;
|
||
|
extern uint16_t qwidgetMouseButtons;
|
||
|
|
||
|
MyWidget::MyWidget(QWidget* parent) : QWidget(parent)
|
||
|
{
|
||
|
// GMouse
|
||
|
if (!qwidgetMouse) {
|
||
|
qFatal("MyWidget::MyWidget(): Invalid GMouse (nullptr).");
|
||
|
}
|
||
|
qwidgetMouse->display = nullptr; // Set your display here!
|
||
|
}
|
||
|
|
||
|
void MyWidget::mousePressEvent(QMouseEvent* event)
|
||
|
{
|
||
|
event->accept();
|
||
|
|
||
|
qwidgetMouseX = event->x();
|
||
|
qwidgetMouseY = event->y();
|
||
|
qwidgetMouseZ = 1;
|
||
|
|
||
|
if (event->buttons() & Qt::LeftButton) {
|
||
|
qwidgetMouseButtons = GINPUT_MOUSE_BTN_LEFT;
|
||
|
} else if (event->buttons() & Qt::RightButton) {
|
||
|
qwidgetMouseButtons = GINPUT_MOUSE_BTN_RIGHT;
|
||
|
}
|
||
|
|
||
|
_gmouseWakeup(qwidgetMouse);
|
||
|
}
|
||
|
|
||
|
void MyWidget::mouseReleaseEvent(QMouseEvent* event)
|
||
|
{
|
||
|
event->accept();
|
||
|
|
||
|
qwidgetMouseZ = 0;
|
||
|
qwidgetMouseButtons = 0;
|
||
|
|
||
|
_gmouseWakeup(qwidgetMouse);
|
||
|
}
|
||
|
|
||
|
void MyWidget::mouseMoveEvent(QMouseEvent* event)
|
||
|
{
|
||
|
event->accept();
|
||
|
|
||
|
qwidgetMouseX = event->x();
|
||
|
qwidgetMouseY = event->y();
|
||
|
|
||
|
_gmouseWakeup(qwidgetMouse);
|
||
|
}
|