CComponents: rework position handling

The real position already used here, if item is bound to a parent.
(bound or embedded means: added with addCCItem() to a form)
This causes no separate calculation in paint methodes of embedded
sub items or sub forms and more nested sub forms.

CComponentsForm have also some new members
- exchangeCCItem() to exchange the order items
- setAppendOffset() to set an offset for auto append mode
 Autoappend is enabled if x or y have value -1 (defined also in CC_APPEND)
 x=horizontal, y=vertical
 Is this activated, no separate calculation of incremental offset
 is required.

However items with independent rendered parts, needs
a separate calculation. In some subclasses was this necessary.


Origin commit data
------------------
Branch: ni/coolstream
Commit: 04300f1874
Author: Thilo Graf <dbt@novatux.de>
Date: 2013-06-16 (Sun, 16 Jun 2013)

Origin message was:
------------------
CComponents: rework position handling

The real position already used here, if item is bound to a parent.
(bound or embedded means: added with addCCItem() to a form)
This causes no separate calculation in paint methodes of embedded
sub items or sub forms and more nested sub forms.

CComponentsForm have also some new members
- exchangeCCItem() to exchange the order items
- setAppendOffset() to set an offset for auto append mode
 Autoappend is enabled if x or y have value -1 (defined also in CC_APPEND)
 x=horizontal, y=vertical
 Is this activated, no separate calculation of incremental offset
 is required.

However items with independent rendered parts, needs
a separate calculation. In some subclasses was this necessary.


------------------
This commit was generated by Migit
This commit is contained in:
2013-06-16 00:19:51 +02:00
parent 7c0b3ab7f8
commit 5820028bb9
5 changed files with 205 additions and 71 deletions

View File

@@ -32,6 +32,8 @@
#include <neutrino.h>
#include "cc_frm.h"
#include <stdlib.h>
#include <algorithm>
using namespace std;
//-------------------------------------------------------------------------------------------------------
@@ -124,22 +126,27 @@ void CComponentsForm::initVarForm()
//CComponentsForm
v_cc_items.clear();
cc_item_type = CC_ITEMTYPE_FRM;
append_h_offset = 0;
append_v_offset = 0;
}
void CComponentsForm::addCCItem(CComponentsItem* cc_Item)
{
if (cc_Item){
#ifdef DEBUG_CC
printf(" [CComponentsForm] %s-%d add cc_Item [type %d] to form [current index=%d] \n", __FUNCTION__, __LINE__, cc_Item->getItemType(), cc_item_index);
printf(" [CComponentsForm] %s-%d try to add cc_Item [type %d] to form [current index=%d] \n", __FUNCTION__, __LINE__, cc_Item->getItemType(), cc_item_index);
#endif
cc_Item->setParent(this);
v_cc_items.push_back(cc_Item);
#ifdef DEBUG_CC
printf(" added cc_Item [type %d] to form [current index=%d] \n", cc_Item->getItemType(), cc_item_index);
#endif
//assign item index
int count = v_cc_items.size();
char buf[16];
char buf[64];
snprintf(buf, sizeof(buf), "%d%d", cc_item_index, count);
buf[15] = '\0';
buf[63] = '\0';
int new_index = atoi(buf);
cc_Item->setIndex(new_index);
#ifdef DEBUG_CC
@@ -233,6 +240,17 @@ void CComponentsForm::removeCCItem(const uint& cc_item_id)
#endif
}
void CComponentsForm::exchangeCCItem(const uint& cc_item_id_a, const uint& cc_item_id_b)
{
if (!v_cc_items.empty())
swap(v_cc_items[cc_item_id_a], v_cc_items[cc_item_id_b]);
}
void CComponentsForm::exchangeCCItem(CComponentsItem* item_a, CComponentsItem* item_b)
{
exchangeCCItem(getCCItemId(item_a), getCCItemId(item_b));
}
void CComponentsForm::paintForm(bool do_save_bg)
{
//paint body
@@ -247,65 +265,78 @@ void CComponentsForm::paint(bool do_save_bg)
paintForm(do_save_bg);
}
void CComponentsForm::paintCCItems()
{
{
size_t items_count = v_cc_items.size();
int x_frm_left = x+fr_thickness; //left form border
int y_frm_top = y+fr_thickness; //top form border
int x_frm_right = x+width-fr_thickness; //right form border
int y_frm_bottom = y+height-fr_thickness; //bottom form border
for(size_t i=0; i<items_count; i++) {
//cache original item position and dimensions
int x_item, y_item, w_item, h_item;
v_cc_items[i]->getDimensions(&x_item, &y_item, &w_item, &h_item);
//using of real x/y values to paint items if this text object is bound in a parent form
int this_x = x, auto_x = x, this_y = y, auto_y = y;
if (cc_parent){
this_x = auto_x = cc_xr;
this_y = auto_y = cc_yr;
}
int xy_ref = 0+fr_thickness; //allowed minimal x and y start position
if (x_item < xy_ref){
#ifdef DEBUG_CC
printf("[CComponentsForm] %s: item %d position is out of form dimensions\ndefinied x=%d\nallowed x>=%d\n", __FUNCTION__, i, x_item, xy_ref);
#endif
x_item = xy_ref;
for(size_t i=0; i<items_count; i++){
//assign item object
CComponentsItem *cc_item = v_cc_items[i];
//get current dimension of item
int w_item = cc_item->getWidth();
int h_item = cc_item->getHeight();
//get current position of item
int xpos = cc_item->getXPos();
int ypos = cc_item->getYPos();
//set required x-position to item
if (xpos == CC_APPEND){
auto_x += append_h_offset;
cc_item->setRealXPos(auto_x + xpos + 1);
auto_x += w_item;
}
if (y_item < xy_ref){
#ifdef DEBUG_CC
printf("[CComponentsForm] %s: item %d position is out of form dimensions\ndefinied y=%d\nallowed y>=%d\n", __FUNCTION__, i, y_item, xy_ref);
#endif
y_item = xy_ref;
else{
cc_item->setRealXPos(this_x + xpos);
auto_x = (cc_item->getRealXPos() + w_item);
}
//set required y-position to item
if (ypos == CC_APPEND){
auto_y += append_v_offset;
cc_item->setRealYPos(auto_y + ypos + 1);
auto_y += h_item;
}
else{
cc_item->setRealYPos(this_y + ypos);
auto_y = (cc_item->getRealYPos() + h_item);
}
//These steps check whether the element can be painted into the container.
//Is it too wide or too high, it will be shortened and displayed in the log.
//This should be avoid!
//checkwidth and adapt if required
int right_frm = (cc_parent ? cc_xr : x) + width - 2*fr_thickness;
int right_item = cc_item->getRealXPos() + w_item;
int w_diff = right_item - right_frm;
int new_w = w_item - w_diff;
if (right_item > right_frm){
printf("[CComponentsForm] %s: item %d width is too large, definied width=%d, possible width=%d \n", __FUNCTION__, i, w_item, new_w);
cc_item->setWidth(new_w);
}
//set adapted position onto form
v_cc_items[i]->setXPos(x_frm_left+x_item);
v_cc_items[i]->setYPos(y_frm_top+y_item);
//watch horizontal x dimensions of items
int x_item_right = v_cc_items[i]->getXPos()+w_item; //right item border
if (x_item_right > x_frm_right){
v_cc_items[i]->setWidth(w_item-(x_item_right-x_frm_right));
#ifdef DEBUG_CC
printf("[CComponentsForm] %s: item %d too large, definied width=%d, possible width=%d \n", __FUNCTION__, i, w_item, v_cc_items[i]->getWidth());
#endif
//check height and adapt if required
int bottom_frm = (cc_parent ? cc_yr : y) + height - 2*fr_thickness;
int bottom_item = cc_item->getRealYPos() + h_item;
int h_diff = bottom_item - bottom_frm;
int new_h = h_item - h_diff;
if (bottom_item > bottom_frm){
printf("[CComponentsForm] %s: item %d height is too large, definied height=%d, possible height=%d \n", __FUNCTION__, i, h_item, new_h);
cc_item->setHeight(new_h);
}
//watch vertical y dimensions
int y_item_bottom = v_cc_items[i]->getYPos()+h_item; //bottom item border
if (y_item_bottom > y_frm_bottom){
v_cc_items[i]->setHeight(h_item-(y_item_bottom-y_frm_bottom));
#ifdef DEBUG_CC
printf("[CComponentsForm] %s: item %d too large, definied height=%d, possible height=%d \n", __FUNCTION__, i, h_item, v_cc_items[i]->getHeight());
#endif
}
//set real position dimension to item
int real_x = v_cc_items[i]->getXPos();
int real_y = v_cc_items[i]->getYPos();
v_cc_items[i]->setRealPos(real_x, real_y);
//paint element without saved screen!
v_cc_items[i]->paint(CC_SAVE_SCREEN_NO);
//restore dimensions and position
v_cc_items[i]->setDimensionsAll(x_item, y_item, w_item, h_item);
//finally paint current item
cc_item->paint(CC_SAVE_SCREEN_NO);
}
}

View File

@@ -41,6 +41,9 @@ class CComponentsForm : public CComponentsItem
std::vector<CComponentsItem*> v_cc_items;
void initVarForm();
void paintForm(bool do_save_bg);
int append_h_offset;
int append_v_offset;
public:
CComponentsForm();
@@ -55,11 +58,14 @@ class CComponentsForm : public CComponentsItem
virtual void removeCCItem(const uint& cc_item_id);
virtual void replaceCCItem(const uint& cc_item_id, CComponentsItem* new_cc_Item);
virtual void replaceCCItem(CComponentsItem* old_cc_Item, CComponentsItem* new_cc_Item);
virtual void exchangeCCItem(const uint& item_id_a, const uint& item_id_b);
virtual void exchangeCCItem(CComponentsItem* item_a, CComponentsItem* item_b);
virtual int getCCItemId(CComponentsItem* cc_Item);
virtual CComponentsItem* getCCItem(const uint& cc_item_id);
virtual void paintCCItems();
virtual void clearCCItems();
virtual void cleanCCForm();
virtual void setAppendOffset(const int &h_offset, const int& v_offset){append_h_offset = h_offset; append_v_offset = v_offset;};
///property: returns true, if item already added to form
virtual bool isAdded(CComponentsItem *cc_item);
};
@@ -176,19 +182,56 @@ class CComponentsFooter : public CComponentsHeader
fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_INFOBAR_SHADOW_PLUS_1, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
};
//! Sub class of CComponentsForm. Shows a window with prepared items.
/*!
CComponentsWindow provides prepared items like header, footer and a container for
items like text, labels, pictures ...
*/
/*
x
y+-------------------------------------------------------+
|icon caption buttons |header (ccw_head)
+-x-----------------------------------------------------+
|cc_item0 |
|cc_item1 |body (ccw_body)
| add items here directly with |
| addWindowItem() or |
y with ccw_body->addCCItem() |
| Note: x/y related to body object |
| |
+-------------------------------------------------------+
| add cc_items with ccw_footer->addCCItem() |footer(ccw_footer)
+-------------------------------------------------------+
*/
class CComponentsWindow : public CComponentsForm
{
private:
///object: header object, to get access to header properties see also getHeaderObject()
CComponentsHeader * ccw_head;
///object: body object, this is the container for all needed items, to add with addWindowItem()
CComponentsForm * ccw_body;
///object: footer object, to get access to header properties see also getFooterObject(
CComponentsForm * ccw_footer;
///property: caption in header, see also getHeaderObject()
std::string ccw_caption;
///property: icon name in header, see also getHeaderObject()
const char* ccw_icon_name;
int ccw_start_y;
///property: assigned default icon buttons in header, see also getHeaderObject()
int ccw_buttons;
///initialze header object
void initHeader();
///initialze body object
void initBody();
///initialze footer object
void initFooter();
///initialze all window objects at once
void initCCWItems();
protected:
///initialize all attributes
void initVarWindow();
public:
@@ -196,17 +239,64 @@ class CComponentsWindow : public CComponentsForm
{
CC_WINDOW_ITEM_HEADER = 0
};
///simple constructor for CComponentsWindow
CComponentsWindow();
///advanced constructor for CComponentsWindow, provides parameters for the most required properties, and caption as string
CComponentsWindow( const int x_pos, const int y_pos, const int w, const int h,
const std::string& caption,
const char* iconname = NULL,
bool has_shadow = CC_SHADOW_OFF,
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);
///advanced constructor for CComponentsWindow, provides parameters for the most required properties, and caption from locales
CComponentsWindow( const int x_pos, const int y_pos, const int w, const int h,
neutrino_locale_t locale_caption,
const char* iconname = NULL,
bool has_shadow = CC_SHADOW_OFF,
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);
///simple constructor for CComponentsWindow, provides parameters for caption as string and icon, position of window is general centered and bound
///to current screen settings, this shows a window over full screen
CComponentsWindow(const std::string& caption, const char* iconname = NULL);
///simple constructor for CComponentsWindow, provides parameters for caption from locales and icon, position of window is general centered and bound
///to current screen settings, this shows a window over full screen
CComponentsWindow(neutrino_locale_t locale_caption, const char* iconname = NULL);
~CComponentsWindow();
///paint window
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
///add item to body object, also usable is addCCItem() to add items to the windo object
void addWindowItem(CComponentsItem* cc_Item);
///set caption in header with string, see also getHeaderObject()
void setWindowCaption(const std::string& text){ccw_caption = text;};
///set caption in header from locales, see also getHeaderObject()
void setWindowCaption(neutrino_locale_t locale_text);
///set icon name in header, see also getHeaderObject()
void setWindowIcon(const char* iconname){ccw_icon_name = iconname;};
///set default header icon buttons, see also getHeaderObject()
void setWindowHeaderButtons(const int& buttons){ccw_buttons = buttons;};
///returns a pointer to the internal header object, use this to get access to header properities
CComponentsHeader* getHeaderObject(){return ccw_head;};
///returns a pointer to the internal body object, use this to get access to body properities
CComponentsForm* getBodyObject(){return ccw_body;};
///returns a pointer to the internal footer object, use this to get access to footer properities
CComponentsForm* getFooterObject(){return ccw_footer;};
int getStartY(); //y value for start of the area below header
};

View File

@@ -78,12 +78,20 @@ void CComponentsItem::paintInit(bool do_save_bg)
//calculate current needed corner radius for body box, depends of frame thickness
int rad = (corner_rad>th) ? corner_rad-th : corner_rad;
int sw = (shadow) ? shadow_w : 0;
//if item is bound on a parent form, we must use real x/y values and from parent form as reference
int ix = x, iy = y;
if (cc_parent){
ix = cc_xr + cc_parent->getFrameThickness();
iy = cc_yr + cc_parent->getFrameThickness();
}
comp_fbdata_t fbdata[] =
{
{CC_FBDATA_TYPE_BGSCREEN, x, y, width+sw, height+sw, 0, 0, 0, NULL, NULL},
{CC_FBDATA_TYPE_SHADOW_BOX, x+sw, y+sw, width, height, col_shadow, corner_rad, 0, NULL, NULL},//shadow
{CC_FBDATA_TYPE_FRAME, x, y, width, height, col_frame_cur, corner_rad, th, NULL, NULL},//frame
{CC_FBDATA_TYPE_BOX, x+th, y+th, width-2*th, height-2*th, col_body, rad, 0, NULL, NULL},//body
{CC_FBDATA_TYPE_BGSCREEN, ix, iy, width+sw, height+sw, 0, 0, 0, NULL, NULL},
{CC_FBDATA_TYPE_SHADOW_BOX, ix+sw, iy+sw, width, height, col_shadow, corner_rad, 0, NULL, NULL},//shadow
{CC_FBDATA_TYPE_FRAME, ix, iy, width, height, col_frame_cur, corner_rad, th, NULL, NULL},//frame
{CC_FBDATA_TYPE_BOX, ix+th, iy+th, width-2*th, height-2*th, col_body, rad, 0, NULL, NULL},//body
};
for(size_t i =0; i< (sizeof(fbdata) / sizeof(fbdata[0])) ;i++) {

View File

@@ -85,8 +85,6 @@ void CComponentsInfoBox::initVarInfobox()
cctext = NULL;
pic_name = "";
x_offset = 10;
x_text = x+fr_thickness+x_offset;;
}
void CComponentsInfoBox::paintPicture()
@@ -101,7 +99,7 @@ void CComponentsInfoBox::paintPicture()
return;
//init pic object and set icon paint position
pic = new CComponentsPicture(x+fr_thickness+x_offset, y+fr_thickness/*+y_offset*/, 0, 0, "");
pic = new CComponentsPicture(x+fr_thickness+x_offset, y+fr_thickness, 0, 0, "");
//define icon
pic->setPicture(pic_name);
@@ -109,7 +107,6 @@ void CComponentsInfoBox::paintPicture()
//fit icon into infobox
pic->setHeight(height-2*fr_thickness);
pic->setColorBody(col_body);
pic->paint(CC_SAVE_SCREEN_NO);
}
@@ -119,15 +116,16 @@ void CComponentsInfoBox::paint(bool do_save_bg)
paintPicture();
//define text x position
x_text = x+fr_thickness+x_offset;
//NOTE: real values are reqiured, if we paint this item within a form as embedded cc-item
int x_text = (cc_parent ? cc_xr : x) + fr_thickness;
int y_text = (cc_parent ? cc_yr : y) + fr_thickness;
//set text to the left border if picture is not painted
if ((pic) && (pic->isPicPainted())){
int pic_w = pic->getWidth();
x_text += pic_w+x_offset;
}
int pic_w = 0;
if ((pic) && (pic->isPicPainted()))
pic_w = pic->getWidth() + x_offset;
//set text and paint text lines
//set text properties and paint text lines
if (!ct_text.empty()){
if (cctext)
delete cctext;
@@ -137,7 +135,13 @@ void CComponentsInfoBox::paint(bool do_save_bg)
cctext->doPaintTextBoxBg(ct_paint_textbg);
cctext->doPaintBg(false);
cctext->setTextColor(ct_col_text);
cctext->setDimensionsAll(x_text, y+fr_thickness, width-(x_text-x+x_offset+fr_thickness), height-2*fr_thickness);
//calculate vars for x-position and dimensions
int tx = x_offset + x_text + pic_w;
int tw = width - x_offset - pic_w - 2*fr_thickness;
int th = height-2*fr_thickness;
cctext->setDimensionsAll(tx, y_text, tw, th);
cctext->paint(CC_SAVE_SCREEN_NO);
}
}

View File

@@ -74,8 +74,9 @@ CComponentsPIP::~CComponentsPIP()
void CComponentsPIP::paint(bool do_save_bg)
{
int pig_x = x+fr_thickness;
int pig_y = y+fr_thickness;
//NOTE: real values are reqiured, if we paint not bound items or an own render methodes
int pig_x = (cc_parent ? cc_xr : x) + fr_thickness;
int pig_y = (cc_parent ? cc_yr : y) + fr_thickness;
int pig_w = width-2*fr_thickness;
int pig_h = height-2*fr_thickness;