Resize framebuffer in windowed mode to match the client area

This commit is contained in:
Magnus Norddahl 2016-09-12 13:04:36 +02:00
parent 02e4ba464a
commit d3d8180f57
4 changed files with 70 additions and 10 deletions

View File

@ -725,6 +725,21 @@ void DCanvas::CalcGamma (float gamma, BYTE gammalookup[256])
DSimpleCanvas::DSimpleCanvas (int width, int height)
: DCanvas (width, height)
{
MemBuffer = nullptr;
Resize(width, height);
}
void DSimpleCanvas::Resize(int width, int height)
{
Width = width;
Height = height;
if (MemBuffer != NULL)
{
delete[] MemBuffer;
MemBuffer = NULL;
}
// Making the pitch a power of 2 is very bad for performance
// Try to maximize the number of cache lines that can be filled
// for each column drawing operation by making the pitch slightly
@ -761,7 +776,7 @@ DSimpleCanvas::DSimpleCanvas (int width, int height)
}
}
MemBuffer = new BYTE[Pitch * height];
memset (MemBuffer, 0, Pitch * height);
memset(MemBuffer, 0, Pitch * height);
}
//==========================================================================
@ -1259,7 +1274,6 @@ CCMD(clean)
bool V_DoModeSetup (int width, int height, int bits)
{
DFrameBuffer *buff = I_SetMode (width, height, screen);
int cx1, cx2;
if (buff == NULL)
{
@ -1274,6 +1288,17 @@ bool V_DoModeSetup (int width, int height, int bits)
// if D3DFB is being used for the display.
FFont::StaticPreloadFonts();
DisplayBits = bits;
V_UpdateModeSize(width, height);
M_RefreshModesList ();
return true;
}
void V_UpdateModeSize (int width, int height)
{
int cx1, cx2;
V_CalcCleanFacs(320, 200, width, height, &CleanXfac, &CleanYfac, &cx1, &cx2);
CleanWidth = width / CleanXfac;
@ -1314,14 +1339,19 @@ bool V_DoModeSetup (int width, int height, int bits)
DisplayWidth = width;
DisplayHeight = height;
DisplayBits = bits;
R_OldBlend = ~0;
Renderer->OnModeSet();
M_RefreshModesList ();
}
return true;
void V_OutputResized (int width, int height)
{
V_UpdateModeSize(width, height);
setsizeneeded = true;
if (StatusBar != NULL)
{
StatusBar->ScreenSizeChanged();
}
}
void V_CalcCleanFacs (int designwidth, int designheight, int realwidth, int realheight, int *cleanx, int *cleany, int *_cx1, int *_cx2)

View File

@ -47,6 +47,8 @@ extern int CleanWidth_1, CleanHeight_1, CleanXfac_1, CleanYfac_1;
extern int DisplayWidth, DisplayHeight, DisplayBits;
bool V_DoModeSetup (int width, int height, int bits);
void V_UpdateModeSize (int width, int height);
void V_OutputResized (int width, int height);
void V_CalcCleanFacs (int designwidth, int designheight, int realwidth, int realheight, int *cleanx, int *cleany, int *cx1=NULL, int *cx2=NULL);
class FTexture;
@ -300,6 +302,8 @@ public:
void Unlock ();
protected:
void Resize(int width, int height);
BYTE *MemBuffer;
DSimpleCanvas() {}

View File

@ -1220,6 +1220,24 @@ void D3DFB::Flip()
CurrRenderTexture ^= RenderTextureToggle;
TempRenderTexture = RenderTexture[CurrRenderTexture];
}
if (Windowed)
{
RECT box;
GetClientRect(Window, &box);
if (box.right > 0 && box.right > 0 && (Width != box.right || Height != box.bottom))
{
Resize(box.right, box.bottom);
TrueHeight = Height;
PixelDoubling = 0;
LBOffsetI = 0;
LBOffset = 0.0f;
Reset();
V_OutputResized(Width, Height);
}
}
}
//==========================================================================

View File

@ -537,10 +537,18 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (screen && !VidResizing)
{
LPMINMAXINFO mmi = (LPMINMAXINFO)lParam;
RECT rect = { 0, 0, screen->GetWidth(), screen->GetHeight() };
AdjustWindowRectEx(&rect, WS_VISIBLE|WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW);
mmi->ptMinTrackSize.x = rect.right - rect.left;
mmi->ptMinTrackSize.y = rect.bottom - rect.top;
if (screen->IsFullscreen())
{
RECT rect = { 0, 0, screen->GetWidth(), screen->GetHeight() };
AdjustWindowRectEx(&rect, WS_VISIBLE | WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW);
mmi->ptMinTrackSize.x = rect.right - rect.left;
mmi->ptMinTrackSize.y = rect.bottom - rect.top;
}
else
{
mmi->ptMinTrackSize.x = 320;
mmi->ptMinTrackSize.y = 200;
}
return 0;
}
break;