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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
/* 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 "Rendering/GL/RenderDataBufferFwd.hpp"
#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 void InitStatic();
static void KillStatic();
void ChangeCursor(const std::string& cmdName, const float scale = 1.0f);
void ReloadCursors();
void ResetCursor() {
ChangeCursor("");
Update();
}
void Update();
void UpdateCursors();
void HideMouse();
void ShowMouse();
void ToggleMiddleClickScroll(); /// lock+hide
void CancelButtonMovement(int button) { buttons[button].movement = 0; }
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;
}
float3 GetCursorCameraDir(int x, int y) const;
float3 GetWorldMapPos() const;
std::string GetCurrentTooltip() const;
const std::string& GetCurrentCursor() const { return queuedCursorName; }
float GetCurrentCursorScale() const { return cursorScale; }
void ToggleHwCursor(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);
void DrawScrollCursor(GL::RenderDataBufferC* buffer);
void DrawFPSCursor(GL::RenderDataBufferC* buffer);
static void GetSelectionBoxCoeff(
const float3& pos1,
const float3& dir1,
const float3& pos2,
const float3& dir2,
float2& topright,
float2& bttmleft
);
public:
int lastx = -1;
int lasty = -1;
int activeButtonIdx = -1;
int activeCursorIdx = -1;
/// true if movement is locked, i.e. during MMB-scroll or in FPS-mode
bool locked = false;
/// stores if mouse was locked before going into FPS-mode,
/// so we can restore it when we return to normal control
bool wasLocked = false;
bool offscreen = false;
bool mmbScroll = false;
private:
bool hideCursor = true;
bool hwHideCursor = true;
bool hardwareCursor = false;
bool invertMouse = false;
bool ignoreMove = false;
float cursorScale = 1.0f;
float scrollx = 0.0f;
float scrolly = 0.0f;
public:
/// locked mouse indicator size
float crossSize = 0.0f;
float crossAlpha = 0.0f;
float crossMoveScale = 0.0f;
float doubleClickTime = 0.0f;
float scrollWheelSpeed = 0.0f;
float dragScrollThreshold = 0.0f;
int dragSelectionThreshold = 0;
int dragBoxCommandThreshold = 0;
int dragCircleCommandThreshold = 0;
int dragFrontCommandThreshold = 0;
struct ButtonPressEvt {
bool pressed = false;
bool chorded = false;
int x = 0;
int y = 0;
float3 camPos;
float3 dir;
float time = 0.0f;
float lastRelease = -20.0f;
int movement = 0;
};
ButtonPressEvt buttons[NUM_BUTTONS + 1]; /// One-bottomed.
float3 dir;
private:
std::string queuedCursorName; /// cursor changes are delayed until Update
std::string activeCursorName; /// 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 = nullptr;
};
extern CMouseHandler* mouse;
#endif /* MOUSEHANDLER_H */
|