CComponents: add new methodes to create forms

Create forms with default constructor and now you can add
cc-items into form with new member addCCItem().

The x/y values are valid to inside of form dimensions itself not inside of screen.
Addable cc-items are all CComponentItem objects and their inheritances
including CComponentsForm itself. So are even nestings possible.

Some changes on other cc-item classes were necessary.
For example, CComponentsPicture or CComponentsText and it's still
much to do.
This commit is contained in:
2012-11-01 16:46:28 +01:00
parent 98b1e38dfa
commit cda02273ea
2 changed files with 175 additions and 107 deletions

View File

@@ -81,12 +81,6 @@ enum
CC_ALIGN_VER_CENTER = 16
};
enum
{
CC_PIC_ICON,
CC_PIC_IMAGE
};
enum
{
CC_ITEMBOX_ICON,
@@ -153,6 +147,10 @@ class CComponents
inline virtual void setColorBody(fb_pixel_t color){col_body = color;};
inline virtual void setColorShadow(fb_pixel_t color){col_shadow = color;};
inline virtual void setColorAll(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;};
/// get colors
inline virtual fb_pixel_t getColorFrame(){return col_frame;};
inline virtual fb_pixel_t getColorBody(){return col_body;};
inline virtual fb_pixel_t getColorShadow(){return col_shadow;};
virtual void hide();
virtual bool isPainted(){return is_painted;};
@@ -172,6 +170,9 @@ class CComponentsItem : public CComponents
/// set corner types: Possible corner types are defined in CFrameBuffer (see: driver/framebuffer.h).
inline virtual void setCornerType(const int& type){corner_type = type;};
inline virtual void setCornerRadius(const int& radius){corner_rad = radius;};
/// get corner types:
inline virtual int getCornerType(){return corner_type;};
inline virtual int getCornerRadius(){return corner_rad;};
inline virtual void setFrameThickness(const int& thickness){fr_thickness = thickness;};
inline virtual void setShadowOnOff(bool has_shadow){shadow = has_shadow;};
@@ -186,23 +187,28 @@ class CComponentsItem : public CComponents
class CComponentsPicture : public CComponentsItem
{
private:
enum
{
CC_PIC_IMAGE_MODE_OFF = 0, //paint pictures in icon mode, mainly not scaled
CC_PIC_IMAGE_MODE_ON = 1, //paint pictures in image mode, paint scaled if required
CC_PIC_IMAGE_MODE_AUTO = 2
};
std::string pic_name;
unsigned char pic_offset;
bool pic_paint, pic_paintBg, pic_painted, do_paint;
int pic_align, pic_x, pic_y, pic_width, pic_height;
int maxWidth, maxHeight, picMode;
int maxWidth, maxHeight, pic_paint_mode;
void initVarPicture();
void init( const int x_pos, const int y_pos, const std::string& picture_name, const int alignment, bool has_shadow,
void init( const int x_pos, const int y_pos, const std::string& image_name, const int alignment, bool has_shadow,
fb_pixel_t color_frame, fb_pixel_t color_background, fb_pixel_t color_shadow);
public:
CComponentsPicture( const int x_pos, const int y_pos,
const std::string& picture_name, const int alignment = CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER, bool has_shadow = CC_SHADOW_OFF,
fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_background = 0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
CComponentsPicture( const int x_pos, const int y_pos, const int w_max, const int h_max,
const std::string& picture_name, const int alignment = CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER, bool has_shadow = CC_SHADOW_OFF,
const std::string& image_name, const int alignment = CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER, bool has_shadow = CC_SHADOW_OFF,
fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_background = 0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
inline void setPictureOffset(const unsigned char offset){pic_offset = offset;};
inline void setPicturePaint(bool paint_p){pic_paint = paint_p;};
inline void setPicturePaintBackground(bool paintBg){pic_paintBg = paintBg;};
@@ -213,7 +219,6 @@ class CComponentsPicture : public CComponentsItem
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
void hide(bool no_restore = false);
inline void getPictureSize(int *pwidth, int *pheight){*pwidth=pic_width; *pheight=pic_height;};
};
class CComponentsText : public CComponentsItem
@@ -234,6 +239,11 @@ class CComponentsText : public CComponentsItem
void paintText(bool do_save_bg = CC_SAVE_SCREEN_YES);
public:
CComponentsText();
CComponentsText(const char* text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL);
CComponentsText( const int x_pos, const int y_pos, const int w, const int h,
const char* text = "", const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL,
bool has_shadow = CC_SHADOW_OFF,
fb_pixel_t color_text = COL_MENUCONTENT, fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUCONTENT_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
~CComponentsText();
void hide(bool no_restore = false);
@@ -258,7 +268,6 @@ class CComponentsInfoBox : public CComponentsText
std::string pic_default_name;
void paintPicture();
// void paintText();
void initVarInfobox();
std::string pic_name;
@@ -416,24 +425,22 @@ class CComponentsTitleBar : public CComponentsItemBox
class CComponentsForm : public CComponentsItem
{
protected:
std::vector<CComponentsItem*> v_cc_items;
void paintCCItems();
private:
CComponentsTitleBar *tb;
std::string tb_text, tb_icon;
void initVarForm();
void paintHead();
public:
CComponentsForm();
CComponentsForm(const int x_pos, const int y_pos, const int w, const int h);
CComponentsForm(const int x_pos, const int y_pos, const int w, const int h, bool has_shadow = CC_SHADOW_ON,
fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUCONTENT_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
~CComponentsForm();
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
void hide(bool no_restore = false);
void setCaption(const std::string& text);
void setCaption(neutrino_locale_t locale_text);
void setIcon(const std::string& icon_name){tb_icon = icon_name;};
void addCCItem(CComponentsItem* cc_Item);
};
#endif

View File

@@ -269,6 +269,42 @@ CComponentsText::CComponentsText()
initVarText();
}
CComponentsText::CComponentsText(const char* text, const int mode, Font* font_text)
{
//CComponentsText
initVarText();
ct_text = text;
ct_text_mode = mode;
ct_font = font_text;
}
CComponentsText::CComponentsText( const int x_pos, const int y_pos, const int w, const int h,
const char* text, const int mode, Font* font_text,
bool has_shadow,
fb_pixel_t color_text, fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow)
{
//CComponentsText
initVarText();
//CComponents
x = x_pos,
y = y_pos,
width = w;
height = h;
col_frame = color_frame;
col_body = color_body;
col_shadow = color_shadow;
shadow = has_shadow;
ct_font = font_text;
ct_text = text;
ct_text_mode = mode;
ct_col_text = color_text;
}
CComponentsText::~CComponentsText()
{
@@ -444,7 +480,7 @@ void CComponentsInfoBox::paintPicture()
{
//init and set icon paint position
if (pic == NULL)
pic = new CComponentsPicture(x+fr_thickness+x_offset, y+fr_thickness/*+y_offset*/, "");
pic = new CComponentsPicture(x+fr_thickness+x_offset, y+fr_thickness/*+y_offset*/, 0, 0, "");
pic->setXPos(x+fr_thickness+x_offset);
pic->setYPos(y+fr_thickness);
@@ -730,40 +766,27 @@ void CComponentsPIP::hide(bool no_restore)
//-------------------------------------------------------------------------------------------------------
//sub class CComponentsPicture from CComponentsItem
CComponentsPicture::CComponentsPicture( const int x_pos, const int y_pos,
const std::string& picture_name, const int alignment, bool has_shadow,
fb_pixel_t color_frame, fb_pixel_t color_background, fb_pixel_t color_shadow)
{
init(x_pos, y_pos, picture_name, alignment, has_shadow, color_frame, color_background, color_shadow);
maxWidth = 0;
maxHeight = 0;
picMode = CC_PIC_ICON;
initVarPicture();
}
CComponentsPicture::CComponentsPicture( const int x_pos, const int y_pos, const int w_max, const int h_max,
const std::string& picture_name, const int alignment, bool has_shadow,
const std::string& image_name, const int alignment, bool has_shadow,
fb_pixel_t color_frame, fb_pixel_t color_background, fb_pixel_t color_shadow)
{
init(x_pos, y_pos, picture_name, alignment, has_shadow, color_frame, color_background, color_shadow);
init(x_pos, y_pos, image_name, alignment, has_shadow, color_frame, color_background, color_shadow);
maxWidth = w_max;
maxHeight = h_max;
picMode = CC_PIC_IMAGE;
pic_paint_mode = CC_PIC_IMAGE_MODE_AUTO,
initVarPicture();
}
void CComponentsPicture::init( int x_pos, int y_pos, const string& picture_name, const int alignment, bool has_shadow,
void CComponentsPicture::init( int x_pos, int y_pos, const string& image_name, const int alignment, bool has_shadow,
fb_pixel_t color_frame, fb_pixel_t color_background, fb_pixel_t color_shadow)
{
//CComponents, CComponentsItem
initVarItem();
//CComponentsPicture
pic_name = picture_name;
pic_name = image_name;
pic_align = alignment;
pic_offset = 1;
pic_paint = true;
@@ -805,9 +828,22 @@ void CComponentsPicture::initVarPicture()
pic_painted = false;
do_paint = false;
if (picMode == CC_PIC_ICON)
//set the image mode depends of name syntax, icon names contains no path,
//so we can detect the required image mode
if (pic_paint_mode == CC_PIC_IMAGE_MODE_AUTO){
if (!access(pic_name.c_str(), F_OK ))
pic_paint_mode = CC_PIC_IMAGE_MODE_ON;
else
pic_paint_mode = CC_PIC_IMAGE_MODE_OFF;
}
if (pic_paint_mode == CC_PIC_IMAGE_MODE_OFF){
frameBuffer->getIconSize(pic_name.c_str(), &pic_width, &pic_height);
else {
pic_width = max(pic_width, maxWidth);
pic_height = max(pic_height, maxHeight);
}
if (pic_paint_mode == CC_PIC_IMAGE_MODE_ON) {
g_PicViewer->getSize(pic_name.c_str(), &pic_width, &pic_height);
if((pic_width > maxWidth) || (pic_height > maxHeight))
g_PicViewer->rescaleImageDimensions(&pic_width, &pic_height, maxWidth, maxHeight);
@@ -850,9 +886,9 @@ void CComponentsPicture::paint(bool do_save_bg)
pic_painted = false;
if (do_paint){
if (picMode == CC_PIC_ICON)
if (pic_paint_mode == CC_PIC_IMAGE_MODE_OFF)
pic_painted = frameBuffer->paintIcon(pic_name, pic_x, pic_y, 0, pic_offset, pic_paint, pic_paintBg, col_body);
else
else if (pic_paint_mode == CC_PIC_IMAGE_MODE_ON)
pic_painted = g_PicViewer->DisplayImage(pic_name, pic_x, pic_y, pic_width, pic_height);
do_paint = false;
}
@@ -1080,7 +1116,7 @@ void CComponentsItemBox::paintImage(size_t index, bool newElement)
pic = new CComponentsPicture( v_element_data[index].x, v_element_data[index].y, v_element_data[index].width,
v_element_data[index].height, v_element_data[index].element);
else
pic = new CComponentsPicture( v_element_data[index].x, v_element_data[index].y, v_element_data[index].element);
pic = new CComponentsPicture( v_element_data[index].x, v_element_data[index].y, 0, 0, v_element_data[index].element);
v_element_data[index].handler1 = (void*)pic;
}
@@ -1448,18 +1484,53 @@ void CComponentsTitleBar::paint(bool do_save_bg)
//-------------------------------------------------------------------------------------------------------
//sub class CComponentsForm from CComponentsItemBox
//sub class CComponentsForm from CComponentsItem
CComponentsForm::CComponentsForm()
{
//CComponentsForm
initVarForm();
}
CComponentsForm::CComponentsForm(const int x_pos, const int y_pos, const int w, const int h)
{
//CComponentsForm
initVarForm();
//CComponents
x = x_pos;
y = y_pos;
width = w;
height = h;
}
CComponentsForm::CComponentsForm(const int x_pos, const int y_pos, const int w, const int h, bool has_shadow,
fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow)
{
//CComponentsForm
initVarForm();
//CComponents
x = x_pos;
y = y_pos;
width = w;
height = h;
shadow = has_shadow;
col_frame = color_frame;
col_body = color_body;
col_shadow = color_shadow;
}
CComponentsForm::~CComponentsForm()
{
hide();
clearSavedScreen();
delete tb;
for(size_t i=0; i<v_cc_items.size(); i++) {
delete v_cc_items[i];
v_cc_items[i] = NULL;
}
v_cc_items.clear();
clear();
}
@@ -1469,7 +1540,7 @@ void CComponentsForm::initVarForm()
initVarItem();
//simple default dimensions
x = 0;
x = 0;
y = 0;
width = 150;
height = 150;
@@ -1482,9 +1553,13 @@ void CComponentsForm::initVarForm()
corner_type = CORNER_ALL;
//CComponentsForm
tb = NULL;
tb_text = "no caption";
tb_icon = "";
v_cc_items.clear();
}
void CComponentsForm::addCCItem(CComponentsItem* cc_Item)
{
v_cc_items.push_back(cc_Item);
}
void CComponentsForm::paint(bool do_save_bg)
@@ -1492,45 +1567,34 @@ void CComponentsForm::paint(bool do_save_bg)
//paint body
paintInit(do_save_bg);
//paint header
paintHead();
//paint items
paintCCItems();
}
void CComponentsForm::paintHead()
void CComponentsForm::paintCCItems()
{
//init header
if (tb == NULL){
tb = new CComponentsTitleBar();
size_t items_count = v_cc_items.size();
int x_tmp = x-fr_thickness;
int y_tmp = y-fr_thickness;
// int w_tmp = (width-2*fr_thickness)/items_count;
// int h_tmp = (height-2*fr_thickness)/items_count;
//init icon
if (!tb_icon.empty())
tb->addIcon(tb_icon, CC_ALIGN_LEFT);
for(size_t i=0; i<items_count; i++) {
//get current item position
int ccx = v_cc_items[i]->getXPos();
int ccy = v_cc_items[i]->getYPos();
//init text
if (!tb_text.empty())
tb->addText(tb_text, CC_ALIGN_LEFT);
//set adapted position onto form
v_cc_items[i]->setXPos(x_tmp+ccx);
v_cc_items[i]->setYPos(y_tmp+ccy);
int tbh = tb->getHeight();
tb->setDimensionsAll(x, y, width, tbh);
//paint element without saved screen!
v_cc_items[i]->paint(CC_SAVE_SCREEN_NO);
//restore position
v_cc_items[i]->setXPos(ccx);
v_cc_items[i]->setYPos(ccy);
}
//paint titlebar
tb->paint(CC_SAVE_SCREEN_NO);
}
void CComponentsForm::setCaption(const string& text)
{
if (tb){
delete tb;
tb = NULL;
}
tb_text = text;
}
void CComponentsForm::setCaption(neutrino_locale_t locale_text)
{
string tmptxt = g_Locale->getText(locale_text);
setCaption(tmptxt);
}
void CComponentsForm::hide(bool no_restore)
@@ -1538,6 +1602,3 @@ void CComponentsForm::hide(bool no_restore)
//hide body
hideContainer(no_restore);
}