diff --git a/configure.ac b/configure.ac index ccab584ab..645f97031 100644 --- a/configure.ac +++ b/configure.ac @@ -395,6 +395,7 @@ data/icons/buttons/Makefile data/icons/filetypes/Makefile data/icons/headers/Makefile data/icons/hints/Makefile +data/icons/hourglass/Makefile data/icons/locale/Makefile data/icons/movieplayer/Makefile data/icons/radar/Makefile diff --git a/data/icons/Makefile.am b/data/icons/Makefile.am index b73f283c1..31cbfe22c 100644 --- a/data/icons/Makefile.am +++ b/data/icons/Makefile.am @@ -3,6 +3,7 @@ SUBDIRS = \ filetypes \ headers \ hints \ + hourglass \ locale \ movieplayer \ radar \ diff --git a/data/icons/hourglass/Makefile.am b/data/icons/hourglass/Makefile.am new file mode 100644 index 000000000..776de78d1 --- /dev/null +++ b/data/icons/hourglass/Makefile.am @@ -0,0 +1,10 @@ +installdir = $(ICONSDIR) + +install_DATA = \ + hourglass0.png \ + hourglass1.png \ + hourglass2.png \ + hourglass3.png \ + hourglass4.png \ + hourglass5.png \ + hourglass6.png diff --git a/data/icons/hourglass/hourglass.xcf b/data/icons/hourglass/hourglass.xcf new file mode 100644 index 000000000..bb12c12e8 Binary files /dev/null and b/data/icons/hourglass/hourglass.xcf differ diff --git a/data/icons/hourglass/hourglass0.png b/data/icons/hourglass/hourglass0.png new file mode 100644 index 000000000..f60ecabf2 Binary files /dev/null and b/data/icons/hourglass/hourglass0.png differ diff --git a/data/icons/hourglass/hourglass1.png b/data/icons/hourglass/hourglass1.png new file mode 100644 index 000000000..ef5adaad6 Binary files /dev/null and b/data/icons/hourglass/hourglass1.png differ diff --git a/data/icons/hourglass/hourglass2.png b/data/icons/hourglass/hourglass2.png new file mode 100644 index 000000000..e747b42af Binary files /dev/null and b/data/icons/hourglass/hourglass2.png differ diff --git a/data/icons/hourglass/hourglass3.png b/data/icons/hourglass/hourglass3.png new file mode 100644 index 000000000..f87595a84 Binary files /dev/null and b/data/icons/hourglass/hourglass3.png differ diff --git a/data/icons/hourglass/hourglass4.png b/data/icons/hourglass/hourglass4.png new file mode 100644 index 000000000..ad0094f5c Binary files /dev/null and b/data/icons/hourglass/hourglass4.png differ diff --git a/data/icons/hourglass/hourglass5.png b/data/icons/hourglass/hourglass5.png new file mode 100644 index 000000000..08ee8371e Binary files /dev/null and b/data/icons/hourglass/hourglass5.png differ diff --git a/data/icons/hourglass/hourglass6.png b/data/icons/hourglass/hourglass6.png new file mode 100644 index 000000000..bb8fd7775 Binary files /dev/null and b/data/icons/hourglass/hourglass6.png differ diff --git a/src/gui/test_menu.cpp b/src/gui/test_menu.cpp index 1d8f77c65..6d600ad97 100644 --- a/src/gui/test_menu.cpp +++ b/src/gui/test_menu.cpp @@ -60,6 +60,7 @@ #include "widget/msgbox.h" #include "widget/progresswindow.h" #include "widget/termwindow.h" +#include "widget/hourglass.h" #include #include #include @@ -1119,8 +1120,19 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey) showRecords(); return res; } - - + else if (actionKey == "hourglass"){ + CHourGlass hg(20, 20); + hg.paint(); + sleep(10); + hg.hide(); + return res; + } + else if (actionKey == "hourglass_proc"){ + CHourGlassProc proc(20, 20, sigc::mem_fun(*this, &CTestMenu::showRecords)); + proc.exec(); + return res; + } + return showTestMenu(); } @@ -1250,6 +1262,10 @@ int CTestMenu::showTestMenu() CKeyboardInput input("Text input", &input_txt, 30, NULL, NULL, "Test"); w_test.addItem(new CMenuForwarder("Text input", true, NULL, &input)); + //hourglass + w_test.addItem(new CMenuForwarder("Hourglass", true, NULL, this, "hourglass")); + w_test.addItem(new CMenuForwarder("Exec process with hourglass!", true, NULL, this, "hourglass_proc")); + //rate banner w_test.addItem(new CMenuForwarder("Rate banner", true, NULL, this, "rate_banner")); diff --git a/src/gui/widget/Makefile.am b/src/gui/widget/Makefile.am index 3c0e896c9..06359a47d 100644 --- a/src/gui/widget/Makefile.am +++ b/src/gui/widget/Makefile.am @@ -22,6 +22,7 @@ libneutrino_gui_widget_a_SOURCES = \ colorchooser.cpp \ helpbox.cpp \ hintbox.cpp \ + hourglass.cpp \ keychooser.cpp \ keyboard_input.cpp \ listbox.cpp \ diff --git a/src/gui/widget/hintbox.cpp b/src/gui/widget/hintbox.cpp index 88dce77a0..d64b3259b 100644 --- a/src/gui/widget/hintbox.cpp +++ b/src/gui/widget/hintbox.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #define MSG_FONT g_Font[SNeutrinoSettings::FONT_TYPE_MESSAGE_TEXT] @@ -495,9 +496,34 @@ int ShowHintS(const char * const Text, int timeout, bool show_background) { int res = messages_return::none; CHint hint(Text, show_background); + CHourGlass hg(CFrameBuffer::getInstance()->getScreenX() + OFFSET_INNER_MID, CFrameBuffer::getInstance()->getScreenY()); hint.setTimeOut(timeout, false); + hint.paint(); + hg.paint(); res = hint.exec(); + hg.hide(); + hint.hide(); + + return res; +} + +int ShowHintS(const char * const Text, const sigc::slot &Slot, int timeout, bool show_background) +{ + int res = messages_return::none; + + sigc::signal OnCall; + OnCall.connect(Slot); + + CHint hint(Text, show_background); + CHourGlass hg(CFrameBuffer::getInstance()->getScreenX() + OFFSET_INNER_MID, CFrameBuffer::getInstance()->getScreenY()); + hint.setTimeOut(timeout, false); + + hint.paint(); + hg.paint(); + OnCall(); + res = hint.exec(); + hg.hide(); hint.hide(); return res; @@ -513,22 +539,6 @@ int ShowHintS(const std::string& Text, int timeout, bool show_background) return ShowHintS(Text.c_str(), timeout, show_background); } -int ShowHintS(const char * const Text, const sigc::slot &Slot, int timeout, bool show_background) -{ - int res = messages_return::none; - - sigc::signal OnCall; - OnCall.connect(Slot); - CHint hint(Text, show_background); - hint.setTimeOut(timeout, false); - hint.paint(); - OnCall(); - res = hint.exec(); - hint.hide(); - - return res; -} - int ShowHintS(const neutrino_locale_t Text, const sigc::slot &Slot, int timeout, bool show_background) { return ShowHintS(g_Locale->getText(Text), Slot, timeout, show_background); diff --git a/src/gui/widget/hintbox.h b/src/gui/widget/hintbox.h index d5a84a522..793b8f982 100644 --- a/src/gui/widget/hintbox.h +++ b/src/gui/widget/hintbox.h @@ -434,10 +434,10 @@ int ShowHintS(const std::string &Text, int timeout = HINTBOX_DEFAULT_TIMEOUT, bo * @li expects sigc::slot * @li example: * @li sigc::slot sl = sigc::mem_fun(g_Plugins, &CPlugins::loadPlugins);\n - * ShowHintS(LOCALE_SERVICEMENU_GETPLUGINS_HINT, 1, true, &sl); + * ShowHintS(LOCALE_SERVICEMENU_GETPLUGINS_HINT, sl, 1); * @li or use a function with parameter(s): * sigc::slot sl = sigc::bind(sigc::mem_fun(*this, &CMyClass::foo), arg1, arg2, arg3, arg4);\n - * ShowHintS(LOCALE_SERVICEMENU_GETPLUGINS_HINT, 1, true, &sl); + * ShowHintS(LOCALE_SERVICEMENU_GETPLUGINS_HINT, sl, 1); * @param[in] timeout * @li optional: expects type int as seconds, default = HINTBOX_DEFAULT_TIMEOUT (get from settings) * @param[in] show_background diff --git a/src/gui/widget/hourglass.cpp b/src/gui/widget/hourglass.cpp new file mode 100644 index 000000000..f17d9c637 --- /dev/null +++ b/src/gui/widget/hourglass.cpp @@ -0,0 +1,138 @@ +/* + Based up Neutrino-GUI - Tuxbox-Project + Copyright (C) 2001 by Steffen Hehn 'McClean' + + Hourglass, provides an hourglass/snakeloader function to visualize running processes. + Copyright (C) 2021, 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 . +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "hourglass.h" + +#include + +#include +#include +#include + +#define MAX_IMAGES 24 + +CHourGlass::CHourGlass( const int x_pos, + const int y_pos, + const int w, + const int h, + const std::string& image_basename, + const int64_t& interval, + CComponentsForm *parent, + int shadow_mode, + fb_pixel_t color_frame, + fb_pixel_t color_body, + fb_pixel_t color_shadow) : CComponentsShapeSquare(x_pos, y_pos, w, h, parent, shadow_mode, color_frame, color_body, color_shadow) +{ + cc_item_type.name ="wg_hourglass"; + + hg_image_basename = image_basename; + cc_bg_image = cc_bg_image_old = cc_bg_sel_image = cc_bg_sec_image = ""; + + initImageFiles(); + + hg_file_num = 0; + hg_interval = interval; + hg_timer = new CComponentsTimer(hg_interval); + hg_timer->OnTimer.connect(sigc::bind(sigc::mem_fun(*this, &CHourGlass::paint), true)); +} + +CHourGlass::~CHourGlass() +{ + delete hg_timer; + hg_timer = NULL; +} + +void CHourGlass::initImageFiles() +{ + std::string path = ""; + std::string filename = ""; + hg_img_files.clear(); + + for(int i = 0; i <= MAX_IMAGES; i++) + { + filename = hg_image_basename; + filename += to_string(i); + path = frameBuffer->getIconPath(filename, "png"); + if (file_exists(path)) + hg_img_files.push_back(filename); + else + continue; + } +} + +void CHourGlass::paint(const bool &do_save_bg) +{ + if (hg_img_files.empty()) + return; + + if (hg_file_num > hg_img_files.size()-1) + hg_file_num = 0; + + cc_bg_image = frameBuffer->getIconPath(hg_img_files.at(hg_file_num), "png"); + + hide(); + + if (!hg_timer->isRun()) + hg_timer->startTimer(); + else + paintInit(do_save_bg); + + hg_file_num ++; +} + + +CHourGlassProc::CHourGlassProc( const int x_pos, + const int y_pos, + const sigc::slot &Slot, + const int w, + const int h, + const std::string& image_basename, + const int64_t& interval, + CComponentsForm *parent, + int shadow_mode, + fb_pixel_t color_frame, + fb_pixel_t color_body, + fb_pixel_t color_shadow) : CHourGlass(x_pos, y_pos, w, h, image_basename, interval, parent, shadow_mode, color_frame, color_body, color_shadow) +{ + cc_item_type.name ="wg_hourglass_proc"; + + OnRun.connect(Slot); +} + +void CHourGlassProc::paint(const bool &do_save_bg) +{ + CHourGlass::paint(do_save_bg); +} + +int CHourGlassProc::exec() +{ + paint(true); + OnRun(); + hide(); + + return messages_return::handled; +} diff --git a/src/gui/widget/hourglass.h b/src/gui/widget/hourglass.h new file mode 100644 index 000000000..cf5a9c226 --- /dev/null +++ b/src/gui/widget/hourglass.h @@ -0,0 +1,140 @@ +/* + Based up Neutrino-GUI - Tuxbox-Project + Copyright (C) 2001 by Steffen Hehn 'McClean' + + Hourglass, provides an hourglass/snakeloader function to visualize running processes. + Copyright (C) 2021, 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 __HOURGLASS_H__ +#define __HOURGLASS_H__ + +#include +#include + +//! CHourglass shows a small image chain with timed order to visualize running processes or breaks. +/*! + CHourglass shows only a timer controlled image chain, CHourglassProc will run an additional process. + */ + +class CHourGlass : public CComponentsShapeSquare +{ + private: + std::string hg_image_basename; + std::vector hg_img_files; + int64_t hg_interval; + CComponentsTimer* hg_timer; + size_t hg_file_num; + + void initImageFiles(); + public: + /**CHourGlass Constructor + * @param[in] x_pos + * @li expects type int, x position on screen + * @param[in] y_pos + * @li expects type int, y position on screen + * @param[in] w + * @li optional: expects type int, defines box width, default value = 48 + * @param[in] h + * @li optional: expects type int, defines box height, default value = 48 + * @param[in] image_basename + * @li optional: expects type std::string, basename as name template for the image set, default = "hourglass" + * The images should have the png, format recommended dimensions are 48x48px, respectively the same values for width and height (see: arguments w and h), + * Different dimensions than arguments cause scaling. + * Filenames must have a digit suffix e.g: 0.png ... 3.png + * The max count of images are defined in MAX_IMAGES. + * Images must be stored as usual inside the defined icon directories. + * @param[in] interval + * @li optional: expects type int64_t, defines paint interval, default = 84ms + * @param[in] parent + * @li optional: expects type CComponentsForm, as a parent container in which this object is embedded, default = NULL (stand alone) + * @param[in] shadow_mode + * @li optional: expects type int, defines the shadow mode of object, default = CC_SHADOW_OFF (no shadow) + * @param[in] color_frame + * @li optional: expects type int, defines the frame color of object, default = COL_FRAME_PLUS_0 + * @param[in] color_body + * @li optional: expects type int, defines the body color of object, default = COL_MENUCONTENT_PLUS_0 + * NOTE: body background is already defined with the image_basename, pure body will only paint if no image is available. + * @param[in] color_shadow + * @li optional: expects type int, defines the shadow color of object, default = COL_SHADOW_PLUS_0 + + * @see class CComponentsShapeSquare() + */ + CHourGlass( const int x_pos, + const int y_pos, + const int w = 48, + const int h = 48, + const std::string& image_basename = "hourglass", + const int64_t& interval = 84, + CComponentsForm *parent = NULL, + int shadow_mode = CC_SHADOW_OFF, + fb_pixel_t color_frame = COL_FRAME_PLUS_0, + fb_pixel_t color_body = COL_MENUCONTENT_PLUS_0, + fb_pixel_t color_shadow = COL_SHADOW_PLUS_0); + + virtual ~CHourGlass(); + + void paint(const bool &do_save_bg = CC_SAVE_SCREEN_YES); +}; + +class CHourGlassProc : public CHourGlass +{ + private: + sigc::signal OnRun; + + public: + /**CHourGlassProc Constructor + * @see CHourGlass() for other parameters + * @li CHourGlassProc() have only one additional parameter, see as follows: + * @param[in] Slot + * @li expects sigc::slot + * @li example: + * @li sigc::slot sl = sigc::mem_fun(g_Plugins, &CPlugins::loadPlugins);\n + * CHourGlassProc proc(20, 20, sl); + * int ret = proc.exec(); + * @li or use a function with parameter(s): + * sigc::slot sl = sigc::bind(sigc::mem_fun(*this, &CMyClass::foo), arg1, arg2, arg3, arg4);\n + * CHourGlassProc proc(20, 20, sl); + * int ret = proc.exec(); + * @see CTestMenu for more examples. + * + * @see class CComponentsShapeSquare(), CHourGlass() + */ + CHourGlassProc( const int x_pos, + const int y_pos, + const sigc::slot &Slot, + const int w = 48, + const int h = 48, + const std::string& image_basename = "hourglass", + const int64_t& interval = 84, + CComponentsForm *parent = NULL, + int shadow_mode = CC_SHADOW_OFF, + fb_pixel_t color_frame = COL_FRAME_PLUS_0, + fb_pixel_t color_body = COL_MENUCONTENT_PLUS_0, + fb_pixel_t color_shadow = COL_SHADOW_PLUS_0); + + virtual ~CHourGlassProc(){}; + + void paint(const bool &do_save_bg = CC_SAVE_SCREEN_YES); + + /// paint and execute process at once, return value = messages_return::handled + int exec(); +}; + +#endif //__HOURGLASS_H__