CComponentsHeader/CComponentsFooter: prevent crash on changed font settings

Default fonts for header and footer must be handled too.
After font settings changes these objects could be invalid.
Default fonts have invalid pointers after font changes too. Extra reset is required.
This commit is contained in:
2016-12-29 23:42:35 +01:00
parent 6a3b07152f
commit b98319cb91
4 changed files with 26 additions and 4 deletions

View File

@@ -68,6 +68,12 @@ void CComponentsFooter::initVarFooter( const int& x_pos, const int& y_pos, const
//init footer width //init footer width
width = w == 0 ? frameBuffer->getScreenWidth(true) : w; width = w == 0 ? frameBuffer->getScreenWidth(true) : w;
//init default fonts
initDefaultFonts();
//init default button text font
ccf_btn_font = g_Font[SNeutrinoSettings::FONT_TYPE_BUTTON_TEXT];
//init footer height //init footer height
initCaptionFont(); initCaptionFont();
height = max(h, cch_font->getHeight()); height = max(h, cch_font->getHeight());
@@ -88,7 +94,6 @@ void CComponentsFooter::initVarFooter( const int& x_pos, const int& y_pos, const
corner_type = CORNER_BOTTOM; corner_type = CORNER_BOTTOM;
ccf_enable_button_bg = false /*g_settings.theme.Button_gradient*/; //TODO: not implemented at the moment ccf_enable_button_bg = false /*g_settings.theme.Button_gradient*/; //TODO: not implemented at the moment
ccf_btn_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_FOOT];
chain = NULL; chain = NULL;
addContextButton(buttons); addContextButton(buttons);
@@ -426,3 +431,9 @@ void CComponentsFooter::enableButtonShadow(int mode, const int& shadow_width, bo
} }
} }
} }
void CComponentsFooter::initDefaultFonts()
{
l_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE];
s_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_FOOT];
}

View File

@@ -84,6 +84,9 @@ class CComponentsFooter : public CComponentsHeader
///property: set font for label caption, see also setButtonFont() ///property: set font for label caption, see also setButtonFont()
Font* ccf_btn_font; Font* ccf_btn_font;
///init default fonts for size modes
virtual void initDefaultFonts();
///container for button objects ///container for button objects
CComponentsFrmChain *chain; CComponentsFrmChain *chain;

View File

@@ -96,8 +96,7 @@ void CComponentsHeader::initVarHeader( const int& x_pos, const int& y_pos, const
height = height_old = h; height = height_old = h;
cch_font = NULL; cch_font = NULL;
l_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]; initDefaultFonts();
s_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU];
cch_size_mode = CC_HEADER_SIZE_LARGE; cch_size_mode = CC_HEADER_SIZE_LARGE;
CNeutrinoApp::getInstance()->OnAfterSetupFonts.connect(sigc::mem_fun(this, &CComponentsHeader::resetFont)); CNeutrinoApp::getInstance()->OnAfterSetupFonts.connect(sigc::mem_fun(this, &CComponentsHeader::resetFont));
@@ -167,9 +166,16 @@ void CComponentsHeader::setCaptionFont(Font* font)
void CComponentsHeader::resetFont() void CComponentsHeader::resetFont()
{ {
if (cch_font){ if (cch_font){
cch_font = NULL;
dprintf(DEBUG_DEBUG, "\033[33m[CComponentsHeader][%s - %d] reset header font \033[0m\n", __func__, __LINE__); dprintf(DEBUG_DEBUG, "\033[33m[CComponentsHeader][%s - %d] reset header font \033[0m\n", __func__, __LINE__);
cch_font = NULL;
} }
initDefaultFonts();
}
void CComponentsHeader::initDefaultFonts()
{
l_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE];
s_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU];
} }
void CComponentsHeader::initCaptionFont() void CComponentsHeader::initCaptionFont()

View File

@@ -102,6 +102,8 @@ class CComponentsHeader : public CComponentsForm, public CCTextScreen
///init font object and recalculates height if required ///init font object and recalculates height if required
void initCaptionFont(); void initCaptionFont();
///init default fonts for size modes
virtual void initDefaultFonts();
///sub: init icon object ///sub: init icon object
void initIcon(); void initIcon();
///sub: init caption object ///sub: init caption object