spline_drawer.cpp

00001 
00002 /***************************************************************************
00003  *  spline_drawer.cpp - Drawer for the Spline class
00004  *
00005  *  Created: Fri Oct 10 14:00:22 2008
00006  *  Copyright  2008  Daniel Beck
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #include <geometry/gtk/spline_drawer.h>
00025 #include <geometry/gtk/bezier_drawer.h>
00026 #include <geometry/spline.h>
00027 
00028 /** @class fawkes::SplineDrawer <geometry/gtk/spline_drawer.h>
00029  * Drawer for Spline objects.
00030  * @author Daniel Beck
00031  */
00032 
00033 using namespace std;
00034 
00035 namespace fawkes {
00036 
00037 /** Constructor.
00038  * This constructor does not copy the Spline object but keeps a
00039  * pointer to the specified Spline object. Consequently, you have to
00040  * make sure that the object is not deleted before it is drawn. If you
00041  * cannot ensure this use the constructor that is given a const
00042  * reference to the object to draw.
00043  * @param s the Spline to draw
00044  */
00045 SplineDrawer::SplineDrawer(Spline& s)
00046 {
00047   m_spline = &s;
00048   m_own_spline = false;
00049 }
00050 
00051 /** Constructor.
00052  * Contrary to the other constructor, this constructor create a local
00053  * copy of the object to draw.
00054  * @param s the Spline to draw
00055  */
00056 SplineDrawer::SplineDrawer(const Spline& s)
00057 {
00058   m_spline = new Spline(s);
00059   m_own_spline = true;
00060 }
00061 
00062 /** Destructor. */
00063 SplineDrawer::~SplineDrawer()
00064 {
00065   if (m_own_spline)
00066     { delete m_spline; }
00067 }
00068 
00069 void
00070 SplineDrawer::draw(Cairo::RefPtr<Cairo::Context>& context)
00071 {
00072   for ( vector<Bezier>::iterator iter = m_spline->m_bezier_curves.begin();
00073         iter != m_spline->m_bezier_curves.end();
00074         ++iter )
00075     {
00076       BezierDrawer d( *iter );
00077       d.draw(context);
00078     }
00079 }
00080 
00081 } // end namespace fawkes