예제 #1
0
        protected override void DrawLegend(int barNumber, ChartProperty property)
        {
            int       iDecimals    = this.AxisY.Decimals;
            Rectangle cRectY       = this.AxisY.AxisRectangle;
            IntPtr    cOldFont     = __cGDI.SelectFont(__cLegendFont);
            Size      cFontMetrics = __cGDI.MeasureString("0");

            __cGDI.BeginRopDraw();

            List <ITrade> cTrades = __cTrades.GetTradeObject(barNumber);
            int           iRow = 0, iCount = cTrades.Count;

            for (int i = 0; i < iCount; i++)
            {
                ITrade      cTrade      = cTrades[i];
                ITradeOrder cEntry      = cTrade.EntryOrder;
                string      sEntryOrder = string.Format("#{0} {1,-10} {2} at {3} {4}", cEntry.Ticket, cEntry.Action, cEntry.Contracts, Math.Round(cEntry.Price, iDecimals), cEntry.Time.ToString("yyyy-MM-dd HH:mm:ss"));
                __cGDI.DrawRopString(sEntryOrder, this.ChartSetting.LegendColor, cRectY.X - (sEntryOrder.Length * cFontMetrics.Width) - 4, cRectY.Top + ((iRow++ *cFontMetrics.Height) + 2));

                ITradeOrder cExit = cTrade.ExitOrder;
                if (cExit != null)
                {
                    string sExitOrder = string.Format("#{0} {1,-10} {2} at {3} {4}", cExit.Ticket, cExit.Action, cExit.Contracts, Math.Round(cExit.Price, iDecimals), cExit.Time.ToString("yyyy-MM-dd HH:mm:ss"));
                    __cGDI.DrawRopString(sExitOrder, this.ChartSetting.LegendColor, cRectY.X - (sExitOrder.Length * cFontMetrics.Width) - 4, cRectY.Top + ((iRow++ *cFontMetrics.Height) + 2));
                }
            }
            __cGDI.EndRopDraw();
            __cGDI.RemoveObject(__cGDI.SelectFont(cOldFont));
        }
예제 #2
0
        protected override void DrawLegend(int barNumber, ChartProperty property)
        {
            Rectangle cRectY    = this.AxisY.AxisRectangle;
            IntPtr    cOldFont  = __cGDI.SelectFont(property.LegendFont);
            int       iDecimals = this.AxisY.Decimals;
            int       iTextY    = ((this.PlotIndex + 1) * __cGDI.MeasureString("0").Height) + 5;
            int       iOffset   = this.ConvertAxisScaleIndexToOffset(barNumber);
            string    sLegend   = string.Format("{0} (O:{1}, H:{2}, L:{3}, C:{4}, V:{5})", __cBars.Time[iOffset].ToString("yyyy/MM/dd HH:mm"), Math.Round(__cBars.Open[iOffset], iDecimals), Math.Round(__cBars.High[iOffset], iDecimals), Math.Round(__cBars.Low[iOffset], iDecimals), Math.Round(__cBars.Close[iOffset], iDecimals), __cBars.Volume[iOffset]);

            __cGDI.BeginRopDraw();
            __cGDI.DrawRopString(sLegend, this.ChartSetting.LegendColor, 5, cRectY.Top + iTextY);
            __cGDI.EndRopDraw();
            __cGDI.RemoveObject(__cGDI.SelectFont(cOldFont));
        }
예제 #3
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);
            }
        }
예제 #4
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;
                }
            }
        }