コード例 #1
0
        private bool DrawOhlc(int offset, int top, AxisXUnit unit, Color eraseColor)
        {
            double[] dValues = null;
            bool     bCheck  = CheckBarsValue(offset, out dValues);

            if (bCheck)
            {
                int iOpen  = top + this.AxisY.ConvertValueToHeight(dValues[0]);
                int iHigh  = top + this.AxisY.ConvertValueToHeight(dValues[1]);
                int iLow   = top + this.AxisY.ConvertValueToHeight(dValues[2]);
                int iClose = top + this.AxisY.ConvertValueToHeight(dValues[3]);

                if (eraseColor != Color.Empty)
                {
                    __cGDI.FillRectangle(eraseColor, unit.LeftPoint + 1, iHigh, (unit.RightPoint - unit.LeftPoint) - 1, iLow - iHigh + 1);
                }

                bool   bOpenH  = iOpen < iClose;
                IntPtr cOldPtr = __cGDI.SelectPen((bOpenH) ? this.ChartSetting.PenStyles[1] : this.ChartSetting.PenStyles[0]);

                __cGDI.DrawLine(unit.CenterPoint, iHigh, unit.CenterPoint, iLow);
                __cGDI.DrawLine(unit.LeftPoint + 1, iOpen, unit.CenterPoint, iOpen);
                __cGDI.DrawLine(unit.CenterPoint, iClose, unit.RightPoint, iClose);
                __cGDI.RemoveObject(__cGDI.SelectPen(cOldPtr));
            }
            return(bCheck);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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);
            }
        }
コード例 #5
0
ファイル: Cross.cs プロジェクト: mirror222/ZeroSystem
        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;
                }
            }
        }