00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 using System;
00053 using System.Drawing;
00054 using System.Drawing.Drawing2D;
00055
00056 namespace NPlot
00057 {
00058
00062 public class Marker
00063 {
00064
00068 public enum MarkerType
00069 {
00073 Cross1,
00077 Cross2,
00081 Circle,
00085 Square,
00089 Triangle,
00093 TriangleUp,
00097 TriangleDown,
00101 Diamond,
00105 FilledCircle,
00109 FilledSquare,
00113 FilledTriangle,
00117 Flag,
00121 FlagUp,
00125 FlagDown,
00129 None
00130 }
00131
00132 private MarkerType markerType_;
00133 private int size_;
00134 private int h_;
00135 private System.Drawing.Pen pen_ = new Pen( Color.Black );
00136 private System.Drawing.Brush brush_ = new SolidBrush( Color.Black );
00137 private bool filled_ = false;
00138 private bool dropLine_ = false;
00139
00140
00144 public MarkerType Type
00145 {
00146 get
00147 {
00148 return markerType_;
00149 }
00150 set
00151 {
00152 markerType_ = value;
00153 }
00154 }
00155
00156
00160 public bool DropLine
00161 {
00162 get
00163 {
00164 return dropLine_;
00165 }
00166 set
00167 {
00168 dropLine_ = value;
00169 }
00170 }
00171
00172
00176 public int Size
00177 {
00178 get
00179 {
00180 return size_;
00181 }
00182 set
00183 {
00184 size_ = value;
00185 h_ = size_/2;
00186 }
00187 }
00188
00189
00193 public Brush FillBrush
00194 {
00195 get
00196 {
00197 return brush_;
00198 }
00199 set
00200 {
00201 brush_ = value;
00202 }
00203 }
00204
00205
00209 public bool Filled
00210 {
00211 get
00212 {
00213 return filled_;
00214 }
00215 set
00216 {
00217 filled_ = value;
00218 }
00219 }
00220
00221
00225 public System.Drawing.Color Color
00226 {
00227 set
00228 {
00229 pen_.Color = value;
00230 brush_ = new SolidBrush( value );
00231 }
00232 get
00233 {
00234 return pen_.Color;
00235 }
00236 }
00237
00238
00242 public System.Drawing.Pen Pen
00243 {
00244 set
00245 {
00246 pen_ = value;
00247 }
00248 get
00249 {
00250 return pen_;
00251 }
00252 }
00253
00254
00258 public Marker()
00259 {
00260 markerType_ = MarkerType.Square;
00261 Size = 4;
00262 filled_ = false;
00263 }
00264
00265
00270 public Marker( MarkerType markertype )
00271 {
00272 markerType_ = markertype;
00273 Size = 4;
00274 filled_ = false;
00275 }
00276
00282 public Marker( MarkerType markertype, int size )
00283 {
00284 markerType_ = markertype;
00285 Size = size;
00286 filled_ = false;
00287 }
00288
00289
00296 public Marker( MarkerType markertype, int size, Color color )
00297 {
00298 markerType_ = markertype;
00299 Size = size;
00300 Color = color;
00301 filled_ = false;
00302 }
00303
00304
00311 public Marker( MarkerType markertype, int size, Pen pen )
00312 {
00313 markerType_ = markertype;
00314 Size = size;
00315 Pen = pen;
00316 filled_ = false;
00317 }
00318
00319
00327 public Marker( MarkerType markertype, int size, Pen pen, bool fill )
00328 {
00329 markerType_ = markertype;
00330 Size = size;
00331 Pen = pen;
00332 filled_ = fill;
00333 }
00334
00335
00336
00343 public void Draw( Graphics g, int x, int y )
00344 {
00345
00346 switch (markerType_)
00347 {
00348
00349 case MarkerType.Cross1:
00350 g.DrawLine( pen_, x-h_, y+h_, x+h_, y-h_ );
00351 g.DrawLine( pen_, x+h_, y+h_, x-h_, y-h_ );
00352 break;
00353
00354 case MarkerType.Cross2:
00355 g.DrawLine( pen_, x, y-h_, x, y+h_ );
00356 g.DrawLine( pen_, x-h_, y, x+h_, y );
00357 break;
00358
00359 case MarkerType.Circle:
00360 g.DrawEllipse( pen_, x-h_, y-h_, size_, size_ );
00361 if ( this.filled_ )
00362 {
00363 g.FillEllipse( brush_, x-h_, y-h_, size_, size_ );
00364 }
00365 break;
00366
00367 case MarkerType.Square:
00368 g.DrawRectangle( pen_, x-h_, y-h_, size_, size_ );
00369 if ( this.filled_ )
00370 {
00371 g.FillRectangle( brush_, x-h_, y-h_, size_, size_ );
00372 }
00373 break;
00374
00375 case MarkerType.Triangle:
00376 case MarkerType.TriangleDown:
00377 {
00378 Point p1 = new Point( x-h_, y-h_ );
00379 Point p2 = new Point( x, y+h_ );
00380 Point p3 = new Point( x+h_, y-h_ );
00381 Point [] pts = new Point [3] { p1, p2, p3 };
00382 GraphicsPath gp = new GraphicsPath();
00383 gp.AddPolygon( pts );
00384 g.DrawPath( pen_, gp );
00385 if (this.filled_)
00386 {
00387 g.FillPath( brush_, gp );
00388 }
00389 break;
00390 }
00391 case MarkerType.TriangleUp:
00392 {
00393 Point p1 = new Point( x-h_, y+h_ );
00394 Point p2 = new Point( x, y-h_ );
00395 Point p3 = new Point( x+h_, y+h_ );
00396 Point [] pts = new Point [3] { p1, p2, p3 };
00397 GraphicsPath gp = new GraphicsPath();
00398 gp.AddPolygon( pts );
00399 g.DrawPath( pen_, gp );
00400 if (this.filled_)
00401 {
00402 g.FillPath( brush_, gp );
00403 }
00404 break;
00405 }
00406 case MarkerType.FilledCircle:
00407 g.DrawEllipse( pen_, x-h_, y-h_, size_, size_ );
00408 g.FillEllipse( brush_, x-h_, y-h_, size_, size_ );
00409 break;
00410
00411 case MarkerType.FilledSquare:
00412 g.DrawRectangle( pen_, x-h_, y-h_, size_, size_ );
00413 g.FillRectangle( brush_, x-h_, y-h_, size_, size_ );
00414 break;
00415
00416 case MarkerType.FilledTriangle:
00417 {
00418 Point p1 = new Point( x-h_, y-h_ );
00419 Point p2 = new Point( x, y+h_ );
00420 Point p3 = new Point( x+h_, y-h_ );
00421 Point [] pts = new Point [3] { p1, p2, p3 };
00422 GraphicsPath gp = new GraphicsPath();
00423 gp.AddPolygon( pts );
00424 g.DrawPath( pen_, gp );
00425 g.FillPath( brush_, gp );
00426 break;
00427 }
00428 case MarkerType.Diamond:
00429 {
00430 Point p1 = new Point( x-h_, y );
00431 Point p2 = new Point( x, y-h_ );
00432 Point p3 = new Point( x+h_, y );
00433 Point p4 = new Point( x, y+h_ );
00434 Point [] pts = new Point [4] { p1, p2, p3, p4 };
00435 GraphicsPath gp = new GraphicsPath();
00436 gp.AddPolygon( pts );
00437 g.DrawPath( pen_, gp );
00438 if (this.filled_)
00439 {
00440 g.FillPath( brush_, gp );
00441 }
00442 break;
00443 }
00444 case MarkerType.Flag:
00445 case MarkerType.FlagUp:
00446 {
00447 Point p1 = new Point( x, y );
00448 Point p2 = new Point( x, y-size_ );
00449 Point p3 = new Point( x+size_, y-size_+size_/3 );
00450 Point p4 = new Point( x, y-size_+2*size_/3 );
00451 g.DrawLine( pen_, p1, p2 );
00452 Point [] pts = new Point [3] { p2, p3, p4 };
00453 GraphicsPath gp = new GraphicsPath();
00454 gp.AddPolygon( pts );
00455 g.DrawPath( pen_, gp );
00456 if (this.filled_)
00457 {
00458 g.FillPath( brush_, gp );
00459 }
00460 break;
00461 }
00462 case MarkerType.FlagDown:
00463 {
00464 Point p1 = new Point( x, y );
00465 Point p2 = new Point( x, y+size_ );
00466 Point p3 = new Point( x+size_, y+size_-size_/3 );
00467 Point p4 = new Point( x, y+size_-2*size_/3 );
00468 g.DrawLine( pen_, p1, p2 );
00469 Point [] pts = new Point [3] { p2, p3, p4 };
00470 GraphicsPath gp = new GraphicsPath();
00471 gp.AddPolygon( pts );
00472 g.DrawPath( pen_, gp );
00473 if (this.filled_)
00474 {
00475 g.FillPath( brush_, gp );
00476 }
00477 break;
00478 }
00479 case MarkerType.None:
00480 break;
00481 }
00482
00483 }
00484
00485
00486 }
00487 }