summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/drawfill.h
blob: 14666d1df5f87c19c428b43a05bc126530eea1ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*****
 * drawfill.h
 * Andy Hammerlindl 2002/06/06
 *
 * Stores a cyclic path that will outline a filled shape in a picture.
 *****/

#ifndef DRAWFILL_H
#define DRAWFILL_H

#include "drawelement.h"
#include "path.h"

namespace camp {

class drawFill : public drawSuperPathPenBase {
protected:  
  bool stroke;
public:
  void noncyclic() {
    reportError("non-cyclic path cannot be filled");
  }
  
  drawFill(const vm::array& src, bool stroke, pen pentype)
    : drawSuperPathPenBase(src,pentype), stroke(stroke) {
    if(!stroke && !cyclic()) noncyclic();
  }

  virtual ~drawFill() {}

  bool draw(psfile *out);
  virtual void palette(psfile *out) {
    penSave(out);
    penTranslate(out);
  }
  virtual void fill(psfile *out) {
    out->setpen(pentype);
    if(stroke) out->strokepath();
    out->fill(pentype);
    penRestore(out);
  };

  drawElement *transformed(const transform& t);
};
  
class drawShade : public drawFill {
public:
  drawShade(const vm::array& src, bool stroke, pen pentype)
    : drawFill(src,stroke,pentype) {}

  void bounds(bbox& b, iopipestream& iopipe, boxvector& vbox,
              bboxlist& bboxstack) {
    if(stroke) strokebounds(b);
    else drawSuperPathPenBase::bounds(b,iopipe,vbox,bboxstack);
  }
  
  virtual void shade(psfile *out)=0;
  void fill(psfile *out) {
    if(stroke) strokepath(out);
    out->clip(pentype.Fillrule());
    shade(out);
    out->grestore();
  }
};
  
class drawLatticeShade : public drawShade {
protected:
  vm::array pens;
public:  
  drawLatticeShade(const vm::array& src, bool stroke, pen pentype,
                   const vm::array& pens)
    : drawShade(src,stroke,pentype), pens(pens) {}
  
  void palette(psfile *out) {
    out->gsave();
  }
  
  void shade(psfile *out) {
    out->latticeshade(pens,bpath);
  }
  
  drawElement *transformed(const transform& t);
};
  
class drawAxialShade : public drawShade {
protected:
  pair a;
  pen penb;
  pair b;
  ColorSpace colorspace;
public:  
  drawAxialShade(const vm::array& src, bool stroke, pen pentype,
                 pair a, pen penb, pair b) 
    : drawShade(src,stroke,pentype), a(a), penb(penb), b(b) {}
  
  void palette(psfile *out);
  
  void shade(psfile *out) {
    out->gradientshade(true,colorspace,pentype,a,0,penb,b,0);
  }
  
  drawElement *transformed(const transform& t);
};
  
class drawRadialShade : public drawAxialShade {
protected:
  double ra;
  double rb;
public:
  drawRadialShade(const vm::array& src, bool stroke,
                  pen pentype, pair a, double ra, pen penb, pair b, double rb)
    : drawAxialShade(src,stroke,pentype,a,penb,b), ra(ra), rb(rb) {}
  
  void shade(psfile *out) {
    out->gradientshade(false,colorspace,pentype,a,ra,penb,b,rb);
  }
  
  drawElement *transformed(const transform& t);
};
  
class drawGouraudShade : public drawShade {
protected:
  vm::array pens,vertices,edges;
public:  
  drawGouraudShade(const vm::array& src, bool stroke, pen pentype,
                   const vm::array& pens, const vm::array& vertices,
                   const vm::array& edges)
    : drawShade(src,stroke,pentype), pens(pens), vertices(vertices),
      edges(edges) {}
  
  void palette(psfile *out) {
    out->gsave();
  }
  
  void shade(psfile *out) {
    out->gouraudshade(pens,vertices,edges);
  }
  
  drawElement *transformed(const transform& t);
};
  
class drawTensorShade : public drawShade {
protected:
  vm::array pens,boundaries,z;
public:  
  drawTensorShade(const vm::array& src, bool stroke,
                  pen pentype, const vm::array& pens,
                  const vm::array& boundaries, const vm::array& z)
    : drawShade(src,stroke,pentype), pens(pens), boundaries(boundaries), z(z) {}
  
  void palette(psfile *out) {
    out->gsave();
  }
  
  void shade(psfile *out) {
    out->tensorshade(pens,boundaries,z);
  }
  
  drawElement *transformed(const transform& t);
};
  
class drawFunctionShade : public drawFill {
protected:  
  string shader;
public:
  drawFunctionShade(const vm::array& src, bool stroke, pen pentype,
                    const string& shader)
    : drawFill(src,stroke,pentype), shader(shader) {
    string texengine=settings::getSetting<string>("tex");
    if(!settings::pdf(texengine))
      reportError("functionshade is not implemented for the '"+texengine+
                  "' tex engine");
  }

  virtual ~drawFunctionShade() {}

  bool draw(psfile *out) {return false;}
  
  bool write(texfile *, const bbox&);
  
  bool islabel() {return true;}
  
  drawElement *transformed(const transform& t);
};
  
}

#endif