Debian Codegraph @

examples/book/drawingarea/joins/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 cr->set_line_width(10.0);
32
33 // Scale to unit square
34 cr->scale(width, height);
35 cr->save();
36 cr->set_source_rgb(1, 1, 1);
37 cr->paint();
38 cr->restore();
39 cr->set_line_width(0.12);
40 cr->move_to(0.3, 0.3);
41 cr->rel_line_to(0.2, -0.2);
42 cr->rel_line_to(0.2, 0.2);
43 cr->set_line_join(Cairo::Context::LineJoin::MITER); /* default */
44 cr->stroke();
45 cr->move_to(0.3, 0.6);
46 cr->rel_line_to(0.2, -0.2);
47 cr->rel_line_to(0.2, 0.2);
48 cr->set_line_join(Cairo::Context::LineJoin::BEVEL);
49 cr->stroke();
50 cr->move_to(0.3, 0.9);
51 cr->rel_line_to(0.2, -0.2);
52 cr->rel_line_to(0.2, 0.2);
53 cr->set_line_join(Cairo::Context::LineJoin::ROUND);
54 cr->stroke();
55 }