CVolumeBar: rework size handling

Signed-off-by: Michael Liebmann <tuxcode.bbg@gmail.com>
This commit is contained in:
2013-05-10 16:34:15 +02:00
parent fb812f38e8
commit b010b3bd09
2 changed files with 54 additions and 49 deletions

View File

@@ -30,14 +30,11 @@
#include "gui/volumebar.h" #include "gui/volumebar.h"
#include <global.h>
#include <neutrino.h> #include <neutrino.h>
#include <gui/infoclock.h> #include <gui/infoclock.h>
using namespace std; using namespace std;
//default vol_height
#define VOL_HEIGHT 36
CVolumeBar::CVolumeBar() CVolumeBar::CVolumeBar()
{ {
@@ -50,7 +47,8 @@ void CVolumeBar::initVarVolumeBar()
initVarForm(); initVarForm();
col_body = COL_MENUCONTENT_PLUS_0; 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 //assume volume value as pointer to global setting
vb_vol = &g_settings.current_volume; vb_vol = &g_settings.current_volume;
@@ -65,8 +63,6 @@ void CVolumeBar::initVarVolumeBar()
vb_pbw = 0; vb_pbw = 0;
vb_pbh = 0; vb_pbh = 0;
vb_pby = 0; vb_pby = 0;
// progressbar whith
pb_w = 200;
//digit //digit
vb_digit = NULL; vb_digit = NULL;
@@ -82,34 +78,29 @@ void CVolumeBar::initVarVolumeBar()
//calculates size referred for possible activated clock or/and mute icon //calculates size referred for possible activated clock or/and mute icon
void CVolumeBar::initVolumeBarSize() 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(); CVolumeHelper *cvh = CVolumeHelper::getInstance();
cvh->getSpacer(&h_spacer, &v_spacer); 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); 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 // mute icon
cvh->getMuteIconDimensions(&mute_ax, &mute_ay, &mute_dx, &mute_dy); cvh->getMuteIconDimensions(&mute_ax, &mute_ay, &mute_dx, &mute_dy);
// info clock // info clock
int dummy;
cvh->getInfoClockDimensions(&dummy, &clock_y, &clock_width, &clock_height, &dummy, &dummy); cvh->getInfoClockDimensions(&dummy, &clock_y, &clock_width, &clock_height, &dummy, &dummy);
int mute_corrY = 0; int mute_corrY = 0;
if (mute_dy < height) if (mute_dy < height)
@@ -136,7 +127,7 @@ void CVolumeBar::initVolumeBarPosition()
if ((neutrino->isMuted()) && (!g_settings.mode_clock)) if ((neutrino->isMuted()) && (!g_settings.mode_clock))
x_corr = mute_dx + h_spacer; x_corr = mute_dx + h_spacer;
if (g_settings.mode_clock) 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; x = sw - width - x_corr;
break; break;
@@ -151,10 +142,10 @@ void CVolumeBar::initVolumeBarPosition()
y = (sh + frameBuffer->getScreenY()) - height - v_spacer; y = (sh + frameBuffer->getScreenY()) - height - v_spacer;
break; break;
case 4:// upper center case 4:// upper center
x = ((sw - width) / 2) + x; x = ((sw - width) / 2) + x - h_spacer/2;
break; break;
case 5:// bottom center case 5:// bottom center
x = ((sw - width) / 2) + x; x = ((sw - width) / 2) + x - h_spacer/2;
y = (sh + frameBuffer->getScreenY()) - height - v_spacer; y = (sh + frameBuffer->getScreenY()) - height - v_spacer;
break; break;
} }
@@ -176,11 +167,11 @@ void CVolumeBar::initVolumeBarItems()
//init current icon object //init current icon object
void CVolumeBar::initVolumeBarIcon() 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->setPictureAlign(CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER);
vb_icon->setColorBody(col_body); vb_icon->setColorBody(col_body);
vb_icon->setCornerRadius(corner_rad); vb_icon->setCornerRadius(cornerRad());
vb_icon->setCornerType(CORNER_LEFT); vb_icon->setCornerType(CORNER_LEFT);
//add icon to container //add icon to container
@@ -192,9 +183,6 @@ void CVolumeBar::initVolumeBarScale()
{ {
vb_pb = new CProgressBar(); vb_pb = new CProgressBar();
vb_pbx = pb_x;
vb_pbw = pb_w;
vb_pb->setInvert(); vb_pb->setInvert();
vb_pb->setBlink(); vb_pb->setBlink();
vb_pb->setRgb(85, 75, 100); vb_pb->setRgb(85, 75, 100);
@@ -216,8 +204,10 @@ void CVolumeBar::initVolumeBarDigit()
{ {
vb_digit = new CComponentsLabel(); 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->setTextColor(COL_MENUCONTENT);
vb_digit->setCornerRadius(cornerRad());
vb_digit->setCornerType(CORNER_RIGHT);
initVolumeBarDigitValue(); initVolumeBarDigitValue();
//add digit label to container //add digit label to container
@@ -241,13 +231,13 @@ void CVolumeBar::paintVolumeBarDigit()
int dy = vb_digit->getRealYPos(); int dy = vb_digit->getRealYPos();
// set real x&y pos // set real x&y pos
vb_digit->setDimensionsAll(dx, dy, digit_w, height); vb_digit->setDimensionsAll(dx, dy, vb_digit_w, height);
// paint digit // paint digit
vb_digit->paint(CC_SAVE_SCREEN_NO); vb_digit->paint(CC_SAVE_SCREEN_NO);
// restore original x&y pos // 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; sw = g_settings.screen_EndX - h_spacer;
sh = frameBuffer->getScreenHeight(); sh = frameBuffer->getScreenHeight();
initVolBarHeight(); initVolBarSize();
initMuteIcon(); initMuteIcon();
initInfoClock(); initInfoClock();
} }
@@ -337,17 +327,21 @@ void CVolumeHelper::initMuteIcon()
mute_ay = y; 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 tmp_h = 0;
int dummy = 0; frameBuffer->getIconSize(NEUTRINO_ICON_VOLUME, &icon_width, &tmp_h);
frameBuffer->getIconSize(NEUTRINO_ICON_VOLUME, &dummy, &tmp_h); tmp_h += 2;
tmp_h += 4; icon_width += 8;
vol_height = max(vol_height, tmp_h); vol_height = max(vol_height, tmp_h);
if (g_settings.volume_digits) { 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; 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); vol_height = max(vol_height, tmp_h);
digit_width = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_INFO]->getRenderWidth("100");
} }
} }

View File

@@ -27,6 +27,8 @@
#ifndef __VOLUMEBAR_H__ #ifndef __VOLUMEBAR_H__
#define __VOLUMEBAR_H__ #define __VOLUMEBAR_H__
#include <global.h>
#include <system/settings.h>
#include <gui/components/cc_frm.h> //CComponentsForm #include <gui/components/cc_frm.h> //CComponentsForm
#include <gui/components/cc_item_progressbar.h> //CProgressBar #include <gui/components/cc_item_progressbar.h> //CProgressBar
#include <gui/components/cc_item_text.h> //CComponentsLabel #include <gui/components/cc_item_text.h> //CComponentsLabel
@@ -43,6 +45,7 @@ class CVolumeBar : public CComponentsForm
int sy, sw, sh; int sy, sw, sh;
int mute_ax, mute_ay, mute_dx, mute_dy, mute_ay_old; int mute_ax, mute_ay, mute_dx, mute_dy, mute_ay_old;
int h_spacer, v_spacer; int h_spacer, v_spacer;
int vb_item_offset;
//clock //clock
int clock_y, clock_width, clock_height; int clock_y, clock_width, clock_height;
@@ -52,8 +55,12 @@ class CVolumeBar : public CComponentsForm
//scale dimensions //scale dimensions
int vb_pbx, vb_pby, vb_pbw, vb_pbh; 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 initVarVolumeBar();
void initVolumeBarPosition(); void initVolumeBarPosition();
@@ -68,6 +75,9 @@ class CVolumeBar : public CComponentsForm
void paintVolScale(); void paintVolScale();
void paintVolumeBarDigit(); 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: public:
CVolumeBar(/*int current_volume*/); CVolumeBar(/*int current_volume*/);
@@ -84,12 +94,13 @@ class CVolumeHelper
int x, y, sw, sh; int x, y, sw, sh;
int mute_ax, mute_ay, mute_dx, mute_dy, mute_corrY; 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 clock_ax, clock_ay, clock_dx, clock_dy, digit_h, digit_offset;
int icon_width, digit_width;
int h_spacer, v_spacer; int h_spacer, v_spacer;
int vol_ay, vol_height; int vol_ay, vol_height;
CFrameBuffer *frameBuffer; CFrameBuffer *frameBuffer;
void Init(); void Init();
void initVolBarHeight(); void initVolBarSize();
void initMuteIcon(); void initMuteIcon();
void initInfoClock(); void initInfoClock();
@@ -99,7 +110,7 @@ class CVolumeHelper
static CVolumeHelper* getInstance(); static CVolumeHelper* getInstance();
void getSpacer(int *h, int *v) { *h = h_spacer; *v = v_spacer; } 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 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 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; } void getVolBarDimensions(int *_y, int *_dy) { *_y = vol_ay; *_dy = vol_height; }