GUIslice  0.16.0
Embedded GUI in C
Graphics General Functions

Helper functions that support graphics operations. More...

Functions

bool gslc_IsInRect (int16_t nSelX, int16_t nSelY, gslc_tsRect rRect)
 Determine if a coordinate is inside of a rectangular region. More...
 
gslc_tsRect gslc_ExpandRect (gslc_tsRect rRect, int16_t nExpandW, int16_t nExpandH)
 Expand or contract a rectangle in width and/or height (equal amounts on both side), based on the centerpoint of the rectangle. More...
 
bool gslc_IsInWH (int16_t nSelX, int16_t nSelY, uint16_t nWidth, uint16_t nHeight)
 Determine if a coordinate is inside of a width x height region. More...
 
void gslc_UnionRect (gslc_tsRect *pRect, gslc_tsRect rAddRect)
 Expand a rect to include another rect. More...
 
void gslc_InvalidateRgnReset (gslc_tsGui *pGui)
 Reset the invalidation region. More...
 
void gslc_InvalidateRgnPage (gslc_tsGui *pGui, gslc_tsPage *pPage)
 Include an entire page (eg. More...
 
void gslc_InvalidateRgnScreen (gslc_tsGui *pGui)
 Mark the entire screen as invalidated. More...
 
void gslc_InvalidateRgnAdd (gslc_tsGui *pGui, gslc_tsRect rAddRect)
 Add a rectangular region to the invalidation region. More...
 
bool gslc_ClipPt (gslc_tsRect *pClipRect, int16_t nX, int16_t nY)
 Perform basic clipping of a single point to a clipping region. More...
 
bool gslc_ClipLine (gslc_tsRect *pClipRect, int16_t *pnX0, int16_t *pnY0, int16_t *pnX1, int16_t *pnY1)
 Perform basic clipping of a line to a clipping region. More...
 
bool gslc_ClipRect (gslc_tsRect *pClipRect, gslc_tsRect *pRect)
 Perform basic clipping of a rectangle to a clipping region. More...
 
gslc_tsImgRef gslc_GetImageFromFile (const char *pFname, gslc_teImgRefFlags eFmt)
 Create an image reference to a bitmap file in LINUX filesystem. More...
 
gslc_tsImgRef gslc_GetImageFromSD (const char *pFname, gslc_teImgRefFlags eFmt)
 Create an image reference to a bitmap file in SD card. More...
 
gslc_tsImgRef gslc_GetImageFromRam (unsigned char *pImgBuf, gslc_teImgRefFlags eFmt)
 Create an image reference to a bitmap in SRAM. More...
 
gslc_tsImgRef gslc_GetImageFromProg (const unsigned char *pImgBuf, gslc_teImgRefFlags eFmt)
 Create an image reference to a bitmap in program memory (PROGMEM) More...
 
void gslc_PolarToXY (uint16_t nRad, int16_t n64Ang, int16_t *nDX, int16_t *nDY)
 Convert polar coordinate to cartesian. More...
 
int16_t gslc_sinFX (int16_t n64Ang)
 Calculate fixed-point sine function from fractional degrees. More...
 
int16_t gslc_cosFX (int16_t n64Ang)
 Calculate fixed-point cosine function from fractional degrees. More...
 
gslc_tsColor gslc_ColorBlend2 (gslc_tsColor colStart, gslc_tsColor colEnd, uint16_t nMidAmt, uint16_t nBlendAmt)
 Create a color based on a blend between two colors. More...
 
gslc_tsColor gslc_ColorBlend3 (gslc_tsColor colStart, gslc_tsColor colMid, gslc_tsColor colEnd, uint16_t nMidAmt, uint16_t nBlendAmt)
 Create a color based on a blend between three colors. More...
 
bool gslc_ColorEqual (gslc_tsColor a, gslc_tsColor b)
 Check whether two colors are equal. More...
 

Detailed Description

Helper functions that support graphics operations.

Function Documentation

bool gslc_ClipLine ( gslc_tsRect pClipRect,
int16_t *  pnX0,
int16_t *  pnY0,
int16_t *  pnX1,
int16_t *  pnY1 
)

Perform basic clipping of a line to a clipping region.

  • Implements Cohen-Sutherland algorithm
  • Coordinates in parameter list are modified to fit the region
Parameters
[in]pClipRectPointer to clipping region
[in,out]pnX0Ptr to X coordinate of line start
[in,out]pnY0Ptr to Y coordinate of line start
[in,out]pnX1Ptr to X coordinate of line end
[in,out]pnY1Ptr to Y coordinate of line end
Returns
true if line is visible, false if it should be discarded
bool gslc_ClipPt ( gslc_tsRect pClipRect,
int16_t  nX,
int16_t  nY 
)

Perform basic clipping of a single point to a clipping region.

Parameters
[in]pClipRectPointer to clipping region
[in]nXX coordinate of point
[in]nYY coordinate of point
Returns
true if point is visible, false if it should be discarded
bool gslc_ClipRect ( gslc_tsRect pClipRect,
gslc_tsRect pRect 
)

Perform basic clipping of a rectangle to a clipping region.

  • Coordinates in parameter rect are modified to fit the region
Parameters
[in]pClipRectPointer to clipping region
[in,out]pRectPtr to rectangle
Returns
true if rect is visible, false if it should be discarded
gslc_tsColor gslc_ColorBlend2 ( gslc_tsColor  colStart,
gslc_tsColor  colEnd,
uint16_t  nMidAmt,
uint16_t  nBlendAmt 
)

Create a color based on a blend between two colors.

Parameters
[in]colStartStarting color
[in]colEndEnding color
[in]nMidAmtPosition (0..1000) between start and end color at which the midpoint between colors should appear. Normally set to 500 (half-way).
[in]nBlendAmtThe position (0..1000) between start and end at which we want to calculate the resulting blended color.
Returns
Blended color
gslc_tsColor gslc_ColorBlend3 ( gslc_tsColor  colStart,
gslc_tsColor  colMid,
gslc_tsColor  colEnd,
uint16_t  nMidAmt,
uint16_t  nBlendAmt 
)

Create a color based on a blend between three colors.

Parameters
[in]colStartStarting color
[in]colMidIntermediate color
[in]colEndEnding color
[in]nMidAmtPosition (0..1000) between start and end color at which the intermediate color should appear.
[in]nBlendAmtThe position (0..1000) between start and end at which we want to calculate the resulting blended color.
Returns
Blended color
bool gslc_ColorEqual ( gslc_tsColor  a,
gslc_tsColor  b 
)

Check whether two colors are equal.

Parameters
[in]aFirst color
[in]bSecond color
Returns
True iff a and b are the same color.
int16_t gslc_cosFX ( int16_t  n64Ang)

Calculate fixed-point cosine function from fractional degrees.

  • Depending on configuration, the result is derived from either floating point math library or fixed point lookup table.
  • gslc_cosFX(nAngDeg*64)/32768.0 = cos(nAngDeg*2pi/360)
Parameters
[in]n64AngAngle (in units of 1/64 degrees)
Returns
Fixed-point cosine result. Signed 16-bit; divide by 32768 to get the actual value.
gslc_tsRect gslc_ExpandRect ( gslc_tsRect  rRect,
int16_t  nExpandW,
int16_t  nExpandH 
)

Expand or contract a rectangle in width and/or height (equal amounts on both side), based on the centerpoint of the rectangle.

Parameters
[in]rRectRectangular region before resizing
[in]nExpandWNumber of pixels to expand the width (if positive) of contract the width (if negative)
[in]nExpandHNumber of pixels to expand the height (if positive) of contract the height (if negative)
Returns
gslc_tsRect() with resized dimensions
gslc_tsImgRef gslc_GetImageFromFile ( const char *  pFname,
gslc_teImgRefFlags  eFmt 
)

Create an image reference to a bitmap file in LINUX filesystem.

Parameters
[in]pFnamePointer to filename string of image in filesystem
[in]eFmtImage format
Returns
Loaded image reference
gslc_tsImgRef gslc_GetImageFromProg ( const unsigned char *  pImgBuf,
gslc_teImgRefFlags  eFmt 
)

Create an image reference to a bitmap in program memory (PROGMEM)

Parameters
[in]pImgBufPointer to image buffer in memory
[in]eFmtImage format
Returns
Loaded image reference
gslc_tsImgRef gslc_GetImageFromRam ( unsigned char *  pImgBuf,
gslc_teImgRefFlags  eFmt 
)

Create an image reference to a bitmap in SRAM.

Parameters
[in]pImgBufPointer to image buffer in memory
[in]eFmtImage format
Returns
Loaded image reference
gslc_tsImgRef gslc_GetImageFromSD ( const char *  pFname,
gslc_teImgRefFlags  eFmt 
)

Create an image reference to a bitmap file in SD card.

Parameters
[in]pFnamePointer to filename string of image in SD card
[in]eFmtImage format
Returns
Loaded image reference
void gslc_InvalidateRgnAdd ( gslc_tsGui pGui,
gslc_tsRect  rAddRect 
)

Add a rectangular region to the invalidation region.

  • This is usually called when an element has been modified
Parameters
[in]pGuiPointer to GUI
[in]rAddRectRectangle to add to the invalidation region
Returns
none
void gslc_InvalidateRgnPage ( gslc_tsGui pGui,
gslc_tsPage pPage 
)

Include an entire page (eg.

from a page stack) in the invalidation region

Parameters
[in]pGuiPointer to GUI
[in]pPagePointer to page
Returns
none
void gslc_InvalidateRgnReset ( gslc_tsGui pGui)

Reset the invalidation region.

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

Mark the entire screen as invalidated.

Parameters
[in]pGuiPointer to GUI
Returns
none
bool gslc_IsInRect ( int16_t  nSelX,
int16_t  nSelY,
gslc_tsRect  rRect 
)

Determine if a coordinate is inside of a rectangular region.

  • This routine is useful in determining if a touch coordinate is inside of a button.
Parameters
[in]nSelXX coordinate to test
[in]nSelYX coordinate to test
[in]rRectRectangular region to compare against
Returns
true if inside region, false otherwise
bool gslc_IsInWH ( int16_t  nSelX,
int16_t  nSelY,
uint16_t  nWidth,
uint16_t  nHeight 
)

Determine if a coordinate is inside of a width x height region.

  • This routine is useful in determining if a relative coordinate is within a given W x H dimension
Parameters
[in]nSelXX coordinate to test
[in]nSelYX coordinate to test
[in]nWidthWidth to test against
[in]nHeightHeight to test against
Returns
true if inside region, false otherwise
void gslc_PolarToXY ( uint16_t  nRad,
int16_t  n64Ang,
int16_t *  nDX,
int16_t *  nDY 
)

Convert polar coordinate to cartesian.

Parameters
[in]nRadRadius of ray
[in]n64AngAngle of ray (in units of 1/64 degrees, 0 is up)
[out]nDXX offset for ray end
[out]nDYY offset for ray end
Returns
none
int16_t gslc_sinFX ( int16_t  n64Ang)

Calculate fixed-point sine function from fractional degrees.

  • Depending on configuration, the result is derived from either floating point math library or fixed point lookup table.
  • gslc_sinFX(nAngDeg*64)/32768.0 = sin(nAngDeg*2pi/360)
Parameters
[in]n64AngAngle (in units of 1/64 degrees)
Returns
Fixed-point sine result. Signed 16-bit; divide by 32768 to get the actual value.
void gslc_UnionRect ( gslc_tsRect pRect,
gslc_tsRect  rAddRect 
)

Expand a rect to include another rect.

  • This routine can be useful to modify an invalidation region to include another modified element
Parameters
[in]pRectInitial rect region
[in]rAddRectRectangle to add to the rect region
Returns
none