Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
spline_drawer.cpp
1 
2 /***************************************************************************
3  * spline_drawer.cpp - Drawer for the Spline class
4  *
5  * Created: Fri Oct 10 14:00:22 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/spline_drawer.h>
25 #include <geometry/gtk/bezier_drawer.h>
26 #include <geometry/spline.h>
27 
28 /** @class fawkes::SplineDrawer <geometry/gtk/spline_drawer.h>
29  * Drawer for Spline objects.
30  * @author Daniel Beck
31  */
32 
33 using namespace std;
34 
35 namespace fawkes {
36 
37 /** Constructor.
38  * This constructor does not copy the Spline object but keeps a
39  * pointer to the specified Spline object. Consequently, you have to
40  * make sure that the object is not deleted before it is drawn. If you
41  * cannot ensure this use the constructor that is given a const
42  * reference to the object to draw.
43  * @param s the Spline to draw
44  */
45 SplineDrawer::SplineDrawer(Spline& s)
46 {
47  m_spline = &s;
48  m_own_spline = false;
49 }
50 
51 /** Constructor.
52  * Contrary to the other constructor, this constructor create a local
53  * copy of the object to draw.
54  * @param s the Spline to draw
55  */
56 SplineDrawer::SplineDrawer(const Spline& s)
57 {
58  m_spline = new Spline(s);
59  m_own_spline = true;
60 }
61 
62 /** Destructor. */
63 SplineDrawer::~SplineDrawer()
64 {
65  if (m_own_spline)
66  { delete m_spline; }
67 }
68 
69 void
70 SplineDrawer::draw(Cairo::RefPtr<Cairo::Context>& context)
71 {
72  for ( vector<Bezier>::iterator iter = m_spline->m_bezier_curves.begin();
73  iter != m_spline->m_bezier_curves.end();
74  ++iter )
75  {
76  BezierDrawer d( *iter );
77  d.draw(context);
78  }
79 }
80 
81 } // end namespace fawkes