Fawkes API  Fawkes Development Version
bezier_drawer.cpp
00001 
00002 /***************************************************************************
00003  *  bezier_drawer.cpp - Drawer for the Bezier class
00004  *
00005  *  Created: Thu Oct 09 15:08:38 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/bezier_drawer.h>
00025 #include <geometry/bezier.h>
00026 #include <geometry/hom_point.h>
00027 
00028 /** @class fawkes::BezierDrawer <geometry/gtk/bezier_drawer.h>
00029  * Drawer for Bezier objects.
00030  * @author Daniel Beck
00031  */
00032 
00033 using namespace std;
00034 
00035 namespace fawkes {
00036 
00037 /** Constructor.
00038  * @param b the Bezier to draw
00039  */
00040 BezierDrawer::BezierDrawer(Bezier& b)
00041 {
00042   m_bezier = &b;
00043 }
00044 
00045 /** Destructor. */
00046 BezierDrawer::~BezierDrawer()
00047 {
00048 }
00049 
00050 void
00051 BezierDrawer::draw(Cairo::RefPtr<Cairo::Context>& context)
00052 {
00053   vector<HomPoint> points = m_bezier->approximate();
00054 
00055   vector<HomPoint>::const_iterator prev = points.begin();
00056   vector<HomPoint>::const_iterator cur  = prev;
00057   ++cur;
00058   
00059   while ( cur != points.end() )
00060     {
00061       context->save();
00062       context->move_to( prev->x(), prev->y() );
00063       context->line_to( cur->x(), cur->y() );
00064       context->restore();
00065 
00066       ++prev;
00067       ++cur;
00068     }
00069 
00070   context->stroke();
00071 }
00072 
00073 } // end namespace fawkes