7
7
#include " src/Application.h"
8
8
#include < CEGUI/System.h>
9
9
#include < CEGUI/WindowManager.h>
10
- #include < CEGUI/InputAggregator.h>
11
10
#include < CEGUI/GUIContext.h>
12
11
#include < qopenglwidget.h>
13
12
#include < qpaintengine.h>
@@ -49,8 +48,6 @@ CEGUIGraphicsView::CEGUIGraphicsView(QWidget *parent) :
49
48
50
49
CEGUIGraphicsView::~CEGUIGraphicsView ()
51
50
{
52
- if (ceguiInput) delete ceguiInput;
53
-
54
51
auto vp = static_cast <QOpenGLWidget*>(viewport ());
55
52
vp->makeCurrent ();
56
53
delete blitter;
@@ -65,17 +62,7 @@ CEGUIGraphicsView::~CEGUIGraphicsView()
65
62
void CEGUIGraphicsView::injectInput (bool inject)
66
63
{
67
64
assert (scene ());
68
-
69
65
_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
- }
79
66
}
80
67
81
68
// We override this and draw CEGUI instead of the whole background.
@@ -170,9 +157,10 @@ void CEGUIGraphicsView::wheelEvent(QWheelEvent* event)
170
157
{
171
158
bool handled = false ;
172
159
173
- if (_injectInput && ceguiInput )
160
+ if (_injectInput)
174
161
{
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 ()));
176
164
}
177
165
178
166
if (!handled) ResizableGraphicsView::wheelEvent (event);
@@ -185,9 +173,10 @@ void CEGUIGraphicsView::mouseMoveEvent(QMouseEvent* event)
185
173
QPointF point = mapToScene (event->pos ());
186
174
emit cursorPositionChanged (static_cast <float >(point.x ()), static_cast <float >(point.y ()));
187
175
188
- if (_injectInput && ceguiInput )
176
+ if (_injectInput)
189
177
{
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 ()));
191
180
}
192
181
193
182
if (!handled) ResizableGraphicsView::mouseMoveEvent (event);
@@ -197,10 +186,11 @@ void CEGUIGraphicsView::mouseMoveEvent(QMouseEvent* event)
197
186
void CEGUIGraphicsView::mousePressEvent (QMouseEvent* event)
198
187
{
199
188
// Process CEGUI input
200
- if (_injectInput && ceguiInput )
189
+ if (_injectInput)
201
190
{
191
+ auto ctx = static_cast <CEGUIGraphicsScene*>(scene ())->getCEGUIContext ();
202
192
auto button = CEGUIUtils::qtMouseButtonToMouseButton (event->button ());
203
- if (ceguiInput ->injectMouseButtonDown (button)) return ;
193
+ if (ctx ->injectMouseButtonDown (button)) return ;
204
194
}
205
195
206
196
// Process middle button drag-scrolling
@@ -216,10 +206,11 @@ void CEGUIGraphicsView::mousePressEvent(QMouseEvent* event)
216
206
void CEGUIGraphicsView::mouseReleaseEvent (QMouseEvent* event)
217
207
{
218
208
// Process CEGUI input
219
- if (_injectInput && ceguiInput )
209
+ if (_injectInput)
220
210
{
211
+ auto ctx = static_cast <CEGUIGraphicsScene*>(scene ())->getCEGUIContext ();
221
212
auto button = CEGUIUtils::qtMouseButtonToMouseButton (event->button ());
222
- if (ceguiInput ->injectMouseButtonUp (button)) return ;
213
+ if (ctx ->injectMouseButtonUp (button)) return ;
223
214
}
224
215
225
216
// Process middle button drag-scrolling
@@ -235,17 +226,18 @@ void CEGUIGraphicsView::mouseReleaseEvent(QMouseEvent* event)
235
226
void CEGUIGraphicsView::keyPressEvent (QKeyEvent* event)
236
227
{
237
228
// Process CEGUI input
238
- if (_injectInput && ceguiInput )
229
+ if (_injectInput)
239
230
{
231
+ auto ctx = static_cast <CEGUIGraphicsScene*>(scene ())->getCEGUIContext ();
240
232
bool handled = false ;
241
233
242
234
auto key = CEGUIUtils::qtKeyToKey (event->key (), event->modifiers () & Qt::KeypadModifier);
243
235
if (key != CEGUI::Key::Scan::Unknown)
244
- handled = ceguiInput ->injectKeyDown (key);
236
+ handled = ctx ->injectKeyDown (key);
245
237
246
238
auto text = event->text ();
247
239
if (!text.isEmpty ())
248
- handled |= ceguiInput ->injectChar (text[0 ].unicode ());
240
+ handled |= ctx ->injectChar (text[0 ].unicode ());
249
241
250
242
if (handled) return ;
251
243
}
@@ -256,10 +248,11 @@ void CEGUIGraphicsView::keyPressEvent(QKeyEvent* event)
256
248
void CEGUIGraphicsView::keyReleaseEvent (QKeyEvent* event)
257
249
{
258
250
// Process CEGUI input
259
- if (_injectInput && ceguiInput )
251
+ if (_injectInput)
260
252
{
253
+ auto ctx = static_cast <CEGUIGraphicsScene*>(scene ())->getCEGUIContext ();
261
254
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 ;
263
256
}
264
257
265
258
ResizableGraphicsView::keyReleaseEvent (event);
0 commit comments