TextureBrush.cs :  » 2.6.4-mono-.net-core » System.Drawing » System » Drawing » 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 » TextureBrush.cs
//
// System.Drawing.TextureBrush.cs
//
// Authors:
//   Dennis Hayes (dennish@Raytek.com)
//   Ravindra (rkumar@novell.com)
//   Sebastien Pouliot  <sebastien@ximian.com>
//
// (C) 2002 Ximian, Inc
// Copyright (C) 2004,2006-2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

namespace System.Drawing{

  public sealed class TextureBrush : Brush {

    internal TextureBrush (IntPtr ptr) :
      base (ptr)
    {
    }

    public TextureBrush (Image bitmap) :
      this (bitmap, WrapMode.Tile)
    {
    }

    public TextureBrush (Image image, Rectangle dstRect) :
      this (image, WrapMode.Tile, dstRect)
    {
    }

    public TextureBrush (Image image, RectangleF dstRect) :
      this (image, WrapMode.Tile, dstRect)
    {
    }

    public TextureBrush (Image image, WrapMode wrapMode)
    {
      if (image == null)
        throw new ArgumentNullException ("image");
      if ((wrapMode < WrapMode.Tile) || (wrapMode > WrapMode.Clamp))
        throw new InvalidEnumArgumentException ("WrapMode");

      Status status = GDIPlus.GdipCreateTexture (image.nativeObject, wrapMode, out nativeObject);
      GDIPlus.CheckStatus (status);
    }

    [MonoLimitation ("ImageAttributes are ignored when using libgdiplus")]
    public TextureBrush (Image image, Rectangle dstRect, ImageAttributes imageAttr)
    {
      if (image == null)
        throw new ArgumentNullException ("image");

      IntPtr attr = imageAttr == null ? IntPtr.Zero : imageAttr.NativeObject;
      Status status = GDIPlus.GdipCreateTextureIAI (image.nativeObject, attr, dstRect.X, dstRect.Y, 
        dstRect.Width, dstRect.Height, out nativeObject);
      GDIPlus.CheckStatus (status);
    }

    [MonoLimitation ("ImageAttributes are ignored when using libgdiplus")]
    public TextureBrush (Image image, RectangleF dstRect, ImageAttributes imageAttr)
    {  
      if (image == null)
        throw new ArgumentNullException ("image");

      IntPtr attr = imageAttr == null ? IntPtr.Zero : imageAttr.NativeObject;
      Status status = GDIPlus.GdipCreateTextureIA (image.nativeObject, attr, dstRect.X, dstRect.Y, 
        dstRect.Width, dstRect.Height, out nativeObject);
      GDIPlus.CheckStatus (status);      
    }

    public TextureBrush (Image image, WrapMode wrapMode, Rectangle dstRect)
    {
      if (image == null)
        throw new ArgumentNullException ("image");
      if ((wrapMode < WrapMode.Tile) || (wrapMode > WrapMode.Clamp))
        throw new InvalidEnumArgumentException ("WrapMode");

      Status status = GDIPlus.GdipCreateTexture2I (image.nativeObject, wrapMode, dstRect.X, dstRect.Y, 
        dstRect.Width, dstRect.Height, out nativeObject);
      GDIPlus.CheckStatus (status);
    }

    public TextureBrush (Image image, WrapMode wrapMode, RectangleF dstRect)
    {
      if (image == null)
        throw new ArgumentNullException ("image");
      if ((wrapMode < WrapMode.Tile) || (wrapMode > WrapMode.Clamp))
        throw new InvalidEnumArgumentException ("WrapMode");

      Status status = GDIPlus.GdipCreateTexture2 (image.nativeObject, wrapMode, dstRect.X, dstRect.Y, 
        dstRect.Width, dstRect.Height, out nativeObject);
      GDIPlus.CheckStatus (status);
    }

    // properties

    public Image Image {
      get {
        // this check is required here as GDI+ doesn't check for it 
        if (nativeObject == IntPtr.Zero)
          throw new ArgumentException ("Object was disposed");

        IntPtr img;
        Status status = GDIPlus.GdipGetTextureImage (nativeObject, out img);
        GDIPlus.CheckStatus (status);
        return new Bitmap (img);
      }
    }

    public Matrix Transform {
      get {
        Matrix matrix = new Matrix ();
        Status status =  GDIPlus.GdipGetTextureTransform (nativeObject, matrix.nativeMatrix);
        GDIPlus.CheckStatus (status);

        return matrix;
      }
      set {
        if (value == null)
          throw new ArgumentNullException ("Transform");

        Status status = GDIPlus.GdipSetTextureTransform (nativeObject, value.nativeMatrix);
        GDIPlus.CheckStatus (status);
      }
    }

    public WrapMode WrapMode {
      get {
        WrapMode mode;
        Status status = GDIPlus.GdipGetTextureWrapMode (nativeObject, out mode);
        GDIPlus.CheckStatus (status);
        return mode;
      }
      set {
        if ((value < WrapMode.Tile) || (value > WrapMode.Clamp))
          throw new InvalidEnumArgumentException ("WrapMode");

        Status status = GDIPlus.GdipSetTextureWrapMode (nativeObject, value);
        GDIPlus.CheckStatus (status);
      }
    }

    // public methods

    public override object Clone ()
    {
      IntPtr clonePtr;
      Status status = GDIPlus.GdipCloneBrush (nativeObject, out clonePtr);
      GDIPlus.CheckStatus (status);

      return new TextureBrush (clonePtr);
    }

    public void MultiplyTransform (Matrix matrix)
    {
      MultiplyTransform (matrix, MatrixOrder.Prepend);
    }

    public void MultiplyTransform (Matrix matrix, MatrixOrder order)
    {
      if (matrix == null)
        throw new ArgumentNullException ("matrix");

      Status status = GDIPlus.GdipMultiplyTextureTransform (nativeObject, matrix.nativeMatrix, order);
      GDIPlus.CheckStatus (status);
    }

    public void ResetTransform ()
    {
      Status status = GDIPlus.GdipResetTextureTransform (nativeObject);
      GDIPlus.CheckStatus (status);
    }

    public void RotateTransform (float angle)
    {
      RotateTransform (angle, MatrixOrder.Prepend);
    }

    public void RotateTransform (float angle, MatrixOrder order)
    {
      Status status = GDIPlus.GdipRotateTextureTransform (nativeObject, angle, order);
      GDIPlus.CheckStatus (status);
    }

    public void ScaleTransform (float sx, float sy)
    {
      ScaleTransform (sx, sy, MatrixOrder.Prepend);
    }

    public void ScaleTransform (float sx, float sy, MatrixOrder order)
    {
      Status status = GDIPlus.GdipScaleTextureTransform (nativeObject, sx, sy, order);
      GDIPlus.CheckStatus (status);
    }

    public void TranslateTransform (float dx, float dy)
    {
      TranslateTransform (dx, dy, MatrixOrder.Prepend);
    }

    public void TranslateTransform (float dx, float dy, MatrixOrder order)
    {
      Status status = GDIPlus.GdipTranslateTextureTransform (nativeObject, dx, dy, order);
      GDIPlus.CheckStatus (status);
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.