PathGradientBrush.jvm.cs :  » 2.6.4-mono-.net-core » System.Drawing » System » Drawing » Drawing2D » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » 2.6.4 mono .net core » System.Drawing 
System.Drawing » System » Drawing » Drawing2D » PathGradientBrush.jvm.cs


using System;
using System.Drawing;
using System.Runtime.InteropServices;
using awtjava.awt;

namespace System.Drawing.Drawing2D{
  /// <summary>
  /// Summary description for PathGradientBrush.
  /// </summary>
  [MonoTODO]
  public sealed class PathGradientBrush : Brush {
    Brush _nativeObject;
    Blend _blend;
    Color _centerColor;
    PointF _center;
    PointF _focus;
    RectangleF _rectangle;
    Color [] _surroundColors;
    ColorBlend _interpolationColors;
    WrapMode _wrapMode;
    GraphicsPath _texturePath;
    bool _triangularShape = false;

    protected override java.awt.Paint NativeObject {
      get {
        return _nativeObject;
      }
    }

    #region initialize

    void Initialize(GraphicsPath path, WrapMode wrapMode, bool initColors, bool calcCenter) {
      
      _texturePath = path;
      _wrapMode = wrapMode;
      _rectangle = path.GetBounds();

      if (initColors) {
        _centerColor = Color.Black;
        _surroundColors = new Color []{ Color.White };
      }
      
      Bitmap texture = new Bitmap( (int)_rectangle.Width, (int)_rectangle.Height );
      Graphics g = Graphics.FromImage( texture );
      PointF [] pathPoints = path.PathPoints;

      if (calcCenter) {
        for (int i=0; i < pathPoints.Length; i++) {
          _center.X += pathPoints[i].X;
          _center.Y += pathPoints[i].Y;
        }
        _center.X /= pathPoints.Length;
        _center.Y /= pathPoints.Length;
      }

      int outerColor = 0;
      DrawSector( g, CenterPoint, pathPoints[pathPoints.Length-1], pathPoints[0], CenterColor, SurroundColors[outerColor] );
      for(int i=0; i < pathPoints.Length - 1; i++) {
        if (outerColor < SurroundColors.Length - 1)
          outerColor++;
        DrawSector( g, CenterPoint, pathPoints[i], pathPoints[i+1], CenterColor, SurroundColors[outerColor] );
      }

      _nativeObject = new TextureBrush( texture );
    }
    private void DrawSector(Graphics g, PointF center, PointF p1, PointF p2, Color innerColor, Color outerColor) {
      GraphicsPath pt = new GraphicsPath();
      pt.AddLine(p1, center);
      pt.AddLine(center, p2);
      LinearGradientBrush lgb = new LinearGradientBrush( GetVertical(center, p1, p2) , center, outerColor, innerColor );
      if (_triangularShape)
        lgb.SetBlendTriangularShape(0.5f);
      g.FillPath( lgb, pt );
    }
    private PointF GetVertical(PointF c, PointF p1, PointF p2) {
      if (p1.X == p2.X)
        return new PointF(p1.X, c.Y);
      if (p1.Y == p2.Y)
        return new PointF(c.X, p2.Y);

      float a = (float)(p2.Y - p1.Y) / (p2.X - p1.X);
      float av = - 1 / a;

      float b1 = p1.Y - a * p1.X;
      float b2 = c.Y - av * c.X;

      float ox = (b1 - b2) / (av - a);
      float oy = av * ox + b2;

      return new PointF(ox, oy);
    }

    #endregion

    #region ctors

    public PathGradientBrush (GraphicsPath path) {
      Initialize( path, WrapMode.Clamp, true, true );
    }

    public PathGradientBrush (Point [] points) : this (points, WrapMode.Clamp) {
    }

    public PathGradientBrush (PointF [] points) : this (points, WrapMode.Clamp) {
    }

    public PathGradientBrush (Point [] points, WrapMode wrapMode) {
      GraphicsPath path = new GraphicsPath();
      path.AddLines( points );
      Initialize( path, wrapMode, true, true );
    }

    public PathGradientBrush (PointF [] points, WrapMode wrapMode) {
      GraphicsPath path = new GraphicsPath();
      path.AddLines( points );
      Initialize( path, wrapMode, true, true );
    }

    #endregion

    #region Properties

    [MonoTODO]
    public Blend Blend {
      get {
        return _blend;
      }
      set {
        _blend = value;
      }
    }

    public Color CenterColor {
      get {
        return _centerColor;
      }
      set {
        _centerColor = value;
        Initialize(_texturePath, _wrapMode, false, false );
      }
    }

    public PointF CenterPoint {
      get {
        return _center;
      }
      set {
        _center = value;
        Initialize(_texturePath, _wrapMode, false, false );
      }
    }

    public PointF FocusScales {
      get {
        return _focus;
      }
      set {
        _focus = value;
      }
    }

    public ColorBlend InterpolationColors {
      get {
        return _interpolationColors;
      }
      set {
        _interpolationColors = value;
      }
    }

    public RectangleF Rectangle {
      get {
        return _rectangle;
      }
    }

    public Color [] SurroundColors {
      get {
        return _surroundColors;
      }
      set {
        _surroundColors = value;
        Initialize(_texturePath, _wrapMode, false, false );
      }
    }

    public Matrix Transform {
      get {
        return BrushTransform;
      }
      set {
        BrushTransform = value;
      }
    }

    public WrapMode WrapMode {
      get {
        return _wrapMode;
      }
      set {
        _wrapMode = value;
      }
    }

    #endregion

    #region Methods

    public void MultiplyTransform (Matrix matrix) {
      base.BrushMultiplyTransform( matrix );
    }

    public void MultiplyTransform (Matrix matrix, MatrixOrder order) {
      base.BrushMultiplyTransform( matrix, order );
    }

    public void ResetTransform () {
      base.BrushResetTransform();
    }

    public void RotateTransform (float angle) {
      base.BrushRotateTransform( angle );
    }

    public void RotateTransform (float angle, MatrixOrder order) {
      base.BrushRotateTransform( angle, order );
    }

    public void ScaleTransform (float sx, float sy) {
      base.BrushScaleTransform( sx, sy );
    }

    public void ScaleTransform (float sx, float sy, MatrixOrder order) {
      base.BrushScaleTransform( sx, sy, order );
    }

    public void SetBlendTriangularShape (float focus) {
      SetBlendTriangularShape (focus, 1.0F);
    }

    public void SetBlendTriangularShape (float focus, float scale) {
      _triangularShape = true;
      Initialize( _texturePath, _wrapMode, false, false );
    }

    public void SetSigmaBellShape (float focus) {
      SetSigmaBellShape (focus, 1.0F);
    }

    [MonoTODO]
    public void SetSigmaBellShape (float focus, float scale) {
      // FALLBACK: Triangle shape used
      SetBlendTriangularShape (focus, scale);
    }

    public void TranslateTransform (float dx, float dy) {
      base.BrushTranslateTransform( dx, dy );
    }

    public void TranslateTransform (float dx, float dy, MatrixOrder order) {
      base.BrushTranslateTransform( dx, dy, order );
    }

    public override object Clone () {
      PathGradientBrush copy = (PathGradientBrush)InternalClone();

      if (copy._nativeObject != null)
        copy._nativeObject = (Brush)copy._nativeObject.Clone();
      
      if (copy._surroundColors != null)
        copy._surroundColors = (Color[])copy._surroundColors.Clone();
      
      if (copy._texturePath != null)
        copy._texturePath = (GraphicsPath)copy._texturePath.Clone();

      //TBD: clone _blend, _interpolationColors
      //copy._blend = copy._blend
      
      return copy;
    }

    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.