Skip to content

Commit

Permalink
MORTEVIELLE: Expand on the mouse/keyboard handling code
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster authored and Strangerke committed Apr 6, 2012
1 parent 471ada7 commit 8a2d928
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 62 deletions.
74 changes: 62 additions & 12 deletions engines/mortevielle/mortevielle.cpp
Expand Up @@ -40,6 +40,7 @@ MortevielleEngine::MortevielleEngine(OSystem *system, const ADGameDescription *g
Engine(system), _gameDescription(gameDesc) {
g_vm = this;
_lastGameFrame = 0;
_mouseButtons = 0;
}

MortevielleEngine::~MortevielleEngine() {
Expand Down Expand Up @@ -164,11 +165,19 @@ bool MortevielleEngine::handleEvents() {
case Common::EVENT_LBUTTONUP:
case Common::EVENT_RBUTTONDOWN:
case Common::EVENT_RBUTTONUP:
case Common::EVENT_MBUTTONDOWN:
case Common::EVENT_MBUTTONUP:
case Common::EVENT_MOUSEMOVE:
_mousePos = event.mouse;
x_s = event.mouse.x;
y_s = event.mouse.y;

if (event.type == Common::EVENT_LBUTTONDOWN)
_mouseButtons |= 1;
else if (event.type == Common::EVENT_LBUTTONUP)
_mouseButtons &= ~1;
else if (event.type == Common::EVENT_RBUTTONDOWN)
_mouseButtons |= 2;
else if (event.type == Common::EVENT_RBUTTONUP)
_mouseButtons &= ~2;
break;

case Common::EVENT_KEYDOWN:
Expand All @@ -182,20 +191,57 @@ bool MortevielleEngine::handleEvents() {
}

/**
* Add the specified key to the event queue
* Add the specified key to the pending keypress stack
*/
void MortevielleEngine::addKeypress(Common::Event &evt) {
// Check for control keypresses
if (evt.kbd.hasFlags(Common::KBD_CTRL) && (evt.kbd.keycode >= Common::KEYCODE_a) &&
(evt.kbd.keycode <= Common::KEYCODE_z)) {
_keypresses.push(evt.kbd.keycode - Common::KEYCODE_a + 1);
return;
// Character to add
char ch = evt.kbd.ascii;

// Handle alphabetic keys
if ((evt.kbd.keycode >= Common::KEYCODE_a) && (evt.kbd.keycode <= Common::KEYCODE_z)) {
if (evt.kbd.hasFlags(Common::KBD_CTRL))
ch = evt.kbd.keycode - Common::KEYCODE_a + 1;
else
ch = evt.kbd.keycode - Common::KEYCODE_a + 'A';
} else if ((evt.kbd.keycode >= Common::KEYCODE_F1) && (evt.kbd.keycode <= Common::KEYCODE_F12)) {
// Handle function keys
ch = 59 + evt.kbd.keycode - Common::KEYCODE_F1;
} else {
// Series of special cases
switch (evt.kbd.keycode) {
case Common::KEYCODE_KP4:
case Common::KEYCODE_LEFT:
ch = '4';
case Common::KEYCODE_KP2:
case Common::KEYCODE_DOWN:
ch = '2';
case Common::KEYCODE_KP6:
case Common::KEYCODE_RIGHT:
ch = '6';
case Common::KEYCODE_KP8:
case Common::KEYCODE_UP:
ch = '8';
case Common::KEYCODE_KP7:
ch = '7';
case Common::KEYCODE_KP1:
ch = '1';
case Common::KEYCODE_KP9:
ch = '9';
case Common::KEYCODE_KP3:
ch = '3';
case Common::KEYCODE_KP5:
ch = '5';
case Common::KEYCODE_RETURN:
ch = '\13';
case Common::KEYCODE_ESCAPE:
ch = '\33';
default:
break;
}
}

// Handle function keys
if ((evt.kbd.keycode >= Common::KEYCODE_F1) && (evt.kbd.keycode <= Common::KEYCODE_F12)) {
_keypresses.push(59 + evt.kbd.keycode - Common::KEYCODE_F1);
}
if (ch != 0)
_keypresses.push(ch);
}

static byte CURSOR_ARROW_DATA[16 * 16] = {
Expand Down Expand Up @@ -225,6 +271,10 @@ void MortevielleEngine::initMouse() {
CursorMan.showMouse(true);
}

void MortevielleEngine::setMousePos(const Common::Point &pt) {
_mousePos = pt;
}

/*-------------------------------------------------------------------------*/

Common::Error MortevielleEngine::run() {
Expand Down
5 changes: 5 additions & 0 deletions engines/mortevielle/mortevielle.h
Expand Up @@ -51,6 +51,8 @@ class MortevielleEngine : public Engine {
const ADGameDescription *_gameDescription;
Common::Stack<int> _keypresses;
uint32 _lastGameFrame;
int _mouseButtons;
Common::Point _mousePos;

Common::ErrorCode initialise();
Common::ErrorCode loadMortDat();
Expand All @@ -70,6 +72,9 @@ class MortevielleEngine : public Engine {

bool keyPressed();
int getChar();
Common::Point getMousePos() const { return _mousePos; }
void setMousePos(const Common::Point &pt);
int getMouseButtons() const { return _mouseButtons; }
};

extern MortevielleEngine *g_vm;
Expand Down
62 changes: 12 additions & 50 deletions engines/mortevielle/mouse.cpp
Expand Up @@ -28,6 +28,7 @@
#include "common/endian.h"
#include "common/rect.h"
#include "mortevielle/mouse.h"
#include "mortevielle/mortevielle.h"
#include "mortevielle/var_mor.h"

namespace Mortevielle {
Expand Down Expand Up @@ -271,67 +272,28 @@ void pos_mouse(int x, int y) {
if (y > 199) y = 199;
else if (y < 0) y = 0;
if ((x == x_s) && (y == y_s)) return;
if (int_m) {
{
reg.ax = 4;
reg.cx = x;
reg.dx = y;
}
intr(0x33, reg);
}
hide_mouse();
x_s = x;
y_s = y;
switch (gd) {
case ams : {
p_o_s = ((uint)y_s >> 1) * 80 + ((uint)x_s >> 3) + (y_s & 1) * 0x2000;
}
break;
/*cga : begin
P_O_S:=(Y_S shr 1)*80+X_S shr 2+(Y_S and 1)*$2000;
end;*/
case ega : {
p_o_s = y_s * 80 + ((uint)x_s >> 3);
}
break;
} /* case Gd */
show_mouse();

// Set the new position
g_vm->setMousePos(Common::Point(x, y));
}

void read_pos_mouse(int &x, int &y, int &c) {
registres reg;

if (int_m) {
reg.ax = 3;
intr(0x33, reg);
x = reg.cx;
y = reg.dx;
c = reg.bx;
} else {
c = 0;
x = x_s;
y = y_s;
}
x = g_vm->getMousePos().x;
y = g_vm->getMousePos().y;
c = g_vm->getMouseButtons();
}

void mov_mouse(bool &funct, char &key) {
bool p_key;
char in1, in2;
int x, y, cx, cy, cd;
registres reg;

if (int_m) {
reg.ax = 3;
intr(0x33, reg);
x = reg.cx;
y = reg.dx;
cd = reg.bx;
pos_mouse(x, y);
if (cd != 0) {
clic = true;
return;
}
// If mouse button clicked, return it
if (g_vm->getMouseButtons() != 0) {
clic = true;
return;
}

funct = false;
key = '\377';
p_key = keypressed();
Expand Down

0 comments on commit 8a2d928

Please sign in to comment.