Пример #1
0
		public void ctor_GraphicsPath () {
			GraphicsPath path = new GraphicsPath ();
			path.AddRectangle (rect);
			Region r1 = new Region (path);
			r1.Xor (r);
			Assert.IsTrue (r1.IsEmpty (t.Graphics));
		}
Пример #2
0
		// a region with an "empty ctor" graphic path is "empty" (i.e. not infinite)
		private void CheckEmpty (string prefix, Region region)
		{
			Assert.IsTrue (region.IsEmpty (graphic), prefix + "IsEmpty");
			Assert.IsFalse (region.IsInfinite (graphic), prefix + "graphic");

			RectangleF rect = region.GetBounds (graphic);
			Assert.AreEqual (0f, rect.X, prefix + "GetBounds.X");
			Assert.AreEqual (0f, rect.Y, prefix + "GetBounds.Y");
			Assert.AreEqual (0f, rect.Width, prefix + "GetBounds.Width");
			Assert.AreEqual (0f, rect.Height, prefix + "GetBounds.Height");
		}
Пример #3
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");
		}
Пример #4
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");
		}
        protected override void OnPaint(PaintEventArgs e)
        {
            DateTime startDate = DateTime.Today;
            DateTime endDate = DateTime.Today.AddDays(1);

            Region clippingRegion = e.Graphics.Clip;

            foreach (GuideProgramCell cell in _guideProgramCells)
            {
                Rectangle visibleRectangle = new Rectangle(cell.Rectangle.Location, cell.Rectangle.Size);
                visibleRectangle.Intersect(e.ClipRectangle);

                Region cellRegion = new Region(visibleRectangle);
                cellRegion.Intersect(clippingRegion);
                if (cellRegion.IsEmpty(e.Graphics))
                {
                    continue;
                }

                bool clipLeft = (visibleRectangle.Left != cell.Rectangle.Left) || cell.ClipLeft;
                bool clipRight = (visibleRectangle.Right != cell.Rectangle.Right) || cell.ClipRight;
                Padding innerPadding = new Padding(2, 2, 2, 2);

                bool onNow = false;
                if (_cursorAtTime.HasValue)
                {
                    DateTime cursorTime = DateTime.Today.Add(_cursorAtTime.Value);
                    onNow = (cell.StartTime <= cursorTime) && (cell.StopTime > cursorTime);
                }
                bool isRecording = IsRecording(cell);

                e.Graphics.SetClip(visibleRectangle);
                if (cell.GuideProgram == null)
                {
                    e.Graphics.FillRectangle(_unusedAreaBrush, visibleRectangle);
                }
                else if (!cell.IsBroadcasted)
                {
                    e.Graphics.FillRectangle(_channelNotBroadcastedCellBrush, visibleRectangle);
                }
                else if (cell == _highlightedCell)
                {
                    e.Graphics.FillRectangle(isRecording ? _highlightRecordingCellBrush : (onNow ? _highlightOnNowCellBrush : _highlightCellBrush), visibleRectangle);
                }
                else if (isRecording)
                {
                    e.Graphics.FillRectangle(_recordingCellBrush, visibleRectangle);
                }
                else if (onNow)
                {
                    e.Graphics.FillRectangle(_onNowCellBrush, visibleRectangle);
                }
                if (cell.IsTop)
                {
                    e.Graphics.DrawLine(_epgBorderPen, visibleRectangle.Left, cell.Rectangle.Top, visibleRectangle.Right - 1, cell.Rectangle.Top);
                    innerPadding.Top++;
                }
                if (clipLeft)
                {
                    e.Graphics.DrawLine(_epgDashedBorderPen, visibleRectangle.Left, cell.Rectangle.Top, visibleRectangle.Left, cell.Rectangle.Bottom - 1);
                    innerPadding.Left++;
                }
                else if (cell.Rectangle.Left == 0)
                {
                    e.Graphics.DrawLine(_epgBorderPen, visibleRectangle.Left, cell.Rectangle.Top, visibleRectangle.Left, cell.Rectangle.Bottom - 1);
                    innerPadding.Left++;
                }
                Pen rightBorderPen = _epgBorderPen;
                if (clipRight)
                {
                    rightBorderPen = _epgDashedBorderPen;
                }
                e.Graphics.DrawLine(_epgBorderPen, visibleRectangle.Right - 1, cell.Rectangle.Bottom - 1, visibleRectangle.Left, cell.Rectangle.Bottom - 1);
                e.Graphics.DrawLine(rightBorderPen, visibleRectangle.Right - 1, cell.Rectangle.Top, visibleRectangle.Right - 1, cell.Rectangle.Bottom - 1);

                int innerWidth = visibleRectangle.Width - innerPadding.Horizontal;
                int innerHeight = cell.Rectangle.Height - innerPadding.Vertical;
                if (cell.GuideProgram != null
                    && innerWidth > 0
                    && innerHeight > 0)
                {
                    Rectangle innerRectangle = new Rectangle(visibleRectangle.Left + innerPadding.Left, cell.Rectangle.Top + innerPadding.Top, innerWidth, innerHeight);
                    e.Graphics.SetClip(innerRectangle);

                    TimeSpan time = cell.GuideProgram.StartTime.TimeOfDay;
                    TimeSpan endTime = cell.GuideProgram.StopTime.TimeOfDay;
                    string timeText = EpgTimeControl.GetTimeString(time);
                    string endTimeText = EpgTimeControl.GetTimeString(endTime);
                    string timeLabelText = timeText;
                    if (clipLeft)
                    {
                        timeLabelText = "<" + timeText;
                    }
                    if (clipRight)
                    {
                        timeLabelText = timeText + "-" + endTimeText;
                    }

                    e.Graphics.DrawString(timeLabelText, _timeFont, _timeBrush, innerRectangle.Left, innerRectangle.Top);

                    float titleTop = innerRectangle.Top + _timeFont.GetHeight();
                    int titleLeft = innerRectangle.Left;

                    bool hasIcons = DrawScheduleIcon(cell, e, titleTop, ref titleLeft, _model.UpcomingRecordingsById);
                    hasIcons = DrawScheduleIcon(cell, e, titleTop, ref titleLeft, _model.UpcomingAlertsById) || hasIcons;
                    hasIcons = DrawScheduleIcon(cell, e, titleTop, ref titleLeft, _model.UpcomingSuggestionsById) || hasIcons;

                    int titleWidth = innerRectangle.Width - (titleLeft - innerRectangle.Left);

                    bool isHighlighted = (cell == _highlightedCell);
                    string title = cell.GuideProgram.Title;
                    Font titleFont = isHighlighted ? _titleHighlightFont : _titleFont;
                    Brush titleBrush = isHighlighted ? _titleHighlightBrush : _titleBrush;

                    int charsFitted;
                    int linesFilled;
                    SizeF titleSize = e.Graphics.MeasureString(title, titleFont,
                        new SizeF(titleWidth, titleFont.Height), StringFormat.GenericDefault, out charsFitted, out linesFilled);
                    if (charsFitted < title.Length)
                    {
                        while (charsFitted > 0
                            && title[charsFitted] != ' ')
                        {
                            charsFitted--;
                        }
                        if (charsFitted == 0)
                        {
                            while (charsFitted < title.Length
                                && title[charsFitted] != ' ')
                            {
                                charsFitted++;
                            }
                        }
                    }
                    if (charsFitted > 0)
                    {
                        e.Graphics.DrawString(title.Substring(0, charsFitted), titleFont, titleBrush,
                            new RectangleF(titleLeft, titleTop, titleWidth, titleFont.Height));
                        titleTop += titleFont.GetHeight();
                        if (charsFitted == title.Length)
                        {
                            title = String.Empty;
                        }
                        else
                        {
                            title = title.Substring(charsFitted).TrimStart();
                        }
                    }
                    if (hasIcons)
                    {
                        titleTop++;
                    }
                    if (!String.IsNullOrEmpty(title))
                    {
                        titleSize = e.Graphics.MeasureString(title, titleFont, innerRectangle.Width);
                        e.Graphics.DrawString(title, titleFont, titleBrush, new RectangleF(innerRectangle.Left, titleTop, titleSize.Width, titleSize.Height));
                        titleTop += titleSize.Height;
                    }
                    if (titleTop < innerRectangle.Bottom)
                    {
                        e.Graphics.DrawString(cell.GuideProgram.CreateEpisodeTitle(), _episodeFont, _episodeBrush,
                            new RectangleF(innerRectangle.Left, titleTop, innerRectangle.Width, innerRectangle.Height));
                    }
                }
            }

            if (this.CursorAtTime.HasValue)
            {
                int position = EpgTimeControl.GetTimeCursorPosition(_cursorAtTime.Value, -1);
                Rectangle timeRectangle = new Rectangle(position, 0, 2, this.Height);
                e.Graphics.SetClip(timeRectangle);
                timeRectangle.Intersect(e.ClipRectangle);

                Region cellRegion = new Region(timeRectangle);
                cellRegion.Intersect(clippingRegion);
                if (!cellRegion.IsEmpty(e.Graphics))
                {
                    e.Graphics.DrawLine(_cursorPen, timeRectangle.Left, timeRectangle.Top, timeRectangle.Left, timeRectangle.Bottom - 1);
                    e.Graphics.DrawLine(_cursorShadowPen, timeRectangle.Left + 1, timeRectangle.Top, timeRectangle.Left + 1, timeRectangle.Bottom - 1);
                }
            }

            base.OnPaint(e);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            Region clippingRegion = e.Graphics.Clip;

            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
            {
                foreach (var cell in _channelCells)
                {
                    Rectangle visibleRectangle = new Rectangle(cell.Rectangle.Location, cell.Rectangle.Size);
                    visibleRectangle.Intersect(e.ClipRectangle);

                    Region cellRegion = new Region(visibleRectangle);
                    cellRegion.Intersect(clippingRegion);
                    if (cellRegion.IsEmpty(e.Graphics))
                    {
                        continue;
                    }

                    e.Graphics.SetClip(visibleRectangle);

                    Padding innerPadding = new Padding(2, 2, 2, 2);

                    if (cell.Channel != null)
                    {
                        Rectangle innerRectangle = new Rectangle(cell.Rectangle.Left + innerPadding.Left, cell.Rectangle.Top + innerPadding.Top,
                            cell.Rectangle.Width - innerPadding.Horizontal, cell.Rectangle.Height - innerPadding.Vertical);

                        Image logoImage = null;
                        try
                        {
                            logoImage = ChannelLogosCache.GetLogoImage(tvSchedulerAgent, cell.Channel, (int)(64 * _widthFactor), (int)(64 * _heightFactor));
                        }
                        catch
                        {
                            logoImage = null;
                        }

                        if (logoImage == null)
                        {
                            e.Graphics.DrawString(cell.Channel.DisplayName, _channelFont, _channelBrush,
                                new RectangleF(innerRectangle.Left, innerRectangle.Top + 6, innerRectangle.Width, innerRectangle.Height));
                        }
                        else
                        {
                            e.Graphics.DrawImage(logoImage, innerRectangle.Left + (int)Math.Round((innerRectangle.Width - logoImage.Width) / 2F),
                                innerRectangle.Top + (int)Math.Round((innerRectangle.Height - logoImage.Height) / 2F),
                                logoImage.Width, logoImage.Height);
                        }
                    }
                }
            }
            base.OnPaint(e);
        }
Пример #7
0
		public virtual void Draw (Graphics dc, Rectangle clip_rectangle, LinkLabel label)
		{
			Rectangle client_rect = label.PaddingClientRectangle;

			label.DrawImage (dc, label.Image, client_rect, label.ImageAlign);

			if (label.pieces == null)
				return;

			// Paint all text as disabled.
			if (!label.Enabled) {
				dc.SetClip (clip_rectangle);
				ThemeEngine.Current.CPDrawStringDisabled (
					dc, label.Text, label.Font, label.BackColor, client_rect, label.string_format);
				return;
			}

			Font font, link_font = ThemeEngine.Current.GetLinkFont (label);
			
			Region text_region = new Region (new Rectangle());

			// Draw links.
			for (int i = 0; i < label.pieces.Length; i ++) {
				LinkLabel.Piece piece = label.pieces[i];
				
				if (piece.link == null) {
					text_region.Union (piece.region);
					continue;
				}

				Color color = GetPieceColor (label, piece, i);

				if ( (label.LinkBehavior == LinkBehavior.AlwaysUnderline) || 
					 (label.LinkBehavior == LinkBehavior.SystemDefault) ||
					 ((label.LinkBehavior == LinkBehavior.HoverUnderline) && piece.link.Hovered) )
					font = link_font;
				else
					font = label.Font;
				
				dc.Clip = piece.region;
				dc.Clip.Intersect (clip_rectangle);
				dc.DrawString (label.Text, font, 
						ThemeEngine.Current.ResPool.GetSolidBrush (color), 
						client_rect, label.string_format);
			
				// Draw focus rectangle
				if ((piece.link != null) && piece.link.Focused) {
					foreach (RectangleF rect in piece.region.GetRegionScans (dc.Transform))
						ControlPaint.DrawFocusRectangle (dc, Rectangle.Round (rect), label.ForeColor, label.BackColor);
				}
			}
			
			// Draw normal text (without links).
			if (!text_region.IsEmpty (dc)) {
				dc.Clip = text_region;
				dc.Clip.Intersect (clip_rectangle);
				if (!dc.Clip.IsEmpty (dc))
					dc.DrawString(label.Text, label.Font, 
						ThemeEngine.Current.ResPool.GetSolidBrush(label.ForeColor),
						client_rect, label.string_format);
			}
		}
Пример #8
0
        internal void UpatePath(Graphics g)
        {
            if ((base.pretime != base.OwnerDocument.ControlTime) || (base.graphPath == null)||(base.IsChanged))
            {
                PointF[] tfArray3;
                if (base.graphPath == null)
                {
                    base.graphPath = new GraphicsPath();
                }
                base.graphPath.Reset();
                PointF tf1 = new PointF(this.X1, this.Y1);
                PointF tf2 = new PointF(this.X2, this.Y2);
                using (Matrix matrix1 = new Matrix())
                {
                    using (Matrix matrix2 = new Matrix())
                    {
                        bool flag1 = false;
                        bool flag2 = false;
                        if (this.StartGraph != null)
                        {
                            flag1 = true;
                            matrix1.Multiply(this.startGraph.Transform.Matrix);
                            RectangleF ef1 = this.GetBounds(this.startGraph, matrix1);
                            PointF tf3 = new PointF(ef1.X + (ef1.Width / 2f), ef1.Y + (ef1.Height / 2f));
                            PointF[] tfArray1 = (this.startGraph as IGraph).ConnectPoints.Clone() as PointF[];
                            if ((this.startGraphPointIndex >= 0) && (this.startGraphPointIndex < tfArray1.Length))
                            {
                                flag1 = false;
                                using (Matrix matrix3 = this.startGraph.Transform.Matrix.Clone())
                                {
                                    matrix3.TransformPoints(tfArray1);
                                    tf3 = tfArray1[this.startGraphPointIndex];
                                }
                                using (Matrix matrix5 = this.Transform.Matrix.Clone())
                                {
                                    matrix5.Invert();
                                    PointF[] tfArray5=new PointF[]{tf3};
                                    matrix5.TransformPoints(tfArray5);
                                    tf3=tfArray5[0];
                                }
                            }
                            tf1 = tf3;
                        }
                        if (this.EndGraph != null)
                        {
                            flag2 = true;
                            matrix2.Multiply(this.endGraph.Transform.Matrix);
                            RectangleF ef2 = this.GetBounds(this.endGraph, matrix2);
                            PointF tf4 = new PointF(ef2.X + (ef2.Width / 2f), ef2.Y + (ef2.Height / 2f));
                            PointF[] tfArray2 =(this.endGraph as IGraph).ConnectPoints.Clone() as PointF[];
                            if ((this.endGraphPointIndex >= 0) && (this.endGraphPointIndex < tfArray2.Length))
                            {
                                flag2 = false;
                                using (Matrix matrix4 = this.endGraph.Transform.Matrix.Clone())
                                {
                                    matrix4.TransformPoints(tfArray2);
                                    tf4 = tfArray2[this.endGraphPointIndex];
                                }
                                using (Matrix matrix5 = this.Transform.Matrix.Clone())
                                {
                                    matrix5.Invert();
                                    PointF[] tfArray5=new PointF[]{tf4};
                                    matrix5.TransformPoints(tfArray5);
                                    tf4=tfArray5[0];
                                }
                            }

                            tf2 = tf4;

                        }
                        if ((flag1 || flag2) && (this.startGraph != this.endGraph))
                        {
                            PointF tf5 = tf1;
                            PointF tf6 = tf2;
                            using (GraphicsPath path1 = new GraphicsPath())
                            {
                                path1.AddLine(tf1, tf2);
                                path1.Widen(new Pen(Color.White, 0.1f));
                                if (flag1)
                                {
                                    using (Region region1 = new Region(this.startGraph.GPath))
                                    {
                                        region1.Transform(matrix1);
                                        region1.Intersect(path1);
                                        if (!region1.IsEmpty(g))
                                        {
                                            tf5 = this.Intersect(region1.GetBounds(g), tf5);
                                            using (Matrix matrix5 = this.Transform.Matrix.Clone())
                                            {
                                                matrix5.Invert();
                                                PointF[] tfArray5=new PointF[]{tf5};
                                                matrix5.TransformPoints(tfArray5);
                                                tf5=tfArray5[0];
                                            }
                                        }
                                    }
                                }
                                if (flag2)
                                {
                                    using (Region region2 = new Region(this.endGraph.GPath))
                                    {
                                        region2.Transform(matrix2);
                                        region2.Intersect(path1);
                                        if (!region2.IsEmpty(g))
                                        {
                                            tf6 = this.Intersect(region2.GetBounds(g), tf6);
                                            using (Matrix matrix5 = this.Transform.Matrix.Clone())
                                            {
                                                matrix5.Invert();
                                                PointF[] tfArray5=new PointF[]{tf6};
                                                matrix5.TransformPoints(tfArray5);
                                                tf6=tfArray5[0];
                                            }
                                        }
                                    }
                                }
                                tf1 = tf5;
                                tf2 = tf6;
                            }
                        }
                    }
                }
                bool flag3 = Math.Abs( (tf2.Y - tf1.Y)) > Math.Abs((tf2.X - tf1.X));

                string text1= base.SvgAttributes["type"].ToString().Trim();
                this.type = (Enums.ConnectType)Enum.Parse(typeof(Enums.ConnectType),text1,true);

                switch (this.type)
                {
                    case Enums.ConnectType.Line:
                    {
                        base.graphPath.AddLine(tf1, tf2);
                        break;
                    }
                    case Enums.ConnectType.Polyline:
                    {
                        if (!flag3)
                        {
                            bool flag5 = tf1.X < tf2.X;
                            tfArray3 = new PointF[] { tf1, new PointF(tf1.X + ((flag5 ? 1 : -1) * 30), tf1.Y), new PointF(tf2.X - ((flag5 ? 1 : -1) * 30), tf2.Y), tf2 };
                            base.graphPath.AddLines(tfArray3);
                            break;
                        }
                        bool flag4 = tf1.Y < tf2.Y;
                        tfArray3 = new PointF[] { tf1, new PointF(tf1.X, tf1.Y + ((flag4 ? 1 : -1) * 30)), new PointF(tf2.X, tf2.Y - ((flag4 ? 1 : -1) * 30)), tf2 } ;
                        base.graphPath.AddLines(tfArray3);
                        break;
                    }
                    case Enums.ConnectType.RightAngle:
                    {
                        if (!flag3)
                        {
                            float single2 = (tf1.X + tf2.X) / 2f;
                            tfArray3 = new PointF[] { tf1, new PointF(single2, tf1.Y), new PointF(single2, tf2.Y), tf2 } ;
                            base.graphPath.AddLines(tfArray3);
                            break;
                        }
                        float single1 = (tf1.Y + tf2.Y) / 2f;
                        tfArray3 = new PointF[] { tf1, new PointF(tf1.X, single1), new PointF(tf2.X, single1), tf2 } ;
                        base.graphPath.AddLines(tfArray3);
                        break;
                    }
                    case Enums.ConnectType.Spline:
                    {
                        if (!flag3)
                        {
                            bool flag7 = tf1.X < tf2.X;
                            base.graphPath.AddBezier(tf1, new PointF(tf1.X + ((flag7 ? 1 : -1) * 70), tf1.Y), new PointF(tf2.X - ((flag7 ? 1 : -1) * 70), tf2.Y), tf2);
                            break;
                        }
                        bool flag6 = tf1.Y < tf2.Y;
                        base.graphPath.AddBezier(tf1, new PointF(tf1.X, tf1.Y + ((flag6 ? 1 : -1) * 70)), new PointF(tf2.X, tf2.Y - ((flag6 ? 1 : -1) * 70)), tf2);
                        break;
                    }
                }
                tfArray3 = new PointF[] { tf1, tf2 } ;
                this.linepoints = tfArray3;
            //				IsChanged=false;
                //base.pretime =this.OwnerDocument.ControlTime;
            }
        }
Пример #9
0
		public void GetHrgn_Empty_MakeInfinite ()
		{
			Region r = new Region (new GraphicsPath ());
			Assert.IsTrue (r.IsEmpty (graphic), "Empty");
			Assert.IsFalse (r.IsInfinite (graphic), "!Infinite");
			IntPtr h = r.GetHrgn (graphic);
			Assert.IsFalse (h == IntPtr.Zero, "Handle!=0");

			r.MakeInfinite ();
			Assert.IsFalse (r.IsEmpty (graphic), "!Empty");
			Assert.IsTrue (r.IsInfinite (graphic), "Infinite");
			Assert.AreEqual (IntPtr.Zero, r.GetHrgn (graphic), "Handle==0");
			r.ReleaseHrgn (h);
		}
Пример #10
0
		public void Complement_383878 ()
		{
			using (Region clipRegion = new Region ()) {
				clipRegion.MakeInfinite ();

				Rectangle smaller = new Rectangle (5, 5, -10, -10);
				Rectangle bigger = new Rectangle (-5, -5, 12, 12);

				clipRegion.Intersect (smaller);
				clipRegion.Complement (bigger);

				Assert.IsFalse (clipRegion.IsEmpty (graphic), "IsEmpty");
				Assert.IsFalse (clipRegion.IsInfinite (graphic), "IsInfinite");

				RectangleF [] rects = clipRegion.GetRegionScans (new Matrix ());
				Assert.AreEqual (2, rects.Length, "Length");
				Assert.AreEqual (new RectangleF (5, -5, 2, 10), rects [0], "0");
				Assert.AreEqual (new RectangleF (-5, 5, 12, 2), rects [1], "1");
			}
		}
Пример #11
0
		public void TestInfiniteAndEmpty()
		{
			Bitmap bmp = new Bitmap (600, 800);
			Graphics dc = Graphics.FromImage (bmp);
			Rectangle rect1, rect2;
			Region rgn1;
			RectangleF [] rects;
			Matrix matrix = new Matrix ();

			rect1 = new Rectangle (500, 30, 60, 80);
			rect2 = new Rectangle (520, 40, 60, 80);
			rgn1 = new Region (rect1);
			rgn1.Union (rect2);

			Assert.AreEqual (false, rgn1.IsEmpty (dc));
			Assert.AreEqual (false, rgn1.IsInfinite (dc));

			rgn1.MakeEmpty();
			Assert.AreEqual (true, rgn1.IsEmpty (dc));

			rgn1 = new Region (rect1);
			rgn1.Union (rect2);
			rgn1.MakeInfinite ();
			rects = rgn1.GetRegionScans (matrix);

			Assert.AreEqual (1, rects.Length);
			Assert.AreEqual (-4194304, rects[0].X);
			Assert.AreEqual (-4194304, rects[0].Y);
			Assert.AreEqual (8388608, rects[0].Width);
			Assert.AreEqual (8388608, rects[0].Height);
			Assert.AreEqual (true, rgn1.IsInfinite (dc));
		}
Пример #12
0
		public void GetHrgn_Infinite_MakeEmpty ()
		{
			Region r = new Region ();
			Assert.IsFalse (r.IsEmpty (graphic), "!Empty");
			Assert.IsTrue (r.IsInfinite (graphic), "Infinite");
			Assert.AreEqual (IntPtr.Zero, r.GetHrgn (graphic), "Handle==0");

			r.MakeEmpty ();
			Assert.IsTrue (r.IsEmpty (graphic), "Empty");
			Assert.IsFalse (r.IsInfinite (graphic), "!Infinite");
			IntPtr h = r.GetHrgn (graphic);
			Assert.IsFalse (h == IntPtr.Zero, "Handle!=0");
#if NET_2_0
			r.ReleaseHrgn (h);
#endif
		}
Пример #13
0
        /// <summary>
        /// 判断点是否在graphicspath中,这个已经包含了直线判断和文字判断
        /// </summary>
        /// <param name="arrPointF"></param>
        /// <param name="MousePoint"></param>
        /// <returns></returns>
        public virtual bool isContains(PointF MousePoint)
        {
            //我想用graphicspath来判断这个是否在其中,这样子会精简很多
            //只有一句话了,很精简
            //return getGraphicsPath().IsVisible(MousePoint);

            //首选用路径判断
            GraphicsPath gpath = getGraphicsPath();//取得路径

            if (gpath.IsVisible(MousePoint))
            {
                return true;//返回真就可以了
            }

            //如下还的判断线段
            //GraphicsPath.PathTypes 属性,这个返回的是一个数组
            //值  含义
            // 0  指示此点是图形的起始点。
            // 1  指示此点是线段的两个终结点之一。
            // 3   指示此点是立方贝塞尔样条的终结点或控制点。
            //0x7 对三个低序位(指示点类型)之外的所有位进行掩码。
            //0x20 指定此点是一个标记。
            //0x80 指定此点是闭合子路径(图形)中的最后一点。
            //一个选段总是前面一个0,后边一个1,因为第一个点是图形的起始点

            //取得所有点
            PointF[] pathPointfs = gpath.PathPoints;
            byte[] pathPointType1 = gpath.PathTypes;//获得点的类型

            //线段总是先一个0,再一个1
            for (int i = 0; i < pathPointType1.Length; i++)
            {
                float fltDistance;

                //直线的判定如果这个为1,就判断前一个是否为0
                if ((pathPointType1[i] == 1)//如果这个等于1
                    && (i - 1 >= 0) &&            //并且上一个没有超出边界,实际上这个不太需要
                    (pathPointType1[i - 1] == 0))//并且上一个等于0
                {
                    fltDistance = getPointLineDistance(pathPointfs[i], pathPointfs[i - 1], MousePoint);

                    //如果这个距离小于精度
                    if (fltDistance <= fltJingDu)
                        return true;

                }

                //为了应对string类型的,我决定每个点都判断距离
                fltDistance = getPointDistance(pathPointfs[i], MousePoint);
                //如果这个距离小于精度
                if (fltDistance <= fltJingDu)
                    return true;

            }

            //到这里肯定返回假了
            return false;

            //如下的也没有用,只是为了增加别人破解的难度
            Region region = new Region(getGraphicsPath());
            region.Intersect(new RectangleF(MousePoint, new SizeF(10, 10)));

            Bitmap bitmap = new Bitmap(1000, 1000);
            Graphics g = Graphics.FromImage(bitmap);
            g.PageUnit = GraphicsUnit.Millimeter;

            return !region.IsEmpty(g);

            //如下的没有作用,只是为了增加别人破解。
            int intResult = PtInPolygon(MousePoint, getRealPoint());

            if (intResult == -1)
                return false;

            return true;

            /**
            System.Drawing.Drawing2D.GraphicsPath   myGraphicsPath=new System.Drawing.Drawing2D.GraphicsPath();
            Region myRegion=new Region();
            myGraphicsPath.Reset();

            myGraphicsPath.AddPolygon(getRealPoint() );
            myRegion.MakeEmpty();
            myRegion.Union(myGraphicsPath);
            //返回判断点是否在多边形里
            return  myRegion.IsVisible(MousePoint);
             * */
        }
Пример #14
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);
        }
 private Region DetermineRegionToRefresh(object primarySelection)
 {
     Rectangle[] curSelectionBounds;
     Rectangle[] prevSelectionBounds;
     Region region = new Region(Rectangle.Empty);
     if (this.curSelectionBounds.Length >= this.prevSelectionBounds.Length)
     {
         curSelectionBounds = this.curSelectionBounds;
         prevSelectionBounds = this.prevSelectionBounds;
     }
     else
     {
         curSelectionBounds = this.prevSelectionBounds;
         prevSelectionBounds = this.curSelectionBounds;
     }
     bool[] flagArray = new bool[prevSelectionBounds.Length];
     for (int i = 0; i < prevSelectionBounds.Length; i++)
     {
         flagArray[i] = false;
     }
     for (int j = 0; j < curSelectionBounds.Length; j++)
     {
         bool flag = false;
         Rectangle rect = curSelectionBounds[j];
         for (int m = 0; m < prevSelectionBounds.Length; m++)
         {
             if (rect.IntersectsWith(prevSelectionBounds[m]))
             {
                 Rectangle rectangle2 = prevSelectionBounds[m];
                 flag = true;
                 if (rect != rectangle2)
                 {
                     region.Union(rect);
                     region.Union(rectangle2);
                 }
                 flagArray[m] = true;
                 break;
             }
         }
         if (!flag)
         {
             region.Union(rect);
         }
     }
     for (int k = 0; k < flagArray.Length; k++)
     {
         if (!flagArray[k])
         {
             region.Union(prevSelectionBounds[k]);
         }
     }
     using (Graphics graphics = this.behaviorService.AdornerWindowGraphics)
     {
         if ((!region.IsEmpty(graphics) || (primarySelection == null)) || primarySelection.Equals(this.prevPrimarySelection))
         {
             return region;
         }
         for (int n = 0; n < this.curSelectionBounds.Length; n++)
         {
             region.Union(this.curSelectionBounds[n]);
         }
     }
     return region;
 }
Пример #16
0
		/// <summary>
		/// This method will use User32 code to capture the specified captureBounds from the screen
		/// </summary>
		/// <param name="captureBounds">Rectangle with the bounds to capture</param>
		/// <returns>Bitmap which is captured from the screen at the location specified by the captureBounds</returns>
		public static Bitmap CaptureRectangle(Rectangle captureBounds) {
			Bitmap returnBitmap = null;
			if (captureBounds.Height <= 0 || captureBounds.Width <= 0) {
				LOG.Warn("Nothing to capture, ignoring!");
				return null;
			}
			LOG.Debug("CaptureRectangle Called!");

			// .NET GDI+ Solution, according to some post this has a GDI+ leak...
			// See http://connect.microsoft.com/VisualStudio/feedback/details/344752/gdi-object-leak-when-calling-graphics-copyfromscreen
			// Bitmap capturedBitmap = new Bitmap(captureBounds.Width, captureBounds.Height);
			// using (Graphics graphics = Graphics.FromImage(capturedBitmap)) {
			//	graphics.CopyFromScreen(captureBounds.Location, Point.Empty, captureBounds.Size, CopyPixelOperation.CaptureBlt);
			// }
			// capture.Image = capturedBitmap;
			// capture.Location = captureBounds.Location;

			using (SafeWindowDCHandle desktopDCHandle = SafeWindowDCHandle.fromDesktop()) {
				if (desktopDCHandle.IsInvalid) {
					// Get Exception before the error is lost
					Exception exceptionToThrow = CreateCaptureException("desktopDCHandle", captureBounds);
					// throw exception
					throw exceptionToThrow;
				}

				// create a device context we can copy to
				using (SafeCompatibleDCHandle safeCompatibleDCHandle = GDI32.CreateCompatibleDC(desktopDCHandle)) {
					// Check if the device context is there, if not throw an error with as much info as possible!
					if (safeCompatibleDCHandle.IsInvalid) {
						// Get Exception before the error is lost
						Exception exceptionToThrow = CreateCaptureException("CreateCompatibleDC", captureBounds);
						// throw exception
						throw exceptionToThrow;
					}
					// Create BITMAPINFOHEADER for CreateDIBSection
					BITMAPINFOHEADER bmi = new BITMAPINFOHEADER(captureBounds.Width, captureBounds.Height, 24);

					// Make sure the last error is set to 0
					Win32.SetLastError(0);

					// create a bitmap we can copy it to, using GetDeviceCaps to get the width/height
					IntPtr bits0; // not used for our purposes. It returns a pointer to the raw bits that make up the bitmap.
					using (SafeDibSectionHandle safeDibSectionHandle = GDI32.CreateDIBSection(desktopDCHandle, ref bmi, BITMAPINFOHEADER.DIB_RGB_COLORS, out bits0, IntPtr.Zero, 0)) {
						if (safeDibSectionHandle.IsInvalid) {
							// Get Exception before the error is lost
							Exception exceptionToThrow = CreateCaptureException("CreateDIBSection", captureBounds);
							exceptionToThrow.Data.Add("hdcDest", safeCompatibleDCHandle.DangerousGetHandle().ToInt32());
							exceptionToThrow.Data.Add("hdcSrc", desktopDCHandle.DangerousGetHandle().ToInt32());

							// Throw so people can report the problem
							throw exceptionToThrow;
						}
						// select the bitmap object and store the old handle
						using (safeCompatibleDCHandle.SelectObject(safeDibSectionHandle)) {
							// bitblt over (make copy)
							GDI32.BitBlt(safeCompatibleDCHandle, 0, 0, captureBounds.Width, captureBounds.Height, desktopDCHandle, captureBounds.X, captureBounds.Y, CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt);
						}

						// get a .NET image object for it
						// A suggestion for the "A generic error occurred in GDI+." E_FAIL/0×80004005 error is to re-try...
						bool success = false;
						ExternalException exception = null;
						for (int i = 0; i < 3; i++) {
							try {
								// Collect all screens inside this capture
								List<Screen> screensInsideCapture = new List<Screen>();
								foreach (Screen screen in Screen.AllScreens) {
									if (screen.Bounds.IntersectsWith(captureBounds)) {
										screensInsideCapture.Add(screen);
									}
								}
								// Check all all screens are of an equal size
								bool offscreenContent;
								using (Region captureRegion = new Region(captureBounds)) {
									// Exclude every visible part
									foreach (Screen screen in screensInsideCapture) {
										captureRegion.Exclude(screen.Bounds);
									}
									// If the region is not empty, we have "offscreenContent"
									using (Graphics screenGraphics = Graphics.FromHwnd(User32.GetDesktopWindow())) {
										offscreenContent = !captureRegion.IsEmpty(screenGraphics);
									}
								}
								// Check if we need to have a transparent background, needed for offscreen content
								if (offscreenContent) {
									using (Bitmap tmpBitmap = Image.FromHbitmap(safeDibSectionHandle.DangerousGetHandle())) {
										// Create a new bitmap which has a transparent background
										returnBitmap = ImageHelper.CreateEmpty(tmpBitmap.Width, tmpBitmap.Height, PixelFormat.Format32bppArgb, Color.Transparent, tmpBitmap.HorizontalResolution, tmpBitmap.VerticalResolution);
										// Content will be copied here
										using (Graphics graphics = Graphics.FromImage(returnBitmap)) {
											// For all screens copy the content to the new bitmap
											foreach (Screen screen in Screen.AllScreens) {
												Rectangle screenBounds = screen.Bounds;
												// Make sure the bounds are offsetted to the capture bounds
												screenBounds.Offset(-captureBounds.X, -captureBounds.Y);
												graphics.DrawImage(tmpBitmap, screenBounds, screenBounds.X, screenBounds.Y, screenBounds.Width, screenBounds.Height, GraphicsUnit.Pixel);
											}
										}
									}
								} else {
									// All screens, which are inside the capture, are of equal size
									// assign image to Capture, the image will be disposed there..
									returnBitmap = Image.FromHbitmap(safeDibSectionHandle.DangerousGetHandle());
								}
								// We got through the capture without exception
								success = true;
								break;
							} catch (ExternalException ee) {
								LOG.Warn("Problem getting bitmap at try " + i + " : ", ee);
								exception = ee;
							}
						}
						if (!success) {
							LOG.Error("Still couldn't create Bitmap!");
							if (exception != null) {
								throw exception;
							}
						}
					}
				}
			}
			return returnBitmap;
		}
Пример #17
0
		internal void ProcessMovement()
		{
			// update robot position
			PointD tOldPosition = m_tPosition;
			m_tPosition += m_tMovement;
			m_tMovement = PointD.Empty;

			// check if we have hit a wall
			bool bHitWall = false;
			if (m_tPosition.X - Size.Width / 2.0 < 0)
			{
				m_tPosition.X = Size.Width / 2.0;
				bHitWall = true;
			}
			else if (m_tPosition.X + Size.Width / 2.0 > m_pBattle.BattleFieldSize.Width)
			{
				m_tPosition.X = m_pBattle.BattleFieldSize.Width - Size.Width / 2.0;
				bHitWall = true;
			}
			if (m_tPosition.Y - Size.Height / 2.0 < 0)
			{
				m_tPosition.Y = Size.Height / 2.0;
				bHitWall = true;
			}
			else if (m_tPosition.Y + Size.Height / 2.0 > m_pBattle.BattleFieldSize.Height)
			{
				m_tPosition.Y = m_pBattle.BattleFieldSize.Height - Size.Height / 2.0;
				bHitWall = true;
			}
			if (bHitWall)
			{
				m_pEvents.Add(new HitWallEvent());
				m_dEnergy -= 3.0;
			}

			// rotate robot
			m_nHeading += m_nRotation;
			if (m_nHeading < 0) m_nHeading = 360 + m_nHeading;
			if (m_nHeading > 359) m_nHeading -= 360;
			m_nRotation = 0;

			PointF tEndPoint = new PointF((float) (Position.X + Math.Sin(HeadingRadians) * BattleFieldSize.Width),
				(float) (Position.Y + Math.Cos(HeadingRadians) * BattleFieldSize.Width));

			// check if we can see another robot
			for (int i = 0; i < m_pBattle.Robots.Length; i++)
			{
				Robot pRobot = m_pBattle.Robots[i];

				// make sure we're not testing against ourselves
				if (pRobot != this)
				{
					GraphicsPath pPath = new GraphicsPath();
					pPath.AddLine(Position, tEndPoint);
					pPath.CloseFigure();
					pPath.Widen(new Pen(Color.Black, 1));
					Region pRegion = new Region(pPath);
					pRegion.Intersect(pRobot.Bounds);
					if (!pRegion.IsEmpty(m_pGraphics))
					{
						// we can see this robot
						PointD tDistance = pRobot.Position - Position;
						double dDistance = Math.Sqrt(tDistance.X * tDistance.X + tDistance.Y * tDistance.Y);
						ScannedRobotEvent pEvent = new ScannedRobotEvent(
							pRobot.Name, pRobot.Energy, pRobot.Heading - Heading,
							dDistance, pRobot.Heading, pRobot.Velocity);
						m_pEvents.Add(pEvent);
					}
				}
			}

			// check if we have collided with another robot
			for (int i = 0; i < m_pBattle.Robots.Length; i++)
			{
				Robot pRobot = m_pBattle.Robots[i];

				// make sure we're not testing against ourselves
				if (pRobot != this)
				{
					if (pRobot.Bounds.IntersectsWith(Bounds))
					{
						// send message to ourselves
						bool bAtFault = true;
						HitRobotEvent pEvent = new HitRobotEvent(pRobot.Name,
							Math.Abs(pRobot.Heading - Heading),
							pRobot.Energy, bAtFault);
						m_pEvents.Add(pEvent);
						m_tPosition = tOldPosition;
						m_dEnergy -= 3.0;
					}
				}
			}
		}