protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { // Create a Font, Brush and TextFormat to draw our text. // For more information on drawing Text, please see the source code for the Text DrawingTool var font = new Gui.Tools.SimpleFont("Arial", 20); SharpDX.Direct2D1.Brush tmpBrush = Brushes.Red.ToDxBrush(RenderTarget); SharpDX.DirectWrite.TextFormat textFormat = font.ToDirectWriteTextFormat(); // Create a TextLayout for our text to draw. var cachedTextLayout = new SharpDX.DirectWrite.TextLayout(Core.Globals.DirectWriteFactory, "Hello, I am sideways text.", textFormat, 600, textFormat.FontSize); // Rotate the RenderTarget by setting the Matrix3x2 Transform property // Matrix3x2.Rotation() will return a rotated Matrix3x2 based off of the angle specified, and the center point where you draw the object RenderTarget.Transform = Matrix3x2.Rotation(1.5708f, new Vector2(100, 100)); // Draw the text on the rotated RenderTarget RenderTarget.DrawTextLayout(new SharpDX.Vector2(100, 100), cachedTextLayout, tmpBrush, SharpDX.Direct2D1.DrawTextOptions.NoSnap); // Dispose of resources textFormat.Dispose(); cachedTextLayout.Dispose(); tmpBrush.Dispose(); // Rotate the RenderTarget back RenderTarget.Transform = Matrix3x2.Identity; // Return rendering to base class base.OnRender(chartControl, chartScale); }
protected void DrawPriceLevelText(double minX, double maxX, Point endPoint, PriceLevel priceLevel, ChartPanel panel) { Gui.Tools.SimpleFont wpfFont = panel.ChartControl.Properties.LabelFont ?? new Gui.Tools.SimpleFont(); SharpDX.DirectWrite.TextFormat dxTextFormat = wpfFont.ToDirectWriteTextFormat(); string str = string.Format("{0}", (priceLevel.Value / 100).ToString("P")); SharpDX.DirectWrite.TextLayout textLayout = new SharpDX.DirectWrite.TextLayout(Core.Globals.DirectWriteFactory, str, dxTextFormat, panel.H, dxTextFormat.FontSize); float usedFontHeight = textLayout.Metrics.Height; float usedFontWidth = textLayout.Metrics.Width; Point textEndPoint = endPoint; double maxWidth = panel.X + panel.W; double maxHeight = panel.Y + panel.H; double minWidth = panel.X; double minHeight = panel.Y; if (textEndPoint.Y + usedFontHeight >= maxHeight) { textEndPoint.Y = maxHeight - usedFontHeight; // Set to bottom } if (textEndPoint.Y < minHeight) // Set to top { textEndPoint.Y = minHeight; } if (textEndPoint.X + usedFontWidth >= maxWidth) { textEndPoint.X = maxWidth - usedFontWidth; //Set to right side; } if (textEndPoint.X < minWidth) { textEndPoint.X = minWidth; // Set to left side; } RenderTarget.DrawTextLayout(new SharpDX.Vector2((float)(textEndPoint.X), (float)(textEndPoint.Y)), textLayout, priceLevel.Stroke.BrushDX, SharpDX.Direct2D1.DrawTextOptions.NoSnap); dxTextFormat.Dispose(); textLayout.Dispose(); }