* share common painting code

* align static control in same way

svn path=/trunk/; revision=23704
This commit is contained in:
Johannes Anderwald
2006-08-25 12:19:42 +00:00
parent a6c41b9d22
commit 50746a376e
5 changed files with 113 additions and 73 deletions
+11 -42
View File
@@ -9,7 +9,6 @@
#include "console.h"
static COLORREF s_Colors[] =
{
RGB(0, 0, 0),
@@ -30,7 +29,6 @@ static COLORREF s_Colors[] =
RGB(255, 255, 255)
};
static TCHAR szText[1024];
static
@@ -40,43 +38,6 @@ PaintStaticControls(HWND hwndDlg, PConsoleInfo pConInfo, LPDRAWITEMSTRUCT drawIt
HBRUSH hBrush;
DWORD index;
if (drawItem->CtlID < IDC_STATIC_COLOR1 || drawItem->CtlID > IDC_STATIC_COLOR16)
{
COLORREF pbkColor, ptColor;
COLORREF nbkColor, ntColor;
/* draw static controls */
if (drawItem->CtlID == IDC_STATIC_SCREEN_COLOR)
{
nbkColor = pConInfo->ScreenBackground;
hBrush = CreateSolidBrush(nbkColor);
ntColor = pConInfo->ScreenText;
}
else
{
nbkColor = pConInfo->PopupBackground;
hBrush = CreateSolidBrush(nbkColor);
ntColor = pConInfo->PopupText;
}
if (!hBrush)
{
return FALSE;
}
FillRect(drawItem->hDC, &drawItem->rcItem, hBrush);
DeleteObject((HGDIOBJ)hBrush);
ptColor = SetTextColor(drawItem->hDC, ntColor);
pbkColor = SetBkColor(drawItem->hDC, nbkColor);
if (ntColor != nbkColor)
{
/* hide text when it has same background color as text color */
DrawText(drawItem->hDC, szText, _tcslen(szText), &drawItem->rcItem, 0);
}
SetTextColor(drawItem->hDC, ptColor);
SetBkColor(drawItem->hDC, pbkColor);
return TRUE;
}
index = drawItem->CtlID - IDC_STATIC_COLOR1;
hBrush = CreateSolidBrush(s_Colors[index]);
if (!hBrush)
@@ -101,6 +62,7 @@ ColorsProc(
PConsoleInfo pConInfo;
LPNMUPDOWN lpnmud;
LPPSHNOTIFY lppsn;
LPDRAWITEMSTRUCT drawItem;
DWORD red = -1;
DWORD green = -1;
DWORD blue = -1;
@@ -113,8 +75,6 @@ ColorsProc(
{
pConInfo = (PConsoleInfo) ((LPPROPSHEETPAGE)lParam)->lParam;
SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pConInfo);
ZeroMemory(szText, sizeof(szText));
LoadString(hApplet, IDS_SCREEN_TEXT, szText, sizeof(szText) / sizeof(TCHAR));
SendMessage(GetDlgItem(hwndDlg, IDC_RADIO_SCREEN_BACKGROUND), BM_SETCHECK, BST_CHECKED, 0);
SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_COLOR_RED), UDM_SETRANGE, 0, (LPARAM)MAKELONG(255, 0));
SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_COLOR_GREEN), UDM_SETRANGE, 0, (LPARAM)MAKELONG(255, 0));
@@ -124,7 +84,16 @@ ColorsProc(
}
case WM_DRAWITEM:
{
return PaintStaticControls(hwndDlg, pConInfo, (LPDRAWITEMSTRUCT) lParam);
drawItem = (LPDRAWITEMSTRUCT)lParam;
if (drawItem->CtlID >= IDC_STATIC_COLOR1 && drawItem->CtlID <= IDC_STATIC_COLOR16)
{
return PaintStaticControls(hwndDlg, pConInfo, drawItem);
}
else if (drawItem->CtlID == IDC_STATIC_SCREEN_COLOR || drawItem->CtlID == IDC_STATIC_POPUP_COLOR)
{
PaintText(drawItem, pConInfo);
return TRUE;
}
}
case WM_NOTIFY:
{
+2
View File
@@ -41,6 +41,8 @@ typedef struct TAGConsoleInfo
BOOL WriteConsoleOptions(PConsoleInfo pConInfo);
void ApplyConsoleInfo(HWND hwndDlg, PConsoleInfo pConInfo);
void PaintConsole(LPDRAWITEMSTRUCT drawItem, PConsoleInfo pConInfo);
void PaintText(LPDRAWITEMSTRUCT drawItem, PConsoleInfo pConInfo);
//globals
+14 -14
View File
@@ -45,13 +45,13 @@ FONT 8, "MS Shell Dlg"
BEGIN
LTEXT "Window Preview", -1, 10, 7, 65, 10
LTEXT "Size", -1, 130, 10, 30, 10
CONTROL "", IDC_STATIC_FONT_WINDOW_PREVIEW, "Static", SS_BLACKRECT | SS_SUNKEN, 10, 20, 115, 70
CONTROL "", IDC_STATIC_FONT_WINDOW_PREVIEW, "Static", SS_OWNERDRAW | SS_SUNKEN, 10, 20, 115, 70
LISTBOX IDC_LBOX_FONTS, 130, 20, 55, 80, LBS_DISABLENOSCROLL | WS_VSCROLL
LTEXT "&Font", -1, 10, 105, 35, 10
CHECKBOX "&Bold fonts", IDC_CHECK_BOLD_FONTS, 45, 105, 60, 10
LISTBOX IDC_LBOX_TYPE, 10, 120, 110, 50, LBS_DISABLENOSCROLL | WS_VSCROLL
GROUPBOX "", IDC_GROUPBOX_FONT_NAME, 10, 155, 200, 50
CONTROL "", IDC_STATIC_SELECT_FONT_PREVIEW, "Static", SS_BLACKRECT | SS_SUNKEN, 15, 165, 95, 35
CONTROL "", IDC_STATIC_SELECT_FONT_PREVIEW, "Static", SS_OWNERDRAW | SS_SUNKEN, 15, 165, 95, 35
LTEXT "Each character is:", -1, 130, 165, 75, 10
LTEXT "screen pixel wide\nscreen pixel high", -1, 140, 180, 65, 20
LTEXT "", IDC_FONT_SIZE_X, 125, 180, 10, 10
@@ -63,30 +63,30 @@ STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_CAPTION
CAPTION "Layout"
FONT 8, "MS Shell Dlg"
BEGIN
LTEXT "Window Preview", -1, 10, 10, 65, 10
CONTROL "", IDC_STATIC_LAYOUT_WINDOW_PREVIEW, "Static", SS_SUNKEN | SS_OWNERDRAW, 10, 20, 100, 70
GROUPBOX "Screen Buffer Size", -1, 115, 15, 115, 40
LTEXT "&Width:", -1, 120, 30, 25, 10
LTEXT "&Height:", -1, 120, 40, 25, 10
LTEXT "Window Preview", -1, 10, 7, 65, 10
CONTROL "", IDC_STATIC_LAYOUT_WINDOW_PREVIEW, "Static", SS_SUNKEN | SS_OWNERDRAW, 10, 20, 115, 70
GROUPBOX "Screen Buffer Size", -1, 130, 15, 115, 40
LTEXT "&Width:", -1, 135, 30, 25, 10
LTEXT "&Height:", -1, 135, 40, 25, 10
EDITTEXT IDC_EDIT_SCREEN_BUFFER_WIDTH, 165, 30, 35, 10, ES_RIGHT | WS_GROUP
CONTROL "", IDC_UPDOWN_SCREEN_BUFFER_WIDTH, UPDOWN_CLASS,UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | WS_BORDER | WS_GROUP, 185, 30, 30, 10
EDITTEXT IDC_EDIT_SCREEN_BUFFER_HEIGHT, 165, 40, 35, 10, ES_RIGHT | WS_GROUP
CONTROL "", IDC_UPDOWN_SCREEN_BUFFER_HEIGHT, UPDOWN_CLASS,UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | WS_BORDER | WS_GROUP, 185, 30, 30, 10
GROUPBOX "Window Size", -1, 115, 60, 115, 40
LTEXT "&W&idth:", -1, 120, 70, 25, 10
LTEXT "&H&eight:", -1, 120, 80, 25, 10
GROUPBOX "Window Size", -1, 130, 60, 115, 40
LTEXT "&W&idth:", -1, 135, 70, 25, 10
LTEXT "&H&eight:", -1, 135, 80, 25, 10
EDITTEXT IDC_EDIT_WINDOW_SIZE_WIDTH, 165, 70, 30, 10, ES_RIGHT | WS_GROUP
CONTROL "", IDC_UPDOWN_WINDOW_SIZE_WIDTH, UPDOWN_CLASS,UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | WS_BORDER | WS_GROUP, 185, 30, 30, 10
EDITTEXT IDC_EDIT_WINDOW_SIZE_HEIGHT, 165, 80, 30, 10, ES_RIGHT | WS_GROUP
CONTROL "", IDC_UPDOWN_WINDOW_SIZE_HEIGHT, UPDOWN_CLASS,UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | WS_BORDER | WS_GROUP, 185, 30, 30, 10
GROUPBOX "Window Position", -1, 115, 105, 115, 55
LTEXT "&Left:", -1, 120, 120, 25, 10
LTEXT "&Top:", -1, 120, 130, 25, 10
GROUPBOX "Window Position", -1, 130, 105, 115, 55
LTEXT "&Left:", -1, 135, 120, 25, 10
LTEXT "&Top:", -1, 135, 130, 25, 10
EDITTEXT IDC_EDIT_WINDOW_POS_LEFT, 165, 120, 30, 10, ES_RIGHT | WS_GROUP
CONTROL "", IDC_UPDOWN_WINDOW_POS_LEFT, UPDOWN_CLASS,UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | WS_BORDER | WS_GROUP, 170, 30, 30, 10
EDITTEXT IDC_EDIT_WINDOW_POS_TOP, 165, 130, 30, 10, ES_RIGHT | WS_GROUP
CONTROL "", IDC_UPDOWN_WINDOW_POS_TOP, UPDOWN_CLASS,UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | WS_BORDER | WS_GROUP, 170, 30, 30, 10
CHECKBOX "Let system &position window", IDC_CHECK_SYSTEM_POS_WINDOW, 120, 145, 100, 10
CHECKBOX "Let system &position window", IDC_CHECK_SYSTEM_POS_WINDOW, 135, 145, 100, 10
END
IDD_PROPPAGECOLORS DIALOGEX 0, 0, 250, 220
+22 -1
View File
@@ -19,6 +19,9 @@ FontProc(
LPARAM lParam
)
{
LPDRAWITEMSTRUCT drawItem;
PConsoleInfo pConInfo = (PConsoleInfo)GetWindowLongPtr(hwndDlg, DWLP_USER);
UNREFERENCED_PARAMETER(hwndDlg);
UNREFERENCED_PARAMETER(wParam);
@@ -26,10 +29,28 @@ FontProc(
switch(uMsg)
{
case WM_INITDIALOG:
{
pConInfo = (PConsoleInfo) ((LPPROPSHEETPAGE)lParam)->lParam;
SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pConInfo);
return TRUE;
}
case WM_DRAWITEM:
{
drawItem = (LPDRAWITEMSTRUCT)lParam;
if (drawItem->CtlID == IDC_STATIC_FONT_WINDOW_PREVIEW)
{
PaintConsole(drawItem, pConInfo);
}
else if (drawItem->CtlID == IDC_STATIC_SELECT_FONT_PREVIEW)
{
PaintText(drawItem, pConInfo);
}
return TRUE;
}
default:
{
break;
}
}
return FALSE;
+64 -16
View File
@@ -9,6 +9,69 @@
#include "console.h"
void PaintConsole(LPDRAWITEMSTRUCT drawItem, PConsoleInfo pConInfo)
{
COLORREF bkColor;
HBRUSH hBrush;
bkColor = GetSysColor(COLOR_BACKGROUND);
hBrush = CreateSolidBrush(bkColor);
FillRect(drawItem->hDC, &drawItem->rcItem, hBrush);
//TODO draw console image
//MoveToEx(drawItem->hDC, 0, 0, NULL);
//LineTo(drawItem->hDC, 10, 10);
//MoveToEx(drawItem->hDC, 30, 30, NULL);
//LineTo(drawItem->hDC, 40, 40);
DeleteObject((HGDIOBJ)hBrush);
}
void PaintText(LPDRAWITEMSTRUCT drawItem, PConsoleInfo pConInfo)
{
COLORREF pbkColor, ptColor;
COLORREF nbkColor, ntColor;
HBRUSH hBrush;
TCHAR szText[1024];
ZeroMemory(szText, sizeof(szText));
LoadString(hApplet, IDS_SCREEN_TEXT, szText, sizeof(szText) / sizeof(TCHAR));
if (drawItem->CtlID == IDC_STATIC_SCREEN_COLOR)
{
nbkColor = pConInfo->ScreenBackground;
hBrush = CreateSolidBrush(nbkColor);
ntColor = pConInfo->ScreenText;
}
else
{
nbkColor = pConInfo->PopupBackground;
hBrush = CreateSolidBrush(nbkColor);
ntColor = pConInfo->PopupText;
}
if (!hBrush)
{
return;
}
FillRect(drawItem->hDC, &drawItem->rcItem, hBrush);
DeleteObject((HGDIOBJ)hBrush);
ptColor = SetTextColor(drawItem->hDC, ntColor);
pbkColor = SetBkColor(drawItem->hDC, nbkColor);
if (ntColor != nbkColor)
{
/* hide text when it has same background color as text color */
DrawText(drawItem->hDC, szText, _tcslen(szText), &drawItem->rcItem, 0);
}
SetTextColor(drawItem->hDC, ptColor);
SetBkColor(drawItem->hDC, pbkColor);
}
INT_PTR
CALLBACK
LayoutProc(
@@ -67,22 +130,7 @@ LayoutProc(
}
case WM_DRAWITEM:
{
COLORREF bkColor;
HBRUSH hBrush;
LPDRAWITEMSTRUCT drawItem;
bkColor = GetSysColor(COLOR_BACKGROUND);
hBrush = CreateSolidBrush(bkColor);
drawItem = (LPDRAWITEMSTRUCT) lParam;
FillRect(drawItem->hDC, &drawItem->rcItem, hBrush);
//TODO draw console image
// MoveToEx(drawItem->hDC, 0, 0, NULL);
// LineTo(drawItem->hDC, 10, 10);
// MoveToEx(drawItem->hDC, 30, 30, NULL);
// LineTo(drawItem->hDC, 40, 40);
DeleteObject((HGDIOBJ)hBrush);
PaintConsole((LPDRAWITEMSTRUCT)lParam, pConInfo);
return TRUE;
}
case WM_COMMAND: