예제 #1
0
        //缩放绘图范围,以当前鼠标所在的坐标为缩放的中心
        public void OnCanvasMouseWheel(MouseEventArgs e)
        {
            int    ex = e.X - Left, ey = e.Y - Top;
            PointF wpos = ScreenToWorld(ex, ey);

            //控制Graphics矩阵的缩放
            if (e.Delta > 0)
            {
                --m_ScaleStepIndex;
                if (m_ScaleStepIndex < 0)
                {
                    m_ScaleStepIndex = 0;
                }
                m_GridScale = m_ScaleStep[m_ScaleStepIndex];
            }
            else
            {
                ++m_ScaleStepIndex;
                if (m_ScaleStepIndex > 18)
                {
                    m_ScaleStepIndex = 18;
                }
                m_GridScale = m_ScaleStep[m_ScaleStepIndex];
            }

            m_OffsetX = -(int)(wpos.X / m_GridScale + Width * 0.5f - ex);
            m_OffsetY = -(int)(wpos.Y / -m_GridScale + Height * 0.5f - ey);

            PointF lt = ScreenToWorld(0, 0);
            PointF rb = ScreenToWorld(Width, Height);

            m_View = new WorldSpaceRect(lt.X, lt.Y, rb.X, rb.Y);
            Invalidate();
        }
예제 #2
0
        //检测点pt是否在线段AB上
        public static bool IsPointOnLine(PointF pt, PointF start, PointF end)
        {
            WorldSpaceRect rect = new WorldSpaceRect(start, end);

            rect.Regular();
            if (!rect.Contains(pt.X, pt.Y))
            {
                return(false);
            }
            PointF pa = new PointF(pt.X - start.X, pt.Y - start.Y);
            PointF ab = new PointF(end.X - start.X, end.Y - start.Y);
            float  ma = (float)Math.Sqrt(pa.X * pa.X + pa.Y * pa.Y);

            pa.X /= ma; pa.Y /= ma;

            float mb = (float)Math.Sqrt(ab.X * ab.X + ab.Y * ab.Y);

            ab.X /= mb; ab.Y /= mb;

            float dot = pa.X * ab.X + pa.Y * ab.Y;

            //0.9962f表示允许5°的误差
            if (Math.Abs(dot) < 0.9962f)
            {
                return(false);
            }
            return(true);
        }
예제 #3
0
        //控件大小发生改变时的处理
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            if (Width == 0 || Height == 0)
            {
                return;
            }
            m_Canvas = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            PointF lt = ScreenToWorld(0, 0);
            PointF rb = ScreenToWorld(Width, Height);

            m_View = new WorldSpaceRect(lt.X, lt.Y, rb.X, rb.Y);

            Invalidate();
        }
예제 #4
0
        //添加时间轴对象,添加时会自动按照时间先后进行一次排序
        public void ShowStream(TimelineStreams item)
        {
            //需要Item按照时间排序
            m_Stream = item;
            if (item.GetStreamCount() == 4)
            {
                m_ScaleStepIndex = 6;
                m_GridScale      = m_ScaleStep[m_ScaleStepIndex];
            }
            else
            {
                m_ScaleStepIndex = 10;
                m_GridScale      = m_ScaleStep[m_ScaleStepIndex];
            }
            PointF lt = ScreenToWorld(0, 0);
            PointF rb = ScreenToWorld(Width, Height);

            m_View = new WorldSpaceRect(lt.X, lt.Y, rb.X, rb.Y);
            Invalidate();
        }
예제 #5
0
        public TimeGrid()
        {
            InitializeComponent();
            m_ScaleStep = new float[20];
            for (int i = 0; i < 20; i += 2)
            {
                m_ScaleStep[i]     = 0.00002f * (float)Math.Pow(10, i / 2) / 2;
                m_ScaleStep[i + 1] = 0.00002f * (float)Math.Pow(10, i / 2);
            }
            m_ScaleStepIndex = 10;
            m_GridScale      = m_ScaleStep[m_ScaleStepIndex];
            m_GridSize       = 50;
            m_Canvas         = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            m_X       = m_Y = 0;
            m_OffsetX = m_OffsetY = 0;
            PointF lt = ScreenToWorld(0, 0);
            PointF rb = ScreenToWorld(Width, Height);

            m_View = new WorldSpaceRect(lt.X, lt.Y, rb.X, rb.Y);
            //----------------------------------------------------------------------------------------
            m_CurrentKeyPointIndex = -1;
            m_CurrentStreamIndex   = -1;
            m_Tooltip = "";
        }
예제 #6
0
        //平移图像,或者平移选中的操作手柄
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                //控制Graphics矩阵的平移
                m_OffsetX += e.X - m_X;
                m_OffsetY += e.Y - m_Y;
                m_X        = e.X;
                m_Y        = e.Y;

                PointF lt = ScreenToWorld(0, 0);
                PointF rb = ScreenToWorld(Width, Height);
                m_View = new WorldSpaceRect(lt.X, lt.Y, rb.X, rb.Y);

                Invalidate();
            }
            else if (e.Button == MouseButtons.Left)
            {
                //如果当前有选中的操作器,则将上下移动映射到改变操作器的值
                if (m_CurrentKeyPoint != null)
                {
                    PointF pt = ScreenToWorld(e.X, e.Y);
                    m_CurrentKeyPoint.SetValue((uint)m_CurrentStreamIndex, pt.Y);
                    {
                        //如果允许修改时间,但是不能超过左右两侧
                        m_CurrentKeyPoint.Time = pt.X;
                        List <KeyPoint> list = m_Stream.GetStream();
                        //不能小于左侧
                        if (m_CurrentKeyPointIndex > 0)
                        {
                            KeyPoint kp = list[m_CurrentKeyPointIndex - 1];
                            if (kp.Time > pt.X)
                            {
                                m_CurrentKeyPoint.Time = kp.Time;
                            }
                        }
                        if (m_CurrentKeyPointIndex < list.Count - 1)
                        {
                            KeyPoint kp = list[m_CurrentKeyPointIndex + 1];
                            if (kp.Time < pt.X)
                            {
                                m_CurrentKeyPoint.Time = kp.Time;
                            }
                        }
                    }
                    m_Stream.Update(m_CurrentKeyPoint);
                    m_Tooltip  = "(";
                    m_Tooltip += pt.X.ToString(); m_Tooltip += ","; m_Tooltip += pt.Y.ToString(); m_Tooltip += ")";
                    m_TooltipX = e.X;
                    m_TooltipY = e.Y;
                    Invalidate();
                }
                else
                {
                    //控制Graphics矩阵的平移
                    m_OffsetX += e.X - m_X;
                    m_OffsetY += e.Y - m_Y;
                    m_X        = e.X;
                    m_Y        = e.Y;

                    PointF lt = ScreenToWorld(0, 0);
                    PointF rb = ScreenToWorld(Width, Height);
                    m_View    = new WorldSpaceRect(lt.X, lt.Y, rb.X, rb.Y);
                    m_Tooltip = "";
                    Invalidate();
                }
            }
            else
            {
                if (m_Tooltip.Length > 0)
                {
                    m_Tooltip = "";
                    Invalidate();
                }
            }

            if (TooltipDelegate != null)
            {
                PointF pt = ScreenToWorld(e.X, e.Y);
                string text;
                text  = "(";
                text += pt.X.ToString(); text += ","; text += pt.Y.ToString(); text += ")";
                TooltipDelegate(text);
            }
            base.OnMouseMove(e);
        }