Beispiel #1
0
 /// <summary>
 /// 重新绘制视图的事件处理
 /// </summary>
 /// <param name="e">事件参数</param>
 protected virtual void OnViewPaint(PaintEventArgs e, SimpleRectangleTransform trans)
 {
     if (ViewPaint != null)
     {
         ViewPaint(this, e);
     }
 }
Beispiel #2
0
        /// <summary>
        /// 刷新坐标转换对象
        /// </summary>
        protected virtual void RefreshScaleTransform()
        {
            Debug.WriteLine(" documentview call RefreshScaleTransform()");
            SimpleRectangleTransform transform = this.myTransform as SimpleRectangleTransform;

            if (transform == null)
            {
                return;
            }

            System.Drawing.Rectangle rect = this.ClientRectangle;
            transform.SourceRect = rect;
            System.Drawing.Point p = this.AutoScrollPosition;
            //rect.Offset( this.AutoScrollPosition.X ,   this.AutoScrollPosition.Y );
            //transform.SourceRect = rect ;

            float xrate = (float)this.ClientToViewXRate;
            float yrate = (float)this.ClientToViewYRate;

            transform.DescRectF = new System.Drawing.RectangleF(
                -p.X * xrate,
                -p.Y * yrate,
                rect.Width * xrate,
                rect.Height * yrate);
        }
Beispiel #3
0
        protected virtual void TransformPaint(PaintEventArgs e, SimpleRectangleTransform trans)
        {
            if (trans == null)
            {
                return;
            }

            System.Drawing.Rectangle rect = e.ClipRectangle;
            rect.Offset(-1, -1);
            rect.Width  += 2;
            rect.Height += 2;
            rect         = System.Drawing.Rectangle.Intersect(trans.SourceRect, rect);
            if (rect.IsEmpty)
            {
                return;
            }

            System.Drawing.RectangleF rectf = trans.TransformRectangleF(
                (float)rect.Left,
                (float)rect.Top,
                (float)rect.Width,
                (float)rect.Height);
            rect.X      = (int)Math.Floor((double)rectf.Left);
            rect.Y      = (int)Math.Floor((double)rectf.Top);
            rect.Width  = (int)System.Math.Ceiling((double)rectf.Width);
            rect.Height = (int)System.Math.Ceiling((double)rectf.Height);

            e.Graphics.PageUnit = this.intGraphicsUnit;
            e.Graphics.ResetTransform();

            e.Graphics.ScaleTransform(this.fXZoomRate, this.fYZoomRate);
            double rate = this.ClientToViewXRate * (double)this.fXZoomRate;

            e.Graphics.TranslateTransform(
                (float)((double)trans.SourceRect.Left * rate - (double)trans.DescRectF.X),
                (float)((double)trans.SourceRect.Top * rate - (double)trans.DescRectF.Y));

            if (trans.XZoomRate < 1f)
            {
                rect.Width += (int)System.Math.Ceiling((double)(1f / trans.XZoomRate));
            }

            if (trans.YZoomRate < 1f)
            {
                rect.Height += (int)System.Math.Ceiling((double)(1f / trans.YZoomRate));
            }

            System.Windows.Forms.PaintEventArgs e2 =
                new System.Windows.Forms.PaintEventArgs(
                    e.Graphics,
                    rect);

            e2.Graphics.ResetClip();
            e2.Graphics.SetClip(new Rectangle(rect.Left, rect.Top, rect.Width + 2, rect.Height + 2));

            OnViewPaint(e2, trans);
        }
        /// <summary>
        /// 添加一个转换关系
        /// </summary>
        /// <param name="SourceRect">原始区域矩形边框</param>
        /// <param name="DescRect">目标区域矩形边框</param>
        /// <remarks>新增的转换关系</remarks>
        public SimpleRectangleTransform Add(
            System.Drawing.Rectangle SourceRect,
            System.Drawing.Rectangle DescRect)
        {
            SimpleRectangleTransform NewItem = new SimpleRectangleTransform(SourceRect, DescRect);

            myItems.Add(NewItem);
            return(NewItem);
        }
        /// <summary>
        /// 添加一个转换关系
        /// </summary>
        /// <param name="SourceLeft">原始区域边框左端位置</param>
        /// <param name="SourceTop">原始区域边框顶端位置</param>
        /// <param name="SourceWidth">原始区域边框宽度</param>
        /// <param name="SourceHeight">原始区域边框高度</param>
        /// <param name="DescLeft">目标区域边框左端位置</param>
        /// <param name="DescTop">目标区域边框顶端位置</param>
        /// <param name="DescWidth">目标区域边框宽度</param>
        /// <param name="DescHeight">目标区域边框高度</param>
        public SimpleRectangleTransform Add(
            int SourceLeft,
            int SourceTop,
            int SourceWidth,
            int SourceHeight,
            int DescLeft,
            int DescTop,
            int DescWidth,
            int DescHeight)
        {
            SimpleRectangleTransform NewItem = new SimpleRectangleTransform(
                new System.Drawing.Rectangle(SourceLeft, SourceTop, SourceWidth, SourceHeight),
                new System.Drawing.Rectangle(DescLeft, DescTop, DescWidth, DescHeight));

            myItems.Add(NewItem);
            return(NewItem);
        }
Beispiel #6
0
        protected System.Drawing.Bitmap CreateContentBitmap(float rate, System.Drawing.Color BmpBackColor)
        {
            SimpleRectangleTransform trans = this.myTransform as SimpleRectangleTransform;

            if (trans == null)
            {
                return(null);
            }

            System.Drawing.Size size = this.AutoScrollMinSize;
            size.Width  = (int)(size.Width * rate);
            size.Height = (int)(size.Height * rate);
            if (size.Width <= 0 || size.Height <= 0)
            {
                return(null);
            }
            System.Drawing.Bitmap bmp = new Bitmap(size.Width, size.Height);
            float rate2 = rate;

            float rateback = this.fXZoomRate;

            try
            {
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
                {
                    g.Clear(BmpBackColor);
                    g.PageUnit = this.intGraphicsUnit;
                    g.ScaleTransform(rate2, rate2);
                    g.TranslateTransform(-trans.DescRectF.X, -trans.DescRectF.Y);
                    System.Windows.Forms.PaintEventArgs e = new PaintEventArgs(g, trans.DescRect);
                    this.fXZoomRate = rate;
                    this.OnViewPaint(e, trans);
                    this.fXZoomRate = rateback;
                }
                return(bmp);
            }
            catch (Exception ext)
            {
                this.fXZoomRate = rateback;
                throw ext;
            }
        }
 public int Add(SimpleRectangleTransform item)
 {
     return(myItems.Add(item));
 }