Cavestory Mod API
VideoTexture.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 #pragma once
31 
35 
36 //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
37 
38 #include <CSMAPI_begincode.h>
39 
40 class ExternalWindow;
41 
42 //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
43 
44 #define INVALID_TEXTURE_COLOR 0x10203040
45 
46 //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
47 
51 {
52 public: // Linkage
53 
54  static VideoTexture* first;
55  VideoTexture* prev;
56  VideoTexture* next;
57 
58 public: // Video specific stuff
59 
63 
67 
70  SDL_Texture* m_pOldLockTexture;
71 
75 
79 
82  SDL_Texture* m_pTexture;
83 
86  SDL_Renderer* m_pRenderer;
87 
90  int m_iWidth;
91 
94  int m_iHeight;
95 
99 
103 
107 
111 
115 
118  bool m_bLocked;
119 
123 
127 
131 
132 public: // C++ Stuff
133 
137 
141 
142 public: // Init / free methods
143 
155  static VideoTexture* CreateTexture(int iWidth, int iHeight, int iBitsPerPixel = 32, ExternalWindow* pWindow = NULL, int iMagnification = -1, bool bNoTexture = false);
156 
165  static VideoTexture* CreateTexture(const char* pFileName, ExternalWindow* pWindow = NULL, int iMagnification = -1);
166 
172  static bool FreeTexture(VideoTexture* pTexture);
173 
177  static void ReloadRenderer(int iMagnification);
178 
179 protected: // Protected methods
180 
186  inline bool InClipRect(GUI_RECT pRect);
187 
188 public: // Manipulation methods
189 
194  void SetTextureSize(int iWidth, int iHeight);
195 
200 
205  void SetClipRect(GUI_RECT* pRect, bool bAbsoluteRect = false);
206 
210 
215 
220 
227  void SetDrawColor(unsigned char iRed, unsigned char iGreen, unsigned char iBlue, unsigned char iAlpha);
228 
232  void SetDrawColor(unsigned long iColor);
233 
236  void Lock();
237 
240  void Unlock();
241 
242 public: // Drawing methods
243 
247  void ClearTexture(GUI_RECT* pRect = NULL);
248 
254  void ClearPixels(GUI_POINT* pPointList, unsigned int iPointCount);
255 
260  void DrawPixel(GUI_POINT pPoint, unsigned long iColor = INVALID_TEXTURE_COLOR);
261 
267  void DrawPixels(GUI_POINT* pPointList, unsigned int iPointCount, unsigned long iColor = INVALID_TEXTURE_COLOR);
268 
274  void DrawMagnifiedPixels(GUI_POINT* pPointList, unsigned int iPointCount, unsigned long iColor = INVALID_TEXTURE_COLOR);
275 
285  void DrawStretchedBitmap(GUI_RECT* pRect, GUI_RECT* pSourceRect, Surface_Ids iSurfaceId, unsigned long iColor = INVALID_TEXTURE_COLOR, bool bAbsloutePos = false);
286 
295  void DrawColoredBitmap(GUI_POINT pPoint, GUI_RECT* pSourceRect, Surface_Ids iSurfaceId, unsigned long iColor, bool bAbsolutePos = false);
296 
305  void DrawBitmap(GUI_POINT pPoint, GUI_RECT* pSourceRect, Surface_Ids iSurfaceId, bool bAbsolutePos = false);
306 
315  void DrawBitmapBox(GUI_RECT* out_rect, GUI_RECT* bmp_rects, CacheSurface::BitmapBoxType type, Surface_Ids bmp_id, int iAlpha = 255);
316 
321  void DrawStripedRect(GUI_RECT* pRect, unsigned long iColor = INVALID_TEXTURE_COLOR);
322 
328  void DrawRect(GUI_RECT* pRect, unsigned long iColor = INVALID_TEXTURE_COLOR, bool bAbsolutePos = false);
329 
335  void DrawFilledRect(GUI_RECT* pRect, unsigned long iColor = INVALID_TEXTURE_COLOR, bool bAbsolutePos = false);
336 
342  void DrawStripedLine(GUI_POINT pStart, GUI_POINT pEnd, unsigned long iColor = INVALID_TEXTURE_COLOR);
343 
349  void DrawLine(GUI_POINT pStart, GUI_POINT pEnd, unsigned long iColor = INVALID_TEXTURE_COLOR, bool bAbsolutePos = false);
350 
355  void DrawMagnifiedLine(GUI_POINT pStart, GUI_POINT pEnd, unsigned long iColor = INVALID_TEXTURE_COLOR);
356 
367  void DrawText(GUI_POINT pPoint, FontObject* pFont, const char* pText, int iTextLen = -1, unsigned long iColor = INVALID_TEXTURE_COLOR, bool bWrap = false, int iShadowSize = 0, unsigned long iShadowColor = 0);
368 
379  void DrawMagnifiedText(GUI_POINT pPoint, FontObject* pFont, const char* pText, int iTextLen = -1, unsigned long iColor = INVALID_TEXTURE_COLOR, bool bWrap = false, int iShadowSize = 0, unsigned long iShadowColor = 0);
380 
381 public: // Methods that require temporary rect list
382 
386  void DrawRects(unsigned long iColor = INVALID_TEXTURE_COLOR);
387 
388 public: // Ease-of-access methods
389 
393 
399  void AddTempRect(GUI_RECT pRect);
400 
401 public: // Self-drawing methods
402 
408  void PutAlpha(int iX, int iY, int iAlpha);
409 
415  void PutSubPixel(int iX, int iY, int iAlpha);
416 
421  void Put(int iX, int iY);
422 
434  void PutStretchedAlpha(int iDstX, int iDstY, int iDstW, int iDstH, int iSrcX, int iSrcY, int iSrcW, int iSrcH, int iAlpha);
435 
447  void PutStretchedSubPixel(int iDstX, int iDstY, int iDstW, int iDstH, int iSrcX, int iSrcY, int iSrcW, int iSrcH, int iAlpha);
448 
459  void PutStretched(int iDstX, int iDstY, int iDstW, int iDstH, int iSrcX, int iSrcY, int iSrcW, int iSrcH);
460 };
461 
462 extern CAVESTORY_MOD_API VideoTexture* gRendererTexture;
463 
464 //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
465 
466 #include <CSMAPI_endcode.h>
467 
468 //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
469 
470 
472 ///
Surface_Ids
List of surface IDs.
Definition: CSMAPI_enums.h:714
An external window to render stuff on.
Definition: ExternalWindow.h:151
An editable texture API.
Definition: VideoTexture.h:51
void DrawPixels(GUI_POINT *pPointList, unsigned int iPointCount, unsigned long iColor=INVALID_TEXTURE_COLOR)
Draw multiple pixels.
void DrawLine(GUI_POINT pStart, GUI_POINT pEnd, unsigned long iColor=INVALID_TEXTURE_COLOR, bool bAbsolutePos=false)
Draw a line.
~VideoTexture()
Default deconstructor.
int m_iBitsPerPixel
Number of bits per pixel.
Definition: VideoTexture.h:98
GUI_RECT m_pOldClipRect
The old clip rect to restore after unlocking this texture.
Definition: VideoTexture.h:74
int m_iWidth
The width of this texture.
Definition: VideoTexture.h:90
void SetTextureSize(int iWidth, int iHeight)
Resize this video texture.
void SetClipRect(GUI_RECT *pRect, bool bAbsoluteRect=false)
Set the clip rect for this texture.
void DrawFilledRect(GUI_RECT *pRect, unsigned long iColor=INVALID_TEXTURE_COLOR, bool bAbsolutePos=false)
Draw a filled rectangle to this texture.
void SetDrawColor(unsigned char iRed, unsigned char iGreen, unsigned char iBlue, unsigned char iAlpha)
Set the drawing color.
void DrawRects(unsigned long iColor=INVALID_TEXTURE_COLOR)
Draw multiple rectangles to this texture.
void Put(int iX, int iY)
Draw this texture onto the screen.
void DrawMagnifiedLine(GUI_POINT pStart, GUI_POINT pEnd, unsigned long iColor=INVALID_TEXTURE_COLOR)
Draw a pre-magnified line.
GUI_RECT * m_pClipRectList
A list of clip rects.
Definition: VideoTexture.h:102
void DrawPixel(GUI_POINT pPoint, unsigned long iColor=INVALID_TEXTURE_COLOR)
Draw a pixel.
bool m_bLocked
Whether this texture is currently locked or not.
Definition: VideoTexture.h:118
void ClearTexture(GUI_RECT *pRect=NULL)
Clear this texture.
VideoTexture()
Default constructor.
int m_iClipRectCount
The number of elements in the clip rect list.
Definition: VideoTexture.h:106
SDL_Texture * m_pTexture
This texture's ACTUAL texture.
Definition: VideoTexture.h:82
void DrawStripedLine(GUI_POINT pStart, GUI_POINT pEnd, unsigned long iColor=INVALID_TEXTURE_COLOR)
Draw a striped line.
SDL_Renderer * m_pRenderer
This texture's renderer.
Definition: VideoTexture.h:86
void DrawText(GUI_POINT pPoint, FontObject *pFont, const char *pText, int iTextLen=-1, unsigned long iColor=INVALID_TEXTURE_COLOR, bool bWrap=false, int iShadowSize=0, unsigned long iShadowColor=0)
Draw text on this texture.
int m_iMagnification
The local magnification for this texture.
Definition: VideoTexture.h:114
void PutStretched(int iDstX, int iDstY, int iDstW, int iDstH, int iSrcX, int iSrcY, int iSrcW, int iSrcH)
Draw this texture onto the screen.
GUI_RECT GetClipRect()
Get the current clip rect.
void PutAlpha(int iX, int iY, int iAlpha)
Draw this texture onto the screen with an alpha value.
void PutStretchedAlpha(int iDstX, int iDstY, int iDstW, int iDstH, int iSrcX, int iSrcY, int iSrcW, int iSrcH, int iAlpha)
Draw this texture onto the screen.
void DrawMagnifiedText(GUI_POINT pPoint, FontObject *pFont, const char *pText, int iTextLen=-1, unsigned long iColor=INVALID_TEXTURE_COLOR, bool bWrap=false, int iShadowSize=0, unsigned long iShadowColor=0)
Draw pre-magnified text on this texture.
void DrawBitmapBox(GUI_RECT *out_rect, GUI_RECT *bmp_rects, CacheSurface::BitmapBoxType type, Surface_Ids bmp_id, int iAlpha=255)
Draw a bitmap box.
void AddTempRect(GUI_RECT pRect)
Add a temporary rect to the rect list.
bool InClipRect(GUI_RECT pRect)
Check to see if a rect is inside of the clip rect.
int m_iHeight
The height of this texture.
Definition: VideoTexture.h:94
void SetDrawColor(unsigned long iColor)
Set the drawing color.
void RecreateTexture()
Recreate this texture.
SDL_Rect * m_pTempArray
A temporary array containing SDL rects.
Definition: VideoTexture.h:122
void DrawStripedRect(GUI_RECT *pRect, unsigned long iColor=INVALID_TEXTURE_COLOR)
Draw a striped rectangle to this texture.
void ClearClipRects()
Clear the clip rect list.
void Unlock()
Unlock this texture.
void DrawMagnifiedPixels(GUI_POINT *pPointList, unsigned int iPointCount, unsigned long iColor=INVALID_TEXTURE_COLOR)
Draw multiple pre-magnified pixels.
void ClearPixels(GUI_POINT *pPointList, unsigned int iPointCount)
Clear multiple pixels.
void DrawStretchedBitmap(GUI_RECT *pRect, GUI_RECT *pSourceRect, Surface_Ids iSurfaceId, unsigned long iColor=INVALID_TEXTURE_COLOR, bool bAbsloutePos=false)
Draw a stretched bitmap.
void ClearTempRectList()
Reset the temporary rectangle list.
static VideoTexture * CreateTexture(int iWidth, int iHeight, int iBitsPerPixel=32, ExternalWindow *pWindow=NULL, int iMagnification=-1, bool bNoTexture=false)
Create a texture.
static VideoTexture * CreateTexture(const char *pFileName, ExternalWindow *pWindow=NULL, int iMagnification=-1)
Create a texture with an image.
GUI_COLOR m_pDrawColor
The current draw color.
Definition: VideoTexture.h:66
static bool FreeTexture(VideoTexture *pTexture)
Free a texture.
int m_iClipRectSize
The size of the clip rect size.
Definition: VideoTexture.h:110
void PutSubPixel(int iX, int iY, int iAlpha)
Draw this texture onto the screen at a subpixel coordinate.
ExternalWindow * m_pWindow
The window object this texture belongs to.
Definition: VideoTexture.h:62
void DrawColoredBitmap(GUI_POINT pPoint, GUI_RECT *pSourceRect, Surface_Ids iSurfaceId, unsigned long iColor, bool bAbsolutePos=false)
Draw a colored bitmap.
void DrawBitmap(GUI_POINT pPoint, GUI_RECT *pSourceRect, Surface_Ids iSurfaceId, bool bAbsolutePos=false)
Draw a bitmap.
SDL_Texture * m_pOldLockTexture
The old lock texture to restore after unlocking this texture.
Definition: VideoTexture.h:70
void PutStretchedSubPixel(int iDstX, int iDstY, int iDstW, int iDstH, int iSrcX, int iSrcY, int iSrcW, int iSrcH, int iAlpha)
Draw this texture onto the screen.
void Lock()
Lock this texture for editing.
bool m_bHasOldClip
Whether the renderer can use the old clip rect.
Definition: VideoTexture.h:78
GUI_RECT GetNonScaledClipRect()
Get the current clip rect (not scaled to local magnification level).
void DrawRect(GUI_RECT *pRect, unsigned long iColor=INVALID_TEXTURE_COLOR, bool bAbsolutePos=false)
Draw a rectangle to this texture.
int m_iTempSize
The size of m_pTempArray.
Definition: VideoTexture.h:130
static void ReloadRenderer(int iMagnification)
Reload the main renderer's texture.
int m_iTempCount
The number of rects in m_pTempArray.
Definition: VideoTexture.h:126
#define CAVESTORY_MOD_API
Exports / imports Cavestory Mod API functions & classes.
Definition: CSMAPI_begincode.h:30
BitmapBoxType
Bitmap box type for CacheSurface::GetBitmapBoxSize and CacheSurface::DrawBitmapBox.
Definition: CSMAPI_drawing.h:443
Manages colors.
Definition: CSMAPI_types.h:497
Manages points.
Definition: CSMAPI_types.h:546
Definition: CSMAPI_types.h:842
Definition: CSMAPI_types.h:51