Skip to content

Commit 26e1a69

Browse files
committed
Update for the new CEGUI input
1 parent aa0fc54 commit 26e1a69

File tree

2 files changed

+19
-32
lines changed

2 files changed

+19
-32
lines changed

src/ui/CEGUIGraphicsView.cpp

+19-26
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "src/Application.h"
88
#include <CEGUI/System.h>
99
#include <CEGUI/WindowManager.h>
10-
#include <CEGUI/InputAggregator.h>
1110
#include <CEGUI/GUIContext.h>
1211
#include <qopenglwidget.h>
1312
#include <qpaintengine.h>
@@ -49,8 +48,6 @@ CEGUIGraphicsView::CEGUIGraphicsView(QWidget *parent) :
4948

5049
CEGUIGraphicsView::~CEGUIGraphicsView()
5150
{
52-
if (ceguiInput) delete ceguiInput;
53-
5451
auto vp = static_cast<QOpenGLWidget*>(viewport());
5552
vp->makeCurrent();
5653
delete blitter;
@@ -65,17 +62,7 @@ CEGUIGraphicsView::~CEGUIGraphicsView()
6562
void CEGUIGraphicsView::injectInput(bool inject)
6663
{
6764
assert(scene());
68-
6965
_injectInput = inject;
70-
71-
if (_injectInput && scene())
72-
{
73-
if (ceguiInput) delete ceguiInput;
74-
auto ctx = static_cast<CEGUIGraphicsScene*>(scene())->getCEGUIContext();
75-
ceguiInput = new CEGUI::InputAggregator(ctx);
76-
ceguiInput->initialise();
77-
ceguiInput->setMouseClickEventGenerationEnabled(true);
78-
}
7966
}
8067

8168
// We override this and draw CEGUI instead of the whole background.
@@ -170,9 +157,10 @@ void CEGUIGraphicsView::wheelEvent(QWheelEvent* event)
170157
{
171158
bool handled = false;
172159

173-
if (_injectInput && ceguiInput)
160+
if (_injectInput)
174161
{
175-
handled = ceguiInput->injectMouseWheelChange(static_cast<float>(event->delta()));
162+
auto ctx = static_cast<CEGUIGraphicsScene*>(scene())->getCEGUIContext();
163+
handled = ctx->injectMouseWheelChange(static_cast<float>(event->angleDelta().y()));
176164
}
177165

178166
if (!handled) ResizableGraphicsView::wheelEvent(event);
@@ -185,9 +173,10 @@ void CEGUIGraphicsView::mouseMoveEvent(QMouseEvent* event)
185173
QPointF point = mapToScene(event->pos());
186174
emit cursorPositionChanged(static_cast<float>(point.x()), static_cast<float>(point.y()));
187175

188-
if (_injectInput && ceguiInput)
176+
if (_injectInput)
189177
{
190-
handled = ceguiInput->injectMousePosition(static_cast<float>(point.x()), static_cast<float>(point.y()));
178+
auto ctx = static_cast<CEGUIGraphicsScene*>(scene())->getCEGUIContext();
179+
handled = ctx->injectMousePosition(static_cast<float>(point.x()), static_cast<float>(point.y()));
191180
}
192181

193182
if (!handled) ResizableGraphicsView::mouseMoveEvent(event);
@@ -197,10 +186,11 @@ void CEGUIGraphicsView::mouseMoveEvent(QMouseEvent* event)
197186
void CEGUIGraphicsView::mousePressEvent(QMouseEvent* event)
198187
{
199188
// Process CEGUI input
200-
if (_injectInput && ceguiInput)
189+
if (_injectInput)
201190
{
191+
auto ctx = static_cast<CEGUIGraphicsScene*>(scene())->getCEGUIContext();
202192
auto button = CEGUIUtils::qtMouseButtonToMouseButton(event->button());
203-
if (ceguiInput->injectMouseButtonDown(button)) return;
193+
if (ctx->injectMouseButtonDown(button)) return;
204194
}
205195

206196
// Process middle button drag-scrolling
@@ -216,10 +206,11 @@ void CEGUIGraphicsView::mousePressEvent(QMouseEvent* event)
216206
void CEGUIGraphicsView::mouseReleaseEvent(QMouseEvent* event)
217207
{
218208
// Process CEGUI input
219-
if (_injectInput && ceguiInput)
209+
if (_injectInput)
220210
{
211+
auto ctx = static_cast<CEGUIGraphicsScene*>(scene())->getCEGUIContext();
221212
auto button = CEGUIUtils::qtMouseButtonToMouseButton(event->button());
222-
if (ceguiInput->injectMouseButtonUp(button)) return;
213+
if (ctx->injectMouseButtonUp(button)) return;
223214
}
224215

225216
// Process middle button drag-scrolling
@@ -235,17 +226,18 @@ void CEGUIGraphicsView::mouseReleaseEvent(QMouseEvent* event)
235226
void CEGUIGraphicsView::keyPressEvent(QKeyEvent* event)
236227
{
237228
// Process CEGUI input
238-
if (_injectInput && ceguiInput)
229+
if (_injectInput)
239230
{
231+
auto ctx = static_cast<CEGUIGraphicsScene*>(scene())->getCEGUIContext();
240232
bool handled = false;
241233

242234
auto key = CEGUIUtils::qtKeyToKey(event->key(), event->modifiers() & Qt::KeypadModifier);
243235
if (key != CEGUI::Key::Scan::Unknown)
244-
handled = ceguiInput->injectKeyDown(key);
236+
handled = ctx->injectKeyDown(key);
245237

246238
auto text = event->text();
247239
if (!text.isEmpty())
248-
handled |= ceguiInput->injectChar(text[0].unicode());
240+
handled |= ctx->injectChar(text[0].unicode());
249241

250242
if (handled) return;
251243
}
@@ -256,10 +248,11 @@ void CEGUIGraphicsView::keyPressEvent(QKeyEvent* event)
256248
void CEGUIGraphicsView::keyReleaseEvent(QKeyEvent* event)
257249
{
258250
// Process CEGUI input
259-
if (_injectInput && ceguiInput)
251+
if (_injectInput)
260252
{
253+
auto ctx = static_cast<CEGUIGraphicsScene*>(scene())->getCEGUIContext();
261254
auto key = CEGUIUtils::qtKeyToKey(event->key(), event->modifiers() & Qt::KeypadModifier);
262-
if (key != CEGUI::Key::Scan::Unknown && ceguiInput->injectKeyUp(key)) return;
255+
if (key != CEGUI::Key::Scan::Unknown && ctx->injectKeyUp(key)) return;
263256
}
264257

265258
ResizableGraphicsView::keyReleaseEvent(event);

src/ui/CEGUIGraphicsView.h

-6
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
// This is a final class, not suitable for subclassing. This views given scene using
77
// QOpenGLWidget. It's designed to work with CEGUIGraphicsScene derived classes.
88

9-
namespace CEGUI
10-
{
11-
class InputAggregator;
12-
}
13-
149
class QOpenGLTextureBlitter;
1510

1611
class CEGUIGraphicsView final : public ResizableGraphicsView
@@ -45,7 +40,6 @@ class CEGUIGraphicsView final : public ResizableGraphicsView
4540
QOpenGLTextureBlitter* blitter = nullptr;
4641
QBrush checkerboardBrush;
4742

48-
CEGUI::InputAggregator* ceguiInput = nullptr;
4943
bool _injectInput = false;
5044

5145
// if true, we render always (possibly capped to some FPS) - suitable for live preview

0 commit comments

Comments
 (0)