3 * Psychlops Standard Library (Universal)
5 * Last Modified 2006/01/04 by Kenchi HOSOKAWA
6 * (C) 2006 Kenchi HOSOKAWA, Kazushi MARUYA and Takao SATO
9 #ifndef HEADER_PSYCHLOPS_GRAPHIC_SHAPE
10 #define HEADER_PSYCHLOPS_GRAPHIC_SHAPE
13 #include "psychlops_g_fundamental.h"
14 #include "psychlops_g_color.h"
15 #include "psychlops_g_module.h"
29 enum Pattern { SOLID=0xFFFF, DASHED=0x0F0F, DOTTED=0xAAAA };
33 unsigned short pattern;
36 Stroke(const Color col, const double wid, const Pattern pat);
37 Stroke& set(const Color col, const double wid, const Pattern pat);
39 static const Stroke null_line;
40 static const Stroke hair_line;
44 class Shape : virtual public Figure {
50 virtual Shape& draw_base(Drawable &target);
51 #if !defined(_MSC_VER)
52 virtual Shape& draw(Drawable &target = *Drawable::prime);
54 virtual Shape& draw(const Color &col, Drawable &target = *Drawable::prime) = 0;
55 virtual Shape& draw(const Stroke &strk, Drawable &target = *Drawable::prime) = 0;
57 using Figure::centering;
58 inline Shape& centering(const Figure& fig) { centering(fig.getDatum()); return *this; }
59 inline Shape& centering(const Drawable &target = *Drawable::prime) { centering(target.getCenter()); return *this; }
60 inline Shape& centering(const double x, const double y, const double z = 0) { centering(Point(x,y,z)); return *this; }
61 inline Shape& shift(const double x, const double y, const double z = 0) { Point n=getDatum(); n=n+Point(x,y,z); setDatum(n); return *this; }
\r
64 template<class T> class Colored : public T {
68 Colored<T>() : T(), color(Color::null_color), stroke(Stroke::null_line) {}
69 template<typename T1> Colored<T>(T1 a1) : T(a1), color(Color::null_color), stroke(Stroke::null_line) {}
70 template<typename T1, typename T2> Colored<T>(T1 a1, T2 a2) : T(a1, a2), color(Color::null_color), stroke(Stroke::null_line) {}
71 template<typename T1, typename T2, typename T3> Colored<T>(T1 a1, T2 a2, T3 a3) : T(a1, a2, a3), color(Color::null_color), stroke(Stroke::null_line) {}
72 template<typename T1, typename T2, typename T3, typename T4> Colored<T>(T1 a1, T2 a2, T3 a3, T4 a4) : T(a1, a2, a3, a4), color(Color::null_color), stroke(Stroke::null_line) {}
73 template<typename T1, typename T2, typename T3, typename T4, typename T5> Colored<T>(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) : T(a1, a2, a3, a4, a5), color(Color::null_color), stroke(Stroke::null_line) {}
74 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> Colored<T>(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) : T(a1, a2, a3, a4, a5, a6), color(Color::null_color), stroke(Stroke::null_line) {}
76 virtual Colored<T>& draw(Drawable &target = *Drawable::prime) {
77 if(color.getA()!=0) T::draw(color, target);
78 if(stroke.width!=0) T::draw(stroke, target);
81 virtual Colored<T>& draw(const Color &col, Drawable &target = *Drawable::prime) { T::draw(col, target); return *this; }
82 virtual Colored<T>& draw(const Stroke &strk, Drawable &target = *Drawable::prime) { T::draw(strk, target); return *this; }
90 class Rectangle : virtual public Shape {
92 friend class Canvas;
\r
93 friend class Devices::CanvasBits;
103 template <typename X> inline void correctInversion(X &l, X &t, X &r, X &b);
104 void setbypix(double l, double t, double r, double b);
105 void setbypix(double width, double height);
106 void set(double size);
110 Rectangle(double l, double t, double r, double b);
111 Rectangle(double width, double height);
112 //Rectangle(double width, double height);
113 //Rectangle(double width, double height, double hcentre, double vcentre);
114 Rectangle& set(const Rectangle &r);
115 Rectangle& set(const Point &po1, const Point &po2);
116 Rectangle& set(double l, double t, double r, double b);
117 Rectangle& set(double width, double height);
119 Rectangle& resize(double width, double height);
120 Rectangle& locate(const Point &p);
121 Rectangle& locate(double x, double y);
\r
123 virtual Rectangle& setDatum(const Point &po);
124 virtual Rectangle& centering(const Drawable& target = *Drawable::prime);
125 virtual Rectangle& centering(const Figure& fig);
126 virtual Rectangle& centering(const Point &po);
127 virtual Rectangle& centering(const double x, const double y, const double z = 0.0);
128 virtual Rectangle& move_to(const double x, const double y, const double z = 0.0);
129 virtual Rectangle& shift(const double h, const double v, const double d = 0.0);
\r
130 Rectangle& alignLeft(const double lef);
\r
131 Rectangle& alignTop(const double to_);
\r
132 Rectangle& alignRight(const double rig);
\r
133 Rectangle& alignBottom(const double bot);
\r
135 void clipped_by(const Rectangle &source);
136 void clip(Rectangle &target);
137 // obsolete: misspelled
138 void cripped(const Rectangle &source);
139 void crip(Rectangle &target);
140 bool include(double x, double y) const;
141 bool include(const Point &p) const;
142 bool include(const Rectangle &rect) const;
144 void setColor(Color col);
145 virtual Rectangle& draw(Drawable &target = *Drawable::prime);
146 virtual Rectangle& draw(const Color &col, Drawable &target = *Drawable::prime);
147 virtual Rectangle& draw(const Stroke &strk, Drawable &target = *Drawable::prime);
149 Rectangle& display();
150 Rectangle& display(const Color &col);
153 double getWidth() const;
154 double getHeight() const;
155 virtual const Point getDatum() const;
156 const Point getCenter() const;
157 double getHcenter() const;
158 double getVcenter() const;
159 double getTop() const;
160 double getLeft() const;
161 double getBottom() const;
162 double getRight() const;
\r
167 class Line : virtual public Shape, virtual public FigureDatum {
169 using FigureDatum::datum;
171 Line& setStart(const Point &dend);
172 Point getStart() const;
173 Line& setEnd(const Point &dend);
174 Point getEnd() const;
\r
176 Polygon *markerStart;
\r
180 Line(const double x1, const double y1, const double x2, const double y2);
181 Line(const Point &dbegin, const Point &dend);
182 Line& set(const double x1, const double y1, const double x2, const double y2);
183 Line& set(const Point &dbegin, const Point &dend);
185 virtual Line& setDatum(const Point &p);
186 virtual Line& centering(const Point &p);
187 virtual Line& shift(const double x, const double y, const double z = 0);
188 virtual Line& draw(Drawable &target = *Drawable::prime);
189 virtual Line& draw(const Color &col, Drawable &target = *Drawable::prime);
190 virtual Line& draw(const Stroke &strk, Drawable &target = *Drawable::prime);
192 using Shape::centering;
196 typedef Ellipse Oval;
197 class Ellipse : virtual public Shape, virtual public FigureDatum {
199 using FigureDatum::datum;
200 double radius, v_radius;
\r
201 double sector_begin, sector_end;
\r
205 Ellipse(const double d_radius, const double d_v_radius = -1, const Point& d_datum = Point());
206 Ellipse(const Rectangle& rect);
208 Ellipse& set(const double d_radius, const double d_v_radius = -1, const Point& d_datum = Point());
209 Ellipse& set(const Rectangle& rect);
\r
210 Ellipse& resize(double width, double height);
211 virtual Ellipse& centering(const Point &p);
212 virtual Ellipse& draw(Drawable &target = *Drawable::prime);
213 virtual Ellipse& draw(const Color &col, Drawable &target = *Drawable::prime);
214 virtual Ellipse& draw(const Stroke &strk, Drawable &target = *Drawable::prime);
216 virtual Ellipse& centering(const Figure& fig);
217 virtual Ellipse& centering(const Drawable &target = *Drawable::prime);
218 virtual Ellipse& centering(const double x, const double y, const double z = 0);
219 virtual Ellipse& shift(const double x, const double y, const double z = 0);
\r
221 using Shape::centering;
224 class Polygon : virtual public Shape, virtual public FigureDatum {
226 struct Vertex { Point point; };
229 std::deque<Point> vertices;
230 using FigureDatum::datum;
236 Polygon& append(const Point& p);
237 Polygon& append(const double x, const double y, const double z = 0.0);
238 // Polygon& append(const Point& p, const Color& col);
239 // Polygon& append(const double x, const double y, const double z, const Color& col);
240 // Polygon& append(const double x, const double y, const Color& col);
242 virtual Polygon& centering(const Point &p);
243 virtual Polygon& draw(Drawable &target = *Drawable::prime);
244 virtual Polygon& draw(const Color& col, Drawable &target = *Drawable::prime);
245 virtual Polygon& draw(const Stroke& strk, Drawable &target = *Drawable::prime);
247 virtual Polygon& centering(const Figure& fig);
248 virtual Polygon& centering(const Drawable &target = *Drawable::prime);
249 virtual Polygon& centering(const double x, const double y, const double z = 0);
250 virtual Polygon& shift(const double x, const double y, const double z = 0);
\r
252 using Shape::centering;
255 class PolyLine : virtual public Shape, virtual public FigureDatum {
257 struct Vertex { Point point; };
260 std::deque<Point> vertices;
261 using FigureDatum::datum;
264 PolyLine& append(const Point& p);
265 PolyLine& append(const double x, const double y, const double z = 0.0);
266 virtual PolyLine& centering(const Point &p);
267 virtual PolyLine& draw(Drawable &target = *Drawable::prime);
268 virtual PolyLine& draw(const Color& col, Drawable &target = *Drawable::prime);
269 virtual PolyLine& draw(const Stroke& strk, Drawable &target = *Drawable::prime);
271 virtual PolyLine& centering(const Figure& fig);
272 virtual PolyLine& centering(const Drawable &target = *Drawable::prime);
273 virtual PolyLine& centering(const double x, const double y, const double z = 0);
274 virtual PolyLine& shift(const double x, const double y, const double z = 0);
\r
276 using Shape::centering;
281 } /* <- namespace Psycholops */