Skip to content

Commit

Permalink
Use more convenient format for color settings
Browse files Browse the repository at this point in the history
We are storing color settings in BBGGRR format (for historical reasons).
This may be confusing for people that are used to (more widely used) RRGGBB format.

Thus we will present color settings in RRGGBB format when editing.

We will still use BBGGRR format for those settings internally. To
maintain backward compatibility with existing settings stored in
registry/xml.

Also setting descriptions now contain hint about expected color format.
This way it should be more clear what values `Open-Shell` expects.

Fixes Open-Shell#82, Open-Shell#1141.
  • Loading branch information
ge0rdi committed Nov 30, 2022
1 parent 5c31b6d commit 55c76ce
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 31 deletions.
12 changes: 6 additions & 6 deletions Src/ClassicIE/ClassicIEDLL/ClassicIEDLL.rc
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,25 @@ BEGIN
IDS_LANGUAGE_SETTINGS "Language"
IDS_CAPTION_FONT "Caption font"
IDS_CAPTION_FONT_TIP "Select the font and text size to use for the caption"
IDS_TEXT_COLOR "Text color"
IDS_TEXT_COLOR "Text color (RRGGBB)"
IDS_TEXT_COLOR_TIP "Select the color for the caption text"
IDS_MAXTEXT_COLOR "Text color (maximized)"
IDS_MAXTEXT_COLOR "Text color (maximized) (RRGGBB)"
IDS_MAXTEXT_COLOR_TIP "Select the color for the caption text when the window is maximized"
IDS_INTEXT_COLOR "Text color (inactive)"
IDS_INTEXT_COLOR "Text color (inactive) (RRGGBB)"
IDS_INTEXT_COLOR_TIP "Select the color for the caption text when the window is inactive"
IDS_MAXINTEXT_COLOR "Text color (maximized, inactive)"
IDS_MAXINTEXT_COLOR "Text color (maximized, inactive) (RRGGBB)"
IDS_MAXINTEXT_COLOR_TIP "Select the color for the caption text when the window is maximized and inactive"
IDS_GLOW "Text glow"
IDS_GLOW_TIP "When this is checked, the text will have a glow around it"
IDS_GLOW_COLOR "Glow color"
IDS_GLOW_COLOR "Glow color (RRGGBB)"
IDS_GLOW_COLOR_TIP "Select the color for the caption glow"
END

STRINGTABLE
BEGIN
IDS_MAXGLOW "Text glow (maximized)"
IDS_MAXGLOW_TIP "When this is checked, the text in the maximized window will have a glow around it"
IDS_MAXGLOW_COLOR "Glow color (maximized)"
IDS_MAXGLOW_COLOR "Glow color (maximized) (RRGGBB)"
IDS_MAXGLOW_COLOR_TIP "Select the color for the caption glow when the window is maximized"
IDS_STATUS_SETTINGS "Status Bar"
IDS_SHOW_PROGRESS "Show progress"
Expand Down
28 changes: 21 additions & 7 deletions Src/Lib/SettingsUIHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2651,15 +2651,14 @@ LRESULT CTreeSettingsDlg::OnBrowse( WORD wNotifyCode, WORD wID, HWND hWndCtl, BO
CString str;
m_EditBox.GetWindowText(str);
str.TrimLeft(); str.TrimRight();
wchar_t *end;
COLORREF val=wcstol(str,&end,16)&0xFFFFFF;
COLORREF val=RgbToBgr(ParseColor(str));
static COLORREF customColors[16];
CHOOSECOLOR choose={sizeof(choose),m_hWnd,NULL,val,customColors};
choose.Flags=CC_ANYCOLOR|CC_FULLOPEN|CC_RGBINIT;
if (ChooseColor(&choose))
{
wchar_t text[100];
Sprintf(text,_countof(text),L"%06X",choose.rgbResult);
Sprintf(text,_countof(text),L"%06X",BgrToRgb(choose.rgbResult));
m_EditBox.SetWindowText(text);
ApplyEditBox();
UpdateGroup(m_pEditSetting);
Expand Down Expand Up @@ -3048,8 +3047,7 @@ void CTreeSettingsDlg::ApplyEditBox( void )
}
else if (pSetting->type==CSetting::TYPE_COLOR)
{
wchar_t *end;
int val=wcstol(str,&end,16)&0xFFFFFF;
int val=RgbToBgr(ParseColor(str));
if (pSetting->value.vt!=VT_I4 || pSetting->value.intVal!=val)
{
pSetting->value=CComVariant(val);
Expand Down Expand Up @@ -3156,7 +3154,7 @@ void CTreeSettingsDlg::ItemSelected( HTREEITEM hItem, CSetting *pSetting, bool b
mode=EDIT_COLOR;
int val=0;
if (valVar.vt==VT_I4)
val=valVar.intVal;
val=BgrToRgb(valVar.intVal);
Sprintf(text,_countof(text),L"%06X",val);
}
}
Expand Down Expand Up @@ -3462,7 +3460,7 @@ void CTreeSettingsDlg::UpdateGroup( const CSetting *pModified )
CString str=LoadStringEx(pSetting->nameID);
int val=0;
if (valVar.vt==VT_I4)
val=valVar.intVal;
val=BgrToRgb(valVar.intVal);
Sprintf(text,_countof(text),L"%s: %06X",str,val);
item.mask|=TVIF_TEXT;
}
Expand Down Expand Up @@ -3616,3 +3614,19 @@ bool CDefaultSettingsPanel::Validate( HWND parent )
s_Dialog.Validate();
return true;
}

DWORD RgbToBgr(DWORD val)
{
return ((val & 0xFF) << 16) | (val & 0xFF00) | ((val >> 16) & 0xFF);
}

DWORD BgrToRgb(DWORD val)
{
return RgbToBgr(val);
}

DWORD ParseColor(const wchar_t* str)
{
wchar_t* end;
return wcstoul(str, &end, 16) & 0xFFFFFF;
}
8 changes: 8 additions & 0 deletions Src/Lib/SettingsUIHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,11 @@ extern const GUID FOLDERID_DesktopRoot;
bool BrowseCommandHelper( HWND parent, wchar_t *text );
bool BrowseLinkHelper( HWND parent, wchar_t *text, bool bFoldersOnly );
bool BrowseIconHelper( HWND parent, wchar_t *text );

// convert color in RRGGBB format to BBGGRR
DWORD RgbToBgr(DWORD val);
// convert color in BBGGRR format to RRGGBB
DWORD BgrToRgb(DWORD val);

// parse color from hexadecimal string
DWORD ParseColor(const wchar_t* str);
39 changes: 28 additions & 11 deletions Src/StartMenu/StartMenuDLL/SettingsUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ const int DEFAULT_TASK_OPACITY10=85; // 85%

///////////////////////////////////////////////////////////////////////////////

CString RgbToBgr(const wchar_t* str)
{
CString retval;
retval.Format(L"%06X", RgbToBgr(ParseColor(str)));

return retval;
}

CString BgrToRgb(const wchar_t* str)
{
return RgbToBgr(str);
}

class CSkinSettingsDlg: public CResizeableDlg<CSkinSettingsDlg>
{
public:
Expand Down Expand Up @@ -422,7 +435,7 @@ void CSkinSettingsDlg::UpdateSkinSettings( void )
if (!option.bEnabled || bLocked)
image|=SETTING_STATE_DISABLED;
if (option.bValue && option.type>SKIN_OPTION_BOOL)
Sprintf(text,_countof(text),L"%s: %s",option.label,option.sValue);
Sprintf(text,_countof(text),L"%s: %s",option.label,(option.type==SKIN_OPTION_COLOR)?BgrToRgb(option.sValue):option.sValue);
else
Sprintf(text,_countof(text),L"%s",option.label);

Expand Down Expand Up @@ -482,9 +495,7 @@ LRESULT CSkinSettingsDlg::OnCustomDraw( int idCtrl, LPNMHDR pnmh, BOOL& bHandled
if (TreeView_GetItemRect(m_Tree,(HTREEITEM)pDraw->nmcd.dwItemSpec,&rc,TRUE))
{
const wchar_t *str=m_CurrentSkin.Options[pDraw->nmcd.lItemlParam].sValue;
wchar_t *end;
COLORREF color=wcstoul(str,&end,16);
SetDCBrushColor(pDraw->nmcd.hdc,color&0xFFFFFF);
SetDCBrushColor(pDraw->nmcd.hdc,ParseColor(str));
SelectObject(pDraw->nmcd.hdc,GetStockObject(DC_BRUSH));
SelectObject(pDraw->nmcd.hdc,GetStockObject(BLACK_PEN));
Rectangle(pDraw->nmcd.hdc,rc.right,rc.top,rc.right+rc.bottom-rc.top,rc.bottom-1);
Expand Down Expand Up @@ -690,15 +701,14 @@ LRESULT CSkinSettingsDlg::OnBrowse( WORD wNotifyCode, WORD wID, HWND hWndCtl, BO
CString str;
m_EditBox.GetWindowText(str);
str.TrimLeft(); str.TrimRight();
wchar_t *end;
COLORREF val=wcstol(str,&end,16)&0xFFFFFF;
COLORREF val=RgbToBgr(ParseColor(str));
static COLORREF customColors[16];
CHOOSECOLOR choose={sizeof(choose),m_hWnd,NULL,val,customColors};
choose.Flags=CC_ANYCOLOR|CC_FULLOPEN|CC_RGBINIT;
if (ChooseColor(&choose))
{
wchar_t text[100];
Sprintf(text,_countof(text),L"%06X",choose.rgbResult);
Sprintf(text,_countof(text),L"%06X",BgrToRgb(choose.rgbResult));
m_EditBox.SetWindowText(text);
ApplyEditBox();
m_Tree.Invalidate();
Expand All @@ -717,7 +727,11 @@ void CSkinSettingsDlg::ApplyEditBox( void )
CString str;
m_EditBox.GetWindowText(str);
str.TrimLeft(); str.TrimRight();
m_CurrentSkin.Options[m_EditItemIndex].sValue=str;
auto& option=m_CurrentSkin.Options[m_EditItemIndex];
if (option.type==SKIN_OPTION_COLOR)
option.sValue=RgbToBgr(str);
else
option.sValue=str;
StoreSkinOptions();
}
}
Expand All @@ -730,7 +744,7 @@ void CSkinSettingsDlg::ItemSelected( HTREEITEM hItem, int index, bool bEnabled )
const MenuSkin::Option &option=m_CurrentSkin.Options[m_EditItemIndex];
wchar_t text[256];
if (option.bValue && option.type>SKIN_OPTION_BOOL)
Sprintf(text,_countof(text),L"%s: %s",option.label,option.sValue);
Sprintf(text,_countof(text),L"%s: %s",option.label,(option.type==SKIN_OPTION_COLOR)?BgrToRgb(option.sValue):option.sValue);
else
Sprintf(text,_countof(text),L"%s",option.label);
TVITEM item={TVIF_TEXT,m_EditItem,0,0,text};
Expand All @@ -745,7 +759,10 @@ void CSkinSettingsDlg::ItemSelected( HTREEITEM hItem, int index, bool bEnabled )
const MenuSkin::Option &option=m_CurrentSkin.Options[index];
if (option.type>SKIN_OPTION_BOOL)
mode=option.type;
text=option.sValue;
if (option.type==SKIN_OPTION_COLOR)
text=BgrToRgb(option.sValue);
else
text=option.sValue;
}

RECT rc;
Expand Down Expand Up @@ -4946,7 +4963,7 @@ void UpdateSettings( void )
if (GetWinVersion()>WIN_VER_WIN7)
{
int color=GetSystemGlassColor8();
UpdateSetting(L"TaskbarColor",CComVariant(((color&0xFF)<<16)|(color&0xFF00)|((color>>16)&0xFF)),false);
UpdateSetting(L"TaskbarColor",CComVariant(RgbToBgr(color)),false);
}

if (GetWinVersion()<=WIN_VER_WIN7)
Expand Down
14 changes: 7 additions & 7 deletions Src/StartMenu/StartMenuDLL/StartMenuDLL.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ BEGIN
IDS_MIN_HEIGHT_TIP "The main menu will be at least as tall as this many search results"
IDS_GLASS_OVERRIDE "Override glass color"
IDS_GLASS_OVERRIDE_TIP "Check this to override the system glass color to use in the menu"
IDS_GLASS_COLOR "Menu glass color"
IDS_GLASS_COLOR "Menu glass color (RRGGBB)"
IDS_GLASS_COLOR_TIP "Select the glass color to use in the menu. How much this color affects the menu will depend on the selected skin"
IDS_GLASS_INTENSITY "Menu glass intensity"
IDS_GLASS_INTENSITY_TIP "Select the intensity (brightness) for the glass color in the menu (0 - dark, 100 - bright)"
Expand Down Expand Up @@ -1144,17 +1144,17 @@ BEGIN
IDS_STRING7024 "Shadows on glass#The text and the arrows in the second column of the main menu will have a drop shadow"
IDS_STRING7025 "Opaque"
IDS_STRING7026 "Main menu color"
IDS_STRING7027 "Custom color#Select custom color for the main menu"
IDS_STRING7027 "Custom color (RRGGBB)#Select custom color for the main menu"
IDS_STRING7028 "Sub-menu color"
IDS_STRING7029 "Custom color#Select custom color for the sub-menus"
IDS_STRING7029 "Custom color (RRGGBB)#Select custom color for the sub-menus"
IDS_STRING7030 "Silver"
IDS_STRING7031 "Gold"
IDS_STRING7032 "Steel"
IDS_STRING7033 "Titanium"
IDS_STRING7034 "Image for first column#Select custom image for the first column of the main menu"
IDS_STRING7035 "Image for second column#Select custom image for the second column of the main menu"
IDS_STRING7036 "Text color for first column#Select custom color for the first column of the main menu text"
IDS_STRING7037 "Text color for second column#Select custom color for the second column of the main menu text"
IDS_STRING7036 "Text color for first column (RRGGBB)#Select custom color for the first column of the main menu text"
IDS_STRING7037 "Text color for second column (RRGGBB)#Select custom color for the second column of the main menu text"
IDS_STRING7038 "Text size#Select custom size for the main menu text"
END

Expand Down Expand Up @@ -1249,7 +1249,7 @@ BEGIN
IDS_TASK_AEROGLASS_TIP "The taskbar will have glass transparency that is compatible with the Aero Glass mod"
IDS_TASK_OPACITY "Taskbar opacity"
IDS_TASK_OPACITY_TIP "Set the opacity for the taskbar (0 - transparent, 100 - opaque)"
IDS_TASK_COLOR "Taskbar color"
IDS_TASK_COLOR "Taskbar color (RRGGBB)"
IDS_TASK_COLOR_TIP "Set the color for the taskbar"
IDS_PCSETTINGS "Settings"
IDS_PCSETTINGS_TIP "Shows the modern Settings window"
Expand Down Expand Up @@ -1288,7 +1288,7 @@ BEGIN
IDS_TASK_BORDERS "Border sizes"
IDS_TASK_BORDERS_TIP "Select how many pixel on each side of the texture to exclude from stretching"
IDS_TASKBAR_SETTINGS "Taskbar"
IDS_TASK_TEXTCOLOR "Taskbar text color"
IDS_TASK_TEXTCOLOR "Taskbar text color (RRGGBB)"
IDS_TASK_TEXTCOLOR_TIP "Select the color for the text on the taskbar"
IDS_SELECT_LAST "Select the last item in shutdown menu"
IDS_SELECT_LAST_TIP "When this is checked, the last item will be selected by default when the shutdown menu is opened with the keyboard"
Expand Down

0 comments on commit 55c76ce

Please # to comment.