Exemple #1
0
        public void Action(ChartParameter parameter)
        {
            InputDeviceStatus cStatus = parameter.Status;

            if (cStatus.Event == EInputDeviceEvent.MouseWheel)
            {
                MouseEventArgs e      = cStatus.GetCurrentMouseArgs();
                ZChart         cChart = parameter.Chart;
                AxisX          cAxisX = cChart.AxisX;

                int iCount = cAxisX.BarCount;
                if (e.Delta < 0)
                {
                    iCount += ZOOM_SCALE_UNIT;
                }
                else
                {
                    iCount -= ZOOM_SCALE_UNIT;
                }

                cAxisX.BarCount = iCount;
                if (cAxisX.Refresh)
                {
                    cChart.Refresh();
                }
            }
        }
Exemple #2
0
        internal Behavior(ZChart chart, Control context, InputDeviceStatus status)
        {
            __cDrawContainer = new DrawContainer();
            __cParameter     = new ChartParameter(chart, context, this, status);

            __cActions = new List <IAction>(8);
            __cActions.Add(new Resize());
            __cActions.Add(new Move());
            __cActions.Add(new Zoom());
        }
Exemple #3
0
        public void Action(ChartParameter parameter)
        {
            ZChart            cChart  = parameter.Chart;
            InputDeviceStatus cStatus = parameter.Status;
            MouseEventArgs    e       = cStatus.GetCurrentMouseArgs();

            if (cStatus.Event == EInputDeviceEvent.MouseUp)
            {
                if (__cStart == Point.Empty)
                {
                    List <Layer> cLayers = cChart.Layers;
                    int          iCount  = cLayers.Count;
                    for (int i = 0; i < iCount; i++)
                    {
                        Layer cLayer = cLayers[i];
                        if (cLayer.IsLayerScope(e.X, e.Y))
                        {
                            __cLayer = cLayer;
                            break;
                        }
                    }

                    __cStart = e.Location;
                }
                else
                {
                    Point cEnd = e.Location;
                    Boundary.BoundFix(ref __cStart, ref cEnd, new Rectangle4(__cLayer.LayerRectangleWithoutAxisY));

                    //保存至使用者繪製容器內
                    parameter.Behavior.DrawContainer.AddDrawObject(__sName, __cLayer, new Point[] { __cStart, cEnd }, new PowerLanguage.PenStyle[] { parameter.CustomPen });

                    __cStart = Point.Empty;
                    parameter.CustomPainter = null;                      //繪圖完畢需要設定為 null

                    __cGDI.ClearRops(__cLineInfos, null, false);
                    cChart.Refresh();
                }
            }
            else if (__cStart != Point.Empty && cStatus.Event == EInputDeviceEvent.MouseMove)
            {
                __cGDI.SaveDC();
                __cGDI.ClipRectangle(__cLayer.LayerRectangleWithoutAxisY);
                __cGDI.ClearRops(__cLineInfos, null, !parameter.Updated);

                ChartProperty cProperty = cChart.ChartProperty;
                IntPtr        cPen      = Gdi.CreatePen(new PowerLanguage.PenStyle(cProperty.DrawAideLineColor, 1));
                __cLineInfos.Add(__cGDI.DrawRopLine(cPen, __cStart.X, __cStart.Y, e.X, e.Y));

                __cGDI.RestoreDC();
            }
        }
Exemple #4
0
        public void Action(ChartParameter parameter)
        {
            InputDeviceStatus cStatus = parameter.Status;

            if (cStatus.IsDrag && cStatus.Event == EInputDeviceEvent.MouseMove)
            {
                MouseEventArgs e = cStatus.GetCurrentMouseArgs();
                if (e.Button == MouseButtons.Left)
                {
                    ZChart cChart  = parameter.Chart;
                    AxisX  cAxisX  = cChart.AxisX;
                    double dUnit   = cAxisX.AxisRectangle.Width / (double)cAxisX.BarCount;
                    int    iOffset = (int)((__iMouseX - e.X) / dUnit);

                    cAxisX.BarNumber = __iInitBarNumber + iOffset;
                    if (cAxisX.Refresh)
                    {
                        cChart.Refresh();
                    }
                }
            }
            else if (!cStatus.IsDrag && cStatus.Event == EInputDeviceEvent.MouseDown)
            {
                MouseEventArgs e = cStatus.GetCurrentMouseArgs();
                if (e.Button == MouseButtons.Left)
                {
                    parameter.IsAction       = true;
                    parameter.Context.Cursor = Cursors.SizeWE;
                    __iMouseX        = cStatus.GetCurrentMouseArgs().X;
                    __iInitBarNumber = parameter.Chart.AxisX.BarNumber;
                }
            }
            else if (cStatus.Event == EInputDeviceEvent.MouseUp)
            {
                parameter.IsAction       = false;
                parameter.Context.Cursor = Cursors.Default;
            }
        }
Exemple #5
0
        public void Action(ChartParameter parameter)
        {
            __cGDI.ClearRops(true);
            __cGDI.ClearRops(__cLineInfos, __cTextInfos, !parameter.Updated);

            InputDeviceStatus cStatus = parameter.Status;

            if (cStatus.Event == EInputDeviceEvent.MouseMove)
            {
                ZChart         cChart    = parameter.Chart;
                AxisX          cAxisX    = cChart.AxisX;
                ChartProperty  cProperty = cChart.ChartProperty;
                MouseEventArgs e         = cStatus.GetCurrentMouseArgs();

                int    iOldBKColor = __cGDI.SelectBackground(cProperty.BackgroundColor);
                IntPtr cOldFont    = __cGDI.SelectFont(cProperty.AxisFont);
                IntPtr cPen        = Gdi.CreatePen(new PowerLanguage.PenStyle(cProperty.ForeColor, 1));

                int iBarNumber = cAxisX.ConvertBarNumberFromX(e.X);
                if (iBarNumber > cAxisX.DataCount)
                {
                    return;
                }
                else
                {
                    Rectangle cAxisXRect = cAxisX.AxisRectangle;
                    AxisXUnit cUnit      = cAxisX.ConvertBarNumberToWidth(iBarNumber);
                    cAxisXRect.X     = cUnit.CenterPoint;
                    cAxisXRect.Width = cAxisX.FontMetrics.Width * 12;

                    DateTime cDateTime = cAxisX.ConvertBarNumberToTime(iBarNumber);
                    __cLineInfos.Add(__cGDI.DrawRopLine(cPen, cUnit.CenterPoint, 0, cUnit.CenterPoint, cAxisXRect.Y));
                    __cTextInfos.Add(__cGDI.DrawRopString(cDateTime.ToString("MM/dd HH:mm"), cProperty.BackgroundColor, cProperty.ForeColor, 2, 5, cAxisXRect));
                }

                List <Layer> cLayers = cChart.Layers;
                int          iCount  = cLayers.Count;
                for (int i = 0; i < iCount; i++)
                {
                    Layer cLayer = cLayers[i];
                    if (__cLineInfos.Count == 1 && cLayer.IsLayerScope(e.X, e.Y))
                    {
                        AxisY     cAxisY     = cLayer.AxisY;
                        Rectangle cAxisYRect = cAxisY.AxisRectangle;
                        cAxisYRect.Y      = e.Y;
                        cAxisYRect.Height = cAxisY.FontMetrics.Height;

                        __cLineInfos.Add(__cGDI.DrawRopLine(cPen, 0, e.Y, cAxisYRect.X, e.Y));
                        __cTextInfos.Add(__cGDI.DrawRopString(Math.Round(cAxisY.ConvertValueFromY(e.Y), cAxisY.Decimals).ToString(), cProperty.BackgroundColor, cProperty.ForeColor, 5, 0, cAxisYRect));
                    }

                    cLayer.LegendIndex = iBarNumber;
                    __cEngine.DrawLegend(cLayer, cProperty);
                }

                __cGDI.RemoveObject(__cGDI.SelectFont(cOldFont));
                __cGDI.SelectBackground(iOldBKColor);
            }

            //如果使用者使用十字線功能, 如果有在選擇繪圖功能會在 CustomPainter 屬性儲存繪圖功能的類別名稱
            //如果有繪圖類別名稱就取出使用
            string sName = parameter.CustomPainter;

            if (__cCustomPainter == null && sName != null)
            {
                __cCustomPainter = parameter.Behavior.GetCustomAction(sName);
                if (__cCustomPainter == null || !(__cCustomPainter is IDrawable))
                {
                    parameter.CustomPainter = null;
                }
            }

            if (__cCustomPainter != null)
            {
                __cCustomPainter.Action(parameter);

                //如果繪圖類別名稱 == null 表示繪圖已經完畢
                if (parameter.CustomPainter == null)
                {
                    __cCustomPainter = null;
                }
            }
        }
Exemple #6
0
        public void Action(ChartParameter parameter)
        {
            InputDeviceStatus cStatus = parameter.Status;

            if (cStatus.Event == EInputDeviceEvent.MouseMove)
            {
                MouseEventArgs e = cStatus.GetCurrentMouseArgs();
                if (cStatus.IsDrag && e.Button == MouseButtons.Left)
                {
                    int          iOffset = e.Y - __iMouseY;
                    ZChart       cChart  = parameter.Chart;
                    List <Layer> cLayers = cChart.Layers;
                    Layer        cLayer  = cLayers[__iLayerIndex];

                    //如果 Layers 只有一個就不需要計算鄰近的 Layer 的相對高度
                    if (cLayers.Count > 1)
                    {
                        double dScale = (__dLayerHeight + iOffset) / cChart.ChartRectangle.Height;
                        cLayers[__iLayerIndex + 1].HeightScale += cLayer.HeightScale - dScale;
                        cLayer.HeightScale = dScale;

                        cChart.Resize();
                        cChart.Refresh();
                    }
                }
                else
                {
                    ZChart       cChart  = parameter.Chart;
                    List <Layer> cLayers = cChart.Layers;
                    int          iCount  = cLayers.Count - 1;
                    for (int i = 0; i < iCount; i++)
                    {
                        Layer cLayer = cLayers[i];
                        if (cLayer.IsLayerScope(e.X, e.Y))
                        {
                            Rectangle cRect      = cLayer.LayerRectangle;
                            int       iMaxBottom = cRect.Y + cRect.Height;
                            int       iMinBottom = iMaxBottom - 5;
                            if (e.Y >= iMinBottom && e.Y <= iMaxBottom)
                            {
                                __bResize                = true;
                                __iLayerIndex            = i;
                                __dLayerHeight           = cRect.Height;
                                parameter.Context.Cursor = Cursors.SizeNS;
                                return;
                            }
                        }
                    }

                    __bResize = false;
                    parameter.Context.Cursor = Cursors.Default;
                }
            }
            else if (__bResize && !cStatus.IsDrag && cStatus.Event == EInputDeviceEvent.MouseDown)
            {
                parameter.IsAction = true;
                __iMouseY          = cStatus.GetCurrentMouseArgs().Y;
            }
            else if (cStatus.Event == EInputDeviceEvent.MouseUp)
            {
                __bResize                = false;
                parameter.IsAction       = false;
                parameter.Context.Cursor = Cursors.Default;
            }
        }