visdisplay.h

00001 
00002 /***************************************************************************
00003  *  visdisplay.h - Visual Display to show VisualDisplay2DInterface objects
00004  *
00005  *  Created: Thu Jan 07 23:36:15 2010
00006  *  Copyright  2008-2010  Tim Niemueller [www.niemueller.de]
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.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022 
00023 #ifndef __TOOLS_LASERGUI_VISDISPLAY_H_
00024 #define __TOOLS_LASERGUI_VISDISPLAY_H_
00025 
00026 #include <cairomm/context.h>
00027 #include <string>
00028 #include <map>
00029 
00030 #include <interfaces/VisualDisplay2DInterface.h>
00031 
00032 class VisualDisplay2D
00033 {
00034  public:
00035   VisualDisplay2D();
00036   ~VisualDisplay2D();
00037 
00038   void set_interface(fawkes::VisualDisplay2DInterface *interface);
00039 
00040   void process_messages();
00041   void draw(Cairo::RefPtr<Cairo::Context> cr);
00042 
00043   class Shape {
00044    public:
00045     Shape(unsigned int id, unsigned int owner,
00046           fawkes::VisualDisplay2DInterface::LineStyle line_style = fawkes::VisualDisplay2DInterface::LS_SOLID,
00047           unsigned char r = 0, unsigned char g = 0,
00048           unsigned char b = 0, unsigned char a = 0);
00049     virtual ~Shape();
00050     virtual void draw(Cairo::RefPtr<Cairo::Context> &cr) = 0;
00051     inline void apply_style(Cairo::RefPtr<Cairo::Context> &cr)
00052     { cr->set_source_rgba(_color_r, _color_g, _color_b, _color_a); }
00053 
00054     inline unsigned int id() { return _id; }
00055     inline unsigned int owner() { return _owner; }
00056     inline void color(float &r, float &g, float &b, float &a)
00057     { r = _color_r; g = _color_g; b = _color_b; a = _color_a; }
00058    protected:
00059 
00060     fawkes::VisualDisplay2DInterface::LineStyle  _line_style;   /**< Line style */
00061     float         _color_r;     /**< red part of RGBA object color */
00062     float         _color_g;     /**< green part of RGBA object color */
00063     float         _color_b;     /**< blue part of RGBA object color */
00064     float         _color_a;     /**< alpha part of RGBA object color */
00065 
00066     unsigned int  _id;          /**< Object ID */
00067     unsigned int  _owner;       /**< Owner ID */
00068   };
00069 
00070   class Line : public Shape {
00071    public:
00072     Line(float x1, float y1, float x2, float y2,
00073          unsigned int id, unsigned int owner,
00074          fawkes::VisualDisplay2DInterface::LineStyle line_style = fawkes::VisualDisplay2DInterface::LS_SOLID,
00075          unsigned char r = 0, unsigned char g = 0,
00076          unsigned char b = 0, unsigned char a = 0);
00077     void draw(Cairo::RefPtr<Cairo::Context> &cr);
00078   private:
00079     float __x1;
00080     float __y1;
00081     float __x2;
00082     float __y2;
00083   };
00084 
00085   class Rectangle : public Shape {
00086    public:
00087     Rectangle(float x, float y, float width, float height,
00088               unsigned int id, unsigned int owner,
00089               fawkes::VisualDisplay2DInterface::LineStyle line_style = fawkes::VisualDisplay2DInterface::LS_SOLID,
00090               unsigned char r = 0, unsigned char g = 0,
00091               unsigned char b = 0, unsigned char a = 0);
00092     void draw(Cairo::RefPtr<Cairo::Context> &cr);
00093    private:
00094     float __x;
00095     float __y;
00096     float __width;
00097     float __height;
00098   };
00099 
00100   class Circle : public Shape {
00101    public:
00102     Circle(float x, float y, float radius,
00103            unsigned int id, unsigned int owner,
00104            fawkes::VisualDisplay2DInterface::LineStyle line_style = fawkes::VisualDisplay2DInterface::LS_SOLID,
00105            unsigned char r = 0, unsigned char g = 0,
00106            unsigned char b = 0, unsigned char a = 0);
00107     void draw(Cairo::RefPtr<Cairo::Context> &cr);
00108    private:
00109     float __x;
00110     float __y;
00111     float __radius;
00112   };
00113 
00114   class Text : public Shape {
00115    public:
00116     Text(float x, float y, std::string text,
00117          fawkes::VisualDisplay2DInterface::Anchor anchor,
00118          float size,
00119          unsigned int id, unsigned int owner,
00120          unsigned char r = 0, unsigned char g = 0,
00121          unsigned char b = 0, unsigned char a = 0);
00122     void draw(Cairo::RefPtr<Cairo::Context> &cr);
00123    private:
00124     float __x;
00125     float __y;
00126     std::string __text;
00127     float __size;
00128     fawkes::VisualDisplay2DInterface::Anchor __anchor;
00129   };
00130 
00131  private:
00132   std::map<unsigned int, Shape *>  __shapes;
00133   std::map<unsigned int, Shape *>::iterator  __sit;
00134   fawkes::VisualDisplay2DInterface  *__interface;
00135 };
00136 
00137 
00138 #endif

Generated on 1 Mar 2011 for Fawkes API by  doxygen 1.6.1