GUIslice  0.16.0
Embedded GUI in C
GUIslice_drv_adagfx.cpp File Reference
#include "GUIslice_config.h"
#include "GUIslice_drv_adagfx.h"
#include <stdio.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include "Adafruit_STMPE610.h"
Include dependency graph for GUIslice_drv_adagfx.cpp:

Macros

#define DRV_TOUCH_INSTANCE
 

Functions

bool gslc_DrvInit (gslc_tsGui *pGui)
 Initialize the SDL library. More...
 
void * gslc_DrvGetDriverDisp (gslc_tsGui *pGui)
 Get the native display driver instance. 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_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_DrvFontSetHelp (gslc_tsGui *pGui, gslc_tsFont *pFont)
 
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=GSLC_COL_BLACK)
 Draw a text string at the given coordinate. More...
 
void gslc_DrvPageFlipNow (gslc_tsGui *pGui)
 Force a page flip to occur. More...
 
void gslc_DrvDrawPoint_base (int16_t nX, int16_t nY, uint16_t nColRaw)
 
void gslc_DrvDrawLine_base (int16_t nX0, int16_t nY0, int16_t nX1, int16_t nY1, uint16_t nColRaw)
 
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_DrvDrawFillRect (gslc_tsGui *pGui, gslc_tsRect rRect, gslc_tsColor nCol)
 Draw a filled rectangle. More...
 
bool gslc_DrvDrawFillRoundRect (gslc_tsGui *pGui, gslc_tsRect rRect, int16_t nRadius, gslc_tsColor nCol)
 Draw a filled rounded rectangle. More...
 
bool gslc_DrvDrawFrameRect (gslc_tsGui *pGui, gslc_tsRect rRect, gslc_tsColor nCol)
 Draw a framed rectangle. More...
 
bool gslc_DrvDrawFrameRoundRect (gslc_tsGui *pGui, gslc_tsRect rRect, int16_t nRadius, gslc_tsColor nCol)
 Draw a framed rounded 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_DrvDrawFrameCircle (gslc_tsGui *pGui, int16_t nMidX, int16_t nMidY, uint16_t nRadius, gslc_tsColor nCol)
 Draw a framed circle. More...
 
bool gslc_DrvDrawFillCircle (gslc_tsGui *pGui, int16_t nMidX, int16_t nMidY, uint16_t nRadius, gslc_tsColor nCol)
 Draw a filled circle. More...
 
bool gslc_DrvDrawFrameTriangle (gslc_tsGui *pGui, int16_t nX0, int16_t nY0, int16_t nX1, int16_t nY1, int16_t nX2, int16_t nY2, gslc_tsColor nCol)
 Draw a framed triangle. More...
 
bool gslc_DrvDrawFillTriangle (gslc_tsGui *pGui, int16_t nX0, int16_t nY0, int16_t nX1, int16_t nY1, int16_t nX2, int16_t nY2, gslc_tsColor nCol)
 Draw a filled triangle. More...
 
void gslc_DrvDrawMonoFromMem (gslc_tsGui *pGui, int16_t nDstX, int16_t nDstY, const unsigned char *pBitmap, bool bProgMem)
 Draw a monochrome bitmap from a memory array. More...
 
void gslc_DrvDrawBmp24FromMem (gslc_tsGui *pGui, int16_t nDstX, int16_t nDstY, const unsigned char *pBitmap, bool bProgMem)
 Draw a color 24-bit depth bitmap from a memory array. More...
 
uint16_t gslc_DrvRead16SD (File &f)
 
uint32_t gslc_DrvRead32SD (File &f)
 
void gslc_DrvDrawBmp24FromSD (gslc_tsGui *pGui, const char *filename, uint16_t x, uint16_t y)
 Draw a color 24-bit depth bitmap from SD card. 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_DrvInitTouch (gslc_tsGui *pGui, const char *acDev)
 Perform any touchscreen-specific initialization. More...
 
void * gslc_DrvGetDriverTouch (gslc_tsGui *pGui)
 Get the native touch driver instance. 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 internal touch handler. More...
 
bool gslc_TDrvInitTouch (gslc_tsGui *pGui, const char *acDev)
 Perform any touchscreen-specific initialization. More...
 
bool gslc_TDrvGetTouch (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 display rotation and any associated touch orientation. More...
 
uint16_t gslc_DrvAdaptColorToRaw (gslc_tsColor nCol)
 

Variables

const char * m_acDrvDisp
 
Adafruit_ILI9341 m_disp
 
const char * m_acDrvTouch
 
Adafruit_STMPE610 m_touch
 

Macro Definition Documentation

#define DRV_TOUCH_INSTANCE

Function Documentation

uint16_t gslc_DrvAdaptColorToRaw ( gslc_tsColor  nCol)
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
void gslc_DrvDrawBmp24FromMem ( gslc_tsGui pGui,
int16_t  nDstX,
int16_t  nDstY,
const unsigned char *  pBitmap,
bool  bProgMem 
)

Draw a color 24-bit depth bitmap from a memory array.

Parameters
[in]pGuiPointer to GUI
[in]nDstXX coord for copy
[in]nDstYY coord for copy
[in]pBitmapPointer to bitmap buffer
[in]bProgMemBitmap is stored in Flash if true, RAM otherwise
Returns
none
void gslc_DrvDrawBmp24FromSD ( gslc_tsGui pGui,
const char *  filename,
uint16_t  x,
uint16_t  y 
)

Draw a color 24-bit depth bitmap from SD card.

Parameters
[in]pGuiPointer to GUI
[in]filenameFilename on SD card (usually in form "/pic.bmp")
[in]xX coordinate to draw bitmap
[in]yY coordinate to draw bitmap
Returns
none
bool gslc_DrvDrawFillCircle ( gslc_tsGui pGui,
int16_t  nMidX,
int16_t  nMidY,
uint16_t  nRadius,
gslc_tsColor  nCol 
)

Draw a filled circle.

Parameters
[in]pGuiPointer to GUI
[in]nMidXCenter of circle (X coordinate)
[in]nMidYCenter of circle (Y coordinate)
[in]nRadiusRadius of circle
[in]nColColor RGB value to fill
Returns
true if success, false if error
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_DrvDrawFillRoundRect ( gslc_tsGui pGui,
gslc_tsRect  rRect,
int16_t  nRadius,
gslc_tsColor  nCol 
)

Draw a filled rounded rectangle.

Parameters
[in]pGuiPointer to GUI
[in]rRectRectangular region to fill
[in]nRadiusRadius for rounded corners
[in]nColColor RGB value to fill
Returns
true if success, false if error
bool gslc_DrvDrawFillTriangle ( gslc_tsGui pGui,
int16_t  nX0,
int16_t  nY0,
int16_t  nX1,
int16_t  nY1,
int16_t  nX2,
int16_t  nY2,
gslc_tsColor  nCol 
)

Draw a filled triangle.

Parameters
[in]pGuiPointer to GUI
[in]nX0X Coordinate #1
[in]nY0Y Coordinate #1
[in]nX1X Coordinate #2
[in]nY1Y Coordinate #2
[in]nX2X Coordinate #3
[in]nY2Y Coordinate #3
[in]nColColor RGB value to fill
Returns
true if success, false if error
bool gslc_DrvDrawFrameCircle ( gslc_tsGui pGui,
int16_t  nMidX,
int16_t  nMidY,
uint16_t  nRadius,
gslc_tsColor  nCol 
)

Draw a framed circle.

Parameters
[in]pGuiPointer to GUI
[in]nMidXCenter of circle (X coordinate)
[in]nMidYCenter of circle (Y coordinate)
[in]nRadiusRadius of circle
[in]nColColor RGB value to frame
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_DrvDrawFrameRoundRect ( gslc_tsGui pGui,
gslc_tsRect  rRect,
int16_t  nRadius,
gslc_tsColor  nCol 
)

Draw a framed rounded rectangle.

Parameters
[in]pGuiPointer to GUI
[in]rRectRectangular region to frame
[in]nRadiusRadius for rounded corners
[in]nColColor RGB value to frame
Returns
true if success, false if error
bool gslc_DrvDrawFrameTriangle ( gslc_tsGui pGui,
int16_t  nX0,
int16_t  nY0,
int16_t  nX1,
int16_t  nY1,
int16_t  nX2,
int16_t  nY2,
gslc_tsColor  nCol 
)

Draw a framed triangle.

Parameters
[in]pGuiPointer to GUI
[in]nX0X Coordinate #1
[in]nY0Y Coordinate #1
[in]nX1X Coordinate #2
[in]nY1Y Coordinate #2
[in]nX2X Coordinate #3
[in]nY2Y Coordinate #3
[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
void gslc_DrvDrawLine_base ( int16_t  nX0,
int16_t  nY0,
int16_t  nX1,
int16_t  nY1,
uint16_t  nColRaw 
)
inline
void gslc_DrvDrawMonoFromMem ( gslc_tsGui pGui,
int16_t  nDstX,
int16_t  nDstY,
const unsigned char *  pBitmap,
bool  bProgMem 
)

Draw a monochrome bitmap from a memory array.

  • Draw from the bitmap buffer using the foreground color defined in the header (unset bits are transparent)
Parameters
[in]pGuiPointer to GUI
[in]nDstXDestination X coord for copy
[in]nDstYDestination Y coord for copy
[in]pBitmapPointer to bitmap buffer
[in]bProgMemBitmap is stored in Flash if true, RAM otherwise
Returns
none
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
void gslc_DrvDrawPoint_base ( int16_t  nX,
int16_t  nY,
uint16_t  nColRaw 
)
inline
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 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_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
bool gslc_DrvFontSetHelp ( gslc_tsGui pGui,
gslc_tsFont pFont 
)
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 internal touch handler.

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(). 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) 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
uint16_t gslc_DrvRead16SD ( File &  f)
uint32_t gslc_DrvRead32SD ( File &  f)
bool gslc_DrvRotate ( gslc_tsGui pGui,
uint8_t  nRotation 
)

Change display rotation and any associated touch orientation.

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
bool gslc_TDrvGetTouch ( 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
bool gslc_TDrvInitTouch ( 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

Variable Documentation

const char* m_acDrvDisp
const char* m_acDrvTouch
Adafruit_ILI9341 m_disp
Adafruit_STMPE610 m_touch