Home2L - C/C++ API v1.4-2-g83f4c (2025-08-23)
Smart Tools for a Private Home
Loading...
Searching...
No Matches
Classes | Macros
ui_base.H File Reference
#include <SDL.h>
#include <SDL_ttf.h>
#include "env.H"
Include dependency graph for ui_base.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  CNetpbmReader
 Reader for Netpbm image files. More...
 
class  CTextFormat
 
class  CTextSet
 Typesetter for longer formatted texts. More...
 

Macros

#define UI_RES_X   1024
 UI resolution in pixels (X)
 
#define UI_RES_Y   600
 UI resolution in pixels (Y)
 
Color palette ...

Functions

Geometry helpers ...
static SDL_Rect RectScreen ()
 Rectangle representing the whole UI screen.
 
void RectAlign (SDL_Rect *rect, SDL_Rect container, int hAlign=-1, int vAlign=-1)
 Align the rectangle 'rect' with an outer rectangle 'container'.
 
static void RectCenter (SDL_Rect *rect, SDL_Rect container)
 Center the rectangle 'rect' with respect to an outer rectangle 'container'.
 
Texture helpers ...
Icon handling ...
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.
 
Complex text formatting ...

See also: CTextFormat, CTextSet

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.
 

SDL audio ...

Audio playing functionality. The following functions are not thread-safe and must be called from the main thread, which is the one executing timers.

#define AUDIO_FOREVER   -1
 Constant to specify an infinite number of repetitions.
 
void AudioStart (const char *fileName, int repetitions=1, TTicks repetitionGap=0)
 Start playing audio.
 
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 state.
 

Color helpers ...

#define SELECTED_SDL_PIXELFORMAT   SDL_PIXELFORMAT_ARGB8888
 Selected (SDL) pixel format.
 
TColor ColorSum (TColor col1, TColor col2)
 Add two colors (with saturation).
 
TColor ColorBrighter (TColor color, int d)
 Increase all color components by d with saturation; d may be negative.
 
static TColor ColorDarker (TColor color, int d)
 Decreas all color components by d with saturation; d may be negative.
 
TColor ColorScale (TColor color, int factor)
 Multiply all components with a factor. 'factor' is a fixed point number with 8 fractional bits (1.0 == 0x100).
 
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 to 'color1'.
 

Surface helpers ...

See also: CNetpbmReader

#define ORIENT(FLIPH, ROT)   (((FLIPH) ? 4 : 0) | ((ROT) & 3))
 Get orientation identifier based on horizontal flipping and a rotation in 90 degree steps clock-wise.
 
#define ORIENT_WITH_FLIPV(FLIPH, ROT)   (((FLIPH) ? 0 : 4) | (((ROT) + 2) & 3))
 Get orientation identifier with implied vertical flipping first.
 
#define ORIENT_FLIPH(ORI)   (((ORI) & 4) ? true : false)
 Get whether horizontal flipping is included in the orientation.
 
#define ORIENT_ROT(ORI)   ((ORI) & 3)
 Get the number of rotations.
 
#define NETPBM_IDLE   -3
 State code "idle" for CNetpbmReader.
 
#define NETPBM_ERROR   -2
 State code "error" for CNetpbmReader.
 
#define NETPBM_SUCCESS   -1
 State code "success" for CNetpbmReader.
 
void SurfaceNormalize (SDL_Surface **pSurf)
 Normalize pixel format to SELECTED_SDL_PIXELFORMAT.
 
void SurfaceRecolor (SDL_Surface *surf, TColor color)
 Replace all RGB values with the passed color while leaving alpha values untouched.
 
SDL_Surface * SurfaceGetOpaqueCopy (SDL_Surface *surf, TColor backColor)
 Create an opaque copy; caller becomes owner of returned surface.
 
void SurfaceMakeTransparentMono (SDL_Surface *surf, Uint8 opaqueLevel=0xff)
 Copy the R values to the A channel and make all RGB values white.
 
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.
 
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.
 
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' must conform to SELECTED_SDL_PIXELFORMAT (see SurfaceNormalize() ).
 
SDL_Surface * SurfaceReadBmp (const char *fileName)
 Read a .bmp file.
 

Events ...

void UiIterate (bool noWait=false)
 
static void UiIterateNoWait ()
 Iterate the application's main event loop; Does not sleep, but returns immediately ("yield"-functionality for longer running processes in the UI thread).
 
void UiQuit ()
 Quit the application.
 
bool UiIsClosed ()
 Is the application quitting?
 
static void MainThreadCallback (void(*func)(void *), void *data=NULL)
 Request function 'func' to be called by main thread at next occasion.
 

Font handling ...

enum  EFontStyle {
  fntNormal = 0 , fntBold , fntItalic , fntBoldItalic ,
  fntLight , fntMono , fntMonoBold , fntMonoItalic ,
  fntMonoBoldItalic , fntEND
}
 Supported font styles. More...
 
TTF_Font * FontGet (EFontStyle style, int size)
 Get a reference to a font of a specific style and size.
 
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 minimal size and must later be free'd using SurfaceFree().
 
SDL_Surface * FontRenderText (TTF_Font *font, const char *text, TColor color, TColor bgColor)
 Render a text using 'shaded' mode of the SDL2_ttf library. This mode is considered faster than 'blended' mode. The returned surface is a new surface of minimal size and must later be free'd using SurfaceFree().