Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: neurocore on September 20, 2013, 05:22:24 am

Title: Customizing colors into dark
Post by: neurocore on September 20, 2013, 05:22:24 am
Hi all! I use Code::Blocks a few years, and decided to change editor style to reduce eye fatigue. Just tried to customize IDE by settings -> editor -> syntax highlighting & margins and caret. But there are 3 problems:

1. I found no way to change the color of the line numbers. It still whitish.
2. Can editor interpret preprocessor commands separately from their arguments? Monolith color is annoying.
3. How to customize Logs & others?

There are 2 screenshots: what i want to achieve, and what i get with Code::Blocks.

[attachment deleted by admin]
Title: Re: Customizing colors into dark
Post by: oBFusCATed on September 20, 2013, 09:27:00 am
1. I found no way to change the color of the line numbers. It still whitish.
3. How to customize Logs & others?
For both of these you'll have to install a darker windows theme. Unfortunately wxWidgets tries to look as native as possible.
Title: Re: Customizing colors into dark
Post by: eranif on September 20, 2013, 09:48:24 am
Quote
For both of these you'll have to install a darker windows theme
This is not entirely correct...

The colour of the line numbers and folding margin can be customized using wxSctinilla API calls

Code
// 33 is the line number style
wxScintilla::StyleSetBackground(33, "RED");
wxScintilla::StyleSetForeground(33, "YELLOW");

// Fold margin:
Code
wxScintilla::SetFoldMarginColour
wxScintilla::SetFoldMarginHiColour

Ofc, someone needs to step up and implement it ;)

Eran
Title: Re: Customizing colors into dark
Post by: oBFusCATed on September 20, 2013, 03:19:01 pm
Ofc, someone needs to step up and implement it ;)
This is quite easy with our new colours system :)

Thanks for letting us know about these apis, Eranif.
Title: Re: Customizing colors into dark
Post by: oBFusCATed on September 20, 2013, 09:06:16 pm
Hm, it seems that setting the background for line numbers doesn't work on wxGTK.

All the other calls seems to work. Can someone test this on windows:

Code
Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp        (revision 9361)
+++ src/sdk/cbeditor.cpp        (working copy)
@@ -1293,6 +1293,11 @@ void cbEditor::InternalSetEditorStyleBeforeFileOpen(cbStyledTextCtrl* control)
     control->SetCaretLineVisible(mgr->ReadBool(_T("/highlight_caret_line"), false));
     control->SetCaretLineBackground(GetOptionColour(_T("/highlight_caret_line_colour"), wxColour(0xFF, 0xFF, 0x00)));

+    control->StyleSetBackground(wxSCI_STYLE_LINENUMBER, *wxRED);
+    control->StyleSetForeground(wxSCI_STYLE_LINENUMBER, *wxBLACK);
+    control->SetFoldMarginColour(true, *wxRED);
+    control->SetFoldMarginHiColour(true, *wxBLACK);
+
     // setup for "CamelCase selection"
     if (mgr->ReadBool(_T("/camel_case"), false))
     {
Index: src/sdk/editorcolourset.cpp
===================================================================
--- src/sdk/editorcolourset.cpp (revision 9361)
+++ src/sdk/editorcolourset.cpp (working copy)
@@ -479,6 +479,8 @@ wxString EditorColourSet::GetLanguageName(HighlightLanguage lang)

 void EditorColourSet::DoApplyStyle(cbStyledTextCtrl* control, int value, OptionColour* option)
 {
+    if (value==33)
+        std::terminate();
     // option->value is ignored here...
     // value is used instead
     if (option->fore != wxNullColour)
@@ -534,10 +536,10 @@ void EditorColourSet::Apply(HighlightLanguage lang, cbStyledTextCtrl* control, b
                 DoApplyStyle(control, i, defaults);
         }
     }
-    // for some strange reason, when switching styles, the line numbering changes colour
-    // too, though we didn't ask it to...
-    // this makes sure it stays the correct colour
-    control->StyleSetForeground(wxSCI_STYLE_LINENUMBER, wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
+//    // for some strange reason, when switching styles, the line numbering changes colour
+//    // too, though we didn't ask it to...
+//    // this makes sure it stays the correct colour
+//    control->StyleSetForeground(wxSCI_STYLE_LINENUMBER, wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));

     for (unsigned int i = 0; i < mset.m_Colours.GetCount(); ++i)
     {
Title: Re: Customizing colors into dark
Post by: eranif on September 20, 2013, 10:08:55 pm
Quote
Hm, it seems that setting the background for line numbers doesn't work on wxGTK.
Strange, this code works for me for all majors OS (including FreeBSD)

Here is a screenshot of how it should look:
(http://codelite.org/images/dark.png)

Eran
Title: Re: Customizing colors into dark
Post by: oBFusCATed on September 20, 2013, 10:36:06 pm
Maybe it is something theme related. Is this screen shot from CodeLite?
Title: Re: Customizing colors into dark
Post by: eranif on September 20, 2013, 10:40:56 pm
Quote
Insert Quote
Maybe it is something theme related
I have it working on various themes / desktops (KDE, Ubuntu, XFCE) all are behaving the same

Quote
Is this screen shot from CodeLite?
Yes

Eran
Title: Re: Customizing colors into dark
Post by: neurocore on September 21, 2013, 02:52:36 am
Aw, thank you, eranif. Thanks for CodeLite too ;)
Title: Re: Customizing colors into dark
Post by: oBFusCATed on September 22, 2013, 01:47:10 pm
It turned out that is just a bug in C::B.

The following code causes it:
Code
void EditorColourSet::Apply(HighlightLanguage lang, cbStyledTextCtrl* control, bool isC)
{
    if (!control)
        return;
    control->StyleClearAll();

If I comment the last line it works as expected.

@devs: Do you know why we call this function?
Title: Re: Customizing colors into dark
Post by: oBFusCATed on September 22, 2013, 02:58:54 pm
Here is a patch that allows the user to change the colours of line numbers and the margin.
Anyone willing to test it or provide feedback?

Code
Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp        (revision 9363)
+++ src/sdk/cbeditor.cpp        (working copy)
@@ -1288,11 +1288,17 @@ void cbEditor::InternalSetEditorStyleBeforeFileOpen(cbStyledTextCtrl* control)
         control->SetCaretWidth(mgr->ReadInt(_T("/caret/width"), 1));
     else
         control->SetCaretWidth(1);
-    control->SetCaretForeground(Manager::Get()->GetColourManager()->GetColour(wxT("editor_caret")));
+
+    ColourManager *colours = Manager::Get()->GetColourManager();
+
+    control->SetCaretForeground(colours->GetColour(wxT("editor_caret")));
     control->SetCaretPeriod(mgr->ReadInt(_T("/caret/period"), 500));
     control->SetCaretLineVisible(mgr->ReadBool(_T("/highlight_caret_line"), false));
     control->SetCaretLineBackground(GetOptionColour(_T("/highlight_caret_line_colour"), wxColour(0xFF, 0xFF, 0x00)));

+    control->SetFoldMarginColour(true, colours->GetColour(wxT("editor_margin_chrome")));
+    control->SetFoldMarginHiColour(true, colours->GetColour(wxT("editor_margin_chrome_highlight")));
+
     // setup for "CamelCase selection"
     if (mgr->ReadBool(_T("/camel_case"), false))
     {
Index: src/sdk/editorcolourset.cpp
===================================================================
--- src/sdk/editorcolourset.cpp (revision 9363)
+++ src/sdk/editorcolourset.cpp (working copy)
@@ -25,6 +25,7 @@
 #include <wx/txtstrm.h>  // wxTextInputStream
 #include <wx/wfstream.h> // wxFileInputStream

+#include "cbcolourmanager.h"
 #include "cbstyledtextctrl.h"

 #include "editorcolourset.h"
@@ -534,10 +535,11 @@ void EditorColourSet::Apply(HighlightLanguage lang, cbStyledTextCtrl* control, b
                 DoApplyStyle(control, i, defaults);
         }
     }
-    // for some strange reason, when switching styles, the line numbering changes colour
-    // too, though we didn't ask it to...
-    // this makes sure it stays the correct colour
-    control->StyleSetForeground(wxSCI_STYLE_LINENUMBER, wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
+
+    // Calling StyleClearAll above clears the style for the line numbers, so we have to re-apply it.
+    ColourManager *colours = Manager::Get()->GetColourManager();
+    control->StyleSetForeground(wxSCI_STYLE_LINENUMBER, colours->GetColour(wxT("editor_linenumbers_fg")));
+    control->StyleSetBackground(wxSCI_STYLE_LINENUMBER, colours->GetColour(wxT("editor_linenumbers_bg")));

     for (unsigned int i = 0; i < mset.m_Colours.GetCount(); ++i)
     {
Index: src/sdk/editormanager.cpp
===================================================================
--- src/sdk/editormanager.cpp   (revision 9363)
+++ src/sdk/editormanager.cpp   (working copy)
@@ -166,6 +166,16 @@ EditorManager::EditorManager()
     ColourManager *colours = Manager::Get()->GetColourManager();
     colours->RegisterColour(_("Editor"), _("Caret"), wxT("editor_caret"), *wxBLACK);
     colours->RegisterColour(_("Editor"), _("Right margin"), wxT("editor_gutter"), *wxLIGHT_GREY);
+    colours->RegisterColour(_("Editor"), _("Line numbers foreground colour"), wxT("editor_linenumbers_fg"),
+                            wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
+    colours->RegisterColour(_("Editor"), _("Line numbers background colour"), wxT("editor_linenumbers_bg"),
+                            wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
+
+    // These two are taken from Platform::Chrome() and Platform::ChromeHightlight()
+    colours->RegisterColour(_("Editor"), _("Margin chrome colour"), wxT("editor_margin_chrome"),
+                            wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
+    colours->RegisterColour(_("Editor"), _("Margin chrome highlight colour"), wxT("editor_margin_chrome_highlight"),
+                            wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT));
 }

 EditorManager::~EditorManager()
Title: Re: Customizing colors into dark
Post by: oBFusCATed on September 22, 2013, 03:03:19 pm
@eranif: Are you using a 1px wide margin for the vertical line after the line numbers in your screenshot?
Title: Re: Customizing colors into dark
Post by: eranif on September 22, 2013, 03:48:38 pm
Quote
@eranif: Are you using a 1px wide margin for the vertical line after the line numbers in your screenshot?
Yes, I am using margin of type MARGIN_FORE:


Code
    
SetMarginType(SYMBOLS_MARGIN_SEP_ID, wxSTC_MARGIN_FORE);
SetMarginMask(SYMBOLS_MARGIN_SEP_ID, 0);

Where SYMBOLS_MARGIN_SEP_ID is the margin number (in my case its 3 )

EDIT: there is another margin in that screenshot: the symbols margin (where you place the debugger current line marker, breakpoints, bookmarks etc)

Eran
Title: Re: Customizing colors into dark
Post by: neurocore on October 19, 2013, 02:20:43 pm
Please, make a color customizable version of Code::Blocks if it not difficult. Thanks.
Title: Re: Customizing colors into dark
Post by: Jenna on October 19, 2013, 02:52:51 pm
Please, make a color customizable version of Code::Blocks if it not difficult. Thanks.
If it is not difficult and you really need it, please provide a patch.
Title: Re: Customizing colors into dark
Post by: MortenMacFly on October 20, 2013, 11:20:58 am
If it is not difficult and you really need it, please provide a patch.
Isn't it already done by Obf?