1 // ***************************************************************************** 2 // 3 // Filename : MouseSystem.h 4 // 5 // Purpose : Defines and typedefs for the "mousesystem" mouse region handler 6 // 7 // Modification history : 8 // 9 // 30jan97:Bret -> Creation 10 // 11 // ***************************************************************************** 12 13 #ifndef _MOUSE_SYSTEM_H_ 14 #define _MOUSE_SYSTEM_H_ 15 16 #include "JA2Types.h" 17 #include "Types.h" 18 19 #include <string_theory/string> 20 21 22 #define _JA2_RENDER_DIRTY // Undef this if not using the JA2 Dirty Rectangle System. 23 24 // Mouse Region Flags 25 #define MSYS_NO_FLAGS 0x00000000 26 #define MSYS_MOUSE_IN_AREA 0x00000001 27 #define MSYS_REGION_EXISTS 0x00000010 28 #define MSYS_REGION_ENABLED 0x00000040 29 #define MSYS_FASTHELP 0x00000080 30 #define MSYS_GOT_BACKGROUND 0x00000100 31 #define MSYS_HAS_BACKRECT 0x00000200 32 #define MSYS_FASTHELP_RESET 0x00000400 33 #define MSYS_ALLOW_DISABLED_FASTHELP 0x00000800 34 35 struct MOUSE_REGION; 36 37 typedef void (*MOUSE_CALLBACK)(MOUSE_REGION*, INT32); 38 39 struct MOUSE_REGION 40 { 41 void ChangeCursor(UINT16 crsr); 42 EnableMOUSE_REGION43 void Enable() { uiFlags |= MSYS_REGION_ENABLED; } DisableMOUSE_REGION44 void Disable() { uiFlags &= ~MSYS_REGION_ENABLED; } 45 46 void SetFastHelpText(const ST::string& str); 47 48 void AllowDisabledRegionFastHelp(bool allow); 49 SetUserPtrMOUSE_REGION50 void SetUserPtr(void* ptr) { user.ptr = ptr; } 51 GetUserPtrMOUSE_REGION52 template<typename T> T* GetUserPtr() const { return static_cast<T*>(user.ptr); } 53 XMOUSE_REGION54 INT16 X() const { return RegionTopLeftX; } YMOUSE_REGION55 INT16 Y() const { return RegionTopLeftY; } WMOUSE_REGION56 INT16 W() const { return RegionBottomRightX - RegionTopLeftX; } HMOUSE_REGION57 INT16 H() const { return RegionBottomRightY - RegionTopLeftY; } 58 59 INT8 PriorityLevel; // Region's Priority, set by system and/or caller 60 UINT32 uiFlags; // Region's state flags 61 INT16 RegionTopLeftX; // Screen area affected by this region (absolute coordinates) 62 INT16 RegionTopLeftY; 63 INT16 RegionBottomRightX; 64 INT16 RegionBottomRightY; 65 INT16 MouseXPos; // Mouse's Coordinates in absolute screen coordinates 66 INT16 MouseYPos; 67 INT16 RelativeXPos; // Mouse's Coordinates relative to the Top-Left corner of the region 68 INT16 RelativeYPos; 69 UINT16 ButtonState; // Current state of the mouse buttons 70 UINT16 Cursor; // Cursor to use when mouse in this region (see flags) 71 MOUSE_CALLBACK MovementCallback; // Pointer to callback function if movement occured in this region 72 MOUSE_CALLBACK ButtonCallback; // Pointer to callback function if button action occured in this region 73 union // User Data, can be set to anything! 74 { 75 INT32 data[4]; 76 void* ptr; 77 } user; 78 79 //Fast help vars. 80 INT16 FastHelpTimer; // Countdown timer for FastHelp text 81 ST::utf32_buffer FastHelpText; // Text string for the FastHelp (describes buttons if left there a while) 82 BACKGROUND_SAVE* FastHelpRect; 83 84 MOUSE_REGION* next; // List maintenance, do NOT touch these entries 85 MOUSE_REGION* prev; 86 }; 87 88 // Mouse region priorities 89 #define MSYS_PRIORITY_LOWEST 0 90 #define MSYS_PRIORITY_LOW 15 91 #define MSYS_PRIORITY_NORMAL 31 92 #define MSYS_PRIORITY_HIGH 63 93 #define MSYS_PRIORITY_HIGHEST 127 94 95 // Mouse system defines used during updates 96 #define MSYS_NO_ACTION 0 97 #define MSYS_DO_MOVE 1 98 #define MSYS_DO_LBUTTON_DWN 2 99 #define MSYS_DO_LBUTTON_UP 4 100 #define MSYS_DO_RBUTTON_DWN 8 101 #define MSYS_DO_RBUTTON_UP 16 102 #define MSYS_DO_LBUTTON_REPEAT 32 103 #define MSYS_DO_RBUTTON_REPEAT 64 104 #define MSYS_DO_WHEEL_UP 0x0080 105 #define MSYS_DO_WHEEL_DOWN 0x0100 106 #define MSYS_DO_MBUTTON_DWN 0x0200 107 #define MSYS_DO_MBUTTON_UP 0x0400 108 #define MSYS_DO_MBUTTON_REPEAT 0x0800 109 110 111 #define MSYS_DO_BUTTONS (MSYS_DO_LBUTTON_DWN | MSYS_DO_LBUTTON_UP | MSYS_DO_RBUTTON_DWN | MSYS_DO_RBUTTON_UP | MSYS_DO_RBUTTON_REPEAT | MSYS_DO_LBUTTON_REPEAT | MSYS_DO_WHEEL_UP | MSYS_DO_WHEEL_DOWN | MSYS_DO_MBUTTON_DWN | MSYS_DO_MBUTTON_UP | MSYS_DO_MBUTTON_REPEAT) 112 113 // Mouse system button masks 114 #define MSYS_LEFT_BUTTON 1 115 #define MSYS_RIGHT_BUTTON 2 116 #define MSYS_MIDDLE_BUTTON 0x04 117 118 // Mouse system special values 119 #define MSYS_NO_CALLBACK NULL 120 #define MSYS_NO_CURSOR 65534 121 122 // Mouse system callback reasons 123 #define MSYS_CALLBACK_REASON_NONE 0 124 #define MSYS_CALLBACK_REASON_MOVE 2 125 #define MSYS_CALLBACK_REASON_LBUTTON_DWN 4 126 #define MSYS_CALLBACK_REASON_LBUTTON_UP 8 127 #define MSYS_CALLBACK_REASON_RBUTTON_DWN 16 128 #define MSYS_CALLBACK_REASON_RBUTTON_UP 32 129 #define MSYS_CALLBACK_REASON_BUTTONS (MSYS_CALLBACK_REASON_LBUTTON_DWN|MSYS_CALLBACK_REASON_LBUTTON_UP|MSYS_CALLBACK_REASON_RBUTTON_DWN|MSYS_CALLBACK_REASON_RBUTTON_UP|MSYS_CALLBACK_REASON_MBUTTON_DWN|MSYS_CALLBACK_REASON_MBUTTON_UP) 130 #define MSYS_CALLBACK_REASON_LOST_MOUSE 64 131 #define MSYS_CALLBACK_REASON_GAIN_MOUSE 128 132 133 #define MSYS_CALLBACK_REASON_LBUTTON_REPEAT 256 134 #define MSYS_CALLBACK_REASON_RBUTTON_REPEAT 512 135 136 #define MSYS_CALLBACK_REASON_MBUTTON_DWN 0x2000 137 #define MSYS_CALLBACK_REASON_MBUTTON_UP 0x4000 138 #define MSYS_CALLBACK_REASON_MBUTTON_REPEAT 0x8000 139 140 //Kris: Nov 31, 1999 141 //Added support for double clicks. The DOUBLECLICK event is passed combined with 142 //the LBUTTON_DWN event if two LBUTTON_DWN events are detected on the same button/region 143 //within the delay defined by MSYS_DOUBLECLICK_DELAY (in milliseconds). If your button/region 144 //supports double clicks and single clicks, make sure the DOUBLECLICK event is checked first (rejecting 145 //the LBUTTON_DWN event if detected) 146 #define MSYS_CALLBACK_REASON_LBUTTON_DOUBLECLICK 1024 147 148 #define MSYS_CALLBACK_REASON_WHEEL_UP 0x0800 149 #define MSYS_CALLBACK_REASON_WHEEL_DOWN 0x1000 150 151 152 // Internal Functions 153 void MSYS_SetCurrentCursor(UINT16 Cursor); 154 155 // External 156 void MSYS_Init(void); 157 void MSYS_Shutdown(void); 158 void MSYS_DefineRegion(MOUSE_REGION *region,UINT16 tlx,UINT16 tly,UINT16 brx,UINT16 bry,INT8 priority, 159 UINT16 crsr,MOUSE_CALLBACK movecallback,MOUSE_CALLBACK buttoncallback); 160 void MSYS_RemoveRegion(MOUSE_REGION *region); 161 162 /* Set one of the user data entries in a mouse region */ 163 void MSYS_SetRegionUserData(MOUSE_REGION*, UINT32 index, INT32 userdata); 164 165 /* Retrieve one of the user data entries in a mouse region */ 166 INT32 MSYS_GetRegionUserData(MOUSE_REGION const*, UINT32 index); 167 168 // This function will force a re-evaluation of mous regions 169 // Usually used to force change of mouse cursor if panels switch, etc 170 void RefreshMouseRegions(void); 171 172 // Now also used by Wizardry -- DB 173 void RenderFastHelp(void); 174 175 // Hook to the SGP's mouse handler 176 void MouseSystemHook(UINT16 Type, UINT16 Xcoord, UINT16 Ycoord); 177 178 class MouseRegion : private MOUSE_REGION 179 { 180 public: MouseRegion(UINT16 const x,UINT16 const y,UINT16 const w,UINT16 const h,INT8 const priority,UINT16 const cursor,MOUSE_CALLBACK const movecallback,MOUSE_CALLBACK const buttoncallback)181 MouseRegion(UINT16 const x, UINT16 const y, UINT16 const w, UINT16 const h, INT8 const priority, UINT16 const cursor, MOUSE_CALLBACK const movecallback, MOUSE_CALLBACK const buttoncallback) 182 { 183 MOUSE_REGION* const r = this; 184 *r = MOUSE_REGION{}; 185 MSYS_DefineRegion(r, x, y, x + w, y + h, priority, cursor, movecallback, buttoncallback); 186 } 187 ~MouseRegion()188 ~MouseRegion() 189 { 190 MSYS_RemoveRegion(this); 191 } 192 Base()193 MOUSE_REGION const& Base() const { return *this; } // XXX hack 194 195 using MOUSE_REGION::ChangeCursor; 196 using MOUSE_REGION::Disable; 197 using MOUSE_REGION::Enable; 198 using MOUSE_REGION::MouseXPos; 199 using MOUSE_REGION::MouseYPos; 200 using MOUSE_REGION::PriorityLevel; 201 using MOUSE_REGION::RegionBottomRightX; 202 using MOUSE_REGION::RegionBottomRightY; 203 using MOUSE_REGION::RegionTopLeftX; 204 using MOUSE_REGION::RegionTopLeftY; 205 using MOUSE_REGION::RelativeXPos; 206 using MOUSE_REGION::RelativeYPos; 207 using MOUSE_REGION::SetFastHelpText; 208 using MOUSE_REGION::SetUserPtr; 209 using MOUSE_REGION::uiFlags; 210 }; 211 212 #endif 213