From 52aa0fb9a1745bd7919c42a37ba48f6bf77e2984 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 19 Dec 2015 19:58:23 +0100 Subject: Make sure that the button is drawn in the center of it's client area. --- plugingui/button.cc | 12 ++++++++---- plugingui/button.h | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/plugingui/button.cc b/plugingui/button.cc index f547cba..a3dd435 100644 --- a/plugingui/button.cc +++ b/plugingui/button.cc @@ -110,6 +110,9 @@ void Button::repaintEvent(RepaintEvent* repaintEvent) p.clear(); + int padTop = 3; + int padLeft = 0; + int w = width(); int h = height(); if(w == 0 || h == 0) @@ -119,16 +122,17 @@ void Button::repaintEvent(RepaintEvent* repaintEvent) switch(draw_state) { case up: - p.drawBox(0, 0, box_up, w, h); + p.drawBox(padLeft, padTop, box_up, w - padLeft, h - padTop); break; case down: - p.drawBox(0, 0, box_down, w, h); + p.drawBox(padLeft, padTop, box_down, w - padLeft, h - padTop); break; } p.setColour(Colour(0.1)); - p.drawText(width()/2-(text.length()*3)+(draw_state==up?0:1), - height()/2+5+1+(draw_state==up?0:1), font, text, true); + p.drawText(width()/2-(text.length()*3)+(draw_state==up?0:1) + (padLeft / 2), + height()/2+5+1+(draw_state==up?0:1) + (padTop / 2), font, text, + true); } void Button::setText(const std::string& text) diff --git a/plugingui/button.h b/plugingui/button.h index e5de6f1..f42dc99 100644 --- a/plugingui/button.h +++ b/plugingui/button.h @@ -58,7 +58,7 @@ protected: virtual void mouseEnterEvent() override; private: - bool in_button; + bool in_button{false}; Painter::Box box_up; Painter::Box box_down; @@ -72,8 +72,8 @@ private: Font font{":fontemboss.png"}; - state_t draw_state; - state_t button_state; + state_t draw_state{up}; + state_t button_state{up}; }; } // GUI:: -- cgit v1.2.3