Debian Codegraph @

examples/book/drawingarea/simple/myarea.cc

raw
1 /* gtkmm example Copyright (C) 2002 gtkmm development team
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, see <https://www.gnu.org/licenses/>.
15 */
16
17 #include "myarea.h"
18 #include <cairomm/context.h>
19
20 MyArea::MyArea()
21 {
22 set_draw_func(sigc::mem_fun(*this, &MyArea::on_draw));
23 }
24
25 MyArea::~MyArea()
26 {
27 }
28
29 void MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
30 {
31 // coordinates for the center of the window
32 int xc, yc;
33 xc = width / 2;
34 yc = height / 2;
35
36 cr->set_line_width(10.0);
37
38 // draw red lines out from the center of the window
39 cr->set_source_rgb(0.8, 0.0, 0.0);
40 cr->move_to(0, 0);
41 cr->line_to(xc, yc);
42 cr->line_to(0, height);
43 cr->move_to(xc, yc);
44 cr->line_to(width, yc);
45 cr->stroke();
46 }