From e7fd59b84c87dbc73dfc703c5451a1edf21b75ab Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Mon, 7 Dec 2020 23:28:52 +0100 Subject: [PATCH] cc_frm_slider: rework slider slider handling Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/5266f88e34d4765ddd88f1ba80c89f654baaf3fb Author: Thilo Graf Date: 2020-12-07 (Mon, 07 Dec 2020) --- data/icons/slider/Makefile.am | 1 + data/icons/slider/slider_body.png | Bin 132 -> 187 bytes data/icons/slider/slider_body_progress.png | Bin 0 -> 228 bytes src/gui/components/cc_frm_slider.cpp | 140 +++++++++++---------- src/gui/components/cc_frm_slider.h | 21 ++-- src/gui/widget/icons.h | 1 + src/system/settings.h | 3 + 7 files changed, 88 insertions(+), 78 deletions(-) create mode 100644 data/icons/slider/slider_body_progress.png diff --git a/data/icons/slider/Makefile.am b/data/icons/slider/Makefile.am index 57d50c0f9..72632c5d3 100644 --- a/data/icons/slider/Makefile.am +++ b/data/icons/slider/Makefile.am @@ -4,6 +4,7 @@ install_DATA = \ slider_alpha.png \ slider_blue.png \ slider_body.png \ + slider_body_progress.png \ slider_green.png \ slider_inactive.png \ slider_red.png diff --git a/data/icons/slider/slider_body.png b/data/icons/slider/slider_body.png index 3ba8dd13e2f0af70f352757930df078de8633763..aa767ad463495f4fe4cd04d4dd0a8e439e80cf9b 100644 GIT binary patch literal 187 zcmeAS@N?(olHy`uVBq!ia0vp^j6f{L!3JU-`?d;5v7|ftIx;Y9?C1WI$O`1MC3(BM zF#HF>1$&oI28wVNctjR6FmMZlFeAgPITAoY_7YEDSN2DY%wo*)Y|P@#Kp_iH7sn8e z>#fH(@*ZH|V0Jt$%8h3N2sYwVXgx>x4 aoVD?Y;+p3*HYPwb7(8A5T-G@yGywo!_%*fw literal 132 zcmeAS@N?(olHy`uVBq!ia0vp^6+q0*#0(@)?pde@q<8{+LR^9Lv}x1+|NnpD#0dcr zkNZGAV@Z%-FoVOh8)-m}nx~6nh{V+7gasTOZI2ike=Jp&IP(87qq)WuwFL9)S~dx+ csSBAHbbZ>MZ*E&K1E_<+)78&qol`;+07oGxod5s; diff --git a/data/icons/slider/slider_body_progress.png b/data/icons/slider/slider_body_progress.png new file mode 100644 index 0000000000000000000000000000000000000000..13fb4deb5fdeb70316571a18ce652db223b0e813 GIT binary patch literal 228 zcmeAS@N?(olHy`uVBq!ia0vp^j6f{L!3JU-`?d;5v7|ftIx;Y9?C1WI$O`1MC3(BM zF#HF>1$&oI28wVNctjR6FmMZlFeAgPITAoY_7YEDSN2DY%wn7>zR$&UfkKI%E{-7_ z*I5rb@--`nxL%xXu4!)(cHpo6YRA>48z(Ol@eo$GZNFYwceS5)tGnCZor`we3$!hp zVlS$@ba9MSl$Z1S`>jpo8ddF+$~E}f((*NU+V0Gl&?FVdQ&MBb@0MbxKh5!Hn literal 0 HcmV?d00001 diff --git a/src/gui/components/cc_frm_slider.cpp b/src/gui/components/cc_frm_slider.cpp index 8284f1dc8..510f41780 100644 --- a/src/gui/components/cc_frm_slider.cpp +++ b/src/gui/components/cc_frm_slider.cpp @@ -24,6 +24,7 @@ #include #include #include "cc_frm_slider.h" +#include using namespace std; @@ -31,7 +32,6 @@ using namespace std; //sub class CComponentsSlider CComponentsSlider::CComponentsSlider( const int& x_pos, const int& y_pos, const int& w, const int& h, const int& current_value, - const int& min_value, const int& max_value, CComponentsForm *parent, int shadow_mode, @@ -43,76 +43,31 @@ CComponentsSlider::CComponentsSlider( const int& x_pos, const int& y_pos, const cc_item_type.name = "cc_slider"; corner_rad = 0; - x = x_pos; - y = y_pos; - width = w; - height = h; + x = cc_xr = x_old = x_pos; + y = cc_yr = y_old = y_pos; + width = width_old = w; + height = height_old = h; csl_current_value = current_value; - csl_min_value = min_value; csl_max_value = max_value; shadow = shadow_mode; col_frame = color_frame; - col_body = color_body; + col_body_std = color_body; col_shadow = color_shadow; - csl_body_obj = NULL; csl_slider_obj = NULL; - csl_body_icon = NEUTRINO_ICON_SLIDER_BODY; - csl_slider_icon =NEUTRINO_ICON_SLIDER_INACTIVE; + setBodyBGImageName(NEUTRINO_ICON_SLIDER_BODY); + csl_slider_icon = frameBuffer->getIconPath(NEUTRINO_ICON_SLIDER_INACTIVE); initCCSlItems(); initParent(parent); } -//set current value -void CComponentsSlider::setValuePos(const int& current_value) +CComponentsSlider::~CComponentsSlider() { - csl_current_value = current_value; - if (csl_slider_obj->isPicPainted()) - csl_slider_obj->hide(); - initCCSlItems(); -} -//set current scale values -void CComponentsSlider::setValueScale(const int& min_value, const int& max_value) -{ - csl_min_value = min_value; - csl_max_value = max_value; - initCCSlItems(); -} - -//init slider body object and add to container -void CComponentsSlider::initCCSlBody() -{ - if (!csl_body_icon.empty()){ - if (csl_body_obj == NULL){ - csl_body_obj = new CComponentsPicture(0, 0, width-2*fr_thickness, 16, csl_body_icon); - csl_body_obj->setColorBody(this->col_body); //FIXME: Background handling during current instance of slider object - csl_body_obj->doPaintBg(true); - addCCItem(csl_body_obj); - } - else - csl_body_obj->setPicture(csl_body_icon); - } - else{ - printf("[CComponentsSlider] [%s] missing or undefinied slider body icon %s\n", __func__, csl_body_icon.c_str()); - return; - } - - //get first icon dimensions - int icon_w = csl_body_obj->getWidth(); - int icon_h = csl_body_obj->getHeight(); - - //position of icon default centered - int icon_x = width/2-icon_w/2; - int icon_y = height/2-icon_h/2; - - if (csl_body_obj){ - csl_body_obj->setDimensionsAll(icon_x, icon_y, icon_w, icon_h); - } } //init slider caption object and add to container @@ -120,34 +75,41 @@ void CComponentsSlider::initCCSlSlider() { if (!csl_slider_icon.empty()){ if (csl_slider_obj == NULL){ - csl_slider_obj = new CComponentsPicture(0, 0, csl_slider_icon); - csl_slider_obj->setColorBody(this->col_body); //FIXME: Background handling during current instance of slider object - csl_slider_obj->doPaintBg(true); - addCCItem(csl_slider_obj); + int icon_h, icon_w; + frameBuffer->getIconSize(csl_slider_icon.c_str(), &icon_w, &icon_h); //current size is required + csl_slider_obj = new CComponentsPicture(0, 0, icon_w, icon_h, csl_slider_icon, this); + csl_slider_obj->setColorBody(this->col_body_std); //FIXME: Background handling during current instance of slider object + csl_slider_obj->doPaintBg(false); + csl_slider_obj->enableSaveBg(); } else - csl_slider_obj->setPicture(csl_slider_icon); + csl_slider_obj->setPicture(frameBuffer->getIconPath(csl_slider_icon)); } else{ - printf("[CComponentsSlider] [%s] missing or undefinied slider icon %s\n", __func__, csl_slider_icon.c_str()); + dprintf(DEBUG_NORMAL, "[CComponentsSlider]\t[%s - %d]: \033[35m WARNING:\033[0m missing or undefinied slider icon %s\n", __func__, __LINE__, csl_slider_icon.c_str()); return; } + if (csl_current_value > csl_max_value) + dprintf(DEBUG_NORMAL, "[CComponentsSlider]\t[%s - %d]: \033[35m WARNING:\033[0m current slider value [%d] is larger than maximal value of slider scale [%d]\n", __func__, __LINE__, csl_current_value, csl_max_value); + //get first icon dimensions int slider_w = csl_slider_obj->getWidth(); - int slider_h = csl_slider_obj->getHeight(); //position of slider icon - int slider_x = csl_body_obj->getXPos() + (csl_body_obj->getWidth()-slider_w) * (abs(csl_min_value) + csl_current_value) / (abs(csl_min_value) + abs(csl_max_value)); - int slider_y = height/2-slider_h/2; + int slider_space = width - slider_w; + int slider_x = csl_current_value * slider_space/csl_max_value; + printf("[CComponentsSlider] [%s] csl_current_value = %d slider_x = %d csl_max_value = %d \n", __func__, csl_current_value, slider_x, csl_max_value); - if (csl_slider_obj) - csl_slider_obj->setDimensionsAll(slider_x, slider_y, slider_w, slider_h); + if (csl_slider_obj){ + printf("[CComponentsSlider] [%s] width = %d\n", __func__, width); + csl_slider_obj->setHeight(height, true); + csl_slider_obj->setXPos(slider_x); + } } void CComponentsSlider::initCCSlItems() { - initCCSlBody(); initCCSlSlider(); } @@ -166,3 +128,49 @@ void CComponentsSlider::setSliderIcon(const std::string &icon_name) // paintForm(do_save_bg); // } +void CComponentsSlider::paint(const bool &do_save_bg) +{ + //prepare items before paint + initCCSlItems(); + + //paint form contents + if (!is_painted) + paintForm(do_save_bg); + + if (is_painted) + paintMarker(); + +} + + +void CComponentsSlider::paintMarker() +{ + if(csl_slider_obj->isPicPainted()) + csl_slider_obj->hide(); +// //if (csl_slider_obj->getXPos()>0) +// PaintBoxRel(cc_xr, cc_yr, csl_slider_obj->getXPos(), height, COL_GREEN); + if(!csl_slider_obj->isPainted()) + csl_slider_obj->paint(); + +} + +//set current value +void CComponentsSlider::setValue(const int& current_value, bool enable_paint) +{ + if (csl_current_value == current_value) + return; + + csl_current_value = current_value; + initCCSlItems(); + + if(enable_paint) + paintMarker(); +} + +//set current scale values +void CComponentsSlider::setValueMax(const int& max_value) +{ + csl_max_value = max_value; + initCCSlItems(); +} + diff --git a/src/gui/components/cc_frm_slider.h b/src/gui/components/cc_frm_slider.h index 1c0d4c624..141091dea 100644 --- a/src/gui/components/cc_frm_slider.h +++ b/src/gui/components/cc_frm_slider.h @@ -40,43 +40,40 @@ class CComponentsSlider : public CComponentsForm { private: ///names of slider icons - std::string csl_body_icon, csl_slider_icon; + std::string csl_slider_icon; ///property: current value that should be displayed by slider button, see also setValuePos() int csl_current_value; - ///property: minimal scale value, see also setValueScale() - int csl_min_value; ///property: maximal scale value, see also setValueScale() int csl_max_value; ///object: image objects for slider button and body - CComponentsPicture *csl_body_obj, *csl_slider_obj; + CComponentsPicture *csl_slider_obj; + void paintMarker(); - ///init body image object - void initCCSlBody(); ///init slider image object void initCCSlSlider(); ///init all items at once void initCCSlItems(); public: - CComponentsSlider( const int& x_pos = 0, const int& y_pos = 0, const int& w = 120+16, const int& h = 32, + CComponentsSlider( const int& x_pos = 0, const int& y_pos = 0, const int& w = SLIDER_WIDHT, const int& h = SLIDER_HEIGHT, const int& current_value = 0, - const int& min_value = 0, const int& max_value = 100, CComponentsForm *parent = NULL, int shadow_mode = CC_SHADOW_OFF, fb_pixel_t& color_frame = COL_FRAME_PLUS_0, fb_pixel_t& color_body = COL_MENUHEAD_PLUS_0, fb_pixel_t& color_shadow = COL_SHADOW_PLUS_0); -// ~CComponentsSlider(); //inherited from CComponentsForm + virtual ~CComponentsSlider(); //inherited from CComponentsForm - void setValuePos(const int& current_value); - void setValueScale(const int& min_value, const int& max_value); + void setValue(const int& current_value, bool enable_paint = true); + int getValue(){return csl_current_value;} + void setValueMax(const int& max_value); void setSliderIcon(const std::string &icon_name); -// void paint(const bool &do_save_bg = CC_SAVE_SCREEN_YES); + void paint(const bool &do_save_bg = CC_SAVE_SCREEN_YES); }; #endif diff --git a/src/gui/widget/icons.h b/src/gui/widget/icons.h index 81cfea726..1b8425352 100644 --- a/src/gui/widget/icons.h +++ b/src/gui/widget/icons.h @@ -122,6 +122,7 @@ /* sliders */ #define NEUTRINO_ICON_SLIDER_BODY "slider_body" +#define NEUTRINO_ICON_SLIDER_BODY_PROGRESS "slider_body_progress" #define NEUTRINO_ICON_SLIDER_INACTIVE "slider_inactive" #define NEUTRINO_ICON_SLIDER_RED "slider_red" #define NEUTRINO_ICON_SLIDER_GREEN "slider_green" diff --git a/src/system/settings.h b/src/system/settings.h index b47ebf74b..aad1c4e66 100644 --- a/src/system/settings.h +++ b/src/system/settings.h @@ -1248,6 +1248,9 @@ const time_settings_struct_t handling_infobar_setting[SNeutrinoSettings::HANDLIN #define SIDEBAR_WIDTH CFrameBuffer::getInstance()->scale2Res(40) +#define SLIDER_HEIGHT CFrameBuffer::getInstance()->scale2Res(22) +#define SLIDER_WIDHT CFrameBuffer::getInstance()->scale2Res(120) + #define BIGFONT_FACTOR 1.5 struct SglobalInfo