示例#1
0
文件: Rect.cs 项目: Scellow/Perspex
 /// <summary>
 /// Centers another rectangle in this rectangle.
 /// </summary>
 /// <param name="rect">The rectangle to center.</param>
 /// <returns>The centered rectangle.</returns>
 public Rect CenterIn(Rect rect)
 {
     return new Rect(
         this.x + ((this.width - rect.width) / 2),
         this.y + ((this.height - rect.height) / 2),
         rect.width,
         rect.height);
 }
示例#2
0
文件: Rect.cs 项目: Scellow/Perspex
        /// <summary>
        /// Gets the intersection of two rectangles.
        /// </summary>
        /// <param name="rect">The other rectangle.</param>
        /// <returns>The intersection.</returns>
        public Rect Intersect(Rect rect)
        {
            double x = Math.Max(this.x, rect.x);
            double y = Math.Max(this.y, rect.y);
            double width = Math.Min(this.Right, rect.Right) - x;
            double height = Math.Min(this.Bottom, rect.Bottom) - y;

            if (width < 0 || height < 0)
            {
                return new Rect(
                    double.PositiveInfinity,
                    double.PositiveInfinity,
                    double.NegativeInfinity,
                    double.NegativeInfinity);
            }
            else
            {
                return new Rect(x, y, width, height);
            }
        }
示例#3
0
文件: Rect.cs 项目: KvanTTT/Perspex
 /// <summary>
 /// Determines whether a rectangle intersects with this rectangle.
 /// </summary>
 /// <param name="rect">The other rectangle.</param>
 /// <returns>
 /// True if the specified rectangle intersects with this one; otherwise false.
 /// </returns>
 public bool Intersects(Rect rect)
 {
     return (rect.X < Right) && (X < rect.Right) && (rect.Y < Bottom) && (Y < rect.Bottom);
 }
示例#4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="dc"></param>
 /// <param name="c"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 private void DrawBackground(DrawingContext dc, ArgbColor c, double width, double height)
 {
     var color = Color.FromArgb(c.A, c.R, c.G, c.B);
     var brush = new SolidColorBrush(color);
     var rect = new Rect(0, 0, width, height);
     dc.FillRectangle(brush, rect);
     // TODO: brush.Dispose();
 }
示例#5
0
文件: Rect.cs 项目: KvanTTT/Perspex
 /// <summary>
 /// Centers another rectangle in this rectangle.
 /// </summary>
 /// <param name="rect">The rectangle to center.</param>
 /// <returns>The centered rectangle.</returns>
 public Rect CenterIn(Rect rect)
 {
     return new Rect(
         _x + ((_width - rect._width) / 2),
         _y + ((_height - rect._height) / 2),
         rect._width,
         rect._height);
 }
示例#6
0
文件: Rect.cs 项目: KvanTTT/Perspex
        /// <summary>
        /// Gets the intersection of two rectangles.
        /// </summary>
        /// <param name="rect">The other rectangle.</param>
        /// <returns>The intersection.</returns>
        public Rect Intersect(Rect rect)
        {
            var newLeft = (rect.X > X) ? rect.X : X;
            var newTop = (rect.Y > Y) ? rect.Y : Y;
            var newRight = (rect.Right < Right) ? rect.Right : Right;
            var newBottom = (rect.Bottom < Bottom) ? rect.Bottom : Bottom;

            if ((newRight > newLeft) && (newBottom > newTop))
            {
                return new Rect(newLeft, newTop, newRight - newLeft, newBottom - newTop);
            }
            else
            {
                return Empty;
            }
        }
示例#7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="brush"></param>
        /// <param name="pen"></param>
        /// <param name="isStroked"></param>
        /// <param name="isFilled"></param>
        /// <param name="rect"></param>
        private static void DrawRectangleInternal(
            IDrawingContext dc,
            Brush brush,
            Pen pen,
            bool isStroked,
            bool isFilled,
            ref Rect2 rect)
        {
            if (!isStroked && !isFilled)
                return;

            var r = new Rect(rect.X, rect.Y, rect.Width, rect.Height);

            if (isFilled)
            {
                dc.FillRectangle(brush, r);
            }

            if (isStroked)
            {
                dc.DrawRectangle(pen, r);
            }
        }
示例#8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="dc"></param>
 /// <param name="container"></param>
 private void DrawBackgroundInternal(IDrawingContext dc, Container container)
 {
     Brush brush = ToSolidBrush(container.Background);
     var rect = new Rect(0, 0, container.Width, container.Height);
     dc.FillRectangle(brush, rect);
     // TODO: brush.Dispose();
 }
示例#9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="brush"></param>
        /// <param name="pen"></param>
        /// <param name="isStroked"></param>
        /// <param name="isFilled"></param>
        /// <param name="rect"></param>
        private static void DrawEllipseInternal(
            IDrawingContext dc,
            Brush brush,
            Pen pen,
            bool isStroked,
            bool isFilled,
            ref Rect2 rect)
        {
            if (!isFilled && !isStroked)
                return;

            var r = new Rect(rect.X, rect.Y, rect.Width, rect.Height);
            var g = new EllipseGeometry(r);

            dc.DrawGeometry(
                isFilled ? brush : null,
                isStroked ? pen : null,
                g);

            // TODO: g.Dispose();
        }
示例#10
0
        /// <summary>
        /// Render the html using the given device.
        /// </summary>
        /// <param name="g">the device to use to render</param>
        /// <param name="clip">the clip rectangle of the html container</param>
        public void PerformPaint(DrawingContext g, Rect clip)
        {
            ArgChecker.AssertArgNotNull(g, "g");

            using (var ig = new GraphicsAdapter(g, Util.Convert(clip)))
            {
                _htmlContainerInt.PerformPaint(ig);
            }
        }
示例#11
0
文件: Util.cs 项目: Arlorean/Perspex
 /// <summary>
 /// Convert from WPF rectangle to core rectangle.
 /// </summary>
 public static RRect Convert(Rect r)
 {
     return new RRect(r.X, r.Y, r.Width, r.Height);
 }
示例#12
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     var res = _text.HitTestPoint(new Point(e.X, e.Y) - _textPos);
     if (res.IsInside)
     {
         _textRect = _text.HitTestTextPosition(res.TextPosition);
         _textRect = new Rect(_textRect.Position + _textPos, _textRect.Size);
         _textString = _text.Text.Substring(res.TextPosition, 1);
     }
     else
         _textRect = new Rect();
     UpdateTitle();
     base.OnMouseMove(e);
 }
示例#13
0
        private void DrawRoundRect(DrawingContext ctx)
        {
            ctx.FillRectangle(new SolidColorBrush(Colors.White),
                new Rect(new Size(ClientSize.Width, ClientSize.Height)));
            var rc = new Rect(0, 0, 60, 60);

            var transform = GetTransform();

            using (ctx.PushPostTransform(transform))
            {
                ctx.FillRectangle(new SolidColorBrush(Colors.Aqua), rc, 20);
                ctx.DrawRectangle(new Pen(new SolidColorBrush(Colors.Magenta), 10), rc, 20);
            }
        }