OSDN Git Service

font
[psychlops/cpp.git] / psychlops / core / graphic / psychlops_g_module.cpp
1 /*
2  *  psychlops_g_module.cpp
3  *  Psychlops Standard Library (Universal)
4  *
5  *  Last Modified 2005/10/05 by Kenchi HOSOKAWA
6  *  (C) 2005 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
7  */
8
9
10 #include "../math/psychlops_math.h"
11 #include "psychlops_g_module.h"
12 #include "psychlops_g_canvas.h"
13
14
15 namespace Psychlops {
16         class DrawableDummy : virtual public Drawable {
17         public:
18                 void NoDrawableError() const { throw new Exception("Canvas-dependent function was called before the instantiation of Canvas."); }
19                 DrawableDummy() {}
20                 virtual ~DrawableDummy() {}
21                 virtual int getWidth() const { NoDrawableError(); return 0; }
22                 virtual int getHeight() const { NoDrawableError(); return 0; }
23                 virtual const Point getCenter() const { NoDrawableError(); return Point(); }    //  means this Drawable's local center.
24
25                 virtual Drawable& clear(const Color &col) { NoDrawableError(); return *this; }
26                 virtual Drawable& pix(const double x, const double y, const Color &col) { NoDrawableError(); return *this; }
27
28                 virtual Drawable& line(const Line &drawee, const Color &col) { NoDrawableError(); return *this; }
29                 virtual Drawable& line(const Line &drawee, const Stroke &strk) { NoDrawableError(); return *this; }
30                 virtual Drawable& rect(const Rectangle &drawee, const Color &col) { NoDrawableError(); return *this; }
31                 virtual Drawable& rect(const Rectangle &drawee, const Stroke &strk) { NoDrawableError(); return *this; }
32                 virtual Drawable& ellipse(const Ellipse &drawee) { NoDrawableError(); return *this; }
33                 virtual Drawable& ellipse(const Ellipse &drawee, const Color &col) { NoDrawableError(); return *this; }
34                 virtual Drawable& ellipse(const Ellipse &drawee, const Stroke &strk) { NoDrawableError(); return *this; }
35                 virtual Drawable& polygon(const Polygon &drawee) { NoDrawableError(); return *this; }
36                 virtual Drawable& polygon(const Polygon &drawee, const Color &col) { NoDrawableError(); return *this; }
37                 virtual Drawable& polygon(const Polygon &drawee, const Stroke &strk) { NoDrawableError(); return *this; }
38                 virtual Drawable& polyline(const PolyLine &drawee) { NoDrawableError(); return *this; }
39                 virtual Drawable& polyline(const PolyLine &drawee, const Color &col) { NoDrawableError(); return *this; }
40                 virtual Drawable& polyline(const PolyLine &drawee, const Stroke &strk) { NoDrawableError(); return *this; }
41                 virtual Drawable& figures(const Group &drawee) { NoDrawableError(); return *this; }
42                 virtual Drawable& figures(const Group &drawee, const Color &col) { NoDrawableError(); return *this; }
43
44                 virtual Drawable& image(const Image &img) { NoDrawableError(); return *this; }
45                 virtual Drawable& image(const Image &img, const double x, const double y) { NoDrawableError(); return *this; }
46                 virtual Drawable& image(Image &img, const Rectangle &target_rect, const Rectangle &source_rect) { NoDrawableError(); return *this; }
47                 virtual Drawable& image(const Image &img, const double) { NoDrawableError(); return *this; }
48                 virtual Drawable& letters(Letters &let, const Color &col) { NoDrawableError(); return *this; }
49         } drawableDummy;
50
51         const Drawable *Drawable::dummy = &drawableDummy;
52         Drawable *Drawable::prime = &drawableDummy;
53         DrawableWithCache *DrawableWithCache::prime = 0;
54         Group Drawable::billboard;
55         const bool Drawable::prime_is_a_canvas() {
56                 if(prime==dummy) return false;
57                 if(dynamic_cast<Canvas*>(prime)) return true;
58                 else return false;
59         }
60
61         Drawable::Drawable() {}
62         Drawable::~Drawable() {}
63
64
65
66
67 /*
68         Figure::DATUM_::DATUM_() {
69                 x.px_ = 0.0;
70                 y.px_ = 0.0;
71                 z.px_ = 0.0;
72         }
73
74         Figure::DATUM_::LENGTH_::operator double() const {
75                 return px_;
76         }
77         Figure::DATUM_::LENGTH_::operator Length() const {
78                 return Length(px_);
79         }
80         double Figure::DATUM_::LENGTH_::operator =(double val) {
81                 px_ = val;
82                 return val;
83         }
84         Length Figure::DATUM_::LENGTH_::operator =(Length &val) {
85                 px_ = val;
86                 return val;
87         }
88 */
89
90
91         Figure::~Figure() {}
92         Figure& Figure::join(Group &fg){ fg.append(this); return *this; }
93
94         FigureDatum::FigureDatum() : datum(0,0,0) {}
95         FigureDatum::~FigureDatum() {}
96         const Point FigureDatum::getDatum() const {
97                 return datum;
98         }
99         FigureDatum& FigureDatum::setDatum(const Point& p) {
100                 datum = p;
101                 return *this;
102         }
103         FigureDatum& FigureDatum::centering(const Point & p) {
104                 datum = p;
105                 return *this;
106         }
107 /*      FigureDatum& FigureDatum::centering(const Figure& fig) {
108                 centering(fig.getDatum());
109                 return *this;
110         }
111         FigureDatum& FigureDatum::centering(const Drawable& target) {
112                 centering(target.getCenter());
113                 return *this;
114         }
115         FigureDatum& FigureDatum::centering(const double x, const double y, const double z) {
116                 centering(Point(x,y,z));
117                 return *this;
118         }
119         FigureDatum& FigureDatum::shift(const double x, const double y, const double z) {
120                 centering(datum.x+x, datum.y+y, datum.z+z);
121 //              centering(datum.x.px_+x, datum.y.px_+y, datum.z.px_+z);
122                 return *this;
123         }
124 */
125 //  see Specific/Graphic/psychlops_g_module_XX.cpp
126 //      const Figure& Figure::draw(const double x, const double y, const double z) const {
127 //              return *this;
128 //      }
129
130
131         Group::Group() : axis(0,0,1), scaling(1,1,1), rotation(0), clip_type(NONE), alpha_mask(0) {
132         }
133         Group& Group::append(Figure &fig) {
134                 contents.push_back(&fig);
135                 return *this;
136         }
137         Group& Group::append(Figure *fig) {
138                 contents.push_back(fig);
139                 return *this;
140         }
141         Group& Group::replace(int index, Figure *fig) {
142                 contents.at(index) = fig;
143                 return *this;
144         }
145         Group& Group::remove(int index) {
146                 if(index>=contents.size()) return *this;
147                 std::vector<Figure*>::iterator it = contents.begin();
148                 for(int i=0;i<index; i++) it++;
149                 contents.erase(it);
150                 return *this;
151         }
152
153
154         Group& Group::draw(Drawable &drawable) {
155                 drawable.figures(*this);
156                 return *this;
157         }
158 /*
159         Group& Group::draw(const Color &col, Drawable &drawable) {
160                 drawable.figures(*this, col);
161                 return *this;
162         }
163 */
164
165         Group& Group::clip(bool sw) {
166                 clip_type = NONE;
167                 return *this;
168         }
169         Group& Group::clip(const Rectangle &rect) {
170                 clip_type = RECT;
171                 scissor_top = rect.getTop();
172                 scissor_left = rect.getLeft();
173                 scissor_width = rect.getWidth();
174                 scissor_height = rect.getHeight();
175                 return *this;
176         }
177         Group& Group::clip(Image *img) {
178                 clip_type = ALPHA;
179                 alpha_mask = img;
180                 return *this;
181         }
182
183
184
185
186 }       /*      <- namespace Psycholops         */
187
188