From ca384e485956059d5d427fbe07a7b2277c43680e Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 9 Nov 2015 21:47:15 +0100 Subject: Refactor ProgressBar. --- plugingui/plugingui.cc | 26 ++++----- plugingui/progressbar.cc | 136 +++++++++++++++++++++++++++-------------------- plugingui/progressbar.h | 49 +++++++++-------- 3 files changed, 114 insertions(+), 97 deletions(-) (limited to 'plugingui') diff --git a/plugingui/plugingui.cc b/plugingui/plugingui.cc index 007a0ff..5de74fb 100644 --- a/plugingui/plugingui.cc +++ b/plugingui/plugingui.cc @@ -93,7 +93,7 @@ void PluginGUI::handleMessage(Message *msg) progress->setProgress((float)ls->numer_of_files_loaded / (float)ls->number_of_files); if(ls->numer_of_files_loaded == ls->number_of_files) { - progress->setState(ProgressBar::green); + progress->setState(ProgressBarState::Green); } } break; @@ -102,9 +102,9 @@ void PluginGUI::handleMessage(Message *msg) LoadStatusMessageMidimap *ls = (LoadStatusMessageMidimap*)msg; progress2->setProgress(1); if(ls->success) { - progress2->setState(ProgressBar::green); + progress2->setState(ProgressBarState::Green); } else { - progress2->setState(ProgressBar::red); + progress2->setState(ProgressBarState::Red); } } break; @@ -114,18 +114,18 @@ void PluginGUI::handleMessage(Message *msg) lineedit->setText(settings->drumkitfile); if(settings->drumkit_loaded) { progress->setProgress(1); - progress->setState(ProgressBar::green); + progress->setState(ProgressBarState::Green); } else { progress->setProgress(0); - progress->setState(ProgressBar::blue); + progress->setState(ProgressBarState::Blue); } lineedit2->setText(settings->midimapfile); if(settings->midimap_loaded) { progress2->setProgress(1); - progress2->setState(ProgressBar::green); + progress2->setState(ProgressBarState::Green); } else { progress2->setProgress(0); - progress2->setState(ProgressBar::blue); + progress2->setState(ProgressBarState::Blue); } velocityCheck->setChecked(settings->enable_velocity_modifier); attackKnob->setValue(settings->velocity_modifier_weight); @@ -195,7 +195,7 @@ void PluginGUI::selectKitFile(const std::string& filename) config->save(); progress->setProgress(0); - progress->setState(ProgressBar::blue); + progress->setState(ProgressBarState::Blue); LoadDrumKitMessage *msg = new LoadDrumKitMessage(); msg->drumkitfile = drumkit; @@ -220,7 +220,7 @@ void PluginGUI::selectMapFile(const std::string& filename) /* if(gui->changeMidimapHandler) gui->changeMidimapHandler(gui->changeMidimapPtr, midimap.c_str()); - gui->progress2->setState(ProgressBar::green); + gui->progress2->setState(ProgressBarState::Green); */ } @@ -442,10 +442,10 @@ void PluginGUI::attackValueChanged(float value) #ifdef STANDALONE int i = value * 4; switch(i) { - case 0: progress->setState(ProgressBar::off); break; - case 1: progress->setState(ProgressBar::blue); break; - case 2: progress->setState(ProgressBar::green); break; - case 3: progress->setState(ProgressBar::red); break; + case 0: progress->setState(ProgressBarState::Off); break; + case 1: progress->setState(ProgressBarState::Blue); break; + case 2: progress->setState(ProgressBarState::Green); break; + case 3: progress->setState(ProgressBarState::Red); break; default: break; } #endif diff --git a/plugingui/progressbar.cc b/plugingui/progressbar.cc index f834fc4..a53aa40 100644 --- a/plugingui/progressbar.cc +++ b/plugingui/progressbar.cc @@ -26,83 +26,101 @@ */ #include "progressbar.h" -#include "painter.h" +namespace GUI { -GUI::ProgressBar::ProgressBar(GUI::Widget *parent) : GUI::Widget(parent) +ProgressBar::ProgressBar(Widget *parent) + : Widget(parent) { - bar_bg.left = new Image(":progress_back_l.png"); - bar_bg.right = new Image(":progress_back_r.png"); - bar_bg.center = new Image(":progress_back_c.png"); + bar_bg.left = new Image(":progress_back_l.png"); + bar_bg.right = new Image(":progress_back_r.png"); + bar_bg.center = new Image(":progress_back_c.png"); - bar_blue.left = new Image(":progress_front_blue_l.png"); - bar_blue.right = new Image(":progress_front_blue_r.png"); - bar_blue.center = new Image(":progress_front_blue_c.png"); + bar_blue.left = new Image(":progress_front_blue_l.png"); + bar_blue.right = new Image(":progress_front_blue_r.png"); + bar_blue.center = new Image(":progress_front_blue_c.png"); - bar_red.left = new Image(":progress_front_red_l.png"); - bar_red.right = new Image(":progress_front_red_r.png"); - bar_red.center = new Image(":progress_front_red_c.png"); + bar_red.left = new Image(":progress_front_red_l.png"); + bar_red.right = new Image(":progress_front_red_r.png"); + bar_red.center = new Image(":progress_front_red_c.png"); - bar_green.left = new Image(":progress_front_green_l.png"); - bar_green.right = new Image(":progress_front_green_r.png"); - bar_green.center = new Image(":progress_front_green_c.png"); + bar_green.left = new Image(":progress_front_green_l.png"); + bar_green.right = new Image(":progress_front_green_r.png"); + bar_green.center = new Image(":progress_front_green_c.png"); - state = blue; - _progress = .5; + state = ProgressBarState::Blue; + _progress = .5; } -void GUI::ProgressBar::setState(GUI::ProgressBar::state_t state) +ProgressBar::~ProgressBar() { - if(this->state != state) { - this->state = state; - repaintEvent(NULL); - } + delete bar_bg.left; + delete bar_bg.right; + delete bar_bg.center; + + delete bar_blue.left; + delete bar_blue.right; + delete bar_blue.center; + + delete bar_red.left; + delete bar_red.right; + delete bar_red.center; + + delete bar_green.left; + delete bar_green.right; + delete bar_green.center; } -float GUI::ProgressBar::progress() +void ProgressBar::setState(ProgressBarState state) { - return _progress; + if(this->state != state) + { + this->state = state; + repaintEvent(nullptr); + } } -void GUI::ProgressBar::setProgress(float progress) +float ProgressBar::progress() { - _progress = progress; - repaintEvent(NULL); + return _progress; } -void GUI::ProgressBar::repaintEvent(GUI::RepaintEvent *e) +void ProgressBar::setProgress(float progress) { - Painter p(*this); - - int max = width() * _progress; - - p.clear(); - - int brd = 4; - p.drawBar(0, 0, bar_bg, width(), height()); - - GUI::Painter::Bar *b = NULL; - switch(state) { - case red: b = &bar_red; break; - case green: b = &bar_green; break; - case blue: b = &bar_blue; break; - default: break; - } - if(b) p.drawBar(brd, 0, *b, max - 2*brd, height()); + _progress = progress; + repaintEvent(nullptr); } -#ifdef TEST_PROGRESSBAR -//Additional dependency files -//deps: -//Required cflags (autoconf vars may be used) -//cflags: -//Required link options (autoconf vars may be used) -//libs: -#include "test.h" - -TEST_BEGIN; - -// TODO: Put some testcode here (see test.h for usable macros). - -TEST_END; +void ProgressBar::repaintEvent(RepaintEvent *e) +{ + Painter p(*this); + + int max = width() * _progress; + + p.clear(); + + int brd = 4; + p.drawBar(0, 0, bar_bg, width(), height()); + + Painter::Bar* bar = nullptr; + switch(state) { + case ProgressBarState::Red: + bar = &bar_red; + break; + case ProgressBarState::Green: + bar = &bar_green; + break; + case ProgressBarState::Blue: + bar = &bar_blue; + break; + case ProgressBarState::Off: + bar = nullptr; + break; + } + + if(bar) + { + p.drawBar(brd, 0, *bar, max - 2 * brd, height()); + } +} -#endif/*TEST_PROGRESSBAR*/ +} // GUI:: diff --git a/plugingui/progressbar.h b/plugingui/progressbar.h index 9d08a9e..e5e567d 100644 --- a/plugingui/progressbar.h +++ b/plugingui/progressbar.h @@ -24,48 +24,47 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#ifndef __DRUMGIZMO_PROGRESSBAR_H__ -#define __DRUMGIZMO_PROGRESSBAR_H__ +#pragma once #include "widget.h" -#include - #include "guievent.h" #include "painter.h" namespace GUI { +enum class ProgressBarState +{ + Red, + Green, + Blue, + Off +}; + class ProgressBar : public Widget { public: - ProgressBar(Widget *parent); + ProgressBar(Widget *parent); + ~ProgressBar(); - float progress(); - void setProgress(float progress); + float progress(); + void setProgress(float progress); - typedef enum { - red, - green, - blue, - off - } state_t; - void setState(state_t state); + void setState(ProgressBarState state); - //protected: - virtual void repaintEvent(RepaintEvent *e); +protected: + // From Widget: + virtual void repaintEvent(RepaintEvent *e) override; private: - state_t state; + ProgressBarState state; - Painter::Bar bar_bg; + Painter::Bar bar_bg; - Painter::Bar bar_green; - Painter::Bar bar_blue; - Painter::Bar bar_red; - - float _progress; -}; + Painter::Bar bar_green; + Painter::Bar bar_blue; + Painter::Bar bar_red; + float _progress; }; -#endif/*__DRUMGIZMO_PROGRESSBAR_H__*/ +} // GUI:: -- cgit v1.2.3