1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /***************************************************************************
3 * button.cc
4 *
5 * Sun Oct 9 13:01:56 CEST 2011
6 * Copyright 2011 Bent Bisballe Nyeng
7 * deva@aasimon.org
8 ****************************************************************************/
9
10 /*
11 * This file is part of DrumGizmo.
12 *
13 * DrumGizmo is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU Lesser General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * DrumGizmo is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public License
24 * along with DrumGizmo; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 */
27 #include "button.h"
28
29 #include "painter.h"
30
31 #include <hugin.hpp>
32 #include <stdio.h>
33
34 namespace GUI
35 {
36
Button(Widget * parent)37 Button::Button(Widget* parent)
38 : ButtonBase(parent)
39 {
40 }
41
~Button()42 Button::~Button()
43 {
44 }
45
repaintEvent(RepaintEvent * repaintEvent)46 void Button::repaintEvent(RepaintEvent* repaintEvent)
47 {
48 Painter p(*this);
49 p.clear();
50
51 int padTop = 3;
52 int padLeft = 0;
53 int padTextTop = 3;
54
55 int w = width();
56 int h = height();
57 if(w == 0 || h == 0)
58 {
59 return;
60 }
61
62 if (enabled) {
63 switch(draw_state)
64 {
65 case State::Up:
66 box_up.setSize(w - padLeft, h - padTop);
67 p.drawImage(padLeft, padTop, box_up);
68 break;
69
70 case State::Down:
71 box_down.setSize(w - padLeft, h - padTop);
72 p.drawImage(padLeft, padTop, box_down);
73 break;
74 }
75 }
76 else {
77 box_grey.setSize(w - padLeft, h - padTop);
78 p.drawImage(padLeft, padTop, box_grey);
79
80 p.setColour(Colour(0.55));
81 }
82
83 auto x = padLeft + (width() - font.textWidth(text)) / 2;
84 auto y = padTop + padTextTop + font.textHeight(text);
85 p.drawText(x, y, font, text, enabled);
86 }
87
88 } // GUI::
89