From 7c50c15ede76869489a94503fa22028180f41cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Thu, 7 Jun 2018 23:30:40 +0200 Subject: Add disabled visualization to powerbutton. --- plugingui/powerbutton.cc | 32 ++++++++++++++++++++++++++------ plugingui/powerbutton.h | 6 ++++++ plugingui/resources/bypass_button.png | Bin 1615 -> 2146 bytes 3 files changed, 32 insertions(+), 6 deletions(-) (limited to 'plugingui') diff --git a/plugingui/powerbutton.cc b/plugingui/powerbutton.cc index a91524f..36edc35 100644 --- a/plugingui/powerbutton.cc +++ b/plugingui/powerbutton.cc @@ -35,31 +35,51 @@ PowerButton::PowerButton(Widget* parent) : Toggle(parent) { } +void PowerButton::setEnabled(bool enabled) +{ + this->enabled = enabled; +} + void PowerButton::repaintEvent(RepaintEvent* repaintEvent) { Painter p(*this); - if(state) + // disabled + if(!enabled) { if(clicked) { - p.drawImage(0, 0, on_clicked); + p.drawImage(0, 0, disabled_clicked); } else { - p.drawImage(0, 0, on); + p.drawImage(0, 0, disabled); } + return; } - else + + // enabled and on + if(state) { if(clicked) { - p.drawImage(0, 0, off_clicked); + p.drawImage(0, 0, on_clicked); } else { - p.drawImage(0, 0, off); + p.drawImage(0, 0, on); } + return; + } + + // enabled and off + if(clicked) + { + p.drawImage(0, 0, off_clicked); + } + else + { + p.drawImage(0, 0, off); } } diff --git a/plugingui/powerbutton.h b/plugingui/powerbutton.h index 53f8d88..14dbeca 100644 --- a/plugingui/powerbutton.h +++ b/plugingui/powerbutton.h @@ -38,15 +38,21 @@ public: PowerButton(Widget* parent); virtual ~PowerButton() = default; + void setEnabled(bool enabled); + protected: // From Widget: virtual void repaintEvent(RepaintEvent* repaintEvent) override; + bool enabled = true; + private: Texture on{getImageCache(), ":resources/bypass_button.png", 32, 0, 16, 16}; Texture on_clicked{getImageCache(), ":resources/bypass_button.png", 48, 0, 16, 16}; Texture off{getImageCache(), ":resources/bypass_button.png", 0, 0, 16, 16}; Texture off_clicked{getImageCache(), ":resources/bypass_button.png", 16, 0, 16, 16}; + Texture disabled{getImageCache(), ":resources/bypass_button.png", 64, 0, 16, 16}; + Texture disabled_clicked{getImageCache(), ":resources/bypass_button.png", 80, 0, 16, 16}; }; } // GUI:: diff --git a/plugingui/resources/bypass_button.png b/plugingui/resources/bypass_button.png index f5399fb..e084d39 100644 Binary files a/plugingui/resources/bypass_button.png and b/plugingui/resources/bypass_button.png differ -- cgit v1.2.3