1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /***************************************************************************
3  *            checkbox.cc
4  *
5  *  Sat Nov 26 15:07:44 CET 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 "checkbox.h"
28 
29 #include "painter.h"
30 
31 namespace GUI
32 {
33 
CheckBox(Widget * parent)34 CheckBox::CheckBox(Widget* parent)
35 	: Toggle(parent)
36 	, bg_on(getImageCache(), ":resources/switch_back_on.png")
37 	, bg_off(getImageCache(), ":resources/switch_back_off.png")
38 	, knob(getImageCache(), ":resources/switch_front.png")
39 {
40 }
41 
repaintEvent(RepaintEvent * repaintEvent)42 void CheckBox::repaintEvent(RepaintEvent* repaintEvent)
43 {
44 	Painter p(*this);
45 	p.clear();
46 	p.drawImage(0, (knob.height() - bg_on.height()) / 2, state ? bg_on : bg_off);
47 
48 	if(clicked)
49 	{
50 		p.drawImage((bg_on.width() - knob.width()) / 2 + 1, 0, knob);
51 		return;
52 	}
53 
54 	if(state)
55 	{
56 		p.drawImage(bg_on.width() - 40 + 2, 0, knob);
57 	}
58 	else
59 	{
60 		p.drawImage(0, 0, knob);
61 	}
62 }
63 
64 } // GUI::
65