Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding some feature to Palette Dialog #327

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 94 additions & 40 deletions src/drivers/win/debugger.cpp

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/drivers/win/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ extern class DebugSystem {
HFONT hFixedFont;
int fixedFontWidth;
int fixedFontHeight;
int fixedFontLineHeight;

HFONT hIDAFont;
int IDAFontLineHeight;

HFONT hDisasmFont;
int disasmFontHeight;

int disasmLineHeight;

HFONT hHexeditorFont;
int HexeditorFontWidth;
Expand Down Expand Up @@ -138,7 +141,7 @@ _OP(DbgRts, 187, 80, 93) /* Imayou */
#define SPCLR(pf, name, suf) pf SBCLR(name, suf)
#define CSCLR(pf, name, suf, op, val) SPCLR(pf, name, suf) op val
#define CNRGB(pf, name, op, r, g, b, sep) CSCLR(pf, name, R, op, r) sep CSCLR(pf, name, G, op, g) sep CSCLR(pf, name, B, op, b)
#define PPRGB(name) NULL, CNRGB(&, name, , , , , _COMMA)
#define PPRGB(name) CNRGB(&, name, , , , , _COMMA), NULL
#define MKRGB(name) (RGB(SBCLR(name, R), SBCLR(name, G), SBCLR(name, B)))
#define DEFRGB(name, r, g, b) CNRGB( , name, =, r, g, b, _COMMA)
#define DCLRGB(name, r, g, b) CNRGB( , name, , , , , _COMMA)
Expand Down
100 changes: 78 additions & 22 deletions src/drivers/win/memview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2396,7 +2396,7 @@ LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case ID_COLOR_HEXEDITOR + 9:
{
int index = wParam - ID_COLOR_HEXEDITOR;
if (ChangeColor(hwnd, &hexcolormenu[index]))
if (ChangeColor(hwnd, (CHOOSECOLORINFO*)&hexcolormenu[index]))
{
UpdateColorTable();
ModifyColorMenu(hwnd, GetHexColorMenu(hwnd), &hexcolormenu[index], index, wParam);
Expand Down Expand Up @@ -2426,7 +2426,7 @@ LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case ID_COLOR_CDLOGGER + 9:
{
int index = wParam - ID_COLOR_CDLOGGER;
if (ChangeColor(hwnd, &cdlcolormenu[index]))
if (ChangeColor(hwnd, (CHOOSECOLORINFO*)&cdlcolormenu[index]))
{
UpdateColorTable();
ModifyColorMenu(hwnd, GetCdlColorMenu(hwnd), &cdlcolormenu[index], index, wParam);
Expand All @@ -2438,7 +2438,7 @@ LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
{
RestoreDefaultCdlColor();
UpdateColorTable();
for (int i = 0; i < sizeof(hexcolormenu) / sizeof(COLORMENU); ++i)
for (int i = 0; i < sizeof(cdlcolormenu) / sizeof(COLORMENU); ++i)
ModifyColorMenu(hwnd, GetCdlColorMenu(hwnd), &cdlcolormenu[i], i, ID_COLOR_CDLOGGER + i);
}
break;
Expand Down Expand Up @@ -3241,16 +3241,18 @@ void SwitchEditingText(int editingText) {
}
}

bool ChangeColor(HWND hwnd, COLORMENU* item)
bool ChangeColor(HWND hwnd, CHOOSECOLORINFO* item)
{
int backup = RGB(*item->r, *item->g, *item->b);
CHOOSECOLOR choose;
memset(&choose, 0, sizeof(CHOOSECOLOR));
choose.lStructSize = sizeof(CHOOSECOLOR);
choose.hwndOwner = hwnd;
choose.rgbResult = backup;
choose.lCustData = (LPARAM)item;
choose.lpCustColors = custom_color;
choose.Flags = CC_RGBINIT | CC_FULLOPEN | CC_ANYCOLOR;
choose.lpfnHook = (LPCCHOOKPROC)ChooseColorHookProc;
choose.Flags = CC_RGBINIT | CC_FULLOPEN | CC_ANYCOLOR | CC_ENABLEHOOK;
if (ChooseColor(&choose) && choose.rgbResult != backup)
{
*item->r = GetRValue(choose.rgbResult);
Expand All @@ -3270,26 +3272,16 @@ BOOL OpColorMenu(HWND hwnd, HMENU menu, COLORMENU* item, int pos, int id, BOOL (
memset(&info, 0, sizeof(MENUITEMINFO));
info.cbSize = sizeof(MENUITEMINFO);

if (item->text)
CHOOSECOLORINFO *color_info = (CHOOSECOLORINFO*)item;
if (color_info->name)
{
HDC hdc = GetDC(hwnd);
HDC memdc = CreateCompatibleDC(hdc);

int width = GetSystemMetrics(SM_CXMENUCHECK);
int height = GetSystemMetrics(SM_CYMENUCHECK);

if (!item->bitmap)
item->bitmap = CreateCompatibleBitmap(hdc, width, height);
SelectObject(memdc, item->bitmap);
HBRUSH brush = CreateSolidBrush(RGB(*item->r, *item->g, *item->b));
RECT rect = { 1, 1, width - 1, height - 1};
FillRect(memdc, &rect, brush);
DeleteObject(brush);
DeleteDC(memdc);
ReleaseDC(hwnd, hdc);

if (item->bitmap)
DeleteObject(item->bitmap);
item->bitmap = CreateColorBitmap(hwnd, GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CYMENUCHECK), RGB(*color_info->r, *color_info->g, *color_info->b));

char menu_str[64];
sprintf(menu_str, "%s\t#%02X%02X%02X", item->text, *item->r, *item->g, *item->b);
sprintf(menu_str, "%s\t#%02X%02X%02X", color_info->name, *color_info->r, *color_info->g, *color_info->b);

info.dwTypeData = menu_str;
info.cch = strlen(menu_str);
Expand All @@ -3306,4 +3298,68 @@ BOOL OpColorMenu(HWND hwnd, HMENU menu, COLORMENU* item, int pos, int id, BOOL (
}

return opMenu(menu, pos, TRUE, &info);
}

UINT CALLBACK ChooseColorHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
static HICON icon;

switch (uiMsg)
{
case WM_INITDIALOG:
{
CHOOSECOLORINFO* item = (CHOOSECOLORINFO*)((CHOOSECOLOR*)lParam)->lCustData;

char title[128];
strcpy(title, "Choose color for ");
strcat(title, item->name);
SetWindowText(hdlg, title);

icon = CreateChooseColorIcon(hdlg, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), RGB(*item->r, *item->g, *item->b));
SendMessage(hdlg, WM_SETICON, ICON_SMALL, (LPARAM)icon);
break;
}
case WM_CLOSE:
case WM_QUIT:
DestroyIcon(icon);
}

return FALSE;
}

HBITMAP CreateColorBitmap(HWND hwnd, int width, int height, COLORREF color)
{

HDC hdc = GetDC(hwnd);
HDC memdc = CreateCompatibleDC(hdc);

HBITMAP bitmap = CreateCompatibleBitmap(hdc, width, height);
HGDIOBJ oldObj = SelectObject(memdc, bitmap);
HBRUSH brush = CreateSolidBrush(color);
RECT rect = { 1, 1, width - 1, height - 1 };
FillRect(memdc, &rect, brush);

SelectObject(memdc, oldObj);
DeleteObject(brush);
DeleteDC(memdc);
ReleaseDC(hwnd, hdc);

return bitmap;
}

HICON CreateChooseColorIcon(HWND hwnd, int width, int height, COLORREF color)
{

HBITMAP bitmap = CreateColorBitmap(hwnd, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), color);

ICONINFO info;
memset(&info, 0, sizeof(ICONINFO));
info.hbmColor = bitmap;
info.hbmMask = bitmap;
info.fIcon = true;
HICON icon = CreateIconIndirect(&info);

DeleteObject(bitmap);

return icon;
}
15 changes: 12 additions & 3 deletions src/drivers/win/memview.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,24 @@ extern int EditingMode;

extern char* EditString[4];

struct CHOOSECOLORINFO
{
char* name;
int *r, *g, *b;
};

struct COLORMENU {
char* text;
CHOOSECOLORINFO info;
HBITMAP bitmap;
int *r, *g, *b;
};
bool ChangeColor(HWND hwnd, COLORMENU* item);
bool ChangeColor(HWND hwnd, CHOOSECOLORINFO* item);
BOOL OpColorMenu(HWND hwnd, HMENU menu, COLORMENU* item, int pos, int id, BOOL (WINAPI *opMenu)(HMENU hmenu, UINT item, BOOL byPos, LPCMENUITEMINFO info));
#define InsertColorMenu(hwnd, menu, item, pos, id) OpColorMenu(hwnd, menu, item, pos, id, InsertMenuItem)
#define ModifyColorMenu(hwnd, menu, item, pos, id) OpColorMenu(hwnd, menu, item, pos, id, SetMenuItemInfo)
#define GetHexColorMenu(hwnd) (GetSubMenu(GetSubMenu(GetMenu(hwnd), HIGHLIGHTING_SUBMENU_POS), HEXEDITOR_COLOR_SUBMENU_POS))
#define GetCdlColorMenu(hwnd) (GetSubMenu(GetSubMenu(GetMenu(hwnd), HIGHLIGHTING_SUBMENU_POS), CDLOGGER_COLOR_SUBMENU_POS))

UINT CALLBACK ChooseColorHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam);
HBITMAP CreateColorBitmap(HWND hwnd, int width, int height, COLORREF color);
HICON CreateChooseColorIcon(HWND hwnd, int width, int height, COLORREF color);
#endif
10 changes: 5 additions & 5 deletions src/drivers/win/memwatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ static INT_PTR CALLBACK MemWatchCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LP
xPositions[i] = r.left;

// experimental: limit the text length and input to hex values
SendDlgItemMessage(hwndDlg, MW_ADDR[i], EM_SETLIMITTEXT, 4, 0);
SendDlgItemMessage(hwndDlg, MW_ADDR[i], EM_SETLIMITTEXT, 6, 0);
DefaultEditCtrlProc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hwndDlg, MW_ADDR[i]), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc);
}

Expand Down Expand Up @@ -1085,8 +1085,8 @@ void RamChange()
{
case 0: whichADDR = 0; break; //Addr 1
case 1: whichADDR = 1; break; //Addr 2
case 2: whichADDR = 11; break; //Addr 12
case 3: whichADDR = 12; break; //Addr 13
case 2: whichADDR = 12; break; //Addr 13
case 3: whichADDR = 13; break; //Addr 14
}
GetDlgItemText(hwndMemWatch, MW_ADDR[whichADDR], editboxnow[x], 6); //Get Address value of edit00
SetDlgItemText(hwndMemWatch, MW_RMADDR[x], editboxnow[x]); //Put Address value
Expand Down Expand Up @@ -1129,11 +1129,11 @@ void RamChange()

}
sprintf(editchangem[x], "%d", editcount[x]); //Convert counter to text
SetDlgItemText(hwndMemWatch, EDIT00_RESULTS+x, editchangem[x]); //Display text in results box
SetDlgItemText(hwndMemWatch, MW_RESULT[x], editchangem[x]); //Display text in results box
}
else
{
SetDlgItemText(hwndMemWatch, MEMW_EDIT00RMADDRESS+x, "");
SetDlgItemText(hwndMemWatch, MW_RMADDR[x], "");
}
} //End of for loop
}
Expand Down
Loading