Skip to content

Commit

Permalink
Moved basic colour API to clColours
Browse files Browse the repository at this point in the history
Signed-off-by: Eran Ifrah <[email protected]>
  • Loading branch information
eranif committed Nov 27, 2024
1 parent e6f8fd8 commit df51084
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 247 deletions.
72 changes: 1 addition & 71 deletions Plugin/ThemeImporters/ThemeImporterBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,59 +70,9 @@ wxString adjust_colour(const wxString& col, bool is_dark)
}
}

wxColour dark_black;
wxColour dark_red;
wxColour dark_green;
wxColour dark_yellow;
wxColour dark_blue;
wxColour dark_magenta;
wxColour dark_cyan;
wxColour dark_grey;
wxColour dark_white;

wxColour black;
wxColour red;
wxColour green;
wxColour yellow;
wxColour blue;
wxColour magenta;
wxColour cyan;
wxColour grey;
wxColour white;

void initialize_base_colours()
{
static bool initialise = true;

if (initialise) {
// dark theme colours
dark_black = wxColour("#0E1415");
dark_red = wxColour("#e25d56");
dark_green = wxColour("#73ca50");
dark_yellow = wxColour("#e9bf57");
dark_blue = wxColour("#4a88e4");
dark_magenta = wxColour("#915caf");
dark_cyan = wxColour("#23acdd");
dark_white = wxColour("#f0f0f0");
dark_grey = "LIGHT GREY";

// normal colours
black = wxColour("#000000");
red = wxColour("#AA3731");
green = wxColour("#448C27");
yellow = wxColour("#CB9000");
blue = wxColour("#325CC0");
magenta = wxColour("#7A3E9D");
cyan = wxColour("#0083B2");
white = wxColour("#BBBBBB");
grey = "GREY";

initialise = false;
}
}
} // namespace

ThemeImporterBase::ThemeImporterBase() { initialize_base_colours(); }
ThemeImporterBase::ThemeImporterBase() {}

ThemeImporterBase::~ThemeImporterBase() {}

Expand Down Expand Up @@ -683,23 +633,3 @@ LexerConf::Ptr_t ThemeImporterBase::ImportVSCodeJSON(const wxFileName& theme_fil
m_javadocKeyword = m_klass;
return lexer;
}

#define RETURN_COLOUR(name) \
wxColour colour = name; \
if (dark_theme) { \
colour = dark_##name; \
} \
if (bright) { \
colour = colour.ChangeLightness(110); \
} \
return colour

wxColour ThemeImporterBase::Black(bool dark_theme, bool bright) { RETURN_COLOUR(black); }
wxColour ThemeImporterBase::Red(bool dark_theme, bool bright) { RETURN_COLOUR(red); }
wxColour ThemeImporterBase::Green(bool dark_theme, bool bright) { RETURN_COLOUR(green); }
wxColour ThemeImporterBase::Yellow(bool dark_theme, bool bright) { RETURN_COLOUR(yellow); }
wxColour ThemeImporterBase::Blue(bool dark_theme, bool bright) { RETURN_COLOUR(blue); }
wxColour ThemeImporterBase::Magenta(bool dark_theme, bool bright) { RETURN_COLOUR(magenta); }
wxColour ThemeImporterBase::Cyan(bool dark_theme, bool bright) { RETURN_COLOUR(cyan); }
wxColour ThemeImporterBase::Grey(bool dark_theme, bool bright) { RETURN_COLOUR(grey); }
wxColour ThemeImporterBase::White(bool dark_theme, bool bright) { RETURN_COLOUR(white); }
9 changes: 0 additions & 9 deletions Plugin/ThemeImporters/ThemeImporterBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,6 @@ class WXDLLIMPEXP_SDK ThemeImporterBase
* @param codeliteXml [output] the output file name
*/
virtual LexerConf::Ptr_t Import(const wxFileName& theme_file) = 0;
wxColour Black(bool dark_theme, bool bright = false);
wxColour Red(bool dark_theme, bool bright = false);
wxColour Green(bool dark_theme, bool bright = false);
wxColour Yellow(bool dark_theme, bool bright = false);
wxColour Blue(bool dark_theme, bool bright = false);
wxColour Magenta(bool dark_theme, bool bright = false);
wxColour Cyan(bool dark_theme, bool bright = false);
wxColour Grey(bool dark_theme, bool bright = false);
wxColour White(bool dark_theme, bool bright = false);
};

#endif // ECLIPSETHEMEIMPORTERBASE_H
16 changes: 4 additions & 12 deletions Plugin/ThemeImporters/ThemeImporterDiff.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "ThemeImporterDiff.hpp"

#include "clColours.h"

#include <wx/colour.h>

ThemeImporterDiff::ThemeImporterDiff() { SetFileExtensions("*.diff;*.patch;Diff;*.Diff"); }
Expand All @@ -16,18 +18,8 @@ LexerConf::Ptr_t ThemeImporterDiff::Import(const wxFileName& theme_file)
AddProperty(lexer, wxSTC_DIFF_COMMAND, "Command", m_klass);
AddProperty(lexer, wxSTC_DIFF_HEADER, "Header", m_keyword);
AddProperty(lexer, wxSTC_DIFF_POSITION, "Position", m_function);

// Use pink and forest green
if (IsDarkTheme()) {
// Use more appropriate diff colours
AddProperty(lexer, wxSTC_DIFF_DELETED, "Line Deleted",
wxColour("RED").ChangeLightness(120).GetAsString(wxC2S_HTML_SYNTAX), m_editor.bg_colour, true);
AddProperty(lexer, wxSTC_DIFF_ADDED, "Line Added",
wxColour("GREEN").ChangeLightness(120).GetAsString(wxC2S_HTML_SYNTAX), m_editor.bg_colour, true);
} else {
AddProperty(lexer, wxSTC_DIFF_DELETED, "Line Deleted", "RED", m_editor.bg_colour, true);
AddProperty(lexer, wxSTC_DIFF_ADDED, "Line Added", "rgb(0, 128, 64)", m_editor.bg_colour, true);
}
AddProperty(lexer, wxSTC_DIFF_DELETED, "Line Deleted", clColours::Red(lexer->IsDark()), m_editor.bg_colour, true);
AddProperty(lexer, wxSTC_DIFF_ADDED, "Line Added", clColours::Green(lexer->IsDark()), m_editor.bg_colour, true);
FinalizeImport(lexer);
return lexer;
}
87 changes: 48 additions & 39 deletions Plugin/ThemeImporters/ThemeImporterErrorlist.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ThemeImporterErrorlist.hpp"

#include "clColours.h"
#include "drawingutils.h"

ThemeImporterErrorlist::ThemeImporterErrorlist()
Expand All @@ -15,55 +16,63 @@ LexerConf::Ptr_t ThemeImporterErrorlist::Import(const wxFileName& theme_file)
bool is_dark = DrawingUtils::IsDark(m_editor.bg_colour);

AddProperty(lexer, wxSTC_ERR_DEFAULT, "Default", m_editor);
AddProperty(lexer, wxSTC_ERR_PYTHON, "Python error message", Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_GCC, "GCC like error message", Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_MS, "MSVC error message", Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_CMD, "CMD error message", Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_BORLAND, "Borland error message", Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_PERL, "Perl error message", Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_NET, ".NET error message", Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_LUA, "LUA error message", Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_CTAG, "CTags line", Cyan(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_DIFF_CHANGED, "Diff line changed", Yellow(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_DIFF_ADDITION, "Diff line added", Green(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_DIFF_DELETION, "Diff line deleted", Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_DIFF_MESSAGE, "Diff line message", Cyan(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_PHP, "PHP error message", Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ELF, "Essential Lahey Fortran error message", Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_IFC, "Intel Fortran Compiler error/warning message", Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_IFORT, "Intel Fortran Compiler v8.0 error/warning message", Red(is_dark),
AddProperty(lexer, wxSTC_ERR_PYTHON, "Python error message", clColours::Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_GCC, "GCC like error message", clColours::Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_MS, "MSVC error message", clColours::Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_CMD, "CMD error message", clColours::Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_BORLAND, "Borland error message", clColours::Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_PERL, "Perl error message", clColours::Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_NET, ".NET error message", clColours::Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_LUA, "LUA error message", clColours::Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_CTAG, "CTags line", clColours::Cyan(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_DIFF_CHANGED, "Diff line changed", clColours::Yellow(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_DIFF_ADDITION, "Diff line added", clColours::Green(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_DIFF_DELETION, "Diff line deleted", clColours::Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_DIFF_MESSAGE, "Diff line message", clColours::Cyan(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_PHP, "PHP error message", clColours::Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ELF, "Essential Lahey Fortran error message", clColours::Red(is_dark),
m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ABSF, "Absoft Pro Fortran 90/95 v8.2 error and/or warning message", Red(is_dark),
AddProperty(lexer, wxSTC_ERR_IFC, "Intel Fortran Compiler error/warning message", clColours::Red(is_dark),
m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_TIDY, "HTML tidy style", Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_JAVA_STACK, "Java stack", Cyan(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_IFORT, "Intel Fortran Compiler v8.0 error/warning message", clColours::Red(is_dark),
m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ABSF, "Absoft Pro Fortran 90/95 v8.2 error and/or warning message",
clColours::Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_TIDY, "HTML tidy style", clColours::Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_JAVA_STACK, "Java stack", clColours::Cyan(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_VALUE, "Value", m_editor);
AddProperty(lexer, wxSTC_ERR_GCC_INCLUDED_FROM, "GCC 'included from'", Grey(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_GCC_INCLUDED_FROM, "GCC 'included from'", clColours::Grey(is_dark),
m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ESCSEQ, "ANSI escape sequence", m_editor);
AddProperty(lexer, wxSTC_ERR_ESCSEQ_UNKNOWN, "ANSI escape sequence unknown", Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ESCSEQ_UNKNOWN, "ANSI escape sequence unknown", clColours::Red(is_dark),
m_editor.bg_colour);

#if wxCHECK_VERSION(3, 3, 0)
AddProperty(lexer, wxSTC_ERR_GCC_EXCERPT, "GCC code excerpt and pointer to issue", Cyan(is_dark),
AddProperty(lexer, wxSTC_ERR_GCC_EXCERPT, "GCC code excerpt and pointer to issue", clColours::Cyan(is_dark),
m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_BASH, "Bash diagnostic line", Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_BASH, "Bash diagnostic line", clColours::Red(is_dark), m_editor.bg_colour);
#endif

AddProperty(lexer, wxSTC_ERR_ES_BLACK, "ANSI escape black", Black(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_RED, "ANSI escape red", Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_GREEN, "ANSI escape green", Green(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_BROWN, "ANSI escape brown", Yellow(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_BLUE, "ANSI escape blue", Blue(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_MAGENTA, "ANSI escape magenta", Magenta(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_CYAN, "ANSI escape cyan", Cyan(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_GRAY, "ANSI escape grey", Grey(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_YELLOW, "ANSI escape yellow", Yellow(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_DARK_GRAY, "ANSI escape dark grey", Grey(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_BRIGHT_RED, "ANSI escape bright red", Red(is_dark, true), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_BRIGHT_GREEN, "ANSI escape bright green", Green(is_dark, true), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_BRIGHT_BLUE, "ANSI escape bright blue", Blue(is_dark, true), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_BRIGHT_MAGENTA, "ANSI escape bright magenta", Magenta(is_dark, true),
AddProperty(lexer, wxSTC_ERR_ES_BLACK, "ANSI escape black", clColours::Black(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_RED, "ANSI escape red", clColours::Red(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_GREEN, "ANSI escape green", clColours::Green(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_BROWN, "ANSI escape brown", clColours::Yellow(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_BLUE, "ANSI escape blue", clColours::Blue(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_MAGENTA, "ANSI escape magenta", clColours::Magenta(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_CYAN, "ANSI escape cyan", clColours::Cyan(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_GRAY, "ANSI escape grey", clColours::Grey(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_YELLOW, "ANSI escape yellow", clColours::Yellow(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_DARK_GRAY, "ANSI escape dark grey", clColours::Grey(is_dark), m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_BRIGHT_RED, "ANSI escape bright red", clColours::Red(is_dark, true),
m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_BRIGHT_GREEN, "ANSI escape bright green", clColours::Green(is_dark, true),
m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_BRIGHT_BLUE, "ANSI escape bright blue", clColours::Blue(is_dark, true),
m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_BRIGHT_MAGENTA, "ANSI escape bright magenta", clColours::Magenta(is_dark, true),
m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_BRIGHT_CYAN, "ANSI escape bright cyan", clColours::Cyan(is_dark, true),
m_editor.bg_colour);
AddProperty(lexer, wxSTC_ERR_ES_BRIGHT_CYAN, "ANSI escape bright cyan", Cyan(is_dark, true), m_editor.bg_colour);
FinalizeImport(lexer);
return lexer;
}
75 changes: 75 additions & 0 deletions Plugin/clColours.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,78 @@ void clColours::FromLexer(LexerConf::Ptr_t lexer)
}

void clColours::InitFromColour(const wxColour& baseColour) { init_from_colour(this, baseColour); }

wxColour dark_black;
wxColour dark_red;
wxColour dark_green;
wxColour dark_yellow;
wxColour dark_blue;
wxColour dark_magenta;
wxColour dark_cyan;
wxColour dark_grey;
wxColour dark_white;

wxColour black;
wxColour red;
wxColour green;
wxColour yellow;
wxColour blue;
wxColour magenta;
wxColour cyan;
wxColour grey;
wxColour white;

namespace
{
void initialize_base_colours()
{
static bool initialise = true;

if (initialise) {
// dark theme colours
dark_black = wxColour("#0E1415");
dark_red = wxColour("#e25d56");
dark_green = wxColour("#73ca50");
dark_yellow = wxColour("#e9bf57");
dark_blue = wxColour("#4a88e4");
dark_magenta = wxColour("#915caf");
dark_cyan = wxColour("#23acdd");
dark_white = wxColour("#f0f0f0");
dark_grey = "LIGHT GREY";

// normal colours
black = wxColour("#000000");
red = wxColour("#AA3731");
green = wxColour("#448C27");
yellow = wxColour("#CB9000");
blue = wxColour("#325CC0");
magenta = wxColour("#7A3E9D");
cyan = wxColour("#0083B2");
white = wxColour("#BBBBBB");
grey = "GREY";

initialise = false;
}
}
} // namespace

#define RETURN_COLOUR(name) \
initialize_base_colours(); \
wxColour colour = name; \
if (dark_theme) { \
colour = dark_##name; \
} \
if (bright) { \
colour = colour.ChangeLightness(110); \
} \
return colour

wxColour clColours::Black(bool dark_theme, bool bright) { RETURN_COLOUR(black); }
wxColour clColours::Red(bool dark_theme, bool bright) { RETURN_COLOUR(red); }
wxColour clColours::Green(bool dark_theme, bool bright) { RETURN_COLOUR(green); }
wxColour clColours::Yellow(bool dark_theme, bool bright) { RETURN_COLOUR(yellow); }
wxColour clColours::Blue(bool dark_theme, bool bright) { RETURN_COLOUR(blue); }
wxColour clColours::Magenta(bool dark_theme, bool bright) { RETURN_COLOUR(magenta); }
wxColour clColours::Cyan(bool dark_theme, bool bright) { RETURN_COLOUR(cyan); }
wxColour clColours::Grey(bool dark_theme, bool bright) { RETURN_COLOUR(grey); }
wxColour clColours::White(bool dark_theme, bool bright) { RETURN_COLOUR(white); }
11 changes: 11 additions & 0 deletions Plugin/clColours.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ class WXDLLIMPEXP_SDK clColours
this->selItemTextColourNoFocus = selItemTextColourNoFocus;
}
const wxColour& GetSelItemTextColourNoFocus() const { return selItemTextColourNoFocus; }

// Return common colours suitable for dark or light theme
static wxColour Black(bool dark_theme, bool bright = false);
static wxColour Red(bool dark_theme, bool bright = false);
static wxColour Green(bool dark_theme, bool bright = false);
static wxColour Yellow(bool dark_theme, bool bright = false);
static wxColour Blue(bool dark_theme, bool bright = false);
static wxColour Magenta(bool dark_theme, bool bright = false);
static wxColour Cyan(bool dark_theme, bool bright = false);
static wxColour Grey(bool dark_theme, bool bright = false);
static wxColour White(bool dark_theme, bool bright = false);
};

#endif // CLCOLOURS_H
3 changes: 3 additions & 0 deletions Plugin/wxTerminalCtrl/wxTerminalOutputCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "FontUtils.hpp"
#include "Platform/Platform.hpp"
#include "StringUtils.h"
#include "ThemeImporters/ThemeImporterBase.hpp"
#include "clIdleEventThrottler.hpp"
#include "clModuleLogger.hpp"
#include "clSystemSettings.h"
Expand Down Expand Up @@ -95,7 +96,9 @@ void wxTerminalOutputCtrl::Initialise(const wxFont& font, const wxColour& bg_col
auto lexer = ColoursAndFontsManager::Get().GetLexer("errorlist");
if (lexer) {
lexer->Apply(m_ctrl);
m_ctrl->IndicatorSetForeground(INDICATOR_HYPERLINK, clColours::Blue(lexer->IsDark()));
}

GetSizer()->Add(m_ctrl, 1, wxEXPAND);
GetSizer()->Fit(this);
CallAfter(&wxTerminalOutputCtrl::ReloadSettings);
Expand Down
Loading

0 comments on commit df51084

Please sign in to comment.