Cavestory Mod API
ExternalWindow.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>
31 
32 #pragma once
33 
37 
38 //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
39 
40 class VideoTexture;
41 class ExternalWindow;
42 struct SDL_Texture;
43 struct SDL_Window;
44 struct SDL_Renderer;
45 union SDL_Event;
46 
47 //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
48 
52 {
54  EXTERNAL_WINDOW_HITTEST_NORMAL = 0,//SDL_HITTEST_NORMAL,
55 
57  EXTERNAL_WINDOW_HITTEST_DRAGGABLE = 1,//SDL_HITTEST_DRAGGABLE,
58 
60  EXTERNAL_WINDOW_HITTEST_RESIZE_TOPLEFT = 2,//SDL_HITTEST_RESIZE_TOPLEFT,
61 
63  EXTERNAL_WINDOW_HITTEST_RESIZE_TOP = 3,//SDL_HITTEST_RESIZE_TOP,
64 
66  EXTERNAL_WINDOW_HITTEST_RESIZE_TOPRIGHT = 4,//SDL_HITTEST_RESIZE_TOPRIGHT,
67 
69  EXTERNAL_WINDOW_HITTEST_RESIZE_RIGHT = 5,//SDL_HITTEST_RESIZE_RIGHT,
70 
72  EXTERNAL_WINDOW_HITTEST_RESIZE_BOTTOMRIGHT = 6,//SDL_HITTEST_RESIZE_BOTTOMRIGHT,
73 
75  EXTERNAL_WINDOW_HITTEST_RESIZE_BOTTOM = 7,//SDL_HITTEST_RESIZE_BOTTOM,
76 
78  EXTERNAL_WINDOW_HITTEST_RESIZE_BOTTOMLEFT = 8,//SDL_HITTEST_RESIZE_BOTTOMLEFT,
79 
81  EXTERNAL_WINDOW_HITTEST_RESIZE_LEFT = 9,//SDL_HITTEST_RESIZE_LEFT
82 };
83 
89 typedef ExternalWindow_HitResult (*ExternalWindow_HitTestFunc)(ExternalWindow* pWindow, GUI_POINT pPoint, void* pUserData);
90 
96 typedef void (*ExternalWindow_OnResizeFunc)(ExternalWindow* pWindow, GUI_POINT pOldSize, GUI_POINT pNewSize, void* pUserData);
97 
98 //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
99 
103 {
106 
109 
112 
115 
118 
123 
128 
131 
134 };
135 
136 //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
137 
140 {
143  SDL_Texture* texture;
144 };
145 
146 //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
147 
151 {
152 public: // Linkage
153 
156  static SDL_Window* mouse_focused;
157 
161 
165 
169 
170 protected: // Protected variables
171 
175 
179 
183 
187 
188 public: // Callbacks
189 
193 
197 
198 public: // Important variables
199 
203 
207 
211 
214  SDL_Renderer* m_pRenderer;
215 
218  SDL_Window* m_pWindow;
219 
222  unsigned int m_iFlags;
223 
227 
231 
232 public: // Cache variables
233 
236  struct
237  {
241 
244  int WindowID;
245  } m_pCache;
246 
247 public: // C++ Stuff
248 
252 
256 
257 public: // Protected methods
258 
269  bool Init(const char* pTitle, GUI_POINT* pPoint, GUI_POINT pSize, unsigned int iFlags = 0, int iMagnification = -1, bool bStartHidden = false);
270 
273  void Free();
274 
278  inline bool IsInitialized() { return m_bInitialized; }
279 
280 public: // Update methods
281 
284  void UpdateFlags();
285 
286 public: // Texture management
287 
291  void RegisterTexture(VideoTexture* pTexture);
292 
297 
298 public: // Window management methods
299 
304 
309 
313  void SetWindowOpacity(unsigned char iOpacity);
314 
320  unsigned char GetWindowOpacity();
321 
325  void SetWindowVisible(bool bVisible);
326 
331 
336 
340  void SetWindowPosition(GUI_POINT pNewPosition);
341 
346 
350  void SetWindowSize(GUI_POINT pNewSize);
351 
355  const char* GetWindowTitle();
356 
360  void SetWindowTitle(const char* pNewTitle);
361 
364  void FocusWindow();
365 
368  void Maximize();
369 
372  void Minimize();
373 
374 public: // Input methods
375 
379  void OnInputEvent(SDL_Event* pEvent);
380 
384  void SetHitTestFunc(ExternalWindow_HitTestFunc pFunc, void* pUserData);
385 
390 
396  static bool TestWindowInputFocus(ExternalWindow* pWindow);
397 
403  static bool TestWindowMouseFocus(ExternalWindow* pWindow);
404 
405 public: // Render methods
406 
412  SDL_Texture* GetSurfaceTexture(Surface_Ids iSurfaceId);
413 
416  void FlipWindow();
417 };
418 
419 //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
420 
421 #include <CSMAPI_endcode.h>
422 
424 ///
Surface_Ids
List of surface IDs.
Definition: CSMAPI_enums.h:714
@ SURFACE_ID_MAX
Number of surfaces.
Definition: CSMAPI_enums.h:866
ExternalWindowFlags
Flags for ExternalWindow.
Definition: ExternalWindow.h:103
@ EXTERNAL_WINDOW_TOPMOST
Window is always topmost window.
Definition: ExternalWindow.h:133
@ EXTERNAL_WINDOW_MINIMIZED
Window is minimized.
Definition: ExternalWindow.h:105
@ EXTERNAL_WINDOW_BORDERLESS
Window has no border.
Definition: ExternalWindow.h:114
@ EXTERNAL_WINDOW_MAXIMIZED
Window is maximized.
Definition: ExternalWindow.h:108
@ EXTERNAL_WINDOW_HIDDEN
Window is hidden.
Definition: ExternalWindow.h:111
@ EXTERNAL_WINDOW_RESIZABLE
Window can be resized.
Definition: ExternalWindow.h:117
@ EXTERNAL_WINDOW_TOOLWINDOW
Window is a tooltip window.
Definition: ExternalWindow.h:130
@ EXTERNAL_WINDOW_HAS_INPUT_FOCUS
Window has input focus.
Definition: ExternalWindow.h:122
@ EXTERNAL_WINDOW_HAS_MOUSE_FOCUS
Window has mouse focus.
Definition: ExternalWindow.h:127
void(* ExternalWindow_OnResizeFunc)(ExternalWindow *pWindow, GUI_POINT pOldSize, GUI_POINT pNewSize, void *pUserData)
Callback for resizing the window.
Definition: ExternalWindow.h:96
ExternalWindow_HitResult(* ExternalWindow_HitTestFunc)(ExternalWindow *pWindow, GUI_POINT pPoint, void *pUserData)
Callback for hittesting.
Definition: ExternalWindow.h:89
ExternalWindow_HitResult
Hittest result.
Definition: ExternalWindow.h:52
@ EXTERNAL_WINDOW_HITTEST_RESIZE_RIGHT
Region is the right resizer.
Definition: ExternalWindow.h:69
@ EXTERNAL_WINDOW_HITTEST_RESIZE_TOP
Region is the top resizer.
Definition: ExternalWindow.h:63
@ EXTERNAL_WINDOW_HITTEST_RESIZE_LEFT
Region is the left resizer.
Definition: ExternalWindow.h:81
@ EXTERNAL_WINDOW_HITTEST_RESIZE_TOPLEFT
Region is the topleft resizer.
Definition: ExternalWindow.h:60
@ EXTERNAL_WINDOW_HITTEST_NORMAL
No special properties.
Definition: ExternalWindow.h:54
@ EXTERNAL_WINDOW_HITTEST_RESIZE_TOPRIGHT
Region is the topright resizer.
Definition: ExternalWindow.h:66
@ EXTERNAL_WINDOW_HITTEST_DRAGGABLE
Region can drag entire window.
Definition: ExternalWindow.h:57
@ EXTERNAL_WINDOW_HITTEST_RESIZE_BOTTOM
Region is the bottom resizer.
Definition: ExternalWindow.h:75
@ EXTERNAL_WINDOW_HITTEST_RESIZE_BOTTOMLEFT
Region is the bottomleft resizer.
Definition: ExternalWindow.h:78
@ EXTERNAL_WINDOW_HITTEST_RESIZE_BOTTOMRIGHT
Region is the bottomright resizer.
Definition: ExternalWindow.h:72
An external window to render stuff on.
Definition: ExternalWindow.h:151
GUI_POINT GetWindowSize()
Get the size of this window.
int WindowID
The window's ID.
Definition: ExternalWindow.h:244
void SetWindowMaximumSize(GUI_POINT pSize)
Set the maximum size for this window.
int m_iVideoTextureCount
The number of textures allocated to this window.
Definition: ExternalWindow.h:182
ExternalWindow_HitTestFunc m_pHitTestFunc
A pointer to the hit test function.
Definition: ExternalWindow.h:206
void SetWindowPosition(GUI_POINT pNewPosition)
Move this window.
const char * GetWindowTitle()
Get the title of this window.
void SetWindowOpacity(unsigned char iOpacity)
Set the opacity of this window.
static SDL_Window * mouse_focused
First entry in list.
Definition: ExternalWindow.h:156
GUI_POINT GetMousePosition()
Get the mouse position relative to this window.
void Maximize()
Maximize this window.
void * m_pHitTestUserData
The user data for the hitfunc.
Definition: ExternalWindow.h:210
void FlipWindow()
Flip this window.
void RegisterTexture(VideoTexture *pTexture)
Register a texture to this window.
void OnInputEvent(SDL_Event *pEvent)
Handle an input.
ExternalWindow * next
Next entry in list.
Definition: ExternalWindow.h:168
void * CallbackUserData
User data for callback.
Definition: ExternalWindow.h:192
static ExternalWindow * first
First entry in list.
Definition: ExternalWindow.h:160
GUI_POINT GetWindowPosition()
Get the position of this window.
void SetWindowMinimumSize(GUI_POINT pSize)
Set the minimum size for this window.
bool m_bInitialized
Whether this window is initialized already or not.
Definition: ExternalWindow.h:174
int m_iVideoTextureSize
The number of texture slots allocated.
Definition: ExternalWindow.h:186
unsigned int m_iFlags
The flags for this window.
Definition: ExternalWindow.h:222
void Minimize()
Minimize this window.
bool Init(const char *pTitle, GUI_POINT *pPoint, GUI_POINT pSize, unsigned int iFlags=0, int iMagnification=-1, bool bStartHidden=false)
Initialize this window.
GUI_RECT WindowRect
The window's rect.
Definition: ExternalWindow.h:240
~ExternalWindow()
Deconstructor.
bool IsInitialized()
Check to see if this window has been initialized.
Definition: ExternalWindow.h:278
void Free()
Reset this window and its memory.
static bool TestWindowInputFocus(ExternalWindow *pWindow)
Test a window's input focus.
void UnregisterTexture(VideoTexture *pTexture)
Unregister a texture from this window.
ExternalWindow * m_pParent
This window's parent window.
Definition: ExternalWindow.h:202
ExternalWindow * prev
Previous entry in list.
Definition: ExternalWindow.h:164
void FocusWindow()
Focus this window.
SDL_Window * m_pWindow
The SDL window pointer for this window.
Definition: ExternalWindow.h:218
ExternalWindow_OnResizeFunc OnResize
Called every time the window's size is changed.
Definition: ExternalWindow.h:196
SDL_Texture * GetSurfaceTexture(Surface_Ids iSurfaceId)
Get the texture specific to this window's renderer for a surface.
VideoTexture * m_pRendererTexture
The renderer texture for this external window.
Definition: ExternalWindow.h:230
void UpdateFlags()
Update a window's flags.
void SetWindowVisible(bool bVisible)
Set the visibility of this window.
SDL_Renderer * m_pRenderer
The SDL renderer pointer for this window.
Definition: ExternalWindow.h:214
void SetWindowSize(GUI_POINT pNewSize)
Resize this window.
void SetHitTestFunc(ExternalWindow_HitTestFunc pFunc, void *pUserData)
Set the hittest function.
void SetWindowTitle(const char *pNewTitle)
Rename this window.
unsigned char GetWindowOpacity()
Get the visibility of this window.
VideoTexture ** m_pVideoTextureList
Texture allocated to this window.
Definition: ExternalWindow.h:178
static bool TestWindowMouseFocus(ExternalWindow *pWindow)
Test a window's mouse focus.
bool IsWindowVisible()
Get the visibility of this window.
ExternalWindow()
Constructor.
An editable texture API.
Definition: VideoTexture.h:51
#define CAVESTORY_MOD_API
Exports / imports Cavestory Mod API functions & classes.
Definition: CSMAPI_begincode.h:30
Holds information for window-specific information pertaining to surf[].
Definition: ExternalWindow.h:140
SDL_Texture * texture
The texture object for this texture.
Definition: ExternalWindow.h:143
Manages points.
Definition: CSMAPI_types.h:546
Definition: CSMAPI_types.h:842