Skip to content

Commit 25976bd

Browse files
committed
C++ lexer
1 parent 890e28a commit 25976bd

6 files changed

Lines changed: 90 additions & 11 deletions

File tree

3DRadSpace/3DRadSpace.slnx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
<Configurations>
33
<Platform Name="x64" />
44
</Configurations>
5-
<Project Path="D:/Projects/3D_Rad_Space/3DRadSpace/Dummy/Dummy.vcxproj" Id="d87f5240-7a4a-fb1f-f513-330b76252c7e" />
5+
<Project Path="Dummy/Dummy.vcxproj" Id="d87f5240-7a4a-fb1f-f513-330b76252c7e" />
66
</Solution>

3DRadSpace/3DRadSpace_Editor_WindowsDX11/Frontend/Windows/EditObjectDialog.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ EditObjectDialog::EditObjectDialog(HWND owner, HINSTANCE hInstance, ReflectedObj
105105
assert(data != nullptr);
106106
}
107107

108+
static std::unordered_map<std::string, int> attribMap =
109+
{
110+
{"HelpURL", 1},
111+
{"Title", 2 },
112+
{"CustomWindow", 3}
113+
};
114+
108115
void EditObjectDialog::createForms()
109116
{
110117
int x = 5;
@@ -127,13 +134,6 @@ void EditObjectDialog::createForms()
127134
{
128135
auto name = attribute->FieldName();
129136

130-
std::unordered_map<std::string, int> attribMap =
131-
{
132-
{"HelpURL", 1},
133-
{"Title", 2 },
134-
{"CustomWindow", 3}
135-
};
136-
137137
switch (attribMap[name])
138138
{
139139
case 1:

3DRadSpace/Engine3DRadSpace/Scripting/CSharp/CSharpScript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ REFL_BEGIN(CSharpScript, "C# Script", "Scripting", "C# script")
7979
REFL_FIELD(CSharpScript, std::string, Name, "Name", "C# Script", "Name of the script object")
8080
REFL_FIELD(CSharpScript, bool, Enabled, "Enabled", true, "Whether the script is enabled or not")
8181
REFL_FIELD(CSharpScript, std::string, ScriptPath, "Script path", "", "Path to script file")
82-
REFL_FIELD(CSharpScript, std::string, Class, "Entry classname", "", "Path to script file")
82+
REFL_FIELD(CSharpScript, std::string, Class, "Entry classname", "", "Name of the class being constructed")
8383
REFL_ATTR("CustomWindow", "CreateCSharpEditorWindow")
8484
REFL_END

3DRadSpace/Engine3DRadSpace/Scripting/CSharp/CSharpScriptEditor.cpp

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
#include "CSharpScriptEditor.hpp"
22
#include "../../Logging/Warning.hpp"
3+
#include <scintilla/Scintilla.h>
4+
#include <scintilla/ILexer.h>
5+
#include <lexilla/SciLexer.h>
6+
#include <lexilla/Lexilla.h>
37

48
using namespace Engine3DRadSpace::Scripting::CSharp;
59

10+
static Scintilla::ILexer5* cpplexer = nullptr;
11+
612
INT_PTR CALLBACK CSharpEditorDlgProc(
713
HWND hwndDlg,
814
UINT message,
@@ -92,10 +98,11 @@ CSharpScriptEditor::CSharpScriptEditor(
9298
_wasAllocated(false)
9399
{
94100
static bool wasScintillaModuleLoaded = false;
101+
static bool wasLexillaModuleLoaded = false;
95102

96103
if (!wasScintillaModuleLoaded)
97104
{
98-
auto scintillaModule = LoadLibrary("Scintilla.dll");
105+
auto scintillaModule = LoadLibraryA("Scintilla.dll");
99106
if (scintillaModule == NULL)
100107
{
101108
WNDCLASSA scintillaClass{};
@@ -111,6 +118,25 @@ CSharpScriptEditor::CSharpScriptEditor(
111118
wasScintillaModuleLoaded = true;
112119
}
113120

121+
if (!wasLexillaModuleLoaded && !cpplexer)
122+
{
123+
wasLexillaModuleLoaded = true;
124+
125+
auto lexillaModule = LoadLibraryA("Lexilla.dll");
126+
if (lexillaModule == nullptr)
127+
{
128+
Logging::SetLastWarning("Lexilla wasn't loaded, syntax highlighting will not work.");
129+
}
130+
131+
Lexilla::CreateLexerFn createLexer = reinterpret_cast<Lexilla::CreateLexerFn>(GetProcAddress(lexillaModule, "CreateLexer"));
132+
if (createLexer == nullptr)
133+
{
134+
Logging::SetLastWarning("Lexilla CreateLexer function not found, syntax highlighting will not work.");
135+
}
136+
137+
cpplexer = createLexer("cpp");
138+
}
139+
114140
if (object == nullptr)
115141
{
116142
_script = new CSharpScript();
@@ -133,6 +159,53 @@ void CSharpScriptEditor::initForms()
133159

134160
HWND classNameTextbox = GetDlgItem(_window, IDC_EDIT2);
135161
SetWindowTextA(classNameTextbox, _script->Class.c_str());
162+
163+
HWND scintilla = GetDlgItem(_window, IDC_CUSTOM1);
164+
if (!scintilla)
165+
{
166+
167+
}
168+
169+
SendMessageA(scintilla, SCI_SETILEXER, 0, reinterpret_cast<LPARAM>(cpplexer));
170+
171+
// Reset and clear styles
172+
SendMessageA(scintilla, SCI_STYLERESETDEFAULT, 0, 0);
173+
SendMessageA(scintilla, SCI_STYLECLEARALL, 0, 0);
174+
175+
// Set default font and size
176+
SendMessageA(scintilla, SCI_STYLESETFONT, SCE_C_DEFAULT, reinterpret_cast<LPARAM>("Consolas"));
177+
SendMessageA(scintilla, SCI_STYLESETSIZE, SCE_C_DEFAULT, 10);
178+
179+
// Configure the CPP (C#) lexer styles
180+
SendMessageA(scintilla, SCI_STYLESETFORE, SCE_C_DEFAULT, RGB(192, 192, 192)); // Silver
181+
SendMessageA(scintilla, SCI_STYLESETFORE, SCE_C_COMMENT, RGB(0, 128, 0)); // Green
182+
SendMessageA(scintilla, SCI_STYLESETFORE, SCE_C_COMMENTLINE, RGB(0, 128, 0)); // Green
183+
SendMessageA(scintilla, SCI_STYLESETFORE, SCE_C_COMMENTDOC, RGB(128, 128, 128)); // Gray
184+
SendMessageA(scintilla, SCI_STYLESETFORE, SCE_C_NUMBER, RGB(128, 128, 0)); // Olive
185+
SendMessageA(scintilla, SCI_STYLESETFORE, SCE_C_WORD, RGB(0, 0, 255)); // Blue
186+
SendMessageA(scintilla, SCI_STYLESETFORE, SCE_C_WORD2, RGB(0, 0, 255)); // Blue
187+
SendMessageA(scintilla, SCI_STYLESETFORE, SCE_C_STRING, RGB(163, 21, 21)); // Red
188+
SendMessageA(scintilla, SCI_STYLESETFORE, SCE_C_CHARACTER, RGB(163, 21, 21)); // Red
189+
SendMessageA(scintilla, SCI_STYLESETFORE, SCE_C_VERBATIM, RGB(163, 21, 21)); // Red
190+
SendMessageA(scintilla, SCI_STYLESETBACK, SCE_C_STRINGEOL, RGB(255, 192, 203)); // Pink
191+
SendMessageA(scintilla, SCI_STYLESETFORE, SCE_C_OPERATOR, RGB(128, 0, 128)); // Purple
192+
SendMessageA(scintilla, SCI_STYLESETFORE, SCE_C_PREPROCESSOR, RGB(128, 0, 0)); // Maroon
193+
194+
SendMessageA(scintilla, SCI_SETKEYWORDS, 0, reinterpret_cast<WPARAM>(
195+
"abstract as base break case catch checked continue default delegate do else event explicit extern false finally "
196+
"fixed for foreach goto if implicit in interface internal is lock namespace new null object operator out override "
197+
"params private protected public readonly ref return sealed sizeof stackalloc switch this throw true try typeof "
198+
" unchecked unsafe using virtual while"
199+
));
200+
201+
SendMessageA(scintilla, SCI_SETKEYWORDS, 1, reinterpret_cast<WPARAM>(
202+
"bool byte char class const decimal double enum float int long sbyte short static string struct uint ulong ushort void"
203+
));
204+
205+
SendMessageA(scintilla, SCI_SETKEYWORDS, 2, reinterpret_cast<WPARAM>(
206+
"add alias ascending async await by descending dynamic equals from get global group into join let nameof on orderby partial "
207+
"remove select set value var when where yield"
208+
));
136209
}
137210

138211
CSharpScript* CSharpScriptEditor::ShowDialog()

3DRadSpace/Engine3DRadSpace/Scripting/CSharp/CSharpScriptEditor.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ namespace Engine3DRadSpace::Scripting::CSharp
3131
CSharpScript* object
3232
);
3333

34+
CSharpScriptEditor(const CSharpScriptEditor&) = delete;
35+
CSharpScriptEditor& operator=(const CSharpScriptEditor&) = delete;
36+
37+
CSharpScriptEditor(CSharpScriptEditor&&) = delete;
38+
CSharpScriptEditor& operator=(CSharpScriptEditor&&) = delete;
39+
3440
CSharpScript* ShowDialog();
3541

3642
friend INT_PTR CALLBACK ::CSharpEditorDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam);

3DRadSpace/Engine3DRadSpace_Tests/Main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int WinMain(
5353
int main(int argc, char** argv) {
5454
::testing::InitGoogleTest(&argc, argv);
5555

56-
WinMain(GetModuleHandle(NULL), NULL, GetCommandLineA(), SW_SHOWDEFAULT);
56+
//WinMain(GetModuleHandle(NULL), NULL, GetCommandLineA(), SW_SHOWDEFAULT);
5757

5858
return RUN_ALL_TESTS();
5959
}

0 commit comments

Comments
 (0)