Пример #1
0
        /// <summary>
        /// Called to actually render the game content to the backbuffer, which will be flipped with
        /// the currently displayed buffer to show the next frame.
        /// </summary>
        /// <param name="gameTime">Current time information of the application</param>
        protected override void Draw(GameTime gameTime)
        {
            Rectangle      CircleDest;
            int            nVertCtr, nPolyCtr;
            List <Vector2> VertList = new List <Vector2>();
            List <Vector2> CurveVerts;
            Rectangle      rectCurveBounds;
            Texture2D      LineTexture = new Texture2D(GraphicsDevice, 1, 1);

            LineTexture.SetData(new[] { Color.Cyan });

            cGraphDevMgr.GraphicsDevice.Clear(Color.Black);
            cDrawBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);

            for (nPolyCtr = 0; nPolyCtr < cPolyList.Count; nPolyCtr++)
            {
                VertList.Clear();
                VertList.AddRange(cPolyList[nPolyCtr].GetVertexes(false));

                //Draw circles at each vertex
                for (nVertCtr = 0; nVertCtr < VertList.Count; nVertCtr++)
                {
                    CircleDest.X      = (int)(VertList[nVertCtr].X - CIRCLERADIUS);
                    CircleDest.Y      = (int)(VertList[nVertCtr].Y - CIRCLERADIUS);
                    CircleDest.Height = CIRCLERADIUS * 2;
                    CircleDest.Width  = CIRCLERADIUS * 2;

                    cDrawBatch.Draw(cCircleTexture, CircleDest, Color.Gray);
                }

                //Draw the polygons
                cPolyList[nPolyCtr].Draw();
            }

            VertList.Clear();
            VertList.AddRange(cPolyList[1].GetVertexes(false));
            MGMath.CubicBezierCurvePoints(VertList[0], VertList[3], VertList[1], VertList[2], 10, out CurveVerts);

            MGMath.CubicBezierCurveBoundaries(VertList[0], VertList[3], VertList[1], VertList[2], out rectCurveBounds);

            DrawTools.DrawLineSeries(GraphicsDevice, cDrawBatch, Color.LightYellow, 2, CurveVerts);
            DrawTools.DrawRectangle(GraphicsDevice, cDrawBatch, Color.RosyBrown, 2, rectCurveBounds);

            //Always draw console last
            cDevConsole.Draw(cDrawBatch);

            cDrawBatch.End();

            //Use monogame draw
            base.Draw(gameTime);
        }
Пример #2
0
        public void DrawVolume(Rect camRect)
        {
            if (!IsSettingsSet)
            {
                return;
            }

            float worldRealToScreen = (CoordGrid.FromDateToXAxis(visibleEndDate) - CoordGrid.FromDateToXAxis(visibleStartDate)) / (worldPointInRightUpCorner.x - worldPointInLeftDownCorner.x);


            int   count            = DateTimeTools.CountFramesInPeriod(chartDataManager.TFrame, visibleStartDate, visibleEndDate, TimeSpan.Zero);
            float pixelLenghtFrame = camRect.width * worldRealToScreen / count;
            float maxVolume        = (float)visibleFluctuations.Max(x => x.Volume);

            //Если свечка видна только частично, то необходимо смещать отрисовку объёма на равную долю видимости
            float   diff = (worldPointInLeftDownCorner.x - CoordGrid.FromDateToXAxis(visibleStartDate)) * camRect.width / (worldPointInRightUpCorner.x - worldPointInLeftDownCorner.x);
            Vector2 barLeftDownCorner = camRect.min - new Vector2(diff + pixelLenghtFrame / 2, 0);
            Vector2 barRightUpCorner;
            Vector2 bordersOffset = new Vector2((20 / count < 1 ? 1 : 20 / count), 0);

            if (chartDataManager.WorkBeginTime > visibleStartDate)
            {
                int shift = DateTimeTools.CountFramesInPeriod(chartDataManager.TFrame, visibleStartDate, chartDataManager.WorkBeginTime, TimeSpan.Zero);
                barLeftDownCorner += new Vector2(shift * pixelLenghtFrame, 0);
            }

            foreach (var fluctuation in visibleFluctuations)
            {
                float pixelHeightFrame = (float)fluctuation.Volume / maxVolume * camRect.height;
                barRightUpCorner = barLeftDownCorner + new Vector2(pixelLenghtFrame, pixelHeightFrame);

                DrawTools.DrawRectangle(barLeftDownCorner + bordersOffset, barRightUpCorner - bordersOffset, fluctuation.Close - fluctuation.Open > 0 ? volumeUpColor : volumeDownColor);

                barLeftDownCorner = new Vector2(barRightUpCorner.x, camRect.min.y);
            }
        }