mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-12 12:09:15 +00:00
Myst3 : Mouse movement. Had to hack a bit the SDL backend ...
This commit is contained in:
parent
8f25d71cdf
commit
6ca044fea3
@ -92,9 +92,11 @@ int SdlEventSource::mapKey(SDLKey key, SDLMod mod, Uint16 unicode) {
|
||||
return key;
|
||||
}
|
||||
|
||||
void SdlEventSource::fillMouseEvent(Common::Event &event, int x, int y) {
|
||||
void SdlEventSource::fillMouseEvent(Common::Event &event, int x, int y, int relx, int rely) {
|
||||
event.mouse.x = x;
|
||||
event.mouse.y = y;
|
||||
event.relMouse.x = relx;
|
||||
event.relMouse.y = rely;
|
||||
|
||||
// Update the "keyboard mouse" coords
|
||||
_km.x = x;
|
||||
@ -363,7 +365,7 @@ bool SdlEventSource::handleKeyUp(SDL_Event &ev, Common::Event &event) {
|
||||
|
||||
bool SdlEventSource::handleMouseMotion(SDL_Event &ev, Common::Event &event) {
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
fillMouseEvent(event, ev.motion.x, ev.motion.y);
|
||||
fillMouseEvent(event, ev.motion.x, ev.motion.y, ev.motion.xrel, ev.motion.yrel);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -386,7 +388,7 @@ bool SdlEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &event)
|
||||
else
|
||||
return false;
|
||||
|
||||
fillMouseEvent(event, ev.button.x, ev.button.y);
|
||||
fillMouseEvent(event, ev.button.x, ev.button.y, 0, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -402,7 +404,7 @@ bool SdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) {
|
||||
#endif
|
||||
else
|
||||
return false;
|
||||
fillMouseEvent(event, ev.button.x, ev.button.y);
|
||||
fillMouseEvent(event, ev.button.x, ev.button.y, 0, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -410,10 +412,10 @@ bool SdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) {
|
||||
bool SdlEventSource::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) {
|
||||
if (ev.jbutton.button == JOY_BUT_LMOUSE) {
|
||||
event.type = Common::EVENT_LBUTTONDOWN;
|
||||
fillMouseEvent(event, _km.x, _km.y);
|
||||
fillMouseEvent(event, _km.x, _km.y, 0, 0);
|
||||
} else if (ev.jbutton.button == JOY_BUT_RMOUSE) {
|
||||
event.type = Common::EVENT_RBUTTONDOWN;
|
||||
fillMouseEvent(event, _km.x, _km.y);
|
||||
fillMouseEvent(event, _km.x, _km.y, 0, 0);
|
||||
} else {
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
switch (ev.jbutton.button) {
|
||||
@ -441,10 +443,10 @@ bool SdlEventSource::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) {
|
||||
bool SdlEventSource::handleJoyButtonUp(SDL_Event &ev, Common::Event &event) {
|
||||
if (ev.jbutton.button == JOY_BUT_LMOUSE) {
|
||||
event.type = Common::EVENT_LBUTTONUP;
|
||||
fillMouseEvent(event, _km.x, _km.y);
|
||||
fillMouseEvent(event, _km.x, _km.y, 0, 0);
|
||||
} else if (ev.jbutton.button == JOY_BUT_RMOUSE) {
|
||||
event.type = Common::EVENT_RBUTTONUP;
|
||||
fillMouseEvent(event, _km.x, _km.y);
|
||||
fillMouseEvent(event, _km.x, _km.y, 0, 0);
|
||||
} else {
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
switch (ev.jbutton.button) {
|
||||
@ -512,7 +514,7 @@ bool SdlEventSource::handleJoyAxisMotion(SDL_Event &ev, Common::Event &event) {
|
||||
#endif
|
||||
}
|
||||
|
||||
fillMouseEvent(event, _km.x, _km.y);
|
||||
fillMouseEvent(event, _km.x, _km.y, 0, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ protected:
|
||||
/**
|
||||
* Assigns the mouse coords to the mouse event
|
||||
*/
|
||||
virtual void fillMouseEvent(Common::Event &event, int x, int y);
|
||||
virtual void fillMouseEvent(Common::Event &event, int x, int y, int relx, int rely);
|
||||
|
||||
/**
|
||||
* Remaps key events. This allows platforms to configure
|
||||
|
@ -68,6 +68,8 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou
|
||||
sdlFlags ^= SDL_INIT_VIDEO;
|
||||
}
|
||||
#endif
|
||||
|
||||
// SDL_ShowCursor(SDL_DISABLE);
|
||||
}
|
||||
|
||||
SurfaceSdlGraphicsManager::~SurfaceSdlGraphicsManager() {
|
||||
|
@ -99,6 +99,11 @@ struct Event {
|
||||
*/
|
||||
Common::Point mouse;
|
||||
|
||||
/**
|
||||
* Mouse movement since the last mouse movement event.
|
||||
*/
|
||||
Common::Point relMouse;
|
||||
|
||||
Event() : type(EVENT_INVALID), synthetic(false) {}
|
||||
};
|
||||
|
||||
|
@ -66,6 +66,7 @@ Common::Error Myst3Engine::run() {
|
||||
}
|
||||
|
||||
_system->setupScreen(w, h, false, true);
|
||||
_system->showMouse(false);
|
||||
|
||||
_scene.init(w, h);
|
||||
|
||||
@ -76,8 +77,11 @@ Common::Error Myst3Engine::run() {
|
||||
Common::Event event;
|
||||
while (_system->getEventManager()->pollEvent(event)) {
|
||||
// Check for "Hard" quit"
|
||||
if (event.type == Common::EVENT_QUIT)
|
||||
if (event.type == Common::EVENT_QUIT) {
|
||||
return Common::kNoError;
|
||||
} else if (event.type == Common::EVENT_MOUSEMOVE) {
|
||||
_scene.updateCamera(event.relMouse);
|
||||
}
|
||||
}
|
||||
|
||||
_scene.clear();
|
||||
|
@ -53,8 +53,13 @@ void Scene::setupCamera() {
|
||||
glLoadIdentity();
|
||||
glRotatef(_cameraPitch, 1.0f, 0.0f, 0.0f);
|
||||
glRotatef(_cameraYaw, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
_cameraYaw += 0.1f;
|
||||
}
|
||||
|
||||
void Scene::updateCamera(Common::Point &mouse) {
|
||||
_cameraYaw += mouse.x / 3.0f;
|
||||
_cameraPitch += mouse.y / 3.0f;
|
||||
|
||||
_cameraPitch = CLIP(_cameraPitch, -90.0f, 90.0f);
|
||||
}
|
||||
|
||||
} // end of namespace Myst3
|
||||
|
@ -33,17 +33,21 @@
|
||||
#include <GL/glu.h>
|
||||
#endif
|
||||
|
||||
#include "common/rect.h"
|
||||
|
||||
namespace Myst3 {
|
||||
|
||||
class Scene {
|
||||
private:
|
||||
float _cameraPitch;
|
||||
float _cameraYaw;
|
||||
Common::Point _mouseOld;
|
||||
|
||||
public:
|
||||
void init(int width, int height);
|
||||
void clear();
|
||||
void setupCamera();
|
||||
void updateCamera(Common::Point &mouse);
|
||||
};
|
||||
|
||||
} // end of namespace Myst3
|
||||
|
Loading…
Reference in New Issue
Block a user