From b010b3bd09fa6aff16fe57f06d0a9e6fc1494e67 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Fri, 10 May 2013 16:34:15 +0200 Subject: [PATCH] CVolumeBar: rework size handling Signed-off-by: Michael Liebmann --- src/gui/volumebar.cpp | 84 ++++++++++++++++++++----------------------- src/gui/volumebar.h | 19 +++++++--- 2 files changed, 54 insertions(+), 49 deletions(-) diff --git a/src/gui/volumebar.cpp b/src/gui/volumebar.cpp index e91acd6a4..7c39c9588 100644 --- a/src/gui/volumebar.cpp +++ b/src/gui/volumebar.cpp @@ -30,14 +30,11 @@ #include "gui/volumebar.h" -#include #include #include using namespace std; -//default vol_height -#define VOL_HEIGHT 36 CVolumeBar::CVolumeBar() { @@ -50,7 +47,8 @@ void CVolumeBar::initVarVolumeBar() initVarForm(); col_body = COL_MENUCONTENT_PLUS_0; - //init variables this + vb_item_offset = 4; + height = 4*vb_item_offset; //default height //assume volume value as pointer to global setting vb_vol = &g_settings.current_volume; @@ -65,12 +63,10 @@ void CVolumeBar::initVarVolumeBar() vb_pbw = 0; vb_pbh = 0; vb_pby = 0; - // progressbar whith - pb_w = 200; //digit vb_digit = NULL; - vb_digit_mode = CTextBox::CENTER; + vb_digit_mode = CTextBox::CENTER ; VolumeFont = SNeutrinoSettings::FONT_TYPE_INFOBAR_INFO; vb_font = g_Font[VolumeFont]; @@ -82,34 +78,29 @@ void CVolumeBar::initVarVolumeBar() //calculates size referred for possible activated clock or/and mute icon void CVolumeBar::initVolumeBarSize() { - // digit whith - if (g_settings.volume_digits) - digit_w = g_Font[VolumeFont]->getRenderWidth("100 "); - else - digit_w = 0; - int dummy = 0; - frameBuffer->getIconSize(NEUTRINO_ICON_VOLUME, &icon_w, &dummy); - icon_w += 12; - - //adapt x-pos - icon_x = corner_rad + 2; - pb_x = icon_x + icon_w + 4; - digit_x = pb_x + pb_w + 5; - - //width - if (g_settings.volume_digits) - width = digit_x + digit_w + corner_rad; - else - width = pb_x + pb_w + corner_rad + 12; - CVolumeHelper *cvh = CVolumeHelper::getInstance(); cvh->getSpacer(&h_spacer, &v_spacer); - cvh->getDimensions(&x, &y, &sw, &sh); + cvh->getDimensions(&x, &y, &sw, &sh, &vb_icon_w, &vb_digit_w); cvh->getVolBarDimensions(&y, &height); + vb_digit_w += cornerRad()/2; + + //scale + vb_pbw = 200; + vb_pbh = height-4*vb_item_offset; + + //adapt x-pos + vb_icon_x = vb_item_offset; + vb_pbx = vb_icon_x + vb_icon_w + vb_item_offset; + vb_digit_x = vb_pbx + vb_pbw + vb_item_offset; + + //result for width + width = (vb_icon_w + vb_pbw + vb_digit_w) + 4*vb_item_offset; + // mute icon cvh->getMuteIconDimensions(&mute_ax, &mute_ay, &mute_dx, &mute_dy); // info clock + int dummy; cvh->getInfoClockDimensions(&dummy, &clock_y, &clock_width, &clock_height, &dummy, &dummy); int mute_corrY = 0; if (mute_dy < height) @@ -136,7 +127,7 @@ void CVolumeBar::initVolumeBarPosition() if ((neutrino->isMuted()) && (!g_settings.mode_clock)) x_corr = mute_dx + h_spacer; if (g_settings.mode_clock) - y += max(clock_y + clock_height, mute_ay + mute_dy) /*+ v_spacer / 2*/; + y += max(clock_y + clock_height, mute_ay + mute_dy); } x = sw - width - x_corr; break; @@ -151,10 +142,10 @@ void CVolumeBar::initVolumeBarPosition() y = (sh + frameBuffer->getScreenY()) - height - v_spacer; break; case 4:// upper center - x = ((sw - width) / 2) + x; + x = ((sw - width) / 2) + x - h_spacer/2; break; case 5:// bottom center - x = ((sw - width) / 2) + x; + x = ((sw - width) / 2) + x - h_spacer/2; y = (sh + frameBuffer->getScreenY()) - height - v_spacer; break; } @@ -176,11 +167,11 @@ void CVolumeBar::initVolumeBarItems() //init current icon object void CVolumeBar::initVolumeBarIcon() { - vb_icon = new CComponentsPicture(icon_x, 0, icon_w, height, NEUTRINO_ICON_VOLUME); + vb_icon = new CComponentsPicture(vb_icon_x, 0, vb_icon_w, height, NEUTRINO_ICON_VOLUME); vb_icon->setPictureAlign(CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER); vb_icon->setColorBody(col_body); - vb_icon->setCornerRadius(corner_rad); + vb_icon->setCornerRadius(cornerRad()); vb_icon->setCornerType(CORNER_LEFT); //add icon to container @@ -192,9 +183,6 @@ void CVolumeBar::initVolumeBarScale() { vb_pb = new CProgressBar(); - vb_pbx = pb_x; - vb_pbw = pb_w; - vb_pb->setInvert(); vb_pb->setBlink(); vb_pb->setRgb(85, 75, 100); @@ -216,8 +204,10 @@ void CVolumeBar::initVolumeBarDigit() { vb_digit = new CComponentsLabel(); - vb_digit->setDimensionsAll(digit_x, 0, digit_w, height); + vb_digit->setDimensionsAll(vb_digit_x, 0, vb_digit_w, height); vb_digit->setTextColor(COL_MENUCONTENT); + vb_digit->setCornerRadius(cornerRad()); + vb_digit->setCornerType(CORNER_RIGHT); initVolumeBarDigitValue(); //add digit label to container @@ -241,13 +231,13 @@ void CVolumeBar::paintVolumeBarDigit() int dy = vb_digit->getRealYPos(); // set real x&y pos - vb_digit->setDimensionsAll(dx, dy, digit_w, height); + vb_digit->setDimensionsAll(dx, dy, vb_digit_w, height); // paint digit vb_digit->paint(CC_SAVE_SCREEN_NO); // restore original x&y pos - vb_digit->setDimensionsAll(_dx, _dy, digit_w, height); + vb_digit->setDimensionsAll(_dx, _dy, vb_digit_w, height); } @@ -298,7 +288,7 @@ void CVolumeHelper::Init() sw = g_settings.screen_EndX - h_spacer; sh = frameBuffer->getScreenHeight(); - initVolBarHeight(); + initVolBarSize(); initMuteIcon(); initInfoClock(); } @@ -337,17 +327,21 @@ void CVolumeHelper::initMuteIcon() mute_ay = y; } -void CVolumeHelper::initVolBarHeight() +void CVolumeHelper::initVolBarSize() { - vol_height = VOL_HEIGHT; + vol_height = 18; + icon_width = 0; + digit_width = 0; int tmp_h = 0; - int dummy = 0; - frameBuffer->getIconSize(NEUTRINO_ICON_VOLUME, &dummy, &tmp_h); - tmp_h += 4; + frameBuffer->getIconSize(NEUTRINO_ICON_VOLUME, &icon_width, &tmp_h); + tmp_h += 2; + icon_width += 8; vol_height = max(vol_height, tmp_h); + if (g_settings.volume_digits) { tmp_h = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_INFO]->getDigitHeight() + (g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_INFO]->getDigitOffset() * 18) / 10; vol_height = max(vol_height, tmp_h); + digit_width = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_INFO]->getRenderWidth("100"); } } diff --git a/src/gui/volumebar.h b/src/gui/volumebar.h index 280ba7716..ce1903ae6 100644 --- a/src/gui/volumebar.h +++ b/src/gui/volumebar.h @@ -27,6 +27,8 @@ #ifndef __VOLUMEBAR_H__ #define __VOLUMEBAR_H__ +#include +#include #include //CComponentsForm #include //CProgressBar #include //CComponentsLabel @@ -43,6 +45,7 @@ class CVolumeBar : public CComponentsForm int sy, sw, sh; int mute_ax, mute_ay, mute_dx, mute_dy, mute_ay_old; int h_spacer, v_spacer; + int vb_item_offset; //clock int clock_y, clock_width, clock_height; @@ -52,8 +55,12 @@ class CVolumeBar : public CComponentsForm //scale dimensions int vb_pbx, vb_pby, vb_pbw, vb_pbh; - int icon_x, pb_x, digit_x; - int icon_w, pb_w, digit_w; + + //icon dimensions + int vb_icon_x, vb_icon_w/*, vb_icon_h*/; + + //digit dimensions + int vb_digit_x, vb_digit_w/*, vb_digit_h*/; void initVarVolumeBar(); void initVolumeBarPosition(); @@ -68,6 +75,9 @@ class CVolumeBar : public CComponentsForm void paintVolScale(); void paintVolumeBarDigit(); +// inline int cornerRad() { return (g_settings.rounded_corners) ? height/2 : 0; } + inline int cornerRad() { return (g_settings.rounded_corners) ? CORNER_RADIUS_SMALL : 0; } + public: CVolumeBar(/*int current_volume*/); @@ -84,12 +94,13 @@ class CVolumeHelper int x, y, sw, sh; int mute_ax, mute_ay, mute_dx, mute_dy, mute_corrY; int clock_ax, clock_ay, clock_dx, clock_dy, digit_h, digit_offset; + int icon_width, digit_width; int h_spacer, v_spacer; int vol_ay, vol_height; CFrameBuffer *frameBuffer; void Init(); - void initVolBarHeight(); + void initVolBarSize(); void initMuteIcon(); void initInfoClock(); @@ -99,7 +110,7 @@ class CVolumeHelper static CVolumeHelper* getInstance(); void getSpacer(int *h, int *v) { *h = h_spacer; *v = v_spacer; } - void getDimensions(int *_x, int *_y, int *_sw, int *_sh) { *_x = x; *_y = y; *_sw = sw; *_sh = sh; } + void getDimensions(int *_x, int *_y, int *_sw, int *_sh, int *_iw, int *_dw) { *_x = x; *_y = y; *_sw = sw; *_sh = sh; *_iw = icon_width; *_dw = digit_width; } void getMuteIconDimensions(int *_x, int *_y, int *w, int *h) { *_x = mute_ax; *_y = mute_ay+mute_corrY; *w = mute_dx; *h = mute_dy; } void getInfoClockDimensions(int *_x, int *_y, int *w, int *h, int *d_h, int *d_o) { *_x = clock_ax; *_y = clock_ay; *w = clock_dx; *h = clock_dy, *d_h = digit_h, *d_o = digit_offset; } void getVolBarDimensions(int *_y, int *_dy) { *_y = vol_ay; *_dy = vol_height; }