GUIslice  0.16.0
Embedded GUI in C
GUIslice_drv_sdl.h File Reference

GUIslice library (driver layer for LINUX / SDL) More...

#include "GUIslice.h"
#include <stdio.h>
Include dependency graph for GUIslice_drv_sdl.h:

Go to the source code of this file.

Data Structures

struct  gslc_tsDriver
 

Macros

#define DRV_HAS_DRAW_POINT
 Support gslc_DrvDrawPoint() More...
 
#define DRV_OVERRIDE_TXT_ALIGN
 Driver provides text alignment. More...
 

Functions

bool gslc_DrvInit (gslc_tsGui *pGui)
 Initialize the SDL library. More...
 
void gslc_DrvDestruct (gslc_tsGui *pGui)
 Free up any members associated with the driver. More...
 
const char * gslc_DrvGetNameDisp (gslc_tsGui *pGui)
 Get the display driver name. More...
 
const char * gslc_DrvGetNameTouch (gslc_tsGui *pGui)
 Get the touch driver name. More...
 
void * gslc_DrvGetDriverDisp (gslc_tsGui *pGui)
 Get the native display driver instance. More...
 
void * gslc_DrvGetDriverTouch (gslc_tsGui *pGui)
 Get the native touch driver instance. More...
 
void * gslc_DrvLoadImage (gslc_tsGui *pGui, gslc_tsImgRef sImgRef)
 Load a bitmap (*.bmp) and create a new image resource. More...
 
bool gslc_DrvSetBkgndImage (gslc_tsGui *pGui, gslc_tsImgRef sImgRef)
 Configure the background to use a bitmap image. More...
 
bool gslc_DrvSetBkgndColor (gslc_tsGui *pGui, gslc_tsColor nCol)
 Configure the background to use a solid color. More...
 
bool gslc_DrvSetElemImageNorm (gslc_tsGui *pGui, gslc_tsElem *pElem, gslc_tsImgRef sImgRef)
 Set an element's normal-state image. More...
 
bool gslc_DrvSetElemImageGlow (gslc_tsGui *pGui, gslc_tsElem *pElem, gslc_tsImgRef sImgRef)
 Set an element's glow-state image. More...
 
void gslc_DrvImageDestruct (void *pvImg)
 Release an image surface. More...
 
bool gslc_DrvSetClipRect (gslc_tsGui *pGui, gslc_tsRect *pRect)
 Set the clipping rectangle for future drawing updates. More...
 
const void * gslc_DrvFontAdd (gslc_teFontRefType eFontRefType, const void *pvFontRef, uint16_t nFontSz)
 Load a font from a resource and return pointer to it. More...
 
void gslc_DrvFontsDestruct (gslc_tsGui *pGui)
 Release all fonts defined in the GUI. More...
 
bool gslc_DrvGetTxtSize (gslc_tsGui *pGui, gslc_tsFont *pFont, const char *pStr, gslc_teTxtFlags eTxtFlags, int16_t *pnTxtX, int16_t *pnTxtY, uint16_t *pnTxtSzW, uint16_t *pnTxtSzH)
 Get the extent (width and height) of a text string. More...
 
bool gslc_DrvDrawTxt (gslc_tsGui *pGui, int16_t nTxtX, int16_t nTxtY, gslc_tsFont *pFont, const char *pStr, gslc_teTxtFlags eTxtFlags, gslc_tsColor colTxt, gslc_tsColor colBg)
 Draw a text string at the given coordinate. More...
 
void gslc_DrvPageFlipNow (gslc_tsGui *pGui)
 Force a page flip to occur. More...
 
bool gslc_DrvDrawPoint (gslc_tsGui *pGui, int16_t nX, int16_t nY, gslc_tsColor nCol)
 Draw a point. More...
 
bool gslc_DrvDrawPoints (gslc_tsGui *pGui, gslc_tsPt *asPt, uint16_t nNumPt, gslc_tsColor nCol)
 Draw a point. More...
 
bool gslc_DrvDrawFrameRect (gslc_tsGui *pGui, gslc_tsRect rRect, gslc_tsColor nCol)
 Draw a framed rectangle. More...
 
bool gslc_DrvDrawFillRect (gslc_tsGui *pGui, gslc_tsRect rRect, gslc_tsColor nCol)
 Draw a filled rectangle. More...
 
bool gslc_DrvDrawLine (gslc_tsGui *pGui, int16_t nX0, int16_t nY0, int16_t nX1, int16_t nY1, gslc_tsColor nCol)
 Draw a line. More...
 
bool gslc_DrvDrawImage (gslc_tsGui *pGui, int16_t nDstX, int16_t nDstY, gslc_tsImgRef sImgRef)
 Copy all of source image to destination screen at specified coordinate. More...
 
void gslc_DrvDrawBkgnd (gslc_tsGui *pGui)
 Copy the background image to destination screen. More...
 
bool gslc_DrvGetTouch (gslc_tsGui *pGui, int16_t *pnX, int16_t *pnY, uint16_t *pnPress, gslc_teInputRawEvent *peInputEvent, int16_t *pnInputVal)
 Get the last touch event from the SDL_Event handler. More...
 
bool gslc_DrvRotate (gslc_tsGui *pGui, uint8_t nRotation)
 Change rotation, automatically adapt touchscreen axes swap/flip. More...
 
bool gslc_DrvCleanStart (const char *sTTY)
 Ensure SDL initializes cleanly to workaround possible issues if previous SDL application failed to close down gracefully. More...
 
void gslc_DrvReportInfoPre ()
 Report driver debug info (before initialization) More...
 
void gslc_DrvReportInfoPost ()
 Report driver debug info (after initialization) More...
 
SDL_Rect gslc_DrvAdaptRect (gslc_tsRect rRect)
 Translate a gslc_tsRect into an SDL_Rect. More...
 
SDL_Color gslc_DrvAdaptColor (gslc_tsColor sCol)
 Translate a gslc_tsColor into an SDL_Color. More...
 
bool gslc_DrvInitTouch (gslc_tsGui *pGui, const char *acDev)
 Perform any touchscreen-specific initialization. More...
 

Detailed Description

GUIslice library (driver layer for LINUX / SDL)

Macro Definition Documentation

#define DRV_HAS_DRAW_POINT
#define DRV_OVERRIDE_TXT_ALIGN

Driver provides text alignment.

Function Documentation

SDL_Color gslc_DrvAdaptColor ( gslc_tsColor  sCol)

Translate a gslc_tsColor into an SDL_Color.

Parameters
[in]sColgslc_tsColor
Returns
Converted SDL_Color
SDL_Rect gslc_DrvAdaptRect ( gslc_tsRect  rRect)

Translate a gslc_tsRect into an SDL_Rect.

Parameters
[in]rRectgslc_tsRect
Returns
Converted SDL_Rect
bool gslc_DrvCleanStart ( const char *  sTTY)

Ensure SDL initializes cleanly to workaround possible issues if previous SDL application failed to close down gracefully.

Parameters
[in]sTTYTerminal device (eg. "/dev/tty0")
Returns
true if success
void gslc_DrvDestruct ( gslc_tsGui pGui)

Free up any members associated with the driver.

  • Eg. renderers, windows, background surfaces, etc.
Parameters
[in]pGuiPointer to GUI
Returns
none
void gslc_DrvDrawBkgnd ( gslc_tsGui pGui)

Copy the background image to destination screen.

Parameters
[in]pGuiPointer to GUI
Returns
true if success, false if fail
bool gslc_DrvDrawFillRect ( gslc_tsGui pGui,
gslc_tsRect  rRect,
gslc_tsColor  nCol 
)

Draw a filled rectangle.

Parameters
[in]pGuiPointer to GUI
[in]rRectRectangular region to fill
[in]nColColor RGB value to fill
Returns
true if success, false if error
bool gslc_DrvDrawFrameRect ( gslc_tsGui pGui,
gslc_tsRect  rRect,
gslc_tsColor  nCol 
)

Draw a framed rectangle.

Parameters
[in]pGuiPointer to GUI
[in]rRectRectangular region to frame
[in]nColColor RGB value to frame
Returns
true if success, false if error
bool gslc_DrvDrawImage ( gslc_tsGui pGui,
int16_t  nDstX,
int16_t  nDstY,
gslc_tsImgRef  sImgRef 
)

Copy all of source image to destination screen at specified coordinate.

Parameters
[in]pGuiPointer to GUI
[in]nDstXDestination X coord for copy
[in]nDstYDestination Y coord for copy
[in]sImgRefImage reference
Returns
true if success, false if fail
bool gslc_DrvDrawLine ( gslc_tsGui pGui,
int16_t  nX0,
int16_t  nY0,
int16_t  nX1,
int16_t  nY1,
gslc_tsColor  nCol 
)

Draw a line.

Parameters
[in]pGuiPointer to GUI
[in]nX0Line start (X coordinate)
[in]nY0Line start (Y coordinate)
[in]nX1Line finish (X coordinate)
[in]nY1Line finish (Y coordinate)
[in]nColColor RGB value to draw
Returns
true if success, false if error
bool gslc_DrvDrawPoint ( gslc_tsGui pGui,
int16_t  nX,
int16_t  nY,
gslc_tsColor  nCol 
)

Draw a point.

Parameters
[in]pGuiPointer to GUI
[in]nXX coordinate of point
[in]nYY coordinate of point
[in]nColColor RGB value to draw
Returns
true if success, false if error
bool gslc_DrvDrawPoints ( gslc_tsGui pGui,
gslc_tsPt asPt,
uint16_t  nNumPt,
gslc_tsColor  nCol 
)

Draw a point.

Parameters
[in]pGuiPointer to GUI
[in]asPtArray of points to draw
[in]nNumPtNumber of points in array
[in]nColColor RGB value to draw
Returns
true if success, false if error
bool gslc_DrvDrawTxt ( gslc_tsGui pGui,
int16_t  nTxtX,
int16_t  nTxtY,
gslc_tsFont pFont,
const char *  pStr,
gslc_teTxtFlags  eTxtFlags,
gslc_tsColor  colTxt,
gslc_tsColor  colBg 
)

Draw a text string at the given coordinate.

Parameters
[in]pGuiPointer to GUI
[in]nTxtXX coordinate of top-left text string
[in]nTxtYY coordinate of top-left text string
[in]pFontPtr to Font
[in]pStrString to display
[in]eTxtFlagsFlags associated with text string
[in]colTxtColor to draw text
[in]colBgunused in SDL, defaults to black
Returns
true if success, false if failure
Parameters
[in]pGuiPointer to GUI
[in]nTxtXX coordinate of top-left text string
[in]nTxtYY coordinate of top-left text string
[in]pFontPtr to Font
[in]pStrString to display
[in]eTxtFlagsFlags associated with text string
[in]colTxtColor to draw text
[in]colBgunused in ADAGFX, defaults to black
Returns
true if success, false if failure
const void* gslc_DrvFontAdd ( gslc_teFontRefType  eFontRefType,
const void *  pvFontRef,
uint16_t  nFontSz 
)

Load a font from a resource and return pointer to it.

Parameters
[in]eFontRefTypeFont reference type (GSLC_FONTREF_FNAME for SDL)
[in]pvFontRefFont reference pointer (Pointer to the font filename)
[in]nFontSzTypeface size to use
Returns
Void ptr to driver-specific font if load was successful, NULL otherwise
Parameters
[in]eFontRefTypeFont reference type (GSLC_FONTREF_PTR for Arduino)
[in]pvFontRefFont reference pointer (Pointer to the GFXFont array)
[in]nFontSzTypeface size to use
Returns
Void ptr to driver-specific font if load was successful, NULL otherwise
void gslc_DrvFontsDestruct ( gslc_tsGui pGui)

Release all fonts defined in the GUI.

Parameters
[in]pGuiPointer to GUI
Returns
none
void* gslc_DrvGetDriverDisp ( gslc_tsGui pGui)

Get the native display driver instance.

  • This can be useful to access special commands available in the selected driver.
Parameters
[in]pGuiPointer to GUI
Returns
Void pointer to the display driver instance. This pointer should be typecast to the particular driver being used. If no driver was created then this function will return NULL.
void* gslc_DrvGetDriverTouch ( gslc_tsGui pGui)

Get the native touch driver instance.

  • This can be useful to access special commands available in the selected driver.
Parameters
[in]pGuiPointer to GUI
Returns
Void pointer to the touch driver instance. This pointer should be typecast to the particular driver being used. If no driver was created then this function will return NULL.
const char* gslc_DrvGetNameDisp ( gslc_tsGui pGui)

Get the display driver name.

Parameters
[in]pGuiPointer to GUI
Returns
String containing driver name
const char* gslc_DrvGetNameTouch ( gslc_tsGui pGui)

Get the touch driver name.

Parameters
[in]pGuiPointer to GUI
Returns
String containing driver name
bool gslc_DrvGetTouch ( gslc_tsGui pGui,
int16_t *  pnX,
int16_t *  pnY,
uint16_t *  pnPress,
gslc_teInputRawEvent peInputEvent,
int16_t *  pnInputVal 
)

Get the last touch event from the SDL_Event handler.

Parameters
[in]pGuiPointer to GUI
[out]pnXPtr to X coordinate of last touch event
[out]pnYPtr to Y coordinate of last touch event
[out]pnPressPtr to Pressure level of last touch event (0 for none, 1 for touch)
[out]peInputEventIndication of event type
[out]pnInputValAdditional data for event type
Returns
true if an event was detected or false otherwise

Get the last touch event from the SDL_Event handler.

Parameters
[in]pGuiPointer to GUI
[out]pnXPtr to X coordinate of last touch event
[out]pnYPtr to Y coordinate of last touch event
[out]pnPressPtr to Pressure level of last touch event (0 for none, 1 for touch)
[out]peInputEventIndication of event type
[out]pnInputValAdditional data for event type
Returns
true if an event was detected or false otherwise
bool gslc_DrvGetTxtSize ( gslc_tsGui pGui,
gslc_tsFont pFont,
const char *  pStr,
gslc_teTxtFlags  eTxtFlags,
int16_t *  pnTxtX,
int16_t *  pnTxtY,
uint16_t *  pnTxtSzW,
uint16_t *  pnTxtSzH 
)

Get the extent (width and height) of a text string.

Parameters
[in]pGuiPointer to GUI
[in]pFontPtr to Font structure
[in]pStrString to display
[in]eTxtFlagsFlags associated with text string
[out]pnTxtXPtr to offset X of text
[out]pnTxtYPtr to offset Y of text
[out]pnTxtSzWPtr to width of text
[out]pnTxtSzHPtr to height of text
Returns
true if success, false if failure
void gslc_DrvImageDestruct ( void *  pvImg)

Release an image surface.

Parameters
[in]pvImgVoid ptr to image
Returns
none
bool gslc_DrvInit ( gslc_tsGui pGui)

Initialize the SDL library.

  • Performs clean startup workaround (if enabled)
  • Configures video mode
  • Initializes font support

PRE:

  • The environment variables should be configured before calling gslc_DrvInit().
Parameters
[in]pGuiPointer to GUI
Returns
true if success, false if fail
  • Performs clean startup workaround (if enabled)
  • Configures video mode
  • Initializes font support

PRE:

  • The environment variables should be configured before calling gslc_DrvInit(). This can be done with gslc_DrvInitEnv() or manually in user function.
Parameters
[in]pGuiPointer to GUI
Returns
true if success, false if fail
bool gslc_DrvInitTouch ( gslc_tsGui pGui,
const char *  acDev 
)

Perform any touchscreen-specific initialization.

Parameters
[in]pGuiPointer to GUI
[in]acDevDevice path to touchscreen eg. "/dev/input/touchscreen"
Returns
true if successful
void* gslc_DrvLoadImage ( gslc_tsGui pGui,
gslc_tsImgRef  sImgRef 
)

Load a bitmap (*.bmp) and create a new image resource.

Transparency is enabled by GSLC_BMP_TRANS_EN through use of color (GSLC_BMP_TRANS_RGB).

Parameters
[in]pGuiPointer to GUI
[in]sImgRefImage reference
Returns
Image pointer (surface/texture/path) or NULL if error

Transparency is enabled by GSLC_BMP_TRANS_EN through use of color (GSLC_BMP_TRANS_RGB).

Parameters
[in]pGuiPointer to GUI
[in]sImgRefImage reference
Returns
Image pointer (surface/texture) or NULL if error
void gslc_DrvPageFlipNow ( gslc_tsGui pGui)

Force a page flip to occur.

This generally copies active screen surface to the display.

Parameters
[in]pGuiPointer to GUI
Returns
none
void gslc_DrvReportInfoPost ( )

Report driver debug info (after initialization)

Returns
none
void gslc_DrvReportInfoPre ( )

Report driver debug info (before initialization)

Returns
none
bool gslc_DrvRotate ( gslc_tsGui pGui,
uint8_t  nRotation 
)

Change rotation, automatically adapt touchscreen axes swap/flip.

Parameters
[in]pGuiPointer to GUI
[in]nRotationScreen Rotation value (0, 1, 2 or 3)
Returns
true if successful

Change rotation, automatically adapt touchscreen axes swap/flip.

bool gslc_DrvSetBkgndColor ( gslc_tsGui pGui,
gslc_tsColor  nCol 
)

Configure the background to use a solid color.

  • The background is used when redrawing the entire page
Parameters
[in]pGuiPointer to GUI
[in]nColRGB Color to use
Returns
true if success, false if fail
bool gslc_DrvSetBkgndImage ( gslc_tsGui pGui,
gslc_tsImgRef  sImgRef 
)

Configure the background to use a bitmap image.

  • The background is used when redrawing the entire page
Parameters
[in]pGuiPointer to GUI
[in]sImgRefImage reference
Returns
true if success, false if fail
bool gslc_DrvSetClipRect ( gslc_tsGui pGui,
gslc_tsRect pRect 
)

Set the clipping rectangle for future drawing updates.

Parameters
[in]pGuiPointer to GUI
[in]pRectRectangular region to constrain edits
Returns
true if success, false if error
bool gslc_DrvSetElemImageGlow ( gslc_tsGui pGui,
gslc_tsElem pElem,
gslc_tsImgRef  sImgRef 
)

Set an element's glow-state image.

Parameters
[in]pGuiPointer to GUI
[in]pElemPointer to Element to update
[in]sImgRefImage reference
Returns
true if success, false if error
bool gslc_DrvSetElemImageNorm ( gslc_tsGui pGui,
gslc_tsElem pElem,
gslc_tsImgRef  sImgRef 
)

Set an element's normal-state image.

Parameters
[in]pGuiPointer to GUI
[in]pElemPointer to Element to update
[in]sImgRefImage reference
Returns
true if success, false if error