hom_point_drawer.cpp

00001
00002 /***************************************************************************
00003  *  hom_point_drawer.cpp - Drawer for the HomPoint class
00004  *
00005  *  Created: Thu Oct 09 14:34:19 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/hom_point_drawer.h>
00025 #include <geometry/hom_point.h>
00026 
00027 /** @class fawkes::HomPointDrawer <geometry/gtk/hom_point_drawer.h>
00028  * Drawer for HomPoint objects.
00029  * @author Daniel Beck
00030  */
00031 
00032 /** @var fawkes::HomPointDrawer::m_point_size
00033  * The radius of the point.
00034  */
00035
00036 namespace fawkes {
00037 
00038 /** Constructor.
00039  * @param p the HomPoint to draw
00040  */
00041 HomPointDrawer::HomPointDrawer(HomPoint& p)
00042 {
00043   m_hom_point = &p;
00044   m_point_size = 0.1;
00045   m_own_point = false;
00046 }
00047 
00048 /** Constructor.
00049  * @param p the HomPoint to draw
00050  */
00051 HomPointDrawer::HomPointDrawer(const HomPoint& p)
00052 {
00053   m_hom_point = new HomPoint(p);
00054   m_point_size = 0.1;
00055   m_own_point = true;
00056 }
00057 
00058 /** Destructor. */
00059 HomPointDrawer::~HomPointDrawer()
00060 {
00061   if (m_own_point)
00062     { delete m_hom_point; }
00063 }
00064 
00065 /** Set the point size with which points a drawn by this drawer.
00066  * @param s the point size
00067  */
00068 void
00069 HomPointDrawer::set_point_size(float s)
00070 {
00071   m_point_size = s;
00072 }
00073
00074 void
00075 HomPointDrawer::draw(Cairo::RefPtr<Cairo::Context>& context)
00076 {
00077   float x = m_hom_point->x();
00078   float y = m_hom_point->y();
00079
00080   context->save();
00081   context->move_to(x, y);
00082   context->arc(x, y, m_point_size, 0.0, 2.0 * M_PI);
00083   context->fill();
00084   context->restore();
00085   context->stroke();
00086 }
00087
00088 } // end namespace fawkes