Skip to content

Commit

Permalink
New feature ‘Adjust lightness of indistinguishable text’ on the ‘Colo…
Browse files Browse the repository at this point in the history
…rs’ settings page.

  The idea is to make text readable if certain foreground and background colors
  are indistinguishable for current palette. ConEmu will try to change the lightness
  of the foreground text.
  • Loading branch information
Maximus5 committed Apr 25, 2016
1 parent 0f9187c commit 51ba398
Show file tree
Hide file tree
Showing 20 changed files with 666 additions and 1 deletion.
529 changes: 529 additions & 0 deletions src/ConEmu/ColorFix.cpp

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions src/ConEmu/ColorFix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

/*
Copyright (c) 2016 Maximus5
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


#pragma once

#include <windows.h>

typedef double real_type;

struct ColorFix
{
// RGB
union
{
struct
{
BYTE r, g, b, dummy;
};
COLORREF rgb;
};

// Lab
struct
{
real_type L, A, B;
};

ColorFix();
ColorFix(COLORREF a_rgb);
ColorFix(real_type a_L, real_type a_a, real_type a_b);
ColorFix(const ColorFix& clr);

void ToLab();
void ToRGB();

real_type DeltaE(ColorFix color);

bool PerceivableColor(COLORREF back/*, COLORREF alt*/, ColorFix& pColor, real_type* oldDE = NULL, real_type* newDE = NULL);
};
1 change: 1 addition & 0 deletions src/ConEmu/ConEmu.rc
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ BEGIN
RTEXT "High:",stColorFadeHigh,79,223,43,8
EDITTEXT tFadeHigh,123,220,24,12,ES_AUTOHSCROLL
CONTROL "TrueMod (24bit color) support",cbTrueColorer,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,193,209,182,8
CONTROL "Adjust lightness of indistinguishable text",cbVividColors,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,193,223,182,8
PUSHBUTTON "Save",cbColorSchemeSave,276,2,50,14,WS_DISABLED
PUSHBUTTON "Delete...",cbColorSchemeDelete,328,2,50,14,WS_DISABLED
RTEXT "Text:",stColorText,7,89,42,8
Expand Down
2 changes: 2 additions & 0 deletions src/ConEmu/ConEmu09.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@
<File RelativePath=".\Background.cpp" />
<File RelativePath=".\BaseDragDrops.cpp" />
<File RelativePath=".\CmdHistory.cpp" />
<File RelativePath=".\ColorFix.cpp" />
<File RelativePath=".\ConEmu.cpp" />
<File RelativePath=".\ConEmuApp.cpp" />
<File RelativePath=".\ConEmuCtrl.cpp" />
Expand Down Expand Up @@ -619,6 +620,7 @@
<File RelativePath=".\Background.h" />
<File RelativePath=".\BaseDragDrops.h" />
<File RelativePath=".\CmdHistory.h" />
<File RelativePath=".\ColorFix.h" />
<File RelativePath=".\ConEmu.h" />
<File RelativePath=".\ConEmuApp.h" />
<File RelativePath=".\ConEmuCtrl.h" />
Expand Down
2 changes: 2 additions & 0 deletions src/ConEmu/ConEmu10.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@
<ClCompile Include="Background.cpp" />
<ClCompile Include="BaseDragDrops.cpp" />
<ClCompile Include="CmdHistory.cpp" />
<ClCompile Include="ColorFix.cpp" />
<ClCompile Include="ConEmu.cpp" />
<ClCompile Include="ConEmuApp.cpp" />
<ClCompile Include="ConEmuCtrl.cpp" />
Expand Down Expand Up @@ -1156,6 +1157,7 @@
<ClInclude Include="Background.h" />
<ClInclude Include="BaseDragDrops.h" />
<ClInclude Include="CmdHistory.h" />
<ClInclude Include="ColorFix.h" />
<ClInclude Include="ConEmu.h" />
<ClInclude Include="ConEmuApp.h" />
<ClInclude Include="ConEmuCtrl.h" />
Expand Down
2 changes: 2 additions & 0 deletions src/ConEmu/ConEmu11.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@
<ClCompile Include="Background.cpp" />
<ClCompile Include="BaseDragDrops.cpp" />
<ClCompile Include="CmdHistory.cpp" />
<ClCompile Include="ColorFix.cpp" />
<ClCompile Include="ConEmu.cpp" />
<ClCompile Include="ConEmuApp.cpp" />
<ClCompile Include="ConEmuCtrl.cpp" />
Expand Down Expand Up @@ -1119,6 +1120,7 @@
<ClInclude Include="Background.h" />
<ClInclude Include="BaseDragDrops.h" />
<ClInclude Include="CmdHistory.h" />
<ClInclude Include="ColorFix.h" />
<ClInclude Include="ConEmu.h" />
<ClInclude Include="ConEmuApp.h" />
<ClInclude Include="ConEmuCtrl.h" />
Expand Down
2 changes: 2 additions & 0 deletions src/ConEmu/ConEmu12.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@ copy "$(TargetPath)" Z:\</Command>
<ClCompile Include="Background.cpp" />
<ClCompile Include="BaseDragDrops.cpp" />
<ClCompile Include="CmdHistory.cpp" />
<ClCompile Include="ColorFix.cpp" />
<ClCompile Include="ConEmu.cpp" />
<ClCompile Include="ConEmuApp.cpp" />
<ClCompile Include="ConEmuCtrl.cpp" />
Expand Down Expand Up @@ -1186,6 +1187,7 @@ copy "$(TargetPath)" Z:\</Command>
<ClInclude Include="Background.h" />
<ClInclude Include="BaseDragDrops.h" />
<ClInclude Include="CmdHistory.h" />
<ClInclude Include="ColorFix.h" />
<ClInclude Include="ConEmu.h" />
<ClInclude Include="ConEmuApp.h" />
<ClInclude Include="ConEmuCtrl.h" />
Expand Down
2 changes: 2 additions & 0 deletions src/ConEmu/ConEmu14.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@
<ClCompile Include="Background.cpp" />
<ClCompile Include="BaseDragDrops.cpp" />
<ClCompile Include="CmdHistory.cpp" />
<ClCompile Include="ColorFix.cpp" />
<ClCompile Include="ConEmu.cpp" />
<ClCompile Include="ConEmuApp.cpp" />
<ClCompile Include="ConEmuCtrl.cpp" />
Expand Down Expand Up @@ -749,6 +750,7 @@
<ClInclude Include="Background.h" />
<ClInclude Include="BaseDragDrops.h" />
<ClInclude Include="CmdHistory.h" />
<ClInclude Include="ColorFix.h" />
<ClInclude Include="ConEmu.h" />
<ClInclude Include="ConEmuApp.h" />
<ClInclude Include="ConEmuCtrl.h" />
Expand Down
1 change: 1 addition & 0 deletions src/ConEmu/LngDataHints.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ static LngPredefined gsDataHints[] = {
{ cbUseWinNumber, L"Enables switching of tabs (30 consoles) by their numbers (1,2,...,9,10,11,...). ‘Host-key’ is ‘Win’ key, by default." },
{ cbUseWinTab, L"Disable Windows 7 Aero switch (Win+Tab) when ConEmu in foreground" },
{ cbVisible, L"Show real console on startup" },
{ cbVividColors, L"Change lightness of text if color difference\r\nbetween text and background is indistinguishable" },
{ lbCmdOutputCP, L"Windows command processor (cmd.exe) may cause then output of internal commands to be OEM or Unicode.\r\nYou may force this selection, or use automatic selection (FAR2 -> Unicode)." },
{ lbCTSBlockSelection, L"Choose modifier to starting ‘Block selection’ with mouse LeftClick+Drag" },
{ lbCTSEOL, L"Choose preferred line separator (\\r\\n, \\n or \\r)" },
Expand Down
4 changes: 4 additions & 0 deletions src/ConEmu/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ void Settings::InitSettings()

isTrueColorer = true; // включим по умолчанию, ибо Far3

isVividColors = true;

AppStd.isExtendColors = false;
AppStd.nExtendColorIdx = CEDEF_ExtendColorIdx/*14*/;
AppStd.nTextColorIdx = AppStd.nBackColorIdx = CEDEF_BackColorAuto/*16*/;
Expand Down Expand Up @@ -2416,6 +2418,7 @@ void Settings::LoadSettings(bool& rbNeedCreateVanilla, const SettingsStorage* ap
LoadAppSettings(reg, &AppStd/*, Colors*/);

reg->Load(L"TrueColorerSupport", isTrueColorer);
reg->Load(L"VividColors", isVividColors);
reg->Load(L"FadeInactive", isFadeInactive);
reg->Load(L"FadeInactiveLow", mn_FadeLow);
reg->Load(L"FadeInactiveHigh", mn_FadeHigh);
Expand Down Expand Up @@ -3516,6 +3519,7 @@ BOOL Settings::SaveSettings(BOOL abSilent /*= FALSE*/, const SettingsStorage* ap
SaveAppSettings(reg, &AppStd/*, Colors*/);

reg->Save(L"TrueColorerSupport", isTrueColorer);
reg->Save(L"VividColors", isVividColors);
reg->Save(L"FadeInactive", isFadeInactive);
reg->Save(L"FadeInactiveLow", mn_FadeLow);
reg->Save(L"FadeInactiveHigh", mn_FadeHigh);
Expand Down
3 changes: 3 additions & 0 deletions src/ConEmu/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ struct Settings
//reg->Load(L"TrueColorerSupport", isTrueColorer);
bool isTrueColorer;

//reg->Load(L"VividColors", isVividColors);
bool isVividColors;


/* *** Background image *** */
//reg->Load(L"BackGround Image show", isShowBgImage);
Expand Down
28 changes: 28 additions & 0 deletions src/ConEmu/RConPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "Header.h"

#include "ColorFix.h"
#include "Options.h"
#include "RConPalette.h"
#include "RealConsole.h"
Expand All @@ -40,6 +41,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
CRConPalette::CRConPalette(CRealConsole* apRCon)
: mp_RCon(apRCon)
, mb_Initialized(false)
, mb_VividColors(false)
, mn_FontNormalColor(0)
, mn_FontBoldColor(0)
, mn_FontItalicColor(0)
Expand All @@ -54,9 +56,11 @@ CRConPalette::~CRConPalette()
}

void CRConPalette::UpdateColorTable(COLORREF *apColors/*[32]*/,
bool bVividColors,
bool bExtendFonts, BYTE nFontNormalColor, BYTE nFontBoldColor, BYTE nFontItalicColor)
{
bool bMainChanged = !mb_Initialized
|| (mb_VividColors != bVividColors)
|| (memcmp(m_Colors, apColors, sizeof(m_Colors)) != 0);
bool bExtChanged = bMainChanged
|| ((mb_ExtendFonts != bExtendFonts)
Expand All @@ -74,6 +78,8 @@ void CRConPalette::UpdateColorTable(COLORREF *apColors/*[32]*/,

if (bMainChanged)
{
real_type oldDE = 0, newDE = 0;
wchar_t szLog[200];
u32 nColorIndex = 0;

for (u32 nBack = 0; nBack <= 0xF; nBack++)
Expand All @@ -86,6 +92,27 @@ void CRConPalette::UpdateColorTable(COLORREF *apColors/*[32]*/,
lca.crForeColor = lca.crOrigForeColor = apColors[lca.nForeIdx];
lca.crBackColor = lca.crOrigBackColor = apColors[lca.nBackIdx];

// New feature, apply modified lightness for text colors
// if text color is indistinguishable with background
if (bVividColors && (lca.crForeColor != lca.crBackColor))
{
ColorFix textColor(lca.crForeColor);
ColorFix vivid;
if (textColor.PerceivableColor(lca.crBackColor, vivid, &oldDE, &newDE))
{
if (mp_RCon->isLogging())
{
swprintf_s(szLog, L"VividColor [Bg=%u] {%u %u %u} [Fg=%u] {%u %u %u} [DE=%.2f] >> {%u %u %u} [DE=%.2f]",
nBack, getR(lca.crBackColor), getG(lca.crBackColor), getB(lca.crBackColor),
nFore, textColor.r, textColor.g, textColor.b, oldDE,
vivid.r, vivid.g, vivid.b, newDE);
mp_RCon->LogString(szLog);
}

lca.crForeColor = vivid.rgb;
}
}

m_TableOrg[nColorIndex] = lca;
}
}
Expand Down Expand Up @@ -140,6 +167,7 @@ void CRConPalette::UpdateColorTable(COLORREF *apColors/*[32]*/,

// Done, remember settings
mb_Initialized = true;
mb_VividColors = bVividColors;
mb_ExtendFonts = bExtendFonts;
mn_FontNormalColor = nFontNormalColor;
mn_FontBoldColor = nFontBoldColor;
Expand Down
2 changes: 2 additions & 0 deletions src/ConEmu/RConPalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class CRConPalette

protected:
bool mb_Initialized;
bool mb_VividColors;
bool mb_ExtendFonts;
BYTE mn_FontNormalColor, mn_FontBoldColor, mn_FontItalicColor;

Expand All @@ -55,6 +56,7 @@ class CRConPalette
public:
// Methods
void UpdateColorTable(COLORREF *apColors/*[32]*/,
bool bVividColors,
bool bExtendFonts, BYTE nFontNormalColor, BYTE nFontBoldColor, BYTE nFontItalicColor);

};
1 change: 1 addition & 0 deletions src/ConEmu/RealBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5671,6 +5671,7 @@ void CRealBuffer::PrepareColorTable(const AppSettings* pApp, CharAttr** pcaTable

// Optimized, palettes are recalculated only when changes are detected
mp_RCon->mp_Palette->UpdateColorTable(mp_RCon->mp_VCon->GetColors()/*[16+]*/,
gpSet->isVividColors,
bExtendFonts, nFontNormalColor, nFontBoldColor, nFontItalicColor);

if (pcaTableOrg)
Expand Down
14 changes: 14 additions & 0 deletions src/ConEmu/SetDlgButtons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,9 @@ bool CSetDlgButtons::ProcessButtonClick(HWND hDlg, WORD CB, BYTE uCheck)
case cbTrueColorer:
OnBtn_TrueColorer(hDlg, CB, uCheck);
break;
case cbVividColors:
OnBtn_VividColors(hDlg, CB, uCheck);
break;
case cbFadeInactive:
OnBtn_FadeInactive(hDlg, CB, uCheck);
break;
Expand Down Expand Up @@ -3707,6 +3710,17 @@ void CSetDlgButtons::OnBtn_TrueColorer(HWND hDlg, WORD CB, BYTE uCheck)
} // cbTrueColorer


// cbVividColors
void CSetDlgButtons::OnBtn_VividColors(HWND hDlg, WORD CB, BYTE uCheck)
{
_ASSERTE(CB==cbVividColors);

gpSet->isVividColors = _bool(uCheck);
gpConEmu->Update(true);

} // cbVividColors


// cbFadeInactive
void CSetDlgButtons::OnBtn_FadeInactive(HWND hDlg, WORD CB, BYTE uCheck)
{
Expand Down
1 change: 1 addition & 0 deletions src/ConEmu/SetDlgButtons.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class CSetDlgButtons : public CDlgItemHelper
static void OnBtn_ColorResetExt(HWND hDlg, WORD CB, BYTE uCheck);
static void OnBtn_ColorSchemeSaveDelete(HWND hDlg, WORD CB, BYTE uCheck);
static void OnBtn_TrueColorer(HWND hDlg, WORD CB, BYTE uCheck);
static void OnBtn_VividColors(HWND hDlg, WORD CB, BYTE uCheck);
static void OnBtn_FadeInactive(HWND hDlg, WORD CB, BYTE uCheck);
static void OnBtn_Transparent(HWND hDlg, WORD CB, BYTE uCheck);
static void OnBtn_TransparentSeparate(HWND hDlg, WORD CB, BYTE uCheck);
Expand Down
1 change: 1 addition & 0 deletions src/ConEmu/SetPgColors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ LRESULT CSetPgColors::OnInitDialog(HWND hDlg, bool abInitial)
checkDlgButton(hDlg, cbExtendColors, gpSet->AppStd.isExtendColors ? BST_CHECKED : BST_UNCHECKED);
CSetDlgButtons::OnButtonClicked(hDlg, cbExtendColors, 0);
checkDlgButton(hDlg, cbTrueColorer, gpSet->isTrueColorer ? BST_CHECKED : BST_UNCHECKED);
checkDlgButton(hDlg, cbVividColors, gpSet->isVividColors ? BST_CHECKED : BST_UNCHECKED);
checkDlgButton(hDlg, cbFadeInactive, gpSet->isFadeInactive ? BST_CHECKED : BST_UNCHECKED);
SetDlgItemInt(hDlg, tFadeLow, gpSet->mn_FadeLow, FALSE);
SetDlgItemInt(hDlg, tFadeHigh, gpSet->mn_FadeHigh, FALSE);
Expand Down
1 change: 1 addition & 0 deletions src/ConEmu/makefile_gcc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ SRCS = \
Background.cpp \
BaseDragDrops.cpp \
CmdHistory.cpp \
ColorFix.cpp \
ConEmu.cpp \
ConEmuApp.cpp \
ConEmuCtrl.cpp \
Expand Down
3 changes: 3 additions & 0 deletions src/ConEmu/makefile_vc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ $(INTDIR)\BaseDragDrops.obj \
$(INTDIR)\CEStr.obj \
$(INTDIR)\CmdHistory.obj \
$(INTDIR)\CmdLine.obj \
$(INTDIR)\ColorFix.obj \
$(INTDIR)\Common.obj \
$(INTDIR)\ConEmu.obj \
$(INTDIR)\ConEmuApp.obj \
Expand Down Expand Up @@ -350,6 +351,8 @@ $(INTDIR)\CmdHistory.obj: CmdHistory.cpp CmdHistory.h

$(INTDIR)\CmdLine.obj: ../common/CmdLine.cpp ../common/CmdLine.h

$(INTDIR)\ColorFix.obj: ColorFix.cpp ColorFix.h

$(INTDIR)\Common.obj: ../common/Common.cpp ../common/Common.h

$(INTDIR)\ConEmu.obj: ConEmu.cpp Version.h GuiServer.h GestureEngine.h ../common/PipeServer.h
Expand Down
3 changes: 2 additions & 1 deletion src/ConEmu/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,7 @@
#define lbHotKeyFilter 3053
#define stElevatedConsolesGroup 3054
#define gbTabDblClkActions 3055
#define cbVividColors 3056
#define IDC_STATIC -1

// Next default values for new objects
Expand All @@ -1338,7 +1339,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 235
#define _APS_NEXT_COMMAND_VALUE 40010
#define _APS_NEXT_CONTROL_VALUE 3056
#define _APS_NEXT_CONTROL_VALUE 3057
#define _APS_NEXT_SYMED_VALUE 130
#endif
#endif

0 comments on commit 51ba398

Please sign in to comment.