Skip to content

Commit

Permalink
Merge pull request ImpulseAdventure#407 from ImpulseAdventure/WIP401-…
Browse files Browse the repository at this point in the history
…unloadFont

Optimise TFT_eSPI unloadFont
  • Loading branch information
ImpulseAdventure authored Aug 6, 2021
2 parents 42422bd + b90928c commit 3edec6a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/GUIslice_drv_tft_espi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ bool gslc_DrvInit(gslc_tsGui* pGui)

pDriver->nColBkgnd = GSLC_COL_BLACK;

pDriver->pvFontLast = NULL;

// These displays can accept partial redraw as they retain the last
// image in the controller graphics RAM
pGui->bRedrawPartialEn = true;
Expand Down Expand Up @@ -405,6 +407,7 @@ bool gslc_DrvGetTxtSize(gslc_tsGui* pGui,gslc_tsFont* pFont,const char* pStr,gsl
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=GSLC_COL_BLACK)
{
gslc_tsDriver* pDriver = (gslc_tsDriver*)(pGui->pvDriver);
uint16_t nColRaw = gslc_DrvAdaptColorToRaw(colTxt);
uint16_t nColBgRaw = gslc_DrvAdaptColorToRaw(colBg);
uint16_t nTxtScale = pFont->nSize;
Expand All @@ -421,7 +424,10 @@ bool gslc_DrvDrawTxtAlign(gslc_tsGui* pGui,int16_t nX0,int16_t nY0,int16_t nX1,i
} else {
#ifdef SMOOTH_FONT
if (pFont->eFontRefType == GSLC_FONTREF_FNAME){
m_disp.loadFont((const char*)pFont->pvFont);
if (pFont->pvFont != pDriver->pvFontLast) {
m_disp.loadFont((const char*)pFont->pvFont);
pDriver->pvFontLast = pFont->pvFont;
}
} else {
m_disp.setFreeFont((const GFXfont *)pFont->pvFont);
}
Expand Down Expand Up @@ -453,12 +459,6 @@ bool gslc_DrvDrawTxtAlign(gslc_tsGui* pGui,int16_t nX0,int16_t nY0,int16_t nX1,i

m_disp.drawString(pStr,nTxtX,nTxtY);

#ifdef SMOOTH_FONT
if (pFont->eFontRefType == GSLC_FONTREF_FNAME){
m_disp.unloadFont();
}
#endif

// For now, always return true
return true;
}
Expand All @@ -478,12 +478,16 @@ bool gslc_DrvDrawTxtAlign(gslc_tsGui* pGui,int16_t nX0,int16_t nY0,int16_t nX1,i
// should be used instead.
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)
{
gslc_tsDriver* pDriver = (gslc_tsDriver*)(pGui->pvDriver);
uint16_t nTxtScale = pFont->nSize;
uint16_t nColRaw = gslc_DrvAdaptColorToRaw(colTxt);
uint16_t nColBgRaw = gslc_DrvAdaptColorToRaw(colBg);
#ifdef SMOOTH_FONT
if (pFont->eFontRefType == GSLC_FONTREF_FNAME){
m_disp.loadFont((const char*)pFont->pvFont);
if (pFont->pvFont != pDriver->pvFontLast) {
m_disp.loadFont((const char*)pFont->pvFont);
pDriver->pvFontLast = pFont->pvFont;
}
m_disp.setTextColor(nColRaw,nColBgRaw);
} else {
m_disp.setTextColor(nColRaw);
Expand Down Expand Up @@ -511,11 +515,6 @@ bool gslc_DrvDrawTxt(gslc_tsGui* pGui,int16_t nTxtX,int16_t nTxtY,gslc_tsFont* p
}
m_disp.println();
}
#ifdef SMOOTH_FONT
if (pFont->eFontRefType == GSLC_FONTREF_FNAME){
m_disp.unloadFont();
}
#endif

return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/GUIslice_drv_tft_espi.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ typedef struct {

gslc_tsRect rClipRect; ///< Clipping rectangle

const void* pvFontLast; ///< Last loadFont() reference

} gslc_tsDriver;


Expand Down

0 comments on commit 3edec6a

Please sign in to comment.