diff --git a/src/gui/components/Makefile.am b/src/gui/components/Makefile.am index d18fc0cbe..8aec4d2ba 100644 --- a/src/gui/components/Makefile.am +++ b/src/gui/components/Makefile.am @@ -34,6 +34,7 @@ libneutrino_gui_components_a_SOURCES = \ cc_frm_ext_text.cpp \ cc_frm_icons.cpp \ cc_frm_signalbars.cpp \ + cc_frm_slider.cpp \ cc_frm_window.cpp \ cc_item.cpp \ cc_item_infobox.cpp \ diff --git a/src/gui/components/cc.h b/src/gui/components/cc.h index 7842a0c10..efae3aae5 100644 --- a/src/gui/components/cc.h +++ b/src/gui/components/cc.h @@ -46,6 +46,7 @@ Basic attributes and member functions for component sub classes #include "cc_frm_button.h" #include "cc_frm_clock.h" #include "cc_frm_signalbars.h" +#include "cc_frm_slider.h" diff --git a/src/gui/components/cc_frm_slider.cpp b/src/gui/components/cc_frm_slider.cpp new file mode 100644 index 000000000..52355e2be --- /dev/null +++ b/src/gui/components/cc_frm_slider.cpp @@ -0,0 +1,168 @@ +/* + 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, see . +*/ + +#include +#include +#include "cc_frm_slider.h" + +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, + bool has_shadow, + fb_pixel_t& color_frame, + fb_pixel_t& color_body, + fb_pixel_t& color_shadow) +{ + initVarSlider(x_pos, y_pos, w, h, current_value, min_value, max_value, has_shadow, color_frame, color_body, color_shadow); + initCCSlItems(); +} + + +void CComponentsSlider::initVarSlider( 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, + bool has_shadow, + fb_pixel_t& color_frame, + fb_pixel_t& color_body, + fb_pixel_t& color_shadow) +{ + cc_item_type = CC_ITEMTYPE_SLIDER; + corner_rad = 0; + + x = x_pos; + y = y_pos; + width = w; + height = h; + + csl_current_value = current_value; + csl_min_value = min_value; + csl_max_value = max_value; + + shadow = has_shadow; + col_frame = color_frame; + col_body = color_body; + col_shadow = color_shadow; + + csl_body_obj = NULL; + csl_slider_obj = NULL; + + csl_body_icon = NEUTRINO_ICON_VOLUMEBODY; + csl_slider_icon =NEUTRINO_ICON_VOLUMESLIDER2; +} + +//set current value +void CComponentsSlider::setValuePos(const int& current_value) +{ + 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, 0, height, csl_body_icon); + csl_body_obj->doPaintBg(false); + addCCItem(csl_body_obj); + } + }else{ + if (csl_body_obj){ + delete csl_body_obj; + csl_body_obj = NULL; + } + } + + //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); + csl_body_obj->setPictureAlign(CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER); + } +} + +//init slider caption object and add to container +void CComponentsSlider::initCCSlSlider() +{ + if (!csl_slider_icon.empty()){ + if (csl_slider_obj == NULL){ + csl_slider_obj = new CComponentsPicture(0, 0, 0, 0, csl_slider_icon); + csl_slider_obj->doPaintBg(false); + addCCItem(csl_slider_obj); + } + }else{ + if (csl_slider_obj){ + delete csl_slider_obj; + csl_slider_obj = NULL; + } + } + + //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() - slider_w/2 + csl_body_obj->getWidth() * (abs(csl_min_value) + csl_current_value) / (abs(csl_min_value) + abs(csl_max_value)); + int slider_y = height/2-slider_h/2; + + if (csl_slider_obj) + csl_slider_obj->setDimensionsAll(slider_x, slider_y, slider_w, slider_h); +} + +void CComponentsSlider::initCCSlItems() +{ + initCCSlBody(); + initCCSlSlider(); +} + +// void CComponentsSlider::paint(bool do_save_bg) +// { +// //prepare items before paint +// initCCSlItems(); +// +// //paint form contents +// paintForm(do_save_bg); +// } + diff --git a/src/gui/components/cc_frm_slider.h b/src/gui/components/cc_frm_slider.h new file mode 100644 index 000000000..9f6672f9d --- /dev/null +++ b/src/gui/components/cc_frm_slider.h @@ -0,0 +1,92 @@ +/* + 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, see . +*/ + +#ifndef __CC_FORM_SLIDER_H__ +#define __CC_FORM_SLIDER_H__ + + +#include +#include "cc_frm.h" + + +//! Sub class of CComponentsForm. Shows a slider. +/*! +Paint a simple slider on screen. +You can set default form parameters like position, size, colors etc. and additional values +to display current values with a slider icon. +*/ + +class CComponentsSlider : public CComponentsForm +{ + private: + ///names of slider icons + std::string csl_body_icon, 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; + + ///init body image object + void initCCSlBody(); + ///init slider image object + void initCCSlSlider(); + ///init all items at once + void initCCSlItems(); + + ///init all required variables + void initVarSlider( 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, + bool has_shadow, + fb_pixel_t& color_frame, + fb_pixel_t& color_body, + fb_pixel_t& color_shadow); + protected: + + + public: + CComponentsSlider( const int& x_pos = 1, const int& y_pos = 1, const int& w = 120+16, const int& h = 32, + const int& current_value = 0, + const int& min_value = 0, + const int& max_value = 100, + bool has_shadow = CC_SHADOW_OFF, + fb_pixel_t& color_frame = COL_MENUCONTENT_PLUS_6, + fb_pixel_t& color_body = COL_MENUHEAD_PLUS_0, + fb_pixel_t& color_shadow = COL_MENUCONTENTDARK_PLUS_0); +// ~CComponentsSlider(); //inherited from CComponentsForm + + void setValuePos(const int& current_value); + void setValueScale(const int& min_value, const int& max_value); + +// void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); +}; + +#endif diff --git a/src/gui/components/cc_types.h b/src/gui/components/cc_types.h index 5a5fb5fe9..89e85e3d1 100644 --- a/src/gui/components/cc_types.h +++ b/src/gui/components/cc_types.h @@ -56,6 +56,7 @@ typedef enum CC_ITEMTYPE_BUTTON_GREEN, CC_ITEMTYPE_BUTTON_YELLOW, CC_ITEMTYPE_BUTTON_BLUE, + CC_ITEMTYPE_SLIDER, CC_ITEMTYPES }CC_ITEMTYPES_T;