Esempio n. 1
0
        private void DrawTradeInfo(ITrade trade, AxisX axisX, ChartProperty property, IntPtr font, Rectangle4 layerRect, int top)
        {
            ITradeOrder cEntry  = trade.EntryOrder;
            Point       cPoint1 = new Point(axisX.ConvertBarNumberToWidth(cEntry.BarNumber).CenterPoint, top + this.AxisY.ConvertValueToHeight(cEntry.Price));

            __cGDI.DrawString("▸", property.TradeSymbolColor, cPoint1.X - 7, cPoint1.Y - 7);
            DrawTradeName(cEntry.Name, font, property.ForeColor, cPoint1, true);

            ITradeOrder cExit = trade.ExitOrder;

            if (cExit != null)
            {
                Point cPoint2 = new Point(axisX.ConvertBarNumberToWidth(cExit.BarNumber).CenterPoint, top + this.AxisY.ConvertValueToHeight(cExit.Price));
                __cGDI.DrawString("◂", property.TradeSymbolColor, cPoint2.X + 1, cPoint2.Y - 7);
                DrawTradeName(cExit.Name, font, property.ForeColor, cPoint2, false);

                if (Boundary.BoundFix(ref cPoint1, ref cPoint2, layerRect))
                {
                    __cGDI.DrawLine(cPoint1.X, cPoint1.Y, cPoint2.X, cPoint2.Y);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///   轉換 PowerLanguage.ChartPoint 為 System.Drawing.Point 座標
        /// </summary>
        /// <param name="layer">Layer 圖層</param>
        /// <returns>返回值: System.Drawing.Point 陣列</returns>
        public Point[] ConvertPoints(Layer layer)
        {
            AxisX cAxisX = layer.AxisX;
            AxisY cAxisY = layer.AxisY;
            int   iTop   = cAxisY.AxisRectangle.Top;

            int iLength = __cPoints.Length;

            Point[] cPoints = new Point[iLength];
            for (int i = 0; i < iLength; i++)
            {
                ChartPoint cCPoint = __cPoints[i];
                cPoints[i] = new Point(cAxisX.ConvertBarNumberToWidth(cCPoint.BarNumber.Value).CenterPoint, iTop + cAxisY.ConvertValueToHeight(cCPoint.Price));
            }
            return(cPoints);
        }
Esempio n. 3
0
        /// <summary>
        ///    繪製 AxisX 座標軸
        /// </summary>
        /// <param name="axis">AxisX 座標軸</param>
        /// <param name="property">Chart 屬性參數</param>
        public override void DrawAxisX(AxisX axis, ChartProperty property)
        {
            uint   uPattern    = 0xaaaaaaaa;         //格線樣式(Gdi.cs 內的 SelectPen 方法有定義格式, 格式皆由 Plugin 設計者自由規劃)
            int    iOldBKColor = __cGDI.SelectBackground(property.BackgroundColor);
            IntPtr cOldPen     = __cGDI.SelectPen(new PowerLanguage.PenStyle(property.GridColor, 1, (int)uPattern));
            IntPtr cGridPen    = __cGDI.SelectPen(new PowerLanguage.PenStyle(property.ForeColor, 1));
            IntPtr cOldFont    = __cGDI.SelectFont(property.AxisFont);

            List <AxisXLabel> cAxises = axis.CalculateAxisScale();
            Rectangle         cRect   = axis.AxisRectangle;

            __cGDI.FillRectangle(property.BackgroundColor, cRect.Left, cRect.Top, cRect.Width, cRect.Height);

            int iCount = cAxises.Count;

            for (int i = 0; i < iCount; i++)
            {
                AxisXLabel cLabel     = cAxises[i];
                AxisXUnit  cUnit      = axis.ConvertBarNumberToWidth(cLabel.BarNumber);
                int        iAbsWidth  = cRect.Left + cUnit.CenterPoint;
                int        iCharWidth = iAbsWidth + axis.FontMetrics.Width * 11;           //MM/dd HH:mm (11 chars)
                if (iCharWidth < cRect.Width)
                {
                    __cGDI.DrawLine(iAbsWidth, cRect.Top, iAbsWidth, cRect.Top + 5);
                    __cGDI.DrawString(cLabel.Time.ToString((i == 0) ? "yyyy/MM/dd" : "MM/dd HH:mm"), property.ForeColor, iAbsWidth, cRect.Top + 5);

                    if (property.IsShowGrid)
                    {
                        //繪製格線(因為 AxisX 軸在最下方, 格線往上延伸即可)
                        IntPtr cAxisPen = __cGDI.SelectPen(cGridPen);
                        __cGDI.DrawLine(iAbsWidth, 0, iAbsWidth, cRect.Top);
                        __cGDI.SelectPen(cAxisPen);
                    }
                }
            }

            __cGDI.RemoveObject(cGridPen);
            __cGDI.RemoveObject(__cGDI.SelectPen(cOldPen));
            __cGDI.RemoveObject(__cGDI.SelectFont(cOldFont));
            __cGDI.SelectBackground(iOldBKColor);
        }
Esempio n. 4
0
        public override bool DrawPlot(Layer layer, ChartProperty property, bool onlyUpdateLastBar)
        {
            AxisX     cAxisX = layer.AxisX;
            Rectangle cRectY = this.AxisY.AxisRectangle;

            int iIndex      = 0;
            int iOldBKColor = __cGDI.SelectBackground(property.BackgroundColor);

            if (onlyUpdateLastBar)
            {
                iIndex = cAxisX.BarNumber + cAxisX.BarCount - 1;
                iIndex = (iIndex > cAxisX.DataCount) ? cAxisX.DataCount : iIndex;
                int       iOffset = this.ConvertAxisScaleIndexToOffset(iIndex);
                AxisXUnit cUnit   = cAxisX.ConvertBarNumberToWidth(iIndex);
                if (!DrawOhlc(iOffset, cRectY.Y, cUnit, property.BackgroundColor))
                {
                    return(false);
                }
            }
            else
            {
                this.RefreshAxisY(property);

                int iCount      = cAxisX.BarCount;
                int iStartIndex = cAxisX.BarNumber;
                for (int i = 0; i < iCount; i++)
                {
                    iIndex = iStartIndex + i;
                    if (iIndex > cAxisX.DataCount)
                    {
                        --iIndex;
                        break;
                    }
                    else
                    {
                        int       iOffset = this.ConvertAxisScaleIndexToOffset(iIndex);
                        AxisXUnit cUnit   = cAxisX.ConvertBarNumberToWidth(iIndex);
                        DrawOhlc(iOffset, cRectY.Y, cUnit, Color.Empty);
                    }
                }

                if (this.PlotIndex == 0)                    //Plot 索引值為 0 才印出標題(其他的索引就不需要再印出標題)
                {
                    DrawTitle(cRectY, property);
                }
            }

            if (!layer.Drawable)
            {
                layer.LegendIndex = iIndex;

                if (this.ChartSetting.IsShowNewPrice)                      //是否要顯示新價格線
                {
                    this.AxisY.Value = __cBars.Close[0];                   //指定最新收盤價格
                    this.Painter.DrawAxisValueLabel(this.AxisY, this.ChartSetting.LegendColor, property);
                }
            }
            this.DrawLegend(layer.LegendIndex, property);

            __cGDI.SelectBackground(iOldBKColor);
            return(true);
        }
Esempio n. 5
0
        private void DrawTextObject(Layer layer, TextObject textObject, ChartProperty property, bool useROP)
        {
            AxisX     cAxisX = layer.AxisX;
            AxisY     cAxisY = layer.AxisY;
            Rectangle cRectY = cAxisY.AxisRectangle;

            int    iOldBackground = 0;
            IntPtr iOldFont       = IntPtr.Zero;
            bool   bUseBG         = textObject.BGColor != property.BackgroundColor;
            bool   bUseFont       = textObject.FontName != property.TextFont.Name || textObject.Size != property.TextFont.Size;

            if (bUseBG)
            {
                iOldBackground = __cGDI.SelectBackground(textObject.BGColor);
            }
            else
            {
                iOldBackground = __cGDI.SelectTransparent();
            }

            if (bUseFont)
            {
                iOldFont = __cGDI.SelectFont(new Font(textObject.FontName, textObject.Size, textObject.Style));
            }

            int        iX = 0, iY = 0;
            ChartPoint cPoint    = textObject.Location;
            bool       bAbsolute = textObject.AbsolutePosition;

            if (bAbsolute)
            {
                iY = cRectY.Y + (int)cPoint.Price;
                iX = cPoint.BarNumber.Value;
            }
            else
            {
                iY = cRectY.Y + cAxisY.ConvertValueToHeight(cPoint.Price) + 1;
                AxisXUnit cUnit = cAxisX.ConvertBarNumberToWidth(cPoint.BarNumber.Value);
                Size      cSize = __cGDI.MeasureString(textObject.Text);

                iY = CalculateYFromStyle(iY, cSize, textObject.VStyle);
                iX = CalculateXFromStyle(cUnit.CenterPoint, cSize, textObject.HStyle);
            }

            Rectangle cLayerRect = layer.LayerRectangleWithoutAxisY;

            if (useROP || bAbsolute)
            {
                __cGDI.BeginRopDraw();
                __cGDI.DrawRopString(textObject.Text, textObject.Color, iX, iY);
                __cGDI.EndRopDraw();
            }
            else
            {
                __cGDI.DrawString(textObject.Text, textObject.Color, iX, iY);
            }

            if (bUseFont)
            {
                __cGDI.RemoveObject(__cGDI.SelectFont(iOldFont));
            }

            if (bUseBG)
            {
                __cGDI.SelectBackground(iOldBackground);
            }
            else
            {
                __cGDI.ClearTransparent(iOldBackground);
            }
        }
Esempio n. 6
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;
                }
            }
        }
Esempio n. 7
0
        public override bool DrawPlot(Layer layer, ChartProperty property, bool onlyUpdateLastBar)
        {
            AxisX     cAxisX = layer.AxisX;
            Rectangle cRectY = this.AxisY.AxisRectangle;

            int iIndex      = 0;
            int iOldBKColor = __cGDI.SelectBackground(property.BackgroundColor);

            PowerLanguage.PenStyle cLinePen = this.ChartSetting.PenStyles[0];
            IntPtr cOldPen = __cGDI.SelectPen(cLinePen);

            if (onlyUpdateLastBar)
            {
                iIndex = cAxisX.BarNumber + cAxisX.BarCount - 1;
                iIndex = (iIndex > cAxisX.DataCount) ? cAxisX.DataCount : iIndex;
                int iOffset = this.ConvertAxisScaleIndexToOffset(iIndex);
                int iX      = cAxisX.ConvertBarNumberToWidth(iIndex).CenterPoint;
                int iPrevX  = cAxisX.ConvertBarNumberToWidth(iIndex - 1).CenterPoint;
                if (!DrawClosingLine(iOffset, cRectY.Y, iX, iPrevX, new PowerLanguage.PenStyle(property.BackgroundColor, cLinePen.Width, cLinePen.Pattern)))
                {
                    return(false);
                }
            }
            else
            {
                this.RefreshAxisY(property);

                __dPrevClose = double.NaN;
                int iCount      = cAxisX.BarCount;
                int iStartIndex = cAxisX.BarNumber;
                for (int i = 0; i < iCount; i++)
                {
                    iIndex = iStartIndex + i;
                    if (iIndex > cAxisX.DataCount)
                    {
                        --iIndex;
                        break;
                    }
                    else
                    {
                        if (__dPrevClose != double.NaN)
                        {
                            int iOffset = this.ConvertAxisScaleIndexToOffset(iIndex);
                            int iX      = cAxisX.ConvertBarNumberToWidth(iIndex).CenterPoint;
                            int iPrevX  = cAxisX.ConvertBarNumberToWidth(iIndex - 1).CenterPoint;
                            DrawClosingLine(iOffset, cRectY.Y, iX, iPrevX, null);
                        }
                    }
                }

                if (this.PlotIndex == 0)                    //Plot 索引值為 0 才印出標題(其他的索引就不需要再印出標題)
                {
                    DrawTitle(cRectY, property);
                }
            }
            __cGDI.RemoveObject(__cGDI.SelectPen(cOldPen));

            if (!layer.Drawable)
            {
                layer.LegendIndex = iIndex;

                if (this.ChartSetting.IsShowNewPrice)                      //是否要顯示新價格線
                {
                    this.AxisY.Value = __cBars.Close[0];                   //指定最新收盤價格
                    this.Painter.DrawAxisValueLabel(this.AxisY, this.ChartSetting.LegendColor, property);
                }
            }
            this.DrawLegend(layer.LegendIndex, property);

            __cGDI.SelectBackground(iOldBKColor);
            return(true);
        }