CComponents: add progressbar class to cc-items

CProgressbar moved into components sub directory and adapt includes.
Progressbar objects are now usable as cc-item

TODO:
-some color and size corrections
-found some dub codes for sig and snr-bars, needs rework


Origin commit data
------------------
Commit: 860be9a412
Author: Thilo Graf <dbt@novatux.de>
Date: 2013-04-01 (Mon, 01 Apr 2013)
This commit is contained in:
2013-04-01 22:01:55 +02:00
parent 17d13ef103
commit 03b22f2d23
28 changed files with 616 additions and 590 deletions

View File

@@ -33,7 +33,6 @@ libneutrino_gui_widget_a_SOURCES = \
messagebox.cpp \
mountchooser.cpp \
msgbox.cpp \
progressbar.cpp \
stringinput.cpp \
stringinput_ext.cpp \
textbox.cpp

View File

@@ -1,323 +0,0 @@
/*
* (C) 2008 by dbt <info@dbox2-tuning.de>
* (C) 2009-2010, 2012-2013 Stefan Seyfried
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <global.h>
#include <neutrino.h>
#include "icons.h"
#include "progressbar.h"
#define ITEMW 4
#define POINT 2
#define RED 0xFF0000
#define GREEN 0x00FF00
#define YELLOW 0xFFFF00
CProgressBar::CProgressBar(const bool bl, const int w, const int h,
const int r, const int g, const int b, const bool inv)
{
frameBuffer = CFrameBuffer::getInstance();
font_pbar = SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL;
// frame width around active bar
frame_widht = 2;
blink = bl;
invert = inv;
red = r;
green = g;
yellow = b;
width = w;
height = h;
last_width = -1;
bl_changed = g_settings.progressbar_color;
}
CProgressBar::~CProgressBar()
{
}
static inline unsigned int make16color(__u32 rgb)
{
return 0xFF000000 | rgb;
}
void CProgressBar::paintProgressBar ( const int pos_x,
const int pos_y,
const int pb_width,
const int pb_height,
const int value,
const int max_value,
const fb_pixel_t activebar_col,
const fb_pixel_t passivebar_col,
const fb_pixel_t backgroundbar_col,
const fb_pixel_t shadowbar_col,
const char *upper_labeltext,
const uint8_t uppertext_col,
const char *iconfile,
bool paintZero)
{
width = pb_width;
height = pb_height;
realpaint(pos_x, pos_y, value, max_value,
activebar_col, passivebar_col, backgroundbar_col, shadowbar_col,
upper_labeltext, uppertext_col, iconfile, paintZero);
}
void CProgressBar::paintProgressBar2(const int pos_x,
const int pos_y,
const int value,
const int max_value,
const fb_pixel_t activebar_col,
const fb_pixel_t passivebar_col,
const fb_pixel_t frame_col,
const fb_pixel_t shadowbar_col,
const char * upper_labeltext,
const uint8_t uppertext_col,
const char * iconfile,
bool paintZero)
{
if (height < 0 || width < 0)
{
fprintf(stderr, "CProgressBar::paintProgressBar2 height or width not set!\n");
return;
}
realpaint(pos_x, pos_y, value, max_value,
activebar_col, passivebar_col, frame_col, shadowbar_col,
upper_labeltext, uppertext_col, iconfile, paintZero);
}
void CProgressBar::realpaint(const int pos_x, const int pos_y,
const int val, const int max_value,
const fb_pixel_t activebar_col,
const fb_pixel_t passivebar_col,
const fb_pixel_t backgroundbar_col,
const fb_pixel_t shadowbar_col,
const char *upper_labeltext,
const uint8_t uppertext_col,
const char *iconfile,
bool paintZero)
{
if(bl_changed != g_settings.progressbar_color) {
bl_changed = g_settings.progressbar_color;
reset();
}
/* stupid callers give invalid values like "-1"... */
int value = val;
if (value < 0)
value = 0;
if (value > max_value)
value = max_value;
// set colors
fb_pixel_t active_col = activebar_col != 0 ? activebar_col : COL_INFOBAR_PLUS_7;
fb_pixel_t passive_col = passivebar_col != 0 ? passivebar_col : COL_INFOBAR_PLUS_3;
/* radius is 0 for now, since the rounded corner code is sufficiently
different from tuxbox.org's so that everything else looks 'strange' */
const int c_rad = 0;
/* if the bar is too small, do not draw the borders around it */
if (height / 2 <= frame_widht || (blink && g_settings.progressbar_color) || backgroundbar_col == 0)
frame_widht = 0;
// get icon size
int icon_w = 0, icon_h = 0;
if(iconfile != NULL)
frameBuffer->getIconSize(iconfile, &icon_w, &icon_h);
// start positions x/y active bar
int start_x = icon_w != 0 ? pos_x + icon_w + 2*frame_widht : pos_x + frame_widht;
int start_y = pos_y + frame_widht;
// width active bar for current value
int active_pb_width;
if (max_value)
active_pb_width = (width - icon_w - 2 * frame_widht) * value / max_value;
else
active_pb_width = 0;
// max width active/passive bar
int pb_max_width = icon_w != 0 ? (width - 2*frame_widht) - icon_w - frame_widht : width - 2*frame_widht;
// max height progressbar bar, if icon height larger than pb_height then get height from icon
int pb_max_height = icon_h > height ? icon_h + 2* frame_widht : height;
if (!blink || !g_settings.progressbar_color)
{
// max height of active/passive bar
int bar_height = pb_max_height - 2*frame_widht;
int start_x_passive_bar = start_x + active_pb_width;
int width_passive_bar = pb_max_width - active_pb_width;
// shadow
if (shadowbar_col != 0)
frameBuffer->paintBoxRel(pos_x + SHADOW_OFFSET, pos_y + SHADOW_OFFSET,
width, pb_max_height, shadowbar_col, c_rad); // shadow
// background = frame
if (backgroundbar_col != 0) {
// we must paint background as frame, because of flicker effects at screen on fast changing values
frameBuffer->paintBoxRel(pos_x, pos_y, 10, pb_max_height, backgroundbar_col, c_rad, CORNER_LEFT);
frameBuffer->paintBoxRel(pos_x + width - 10, pos_y, 10, pb_max_height, backgroundbar_col, c_rad, CORNER_RIGHT);
frameBuffer->paintBoxRel(pos_x + 10, pos_y, width - 20, frame_widht, backgroundbar_col);
frameBuffer->paintBoxRel(pos_x + 10, pos_y + pb_max_height - frame_widht, width - 20, frame_widht, backgroundbar_col);
}
frameBuffer->paintBoxRel(start_x, start_y, active_pb_width, bar_height, active_col); // active bar
frameBuffer->paintBoxRel(start_x_passive_bar, start_y, width_passive_bar, bar_height, passive_col); // passive bar
if (paintZero && value == 0)
frameBuffer->paintLine(pos_x+2 , pos_y+2, pos_x+width-3, pos_y+height-3, active_col); // zero line
}
else
{
int itemw = ITEMW, itemh = ITEMW, pointx = POINT, pointy = POINT;
if(g_settings.progressbar_color){
switch ((pb_color_t)g_settings.progressbar_design){
default:
case PB_MATRIX: /* matrix */
break;
case PB_LINES_V: /* vert. lines */
itemh = height;
pointy = height;
break;
case PB_LINES_H: /* horiz. lines */
itemw = POINT;
break;
case PB_COLOR: /* filled color */
itemw = POINT;
itemh = height;
pointy = height;
break;
}
}
const int spc = itemh - pointy; /* space between horizontal lines / points */
int hcnt = (height + spc) / itemh; /* how many POINTs is the bar high */
int yoff = (height + spc - itemh * hcnt) / 2;
//printf("height: %d itemh: %d hcnt: %d yoff: %d spc: %d\n", height, itemh, hcnt, yoff, spc);
/* red, yellow, green are given in percent */
int rd = red * width / (100 * itemw); /* how many POINTs red */
int yw = yellow * width / (100 * itemw); /* how many POINTs yellow */
int gn = green * width / (100 * itemw); /* how many POINTs green */
int maxi = active_pb_width / itemw; /* how many POINTs is the active bar */
int total = width / itemw; /* total number of POINTs */
uint32_t rgb;
fb_pixel_t color;
if (last_width == -1 && backgroundbar_col != 0) /* first paint */
{
frameBuffer->paintBoxRel(pos_x, pos_y, width, pb_max_height, backgroundbar_col);
if (shadowbar_col != 0)
frameBuffer->paintBoxRel(pos_x + SHADOW_OFFSET, pos_y + SHADOW_OFFSET,
width, pb_max_height, shadowbar_col, c_rad); // shadow
}
if (active_pb_width != last_width) {
int i, j;
const int py = pos_y + yoff;
if (active_pb_width > last_width) {
int step, off;
int b = 0;
uint8_t diff = 0;
for (i = 0; (i < rd) && (i < maxi); i++) {
diff = i * 255 / rd;
if (invert)
rgb = GREEN + (diff << 16); // adding red
else
rgb = RED + (diff << 8); // adding green
color = make16color(rgb);
for (j = 0; j < hcnt; j++)
frameBuffer->paintBoxRel(pos_x + i * itemw, py + j * itemh,
pointx, pointy, color);
}
step = yw - rd - 1;
if (step < 1)
step = 1;
for (; (i < yw) && (i < maxi); i++) {
diff = b++ * 255 / step / 2;
if (invert)
rgb = YELLOW - (diff << 8); // removing green
else
rgb = YELLOW - (diff << 16); // removing red
color = make16color(rgb);
for (j = 0; j < hcnt; j++)
frameBuffer->paintBoxRel(pos_x + i * itemw, py + j * itemh,
pointx, pointy, color);
}
off = diff;
b = 0;
step = gn - yw - 1;
if (step < 1)
step = 1;
for (; (i < gn) && (i < maxi); i++) {
diff = b++ * 255 / step / 2 + off;
if (invert)
rgb = YELLOW - (diff << 8); // removing green
else
rgb = YELLOW - (diff << 16); // removing red
color = make16color(rgb);
for (j = 0; j < hcnt; j++)
frameBuffer->paintBoxRel(pos_x + i * itemw, py + j * itemh,
pointx, pointy, color);
}
}
for(i = maxi; i < total; i++) {
for (j = 0; j < hcnt; j++)
frameBuffer->paintBoxRel(pos_x + i * itemw, py + j * itemh,
pointx, pointy, COL_INFOBAR_PLUS_3);//fill passive
}
last_width = active_pb_width;
}
}
// paint icon if present
if (iconfile != NULL){
int icon_y = pos_y + pb_max_height / 2 - icon_h / 2;
frameBuffer->paintIcon(iconfile, pos_x + frame_widht, icon_y);
}
// upper text
int upper_labeltext_y = start_y - frame_widht;
if (upper_labeltext != NULL) {
g_Font[font_pbar]->RenderString(start_x +2,
upper_labeltext_y,
width,
upper_labeltext,
uppertext_col != 0 ? uppertext_col : COL_INFOBAR,
height,
true); // UTF8
}
}
void CProgressBar::paintProgressBarDefault( const int pos_x,
const int pos_y,
const int pb_width,
const int pb_height,
const int value,
const int max_value)
{
paintProgressBar (pos_x, pos_y, pb_width, pb_height, value, max_value, 0, 0, COL_INFOBAR_SHADOW_PLUS_1, 0, "", 0);
}

View File

@@ -1,142 +0,0 @@
/*
* (C) 2008 by dbt <info@dbox2-tuning.de>
* (C) 2009,2010,2013 Stefan Seyfried
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __gui_widget_progressbar_h__
#define __gui_widget_progressbar_h__
#include "config.h"
#include <gui/color.h>
#include <driver/framebuffer.h>
#include <driver/fontrenderer.h>
#include <system/settings.h>
#include <string>
class CProgressBar
{
private:
CFrameBuffer * frameBuffer;
int font_pbar;
int frame_widht;
int last_width;
int red, green, yellow;
bool blink, invert, bl_changed;
int width, height;
void realpaint(const int pos_x, const int pos_y,
const int value, const int max_value,
const fb_pixel_t activebar_col,
const fb_pixel_t passivebar_col,
const fb_pixel_t backgroundbar_col,
const fb_pixel_t shadowbar_col,
const char *upper_labeltext,
const uint8_t uppertext_col,
const char *iconfile,
bool paintZero);
public:
/* parameters:
blinkenligts: true if you want code to follow progressbar_color. needed, no default.
w, h: width / height of bar. Can later be set with paintProgressbar.
paintProgressBar2 can oly be used if w and h are set.
r, g, b: percentage of the bar where red/green/yellow is used.
only used if blinkenlights == true.
inv: false => red on the left side, true: red on right side. */
CProgressBar(const bool blinkenlights,
const int w = -1,
const int h = -1,
const int r = 40,
const int g = 100,
const int b =70,
const bool inv = false);
~CProgressBar();
/// void paintProgressBar(...)
/*!
description of parameters:
position of progressbar:
pos_x > start position on screen x
pos_y > start position on screen y
pb_width > with of progressbar
pb_height > height of progressbar
definitions of values:
value > value, you will display
max_value > maximal value that you will display
appearance:
activebar_col > color of inner bar that shows the current value
passivebar_col > color of passive bar
frame_col > general frame color of progressbar, set 0 for no frame
shadowbar_col color > shadow behind progressbar, set 0 for no shadow
upper_labeltext > optional, label text, will be painted upper/left the progressbar
uppertext_col > optional, but necessary with label text, color of label text
iconfile > optional, name of iconfile
paintZero > optional, if set to true and value = 0, then paints a diagonal line instead of active bar as symbolic for a zero value
*/
void paintProgressBar ( const int pos_x,
const int pos_y,
const int pb_width,
const int pb_height,
const int value,
const int max_value,
const fb_pixel_t activebar_col = 0,
const fb_pixel_t passivebar_col = 0,
const fb_pixel_t frame_col = 0,
const fb_pixel_t shadowbar_col = 0,
const char * upper_labeltext = NULL,
const uint8_t uppertext_col = 0,
const char * iconfile = NULL,
bool paintZero = false);
void paintProgressBar2 (const int pos_x,
const int pos_y,
const int value,
const int max_value = 100,
const fb_pixel_t activebar_col = 0,
const fb_pixel_t passivebar_col = 0,
const fb_pixel_t frame_col = 0,
const fb_pixel_t shadowbar_col = 0,
const char * upper_labeltext = NULL,
const uint8_t uppertext_col = 0,
const char * iconfile = NULL,
bool paintZero = false);
void paintProgressBarDefault ( const int pos_x,
const int pos_y,
const int pb_width,
const int pb_height,
const int value,
const int max_value);
void reset() { last_width = -1; } /* force update on next paint */
void hide();
enum pb_color_t {
PB_MATRIX = 0, /* 0 */
PB_LINES_V, /* 1 */
PB_LINES_H, /* 2 */
PB_COLOR /* 3 */
};
};
#endif /* __gui_widget_progressbar_h__ */