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 <string>
28 #include <map>
29 
30 #include <interfaces/VisualDisplay2DInterface.h>
31 
33 {
34  public:
37 
39 
40  void process_messages();
41  void draw(Cairo::RefPtr<Cairo::Context> cr);
42 
43  class Shape {
44  public:
45  Shape(unsigned int id, unsigned int owner,
47  unsigned char r = 0, unsigned char g = 0,
48  unsigned char b = 0, unsigned char a = 0);
49  virtual ~Shape();
50  virtual void draw(Cairo::RefPtr<Cairo::Context> &cr) = 0;
51  inline void apply_style(Cairo::RefPtr<Cairo::Context> &cr)
52  { cr->set_source_rgba(_color_r, _color_g, _color_b, _color_a); }
53 
54  inline unsigned int id() { return _id; }
55  inline unsigned int owner() { return _owner; }
56  inline void color(float &r, float &g, float &b, float &a)
57  { r = _color_r; g = _color_g; b = _color_b; a = _color_a; }
58  protected:
59 
61  float _color_r; /**< red part of RGBA object color */
62  float _color_g; /**< green part of RGBA object color */
63  float _color_b; /**< blue part of RGBA object color */
64  float _color_a; /**< alpha part of RGBA object color */
65 
66  unsigned int _id; /**< Object ID */
67  unsigned int _owner; /**< Owner ID */
68  };
69 
70  class Line : public Shape {
71  public:
72  Line(float x1, float y1, float x2, float y2,
73  unsigned int id, unsigned int owner,
75  unsigned char r = 0, unsigned char g = 0,
76  unsigned char b = 0, unsigned char a = 0);
77  void draw(Cairo::RefPtr<Cairo::Context> &cr);
78  private:
79  float __x1;
80  float __y1;
81  float __x2;
82  float __y2;
83  };
84 
85  class Rectangle : public Shape {
86  public:
87  Rectangle(float x, float y, float width, float height,
88  unsigned int id, unsigned int owner,
90  unsigned char r = 0, unsigned char g = 0,
91  unsigned char b = 0, unsigned char a = 0);
92  void draw(Cairo::RefPtr<Cairo::Context> &cr);
93  private:
94  float __x;
95  float __y;
96  float __width;
97  float __height;
98  };
99 
100  class Circle : public Shape {
101  public:
102  Circle(float x, float y, float radius,
103  unsigned int id, unsigned int owner,
105  unsigned char r = 0, unsigned char g = 0,
106  unsigned char b = 0, unsigned char a = 0);
107  void draw(Cairo::RefPtr<Cairo::Context> &cr);
108  private:
109  float __x;
110  float __y;
111  float __radius;
112  };
113 
114  class Text : public Shape {
115  public:
116  Text(float x, float y, std::string text,
118  float size,
119  unsigned int id, unsigned int owner,
120  unsigned char r = 0, unsigned char g = 0,
121  unsigned char b = 0, unsigned char a = 0);
122  void draw(Cairo::RefPtr<Cairo::Context> &cr);
123  private:
124  float __x;
125  float __y;
126  std::string __text;
127  float __size;
129  };
130 
131  private:
132  std::map<unsigned int, Shape *> __shapes;
133  std::map<unsigned int, Shape *>::iterator __sit;
135 };
136 
137 
138 #endif
void color(float &r, float &g, float &b, float &a)
Get shape color.
Definition: visdisplay.h:56
LineStyle
Enumeration defining the possible line styles.
fawkes::VisualDisplay2DInterface::LineStyle _line_style
Line style.
Definition: visdisplay.h:60
2D visualization processor for VisualDisplay2DInterface.
Definition: visdisplay.h:32
float _color_g
green part of RGBA object color
Definition: visdisplay.h:62
float _color_a
alpha part of RGBA object color
Definition: visdisplay.h:64
void set_interface(fawkes::VisualDisplay2DInterface *interface)
Set interface.
Definition: visdisplay.cpp:57
Anchor
Enumeration defining the possible anchor points.
~VisualDisplay2D()
Destructor.
Definition: visdisplay.cpp:44
float _color_b
blue part of RGBA object color
Definition: visdisplay.h:63
unsigned int id()
Get shape ID.
Definition: visdisplay.h:54
void apply_style(Cairo::RefPtr< Cairo::Context > &cr)
Set style on context.
Definition: visdisplay.h:51
void process_messages()
Process messages.
Definition: visdisplay.cpp:68
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:179
Class representing a text object.
Definition: visdisplay.h:114
unsigned int owner()
Get owner ID.
Definition: visdisplay.h:55
virtual void draw(Cairo::RefPtr< Cairo::Context > &cr)=0
Draw shape to Cairo context.
unsigned int _id
Object ID.
Definition: visdisplay.h:66
Class representing a circle Line represented by its center point and radius.
Definition: visdisplay.h:100
Class representing a shape.
Definition: visdisplay.h:43
Class representing a rectangle.
Definition: visdisplay.h:85
Class representing a line.
Definition: visdisplay.h:70
void draw(Cairo::RefPtr< Cairo::Context > cr)
Draw objects.
Definition: visdisplay.cpp:117
virtual ~Shape()
Virtual empty destructor.
Definition: visdisplay.cpp:195
VisualDisplay2DInterface Fawkes BlackBoard Interface.
unsigned int _owner
Owner ID.
Definition: visdisplay.h:67
VisualDisplay2D()
Constructor.
Definition: visdisplay.cpp:38
float _color_r
red part of RGBA object color
Definition: visdisplay.h:61