OpenClonk
C4MouseControl.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Mouse input */
19 
20 #ifndef INC_C4MouseControl
21 #define INC_C4MouseControl
22 
23 #include "graphics/C4Facet.h"
24 #include "lib/C4Rect.h"
25 #include "object/C4ObjectList.h"
26 struct ZoomData; // #include "graphics/C4Draw.h"
27 
28 const int32_t C4MC_Button_None = 0,
45 
46 const int32_t C4MC_DragSensitivity = 5;
47 
48 const int32_t C4MC_MD_DragSource = 1,
51 
52 const int32_t C4MC_Cursor_Select = 0, // click cursor to select/click stuff in the GUI
53  C4MC_Cursor_Crosshair = 1, // standard ingame cursor
54  C4MC_Cursor_DragDrop = 2, // cursor when drag&dropping
55  C4MC_Cursor_Up = 3, // cursors for scrolling the viewport ...
56  C4MC_Cursor_Down = 4, // ...
63  C4MC_Cursor_Passive = 11, // passive cursor in records and and fog of war and outside viewport
64  C4MC_Cursor_DropInto = 12; // drop into contents
65 
67 {
68  friend class C4Viewport;
69 public:
72 protected:
73  bool Active;
75  int32_t Player;
76  C4Player *pPlayer; // valid during Move()
77  C4Viewport *Viewport; // valid during Move()
78 
79  int32_t Cursor;
80 
81  int32_t VpX,VpY; // Pixel coordinates of mouse pos
82  float ViewX,ViewY; // Game coordinate scrolling offset of viewport
83  float GameX,GameY; // Game coordinates of mouse pos
84  float GuiX,GuiY; // GUI coorindates of mouse pos
86 
87  float DownX,DownY; // Game coordinates of mouse-down-pos while dragging
88 
89  int32_t ScrollSpeed;
90  int32_t Drag;
91 
95  bool ShiftDown;
96  bool AltDown;
97  bool Scrolling;
99  bool FogOfWar;
100  bool Visible;
101 
102  C4ObjectList Selection; //obsolete!
103 
108 
109  // Tooltip management
110 
111  // currently shown caption
113  // tooltip text that will be shown when the mouse is kept in the tooltip rectangle for some time
115  int32_t CaptionBottomY;
116  int32_t KeepCaption;
119 
120  // Target object
121  C4Object *TargetObject; // valid during Move()
123 public:
124  void Default();
125  void Clear();
126  bool Init(int32_t iPlayer);
127  void Execute();
128  void HideCursor();
129  void ShowCursor();
130  void Draw(C4TargetFacet &cgo, const ZoomData &GameZoom);
131  void Move(int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyFlags, bool fCenter = false);
132  void DoMoveInput();
133  bool IsViewport(C4Viewport *pViewport);
134  void ClearPointers(C4Object *pObj);
135  void UpdateClip(); // update clipping region for mouse cursor
136  void SetOwnedMouse(bool fToVal) { fMouseOwned = fToVal; }
137  bool IsMouseOwned() { return fMouseOwned; }
138  bool IsActive() { return !!Active; }
139  bool GetLastCursorPos(int32_t *x_out_gui, int32_t *y_out_gui, int32_t *x_out_game, int32_t *y_out_game) const;
140 
141  const char *GetCaption();
142  void SetTooltipText(const StdStrBuf &text);
143  void SetTooltipRectangle(const C4Rect &rectangle);
144 protected:
145  void UpdateFogOfWar();
146  void RightUpDragNone();
147  void ButtonUpDragScript();
148  void LeftUpDragNone();
149  void DragScript();
150  void Wheel(DWORD dwFlags);
151  void RightUp();
152  void RightDown();
153  void LeftDouble();
154  void DragNone();
155  void LeftUp();
156  void LeftDown();
157  void UpdateScrolling();
158  void UpdateCursorTarget();
159  int32_t UpdateSingleSelection();
160  C4Object *GetTargetObject(); // get MouseSelection object at position
161  bool IsPassive(); // return whether mouse is only used to look around
162  void ScrollView(float iX, float iY, float ViewWdt, float ViewHgt); // in landscape coordinates
163 
164 public:
165  bool IsDragging();
166  bool IsLeftDown() { return LeftButtonDown; }
167  int32_t GetPlayer() { return Player; }
168 };
169 
171 #endif
const int32_t C4MC_Button_X1Double
const int32_t C4MC_Cursor_Passive
const int32_t C4MC_Button_X2Up
const int32_t C4MC_Cursor_Left
const int32_t C4MC_Cursor_Up
const int32_t C4MC_Button_None
const int32_t C4MC_DragSensitivity
const int32_t C4MC_Button_RightDown
const int32_t C4MC_Cursor_DownRight
const int32_t C4MC_Button_MiddleUp
const int32_t C4MC_Button_RightUp
const int32_t C4MC_Cursor_Crosshair
const int32_t C4MC_Button_MiddleDouble
const int32_t C4MC_MD_DragSource
const int32_t C4MC_Button_X1Up
const int32_t C4MC_Button_MiddleDown
const int32_t C4MC_Cursor_DownLeft
const int32_t C4MC_Cursor_Down
const int32_t C4MC_Cursor_DragDrop
const int32_t C4MC_Button_RightDouble
const int32_t C4MC_Button_LeftUp
C4MouseControl MouseControl
Definition: C4Globals.cpp:47
const int32_t C4MC_Cursor_Select
const int32_t C4MC_Cursor_UpRight
const int32_t C4MC_Button_X1Down
const int32_t C4MC_Button_LeftDown
const int32_t C4MC_Button_LeftDouble
const int32_t C4MC_Button_X2Double
const int32_t C4MC_MD_NoClick
const int32_t C4MC_Cursor_DropInto
const int32_t C4MC_Cursor_Right
const int32_t C4MC_Button_X2Down
const int32_t C4MC_MD_DropTarget
const int32_t C4MC_Cursor_UpLeft
const int32_t C4MC_Button_Wheel
uint32_t DWORD
Definition: C4Def.h:99
Definition: C4Id.h:26
int32_t GetPlayer()
C4Viewport * Viewport
void SetTooltipText(const StdStrBuf &text)
void Draw(C4TargetFacet &cgo, const ZoomData &GameZoom)
bool IsViewport(C4Viewport *pViewport)
void SetOwnedMouse(bool fToVal)
C4Facet fctViewport
StdCopyStrBuf Caption
C4Facet fctViewportGame
C4ObjectList Selection
C4Rect ToolTipRectangle
StdCopyStrBuf TooltipText
bool GetLastCursorPos(int32_t *x_out_gui, int32_t *y_out_gui, int32_t *x_out_game, int32_t *y_out_game) const
void ScrollView(float iX, float iY, float ViewWdt, float ViewHgt)
int32_t ScrollSpeed
const char * GetCaption()
void Move(int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyFlags, bool fCenter=false)
bool ButtonDownOnSelection
int32_t UpdateSingleSelection()
C4Object * GetTargetObject()
C4Object * TargetObject
C4Def * DragImageDef
C4Object * DownTarget
void SetTooltipRectangle(const C4Rect &rectangle)
C4Object * DragObject
C4Facet fctViewportGUI
C4Object * DragImageObject
void Wheel(DWORD dwFlags)
int32_t TimeInTooltipRectangle
bool Init(int32_t iPlayer)
void ClearPointers(C4Object *pObj)
int32_t CaptionBottomY
C4Player * pPlayer
Definition: C4Rect.h:28
int32_t ViewWdt
Definition: C4Viewport.h:36
int32_t ViewHgt
Definition: C4Viewport.h:37