Marker.cs

Go to the documentation of this file.
00001 /*
00002 NPlot - A charting library for .NET
00003 
00004 Marker.cs
00005 Copyright (C) 2003
00006 Paolo Pierini, Matt Howlett
00007 
00008 Redistribution and use of NPlot or parts there-of in source and
00009 binary forms, with or without modification, are permitted provided
00010 that the following conditions are met:
00011 
00012 1. Re-distributions in source form must retain at the head of each
00013    source file the above copyright notice, this list of conditions
00014    and the following disclaimer.
00015 
00016 2. Any product ("the product") that makes use NPlot or parts 
00017    there-of must either:
00018   
00019     (a) allow any user of the product to obtain a complete machine-
00020         readable copy of the corresponding source code for the 
00021         product and the version of NPlot used for a charge no more
00022         than your cost of physically performing source distribution,
00023         on a medium customarily used for software interchange, or:
00024 
00025     (b) reproduce the following text in the documentation, about 
00026         box or other materials intended to be read by human users
00027         of the product that is provided to every human user of the
00028         product: 
00029    
00030               "This product includes software developed as 
00031               part of the NPlot library project available 
00032               from: http://www.nplot.com/" 
00033 
00034         The words "This product" may optionally be replace with 
00035         the actual name of the product.
00036 
00037 ------------------------------------------------------------------------
00038 
00039 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00040 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00041 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00042 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00043 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00044 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00045 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00046 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00047 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00048 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 }

Generated on Sat Nov 5 01:04:06 2005 for NPlot by  doxygen 1.4.5