Пример #1
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();
            }
        }
Пример #2
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;
                }
            }
        }