ppu viewer now expands to minimum size for pixel-based controls (also some cleanup of parallel solution in nt viewer), fixes second half of bug #753
This commit is contained in:
parent
1d5c5b27c0
commit
601cce4084
|
@ -83,13 +83,16 @@ NT_MirrorType ntmirroring, oldntmirroring = NT_NONE;
|
|||
|
||||
int horzscroll, vertscroll;
|
||||
|
||||
#define NTWIDTH 256
|
||||
#define NTHEIGHT 240
|
||||
//#define PATTERNBITWIDTH PATTERNWIDTH*3
|
||||
#define NTDESTX 10
|
||||
#define NTDESTY 15
|
||||
#define ZOOM 1
|
||||
#define NTWIDTH 256
|
||||
#define NTHEIGHT 240
|
||||
#define NTDESTX_BASE 6
|
||||
#define NTDESTY_BASE 18
|
||||
|
||||
int ntDestX = NTDESTX_BASE;
|
||||
int ntDestY = NTDESTY_BASE;
|
||||
|
||||
//#define PATTERNBITWIDTH PATTERNWIDTH*3
|
||||
//#define ZOOM 1
|
||||
//#define PALETTEWIDTH 32*4*4
|
||||
//#define PALETTEHEIGHT 32*2
|
||||
//#define PALETTEBITWIDTH PALETTEWIDTH*3
|
||||
|
@ -125,10 +128,10 @@ void NTViewDoBlit(int autorefresh) {
|
|||
|
||||
if((redrawtables && !autorefresh) || (autorefresh) || (scrolllines)){
|
||||
|
||||
BitBlt(pDC,NTDESTX,NTDESTY,NTWIDTH,NTHEIGHT,cache[0].hdc,0,0,SRCCOPY);
|
||||
BitBlt(pDC,NTDESTX+NTWIDTH,NTDESTY,NTWIDTH,NTHEIGHT,cache[1].hdc,0,0,SRCCOPY);
|
||||
BitBlt(pDC,NTDESTX,NTDESTY+NTHEIGHT,NTWIDTH,NTHEIGHT,cache[2].hdc,0,0,SRCCOPY);
|
||||
BitBlt(pDC,NTDESTX+NTWIDTH,NTDESTY+NTHEIGHT,NTWIDTH,NTHEIGHT,cache[3].hdc,0,0,SRCCOPY);
|
||||
BitBlt(pDC,ntDestX,ntDestY,NTWIDTH,NTHEIGHT,cache[0].hdc,0,0,SRCCOPY);
|
||||
BitBlt(pDC,ntDestX+NTWIDTH,ntDestY,NTWIDTH,NTHEIGHT,cache[1].hdc,0,0,SRCCOPY);
|
||||
BitBlt(pDC,ntDestX,ntDestY+NTHEIGHT,NTWIDTH,NTHEIGHT,cache[2].hdc,0,0,SRCCOPY);
|
||||
BitBlt(pDC,ntDestX+NTWIDTH,ntDestY+NTHEIGHT,NTWIDTH,NTHEIGHT,cache[3].hdc,0,0,SRCCOPY);
|
||||
|
||||
redrawtables = false;
|
||||
}
|
||||
|
@ -137,12 +140,12 @@ void NTViewDoBlit(int autorefresh) {
|
|||
SetROP2(pDC,R2_NOT);
|
||||
|
||||
//draw vertical line
|
||||
MoveToEx(pDC,NTDESTX+xpos,NTDESTY,NULL);
|
||||
LineTo(pDC,NTDESTX+xpos,NTDESTY+(NTHEIGHT*2)-1);
|
||||
MoveToEx(pDC,ntDestX+xpos,ntDestY,NULL);
|
||||
LineTo(pDC,ntDestX+xpos,ntDestY+(NTHEIGHT*2)-1);
|
||||
|
||||
//draw horizontal line
|
||||
MoveToEx(pDC,NTDESTX,NTDESTY+ypos,NULL);
|
||||
LineTo(pDC,NTDESTX+(NTWIDTH*2)-1,NTDESTY+ypos);
|
||||
MoveToEx(pDC,ntDestX,ntDestY+ypos,NULL);
|
||||
LineTo(pDC,ntDestX+(NTWIDTH*2)-1,ntDestY+ypos);
|
||||
|
||||
SetROP2(pDC,R2_COPYPEN);
|
||||
}
|
||||
|
@ -310,6 +313,18 @@ void DrawNameTable(int scanline, int ntnum, bool invalidateCache) {
|
|||
//}
|
||||
}
|
||||
|
||||
static void CalculateBitmapPositions(HWND hwndDlg)
|
||||
{
|
||||
RECT rect;
|
||||
POINT pt;
|
||||
GetWindowRect(GetDlgItem(hwndDlg, IDC_NTVIEW_TABLE_BOX), &rect);
|
||||
pt.x = rect.left;
|
||||
pt.y = rect.top;
|
||||
ScreenToClient(hwndDlg, &pt);
|
||||
ntDestX = pt.x + NTDESTX_BASE;
|
||||
ntDestY = pt.y + NTDESTY_BASE;
|
||||
}
|
||||
|
||||
static BOOL CALLBACK EnsurePixelSizeEnumWindowsProc(HWND hwnd, LPARAM lParam)
|
||||
{
|
||||
const int shift = lParam;
|
||||
|
@ -334,13 +349,12 @@ static void EnsurePixelSize()
|
|||
if (!hNTView) return;
|
||||
HWND ntbox = GetDlgItem(hNTView, IDC_NTVIEW_TABLE_BOX);
|
||||
|
||||
const int MARGIN_W = 12;
|
||||
const int MARGIN_H = 22;
|
||||
const int MIN_W = 512 + MARGIN_W;
|
||||
const int MIN_H = 480 + MARGIN_H;
|
||||
const int MIN_W = (NTWIDTH * 2) + (NTDESTX_BASE * 2);
|
||||
const int MIN_H = (NTHEIGHT * 2) + (NTDESTY_BASE + 8);
|
||||
|
||||
RECT rect;
|
||||
RECT rect, client;
|
||||
GetWindowRect(ntbox,&rect);
|
||||
GetClientRect(ntbox,&client);
|
||||
|
||||
int nt_w = rect.right - rect.left;
|
||||
int nt_h = rect.bottom - rect.top;
|
||||
|
@ -348,7 +362,7 @@ static void EnsurePixelSize()
|
|||
int nt_w_add = (nt_w < MIN_W) ? (MIN_W - nt_w) : 0;
|
||||
int nt_h_add = (nt_h < MIN_H) ? (MIN_H - nt_h) : 0;
|
||||
|
||||
if (nt_w_add == 0 && nt_h_add == 0) return;
|
||||
if (nt_w_add <= 0 && nt_h_add <= 0) return;
|
||||
|
||||
// expand parent window
|
||||
RECT wrect;
|
||||
|
@ -360,12 +374,13 @@ static void EnsurePixelSize()
|
|||
// expand NT box
|
||||
SetWindowPos(ntbox,0,0,0,nt_w + nt_w_add,nt_h + nt_h_add, SWP_NOZORDER | SWP_NOMOVE);
|
||||
|
||||
// expand children
|
||||
// move children
|
||||
if (nt_h_add > 0)
|
||||
{
|
||||
EnumChildWindows(hNTView, EnsurePixelSizeEnumWindowsProc, nt_h_add);
|
||||
}
|
||||
|
||||
CalculateBitmapPositions(hNTView);
|
||||
RedrawWindow(hNTView,0,0,RDW_ERASE | RDW_INVALIDATE);
|
||||
}
|
||||
|
||||
|
@ -448,6 +463,8 @@ BOOL CALLBACK NTViewCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
if (NTViewPosY==-32000) NTViewPosY=0;
|
||||
SetWindowPos(hwndDlg,0,NTViewPosX,NTViewPosY,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOOWNERZORDER);
|
||||
|
||||
CalculateBitmapPositions(hwndDlg);
|
||||
|
||||
//prepare the bitmap attributes
|
||||
//pattern tables
|
||||
memset(&bmInfo.bmiHeader,0,sizeof(BITMAPINFOHEADER));
|
||||
|
@ -531,10 +548,10 @@ BOOL CALLBACK NTViewCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
case WM_MOUSEMOVE:
|
||||
mouse_x = GET_X_LPARAM(lParam);
|
||||
mouse_y = GET_Y_LPARAM(lParam);
|
||||
if((mouse_x > NTDESTX) && (mouse_x < NTDESTX+(NTWIDTH*2))
|
||||
&& (mouse_y > NTDESTY) && (mouse_y < NTDESTY+(NTHEIGHT*2))){
|
||||
TileX = (mouse_x-NTDESTX)/8;
|
||||
TileY = (mouse_y-NTDESTY)/8;
|
||||
if((mouse_x > ntDestX) && (mouse_x < ntDestX+(NTWIDTH*2))
|
||||
&& (mouse_y > ntDestY) && (mouse_y < ntDestY+(NTHEIGHT*2))){
|
||||
TileX = (mouse_x-ntDestX)/8;
|
||||
TileY = (mouse_y-ntDestY)/8;
|
||||
sprintf(str,"X / Y: %0d / %0d",TileX,TileY);
|
||||
SetDlgItemText(hwndDlg,IDC_NTVIEW_PROPERTIES_LINE_2,str);
|
||||
NameTable = (TileX/32)+((TileY/30)*2);
|
||||
|
@ -645,11 +662,11 @@ void DoNTView()
|
|||
if (!hNTView)
|
||||
{
|
||||
hNTView = CreateDialog(fceu_hInstance,"NTVIEW",NULL,NTViewCallB);
|
||||
EnsurePixelSize();
|
||||
new(cache) NTCache[4]; //reinitialize NTCache
|
||||
}
|
||||
if (hNTView)
|
||||
{
|
||||
EnsurePixelSize();
|
||||
//SetWindowPos(hNTView,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER);
|
||||
ShowWindow(hNTView, SW_SHOWNORMAL);
|
||||
SetForegroundWindow(hNTView);
|
||||
|
|
|
@ -45,21 +45,21 @@ int PPUViewSkip;
|
|||
int PPUViewRefresh = 0;
|
||||
int mouse_x, mouse_y;
|
||||
|
||||
#define PATTERNWIDTH 128
|
||||
#define PATTERNHEIGHT 128
|
||||
#define PATTERNBITWIDTH PATTERNWIDTH*3
|
||||
#define PATTERNDESTX_BASE 7
|
||||
#define PATTERNDESTY_BASE 18
|
||||
#define ZOOM 2
|
||||
#define PATTERNWIDTH 128
|
||||
#define PATTERNHEIGHT 128
|
||||
#define PATTERNBITWIDTH PATTERNWIDTH*3
|
||||
#define PATTERNDESTX_BASE 7
|
||||
#define PATTERNDESTY_BASE 18
|
||||
#define ZOOM 2
|
||||
|
||||
#define PALETTEWIDTH 32*4*4
|
||||
#define PALETTEHEIGHT 32*2
|
||||
#define PALETTEBITWIDTH PALETTEWIDTH*3
|
||||
#define PALETTEDESTX_BASE 7
|
||||
#define PALETTEDESTY_BASE 18
|
||||
#define PALETTEWIDTH 32*4*4
|
||||
#define PALETTEHEIGHT 32*2
|
||||
#define PALETTEBITWIDTH PALETTEWIDTH*3
|
||||
#define PALETTEDESTX_BASE 7
|
||||
#define PALETTEDESTY_BASE 18
|
||||
|
||||
#define TBM_SETPOS (WM_USER+5)
|
||||
#define TBM_SETRANGE (WM_USER+6)
|
||||
#define TBM_SETRANGE (WM_USER+6)
|
||||
#define TBM_GETPOS (WM_USER)
|
||||
|
||||
int patternDestX = PATTERNDESTX_BASE;
|
||||
|
@ -229,6 +229,121 @@ void FCEUD_UpdatePPUView(int scanline, int refreshchr)
|
|||
//PPUViewDoBlit();
|
||||
}
|
||||
|
||||
static void CalculateBitmapPositions(HWND hwndDlg)
|
||||
{
|
||||
// calculate bitmaps positions relative to their groupboxes
|
||||
RECT rect;
|
||||
POINT pt;
|
||||
GetWindowRect(GetDlgItem(hwndDlg, GRP_PPUVIEW_TABLES), &rect);
|
||||
pt.x = rect.left;
|
||||
pt.y = rect.top;
|
||||
ScreenToClient(hwndDlg, &pt);
|
||||
patternDestX = pt.x + PATTERNDESTX_BASE;
|
||||
patternDestY = pt.y + PATTERNDESTY_BASE;
|
||||
GetWindowRect(GetDlgItem(hwndDlg, LBL_PPUVIEW_PALETTES), &rect);
|
||||
pt.x = rect.left;
|
||||
pt.y = rect.top;
|
||||
ScreenToClient(hwndDlg, &pt);
|
||||
paletteDestX = pt.x + PALETTEDESTX_BASE;
|
||||
paletteDestY = pt.y + PALETTEDESTY_BASE;
|
||||
}
|
||||
|
||||
static BOOL CALLBACK EnsurePixelSizeEnumWindowsProc(HWND hwnd, LPARAM lParam)
|
||||
{
|
||||
const int shift = lParam;
|
||||
HWND chrbox = GetDlgItem(hPPUView, GRP_PPUVIEW_TABLES);
|
||||
HWND palbox = GetDlgItem(hPPUView, LBL_PPUVIEW_PALETTES);
|
||||
|
||||
if (hwnd != chrbox && hwnd != palbox)
|
||||
{
|
||||
RECT rect;
|
||||
GetWindowRect(hwnd, &rect);
|
||||
ScreenToClient(hPPUView,(LPPOINT)&rect);
|
||||
ScreenToClient(hPPUView,((LPPOINT)&rect)+1);
|
||||
SetWindowPos(hwnd,0,rect.left,rect.top+shift,0,0,SWP_NOZORDER | SWP_NOSIZE);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void EnsurePixelSize()
|
||||
{
|
||||
// DPI varies, so the pixel size of the window may be too small to fit the viewer.
|
||||
// This expands the window and moves its controls around if necessary.
|
||||
|
||||
if (!hPPUView) return;
|
||||
HWND chrbox = GetDlgItem(hPPUView, GRP_PPUVIEW_TABLES);
|
||||
HWND palbox = GetDlgItem(hPPUView, LBL_PPUVIEW_PALETTES);
|
||||
HWND chrlab = GetDlgItem(hPPUView, LBL_PPUVIEW_TILE1);
|
||||
|
||||
RECT crect, prect, lrect;
|
||||
GetWindowRect(chrbox,&crect);
|
||||
GetWindowRect(palbox,&prect);
|
||||
GetWindowRect(chrlab,&lrect);
|
||||
|
||||
const int MIN_CHR_W = (PATTERNWIDTH * ZOOM * 2) + 1 + (PATTERNDESTX_BASE * 2);
|
||||
const int MIN_CHR_H = (PATTERNHEIGHT * ZOOM) + (PATTERNDESTY_BASE + 8);
|
||||
const int MIN_PAL_W = PALETTEWIDTH + (PALETTEDESTX_BASE * 2);
|
||||
const int MIN_PAL_H = PALETTEHEIGHT + (PALETTEDESTY_BASE + 8);
|
||||
|
||||
const int chr_w = crect.right - crect.left;
|
||||
const int chr_h = lrect.top - crect.top; // measure CHR height against "Tile:" label
|
||||
const int pal_w = prect.right - prect.left;
|
||||
const int pal_h = prect.bottom - prect.top;
|
||||
|
||||
int chr_w_add = 0;
|
||||
int chr_h_add = 0;
|
||||
int pal_w_add = 0;
|
||||
int pal_h_add = 0;
|
||||
|
||||
if (chr_w < MIN_CHR_W) chr_w_add = MIN_CHR_W - chr_w;
|
||||
if (chr_h < MIN_CHR_H) chr_h_add = MIN_CHR_H - chr_h;
|
||||
if (pal_w < MIN_PAL_W) pal_w_add = MIN_PAL_W - pal_w;
|
||||
if (pal_h < MIN_PAL_H) pal_h_add = MIN_PAL_H - pal_h;
|
||||
|
||||
const int all_w_add = (pal_w_add > chr_w_add) ? pal_w_add : chr_w_add;
|
||||
const int all_h_add = chr_h_add + pal_h_add;
|
||||
|
||||
if (all_h_add <= 0 && all_w_add <= 0) return;
|
||||
|
||||
// expand parent window
|
||||
RECT wrect;
|
||||
GetWindowRect(hPPUView,&wrect);
|
||||
int ww = (wrect.right - wrect.left) + all_w_add;
|
||||
int wh = (wrect.bottom - wrect.top) + all_h_add;
|
||||
SetWindowPos(hPPUView,0,0,0,ww,wh,SWP_NOZORDER | SWP_NOMOVE);
|
||||
|
||||
if (all_w_add > 0 || chr_h_add > 0)
|
||||
{
|
||||
// expand CHR box
|
||||
SetWindowPos(chrbox,0,0,0,
|
||||
chr_w + all_w_add,
|
||||
(crect.bottom - crect.top) + chr_h_add,
|
||||
SWP_NOZORDER | SWP_NOMOVE);
|
||||
}
|
||||
|
||||
if (all_w_add > 0 || pal_h_add > 0)
|
||||
{
|
||||
// expand and move palette box
|
||||
ScreenToClient(hPPUView,(LPPOINT)&prect);
|
||||
ScreenToClient(hPPUView,(LPPOINT)&prect+1);
|
||||
SetWindowPos(palbox,0,
|
||||
prect.left,
|
||||
prect.top + chr_h_add,
|
||||
pal_w + all_w_add,
|
||||
pal_h + pal_h_add,
|
||||
SWP_NOZORDER);
|
||||
}
|
||||
|
||||
// move children
|
||||
if (chr_h_add > 0)
|
||||
{
|
||||
EnumChildWindows(hPPUView, EnsurePixelSizeEnumWindowsProc, chr_h_add);
|
||||
}
|
||||
|
||||
CalculateBitmapPositions(hPPUView);
|
||||
RedrawWindow(hPPUView,0,0,RDW_ERASE | RDW_INVALIDATE);
|
||||
}
|
||||
|
||||
void KillPPUView()
|
||||
{
|
||||
//GDI cleanup
|
||||
|
@ -262,21 +377,7 @@ BOOL CALLBACK PPUViewCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
|
|||
if (PPUViewPosY==-32000) PPUViewPosY=0;
|
||||
SetWindowPos(hwndDlg,0,PPUViewPosX,PPUViewPosY,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOOWNERZORDER);
|
||||
|
||||
// calculate bitmaps positions relative to their groupboxes
|
||||
RECT rect;
|
||||
POINT pt;
|
||||
GetWindowRect(GetDlgItem(hwndDlg, GRP_PPUVIEW_TABLES), &rect);
|
||||
pt.x = rect.left;
|
||||
pt.y = rect.top;
|
||||
ScreenToClient(hwndDlg, &pt);
|
||||
patternDestX = pt.x + PATTERNDESTX_BASE;
|
||||
patternDestY = pt.y + PATTERNDESTY_BASE;
|
||||
GetWindowRect(GetDlgItem(hwndDlg, LBL_PPUVIEW_PALETTES), &rect);
|
||||
pt.x = rect.left;
|
||||
pt.y = rect.top;
|
||||
ScreenToClient(hwndDlg, &pt);
|
||||
paletteDestX = pt.x + PALETTEDESTX_BASE;
|
||||
paletteDestY = pt.y + PALETTEDESTY_BASE;
|
||||
CalculateBitmapPositions(hwndDlg);
|
||||
|
||||
//prepare the bitmap attributes
|
||||
//pattern tables
|
||||
|
@ -523,7 +624,11 @@ void DoPPUView()
|
|||
return;
|
||||
}
|
||||
|
||||
if(!hPPUView) hPPUView = CreateDialog(fceu_hInstance,"PPUVIEW",NULL,PPUViewCallB);
|
||||
if(!hPPUView)
|
||||
{
|
||||
hPPUView = CreateDialog(fceu_hInstance,"PPUVIEW",NULL,PPUViewCallB);
|
||||
EnsurePixelSize();
|
||||
}
|
||||
if(hPPUView)
|
||||
{
|
||||
//SetWindowPos(hPPUView,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER);
|
||||
|
|
Loading…
Reference in New Issue