Chesto 0.9
A declarative and element-based library for creating GUIs on homebrew'd consoles
DrawUtils.hpp
1#include <vector>
2
3#include <SDL2/SDL.h>
4#include <SDL2/SDL_image.h>
5#include <SDL2/SDL_ttf.h>
6
7#if !defined(_3DS)
8#include <SDL2/SDL2_gfxPrimitives.h> // 3ds has no gfx library
9#endif
10
11#include "../libs/SDL_FontCache/SDL_FontCache.h"
12
13#include <string>
14
15#if defined(MUSIC)
16 #include <SDL2/SDL_mixer.h>
17 #include <mpg123.h>
18 typedef Mix_Music CST_Music;
19#endif
20
21typedef SDL_Window CST_Window;
22typedef SDL_Renderer CST_Renderer;
23typedef SDL_Texture CST_Texture;
24
25typedef SDL_Surface CST_Surface;
26typedef SDL_Color CST_Color;
27typedef SDL_Rect CST_Rect;
28
29class RootDisplay;
30class InputEvents;
31
32#define CST_CURSOR_NONE -1
33#define CST_CURSOR_ARROW 0
34#define CST_CURSOR_HAND 1
35#define CST_CURSOR_TEXT 2
36#define CST_CURSOR_SPINNER 3
37
38// init / rendering analogues
39bool CST_DrawInit(RootDisplay* root);
40void CST_MixerInit(RootDisplay* root);
41void CST_FadeInMusic(RootDisplay* root);
42void CST_DrawExit();
43void CST_RenderPresent(CST_Renderer* render);
44void CST_FreeSurface(CST_Surface* surface);
45
46void CST_RenderCopy(CST_Renderer* dest, CST_Texture* src, CST_Rect* src_rect, CST_Rect* dest_rect);
47void CST_RenderCopyRotate(CST_Renderer* dest, CST_Texture* src, CST_Rect* src_rect, CST_Rect* dest_rect, int angle);
48
49// color analogues
50void CST_SetDrawColor(CST_Renderer* renderer, CST_Color c);
51void CST_SetDrawColorRGBA(CST_Renderer* renderer, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
52void CST_FillRect(CST_Renderer* renderer, CST_Rect* dimens);
53void CST_DrawRect(CST_Renderer* renderer, CST_Rect* dimens);
54void CST_SetDrawBlend(CST_Renderer* renderer, bool enabled);
55void CST_DrawLine(CST_Renderer* renderer, int x, int y, int w, int h);
56
57void CST_QueryTexture(CST_Texture* texture, int* w, int* h);
58CST_Texture* CST_CreateTextureFromSurface(CST_Renderer* renderer, CST_Surface* surface, bool isAccessible);
59void CST_SetQualityHint(const char* quality);
60
61void CST_filledCircleRGBA(CST_Renderer* renderer, uint32_t x, uint32_t y, uint32_t radius, uint32_t r, uint32_t g, uint32_t b, uint32_t a);
62void CST_roundedBoxRGBA (
63 CST_Renderer *renderer,
64 Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,
65 Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a
66);
67void CST_roundedRectangleRGBA (
68 CST_Renderer *renderer,
69 Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,
70 Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a
71);
72void CST_rectangleRGBA (
73 CST_Renderer *renderer,
74 Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,
75 Uint8 r, Uint8 g, Uint8 b, Uint8 a
76);
77float CST_GetDpiScale();
78void CST_SetWindowSize(CST_Window* renderer, int w, int h);
79void CST_Delay(int time);
80
81int CST_GetTicks();
82bool CST_isRectOffscreen(CST_Rect* rect);
83
84void CST_GetRGBA(Uint32 pixel, SDL_PixelFormat* format, CST_Color* cstColor);
85bool CST_SavePNG(CST_Texture* texture, const char* filename);
86void CST_SetWindowTitle(const char* title);
87
88void CST_SetCursor(int cursor);
89void CST_LowRumble(InputEvents* event, int ms);
90
91#ifdef MUSIC
92std::vector<std::string> CST_GetMusicInfo(CST_Music* music);
93#endif
94
95// font cache analogues
96// SDL2, will be backed by SDL_FontCache
97#define CST_Font FC_Font
98#define CST_CreateFont FC_CreateFont
99#define CST_LoadFont FC_LoadFont
100#define CST_MakeColor FC_MakeColor
101#define CST_GetFontLineHeight FC_GetLineHeight
102#define CST_GetFontWidth FC_GetWidth
103#define CST_GetFontHeight FC_GetHeight
104#define CST_DrawFont FC_Draw
105
106void chdirForPlatform();
107std::string replaceAll(std::string str, const std::string& from, const std::string& to);