Fawkes API  Fawkes Development Version
visdisplay.h
1 
2 /***************************************************************************
3  * visdisplay.h - Visual Display to show VisualDisplay2DInterface objects
4  *
5  * Created: Thu Jan 07 23:36:15 2010
6  * Copyright 2008-2010 Tim Niemueller [www.niemueller.de]
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.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef _TOOLS_LASERGUI_VISDISPLAY_H_
24 #define _TOOLS_LASERGUI_VISDISPLAY_H_
25 
26 #include <cairomm/context.h>
27 #include <interfaces/VisualDisplay2DInterface.h>
28 
29 #include <map>
30 #include <string>
31 
33 {
34 public:
37 
39 
40  void process_messages();
41  void draw(Cairo::RefPtr<Cairo::Context> cr);
42 
43  class Shape
44  {
45  public:
46  Shape(unsigned int id,
47  unsigned int owner,
50  unsigned char r = 0,
51  unsigned char g = 0,
52  unsigned char b = 0,
53  unsigned char a = 0);
54  virtual ~Shape();
55  virtual void draw(Cairo::RefPtr<Cairo::Context> &cr) = 0;
56  inline void
57  apply_style(Cairo::RefPtr<Cairo::Context> &cr)
58  {
59  cr->set_source_rgba(_color_r, _color_g, _color_b, _color_a);
60  }
61 
62  inline unsigned int
63  id()
64  {
65  return _id;
66  }
67  inline unsigned int
69  {
70  return _owner;
71  }
72  inline void
73  color(float &r, float &g, float &b, float &a)
74  {
75  r = _color_r;
76  g = _color_g;
77  b = _color_b;
78  a = _color_a;
79  }
80 
81  protected:
83  float _color_r; /**< red part of RGBA object color */
84  float _color_g; /**< green part of RGBA object color */
85  float _color_b; /**< blue part of RGBA object color */
86  float _color_a; /**< alpha part of RGBA object color */
87 
88  unsigned int _id; /**< Object ID */
89  unsigned int _owner; /**< Owner ID */
90  };
91 
92  class Line : public Shape
93  {
94  public:
95  Line(float x1,
96  float y1,
97  float x2,
98  float y2,
99  unsigned int id,
100  unsigned int owner,
103  unsigned char r = 0,
104  unsigned char g = 0,
105  unsigned char b = 0,
106  unsigned char a = 0);
107  void draw(Cairo::RefPtr<Cairo::Context> &cr);
108 
109  private:
110  float x1_;
111  float y1_;
112  float x2_;
113  float y2_;
114  };
115 
116  class Rectangle : public Shape
117  {
118  public:
119  Rectangle(float x,
120  float y,
121  float width,
122  float height,
123  unsigned int id,
124  unsigned int owner,
127  unsigned char r = 0,
128  unsigned char g = 0,
129  unsigned char b = 0,
130  unsigned char a = 0);
131  void draw(Cairo::RefPtr<Cairo::Context> &cr);
132 
133  private:
134  float x_;
135  float y_;
136  float width_;
137  float height_;
138  };
139 
140  class Circle : public Shape
141  {
142  public:
143  Circle(float x,
144  float y,
145  float radius,
146  unsigned int id,
147  unsigned int owner,
150  unsigned char r = 0,
151  unsigned char g = 0,
152  unsigned char b = 0,
153  unsigned char a = 0);
154  void draw(Cairo::RefPtr<Cairo::Context> &cr);
155 
156  private:
157  float x_;
158  float y_;
159  float radius_;
160  };
161 
162  class Text : public Shape
163  {
164  public:
165  Text(float x,
166  float y,
167  const std::string & text,
169  float size,
170  unsigned int id,
171  unsigned int owner,
172  unsigned char r = 0,
173  unsigned char g = 0,
174  unsigned char b = 0,
175  unsigned char a = 0);
176  void draw(Cairo::RefPtr<Cairo::Context> &cr);
177 
178  private:
179  float x_;
180  float y_;
181  std::string text_;
182  float size_;
184  };
185 
186 private:
187  std::map<unsigned int, Shape *> shapes_;
188  std::map<unsigned int, Shape *>::iterator sit_;
190 };
191 
192 #endif
VisualDisplay2D::Shape::apply_style
void apply_style(Cairo::RefPtr< Cairo::Context > &cr)
Set style on context.
Definition: visdisplay.h:57
VisualDisplay2D::Circle::Circle
Circle(float x, float y, float radius, unsigned int id, unsigned int owner, fawkes::VisualDisplay2DInterface::LineStyle line_style=fawkes::VisualDisplay2DInterface::LS_SOLID, unsigned char r=0, unsigned char g=0, unsigned char b=0, unsigned char a=0)
Constructor.
Definition: visdisplay.cpp:335
VisualDisplay2D::Text
Class representing a text object.
Definition: visdisplay.h:163
VisualDisplay2D::Shape::draw
virtual void draw(Cairo::RefPtr< Cairo::Context > &cr)=0
Draw shape to Cairo context.
fawkes::VisualDisplay2DInterface::LS_SOLID
@ LS_SOLID
Solid line.
Definition: VisualDisplay2DInterface.h:45
VisualDisplay2D::Circle::draw
void draw(Cairo::RefPtr< Cairo::Context > &cr)
Draw shape to Cairo context.
Definition: visdisplay.cpp:353
VisualDisplay2D::Rectangle::Rectangle
Rectangle(float x, float y, float width, float height, unsigned int id, unsigned int owner, fawkes::VisualDisplay2DInterface::LineStyle line_style=fawkes::VisualDisplay2DInterface::LS_SOLID, unsigned char r=0, unsigned char g=0, unsigned char b=0, unsigned char a=0)
Constructor.
Definition: visdisplay.cpp:292
VisualDisplay2D::Shape::id
unsigned int id()
Get shape ID.
Definition: visdisplay.h:63
VisualDisplay2D::Line::draw
void draw(Cairo::RefPtr< Cairo::Context > &cr)
Draw shape to Cairo context.
Definition: visdisplay.cpp:265
VisualDisplay2D
2D visualization processor for VisualDisplay2DInterface.
Definition: visdisplay.h:33
VisualDisplay2D::Shape::owner
unsigned int owner()
Get owner ID.
Definition: visdisplay.h:68
VisualDisplay2D::Shape::_owner
unsigned int _owner
Owner ID.
Definition: visdisplay.h:89
VisualDisplay2D::Line
Class representing a line.
Definition: visdisplay.h:93
VisualDisplay2D::Circle
Class representing a circle Line represented by its center point and radius.
Definition: visdisplay.h:141
VisualDisplay2D::Line::Line
Line(float x1, float y1, float x2, float y2, unsigned int id, unsigned int owner, fawkes::VisualDisplay2DInterface::LineStyle line_style=fawkes::VisualDisplay2DInterface::LS_SOLID, unsigned char r=0, unsigned char g=0, unsigned char b=0, unsigned char a=0)
Constructor.
Definition: visdisplay.cpp:245
VisualDisplay2D::Shape::_id
unsigned int _id
Object ID.
Definition: visdisplay.h:88
VisualDisplay2D::set_interface
void set_interface(fawkes::VisualDisplay2DInterface *interface)
Set interface.
Definition: visdisplay.cpp:55
fawkes::VisualDisplay2DInterface
VisualDisplay2DInterface Fawkes BlackBoard Interface.
Definition: VisualDisplay2DInterface.h:34
VisualDisplay2D::Rectangle
Class representing a rectangle.
Definition: visdisplay.h:117
VisualDisplay2D::Text::draw
void draw(Cairo::RefPtr< Cairo::Context > &cr)
Draw shape to Cairo context.
Definition: visdisplay.cpp:399
VisualDisplay2D::Text::Text
Text(float x, float y, const std::string &text, fawkes::VisualDisplay2DInterface::Anchor anchor, float size, unsigned int id, unsigned int owner, unsigned char r=0, unsigned char g=0, unsigned char b=0, unsigned char a=0)
Constructor.
Definition: visdisplay.cpp:378
VisualDisplay2D::Shape::_color_r
float _color_r
red part of RGBA object color
Definition: visdisplay.h:83
VisualDisplay2D::VisualDisplay2D
VisualDisplay2D()
Constructor.
Definition: visdisplay.cpp:37
VisualDisplay2D::draw
void draw(Cairo::RefPtr< Cairo::Context > cr)
Draw objects.
Definition: visdisplay.cpp:143
VisualDisplay2D::Shape
Class representing a shape.
Definition: visdisplay.h:44
VisualDisplay2D::~VisualDisplay2D
~VisualDisplay2D()
Destructor.
Definition: visdisplay.cpp:43
VisualDisplay2D::Shape::_color_g
float _color_g
green part of RGBA object color
Definition: visdisplay.h:84
VisualDisplay2D::Rectangle::draw
void draw(Cairo::RefPtr< Cairo::Context > &cr)
Draw shape to Cairo context.
Definition: visdisplay.cpp:312
VisualDisplay2D::process_messages
void process_messages()
Process messages.
Definition: visdisplay.cpp:65
fawkes::VisualDisplay2DInterface::LineStyle
LineStyle
Enumeration defining the possible line styles.
Definition: VisualDisplay2DInterface.h:44
VisualDisplay2D::Shape::_line_style
fawkes::VisualDisplay2DInterface::LineStyle _line_style
Line style.
Definition: visdisplay.h:82
VisualDisplay2D::Shape::~Shape
virtual ~Shape()
Virtual empty destructor.
Definition: visdisplay.cpp:222
VisualDisplay2D::Shape::color
void color(float &r, float &g, float &b, float &a)
Get shape color.
Definition: visdisplay.h:73
VisualDisplay2D::Shape::_color_b
float _color_b
blue part of RGBA object color
Definition: visdisplay.h:85
VisualDisplay2D::Shape::_color_a
float _color_a
alpha part of RGBA object color
Definition: visdisplay.h:86
fawkes::VisualDisplay2DInterface::Anchor
Anchor
Enumeration defining the possible anchor points.
Definition: VisualDisplay2DInterface.h:58
VisualDisplay2D::Shape::Shape
Shape(unsigned int id, unsigned int owner, fawkes::VisualDisplay2DInterface::LineStyle line_style=fawkes::VisualDisplay2DInterface::LS_SOLID, unsigned char r=0, unsigned char g=0, unsigned char b=0, unsigned char a=0)
Constructor.
Definition: visdisplay.cpp:204