Fawkes API  Fawkes Development Version
bezier_drawer.cpp
1 
2 /***************************************************************************
3  * bezier_drawer.cpp - Drawer for the Bezier class
4  *
5  * Created: Thu Oct 09 15:08:38 2008
6  * Copyright 2008 Daniel Beck
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <geometry/gtk/bezier_drawer.h>
25 #include <geometry/bezier.h>
26 #include <geometry/hom_point.h>
27 
28 /** @class fawkes::BezierDrawer <geometry/gtk/bezier_drawer.h>
29  * Drawer for Bezier objects.
30  * @author Daniel Beck
31  */
32 
33 using namespace std;
34 
35 namespace fawkes {
36 
37 /** Constructor.
38  * @param b the Bezier to draw
39  */
40 BezierDrawer::BezierDrawer(Bezier& b)
41 {
42  m_bezier = &b;
43 }
44 
45 /** Destructor. */
46 BezierDrawer::~BezierDrawer()
47 {
48 }
49 
50 void
51 BezierDrawer::draw(Cairo::RefPtr<Cairo::Context>& context)
52 {
53  vector<HomPoint> points = m_bezier->approximate();
54 
55  vector<HomPoint>::const_iterator prev = points.begin();
56  vector<HomPoint>::const_iterator cur = prev;
57  ++cur;
58 
59  while ( cur != points.end() )
60  {
61  context->save();
62  context->move_to( prev->x(), prev->y() );
63  context->line_to( cur->x(), cur->y() );
64  context->restore();
65 
66  ++prev;
67  ++cur;
68  }
69 
70  context->stroke();
71 }
72 
73 } // end namespace fawkes
Fawkes library namespace.
A Bezier curve class.
Definition: bezier.h:34
STL namespace.
const std::vector< HomPoint > & approximate(unsigned int num_subdivisions=4)
Approximate the curve with points.
Definition: bezier.cpp:253