| 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 |
#include <vector> |
| 20 |
|
| 21 |
MyArea::MyArea() |
| 22 |
{ |
| 23 |
set_draw_func(sigc::mem_fun(*this, &MyArea::on_draw)); |
| 24 |
} |
| 25 |
|
| 26 |
MyArea::~MyArea() |
| 27 |
{ |
| 28 |
} |
| 29 |
|
| 30 |
void MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height) |
| 31 |
{ |
| 32 |
const double x0=0.1, y0=0.5, // start point |
| 33 |
x1=0.4, y1=0.9, // control point #1 |
| 34 |
x2=0.6, y2=0.1, // control point #2 |
| 35 |
x3=0.9, y3=0.5; // end point |
| 36 |
const std::vector<double> dashes = {0.08, 0.05}; |
| 37 |
|
| 38 |
// scale to unit square (0 to 1 width and height) |
| 39 |
cr->scale(width, height); |
| 40 |
|
| 41 |
// draw curve |
| 42 |
cr->set_line_width(0.05); |
| 43 |
cr->move_to(x0, y0); |
| 44 |
cr->curve_to(x1, y1, x2, y2, x3, y3); |
| 45 |
cr->stroke(); |
| 46 |
|
| 47 |
// show first control point (red) |
| 48 |
cr->set_line_width(0.03); |
| 49 |
cr->set_dash(dashes, 0.0); |
| 50 |
cr->set_source_rgba(1.0, 0.2, 0.2, 0.6); |
| 51 |
cr->set_line_cap(Cairo::Context::LineCap::ROUND); |
| 52 |
cr->move_to(x1, y1); |
| 53 |
cr->line_to (x0, y0); |
| 54 |
cr->stroke(); |
| 55 |
|
| 56 |
// show second control point (blue) |
| 57 |
cr->set_source_rgba(0.2, 0.2, 1.0, 0.6); |
| 58 |
cr->set_line_cap(Cairo::Context::LineCap::BUTT); |
| 59 |
cr->move_to(x2, y2); |
| 60 |
cr->line_to (x3, y3); |
| 61 |
cr->stroke(); |
| 62 |
} |