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{
34public:
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,
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
64 {
65 return _id;
66 }
67 inline fawkes::Uuid
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 fawkes::Uuid _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,
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,
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,
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,
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
186private:
187 std::map<unsigned int, Shape *> shapes_;
188 std::map<unsigned int, Shape *>::iterator sit_;
190};
191
192#endif
Class representing a circle Line represented by its center point and radius.
Definition: visdisplay.h:141
Circle(float x, float y, float radius, unsigned int id, fawkes::Uuid 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
void draw(Cairo::RefPtr< Cairo::Context > &cr)
Draw shape to Cairo context.
Definition: visdisplay.cpp:353
Class representing a line.
Definition: visdisplay.h:93
void draw(Cairo::RefPtr< Cairo::Context > &cr)
Draw shape to Cairo context.
Definition: visdisplay.cpp:265
Line(float x1, float y1, float x2, float y2, unsigned int id, fawkes::Uuid 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
Class representing a rectangle.
Definition: visdisplay.h:117
Rectangle(float x, float y, float width, float height, unsigned int id, fawkes::Uuid 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
void draw(Cairo::RefPtr< Cairo::Context > &cr)
Draw shape to Cairo context.
Definition: visdisplay.cpp:312
Class representing a shape.
Definition: visdisplay.h:44
fawkes::Uuid _owner
Owner ID.
Definition: visdisplay.h:89
unsigned int _id
Object ID.
Definition: visdisplay.h:88
float _color_g
green part of RGBA object color
Definition: visdisplay.h:84
virtual void draw(Cairo::RefPtr< Cairo::Context > &cr)=0
Draw shape to Cairo context.
fawkes::VisualDisplay2DInterface::LineStyle _line_style
Line style.
Definition: visdisplay.h:82
float _color_r
red part of RGBA object color
Definition: visdisplay.h:83
Shape(unsigned int id, fawkes::Uuid 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
float _color_b
blue part of RGBA object color
Definition: visdisplay.h:85
void apply_style(Cairo::RefPtr< Cairo::Context > &cr)
Set style on context.
Definition: visdisplay.h:57
fawkes::Uuid owner()
Get owner ID.
Definition: visdisplay.h:68
float _color_a
alpha part of RGBA object color
Definition: visdisplay.h:86
void color(float &r, float &g, float &b, float &a)
Get shape color.
Definition: visdisplay.h:73
unsigned int id()
Get shape ID.
Definition: visdisplay.h:63
virtual ~Shape()
Virtual empty destructor.
Definition: visdisplay.cpp:222
Class representing a text object.
Definition: visdisplay.h:163
void draw(Cairo::RefPtr< Cairo::Context > &cr)
Draw shape to Cairo context.
Definition: visdisplay.cpp:399
Text(float x, float y, const std::string &text, fawkes::VisualDisplay2DInterface::Anchor anchor, float size, unsigned int id, fawkes::Uuid owner, unsigned char r=0, unsigned char g=0, unsigned char b=0, unsigned char a=0)
Constructor.
Definition: visdisplay.cpp:378
2D visualization processor for VisualDisplay2DInterface.
Definition: visdisplay.h:33
VisualDisplay2D()
Constructor.
Definition: visdisplay.cpp:37
void set_interface(fawkes::VisualDisplay2DInterface *interface)
Set interface.
Definition: visdisplay.cpp:55
void draw(Cairo::RefPtr< Cairo::Context > cr)
Draw objects.
Definition: visdisplay.cpp:143
~VisualDisplay2D()
Destructor.
Definition: visdisplay.cpp:43
void process_messages()
Process messages.
Definition: visdisplay.cpp:65
A convenience class for universally unique identifiers (UUIDs).
Definition: uuid.h:29
VisualDisplay2DInterface Fawkes BlackBoard Interface.
Anchor
Enumeration defining the possible anchor points.
LineStyle
Enumeration defining the possible line styles.