1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef MOUSEHANDLER_H
#define MOUSEHANDLER_H
#include <string>
#include <vector>
#include "System/float3.h"
#include "System/type2.h"
#include "System/UnorderedMap.hpp"
#include "MouseCursor.h"
static const int NUM_BUTTONS = 10;
class CInputReceiver;
class CCameraController;
class CUnit;
class CMouseHandler
{
public:
CMouseHandler();
~CMouseHandler();
static CMouseHandler* GetOrReloadInstance();
void ChangeCursor(const std::string& cmdName, const float scale = 1.0f);
void ReloadCursors();
void Update();
void UpdateCursors();
std::string GetCurrentTooltip();
void HideMouse();
void ShowMouse();
void ToggleMiddleClickScroll(); /// lock+hide
void WarpMouse(int x, int y);
void DrawSelectionBox(); /// draw mousebox (selection box)
void DrawCursor();
void MouseRelease(int x, int y, int button);
void MousePress(int x, int y, int button);
void MouseMove(int x, int y, int dx, int dy);
void MouseWheel(float delta);
bool AssignMouseCursor(const std::string& cmdName,
const std::string& fileName,
CMouseCursor::HotSpot hotSpot,
bool overwrite);
bool ReplaceMouseCursor(const std::string& oldName,
const std::string& newName,
CMouseCursor::HotSpot hotSpot);
const CMouseCursor* FindCursor(const std::string& cursorName) const {
const auto it = cursorCommandMap.find(cursorName);
if (it != cursorCommandMap.end())
return &loadedCursors[it->second];
return nullptr;
}
const std::string& GetCurrentCursor() const { return newCursor; }
const float& GetCurrentCursorScale() const { return cursorScale; }
void ToggleHwCursor(const bool& enable);
/// @see ConfigHandler::ConfigNotifyCallback
void ConfigNotify(const std::string& key, const std::string& value);
private:
void SetCursor(const std::string& cmdName, const bool forceRebind = false);
static void GetSelectionBoxCoeff(const float3& pos1, const float3& dir1, const float3& pos2, const float3& dir2, float2& topright, float2& btmleft);
void DrawScrollCursor();
void DrawFPSCursor();
public:
int lastx;
int lasty;
int activeButtonIdx;
int activeCursorIdx;
bool locked;
/// Stores if the mouse was locked or not before going into direct control,
/// so we can restore it when we return to normal.
bool wasLocked;
bool offscreen;
private:
bool hide;
bool hwHide;
bool hardwareCursor;
bool invertMouse;
float cursorScale;
float dragScrollThreshold;
float scrollx;
float scrolly;
public:
float doubleClickTime;
float scrollWheelSpeed;
/// locked mouse indicator size
float crossSize;
float crossAlpha;
float crossMoveScale;
struct ButtonPressEvt {
bool pressed;
bool chorded;
int x;
int y;
float3 camPos;
float3 dir;
float time;
float lastRelease;
int movement;
};
ButtonPressEvt buttons[NUM_BUTTONS + 1]; /// One-bottomed.
float3 dir;
private:
std::string newCursor; /// cursor changes are delayed
std::string cursorText; /// current cursor name
std::vector<CMouseCursor> loadedCursors;
spring::unordered_map<std::string, size_t> cursorFileMap;
spring::unordered_map<std::string, size_t> cursorCommandMap;
const CUnit* lastClicked;
};
extern CMouseHandler* mouse;
#endif /* MOUSEHANDLER_H */
|