Skip to content

Commit

Permalink
Settings Fonts and Colors dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
nzeemin committed Jul 24, 2020
1 parent b29256f commit 8584a61
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 24 deletions.
173 changes: 152 additions & 21 deletions emulator/Dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ INT_PTR CALLBACK AboutBoxProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa
INT_PTR CALLBACK InputBoxProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK CreateDiskProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK SettingsColorsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK DcbEditorProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK ConfigDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);

Expand Down Expand Up @@ -392,21 +393,6 @@ int CALLBACK SettingsDialog_EnumFontProc(const LOGFONT* lpelfe, const TEXTMETRIC
return TRUE;
}

void FillDebugFontCombo(HWND hCombo)
{
LOGFONT logfont; ZeroMemory(&logfont, sizeof logfont);
logfont.lfCharSet = DEFAULT_CHARSET;
logfont.lfWeight = FW_NORMAL;
logfont.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;

HDC hdc = GetDC(NULL);
EnumFontFamiliesEx(hdc, &logfont, (FONTENUMPROC)SettingsDialog_EnumFontProc, (LPARAM)hCombo, 0);
ReleaseDC(NULL, hdc);

Settings_GetDebugFontName(logfont.lfFaceName);
::SendMessage(hCombo, CB_SELECTSTRING, 0, (LPARAM)logfont.lfFaceName);
}

INT_PTR CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM /*lParam*/)
{
switch (message)
Expand All @@ -425,9 +411,6 @@ INT_PTR CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM /*l
HWND hScreenshotMode = GetDlgItem(hDlg, IDC_SCREENSHOTMODE);
FillScreenshotModeCombo(hScreenshotMode);

HWND hDebugFont = GetDlgItem(hDlg, IDC_DEBUGFONT);
FillDebugFontCombo(hDebugFont);

TCHAR buffer[10];

Settings_GetSerialPort(buffer);
Expand Down Expand Up @@ -471,9 +454,6 @@ INT_PTR CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM /*l

Settings_SetSerialConfig(&m_DialogSettings_SerialConfig);
Settings_SetNetComConfig(&m_DialogSettings_NetComConfig);

GetDlgItemText(hDlg, IDC_DEBUGFONT, buffer, 32);
Settings_SetDebugFontName(buffer);
}

EndDialog(hDlg, LOWORD(wParam));
Expand Down Expand Up @@ -502,6 +482,157 @@ INT_PTR CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM /*l
}


//////////////////////////////////////////////////////////////////////
// Settings Colors Dialog

BOOL ShowSettingsColorsDialog()
{
return IDOK == DialogBox(g_hInst, MAKEINTRESOURCE(IDD_SETTINGS_COLORS), g_hwnd, SettingsColorsProc);
}

void SettingsDialog_FillDebugFontCombo(HWND hCombo)
{
LOGFONT logfont; ZeroMemory(&logfont, sizeof logfont);
logfont.lfCharSet = DEFAULT_CHARSET;
logfont.lfWeight = FW_NORMAL;
logfont.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;

HDC hdc = GetDC(NULL);
EnumFontFamiliesEx(hdc, &logfont, (FONTENUMPROC)SettingsDialog_EnumFontProc, (LPARAM)hCombo, 0);
ReleaseDC(NULL, hdc);

Settings_GetDebugFontName(logfont.lfFaceName);
::SendMessage(hCombo, CB_SELECTSTRING, 0, (LPARAM)logfont.lfFaceName);
}

void SettingsDialog_FillColorsList(HWND hList)
{
for (int itemIndex = 0; itemIndex < ColorIndicesCount; itemIndex++)
{
LPCTSTR colorName = Settings_GetColorName((ColorIndices)itemIndex);
::SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)colorName);
::SendMessage(hList, LB_SETITEMDATA, itemIndex, (LPARAM)Settings_GetColor((ColorIndices)itemIndex));
}

::SendMessage(hList, LB_SETCURSEL, 0, 0);
}

void SettingsDialog_OnColorListDrawItem(PDRAWITEMSTRUCT lpDrawItem)
{
if (lpDrawItem->itemID == -1) return;

HDC hdc = lpDrawItem->hDC;
switch (lpDrawItem->itemAction)
{
case ODA_DRAWENTIRE:
case ODA_SELECT:
{
HBRUSH hBrushBk = ::GetSysColorBrush((lpDrawItem->itemState & ODS_SELECTED) ? COLOR_HIGHLIGHT : COLOR_WINDOW);
::FillRect(hdc, &lpDrawItem->rcItem, hBrushBk);

int colorIndex = lpDrawItem->itemID;
COLORREF color = (COLORREF)(lpDrawItem->itemData);

HBRUSH hBrush = ::CreateSolidBrush(color);
RECT rcFill; ::CopyRect(&rcFill, &lpDrawItem->rcItem);
::InflateRect(&rcFill, -1, -1);
rcFill.left = rcFill.right - 50;
::FillRect(hdc, &rcFill, hBrush);

::SetTextColor(hdc, ::GetSysColor((lpDrawItem->itemState & ODS_SELECTED) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT));
RECT rcText; ::CopyRect(&rcText, &lpDrawItem->rcItem);
::InflateRect(&rcText, -2, 0);
LPCTSTR colorName = Settings_GetColorName((ColorIndices)colorIndex);
::DrawText(hdc, colorName, _tcslen(colorName), &rcText, DT_LEFT | DT_NOPREFIX);
}
break;
case ODA_FOCUS:
break;
}
}

void SettingsDialog_OnChooseColor(HWND hDlg)
{
static COLORREF acrCustClr[16]; // array of custom colors

HWND hList = GetDlgItem(hDlg, IDC_LIST1);
int itemIndex = ::SendMessage(hList, LB_GETCURSEL, 0, 0);
COLORREF color = ::SendMessage(hList, LB_GETITEMDATA, itemIndex, 0);

CHOOSECOLOR cc; memset(&cc, 0, sizeof(cc));
cc.lStructSize = sizeof(cc);
cc.hwndOwner = hDlg;
cc.lpCustColors = (LPDWORD)acrCustClr;
cc.rgbResult = color;
cc.Flags = CC_FULLOPEN | CC_RGBINIT;

if (::ChooseColor(&cc))
{
::SendMessage(hList, LB_SETITEMDATA, itemIndex, (LPARAM)cc.rgbResult);
::InvalidateRect(hList, NULL, TRUE);
}
}

void SettingsDialog_SaveFontsAndColors(HWND hDlg)
{
TCHAR buffer[32];
GetDlgItemText(hDlg, IDC_DEBUGFONT, buffer, 32);
Settings_SetDebugFontName(buffer);

HWND hList = GetDlgItem(hDlg, IDC_LIST1);
for (int itemIndex = 0; itemIndex < ColorIndicesCount; itemIndex++)
{
COLORREF color = ::SendMessage(hList, LB_GETITEMDATA, itemIndex, 0);
Settings_SetColor((ColorIndices)itemIndex, color);
}
}

INT_PTR CALLBACK SettingsColorsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
HWND hDebugFont = GetDlgItem(hDlg, IDC_DEBUGFONT);
SettingsDialog_FillDebugFontCombo(hDebugFont);

HWND hColorList = GetDlgItem(hDlg, IDC_LIST1);
SettingsDialog_FillColorsList(hColorList);

return (INT_PTR)FALSE;
}
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_BUTTON1:
SettingsDialog_OnChooseColor(hDlg);
break;
case IDOK:
SettingsDialog_SaveFontsAndColors(hDlg);
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
case IDCANCEL:
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
default:
return (INT_PTR)FALSE;
}
break;
case WM_CTLCOLORLISTBOX:
return (LRESULT)CreateSolidBrush(GetSysColor(COLOR_WINDOW));
case WM_DRAWITEM:
{
PDRAWITEMSTRUCT pdis = (PDRAWITEMSTRUCT)lParam;
if (pdis->itemID == -1) break;
SettingsDialog_OnColorListDrawItem(pdis);
break;
}
break;
}
return (INT_PTR)FALSE;
}


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


Expand Down
2 changes: 2 additions & 0 deletions emulator/Dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ void ShowCreateDiskDialog();

void ShowSettingsDialog();

BOOL ShowSettingsColorsDialog();

void ShowSerialPortSettings(DCB * pDCB);

void ShowConfigurationDialog();
Expand Down
3 changes: 3 additions & 0 deletions emulator/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ void Settings_GetNetComPort(LPTSTR buffer);
void Settings_SetNetComPort(LPCTSTR sValue);
void Settings_GetNetComConfig(DCB * pDcb);
void Settings_SetNetComConfig(const DCB * pDcb);

LPCTSTR Settings_GetColorName(ColorIndices colorIndex);
COLORREF Settings_GetColor(ColorIndices colorIndex);
void Settings_SetColor(ColorIndices colorIndex, COLORREF color);


//////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 12 additions & 0 deletions emulator/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void MainWindow_DoFileScreenshotSaveAs();
void MainWindow_DoFileScreenToClipboard();
void MainWindow_DoFileCreateDisk();
void MainWindow_DoFileSettings();
void MainWindow_DoFileSettingsColors();
void MainWindow_DoEmulatorConfiguration();
void MainWindow_OnStatusbarClick(LPNMMOUSE lpnm);
void MainWindow_OnStatusbarDrawItem(LPDRAWITEMSTRUCT);
Expand Down Expand Up @@ -1105,6 +1106,9 @@ bool MainWindow_DoCommand(int commandId)
case ID_FILE_SETTINGS:
MainWindow_DoFileSettings();
break;
case ID_FILE_SETTINGS_COLORS:
MainWindow_DoFileSettingsColors();
break;
case ID_EMULATOR_CONFIGURATION:
ShowConfigurationDialog();
break;
Expand Down Expand Up @@ -1428,6 +1432,14 @@ void MainWindow_DoFileSettings()
ShowSettingsDialog();
}

void MainWindow_DoFileSettingsColors()
{
if (ShowSettingsColorsDialog())
{
RedrawWindow(g_hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN);
}
}

void MainWindow_DoEmulatorFloppy(int slot)
{
BOOL okImageAttached = g_pBoard->IsFloppyImageAttached(slot);
Expand Down
23 changes: 23 additions & 0 deletions emulator/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,18 @@ static ColorDescriptors[ColorIndicesCount] =
{ _T("ColorDebugHint"), RGB(40, 40, 160), FALSE },
};

LPCTSTR Settings_GetColorName(ColorIndices colorIndex)
{
ColorDescriptorStruct* desc = ColorDescriptors + colorIndex;

return desc->settingname;
}

COLORREF Settings_GetColor(ColorIndices colorIndex)
{
if (colorIndex < 0 || colorIndex >= ColorIndicesCount)
return 0;

ColorDescriptorStruct* desc = ColorDescriptors + colorIndex;

if (desc->valid)
Expand All @@ -492,5 +502,18 @@ COLORREF Settings_GetColor(ColorIndices colorIndex)
return desc->color; // Return default value
}

void Settings_SetColor(ColorIndices colorIndex, COLORREF color)
{
if (colorIndex < 0 || colorIndex >= ColorIndicesCount)
return;

ColorDescriptorStruct* desc = ColorDescriptors + colorIndex;

desc->color = color;
desc->valid = TRUE;

Settings_SaveColorValue(desc->settingname, color);
}


//////////////////////////////////////////////////////////////////////
2 changes: 2 additions & 0 deletions emulator/res/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define IDB_TOOLBAR 143
#define IDD_CREATEDISK 144
#define IDD_SETTINGS 145
#define IDD_SETTINGS_COLORS 146
#define IDR_UKNC_ROM 147
#define IDD_DCB_EDITOR 148
#define IDB_KEYBOARDMASK 149
Expand Down Expand Up @@ -60,6 +61,7 @@
#define ID_FILE_SCREENSHOTTOCLIPBOARD 32777
#define ID_FILE_CREATEDISK 32778
#define ID_FILE_SETTINGS 32779
#define ID_FILE_SETTINGS_COLORS 32780
#define ID_VIEW 32781
#define ID_VIEW_MEMORY 32782
#define ID_VIEW_KEYBOARD 32783
Expand Down
19 changes: 16 additions & 3 deletions emulator/res/UKNCBTL.rc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ BEGIN
MENUITEM "Screen Text to Clipboard", ID_FILE_SCREENTOCLIPBOARD,MFT_STRING,MFS_ENABLED
MENUITEM MFT_SEPARATOR
MENUITEM "Create Disk...", ID_FILE_CREATEDISK,MFT_STRING,MFS_ENABLED
MENUITEM "Settings", ID_FILE_SETTINGS,MFT_STRING,MFS_ENABLED
MENUITEM "Settings General", ID_FILE_SETTINGS,MFT_STRING,MFS_ENABLED
MENUITEM "Settings Fonts and Colors", ID_FILE_SETTINGS_COLORS,MFT_STRING,MFS_ENABLED
MENUITEM MFT_SEPARATOR
MENUITEM "E&xit\tAlt+F4", IDM_EXIT,MFT_STRING,MFS_ENABLED
END
Expand Down Expand Up @@ -246,8 +247,20 @@ BEGIN
LTEXT "COM port name:",IDC_STATIC,15,149,66,8
EDITTEXT IDC_NETWORKPORT,84,147,61,12,ES_UPPERCASE | ES_AUTOHSCROLL
PUSHBUTTON "Configuration",IDC_BUTTON2,150,146,74,14
LTEXT "Debug font:",IDC_STATIC,8,180,61,8
COMBOBOX IDC_DEBUGFONT,84,178,147,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
DEFPUSHBUTTON "OK",IDOK,136,218,50,14
PUSHBUTTON "Cancel",IDCANCEL,189,218,50,14
END

IDD_SETTINGS_COLORS DIALOGEX 64, 40, 246, 239
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Settings Fonts and Colors"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LTEXT "Debug font:",IDC_STATIC,8,15,61,8
COMBOBOX IDC_DEBUGFONT,84,13,147,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
LTEXT "Colors:",IDC_STATIC,8,32,61,8
LISTBOX IDC_LIST1,8,42,160,160,LBS_NOTIFY | WS_BORDER | WS_VSCROLL | LBS_DISABLENOSCROLL | LBS_OWNERDRAWFIXED
PUSHBUTTON "Choose Color",IDC_BUTTON1,172,42,64,14
DEFPUSHBUTTON "OK",IDOK,136,218,50,14
PUSHBUTTON "Cancel",IDCANCEL,189,218,50,14
END
Expand Down

0 comments on commit 8584a61

Please sign in to comment.