65extern SDL_Renderer *uiSdlRenderer;
68void UiInit (
const char *windowTitle =
"Home2L");
71static inline SDL_Renderer *UiGetSdlRenderer () {
return uiSdlRenderer; }
73void UiGetWindowSize (
int *w,
int *h);
77void UiSetWindowSize (
int w,
int h);
79bool UiGetWindowFullScreen ();
80void UiSetWindowFullScreen (
bool _fullScreen);
81void UiToggleWindowFullScreen ();
83bool UiGetWindowResizable ();
84void UiSetWindowResizable (
bool _resizable);
85void UiToggleWindowResizable ();
105 evMainThreadCallback = 0,
130void UiPushUserEvent (EUserEvent code,
void *data1 = NULL,
void *data2 = NULL);
132static inline void MainThreadCallback (
void (*func) (
void *),
void *data = NULL) { UiPushUserEvent (evMainThreadCallback, (
void *) func, data); }
154#define AUDIO_FOREVER -1
184#define SELECTED_SDL_PIXELFORMAT SDL_PIXELFORMAT_ARGB8888
196#if SELECTED_SDL_PIXELFORMAT==SDL_PIXELFORMAT_ARGB8888
207#define COL_MASK_R 0x00FF0000
208#define COL_MASK_G 0x0000FF00
209#define COL_MASK_B 0x000000FF
210#define COL_MASK_A 0xFF000000
211#define COL_MASK_RGB (COL_MASK_R | COL_MASK_G | COL_MASK_B)
214static inline TColor ToColor (Uint8 r, Uint8 g, Uint8 b, Uint8 a = 255) {
216 ret.r = r; ret.g = g; ret.b = b; ret.a = a;
221static inline TColor ToColor (Uint32 val) {
222 union { Uint32 i; TColor c; } ret;
231static inline Uint32 ToUint32 (TColor color) {
232 union { Uint32 i; TColor c; } ret;
238static inline Uint32 ToUint32 (Uint8 r, Uint8 g, Uint8 b, Uint8 a = 255) {
239 return ToUint32 (ToColor (r, g, b, a));
243static inline TColor ToColor (SDL_Color sdlCol) {
245 ret.r = sdlCol.r; ret.g = sdlCol.g; ret.b = sdlCol.b; ret.a = sdlCol.a;
250static inline bool operator == (
const TColor &col1,
const TColor &col2) {
return ToUint32 (col1) == ToUint32 (col2); }
251static inline bool operator != (
const TColor &col1,
const TColor &col2) {
return ToUint32 (col1) != ToUint32 (col2); }
254static inline SDL_Color ToSDL_Color (TColor color) {
255 SDL_Color ret = { .r = color.r, .g = color.g, .b = color.b, .a = color.a };
271TColor
ColorBlend (TColor color0, TColor color1,
int weight1);
281#define WHITE ToColor (0xff, 0xff, 0xff)
282#define LIGHT_GREY ToColor (0xc0, 0xc0, 0xc0)
283#define GREY ToColor (0x80, 0x80, 0x80)
284#define DARK_GREY ToColor (0x40, 0x40, 0x40)
285#define DARK_DARK_GREY ToColor (0x20, 0x20, 0x20)
286#define BLACK ToColor (0x00, 0x00, 0x00)
288#define RED ToColor (0xff, 0x00, 0x00)
289#define GREEN ToColor (0x00, 0xff, 0x00)
290#define BLUE ToColor (0x00, 0x00, 0xff)
291#define CYAN ToColor (0x00, 0xff, 0xff)
292#define MAGENTA ToColor (0xff, 0x00, 0xff)
293#define YELLOW ToColor (0xff, 0xff, 0x00)
295#define DARK_RED ToColor (0x80, 0x00, 0x00)
296#define DARK_GREEN ToColor (0x00, 0x80, 0x00)
297#define DARK_BLUE ToColor (0x00, 0x00, 0x80)
298#define DARK_CYAN ToColor (0x00, 0x80, 0x80)
299#define DARK_MAGENTA ToColor (0x80, 0x00, 0x80)
300#define DARK_YELLOW ToColor (0x80, 0x80, 0x00)
302#define LIGHT_RED ToColor (0xff, 0x80, 0x80)
303#define LIGHT_GREEN ToColor (0x80, 0xff, 0x80)
304#define LIGHT_BLUE ToColor (0x80, 0x80, 0xff)
305#define LIGHT_CYAN ToColor (0x80, 0xff, 0xff)
306#define LIGHT_MAGENTA ToColor (0xff, 0x80, 0xff)
307#define LIGHT_YELLOW ToColor (0xff, 0xff, 0x80)
309#define BROWN ToColor (0x80, 0x40, 0x00)
310#define LIGHT_BROWN ToColor (0xc0, 0x80, 0x40)
312#define ORANGE ToColor (0xc0, 0x40, 0x00)
314#define TRANSPARENT ToColor (0x00, 0x00, 0x00, 0x00)
329static inline SDL_Rect Rect (
int x,
int y,
int w,
int h) {
330 SDL_Rect ret = { .x = x, .y = y, .w = w, .h = h };
335static inline SDL_Rect Rect (
int w,
int h) {
336 SDL_Rect ret = { .x = 0, .y = 0, .w = w, .h = h };
341static inline SDL_Rect Rect (SDL_Surface *surf) {
342 SDL_Rect ret = { .x = 0, .y = 0, .w = surf->w, .h = surf->h };
347static inline SDL_Rect Rect (SDL_Texture *tex) {
350 SDL_QueryTexture (tex, NULL, NULL, &ret.w, &ret.h);
359static inline void RectMove (SDL_Rect *rect,
int dx,
int dy) {
365static inline void RectGrow (SDL_Rect *rect,
int dx,
int dy) {
373void RectAlign (SDL_Rect *rect, SDL_Rect container,
int hAlign = -1,
int vAlign = -1);
385static inline bool RectContains (SDL_Rect *rect,
int x,
int y) {
386 return x >= rect->x && x < rect->x+rect->w && y >= rect->y && y < rect->y+rect->h;
404#define ORIENT(FLIPH, ROT) (((FLIPH) ? 4 : 0) | ((ROT) & 3))
406#define ORIENT_WITH_FLIPV(FLIPH, ROT) (((FLIPH) ? 0 : 4) | (((ROT) + 2) & 3))
409#define ORIENT_FLIPH(ORI) (((ORI) & 4) ? true : false)
411#define ORIENT_ROT(ORI) ((ORI) & 3)
415#if SELECTED_SDL_PIXELFORMAT==SDL_PIXELFORMAT_ARGB8888
417static inline SDL_Surface *CreateSurface (
int w,
int h) {
return SDL_CreateRGBSurfaceWithFormat (0, w, h, 32,
SELECTED_SDL_PIXELFORMAT); }
418static inline SDL_Surface *CreateSurface (SDL_Rect r) {
return CreateSurface (r.w, r.h); }
419static inline SDL_Surface *CreateSurface (SDL_Rect *r) {
return CreateSurface (r->w, r->h); }
421static inline SDL_Surface *CreateSurfaceFrom (
int w,
int h,
void *_pixels,
int _pitch) {
return SDL_CreateRGBSurfaceFrom (_pixels, w, h, 32, _pitch, COL_MASK_R, COL_MASK_G, COL_MASK_B, COL_MASK_A); }
426static inline SDL_Surface *SurfaceSet (SDL_Surface **pSurf, SDL_Surface *newSurf) {
if (*pSurf) SDL_FreeSurface (*pSurf); *pSurf = newSurf;
return newSurf; }
427static inline void SurfaceFree (SDL_Surface **pSurf) { SurfaceSet (pSurf, NULL); }
428static inline void SurfaceFree (SDL_Surface *surf) { SDL_FreeSurface (surf); }
430static inline SDL_Surface *SurfaceDup (SDL_Surface *src) {
return SDL_ConvertSurface (src, src->format, 0); }
445void SurfaceBlit (SDL_Surface *src, SDL_Rect *srcRect, SDL_Surface *dst, SDL_Rect *dstRect = NULL,
int hAlign = 0,
int vAlign = 0, SDL_BlendMode blendMode = SDL_BLENDMODE_NONE);
454static inline void SurfaceFill (SDL_Surface *surf, TColor col) { SDL_FillRect (surf, NULL, ToUint32 (col)); }
455static inline void SurfaceFillRect (SDL_Surface *surf, SDL_Rect r, TColor col) { SDL_FillRect (surf, &r, ToUint32 (col)); }
456static inline void SurfaceFillRect (SDL_Surface *surf, SDL_Rect *r, TColor col) { SDL_FillRect (surf, r, ToUint32 (col)); }
479#define NETPBM_IDLE -3
480#define NETPBM_ERROR -2
481#define NETPBM_SUCCESS -1
497 void Put (
const char *line);
502 int State () {
return state; }
503 bool Running () {
return state >= 0; }
507 SDL_Surface *
Surface () {
return Success () ? surf : NULL; }
517 bool ReadFile (
const char *fileName);
518 bool ReadStream (
int fd);
519 bool ReadShell (
CShell *shell);
543static inline SDL_Texture *CreateTexture (SDL_Surface *surf) {
return SDL_CreateTextureFromSurface (uiSdlRenderer, surf); }
545static inline void TextureSet (SDL_Texture **pTex, SDL_Texture *newTex) {
if (*pTex) SDL_DestroyTexture (*pTex); *pTex = newTex; }
546static inline void TextureFree (SDL_Texture **pTex) { TextureSet (pTex, NULL); }
548static inline void TextureRender (SDL_Texture *tex, SDL_Rect *srcRect = NULL, SDL_Rect *dstRect = NULL) { SDL_RenderCopy (uiSdlRenderer, tex, srcRect, dstRect); }
564SDL_Surface *
IconGet (
const char *name, TColor color = WHITE, TColor bgColor = TRANSPARENT,
int scaleDown = 1,
int orient = 0,
bool preserveThinLines =
false);
603SDL_Surface *
FontRenderText (TTF_Font *font,
const char *text, TColor color);
607SDL_Surface *
FontRenderText (TTF_Font *font,
const char *text, TColor color, TColor bgColor);
613static inline int FontGetLineSkip (TTF_Font *font) {
return TTF_FontLineSkip (font); }
615static inline int FontGetHeight (TTF_Font *font) {
return TTF_FontHeight (font); }
616int FontGetWidth (TTF_Font *font,
const char *text,
int textLen = -1);
638 CTextFormat (TTF_Font *_font, TColor _color, TColor _bgColor = TRANSPARENT,
639 int _hAlign = -1,
int _vAlign = -1,
640 int _hSpace = 0,
int _vSpace = 0,
641 int _maxWidth = 0,
int _maxHeigth = 0) {
643 hAlign = _hAlign;
vAlign = _vAlign;
644 hSpace = _hSpace; vSpace = _vSpace;
645 maxWidth = _maxWidth;
661 CTextSet () { surface = NULL; firstItem = NULL; height = 0; }
673 SDL_Surface *
Render (SDL_Surface *dst = NULL, SDL_Rect *dstRect = NULL);
685 SDL_Surface *surface;
686 class CTextItem *firstItem;
692SDL_Surface *
TextRender (
const char *text,
CTextFormat fmt, SDL_Surface *dst = NULL, SDL_Rect *dstRect = NULL,
bool *retAbbreviated = NULL);
Reader for Netpbm image files.
void Put(const char *line)
Put a text line.
SDL_Surface * Surface()
Return surface on success or NULL in all other cases.
void Clear()
Reset reader (not necessary at the first time).
Abstract base class for shells that can execute system commands.
int hSpace
Vertical and horizontal space in pixels.
TColor bgColor
Foreground and background color; 'bgColor' == 'TRANSPARENT' selects "blended mode" in font rendering.
int maxHeight
Maximum width in pixels (for automatic line breaking).
int vAlign
Alignment: -1 = left/up, 0 = center, +1 = right/down.
TTF_Font * font
Text font.
Typesetter for longer formatted texts.
SDL_Surface * Render(SDL_Surface *dst=NULL, SDL_Rect *dstRect=NULL)
Render everything and return a new surface containing the text.
int GetHeight()
Accumulated height in pixels according to all previous AddLines() invocations.
void AddLines(const char *text, CTextFormat fmt, bool *retAbbreviated=NULL)
Add text with a given format. If the 'maxHeight' parameter is set in 'fmt', the text is automatically...
void Clear()
Clear everything.
int64_t TTicks
Time value (relative, absolute, or monotonic).
#define UI_RES_Y
UI resolution in pixels (Y)
void SurfaceMakeTransparentMono(SDL_Surface *surf, Uint8 opaqueLevel=0xff)
Copy the R values to the A channel and make all RGB values white.
#define NETPBM_ERROR
State code "error" for CNetpbmReader.
void UiQuit()
Quit the application.
static TColor ColorDarker(TColor color, int d)
Decreas all color components by d with saturation; d may be negative.
EFontStyle
Supported font styles.
SDL_Surface * SurfaceGetScaledDownCopy(SDL_Surface *surf, int factor, bool preserveThinLines=false)
Get a copy of the surface, scaled down by a factor in both dimensions.
void SurfaceBlit(SDL_Surface *src, SDL_Rect *srcRect, SDL_Surface *dst, SDL_Rect *dstRect=NULL, int hAlign=0, int vAlign=0, SDL_BlendMode blendMode=SDL_BLENDMODE_NONE)
Blit a surface; It is allowed to leave 'src == NULL', in which case nothing happens.
bool UiIsClosed()
Is the application quitting?
static SDL_Rect RectScreen()
Rectangle representing the whole UI screen.
SDL_Surface * TextRender(const char *text, CTextFormat fmt, SDL_Surface *dst=NULL, SDL_Rect *dstRect=NULL, bool *retAbbreviated=NULL)
Easy-to-use function to typeset a text with a single format.
static void RectCenter(SDL_Rect *rect, SDL_Rect container)
Center the rectangle 'rect' with respect to an outer rectangle 'container'.
void RectAlign(SDL_Rect *rect, SDL_Rect container, int hAlign=-1, int vAlign=-1)
Align the rectangle 'rect' with an outer rectangle 'container'.
#define NETPBM_IDLE
State code "idle" for CNetpbmReader.
void SurfaceRecolor(SDL_Surface *surf, TColor color)
Replace all RGB values with the passed color while leaving alpha values untouched.
TColor ColorSum(TColor col1, TColor col2)
Add two colors (with saturation).
SDL_Surface * SurfaceGetOpaqueCopy(SDL_Surface *surf, TColor backColor)
Create an opaque copy; caller becomes owner of returned surface.
SDL_Surface * FontRenderText(TTF_Font *font, const char *text, TColor color)
Render a text using 'blended' mode of the SDL2_ttf library. The returned surface is a new surface of ...
TColor ColorScale(TColor color, int factor)
Multiply all components with a factor. 'factor' is a fixed point number with 8 fractional bits (1....
TColor ColorBrighter(TColor color, int d)
Increase all color components by d with saturation; d may be negative.
void SurfaceNormalize(SDL_Surface **pSurf)
Normalize pixel format to SELECTED_SDL_PIXELFORMAT.
SDL_Surface * SurfaceGetFlippedAndRotatedCopy(SDL_Surface *surf, int orient)
Get a copy of the surface, which is eventually flipped and then rotated in 90° steps clockwise 'surf'...
void UiIterate(bool noWait=false)
#define NETPBM_SUCCESS
State code "success" for CNetpbmReader.
SDL_Surface * IconGet(const char *name, TColor color=WHITE, TColor bgColor=TRANSPARENT, int scaleDown=1, int orient=0, bool preserveThinLines=false)
Get a reference to an icon from the application's 'etc/icons/' or 'share/icons/' folder.
#define SELECTED_SDL_PIXELFORMAT
Selected (SDL) pixel format.
static void UiIterateNoWait()
Iterate the application's main event loop; Does not sleep, but returns immediately ("yield"-functiona...
SDL_Surface * SurfaceReadBmp(const char *fileName)
Read a .bmp file.
void AudioStop()
Stop playing audio immediately.
bool AudioIsPlaying()
Query if audio is still playing. If 'false' is returned, the audio device is surely in a stopped stat...
#define UI_RES_X
UI resolution in pixels (X)
TTF_Font * FontGet(EFontStyle style, int size)
Get a reference to a font of a specific style and size.
void AudioStart(const char *fileName, int repetitions=1, TTicks repetitionGap=0)
Start playing audio.
TColor ColorBlend(TColor color0, TColor color1, int weight1)
Blend two colors; 'weight' is a fixed point number with 8 fractional bits (1.0 == 0x100) and refers t...
static void MainThreadCallback(void(*func)(void *), void *data=NULL)
Request function 'func' to be called by main thread at next occasion.
@ fntMonoItalic
Monotype, italic.
@ fntMonoBold
Monotype, bold.
@ fntMonoBoldItalic
Monotype, bold and italic.
@ fntBoldItalic
Bold and italic.