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