ExcludeClip() публичный метод

public ExcludeClip ( Rectangle rect ) : void
rect Rectangle
Результат void
Пример #1
2
        public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
        {
            Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

            if (applyRect.Width == 0 || applyRect.Height == 0)
            {
                // nothing to do
                return;
            }
            GraphicsState state = graphics.Save();
            if (Invert)
            {
                graphics.SetClip(applyRect);
                graphics.ExcludeClip(rect);
            }
            ColorMatrix grayscaleMatrix = new ColorMatrix(new[] {
                new[] {.3f, .3f, .3f, 0, 0},
                new[] {.59f, .59f, .59f, 0, 0},
                new[] {.11f, .11f, .11f, 0, 0},
                new float[] {0, 0, 0, 1, 0},
                new float[] {0, 0, 0, 0, 1}
            });
            using (ImageAttributes ia = new ImageAttributes())
            {
                ia.SetColorMatrix(grayscaleMatrix);
                graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia);
            }
            graphics.Restore(state);
        }
        public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
        {
            Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

            if (applyRect.Width == 0 || applyRect.Height == 0)
            {
                // nothing to do
                return;
            }
            int magnificationFactor = GetFieldValueAsInt(FieldType.MAGNIFICATION_FACTOR);
            GraphicsState state = graphics.Save();
            if (Invert)
            {
                graphics.SetClip(applyRect);
                graphics.ExcludeClip(rect);
            }
            graphics.SmoothingMode = SmoothingMode.None;
            graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.PixelOffsetMode = PixelOffsetMode.None;
            int halfWidth = rect.Width / 2;
            int halfHeight = rect.Height / 2;
            int newWidth = rect.Width / magnificationFactor;
            int newHeight = rect.Height / magnificationFactor;
            Rectangle source = new Rectangle(rect.X + halfWidth - (newWidth / 2), rect.Y + halfHeight - (newHeight / 2), newWidth, newHeight);
            graphics.DrawImage(applyBitmap, rect, source, GraphicsUnit.Pixel);
            graphics.Restore(state);
        }
Пример #3
0
		/// <summary>
		/// Implements the Apply code for the Brightness Filet
		/// </summary>
		/// <param name="graphics"></param>
		/// <param name="applyBitmap"></param>
		/// <param name="rect"></param>
		/// <param name="renderMode"></param>
		public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
			Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

			if (applyRect.Width == 0 || applyRect.Height == 0) {
				// nothing to do
				return;
			}
			GraphicsState state = graphics.Save();
			if (Invert) {
				graphics.SetClip(applyRect);
				graphics.ExcludeClip(rect);
			}
			using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(applyBitmap, applyRect)) {
				Color highlightColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
				for (int y = fastBitmap.Top; y < fastBitmap.Bottom; y++) {
					for (int x = fastBitmap.Left; x < fastBitmap.Right; x++) {
						Color color = fastBitmap.GetColorAt(x, y);
						color = Color.FromArgb(color.A, Math.Min(highlightColor.R, color.R), Math.Min(highlightColor.G, color.G), Math.Min(highlightColor.B, color.B));
						fastBitmap.SetColorAt(x, y, color);
					}
				}
				fastBitmap.DrawTo(graphics, applyRect.Location);
			}
			graphics.Restore(state);
		}
Пример #4
0
 public unsafe override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
 {
     int blurRadius = GetFieldValueAsInt(FieldType.BLUR_RADIUS);
     double previewQuality = GetFieldValueAsDouble(FieldType.PREVIEW_QUALITY);
     Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
     if (applyRect.Width == 0 || applyRect.Height == 0)
     {
         return;
     }
     GraphicsState state = graphics.Save();
     if (Invert)
     {
         graphics.SetClip(applyRect);
         graphics.ExcludeClip(rect);
     }
     if (GDIplus.IsBlurPossible(blurRadius))
     {
         GDIplus.DrawWithBlur(graphics, applyBitmap, applyRect, null, null, blurRadius, false);
     }
     else
     {
         using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(applyBitmap, applyRect))
         {
             ImageHelper.ApplyBoxBlur(fastBitmap, blurRadius);
             fastBitmap.DrawTo(graphics, applyRect);
         }
     }
     graphics.Restore(state);
     return;
 }
        protected override void Draw(Graphics g)
        {
            regionFillPath = new GraphicsPath();

            for (int i = 0; i < nodes.Count - 1; i++)
            {
                regionFillPath.AddLine(nodes[i].Position, nodes[i + 1].Position);
            }

            if (nodes.Count > 2)
            {
                regionFillPath.CloseFigure();

                using (Region region = new Region(regionFillPath))
                {
                    g.ExcludeClip(region);
                    g.FillRectangle(shadowBrush, 0, 0, Width, Height);
                    g.ResetClip();
                }

                g.DrawRectangleProper(borderPen, currentArea);
            }
            else
            {
                g.FillRectangle(shadowBrush, 0, 0, Width, Height);
            }

            if (nodes.Count > 1)
            {
                g.DrawPath(borderPen, regionFillPath);
            }

            base.Draw(g);
        }
Пример #6
0
        public void ExcludeClipRectangle(Graphics g)
        {
            // Create rectangle for exclusion.
            Rectangle excludeRect = new Rectangle(100, 100, 200, 200);

            // Set clipping region to exclude rectangle.
            g.ExcludeClip(excludeRect);

            var myBrush = new SolidBrush(Color.FromArgb(127, 0x66, 0xEF, 0x7F));

            // Fill large rectangle to show clipping region.
            g.FillRectangle(myBrush, 0, 0, 500, 500);
        }
Пример #7
0
		/// <summary>
		/// Implements the Apply code for the Brightness Filet
		/// </summary>
		/// <param name="graphics"></param>
		/// <param name="applyBitmap"></param>
		/// <param name="rect"></param>
		/// <param name="renderMode"></param>
		public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
			Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

			if (applyRect.Width == 0 || applyRect.Height == 0) {
				// nothing to do
				return;
			}

			GraphicsState state =  graphics.Save();
			if (Invert) {
				graphics.SetClip(applyRect);
				graphics.ExcludeClip(rect);
			}
			float brightness = GetFieldValueAsFloat(FieldType.BRIGHTNESS);
			using (ImageAttributes ia = ImageHelper.CreateAdjustAttributes(brightness, 1f, 1f)) {
				graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia);
			}
			graphics.Restore(state);
		}
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            this.checkBox.Size = CheckBoxRenderer.GetGlyphSize(graphics, CheckBoxState.UncheckedNormal);
            this.checkBox.Location = new Point(2, cellBounds.Height / 2 - this.checkBox.Height / 2);
            this.checkRectangle.Size = new Size(this.checkBox.Right + 1, clipBounds.Height);

            Point realLocation = this.checkBox.Location + (Size)cellBounds.Location;
            ButtonState state = GetCheckBoxState();

            Padding newPadding = cellStyle.Padding;
            newPadding.Left = checkRectangle.Width;
            cellStyle.Padding = newPadding;

            GraphicsState gstate = graphics.Save();
            graphics.ExcludeClip(new Rectangle(realLocation, this.checkBox.Size));
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
            graphics.Restore(gstate);

            CheckBoxRenderer.DrawCheckBox(graphics, realLocation, ConvertFromButtonState(state, false, this.mouseInCheckBox));
        }
        protected override void Draw(Graphics g)
        {
            if (points.Count > 2)
            {
                using (Region region = new Region(regionFillPath))
                {
                    g.ExcludeClip(region);
                    g.FillRectangle(shadowBrush, 0, 0, Width, Height);
                    g.ResetClip();
                }

                g.DrawPath(borderPen, regionFillPath);
                g.DrawLine(borderPen, points[0], points[points.Count - 1]);
                g.DrawRectangleProper(borderPen, currentArea);
            }
            else
            {
                g.FillRectangle(shadowBrush, 0, 0, Width, Height);
            }

            base.Draw(g);
        }
        public override void OnDraw(Graphics g)
        {
            if (Rectangle.Width > 10 && Rectangle.Height > 10)
            {
                GraphicsPath gpTail = null;

                if (TailVisible)
                {
                    gpTail = CreateTailPath();
                }

                if (FillColor.A > 0)
                {
                    using (Brush brush = new SolidBrush(FillColor))
                    {
                        g.FillRectangle(brush, Rectangle);
                    }
                }

                if (gpTail != null)
                {
                    g.SmoothingMode = SmoothingMode.HighQuality;

                    if (FillColor.A > 0)
                    {
                        g.ExcludeClip(Rectangle);

                        using (Brush brush = new SolidBrush(FillColor))
                        {
                            g.FillPath(brush, gpTail);
                        }

                        g.ResetClip();
                    }

                    if (BorderSize > 0 && BorderColor.A > 0)
                    {
                        g.ExcludeClip(Rectangle.Offset(-1));

                        using (Pen pen = new Pen(BorderColor, BorderSize))
                        {
                            g.DrawPath(pen, gpTail);
                        }

                        g.ResetClip();
                    }

                    g.SmoothingMode = SmoothingMode.None;
                }

                if (BorderSize > 0 && BorderColor.A > 0)
                {
                    if (gpTail != null)
                    {
                        using (Region region = new Region(gpTail))
                        {
                            g.ExcludeClip(region);
                        }
                    }

                    Rectangle rect = Rectangle.Offset(BorderSize - 1);

                    using (Pen pen = new Pen(BorderColor, BorderSize) { Alignment = PenAlignment.Inset })
                    {
                        g.DrawRectangleProper(pen, rect);
                    }

                    g.ResetClip();
                }

                if (gpTail != null)
                {
                    gpTail.Dispose();
                }

                DrawText(g);
            }
        }
Пример #11
0
        void DrawItem(Graphics g, int index, Rectangle itemRect, bool hot, bool pressed, Rectangle targetRect, OutlookBarBand drawingBand)
        {
            OutlookBarBand band = bands[currentBandIndex];
            if (drawingBand != null)
                band = drawingBand;

            Point pt = new Point(0, 0);
            // Set clip region so that we don't draw outside the viewport
            Rectangle viewPortRect = GetViewPortRect();
            if (targetRect != Rectangle.Empty)
                viewPortRect = targetRect;

            using (Region clippingRegion = new Region(viewPortRect))
            {
                g.Clip = clippingRegion;
                // Clip the arrow buttons
                g.ExcludeClip(downArrowRect);
                g.ExcludeClip(upArrowRect);

                Color textColor = band.TextColor;
                Color backColor = band.Background;
                Color highLight = band.Background;

                if (ColorUtil.UsingCustomColor)
                {
                    backColor = ColorUtil.VSNetControlColor;
                    highLight = ColorUtil.VSNetControlColor;
                }

                if (hot)
                {
                    backColor = ColorUtil.VSNetSelectionColor;
                    highLight = ColorUtil.VSNetBorderColor;
                }

                if (pressed)
                    backColor = ColorUtil.VSNetPressedColor;

                //john hatton jdh
                if (band.Items[index].Selected)
                    highLight = Color.Blue;

                if (band.IconView == IconView.Large && band.LargeImageList != null)
                {
                    Size largeImageSize = band.LargeImageList.ImageSize;
                    pt.X = itemRect.Left + (viewPortRect.Width - largeImageSize.Width) / 2;
                    pt.Y = itemRect.Top;

                    Rectangle iconRect = new Rectangle(pt, largeImageSize);
                    using (Brush b = new SolidBrush(backColor))
                    {
                        iconRect.Inflate(2, 2);
                        if (backgroundBitmap != null)
                        {
                            g.DrawImage(backgroundBitmap, iconRect, iconRect, GraphicsUnit.Pixel);
                            // If we have a background bitmap, draw the item background
                            // only during the hot state
                            if (hot)
                            {
                                g.FillRectangle(b, iconRect.Left, iconRect.Top,
                                    iconRect.Width, iconRect.Height);
                            }
                        }
                        else
                        {

                            // If we don't have a background, always draw the
                            // item backgound
                            g.FillRectangle(b, iconRect.Left, iconRect.Top,
                                iconRect.Width, iconRect.Height);
                        }

                        using (Pen p = new Pen(highLight))
                        {
                            if (backgroundBitmap == null || hot == true)
                            {
                                g.DrawRectangle(p, iconRect.Left, iconRect.Top, iconRect.Width - 1, iconRect.Height - 1);
                            }

                        }
                    }

                    // I dont' use the image list to do the drawing because cliping does not work
                    if (band.Items[index].ImageIndex != -1 && band.LargeImageList != null)
                    {
                        // Only if we have a valid image index
                        g.SmoothingMode = SmoothingMode.HighQuality;
                        g.DrawImage(band.LargeImageList.Images[band.Items[index].ImageIndex], pt);
                        g.SmoothingMode = SmoothingMode.Default;
                    }

                    // Draw the label
                    int top = itemRect.Top + largeImageSize.Height + Y_LARGEICON_LABEL_OFFSET;
                    Size textSize = GetLabelSize(g, band, index);
                    int left = itemRect.Left + (viewPortRect.Width - textSize.Width) / 2;
                    using (Brush b = new SolidBrush(textColor))
                    {
                        g.DrawString(band.Items[index].Text, Font, b, new Point(left, top));
                    }

                    // Reset clip region to the whole rectangle so that the arrows can be painted
                    g.Clip = new Region(viewPortRect);
                }
                else if (band.IconView == IconView.Small && band.SmallImageList != null)
                {

                    Size smallImageSize = band.SmallImageList.ImageSize;
                    pt.X = itemRect.Left;
                    pt.Y = itemRect.Top + (itemRect.Height - smallImageSize.Height) / 2;

                    Rectangle iconRect = new Rectangle(pt, smallImageSize);
                    using (Brush b = new SolidBrush(backColor))
                    {
                        iconRect.Inflate(1, 1);
                        if (backgroundBitmap != null)
                        {
                            g.DrawImage(backgroundBitmap, iconRect, iconRect, GraphicsUnit.Pixel);
                            // If we have a background bitmap, draw the item background
                            // only during the hot state
                            if (hot)
                            {
                                g.FillRectangle(b, iconRect.Left, iconRect.Top,
                                    iconRect.Width, iconRect.Height);
                            }
                        }
                        else
                        {
                            // If we don't have a background, always draw the
                            // item backgound
                            g.FillRectangle(b, iconRect.Left, iconRect.Top,
                                iconRect.Width, iconRect.Height);
                        }

                        using (Pen p = new Pen(highLight))
                        {
                            if (backgroundBitmap == null || hot == true)
                            {
                                g.DrawRectangle(p, iconRect.Left, iconRect.Top, iconRect.Width - 1, iconRect.Height - 1);
                            }
                        }
                    }

                    // I dont' use the image list to do the drawing because cliping does not work
                    if (band.Items[index].ImageIndex != -1 && band.SmallImageList != null)
                    {
                        // Only if we have a valid image index
                        g.DrawImage(band.SmallImageList.Images[band.Items[index].ImageIndex], pt);
                    }

                    // Draw the label
                    Size labelSize = GetLabelSize(g, band, index);
                    pt.X = pt.X + smallImageSize.Width + X_SMALLICON_LABEL_OFFSET;
                    pt.Y = itemRect.Top + (itemRect.Height - labelSize.Height) / 2;
                    using (Brush b = new SolidBrush(textColor))
                    {
                        g.DrawString(band.Items[index].Text, Font, b, pt);
                    }
                }
            }
        }
 internal static void DrawDropShadow(Graphics graphics, Rectangle shadowSourceRectangle, Color baseColor, int shadowDepth, LightSourcePosition lightSourcePosition, float lightSourceIntensity, bool roundEdges)
 {
     if (graphics == null)
     {
         throw new ArgumentNullException("graphics");
     }
     if ((shadowSourceRectangle.IsEmpty || (shadowSourceRectangle.Width < 0)) || (shadowSourceRectangle.Height < 0))
     {
         throw new ArgumentException(SR.GetString("Error_InvalidShadowRectangle"), "shadowRectangle");
     }
     if ((shadowDepth < 1) || (shadowDepth > 12))
     {
         throw new ArgumentException(SR.GetString("Error_InvalidShadowDepth"), "shadowDepth");
     }
     if ((lightSourceIntensity <= 0f) || (lightSourceIntensity > 1f))
     {
         throw new ArgumentException(SR.GetString("Error_InvalidLightSource"), "lightSourceIntensity");
     }
     Rectangle rectangle = shadowSourceRectangle;
     Size empty = Size.Empty;
     if ((lightSourcePosition & LightSourcePosition.Center) > 0)
     {
         rectangle.Inflate(shadowDepth, shadowDepth);
     }
     if ((lightSourcePosition & LightSourcePosition.Left) > 0)
     {
         empty.Width += shadowDepth + 1;
     }
     else if ((lightSourcePosition & LightSourcePosition.Right) > 0)
     {
         empty.Width -= shadowDepth + 1;
     }
     if ((lightSourcePosition & LightSourcePosition.Top) > 0)
     {
         empty.Height += shadowDepth + 1;
     }
     else if ((lightSourcePosition & LightSourcePosition.Bottom) > 0)
     {
         empty.Height -= shadowDepth + 1;
     }
     rectangle.Offset(empty.Width, empty.Height);
     GraphicsContainer container = graphics.BeginContainer();
     GraphicsPath path = new GraphicsPath();
     if (roundEdges)
     {
         path.AddPath(GetRoundedRectanglePath(shadowSourceRectangle, 8), true);
     }
     else
     {
         path.AddRectangle(shadowSourceRectangle);
     }
     try
     {
         using (Region region = new Region(path))
         {
             graphics.SmoothingMode = SmoothingMode.AntiAlias;
             graphics.ExcludeClip(region);
             Color color = Color.FromArgb(Convert.ToInt32((float) (40f * lightSourceIntensity)), baseColor);
             int num = Math.Max(40 / shadowDepth, 2);
             for (int i = 0; i < shadowDepth; i++)
             {
                 rectangle.Inflate(-1, -1);
                 using (Brush brush = new SolidBrush(color))
                 {
                     using (GraphicsPath path2 = new GraphicsPath())
                     {
                         if (roundEdges)
                         {
                             path2.AddPath(GetRoundedRectanglePath(rectangle, 8), true);
                         }
                         else
                         {
                             path2.AddRectangle(rectangle);
                         }
                         graphics.FillPath(brush, path2);
                     }
                 }
                 color = Color.FromArgb(color.A + num, color.R, color.G, color.B);
             }
         }
     }
     finally
     {
         graphics.EndContainer(container);
     }
 }
        protected override void Draw(Graphics g)
        {
            List<Rectangle> areas = AreaManager.GetValidAreas;

            if (areas.Count > 0 || !AreaManager.CurrentHoverArea.IsEmpty)
            {
                UpdateRegionPath();

                using (Region region = new Region(regionFillPath))
                {
                    g.ExcludeClip(region);
                    g.FillRectangle(shadowBrush, 0, 0, Width, Height);
                    g.ResetClip();
                }

                /*foreach (WindowInfo wi in AreaManager.Windows)
                {
                    g.DrawRectangleProper(Pens.Yellow, Rectangle.Intersect(ScreenRectangle0Based, wi.Rectangle0Based));
                }*/

                borderDotPen.DashOffset = (float)timer.Elapsed.TotalSeconds * 10;
                borderDotPen2.DashOffset = 5 + (float)timer.Elapsed.TotalSeconds * 10;

                g.DrawPath(borderPen, regionDrawPath);

                if (areas.Count > 1)
                {
                    Rectangle totalArea = AreaManager.CombineAreas();
                    g.DrawCrossRectangle(borderPen, totalArea, 15);
                    CaptureHelpers.DrawTextWithOutline(g, string.Format("X:{0}, Y:{1}, Width:{2}, Height:{3}", totalArea.X, totalArea.Y,
                        totalArea.Width, totalArea.Height), new PointF(totalArea.X + 5, totalArea.Y - 20), textFont, Color.White, Color.Black);
                }

                if (AreaManager.IsCurrentHoverAreaValid)
                {
                    GraphicsPath hoverFillPath = new GraphicsPath() { FillMode = FillMode.Winding };
                    AddShapePath(hoverFillPath, AreaManager.CurrentHoverArea);

                    g.FillPath(lightBrush, hoverFillPath);

                    GraphicsPath hoverDrawPath = new GraphicsPath() { FillMode = FillMode.Winding };
                    AddShapePath(hoverDrawPath, AreaManager.CurrentHoverArea.SizeOffset(-1));

                    g.DrawPath(borderDotPen, hoverDrawPath);
                    g.DrawPath(borderDotPen2, hoverDrawPath);
                }

                if (AreaManager.IsCurrentAreaValid)
                {
                    g.DrawRectangleProper(borderDotPen, AreaManager.CurrentArea);
                    g.DrawRectangleProper(borderDotPen2, AreaManager.CurrentArea);
                    g.ExcludeClip(AreaManager.CurrentArea);
                    DrawObjects(g);
                    g.ResetClip();
                }

                foreach (Rectangle area in areas)
                {
                    if (area.Width > 100 && area.Height > 20)
                    {
                        g.Clip = new Region(area);

                        CaptureHelpers.DrawTextWithOutline(g, string.Format("X:{0}, Y:{1}, Width:{2}, Height:{3}", area.X, area.Y, area.Width, area.Height),
                            new PointF(area.X + 5, area.Y + 5), textFont, Color.White, Color.Black);
                    }
                }
            }
            else
            {
                g.FillRectangle(shadowBrush, 0, 0, Width, Height);
            }
        }
 public static void DrawSelectionFrame(Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect, Color backColor)
 {
     Brush activeBrush;
     if (graphics == null)
     {
         throw new ArgumentNullException("graphics");
     }
     if (active)
     {
         activeBrush = GetActiveBrush(backColor);
     }
     else
     {
         activeBrush = GetSelectedBrush(backColor);
     }
     Region clip = graphics.Clip;
     graphics.ExcludeClip(insideRect);
     graphics.FillRectangle(activeBrush, outsideRect);
     graphics.Clip = clip;
 }
Пример #15
0
        // Render the treeview starting from startingLine
        internal void Draw(Graphics g, TreeNodeEx startNode)
        {
            if (updating > 0)
            {
                return;
            }

            Rectangle clientRectangle = ClientRectangle;
            int drawableHeight = clientRectangle.Height;
            int drawableWidth = clientRectangle.Width - xOffset;

            // We count the visible rows to see if we need the v scrollbar but we wait before deciding if we need the h scroll bar.
            bool needsHScrollBar = false;
            bool needsVScrollBar = GetNeedVScrollBar() && scrollable;
            bool createNewVScrollBar = false;
            bool createNewHScrollBar = false;

            if (needsVScrollBar)
            {
                // Don't allow drawing on the area that is going to be the scroll bar.
                // Create the scroll bar so we can get its width.
                if (vScrollBar == null)
                {
                    vScrollBar = new Forms.VScrollBar();
                    createNewVScrollBar = true;
                }
                drawableWidth -= vScrollBar.Width;
                Rectangle rect = new Rectangle(drawableWidth + xOffset, 0, vScrollBar.Width, clientRectangle.Height);
                g.ExcludeClip(rect);
            }
            else
            {
                // Check to see if the top node is not the first node and we have room for the whole tree.
                // If so, abandon the draw and redraw the whole tree from the top.
                if (topNode != null && topNode != this.nodes[0])
                {
                    topNode = null;
                    Invalidate();
                    return;
                }
                if (vScrollBar != null)
                {
                    // We don't need the scroll bar anymore.
                    Controls.Remove(vScrollBar);
                    vScrollBar.Dispose();
                    vScrollBar = null;
                }
            }
            // Is the node being processed on the screen.
            bool drawing = false;
            // Start counting from the top.
            int nodeFromTop = -1;
            // Number of nodes.
            int nodeCount = 0;
            int topNodePosition = 0;
            // The maximum width of a displayed node.
            float maxWidth = 0;
            //StringFormat format = new StringFormat(StringFormatFlags.NoWrap);
            if (topNode == null && this.nodes.Count > 0)
            {
                topNode = this.nodes[0];
            }
            RectangleF textBounds = Rectangle.Empty;

            NodeEnumeratorEx nodes = new NodeEnumeratorEx(this.nodes);
            using (Pen markerPen = new Pen(SystemColors.ControlDarkDark))
            {
                markerPen.DashStyle = DashStyle.Dot;
                while (nodes.MoveNext())
                {
                    // If we havnt started drawing yet, then see if we need to and if so clear the background.
                    if (!drawing)
                    {
                        if (nodes.currentNode  == topNode)
                        {
                            // We are at the top node.
                            nodeFromTop = 0;
                            topNodePosition = nodeCount;
                        }

                        // Check to see if we must start drawing. Clear the background.
                        if (nodeFromTop >= 0 && (nodes.currentNode == startNode || startNode == root))
                        {
                            // Clear background.
                            int y = ItemHeight * nodeFromTop;
                            using (SolidBrush b = new SolidBrush(BackColor))
                            {
                                g.FillRectangle(b, 0, y, ClientSize.Width, ClientSize.Height - y);
                            }
                            drawing = true;
                        }
                    }

                    // Even if we arnt drawing nodes yet, we need to measure if the nodes are visible, for hscrollbar purposes.
                    if (nodeFromTop >= 0 && drawableHeight > 0)
                    {
                        textBounds = GetTextBounds(g, nodes.currentNode, nodeFromTop, nodes.level);
                        // Is the text too wide to fit in - if so we need an h scroll bar.
                        if (textBounds.Right > drawableWidth && !needsHScrollBar && scrollable)
                        {
                            needsHScrollBar = true;
                            if (hScrollBar == null)
                            {
                                hScrollBar = new Forms.HScrollBar();
                                createNewHScrollBar = true;
                            }
                            drawableHeight -= hScrollBar.Height;
                            // Don't allow drawing on the area that is going to be the scroll bar.
                            Rectangle rect = new Rectangle(0, clientRectangle.Height - hScrollBar.Height, clientRectangle.Width, hScrollBar.Height);
                            g.ExcludeClip(rect);
                        }
                        if (textBounds.Right > maxWidth)
                        {
                            maxWidth = textBounds.Right;
                        }

                    }

                    // Draw the node if we still have space.
                    if (drawing && drawableHeight > 0)
                    {
                        RectangleF bounds;
                        // Draw the lines and the expander.
                        DrawExpanderMarker(g, markerPen, nodes.currentNode, nodeFromTop, nodes.level);

                        // Draw checkboxes.
                        if (checkBoxes)
                        {
                            bounds = GetCheckBounds(nodeFromTop, nodes.level);
                            Forms.ButtonState state;
                            if (nodes.currentNode.isChecked)
                            {
                                state = Forms.ButtonState.Checked;
                            }
                            else
                            {
                                state = Forms.ButtonState.Normal;
                            }
                            Forms.ControlPaint.DrawCheckBox(g, RectIFromRectF(bounds), state);
                        }

                        // Draw the node image.
                        if (imageList != null)
                        {
                            bounds = GetImageBounds(nodeFromTop, nodes.level);
                            int index = GetDisplayIndex(nodes.currentNode);

                            if (index < imageList.Images.Count && index >= 0)
                            {
                                Image image = imageList.Images[index];
                                g.DrawImage(image, bounds.X, bounds.Y);
                            }
                        }

                        bounds = textBounds;
                        // The height may be too small now.
                        // If we are currently editing a node then dont draw it.
                        if (drawableHeight > 0 && nodes.currentNode != editNode)
                        {
                            // Draw the node text.
                            var bnds = RectIFromRectF(bounds);

                            if (selectedDropNode == nodes.currentNode)
                            {
                                if (dragMoveDirection == DragMoveDirection.Above)
                                    g.DrawLine(Pens.Black, new PointF(bnds.X, bnds.Y), new PointF(bnds.X + bnds.Width, bnds.Y));
                                else if (dragMoveDirection == DragMoveDirection.Below)
                                    g.DrawLine(Pens.Black, new PointF(bnds.X, bnds.Y + bnds.Height), new PointF(bnds.X + bnds.Width, bnds.Y + bnds.Height));
                                else
                                    g.FillRectangle(SystemBrushes.Highlight, bnds);
                            }

                            if ((selectedDropNode == nodes.currentNode && dragMoveDirection == DragMoveDirection.On) ||
                                (((nodeToBeDropped == null && nodes.currentNode == selectedNode)
                                || (nodes.currentNode == nodeToBeDropped))
                                && (Focused || !hideSelection)))
                            {
                                // TODO: FullRowSelect
                                g.FillRectangle(SystemBrushes.Highlight, bnds);
                                Forms.TextRenderer.DrawText(g, nodes.currentNode.Text, Font, bnds, SystemColors.HighlightText, Forms.TextFormatFlags.NoClipping);
                                // Draw the focus rectangle.
                                Rectangle r = new Rectangle((int)(bounds.X), (int)(bounds.Y), (int)(bounds.Width), (int)(bounds.Height));
                                Forms.ControlPaint.DrawFocusRectangle(g, r);
                            }
                            else
                            {
                                Forms.TextRenderer.DrawText(g, nodes.currentNode.Text, Font, bnds, SystemColors.ControlText, Forms.TextFormatFlags.NoClipping);
                            }
                        }
                        drawableHeight -= ItemHeight;
                    }

                    if (nodeFromTop >= 0)
                    {
                        nodeFromTop++;
                    }
                    nodeCount++;
                }
            }
            // If we need a v scroll bar, then set it up.
            if (needsVScrollBar)
            {
                SetupVScrollBar(nodeCount, needsHScrollBar, createNewVScrollBar, topNodePosition);
            }
            if (needsHScrollBar)
            {
                SetupHScrollBar(needsVScrollBar, (int)maxWidth, createNewHScrollBar, g);
            }
            else if (hScrollBar != null)
            {
                // We dont need the scroll bar.
                // If we have scrolled then we need to reset the position.
                if (xOffset != 0)
                {
                    xOffset = 0;
                    Invalidate();
                }
                Controls.Remove(hScrollBar);
                hScrollBar.Dispose();
                hScrollBar = null;
            }
        }
 private void PaintRows(Graphics g, ref Rectangle boundingRect)
 {
     int num = 0;
     bool alignToRight = this.isRightToLeft();
     Rectangle rect = boundingRect;
     Rectangle empty = Rectangle.Empty;
     bool rowHeadersVisible = this.layout.RowHeadersVisible;
     Rectangle rectangle3 = Rectangle.Empty;
     int dataGridRowsLength = this.DataGridRowsLength;
     DataGridRow[] dataGridRows = this.DataGridRows;
     int numVisibleColumns = this.myGridTable.GridColumnStyles.Count - this.firstVisibleCol;
     for (int i = this.firstVisibleRow; i < dataGridRowsLength; i++)
     {
         if (num > boundingRect.Height)
         {
             break;
         }
         rect = boundingRect;
         rect.Height = dataGridRows[i].Height;
         rect.Y = boundingRect.Y + num;
         if (rowHeadersVisible)
         {
             rectangle3 = rect;
             rectangle3.Width = this.layout.RowHeaders.Width;
             if (alignToRight)
             {
                 rectangle3.X = rect.Right - rectangle3.Width;
             }
             if (g.IsVisible(rectangle3))
             {
                 dataGridRows[i].PaintHeader(g, rectangle3, alignToRight, this.gridState[0x8000]);
                 g.ExcludeClip(rectangle3);
             }
             if (!alignToRight)
             {
                 rect.X += rectangle3.Width;
             }
             rect.Width -= rectangle3.Width;
         }
         if (g.IsVisible(rect))
         {
             empty = rect;
             if (!alignToRight)
             {
                 empty.X -= this.negOffset;
             }
             empty.Width += this.negOffset;
             dataGridRows[i].Paint(g, empty, rect, this.firstVisibleCol, numVisibleColumns, alignToRight);
         }
         num += rect.Height;
     }
     boundingRect.Y += num;
     boundingRect.Height -= num;
 }
        void RenderPage(Graphics g, Image img, Rectangle rc)
        {
            // draw the page
            rc.Offset(1, 1);
            g.DrawRectangle(Pens.Black, rc);
            rc.Offset(-1, -1);
            g.FillRectangle(Brushes.White, rc);
            g.DrawImage(img, rc);
            g.DrawRectangle(Pens.Black, rc);

            // exclude cliprect to paint background later
            rc.Width++;
            rc.Height++;
            g.ExcludeClip(rc);
            rc.Offset(1, 1);
            g.ExcludeClip(rc);
        }
Пример #18
0
 public void Render(IGitterStyle style, Graphics graphics, Font font, Rectangle rect)
 {
     bool useCache = _cachedRect == rect;
     if(useCache)
     {
         for(int i = 0; i < _glyphs.Length; ++i)
         {
             graphics.ExcludeClip(_glyphs[i].Region);
         }
     }
     else
     {
         var cr = graphics.MeasureCharacterRanges(_text, font, rect, _sf);
         for(int i = 0; i < _glyphs.Length; ++i)
         {
             _glyphs[i].Region = cr[i];
             graphics.ExcludeClip(cr[i]);
         }
     }
     using(var brush = new SolidBrush(style.Colors.WindowText))
     {
         GitterApplication.TextRenderer.DrawText(
             graphics, _text, font, brush, rect, _sf);
     }
     graphics.ResetClip();
     bool clipIsSet = false;
     foreach(var glyph in _glyphs)
     {
         if(glyph != _hoveredLink.Item)
         {
             if(clipIsSet)
             {
                 graphics.SetClip(glyph.Region, CombineMode.Union);
             }
             else
             {
                 graphics.Clip = glyph.Region;
                 clipIsSet = true;
             }
         }
     }
     if(clipIsSet)
     {
         using(var linkTextBrush = new SolidBrush(style.Colors.HyperlinkText))
         {
             GitterApplication.TextRenderer.DrawText(
                 graphics, _text, font, linkTextBrush, rect, _sf);
         }
     }
     if(_hoveredLink.IsTracked)
     {
         graphics.Clip = _hoveredLink.Item.Region;
         using(var f = new Font(font, FontStyle.Underline))
         using(var linkTextBrush = new SolidBrush(style.Colors.HyperlinkTextHotTrack))
         {
             GitterApplication.TextRenderer.DrawText(
                 graphics, _text, f, linkTextBrush, rect, _sf);
         }
     }
     graphics.ResetClip();
     _cachedRect = rect;
 }
Пример #19
0
 internal static void DrawBackground(Graphics g, RectangleF rect, Brush fillBrush, CornerShape bShape,
     int cornerRadius, Region excRegion)
 {
     if (excRegion != null)
     {
         g.ExcludeClip(excRegion);
     }
     var path = GetDrawingPath(rect, bShape, cornerRadius);
     g.FillPath(fillBrush, path);
     fillBrush.Dispose();
     path.Dispose();
 }
 private void PaintRelations(Graphics g, Rectangle bounds, Rectangle trueRowBounds, int dataWidth, int firstCol, int nCols, bool alignToRight)
 {
     Rectangle relationshipRect = this.GetRelationshipRect();
     relationshipRect.X = alignToRight ? (bounds.Right - relationshipRect.Width) : bounds.X;
     relationshipRect.Y = bounds.Y;
     int num = Math.Max(dataWidth, relationshipRect.Width);
     Region clip = g.Clip;
     g.ExcludeClip(relationshipRect);
     g.FillRectangle(base.GetBackBrush(), alignToRight ? (bounds.Right - dataWidth) : bounds.X, bounds.Y, dataWidth, bounds.Height);
     g.SetClip(bounds);
     relationshipRect.Height -= base.dgTable.BorderWidth;
     g.DrawRectangle(SystemPens.ControlText, relationshipRect.X, relationshipRect.Y, relationshipRect.Width - 1, relationshipRect.Height - 1);
     relationshipRect.Inflate(-1, -1);
     int num2 = this.PaintRelationText(g, relationshipRect, alignToRight);
     if (num2 < relationshipRect.Height)
     {
         g.FillRectangle(base.GetBackBrush(), relationshipRect.X, relationshipRect.Y + num2, relationshipRect.Width, relationshipRect.Height - num2);
     }
     g.Clip = clip;
     if (num < bounds.Width)
     {
         int gridLineWidth;
         if (base.dgTable.IsDefault)
         {
             gridLineWidth = base.DataGrid.GridLineWidth;
         }
         else
         {
             gridLineWidth = base.dgTable.GridLineWidth;
         }
         g.FillRectangle(base.DataGrid.BackgroundBrush, alignToRight ? bounds.X : (bounds.X + num), bounds.Y, ((bounds.Width - num) - gridLineWidth) + 1, bounds.Height);
         if (gridLineWidth > 0)
         {
             Brush gridLineBrush;
             if (base.dgTable.IsDefault)
             {
                 gridLineBrush = base.DataGrid.GridLineBrush;
             }
             else
             {
                 gridLineBrush = base.dgTable.GridLineBrush;
             }
             g.FillRectangle(gridLineBrush, alignToRight ? ((bounds.Right - gridLineWidth) - num) : ((bounds.X + num) - gridLineWidth), bounds.Y, gridLineWidth, bounds.Height);
         }
     }
 }
Пример #21
0
        internal void DrawTab(Graphics g, int index, bool drawFocused)
        {
            RectangleF bounds = GetTabRect(index);

              TabPage page = TabPages[index];
              bool isSelected = (SelectedIndex == index);

              // For high quality drawing with antialiased lines we need to specify line and gradient coordinates
              // which lie between two pixels (not exactly *on* one, so adjust by a half pixel offset for these cases.
              bounds.X -= 0.5f;
              bounds.Y -= 0.5f;

              GraphicsPath outline = null;
              if (isSelected || tabStyle == TabStyleType.TopTransparent)
              {
            outline = GetTabOutline(bounds, isSelected);
            Color tabColor;

            switch (tabStyle)
            {
              case TabStyleType.BottomNormal:
            tabColor = bottomTabSelectedColor;
            break;

              case TabStyleType.TopTransparent:
            if (isSelected)
              tabColor = topTransparentTabColor;
            else
              tabColor = Color.FromArgb(128, topTransparentTabColor);
            break;

              default: // Top normal.
            if (isSelected)
            {
              if (drawFocused)
                tabColor = topNormalTabSelectedFocusedColor;
              else
                tabColor = topNormalTabSelectedUnfocusedColor;
            }
            else
              tabColor = topNormalTabTextColor;
            break;
            }

            using (SolidBrush brush = new SolidBrush(tabColor))
              g.FillPath(brush, outline);
              }

              bool drawingOnGlass = (tabStyle == TabStyleType.TopTransparent && !isSelected &&
                             ControlUtilities.IsCompositionEnabled());

              // Tab icon. Compute position here but draw after the text (to draw it over the text glow
              // if necessary).
              bool drawImage = false;
              Point imagePosition = new Point(0, 0);
              if ((page.ImageIndex >= 0) && (ImageList != null) && (ImageList.Images.Count > page.ImageIndex) &&
            (ImageList.Images[page.ImageIndex] != null))
              {
            drawImage = true;
            int iconSpacing = 4;

            imagePosition = new Point((int) bounds.X + itemPadding.Left, (int) bounds.Y);

            int adjustment = ImageList.ImageSize.Width + iconSpacing;

            imagePosition.Y += ((int)bounds.Height - ImageList.ImageSize.Height) / 2;
            bounds.X += adjustment;
            bounds.Width -= adjustment;
              }

              bool buttonSpaceNeeded = IsCloseButtonVisible(index) || (layoutInfo[index].isBusy);
              Rectangle buttonRect = GetTabButtonRect(index);

              // Tab text.
              if (page.Text.Length > 0)
              {
            using (StringFormat stringFormat = new StringFormat())
            {
              stringFormat.Alignment = StringAlignment.Near;
              stringFormat.Trimming = StringTrimming.EllipsisCharacter;
              stringFormat.FormatFlags = StringFormatFlags.NoWrap;
              stringFormat.LineAlignment = StringAlignment.Center;

              // Create format flags variant of the StringFormat for Aero rendering.
              TextFormatFlags formatFlags = TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter |
            TextFormatFlags.SingleLine;

              Brush brush;
              switch (tabStyle)
              {
            case TabStyleType.TopTransparent:
              brush = new SolidBrush(topTransparentTabTextColor);
              break;

            case TabStyleType.BottomNormal:
              if (isSelected)
                brush = new SolidBrush(bottomTabSelectedTextColor);
              else
                brush = new SolidBrush(bottomTabTextColor);
              break;

            default: // Top tab normal.
              if (isSelected)
              {
                if (drawFocused)
                  brush = new SolidBrush(topNormalTabSelectedFocusedTextColor);
                else
                  brush = new SolidBrush(topNormalTabSelectedUnfocusedTextColor);

              }
              else
                brush = new SolidBrush(topNormalTabTextColor);
              break;
              }

              int buttonPart = 0;
              if (buttonSpaceNeeded)
            buttonPart = buttonSpacing + buttonRect.Width;

              // When computing the left padding take the necessary glow around text into account, so we
              // don't add too much extra space.
              if (drawingOnGlass)
              {
            int leftSpace = itemPadding.Left - (renderWithGlow ? glowSize : 0) + 1;
            int rightSpace = itemPadding.Right > glowSize ? itemPadding.Right - glowSize : 0;
            bounds.X += leftSpace;
            bounds.Width -= buttonPart + leftSpace + rightSpace;
              }
              else
              {
            bounds.X += itemPadding.Left;
            bounds.Width -= itemPadding.Horizontal + buttonPart;
              }
              bounds.Height -= itemPadding.Vertical;

              Font font = this.Font;
              if (Conversions.InHighContrastMode())
            font = new Font(font, font.Style | FontStyle.Bold);

              // For writing text on a (semi) transparent surface (e.g. when using Aero)
              // normal text output routines will mess up the ClearType/anti aliasing extra pixels
              // or the text color (sometimes both together). Hence we use a path to draw the text.
              if (tabStyle != TabStyleType.TopTransparent || isSelected)
              {
            // Since GraphicsPath.AddString renders text significantly different we use it only
            // if we really need to.
            g.DrawString(page.Text, font, brush, bounds, stringFormat);
              }
              else
              {
            if (ControlUtilities.IsCompositionEnabled())
            {
              Rectangle intBounds = Rectangle.Ceiling(bounds);
              Win32.DrawTextOnGlass(g, page.Text, font, intBounds, Color.Black, formatFlags, renderWithGlow);
            }
            else
              using (GraphicsPath textPath = new GraphicsPath())
              {
                float emSize = g.DpiY * font.SizeInPoints / 72;
                if (tabStyle == TabStyleType.TopTransparent)
                  bounds.Y--; // Account for outline border.
                textPath.AddString(page.Text, font.FontFamily, (int)font.Style, emSize, bounds, stringFormat);
                g.FillPath(brush, textPath);
              }
              }
              brush.Dispose();
            }
              }

              if (drawImage)
            g.DrawImageUnscaled(ImageList.Images[page.ImageIndex], imagePosition);

              // Finally the close button if this tab is active (or we use the TopTransparent style or
              // the tab is marked as busy).
              if ((isSelected || tabStyle == TabStyleType.TopTransparent || layoutInfo[index].isBusy) &&
            buttonSpaceNeeded)
              {
            if (layoutInfo[index].isBusy)
            {
              Bitmap indicator;
              switch (tabStyle)
              {
            case TabStyleType.TopNormal:
              if (isSelected)
              {
                if (drawFocused)
                  indicator = GetBusyIndicatorForStyle("blue");
                else
                  indicator = GetBusyIndicatorForStyle("white");
              }
              else
                indicator = GetBusyIndicatorForStyle("white");
              break;

            default:
              indicator = GetBusyIndicatorForStyle("white");
              break;
              }
              ImageAnimator.UpdateFrames(indicator);
              g.DrawImageUnscaled(indicator, buttonRect);
            }
            else
            {
              switch (tabStyle)
              {
            case TabStyleType.TopTransparent:
              g.DrawImageUnscaled(darkCloseButton, buttonRect);
              break;
            case TabStyleType.TopNormal:
              {
                bool drawDark = isSelected && drawFocused;
                if (Conversions.UseWin8Drawing())
                  drawDark = false;
                else
                  if (Conversions.InHighContrastMode())
                    drawDark = !drawDark;
                if (drawDark)
                  g.DrawImageUnscaled(darkCloseButton, buttonRect);
                else
                  g.DrawImageUnscaled(lightCloseButton, buttonRect);
                break;
              }
            case TabStyleType.BottomNormal:
              g.DrawImageUnscaled(darkCloseButton, buttonRect);
              break;
              }
            }
              }
              if (outline != null)
              {
            // The Widen operation discards the inner part, so we need to compose the result.
            GraphicsPath inner = (GraphicsPath)outline.Clone();
            Pen pen = new Pen(Color.White, 1.5f);
            outline.Widen(pen);
            outline.AddPath(inner, true);
            g.ExcludeClip(new Region(outline));

            inner.Dispose();
            outline.Dispose();
            pen.Dispose();
              }
        }
        /// <include file='doc\DataGridRelationshipRow.uex' path='docs/doc[@for="DataGridRelationshipRow.PaintRelations"]/*' />
        /// <devdoc>
        ///      Paints the relationships below the data area.
        /// </devdoc>
        private void PaintRelations(Graphics g, Rectangle bounds, Rectangle trueRowBounds,
                                    int dataWidth, int firstCol, int nCols, bool alignToRight) {

            // Calculate the relationship rect.
            // relationshipRect = Rectangle.Empty;
            Rectangle relRect = GetRelationshipRect();
            //relRect.Offset(trueRowBounds.X, trueRowBounds.Y);
            relRect.X = alignToRight ? bounds.Right - relRect.Width : bounds.X;
            relRect.Y = bounds.Y;
            int paintedWidth = Math.Max(dataWidth, relRect.Width);

            // Paint the stuff to the right , or left (Bi-Di) of the relationship rect.
            Region r = g.Clip;
            g.ExcludeClip(relRect);

            g.FillRectangle(GetBackBrush(),
                            alignToRight ? bounds.Right - dataWidth : bounds.X,
                            bounds.Y,
                            dataWidth,
                            bounds.Height);

            // Paint the relations' text
            g.SetClip(bounds);

            relRect.Height -= this.dgTable.BorderWidth;     // use bWidth not 1
            g.DrawRectangle(SystemPens.ControlText, relRect.X, relRect.Y, relRect.Width - 1, relRect.Height - 1);
            relRect.Inflate(-1, -1);

            int cy = PaintRelationText(g, relRect, alignToRight);

            if (cy < relRect.Height) {
                g.FillRectangle(GetBackBrush(), relRect.X, relRect.Y + cy, relRect.Width, relRect.Height - cy);
            }

            g.Clip = r;

            // paint any exposed area to the right or to the left (BI-DI)
            if (paintedWidth < bounds.Width) {
                int bWidth;
                if (this.dgTable.IsDefault)
                    bWidth = this.DataGrid.GridLineWidth;
                else
                    bWidth = this.dgTable.GridLineWidth;
                g.FillRectangle(DataGrid.BackgroundBrush,
                                alignToRight ? bounds.X : bounds.X + paintedWidth,
                                bounds.Y,
                                bounds.Width - paintedWidth - bWidth + 1, // + 1 cause the relationship rectangle was deflated
                                bounds.Height);

                // Paint the border to the right of each cell
                if (bWidth > 0) {
                    Brush br;
                    // if the user changed the gridLineColor on the dataGrid
                    // from the defaultValue, then use that value;
                    if (this.dgTable.IsDefault)
                        br = this.DataGrid.GridLineBrush;
                    else
                        br = this.dgTable.GridLineBrush;
                    g.FillRectangle(br,
                                    alignToRight ? bounds.Right - bWidth - paintedWidth : bounds.X + paintedWidth - bWidth,
                                    bounds.Y,
                                    bWidth,
                                    bounds.Height);
                }
            }

        }
Пример #23
0
        void DrawBackground(Graphics g)
        {
            Rectangle rc = ClientRectangle;
            // If we don't have any bands, just fill the rectangle
            // with the System Control Color
            if ( bands.Count == 0 || currentBandIndex == -1 )
            {
                g.FillRectangle(SystemBrushes.Control, rc);
                return;
            }

            if ( backgroundBitmap == null )
            {
                if ( currentBandIndex >= 0 && bands[currentBandIndex] != null )
                {
                    using ( SolidBrush b = new SolidBrush(bands[currentBandIndex].Background) )
                    {
                        // If there is a child control clip the area where the child
                        // control will be drawn to avoid flickering
                        if ( HasChild() )
                        {
                            Rectangle clipRect = GetViewPortRect();
                            g.ExcludeClip(clipRect);
                        }
                        g.FillRectangle(b, rc);
                    }
                }
            }
            else
            {
                // Draw custom background bitmap
                // -- I don't know why but the bitmap is not painted properly if using the right size
                // I use the WindowsAPI to work around the problem
                GDIUtil.StrechBitmap(g, rc, backgroundBitmap);

                if ( needBackgroundBitmapResize )
                {
                    needBackgroundBitmapResize = false;
                    backgroundBitmap = GDIUtil.GetStrechedBitmap(g, rc, backgroundBitmap);
                }
            }
        }
Пример #24
0
		protected virtual void OnNCPaint(Graphics g)
		{
			Rectangle windowRect = new Rectangle(new Point(0, 0), this.Size);
			Rectangle clientRect = OnNCCalcSize(windowRect);
			
			clientRect.Offset(-windowRect.Left, -windowRect.Top);
			g.ExcludeClip(clientRect);
			windowRect.Offset(-windowRect.Left, -windowRect.Top);
			
			Brush b = new SolidBrush(this.BackColor);
			g.FillRectangle(b, windowRect);
			b.Dispose();
			
			Pen p = new Pen(this.ForeColor, 2);
			g.DrawPath(p, path);
			p.Dispose();
		}
Пример #25
0
        protected void DrawSpeechBalloon(Graphics g, Color borderColor, int borderSize, Color fillColor, Rectangle rect, Point tailPosition)
        {
            GraphicsPath gpTail = null;

            if (TailVisible)
            {
                gpTail = CreateTailPath(rect, tailPosition);
            }

            if (fillColor.A > 0)
            {
                using (Brush brush = new SolidBrush(fillColor))
                {
                    g.FillRectangle(brush, rect);
                }
            }

            if (gpTail != null)
            {
                g.SmoothingMode = SmoothingMode.HighQuality;

                if (fillColor.A > 0)
                {
                    g.ExcludeClip(rect);

                    using (Brush brush = new SolidBrush(fillColor))
                    {
                        g.FillPath(brush, gpTail);
                    }

                    g.ResetClip();
                }

                if (borderSize > 0 && borderColor.A > 0)
                {
                    g.ExcludeClip(rect.Offset(-1));

                    using (Pen pen = new Pen(borderColor, borderSize))
                    {
                        g.DrawPath(pen, gpTail);
                    }

                    g.ResetClip();
                }

                g.SmoothingMode = SmoothingMode.None;
            }

            if (borderSize > 0 && borderColor.A > 0)
            {
                if (gpTail != null)
                {
                    using (Region region = new Region(gpTail))
                    {
                        g.ExcludeClip(region);
                    }
                }

                using (Pen pen = new Pen(borderColor, borderSize) { Alignment = PenAlignment.Inset })
                {
                    g.DrawRectangleProper(pen, rect.Offset(borderSize - 1));
                }

                g.ResetClip();
            }

            if (gpTail != null)
            {
                gpTail.Dispose();
            }
        }
 private void DrawTabs(IList tabs, Graphics gr, bool fRegion)
 {
     Control current;
     IEnumerator enumerator = tabs.GetEnumerator();
     int num = 0;
     Rectangle empty = Rectangle.Empty;
     Size size = Size.Empty;
     Font tabFont = this.tabFont;
     if (fRegion)
     {
         this.region = new Region(new Rectangle(0, 0, 0, 0));
     }
     if (this.ctlHover != null)
     {
         Rectangle convertedBounds = this.GetConvertedBounds(this.ctlHover);
         Rectangle rect = convertedBounds;
         rect.Inflate(this.selSize, this.selSize);
         if (fRegion)
         {
             this.region = new Region(rect);
             this.region.Exclude(convertedBounds);
         }
         else
         {
             Color backColor = this.ctlHover.Parent.BackColor;
             Region clip = gr.Clip;
             gr.ExcludeClip(convertedBounds);
             using (SolidBrush brush = new SolidBrush(backColor))
             {
                 gr.FillRectangle(brush, rect);
             }
             ControlPaint.DrawSelectionFrame(gr, false, rect, convertedBounds, backColor);
             gr.Clip = clip;
         }
     }
     while (enumerator.MoveNext())
     {
         current = (Control) enumerator.Current;
         empty = this.GetConvertedBounds(current);
         this.drawString.Length = 0;
         Control sitedParent = this.GetSitedParent(current);
         Control rootComponent = (Control) this.host.RootComponent;
         while ((sitedParent != rootComponent) && (sitedParent != null))
         {
             this.drawString.Insert(0, this.decimalSep);
             this.drawString.Insert(0, sitedParent.TabIndex.ToString(CultureInfo.CurrentCulture));
             sitedParent = this.GetSitedParent(sitedParent);
         }
         this.drawString.Insert(0, ' ');
         this.drawString.Append(current.TabIndex.ToString(CultureInfo.CurrentCulture));
         this.drawString.Append(' ');
         if (((PropertyDescriptor) this.tabProperties[current]).IsReadOnly)
         {
             this.drawString.Append(System.Design.SR.GetString("WindowsFormsTabOrderReadOnly"));
             this.drawString.Append(' ');
         }
         string text = this.drawString.ToString();
         size = Size.Ceiling(gr.MeasureString(text, tabFont));
         empty.Width = size.Width + 2;
         empty.Height = size.Height + 2;
         this.tabGlyphs[num++] = empty;
         if (fRegion)
         {
             this.region.Union(empty);
         }
         else
         {
             Brush highlightTextBrush;
             Pen highlightPen;
             Color highlight;
             if (this.tabComplete.IndexOf(current) != -1)
             {
                 highlightTextBrush = this.highlightTextBrush;
                 highlightPen = this.highlightPen;
                 highlight = SystemColors.Highlight;
             }
             else
             {
                 highlightTextBrush = SystemBrushes.Highlight;
                 highlightPen = SystemPens.HighlightText;
                 highlight = SystemColors.HighlightText;
             }
             gr.FillRectangle(highlightTextBrush, empty);
             gr.DrawRectangle(highlightPen, empty.X, empty.Y, empty.Width - 1, empty.Height - 1);
             Brush brush3 = new SolidBrush(highlight);
             gr.DrawString(text, tabFont, brush3, (float) (empty.X + 1), (float) (empty.Y + 1));
             brush3.Dispose();
         }
     }
     if (fRegion)
     {
         current = (Control) this.host.RootComponent;
         empty = this.GetConvertedBounds(current);
         this.region.Intersect(empty);
         base.Region = this.region;
     }
 }
 protected internal override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight)
 {
     object obj2 = (this.isEditing && (this.editingRow == rowNum)) ? this.currentValue : this.GetColumnValueAtRow(source, rowNum);
     ButtonState inactive = ButtonState.Inactive;
     if (!Convert.IsDBNull(obj2))
     {
         inactive = ((bool) obj2) ? ButtonState.Checked : ButtonState.Normal;
     }
     Rectangle checkBoxBounds = this.GetCheckBoxBounds(bounds, alignToRight);
     Region clip = g.Clip;
     g.ExcludeClip(checkBoxBounds);
     Brush brush = this.DataGridTableStyle.IsDefault ? this.DataGridTableStyle.DataGrid.SelectionBackBrush : this.DataGridTableStyle.SelectionBackBrush;
     if ((this.isSelected && (this.editingRow == rowNum)) && !this.IsReadOnly())
     {
         g.FillRectangle(brush, bounds);
     }
     else
     {
         g.FillRectangle(backBrush, bounds);
     }
     g.Clip = clip;
     if (inactive == ButtonState.Inactive)
     {
         ControlPaint.DrawMixedCheckBox(g, checkBoxBounds, ButtonState.Checked);
     }
     else
     {
         ControlPaint.DrawCheckBox(g, checkBoxBounds, inactive);
     }
     if ((this.IsReadOnly() && this.isSelected) && (source.Position == rowNum))
     {
         bounds.Inflate(-1, -1);
         Pen pen = new Pen(brush) {
             DashStyle = DashStyle.Dash
         };
         g.DrawRectangle(pen, bounds);
         pen.Dispose();
         bounds.Inflate(1, 1);
     }
 }
Пример #28
0
        /// <include file='doc\DataGridBoolColumn.uex' path='docs/doc[@for="DataGridBoolColumn.Paint2"]/*' />
        /// <devdoc>
        /// <para>Draws the <see cref='System.Windows.Forms.DataGridBoolColumn'/> with the given <see cref='System.Drawing.Graphics'/>, <see cref='System.Drawing.Rectangle'/>,
        ///    row number, <see cref='System.Drawing.Brush'/>, and <see cref='System.Drawing.Color'/>. </para>
        /// </devdoc>
        protected internal override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum,
                                     Brush backBrush, Brush foreBrush,
                                     bool alignToRight) {
            object value = (isEditing && editingRow == rowNum) ? currentValue : GetColumnValueAtRow(source, rowNum);
            ButtonState checkedState = ButtonState.Inactive;
            if (!Convert.IsDBNull(value)) {
                checkedState = ((bool)value ? ButtonState.Checked : ButtonState.Normal);
            }

            Rectangle box = GetCheckBoxBounds(bounds, alignToRight);

            Region r = g.Clip;
            g.ExcludeClip(box);

            System.Drawing.Brush selectionBrush = this.DataGridTableStyle.IsDefault ? this.DataGridTableStyle.DataGrid.SelectionBackBrush : this.DataGridTableStyle.SelectionBackBrush;
            if (isSelected && editingRow == rowNum && !IsReadOnly()) {
                g.FillRectangle(selectionBrush, bounds);
            }
            else
                g.FillRectangle(backBrush, bounds);
            g.Clip = r;

            if (checkedState == ButtonState.Inactive) {
                ControlPaint.DrawMixedCheckBox(g, box, ButtonState.Checked);
            } else {
                ControlPaint.DrawCheckBox(g, box, checkedState);
            }

            // if the column is read only we should still show selection
            if (IsReadOnly() && isSelected && source.Position == rowNum) {
                bounds.Inflate(-1,-1);
                System.Drawing.Pen pen = new System.Drawing.Pen(selectionBrush);
                pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                g.DrawRectangle(pen, bounds);
                pen.Dispose();
                // restore the bounds rectangle
                bounds.Inflate(1,1);
            }
        }
Пример #29
0
        internal static void DrawBorder(Graphics g, RectangleF rect, CornerShape bShape,
            ToolStripStatusLabelBorderSides bVisibility, DashStyle bLineStyle,
            int cornerRadius, Color borderColor, Brush borderBrush, Region excRegion)
        {
            if (bVisibility == ToolStripStatusLabelBorderSides.None)
            {
                return;
            }
            if (excRegion != null)
            {
                g.ExcludeClip(excRegion);
            }
            var pen = borderBrush != null ? new Pen(borderBrush, 1f) : new Pen(borderColor, 1f);
            var smoothingMode = g.SmoothingMode;
            pen.DashStyle = bLineStyle;
            var num = 2*cornerRadius;
            if (bVisibility == ToolStripStatusLabelBorderSides.All)
            {
                var path = GetDrawingPath(rect, bShape, cornerRadius);
                g.DrawPath(pen, path);
                path.Dispose();
                g.SmoothingMode = smoothingMode;
                pen.Dispose();
                return;
            }
            if ((bVisibility & ToolStripStatusLabelBorderSides.Left) > ToolStripStatusLabelBorderSides.None)
            {
                g.DrawLine(pen, rect.X, rect.Y + cornerRadius, rect.X, (rect.Y + rect.Height) - cornerRadius);
            }
            if ((bVisibility & ToolStripStatusLabelBorderSides.Top) > ToolStripStatusLabelBorderSides.None)
            {
                g.DrawLine(pen, rect.X + cornerRadius, rect.Y, (rect.X + rect.Width) - cornerRadius, rect.Y);
            }
            if ((bVisibility & ToolStripStatusLabelBorderSides.Right) > ToolStripStatusLabelBorderSides.None)
            {
                g.DrawLine(pen, rect.X + rect.Width, rect.Y + cornerRadius, rect.X + rect.Width,
                           (rect.Y + rect.Height) - cornerRadius);
            }
            if ((bVisibility & ToolStripStatusLabelBorderSides.Bottom) > ToolStripStatusLabelBorderSides.None)
            {
                g.DrawLine(pen, rect.X + cornerRadius, rect.Y + rect.Height, (rect.X + rect.Width) - cornerRadius,
                           rect.Y + rect.Height);
            }
            if (((bVisibility & ToolStripStatusLabelBorderSides.Left) > ToolStripStatusLabelBorderSides.None) ||
                ((bVisibility & ToolStripStatusLabelBorderSides.Top) > ToolStripStatusLabelBorderSides.None))
            {
                switch (bShape.TopLeft)
                {
                    case CornerType.Sliced:
                        g.DrawLine(pen, rect.X, rect.Y + cornerRadius, rect.X + cornerRadius, rect.Y);
                        break;

                    case CornerType.Square:
                        if (((bVisibility & ToolStripStatusLabelBorderSides.Left) <=
                             ToolStripStatusLabelBorderSides.None) ||
                            ((bVisibility & ToolStripStatusLabelBorderSides.Top) > ToolStripStatusLabelBorderSides.None))
                        {
                            if (((bVisibility & ToolStripStatusLabelBorderSides.Left) <=
                                 ToolStripStatusLabelBorderSides.None) &&
                                ((bVisibility & ToolStripStatusLabelBorderSides.Top) >
                                 ToolStripStatusLabelBorderSides.None))
                            {
                                g.DrawLine(pen, rect.X, rect.Y, rect.X + cornerRadius, rect.Y);
                            }
                            else
                            {
                                g.DrawLine(pen, rect.X, rect.Y + cornerRadius, rect.X, rect.Y);
                                g.DrawLine(pen, rect.X, rect.Y, rect.X + cornerRadius, rect.Y);
                            }
                        }
                        else
                        {
                            g.DrawLine(pen, rect.X, rect.Y + cornerRadius, rect.X, rect.Y);
                        }
                        break;
                }
                if (((bVisibility & ToolStripStatusLabelBorderSides.Top) > ToolStripStatusLabelBorderSides.None) ||
                    ((bVisibility & ToolStripStatusLabelBorderSides.Right) > ToolStripStatusLabelBorderSides.None))
                {
                    switch (bShape.TopRight)
                    {
                        case CornerType.Sliced:
                            g.DrawLine(pen, (rect.X + rect.Width) - cornerRadius, rect.Y, rect.X + rect.Width,
                                       rect.Y + cornerRadius);
                            break;
                        case CornerType.Square:
                            if (((bVisibility & ToolStripStatusLabelBorderSides.Right) >
                                 ToolStripStatusLabelBorderSides.None) ||
                                ((bVisibility & ToolStripStatusLabelBorderSides.Top) <=
                                 ToolStripStatusLabelBorderSides.None))
                            {
                                if (((bVisibility & ToolStripStatusLabelBorderSides.Right) >
                                     ToolStripStatusLabelBorderSides.None) &&
                                    ((bVisibility & ToolStripStatusLabelBorderSides.Top) <=
                                     ToolStripStatusLabelBorderSides.None))
                                {
                                    g.DrawLine(pen, rect.X + rect.Width, rect.Y, rect.X + rect.Width,
                                               rect.Y + cornerRadius);
                                }
                                else
                                {
                                    g.DrawLine(pen, (rect.X + rect.Width) - cornerRadius, rect.Y, rect.X + rect.Width,
                                               rect.Y);
                                    g.DrawLine(pen, rect.X + rect.Width, rect.Y, rect.X + rect.Width,
                                               rect.Y + cornerRadius);
                                }
                            }
                            else
                            {
                                g.DrawLine(pen, (rect.X + rect.Width) - cornerRadius, rect.Y, rect.X + rect.Width,
                                           rect.Y);
                            }
                            break;
                    }
                    if (((bVisibility & ToolStripStatusLabelBorderSides.Right) > ToolStripStatusLabelBorderSides.None) ||
                        ((bVisibility & ToolStripStatusLabelBorderSides.Bottom) > ToolStripStatusLabelBorderSides.None))
                    {
                        switch (bShape.BottomRight)
                        {
                            case CornerType.Sliced:
                                g.DrawLine(pen, rect.X + rect.Width, (rect.Y + rect.Height) - cornerRadius,
                                           (rect.X + rect.Width) - cornerRadius, rect.Y + rect.Height);
                                break;

                            case CornerType.Square:
                                if (((bVisibility & ToolStripStatusLabelBorderSides.Right) <=
                                     ToolStripStatusLabelBorderSides.None) ||
                                    ((bVisibility & ToolStripStatusLabelBorderSides.Bottom) >
                                     ToolStripStatusLabelBorderSides.None))
                                {
                                    if (((bVisibility & ToolStripStatusLabelBorderSides.Right) <=
                                         ToolStripStatusLabelBorderSides.None) &&
                                        ((bVisibility & ToolStripStatusLabelBorderSides.Bottom) >
                                         ToolStripStatusLabelBorderSides.None))
                                    {
                                        g.DrawLine(pen, (rect.X + rect.Width), (rect.Y + rect.Height),
                                                   (rect.X + rect.Width) - cornerRadius, (rect.Y + rect.Height));
                                    }
                                    else
                                    {
                                        g.DrawLine(pen, (rect.X + rect.Width), ((rect.Y + rect.Height) - cornerRadius),
                                                   rect.X + rect.Width, (rect.Y + rect.Height));
                                        g.DrawLine(pen, (rect.X + rect.Width), (rect.Y + rect.Height),
                                                   (rect.X + rect.Width) - cornerRadius, (rect.Y + rect.Height));
                                    }
                                }
                                else
                                {
                                    g.DrawLine(pen, rect.X + rect.Width, (rect.Y + rect.Height) - cornerRadius,
                                               rect.X + rect.Width, rect.Y + rect.Height);
                                }
                                break;
                        }
                        if (((bVisibility & ToolStripStatusLabelBorderSides.Bottom) >
                             ToolStripStatusLabelBorderSides.None) ||
                            ((bVisibility & ToolStripStatusLabelBorderSides.Left) > ToolStripStatusLabelBorderSides.None))
                        {
                            switch (bShape.BottomLeft)
                            {
                                case CornerType.Sliced:
                                    g.DrawLine(pen, rect.X + cornerRadius, rect.Y + rect.Height, rect.X,
                                               (rect.Y + rect.Height) - cornerRadius);
                                    g.SmoothingMode = smoothingMode;
                                    pen.Dispose();
                                    return;

                                case CornerType.Square:
                                    if (((bVisibility & ToolStripStatusLabelBorderSides.Left) >
                                         ToolStripStatusLabelBorderSides.None) ||
                                        ((bVisibility & ToolStripStatusLabelBorderSides.Bottom) <=
                                         ToolStripStatusLabelBorderSides.None))
                                    {
                                        if (((bVisibility & ToolStripStatusLabelBorderSides.Left) >
                                             ToolStripStatusLabelBorderSides.None) &&
                                            ((bVisibility & ToolStripStatusLabelBorderSides.Bottom) <=
                                             ToolStripStatusLabelBorderSides.None))
                                        {
                                            g.DrawLine(pen, rect.X, rect.Y + rect.Height, rect.X,
                                                       (rect.Y + rect.Height) - cornerRadius);
                                        }
                                        else
                                        {
                                            g.DrawLine(pen, rect.X + cornerRadius, rect.Y + rect.Height, rect.X,
                                                       rect.Y + rect.Height);
                                            g.DrawLine(pen, rect.X, rect.Y + rect.Height, rect.X,
                                                       (rect.Y + rect.Height) - cornerRadius);
                                        }
                                    }
                                    else
                                    {
                                        g.DrawLine(pen, rect.X + cornerRadius, rect.Y + rect.Height, rect.X,
                                                   rect.Y + rect.Height);
                                    }
                                    g.SmoothingMode = smoothingMode;
                                    pen.Dispose();
                                    return;
                            }
                            g.DrawArc(pen, rect.X, (rect.Y + rect.Height) - num, num, num, 90f, 90f);
                        }
                        g.DrawArc(pen, (rect.X + rect.Width) - num, (rect.Y + rect.Height) - num, num, num, 0f, 90f);
                    }
                    g.DrawArc(pen, (rect.X + rect.Width) - num, rect.Y, num, num, 270f, 90f);
                }
                g.DrawArc(pen, rect.X, rect.Y, num, num, 180f, 90f);
            }
        }
Пример #30
0
 private void Draw(Graphics g)
 {
     int width = this.Width;
     int height = this.Height;
     using (Bitmap image = new Bitmap(width, height, g))
     {
         using (Graphics g2 = Graphics.FromImage(image))
         {
             GraphicsEx gEx = new GraphicsEx(g2);
             gEx.FillRectangle(m_settings.BackgroundColor, 0, 0, width, height);
             gEx.SetRenderingMode(m_settings.Mode);
             DoDraw(gEx);
             Rectangle rect = new Rectangle(m_spreads.Location, m_spreads.Size);
             g.ExcludeClip(rect);
             g.DrawImage(image, 0, 0);
         }
     }
 }