hom_vector_drawer.cpp

00001 
00002 /***************************************************************************
00003  *  hom_vector_drawer.cpp - Drawer for the HomVector class
00004  *
00005  *  Created: Thu Oct 16 18:00:59 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_vector_drawer.h>
00025 #include <geometry/hom_vector.h>
00026 #include <geometry/hom_point.h>
00027 
00028 /** @class fawkes::HomVectorDrawer <geometry/gtk/hom_vector_drawer.h>
00029  * Drawer for HomVector objects. In order to draw a vector an
00030  * additional offset point needs to be given.
00031  * @author Daniel Beck
00032  */
00033 
00034 namespace fawkes {
00035 
00036 /** Constructor.
00037  * @param v a HomVector.
00038  */
00039 HomVectorDrawer::HomVectorDrawer(HomVector& v)
00040 {
00041   m_vector = &v;
00042   m_offset = NULL;
00043   m_manager = false;
00044 }
00045 
00046 /** Constructor.
00047  * @param v a HomVector.
00048  * @param offset an offset point
00049  */
00050 HomVectorDrawer::HomVectorDrawer(HomVector& v, HomPoint& offset)
00051 {
00052   m_vector = &v;
00053   m_offset = &offset;
00054   m_manager = false;
00055 }
00056 
00057 /** Constructor.
00058  * This constructor creates a copy of the vector to draw.
00059  * @param v a HomVector
00060  */
00061 HomVectorDrawer::HomVectorDrawer(const HomVector& v)
00062 {
00063   m_vector = new HomVector(v);
00064   m_offset = NULL;
00065   m_manager = true;
00066 }
00067 
00068 /** Constructor.
00069  * This constructor creates copies of the vector and the offset.
00070  * @param v a HomVector.
00071  * @param offset an offset point
00072  */
00073 HomVectorDrawer::HomVectorDrawer(const HomVector& v, const HomPoint& offset)
00074 {
00075   m_vector = new HomVector(v);
00076   m_offset = new HomPoint(offset);
00077   m_manager = true;
00078 }
00079 
00080 /** Copy constructor.
00081  * @param d another HomVectorDrawer
00082  */
00083 HomVectorDrawer::HomVectorDrawer(const HomVectorDrawer& d)
00084 {
00085   m_vector = new HomVector( *d.m_vector );
00086   m_offset = new HomPoint( *d.m_offset );
00087   m_manager = true;
00088 }
00089 
00090 /** Destrcutor. */
00091 HomVectorDrawer::~HomVectorDrawer()
00092 {
00093   if (m_manager)
00094     {
00095       delete m_vector;
00096       delete m_offset;
00097     }
00098 }
00099 
00100 void
00101 HomVectorDrawer::draw(Cairo::RefPtr<Cairo::Context>& context)
00102 {
00103   context->save();
00104 
00105   HomPoint start, end;
00106   if (m_offset)
00107     {
00108       start = HomPoint( m_offset->x(), m_offset->y() );
00109       end   = HomPoint( m_offset->x() + m_vector->x(),
00110                         m_offset->y() + m_vector->y() );
00111     }
00112   else
00113     {
00114       start = HomPoint( 0.0, 0.0 );
00115       end   = HomPoint( m_vector->x(), m_vector->y() );
00116     }
00117 
00118   context->move_to( start.x(), start.y() );
00119   context->line_to( end.x()  , end.y()   );
00120   context->arc( end.x(), end.y(), 0.06, 0.0, 2.0 * M_PI);
00121   context->fill();
00122 
00123   context->stroke();
00124   context->restore();
00125 }
00126 
00127 
00128 } // end namespace fawkes

Generated on 1 Mar 2011 for Fawkes API by  doxygen 1.6.1