Play 'round
include/Shape.h
00001 #ifndef __SHAPE_H
00002 #define __SHAPE_H
00003 
00004 #include <vector>
00005 #include <algorithm>
00006 
00007 #include "Common.h"
00008 #include "Point.h"
00009 #include "Color.h"
00010 
00014 class Shape
00015 {
00016 public:
00017   virtual void draw() = 0;
00018   virtual void setColor(Color color) { m_color = color; }
00019 
00020   virtual void setDotted(bool fDotted) { m_fDotted = fDotted; }
00021   virtual void setDirected(bool fDirected) { m_fDirected = fDirected; }
00022   virtual void setLineWidth(float lineWidth) { m_lineWidth = lineWidth; }
00023 
00024 protected:
00025   Color m_color;
00026   bool m_fDotted;
00027   bool m_fDirected;
00028   float m_lineWidth;
00029 };
00030 
00034 class Spiral : public Shape
00035 {
00036 public:
00037   Spiral(Point2D center, float startAngle, float startRadius, float endAngle, float endRadius);
00038 
00039   virtual void draw();
00040   virtual void setStartRadius(float radius) { m_startRadius = radius; }
00041   virtual void setEndRadius(float radius) { m_endRadius = radius; }
00042   virtual void setRadii(float startRadius, float endRadius) {
00043     m_startRadius = startRadius;
00044     m_endRadius = endRadius;
00045   }
00046   virtual void setCenter(Point2D center) { m_center = center; }
00047   virtual void setStartAngle(float angle) { m_startAngle = angle; }
00048   virtual void setEndAngle(float angle) { m_endAngle = angle; }
00049   virtual void setAngles(float startAngle, float endAngle) {
00050     m_startAngle = startAngle;
00051     m_endAngle = endAngle;
00052   }
00053 
00054   virtual float getStartRadius() { return m_startRadius; }
00055   virtual float getEndRadius() { return m_endRadius; }
00056 
00057   static float getAngle(Point2D center, Point2D p);
00061   static Point2D getPointFromRadius(Point2D center, float radius, float angle);
00065   static float clampAngle(float angle);
00066 
00067   void setFilled(bool filled);
00068   void setColor(const Color&);
00069 
00070 protected:
00071   Point2D m_center;
00072   float m_startRadius, m_endRadius,
00073         m_startAngle, m_endAngle;
00074   bool m_filled;
00075 };
00079 class Line : public Shape
00080 {
00081 public:
00082   Line(Point2D p1, Point2D p2);
00083 
00084   virtual void draw();
00085   virtual Point2D getP1() { return m_p1; }
00086   virtual Point2D getP2() { return m_p2; }
00087   virtual void setPoints(Point2D p1, Point2D p2) { m_p1 = p1; m_p2 = p2; }
00088   
00092   virtual float getDistance(Point2D pos);
00093   virtual float getParallelPosition(Point2D pos);
00094 
00095 protected:
00096   Point2D m_p1, m_p2;
00097 };
00098 
00102 class Text : public Shape
00103 {
00104 public:
00105   Text(Point2D pos, std::string str);
00106   virtual void draw();
00107   virtual void setPos(Point2D pos) { m_pos = pos; }
00108   virtual Point2D getPos() { return m_pos; }
00109   virtual void setText(std::string str) { m_str = str; }
00110   virtual std::string getText() { return m_str; }
00111   virtual int getWidth();
00112 
00113 private:
00114   Point2D m_pos;
00115   std::string m_str;
00116 };
00117 #endif
 All Classes Functions Enumerations