GUIslice  0.16.0
Embedded GUI in C
GUIslice_drv_utft.h
Go to the documentation of this file.
1 #ifndef _GUISLICE_DRV_UTFT_H_
2 #define _GUISLICE_DRV_UTFT_H_
3 
4 // =======================================================================
5 // GUIslice library (driver layer for UTFT)
6 // - Calvin Hass
7 // - https://www.impulseadventure.com/elec/guislice-gui.html
8 // - https://github.com/ImpulseAdventure/GUIslice
9 // =======================================================================
10 //
11 // The MIT License
12 //
13 // Copyright 2016-2020 Calvin Hass
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining a copy
16 // of this software and associated documentation files (the "Software"), to deal
17 // in the Software without restriction, including without limitation the rights
18 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19 // copies of the Software, and to permit persons to whom the Software is
20 // furnished to do so, subject to the following conditions:
21 //
22 // The above copyright notice and this permission notice shall be included in
23 // all copies or substantial portions of the Software.
24 //
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31 // THE SOFTWARE.
32 //
33 // =======================================================================
36 
37 
38 // =======================================================================
39 // Driver Layer for UTFT
40 // =======================================================================
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif // __cplusplus
45 
46 #include "GUIslice.h"
47 
48 #include <stdio.h>
49 
50 
51 // Determine characteristics for configured touch driver
52 // - DRV_TOUCH_TYPE_EXTERNAL: TDrv* external touch APIs are enabled
53 // - DRV_TOUCH_TYPE_RES: Resistive overlay
54 // - DRV_TOUCH_TYPE_CAP: Capacitive overlay
55 // - DRV_TOUCH_TYPE_ANALOG: Analog input
56 #if defined(DRV_TOUCH_URTOUCH)
57  #define DRV_TOUCH_TYPE_EXTERNAL
58  // Don't set DRV_TOUCH_TYPE_RES since URTouch provides its own calibration
59  //#define DRV_TOUCH_TYPE_RES // Resistive
60 #elif defined(DRV_TOUCH_INPUT)
61  #define DRV_TOUCH_TYPE_EXTERNAL
62 #elif defined(DRV_TOUCH_NONE)
63 #endif // DRV_TOUCH_*
64 
65 // Determine if calibration required
66 // - Enable for resistive displays
67 // - User config can also enable for capacitive displays by adding:
68 // #define DRV_TOUCH_CALIB
69 #if defined(DRV_TOUCH_TYPE_RES)
70  #define DRV_TOUCH_CALIB
71 #endif
72 
73 #if defined(DRV_TOUCH_CALIB)
74  // Ensure calibration settings are present in the config file
75  #if !defined(ADATOUCH_X_MIN)
76  // We didn't locate the calibration settings, so provide some
77  // temporary defaults. This typically only occurs if user has
78  // decided to force calibration on a capacitive display by
79  // adding DRV_TOUCH_CALIB, but hasn't yet added the calibration
80  // settings (ADATOUCH_X/Y_MIN/MAX) from the calibration sketch yet.
81  #warning Calibration settings (ADATOUCH_X/Y_MIN/MAX) need to be added to config. Using defaults.
82  #define ADATOUCH_X_MIN 0
83  #define ADATOUCH_X_MAX 4000
84  #define ADATOUCH_Y_MIN 0
85  #define ADATOUCH_Y_MAX 4000
86  #define ADATOUCH_REMAP_YX 0
87  #endif // ADATOUCH_X_MIN
88 #endif // DRV_TOUCH_CALIB
89 
90 // =======================================================================
91 // API support definitions
92 // - These defines indicate whether the driver includes optimized
93 // support for various APIs. If a define is set to 0, then the
94 // GUIslice core emulation will be used instead.
95 // - At the very minimum, the point draw routine must be available:
96 // gslc_DrvDrawPoint()
97 // =======================================================================
98 
99 #define DRV_HAS_DRAW_POINT 1
100 
101 #define DRV_HAS_DRAW_POINTS 0
102 #define DRV_HAS_DRAW_LINE 1
103 #define DRV_HAS_DRAW_RECT_FRAME 1
104 #define DRV_HAS_DRAW_RECT_FILL 1
105 #define DRV_HAS_DRAW_RECT_ROUND_FRAME 1
106 #define DRV_HAS_DRAW_RECT_ROUND_FILL 1
107 #define DRV_HAS_DRAW_CIRCLE_FRAME 1
108 #define DRV_HAS_DRAW_CIRCLE_FILL 1
109 #define DRV_HAS_DRAW_TRI_FRAME 0
110 #define DRV_HAS_DRAW_TRI_FILL 0
111 #define DRV_HAS_DRAW_TEXT 1
112 #define DRV_HAS_DRAW_BMP_MEM 0
113 
114 #define DRV_OVERRIDE_TXT_ALIGN 0
115 
116 // =======================================================================
117 // Driver-specific members
118 // =======================================================================
119 typedef struct {
120  gslc_tsColor nColBkgnd;
121 
122  gslc_tsRect rClipRect;
123 
124 } gslc_tsDriver;
125 
126 
127 
128 // =======================================================================
129 // Public APIs to GUIslice core library
130 // - These functions define the renderer / driver-dependent
131 // implementations for the core drawing operations within
132 // GUIslice.
133 // =======================================================================
134 
135 
136 // -----------------------------------------------------------------------
137 // Configuration Functions
138 // -----------------------------------------------------------------------
139 
156 bool gslc_DrvInit(gslc_tsGui* pGui);
157 
158 
168 bool gslc_DrvInitTs(gslc_tsGui* pGui,const char* acDev);
169 
170 
179 void gslc_DrvDestruct(gslc_tsGui* pGui);
180 
181 
189 const char* gslc_DrvGetNameDisp(gslc_tsGui* pGui);
190 
191 
199 const char* gslc_DrvGetNameTouch(gslc_tsGui* pGui);
200 
213 void* gslc_DrvGetDriverDisp(gslc_tsGui* pGui);
214 
228 
229 // -----------------------------------------------------------------------
230 // Image/surface handling Functions
231 // -----------------------------------------------------------------------
232 
233 
244 void* gslc_DrvLoadImage(gslc_tsGui* pGui,gslc_tsImgRef sImgRef);
245 
246 
257 
268 
279 
290 
291 
299 void gslc_DrvImageDestruct(void* pvImg);
300 
301 
310 bool gslc_DrvSetClipRect(gslc_tsGui* pGui,gslc_tsRect* pRect);
311 
312 
313 // -----------------------------------------------------------------------
314 // Font handling Functions
315 // -----------------------------------------------------------------------
316 
326 const void* gslc_DrvFontAdd(gslc_teFontRefType eFontRefType,const void* pvFontRef,uint16_t nFontSz);
327 
336 
337 
352 bool gslc_DrvGetTxtSize(gslc_tsGui* pGui,gslc_tsFont* pFont,const char* pStr,gslc_teTxtFlags eTxtFlags,
353  int16_t* pnTxtX,int16_t* pnTxtY,uint16_t* pnTxtSzW,uint16_t* pnTxtSzH);
354 
355 
370 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);
371 
372 
373 // -----------------------------------------------------------------------
374 // Screen Management Functions
375 // -----------------------------------------------------------------------
376 
385 void gslc_DrvPageFlipNow(gslc_tsGui* pGui);
386 
387 
388 // -----------------------------------------------------------------------
389 // Graphics Primitives Functions
390 // -----------------------------------------------------------------------
391 
402 bool gslc_DrvDrawPoint(gslc_tsGui* pGui,int16_t nX,int16_t nY,gslc_tsColor nCol);
403 
414 bool gslc_DrvDrawPoints(gslc_tsGui* pGui,gslc_tsPt* asPt,uint16_t nNumPt,gslc_tsColor nCol);
415 
426 
427 
438 
439 
450 bool gslc_DrvDrawFrameRoundRect(gslc_tsGui* pGui,gslc_tsRect rRect,int16_t nRadius,gslc_tsColor nCol);
451 
452 
463 bool gslc_DrvDrawFillRoundRect(gslc_tsGui* pGui,gslc_tsRect rRect,int16_t nRadius,gslc_tsColor nCol);
464 
465 
466 
479 bool gslc_DrvDrawLine(gslc_tsGui* pGui,int16_t nX0,int16_t nY0,int16_t nX1,int16_t nY1,gslc_tsColor nCol);
480 
481 
493 bool gslc_DrvDrawFrameCircle(gslc_tsGui* pGui,int16_t nMidX,int16_t nMidY,uint16_t nRadius,gslc_tsColor nCol);
494 
495 
507 bool gslc_DrvDrawFillCircle(gslc_tsGui* pGui,int16_t nMidX,int16_t nMidY,uint16_t nRadius,gslc_tsColor nCol);
508 
509 
524 bool gslc_DrvDrawFrameTriangle(gslc_tsGui* pGui,int16_t nX0,int16_t nY0,
525  int16_t nX1,int16_t nY1,int16_t nX2,int16_t nY2,gslc_tsColor nCol);
526 
527 
542 bool gslc_DrvDrawFillTriangle(gslc_tsGui* pGui,int16_t nX0,int16_t nY0,
543  int16_t nX1,int16_t nY1,int16_t nX2,int16_t nY2,gslc_tsColor nCol);
544 
545 
556 bool gslc_DrvDrawImage(gslc_tsGui* pGui,int16_t nDstX,int16_t nDstY,gslc_tsImgRef sImgRef);
557 
558 
572 void gslc_DrvDrawMonoFromMem(gslc_tsGui* pGui,int16_t nDstX, int16_t nDstY, const unsigned char *pBitmap,bool bProgMem);
573 
574 
591 void gslc_DrvDrawBmp24FromMem(gslc_tsGui* pGui,int16_t nDstX, int16_t nDstY,const unsigned char* pBitmap,bool bProgMem);
592 
600 void gslc_DrvDrawBkgnd(gslc_tsGui* pGui);
601 
602 
603 // -----------------------------------------------------------------------
604 // Touch Functions (if using display driver library)
605 // -----------------------------------------------------------------------
606 
616 bool gslc_DrvInitTouch(gslc_tsGui* pGui,const char* acDev);
617 
618 
631 bool gslc_DrvGetTouch(gslc_tsGui* pGui,int16_t* pnX,int16_t* pnY,uint16_t* pnPress,gslc_teInputRawEvent* peInputEvent,int16_t* pnInputVal);
632 
633 
634 // -----------------------------------------------------------------------
635 // Touch Functions (if using external touch driver library)
636 // -----------------------------------------------------------------------
637 
638 
639 #if defined(DRV_TOUCH_TYPE_EXTERNAL)
640 bool gslc_TDrvInitTouch(gslc_tsGui* pGui,const char* acDev);
650 
651 
664 bool gslc_TDrvGetTouch(gslc_tsGui* pGui, int16_t* pnX, int16_t* pnY, uint16_t* pnPress, gslc_teInputRawEvent* peInputEvent, int16_t* pnInputVal);
665 
666 #endif // DRV_TOUCH_*
667 
668 
669 // -----------------------------------------------------------------------
670 // Dynamic Screen rotation and Touch axes swap/flip functions
671 // -----------------------------------------------------------------------
672 
681 bool gslc_DrvRotate(gslc_tsGui* pGui, uint8_t nRotation);
682 
683 
684 // =======================================================================
685 // Private Functions
686 // - These functions are not included in the scope of APIs used by
687 // the core GUIslice library. Instead, these functions are used
688 // to support the operations within this driver layer.
689 // =======================================================================
690 
692 
693 #ifdef __cplusplus
694 }
695 #endif // __cplusplus
696 #endif // _GUISLICE_DRV_ADAGFX_H_
void gslc_DrvFontsDestruct(gslc_tsGui *pGui)
Release all fonts defined in the GUI.
Definition: GUIslice_drv_adagfx.cpp:922
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.
Definition: GUIslice_drv_adagfx.cpp:1198
bool gslc_DrvInit(gslc_tsGui *pGui)
Initialize the SDL library.
Definition: GUIslice_drv_adagfx.cpp:571
bool gslc_DrvDrawFrameRoundRect(gslc_tsGui *pGui, gslc_tsRect rRect, int16_t nRadius, gslc_tsColor nCol)
Draw a framed rounded rectangle.
Definition: GUIslice_drv_adagfx.cpp:1639
bool gslc_DrvSetElemImageGlow(gslc_tsGui *pGui, gslc_tsElem *pElem, gslc_tsImgRef sImgRef)
Set an element&#39;s glow-state image.
Definition: GUIslice_drv_adagfx.cpp:872
gslc_teFontRefType
Font Reference types.
Definition: GUIslice.h:383
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.
Definition: GUIslice_drv_adagfx.cpp:2026
bool gslc_DrvDrawLine(gslc_tsGui *pGui, int16_t nX0, int16_t nY0, int16_t nX1, int16_t nY1, gslc_tsColor nCol)
Draw a line.
Definition: GUIslice_drv_adagfx.cpp:1658
bool gslc_DrvDrawFrameRect(gslc_tsGui *pGui, gslc_tsRect rRect, gslc_tsColor nCol)
Draw a framed rectangle.
Definition: GUIslice_drv_adagfx.cpp:1591
bool gslc_DrvDrawFrameCircle(gslc_tsGui *pGui, int16_t nMidX, int16_t nMidY, uint16_t nRadius, gslc_tsColor nCol)
Draw a framed circle.
Definition: GUIslice_drv_adagfx.cpp:1672
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.
Definition: GUIslice_drv_adagfx.cpp:2399
Image reference structure.
Definition: GUIslice.h:569
bool gslc_DrvInitTouch(gslc_tsGui *pGui, const char *acDev)
Perform any touchscreen-specific initialization.
Definition: GUIslice_drv_adagfx.cpp:2135
gslc_teTxtFlags
Text reference flags: Describes the characteristics of a text string (ie.
Definition: GUIslice.h:463
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.
Definition: GUIslice_drv_adagfx.cpp:1817
bool gslc_TDrvInitTouch(gslc_tsGui *pGui, const char *acDev)
Perform any touchscreen-specific initialization.
Definition: GUIslice_drv_adagfx.cpp:2295
bool gslc_DrvRotate(gslc_tsGui *pGui, uint8_t nRotation)
Change rotation, automatically adapt touchscreen axes swap/flip.
Definition: GUIslice_drv_adagfx.cpp:3059
void * gslc_DrvGetDriverDisp(gslc_tsGui *pGui)
Get the native display driver instance.
Definition: GUIslice_drv_adagfx.cpp:781
bool gslc_DrvDrawPoint(gslc_tsGui *pGui, int16_t nX, int16_t nY, gslc_tsColor nCol)
Draw a point.
Definition: GUIslice_drv_adagfx.cpp:1527
void gslc_DrvDestruct(gslc_tsGui *pGui)
Free up any members associated with the driver.
Definition: GUIslice_drv_adagfx.cpp:787
void gslc_DrvDrawBkgnd(gslc_tsGui *pGui)
Copy the background image to destination screen.
Definition: GUIslice_drv_adagfx.cpp:2099
bool gslc_DrvSetElemImageNorm(gslc_tsGui *pGui, gslc_tsElem *pElem, gslc_tsImgRef sImgRef)
Set an element&#39;s normal-state image.
Definition: GUIslice_drv_adagfx.cpp:862
const char * gslc_DrvGetNameTouch(gslc_tsGui *pGui)
Get the touch driver name.
Definition: GUIslice_drv_adagfx.cpp:798
Rectangular region. Defines X,Y corner coordinates plus dimensions.
Definition: GUIslice.h:519
bool gslc_DrvInitTs(gslc_tsGui *pGui, const char *acDev)
Perform any touchscreen-specific initialization.
Definition: GUIslice_drv_adagfx.h:199
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.
Definition: GUIslice_drv_adagfx.cpp:1779
gslc_teInputRawEvent
Raw input event types: touch, key, GPIOs.
Definition: GUIslice.h:260
uint16_t gslc_DrvAdaptColorToRaw(gslc_tsColor nCol)
Definition: GUIslice_drv_adagfx.cpp:3314
bool gslc_DrvDrawFillRoundRect(gslc_tsGui *pGui, gslc_tsRect rRect, int16_t nRadius, gslc_tsColor nCol)
Draw a filled rounded rectangle.
Definition: GUIslice_drv_adagfx.cpp:1574
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.
Definition: GUIslice_drv_adagfx.cpp:1711
void gslc_DrvImageDestruct(void *pvImg)
Release an image surface.
Definition: GUIslice_drv_adagfx.cpp:882
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.
Definition: GUIslice_drv_adagfx.cpp:1733
void * gslc_DrvLoadImage(gslc_tsGui *pGui, gslc_tsImgRef sImgRef)
Load a bitmap (*.bmp) and create a new image resource.
Definition: GUIslice_drv_adagfx.cpp:809
bool gslc_DrvSetBkgndColor(gslc_tsGui *pGui, gslc_tsColor nCol)
Configure the background to use a solid color.
Definition: GUIslice_drv_adagfx.cpp:852
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.
Definition: GUIslice_drv_adagfx.cpp:2159
const char * gslc_DrvGetNameDisp(gslc_tsGui *pGui)
Get the display driver name.
Definition: GUIslice_drv_adagfx.cpp:792
const void * gslc_DrvFontAdd(gslc_teFontRefType eFontRefType, const void *pvFontRef, uint16_t nFontSz)
Load a font from a resource and return pointer to it.
Definition: GUIslice_drv_adagfx.cpp:910
bool gslc_DrvSetClipRect(gslc_tsGui *pGui, gslc_tsRect *pRect)
Set the clipping rectangle for future drawing updates.
Definition: GUIslice_drv_adagfx.cpp:887
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.
Definition: GUIslice_drv_adagfx.cpp:982
void * gslc_DrvGetDriverTouch(gslc_tsGui *pGui)
Get the native touch driver instance.
Definition: GUIslice_drv_adagfx.cpp:2146
Define point coordinates.
Definition: GUIslice.h:528
GUI structure.
Definition: GUIslice.h:716
bool gslc_DrvDrawFillRect(gslc_tsGui *pGui, gslc_tsRect rRect, gslc_tsColor nCol)
Draw a filled rectangle.
Definition: GUIslice_drv_adagfx.cpp:1550
bool gslc_DrvDrawFillCircle(gslc_tsGui *pGui, int16_t nMidX, int16_t nMidY, uint16_t nRadius, gslc_tsColor nCol)
Draw a filled circle.
Definition: GUIslice_drv_adagfx.cpp:1691
Element Struct.
Definition: GUIslice.h:593
Color structure. Defines RGB triplet.
Definition: GUIslice.h:534
Font reference structure.
Definition: GUIslice.h:559
bool gslc_DrvDrawPoints(gslc_tsGui *pGui, gslc_tsPt *asPt, uint16_t nNumPt, gslc_tsColor nCol)
Draw a point.
Definition: GUIslice_drv_adagfx.cpp:1541
void gslc_DrvPageFlipNow(gslc_tsGui *pGui)
Force a page flip to occur.
Definition: GUIslice_drv_adagfx.cpp:1483
bool gslc_DrvSetBkgndImage(gslc_tsGui *pGui, gslc_tsImgRef sImgRef)
Configure the background to use a bitmap image.
Definition: GUIslice_drv_adagfx.cpp:833