1 /*
2 ** jstest-gtk - A graphical joystick tester
3 ** Copyright (C) 2009 Ingo Ruhnke <grumbel@gmail.com>
4 **
5 ** This program is free software: you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation, either version 3 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "button_widget.hpp"
20
ButtonWidget(int width,int height,const std::string & name_)21 ButtonWidget::ButtonWidget(int width, int height, const std::string& name_)
22 : name(name_)
23 {
24 set_size_request(width, height);
25 }
26
27 bool
on_draw(const Cairo::RefPtr<Cairo::Context> & cr)28 ButtonWidget::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
29 {
30 Gtk::DrawingArea::on_draw(cr);
31
32 int w = get_allocation().get_width() - 10;
33 int h = get_allocation().get_height() - 10;
34
35 cr->set_source_rgb(0.0, 0.0, 0.0);
36 cr->set_line_width(1.0);
37 cr->translate(5, 5);
38 cr->rectangle(0, 0, w, h);
39
40 if (down)
41 cr->fill_preserve();
42
43 cr->stroke();
44
45 if (down)
46 cr->set_source_rgb(1.0, 1.0, 1.0);
47
48 // FIXME: There are better ways to center text
49 if (name.size() == 2)
50 cr->move_to(w/2-6, h/2+3);
51 else
52 cr->move_to(w/2-4, h/2+3);
53 cr->show_text(name);
54
55 return true;
56 }
57
58 void
set_down(bool t)59 ButtonWidget::set_down(bool t)
60 {
61 down = t;
62 queue_draw();
63 }
64
65 /* EOF */
66