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
48using namespace Engine3DRadSpace ::Scripting::CSharp;
59
10+ static Scintilla::ILexer5* cpplexer = nullptr ;
11+
612INT_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
138211CSharpScript* CSharpScriptEditor::ShowDialog ()
0 commit comments