Skip to content

Commit 11ab86d

Browse files
committed
add tab/space options + visible whitespace
1 parent e95a547 commit 11ab86d

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

Diff for: README.md

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Create a ```config.json``` with e.g. the following contents: (all fields are opt
2929
"outputHeight": 200,
3030
"opacity": 192, // 255 means the editor occludes the effect completely, 0 means the editor is fully transparent
3131
"texturePreviewWidth": 64,
32+
"spacesForTabs": false,
33+
"tabSize": 8,
34+
"visibleWhitespace": true,
3235
},
3336
"midi":{ /* the keys below will become the shader variable names, the values are the CC numbers */
3437
"fMidiKnob": 16, /* e.g. this would be CC#16, i.e. by default the leftmost knob on a nanoKONTROL 2 */

Diff for: ShaderEditor.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,17 @@ void ShaderEditor::Initialise()
108108
WndProc(SCI_MARKERSETBACK, markersArray[FOLDER_TYPE][i], 0xFF6A6A6A);
109109
WndProc(SCI_MARKERSETFORE, markersArray[FOLDER_TYPE][i], 0xFF333333);
110110
}
111-
WndProc(SCI_SETUSETABS, 1, NULL);
112-
WndProc(SCI_SETTABWIDTH, 2, NULL);
111+
WndProc(SCI_SETUSETABS, bUseSpacesForTabs ? 0 : 1, NULL);
112+
WndProc(SCI_SETTABWIDTH, nTabSize, NULL);
113113
WndProc(SCI_SETINDENTATIONGUIDES, SC_IV_REAL, NULL);
114114

115+
if (bVisibleWhitespace)
116+
{
117+
WndProc(SCI_SETVIEWWS, SCWS_VISIBLEALWAYS, NULL);
118+
WndProc(SCI_SETWHITESPACEFORE, 1, 0x30FFFFFF);
119+
WndProc(SCI_SETWHITESPACESIZE, 2, NULL );
120+
}
121+
115122
lexState->SetLexer( SCLEX_CPP );
116123
lexState->SetWordList(0, shaderKeyword);
117124
lexState->SetWordList(1, shaderType);
@@ -126,7 +133,7 @@ void ShaderEditor::Initialise()
126133
SetAStyle(SCE_C_OPERATOR, 0xFF00CCFF, BACKGROUND( 0x000000 ));
127134
SetAStyle(SCE_C_COMMENT, 0xFF00FF00, BACKGROUND( 0x000000 ));
128135
SetAStyle(SCE_C_COMMENTLINE, 0xFF00FF00, BACKGROUND( 0x000000 ));
129-
136+
130137
lexState->Colourise( 0, -1 );
131138

132139
//WndProc( SCI_COLOURISE, NULL, NULL );
@@ -139,6 +146,10 @@ void ShaderEditor::Initialise( SHADEREDITOR_OPTIONS &options )
139146
nFontSize = options.nFontSize;
140147
sFontFile = options.sFontPath;
141148
nOpacity = options.nOpacity;
149+
bUseSpacesForTabs = options.bUseSpacesForTabs;
150+
nTabSize = options.nTabSize;
151+
bVisibleWhitespace = options.bVisibleWhitespace;
152+
142153
Initialise();
143154
SetPosition( options.rect );
144155
}
@@ -285,6 +296,7 @@ void ShaderEditor::SetReadOnly( bool b )
285296
WndProc( SCI_SETREADONLY, bReadOnly, NULL );
286297
if (bReadOnly)
287298
{
299+
WndProc(SCI_SETVIEWWS, SCWS_INVISIBLE, NULL);
288300
WndProc(SCI_SETMARGINWIDTHN, 0, 0);
289301
WndProc(SCI_SETMARGINWIDTHN, 1, 0);
290302
WndProc( SCI_SETCARETLINEVISIBLE, 0, NULL);

Diff for: ShaderEditor.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,25 @@ struct SHADEREDITOR_OPTIONS {
5353
int nFontSize;
5454
Scintilla::PRectangle rect;
5555
unsigned char nOpacity;
56+
bool bUseSpacesForTabs;
57+
int nTabSize;
58+
bool bVisibleWhitespace;
5659
};
5760

5861
class ShaderEditor : public Scintilla::Editor
5962
{
6063
Scintilla::Surface *surfaceWindow;
6164
Scintilla::LexState * lexState;
6265
bool bReadOnly;
66+
bool bHasMouseCapture;
67+
6368
std::string sFontFile;
6469
int nFontSize;
65-
bool bHasMouseCapture;
6670
unsigned char nOpacity;
71+
bool bUseSpacesForTabs;
72+
int nTabSize;
73+
bool bVisibleWhitespace;
74+
6775
public:
6876
ShaderEditor(Scintilla::Surface *surfaceWindow);
6977

Diff for: main.cpp

+18-11
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,22 @@ int main()
6767
std::map<std::string,Renderer::Texture*> textures;
6868
std::map<int,std::string> midiRoutes;
6969

70-
int nFontSize = 16;
70+
SHADEREDITOR_OPTIONS options;
71+
options.nFontSize = 16;
7172
#ifdef _WIN32
72-
std::string sFontPath = "c:\\Windows\\Fonts\\cour.ttf";
73+
options.sFontPath = "c:\\Windows\\Fonts\\cour.ttf";
7374
#else
74-
std::string sFontPath = "/usr/share/fonts/corefonts/cour.ttf";
75+
options.sFontPath = "/usr/share/fonts/corefonts/cour.ttf";
7576
#endif
76-
unsigned char nOpacity = 0xC0;
77+
options.nOpacity = 0xC0;
78+
options.bUseSpacesForTabs = true;
79+
options.nTabSize = 2;
80+
options.bVisibleWhitespace = false;
7781

7882
int nDebugOutputHeight = 200;
7983
int nTexPreviewWidth = 64;
8084

85+
8186
char szConfig[65535];
8287
FILE * fConf = fopen("config.json","rb");
8388
if (fConf)
@@ -104,9 +109,9 @@ int main()
104109
if (o.has<jsonxx::Object>("font"))
105110
{
106111
if (o.get<jsonxx::Object>("font").has<jsonxx::Number>("size"))
107-
nFontSize = o.get<jsonxx::Object>("font").get<jsonxx::Number>("size");
112+
options.nFontSize = o.get<jsonxx::Object>("font").get<jsonxx::Number>("size");
108113
if (o.get<jsonxx::Object>("font").has<jsonxx::String>("file"))
109-
sFontPath = o.get<jsonxx::Object>("font").get<jsonxx::String>("file");
114+
options.sFontPath = o.get<jsonxx::Object>("font").get<jsonxx::String>("file");
110115
}
111116
if (o.has<jsonxx::Object>("gui"))
112117
{
@@ -115,7 +120,13 @@ int main()
115120
if (o.get<jsonxx::Object>("gui").has<jsonxx::Number>("texturePreviewWidth"))
116121
nTexPreviewWidth = o.get<jsonxx::Object>("gui").get<jsonxx::Number>("texturePreviewWidth");
117122
if (o.get<jsonxx::Object>("gui").has<jsonxx::Number>("opacity"))
118-
nOpacity = o.get<jsonxx::Object>("gui").get<jsonxx::Number>("opacity");
123+
options.nOpacity = o.get<jsonxx::Object>("gui").get<jsonxx::Number>("opacity");
124+
if (o.get<jsonxx::Object>("gui").has<jsonxx::Boolean>("spacesForTabs"))
125+
options.bUseSpacesForTabs = o.get<jsonxx::Object>("gui").get<jsonxx::Boolean>("spacesForTabs");
126+
if (o.get<jsonxx::Object>("gui").has<jsonxx::Number>("tabSize"))
127+
options.nTabSize = o.get<jsonxx::Object>("gui").get<jsonxx::Number>("tabSize");
128+
if (o.get<jsonxx::Object>("gui").has<jsonxx::Boolean>("visibleWhitespace"))
129+
options.bVisibleWhitespace = o.get<jsonxx::Object>("gui").get<jsonxx::Boolean>("visibleWhitespace");
119130
}
120131
if (o.has<jsonxx::Object>("midi"))
121132
{
@@ -175,10 +186,6 @@ int main()
175186

176187
bool bTexPreviewVisible = true;
177188

178-
SHADEREDITOR_OPTIONS options;
179-
options.sFontPath = sFontPath;
180-
options.nFontSize = nFontSize;
181-
options.nOpacity = nOpacity;
182189
options.rect = Scintilla::PRectangle( nMargin, nMargin, settings.nWidth - nMargin - nTexPreviewWidth - nMargin, settings.nHeight - nMargin * 2 - nDebugOutputHeight );
183190
ShaderEditor mShaderEditor( surface );
184191
mShaderEditor.Initialise( options );

0 commit comments

Comments
 (0)