mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-22 21:53:52 +00:00
Let gui/events handle mouse position locally, makes it remember position when disabled and reenabled.
This commit is contained in:
parent
82a3c071e5
commit
c04d72cbe3
2 changed files with 32 additions and 11 deletions
|
@ -1,11 +1,27 @@
|
||||||
#include <MyGUI.h>
|
#include <MyGUI.h>
|
||||||
#include <OIS/OIS.h>
|
#include <OIS/OIS.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "events.hpp"
|
#include "events.hpp"
|
||||||
|
|
||||||
using namespace OIS;
|
using namespace OIS;
|
||||||
using namespace OEngine::GUI;
|
using namespace OEngine::GUI;
|
||||||
|
|
||||||
|
EventInjector::EventInjector(MyGUI::Gui *g)
|
||||||
|
: gui(g), mouseX(0), mouseY(0), enabled(true)
|
||||||
|
{
|
||||||
|
assert(gui);
|
||||||
|
maxX = gui->getViewWidth();
|
||||||
|
maxY = gui->getViewHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename X>
|
||||||
|
void setRange(X &x, X min, X max)
|
||||||
|
{
|
||||||
|
if(x < min) x = min;
|
||||||
|
else if(x > max) x = max;
|
||||||
|
}
|
||||||
|
|
||||||
void EventInjector::event(Type type, int index, const void *p)
|
void EventInjector::event(Type type, int index, const void *p)
|
||||||
{
|
{
|
||||||
if(!enabled) return;
|
if(!enabled) return;
|
||||||
|
@ -17,13 +33,14 @@ void EventInjector::event(Type type, int index, const void *p)
|
||||||
if(type == EV_KeyDown)
|
if(type == EV_KeyDown)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
This is just a first approximation. Apparently, OIS sucks
|
This is just a first approximation. Apparently, OIS is
|
||||||
to such a degree that it's unable to provide any sort of
|
unable to provide reliable unicode characters on all
|
||||||
reliable unicode character on all platforms and for all
|
platforms. At least that's what I surmise from the amount
|
||||||
keys. At least that's what I surmise from the amount of
|
of workaround that the MyGUI folks have put in place for
|
||||||
workaround that the MyGUI folks have put in place for
|
|
||||||
this. See Common/Input/OIS/InputManager.cpp in the MyGUI
|
this. See Common/Input/OIS/InputManager.cpp in the MyGUI
|
||||||
sources for details. If this is indeed necessary (I
|
sources for details.
|
||||||
|
|
||||||
|
If the work they have done there is indeed necessary (I
|
||||||
haven't tested that it is, although I have had dubious
|
haven't tested that it is, although I have had dubious
|
||||||
experinces with OIS events in the past), then we should
|
experinces with OIS events in the past), then we should
|
||||||
probably adapt all that code here. Or even better,
|
probably adapt all that code here. Or even better,
|
||||||
|
@ -46,10 +63,12 @@ void EventInjector::event(Type type, int index, const void *p)
|
||||||
MouseEvent *mouse = (MouseEvent*)p;
|
MouseEvent *mouse = (MouseEvent*)p;
|
||||||
MyGUI::MouseButton id = MyGUI::MouseButton::Enum(index);
|
MyGUI::MouseButton id = MyGUI::MouseButton::Enum(index);
|
||||||
|
|
||||||
// I'm not sure these should be used directly, MyGUI demo code
|
// Update mouse position
|
||||||
// use local mouse position variables.
|
mouseX += mouse->state.X.rel;
|
||||||
int mouseX = mouse->state.X.abs;
|
mouseY += mouse->state.Y.rel;
|
||||||
int mouseY = mouse->state.Y.abs;
|
|
||||||
|
setRange(mouseX,0,maxX);
|
||||||
|
setRange(mouseY,0,maxY);
|
||||||
|
|
||||||
if(type == EV_MouseDown)
|
if(type == EV_MouseDown)
|
||||||
gui->injectMousePress(mouseX, mouseY, id);
|
gui->injectMousePress(mouseX, mouseY, id);
|
||||||
|
|
|
@ -16,11 +16,13 @@ namespace GUI
|
||||||
class EventInjector : public Mangle::Input::Event
|
class EventInjector : public Mangle::Input::Event
|
||||||
{
|
{
|
||||||
MyGUI::Gui *gui;
|
MyGUI::Gui *gui;
|
||||||
|
int mouseX, mouseY;
|
||||||
|
int maxX, maxY;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool enabled;
|
bool enabled;
|
||||||
|
|
||||||
EventInjector(MyGUI::Gui *g) : gui(g), enabled(true) {}
|
EventInjector(MyGUI::Gui *g);
|
||||||
void event(Type type, int index, const void *p);
|
void event(Type type, int index, const void *p);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue