System.Drawing.TextureBrush.Setup C# (CSharp) Method

Setup() private method

private Setup ( Graphics graphics, bool fill ) : void
graphics Graphics
fill bool
return void
        internal override void Setup(Graphics graphics, bool fill)
        {
            // if this is the same as the last that was set then return and no changes have been made
            // then return.
            if (graphics.LastBrush == this && !changed)
                return;

            // obtain our width and height so we can set the pattern rectangle
            float textureWidth = textureImage.Width;
            float textureHeight = textureImage.Height;

            if (wrapMode == WrapMode.TileFlipX || wrapMode == WrapMode.TileFlipY)
                textureWidth *= 2;

            if (wrapMode == WrapMode.TileFlipXY)
            {
                textureWidth *= 2;
                textureHeight *= 2;
            }

            // this is here for testing only
            var textureOffset = new PointF(0,-0);

            //choose the pattern to be filled based on the currentPattern selected
            var patternSpace = CGColorSpace.CreatePattern(null);
            graphics.context.SetFillColorSpace(patternSpace);
            patternSpace.Dispose();

            // Pattern default work variables
            var patternRect = new CGRect (HALF_PIXEL_X,HALF_PIXEL_Y,
                                             textureWidth+HALF_PIXEL_X,
                                             textureHeight+HALF_PIXEL_Y);
            var patternTransform = CGAffineTransform.MakeIdentity();

            // We need to take into account the orientation of the graphics object
            #if MONOMAC
            if (!graphics.isFlipped)
                patternTransform = new CGAffineTransform(1, 0, 0, -1,
                                                         textureOffset.X,
                                                         textureHeight + textureOffset.Y);
            #endif
            #if MONOTOUCH
            if (graphics.isFlipped)
                patternTransform = new CGAffineTransform(1, 0, 0, -1,
                                                         textureOffset.X,
                                                         textureHeight + textureOffset.Y);
            #endif

            patternTransform = CGAffineTransform.Multiply(patternTransform, textureTransform.transform);

            // DrawPattern callback which will be set depending on hatch style
            CGPattern.DrawPattern drawPattern;

            drawPattern = DrawTexture;

            //set the pattern as the Current Context’s fill pattern
            var pattern = new CGPattern(patternRect,
                                        patternTransform,
                                        textureWidth,
                                        textureHeight,
                                        //textureHeight,
                                        CGPatternTiling.NoDistortion,
                                        true, drawPattern);
            //we dont need to set any color, as the pattern cell itself has chosen its own color
            graphics.context.SetFillPattern(pattern, new nfloat[] { 1 });

            changed = false;

            graphics.LastBrush = this;
            // I am setting this to be used for Text coloring in DrawString
            //graphics.lastBrushColor = foreColor;
        }