mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-31 01:11:06 +02:00
neutrino: consolidate CScale and CProgressBar code
Add code for coloured progressbars to CProgressBar class. This
allows to deprecate the CScale code completely (is not used anymore)
and, in a follow-up step, make the progress bar style runtime configurable.
TODO: documentation ;)
check if all progressbars still behave the same
git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@131 e54a6e83-5905-42d5-8d5c-058d10e6a962
Origin commit data
------------------
Commit: 697e3c6756
Author: Stefan Seyfried <seife@tuxbox-git.slipkontur.de>
Date: 2010-01-03 (Sun, 03 Jan 2010)
Origin message was:
------------------
neutrino: consolidate CScale and CProgressBar code
Add code for coloured progressbars to CProgressBar class. This
allows to deprecate the CScale code completely (is not used anymore)
and, in a follow-up step, make the progress bar style runtime configurable.
TODO: documentation ;)
check if all progressbars still behave the same
git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@131 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
@@ -26,19 +26,53 @@
|
||||
#include "icons.h"
|
||||
#include "progressbar.h"
|
||||
|
||||
#define ITEMW 4
|
||||
#define POINT 2
|
||||
|
||||
CProgressBar::CProgressBar()
|
||||
#define RED 0xFF0000
|
||||
#define GREEN 0x00FF00
|
||||
#define YELLOW 0xFFFF00
|
||||
|
||||
|
||||
CProgressBar::CProgressBar(const bool bl, 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 = height = -1;
|
||||
}
|
||||
|
||||
CProgressBar::CProgressBar(const int w, const int h,
|
||||
const bool bl, 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;
|
||||
}
|
||||
|
||||
CProgressBar::~CProgressBar()
|
||||
{
|
||||
}
|
||||
|
||||
inline unsigned int make16color(__u32 rgb)
|
||||
{
|
||||
return 0xFF000000 | rgb;
|
||||
}
|
||||
|
||||
void CProgressBar::paintProgressBar ( const int pos_x,
|
||||
const int pos_y,
|
||||
const int pb_width,
|
||||
@@ -53,6 +87,41 @@ void CProgressBar::paintProgressBar ( const int pos_x,
|
||||
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 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)
|
||||
{
|
||||
// set colors
|
||||
fb_pixel_t active_col = activebar_col != 0 ? activebar_col : COL_INFOBAR_PLUS_7;
|
||||
@@ -63,9 +132,8 @@ void CProgressBar::paintProgressBar ( const int pos_x,
|
||||
const int c_rad = 0;
|
||||
|
||||
/* if the bar is too small, do not draw the borders around it */
|
||||
if (pb_height / 2 <= frame_widht)
|
||||
if (height / 2 <= frame_widht || blink)
|
||||
frame_widht = 0;
|
||||
|
||||
// get icon size
|
||||
int icon_w = 0, icon_h = 0;
|
||||
icon_w = iconfile != NULL ? frameBuffer->getIconWidth(iconfile) : 0;
|
||||
@@ -78,33 +146,111 @@ void CProgressBar::paintProgressBar ( const int pos_x,
|
||||
// width active bar for current value
|
||||
int active_pb_width;
|
||||
if (max_value)
|
||||
active_pb_width = (pb_width - icon_w - 2 * frame_widht) * value / 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 ? (pb_width - 2*frame_widht) - icon_w - frame_widht : pb_width - 2*frame_widht;
|
||||
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 > pb_height ? icon_h + 2* frame_widht : pb_height;
|
||||
int pb_max_height = icon_h > height ? icon_h + 2* frame_widht : height;
|
||||
|
||||
// max height of active/passive bar
|
||||
int bar_height = pb_max_height - 2*frame_widht;
|
||||
if (! blink)
|
||||
{
|
||||
// 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;
|
||||
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, pb_width, pb_max_height, shadowbar_col, c_rad); // shadow
|
||||
// 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+pb_width-10,pos_y, 10, pb_max_height, backgroundbar_col, c_rad, CORNER_RIGHT);
|
||||
frameBuffer->paintBoxRel(pos_x+10,pos_y, pb_width-20, frame_widht, backgroundbar_col);
|
||||
frameBuffer->paintBoxRel(pos_x+10,pos_y+pb_max_height-frame_widht, pb_width-20, frame_widht, backgroundbar_col);
|
||||
// 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
|
||||
{
|
||||
/* 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 hcnt = height / ITEMW; /* how many POINTs is the bar high */
|
||||
int maxi = active_pb_width / ITEMW; /* how many POINTs is the active bar */
|
||||
int total = width / ITEMW; /* total number of POINTs */
|
||||
|
||||
int i, j;
|
||||
uint32_t rgb;
|
||||
fb_pixel_t color;
|
||||
int b = 0;
|
||||
|
||||
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 step;
|
||||
if (active_pb_width > last_width) {
|
||||
step = 255 / rd;
|
||||
for (i = 0; (i < rd) && (i < maxi); i++) {
|
||||
if (invert)
|
||||
rgb = GREEN + ((unsigned char)(step * i) << 16); // adding red
|
||||
else
|
||||
rgb = RED + ((unsigned char)(step * i) << 8); // adding green
|
||||
color = make16color(rgb);
|
||||
for(j = 0; j <= hcnt; j++)
|
||||
frameBuffer->paintBoxRel(pos_x + i * ITEMW, pos_y + j * ITEMW,
|
||||
POINT, POINT, color);
|
||||
}
|
||||
step = 255 / yw / 2;
|
||||
for (; (i < yw) && (i < maxi); i++) {
|
||||
if (invert)
|
||||
rgb = YELLOW - ((unsigned char)(step * (b++)) << 8); // removing green
|
||||
else
|
||||
rgb = YELLOW - ((unsigned char)(step * (b++)) << 16); // removing red
|
||||
color = make16color(rgb);
|
||||
for(j = 0; j <= hcnt; j++)
|
||||
frameBuffer->paintBoxRel(pos_x + i * ITEMW, pos_y + j * ITEMW,
|
||||
POINT, POINT, color);
|
||||
}
|
||||
step = 255 / gn;
|
||||
for (; (i < gn) && (i < maxi); i++) {
|
||||
if (invert)
|
||||
rgb = YELLOW - ((unsigned char) (step * (b++)) << 8); // removing green
|
||||
else
|
||||
rgb = YELLOW - ((unsigned char) (step * (b++)) << 16); // removing red
|
||||
color = make16color(rgb);
|
||||
for(j = 0; j <= hcnt; j++)
|
||||
frameBuffer->paintBoxRel(pos_x + i * ITEMW, pos_y + j * ITEMW,
|
||||
POINT, POINT, color);
|
||||
}
|
||||
}
|
||||
for(i = maxi; i < total; i++) {
|
||||
for(j = 0; j <= hcnt; j++)
|
||||
frameBuffer->paintBoxRel(pos_x + i * ITEMW, pos_y + j * ITEMW,
|
||||
POINT, POINT, COL_INFOBAR_PLUS_3);//fill passive
|
||||
}
|
||||
last_width = active_pb_width;
|
||||
}
|
||||
}
|
||||
|
||||
// paint icon if present
|
||||
@@ -118,17 +264,12 @@ void CProgressBar::paintProgressBar ( const int pos_x,
|
||||
if (upper_labeltext != NULL) {
|
||||
g_Font[font_pbar]->RenderString(start_x +2,
|
||||
upper_labeltext_y,
|
||||
pb_width,
|
||||
width,
|
||||
upper_labeltext,
|
||||
uppertext_col != 0 ? uppertext_col : COL_INFOBAR,
|
||||
pb_height,
|
||||
height,
|
||||
true); // UTF8
|
||||
}
|
||||
|
||||
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+pb_width-3, pos_y+pb_height-3, active_col); // zero line
|
||||
}
|
||||
|
||||
|
||||
|
@@ -21,12 +21,17 @@
|
||||
|
||||
#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>
|
||||
|
||||
#ifdef NO_BLINKENLIGHTS
|
||||
#define PB_COLORED false
|
||||
#else
|
||||
#define PB_COLORED true
|
||||
#endif
|
||||
#include <string>
|
||||
|
||||
class CProgressBar
|
||||
@@ -35,9 +40,32 @@ class CProgressBar
|
||||
CFrameBuffer * frameBuffer;
|
||||
int font_pbar;
|
||||
int frame_widht;
|
||||
|
||||
int last_width;
|
||||
int red, green, yellow;
|
||||
bool blink, invert;
|
||||
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:
|
||||
CProgressBar();
|
||||
CProgressBar(const bool blinkenlights = PB_COLORED,
|
||||
const int r = 40,
|
||||
const int g = 100,
|
||||
const int b =70, const bool inv = false);
|
||||
CProgressBar(const int w, const int h,
|
||||
const bool blinkenlights = PB_COLORED,
|
||||
const int r = 40,
|
||||
const int g = 100,
|
||||
const int b =70, const bool inv = false);
|
||||
~CProgressBar();
|
||||
|
||||
/// void paintProgressBar(...)
|
||||
@@ -81,14 +109,28 @@ class CProgressBar
|
||||
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 */
|
||||
};
|
||||
|
||||
#endif /* __gui_widget_progressbar_h__ */
|
||||
|
Reference in New Issue
Block a user