Cavestory Mod API
ModeInputVector.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 #ifndef CAVESTORY_MOD_API_H_
27 #error "Please include CavestoryModAPI.h before including sub-classes."
28 #endif
29 
30 #include <CSMAPI_begincode.h>
32 
33 #pragma once
34 
38 
41 typedef unsigned int ModeInputSelectionId;
42 
45 typedef unsigned int ModeInputIndex;
46 
49 
53 {
56 
59 
61  MIBS_PRESSED = 2
62 };
63 
64 
67 {
71  bool clickable;
72 
75  struct
76  {
79  int left;
80 
83  int up;
84 
87  int right;
88 
91  int down;
93 
96  struct
97  {
101 
105 
109 
113 
116  FontObject* font;
118 
122  {
123  clickable = true;
124  tooltip.open_for_keyboard = true;
125  tooltip.allocate_text = true;
126  tooltip.surface_offset.x = 0;
127  tooltip.surface_offset.y = 0;
128  tooltip.magnification_lvl = -1;
129  tooltip.font = NULL;
130  increment.left = 1;
131  increment.up = 1;
132  increment.right = 1;
133  increment.down = 1;
134  }
135 };
136 
140 {
143  {
146 
149 
152 
155 
158 
161  };
162 
166 
169  unsigned int flags;
170 
174 
177  struct
178  {
182  bool use;
183 
187 
191 
195 
200 
203  struct
204  {
208 
212 
216 
221 
224  struct
225  {
228  bool use;
229 
233  } clip;
234 
237  struct
238  {
241  bool enabled;
242 
245  char* text;
247 
251 
255 
259 
263 
267 };
268 
275 {
276 private: // Mechanical variables
277 
281  GUI_POINT m_MinSize;
282 
286  ModeInputOption** m_OptionList;
287 
291  int m_OptionCount;
292 
296  ScrollAreaInfo** m_ScrollList;
297 
301  int m_ScrollCount;
302 
306  ModeInputIndex* m_Array;
307 
311  int m_ArrayWidth;
312 
316  int m_ArrayHeight;
317 
318 private: // Selected variables
319 
323  BaseModeInstance* m_Owner;
324 
328  int m_TooltipOption;
329 
333  int m_SelectedOption;
334 
338  int m_OldSelectedOption;
339 
343  bool m_UsedKeyboard;
344 
348  GUI_POINT m_SelectedPos;
349 
353  bool m_IsSelectionProcessing;
354 
355 private: // Lock variables
356 
360  bool m_Dirty;
361 
364  bool m_Locked;
365 
366 public: // State variables
367 
372 
377 
378 public: // C++ stuff
379 
383 
387 
388 protected: // Internal methods
389 
394  bool RebuildArray();
395 
400  bool IndexOptions();
401 
407 
414  ModeInputOption* FindOptionById(ModeInputSelectionId iSelectionId, int* pIndexPtr = NULL);
415 
422 
440 
441 public: // Public memory management
442 
448 
466  bool AddOption(ModeInputSelectionId iSelectionId, ModeInputOptionCoord iX, ModeInputOptionCoord iY, ModeInputOptionCoord iW, ModeInputOptionCoord iH, GUI_RECT* pRect, ScrollAreaInfo* pScroll = NULL, GUI_RECT* pClipRect = NULL, const char* pTooltipText = NULL, ModeInputOptionConfig* pConfig = NULL, unsigned int iFlags = 0);
467 
484  bool AddOption(ModeInputSelectionId iSelectionId, ModeInputOptionCoord iX, ModeInputOptionCoord iY, ModeInputOptionCoord iW, ModeInputOptionCoord iH, GuiBase* pGui, ScrollAreaInfo* pScroll = NULL, GUI_RECT* pClipRect = NULL, const char* pTooltipText = NULL, ModeInputOptionConfig* pConfig = NULL, unsigned int iFlags = 0);
485 
502  bool AddOption(ModeInputSelectionId iSelectionId, ModeInputOptionCoord iX, ModeInputOptionCoord iY, ModeInputOptionCoord iW, ModeInputOptionCoord iH, GUI_RECT pRect, ScrollAreaInfo* pScroll = NULL, GUI_RECT* pClipRect = NULL, const char* pTooltipText = NULL, ModeInputOptionConfig* pConfig = NULL, unsigned int iFlags = 0);
503 
517  bool AddOption(ModeInputSelectionId iSelectionId, GUI_RECT* pRect, ScrollAreaInfo* pScroll = NULL, GUI_RECT* pClipRect = NULL, const char* pTooltipText = NULL, ModeInputOptionConfig* pConfig = NULL, unsigned int iFlags = 0);
518 
535  bool AddOption(ModeInputSelectionId iSelectionId, GuiBase* pGui, ScrollAreaInfo* pScroll = NULL, GUI_RECT* pClipRect = NULL, const char* pTooltipText = NULL, ModeInputOptionConfig* pConfig = NULL, unsigned int iFlags = 0);
536 
553  bool AddOption(ModeInputSelectionId iSelectionId, GUI_RECT pRect, ScrollAreaInfo* pScroll = NULL, GUI_RECT* pClipRect = NULL, const char* pTooltipText = NULL, ModeInputOptionConfig* pConfig = NULL, unsigned int iFlags = 0);
554 
560  bool RemoveOption(ModeInputSelectionId iSelectionId);
561 
567  bool AddScroll(ScrollAreaInfo* pScroll);
568 
571  void Reset();
572 
573 public: // More option methods
574 
581 
588 
589 public: // Selection manipulation methods
590 
597  void SetSelectionByPos(int iX, int iY, bool bUsedKeyboard, bool bOpenTooltip = true);
598 
605  void SetSelectionById(ModeInputSelectionId iSelectionId, bool bUsedKeyboard);
606 
611 
616 
621 
625  inline bool WasKeyboardUsed() { return m_UsedKeyboard; }
626 
627 protected: // Protected tooltip methods
628 
632  void SetTooltip(ModeInputOption* pOption);
633 
640 
641 public: // Tooltip processing
642 
646  inline void SetModeOwner(BaseModeInstance* pMode) { m_Owner = pMode; }
647 
648 public: // Processing methods
649 
654 
661  int MoveSelection(int iXM, int iYM);
662 
668  int ProcessKeys(int* iSelectedOutTrg);
669 
676  int ProcessMouse(int* iSelectedOutTrg, GUI_POINT pMousePoint);
677 
680  void Lock();
681 
684  void Unlock();
685 
686 public: // Debugging methods
687 
690  void DumpMap();
691 };
692 
695 
696 #include <CSMAPI_endcode.h>
Easy UI management.
Definition: CSMAPI_BaseModeInstance.h:469
The base class for GUI elements.
Definition: CSMAPI_types.h:2713
A helpful 2D vector class to manage mode input.
Definition: ModeInputVector.h:275
void DumpMap()
Dump the input map.
void SetMinArraySize(ModeInputOptionCoord iWidth, ModeInputOptionCoord iHeight)
Set the minimum size for this vector.
bool AddOption(ModeInputSelectionId iSelectionId, GuiBase *pGui, ScrollAreaInfo *pScroll=NULL, GUI_RECT *pClipRect=NULL, const char *pTooltipText=NULL, ModeInputOptionConfig *pConfig=NULL, unsigned int iFlags=0)
Add an unselectable option to the vector.
int ProcessKeys(int *iSelectedOutTrg)
Process key input for the vector.
int GetSelectedId()
Get the selected ID.
GUI_POINT GetSelectedPos()
Get the selected position.
bool AddOption(ModeInputSelectionId iSelectionId, ModeInputOptionCoord iX, ModeInputOptionCoord iY, ModeInputOptionCoord iW, ModeInputOptionCoord iH, GUI_RECT pRect, ScrollAreaInfo *pScroll=NULL, GUI_RECT *pClipRect=NULL, const char *pTooltipText=NULL, ModeInputOptionConfig *pConfig=NULL, unsigned int iFlags=0)
Add an option to the vector.
ModeInputOption * FindOptionById(ModeInputSelectionId iSelectionId, int *pIndexPtr=NULL)
Find an option by ID.
bool AddOption(ModeInputSelectionId iSelectionId, GUI_RECT *pRect, ScrollAreaInfo *pScroll=NULL, GUI_RECT *pClipRect=NULL, const char *pTooltipText=NULL, ModeInputOptionConfig *pConfig=NULL, unsigned int iFlags=0)
Add an unselectable option to the vector.
ModeInputVector()
Constructor.
bool m_Clicking
Are we clicking on the selected option whilst hovering over it? Don't change this.
Definition: ModeInputVector.h:371
bool IndexOptions()
Index all options.
bool RemoveOption(ModeInputSelectionId iSelectionId)
Remove an option by ID.
int MoveSelection(int iXM, int iYM)
Move the current selection.
bool AddOption(ModeInputSelectionId iSelectionId, ModeInputOptionCoord iX, ModeInputOptionCoord iY, ModeInputOptionCoord iW, ModeInputOptionCoord iH, GUI_RECT *pRect, ScrollAreaInfo *pScroll=NULL, GUI_RECT *pClipRect=NULL, const char *pTooltipText=NULL, ModeInputOptionConfig *pConfig=NULL, unsigned int iFlags=0)
Add an option to the vector.
GUI_POINT GetArraySize()
Get the array's dimensions.
ModeInputOption * Internal_AddOption(ModeInputSelectionId iSelectionId, ModeInputOptionCoord iX, ModeInputOptionCoord iY, ModeInputOptionCoord iW, ModeInputOptionCoord iH, ScrollAreaInfo *pScroll, GUI_RECT *pClipRect, char *pTooltipText, ModeInputOptionConfig *pConfig, unsigned int iFlags)
The general internal method to add an option.
void Unlock()
Allow the vector to rebuild its array if necessary.
ModeInputButtonState GetOptionState(ModeInputSelectionId iSelectionId)
Get the selected button's determined state.
bool AddOption(ModeInputSelectionId iSelectionId, GUI_RECT pRect, ScrollAreaInfo *pScroll=NULL, GUI_RECT *pClipRect=NULL, const char *pTooltipText=NULL, ModeInputOptionConfig *pConfig=NULL, unsigned int iFlags=0)
Add an unselectable option to the vector.
GUI_RECT Internal_GetOptionRect(ModeInputOption *pOption)
Get the screen rect for an option.
bool WasKeyboardUsed()
Self explanatory.
Definition: ModeInputVector.h:625
void SetTooltip(ModeInputOption *pOption)
Open an option's tooltip.
~ModeInputVector()
Deconstructor.
GUI_RECT GetOptionRect(ModeInputSelectionId iSelectionId)
Get the rect for an option.
void Lock()
Lock the input vector from rebuilding its array.
bool m_Hovering
Are we hovering over the selected option? Don't change this.
Definition: ModeInputVector.h:376
void Reset()
Reset everything – Unallocates all buffers and resets all variables.
bool AddScroll(ScrollAreaInfo *pScroll)
Add a controllable scroll area.
void SetModeOwner(BaseModeInstance *pMode)
Set the mode to use for processing.
Definition: ModeInputVector.h:646
void SetSelectionByPos(int iX, int iY, bool bUsedKeyboard, bool bOpenTooltip=true)
Set the selected option.
bool IsTooltipSetTo(ModeInputOption *pOption)
Test to see if the current tooltip is set to an option.
bool AddOption(ModeInputSelectionId iSelectionId, ModeInputOptionCoord iX, ModeInputOptionCoord iY, ModeInputOptionCoord iW, ModeInputOptionCoord iH, GuiBase *pGui, ScrollAreaInfo *pScroll=NULL, GUI_RECT *pClipRect=NULL, const char *pTooltipText=NULL, ModeInputOptionConfig *pConfig=NULL, unsigned int iFlags=0)
Add an option to the vector.
void SetSelectionById(ModeInputSelectionId iSelectionId, bool bUsedKeyboard)
Set the selected selection ID.
int ProcessMouse(int *iSelectedOutTrg, GUI_POINT pMousePoint)
Process mouse input.
bool RebuildArray()
Rebuild the m_Array array.
ModeInputOption * AllocateOption()
Allocate an option.
int GetSelectedIndex()
Get the selected index.
A scroll area.
Definition: CSMAPI_types.h:3401
int ModeInputOptionCoord
Coordinate type for ModeInputOption.
Definition: ModeInputVector.h:48
unsigned int ModeInputIndex
For ModeInputVector's indexes.
Definition: ModeInputVector.h:45
ModeInputButtonState
Controls the button states for non-GUI driven ModeInputOption s.
Definition: ModeInputVector.h:53
unsigned int ModeInputSelectionId
Used for ModeInputOption.
Definition: ModeInputVector.h:41
@ MIBS_NORMAL
Normal draw type.
Definition: ModeInputVector.h:55
@ MIBS_HOVERED
Button is being hovered over.
Definition: ModeInputVector.h:58
@ MIBS_PRESSED
Button is being pressed.
Definition: ModeInputVector.h:61
#define CAVESTORY_MOD_API
Exports / imports Cavestory Mod API functions & classes.
Definition: CSMAPI_begincode.h:30
Manages points.
Definition: CSMAPI_types.h:546
Definition: CSMAPI_types.h:842
Advanced configuration for a ModeInputOption.
Definition: ModeInputVector.h:67
bool open_for_keyboard
Whether or not to open the tooltip when the user selects it with the keyboard / controller.
Definition: ModeInputVector.h:100
struct ModeInputOptionConfig::@36 tooltip
Tooltip options.
struct ModeInputOptionConfig::@35 increment
Increment options.
bool clickable
Whether this option is clickable or not.
Definition: ModeInputVector.h:71
int up
How much pressing 'up' while this option is selected will increment the selection position by.
Definition: ModeInputVector.h:83
int right
How much pressing 'right' while this option is selected will increment the selection position by.
Definition: ModeInputVector.h:87
bool allocate_text
Whether or not to duplicate the string (true), or to just store a pointer to a buffer (false).
Definition: ModeInputVector.h:104
int magnification_lvl
The amount of magnification for the tooltip.
Definition: ModeInputVector.h:112
FontObject * font
The font to be used for this tooltip.
Definition: ModeInputVector.h:116
GUI_POINT surface_offset
The screen offset of the surface that this option belongs to.
Definition: ModeInputVector.h:108
int left
How much pressing 'left' while this option is selected will increment the selection position by.
Definition: ModeInputVector.h:79
int down
How much pressing 'down' while this option is selected will increment the selection position by.
Definition: ModeInputVector.h:91
ModeInputOptionConfig()
Default constructor.
Definition: ModeInputVector.h:121
ModeInputVector's input object.
Definition: ModeInputVector.h:140
bool use
Whether this option can be built into the array or not.
Definition: ModeInputVector.h:182
GuiBase * gui_ptr
This option's GUI element.
Definition: ModeInputVector.h:262
ModeInputSelectionId selection_id
The ID that will be returned when this option is selected / clicked on.
Definition: ModeInputVector.h:173
GUI_RECT rect
The rect to use.
Definition: ModeInputVector.h:232
ModeInputOptionConfig config
The configuration for this option.
Definition: ModeInputVector.h:250
struct ModeInputOption::@37 input_rect
The input vector position of this option.
char * text
The tooltip text to use.
Definition: ModeInputVector.h:245
struct ModeInputOption::@40 tooltip
The tooltip for this option.
struct ModeInputOption::@38 calculated_input_rect
The calculated input vector rect for this option.
ModeInputOptionCoord y
Y Position.
Definition: ModeInputVector.h:190
ScrollAreaInfo * scroll_ptr
A pointer to the scroll this option is inside of.
Definition: ModeInputVector.h:254
ModeInputOptionCoord x
X Position.
Definition: ModeInputVector.h:186
struct ModeInputOption::@39 clip
The clip rect that should be accessed before this option can be processed.
ModeInputOptionCoord h
Height.
Definition: ModeInputVector.h:198
unsigned int flags
Flags for this option.
Definition: ModeInputVector.h:169
OptionFlags
Flags for ModeInputVector options.
Definition: ModeInputVector.h:143
@ START_FROM_BOTTOM
Subtract this option's input_rect.y value from the array height to get the option's true Y position.
Definition: ModeInputVector.h:154
@ START_FROM_RIGHT
Subtract this option's input_rect.x value from the array width to get the option's true X position.
Definition: ModeInputVector.h:151
@ AUTO_EXPAND_HEIGHT
Auto expand the option's array height to the fullest possible extent.
Definition: ModeInputVector.h:148
@ START_ON_NEW_LINE
Start this option on a new line.
Definition: ModeInputVector.h:157
@ AUTO_EXPAND_WIDTH
Auto expand the option's array width to the fullest possible extent.
Definition: ModeInputVector.h:145
@ AUTOMATION_FLAGS
Automation flags.
Definition: ModeInputVector.h:160
bool enabled
Whether this tooltip is enabled or not.
Definition: ModeInputVector.h:241
ModeInputIndex index
The local index of this option.
Definition: ModeInputVector.h:165
GUI_RECT rect_plain
This option's rect.
Definition: ModeInputVector.h:266
GUI_RECT * rect_ptr
A pointer to this input option's on-screen rect.
Definition: ModeInputVector.h:258
ModeInputOptionCoord w
Width.
Definition: ModeInputVector.h:194