Intersect() public method

Updates this Region to the intersection of itself with the specified GraphicsPath.
public Intersect ( GraphicsPath path ) : void
path System.Drawing.Drawing2D.GraphicsPath Path.
return void
        public Region CombineAreas()
        {
            Region region = new Region();
            region.MakeEmpty();

            foreach (Area area in Areas)
            {
                region.Union(area.Region);
            }

            region.Intersect(new Region(Crop.Bounds));

            return region;
        }
Esempio n. 2
0
        //draw round rectangular button function
        void DrawRoundRectangularButton(Graphics g)
        {
            Color c1 = Color.FromArgb(color1Transparent, color1);
            Color c2 = Color.FromArgb(color2Transparent, color2);


            Brush b = new System.Drawing.Drawing2D.LinearGradientBrush(ClientRectangle, c1, c2, angle);

            Region region = new System.Drawing.Region(new Rectangle(5, 5, this.Width, this.Height));

            GraphicsPath grp = new GraphicsPath();

            grp.AddArc(5, 5, 40, 40, 180, 90);
            grp.AddLine(25, 5, this.Width - 25, 5);
            grp.AddArc(this.Width - 45, 5, 40, 40, 270, 90);
            grp.AddLine(this.Width - 5, 25, this.Width - 5, this.Height - 25);
            grp.AddArc(this.Width - 45, this.Height - 45, 40, 40, 0, 90);
            grp.AddLine(25, this.Height - 5, this.Width - 25, this.Height - 5);
            grp.AddArc(5, this.Height - 45, 40, 40, 90, 90);
            grp.AddLine(5, 25, 5, this.Height - 25);

            region.Intersect(grp);

            g.FillRegion(b, region);

            for (int i = 0; i < borderWidth; i++)
            {
                g.DrawArc(new Pen(buttonborder_1), 5 + i, 5 + i, 40, 40, 180, 90);
                g.DrawLine(new Pen(buttonborder_1), 25, 5 + i, this.Width - 25, 5 + i);
                g.DrawArc(new Pen(buttonborder_1), this.Width - 45 - i, 5 + i, 40, 40, 270, 90);
                g.DrawLine(new Pen(buttonborder_1), 5 + i, 25, 5 + i, this.Height - 25);


                g.DrawLine(new Pen(buttonborder_2), this.Width - 5 - i, 25, this.Width - 5 - i, this.Height - 25);
                g.DrawArc(new Pen(buttonborder_2), this.Width - 45 - i, this.Height - 45 - i, 40, 40, 0, 90);
                g.DrawLine(new Pen(buttonborder_2), 25, this.Height - 5 - i, this.Width - 25, this.Height - 5 - i);
                g.DrawArc(new Pen(buttonborder_2), 5 + i, this.Height - 45 - i, 40, 40, 90, 90);
            }



            if (showButtonText)
            {
                Point      p       = new Point(textX, textY);
                SolidBrush frcolor = new SolidBrush(this.ForeColor);
                g.DrawString(text, this.Font, frcolor, p);
            }

            b.Dispose();
        }
Esempio n. 3
0
        // Returns a percentage of the ErrorArea circle trespassing on the zone.
        // If anyone knows calculus better than me I'd welcome you to clean up this function =)
        public float TrespassArea(Point3D pntLocation, float flErrorRadius) {

            float flReturnPercentage = 0.0F;
            float flErrorArea = (float)(flErrorRadius * flErrorRadius * Math.PI);

            GraphicsPath gpLocationError = new GraphicsPath();
            gpLocationError.AddEllipse(new RectangleF(pntLocation.X - flErrorRadius, pntLocation.Y - flErrorRadius, flErrorRadius * 2, flErrorRadius * 2));
            gpLocationError.CloseAllFigures();

            Region regZone = new Region(this.ZoneGraphicsPath);
            regZone.Intersect(gpLocationError);
            RectangleF[] a_recScans = regZone.GetRegionScans(new Matrix());
            Rectangle recIntersection = new Rectangle(int.MaxValue, int.MaxValue, 0, 0);

            int iPixelCount = 0;

            if (a_recScans.Length > 0) {

                for (int i = 0; i < a_recScans.Length; i++) {
                    recIntersection.X = a_recScans[i].X < recIntersection.X ? (int)a_recScans[i].X : recIntersection.X;
                    recIntersection.Y = a_recScans[i].Y < recIntersection.Y ? (int)a_recScans[i].Y : recIntersection.Y;

                    recIntersection.Width = a_recScans[i].Right > recIntersection.Right ? (int)a_recScans[i].Right - recIntersection.X : recIntersection.Width;
                    recIntersection.Height = a_recScans[i].Bottom > recIntersection.Bottom ? (int)a_recScans[i].Bottom - recIntersection.Y : recIntersection.Height;
                }

                //recIntersection = this.RecFtoRec(regZone.GetBounds(this.CreateGraphics()));
                Point pntVisible = new Point(recIntersection.X, recIntersection.Y);

                for (pntVisible.X = recIntersection.X; pntVisible.X <= recIntersection.Right; pntVisible.X++) {
                    for (pntVisible.Y = recIntersection.Y; pntVisible.Y <= recIntersection.Bottom; pntVisible.Y++) {
                        if (regZone.IsVisible(pntVisible) == true) {
                            iPixelCount++;
                        }
                    }
                }
            }

            flReturnPercentage = (float)iPixelCount / flErrorArea;

            // Accounts for low error when using this method. (98.4% should be 100%)
            // but using regZone.GetRegionScans is slightly lossy.
            if (flReturnPercentage > 0.0F) {
                flReturnPercentage = (float)Math.Min(1.0F, flReturnPercentage + 0.02);
            }

            return flReturnPercentage;
        }
Esempio n. 4
0
        /// <summary>
        /// Initialize a new instance of the Clipping class.
        /// </summary>
        /// <param name="graphics">Graphics context.</param>
        /// <param name="path">Path to clip.</param>
        /// <param name="exclude">Exclude path from clipping.</param>
        public Clipping(Graphics graphics, GraphicsPath path, bool exclude)
        {
            // Cache graphics instance
            _graphics = graphics;

            // Save the existing clipping region
            _previousRegion = _graphics.Clip;

            // Add clipping of path to existing clipping region
            _newRegion = _previousRegion.Clone();

            if (exclude)
                _newRegion.Exclude(path);
            else
                _newRegion.Intersect(path);

            _graphics.Clip = _newRegion;
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            Region regionRing = new Region(outCircle.Path);
            //形成圆环
            regionRing.Xor(innerCircle.Path);
            //截取部分圆环
            regionRing.Intersect(clipRectangle);
            e.Graphics.FillRegion(Brushes.Red, regionRing);
            //画处边框
            using (Pen p = new Pen(Brushes.Black))
            {
                e.Graphics.DrawPath(p, outCircle.Path);
                e.Graphics.DrawPath(p, innerCircle.Path);
            }
        }
Esempio n. 6
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.Clear(this.BackColor);
            // Создаем два прямоугольника
            Rectangle rect1 = new Rectangle(40, 40, 140, 140);
            Rectangle rect2 = new Rectangle(100, 100, 140, 140);
            // Создаем два региона
            Region rgn1 = new Region(rect1);
            Region rgn2 = new Region(rect2);
            g.DrawRectangle(Pens.Blue, rect1);
            g.DrawRectangle(Pens.Black, rect2);
            // определяем область пересеченияния
            rgn1.Intersect(rgn2);
            // заливаем ее красным цветом
            g.FillRegion(Brushes.Red, rgn1);
            g.Dispose();

        }
Esempio n. 7
0
        static BlockRegions()
        {
            int n = Constants.PROJ_WIDTH / 4;

            WholeBlock = new Region();
            WholeBlock.MakeEmpty();
            for (int i = 0; i <= n; i++)
            {
                WholeBlock.Union(new Rectangle(n * 2 - 1 - 2 * i, i, i * 4 + 2, Constants.PROJ_HEIGHT - 2 * i));
            }
            WholeBlock.Intersect(new Rectangle(0, 0, Constants.PROJ_WIDTH, Constants.PROJ_HEIGHT));
            InnerBlock = new Region();
            InnerBlock.MakeEmpty();
            for (int i = 0; i <= n; i++)
            {
                InnerBlock.Union(new Rectangle(n * 2 - 1 - 2 * i, i + 1, i * 4 + 2, Constants.PROJ_HEIGHT - 2 - 2 * i));
            }
            InnerBlock.Intersect(new Rectangle(1, 1, Constants.PROJ_WIDTH - 2, Constants.PROJ_HEIGHT - 2));

            OuterBorder = WholeBlock.Clone();
            OuterBorder.Exclude(InnerBlock);

            Top = InnerBlock.Clone();
            Top.Translate(0, -Constants.BLOCK_HEIGHT);
            Top.Intersect(InnerBlock);

            Left = InnerBlock.Clone();
            Left.Exclude(Top);
            Top.Translate(0, 1);
            Left.Exclude(Top);
            Top.Translate(0, -1);

            Right = Left.Clone();
            Left.Intersect(new Rectangle(0, 0, Constants.PROJ_WIDTH / 2, Constants.PROJ_HEIGHT));
            Right.Intersect(new Rectangle(Constants.PROJ_WIDTH / 2 + 1, 0, Constants.PROJ_WIDTH / 2, Constants.PROJ_HEIGHT));

            InnerBorder = InnerBlock.Clone();
            InnerBorder.Exclude(Top);
            InnerBorder.Exclude(Left);
            InnerBorder.Exclude(Right);
        }
Esempio n. 8
0
 public static Rectangle DrawIcons(Graphics gr, Rectangle aTextRect, CustomAppointment anAppointment, ImageList anAppIcons)
 {
     if ((anAppIcons != null) && (anAppointment.IconIndexes != null))
     {
         int length = anAppointment.IconIndexes.Length;
         int width = anAppIcons.ImageSize.Width;
         int num3 = aTextRect.Width / 3;
         if ((aTextRect.Width / 2) > width)
         {
             int x = (aTextRect.Right - 1) - width;
             int y = aTextRect.Y + 1;
             Region clip = gr.Clip;
             Region region2 = new Region(aTextRect);
             region2.Intersect(clip);
             gr.Clip = region2;
             for (int i = length - 1; i >= 0; i--)
             {
                 using (Image image = anAppIcons.Images[anAppointment.IconIndexes[i]])
                 {
                     Rectangle rect = new Rectangle(x, y, width, width);
                     DrawSingleIcon(gr, rect, image);
                 }
                 x -= width;
                 if (num3 >= (x - aTextRect.X))
                 {
                     aTextRect.Width -= width * (length - i);
                     return aTextRect;
                 }
             }
             gr.ResetClip();
             region2.Dispose();
             region2 = null;
             if (clip != null)
             {
                 gr.Clip = clip;
             }
             aTextRect.Width -= width * length;
         }
     }
     return aTextRect;
 }
Esempio n. 9
0
        private void DrawRegionOperations()
        {
            g = this.CreateGraphics();
            // Создаем два прямоугольника
            Rectangle rect1 = new Rectangle(100, 100, 120, 120);
            Rectangle rect2 = new Rectangle(70, 70, 120, 120);
            // Создаем два региона
            Region rgn1 = new Region(rect1);
            Region rgn2 = new Region(rect2);
            // рисуем прямоугольники
            g.DrawRectangle(Pens.Green, rect1);
            g.DrawRectangle(Pens.Black, rect2);

            // обработаем перечисление и вызовем соответствующий метод
            switch (rgnOperation)
            {
                case RegionOperations.Union:
                    rgn1.Union(rgn2);
                    break;
                case RegionOperations.Complement:
                    rgn1.Complement(rgn2);
                    break;
                case RegionOperations.Intersect:
                    rgn1.Intersect(rgn2);
                    break;
                case RegionOperations.Exclude:
                    rgn1.Exclude(rgn2);
                    break;
                case RegionOperations.Xor:
                    rgn1.Xor(rgn2);
                    break;
                default:
                    break;
            }
            // Рисуем регион
            g.FillRegion(Brushes.Blue, rgn1);
            g.Dispose();
        }
Esempio n. 10
0
        void DrawRegionOperation()
        {
            g = this.CreateGraphics();
            Rectangle rect1 = new Rectangle(100, 100, 120, 120);
            Rectangle rect2 = new Rectangle(70, 70, 120, 120);

            Region rgn1 = new Region(rect1);
            Region rgn2 = new Region(rect2);

            g.DrawRectangle(Pens.Blue, rect1);
            g.DrawRectangle(Pens.Red, rect2);

            switch(rgnOperation)
            {
                case RegionOperation.Union:
                    rgn1.Union(rgn2);
                    break;
                case RegionOperation.Complement:
                    rgn1.Complement(rgn2);
                    break;
                case RegionOperation.Intersect:
                    rgn1.Intersect(rgn2);
                    break;
                case RegionOperation.Exclude:
                    rgn1.Exclude(rgn2);
                    break;
                case RegionOperation.Xor:
                    rgn1.Xor(rgn2);
                    break;
                default:
                    break;

            }

            g.FillRegion(Brushes.Tomato, rgn1);

            g.Dispose();
        }
Esempio n. 11
0
        //draw round rectangular button function
        void DrawRoundRectangularButton(Graphics g)
        {
            Color c1     = Color.FromArgb(color1Transparent, color1);
            Color c2     = Color.FromArgb(color2Transparent, color2);
            int   radius = 20;

            Brush b = new System.Drawing.Drawing2D.LinearGradientBrush(ClientRectangle, c1, c2, angle);

            Region region = new System.Drawing.Region(new Rectangle(5, 5, this.Width, this.Height));

            GraphicsPath grp = new GraphicsPath();

            grp.AddArc(5, 5, radius, radius, 180, 90);

            grp.AddArc(this.Width - (radius + 5), 5, radius, radius, 270, 90);

            grp.AddArc(this.Width - (radius + 5), this.Height - (radius + 5), radius, radius, 0, 90);

            grp.AddArc(5, this.Height - (radius + 5), radius, radius, 90, 90);


            region.Intersect(grp);

            g.FillRegion(b, region);



            if (showButtonText)
            {
                Point      p       = new Point(textX, textY);
                SolidBrush frcolor = new SolidBrush(this.ForeColor);
                g.DrawString(text, this.Font, frcolor, p);
            }

            b.Dispose();
        }
Esempio n. 12
0
		public override void DataGridPaintParentRows (Graphics g, Rectangle clip, DataGrid grid)
		{
			Rectangle rect_row = new Rectangle ();

			rect_row.X = grid.ParentRowsArea.X;
			rect_row.Width = grid.ParentRowsArea.Width;
			rect_row.Height = (grid.CaptionFont.Height + 3);

			object[] parentRows = grid.data_source_stack.ToArray();
			
			Region current_clip;
			Region prev_clip = g.Clip;
			for (int row = 0; row < parentRows.Length; row++) {
				rect_row.Y = grid.ParentRowsArea.Y + row * rect_row.Height;

				if (clip.IntersectsWith (rect_row) == false)
					continue;

				current_clip = new Region (rect_row);
				current_clip.Intersect (prev_clip);
				g.Clip = current_clip;

				DataGridPaintParentRow (g, rect_row, (DataGridDataSource)parentRows[parentRows.Length - row - 1], grid);

				current_clip.Dispose ();
			}
			
			g.Clip = prev_clip;
		}
Esempio n. 13
0
		public override void DataGridPaintColumnHeaders (Graphics g, Rectangle clip, DataGrid grid)
		{
			if (!grid.CurrentTableStyle.ColumnHeadersVisible)
				return;

			Rectangle columns_area = grid.column_headers_area;

			// Paint corner shared between row and column header
			if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
				Rectangle rect_bloc = grid.column_headers_area;
				rect_bloc.Width = grid.RowHeaderWidth;
				if (clip.IntersectsWith (rect_bloc)) {
					if (grid.FlatMode)
						g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), rect_bloc);
					else
						CPDrawBorder3D (g, rect_bloc, Border3DStyle.RaisedInner, 
							Border3DSide.Left | Border3DSide.Right | 
							Border3DSide.Top | Border3DSide.Bottom | Border3DSide.Middle, 
							grid.CurrentTableStyle.CurrentHeaderBackColor);
				}

				columns_area.X += grid.RowHeaderWidth;
				columns_area.Width -= grid.RowHeaderWidth;
			}

			// Set column painting
			Rectangle rect_columnhdr = new Rectangle ();
			int col_pixel;
			Region current_clip;
			Region prev_clip = g.Clip;
			rect_columnhdr.Y = columns_area.Y;
			rect_columnhdr.Height = columns_area.Height;

			int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
			for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) {
				if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false)
					continue;
				
				col_pixel = grid.GetColumnStartingPixel (column);
				rect_columnhdr.X = columns_area.X + col_pixel - grid.HorizPixelOffset;
				rect_columnhdr.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;

				if (clip.IntersectsWith (rect_columnhdr) == false)
					continue;

				current_clip = new Region (rect_columnhdr);
				current_clip.Intersect (columns_area);
				current_clip.Intersect (prev_clip);
				g.Clip = current_clip;

				DataGridPaintColumnHeader (g, rect_columnhdr, grid, column);

				current_clip.Dispose ();
			}

			g.Clip = prev_clip;
				
			Rectangle not_usedarea = grid.column_headers_area;
			not_usedarea.X = (column_cnt == 0) ? grid.RowHeaderWidth : rect_columnhdr.X + rect_columnhdr.Width;
			not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - not_usedarea.X;
			g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
		}
        bool IWorkflowDesignerMessageSink.OnPaint(PaintEventArgs e, Rectangle viewPort)
        {
            try
            {
                Rectangle bounds = Bounds;
                if (IsVisible && viewPort.IntersectsWith(bounds))
                {
                    GlyphManager glyphManager = GetService(typeof(IDesignerGlyphProviderService)) as GlyphManager;
                    bounds.Width += 1; bounds.Height += 1;

                    using (GraphicsPath graphicsPath = ActivityDesignerPaint.GetDesignerPath(this, Point.Empty, new Size(DesignerTheme.BorderWidth, DesignerTheme.BorderWidth), DesignerEdges.All, false))
                    using (Region clipRegion = new Region(graphicsPath))
                    {
                        Region oldRegion = e.Graphics.Clip;
                        clipRegion.Intersect(oldRegion);
                        clipRegion.Intersect(viewPort);

                        bool restoredClipState = false;
                        try
                        {
                            ActivityDesignerPaintEventArgs eventArgs = new ActivityDesignerPaintEventArgs(e.Graphics, bounds, viewPort, DesignerTheme);

                            e.Graphics.Clip = clipRegion;
                            OnPaint(eventArgs);
                            e.Graphics.Clip = oldRegion;
                            restoredClipState = true;

                            if (glyphManager != null)
                                glyphManager.DrawDesignerGlyphs(eventArgs, this);

                            DrawingState &= (~DrawingStates.InvalidDraw);
                        }
                        catch
                        {
                            //Eat the exception thrown
                            DrawingState |= DrawingStates.InvalidDraw;
                        }
                        finally
                        {
                            if (!restoredClipState)
                                e.Graphics.Clip = oldRegion;

                            if (DrawingState != DrawingStates.Valid)
                                ActivityDesignerPaint.DrawInvalidDesignerIndicator(e.Graphics, this);
                        }
                    }
                }
            }
            catch
            {
            }
            return true;
        }
Esempio n. 15
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Region clippingRegion = e.Graphics.Clip;

            TimeSpan time = TimeSpan.FromHours(EpgControl.EpgHoursOffset);
            int left = 0;
            const int step = 15;
            for (int count = 0; count < (24 * 60) / step; count++)
            {
                TimeSpan nextTime = time.Add(TimeSpan.FromMinutes(step));
                int nextLeft = EpgTimeControl.GetTimeCursorPosition(nextTime, 0);
                Rectangle visibleRectangle = new Rectangle(left - 1, 0, nextLeft - left + 1, this.Height);
                visibleRectangle.Intersect(e.ClipRectangle);

                Region cellRegion = new Region(visibleRectangle);
                cellRegion.Intersect(clippingRegion);
                if (!cellRegion.IsEmpty(e.Graphics))
                {
                    int lineLeft = Math.Max(0, left - 1);
                    e.Graphics.DrawLine(_epgBorderPen, lineLeft, 0, lineLeft, this.Height - 1);
                    string timeText = EpgTimeControl.GetTimeString(time);
                    e.Graphics.DrawString(timeText, _timeFont, _timeBrush, lineLeft + 1, 2);
                }

                left = nextLeft;
                time = nextTime;
            }

            if (this.CursorAtTime.HasValue)
            {
                int position = EpgTimeControl.GetTimeCursorPosition(_cursorAtTime.Value, -1);
                e.Graphics.DrawLine(_cursorPen, position, 0, position, this.Height - 1);
                e.Graphics.DrawLine(_cursorShadowPen, position + 1, 0, position + 1, this.Height - 1);

                string timeText = EpgTimeControl.GetTimeString(this.CursorAtTime.Value);
                SizeF size = e.Graphics.MeasureString(timeText, _cursorFont);

                e.Graphics.FillRectangle(_cursorBgBrush, position + 2, 1, size.Width, size.Height);
                e.Graphics.DrawString(timeText, _cursorFont, _cursorBrush, position + 2, 0);
            }

            base.OnPaint(e);
        }
Esempio n. 16
0
        // end DrawGraph
        private bool DrawItem(Graphics wa, Graph.LaneRow row)
        {
            if (row == null || row.NodeLane == -1)
            {
                return false;
            }

            // Clip to the area we're drawing in, but draw 1 pixel past so
            // that the top/bottom of the line segment's anti-aliasing isn't
            // visible in the final rendering.
            int top = wa.RenderingOrigin.Y + _rowHeight / 2;
            var laneRect = new Rectangle(0, top, Width, _rowHeight);
            Region oldClip = wa.Clip;
            var newClip = new Region(laneRect);
            newClip.Intersect(oldClip);
            wa.Clip = newClip;
            wa.Clear(Color.Transparent);

            for (int r = 0; r < 2; r++)
                for (int lane = 0; lane < row.Count; lane++)
                {
                    int mid = wa.RenderingOrigin.X + (int)((lane + 0.5) * LaneWidth);

                    for (int item = 0; item < row.LaneInfoCount(lane); item++)
                    {
                        Graph.LaneInfo laneInfo = row[lane, item];

                        //Draw all non-relative items first, them draw
                        //all relative items on top
                        if (laneInfo.Junctions.FirstOrDefault() != null)
                            if (laneInfo.Junctions.First().IsRelative == (r == 0))
                                continue;

                        List<Color> curColors = GetJunctionColors(laneInfo.Junctions);

                        // Create the brush for drawing the line
                        Brush brushLineColor;
                        bool drawBorder = BranchBorders; //hide border for "non-relatives"
                        if (curColors.Count == 1 || !StripedBranchChange)
                        {
                            if (curColors[0] != _nonRelativeColor)
                            {
                                brushLineColor = new SolidBrush(curColors[0]);
                            }
                            else if (curColors.Count > 1 && curColors[1] != _nonRelativeColor)
                            {
                                brushLineColor = new SolidBrush(curColors[1]);
                            }
                            else
                            {
                                drawBorder = false;
                                brushLineColor = new SolidBrush(_nonRelativeColor);
                            }
                        }
                        else
                        {
                            brushLineColor = new HatchBrush(HatchStyle.DarkDownwardDiagonal, curColors[0], curColors[1]);
                            if (curColors[0] == _nonRelativeColor && curColors[1] == _nonRelativeColor) drawBorder = false;
                        }

                        for (int i = drawBorder ? 0 : 2; i < 3; i++)
                        {
                            Pen penLine;
                            if (i == 0)
                            {
                                penLine = new Pen(new SolidBrush(Color.White), LaneLineWidth + 2);
                            }
                            else if (i == 1)
                            {
                                penLine = new Pen(new SolidBrush(Color.Black), LaneLineWidth + 1);
                            }
                            else
                            {
                                penLine = new Pen(brushLineColor, LaneLineWidth);
                            }

                            if (laneInfo.ConnectLane == lane)
                            {
                                wa.DrawLine
                                    (
                                        penLine,
                                        new Point(mid, top - 1),
                                        new Point(mid, top + _rowHeight + 2)
                                    );
                            }
                            else
                            {
                                wa.DrawBezier
                                    (
                                        penLine,
                                        new Point(mid, top - 1),
                                        new Point(mid, top + _rowHeight + 2),
                                        new Point(mid + (laneInfo.ConnectLane - lane) * LaneWidth, top - 1),
                                        new Point(mid + (laneInfo.ConnectLane - lane) * LaneWidth, top + _rowHeight + 2)
                                    );
                            }
                        }
                    }
                }

            // Reset the clip region
            wa.Clip = oldClip;
            {
                // Draw node
                var nodeRect = new Rectangle
                    (
                    wa.RenderingOrigin.X + (LaneWidth - NodeDimensions) / 2 + row.NodeLane * LaneWidth,
                    wa.RenderingOrigin.Y + (_rowHeight - NodeDimensions) / 2,
                    NodeDimensions,
                    NodeDimensions
                    );

                Brush nodeBrush;
                bool drawBorder = BranchBorders;
                List<Color> nodeColors = GetJunctionColors(row.Node.Ancestors);
                if (nodeColors.Count == 1)
                {
                    nodeBrush = new SolidBrush(nodeColors[0]);
                    if (nodeColors[0] == _nonRelativeColor) drawBorder = false;
                }
                else
                {
                    nodeBrush = new LinearGradientBrush(nodeRect, nodeColors[0], nodeColors[1],
                                                        LinearGradientMode.Horizontal);
                    if (nodeColors[0] == _nonRelativeColor && nodeColors[1] == Color.LightGray) drawBorder = false;
                }

                if (_filterMode == FilterType.Highlight && row.Node.IsFiltered)
                {
                    Rectangle highlightRect = nodeRect;
                    highlightRect.Inflate(2, 3);
                    wa.FillRectangle(Brushes.Yellow, highlightRect);
                    wa.DrawRectangle(new Pen(Brushes.Black), highlightRect);
                }

                if (row.Node.Data == null)
                {
                    wa.FillEllipse(Brushes.White, nodeRect);
                    wa.DrawEllipse(new Pen(Color.Red, 2), nodeRect);
                }
                else if (row.Node.IsActive)
                {
                    wa.FillRectangle(nodeBrush, nodeRect);
                    nodeRect.Inflate(1, 1);
                    wa.DrawRectangle(new Pen(Color.Black, 3), nodeRect);
                }
                else if (row.Node.IsSpecial)
                {
                    wa.FillRectangle(nodeBrush, nodeRect);
                    if (drawBorder)
                    {
                        wa.DrawRectangle(new Pen(Color.Black, 1), nodeRect);
                    }
                }
                else
                {
                    wa.FillEllipse(nodeBrush, nodeRect);
                    if (drawBorder)
                    {
                        wa.DrawEllipse(new Pen(Color.Black, 1), nodeRect);
                    }
                }
            }
            return true;
        }
Esempio n. 17
0
		private void drawCells(Graphics g, System.Drawing.Pen pen,
			System.Drawing.Brush brText, RectangleF rc)
		{
			// DrawBorder3D does not honor clipping, so...
			CellFrameStyle cb = cellBorders;
			if (flowChart.NowPrinting && cb == CellFrameStyle.System3D)
				cb = CellFrameStyle.Simple;

			// draw the cells
			if (cells != null)
			{
				bool[,] coveredCells =
					hasSpanningCells ? getCoveredCells() : null;
				RectangleF cellsRect = RectangleF.FromLTRB(rc.Left,
					rc.Top + captionHeight, rc.Right, rc.Bottom);

				int rowFrom = CurrentRow - maxRowSpan + 1;
				if (rowFrom < 0)
					rowFrom = 0;

				float h = rc.Top + captionHeight;
				for (int r = rowFrom; r < rowsCount; r++)
				{
					RectangleF cellRect = rc;
					cellRect.Y = h;
					if (cellRect.Top >= rc.Bottom) break;

					cellRect.Height = ((Row)rowsList[r]).Height;

					if (cellRect.Bottom >= rc.Bottom) break;

					// If it is a hidden row below a collapsed header row, skip it
					if (isRowCollapsed(r))
						continue;

					if (rowFrom >= currScrollRow)
						h += ((Row)rowsList[r]).Height;

					for (int c = 0; c < columnsCount; ++c)
					{
						RectangleF imgRect = RectangleF.Empty;
						cellRect = getSpannedCellRect(r, c, true, ref imgRect);

						if (cellRect.Height == 0 ||
							cellRect.Width == 0 ||
							cellRect.Bottom <= cellsRect.Top)
							continue;

						Cell cell = (Cell)cells[r * columnsCount + c];

						if (!hasSpanningCells)
						{
							cell.draw(g, pen, brText, cellRect, Font, cb, r, c, imgRect);
						}
						else
						{
							// If the cell is covered by a spanned cell
							// and is not a span cell itself, do not draw it
							if (!coveredCells[c,r] ||
								(cell.RowSpan != 1 || cell.ColumnSpan != 1))
							{
								if (cell.RowSpan != 1 || cell.ColumnSpan != 1)
								{
									RectangleF cellVisibleRect =
										RectangleF.Intersect(cellRect, cellsRect);

									// Clip with the visible rect, and draw in the
									// absolute rect
									Region oldClip = g.Clip;
									Region newClip = new Region(cellVisibleRect);
									newClip.Intersect(oldClip);
									g.Clip = newClip;

									cell.draw(g, pen, brText, cellRect, Font, cb, r, c, imgRect);

									g.Clip = oldClip;
									newClip.Dispose();
								}
								else
								{
									cell.draw(g, pen, brText, cellRect, Font, cb, r, c, imgRect);
								}
							}
						}

						cellRect.X = cellRect.Right;
						if (cellRect.Left >= rc.Right) break;
					}
				}
			}
		}
Esempio n. 18
0
		public void EmptyRegionWithInfiniteRegion ()
		{
			Region empty = new Region ();
			empty.MakeEmpty ();
			Assert.IsTrue (empty.IsEmpty (graphic), "IsEmpty");

			Region region = new Region ();
			Assert.IsTrue (region.IsInfinite (graphic), "IsInfinite");

			region.Union (empty);
			Assert.IsTrue (region.IsInfinite (graphic), "Union-IsInfinite");

			region.Xor (empty);
			Assert.IsTrue (region.IsInfinite (graphic), "Xor-IsInfinite");

			region.Exclude (empty);
			Assert.IsTrue (region.IsInfinite (graphic), "Exclude-IsInfinite");

			region.Intersect (empty);
			Assert.IsTrue (region.IsEmpty (graphic), "Intersect-IsEmpty");

			region.MakeInfinite ();
			region.Complement (empty);
			Assert.IsTrue (region.IsEmpty (graphic), "Complement-IsEmpty");
		}
Esempio n. 19
0
		public void EmptyPathWithInfiniteRegion ()
		{
			GraphicsPath gp = new GraphicsPath ();
			Region region = new Region ();
			Assert.IsTrue (region.IsInfinite (graphic), "IsInfinite");

			region.Union (gp);
			Assert.IsTrue (region.IsInfinite (graphic), "Union-IsInfinite");

			region.Xor (gp);
			Assert.IsTrue (region.IsInfinite (graphic), "Xor-IsInfinite");

			region.Exclude (gp);
			Assert.IsTrue (region.IsInfinite (graphic), "Exclude-IsInfinite");

			region.Intersect (gp);
			Assert.IsTrue (region.IsEmpty (graphic), "Intersect-IsEmpty");

			region.MakeInfinite ();
			region.Complement (gp);
			Assert.IsTrue (region.IsEmpty (graphic), "Complement-IsEmpty");
		}
Esempio n. 20
0
		public void Translate_Float ()
		{
			Region r1 = new Region (sp1);
			Region r2 = new Region (sp2);
			r2.Translate (-2.0f, -2.0f);
			r1.Intersect (r2);
			CompareSmallRegion (r1, self1, 7, 7);
		}
Esempio n. 21
0
        /// <summary>
        /// Draws each element in group on graph object
        /// </summary>
        /// <param name="graphObj">Graph object to be drawn on</param>
        /// <param name="dx">X region</param>
        /// <param name="dy">Y region</param>
        /// <param name="zoom">Zoom value</param>
        public override void Draw(Graphics graphObj, int dx, int dy, float zoom)
        {
            GraphicsState oldGraphState = graphObj.Save();    //store previos trasformation
            Matrix        matrix        = graphObj.Transform; // get previous trasformation

            PointF point = new PointF(zoom * (region.X0 + dx + (region.X1 - region.X0) / 2),
                                      zoom * (region.Y0 + dy + (region.Y1 - region.Y0) / 2));

            if (this.Rotation > 0)
            {
                matrix.RotateAt(this.Rotation, point, MatrixOrder.Append); //add a trasformation
            }
            //X MIRROR  //Y MIRROR
            if (this.xMirror || this.yMirror)
            {
                matrix.Translate(-(region.X0 + region.Width / 2 + dx) * zoom,
                                 -(region.Y0 + region.Height / 2 + dy) * zoom, MatrixOrder.Append);

                if (this.xMirror)
                {
                    matrix.Multiply(new Matrix(-1, 0, 0, 1, 0, 0), MatrixOrder.Append);
                }
                if (this.yMirror)
                {
                    matrix.Multiply(new Matrix(1, 0, 0, -1, 0, 0), MatrixOrder.Append);
                }

                matrix.Translate((region.X0 + region.Width / 2 + dx) * zoom,
                                 (region.Y0 + region.Height / 2 + dy) * zoom, MatrixOrder.Append);
            }

            if (this.groupZoomX > 0 && this.groupZoomY > 0)
            {
                matrix.Translate((-1) * zoom * (region.X0 + dx +
                                                (region.X1 - region.X0) / 2), (-1) * zoom * (region.Y0 + dy +
                                                                                             (region.Y1 - region.Y0) / 2), MatrixOrder.Append);
                matrix.Scale(this.groupZoomX, this.groupZoomY, MatrixOrder.Append);
                matrix.Translate(zoom * (region.X0 + dx + (region.X1 - region.X0) / 2),
                                 zoom * (region.Y0 + dy + (region.Y1 - region.Y0) / 2),
                                 MatrixOrder.Append);
            }
            graphObj.Transform = matrix;

            if (this.IsGraphPath)
            {
                Brush myBrush = GetBrush(dx, dy, zoom);
                Pen   myPen   = this.CreatePen(zoom);

                GraphicsPath graphPath = new GraphicsPath();

                foreach (ShapeElement element in this.elementList)
                {
                    element.AddToGraphPath(graphPath, dx, dy, zoom);
                }

                if (this.FillEnabled)
                {
                    graphObj.FillPath(myBrush, graphPath);

                    if (this.ShowBorder)
                    {
                        graphObj.DrawPath(myPen, graphPath);
                    }
                }
                else
                {
                    graphObj.DrawPath(myPen, graphPath);
                }

                if (myBrush != null)
                {
                    myBrush.Dispose();
                }
                myPen.Dispose();
            }
            else
            {
                //MANAGE This.GroupDisplay
                System.Drawing.Region gregion = new System.Drawing.Region();

                if (GroupDisplay != GroupDisplay.Default)
                {
                    bool first = true;
                    foreach (ShapeElement element in this.elementList)
                    {
                        GraphicsPath graphPath = new GraphicsPath(FillMode.Winding);
                        element.AddToGraphPath(graphPath, dx, dy, zoom);

                        if (first)
                        {
                            gregion.Intersect(graphPath);
                        }
                        else
                        {
                            switch (GroupDisplay)
                            {
                            case GroupDisplay.Intersect:
                                gregion.Intersect(graphPath);
                                break;

                            case GroupDisplay.Xor:
                                gregion.Xor(graphPath);
                                break;

                            case GroupDisplay.Exclude:
                                gregion.Exclude(graphPath);
                                break;

                            default:
                                break;
                            }
                        }
                        first = false;
                    }
                    graphObj.SetClip(gregion, CombineMode.Intersect);
                }

                foreach (ShapeElement element in this.elementList)
                {
                    element.Draw(graphObj, dx, dy, zoom);
                }

                if (GroupDisplay != GroupDisplay.Default)
                {
                    graphObj.ResetClip();
                }
            }
            graphObj.Restore(oldGraphState);//restore previos trasformation

            if (this.Selected)
            {
                Brush myBrush = GetBrush(dx, dy, zoom);
                Pen   myPen   = this.CreatePen(zoom);

                graphObj.DrawRectangle(myPen, Rectangle.Round(region.GetRectangleF(dx, dy, zoom)));
                if (myBrush != null)
                {
                    myBrush.Dispose();
                }
                myPen.Dispose();
            }
            matrix.Dispose();
        }
Esempio n. 22
0
		public override void DataGridPaintRowContents (Graphics g, int row, Rectangle row_rect, bool is_newrow,
							       Rectangle clip, DataGrid grid)
		{
			Rectangle rect_cell = new Rectangle ();
			int col_pixel;
			Color backcolor, forecolor;
			Brush backBrush, foreBrush;
			Rectangle not_usedarea = Rectangle.Empty;

			rect_cell.Y = row_rect.Y;
			rect_cell.Height = row_rect.Height;

			if (grid.IsSelected (row)) {
				backcolor =  grid.SelectionBackColor;
				forecolor =  grid.SelectionForeColor;
			} else {
				if (row % 2 == 0) {
					backcolor =  grid.BackColor;
				} else {
					backcolor =  grid.AlternatingBackColor;
				}

				forecolor =  grid.ForeColor;
			}			


			backBrush = ResPool.GetSolidBrush (backcolor);
			foreBrush = ResPool.GetSolidBrush (forecolor);

			// PaintCells at row, column
			int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
			DataGridCell current_cell = grid.CurrentCell;

			if (column_cnt > 0) {
				Region prev_clip = g.Clip;
				Region current_clip;

				for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) {
					if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false)
						continue;

					col_pixel = grid.GetColumnStartingPixel (column);

					rect_cell.X = row_rect.X + col_pixel - grid.HorizPixelOffset;
					rect_cell.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;

					if (clip.IntersectsWith (rect_cell)) {
						current_clip = new Region (rect_cell);
						current_clip.Intersect (row_rect);
						current_clip.Intersect (prev_clip);
						g.Clip = current_clip;

						Brush colBackBrush = backBrush;
						Brush colForeBrush = foreBrush;

						// If we are in the precise cell we are editing, then use the normal colors
						// even if we are selected.
						if (grid.is_editing && column == current_cell.ColumnNumber && row == current_cell.RowNumber) {
							colBackBrush = ResPool.GetSolidBrush (grid.BackColor);
							colForeBrush = ResPool.GetSolidBrush (grid.ForeColor);
						}

						if (is_newrow) {
							grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell, 
														     colBackBrush,
														     colForeBrush);
						} else {
							grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row,
													       colBackBrush,
													       colForeBrush,
													       grid.RightToLeft == RightToLeft.Yes);
						}

						current_clip.Dispose ();
					}
				}

				g.Clip = prev_clip;
			
				if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
					not_usedarea.X = rect_cell.X + rect_cell.Width;
					not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
					not_usedarea.Y = row_rect.Y;
					not_usedarea.Height = row_rect.Height;
				}
			}
			else {
				not_usedarea = row_rect;
			}

			if (!not_usedarea.IsEmpty && clip.IntersectsWith (not_usedarea))
				g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
						 not_usedarea);
		}
Esempio n. 23
0
        // end drawGraph
        private bool DrawItem(Graphics wa, Graph.ILaneRow row)
        {
            if (row == null || row.NodeLane == -1)
            {
                return false;
            }

            // Clip to the area we're drawing in, but draw 1 pixel past so
            // that the top/bottom of the line segment's anti-aliasing isn't
            // visible in the final rendering.
            int top = wa.RenderingOrigin.Y + rowHeight / 2;
            var laneRect = new Rectangle(0, top, Width, rowHeight);
            Region oldClip = wa.Clip;
            var newClip = new Region(laneRect);
            newClip.Intersect(oldClip);
            wa.Clip = newClip;
            wa.Clear(Color.Transparent);

            //for (int r = 0; r < 2; r++)
                for (int lane = 0; lane < row.Count; lane++)
                {
                    int mid = wa.RenderingOrigin.X + (int)((lane + 0.5) * LANE_WIDTH);

                    for (int item = 0; item < row.LaneInfoCount(lane); item++)
                    {
                        Graph.LaneInfo laneInfo = row[lane, item];

                        bool highLight = (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.DrawNonRelativesGray && laneInfo.Junctions.Any(j => j.IsRelative)) ||
                                         (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.HighlightSelected && laneInfo.Junctions.Any(j => j.HighLight)) ||
                                         (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.Normal);

                        List<Color> curColors = GetJunctionColors(laneInfo.Junctions);

                        // Create the brush for drawing the line
                        Brush brushLineColor = null;
                        Pen brushLineColorPen = null;
                        try
                        {
                            bool drawBorder = Settings.BranchBorders && highLight; //hide border for "non-relatives"

                            if (curColors.Count == 1 || !Settings.StripedBranchChange)
                            {
                                if (curColors[0] != nonRelativeColor)
                                {
                                    brushLineColor = new SolidBrush(curColors[0]);
                                }
                                else if (curColors.Count > 1 && curColors[1] != nonRelativeColor)
                                {
                                    brushLineColor = new SolidBrush(curColors[1]);
                                }
                                else
                                {
                                    drawBorder = false;
                                    brushLineColor = new SolidBrush(nonRelativeColor);
                                }
                            }
                            else
                            {
                                Color lastRealColor = curColors.LastOrDefault(c => c != nonRelativeColor);

                                if (lastRealColor.IsEmpty)
                                {
                                    brushLineColor = new SolidBrush(nonRelativeColor);
                                    drawBorder = false;
                                }
                                else
                                {
                                    brushLineColor = new HatchBrush(HatchStyle.DarkDownwardDiagonal, curColors[0], lastRealColor);
                                }
                            }

                            for (int i = drawBorder ? 0 : 2; i < 3; i++)
                            {
                                Pen penLine = null;
                                if (i == 0)
                                {
                                    penLine = whiteBorderPen;
                                }
                                else if (i == 1)
                                {
                                    penLine = blackBorderPen;
                                }
                                else
                                {
                                    if (brushLineColorPen == null)
                                        brushLineColorPen = new Pen(brushLineColor, LANE_LINE_WIDTH);
                                    penLine = brushLineColorPen;
                                }

                                if (laneInfo.ConnectLane == lane)
                                {
                                    wa.DrawLine
                                        (
                                            penLine,
                                            new Point(mid, top - 1),
                                            new Point(mid, top + rowHeight + 2)
                                        );
                                }
                                else
                                {
                                    wa.DrawBezier
                                        (
                                            penLine,
                                            new Point(mid, top - 1),
                                            new Point(mid, top + rowHeight + 2),
                                            new Point(mid + (laneInfo.ConnectLane - lane) * LANE_WIDTH, top - 1),
                                            new Point(mid + (laneInfo.ConnectLane - lane) * LANE_WIDTH, top + rowHeight + 2)
                                        );
                                }
                            }
                        }
                        finally
                        {
                            if (brushLineColorPen != null)
                                ((IDisposable)brushLineColorPen).Dispose();
                            if (brushLineColor != null)
                                ((IDisposable)brushLineColor).Dispose();
                        }
                    }
                }

            // Reset the clip region
            wa.Clip = oldClip;
            {
                // Draw node
                var nodeRect = new Rectangle
                    (
                    wa.RenderingOrigin.X + (LANE_WIDTH - NODE_DIMENSION) / 2 + row.NodeLane * LANE_WIDTH,
                    wa.RenderingOrigin.Y + (rowHeight - NODE_DIMENSION) / 2,
                    NODE_DIMENSION,
                    NODE_DIMENSION
                    );

                Brush nodeBrush;

                List<Color> nodeColors = GetJunctionColors(row.Node.Ancestors);

                bool highlight = (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.DrawNonRelativesGray && row.Node.Ancestors.Any(j => j.IsRelative)) ||
                                 (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.HighlightSelected && row.Node.Ancestors.Any(j => j.HighLight)) ||
                                 (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.Normal);

                bool drawBorder = Settings.BranchBorders && highlight;

                if (nodeColors.Count == 1)
                {
                    nodeBrush = new SolidBrush(highlight ? nodeColors[0] : nonRelativeColor);
                    if (nodeColors[0] == nonRelativeColor) drawBorder = false;
                }
                else
                {
                    nodeBrush = new LinearGradientBrush(nodeRect, nodeColors[0], nodeColors[1],
                                                        LinearGradientMode.Horizontal);
                    if (nodeColors.All(c => c == nonRelativeColor))
                        drawBorder = false;
                }

                if (filterMode == FilterType.Highlight && row.Node.IsFiltered)
                {
                    Rectangle highlightRect = nodeRect;
                    highlightRect.Inflate(2, 3);
                    wa.FillRectangle(Brushes.Yellow, highlightRect);
                    wa.DrawRectangle(Pens.Black, highlightRect);
                }

                if (row.Node.Data == null)
                {
                    wa.FillEllipse(Brushes.White, nodeRect);
                    using (var pen = new Pen(Color.Red, 2))
                    {
                        wa.DrawEllipse(pen, nodeRect);
                    }
                }
                else if (row.Node.IsActive)
                {
                    wa.FillRectangle(nodeBrush, nodeRect);
                    nodeRect.Inflate(1, 1);
                    using (var pen = new Pen(Color.Black, 3))
                        wa.DrawRectangle(pen, nodeRect);
                }
                else if (row.Node.IsSpecial)
                {
                    wa.FillRectangle(nodeBrush, nodeRect);
                    if (drawBorder)
                    {
                        wa.DrawRectangle(Pens.Black, nodeRect);
                    }
                }
                else
                {
                    wa.FillEllipse(nodeBrush, nodeRect);
                    if (drawBorder)
                    {
                        wa.DrawEllipse(Pens.Black, nodeRect);
                    }
                }
            }
            return true;
        }
Esempio n. 24
0
        private void SnippingTool_Paint(object sender, PaintEventArgs e)
        {
            using (Brush b = new SolidBrush(Color.FromArgb(120, Color.White)))
            using (Pen pen = new Pen(Color.Red, 1))
            using (Region region = new Region(new Rectangle(0, 0, Width, Height)))
            {
                // Create a region
                // Negate it from the current sleection
                region.Exclude(rcSelect);
                region.Intersect(e.ClipRectangle);

                // Draw overlay of non-selected portions
                e.Graphics.FillRegion(b, region);

                // Draw selection
                e.Graphics.DrawRectangle(pen, rcSelect.X, rcSelect.Y, rcSelect.Width - 1, rcSelect.Height - 1);
            }
        }
Esempio n. 25
0
        public void SetClip(Region region, CombineMode combineMode)
        {
            // We need to reset the clip that is active now so that the graphic
            // states are correct when we set them.
            ResetClip ();

            switch (combineMode)
            {
            case CombineMode.Replace:
                // Set our clip region by cloning the region that is passed for now
                clipRegion = region.Clone ();
                break;
            case CombineMode.Intersect:

                clipRegion.Intersect (region);

                break;
            case CombineMode.Union:

                clipRegion.Union (region);

                break;
            case CombineMode.Exclude:

                clipRegion.Exclude (region);

                break;
            case CombineMode.Xor:

                clipRegion.Xor (region);

                break;
            default:
                throw new NotImplementedException ("SetClip for CombineMode " + combineMode + " not implemented");
            }

            //Unlike the current path, the current clipping path is part of the graphics state.
            //Therefore, to re-enlarge the paintable area by restoring the clipping path to a
            //prior state, you must save the graphics state before you clip and restore the graphics
            //state after you’ve completed any clipped drawing.
            context.SaveState ();
            if (clipRegion.IsEmpty) {
                context.ClipToRect (CGRect.Empty);
            } else {
                //context.ClipToRect ((RectangleF)clipRegion.regionObject);
                context.AddPath (clipRegion.regionPath);
                context.ClosePath ();
                context.Clip ();
            }
            clipSet++;
        }
Esempio n. 26
0
        private void DrawImageBackground(PageImage pi, StyleInfo si, Graphics g, RectangleF r)
        {
            Stream strm = null;
            System.Drawing.Image im = null;
            try
            {
                strm = new MemoryStream(pi.ImageData);
                im = System.Drawing.Image.FromStream(strm);

                // http://www.fyireporting.com/forum/viewtopic.php?t=892
                //A.S.> convert pt to px if needed(when printing we need px, when draw preview - pt)

                RectangleF r2;
                if (g.PageUnit == GraphicsUnit.Pixel)
                {
                    r2 = new RectangleF(r.Left + (si.PaddingLeft * g.DpiX) / 72,
                    r.Top + (si.PaddingTop * g.DpiX) / 72,
                    r.Width - ((si.PaddingLeft + si.PaddingRight) * g.DpiX) / 72,
                    r.Height - ((si.PaddingTop + si.PaddingBottom) * g.DpiX) / 72);
                }
                else
                {
                    // adjust drawing rectangle based on padding
                    r2 = new RectangleF(r.Left + si.PaddingLeft,
                    r.Top + si.PaddingTop,
                    r.Width - si.PaddingLeft - si.PaddingRight,
                    r.Height - si.PaddingTop - si.PaddingBottom);
                }

                int repeatX = 0;
                int repeatY = 0;
                switch (pi.Repeat)
                {
                    case ImageRepeat.Repeat:
                        repeatX = (int)Math.Floor(r2.Width / pi.SamplesW);
                        repeatY = (int)Math.Floor(r2.Height / pi.SamplesH);
                        break;
                    case ImageRepeat.RepeatX:
                        repeatX = (int)Math.Floor(r2.Width / pi.SamplesW);
                        repeatY = 1;
                        break;
                    case ImageRepeat.RepeatY:
                        repeatY = (int)Math.Floor(r2.Height / pi.SamplesH);
                        repeatX = 1;
                        break;
                    case ImageRepeat.NoRepeat:
                    default:
                        repeatX = repeatY = 1;
                        break;
                }

                //make sure the image is drawn at least 1 times
                repeatX = Math.Max(repeatX, 1);
                repeatY = Math.Max(repeatY, 1);

                float startX = r2.Left;
                float startY = r2.Top;

                Region saveRegion = g.Clip;
                Region clipRegion = new Region(g.Clip.GetRegionData());
                clipRegion.Intersect(r2);
                g.Clip = clipRegion;

                for (int i = 0; i < repeatX; i++)
                {
                    for (int j = 0; j < repeatY; j++)
                    {
                        float currX = startX + i * pi.SamplesW;
                        float currY = startY + j * pi.SamplesH;
                        g.DrawImage(im, new RectangleF(currX, currY, pi.SamplesW, pi.SamplesH));
                    }
                }
                g.Clip = saveRegion;
            }
            finally
            {
                if (strm != null)
                    strm.Close();
                if (im != null)
                    im.Dispose();
            }
        }
Esempio n. 27
0
 protected override void OnPaint(PaintEventArgs e)
 {
     using (Region region = new Region(new Rectangle(0, 0, this.Width, this.Height)))
     {
         region.Exclude(select);
         region.Intersect(e.ClipRectangle);
         e.Graphics.FillRegion(brush, region);
         e.Graphics.DrawRectangle(pen, select.X, select.Y, select.Width - 1, select.Height - 1);
     }
 }
Esempio n. 28
0
        private void CalcWalkableArea()
        {
            if (_battle == null)
            {
                return;
            }

            int width  = _battle.Width / 8;
            int height = _battle.Height / 8;

            Image    image    = new Bitmap(width, height);
            Graphics graphics = Graphics.FromImage(image);

            graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, width, height));

            BTBLib.Region        battleBoundary    = null;
            List <BTBLib.Region> boundaries        = new List <BTBLib.Region>();
            List <BTBLib.Region> inverseBoundaries = new List <BTBLib.Region>();

            foreach (BTBLib.Region region in _battle.Regions)
            {
                if (region.IsClosed)
                {
                    if (region.IsBattleBoundary)
                    {
                        battleBoundary = region;
                    }
                    else if (region.IsBoundaryInversed)
                    {
                        inverseBoundaries.Add(region);
                    }
                    else if (region.IsBoundary)
                    {
                        boundaries.Add(region);
                    }
                }
            }

            if (battleBoundary == null)
            {
                return;
            }

            boundaries.Insert(0, battleBoundary);

            System.Drawing.Region graphicsRegion = new System.Drawing.Region(new Rectangle(0, 0, width, height));

            foreach (BTBLib.Region region in boundaries)
            {
                Point[] points = new Point[region.Lines.Count];
                for (int i = 0; i < points.Length; ++i)
                {
                    var segment = region.Lines[i];
                    points[i] = new Point(segment.StartX / 8, height - segment.StartY / 8);
                }

                GraphicsPath graphicsPath = new GraphicsPath();
                graphicsPath.AddPolygon(points);

                graphicsRegion.Intersect(graphicsPath);
            }

            foreach (BTBLib.Region region in inverseBoundaries)
            {
                Point[] points = new Point[region.Lines.Count];
                for (int i = 0; i < points.Length; ++i)
                {
                    var segment = region.Lines[i];
                    points[i] = new Point(segment.StartX / 8, height - segment.StartY / 8);
                }

                GraphicsPath graphicsPath = new GraphicsPath();
                graphicsPath.AddPolygon(points);

                graphicsRegion.Exclude(graphicsPath);
            }

            graphics.FillRegion(new SolidBrush(Color.Red), graphicsRegion);

            //Form form = new Form();
            //form.ClientSize = new Size(width * 3, height * 3);
            //PictureBox pictureBox = new PictureBox();
            //pictureBox.Image = image;
            //pictureBox.SizeMode = PictureBoxSizeMode.Zoom;
            //form.Controls.Add(pictureBox);
            //pictureBox.Dock = DockStyle.Fill;
            //form.Show();

            ImageForm form = new ImageForm();

            form.SetImage(image);
            form.ShowDialog();
        }
Esempio n. 29
0
        private void DrawTabFocusIndicator(GraphicsPath tabpath, int index, Graphics graphics)
        {
            if (this._FocusTrack && this._TabControl.Focused && index == this._TabControl.SelectedIndex)
            {
                Brush focusBrush = null;
                RectangleF pathRect = tabpath.GetBounds();
                Rectangle focusRect = Rectangle.Empty;
                switch (this._TabControl.Alignment)
                {
                    case TabAlignment.Top:
                        focusRect = new Rectangle((int)pathRect.X, (int)pathRect.Y, (int)pathRect.Width, 4);
                        focusBrush = new LinearGradientBrush(focusRect, this._FocusColor, SystemColors.Window, LinearGradientMode.Vertical);
                        break;
                    case TabAlignment.Bottom:
                        focusRect = new Rectangle((int)pathRect.X, (int)pathRect.Bottom - 4, (int)pathRect.Width, 4);
                        focusBrush = new LinearGradientBrush(focusRect, SystemColors.ControlLight, this._FocusColor, LinearGradientMode.Vertical);
                        break;
                    case TabAlignment.Left:
                        focusRect = new Rectangle((int)pathRect.X, (int)pathRect.Y, 4, (int)pathRect.Height);
                        focusBrush = new LinearGradientBrush(focusRect, this._FocusColor, SystemColors.ControlLight, LinearGradientMode.Horizontal);
                        break;
                    case TabAlignment.Right:
                        focusRect = new Rectangle((int)pathRect.Right - 4, (int)pathRect.Y, 4, (int)pathRect.Height);
                        focusBrush = new LinearGradientBrush(focusRect, SystemColors.ControlLight, this._FocusColor, LinearGradientMode.Horizontal);
                        break;
                }

                //	Ensure the focus stip does not go outside the tab
                Region focusRegion = new Region(focusRect);
                focusRegion.Intersect(tabpath);
                graphics.FillRegion(focusBrush, focusRegion);
                focusRegion.Dispose();
                focusBrush.Dispose();
            }
        }
Esempio n. 30
0
        /// <summary>
        /// The draw tab focus indicator.
        /// </summary>
        /// <param name="brush">
        /// The brush.
        /// </param>
        /// <param name="tabpath">
        /// The tabpath.
        /// </param>
        /// <param name="index">
        /// The index.
        /// </param>
        /// <param name="graphics">
        /// The graphics.
        /// </param>
        private void DrawTabFocusIndicator(Brush brush, GraphicsPath tabpath, int index, Graphics graphics)
        {
            if (this.Focused && index == this.SelectedIndex)
            {
                RectangleF pathRect = tabpath.GetBounds();
                Rectangle focusRect = Rectangle.Empty;
                switch (this.Alignment)
                {
                    case TabAlignment.Top:
                        focusRect = new Rectangle((int)pathRect.X, (int)pathRect.Y, (int)pathRect.Width, this.IndicatorWidth);
                        break;
                    case TabAlignment.Bottom:
                        focusRect = new Rectangle(
                            (int)pathRect.X,
                            (int)pathRect.Bottom - this.IndicatorWidth,
                            (int)pathRect.Width,
                            this.IndicatorWidth);
                        break;
                    case TabAlignment.Left:
                        focusRect = new Rectangle((int)pathRect.X, (int)pathRect.Y, this.IndicatorWidth, (int)pathRect.Height);
                        break;
                    case TabAlignment.Right:
                        focusRect = new Rectangle(
                            (int)pathRect.Right - this.IndicatorWidth,
                            (int)pathRect.Y,
                            this.IndicatorWidth,
                            (int)pathRect.Height);
                        break;
                }

                // 	Ensure the focus stip does not go outside the tab
                using (var focusRegion = new Region(focusRect))
                {
                    focusRegion.Intersect(tabpath);
                    graphics.FillRegion(brush, focusRegion);
                }
            }
        }
      public override void OnPaint(object sender, RibbonElementPaintEventArgs e)
      {
         Owner.Renderer.OnRenderRibbonItem(new RibbonItemRenderEventArgs(Owner, e.Graphics, e.Clip, this));

         if (e.Mode != RibbonElementSizeMode.Compact)
         {
            Region lastClip = e.Graphics.Clip;
            Region newClip = new Region(lastClip.GetBounds(e.Graphics));
            newClip.Intersect(ContentBounds);
            e.Graphics.SetClip(newClip.GetBounds(e.Graphics));

            foreach (RibbonButton button in Buttons)
            {
               if (!button.Bounds.IsEmpty)
                  button.OnPaint(this, new RibbonElementPaintEventArgs(button.Bounds, e.Graphics, ButtonsSizeMode));
            }
            e.Graphics.SetClip(lastClip.GetBounds(e.Graphics));
         }
      }
Esempio n. 32
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Paints the current <see cref="T:System.Windows.Forms.DataGridViewCell"></see>.
		/// </summary>
		/// <param name="graphics">The <see cref="T:System.Drawing.Graphics"></see> used to
		/// paint the <see cref="T:System.Windows.Forms.DataGridViewCell"></see>.</param>
		/// <param name="clipBounds">A <see cref="T:System.Drawing.Rectangle"></see> that
		/// represents the area of the <see cref="T:System.Windows.Forms.DataGridView"></see>
		/// that needs to be repainted.</param>
		/// <param name="cellBounds">A <see cref="T:System.Drawing.Rectangle"></see> that
		/// contains the bounds of the <see cref="T:System.Windows.Forms.DataGridViewCell"></see>
		/// that is being painted.</param>
		/// <param name="rowIndex">The row index of the cell that is being painted.</param>
		/// <param name="cellState">A bitwise combination of
		/// <see cref="T:System.Windows.Forms.DataGridViewElementStates"></see> values that
		/// specifies the state of the cell.</param>
		/// <param name="value">The data of the <see cref="T:System.Windows.Forms.DataGridViewCell">
		/// </see> that is being painted.</param>
		/// <param name="formattedValue">The formatted data of the
		/// <see cref="T:System.Windows.Forms.DataGridViewCell"></see> that is being painted.
		/// </param>
		/// <param name="errorText">An error message that is associated with the cell.</param>
		/// <param name="cellStyle">A <see cref="T:System.Windows.Forms.DataGridViewCellStyle">
		/// </see> that contains formatting and style information about the cell.</param>
		/// <param name="advancedBorderStyle">A
		/// <see cref="T:System.Windows.Forms.DataGridViewAdvancedBorderStyle"></see> that
		/// contains border styles for the cell that is being painted.</param>
		/// <param name="paintParts">A bitwise combination of the
		/// <see cref="T:System.Windows.Forms.DataGridViewPaintParts"></see> values that
		/// specifies which parts of the cell need to be painted.</param>
		/// ------------------------------------------------------------------------------------
		protected override void Paint(Graphics graphics, Rectangle clipBounds,
			Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
			object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle,
			DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
		{
			if (!m_fAllowPaint)
				return;

			// Clear the background
			Region background = new Region(cellBounds);
			background.Xor(GetCellContentDisplayRectangle(advancedBorderStyle));
			background.Intersect(clipBounds);
			graphics.FillRegion(SystemBrushes.Window, background);

			// Invalidate the view so that it redraws
			if (m_Control != null)
			{
				Point pt = m_Control.PointToClient(DataGridView.PointToScreen(new Point(clipBounds.X, clipBounds.Y)));
				Rectangle borderRect = BorderWidths(advancedBorderStyle);
				Rectangle toDraw = new Rectangle(0, 0,
					cellBounds.Width, cellBounds.Height);
				Rectangle clientClip = new Rectangle(pt.X, pt.Y, clipBounds.Width, clipBounds.Height);
				toDraw.Intersect(clientClip);
				m_Control.Invalidate(toDraw, true);
				m_Control.Update();
			}

			// Finally draw the borders
			if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border)
				PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
		}
Esempio n. 33
0
        private void DrawImageSized(PageImage pi, Image im, Graphics g, RectangleF r)
        {
            float height, width;		// some work variables
            StyleInfo si = pi.SI;

            // adjust drawing rectangle based on padding

            // http://www.fyireporting.com/forum/viewtopic.php?t=892
            //A.S.> convert pt to px if needed(when printing we need px, when draw preview - pt)

            RectangleF r2;
            if (g.PageUnit == GraphicsUnit.Pixel)
            {
                r2 = new RectangleF(r.Left + (si.PaddingLeft * g.DpiX) / 72,
                r.Top + (si.PaddingTop * g.DpiX) / 72,
                r.Width - ((si.PaddingLeft + si.PaddingRight) * g.DpiX) / 72,
                r.Height - ((si.PaddingTop + si.PaddingBottom) * g.DpiX) / 72);
            }
            else
            {
                // adjust drawing rectangle based on padding
                r2 = new RectangleF(r.Left + si.PaddingLeft,
                r.Top + si.PaddingTop,
                r.Width - si.PaddingLeft - si.PaddingRight,
                r.Height - si.PaddingTop - si.PaddingBottom);
            }

            Rectangle ir;	// int work rectangle
            ir = new Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                               Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height));
            switch (pi.Sizing)
            {
                case ImageSizingEnum.AutoSize:
                    // Note: GDI+ will stretch an image when you only provide
                    //  the left/top coordinates.  This seems pretty stupid since
                    //  it results in the image being out of focus even though
                    //  you don't want the image resized.
                    if (g.DpiX == im.HorizontalResolution &&
                        g.DpiY == im.VerticalResolution)
                    {
                        ir = new Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                                                        im.Width, im.Height);
                    }
                    g.DrawImage(im, ir);

                    break;
                case ImageSizingEnum.Clip:
                    Region saveRegion = g.Clip;
                    Region clipRegion = new Region(g.Clip.GetRegionData());
                    clipRegion.Intersect(r2);
                    g.Clip = clipRegion;
                    if (g.DpiX == im.HorizontalResolution &&
                        g.DpiY == im.VerticalResolution)
                    {
                        ir = new Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                                                        im.Width, im.Height);
                    }
                    g.DrawImage(im, ir);
                    g.Clip = saveRegion;
                    break;
                case ImageSizingEnum.FitProportional:
                    float ratioIm = (float)im.Height / (float)im.Width;
                    float ratioR = r2.Height / r2.Width;
                    height = r2.Height;
                    width = r2.Width;
                    if (ratioIm > ratioR)
                    {	// this means the rectangle width must be corrected
                        width = height * (1 / ratioIm);
                    }
                    else if (ratioIm < ratioR)
                    {	// this means the ractangle height must be corrected
                        height = width * ratioIm;
                    }
                    r2 = new RectangleF(r2.X, r2.Y, width, height);
                    g.DrawImage(im, r2);
                    break;
                case ImageSizingEnum.Fit:
                default:
                    g.DrawImage(im, r2);
                    break;
            }

            if (SelectTool && pi.AllowSelect && _SelectList.Contains(pi))
            {
                g.FillRectangle(new SolidBrush(Color.FromArgb(50, _SelectItemColor)), ir);
            }

            return;
        }
Esempio n. 34
0
		internal override PaintEventArgs PaintEventStart(ref Message msg, IntPtr handle, bool client)
		{
			PaintEventArgs	paint_event;
			Hwnd		hwnd;
			Hwnd		paint_hwnd;
			
			// 
			// handle  (and paint_hwnd) refers to the window that is should be painted.
			// msg.HWnd (and hwnd) refers to the window that got the paint message.
			// 
			
			hwnd = Hwnd.ObjectFromHandle(msg.HWnd);
			if (msg.HWnd == handle) {
				paint_hwnd = hwnd;
			} else {
				paint_hwnd = Hwnd.ObjectFromHandle (handle);
			}
	
			if (Caret.Visible == true) {
				Caret.Paused = true;
				HideCaret();
			}

			Graphics dc;

			if (client) {
				dc = Graphics.FromHwnd (paint_hwnd.client_window);

				Region clip_region = new Region ();
				clip_region.MakeEmpty();

				foreach (Rectangle r in hwnd.ClipRectangles) {
					/* Expand the region slightly.
					 * See bug 464464.
					 */
					Rectangle r2 = Rectangle.FromLTRB (r.Left, r.Top, r.Right, r.Bottom + 1);
					clip_region.Union (r2);
				}

				if (hwnd.UserClip != null) {
					clip_region.Intersect(hwnd.UserClip);
				}

				dc.Clip = clip_region;
				paint_event = new PaintEventArgs(dc, hwnd.Invalid);
				hwnd.expose_pending = false;

				hwnd.ClearInvalidArea();

				hwnd.drawing_stack.Push (paint_event);
				hwnd.drawing_stack.Push (dc);

				return paint_event;
			} else {
				dc = Graphics.FromHwnd (paint_hwnd.whole_window);

				if (!hwnd.nc_invalid.IsEmpty) {
					dc.SetClip (hwnd.nc_invalid);
					paint_event = new PaintEventArgs(dc, hwnd.nc_invalid);
				} else {
					paint_event = new PaintEventArgs(dc, new Rectangle(0, 0, hwnd.width, hwnd.height));
				}
				hwnd.nc_expose_pending = false;

				hwnd.ClearNcInvalidArea ();

				hwnd.drawing_stack.Push (paint_event);
				hwnd.drawing_stack.Push (dc);

				return paint_event;
			}
		}