CComponentsExtTextForm: add new class CComponentsExtTextForm

this provides a combining form, that contains a text object with label
This commit is contained in:
2013-11-01 22:20:50 +01:00
parent 4ed6e54da6
commit d8514b19ee
6 changed files with 353 additions and 8 deletions

View File

@@ -31,6 +31,7 @@ libneutrino_gui_components_a_SOURCES = \
cc_frm_clock.cpp \ cc_frm_clock.cpp \
cc_frm_footer.cpp \ cc_frm_footer.cpp \
cc_frm_header.cpp \ cc_frm_header.cpp \
cc_frm_ext_text.cpp \
cc_frm_icons.cpp \ cc_frm_icons.cpp \
cc_frm_signalbars.cpp \ cc_frm_signalbars.cpp \
cc_frm_window.cpp \ cc_frm_window.cpp \

View File

@@ -31,8 +31,8 @@ Basic attributes and member functions for component sub classes
#ifndef __N_COMPONENTS__ #ifndef __N_COMPONENTS__
#define __N_COMPONENTS__ #define __N_COMPONENTS__
#include "cc_base.h"
#include "cc_types.h" #include "cc_types.h"
#include "cc_base.h"
#include "cc_item_infobox.h" #include "cc_item_infobox.h"
#include "cc_item_picture.h" #include "cc_item_picture.h"

View File

@@ -322,4 +322,95 @@ class CComponentsWindow : public CComponentsForm
void Refresh(){initCCWItems();}; void Refresh(){initCCWItems();};
}; };
class CComponentsExtTextForm : public CComponentsForm
{
private:
///property: content of label, see also setLabelAndText()
std::string ccx_label_text;
///property: content of text, see also setLabelAndText()
std::string ccx_text;
///property: color of label text, see also setLabelAndTextColor()
fb_pixel_t ccx_label_color;
///property: color of text, see also setLabelAndTextColor()
fb_pixel_t ccx_text_color;
///property: mode of label text, see also setTextModes()
int ccx_label_align;
///property: mode of text, see also setTextModes()
int ccx_text_align;
///property: width of label, see also setLabelWidthPercent()
int ccx_label_width;
///property: width of text, see also setLabelWidthPercent()
int ccx_text_width;
///property: font type of both items (label and text), see also setLabelAndText()
Font* ccx_font;
///object: label object
CComponentsLabel *ccx_label_obj;
///object: text object
CComponentsText *ccx_text_obj;
///initialize of properties for all objects
void initCCTextItems();
///initialize the label object
void initLabel();
///initialize the text object
void initText();
protected:
///initialize basic variables
void initVarExtTextForm(const int x_pos = 0, const int y_pos = 0, const int w = 300, const int h = 27,
bool has_shadow = CC_SHADOW_OFF,
fb_pixel_t label_color = COL_MENUCONTENTINACTIVE_TEXT,
fb_pixel_t text_color = COL_MENUCONTENT_TEXT,
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);
public:
///simple constructor for CComponentsExtTextForm
CComponentsExtTextForm();
///advanced constructor for CComponentsExtTextForm, provides parameters for the most required properties, and caption as string
CComponentsExtTextForm( const int x_pos, const int y_pos, const int w, const int h,
const std::string& label_text, const std::string& text,
bool has_shadow = CC_SHADOW_OFF,
fb_pixel_t label_color = COL_MENUCONTENTINACTIVE_TEXT,
fb_pixel_t text_color = COL_MENUCONTENT_TEXT,
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 CComponentsExtTextForm, provides parameters for the most required properties, and caption as locales
CComponentsExtTextForm( const int x_pos, const int y_pos, const int w, const int h,
const neutrino_locale_t& locale_label_text, const neutrino_locale_t& locale_text,
bool has_shadow = CC_SHADOW_OFF,
fb_pixel_t label_color = COL_MENUCONTENTINACTIVE_TEXT,
fb_pixel_t text_color = COL_MENUCONTENT_TEXT,
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);
// ~CComponentsExtTextForm(); //inherited from CComponentsForm
///assigns texts for label and text, parameter as string, parameter Font is optional for required font type, default font is dependently from defined item height
void setLabelAndText(const std::string& label_text, const std::string& text, Font* font_text = NULL);
void setLabelAndText(const neutrino_locale_t& locale_label_text, const neutrino_locale_t& locale_text, Font* font_text = NULL);
///assigns texts for label and text, parameter as struct (locale_ext_txt_t), parameters provide the same properties like setLabelAndText()
void setLabelAndTexts(const locale_ext_txt_t& texts);
///assigns texts for label and text, parameter as struct (string_ext_txt_t), parameters provide the same properties like setLabelAndText()
void setLabelAndTexts(const string_ext_txt_t& locale_texts);
///assigns colors for text for label text, parameter as fb_pixel_t
void setLabelAndTextColor(const fb_pixel_t label_color , const fb_pixel_t text_color);
///assigns width of label and text related to width, parameter as uint8_t in percent of width, fits text automatically into the available remaining size of item
void setLabelWidthPercent(const uint8_t& percent_val);
///returns a pointer to the internal label object, use this to get access to its most properties
CComponentsLabel*getLabelObject(){return ccx_label_obj;};
///returns a pointer to the internal text object, use this to get access to its most properties
CComponentsText*getTextObject(){return ccx_text_obj;};
///sets the text modes (mainly text alignment) to the label and text object, see /gui/widget/textbox.h for possible modes
void setTextModes(const int& label_mode, const int& text_mode);
///paint this item/form
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
};
#endif #endif

View File

@@ -0,0 +1,225 @@
/*
Based up Neutrino-GUI - Tuxbox-Project
Copyright (C) 2001 by Steffen Hehn 'McClean'
Classes for generic GUI-related components.
Copyright (C) 2013, Thilo Graf 'dbt'
License: GPL
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., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <global.h>
#include <neutrino.h>
#include "cc_frm.h"
#define DEF_HEIGHT 27
#define DEF_LABEL_WIDTH_PERCENT 30
#define DEF_WIDTH 300
using namespace std;
CComponentsExtTextForm::CComponentsExtTextForm()
{
initVarExtTextForm();
initCCTextItems();
}
CComponentsExtTextForm::CComponentsExtTextForm( const int x_pos, const int y_pos, const int w, const int h,
const std::string& label_text, const std::string& text,
bool has_shadow,
fb_pixel_t label_color,
fb_pixel_t text_color,
fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow)
{
initVarExtTextForm(x_pos, y_pos, w, h, has_shadow, label_color, text_color, color_frame, color_body, color_shadow);
ccx_label_text = label_text;
ccx_text = text;
initCCTextItems();
}
CComponentsExtTextForm::CComponentsExtTextForm( const int x_pos, const int y_pos, const int w, const int h,
const neutrino_locale_t& locale_label_text, const neutrino_locale_t& locale_text,
bool has_shadow,
fb_pixel_t label_color,
fb_pixel_t text_color,
fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow)
{
initVarExtTextForm(x_pos, y_pos, w, h, has_shadow, label_color, text_color, color_frame, color_body, color_shadow);
ccx_label_text = g_Locale->getText(locale_label_text);
ccx_text = g_Locale->getText(locale_text);
initCCTextItems();
}
void CComponentsExtTextForm::initVarExtTextForm(const int x_pos, const int y_pos, const int w, const int h,
bool has_shadow,
fb_pixel_t label_color,
fb_pixel_t text_color,
fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow)
{
initVarForm();
cc_item_type = CC_ITEMTYPE_FRM_EXT_TEXT;
x = x_pos;
y = y_pos;
width = w;
height = h;
ccx_label_text = "";
ccx_text = "";
shadow = has_shadow;
ccx_label_color = label_color;
ccx_text_color = text_color;
col_frame = color_frame;
col_body = color_body;
col_shadow = color_shadow;
ccx_label_obj = NULL;
ccx_text_obj = NULL;
corner_type = 0;
int dx = 0, dy = DEF_HEIGHT;
ccx_font = *(CNeutrinoFonts::getInstance()->getDynFont(dx, dy));
ccx_label_align = ccx_text_align = CTextBox::NO_AUTO_LINEBREAK;
//init ccx_label_width and ccx_text_width
//default ccx_label_width = 30% of form width
setLabelWidthPercent(DEF_LABEL_WIDTH_PERCENT );
}
void CComponentsExtTextForm::initLabel()
{
//init label object only if text available
if (ccx_label_text.empty()) {
if (ccx_label_obj)
delete ccx_label_obj;
ccx_label_obj = NULL;
return;
}
//initialize label object
if (ccx_label_obj == NULL){
ccx_label_obj = new CComponentsLabel();
ccx_label_obj->doPaintBg(false);
}
//add label object
if (!ccx_label_obj->isAdded())
addCCItem(ccx_label_obj);
//set properties
if (ccx_label_obj){
ccx_label_obj->setText(ccx_label_text, ccx_label_align, ccx_font);
ccx_label_obj->setTextColor(ccx_label_color);
ccx_label_obj->setDimensionsAll(fr_thickness, 0, ccx_label_width-fr_thickness, height-2*fr_thickness);
ccx_label_obj->setCorner(this->corner_rad, CORNER_LEFT);
}
}
void CComponentsExtTextForm::initText()
{
//init text object only if text available
if (ccx_text.empty()) {
if (ccx_text_obj)
delete ccx_text_obj;
ccx_text_obj = NULL;
return;
}
//initialize text object
if (ccx_text_obj == NULL){
ccx_text_obj = new CComponentsLabel();
ccx_text_obj->doPaintBg(false);
}
//add text object
if (!ccx_text_obj->isAdded())
addCCItem(ccx_text_obj);
//set properties
if (ccx_text_obj){
ccx_text_obj->setText(ccx_text, ccx_text_align, ccx_font);
ccx_text_obj->setTextColor(ccx_text_color);
ccx_text_obj->setDimensionsAll(CC_APPEND, 0, ccx_text_width-2*fr_thickness, height-2*fr_thickness);
ccx_text_obj->setCorner(this->corner_rad, CORNER_RIGHT);
}
}
void CComponentsExtTextForm::setLabelAndText(const std::string& label_text, const std::string& text, Font* font_text)
{
ccx_label_text = label_text;
ccx_text = text;
if (font_text)
ccx_font = font_text;
initCCTextItems();
}
void CComponentsExtTextForm::setLabelAndText(const neutrino_locale_t& locale_label_text, const neutrino_locale_t& locale_text, Font* font_text)
{
setLabelAndText(g_Locale->getText(locale_label_text), g_Locale->getText(locale_text), font_text);
}
void CComponentsExtTextForm::setLabelAndTexts(const string_ext_txt_t& texts)
{
setLabelAndText(texts.label_text, texts.text, texts.font);
}
void CComponentsExtTextForm::setLabelAndTexts(const locale_ext_txt_t& locale_texts)
{
setLabelAndText(g_Locale->getText(locale_texts.label_text), g_Locale->getText(locale_texts.text), locale_texts.font);
}
void CComponentsExtTextForm::setTextModes(const int& label_mode, const int& text_mode)
{
ccx_label_align = label_mode;
ccx_text_align = text_mode;
initCCTextItems();
}
void CComponentsExtTextForm::setLabelAndTextColor(const fb_pixel_t label_color , const fb_pixel_t text_color)
{
ccx_label_color = label_color;
ccx_text_color = text_color;
initCCTextItems();
}
void CComponentsExtTextForm::initCCTextItems()
{
height = max(height, ccx_font->getHeight());
initLabel();
initText();
}
void CComponentsExtTextForm::setLabelWidthPercent(const uint8_t& percent_val)
{
ccx_label_width = percent_val * width/100;
ccx_text_width = width-ccx_label_width;
initCCTextItems();
}
void CComponentsExtTextForm::paint(bool do_save_bg)
{
//prepare items before paint
initCCTextItems();
//paint form contents
paintForm(do_save_bg);
}

View File

@@ -109,7 +109,7 @@ void CComponentsText::initVarText()
ct_text_Vborder = 0; ct_text_Vborder = 0;
ct_col_text = COL_MENUCONTENT_TEXT; ct_col_text = COL_MENUCONTENT_TEXT;
ct_old_col_text = ct_col_text; ct_old_col_text = 0;
ct_text_sent = false; ct_text_sent = false;
ct_paint_textbg = false; ct_paint_textbg = false;
ct_force_text_paint = false; ct_force_text_paint = false;
@@ -153,11 +153,24 @@ void CComponentsText::initCCText()
ct_textbox->setWindowMaxDimensions(width, height); ct_textbox->setWindowMaxDimensions(width, height);
ct_textbox->setWindowMinDimensions(width, height); ct_textbox->setWindowMinDimensions(width, height);
//send text to CTextBox object, but paint text only if text or text coloer has changed or force option is enabled //observe behavior of parent form if available
if ((ct_old_text != ct_text) || ct_old_col_text != ct_col_text || ct_force_text_paint) bool force_text_paint = ct_force_text_paint;
ct_text_sent = ct_textbox->setText(&ct_text, this->iWidth); if (cc_parent){
//if any embedded text item was hided because of hided parent form,
//we must ensure repaint of text, otherwise text item is not visible
if (cc_parent->isPainted())
force_text_paint = true;
}
//send text to CTextBox object, but force text paint text if force_text_paint option is enabled
//this is managed by CTextBox object itself
ct_text_sent = ct_textbox->setText(&ct_text, this->iWidth, force_text_paint);
//set current text status, needed by textChanged()
if (ct_text_sent){
ct_old_text = ct_text; ct_old_text = ct_text;
ct_old_col_text = ct_col_text; ct_old_col_text = ct_col_text;
}
#ifdef DEBUG_CC #ifdef DEBUG_CC
printf(" [CComponentsText] [%s - %d] init text: %s [x %d, y %d, w %d, h %d]\n", __FUNCTION__, __LINE__, ct_text.c_str(), this->iX, this->iY, this->iWidth, this->iHeight); printf(" [CComponentsText] [%s - %d] init text: %s [x %d, y %d, w %d, h %d]\n", __FUNCTION__, __LINE__, ct_text.c_str(), this->iX, this->iY, this->iWidth, this->iHeight);
#endif #endif
@@ -170,7 +183,6 @@ void CComponentsText::clearCCText()
ct_textbox = NULL; ct_textbox = NULL;
} }
void CComponentsText::setText(const std::string& stext, const int mode, Font* font_text) void CComponentsText::setText(const std::string& stext, const int mode, Font* font_text)
{ {
ct_old_text = ct_text; ct_old_text = ct_text;

View File

@@ -28,6 +28,7 @@
#include <driver/framebuffer.h> #include <driver/framebuffer.h>
#include <system/localize.h> #include <system/localize.h>
#include <driver/fontrenderer.h>
///cc item types ///cc item types
typedef enum typedef enum
@@ -45,6 +46,7 @@ typedef enum
CC_ITEMTYPE_FOOTER, CC_ITEMTYPE_FOOTER,
CC_ITEMTYPE_FRM_ICONFORM, CC_ITEMTYPE_FRM_ICONFORM,
CC_ITEMTYPE_FRM_WINDOW, CC_ITEMTYPE_FRM_WINDOW,
CC_ITEMTYPE_FRM_EXT_TEXT,
CC_ITEMTYPE_LABEL, CC_ITEMTYPE_LABEL,
CC_ITEMTYPE_PROGRESSBAR, CC_ITEMTYPE_PROGRESSBAR,
CC_ITEMTYPE_BUTTON, CC_ITEMTYPE_BUTTON,
@@ -125,6 +127,20 @@ typedef struct comp_element_data_t
void* handler2; void* handler2;
}comp_element_data_struct_t; }comp_element_data_struct_t;
//text lebel types
typedef struct locale_ext_txt_t
{
neutrino_locale_t label_text;
neutrino_locale_t text;
Font* font;
} locale_ext_txt_struct_t;
typedef struct string_ext_txt_t
{
std::string label_text;
std::string text;
Font* font;
} string_ext_txt_struct_t;
#define CC_WIDTH_MIN 16 #define CC_WIDTH_MIN 16
#define CC_HEIGHT_MIN 16 #define CC_HEIGHT_MIN 16