1/*
2 * LegacyClonk
3 *
4 * Copyright (c) 1998-2000, Matthes Bender (RedWolf Design)
5 * Copyright (c) 2017-2019, The LegacyClonk Team and contributors
6 *
7 * Distributed under the terms of the ISC license; see accompanying file
8 * "COPYING" for details.
9 *
10 * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11 * See accompanying file "TRADEMARK" for details.
12 *
13 * To redistribute this file separately, substitute the full license texts
14 * for the above references.
15 */
16
17/* Mouse input */
18
19#pragma once
20
21#include "C4ObjectList.h"
22#include "C4Player.h"
23#include "C4Region.h"
24
25const int32_t C4MC_Button_None = 0,
26 C4MC_Button_LeftDown = 1,
27 C4MC_Button_LeftUp = 2,
28 C4MC_Button_RightDown = 3,
29 C4MC_Button_RightUp = 4,
30 C4MC_Button_LeftDouble = 5,
31 C4MC_Button_RightDouble = 6,
32 C4MC_Button_Wheel = 7,
33 C4MC_Button_MiddleDown = 8,
34 C4MC_Button_MiddleUp = 9;
35
36const int32_t C4MC_DragSensitivity = 5;
37
38class C4MouseControl
39{
40 friend class C4Viewport;
41
42public:
43 C4MouseControl();
44 ~C4MouseControl();
45
46protected:
47 bool Active;
48 bool fMouseOwned;
49 int32_t Player;
50 C4Player *pPlayer; // valid during Move()
51 C4Viewport *Viewport; // valid during Move()
52 std::string Caption;
53 bool IsHelpCaption;
54 int32_t Cursor;
55 int32_t DownCursor;
56 int32_t CaptionBottomY;
57 int32_t VpX, VpY, X, Y, ViewX, ViewY;
58 C4Facet fctViewport;
59 int32_t DownX, DownY, DownOffsetX, DownOffsetY;
60 int32_t ShowPointX, ShowPointY;
61 int32_t KeepCaption;
62 int32_t ScrollSpeed;
63 int32_t Drag, DragSelecting;
64 int32_t DragImagePhase;
65 bool LeftButtonDown, RightButtonDown, LeftDoubleIgnoreUp;
66 bool ControlDown;
67 bool ShiftDown;
68 bool Scrolling;
69 bool InitCentered;
70 bool Help;
71 bool FogOfWar;
72 bool Visible;
73 C4ID DragID;
74 C4ObjectList Selection;
75 C4FacetEx DragImage;
76 // Target object
77 C4Object *TargetObject; // valid during Move()
78 C4Object *DownTarget;
79 int32_t TimeOnTargetObject;
80 // Region
81 C4Region *TargetRegion; // valid during Move()
82 C4Region DownRegion;
83
84public:
85 void Default();
86 void Clear();
87 bool Init(int32_t iPlayer);
88 void Execute();
89 const char *GetCaption();
90 void HideCursor();
91 void ShowCursor();
92 void Draw(C4FacetEx &cgo);
93 void Move(int32_t iButton, int32_t iX, int32_t iY, uint32_t dwKeyFlags, bool fCenter = false);
94 bool IsViewport(C4Viewport *pViewport);
95 void ClearPointers(C4Object *pObj);
96 void UpdateClip(); // update clipping region for mouse cursor
97 void SetOwnedMouse(bool fToVal) { fMouseOwned = fToVal; }
98 bool IsMouseOwned() { return fMouseOwned; }
99 bool IsActive() { return !!Active; }
100
101protected:
102 void SendPlayerSelectNext();
103 void UpdateFogOfWar();
104 void RightUpDragNone();
105 void ButtonUpDragConstruct();
106 void ButtonUpDragMoving();
107 void ButtonUpDragSelecting();
108 void LeftUpDragNone();
109 void DragConstruct();
110 void Wheel(uint32_t dwFlags);
111 void RightUp();
112 void RightDown();
113 void LeftDouble();
114 void DragNone();
115 void DragMoving();
116 void LeftUp();
117 void DragSelect();
118 void LeftDown();
119 void UpdateTargetRegion();
120 void UpdateScrolling();
121 void CreateDragImage(C4ID id);
122 void UpdateCursorTarget();
123 void SendCommand(int32_t iCommand, int32_t iX = 0, int32_t iY = 0, C4Object *pTarget = nullptr, C4Object *pTarget2 = nullptr, int32_t iData = 0, int32_t iAddMode = C4P_Command_Set);
124 int32_t UpdateObjectSelection();
125 int32_t UpdateCrewSelection();
126 int32_t UpdateSingleSelection();
127 bool SendControl(int32_t iCom, int32_t iData = 0);
128 bool UpdatePutTarget(bool fVehicle);
129 C4Object *GetTargetObject(int32_t iX, int32_t iY, uint32_t &dwOCF, C4Object *pExclude = nullptr);
130 bool IsPassive(); // return whether mouse is only used to look around
131 void ScrollView(int32_t iX, int32_t iY, int32_t ViewWdt, int32_t ViewHgt);
132
133private:
134 template<C4ResStrTableKey Id, typename T>
135 void SetCaption(T *nameSource, bool isDouble);
136
137 template<C4ResStrTableKey Id>
138 void SetCaption(bool isDouble);
139
140public:
141 bool IsHelp() { return Help; }
142 void AbortHelp() { Help = false; }
143 bool IsDragging();
144 void StartConstructionDrag(C4ID id);
145 int32_t GetPlayer() { return Player; }
146};
147