6 changed files with 155 additions and 0 deletions
@ -0,0 +1,54 @@ |
|||
#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); |
|||
} |
@ -0,0 +1,18 @@ |
|||
#pragma once |
|||
|
|||
class MyWidget : public QWidget |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
MyWidget(QWidget* parent = nullptr); |
|||
virtual ~MyWidget() = default; |
|||
|
|||
protected: |
|||
virtual void mousePressEvent(QMouseEvent* event) override; |
|||
virtual void mouseReleaseEvent(QMouseEvent* event) override; |
|||
virtual void mouseMoveEvent(QMouseEvent* event) override; |
|||
|
|||
private: |
|||
Q_DISABLE_COPY(MyWidget) |
|||
}; |
@ -0,0 +1,3 @@ |
|||
This example shows how a QWidget can be used as touch input. |
|||
|
|||
Important note: The GDisplay pointer must be set to a valid display in mywidget.cpp:16 for this to work. |
@ -0,0 +1,74 @@ |
|||
/*
|
|||
* This file is subject to the terms of the GFX License. If a copy of |
|||
* the license was not distributed with this file, you can obtain one at: |
|||
* |
|||
* http://ugfx.org/license.html
|
|||
*/ |
|||
|
|||
#include "ugfx/gfx.h" |
|||
|
|||
|
|||
#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE |
|||
|
|||
#define GMOUSE_DRIVER_VMT GMOUSEVMT_QWidget |
|||
#include "../../../../src/ginput/ginput_driver_mouse.h" |
|||
|
|||
GMouse* qwidgetMouse; |
|||
coord_t qwidgetMouseX; |
|||
coord_t qwidgetMouseY; |
|||
coord_t qwidgetMouseZ; |
|||
uint16_t qwidgetMouseButtons; |
|||
|
|||
static bool_t _init(GMouse* m, unsigned driverinstance) |
|||
{ |
|||
(void)driverinstance; |
|||
|
|||
qwidgetMouse = m; |
|||
|
|||
return TRUE; |
|||
} |
|||
|
|||
static bool_t _read(GMouse* m, GMouseReading* pdr) |
|||
{ |
|||
(void)m; |
|||
|
|||
pdr->x = qwidgetMouseX; |
|||
pdr->y = qwidgetMouseY; |
|||
pdr->z = qwidgetMouseZ; |
|||
pdr->buttons = qwidgetMouseButtons; |
|||
|
|||
return TRUE; |
|||
} |
|||
|
|||
const GMouseVMT GMOUSE_DRIVER_VMT[1] = {{ |
|||
{ |
|||
GDRIVER_TYPE_MOUSE, |
|||
0, |
|||
sizeof(GMouse), |
|||
_gmouseInitDriver, |
|||
_gmousePostInitDriver, |
|||
_gmouseDeInitDriver |
|||
}, |
|||
1, // z_max
|
|||
0, // z_min
|
|||
1, // z_touchon
|
|||
0, // z_touchoff
|
|||
{ // pen_jitter
|
|||
1, // calibrate
|
|||
1, // click
|
|||
1 // move
|
|||
}, |
|||
{ // finger_jitter
|
|||
1, // calibrate
|
|||
1, // click
|
|||
1 // move
|
|||
}, |
|||
_init, // init
|
|||
0, // deinit
|
|||
_read, // get
|
|||
0, // calsave
|
|||
0 // calload
|
|||
}}; |
|||
|
|||
#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */ |
|||
|
@ -0,0 +1,5 @@ |
|||
Limitation: As this driver only exports one set of variables, this driver can only be used |
|||
on systems with one single touch input device of this type. To overcome this |
|||
limitation, the global variables have to be converted into arrays. The driverinstance |
|||
variable passed to the _read() function is then used to distinguish between the |
|||
different instances. |
Loading…
Reference in new issue