GUIslice  0.16.0
Embedded GUI in C
GUIslice_drv_m5stack.h
Go to the documentation of this file.
1 #ifndef _GUISLICE_DRV_M5STACK_H_
2 #define _GUISLICE_DRV_M5STACK_H_
3 
4 // =======================================================================
5 // GUIslice library (driver layer for m5stack/M5Stack)
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 m5stack/M5Stack
40 // - https://github.com/m5stack/M5Stack
41 // =======================================================================
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif // __cplusplus
46 
47 #include "GUIslice.h"
48 
49 #include <stdio.h>
50 
51 
52 // ------------------------------------------------------------------------
53 // Error Strings
54 // ------------------------------------------------------------------------
55 
56 extern const char GSLC_PMEM ERRSTR_NULL[];
57 extern const char GSLC_PMEM ERRSTR_PXD_NULL[];
58 
59 
60 
61 // =======================================================================
62 // API support definitions
63 // - These defines indicate whether the driver includes optimized
64 // support for various APIs. If a define is set to 0, then the
65 // GUIslice core emulation will be used instead.
66 // - At the very minimum, the point draw routine must be available:
67 // gslc_DrvDrawPoint()
68 // =======================================================================
69 
70 #define DRV_HAS_DRAW_POINT 1
71 
72 #define DRV_HAS_DRAW_POINTS 0
73 #define DRV_HAS_DRAW_LINE 1
74 #define DRV_HAS_DRAW_RECT_FRAME 1
75 #define DRV_HAS_DRAW_RECT_FILL 1
76 #define DRV_HAS_DRAW_RECT_ROUND_FRAME 1
77 #define DRV_HAS_DRAW_RECT_ROUND_FILL 1
78 #define DRV_HAS_DRAW_CIRCLE_FRAME 1
79 #define DRV_HAS_DRAW_CIRCLE_FILL 1
80 #define DRV_HAS_DRAW_TRI_FRAME 1
81 #define DRV_HAS_DRAW_TRI_FILL 1
82 #define DRV_HAS_DRAW_TEXT 1
83 #define DRV_HAS_DRAW_BMP_MEM 0
84 
85 #define DRV_OVERRIDE_TXT_ALIGN 1
86 
87 // =======================================================================
88 // Driver-specific members
89 // =======================================================================
90 typedef struct {
91  gslc_tsColor nColBkgnd;
92 
93  gslc_tsRect rClipRect;
94 
96 
97 
98 
99 // =======================================================================
100 // Public APIs to GUIslice core library
101 // - These functions define the renderer / driver-dependent
102 // implementations for the core drawing operations within
103 // GUIslice.
104 // =======================================================================
105 
106 
107 // -----------------------------------------------------------------------
108 // Configuration Functions
109 // -----------------------------------------------------------------------
110 
127 bool gslc_DrvInit(gslc_tsGui* pGui);
128 
129 
139 bool gslc_DrvInitTs(gslc_tsGui* pGui,const char* acDev);
140 
141 
150 void gslc_DrvDestruct(gslc_tsGui* pGui);
151 
152 
160 const char* gslc_DrvGetNameDisp(gslc_tsGui* pGui);
161 
162 
170 const char* gslc_DrvGetNameTouch(gslc_tsGui* pGui);
171 
184 void* gslc_DrvGetDriverDisp(gslc_tsGui* pGui);
185 
199 
200 // -----------------------------------------------------------------------
201 // Image/surface handling Functions
202 // -----------------------------------------------------------------------
203 
204 
215 void* gslc_DrvLoadImage(gslc_tsGui* pGui,gslc_tsImgRef sImgRef);
216 
217 
228 
239 
250 
261 
262 
270 void gslc_DrvImageDestruct(void* pvImg);
271 
272 
281 bool gslc_DrvSetClipRect(gslc_tsGui* pGui,gslc_tsRect* pRect);
282 
283 
284 // -----------------------------------------------------------------------
285 // Font handling Functions
286 // -----------------------------------------------------------------------
287 
297 const void* gslc_DrvFontAdd(gslc_teFontRefType eFontRefType,const void* pvFontRef,uint16_t nFontSz);
298 
307 
308 
323 bool gslc_DrvGetTxtSize(gslc_tsGui* pGui,gslc_tsFont* pFont,const char* pStr,gslc_teTxtFlags eTxtFlags,
324  int16_t* pnTxtX,int16_t* pnTxtY,uint16_t* pnTxtSzW,uint16_t* pnTxtSzH);
325 
326 
341 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);
342 
360 bool gslc_DrvDrawTxtAlign(gslc_tsGui* pGui,int16_t nX0,int16_t nY0,int16_t nX1,int16_t nY1,int8_t eTxtAlign,
361  gslc_tsFont* pFont,const char* pStr,gslc_teTxtFlags eTxtFlags,gslc_tsColor colTxt,gslc_tsColor colBg);
362 
363 // -----------------------------------------------------------------------
364 // Screen Management Functions
365 // -----------------------------------------------------------------------
366 
375 void gslc_DrvPageFlipNow(gslc_tsGui* pGui);
376 
377 
378 // -----------------------------------------------------------------------
379 // Graphics Primitives Functions
380 // -----------------------------------------------------------------------
381 
392 bool gslc_DrvDrawPoint(gslc_tsGui* pGui,int16_t nX,int16_t nY,gslc_tsColor nCol);
393 
404 bool gslc_DrvDrawPoints(gslc_tsGui* pGui,gslc_tsPt* asPt,uint16_t nNumPt,gslc_tsColor nCol);
405 
416 
417 
428 
429 
440 bool gslc_DrvDrawFrameRoundRect(gslc_tsGui* pGui,gslc_tsRect rRect,int16_t nRadius,gslc_tsColor nCol);
441 
442 
453 bool gslc_DrvDrawFillRoundRect(gslc_tsGui* pGui,gslc_tsRect rRect,int16_t nRadius,gslc_tsColor nCol);
454 
455 
456 
469 bool gslc_DrvDrawLine(gslc_tsGui* pGui,int16_t nX0,int16_t nY0,int16_t nX1,int16_t nY1,gslc_tsColor nCol);
470 
471 
483 bool gslc_DrvDrawFrameCircle(gslc_tsGui* pGui,int16_t nMidX,int16_t nMidY,uint16_t nRadius,gslc_tsColor nCol);
484 
485 
497 bool gslc_DrvDrawFillCircle(gslc_tsGui* pGui,int16_t nMidX,int16_t nMidY,uint16_t nRadius,gslc_tsColor nCol);
498 
499 
514 bool gslc_DrvDrawFrameTriangle(gslc_tsGui* pGui,int16_t nX0,int16_t nY0,
515  int16_t nX1,int16_t nY1,int16_t nX2,int16_t nY2,gslc_tsColor nCol);
516 
517 
532 bool gslc_DrvDrawFillTriangle(gslc_tsGui* pGui,int16_t nX0,int16_t nY0,
533  int16_t nX1,int16_t nY1,int16_t nX2,int16_t nY2,gslc_tsColor nCol);
534 
535 
546 bool gslc_DrvDrawImage(gslc_tsGui* pGui,int16_t nDstX,int16_t nDstY,gslc_tsImgRef sImgRef);
547 
548 
562 void gslc_DrvDrawMonoFromMem(gslc_tsGui* pGui,int16_t nDstX, int16_t nDstY, const unsigned char *pBitmap,bool bProgMem);
563 
580 void gslc_DrvDrawBmp24FromMem(gslc_tsGui* pGui,int16_t nDstX, int16_t nDstY,const unsigned char* pBitmap,bool bProgMem);
581 
589 void gslc_DrvDrawBkgnd(gslc_tsGui* pGui);
590 
591 
592 // -----------------------------------------------------------------------
593 // Touch Functions (if using display driver library)
594 // -----------------------------------------------------------------------
595 
596 #if defined(DRV_TOUCH_IN_DISP)
597 // Use M5stack's integrated button handler
598 
609 bool gslc_DrvInitTouch(gslc_tsGui* pGui,const char* acDev);
610 
611 
624 bool gslc_DrvGetTouch(gslc_tsGui* pGui,int16_t* pnX,int16_t* pnY,uint16_t* pnPress,gslc_teInputRawEvent* peInputEvent,int16_t* pnInputVal);
625 
626 #endif // DRV_TOUCH_IN_DISP
627 
628 
629 // -----------------------------------------------------------------------
630 // Dynamic Screen rotation and Touch axes swap/flip functions
631 // -----------------------------------------------------------------------
632 
641 bool gslc_DrvRotate(gslc_tsGui* pGui, uint8_t nRotation);
642 
643 
644 // =======================================================================
645 // Private Functions
646 // - These functions are not included in the scope of APIs used by
647 // the core GUIslice library. Instead, these functions are used
648 // to support the operations within this driver layer.
649 // =======================================================================
650 
652 
653 #ifdef __cplusplus
654 }
655 #endif // __cplusplus
656 #endif // _GUISLICE_DRV_M5STACK_H_
const char GSLC_PMEM ERRSTR_PXD_NULL[]
Definition: GUIslice.c:92
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_DrvDrawPoints(gslc_tsGui *pGui, gslc_tsPt *asPt, uint16_t nNumPt, gslc_tsColor nCol)
Draw a point.
Definition: GUIslice_drv_adagfx.cpp:1541
bool gslc_DrvInitTs(gslc_tsGui *pGui, const char *acDev)
Perform any touchscreen-specific initialization.
gslc_teFontRefType
Font Reference types.
Definition: GUIslice.h:383
const char GSLC_PMEM ERRSTR_NULL[]
Definition: GUIslice.c:91
void * gslc_DrvGetDriverTouch(gslc_tsGui *pGui)
Get the native touch driver instance.
Definition: GUIslice_drv_adagfx.cpp:2146
void gslc_DrvDestruct(gslc_tsGui *pGui)
Free up any members associated with the driver.
Definition: GUIslice_drv_adagfx.cpp:787
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_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 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_DrvSetElemImageGlow(gslc_tsGui *pGui, gslc_tsElem *pElem, gslc_tsImgRef sImgRef)
Set an element&#39;s glow-state image.
Definition: GUIslice_drv_adagfx.cpp:872
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
const char * gslc_DrvGetNameTouch(gslc_tsGui *pGui)
Get the touch driver name.
Definition: GUIslice_drv_adagfx.cpp:798
uint16_t gslc_DrvAdaptColorToRaw(gslc_tsColor nCol)
Definition: GUIslice_drv_adagfx.cpp:3314
void * gslc_DrvGetDriverDisp(gslc_tsGui *pGui)
Get the native display driver instance.
Definition: GUIslice_drv_adagfx.cpp:781
Image reference structure.
Definition: GUIslice.h:569
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
gslc_teTxtFlags
Text reference flags: Describes the characteristics of a text string (ie.
Definition: GUIslice.h:463
void gslc_DrvDrawBkgnd(gslc_tsGui *pGui)
Copy the background image to destination screen.
Definition: GUIslice_drv_adagfx.cpp:2099
const char * gslc_DrvGetNameDisp(gslc_tsGui *pGui)
Get the display driver name.
Definition: GUIslice_drv_adagfx.cpp:792
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_DrvInitTouch(gslc_tsGui *pGui, const char *acDev)
Perform any touchscreen-specific initialization.
Definition: GUIslice_drv_adagfx.cpp:2135
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
bool gslc_DrvSetClipRect(gslc_tsGui *pGui, gslc_tsRect *pRect)
Set the clipping rectangle for future drawing updates.
Definition: GUIslice_drv_adagfx.cpp:887
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_DrvDrawTxtAlign(gslc_tsGui *pGui, int16_t nX0, int16_t nY0, int16_t nX1, int16_t nY1, int8_t eTxtAlign, gslc_tsFont *pFont, const char *pStr, gslc_teTxtFlags eTxtFlags, gslc_tsColor colTxt, gslc_tsColor colBg)
Draw a text string in a bounding box using the specified alignment.
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
Rectangular region. Defines X,Y corner coordinates plus dimensions.
Definition: GUIslice.h:519
Definition: GUIslice_drv_adagfx.h:199
gslc_teInputRawEvent
Raw input event types: touch, key, GPIOs.
Definition: GUIslice.h:260
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_DrvRotate(gslc_tsGui *pGui, uint8_t nRotation)
Change rotation, automatically adapt touchscreen axes swap/flip.
Definition: GUIslice_drv_adagfx.cpp:3059
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_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
bool gslc_DrvDrawFrameRect(gslc_tsGui *pGui, gslc_tsRect rRect, gslc_tsColor nCol)
Draw a framed rectangle.
Definition: GUIslice_drv_adagfx.cpp:1591
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_DrvDrawPoint(gslc_tsGui *pGui, int16_t nX, int16_t nY, gslc_tsColor nCol)
Draw a point.
Definition: GUIslice_drv_adagfx.cpp:1527
void gslc_DrvImageDestruct(void *pvImg)
Release an image surface.
Definition: GUIslice_drv_adagfx.cpp:882
void gslc_DrvPageFlipNow(gslc_tsGui *pGui)
Force a page flip to occur.
Definition: GUIslice_drv_adagfx.cpp:1483
#define GSLC_PMEM
Definition: GUIslice.h:61
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
Define point coordinates.
Definition: GUIslice.h:528
GUI structure.
Definition: GUIslice.h:716
Element Struct.
Definition: GUIslice.h:593
Color structure. Defines RGB triplet.
Definition: GUIslice.h:534
Font reference structure.
Definition: GUIslice.h:559
bool gslc_DrvDrawFillRect(gslc_tsGui *pGui, gslc_tsRect rRect, gslc_tsColor nCol)
Draw a filled rectangle.
Definition: GUIslice_drv_adagfx.cpp:1550
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
void gslc_DrvFontsDestruct(gslc_tsGui *pGui)
Release all fonts defined in the GUI.
Definition: GUIslice_drv_adagfx.cpp:922
bool gslc_DrvSetBkgndImage(gslc_tsGui *pGui, gslc_tsImgRef sImgRef)
Configure the background to use a bitmap image.
Definition: GUIslice_drv_adagfx.cpp:833
bool gslc_DrvInit(gslc_tsGui *pGui)
Initialize the SDL library.
Definition: GUIslice_drv_adagfx.cpp:571