OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 "object/C4ObjectList.h"
25 #include "lib/C4Rect.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
void SetTooltipRectangle(const C4Rect &rectangle)
C4ObjectList Selection
const int32_t C4MC_Button_MiddleUp
const int32_t C4MC_Button_LeftDown
C4Rect ToolTipRectangle
C4Player * pPlayer
int32_t TimeInTooltipRectangle
const int32_t C4MC_Cursor_Right
const int32_t C4MC_Cursor_Passive
StdCopyStrBuf TooltipText
const int32_t C4MC_Cursor_DragDrop
C4Object * DragImageObject
int32_t UpdateSingleSelection()
const int32_t C4MC_DragSensitivity
const int32_t C4MC_Button_RightUp
Definition: C4Rect.h:29
C4Object * DownTarget
bool ButtonDownOnSelection
const int32_t C4MC_Button_X2Down
const int32_t C4MC_Cursor_Down
C4Object * TargetObject
bool GetLastCursorPos(int32_t *x_out_gui, int32_t *y_out_gui, int32_t *x_out_game, int32_t *y_out_game) const
const int32_t C4MC_Button_MiddleDouble
void ScrollView(float iX, float iY, float ViewWdt, float ViewHgt)
void SetOwnedMouse(bool fToVal)
const int32_t C4MC_Button_X1Double
const int32_t C4MC_MD_NoClick
const int32_t C4MC_MD_DropTarget
C4Facet fctViewportGame
const int32_t C4MC_Button_LeftDouble
int32_t ViewHgt
Definition: C4Viewport.h:36
void SetTooltipText(const StdStrBuf &text)
void Draw(C4TargetFacet &cgo, const ZoomData &GameZoom)
const int32_t C4MC_Button_X2Double
C4MouseControl MouseControl
Definition: C4Globals.cpp:47
const int32_t C4MC_Button_LeftUp
int32_t ViewWdt
Definition: C4Viewport.h:36
int32_t GetPlayer()
const int32_t C4MC_Button_X1Up
bool IsViewport(C4Viewport *pViewport)
void Move(int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyFlags, bool fCenter=false)
StdCopyStrBuf Caption
const int32_t C4MC_Cursor_Left
int32_t ScrollSpeed
const int32_t C4MC_Cursor_DownLeft
C4Object * DragObject
Definition: C4Def.h:100
int32_t CaptionBottomY
const int32_t C4MC_Cursor_DropInto
const int32_t C4MC_Cursor_Select
const int32_t C4MC_Button_X1Down
C4Viewport * Viewport
Definition: C4Id.h:28
C4Def * DragImageDef
C4Facet fctViewportGUI
const int32_t C4MC_Button_RightDown
const int32_t C4MC_Cursor_Up
void Wheel(DWORD dwFlags)
const int32_t C4MC_Button_Wheel
const int32_t C4MC_Cursor_UpLeft
const int32_t C4MC_MD_DragSource
bool Init(int32_t iPlayer)
const int32_t C4MC_Button_RightDouble
const int32_t C4MC_Button_None
C4Facet fctViewport
const int32_t C4MC_Cursor_DownRight
const int32_t C4MC_Button_MiddleDown
const int32_t C4MC_Cursor_UpRight
C4Object * GetTargetObject()
uint32_t DWORD
const char * GetCaption()
void ClearPointers(C4Object *pObj)
const int32_t C4MC_Cursor_Crosshair
const int32_t C4MC_Button_X2Up