CComponentsFrmClock: Rework font handling

- Use setClockFont(enum FONT_TYPES) for selection of neutrino fonts
- Use setClockFontSize(size) for Dynamic Font


Origin commit data
------------------
Commit: 1bfb6d2cd3
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2013-11-27 (Wed, 27 Nov 2013)
This commit is contained in:
Michael Liebmann
2013-11-27 00:19:05 +01:00
parent 658f794ef5
commit e8d55630df
6 changed files with 73 additions and 29 deletions

View File

@@ -91,6 +91,7 @@ class CNeutrinoFonts
}; };
enum { enum {
FONT_ID_VOLBAR, FONT_ID_VOLBAR,
FONT_ID_INFOCLOCK,
FONT_ID_MAX FONT_ID_MAX
}; };

View File

@@ -29,6 +29,7 @@
#include <global.h> #include <global.h>
#include <neutrino.h> #include <neutrino.h>
#include <driver/neutrinofonts.h>
#include "cc_frm_clock.h" #include "cc_frm_clock.h"
#include <time.h> #include <time.h>
@@ -70,16 +71,19 @@ CComponentsFrmClock::CComponentsFrmClock( const int x_pos, const int y_pos, cons
void CComponentsFrmClock::initVarClock() void CComponentsFrmClock::initVarClock()
{ {
initVarForm(); initVarForm();
cc_item_type = CC_ITEMTYPE_FRM_CLOCK; cc_item_type = CC_ITEMTYPE_FRM_CLOCK;
corner_rad = RADIUS_SMALL; corner_rad = RADIUS_SMALL;
cl_font = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_INFO]; cl_font_type = SNeutrinoSettings::FONT_TYPE_INFOBAR_INFO;
cl_col_text = COL_MENUCONTENT_TEXT; cl_font = &g_Font[cl_font_type];
cl_format_str = "%H:%M"; dyn_font_size = 0;
cl_align = CC_ALIGN_VER_CENTER | CC_ALIGN_HOR_CENTER;
cl_thread = 0; cl_col_text = COL_MENUCONTENT_TEXT;
cl_interval = 1; cl_format_str = "%H:%M";
cl_align = CC_ALIGN_VER_CENTER | CC_ALIGN_HOR_CENTER;
cl_thread = 0;
cl_interval = 1;
} }
CComponentsFrmClock::~CComponentsFrmClock() CComponentsFrmClock::~CComponentsFrmClock()
@@ -117,8 +121,8 @@ void CComponentsFrmClock::initCCLockItems()
string s_time = cl_timestr; string s_time = cl_timestr;
//get minimal required height, width from raw text //get minimal required height, width from raw text
int min_text_w = cl_font->getRenderWidth(s_time, true);; int min_text_w = (*getClockFont())->getRenderWidth(s_time, true);;
int min_text_h = cl_font->getHeight(); int min_text_h = (*getClockFont())->getHeight();
height = max(height, min_text_h); height = max(height, min_text_h);
width = max(width, min_text_w); width = max(width, min_text_w);
@@ -169,13 +173,13 @@ void CComponentsFrmClock::initCCLockItems()
string stmp = s_time.substr(i, 1); string stmp = s_time.substr(i, 1);
//get width of current segment //get width of current segment
int wtmp = cl_font->getRenderWidth(stmp, true); int wtmp = (*getClockFont())->getRenderWidth(stmp, true);
//set size, text, color of current item //set size, text, color of current item
lbl->setDimensionsAll(cl_x, cl_y, wtmp, cl_h); lbl->setDimensionsAll(cl_x, cl_y, wtmp, cl_h);
lbl->setTextColor(cl_col_text); lbl->setTextColor(cl_col_text);
lbl->setColorAll(col_frame, col_body, col_shadow); lbl->setColorAll(col_frame, col_body, col_shadow);
lbl->setText(stmp, CTextBox::CENTER, cl_font); lbl->setText(stmp, CTextBox::CENTER, *getClockFont());
//use matching height for digits for better vertical centerring into form //use matching height for digits for better vertical centerring into form
CTextBox* ctb = lbl->getCTextBoxObject(); CTextBox* ctb = lbl->getCTextBoxObject();
@@ -333,3 +337,24 @@ void CComponentsFrmClock::paint(bool do_save_bg)
//paint form contents //paint form contents
paintForm(do_save_bg); paintForm(do_save_bg);
} }
void CComponentsFrmClock::setClockFontSize(int size)
{
int tmp_w = 0;
dyn_font_size = size;
cl_font = CNeutrinoFonts::getInstance()->getDynFont(tmp_w, dyn_font_size, "", CNeutrinoFonts::FONT_STYLE_BOLD, CNeutrinoFonts::FONT_ID_INFOCLOCK);
}
void CComponentsFrmClock::setClockFont(int font)
{
cl_font_type = font;
cl_font = &g_Font[cl_font_type];
}
Font** CComponentsFrmClock::getClockFont()
{
if (dyn_font_size == 0)
cl_font = &g_Font[cl_font_type];
return cl_font;
}

View File

@@ -62,7 +62,11 @@ class CComponentsFrmClock : public CComponentsForm
bool activeClock; bool activeClock;
///object: font render object ///object: font render object
Font *cl_font; Font **cl_font;
int cl_font_type;
int dyn_font_size;
///text color ///text color
int cl_col_text; int cl_col_text;
///time format ///time format
@@ -80,6 +84,9 @@ class CComponentsFrmClock : public CComponentsForm
///initialize of general alignment of timestring segments within form area ///initialize of general alignment of timestring segments within form area
void initSegmentAlign(int* segment_width, int* segment_height); void initSegmentAlign(int* segment_width, int* segment_height);
///return pointer of font object
inline Font** getClockFont();
public: public:
CComponentsFrmClock(); CComponentsFrmClock();
CComponentsFrmClock( const int x_pos, const int y_pos, const int w, const int h, CComponentsFrmClock( const int x_pos, const int y_pos, const int w, const int h,
@@ -87,8 +94,9 @@ class CComponentsFrmClock : public CComponentsForm
fb_pixel_t color_frame = COL_LIGHT_GRAY, fb_pixel_t color_body = COL_MENUCONTENT_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0); fb_pixel_t color_frame = COL_LIGHT_GRAY, fb_pixel_t color_body = COL_MENUCONTENT_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
virtual ~CComponentsFrmClock(); virtual ~CComponentsFrmClock();
///set font type for segments ///set font type or font size for segments
virtual void setClockFont(Font *font){cl_font = font;}; virtual void setClockFont(int font);
virtual void setClockFontSize(int size);
///set text color ///set text color
virtual void setTextColor(fb_pixel_t color_text){ cl_col_text = color_text;}; virtual void setTextColor(fb_pixel_t color_text){ cl_col_text = color_text;};

View File

@@ -58,8 +58,7 @@ void CInfoClock::initVarInfoClock()
void CInfoClock::Init() void CInfoClock::Init()
{ {
int x_old = x, y_old = y, width_old = width, height_old = height; int x_old = x, y_old = y, width_old = width, height_old = height;
cl_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]; CVolumeHelper::getInstance()->refresh(cl_font);
CVolumeHelper::getInstance()->refresh();
CVolumeHelper::getInstance()->getInfoClockDimensions(&x, &y, &width, &height); CVolumeHelper::getInstance()->getInfoClockDimensions(&x, &y, &width, &height);
if ((x_old != x) || (y_old != y) || (width_old != width) || (height_old != height)) { if ((x_old != x) || (y_old != y) || (width_old != width) || (height_old != height)) {
cleanCCForm(); cleanCCForm();

View File

@@ -269,7 +269,7 @@ CVolumeHelper::CVolumeHelper()
Init(); Init();
} }
void CVolumeHelper::Init() void CVolumeHelper::Init(Font** font)
{ {
x = frameBuffer->getScreenX() + h_spacer; x = frameBuffer->getScreenX() + h_spacer;
@@ -279,15 +279,26 @@ void CVolumeHelper::Init()
initVolBarSize(); initVolBarSize();
initMuteIcon(); initMuteIcon();
initInfoClock(); initInfoClock(font);
} }
void CVolumeHelper::initInfoClock() void CVolumeHelper::initInfoClock(Font** font)
{ {
digit_offset = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getDigitOffset(); if (clock_font == NULL){
digit_h = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getDigitHeight(); if (font == NULL) {
int t1 = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getRenderWidth(widest_number); clock_font = &g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE];
int t2 = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getRenderWidth(":"); }
else
clock_font = font;
}
else {
if (font != NULL)
clock_font = font;
}
digit_offset = (*clock_font)->getDigitOffset();
digit_h = (*clock_font)->getDigitHeight();
int t1 = (*clock_font)->getRenderWidth(widest_number);
int t2 = (*clock_font)->getRenderWidth(":");
clock_dy = digit_h + (int)((float)digit_offset * 1.3); clock_dy = digit_h + (int)((float)digit_offset * 1.3);
clock_dx = t1*7 + t2*2; clock_dx = t1*7 + t2*2;
clock_ax = sw - clock_dx; clock_ax = sw - clock_dx;
@@ -347,9 +358,9 @@ int CVolumeHelper::getInfoClockX()
return clock_ax; return clock_ax;
} }
void CVolumeHelper::refresh() void CVolumeHelper::refresh(Font** font)
{ {
Init(); Init(font);
} }
CVolumeHelper* CVolumeHelper::getInstance() CVolumeHelper* CVolumeHelper::getInstance()

View File

@@ -108,10 +108,10 @@ class CVolumeHelper
Font** clock_font; Font** clock_font;
CFrameBuffer *frameBuffer; CFrameBuffer *frameBuffer;
void Init(); void Init(Font** font=NULL);
void initVolBarSize(); void initVolBarSize();
void initMuteIcon(); void initMuteIcon();
void initInfoClock(); void initInfoClock(Font** font);
public: public:
@@ -128,7 +128,7 @@ class CVolumeHelper
void getInfoClockDimensions(int *_x, int *_y, int *w, int *h) { *_x = getInfoClockX(); *_y = clock_ay; *w = clock_dx; *h = clock_dy; } void getInfoClockDimensions(int *_x, int *_y, int *w, int *h) { *_x = getInfoClockX(); *_y = clock_ay; *w = clock_dx; *h = clock_dy; }
void getVolBarDimensions(int *_y, int *_dy) { *_y = vol_ay; *_dy = vol_height; } void getVolBarDimensions(int *_y, int *_dy) { *_y = vol_ay; *_dy = vol_height; }
void setMuteIconCorrY(int corr) { mute_corrY = corr; } void setMuteIconCorrY(int corr) { mute_corrY = corr; }
void refresh(); void refresh(Font** font=NULL);
}; };
#endif #endif