-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathOnChartLogging.cpp
More file actions
100 lines (89 loc) · 3.23 KB
/
OnChartLogging.cpp
File metadata and controls
100 lines (89 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) 2025 Chek Wei Tan
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
#include "OnChartLogging.hpp"
#include "Enum.hpp"
namespace OnChartLogging
{
std::vector<SCString> *GetLogMessagesVector(SCStudyInterfaceRef sc)
{
auto *logMessages = reinterpret_cast<std::vector<SCString> *>(sc.GetPersistentPointer(PersistentVars::LogMessagesPtr));
if (logMessages == nullptr)
{
logMessages = new std::vector<SCString>();
sc.SetPersistentPointer(PersistentVars::LogMessagesPtr, logMessages);
}
return logMessages;
}
void AddLog(SCStudyInterfaceRef sc, const SCString &message, const SCString &fontFace)
{
int &enableLog = sc.GetPersistentIntFast(PersistentVars::EnableLog);
if (enableLog == 0)
return;
sc.AddMessageToLog(message, 0);
auto *logMessages = GetLogMessagesVector(sc);
int &maxLogLines = sc.GetPersistentIntFast(PersistentVars::MaxLogLines);
if (logMessages->size() >= maxLogLines)
{
logMessages->erase(logMessages->begin());
}
logMessages->push_back(message);
int &enableShowLogOnChart = sc.GetPersistentIntFast(PersistentVars::EnableShowLogOnChart);
if (enableShowLogOnChart != 0)
{
DrawLogs(sc, fontFace);
}
}
void DrawLogs(SCStudyInterfaceRef sc, const SCString &fontFace)
{
int &textDrawingLineNumber = sc.GetPersistentIntFast(PersistentVars::LogDrawingLineNumber);
auto *logMessages = GetLogMessagesVector(sc);
if (logMessages->empty())
{
// If there are no messages but the drawing exists, delete it.
if (textDrawingLineNumber != 0)
{
sc.DeleteUserDrawnACSDrawing(sc.ChartNumber, textDrawingLineNumber);
textDrawingLineNumber = 0;
}
return;
}
SCString logText;
for (const auto &msg : *logMessages)
{
logText += msg;
logText += "\n";
}
s_UseTool tool;
tool.Clear();
tool.ChartNumber = sc.ChartNumber;
tool.DrawingType = DRAWING_TEXT;
tool.Region = sc.GraphRegion;
tool.LineNumber = textDrawingLineNumber;
tool.AddMethod = UTAM_ADD_OR_ADJUST;
tool.AddAsUserDrawnDrawing = 1;
tool.AllowSaveToChartbook = 0;
tool.UseRelativeVerticalValues = true;
tool.BeginDateTime = 5;
tool.BeginValue = 95;
tool.Color = RGB(255, 255, 255);
tool.Text = logText;
tool.FontSize = 10;
tool.TextAlignment = DT_LEFT | DT_TOP;
tool.FontFace = "Consolas";
if (sc.UseTool(tool) > 0)
{
textDrawingLineNumber = tool.LineNumber;
}
}
void ClearLogs(SCStudyInterfaceRef sc)
{
int &textDrawingLineNumber = sc.GetPersistentIntFast(PersistentVars::LogDrawingLineNumber);
auto *logMessages = GetLogMessagesVector(sc);
logMessages->clear();
if (textDrawingLineNumber != 0)
{
sc.DeleteUserDrawnACSDrawing(sc.ChartNumber, textDrawingLineNumber);
textDrawingLineNumber = 0;
}
}
}