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, 29 C4MC_Button_LeftDown = 1, 30 C4MC_Button_LeftUp = 2, 31 C4MC_Button_RightDown = 3, 32 C4MC_Button_RightUp = 4, 33 C4MC_Button_LeftDouble = 5, 34 C4MC_Button_RightDouble = 6, 35 C4MC_Button_Wheel = 7, 36 C4MC_Button_MiddleDown = 8, 37 C4MC_Button_MiddleUp = 9, 38 C4MC_Button_MiddleDouble= 10, 39 C4MC_Button_X1Down = 11, 40 C4MC_Button_X1Up = 12, 41 C4MC_Button_X1Double = 13, 42 C4MC_Button_X2Down = 14, 43 C4MC_Button_X2Up = 15, 44 C4MC_Button_X2Double = 16; 45 46 const int32_t C4MC_DragSensitivity = 5; 47 48 const int32_t C4MC_MD_DragSource = 1, 49 C4MC_MD_DropTarget = 2, 50 C4MC_MD_NoClick = 4; 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, // ... 57 C4MC_Cursor_Left = 5, 58 C4MC_Cursor_Right = 6, 59 C4MC_Cursor_UpLeft = 7, 60 C4MC_Cursor_UpRight = 8, 61 C4MC_Cursor_DownLeft = 9, 62 C4MC_Cursor_DownRight = 10, 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 66 class C4MouseControl 67 { 68 friend class C4Viewport; 69 public: 70 C4MouseControl(); 71 ~C4MouseControl(); 72 protected: 73 bool Active; 74 bool fMouseOwned; 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 85 C4Facet fctViewport, fctViewportGame, fctViewportGUI; 86 87 float DownX,DownY; // Game coordinates of mouse-down-pos while dragging 88 89 int32_t ScrollSpeed; 90 int32_t Drag; 91 92 bool LeftButtonDown,RightButtonDown,LeftDoubleIgnoreUp; 93 bool ButtonDownOnSelection; 94 bool ControlDown; 95 bool ShiftDown; 96 bool AltDown; 97 bool Scrolling; 98 bool InitCentered; 99 bool FogOfWar; 100 bool Visible; 101 102 C4ObjectList Selection; //obsolete! 103 104 C4Object *DragObject; 105 C4ID DragID; 106 C4Def* DragImageDef; 107 C4Object* DragImageObject; 108 109 // Tooltip management 110 111 // currently shown caption 112 StdCopyStrBuf Caption; 113 // tooltip text that will be shown when the mouse is kept in the tooltip rectangle for some time 114 StdCopyStrBuf TooltipText; 115 int32_t CaptionBottomY; 116 int32_t KeepCaption; 117 int32_t TimeInTooltipRectangle; 118 C4Rect ToolTipRectangle; 119 120 // Target object 121 C4Object *TargetObject; // valid during Move() 122 C4Object *DownTarget; 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 SetOwnedMouse(bool fToVal)136 void SetOwnedMouse(bool fToVal) { fMouseOwned = fToVal; } IsMouseOwned()137 bool IsMouseOwned() { return fMouseOwned; } IsActive()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(); IsLeftDown()166 bool IsLeftDown() { return LeftButtonDown; } GetPlayer()167 int32_t GetPlayer() { return Player; } 168 }; 169 170 extern C4MouseControl MouseControl; 171 #endif 172