Login Page - Create Account

Support Board


Date/Time: Mon, 25 Nov 2024 11:39:10 +0000



Post From: GDI Flickering

[2024-03-15 20:24:51]
TPH_Main - Posts: 13
I have tried the code below with Open GL enabled and not enabled.
Basically if I have two charts open
1. apply this study.
2. change x/y inputs of the study on one chart
3. Flickering happens or the indicator is being redrawn in both the old input settings and the new input settings.


#pragma once

struct LabelSettings
{
int xPosition;
int yPosition;
int alignment;
int fontSize;
COLORREF fontColor;
COLORREF bgColor;
COLORREF invalidBgColor;
};

LabelSettings LabelSettings;

// FUNCTION: Draw Info
void DrawLabel(HWND WindowHandle,
HDC DeviceContext,
SCStudyInterfaceRef sc)
{
// Set drawing font
n_ACSIL::s_GraphicsFont GraphicsFont;
GraphicsFont.m_FaceName = sc.ChartTextFont();
GraphicsFont.m_Height = LabelSettings.fontSize;
GraphicsFont.m_Weight = FW_BOLD;
sc.Graphics.SetTextFont(GraphicsFont);

// Set colors
n_ACSIL::s_GraphicsColor fontColor;
fontColor.SetColorValue(LabelSettings.fontColor);
sc.Graphics.SetTextColor(fontColor);

n_ACSIL::s_GraphicsColor GraphicsColor;
GraphicsColor.SetColorValue(LabelSettings.bgColor);
sc.Graphics.SetBackgroundColor(GraphicsColor);

// Set position
int width = sc.ChartRegion1RightCoordinate - sc.ChartRegion1LeftCoordinate;
int height = sc.ChartRegion1BottomCoordinate - sc.ChartRegion1TopCoordinate;

int xPosition = width * LabelSettings.xPosition / 100.00;
int yPosition = height * LabelSettings.yPosition / 100.00;
switch (LabelSettings.alignment)
{
case 0:
sc.Graphics.SetTextAlign(TA_LEFT);
break;
case 1:
sc.Graphics.SetTextAlign(TA_CENTER);
break;
case 2:
sc.Graphics.SetTextAlign(TA_RIGHT);
break;
default:
sc.Graphics.SetTextAlign(TA_CENTER);
break;
}

// Draw
sc.Graphics.DrawTextAt("testing 123", xPosition, yPosition);
}

SCSFExport scsf_Test_GDILabels(SCStudyInterfaceRef sc)
{

int inputNum = -1;
SCInputRef Input_FontxPOS = sc.Input[++inputNum];
SCInputRef Input_FontyPOS = sc.Input[++inputNum];
SCInputRef Input_FontAlignment = sc.Input[++inputNum];

SCInputRef Input_FontSize = sc.Input[++inputNum];
SCInputRef Input_FontColorCSS = sc.Input[++inputNum];
SCInputRef Input_BgColorCSS = sc.Input[++inputNum];
SCInputRef Input_InvalidBgColorCSS = sc.Input[++inputNum];

if (sc.SetDefaults)
{
sc.GraphName = "Test";
sc.GraphRegion = 0;
sc.AutoLoop = 0;
// sc.UpdateAlways = 1;

sc.HideDLLAndFunctionNames = 1;
sc.HideStudy = 0;
sc.IncludeInStudySummary = 0;
sc.IncludeInSpreadsheet = 0;
sc.AlertConditionEnabled = 0;
sc.DisplayStudyInputValues = 0;
sc.DisplayStudyName = 0;
sc.GlobalDisplayStudySubgraphsNameAndValue = 0;
sc.ProtectStudy = 1;
sc.CalculationPrecedence = STD_PREC_LEVEL;

Input_FontxPOS.Name = "Label x Position";
Input_FontxPOS.SetInt(100);
Input_FontxPOS.SetIntLimits(1, 100);

Input_FontyPOS.Name = "Label y Position";
Input_FontyPOS.SetInt(3);
Input_FontyPOS.SetIntLimits(1, 100);

Input_FontAlignment.Name = "Label Alignment";
Input_FontAlignment.SetCustomInputStrings("Left;Center;Right");
Input_FontAlignment.SetCustomInputIndex(2);

Input_FontSize.Name = "Font Size";
Input_FontSize.SetInt(10);
Input_FontSize.SetIntLimits(6, 36);

Input_FontColorCSS.Name = "Font Color";
Input_FontColorCSS.SetColor(255, 255, 255);

Input_BgColorCSS.Name = "Background Color";
Input_BgColorCSS.SetColor(90, 100, 113);

Input_InvalidBgColorCSS.Name = "Invalid Background Color";
Input_InvalidBgColorCSS.SetColor(255, 0, 255);
}

// Set Colors
LabelSettings.xPosition = Input_FontxPOS.GetInt();
LabelSettings.yPosition = Input_FontyPOS.GetInt();
LabelSettings.alignment = Input_FontAlignment.GetIndex();
LabelSettings.fontSize = Input_FontSize.GetInt();
LabelSettings.fontColor = Input_FontColorCSS.GetColor();
LabelSettings.bgColor = Input_BgColorCSS.GetColor();
LabelSettings.invalidBgColor = Input_InvalidBgColorCSS.GetColor();

// Hook drawing function
sc.p_GDIFunction = DrawLabel;
}