*components: add members for generic paint, hide and restore items

This commit is contained in:
2012-07-19 15:40:09 +02:00
committed by micha-bbg
parent 084fb88f50
commit bc01ed9a86
3 changed files with 174 additions and 97 deletions

View File

@@ -27,10 +27,12 @@
#include <config.h> #include <config.h>
#endif #endif
#include <gui/widget/components.h>
#include <global.h> #include <global.h>
#include <neutrino.h> #include <neutrino.h>
#include <gui/widget/components.h>
//basic class CComponents //basic class CComponents
@@ -40,32 +42,74 @@ CComponents::CComponents(const int x_pos, const int y_pos, const int h, const in
y = y_pos; y = y_pos;
height = h; height = h;
width = w; width = w;
frameBuffer = CFrameBuffer::getInstance(); sw = 0; //shadow width
bg_buf = NULL; frameBuffer = CFrameBuffer::getInstance();
v_screen_val.clear();
} }
CComponents::~CComponents() CComponents::~CComponents()
{ {
if (bg_buf) { clear();
delete[] bg_buf; }
bg_buf = NULL;
//paint framebuffer stuff and fill buffer
void CComponents::paintFbItems(struct comp_fbdata_t * fbdata, const int items_count, bool do_save_bg)
{
for(int i=0; i< items_count ;i++){
if (do_save_bg){
fbdata[i].pixbuf = new fb_pixel_t[fbdata[i].dx * fbdata[i].dy];
frameBuffer->SaveScreen(fbdata[i].x, fbdata[i].y, fbdata[i].dx, fbdata[i].dy, fbdata[i].pixbuf);
}
v_screen_val.push_back(fbdata[i]);
if (fbdata[i].is_frame)
frameBuffer->paintBoxFrame(fbdata[i].x, fbdata[i].y, fbdata[i].dx, fbdata[i].dy, fbdata[i].frame_thickness, fbdata[i].color, fbdata[i].r);
else
frameBuffer->paintBoxRel(fbdata[i].x, fbdata[i].y, fbdata[i].dx, fbdata[i].dy, fbdata[i].color, fbdata[i].r);
} }
} }
//restore screen
inline void CComponents::restore()
{
for(size_t i =0; i< v_screen_val.size() ;i++) {
if (v_screen_val[i].pixbuf != NULL){
frameBuffer->RestoreScreen(v_screen_val[i].x, v_screen_val[i].y, v_screen_val[i].dx, v_screen_val[i].dy, v_screen_val[i].pixbuf);
delete[] v_screen_val[i].pixbuf;
}
}
v_screen_val.clear();
}
//clean old screen buffer
inline void CComponents::clear()
{
for(size_t i =0; i< v_screen_val.size() ;i++)
if (v_screen_val[i].pixbuf != NULL)
delete[] v_screen_val[i].pixbuf;
v_screen_val.clear();
}
//------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------
//sub class CComponentsDetailLine //sub class CComponentsDetailLine
CComponentsDetailLine::CComponentsDetailLine(const int x_pos, const int y_pos_top, const int y_pos_down, const int h_mark_top_, const int h_mark_down_, fb_pixel_t color1, fb_pixel_t color2) CComponentsDetailLine::CComponentsDetailLine(const int x_pos, const int y_pos_top, const int y_pos_down, const int h_mark_top_, const int h_mark_down_, fb_pixel_t color_line, fb_pixel_t color_shadow)
{ {
x = x_pos; x = x_pos;
width = 16; width = 16;
thickness = 4; thickness = 4;
sw = 1; //shadow width
y = y_pos_top; y = y_pos_top;
y_down = y_pos_down; y_down = y_pos_down;
h_mark_top = h_mark_top_; h_mark_top = h_mark_top_;
h_mark_down = h_mark_down_; h_mark_down = h_mark_down_;
offs_up = offs_down = 0; col_line = color_line;
col1 = color1; col_shadow = color_shadow;
col2 = color2; }
CComponentsDetailLine::~CComponentsDetailLine()
{
clear();
} }
// y_top (=y) // y_top (=y)
@@ -82,32 +126,42 @@ CComponentsDetailLine::CComponentsDetailLine(const int x_pos, const int y_pos_to
// +--|h_mark_down // +--|h_mark_down
// y_down // y_down
#define DLINE_ITEMS_COUNT 12
//paint details line with current parameters //paint details line with current parameters
void CComponentsDetailLine::paint() void CComponentsDetailLine::paint(bool do_save_bg)
{ {
offs_up = h_mark_top/2-thickness+1; clear();
offs_down = h_mark_down/2-thickness+2;
int y_top = y; int y_mark_top = y-h_mark_top/2+thickness/2;
int y_mark_down = y_down-h_mark_down/2+thickness/2;
/* vertical item mark | */ comp_fbdata_t fbdata[DLINE_ITEMS_COUNT] =
frameBuffer->paintBoxRel(x+width-4, y_top-offs_up, thickness, h_mark_top, col1); {
frameBuffer->paintBoxRel(x+width-5+thickness, y_top-offs_up, 1, h_mark_top, col2); /* vertical item mark | */
{x+width-thickness-sw, y_mark_top, thickness, h_mark_top, col_line, 0, NULL, NULL, false, 0},
{x+width-sw, y_mark_top, sw, h_mark_top, col_shadow, 0, NULL, NULL, false, 0},
{x+width-thickness-sw, y_mark_top+h_mark_top, thickness+sw, sw , col_shadow, 0, NULL, NULL, false, 0},
/* horizontal item line - */
{x, y, width-thickness-sw, thickness, col_line, 0, NULL, NULL, false, 0},
{x+thickness, y+thickness, width-2*thickness-sw, sw, col_shadow, 0, NULL, NULL, false, 0},
/* vertical connect line [ */
{x, y+thickness, thickness, y_down-y-thickness, col_line, 0, NULL, NULL, false, 0},
{x+thickness, y+thickness+sw, sw, y_down-y-thickness-sw, col_shadow, 0, NULL, NULL, false, 0},
/* horizontal info line - */
{x, y_down, width-thickness-sw, thickness, col_line, 0, NULL, NULL, false, 0},
{x, y_down+thickness, width-thickness-sw, sw, col_shadow, 0, NULL, NULL, false, 0},
/* vertical info mark | */
{x+width-thickness-sw, y_mark_down, thickness, h_mark_down, col_line, 0, NULL, NULL, false, 0},
{x+width-sw, y_mark_down, sw, h_mark_down, col_shadow, 0, NULL, NULL, false, 0},
{x+width-thickness-sw, y_mark_down+h_mark_down,thickness+sw, sw, col_shadow, 0, NULL, NULL, false, 0},
};
/* horizontal item line - */ paintFbItems(fbdata, DLINE_ITEMS_COUNT, do_save_bg);
frameBuffer->paintBoxRel(x+width-15, y_top+1, 11, thickness, col1);
frameBuffer->paintBoxRel(x+width-15+thickness, y_top+1+thickness, 11-thickness, 1, col2);
/* vertical connect line [ */
frameBuffer->paintBoxRel(x+width-15, y_top+2, thickness, y_down-y_top-1, col1);
frameBuffer->paintBoxRel(x+width-15+thickness, y_top+2+thickness, 1, y_down-y_top+3-2*thickness, col2);
/* horizontal info line - */
frameBuffer->paintBoxRel(x+width-15, y_down, 11, thickness, col1);
frameBuffer->paintBoxRel(x+width-14+thickness, y_down+thickness, 11-thickness, 1, col2);
/* vertical info mark | */
frameBuffer->paintBoxRel(x+width-4, y_down-offs_down, thickness, h_mark_down, col1);
frameBuffer->paintBoxRel(x+width-5+thickness, y_down-offs_down, 1, h_mark_down, col2);
} }
//remove painted lines from screen //remove painted lines from screen
@@ -115,63 +169,66 @@ void CComponentsDetailLine::hide()
{ {
//caching current colors //caching current colors
fb_pixel_t c_tmp1, c_tmp2; fb_pixel_t c_tmp1, c_tmp2;
c_tmp1 = col1; c_tmp1 = col_line;
c_tmp2 = col2; c_tmp2 = col_shadow;
//set background color //set background color
col1 = col2 = COL_BACKGROUND; col_line = col_shadow = COL_BACKGROUND;
//paint with background and restore set last used colors //paint with background and restore, set last used colors
paint(); paint(false);
col1 = c_tmp1; col_line = c_tmp1;
col2 = c_tmp2; col_shadow = c_tmp2;
} }
//------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------
//sub class CComponentsInfoBox //sub class CComponentsInfoBox
CComponentsInfoBox::CComponentsInfoBox( const int x_pos, const int y_pos, const int width_, const int height_, bool shadow_, CComponentsInfoBox::CComponentsInfoBox(const int x_pos, const int y_pos, const int h, const int w, fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow, bool has_shadow)
fb_pixel_t color1, fb_pixel_t color2, fb_pixel_t color3)
{ {
x = x_pos; x = x_pos;
y = y_pos; y = y_pos;
width = width_; width = w;
height = height_; height = h;
rad = RADIUS_LARGE; rad = 0;
shadow = shadow_; shadow = has_shadow;
bg_saved = false; col_frame = color_frame;
col_body = color_body;
col_frame = color1; col_shadow = color_shadow;
col_body = color2; fr_thickness = 2;
col_shadow = color3;
bg_buf = new fb_pixel_t[(width+SHADOW_OFFSET) * (height+SHADOW_OFFSET)];
} }
void CComponentsInfoBox::paint(int rad_) #define INFOBOX_ITEMS_COUNT 3
void CComponentsInfoBox::paint(bool do_save_bg)
{ {
rad = rad_; clear();
if ((bg_buf != NULL) && (!bg_saved)) { rad = RADIUS_LARGE;
frameBuffer->SaveScreen(x, y, width+SHADOW_OFFSET, height+SHADOW_OFFSET, bg_buf);
bg_saved = true;
}
/* box shadow */ comp_fbdata_t fbdata[INFOBOX_ITEMS_COUNT] =
if (shadow) {
frameBuffer->paintBoxRel(x+SHADOW_OFFSET, y+SHADOW_OFFSET, width, height, col_shadow, rad); {x+SHADOW_OFFSET, y+SHADOW_OFFSET, width, height, col_shadow, rad, NULL, NULL, false, 0},
/* box frame */ {x, y, width, height, col_frame, rad, NULL, NULL, true, fr_thickness},
// frameBuffer->paintBoxFrame(x, y, width, height, 2, col_frame, rad); {x+fr_thickness, y+fr_thickness, width-2*fr_thickness, height-2*fr_thickness, col_body, rad, NULL, NULL, false, 0},
frameBuffer->paintBoxRel(x, y, width, height, col_frame, rad); };
/* box fill */
frameBuffer->paintBoxRel(x+2, y+2, width-4, height-4, col_body, rad); paintFbItems(fbdata, INFOBOX_ITEMS_COUNT, do_save_bg);
} }
void CComponentsInfoBox::hide(bool full) void CComponentsInfoBox::hide()
{ {
if (full) { //caching current colors
if (bg_buf != NULL) fb_pixel_t c_tmp1, c_tmp2, c_tmp3;
frameBuffer->RestoreScreen(x, y, width+SHADOW_OFFSET, height+SHADOW_OFFSET, bg_buf); c_tmp1 = col_body;
else c_tmp2 = col_shadow;
frameBuffer->paintBackgroundBoxRel(x, y, width+SHADOW_OFFSET, height+SHADOW_OFFSET); c_tmp3 = col_frame;
}
else //set background color
frameBuffer->paintBoxRel(x+2, y+2, width-4, height-4, col_body, rad); col_body = col_frame = col_shadow = COL_BACKGROUND;
//paint with background and restore, set last used colors
paint(false);
col_body = c_tmp1;
col_shadow = c_tmp2;
col_frame = c_tmp3;
} }

View File

@@ -29,14 +29,32 @@
#include <driver/framebuffer.h> #include <driver/framebuffer.h>
#include <gui/color.h> #include <gui/color.h>
#include <gui/customcolor.h> #include <gui/customcolor.h>
#include <vector>
//required typedefs
typedef struct comp_fbdata_t
{
int x;
int y;
int dx;
int dy;
fb_pixel_t color;
int r;
void * data;
fb_pixel_t* pixbuf;
bool is_frame;
int frame_thickness;
} comp_fbdata_struct_t;
class CComponents class CComponents
{ {
protected: protected:
int x, y, height, width; int x, y, height, width, sw;
fb_pixel_t *bg_buf;
CFrameBuffer * frameBuffer; CFrameBuffer * frameBuffer;
std::vector<comp_fbdata_t> v_screen_val;
void paintFbItems(struct comp_fbdata_t * fbdata, const int items_count, bool do_save_bg = true);
void clear();
public: public:
CComponents(const int x_pos = 0, const int y_pos = 0, const int h = 0, const int w = 0); CComponents(const int x_pos = 0, const int y_pos = 0, const int h = 0, const int w = 0);
@@ -46,22 +64,24 @@ class CComponents
virtual void setYPos(const int& ypos){y = ypos;}; virtual void setYPos(const int& ypos){y = ypos;};
virtual void setHeight(const int& h){height = h;}; virtual void setHeight(const int& h){height = h;};
virtual void setWidth(const int& w){width = w;}; virtual void setWidth(const int& w){width = w;};
virtual void restore();
}; };
class CComponentsDetailLine : public CComponents class CComponentsDetailLine : public CComponents
{ {
private: private:
int thickness, y_down, h_mark_top, h_mark_down, offs_up, offs_down; int thickness, y_down, h_mark_top, h_mark_down;
fb_pixel_t col1, col2; fb_pixel_t col_line, col_shadow;
public: public:
CComponentsDetailLine( const int x_pos,const int y_pos_top, const int y_pos_down, CComponentsDetailLine( const int x_pos,const int y_pos_top, const int y_pos_down,
const int h_mark_up =16 , const int h_mark_down = 16, const int h_mark_up =16 , const int h_mark_down = 16,
fb_pixel_t color1 = COL_MENUCONTENT_PLUS_6, fb_pixel_t color2 = COL_MENUCONTENTDARK_PLUS_0); fb_pixel_t color_line = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
~CComponentsDetailLine();
void paint(); void paint(bool do_save_bg = true);
void hide(); void hide();
void setColor(fb_pixel_t color1, fb_pixel_t color2){col1 = color1; col2 = color2;}; void setColor(fb_pixel_t color_line, fb_pixel_t color_shadow){col_line = color_line; col_shadow = color_shadow;};
void setYPosDown(const int& y_pos_down){y_down = y_pos_down;}; void setYPosDown(const int& y_pos_down){y_down = y_pos_down;};
void setHMarkDown(const int& h_mark_down_){h_mark_down = h_mark_down_;}; void setHMarkDown(const int& h_mark_down_){h_mark_down = h_mark_down_;};
}; };
@@ -69,19 +89,18 @@ class CComponentsDetailLine : public CComponents
class CComponentsInfoBox : public CComponents class CComponentsInfoBox : public CComponents
{ {
private: private:
int width, height, rad; int rad,fr_thickness;
bool shadow;
fb_pixel_t col_frame, col_body, col_shadow; fb_pixel_t col_frame, col_body, col_shadow;
bool shadow, bg_saved;
public: public:
CComponentsInfoBox( const int x_pos, const int y_pos, const int width_, const int height_, bool shadow_ = true, CComponentsInfoBox( const int x_pos, const int y_pos, const int h, const int w,
fb_pixel_t color1 = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUCONTENTDARK_PLUS_0,fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0,
fb_pixel_t color2 = COL_MENUCONTENTDARK_PLUS_0, bool has_shadow = true);
fb_pixel_t color3 = COL_MENUCONTENTDARK_PLUS_0);
void paint(int rad_); void paint(bool do_save_bg = true);
void hide(bool full = false); void hide();
void setColor(fb_pixel_t color1, fb_pixel_t color2, fb_pixel_t color3){col_frame = color1; col_body = color2; col_shadow = color3;}; void setColor(fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow){col_frame = color_frame; col_body = color_body; col_shadow = color_shadow;};
}; };
#endif #endif

View File

@@ -1058,7 +1058,7 @@ void CMenuWidget::paintHint(int pos)
details_line->restore(); details_line->restore();
/* clear info box */ /* clear info box */
if (info_box != NULL) if (info_box != NULL)
info_box->hide((pos == -1) ? true : false); pos == -1 ? info_box->hide() : info_box->restore();
hint_painted = false; hint_painted = false;
} }
if (pos < 0) if (pos < 0)
@@ -1069,7 +1069,7 @@ printf("paintHint: icon %s text %s\n", item->hintIcon.c_str(), g_Locale->getText
if (item->hintIcon.empty() && item->hint == NONEXISTANT_LOCALE) { if (item->hintIcon.empty() && item->hint == NONEXISTANT_LOCALE) {
if (info_box != NULL) if (info_box != NULL)
info_box->hide(true); info_box->hide();
return; return;
} }
@@ -1080,7 +1080,7 @@ printf("paintHint: icon %s text %s\n", item->hintIcon.c_str(), g_Locale->getText
//details line //details line
int ypos1 = item->getYPosition(); int ypos1 = item->getYPosition();
int ypos1a = ypos1 + (iheight/2)-2; int ypos1a = ypos1 + (iheight/2)-2;
int ypos2a = ypos2 + (hint_height/2)-2; int ypos2a = ypos2 + (hint_height/2);
int markh = hint_height > rad*2 ? hint_height - rad*2 : hint_height; int markh = hint_height > rad*2 ? hint_height - rad*2 : hint_height;
int imarkh = iheight/2+1; int imarkh = iheight/2+1;
@@ -1090,17 +1090,18 @@ printf("paintHint: icon %s text %s\n", item->hintIcon.c_str(), g_Locale->getText
details_line->setXPos(xpos); details_line->setXPos(xpos);
details_line->setYPos(ypos1a); details_line->setYPos(ypos1a);
details_line->setYPosDown(ypos2a); details_line->setYPosDown(ypos2a);
details_line->setHMarkDown(markh); details_line->setHMarkDown(markh);
} }
details_line->paint(); details_line->paint();
if (info_box == NULL) if (info_box == NULL)
info_box = new CComponentsInfoBox(x, ypos2, iwidth, hint_height); info_box = new CComponentsInfoBox(x, ypos2, hint_height, iwidth);
else { else {
info_box->setXPos(x); info_box->setXPos(x);
info_box->setYPos(ypos2); info_box->setYPos(ypos2);
info_box->setWidth(iwidth);
} }
info_box->paint(rad); info_box->paint();
int offset = 10; int offset = 10;
if (!item->hintIcon.empty()) { if (!item->hintIcon.empty()) {