mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-29 16:31:05 +02:00
CComponents: implement scroll functionality into CComponentsForm
CComponentsForm provides page scroll if found more
than one pre defined page and is working with all derivated sub classes from CComponentsForm .
Pages are defined with setPageNumber(0...n) in items (1st page = 0). The item page number property is
defined in variable cc_page_number. The highest page number sets the
count of pages inside container to required value. Thats compellingly!
To show a page, we can use setCurrentPage(0...n ) and paintCurPage() or use directly paintPage(0...n).
Note: global paint() will show the current page. Default page is 0 (as first).
Use setCurrentPage(0...n) to change this before first call of paint().
Note: In CComponentsWindow class, these methods are applied to window body.
For examples, take a look into CTestMenu
Origin commit data
------------------
Branch: ni/coolstream
Commit: 672757606c
Author: Thilo Graf <dbt@novatux.de>
Date: 2014-06-26 (Thu, 26 Jun 2014)
------------------
This commit was generated by Migit
This commit is contained in:
@@ -34,6 +34,7 @@ libneutrino_gui_components_a_SOURCES = \
|
|||||||
cc_frm_header.cpp \
|
cc_frm_header.cpp \
|
||||||
cc_frm_ext_text.cpp \
|
cc_frm_ext_text.cpp \
|
||||||
cc_frm_icons.cpp \
|
cc_frm_icons.cpp \
|
||||||
|
cc_frm_scrollbar.cpp \
|
||||||
cc_frm_signalbars.cpp \
|
cc_frm_signalbars.cpp \
|
||||||
cc_frm_slider.cpp \
|
cc_frm_slider.cpp \
|
||||||
cc_frm_window.cpp \
|
cc_frm_window.cpp \
|
||||||
|
@@ -42,9 +42,10 @@ Basic attributes and member functions for component sub classes
|
|||||||
|
|
||||||
#include "cc_detailsline.h"
|
#include "cc_detailsline.h"
|
||||||
|
|
||||||
|
#include "cc_frm_scrollbar.h"
|
||||||
#include "cc_frm.h"
|
#include "cc_frm.h"
|
||||||
#include "cc_frm_button.h"
|
|
||||||
#include "cc_frm_chain.h"
|
#include "cc_frm_chain.h"
|
||||||
|
#include "cc_frm_button.h"
|
||||||
#include "cc_frm_clock.h"
|
#include "cc_frm_clock.h"
|
||||||
#include "cc_frm_ext_text.h"
|
#include "cc_frm_ext_text.h"
|
||||||
#include "cc_frm_header.h"
|
#include "cc_frm_header.h"
|
||||||
|
@@ -231,6 +231,9 @@ class CComponentsItem : public CComponents
|
|||||||
bool cc_item_enabled;
|
bool cc_item_enabled;
|
||||||
///property: default not selected
|
///property: default not selected
|
||||||
bool cc_item_selected;
|
bool cc_item_selected;
|
||||||
|
///property: page number, this defines current item page location, means: this item is embedded in a parent container on page number n, see also setPageNumber()
|
||||||
|
///default value is 0 for page one, any value > 0 causes handling for mutilple pages at parent container
|
||||||
|
uint8_t cc_page_number;
|
||||||
|
|
||||||
///Pointer to the form object in which this item is embedded.
|
///Pointer to the form object in which this item is embedded.
|
||||||
///Is typically the type CComponentsForm or derived classes, default intialized with NULL
|
///Is typically the type CComponentsForm or derived classes, default intialized with NULL
|
||||||
@@ -291,6 +294,11 @@ class CComponentsItem : public CComponents
|
|||||||
///To generate an index, use genIndex()
|
///To generate an index, use genIndex()
|
||||||
virtual void setIndex(const int& index){cc_item_index = index;};
|
virtual void setIndex(const int& index){cc_item_index = index;};
|
||||||
|
|
||||||
|
///sets page location of current item, parameter as uint8_t, see: cc_page_number
|
||||||
|
virtual void setPageNumber(const uint8_t& on_page_number){cc_page_number = on_page_number;};
|
||||||
|
///returns current number of page location of current item, see: cc_page_number
|
||||||
|
virtual u_int8_t getPageNumber(){return cc_page_number;};
|
||||||
|
|
||||||
///set screen x-position, parameter as uint8_t, percent x value related to current width of parent form or screen
|
///set screen x-position, parameter as uint8_t, percent x value related to current width of parent form or screen
|
||||||
virtual void setXPosP(const uint8_t& xpos_percent);
|
virtual void setXPosP(const uint8_t& xpos_percent);
|
||||||
///set screen y-position, parameter as uint8_t, percent y value related to current height of parent form or screen
|
///set screen y-position, parameter as uint8_t, percent y value related to current height of parent form or screen
|
||||||
|
@@ -67,11 +67,16 @@ CComponentsForm::CComponentsForm( const int x_pos, const int y_pos, const int w,
|
|||||||
|
|
||||||
append_x_offset = 0;
|
append_x_offset = 0;
|
||||||
append_y_offset = 0;
|
append_y_offset = 0;
|
||||||
|
page_count = 1;
|
||||||
|
cur_page = 0;
|
||||||
|
sb = NULL;
|
||||||
|
w_sb = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
CComponentsForm::~CComponentsForm()
|
CComponentsForm::~CComponentsForm()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
delete sb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -234,22 +239,70 @@ void CComponentsForm::paint(bool do_save_bg)
|
|||||||
paintForm(do_save_bg);
|
paintForm(do_save_bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CComponentsForm::isPageChanged()
|
||||||
|
{
|
||||||
|
for(size_t i=0; i<v_cc_items.size(); i++){
|
||||||
|
if (v_cc_items[i]->getPageNumber() != cur_page)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CComponentsForm::paintPage(const u_int8_t& page_number, bool do_save_bg)
|
||||||
|
{
|
||||||
|
cur_page = page_number;
|
||||||
|
paint(do_save_bg);
|
||||||
|
}
|
||||||
|
|
||||||
void CComponentsForm::paintCCItems()
|
void CComponentsForm::paintCCItems()
|
||||||
{
|
{
|
||||||
size_t items_count = v_cc_items.size();
|
size_t items_count = v_cc_items.size();
|
||||||
|
|
||||||
//using of real x/y values to paint items if this text object is bound in a parent form
|
//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;
|
int this_x = x, auto_x = x, this_y = y, auto_y = y, this_w = width;
|
||||||
if (cc_parent){
|
if (cc_parent){
|
||||||
this_x = auto_x = cc_xr;
|
this_x = auto_x = cc_xr;
|
||||||
this_y = auto_y = cc_yr;
|
this_y = auto_y = cc_yr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//init and handle scrollbar
|
||||||
|
getPageCount();
|
||||||
|
int y_sb = this_y+1;
|
||||||
|
int x_sb = this_x + width - w_sb;
|
||||||
|
int h_sb = height-2;
|
||||||
|
if (sb == NULL){
|
||||||
|
sb = new CComponentsScrollBar(x_sb, y_sb, w_sb, h_sb);
|
||||||
|
}else{
|
||||||
|
//clean background, if dimension of scrollbar was changed
|
||||||
|
if (w_sb != sb->getWidth())
|
||||||
|
sb->kill(col_body);
|
||||||
|
|
||||||
|
//set current dimensions and position
|
||||||
|
sb->setDimensionsAll(x_sb, y_sb, w_sb, h_sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(page_count > 1){
|
||||||
|
sb->setSegmentCount(page_count);
|
||||||
|
sb->setMarkID(cur_page);
|
||||||
|
this_w = width - w_sb;
|
||||||
|
sb->paint(false);
|
||||||
|
}else{
|
||||||
|
if (sb->isPainted())
|
||||||
|
sb->kill(col_body);
|
||||||
|
this_w = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
//detect if current page has changed, if true then kill items from screen
|
||||||
|
if(isPageChanged()){
|
||||||
|
this->killCCItems(col_body, true);
|
||||||
|
}
|
||||||
|
|
||||||
for(size_t i=0; i<items_count; i++){
|
for(size_t i=0; i<items_count; i++){
|
||||||
//assign item object
|
//assign item object
|
||||||
CComponentsItem *cc_item = v_cc_items[i];
|
CComponentsItem *cc_item = v_cc_items[i];
|
||||||
|
|
||||||
|
dprintf(DEBUG_INFO, "[CComponentsForm] %s: page_count = %u, item_page = %u, cur_page = %u\n", __func__, getPageCount(), cc_item->getPageNumber(), this->cur_page);
|
||||||
|
|
||||||
//get current dimension of item
|
//get current dimension of item
|
||||||
int w_item = cc_item->getWidth();
|
int w_item = cc_item->getWidth();
|
||||||
int h_item = cc_item->getHeight();
|
int h_item = cc_item->getHeight();
|
||||||
@@ -259,10 +312,9 @@ void CComponentsForm::paintCCItems()
|
|||||||
int ypos = cc_item->getYPos();
|
int ypos = cc_item->getYPos();
|
||||||
|
|
||||||
//check item for corrupt position, skip current item if found problems
|
//check item for corrupt position, skip current item if found problems
|
||||||
//TODO: need a solution with possibility for scrolling
|
if (ypos > height || xpos > this_w){
|
||||||
if (ypos > height || xpos > width){
|
dprintf(DEBUG_INFO, "[CComponentsForm] %s: [form: %d] [item-index %d] [type=%d] WARNING: item position is out of form size:\ndefinied x=%d, defined this_w=%d \ndefinied y=%d, defined height=%d \n",
|
||||||
dprintf(DEBUG_INFO, "[CComponentsForm] %s: [form: %d] [item-index %d] [type=%d] WARNING: item position is out of form size:\ndefinied x=%d, defined width=%d \ndefinied y=%d, defined height=%d \n",
|
__func__, cc_item_index, cc_item->getIndex(), cc_item->getItemType(), xpos, this_w, ypos, height);
|
||||||
__func__, cc_item_index, cc_item->getIndex(), cc_item->getItemType(), xpos, width, ypos, height);
|
|
||||||
if (this->cc_item_type != CC_ITEMTYPE_FRM_CHAIN)
|
if (this->cc_item_type != CC_ITEMTYPE_FRM_CHAIN)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -276,7 +328,7 @@ void CComponentsForm::paintCCItems()
|
|||||||
}
|
}
|
||||||
//positionize vertical centered
|
//positionize vertical centered
|
||||||
else if (xpos == CC_CENTERED){
|
else if (xpos == CC_CENTERED){
|
||||||
auto_x = width/2 - w_item/2;
|
auto_x = this_w/2 - w_item/2;
|
||||||
cc_item->setRealXPos(this_x + auto_x);
|
cc_item->setRealXPos(this_x + auto_x);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@@ -301,12 +353,11 @@ void CComponentsForm::paintCCItems()
|
|||||||
auto_y = (cc_item->getRealYPos() + h_item);
|
auto_y = (cc_item->getRealYPos() + h_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//These steps check whether the element can be painted into the container.
|
//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.
|
//Is it too wide or too high, it will be shortened and displayed in the log.
|
||||||
//This should be avoid!
|
//This should be avoid!
|
||||||
//checkwidth and adapt if required
|
//checkwidth and adapt if required
|
||||||
int right_frm = (cc_parent ? cc_xr : x) + width - 2*fr_thickness;
|
int right_frm = (cc_parent ? cc_xr : x) + this_w - 2*fr_thickness;
|
||||||
int right_item = cc_item->getRealXPos() + w_item;
|
int right_item = cc_item->getRealXPos() + w_item;
|
||||||
int w_diff = right_item - right_frm;
|
int w_diff = right_item - right_frm;
|
||||||
int new_w = w_item - w_diff;
|
int new_w = w_item - w_diff;
|
||||||
@@ -314,7 +365,7 @@ void CComponentsForm::paintCCItems()
|
|||||||
right_item -= (new_w%2);
|
right_item -= (new_w%2);
|
||||||
w_item -= (new_w%2);
|
w_item -= (new_w%2);
|
||||||
if (right_item > right_frm){
|
if (right_item > right_frm){
|
||||||
dprintf(DEBUG_INFO, "[CComponentsForm] %s: [form: %d] [item-index %d] [type=%d] width is too large, definied width=%d, possible width=%d \n",
|
dprintf(DEBUG_INFO, "[CComponentsForm] %s: [form: %d] [item-index %d] [type=%d] this_w is too large, definied width=%d, possible width=%d \n",
|
||||||
__func__, cc_item_index, cc_item->getIndex(), cc_item->getItemType(), w_item, new_w);
|
__func__, cc_item_index, cc_item->getIndex(), cc_item->getItemType(), w_item, new_w);
|
||||||
cc_item->setWidth(new_w);
|
cc_item->setWidth(new_w);
|
||||||
}
|
}
|
||||||
@@ -339,8 +390,9 @@ void CComponentsForm::paintCCItems()
|
|||||||
if (!this->cc_allow_paint)
|
if (!this->cc_allow_paint)
|
||||||
cc_item->allowPaint(false);
|
cc_item->allowPaint(false);
|
||||||
|
|
||||||
//finally paint current item
|
//finally paint current item, but only required contents of page
|
||||||
cc_item->paint(CC_SAVE_SCREEN_NO);
|
if (cc_item->getPageNumber() == cur_page)
|
||||||
|
cc_item->paint(CC_SAVE_SCREEN_NO);
|
||||||
|
|
||||||
//restore defined old visibility mode of item after paint
|
//restore defined old visibility mode of item after paint
|
||||||
cc_item->allowPaint(item_visible);
|
cc_item->allowPaint(item_visible);
|
||||||
@@ -369,3 +421,26 @@ void CComponentsForm::killCCItems(const fb_pixel_t& bg_color, bool ignore_parent
|
|||||||
for(size_t i=0; i<v_cc_items.size(); i++)
|
for(size_t i=0; i<v_cc_items.size(); i++)
|
||||||
v_cc_items[i]->kill(bg_color, ignore_parent);
|
v_cc_items[i]->kill(bg_color, ignore_parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CComponentsForm::setPageCount(const u_int8_t& pageCount)
|
||||||
|
{
|
||||||
|
u_int8_t new_val = pageCount;
|
||||||
|
if (new_val < page_count)
|
||||||
|
dprintf(DEBUG_NORMAL, "[CComponentsForm] %s: current count (= %u) of pages higher than page_count (= %u) will be set, smaller value is ignored!\n", __func__, page_count, new_val) ;
|
||||||
|
page_count = max(new_val, page_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
u_int8_t CComponentsForm::getPageCount()
|
||||||
|
{
|
||||||
|
u_int8_t num = 0;
|
||||||
|
for(size_t i=0; i<v_cc_items.size(); i++){
|
||||||
|
u_int8_t item_num = v_cc_items[i]->getPageNumber();
|
||||||
|
num = max(item_num, num);
|
||||||
|
}
|
||||||
|
|
||||||
|
//convert type, possible -Wconversion warnings!
|
||||||
|
page_count = static_cast<u_int8_t>(num + 1);
|
||||||
|
|
||||||
|
return page_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <gui/components/cc_base.h>
|
#include <gui/components/cc_base.h>
|
||||||
|
#include "cc_frm_scrollbar.h"
|
||||||
|
|
||||||
class CComponentsForm : public CComponentsItem
|
class CComponentsForm : public CComponentsItem
|
||||||
{
|
{
|
||||||
@@ -37,8 +37,21 @@ class CComponentsForm : public CComponentsItem
|
|||||||
///generates next possible index for an item, see also cc_item_index, getIndex(), setIndex()
|
///generates next possible index for an item, see also cc_item_index, getIndex(), setIndex()
|
||||||
int genIndex();
|
int genIndex();
|
||||||
|
|
||||||
|
///scrollbar object
|
||||||
|
CComponentsScrollBar *sb;
|
||||||
|
|
||||||
int append_x_offset;
|
int append_x_offset;
|
||||||
int append_y_offset;
|
int append_y_offset;
|
||||||
|
|
||||||
|
///property: count of pages of form
|
||||||
|
u_int8_t page_count;
|
||||||
|
///property: id of current page, default = 0 for 1st page
|
||||||
|
u_int8_t cur_page;
|
||||||
|
///scrollbar width
|
||||||
|
int w_sb;
|
||||||
|
///returns true, if current page is changed, see also: setCurrentPage()
|
||||||
|
bool isPageChanged();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CComponentsForm( const int x_pos = 0, const int y_pos = 0, const int w = 800, const int h = 600,
|
CComponentsForm( const int x_pos = 0, const int y_pos = 0, const int w = 800, const int h = 600,
|
||||||
CComponentsForm *parent = NULL,
|
CComponentsForm *parent = NULL,
|
||||||
@@ -48,7 +61,9 @@ class CComponentsForm : public CComponentsItem
|
|||||||
fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
|
fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
|
||||||
virtual ~CComponentsForm();
|
virtual ~CComponentsForm();
|
||||||
|
|
||||||
|
///paints current form on screen, for paint a page use paintPage()
|
||||||
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
|
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
|
||||||
|
///hides current form, background will be restored, if parameter = false
|
||||||
void hide(bool no_restore = false);
|
void hide(bool no_restore = false);
|
||||||
|
|
||||||
///same like CComponentsItem::kill(), but erases all embedded items inside of parent at once, this = parent
|
///same like CComponentsItem::kill(), but erases all embedded items inside of parent at once, this = parent
|
||||||
@@ -83,7 +98,25 @@ class CComponentsForm : public CComponentsItem
|
|||||||
///return reference to last item
|
///return reference to last item
|
||||||
virtual CComponentsItem* back(){return v_cc_items.back();};
|
virtual CComponentsItem* back(){return v_cc_items.back();};
|
||||||
|
|
||||||
|
///sets alignment offset between items
|
||||||
virtual void setAppendOffset(const int &x_offset, const int& y_offset){append_x_offset = x_offset; append_y_offset = y_offset;};
|
virtual void setAppendOffset(const int &x_offset, const int& y_offset){append_x_offset = x_offset; append_y_offset = y_offset;};
|
||||||
|
|
||||||
|
///sets count of pages, parameter as u_int8_t
|
||||||
|
///NOTE: page numbers are primary defined in items and this values have priority!! Consider that smaller values
|
||||||
|
///than the current values can make problems and are not allowed, therefore smaller values than
|
||||||
|
///current page count are ignored!
|
||||||
|
virtual void setPageCount(const u_int8_t& pageCount);
|
||||||
|
///returns current count of pages,
|
||||||
|
///NOTE: page number are primary defined in items and secondary in form variable 'page_count'. This function returns the maximal value from both!
|
||||||
|
virtual u_int8_t getPageCount();
|
||||||
|
///sets current page
|
||||||
|
virtual void setCurrentPage(const u_int8_t& current_page){cur_page = current_page;};
|
||||||
|
///get current page
|
||||||
|
virtual u_int8_t getCurrentPage(){return cur_page;};
|
||||||
|
///paint defined page number 0...n
|
||||||
|
virtual void paintPage(const u_int8_t& page_number, bool do_save_bg = CC_SAVE_SCREEN_NO);
|
||||||
|
///set width of scrollbar
|
||||||
|
virtual void setScrollBarWidth(const int& scrollbar_width){w_sb = scrollbar_width;};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
175
src/gui/components/cc_frm_scrollbar.cpp
Normal file
175
src/gui/components/cc_frm_scrollbar.cpp
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
/*
|
||||||
|
Based up Neutrino-GUI - Tuxbox-Project
|
||||||
|
Copyright (C) 2001 by Steffen Hehn 'McClean'
|
||||||
|
|
||||||
|
Scrollbar class based up CComponentsFrmChain.
|
||||||
|
Copyright (C) 2014 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, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <global.h>
|
||||||
|
#include <neutrino.h>
|
||||||
|
#include "cc_frm_scrollbar.h"
|
||||||
|
#include "system/debug.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
/* base schema
|
||||||
|
x,y
|
||||||
|
+-----------------+
|
||||||
|
|+---------------+|
|
||||||
|
||sb_up_obj ||
|
||||||
|
|| ||
|
||||||
|
|+---------------+|
|
||||||
|
|+---------------+|
|
||||||
|
||sb_segments_obj||
|
||||||
|
||+-------------+||
|
||||||
|
||| segment |||
|
||||||
|
||| id 0 |||
|
||||||
|
||| |||
|
||||||
|
||+-------------+||
|
||||||
|
||| segment |||
|
||||||
|
||| id 1 |||
|
||||||
|
||| |||
|
||||||
|
||+-------------+||
|
||||||
|
|+---------------+|
|
||||||
|
|+---------------+|
|
||||||
|
||sb_up_obj ||
|
||||||
|
|| ||
|
||||||
|
|+---------------+|
|
||||||
|
+-----------------+
|
||||||
|
*/
|
||||||
|
|
||||||
|
//sub class CComponentsScrollBar inherit from CComponentsFrmChain
|
||||||
|
CComponentsScrollBar::CComponentsScrollBar( const int &x_pos, const int &y_pos, const int &w, const int &h,
|
||||||
|
const int& count,
|
||||||
|
CComponentsForm* parent,
|
||||||
|
bool has_shadow,
|
||||||
|
fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow)
|
||||||
|
:CComponentsFrmChain(x_pos, y_pos, w, h, NULL, CC_DIR_Y, parent, has_shadow, color_frame, color_body, color_shadow)
|
||||||
|
{
|
||||||
|
initVarSbForm(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CComponentsScrollBar::initVarSbForm(const int& count)
|
||||||
|
{
|
||||||
|
cc_item_type = CC_ITEMTYPE_FRM_SCROLLBAR;
|
||||||
|
fr_thickness = 0;
|
||||||
|
|
||||||
|
append_x_offset = 0;
|
||||||
|
append_y_offset = 2;
|
||||||
|
|
||||||
|
sb_up_obj = sb_down_obj = NULL;
|
||||||
|
sb_segments_obj = NULL;
|
||||||
|
sb_up_icon = frameBuffer->getIconBasePath() + NEUTRINO_ICON_BUTTON_TOP;
|
||||||
|
sb_up_icon += ".png";
|
||||||
|
sb_down_icon = frameBuffer->getIconBasePath() + NEUTRINO_ICON_BUTTON_DOWN;
|
||||||
|
sb_down_icon += ".png";
|
||||||
|
|
||||||
|
sb_segments_count = count;
|
||||||
|
sb_mark_id = 0;
|
||||||
|
|
||||||
|
initCCItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CComponentsScrollBar::setSegmentCount(const int& segment_count, const int& mark_id)
|
||||||
|
{
|
||||||
|
sb_segments_count = segment_count;
|
||||||
|
sb_mark_id = mark_id;
|
||||||
|
initSegments();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CComponentsScrollBar::initCCItems()
|
||||||
|
{
|
||||||
|
initTopNaviIcon();
|
||||||
|
initSegments();
|
||||||
|
initBottomNaviIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CComponentsScrollBar::initTopNaviIcon()
|
||||||
|
{
|
||||||
|
//initialize icon object
|
||||||
|
if (sb_up_obj == NULL){
|
||||||
|
sb_up_obj = new CComponentsPicture(CC_CENTERED, fr_thickness, sb_up_icon, this);
|
||||||
|
sb_up_obj->doPaintBg(false);
|
||||||
|
}
|
||||||
|
sb_up_obj->setWidth(width-2*fr_thickness);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CComponentsScrollBar::initBottomNaviIcon()
|
||||||
|
{
|
||||||
|
//initialize icon object
|
||||||
|
if (sb_down_obj == NULL){
|
||||||
|
sb_down_obj = new CComponentsPicture(CC_CENTERED, CC_APPEND, sb_down_icon, this);
|
||||||
|
sb_down_obj->doPaintBg(false);
|
||||||
|
}
|
||||||
|
sb_down_obj->setWidth(width-2*fr_thickness);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CComponentsScrollBar::initSegments()
|
||||||
|
{
|
||||||
|
//init dimensions for segments
|
||||||
|
int w_seg = width - 4*fr_thickness;
|
||||||
|
int h_seg = height - (sb_segments_count-1)*append_y_offset;
|
||||||
|
|
||||||
|
//calculate height of segment container
|
||||||
|
int h_seg_obj = height - 2*sb_up_obj->getHeight() - 3*append_y_offset;
|
||||||
|
|
||||||
|
//init segment container
|
||||||
|
if (sb_segments_obj == NULL){
|
||||||
|
sb_segments_obj = new CComponentsFrmChain(CC_CENTERED, CC_APPEND, w_seg, h_seg_obj, NULL, CC_DIR_Y, this, false);
|
||||||
|
sb_segments_obj->setFrameThickness(0,0);
|
||||||
|
sb_segments_obj->setAppendOffset(0, 3);
|
||||||
|
}else
|
||||||
|
sb_segments_obj->setDimensionsAll(CC_CENTERED, CC_APPEND, w_seg, h_seg_obj);
|
||||||
|
|
||||||
|
//set current color for segment container
|
||||||
|
sb_segments_obj->setColorBody(col_body);
|
||||||
|
|
||||||
|
//clean up segment container before add new segments
|
||||||
|
sb_segments_obj->clear();
|
||||||
|
|
||||||
|
//set y position of 1st segment and set height of segments
|
||||||
|
int y_seg = 1+ append_y_offset;
|
||||||
|
h_seg = sb_segments_obj->getHeight()/sb_segments_count - append_y_offset;
|
||||||
|
|
||||||
|
//create and add segments to segment container
|
||||||
|
for(u_int8_t i=0; i<sb_segments_count; i++){
|
||||||
|
CComponentsShapeSquare *item = new CComponentsShapeSquare(0, y_seg, w_seg, h_seg, sb_segments_obj, false);
|
||||||
|
y_seg += h_seg + append_y_offset;
|
||||||
|
|
||||||
|
int id = sb_segments_obj->getCCItemId(item);
|
||||||
|
if (sb_mark_id > id){
|
||||||
|
dprintf(DEBUG_NORMAL, "[CComponentsScrollBar] %s: sb_mark_id out of range current=%d allowed=%d\n", __func__, sb_mark_id, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
//set color for marked id
|
||||||
|
if (sb_mark_id == id)
|
||||||
|
item->setColorBody(COL_MENUCONTENTSELECTED_PLUS_0);
|
||||||
|
else
|
||||||
|
item->setColorBody(COL_MENUCONTENT_PLUS_1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//set corner types
|
||||||
|
sb_segments_obj->front()->setCorner(RADIUS_MIN, CORNER_TOP);
|
||||||
|
sb_segments_obj->back()->setCorner(RADIUS_MIN, CORNER_BOTTOM);
|
||||||
|
}
|
82
src/gui/components/cc_frm_scrollbar.h
Normal file
82
src/gui/components/cc_frm_scrollbar.h
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
Based up Neutrino-GUI - Tuxbox-Project
|
||||||
|
Copyright (C) 2001 by Steffen Hehn 'McClean'
|
||||||
|
|
||||||
|
Scrollbar class based up CComponentsFrmChain.
|
||||||
|
Copyright (C) 2014 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, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __CC_FORM_SCROLLBAR_H__
|
||||||
|
#define __CC_FORM_SCROLLBAR_H__
|
||||||
|
|
||||||
|
#include "cc_frm_chain.h"
|
||||||
|
#include "cc_item_picture.h"
|
||||||
|
|
||||||
|
class CComponentsScrollBar : public CComponentsFrmChain
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
///scroll up navi icon object
|
||||||
|
CComponentsPicture *sb_up_obj;
|
||||||
|
///scroll down navi icon object
|
||||||
|
CComponentsPicture *sb_down_obj;
|
||||||
|
///container object for segments
|
||||||
|
CComponentsFrmChain *sb_segments_obj;
|
||||||
|
|
||||||
|
///names of navi icons
|
||||||
|
std::string sb_up_icon, sb_down_icon;
|
||||||
|
|
||||||
|
///count of segments
|
||||||
|
int sb_segments_count;
|
||||||
|
|
||||||
|
///mark id
|
||||||
|
int sb_mark_id;
|
||||||
|
|
||||||
|
///init top icon
|
||||||
|
void initTopNaviIcon();
|
||||||
|
///init bottom icon
|
||||||
|
void initBottomNaviIcon();
|
||||||
|
|
||||||
|
///init segements
|
||||||
|
void initSegments();
|
||||||
|
|
||||||
|
///init all items
|
||||||
|
void initCCItems();
|
||||||
|
|
||||||
|
void initVarSbForm( const int& count);
|
||||||
|
|
||||||
|
public:
|
||||||
|
CComponentsScrollBar( const int &x_pos, const int &y_pos, const int &w = 15, const int &h = 40,
|
||||||
|
const int& count = 1,
|
||||||
|
CComponentsForm *parent = NULL,
|
||||||
|
bool has_shadow = CC_SHADOW_OFF,
|
||||||
|
fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_3,
|
||||||
|
fb_pixel_t color_body = COL_MENUCONTENT_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
|
||||||
|
// ~CComponentsScrollBar(); //inherited from CComponentsForm
|
||||||
|
|
||||||
|
///set marked segment, 1st = 0, 2nd = 1 ...
|
||||||
|
void setMarkID(const int& mark_id){sb_mark_id = mark_id; initSegments();};
|
||||||
|
///get current assigned marked id
|
||||||
|
int getMarkID(){return sb_mark_id;};
|
||||||
|
|
||||||
|
///Sets count of scrollbar segments and is similar e.g. page count. Each segment is assigned to an id. Starting with id 0...n see also setMarkID(), getMarkID().
|
||||||
|
void setSegmentCount(const int& segment_count, const int& mark_id = 0);
|
||||||
|
///Get count of current scrollbar segments
|
||||||
|
int getSegmentCount(){return sb_segments_count;}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@@ -360,6 +360,34 @@ void CComponentsWindow::addWindowItem(CComponentsItem* cc_Item)
|
|||||||
ccw_body->addCCItem(cc_Item);
|
ccw_body->addCCItem(cc_Item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CComponentsWindow::setCurrentPage(const u_int8_t& current_page)
|
||||||
|
{
|
||||||
|
ccw_body->setCurrentPage(current_page);
|
||||||
|
}
|
||||||
|
|
||||||
|
u_int8_t CComponentsWindow::getCurrentPage()
|
||||||
|
{
|
||||||
|
return ccw_body->getCurrentPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CComponentsWindow::setScrollBarWidth(const int& scrollbar_width)
|
||||||
|
{
|
||||||
|
ccw_body->setScrollBarWidth(scrollbar_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CComponentsWindow::paintCurPage(bool do_save_bg)
|
||||||
|
{
|
||||||
|
if (is_painted) //ensure that we have painted already the parent form before paint body
|
||||||
|
ccw_body->paint(do_save_bg);
|
||||||
|
else
|
||||||
|
paint(do_save_bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CComponentsWindow::paintPage(const u_int8_t& page_number, bool do_save_bg)
|
||||||
|
{
|
||||||
|
CComponentsWindow::setCurrentPage(page_number);
|
||||||
|
CComponentsWindow::paintCurPage(do_save_bg);
|
||||||
|
}
|
||||||
|
|
||||||
void CComponentsWindow::paint(bool do_save_bg)
|
void CComponentsWindow::paint(bool do_save_bg)
|
||||||
{
|
{
|
||||||
|
@@ -183,11 +183,23 @@ class CComponentsWindow : public CComponentsForm
|
|||||||
///sets width of sidebars
|
///sets width of sidebars
|
||||||
void setWidthSidebar(const int& sidebar_width){ccw_w_sidebar = sidebar_width; initCCWItems();};
|
void setWidthSidebar(const int& sidebar_width){ccw_w_sidebar = sidebar_width; initCCWItems();};
|
||||||
|
|
||||||
|
///sets current page, NOTE: this is simliar with setCurrentPage() known from basic class CComponentsForm, but here it is related only for window body object
|
||||||
|
void setCurrentPage(const u_int8_t& current_page);
|
||||||
|
///get current page, NOTE: this is simliar with getCurrentPage() known from basic class CComponentsForm, but here it is related only for window body object
|
||||||
|
u_int8_t getCurrentPage();
|
||||||
|
|
||||||
|
///paint window body items, this paints only the current page, body = page, current page is definied in body object, see setCurrentPage()
|
||||||
|
void paintCurPage(bool do_save_bg = CC_SAVE_SCREEN_NO);
|
||||||
|
///paint defined page of body, parameter number 0...n
|
||||||
|
void paintPage(const u_int8_t& page_number, bool do_save_bg = CC_SAVE_SCREEN_NO);
|
||||||
|
///set width of body scrollbar
|
||||||
|
void setScrollBarWidth(const int& scrollbar_width);
|
||||||
|
|
||||||
///refresh position and dimension and reinitialize elemenatary properties
|
///refresh position and dimension and reinitialize elemenatary properties
|
||||||
void Refresh(){initCCWItems();};
|
void Refresh(){initCCWItems();};
|
||||||
|
|
||||||
///paint all window items, this overwriting paint() from CComponentsForm
|
///paint all window items, this overwriting paint() from CComponentsForm
|
||||||
virtual void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
|
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
|
||||||
};
|
};
|
||||||
|
|
||||||
class CComponentsWindowMax : public CComponentsWindow
|
class CComponentsWindowMax : public CComponentsWindow
|
||||||
|
@@ -49,6 +49,7 @@ CComponentsItem::CComponentsItem(CComponentsForm* parent)
|
|||||||
cc_item_index = CC_NO_INDEX;
|
cc_item_index = CC_NO_INDEX;
|
||||||
cc_item_enabled = true;
|
cc_item_enabled = true;
|
||||||
cc_item_selected = false;
|
cc_item_selected = false;
|
||||||
|
cc_page_number = 0;
|
||||||
initParent(parent);
|
initParent(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class CComponentsForm;
|
class CComponentsForm;
|
||||||
|
class CComponentsScrollBar;
|
||||||
|
|
||||||
///cc item types
|
///cc item types
|
||||||
typedef enum
|
typedef enum
|
||||||
@@ -60,6 +61,7 @@ typedef enum
|
|||||||
CC_ITEMTYPE_BUTTON_YELLOW,
|
CC_ITEMTYPE_BUTTON_YELLOW,
|
||||||
CC_ITEMTYPE_BUTTON_BLUE,
|
CC_ITEMTYPE_BUTTON_BLUE,
|
||||||
CC_ITEMTYPE_SLIDER,
|
CC_ITEMTYPE_SLIDER,
|
||||||
|
CC_ITEMTYPE_FRM_SCROLLBAR,
|
||||||
|
|
||||||
CC_ITEMTYPES
|
CC_ITEMTYPES
|
||||||
}CC_ITEMTYPES_T;
|
}CC_ITEMTYPES_T;
|
||||||
|
@@ -84,6 +84,7 @@ CTestMenu::CTestMenu()
|
|||||||
button = NULL;
|
button = NULL;
|
||||||
clock = clock_r = NULL;
|
clock = clock_r = NULL;
|
||||||
text_ext = NULL;
|
text_ext = NULL;
|
||||||
|
scrollbar = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTestMenu::~CTestMenu()
|
CTestMenu::~CTestMenu()
|
||||||
@@ -102,6 +103,7 @@ CTestMenu::~CTestMenu()
|
|||||||
delete clock_r;
|
delete clock_r;
|
||||||
delete chnl_pic;
|
delete chnl_pic;
|
||||||
delete text_ext;
|
delete text_ext;
|
||||||
|
delete scrollbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int test_pos[4] = { 130, 192, 282, 360 };
|
static int test_pos[4] = { 130, 192, 282, 360 };
|
||||||
@@ -566,6 +568,25 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey)
|
|||||||
footer->hide();
|
footer->hide();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
else if (actionKey == "scrollbar"){
|
||||||
|
if (scrollbar == NULL)
|
||||||
|
scrollbar = new CComponentsScrollBar(50, 100, 20, 400, 1);
|
||||||
|
|
||||||
|
if (scrollbar->isPainted()){
|
||||||
|
if (scrollbar->getMarkID() == scrollbar->getSegmentCount()){
|
||||||
|
scrollbar->hide();
|
||||||
|
scrollbar->setSegmentCount(scrollbar->getSegmentCount()+1);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
scrollbar->setMarkID(scrollbar->getMarkID()+1);
|
||||||
|
scrollbar->paint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
scrollbar->paint();
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
else if (actionKey == "iconform"){
|
else if (actionKey == "iconform"){
|
||||||
if (iconform == NULL)
|
if (iconform == NULL)
|
||||||
iconform = new CComponentsIconForm();
|
iconform = new CComponentsIconForm();
|
||||||
@@ -607,8 +628,9 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey)
|
|||||||
if (window == NULL){
|
if (window == NULL){
|
||||||
window = new CComponentsWindow();
|
window = new CComponentsWindow();
|
||||||
window->setWindowCaption("|.....................|");
|
window->setWindowCaption("|.....................|");
|
||||||
window->setDimensionsAll(50, 50, 1000, 500);
|
window->setDimensionsAll(50, 50, 500, 500);
|
||||||
window->setWindowIcon(NEUTRINO_ICON_INFO);
|
window->setWindowIcon(NEUTRINO_ICON_INFO);
|
||||||
|
window->setShadowOnOff(true);
|
||||||
|
|
||||||
CComponentsShapeCircle *c10 = new CComponentsShapeCircle(0, 0, 28);
|
CComponentsShapeCircle *c10 = new CComponentsShapeCircle(0, 0, 28);
|
||||||
CComponentsShapeCircle *c11 = new CComponentsShapeCircle(0, CC_APPEND, 28);
|
CComponentsShapeCircle *c11 = new CComponentsShapeCircle(0, CC_APPEND, 28);
|
||||||
@@ -624,19 +646,37 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey)
|
|||||||
window->addWindowItem(c11);
|
window->addWindowItem(c11);
|
||||||
window->addWindowItem(c12);
|
window->addWindowItem(c12);
|
||||||
window->addWindowItem(c13);
|
window->addWindowItem(c13);
|
||||||
|
|
||||||
|
CComponentsShapeCircle *c14 = new CComponentsShapeCircle(20, 20, 100);
|
||||||
|
c14->setColorBody(COL_RED);
|
||||||
|
c14->setPageNumber(1);
|
||||||
|
window->addWindowItem(c14);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
window->setWindowIcon(NEUTRINO_ICON_LOCK);
|
window->setWindowIcon(NEUTRINO_ICON_LOCK);
|
||||||
window->setWindowCaption("Test");
|
window->setWindowCaption("Test");
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
|
if (!window->isPainted()){
|
||||||
|
window->paint(); //if no other page has been defined, 1st page always painted
|
||||||
if (!window->isPainted())
|
}
|
||||||
window->paint();
|
else{
|
||||||
else
|
#endif //or paint direct a defined page
|
||||||
|
if (window->getCurrentPage() == 1)
|
||||||
|
window->paintPage(0);
|
||||||
|
else
|
||||||
|
window->paintPage(1);
|
||||||
|
#if 0
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
else if (actionKey == "window_close"){
|
||||||
|
if (window){
|
||||||
window->hide();
|
window->hide();
|
||||||
|
delete window;
|
||||||
|
window = NULL;
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
else if (actionKey == "running_clock"){
|
else if (actionKey == "running_clock"){
|
||||||
@@ -754,7 +794,9 @@ void CTestMenu::showCCTests(CMenuWidget *widget)
|
|||||||
widget->addItem(new CMenuForwarder("Footer", true, NULL, this, "footer"));
|
widget->addItem(new CMenuForwarder("Footer", true, NULL, this, "footer"));
|
||||||
widget->addItem(new CMenuForwarder("Icon-Form", true, NULL, this, "iconform"));
|
widget->addItem(new CMenuForwarder("Icon-Form", true, NULL, this, "iconform"));
|
||||||
widget->addItem(new CMenuForwarder("Window", true, NULL, this, "window"));
|
widget->addItem(new CMenuForwarder("Window", true, NULL, this, "window"));
|
||||||
|
widget->addItem(new CMenuForwarder("Window-Close", true, NULL, this, "window_close"));
|
||||||
widget->addItem(new CMenuForwarder("Text-Extended", true, NULL, this, "text_ext"));
|
widget->addItem(new CMenuForwarder("Text-Extended", true, NULL, this, "text_ext"));
|
||||||
|
widget->addItem(new CMenuForwarder("Scrollbar", true, NULL, this, "scrollbar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTestMenu::showHWTests(CMenuWidget *widget)
|
void CTestMenu::showHWTests(CMenuWidget *widget)
|
||||||
|
@@ -53,6 +53,7 @@ class CTestMenu : public CMenuTarget
|
|||||||
CComponentsFrmClock *clock ,*clock_r;
|
CComponentsFrmClock *clock ,*clock_r;
|
||||||
CComponentsChannelLogo* chnl_pic;
|
CComponentsChannelLogo* chnl_pic;
|
||||||
CComponentsExtTextForm* text_ext;
|
CComponentsExtTextForm* text_ext;
|
||||||
|
CComponentsScrollBar* scrollbar;
|
||||||
int width, selected;
|
int width, selected;
|
||||||
|
|
||||||
int showTestMenu();
|
int showTestMenu();
|
||||||
|
Reference in New Issue
Block a user