00001
00011 #ifndef STROKE_H
00012 #define STROKE_H
00013
00014 #include <basic.h>
00015 #include <vector>
00016 #include <btron/dp.h>
00017 #include <tad.h>
00018 #include <btron/taddata.h>
00019 #include <limits.h>
00020
00022
00025 class AbstractStroke {
00026
00027 protected:
00028
00030 std::vector<PNT> poly;
00031
00033 static const int sz_header = 1;
00034
00035 int y_lbound;
00036 int y_ubound;
00037
00038 bool sel;
00039
00041 AbstractStroke()
00042 : y_lbound(INT_MAX), y_ubound(INT_MIN), sel(false)
00043 {
00044 PNT p;
00045 reinterpret_cast<POLY*>(&p)->round = 0;
00046 reinterpret_cast<POLY*>(&p)->size = 0;
00047 poly.push_back(p);
00048 }
00049
00050 public:
00051
00053
00056 virtual void clear() = 0;
00057
00059
00063 const POLY* getPoly() const {
00064 return reinterpret_cast<const POLY*>(&(poly[0]));
00065 }
00066
00068
00072 PNT getPoint(int index) const {
00073 return poly.at(index + sz_header);
00074 }
00075
00077
00081 int getSize() const {
00082 return poly.size() - sz_header;
00083 }
00084
00086
00090 int getLowerBound() const {
00091 return y_lbound;
00092 }
00093
00095
00099 int getUpperBound() const {
00100 return y_ubound;
00101 }
00102
00104
00108 void addPoint(const PNT& p);
00109
00111
00116 void moveOffset(int dh, int dv);
00117
00119
00126 bool hasIntersection(int lb, int ub) const {
00127 return (getSize() > 0 &&
00128 ((y_lbound < ub && y_lbound > lb)
00129 || (y_ubound < ub && y_ubound > lb)));
00130 }
00131
00132 };
00133
00134
00136
00139 class DrawingStroke : public AbstractStroke {
00140
00141 static int lwidth;
00142 static LATTR lattr;
00143 static PAT pat;
00144 static PAT pat_sel;
00145 static DCM dcm;
00146
00147 public:
00148
00150 DrawingStroke() : AbstractStroke() {}
00151
00153
00157 DrawingStroke(const TF_SPLINE *p) : AbstractStroke() {
00158 for (int i = 0; i < p->np; i++){
00159 addPoint(p->pt[i]);
00160 }
00161 }
00162
00164
00171 W draw(W gid, int lb, int ub) const;
00172
00174
00179 W drawSelection(W gid) const {
00180 return gdra_pln(gid, (POLY*)&(poly[0]), lattr, &pat_sel, dcm);
00181 }
00182
00184
00189 W drawLatest(W gid) const {
00190 int sz = getSize();
00191 if (sz >= 2){
00192 return gdra_lin(gid, getPoint(sz-2), getPoint(sz-1), lattr, &pat, dcm);
00193 }
00194 return 0;
00195 }
00196
00197 virtual void clear();
00198
00200
00204 void select(bool f) {
00205 sel = f;
00206 }
00207
00209
00214 bool isSelected() const {
00215 return sel;
00216 }
00217
00218 };
00219
00220
00222
00225 class SelectionStroke : public AbstractStroke {
00226
00227 static int lwidth;
00228 static LATTR lattr;
00229 static PAT pat_line;
00230 static PAT pat_fill;
00231 static DCM dcm_line;
00232 static DCM dcm_fill;
00233
00235 mutable bool sel_finished;
00236
00237 public:
00238
00240 SelectionStroke() : AbstractStroke(), sel_finished(false) {}
00241
00243
00246 void finishSelection() const {
00247 sel_finished = true;
00248 }
00249
00251
00256 bool isSelectionFinished() const {
00257 return sel_finished;
00258 }
00259
00261
00268 W draw(W gid, int lb, int ub) const;
00269
00271
00276 W drawLatest(W gid) const;
00277
00278 virtual void clear();
00279
00281
00287 bool contain(const PNT& p) const;
00288
00290
00296 bool contain(DrawingStroke& stroke) const;
00297
00298 };
00299
00300 #endif // STROKE_H