* Hexeditor: fixed font spacing

This commit is contained in:
ansstuff 2012-10-14 13:52:18 +00:00
parent c08253cef7
commit a0b7c35ada
3 changed files with 76 additions and 37 deletions

View File

@ -2015,14 +2015,25 @@ DebugSystem::DebugSystem()
DEFAULT_QUALITY, DEFAULT_PITCH, /*quality, and pitch*/ DEFAULT_QUALITY, DEFAULT_PITCH, /*quality, and pitch*/
"Courier New"); /*font name*/ "Courier New"); /*font name*/
hHexeditorFont = CreateFont(14, 8, /*Height,Width*/
0,0, /*escapement,orientation*/
FW_REGULAR,FALSE,FALSE,FALSE, /*weight, italic, underline, strikeout*/
ANSI_CHARSET,OUT_DEVICE_PRECIS,CLIP_MASK, /*charset, precision, clipping*/
DEFAULT_QUALITY, DEFAULT_PITCH, /*quality, and pitch*/
"Courier New"); /*font name*/
HDC hdc = GetDC(GetDesktopWindow()); HDC hdc = GetDC(GetDesktopWindow());
HGDIOBJ old = SelectObject(hdc,hFixedFont); HGDIOBJ old = SelectObject(hdc,hFixedFont);
TEXTMETRIC tm; TEXTMETRIC tm;
GetTextMetrics(hdc,&tm); GetTextMetrics(hdc,&tm);
fixedFontHeight = tm.tmHeight; fixedFontHeight = tm.tmHeight;
fixedFontWidth = tm.tmAveCharWidth; fixedFontWidth = tm.tmAveCharWidth;
printf("fixed font height: %d\n",fixedFontHeight); //printf("fixed font height: %d\n",fixedFontHeight);
printf("fixed font width: %d\n",fixedFontWidth); //printf("fixed font width: %d\n",fixedFontWidth);
SelectObject(hdc, hHexeditorFont);
GetTextMetrics(hdc,&tm);
HexeditorFontHeight = tm.tmHeight;
HexeditorFontWidth = tm.tmAveCharWidth;
SelectObject(hdc,old); SelectObject(hdc,old);
DeleteDC(hdc); DeleteDC(hdc);
} }
@ -2030,5 +2041,6 @@ DebugSystem::DebugSystem()
DebugSystem::~DebugSystem() DebugSystem::~DebugSystem()
{ {
DeleteObject(hFixedFont); DeleteObject(hFixedFont);
DeleteObject(hHexeditorFont);
} }

View File

@ -50,6 +50,11 @@ public:
HFONT hFixedFont; HFONT hFixedFont;
int fixedFontWidth; int fixedFontWidth;
int fixedFontHeight; int fixedFontHeight;
HFONT hHexeditorFont;
int HexeditorFontWidth;
int HexeditorFontHeight;
} *debugSystem; } *debugSystem;

View File

@ -61,6 +61,7 @@ using namespace std;
string memviewhelp = "{06F7BBD5-399E-4CA0-8E4E-75BE0ACC525A}"; //Hex Editor Help Page string memviewhelp = "{06F7BBD5-399E-4CA0-8E4E-75BE0ACC525A}"; //Hex Editor Help Page
int HexRowHeightBorder = 0; //adelikat: This will determine the number of pixels between rows in the hex editor, to alter this, the user can change it in the .cfg file, changing one will revert to the way FCEUX2.1.0 did it int HexRowHeightBorder = 0; //adelikat: This will determine the number of pixels between rows in the hex editor, to alter this, the user can change it in the .cfg file, changing one will revert to the way FCEUX2.1.0 did it
int HexCharSpacing = 1; // pixels between chars
// Partial List of Color Definitions // Partial List of Color Definitions
int HexBackColorR = 255; // White int HexBackColorR = 255; // White
@ -401,14 +402,13 @@ void UnloadTableFile(){
void UpdateMemoryView(int draw_all) void UpdateMemoryView(int draw_all)
{ {
if (!hMemView) return; if (!hMemView) return;
int MemFontWidth = debugSystem->fixedFontWidth; int MemFontWidth = debugSystem->HexeditorFontWidth + HexCharSpacing;
int MemFontHeight = debugSystem->fixedFontHeight + HexRowHeightBorder; int MemFontHeight = debugSystem->HexeditorFontHeight + HexRowHeightBorder;
int i, j; int i, j;
//LPVOID lpMsgBuf; //LPVOID lpMsgBuf;
//int curlength; //int curlength;
char str[100]; char str[100];
char str2[100];
/* /*
if(draw_all){ if(draw_all){
@ -430,40 +430,55 @@ void UpdateMemoryView(int draw_all)
TextOut(HDataDC,0,0,str,strlen(str)); TextOut(HDataDC,0,0,str,strlen(str));
} }
} else {*/ } else {*/
for(i = CurOffset;i < CurOffset+DataAmount;i+=16){ for(i = CurOffset;i < CurOffset+DataAmount;i+=16)
if((OldCurOffset != CurOffset) || draw_all){ {
if((OldCurOffset != CurOffset) || draw_all)
{
MoveToEx(HDataDC,0,MemFontHeight*((i-CurOffset)/16),NULL); MoveToEx(HDataDC,0,MemFontHeight*((i-CurOffset)/16),NULL);
SetTextColor(HDataDC,RGB(HexForeColorR,HexForeColorG,HexForeColorB)); //addresses text color 000 = black, 255255255 = white SetTextColor(HDataDC,RGB(HexForeColorR,HexForeColorG,HexForeColorB)); //addresses text color 000 = black, 255255255 = white
SetBkColor(HDataDC,RGB(HexBackColorR,HexBackColorG,HexBackColorB)); //addresses back color SetBkColor(HDataDC,RGB(HexBackColorR,HexBackColorG,HexBackColorB)); //addresses back color
sprintf(str,"%06X: ",i); sprintf(str,"%06X: ",i);
TextOut(HDataDC,0,0,str,strlen(str)); TextOut(HDataDC,0,0,str,strlen(str));
} }
for(j = 0;j < 16;j++){ for(j = 0;j < 16;j++)
if((CursorEndAddy == -1) && (CursorStartAddy == i+j)){ //print up single highlighted text {
sprintf(str,"%02X",GetMemViewData(CursorStartAddy)); if((CursorEndAddy == -1) && (CursorStartAddy == i+j))
{
//print up single highlighted text
OldValues[i+j-CurOffset] = -1; //set it to redraw this one next time OldValues[i+j-CurOffset] = -1; //set it to redraw this one next time
MoveToEx(HDataDC, 8 * MemFontWidth + (j * 3 * MemFontWidth), MemFontHeight * ((i - CurOffset) / 16), NULL); MoveToEx(HDataDC, 8 * MemFontWidth + (j * 3 * MemFontWidth), MemFontHeight * ((i - CurOffset) / 16), NULL);
if(TempData != -1){ if(TempData != -1)
// Typing New Data {
sprintf(str2,"%X",TempData); // User is typing New Data
// 1st nybble
sprintf(str,"%X",TempData);
SetBkColor(HDataDC,RGB(255,255,255)); SetBkColor(HDataDC,RGB(255,255,255));
SetTextColor(HDataDC,RGB(255,0,0)); SetTextColor(HDataDC,RGB(255,0,0));
TextOut(HDataDC,0,0,str2,1); TextOut(HDataDC,0,0,str,1);
// 2nd nybble
MoveToEx(HDataDC, MemFontWidth + 8 * MemFontWidth + (j * 3 * MemFontWidth), MemFontHeight * ((i - CurOffset) / 16), NULL);
sprintf(str,"%X",GetMemViewData(CursorStartAddy) % 16);
SetTextColor(HDataDC,RGB(HexBackColorR,HexBackColorG,HexBackColorB)); SetTextColor(HDataDC,RGB(HexBackColorR,HexBackColorG,HexBackColorB));
SetBkColor(HDataDC,RGB(HexForeColorR,HexForeColorG,HexForeColorB)); SetBkColor(HDataDC,RGB(HexForeColorR,HexForeColorG,HexForeColorB));
TextOut(HDataDC,0,0,&str[1],1); TextOut(HDataDC, 0, 0, str, 1);
} else { } else
{
// Selecting a Single Byte // Selecting a Single Byte
sprintf(str,"%X",(int)(GetMemViewData(CursorStartAddy) / 16));
SetTextColor(HDataDC,RGB(255,255,255)); //single address highlight SetTextColor(HDataDC,RGB(255,255,255)); //single address highlight
SetBkColor(HDataDC,RGB(0,0,0)); SetBkColor(HDataDC,RGB(0,0,0));
TextOut(HDataDC,0,0,str,1); TextOut(HDataDC,0,0,str,1);
// 2nd nybble
MoveToEx(HDataDC, MemFontWidth + 8 * MemFontWidth + (j * 3 * MemFontWidth), MemFontHeight * ((i - CurOffset) / 16), NULL);
sprintf(str,"%X",GetMemViewData(CursorStartAddy) % 16);
SetTextColor(HDataDC,TextColorList[i+j-CurOffset]); //single address highlight 2nd address SetTextColor(HDataDC,TextColorList[i+j-CurOffset]); //single address highlight 2nd address
SetBkColor(HDataDC,RGB(HexBackColorR,HexBackColorG,HexBackColorB)); SetBkColor(HDataDC,RGB(HexBackColorR,HexBackColorG,HexBackColorB));
TextOut(HDataDC,0,0,&str[1],1); TextOut(HDataDC,0,0,str,1);
} }
TextOut(HDataDC,0,0," ",1); //TextOut(HDataDC,0,0," ",1);
SetTextColor(HDataDC,RGB(255,255,255)); //single addres highlight - right column //single addres highlight - right column
SetTextColor(HDataDC,RGB(255,255,255));
SetBkColor(HDataDC,RGB(0,0,0)); SetBkColor(HDataDC,RGB(0,0,0));
MoveToEx(HDataDC, (59 + j) * MemFontWidth, MemFontHeight * ((i - CurOffset) / 16), NULL); //todo: try moving this above the for loop MoveToEx(HDataDC, (59 + j) * MemFontWidth, MemFontHeight * ((i - CurOffset) / 16), NULL); //todo: try moving this above the for loop
str[0] = chartable[GetMemViewData(i+j)]; str[0] = chartable[GetMemViewData(i+j)];
@ -474,12 +489,16 @@ void UpdateMemoryView(int draw_all)
continue; continue;
} }
if((OldValues[i+j-CurOffset] != GetMemViewData(i+j)) || draw_all){ if((OldValues[i+j-CurOffset] != GetMemViewData(i+j)) || draw_all)
{
MoveToEx(HDataDC, 8 * MemFontWidth + (j * 3 * MemFontWidth), MemFontHeight * ((i - CurOffset) / 16),NULL); MoveToEx(HDataDC, 8 * MemFontWidth + (j * 3 * MemFontWidth), MemFontHeight * ((i - CurOffset) / 16),NULL);
SetTextColor(HDataDC,TextColorList[i+j-CurOffset]);//(8+j*3)*MemFontWidth SetTextColor(HDataDC,TextColorList[i+j-CurOffset]);//(8+j*3)*MemFontWidth
SetBkColor(HDataDC,BGColorList[i+j-CurOffset]); SetBkColor(HDataDC,BGColorList[i+j-CurOffset]);
sprintf(str,"%02X ",GetMemViewData(i+j)); sprintf(str,"%X", (int)(GetMemViewData(i+j) / 16));
TextOut(HDataDC,0,0,str,strlen(str)); TextOut(HDataDC, 0, 0, str, 1);
MoveToEx(HDataDC, MemFontWidth + 8 * MemFontWidth + (j * 3 * MemFontWidth), MemFontHeight * ((i - CurOffset) / 16),NULL);
sprintf(str,"%X", GetMemViewData(i+j) % 16);
TextOut(HDataDC, 0, 0, str, 1);
MoveToEx(HDataDC,(59+j)*MemFontWidth,MemFontHeight*((i-CurOffset)/16),NULL); //todo: try moving this above the for loop MoveToEx(HDataDC,(59+j)*MemFontWidth,MemFontHeight*((i-CurOffset)/16),NULL); //todo: try moving this above the for loop
str[0] = chartable[GetMemViewData(i+j)]; str[0] = chartable[GetMemViewData(i+j)];
@ -490,7 +509,8 @@ void UpdateMemoryView(int draw_all)
if(CursorStartAddy != i+j)OldValues[i+j-CurOffset] = GetMemViewData(i+j); if(CursorStartAddy != i+j)OldValues[i+j-CurOffset] = GetMemViewData(i+j);
} }
} }
if(draw_all){ if(draw_all)
{
MoveToEx(HDataDC,56*MemFontWidth,MemFontHeight*((i-CurOffset)/16),NULL); MoveToEx(HDataDC,56*MemFontWidth,MemFontHeight*((i-CurOffset)/16),NULL);
SetTextColor(HDataDC,RGB(HexForeColorR,HexForeColorG,HexForeColorB)); //Column separator SetTextColor(HDataDC,RGB(HexForeColorR,HexForeColorG,HexForeColorB)); //Column separator
SetBkColor(HDataDC,RGB(HexBackColorR,HexBackColorG,HexBackColorB)); SetBkColor(HDataDC,RGB(HexBackColorR,HexBackColorG,HexBackColorB));
@ -928,12 +948,14 @@ void ChangeMemViewFocus(int newEditingMode, int StartOffset,int EndOffset){
} }
int GetHexScreenCoordx(int offset){ int GetHexScreenCoordx(int offset)
return (8*debugSystem->fixedFontWidth)+((offset%16)*3*debugSystem->fixedFontWidth); //todo: add Curoffset to this and to below function {
return (8 * (debugSystem->HexeditorFontWidth + HexCharSpacing)) + ((offset % 16) * 3 * (debugSystem->HexeditorFontWidth + HexCharSpacing)); //todo: add Curoffset to this and to below function
} }
int GetHexScreenCoordy(int offset){ int GetHexScreenCoordy(int offset)
return (offset/16)*(debugSystem->fixedFontHeight+HexRowHeightBorder); {
return (offset / 16) * (debugSystem->HexeditorFontHeight + HexRowHeightBorder);
} }
//0000E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................ //0000E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................
@ -942,8 +964,8 @@ int GetHexScreenCoordy(int offset){
//if the mouse wasn't in any range, this function returns -1 //if the mouse wasn't in any range, this function returns -1
int GetAddyFromCoord(int x,int y) int GetAddyFromCoord(int x,int y)
{ {
int MemFontWidth = debugSystem->fixedFontWidth; int MemFontWidth = debugSystem->HexeditorFontWidth + HexCharSpacing;
int MemFontHeight = debugSystem->fixedFontHeight + HexRowHeightBorder; int MemFontHeight = debugSystem->HexeditorFontHeight + HexRowHeightBorder;
if(y < 0)y = 0; if(y < 0)y = 0;
if(x < 8*MemFontWidth)x = 8*MemFontWidth+1; if(x < 8*MemFontWidth)x = 8*MemFontWidth+1;
@ -1016,8 +1038,8 @@ LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
SCROLLINFO si; SCROLLINFO si;
int x, y, i, j; int x, y, i, j;
int tempAddy; int tempAddy;
const int MemFontWidth = debugSystem->fixedFontWidth; const int MemFontWidth = debugSystem->HexeditorFontWidth;
const int MemFontHeight = debugSystem->fixedFontHeight + HexRowHeightBorder; const int MemFontHeight = debugSystem->HexeditorFontHeight + HexRowHeightBorder;
char c[2]; char c[2];
char str[100]; char str[100];
@ -1045,7 +1067,7 @@ LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
// ################################## End of SP CODE ########################### // ################################## End of SP CODE ###########################
mDC = GetDC(hwnd); mDC = GetDC(hwnd);
HDataDC = mDC;//deleteme HDataDC = mDC;//deleteme
SelectObject (HDataDC, debugSystem->hFixedFont); SelectObject (HDataDC, debugSystem->hHexeditorFont);
SetTextAlign(HDataDC,TA_UPDATECP | TA_TOP | TA_LEFT); SetTextAlign(HDataDC,TA_UPDATECP | TA_TOP | TA_LEFT);
GetTextMetrics (HDataDC, &tm); GetTextMetrics (HDataDC, &tm);