Support Board
Date/Time: Tue, 26 Nov 2024 14:42:30 +0000
Post From: How to center text using sc.Graphics.DrawText?
[2023-11-24 01:02:39] |
LudaTrades - Posts: 27 |
#include "sierrachart.h"
SCDLLName("OpenGL GDI Centered Text Test") // http://msdn.microsoft.com/en-nz/library/windows/desktop/dd145203%28v=vs.85%29.aspx void DrawToChart(HWND WindowHandle, HDC DeviceContext, SCStudyInterfaceRef sc); SCSFExport scsf_DrawToChartTest_CenteredText(SCStudyInterfaceRef sc) { if (sc.SetDefaults) { // Set the configuration and defaults sc.GraphName = "OpenGL GDI Centered Text Test"; sc.GraphRegion = 0; sc.AutoLoop = 0; return; } sc.p_GDIFunction = DrawToChart; } void DrawToChart(HWND WindowHandle, HDC DeviceContext, SCStudyInterfaceRef sc ) { //Text SCString TextToDraw; TextToDraw.Format("This text should be centered."); n_ACSIL::s_GraphicsFont GraphicsFont; n_ACSIL::s_GraphicsColor TextGraphicsColor; GraphicsFont.m_Height = 16; GraphicsFont.m_Weight = FW_BOLD; TextGraphicsColor.SetRGB(255, 255, 255); sc.Graphics.SetTextFont(GraphicsFont); sc.Graphics.SetTextAlign(TA_CENTER); sc.Graphics.SetTextColor(TextGraphicsColor); //Rectangle n_ACSIL::s_GraphicsRectangle TextRectangle; n_ACSIL::s_GraphicsColor BackgroundGraphicsColor; BackgroundGraphicsColor.SetRGB(64, 128, 0); sc.Graphics.SetBackgroundColor(BackgroundGraphicsColor); TextRectangle.Left = 100; TextRectangle.Top = 100; TextRectangle.Right = 500; TextRectangle.Bottom = 500; // Draw the text centered //int32_t (SCDLLCALL* DrawText)(const SCString& Text, n_ACSIL::s_GraphicsRectangle& r_Rectangle, const uint32_t Flags); int result = sc.Graphics.DrawText(TextToDraw, TextRectangle, DT_CENTER | DT_VCENTER | DT_SINGLELINE); return; } Using these center flags from the Microsoft GDI docs and also sc.Graphics.SetTextAlign but I'm unable to get the text to center. |
Sierra_openGL_GDI_centered_text.png / V - Attached On 2023-11-24 01:02:06 UTC - Size: 9.79 KB - 118 views |