Skip to content

Commit

Permalink
Merge branch 'graphics-backends-improvements'
Browse files Browse the repository at this point in the history
  • Loading branch information
csnover committed Oct 15, 2017
2 parents 7fc8619 + 4757c24 commit 7d8d2f8
Show file tree
Hide file tree
Showing 35 changed files with 1,284 additions and 1,223 deletions.
26 changes: 26 additions & 0 deletions backends/events/default/default-events.cpp
Expand Up @@ -254,4 +254,30 @@ void DefaultEventManager::pushEvent(const Common::Event &event) {
_artificialEventSource.addEvent(event);
}

void DefaultEventManager::purgeMouseEvents() {
_dispatcher.dispatch();

Common::Queue<Common::Event> filteredQueue;
while (!_eventQueue.empty()) {
Common::Event event = _eventQueue.pop();
switch (event.type) {
case Common::EVENT_MOUSEMOVE:
case Common::EVENT_LBUTTONDOWN:
case Common::EVENT_LBUTTONUP:
case Common::EVENT_RBUTTONDOWN:
case Common::EVENT_RBUTTONUP:
case Common::EVENT_WHEELUP:
case Common::EVENT_WHEELDOWN:
case Common::EVENT_MBUTTONDOWN:
case Common::EVENT_MBUTTONUP:
// do nothing
break;
default:
filteredQueue.push(event);
break;
}
}
_eventQueue = filteredQueue;
}

#endif // !defined(DISABLE_DEFAULT_EVENTMANAGER)
1 change: 1 addition & 0 deletions backends/events/default/default-events.h
Expand Up @@ -80,6 +80,7 @@ class DefaultEventManager : public Common::EventManager, Common::EventObserver {
virtual void init();
virtual bool pollEvent(Common::Event &event);
virtual void pushEvent(const Common::Event &event);
virtual void purgeMouseEvents() override;

virtual Common::Point getMousePos() const { return _mousePos; }
virtual int getButtonState() const { return _buttonState; }
Expand Down
56 changes: 34 additions & 22 deletions backends/events/sdl/sdl-events.cpp
Expand Up @@ -75,7 +75,7 @@ static uint32 convUTF8ToUTF32(const char *src) {
#endif

SdlEventSource::SdlEventSource()
: EventSource(), _scrollLock(false), _joystick(0), _lastScreenID(0), _graphicsManager(0)
: EventSource(), _scrollLock(false), _joystick(0), _lastScreenID(0), _graphicsManager(0), _queuedFakeMouseMove(false)
#if SDL_VERSION_ATLEAST(2, 0, 0)
, _queuedFakeKeyUp(false), _fakeKeyUp()
#endif
Expand Down Expand Up @@ -158,7 +158,7 @@ int SdlEventSource::mapKey(SDLKey sdlKey, SDLMod mod, Uint16 unicode) {
} else if (key >= Common::KEYCODE_UP && key <= Common::KEYCODE_PAGEDOWN) {
return key;
} else if (unicode) {
// Return unicode in case it's stil set and wasn't filtered.
// Return unicode in case it's still set and wasn't filtered.
return unicode;
} else if (key >= 'a' && key <= 'z' && (mod & KMOD_SHIFT)) {
return key & ~0x20;
Expand All @@ -169,14 +169,15 @@ int SdlEventSource::mapKey(SDLKey sdlKey, SDLMod mod, Uint16 unicode) {
}
}

void SdlEventSource::processMouseEvent(Common::Event &event, int x, int y) {
bool SdlEventSource::processMouseEvent(Common::Event &event, int x, int y) {
event.mouse.x = x;
event.mouse.y = y;

if (_graphicsManager) {
_graphicsManager->notifyMousePos(Common::Point(x, y));
_graphicsManager->transformMouseCoordinates(event.mouse);
return _graphicsManager->notifyMousePosition(event.mouse);
}

return true;
}

bool SdlEventSource::handleKbdMouse(Common::Event &event) {
Expand Down Expand Up @@ -308,8 +309,7 @@ bool SdlEventSource::handleKbdMouse(Common::Event &event) {

if (_km.x != oldKmX || _km.y != oldKmY) {
event.type = Common::EVENT_MOUSEMOVE;
processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
return true;
return processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
}
}
}
Expand Down Expand Up @@ -508,6 +508,12 @@ bool SdlEventSource::pollEvent(Common::Event &event) {
return true;
}

if (_queuedFakeMouseMove) {
event = _fakeMouseMove;
_queuedFakeMouseMove = false;
return true;
}

SDL_Event ev;
while (SDL_PollEvent(&ev)) {
preprocessEvents(&ev);
Expand Down Expand Up @@ -549,7 +555,9 @@ bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
// with a mouse wheel event. However, SDL2 does not supply
// these, thus we use whatever we got last time. It seems
// these are always stored in _km.x, _km.y.
processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
if (!processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER)) {
return false;
}
if (yDir < 0) {
event.type = Common::EVENT_WHEELDOWN;
return true;
Expand Down Expand Up @@ -740,12 +748,12 @@ bool SdlEventSource::handleKeyUp(SDL_Event &ev, Common::Event &event) {

bool SdlEventSource::handleMouseMotion(SDL_Event &ev, Common::Event &event) {
event.type = Common::EVENT_MOUSEMOVE;
processMouseEvent(event, ev.motion.x, ev.motion.y);

// update KbdMouse
_km.x = ev.motion.x * MULTIPLIER;
_km.y = ev.motion.y * MULTIPLIER;

return true;
return processMouseEvent(event, ev.motion.x, ev.motion.y);
}

bool SdlEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &event) {
Expand All @@ -766,12 +774,11 @@ bool SdlEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &event)
else
return false;

processMouseEvent(event, ev.button.x, ev.button.y);
// update KbdMouse
_km.x = ev.button.x * MULTIPLIER;
_km.y = ev.button.y * MULTIPLIER;

return true;
return processMouseEvent(event, ev.button.x, ev.button.y);
}

bool SdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) {
Expand All @@ -785,21 +792,21 @@ bool SdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) {
#endif
else
return false;
processMouseEvent(event, ev.button.x, ev.button.y);

// update KbdMouse
_km.x = ev.button.x * MULTIPLIER;
_km.y = ev.button.y * MULTIPLIER;

return true;
return processMouseEvent(event, ev.button.x, ev.button.y);
}

bool SdlEventSource::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) {
if (ev.jbutton.button == JOY_BUT_LMOUSE) {
event.type = Common::EVENT_LBUTTONDOWN;
processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
return processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
} else if (ev.jbutton.button == JOY_BUT_RMOUSE) {
event.type = Common::EVENT_RBUTTONDOWN;
processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
return processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
} else {
event.type = Common::EVENT_KEYDOWN;
switch (ev.jbutton.button) {
Expand All @@ -820,17 +827,17 @@ bool SdlEventSource::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) {
event.kbd.ascii = mapKey(SDLK_F5, (SDLMod)ev.key.keysym.mod, 0);
break;
}
return true;
}
return true;
}

bool SdlEventSource::handleJoyButtonUp(SDL_Event &ev, Common::Event &event) {
if (ev.jbutton.button == JOY_BUT_LMOUSE) {
event.type = Common::EVENT_LBUTTONUP;
processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
return processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
} else if (ev.jbutton.button == JOY_BUT_RMOUSE) {
event.type = Common::EVENT_RBUTTONUP;
processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
return processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
} else {
event.type = Common::EVENT_KEYUP;
switch (ev.jbutton.button) {
Expand All @@ -851,8 +858,8 @@ bool SdlEventSource::handleJoyButtonUp(SDL_Event &ev, Common::Event &event) {
event.kbd.ascii = mapKey(SDLK_F5, (SDLMod)ev.key.keysym.mod, 0);
break;
}
return true;
}
return true;
}

bool SdlEventSource::handleJoyAxisMotion(SDL_Event &ev, Common::Event &event) {
Expand Down Expand Up @@ -968,9 +975,8 @@ bool SdlEventSource::remapKey(SDL_Event &ev, Common::Event &event) {
event.kbd.keycode = Common::KEYCODE_F5;
event.kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0);
}
// Nap center (space) to tab (default action )
// Map center (space) to tab (default action)
// I wanted to map the calendar button but the calendar comes up
//
else if (ev.key.keysym.sym == SDLK_SPACE) {
event.type = Common::EVENT_KEYDOWN;
event.kbd.keycode = Common::KEYCODE_TAB;
Expand Down Expand Up @@ -1003,6 +1009,12 @@ void SdlEventSource::resetKeyboardEmulation(int16 x_max, int16 y_max) {
_km.joy_y = 0;
}

void SdlEventSource::fakeWarpMouse(const int x, const int y) {
_queuedFakeMouseMove = true;
_fakeMouseMove.type = Common::EVENT_MOUSEMOVE;
_fakeMouseMove.mouse = Common::Point(x, y);
}

bool SdlEventSource::handleResizeEvent(Common::Event &event, int w, int h) {
if (_graphicsManager) {
_graphicsManager->notifyResize(w, h);
Expand Down
20 changes: 19 additions & 1 deletion backends/events/sdl/sdl-events.h
Expand Up @@ -51,6 +51,12 @@ class SdlEventSource : public Common::EventSource {
*/
virtual void resetKeyboardEmulation(int16 x_max, int16 y_max);

/**
* Emulates a mouse movement that would normally be caused by a mouse warp
* of the system mouse.
*/
void fakeWarpMouse(const int x, const int y);

protected:
/** @name Keyboard mouse emulation
* Disabled by fingolfin 2004-12-18.
Expand Down Expand Up @@ -117,7 +123,7 @@ class SdlEventSource : public Common::EventSource {
* Assigns the mouse coords to the mouse event. Furthermore notify the
* graphics manager about the position change.
*/
virtual void processMouseEvent(Common::Event &event, int x, int y);
virtual bool processMouseEvent(Common::Event &event, int x, int y);

/**
* Remaps key events. This allows platforms to configure
Expand Down Expand Up @@ -156,6 +162,18 @@ class SdlEventSource : public Common::EventSource {
*/
SDLKey obtainKeycode(const SDL_keysym keySym);

/**
* Whether _fakeMouseMove contains an event we need to send.
*/
bool _queuedFakeMouseMove;

/**
* A fake mouse motion event sent when the graphics manager is told to warp
* the mouse but the system mouse is unable to be warped (e.g. because the
* window is not focused).
*/
Common::Event _fakeMouseMove;

#if SDL_VERSION_ATLEAST(2, 0, 0)
/**
* Whether _fakeKeyUp contains an event we need to send.
Expand Down
8 changes: 0 additions & 8 deletions backends/graphics/dinguxsdl/dinguxsdl-graphics.cpp
Expand Up @@ -487,14 +487,6 @@ bool DINGUXSdlGraphicsManager::getFeatureState(OSystem::Feature f) {
}
}

SurfaceSdlGraphicsManager::MousePos *DINGUXSdlGraphicsManager::getMouseCurState() {
return &_mouseCurState;
}

SurfaceSdlGraphicsManager::VideoState *DINGUXSdlGraphicsManager::getVideoMode() {
return &_videoMode;
}

void DINGUXSdlGraphicsManager::warpMouse(int x, int y) {
if (_mouseCurState.x != x || _mouseCurState.y != y) {
if (_videoMode.mode == GFX_HALF && !_overlayVisible) {
Expand Down
37 changes: 17 additions & 20 deletions backends/graphics/dinguxsdl/dinguxsdl-graphics.h
Expand Up @@ -36,26 +36,23 @@ class DINGUXSdlGraphicsManager : public SurfaceSdlGraphicsManager {
public:
DINGUXSdlGraphicsManager(SdlEventSource *boss, SdlWindow *window);

bool hasFeature(OSystem::Feature f);
void setFeatureState(OSystem::Feature f, bool enable);
bool getFeatureState(OSystem::Feature f);
int getDefaultGraphicsMode() const;

void initSize(uint w, uint h);
const OSystem::GraphicsMode *getSupportedGraphicsModes() const;
bool setGraphicsMode(const char *name);
bool setGraphicsMode(int mode);
void setGraphicsModeIntern();
void internUpdateScreen();
void showOverlay();
void hideOverlay();
bool loadGFXMode();
void drawMouse();
void undrawMouse();
virtual void warpMouse(int x, int y);

SurfaceSdlGraphicsManager::MousePos *getMouseCurState();
SurfaceSdlGraphicsManager::VideoState *getVideoMode();
bool hasFeature(OSystem::Feature f) const override;
void setFeatureState(OSystem::Feature f, bool enable) override;
bool getFeatureState(OSystem::Feature f) override;
int getDefaultGraphicsMode() const override;

void initSize(uint w, uint h) override;
const OSystem::GraphicsMode *getSupportedGraphicsModes() const override;
bool setGraphicsMode(const char *name) override;
bool setGraphicsMode(int mode) override;
void setGraphicsModeIntern() override;
void internUpdateScreen() override;
void showOverlay() override;
void hideOverlay() override;
bool loadGFXMode() override;
void drawMouse() override;
void undrawMouse() override;
void warpMouse(int x, int y) override;

virtual void transformMouseCoordinates(Common::Point &point);
};
Expand Down
12 changes: 2 additions & 10 deletions backends/graphics/gph/gph-graphics.cpp
Expand Up @@ -477,7 +477,7 @@ bool GPHGraphicsManager::loadGFXMode() {
return true;
}

bool GPHGraphicsManager::hasFeature(OSystem::Feature f) {
bool GPHGraphicsManager::hasFeature(OSystem::Feature f) const {
return
(f == OSystem::kFeatureAspectRatioCorrection) ||
(f == OSystem::kFeatureCursorPalette);
Expand All @@ -497,7 +497,7 @@ void GPHGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) {
}
}

bool GPHGraphicsManager::getFeatureState(OSystem::Feature f) {
bool GPHGraphicsManager::getFeatureState(OSystem::Feature f) const {
assert(_transactionMode == kTransactionNone);

switch (f) {
Expand All @@ -510,14 +510,6 @@ bool GPHGraphicsManager::getFeatureState(OSystem::Feature f) {
}
}

SurfaceSdlGraphicsManager::MousePos *GPHGraphicsManager::getMouseCurState() {
return &_mouseCurState;
}

SurfaceSdlGraphicsManager::VideoState *GPHGraphicsManager::getVideoMode() {
return &_videoMode;
}

void GPHGraphicsManager::warpMouse(int x, int y) {
if (_mouseCurState.x != x || _mouseCurState.y != y) {
if (_videoMode.mode == GFX_HALF && !_overlayVisible) {
Expand Down
37 changes: 17 additions & 20 deletions backends/graphics/gph/gph-graphics.h
Expand Up @@ -35,26 +35,23 @@ class GPHGraphicsManager : public SurfaceSdlGraphicsManager {
public:
GPHGraphicsManager(SdlEventSource *boss, SdlWindow *window);

bool hasFeature(OSystem::Feature f);
void setFeatureState(OSystem::Feature f, bool enable);
bool getFeatureState(OSystem::Feature f);
int getDefaultGraphicsMode() const;

void initSize(uint w, uint h, const Graphics::PixelFormat *format = NULL);
const OSystem::GraphicsMode *getSupportedGraphicsModes() const;
bool setGraphicsMode(const char *name);
bool setGraphicsMode(int mode);
void setGraphicsModeIntern();
void internUpdateScreen();
void showOverlay();
void hideOverlay();
bool loadGFXMode();
void drawMouse();
void undrawMouse();
virtual void warpMouse(int x, int y);

SurfaceSdlGraphicsManager::MousePos *getMouseCurState();
SurfaceSdlGraphicsManager::VideoState *getVideoMode();
bool hasFeature(OSystem::Feature f) const override;
void setFeatureState(OSystem::Feature f, bool enable) override;
bool getFeatureState(OSystem::Feature f) const;
int getDefaultGraphicsMode() const override;

void initSize(uint w, uint h, const Graphics::PixelFormat *format = NULL) override;
const OSystem::GraphicsMode *getSupportedGraphicsModes() const override;
bool setGraphicsMode(const char *name) override;
bool setGraphicsMode(int mode) override;
void setGraphicsModeIntern() override;
void internUpdateScreen() override;
void showOverlay() override;
void hideOverlay() override;
bool loadGFXMode() override;
void drawMouse() override;
void undrawMouse() override;
void warpMouse(int x, int y) override;

virtual void transformMouseCoordinates(Common::Point &point);
};
Expand Down

0 comments on commit 7d8d2f8

Please sign in to comment.