Fawkes API  Fawkes Development Version
hom_vector_drawer.cpp
1 
2 /***************************************************************************
3  * hom_vector_drawer.cpp - Drawer for the HomVector class
4  *
5  * Created: Thu Oct 16 18:00:59 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/hom_vector_drawer.h>
25 #include <geometry/hom_vector.h>
26 #include <geometry/hom_point.h>
27 
28 /** @class fawkes::HomVectorDrawer <geometry/gtk/hom_vector_drawer.h>
29  * Drawer for HomVector objects. In order to draw a vector an
30  * additional offset point needs to be given.
31  * @author Daniel Beck
32  */
33 
34 namespace fawkes {
35 
36 /** Constructor.
37  * @param v a HomVector.
38  */
40 {
41  m_vector = &v;
42  m_offset = NULL;
43  m_manager = false;
44 }
45 
46 /** Constructor.
47  * @param v a HomVector.
48  * @param offset an offset point
49  */
51 {
52  m_vector = &v;
53  m_offset = &offset;
54  m_manager = false;
55 }
56 
57 /** Constructor.
58  * This constructor creates a copy of the vector to draw.
59  * @param v a HomVector
60  */
62 {
63  m_vector = new HomVector(v);
64  m_offset = NULL;
65  m_manager = true;
66 }
67 
68 /** Constructor.
69  * This constructor creates copies of the vector and the offset.
70  * @param v a HomVector.
71  * @param offset an offset point
72  */
74 {
75  m_vector = new HomVector(v);
76  m_offset = new HomPoint(offset);
77  m_manager = true;
78 }
79 
80 /** Copy constructor.
81  * @param d another HomVectorDrawer
82  */
84 {
85  m_vector = new HomVector( *d.m_vector );
86  m_offset = new HomPoint( *d.m_offset );
87  m_manager = true;
88 }
89 
90 /** Destrcutor. */
92 {
93  if (m_manager)
94  {
95  delete m_vector;
96  delete m_offset;
97  }
98 }
99 
100 void
101 HomVectorDrawer::draw(Cairo::RefPtr<Cairo::Context>& context)
102 {
103  context->save();
104 
105  HomPoint start, end;
106  if (m_offset)
107  {
108  start = HomPoint( m_offset->x(), m_offset->y() );
109  end = HomPoint( m_offset->x() + m_vector->x(),
110  m_offset->y() + m_vector->y() );
111  }
112  else
113  {
114  start = HomPoint( 0.0, 0.0 );
115  end = HomPoint( m_vector->x(), m_vector->y() );
116  }
117 
118  context->move_to( start.x(), start.y() );
119  context->line_to( end.x() , end.y() );
120  context->arc( end.x(), end.y(), 0.06, 0.0, 2.0 * M_PI);
121  context->fill();
122 
123  context->stroke();
124  context->restore();
125 }
126 
127 
128 } // end namespace fawkes
virtual float y() const
RO-getter for y.
Definition: hom_coord.cpp:115
virtual void draw(Cairo::RefPtr< Cairo::Context > &context)
This method is called by the GeomDrawingArea.
Fawkes library namespace.
HomVectorDrawer(HomVector &v)
Constructor.
A homogeneous point.
Definition: hom_point.h:33
HomPoint & move_to(float x, float y, float z)
Move the point to the given coordiantes.
Definition: hom_point.cpp:117
Drawer for HomVector objects.
A homogeneous vector.
Definition: hom_vector.h:31
virtual float x() const
RO-getter for x.
Definition: hom_coord.cpp:85
virtual ~HomVectorDrawer()
Destrcutor.