2014-02-18 20:08:58 -05:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MADS_EVENTS_H
|
|
|
|
#define MADS_EVENTS_H
|
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
2014-04-08 22:04:43 -04:00
|
|
|
#include "common/events.h"
|
|
|
|
#include "common/stack.h"
|
2014-02-22 12:17:37 -05:00
|
|
|
#include "mads/assets.h"
|
2014-03-04 22:33:27 -05:00
|
|
|
#include "mads/sprites.h"
|
2014-02-18 20:08:58 -05:00
|
|
|
|
|
|
|
namespace MADS {
|
|
|
|
|
2014-05-08 11:43:23 +03:00
|
|
|
enum CursorType { CURSOR_NONE = 0, CURSOR_ARROW = 1, CURSOR_WAIT = 2, CURSOR_GO_DOWN = 3,
|
2014-02-22 11:13:35 -05:00
|
|
|
CURSOR_GO_UP = 4, CURSOR_GO_LEFT = 5, CURSOR_GO_RIGHT = 6 };
|
|
|
|
|
2014-05-02 21:29:33 -04:00
|
|
|
#define GAME_FRAME_RATE 50
|
2014-05-08 11:43:23 +03:00
|
|
|
#define GAME_FRAME_TIME (1000 / GAME_FRAME_RATE)
|
2014-05-02 21:29:33 -04:00
|
|
|
|
2014-02-18 20:08:58 -05:00
|
|
|
class MADSEngine;
|
|
|
|
|
2014-07-26 20:19:35 -04:00
|
|
|
class EventTarget {
|
|
|
|
public:
|
2014-07-27 20:40:05 +02:00
|
|
|
virtual ~EventTarget() {}
|
2014-07-26 20:19:35 -04:00
|
|
|
virtual bool onEvent(Common::Event &event) { return false; }
|
|
|
|
};
|
|
|
|
|
2014-02-18 20:08:58 -05:00
|
|
|
class EventsManager {
|
|
|
|
private:
|
|
|
|
MADSEngine *_vm;
|
2014-03-04 20:06:48 -05:00
|
|
|
uint32 _frameCounter;
|
2014-02-22 17:25:30 -05:00
|
|
|
uint32 _priorFrameTime;
|
|
|
|
Common::Point _mousePos;
|
2014-03-02 23:09:17 -05:00
|
|
|
Common::Point _currentPos;
|
2014-07-26 20:19:35 -04:00
|
|
|
EventTarget *_eventTarget;
|
2014-02-22 11:13:35 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the cursor image when the current cursor changes
|
|
|
|
*/
|
|
|
|
void changeCursor();
|
2014-02-22 12:17:37 -05:00
|
|
|
public:
|
|
|
|
SpriteAsset *_cursorSprites;
|
2014-03-03 00:42:41 -05:00
|
|
|
CursorType _cursorId;
|
|
|
|
CursorType _newCursorId;
|
2014-02-22 17:25:30 -05:00
|
|
|
bool _mouseClicked;
|
2014-03-02 23:09:17 -05:00
|
|
|
bool _mouseReleased;
|
|
|
|
byte _mouseButtons;
|
2014-04-05 14:27:33 -04:00
|
|
|
bool _rightMousePressed;
|
2014-04-08 22:04:43 -04:00
|
|
|
int _mouseStatus;
|
2014-03-02 23:09:17 -05:00
|
|
|
int _vD2;
|
2014-04-08 22:04:43 -04:00
|
|
|
int _mouseStatusCopy;
|
2014-03-22 12:02:17 -04:00
|
|
|
bool _mouseMoved;
|
2015-02-14 16:54:47 -05:00
|
|
|
Common::Stack<Common::KeyState> _pendingKeys;
|
2014-02-18 20:08:58 -05:00
|
|
|
public:
|
2014-02-22 11:13:35 -05:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2014-02-18 20:08:58 -05:00
|
|
|
EventsManager(MADSEngine *vm);
|
|
|
|
|
2014-02-22 11:13:35 -05:00
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
~EventsManager();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the sprite set containing the cursors
|
|
|
|
*/
|
|
|
|
void loadCursors(const Common::String &spritesName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the cursor
|
|
|
|
*/
|
|
|
|
void setCursor(CursorType cursorId);
|
|
|
|
|
2014-02-22 12:17:37 -05:00
|
|
|
/**
|
|
|
|
* Sets the cursor
|
|
|
|
*/
|
|
|
|
void setCursor2(CursorType cursorId);
|
|
|
|
|
2014-02-22 17:25:30 -05:00
|
|
|
/**
|
|
|
|
* Show the mouse cursor
|
|
|
|
*/
|
|
|
|
void showCursor();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide the mouse cursor
|
|
|
|
*/
|
|
|
|
void hideCursor();
|
|
|
|
|
2014-04-29 12:56:22 +03:00
|
|
|
/**
|
|
|
|
* Returns if the mouse cursor is visible
|
|
|
|
*/
|
|
|
|
bool isCursorVisible();
|
|
|
|
|
2014-02-23 19:33:26 -05:00
|
|
|
/**
|
2014-03-27 21:04:27 -04:00
|
|
|
* Shows the wait cursor
|
2014-02-23 19:33:26 -05:00
|
|
|
*/
|
2014-03-27 21:04:27 -04:00
|
|
|
void waitCursor();
|
2014-02-23 19:33:26 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Free currently loaded cursors
|
|
|
|
*/
|
|
|
|
void freeCursors();
|
|
|
|
|
2014-02-22 17:25:30 -05:00
|
|
|
/**
|
|
|
|
* Poll any pending events
|
|
|
|
*/
|
|
|
|
void pollEvents();
|
|
|
|
|
2014-07-26 20:19:35 -04:00
|
|
|
/**
|
|
|
|
* Sets an event handler other than the events manager
|
|
|
|
*/
|
|
|
|
void setEventTarget(EventTarget *target) { _eventTarget = target; }
|
|
|
|
|
2014-02-22 17:25:30 -05:00
|
|
|
/**
|
|
|
|
* Return the current mouse position
|
|
|
|
*/
|
|
|
|
Common::Point mousePos() const { return _mousePos; }
|
|
|
|
|
2014-03-02 23:09:17 -05:00
|
|
|
/**
|
|
|
|
* Return the current mouse position
|
|
|
|
*/
|
|
|
|
Common::Point currentPos() const { return _currentPos; }
|
|
|
|
|
2014-02-22 17:25:30 -05:00
|
|
|
/**
|
|
|
|
* Delay for a given number of frames
|
|
|
|
*/
|
|
|
|
void delay(int amount);
|
2014-03-02 10:49:20 -05:00
|
|
|
|
2014-03-04 20:06:48 -05:00
|
|
|
/**
|
|
|
|
* Wait for the next frame
|
|
|
|
*/
|
|
|
|
void waitForNextFrame();
|
|
|
|
|
2014-07-18 20:20:18 -04:00
|
|
|
/**
|
|
|
|
* Checks for whether the next game frame number has been reached.
|
|
|
|
*/
|
|
|
|
bool checkForNextFrameCounter();
|
|
|
|
|
2014-03-02 10:49:20 -05:00
|
|
|
/**
|
|
|
|
* Gets the current frame counter
|
|
|
|
*/
|
2014-03-04 20:06:48 -05:00
|
|
|
uint32 getFrameCounter() const { return _frameCounter; }
|
2014-03-02 19:29:54 -05:00
|
|
|
|
|
|
|
void initVars();
|
2014-04-08 22:04:43 -04:00
|
|
|
|
|
|
|
/**
|
2014-05-08 11:43:23 +03:00
|
|
|
* Returns true if there's any pending keys to be processed
|
2014-04-08 22:04:43 -04:00
|
|
|
*/
|
|
|
|
bool isKeyPressed() const { return !_pendingKeys.empty(); }
|
2015-02-14 16:54:47 -05:00
|
|
|
|
|
|
|
Common::KeyState getKey() { return _pendingKeys.pop(); }
|
2014-02-18 20:08:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace MADS
|
|
|
|
|
|
|
|
#endif /* MADS_EVENTS_H */
|