2009-04-15 17:03:31 +03:00
|
|
|
/*
|
2017-07-13 10:26:03 +02:00
|
|
|
* CCursorHandler.h, part of VCMI engine
|
2009-04-15 17:03:31 +03:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
2009-04-16 14:14:13 +03:00
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
2023-01-05 19:03:27 +02:00
|
|
|
|
2018-07-25 00:36:48 +02:00
|
|
|
class CIntObject;
|
2017-07-13 10:26:03 +02:00
|
|
|
class CAnimImage;
|
|
|
|
struct SDL_Surface;
|
2018-07-25 00:36:48 +02:00
|
|
|
struct SDL_Texture;
|
2023-01-05 19:03:27 +02:00
|
|
|
|
|
|
|
#include "Geometries.h"
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2022-12-18 22:32:07 +02:00
|
|
|
namespace Cursor
|
2012-03-31 00:36:07 +03:00
|
|
|
{
|
2022-12-18 22:32:07 +02:00
|
|
|
enum class Type {
|
2022-12-16 11:22:58 +02:00
|
|
|
ADVENTURE, // set of various cursors for adventure map
|
|
|
|
COMBAT, // set of various cursors for combat
|
2022-12-18 17:13:34 +02:00
|
|
|
DEFAULT, // default arrow and hourglass cursors
|
2022-12-16 11:22:58 +02:00
|
|
|
SPELLBOOK // animated cursor for spellcasting
|
|
|
|
};
|
2012-03-31 00:36:07 +03:00
|
|
|
|
2022-12-18 22:32:07 +02:00
|
|
|
enum class Default {
|
|
|
|
POINTER = 0,
|
|
|
|
//ARROW_COPY = 1, // probably unused
|
|
|
|
HOURGLASS = 2,
|
2022-12-18 17:13:34 +02:00
|
|
|
};
|
|
|
|
|
2022-12-18 22:32:07 +02:00
|
|
|
enum class Combat {
|
|
|
|
INVALID = -1,
|
|
|
|
|
|
|
|
BLOCKED = 0,
|
|
|
|
MOVE = 1,
|
|
|
|
FLY = 2,
|
|
|
|
SHOOT = 3,
|
|
|
|
HERO = 4,
|
|
|
|
QUERY = 5,
|
|
|
|
POINTER = 6,
|
|
|
|
HIT_NORTHEAST = 7,
|
|
|
|
HIT_EAST = 8,
|
|
|
|
HIT_SOUTHEAST = 9,
|
|
|
|
HIT_SOUTHWEST = 10,
|
|
|
|
HIT_WEST = 11,
|
|
|
|
HIT_NORTHWEST = 12,
|
|
|
|
HIT_NORTH = 13,
|
|
|
|
HIT_SOUTH = 14,
|
|
|
|
SHOOT_PENALTY = 15,
|
|
|
|
SHOOT_CATAPULT = 16,
|
|
|
|
HEAL = 17,
|
|
|
|
SACRIFICE = 18,
|
2023-01-05 19:03:27 +02:00
|
|
|
TELEPORT = 19,
|
|
|
|
|
|
|
|
COUNT
|
2022-12-16 11:22:58 +02:00
|
|
|
};
|
2022-12-18 17:13:34 +02:00
|
|
|
|
2022-12-18 22:32:07 +02:00
|
|
|
enum class Map {
|
|
|
|
POINTER = 0,
|
|
|
|
HOURGLASS = 1,
|
|
|
|
HERO = 2,
|
|
|
|
TOWN = 3,
|
|
|
|
T1_MOVE = 4,
|
|
|
|
T1_ATTACK = 5,
|
|
|
|
T1_SAIL = 6,
|
|
|
|
T1_DISEMBARK = 7,
|
|
|
|
T1_EXCHANGE = 8,
|
|
|
|
T1_VISIT = 9,
|
|
|
|
T2_MOVE = 10,
|
|
|
|
T2_ATTACK = 11,
|
|
|
|
T2_SAIL = 12,
|
|
|
|
T2_DISEMBARK = 13,
|
|
|
|
T2_EXCHANGE = 14,
|
|
|
|
T2_VISIT = 15,
|
|
|
|
T3_MOVE = 16,
|
|
|
|
T3_ATTACK = 17,
|
|
|
|
T3_SAIL = 18,
|
|
|
|
T3_DISEMBARK = 19,
|
|
|
|
T3_EXCHANGE = 20,
|
|
|
|
T3_VISIT = 21,
|
|
|
|
T4_MOVE = 22,
|
|
|
|
T4_ATTACK = 23,
|
|
|
|
T4_SAIL = 24,
|
|
|
|
T4_DISEMBARK = 25,
|
|
|
|
T4_EXCHANGE = 26,
|
|
|
|
T4_VISIT = 27,
|
|
|
|
T1_SAIL_VISIT = 28,
|
|
|
|
T2_SAIL_VISIT = 29,
|
|
|
|
T3_SAIL_VISIT = 30,
|
|
|
|
T4_SAIL_VISIT = 31,
|
|
|
|
SCROLL_NORTH = 32,
|
|
|
|
SCROLL_NORTHEAST = 33,
|
|
|
|
SCROLL_EAST = 34,
|
|
|
|
SCROLL_SOUTHEAST = 35,
|
|
|
|
SCROLL_SOUTH = 36,
|
|
|
|
SCROLL_SOUTHWEST = 37,
|
|
|
|
SCROLL_WEST = 38,
|
|
|
|
SCROLL_NORTHWEST = 39,
|
|
|
|
//POINTER_COPY = 40, // probably unused
|
|
|
|
TELEPORT = 41,
|
2023-01-05 19:03:27 +02:00
|
|
|
SCUTTLE_BOAT = 42,
|
|
|
|
|
|
|
|
COUNT
|
2022-12-18 22:32:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class Spellcast {
|
|
|
|
SPELL = 0,
|
2022-12-18 17:13:34 +02:00
|
|
|
};
|
2012-03-31 00:36:07 +03:00
|
|
|
}
|
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// handles mouse cursor
|
2016-10-28 13:03:26 +02:00
|
|
|
class CCursorHandler final
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
2018-07-25 00:36:48 +02:00
|
|
|
bool needUpdate;
|
|
|
|
SDL_Texture * cursorLayer;
|
|
|
|
|
|
|
|
SDL_Surface * buffer;
|
2012-12-14 18:32:53 +03:00
|
|
|
CAnimImage * currentCursor;
|
2016-10-28 12:39:16 +02:00
|
|
|
|
|
|
|
std::unique_ptr<CAnimImage> dndObject; //if set, overrides currentCursor
|
2016-10-28 13:03:26 +02:00
|
|
|
|
|
|
|
std::array<std::unique_ptr<CAnimImage>, 4> cursors;
|
|
|
|
|
2012-12-14 18:32:53 +03:00
|
|
|
bool showing;
|
|
|
|
|
2018-07-25 00:36:48 +02:00
|
|
|
void clearBuffer();
|
|
|
|
void updateBuffer(CIntObject * payload);
|
|
|
|
void replaceBuffer(CIntObject * payload);
|
|
|
|
|
|
|
|
void updateTexture();
|
2012-12-14 18:32:53 +03:00
|
|
|
|
|
|
|
/// Current cursor
|
2022-12-18 22:32:07 +02:00
|
|
|
Cursor::Type type;
|
2012-12-14 18:32:53 +03:00
|
|
|
size_t frame;
|
2022-12-18 22:32:07 +02:00
|
|
|
float frameTime;
|
2012-12-14 18:32:53 +03:00
|
|
|
|
2022-12-18 22:32:07 +02:00
|
|
|
void changeGraphic(Cursor::Type type, size_t index);
|
2012-12-14 18:32:53 +03:00
|
|
|
|
2022-12-18 22:32:07 +02:00
|
|
|
/// position of cursor
|
2023-01-05 19:03:27 +02:00
|
|
|
Point pos;
|
|
|
|
|
|
|
|
Point getPivotOffsetDefault(size_t index);
|
|
|
|
Point getPivotOffsetMap(size_t index);
|
|
|
|
Point getPivotOffsetCombat(size_t index);
|
|
|
|
Point getPivotOffsetSpellcast();
|
|
|
|
Point getPivotOffset();
|
2022-12-18 22:32:07 +02:00
|
|
|
|
2023-01-05 19:03:27 +02:00
|
|
|
void updateSpellcastCursor();
|
2022-12-18 22:32:07 +02:00
|
|
|
public:
|
|
|
|
CCursorHandler();
|
|
|
|
~CCursorHandler();
|
2012-12-14 18:32:53 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces the cursor with a custom image.
|
|
|
|
*
|
2013-06-26 14:18:27 +03:00
|
|
|
* @param image Image to replace cursor with or nullptr to use the normal
|
2012-12-14 18:32:53 +03:00
|
|
|
* cursor. CursorHandler takes ownership of object
|
|
|
|
*/
|
2016-10-28 12:39:16 +02:00
|
|
|
void dragAndDropCursor (std::unique_ptr<CAnimImage> image);
|
|
|
|
|
2022-12-18 22:32:07 +02:00
|
|
|
/// Returns current position of the cursor
|
|
|
|
Point position() const;
|
|
|
|
|
|
|
|
/// Changes cursor to specified index
|
|
|
|
void set(Cursor::Default index);
|
|
|
|
void set(Cursor::Map index);
|
|
|
|
void set(Cursor::Combat index);
|
|
|
|
void set(Cursor::Spellcast index);
|
|
|
|
|
|
|
|
/// Returns current index of cursor
|
|
|
|
template<typename Index>
|
|
|
|
Index get()
|
|
|
|
{
|
|
|
|
assert((std::is_same<Index, Cursor::Default>::value )|| type != Cursor::Type::DEFAULT );
|
|
|
|
assert((std::is_same<Index, Cursor::Map>::value )|| type != Cursor::Type::ADVENTURE );
|
|
|
|
assert((std::is_same<Index, Cursor::Combat>::value )|| type != Cursor::Type::COMBAT );
|
|
|
|
assert((std::is_same<Index, Cursor::Spellcast>::value )|| type != Cursor::Type::SPELLBOOK );
|
|
|
|
|
|
|
|
return static_cast<Index>(frame);
|
|
|
|
}
|
|
|
|
|
2014-07-03 14:10:01 +03:00
|
|
|
void render();
|
2009-08-30 15:47:40 +03:00
|
|
|
|
2018-07-25 00:36:48 +02:00
|
|
|
void hide() { showing=false; };
|
|
|
|
void show() { showing=true; };
|
2012-12-14 18:32:53 +03:00
|
|
|
|
|
|
|
/// change cursor's positions to (x, y)
|
|
|
|
void cursorMove(const int & x, const int & y);
|
|
|
|
/// Move cursor to screen center
|
2011-04-05 20:38:24 +03:00
|
|
|
void centerCursor();
|
2012-12-14 18:32:53 +03:00
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|