Cavestory Mod API
CSMAPI_BaseModeInstance.h
Go to the documentation of this file.
1 /*
2  Cavestory Multiplayer API
3  Copyright (C) 2021 Johnny Ledger
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
26 #pragma once
27 
28 class VideoTexture;
29 
30 #include <CSMAPI_begincode.h>
34 #include <CSMAPI_endcode.h>
35 
36 //------------------------------------------------------------------------------------------------------------------------------------
37 
38 namespace Platform
39 {
40  void OpenBugReporter();
41 }
42 
43 namespace ChatEmotes
44 {
45  extern int CheckOpenList(BaseModeInstance*);
46 }
47 
48 #include <CSMAPI_begincode.h>
49 extern void CAVESTORY_MOD_API MessageBox_DrawMode(void*);
50 
51 //------------------------------------------------------------------------------------------------------------------------------------
52 
55 typedef unsigned int ModeThreadId;
56 
59 typedef unsigned int EventScheduleId;
60 
65 typedef void(*EventSchedulePayloadFunc)(BaseModeInstance* pOwner, void* pUserData);
66 
67 //------------------------------------------------------------------------------------------------------------------------------------
68 
70 #define MODE_INSTANCE_MAX_TEXTURES 64
71 
73 #define MODE_INSTANCE_MAX_SURFACES 64
74 
76 #define MODE_INSTANCE_MAX_THREADS 8
77 
79 #define MODE_INSTANCE_DEBUG
80 
82 #define MODE_INSTANCE_GUARDS
83 
84 //------------------------------------------------------------------------------------------------------------------------------------
85 // Configuration
86 
88 #define MODE_TOOLTIP_ANIMATION_TIME 1000
89 
91 #define MODE_DRAW_CENTERED_SURFACE -0x7FFFFFF
92 
94 #define MODE_IM_STILL_RUNNING 0x7FFFFFFF
95 
97 #define CONTROL_MARGIN 4
98 
100 #define MODE_INVALID_THREAD_ID 0
101 
103 #define INVALID_SCHEDULE_ID 0xFFFFFFFF
104 
105 
106 //------------------------------------------------------------------------------------------------------------------------------------
107 // Helper macros
108 
115 #define DefineKeyControlStruct(INPUT_TYPE, KEY, DESC) { INPUT_TYPE, KEY, DESC }
116 
117 //------------------------------------------------------------------------------------------------------------------------------------
118 
122 {
125 };
126 
130 {
133 
136 
139 
142 
144  CDP_CENTER = 4
145 };
146 
150 {
152  ANIMATED = 0,
153 
155  NORMAL = 1,
156 
158  DEPRESSED = 2
159 };
160 
164 {
167 
170 
173 
176 
178  MCA_OPENING = 4
179 };
180 
184 {
186  KCIT_KEY = 0,
187 
190 
193 
195  KCIT_MOUSE = 3
196 };
197 
198 //------------------------------------------------------------------------------------------------------------------------------------
199 
203 {
207 
210  int Key;
211 
214  char Desc[128];
215 };
216 
217 //------------------------------------------------------------------------------------------------------------------------------------
218 
222 {
226 
229  unsigned long long int end_time;
230 
234 
238 
241  void* user_data;
242 
246 
250 };
251 
252 //------------------------------------------------------------------------------------------------------------------------------------
253 
257 {
260  bool shown;
261 
265 
269 
273 
277 
281 };
282 
283 //------------------------------------------------------------------------------------------------------------------------------------
284 
288 {
289  friend class BaseModeInstance;
290  friend int ModeThreadInstance_AsyncFunc(void* ptr);
291 
292 private: // Static variables
293 
296  static void* sMainModeMutex;
297 
300  static ModeThreadId sNextThreadId;
301 
302 public: // Enumerations
303 
307  {
309  THREAD_NOT_RUNNING = 0,
310 
312  THREAD_STARTING = 1,
313 
315  THREAD_RUNNING = 2,
316 
318  THREAD_STOPPING = 3,
319 
321  THREAD_DELETABLE = 4,
322  };
323 
324 public: // Typedefs
325 
328  typedef void(*ModeCallback_OnThreadComplete)(BaseModeInstance* pMode, ModeThreadInstance* pThread, void* pUserData);
329 
332  typedef void(*ModeCallback_OnThreadLoop)(BaseModeInstance* pMode, ModeThreadInstance* pThread, void* pUserData);
333 
334 protected: // Variables
335 
338  char m_ThreadName[128];
339 
343 
346  ModeCallback_OnThreadComplete m_OnComplete;
347 
350  ModeCallback_OnThreadComplete m_OnLoop;
351 
355 
358  void* m_Thread;
359 
362  void* m_Mutex;
363 
367 
370  bool m_Running;
371 
374  int m_Result;
375 
378  void* m_UserData;
379 
380 public: // Constructor & deconstructor
381 
385 
389 
390 protected: // Internal methods
391 
400  bool InitThread(BaseModeInstance* pOwner, ModeCallback_OnThreadLoop pOnLoopFunc, ModeCallback_OnThreadComplete pOnCompleteFunc, void* pUserData = NULL);
401 
405 
406 public: // Locking & unlocking
407 
411  static bool TryLock();
412 
415  static void Lock();
416 
419  static void Unlock();
420 
421 public: // Unique mutex locking & unlocking
422 
427 
430  void LockUnique();
431 
434  void UnlockUnique();
435 
436 public: // Methods
437 
440  bool Start();
441 
444  void End(int iResult = 0);
445 
448  void WaitToFinish();
449 
452  void Detach();
453 
456  int GetResult();
457 };
458 
459 //------------------------------------------------------------------------------------------------------------------------------------
460 
469 {
470  friend class ModeInputVector;
471  friend class ModeThreadInstance;
474  friend extern void SetGameResolution(int iNewWidth, int iNewHeight, int iNewMagnification);
475  friend extern void CAVESTORY_MOD_API MessageBox_DrawMode(void*);
476  friend extern int ChatEmotes::CheckOpenList(BaseModeInstance* pMode);
477  friend extern void Platform::OpenBugReporter();
478 
479 public: // Exposed internal structs
480 
484  {
488 
492 
496 
500 
504 
508 
511  unsigned int CustomMagnification;
512 
515  struct
516  {
519  bool Enabled;
520 
524 
528 
531  bool OpenOnTab;
532 
536 
540 
544 
548 
551  int HideTime;
552  } MenuControls;
553  };
554 
555 private: // Screen grab stuff
556 
559  struct BASEMODE_SCREEN_GRAB_CACHE
560  {
563  Surface_Ids surf;
564 
567  bool used;
568  };
569 
572  static BASEMODE_SCREEN_GRAB_CACHE m_szScreenGrabData[3];
573 
574 protected: // Global configuration
575 
579  {
580  public:
584 
588 
592  {
593  IgnoreWindow = false;
594  RefreshAllModes = false;
595  }
596  };
597 
601 
602 public: // Typedefs
603 
606  typedef void(*ModeCallback_OnEnd)(BaseModeInstance* pMode, const int& iResult, bool& bDelete);
607 
608 public: // Linkage
609 
612  static BaseModeInstance* m_FocusedInstance;
613 
616  static BaseModeInstance* m_FirstInstance;
617 
620  static BaseModeInstance* m_FreeRun_Start;
621 
624  BaseModeInstance* m_FreeRun_Next;
625 
628  BaseModeInstance* m_NextInstance;
629 
630 private: // Variables for free-running mode
631 
634  GUI_POINT m_OldMousePoint;
635 
638  GUI_POINT m_MousePoint;
639 
640 private: // Schedule stuff
641 
644  static EventScheduleStruct* m_ScheduleLink;
645 
648  static EventScheduleId m_NextScheduleId;
649 
650 private: // Private data
651 
654  static int m_ModeCursorCount;
655 
658  static FontObject* m_DefaultFont[10];
659 
662  Surface_Ids m_SurfaceIDList[MODE_INSTANCE_MAX_SURFACES];
663 
667 
671 
674  int m_AllocThreadCount;
675 
676 protected: // Tooltip data
677 
681 
685 
686 private: // Control table surfaces
687 
688  struct
689  {
692  int Indices[2];
693 
696  GUI_POINT MenuSize;
697 
700  int AnimTimer;
701 
704  int FrameTimer;
705 
708  MENU_CONTROLS_ACTS ActNo;
709 
712  bool Joypad;
713  } m_MenuControls;
714 
715 public: // Callbacks
716 
717  struct
718  {
722  ModeCallback_OnEnd OnEnd;
723  } m_Callbacks;
724 
725 private: // 'Mouse Rect Check' (MRC)
726 
729  GUI_RECT m_MRC_Last;
730 
733  GUI_RECT m_MRC_Curr;
734 
737  unsigned int m_MRC_Time;
738 
739 private: // Key input private variables
740 
743  unsigned int m_KeyOld;
744 
747  unsigned int m_KeyOld2;
748 
751  unsigned int m_KeyOld_JOY;
752 
753 protected: // Shared data
754 
758 
762  struct ModeInput
763  {
766  unsigned int Key;
767 
770  unsigned int KeyTrg;
771 
774  unsigned int Key2;
775 
778  unsigned int KeyTrg2;
779 
782  unsigned int Key_JOY;
783 
786  unsigned int KeyTrg_JOY;
787  } m_ModeInput;
788 
792 
795  bool m_Dirty;
796 
799  bool m_End;
800 
804 
808 
813 
814 public: // Data
815 
818  void* m_PrivData;
819 
820 public: // Constructor
821 
824  ~BaseModeInstance();
825 
826 protected: // Main protected methods
827 
831  virtual int Init() = 0;
832 
836  virtual int Free() = 0;
837 
841  virtual int GetMagnification();
842 
845  virtual int ModePixelToScreenPixel(int iInput);
846 
852  virtual void QueryMenuControls(KeyControlStruct pControlBuffer[32], int& pControlCount, bool& bStackControls);
853 
856  virtual void ProcessLogic() = 0;
857 
861  virtual void ProcessMouse(GUI_POINT mouse_point) = 0;
862 
865  virtual void ProcessKeys() = 0;
866 
869  virtual void PreRender() = 0;
870 
873  virtual void Draw() = 0;
874 
877  virtual void PostDraw() {}
878 
879 public: // Global Configuration
880 
885  static void SetGlobalConfig(MODE_GLOBAL_CONFIG_TYPE eType, const char* pValue);
886 
887 protected: // HELPER: Internal schedule methods
888 
893 
894 public: // HELPER: Schedule methods
895 
898  static void ProcessScheduleList();
899 
908  static EventScheduleId Schedule(unsigned int iDelay, EventSchedulePayloadFunc pPayloadFunc, void* pUserData = NULL, BaseModeInstance* pOwner = NULL);
909 
915  static bool CancelSchedule(EventScheduleId iEventId);
916 
920  static bool IsSchedulePending(EventScheduleId iEventId);
921 
922 public: // HELPER: Static helper methods
923 
927  static void ShowCursor();
928 
932  static void HideCursor();
933 
939  static void SetCursor(CSMP_CURSOR_TYPE iType, int iEventId = -1, GUI_RECT* pRect = NULL);
940 
947  static CSMP_CURSOR_TYPE GetCursor(GUI_RECT** pRect = NULL, int* pEventId = NULL);
948 
951  static void ReloadOpenModes();
952 
955  static void ScheduleReloadOpenModes();
956 
962  static FontObject* GetDefaultFont(unsigned int iMagnification = 0);
963 
971  static void ReloadFont(const char* pFontName, const char* pFontPath, int iFontW = -1, int iFontH = -1, unsigned int iMagnification = 0);
972 
980  static GameProcessMode ShowTutorialPages(BaseModeInstance* pCaller, int iPageCount, ...);
981 
982 protected: // HELPER: Tooltip methods
983 
987  bool IsTooltipOpen();
988 
999  bool CreateTooltip(GUI_POINT point, FontObject* font, const char* text, int life_time = 5000);
1000 
1012  bool CreateTextureTooltip(GUI_POINT point, FontObject* font, const char* text, int life_time = 5000, int Magnification = -1);
1013 
1019  bool CloseTooltip(bool fade_out = true);
1020 
1025 
1029  void SetTooltipPosition(GUI_POINT new_position);
1030 
1034 
1038 
1039 protected: // HELPER: Rect timers
1040 
1049  uint32_t GetRectHoverTime(GUI_POINT mouse_point, GUI_RECT rect);
1050 
1054 
1055 public: // HELPER: Static uniform drawing methods
1056 
1060  static void RunGameLogic(bool AllowACT = true);
1061 
1069  static void DrawGame(bool AllowACT = true, int OffsetX = 0, int OffsetY = 0, bool DoPutFade = true, bool bRunGameLogic = true);
1070 
1073  static void DrawHUD(int OffsetX = 0, int OffsetY = 0);
1074 
1083  static GUI_POINT GetControlKeySize(const KeyControlStruct* Buttons, int ButtonCount, bool StackControls = false, unsigned int CustomMagnification = 0);
1084 
1095  static void DrawControls(MENU_CONTROLS_DRAW_POSITION DrawPosition, Surface_Ids destSID, const KeyControlStruct* Buttons, int ButtonCount, bool Flash = false, bool StackControls = false, int Alpha = 255, unsigned int CustomMagnification = 0);
1096 
1097 private: // HELPER: Asynchronous methods (private)
1098 
1102  void CompleteAsyncOperation(ModeThreadInstance* pCompleteThread);
1103 
1104 public: // HELPER: Asynchronous methods
1105 
1114 
1121  bool StopThread(ModeThreadId iThreadId, bool bWaitForFinish = false);
1122 
1126 
1130 
1131 public: // HELPER: Uniform drawing methods
1132 
1137 
1143  int DrawBasicWindow(GUI_RECT* pRect = NULL);
1144 
1145 protected: // Menu Control Table
1146 
1154  bool CreateMenuControls(const KeyControlStruct* Buttons, int ButtonCount, bool StackControls = false);
1155 
1161 
1166 
1171 
1172 protected: // Non-overridable protected methods
1173 
1176  bool GrabScreen();
1177 
1181 
1185 
1189 
1194 
1203  int AllocSurface(int InsertIndex = -1, int Width = WINDOW_WIDTH, int Height = WINDOW_HEIGHT, unsigned int iMagnification = 0);
1204 
1211  int LoadImageToSurface(const char* FileName, int InsertIndex = -1);
1212 
1219  int LoadImageToTexture(const char* FileName, int InsertIndex = -1);
1220 
1227  int LoadSurfaceIDToSurface(Surface_Ids SurfaceID, int InsertIndex = -1);
1228 
1235  int LoadSurfaceIDToTexture(Surface_Ids SurfaceID, int InsertIndex = -1);
1236 
1240  void FreeSurface(int Index);
1241 
1245 
1251  bool IsLocalSurfaceAllocated(int Index);
1252 
1256  void SelectSurface(int Index);
1257 
1262 
1269 
1276 
1284  void DrawSurface(int Index, int X = 0, int Y = 0, unsigned char Alpha = 255, bool AbsolutePos = false);
1285 
1291  int GetSurfaceWidth(int Index);
1292 
1298  int GetSurfaceHeight(int Index);
1299 
1305  int GetCenteredX(int Index);
1306 
1312  int GetCenteredY(int Index);
1313 
1320  virtual GUI_POINT TranslateMousePosition(GUI_POINT* pMouseInput, const GUI_POINT& pWindowOffset);
1321 
1328 
1332  virtual int GetRelativeScreenWidth();
1333 
1338 
1343 
1344 public: // Texture methods
1345 
1352 
1363  int AllocTexture(int InsertIndex = -1, int Width = WINDOW_WIDTH, int Height = WINDOW_HEIGHT, int BitsPerPixel = 32, int Magnification = -1, int WindowIndex = 0);
1364 
1368  void FreeTexture(int Index);
1369 
1373 
1379  bool IsLocalTextureAllocated(int Index);
1380 
1384  void SelectTexture(int Index);
1385 
1390 
1394  void FinishTexture(int Index);
1395 
1404  void DrawTexture(int Index, int X = 0, int Y = 0, unsigned char Alpha = 255, bool bSubPixels = false, bool bWrapCoordinates = false);
1405 
1411  int GetTextureCenteredX(int Index);
1412 
1418  int GetTextureCenteredY(int Index);
1419 
1426 
1433  int GetTextureWidth(int Index, bool Magnified = true);
1434 
1441  int GetTextureHeight(int Index, bool Magnified = true);
1442 
1449 
1450 protected: // Control menu methods
1451 
1455 
1460 
1461 private: // Input methods
1462 
1465  void ProcKey();
1466 
1467 protected: // Protected input methods
1468 
1475  void RemoveKey(int iInputFlags, KeyInputType iType = KeyInputType::KIT_Key);
1476 
1483 
1484 public: // Free-call methods
1485 
1489  virtual bool StartMode();
1490 
1495  virtual void EndMode(int value = 0x6FFFFFFF, bool bSchedule = false);
1496 
1502  void SetModePaused(bool bValue);
1503 
1507  virtual bool ModeTick();
1508 
1513 
1518 
1519 public: // General methods
1520 
1524  ModeConfiguration* GetModeConfig();
1525 
1528  virtual void SetDirty();
1529 
1532  void ReloadMode();
1533 
1536  void ResetMode();
1537 
1541  void SetRetValue(int value);
1542 
1558  virtual int DoMode();
1559 
1560 #ifdef _DEBUG
1561 public: // Debugging methods
1562 
1566  void DumpMemory();
1567 #endif
1568 };
1569 
1570 //------------------------------------------------------------------------------------------------------------------------------------
1571 
1573 {
1574  return &m_ModeConfig;
1575 }
1576 
1578 {
1579  m_Dirty = true;
1580 }
1581 
1583 {
1584  return m_CurTooltip.shown;
1585 }
1586 
1587 #include <CSMAPI_endcode.h>
#define MODE_INSTANCE_MAX_THREADS
Maximum allocatable threads per mode instance.
Definition: CSMAPI_BaseModeInstance.h:76
MENU_CONTROLS_DRAW_FRAME
States of the menu control element.
Definition: CSMAPI_BaseModeInstance.h:150
@ NORMAL
Opened.
Definition: CSMAPI_BaseModeInstance.h:155
@ DEPRESSED
Closed.
Definition: CSMAPI_BaseModeInstance.h:158
@ ANIMATED
Being animated (opening, closing)
Definition: CSMAPI_BaseModeInstance.h:152
unsigned int EventScheduleId
The identifier for a schedule's ID.
Definition: CSMAPI_BaseModeInstance.h:59
#define MODE_INSTANCE_MAX_SURFACES
Maximum allocatable surfaces per mode instance.
Definition: CSMAPI_BaseModeInstance.h:73
MENU_CONTROLS_DRAW_POSITION
How to draw the menu controls.
Definition: CSMAPI_BaseModeInstance.h:130
@ CDP_BTM_RIGHT
Draw them in bottom right.
Definition: CSMAPI_BaseModeInstance.h:141
@ CDP_CENTER
Draw them in the middle of the screen.
Definition: CSMAPI_BaseModeInstance.h:144
@ CDP_TOP_LEFT
Draw them in the top left.
Definition: CSMAPI_BaseModeInstance.h:132
@ CDP_BTM_LEFT
Draw them in bottom left.
Definition: CSMAPI_BaseModeInstance.h:138
@ CDP_TOP_RIGHT
Draw them in top right.
Definition: CSMAPI_BaseModeInstance.h:135
MENU_CONTROLS_ACTS
Act descriptors for menu controls.
Definition: CSMAPI_BaseModeInstance.h:164
@ MCA_CLOSING
Closing.
Definition: CSMAPI_BaseModeInstance.h:172
@ MCA_CLOSED
Closed.
Definition: CSMAPI_BaseModeInstance.h:175
@ MCA_FIRST_OPEN
First open.
Definition: CSMAPI_BaseModeInstance.h:166
@ MCA_OPENED
Opened.
Definition: CSMAPI_BaseModeInstance.h:169
@ MCA_OPENING
Opening.
Definition: CSMAPI_BaseModeInstance.h:178
#define MODE_INSTANCE_MAX_TEXTURES
Maximum allocatable textures per mode instance.
Definition: CSMAPI_BaseModeInstance.h:70
KEY_CONTROL_INPUT_TYPE
The type of key input to expect from a KeyControlStruct.
Definition: CSMAPI_BaseModeInstance.h:184
@ KCIT_MOUSE
Mouse input.
Definition: CSMAPI_BaseModeInstance.h:195
@ KCIT_KEY2
Key2 input (gKey2, gKeyTrg2)
Definition: CSMAPI_BaseModeInstance.h:189
@ KCIT_KEY
Normal input (gKey, gKeyTrg)
Definition: CSMAPI_BaseModeInstance.h:186
@ KCIT_KEY3
Key3 input (gKey3, gKeyTrg3)
Definition: CSMAPI_BaseModeInstance.h:192
unsigned int ModeThreadId
The identifier for a ModeThreadInstance's ID.
Definition: CSMAPI_BaseModeInstance.h:55
MODE_GLOBAL_CONFIG_TYPE
Global variables for BaseModeInstance classes.
Definition: CSMAPI_BaseModeInstance.h:122
@ GCT_IGNORE_WINDOW_DEFAULT
Defines the default value for m_ModeConfig.IgnoreWindow.
Definition: CSMAPI_BaseModeInstance.h:124
void(* EventSchedulePayloadFunc)(BaseModeInstance *pOwner, void *pUserData)
The function structure of a payload for 'EventScheduleStruct'.
Definition: CSMAPI_BaseModeInstance.h:65
CSMP_CURSOR_TYPE
All possible cursor types for BaseModeInstance::SetCursor.
Definition: CSMAPI_enums.h:1168
Surface_Ids
List of surface IDs.
Definition: CSMAPI_enums.h:714
GameProcessMode
Controls what the game is currently doing.
Definition: CSMAPI_enums.h:970
KeyInputType
Key input types.
Definition: CSMAPI_enums.h:66
@ KIT_Key
gKey and gKeyTrg
Definition: CSMAPI_enums.h:68
Holds all global config variables for BaseModeInstance.
Definition: CSMAPI_BaseModeInstance.h:579
GLOBAL_CONFIG_STRUCT()
Constructor.
Definition: CSMAPI_BaseModeInstance.h:591
bool IgnoreWindow
Default value for m_ModeConfig.IgnoreWindow.
Definition: CSMAPI_BaseModeInstance.h:583
bool RefreshAllModes
Default value for m_ModeConfig.IgnoreWindow.
Definition: CSMAPI_BaseModeInstance.h:587
Easy UI management.
Definition: CSMAPI_BaseModeInstance.h:469
virtual void ProcessLogic()=0
Process the logic of this menu.
static void DrawHUD(int OffsetX=0, int OffsetY=0)
Draw HUD.
void * m_PrivData
Pointer to private data structure, defined by each mode.
Definition: CSMAPI_BaseModeInstance.h:818
virtual int GetRelativeScreenHeight()
Get the game window's height relative to this mode.
static GameProcessMode ShowTutorialPages(BaseModeInstance *pCaller, int iPageCount,...)
Show a messagebox that allows the user to scroll through a list of tutorial pages.
static bool CancelSchedule(EventScheduleId iEventId)
BaseModeInstance()
Initialize certain values.
virtual void QueryMenuControls(KeyControlStruct pControlBuffer[32], int &pControlCount, bool &bStackControls)
Ask the mode to populate pControlBuffer with its control scheme.
int GetTextureCenteredX(int Index)
Get the screen-centered X position of a texture.
int AllocTexture(int InsertIndex=-1, int Width=WINDOW_WIDTH, int Height=WINDOW_HEIGHT, int BitsPerPixel=32, int Magnification=-1, int WindowIndex=0)
Allocate private resources.
virtual void ProcessKeys()=0
Process key input.
static void ShowCursor()
Show the cursor.
int GetTextureCenteredY(int Index)
Get the screen-centered Y position of a texture.
int AllocSurface(int InsertIndex=-1, int Width=WINDOW_WIDTH, int Height=WINDOW_HEIGHT, unsigned int iMagnification=0)
Allocate private resources.
int LoadImageToTexture(const char *FileName, int InsertIndex=-1)
Allocate private resources.
void DrawTexture(int Index, int X=0, int Y=0, unsigned char Alpha=255, bool bSubPixels=false, bool bWrapCoordinates=false)
Draw an allocated texture onto the screen.
void DrawSurface(int Index, int X=0, int Y=0, unsigned char Alpha=255, bool AbsolutePos=false)
Draw an allocated surface on the screen.
static void ProcessScheduleList()
Process all schedules.
int LoadImageToSurface(const char *FileName, int InsertIndex=-1)
Allocate private resources.
void SetTooltipPosition(GUI_POINT new_position)
Set the tooltip's position.
void ProcessTooltips()
Process the current & old tooltips.
virtual void SetDirty()
Set this mode as dirty.
Definition: CSMAPI_BaseModeInstance.h:1577
int LoadSurfaceIDToSurface(Surface_Ids SurfaceID, int InsertIndex=-1)
Allocate private resources.
ModeConfiguration * GetModeConfig()
Get a pointer to this mode's config.
Definition: CSMAPI_BaseModeInstance.h:1572
virtual int GetRelativeScreenWidth()
Get the game window's width relative to this mode.
int GetSurfaceHeight(int Index)
Get the height of an allocated surface.
ToolTipStruct m_CurTooltip
The tooltip that is currently being shown.
Definition: CSMAPI_BaseModeInstance.h:684
virtual GUI_POINT TranslateMousePosition(GUI_POINT *pMouseInput)
Translate the mouse position to relative coordinates.
void SetMenuControlsAct(MENU_CONTROLS_ACTS NewAct)
Set the act number of the menu controls menu.
void SetModePaused(bool bValue)
Set the 'paused' value for this mode.
bool GrabScreen()
Backup the screen to a surface.
GUI_POINT GetTextureRelativeMousePoint(int Index)
Get the current mouse position relative to a texture.
uint32_t GetRectHoverTime(GUI_POINT mouse_point, GUI_RECT rect)
A helper method.
static GLOBAL_CONFIG_STRUCT g_GlobalConfig
The global configuration.
Definition: CSMAPI_BaseModeInstance.h:600
virtual void Draw()=0
Draw rendered surfaces.
GUI_POINT GetTextureCentered(int Index)
Get the screen-centered position of a texture.
int GetTextureHeight(int Index, bool Magnified=true)
Get the height of an allocated texture.
ModeConfiguration m_ModeConfig
The configuration for this mode.
Definition: CSMAPI_BaseModeInstance.h:757
void ResetMode()
Reset the mode.
virtual GUI_POINT TranslateMousePosition(GUI_POINT *pMouseInput, const GUI_POINT &pWindowOffset)
Translate the mouse position to relative coordinates.
void UpdateScreenGrab()
Update the screen grab surface.
int GetSelectedTexture()
Get the currently selected texture.
static void ReloadFont(const char *pFontName, const char *pFontPath, int iFontW=-1, int iFontH=-1, unsigned int iMagnification=0)
Reload the default font.
static void DrawControls(MENU_CONTROLS_DRAW_POSITION DrawPosition, Surface_Ids destSID, const KeyControlStruct *Buttons, int ButtonCount, bool Flash=false, bool StackControls=false, int Alpha=255, unsigned int CustomMagnification=0)
Draw standard controls.
bool m_Dirty
Controls whether this mode should re-render.
Definition: CSMAPI_BaseModeInstance.h:795
bool CreateTextureTooltip(GUI_POINT point, FontObject *font, const char *text, int life_time=5000, int Magnification=-1)
Create a texture tooltip.
void FreeSurface(int Index)
Free a previously allocated surface.
void DoEscapeMenu()
Open the escape menu.
void SelectSurface(int Index)
Select a previously allocated surface.
void DrawMenuControls(MENU_CONTROLS_DRAW_POSITION DrawPosition, MENU_CONTROLS_DRAW_FRAME DrawFrame)
Draw the menu control surfaces generated by CreateMenuControls.
ToolTipStruct m_OldTooltip
The tooltip that is fading out.
Definition: CSMAPI_BaseModeInstance.h:680
bool StopThread(ModeThreadId iThreadId, bool bWaitForFinish=false)
Stop a thread.
int GetCenteredX(int Index)
Get the screen-centered X position of a surface.
virtual int DoMode()
Run this mode until it stops.
static void CancelAllModeSchedules(BaseModeInstance *pMode)
virtual int ModePixelToScreenPixel(int iInput)
Convert a mode coordinate to screen coordinates.
void DrawScreenGrab()
Draw the backed up screen.
GUI_POINT GetRelativeMousePosition(int iIndex)
Get the mouse position relative to a surface.
virtual void EndMode(int value=0x6FFFFFFF, bool bSchedule=false)
End this mode.
void SelectTexture(int Index)
Select a previously allocated surface.
int m_RetValue
Controls the return value of DoMode() internally.
Definition: CSMAPI_BaseModeInstance.h:812
virtual void PreRender()=0
Render everything to surfaces.
bool CreateMenuControls(const KeyControlStruct *Buttons, int ButtonCount, bool StackControls=false)
Create control surfaces.
ModeThreadId StartAsyncOperation(ModeThreadInstance::ModeCallback_OnThreadLoop pOnLoopFunc, ModeThreadInstance::ModeCallback_OnThreadComplete pOnCompleteFunc=NULL, void *pUserData=NULL)
Begin a thread-safe asynchronous operation.
static CSMP_CURSOR_TYPE GetCursor(GUI_RECT **pRect=NULL, int *pEventId=NULL)
Get the current cursor type.
virtual int Init()=0
Initialize this mode.
static void DrawGame(bool AllowACT=true, int OffsetX=0, int OffsetY=0, bool DoPutFade=true, bool bRunGameLogic=true)
Draw game elements.
Surface_Ids m_ScreenGrabSurf
The screen grab surface ID.
Definition: CSMAPI_BaseModeInstance.h:791
static void SetCursor(CSMP_CURSOR_TYPE iType, int iEventId=-1, GUI_RECT *pRect=NULL)
Set the current cursor.
bool IsModeFreeRunning()
Check to see if this mode is running in freerun mode.
void FreeTexture(int Index)
Free a previously allocated texture.
int DrawBasicWindow(GUI_RECT *pRect=NULL)
Draw a basic window.
virtual void ProcessMouse(GUI_POINT mouse_point)=0
Process this menu's mouse.
void FreeAllSurfaces()
Free all allocated surfaces.
void InitControlMenu()
Initialize the control menu.
virtual int GetMagnification()
Fetch the magnification level for this UI.
void DrawTooltips()
Draw the current & old tooltips.
static void ReloadOpenModes()
Reload all currently opened modes.
static FontObject * GetDefaultFont(unsigned int iMagnification=0)
Get the default font that all GUIs should use.
int GetRetValue()
Get the return value for this mode.
bool IsFocusedMode()
Check to see if this mode is the currently focused mode.
bool IsTooltipOpen()
Check to see if a tooltip is open.
Definition: CSMAPI_BaseModeInstance.h:1582
bool IsLocalSurfaceAllocated(int Index)
Check to see if a surface at a given local index is allocated.
void SetRetValue(int value)
Set the return value.
void ReleaseScreenGrab()
Release this mode's screengrab.
bool CloseTooltip(bool fade_out=true)
Close the currently opened tooltip.
void FreeAllTextures()
Free all allocated textures.
virtual void PostDraw()
Draw rendered surfaces over top of everything else.
Definition: CSMAPI_BaseModeInstance.h:877
VideoTexture * GetLocalVideoTexture(int LocalIndex)
Get a locally allocated video texture object by its index.
static void ScheduleReloadOpenModes()
Reload all currently opened modes.
bool m_FreeCall
Controls whether this mode is in free-call mode.
Definition: CSMAPI_BaseModeInstance.h:803
int GetCenteredY(int Index)
Get the screen-centered Y position of a surface.
static void HideCursor()
Hide the cursor.
bool m_End
Controls whether this mode should end.
Definition: CSMAPI_BaseModeInstance.h:799
int GlobalSurfaceIndexToLocal(Surface_Ids sId)
Convert the global index of a surface to a local index.
bool IsControlMenuOpen()
Check to see if the control menu is open.
MENU_CONTROLS_ACTS GetMenuControlsAct()
Get the act number of the menu controls menu.
int GetTextureWidth(int Index, bool Magnified=true)
Get the width of an allocated texture.
void RemoveKey(int iInputFlags, KeyInputType iType=KeyInputType::KIT_Key)
Remove key inputs after processing them.
ModeCallback_OnEnd OnEnd
This is called when the mode is ending, just before 'Free()'.
Definition: CSMAPI_BaseModeInstance.h:722
int LoadSurfaceIDToTexture(Surface_Ids SurfaceID, int InsertIndex=-1)
Allocate private resources.
void ResetRectHover()
Reset rect hover system.
static void RunGameLogic(bool AllowACT=true)
Run game logic.
void StartAllNewThreads()
Start all new threads.
void FinishTexture(int Index)
Finish drawing a texture.
int GetSelectedSurface()
Get the currently selected surface.
static GUI_POINT GetControlKeySize(const KeyControlStruct *Buttons, int ButtonCount, bool StackControls=false, unsigned int CustomMagnification=0)
Get the size of what DrawControls() would output to the screen.
virtual int Free()=0
De-initialize this mode.
GUI_RECT * GetTooltipRect()
Get a pointer to the tooltip's rect.
Surface_Ids LocalSurfaceIndexToGlobal(int Index)
Convert the local index of a surface we own to a global index.
int GetSurfaceWidth(int Index)
Get the width of an allocated surface.
virtual bool ModeTick()
Run this mode for one frame.
static void SetGlobalConfig(MODE_GLOBAL_CONFIG_TYPE eType, const char *pValue)
Set the value of a global config variable.
bool IsLocalTextureAllocated(int Index)
Check to see if a texture at a given local index is allocated.
void ReloadMode()
Reload this mode.
static bool IsSchedulePending(EventScheduleId iEventId)
static EventScheduleId Schedule(unsigned int iDelay, EventSchedulePayloadFunc pPayloadFunc, void *pUserData=NULL, BaseModeInstance *pOwner=NULL)
Schedule an event for later.
void EnforceBasicWindowSize(GUI_RECT *pRect)
Ensure a rect conforms to the size of a basic window.
void FreeAllThreads()
Stop & wait for all threads to finish.
bool m_FreeCall_Paused
Controls whether this mode is paused or not.
Definition: CSMAPI_BaseModeInstance.h:807
bool CreateTooltip(GUI_POINT point, FontObject *font, const char *text, int life_time=5000)
Create a tooltip.
virtual bool StartMode()
Initialize the mode in free-call mode.
An external window to render stuff on.
Definition: ExternalWindow.h:151
A helpful 2D vector class to manage mode input.
Definition: ModeInputVector.h:275
Easy multi-threading for modes.
Definition: CSMAPI_BaseModeInstance.h:288
ModeThreadId m_ThreadId
This thread's local ID.
Definition: CSMAPI_BaseModeInstance.h:342
void End(int iResult=0)
End the thread.
BaseModeInstance * m_Owner
The owner of this thread.
Definition: CSMAPI_BaseModeInstance.h:354
void * m_UserData
Function callback userdata.
Definition: CSMAPI_BaseModeInstance.h:378
ModeThreadInstance()
Main constructor.
void WaitToFinish()
Wait for the thread to finish.
bool InitThread(BaseModeInstance *pOwner, ModeCallback_OnThreadLoop pOnLoopFunc, ModeCallback_OnThreadComplete pOnCompleteFunc, void *pUserData=NULL)
Initialize this thread instance.
void LockUnique()
Lock a critical part of code.
void * m_Mutex
This thread's unique mutex.
Definition: CSMAPI_BaseModeInstance.h:362
~ModeThreadInstance()
Deconstructor.
void Detach()
Detach this thread.
int GetResult()
Get the return result.
void __Complete_And_Send_Result__()
Complete this mode.
void UnlockUnique()
Unlock a critical part of code.
static void Lock()
Lock a critical part of code.
ModeCallback_OnThreadComplete m_OnLoop
Called every frame.
Definition: CSMAPI_BaseModeInstance.h:350
static void Unlock()
Unlock a critical part of code.
static bool TryLock()
Try to lock a critical part of code.
bool TryLockUnique()
Try to lock a critical part of code.
void(* ModeCallback_OnThreadComplete)(BaseModeInstance *pMode, ModeThreadInstance *pThread, void *pUserData)
Callback function for when a thread completes.
Definition: CSMAPI_BaseModeInstance.h:328
ThreadState
Thread states.
Definition: CSMAPI_BaseModeInstance.h:307
ThreadState m_State
The state of this thread.
Definition: CSMAPI_BaseModeInstance.h:366
ModeCallback_OnThreadComplete m_OnComplete
Called when the asynchronous operation ends, by any means.
Definition: CSMAPI_BaseModeInstance.h:346
bool m_Running
This is controlled by the async function.
Definition: CSMAPI_BaseModeInstance.h:370
void(* ModeCallback_OnThreadLoop)(BaseModeInstance *pMode, ModeThreadInstance *pThread, void *pUserData)
Callback function for when a thread completes.
Definition: CSMAPI_BaseModeInstance.h:332
int m_Result
The result from the async operation.
Definition: CSMAPI_BaseModeInstance.h:374
bool Start()
Start the thread.
void * m_Thread
The thread for this mode.
Definition: CSMAPI_BaseModeInstance.h:358
An editable texture API.
Definition: VideoTexture.h:51
#define CAVESTORY_MOD_API
Exports / imports Cavestory Mod API functions & classes.
Definition: CSMAPI_begincode.h:30
Configuration class for BaseModeInstance.
Definition: CSMAPI_BaseModeInstance.h:484
int OpenedAlpha
The alpha value when the menu controls are opened (0 - 255)
Definition: CSMAPI_BaseModeInstance.h:543
int HideTime
The amount of time it takes to close the menu controls.
Definition: CSMAPI_BaseModeInstance.h:551
bool AllowKeyControl
Allow keyboard control – If false, then BaseModeInstance::ProcessKeys is not called.
Definition: CSMAPI_BaseModeInstance.h:495
bool IgnoreWindow
Ignore window input requirement - If true, ProcessKeys and ProcessMouse will always be queried regard...
Definition: CSMAPI_BaseModeInstance.h:491
int ClosedAlpha
The alpha value when the menu controls are closed (0 - 255)
Definition: CSMAPI_BaseModeInstance.h:539
bool OpenOnTab
Open when 'TAB' is pressed.
Definition: CSMAPI_BaseModeInstance.h:531
bool Enabled
If menu controls are actually enabled.
Definition: CSMAPI_BaseModeInstance.h:519
unsigned int CustomMagnification
The return code that pressing Alt+F4 should provide.
Definition: CSMAPI_BaseModeInstance.h:511
bool OpenOnHover
Open when hovered over.
Definition: CSMAPI_BaseModeInstance.h:535
bool AllowMouseControl
Allow mouse control – If false, then BaseModeInstance::ProcessMouse is not called.
Definition: CSMAPI_BaseModeInstance.h:499
int FrameTime
The amount of time it takes to open the menu controls.
Definition: CSMAPI_BaseModeInstance.h:547
MENU_CONTROLS_DRAW_POSITION DrawPosition
The draw position for menu controls.
Definition: CSMAPI_BaseModeInstance.h:523
int AltF4RetValue
The return code that pressing Alt+F4 should provide.
Definition: CSMAPI_BaseModeInstance.h:507
bool AllowAutoHide
Automatically hide the menu controls after a while.
Definition: CSMAPI_BaseModeInstance.h:527
bool ProcessMouseOnMove
Only process mouse on movement – If true, then BaseModeInstance::ProcessMouse will only be called whe...
Definition: CSMAPI_BaseModeInstance.h:503
ExternalWindow * Window
The external window this mode belongs to.
Definition: CSMAPI_BaseModeInstance.h:487
Used for handling input.
Definition: CSMAPI_BaseModeInstance.h:763
unsigned int KeyTrg
Same as gKeyTrg.
Definition: CSMAPI_BaseModeInstance.h:770
unsigned int Key2
Same as gKey2.
Definition: CSMAPI_BaseModeInstance.h:774
unsigned int Key_JOY
Same as gKey_JOY.
Definition: CSMAPI_BaseModeInstance.h:782
unsigned int KeyTrg2
Same as gKeyTrg2.
Definition: CSMAPI_BaseModeInstance.h:778
unsigned int KeyTrg_JOY
Same as gKeyTrg_JOY.
Definition: CSMAPI_BaseModeInstance.h:786
unsigned int Key
Same as gKey.
Definition: CSMAPI_BaseModeInstance.h:766
Scheduled Event Info.
Definition: CSMAPI_BaseModeInstance.h:222
EventScheduleId id
The ID for this schedule.
Definition: CSMAPI_BaseModeInstance.h:225
BaseModeInstance * executor
The mode that scheduled this event.
Definition: CSMAPI_BaseModeInstance.h:233
EventScheduleStruct * next
The next event in the link.
Definition: CSMAPI_BaseModeInstance.h:249
bool is_executing
Whether or not this schedule is already being executed.
Definition: CSMAPI_BaseModeInstance.h:245
unsigned long long int end_time
The timestamp that GetTicks() should reach for this schedule to execute its payload.
Definition: CSMAPI_BaseModeInstance.h:229
void * user_data
The user data to be included in the payload call.
Definition: CSMAPI_BaseModeInstance.h:241
EventSchedulePayloadFunc payload
The payload function.
Definition: CSMAPI_BaseModeInstance.h:237
Manages points.
Definition: CSMAPI_types.h:546
Definition: CSMAPI_types.h:842
For MenuControls.
Definition: CSMAPI_BaseModeInstance.h:203
KEY_CONTROL_INPUT_TYPE Type
The type of input to expect.
Definition: CSMAPI_BaseModeInstance.h:206
char Desc[128]
The description of what happens when you press this button.
Definition: CSMAPI_BaseModeInstance.h:214
int Key
What button to display (gKeyShot, gKeyCancel, etc.) Only takes one trigger flag, so don't include mor...
Definition: CSMAPI_BaseModeInstance.h:210
ToolTip Info.
Definition: CSMAPI_BaseModeInstance.h:257
GUI_RECT rect
The showing position for this tooltip.
Definition: CSMAPI_BaseModeInstance.h:264
int surface_idx
The surface index that is allocated for this tooltip.
Definition: CSMAPI_BaseModeInstance.h:268
int life_time
The life time for this tooltip in milliseconds.
Definition: CSMAPI_BaseModeInstance.h:280
int texture_idx
The texture index that is allocated for this tooltip.
Definition: CSMAPI_BaseModeInstance.h:272
bool shown
Whether or not this tooltip is currently being shown.
Definition: CSMAPI_BaseModeInstance.h:260
int start_time
The time that this tooltip started being displayed.
Definition: CSMAPI_BaseModeInstance.h:276