mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
Adding awareness of window minimization/maximization
This commit is contained in:
parent
e7a96d8786
commit
c0fe3c4dc6
6 changed files with 118 additions and 20 deletions
|
@ -44,7 +44,9 @@ namespace Beefy
|
||||||
UseParentMenu = 0x20'0000,
|
UseParentMenu = 0x20'0000,
|
||||||
CaptureMediaKeys = 0x40'0000,
|
CaptureMediaKeys = 0x40'0000,
|
||||||
Fullscreen = 0x80'0000,
|
Fullscreen = 0x80'0000,
|
||||||
FakeFocus = 0x0100'0000
|
FakeFocus = 0x0100'0000,
|
||||||
|
ShowMinimized = 0x0200'0000,
|
||||||
|
ShowMaximized = 0x0400'0000,
|
||||||
};
|
};
|
||||||
|
|
||||||
public enum HitTestResult
|
public enum HitTestResult
|
||||||
|
@ -101,6 +103,13 @@ namespace Beefy
|
||||||
#if !STUDIO_CLIENT
|
#if !STUDIO_CLIENT
|
||||||
public class BFWindow : BFWindowBase, INativeWindow
|
public class BFWindow : BFWindowBase, INativeWindow
|
||||||
{
|
{
|
||||||
|
public enum ShowKind
|
||||||
|
{
|
||||||
|
Normal,
|
||||||
|
Minimized,
|
||||||
|
Maximized
|
||||||
|
}
|
||||||
|
|
||||||
delegate void NativeMovedDelegate(void* window);
|
delegate void NativeMovedDelegate(void* window);
|
||||||
delegate int32 NativeCloseQueryDelegate(void* window);
|
delegate int32 NativeCloseQueryDelegate(void* window);
|
||||||
delegate void NativeClosedDelegate(void* window);
|
delegate void NativeClosedDelegate(void* window);
|
||||||
|
@ -130,6 +139,11 @@ namespace Beefy
|
||||||
public int32 mY;
|
public int32 mY;
|
||||||
public int32 mWindowWidth;
|
public int32 mWindowWidth;
|
||||||
public int32 mWindowHeight;
|
public int32 mWindowHeight;
|
||||||
|
public int32 mNormX;
|
||||||
|
public int32 mNormY;
|
||||||
|
public int32 mNormWidth;
|
||||||
|
public int32 mNormHeight;
|
||||||
|
public ShowKind mShowKind;
|
||||||
public int32 mClientX;
|
public int32 mClientX;
|
||||||
public int32 mClientY;
|
public int32 mClientY;
|
||||||
public int32 mClientWidth;
|
public int32 mClientWidth;
|
||||||
|
@ -186,7 +200,10 @@ namespace Beefy
|
||||||
static extern void BFWindow_GetPosition(void* window, out int32 x, out int32 y, out int32 width, out int32 height, out int32 clientX, out int32 clientY, out int32 clientWidth, out int32 clientHeight);
|
static extern void BFWindow_GetPosition(void* window, out int32 x, out int32 y, out int32 width, out int32 height, out int32 clientX, out int32 clientY, out int32 clientWidth, out int32 clientHeight);
|
||||||
|
|
||||||
[StdCall, CLink]
|
[StdCall, CLink]
|
||||||
static extern void BFWindow_Resize(void* window, int32 x, int32 y, int32 width, int32 height);
|
static extern void BFWindow_GetPlacement(void* window, out int32 normX, out int32 normY, out int32 normWidth, out int32 normHeight, out int32 showKind);
|
||||||
|
|
||||||
|
[StdCall, CLink]
|
||||||
|
static extern void BFWindow_Resize(void* window, int32 x, int32 y, int32 width, int32 height, int showKind);
|
||||||
|
|
||||||
[StdCall, CLink]
|
[StdCall, CLink]
|
||||||
static extern void BFWindow_Close(void* window, int32 force);
|
static extern void BFWindow_Close(void* window, int32 force);
|
||||||
|
@ -425,10 +442,10 @@ namespace Beefy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Resize(int x, int y, int width, int height)
|
public virtual void Resize(int x, int y, int width, int height, ShowKind showKind = .Normal)
|
||||||
{
|
{
|
||||||
Debug.Assert(mNativeWindow != null);
|
Debug.Assert(mNativeWindow != null);
|
||||||
BFWindow_Resize(mNativeWindow, (int32)x, (int32)y, (int32)width, (int32)height);
|
BFWindow_Resize(mNativeWindow, (int32)x, (int32)y, (int32)width, (int32)height, (int32)showKind);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetForeground()
|
public void SetForeground()
|
||||||
|
@ -476,6 +493,11 @@ namespace Beefy
|
||||||
public virtual void Moved()
|
public virtual void Moved()
|
||||||
{
|
{
|
||||||
BFWindow_GetPosition(mNativeWindow, out mX, out mY, out mWindowWidth, out mWindowHeight, out mClientX, out mClientY, out mClientWidth, out mClientHeight);
|
BFWindow_GetPosition(mNativeWindow, out mX, out mY, out mWindowWidth, out mWindowHeight, out mClientX, out mClientY, out mClientWidth, out mClientHeight);
|
||||||
|
|
||||||
|
int32 showKind = 0;
|
||||||
|
BFWindow_GetPlacement(mNativeWindow, out mNormX, out mNormY, out mNormWidth, out mNormHeight, out showKind);
|
||||||
|
mShowKind = (.)showKind;
|
||||||
|
|
||||||
mIsDirty = true;
|
mIsDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,10 @@ enum
|
||||||
BFWINDOW_USE_PARENT_MENU = 0x200000,
|
BFWINDOW_USE_PARENT_MENU = 0x200000,
|
||||||
BFWINDOW_CAPTURE_MEDIA_KEYS = 0x400000,
|
BFWINDOW_CAPTURE_MEDIA_KEYS = 0x400000,
|
||||||
BFWINDOW_FULLSCREEN = 0x800000,
|
BFWINDOW_FULLSCREEN = 0x800000,
|
||||||
BFWINDOW_FAKEFOCUS = 0x1000000
|
BFWINDOW_FAKEFOCUS = 0x1000000,
|
||||||
|
BFWINDOW_SHOWMINIMIZED = 0x2000000,
|
||||||
|
BFWINDOW_SHOWMAXIMIZED = 0x4000000,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class RenderWindow;
|
class RenderWindow;
|
||||||
|
@ -118,7 +121,8 @@ public:
|
||||||
virtual void SetTitle(const char* title) = 0;
|
virtual void SetTitle(const char* title) = 0;
|
||||||
virtual void SetMinimumSize(int minWidth, int minHeight, bool clientSized) = 0;
|
virtual void SetMinimumSize(int minWidth, int minHeight, bool clientSized) = 0;
|
||||||
virtual void GetPosition(int* x, int* y, int* width, int* height, int* clientX, int* clientY, int* clientWidth, int* clientHeight) = 0;
|
virtual void GetPosition(int* x, int* y, int* width, int* height, int* clientX, int* clientY, int* clientWidth, int* clientHeight) = 0;
|
||||||
virtual void Resize(int x, int y, int width, int height) = 0;
|
virtual void GetPlacement(int* normX, int* normY, int* normWidth, int* normHeight, int* showKind) = 0;
|
||||||
|
virtual void Resize(int x, int y, int width, int height, int showKind) = 0;
|
||||||
virtual void SetClientPosition(int x, int y) = 0;
|
virtual void SetClientPosition(int x, int y) = 0;
|
||||||
virtual void SetMouseVisible(bool isMouseVisible) = 0;
|
virtual void SetMouseVisible(bool isMouseVisible) = 0;
|
||||||
virtual void SetAlpha(float alpha, uint32 destAlphaSrcMask, bool isMouseVisible) = 0;
|
virtual void SetAlpha(float alpha, uint32 destAlphaSrcMask, bool isMouseVisible) = 0;
|
||||||
|
|
|
@ -312,9 +312,14 @@ BF_EXPORT void BF_CALLTYPE BFWindow_GetPosition(BFWindow* window, int* x, int* y
|
||||||
window->GetPosition(x, y, width, height, clientX, clientY, clientWidth, clientHeight);
|
window->GetPosition(x, y, width, height, clientX, clientY, clientWidth, clientHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
BF_EXPORT void BF_CALLTYPE BFWindow_Resize(BFWindow* window, int x, int y, int width, int height)
|
BF_EXPORT void BF_CALLTYPE BFWindow_GetPlacement(BFWindow* window, int* normX, int* normY, int* normWidth, int* normHeight, int* showKind)
|
||||||
{
|
{
|
||||||
window->Resize(x, y, width, height);
|
window->GetPlacement(normX, normY, normWidth, normHeight, showKind);
|
||||||
|
}
|
||||||
|
|
||||||
|
BF_EXPORT void BF_CALLTYPE BFWindow_Resize(BFWindow* window, int x, int y, int width, int height, int showKind)
|
||||||
|
{
|
||||||
|
window->Resize(x, y, width, height, showKind);
|
||||||
}
|
}
|
||||||
|
|
||||||
BF_EXPORT void BF_CALLTYPE BFWindow_SetForeground(BFWindow* window)
|
BF_EXPORT void BF_CALLTYPE BFWindow_SetForeground(BFWindow* window)
|
||||||
|
|
|
@ -1486,9 +1486,8 @@ Texture* DXRenderDevice::LoadTexture(ImageData* imageData, int flags)
|
||||||
desc.ArraySize = 1;
|
desc.ArraySize = 1;
|
||||||
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
desc.SampleDesc.Count = 1;
|
desc.SampleDesc.Count = 1;
|
||||||
//desc.Usage = D3D11_USAGE_DYNAMIC;
|
|
||||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||||
//desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
desc.CPUAccessFlags = 0;
|
||||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||||
|
|
||||||
//OutputDebugStrF("Creating texture\n");
|
//OutputDebugStrF("Creating texture\n");
|
||||||
|
@ -1536,9 +1535,8 @@ Texture* DXRenderDevice::CreateDynTexture(int width, int height)
|
||||||
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
desc.SampleDesc.Count = 1;
|
desc.SampleDesc.Count = 1;
|
||||||
desc.SampleDesc.Quality = 0;
|
desc.SampleDesc.Quality = 0;
|
||||||
//desc.Usage = D3D11_USAGE_DYNAMIC;
|
|
||||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
desc.CPUAccessFlags = 0;
|
||||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||||
|
|
||||||
ID3D11Texture2D* d3DTexture = NULL;
|
ID3D11Texture2D* d3DTexture = NULL;
|
||||||
|
|
|
@ -168,6 +168,8 @@ WinBFWindow::WinBFWindow(BFWindow* parent, const StringImpl& title, int x, int y
|
||||||
if ((windowFlags & BFWINDOW_TOPMOST) && (parent == NULL))
|
if ((windowFlags & BFWINDOW_TOPMOST) && (parent == NULL))
|
||||||
relativeWindow = HWND_TOP;
|
relativeWindow = HWND_TOP;
|
||||||
int showFlags = SWP_SHOWWINDOW;
|
int showFlags = SWP_SHOWWINDOW;
|
||||||
|
// if (windowFlags & BFWINDOW_SHOWMINIMIZED)
|
||||||
|
// showFlags = SWP_
|
||||||
mHasFocus = true;
|
mHasFocus = true;
|
||||||
mSoftHasFocus = true;
|
mSoftHasFocus = true;
|
||||||
if (windowFlags & BFWINDOW_FAKEFOCUS)
|
if (windowFlags & BFWINDOW_FAKEFOCUS)
|
||||||
|
@ -186,7 +188,29 @@ WinBFWindow::WinBFWindow(BFWindow* parent, const StringImpl& title, int x, int y
|
||||||
mSoftHasFocus = false;
|
mSoftHasFocus = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (windowFlags & (BFWINDOW_SHOWMINIMIZED | BFWINDOW_SHOWMAXIMIZED))
|
||||||
|
{
|
||||||
|
WINDOWPLACEMENT wndPlacement = { sizeof(WINDOWPLACEMENT), 0 };
|
||||||
|
::GetWindowPlacement(mHWnd, &wndPlacement);
|
||||||
|
|
||||||
|
if (windowFlags & BFWINDOW_SHOWMINIMIZED)
|
||||||
|
wndPlacement.showCmd = SW_SHOWMINIMIZED;
|
||||||
|
else if (windowFlags & BFWINDOW_SHOWMAXIMIZED)
|
||||||
|
wndPlacement.showCmd = SW_SHOWMAXIMIZED;
|
||||||
|
else
|
||||||
|
wndPlacement.showCmd = SW_SHOWNORMAL;
|
||||||
|
|
||||||
|
wndPlacement.rcNormalPosition.left = x;
|
||||||
|
wndPlacement.rcNormalPosition.top = y;
|
||||||
|
wndPlacement.rcNormalPosition.right = x + width;
|
||||||
|
wndPlacement.rcNormalPosition.bottom = y + height;
|
||||||
|
::SetWindowPlacement(mHWnd, &wndPlacement);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
SetWindowPos(mHWnd, relativeWindow, x, y, width, height, showFlags);
|
SetWindowPos(mHWnd, relativeWindow, x, y, width, height, showFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SetTimer(mHWnd, 0, 10, NULL);
|
SetTimer(mHWnd, 0, 10, NULL);
|
||||||
|
|
||||||
|
@ -1174,10 +1198,10 @@ void WinBFWindow::SetMinimumSize(int minWidth, int minHeight, bool clientSized)
|
||||||
void WinBFWindow::GetPosition(int* x, int* y, int* width, int* height, int* clientX, int* clientY, int* clientWidth, int* clientHeight)
|
void WinBFWindow::GetPosition(int* x, int* y, int* width, int* height, int* clientX, int* clientY, int* clientWidth, int* clientHeight)
|
||||||
{
|
{
|
||||||
RECT windowRect;
|
RECT windowRect;
|
||||||
GetWindowRect(mHWnd, &windowRect);
|
::GetWindowRect(mHWnd, &windowRect);
|
||||||
|
|
||||||
RECT clientRect;
|
RECT clientRect;
|
||||||
GetClientRect(mHWnd, &clientRect);
|
::GetClientRect(mHWnd, &clientRect);
|
||||||
|
|
||||||
if (clientRect.right <= clientRect.left)
|
if (clientRect.right <= clientRect.left)
|
||||||
return; // TODO: return failure?
|
return; // TODO: return failure?
|
||||||
|
@ -1195,9 +1219,53 @@ void WinBFWindow::GetPosition(int* x, int* y, int* width, int* height, int* clie
|
||||||
*clientY = startPt.y;
|
*clientY = startPt.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WinBFWindow::Resize(int x, int y, int width, int height)
|
void WinBFWindow::GetPlacement(int* normX, int* normY, int* normWidth, int* normHeight, int* showKind)
|
||||||
{
|
{
|
||||||
::MoveWindow(mHWnd, x, y, width, height, FALSE);
|
WINDOWPLACEMENT wndPlacement = { sizeof(WINDOWPLACEMENT), 0 };
|
||||||
|
::GetWindowPlacement(mHWnd, &wndPlacement);
|
||||||
|
*normX = wndPlacement.rcNormalPosition.left;
|
||||||
|
*normY = wndPlacement.rcNormalPosition.top;
|
||||||
|
*normWidth = wndPlacement.rcNormalPosition.right - wndPlacement.rcNormalPosition.left;
|
||||||
|
*normHeight = wndPlacement.rcNormalPosition.bottom - wndPlacement.rcNormalPosition.top;
|
||||||
|
switch (wndPlacement.showCmd)
|
||||||
|
{
|
||||||
|
case SW_SHOWMINIMIZED:
|
||||||
|
*showKind = 1;
|
||||||
|
break;
|
||||||
|
case SW_SHOWMAXIMIZED:
|
||||||
|
*showKind = 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
*showKind = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WinBFWindow::Resize(int x, int y, int width, int height, int showKind)
|
||||||
|
{
|
||||||
|
WINDOWPLACEMENT wndPlacement = { sizeof(WINDOWPLACEMENT), 0 };
|
||||||
|
::GetWindowPlacement(mHWnd, &wndPlacement);
|
||||||
|
|
||||||
|
switch (showKind)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
wndPlacement.showCmd = SW_SHOWMINIMIZED;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
wndPlacement.showCmd = SW_SHOWMAXIMIZED;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
wndPlacement.showCmd = SW_SHOWNORMAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
wndPlacement.rcNormalPosition.left = x;
|
||||||
|
wndPlacement.rcNormalPosition.top = y;
|
||||||
|
wndPlacement.rcNormalPosition.right = x + width;
|
||||||
|
wndPlacement.rcNormalPosition.bottom = y + height;
|
||||||
|
::SetWindowPlacement(mHWnd, &wndPlacement);
|
||||||
|
|
||||||
|
//::MoveWindow(mHWnd, x, y, width, height, FALSE);
|
||||||
mRenderWindow->Resized();
|
mRenderWindow->Resized();
|
||||||
if (mMovedFunc != NULL)
|
if (mMovedFunc != NULL)
|
||||||
mMovedFunc(this);
|
mMovedFunc(this);
|
||||||
|
|
|
@ -69,7 +69,8 @@ public:
|
||||||
virtual void LostFocus(BFWindow* newFocus) override;
|
virtual void LostFocus(BFWindow* newFocus) override;
|
||||||
virtual void SetMinimumSize(int minWidth, int minHeight, bool clientSized) override;
|
virtual void SetMinimumSize(int minWidth, int minHeight, bool clientSized) override;
|
||||||
virtual void GetPosition(int* x, int* y, int* width, int* height, int* clientX, int* clientY, int* clientWidth, int* clientHeight) override;
|
virtual void GetPosition(int* x, int* y, int* width, int* height, int* clientX, int* clientY, int* clientWidth, int* clientHeight) override;
|
||||||
virtual void Resize(int x, int y, int width, int height) override;
|
virtual void GetPlacement(int* normX, int* normY, int* normWidth, int* normHeight, int* showKind) override;
|
||||||
|
virtual void Resize(int x, int y, int width, int height, int showKind) override;
|
||||||
virtual void SetClientPosition(int x, int y) override;
|
virtual void SetClientPosition(int x, int y) override;
|
||||||
virtual void SetMouseVisible(bool isMouseVisible) override;
|
virtual void SetMouseVisible(bool isMouseVisible) override;
|
||||||
virtual void SetAlpha(float alpha, uint32 destAlphaSrcMask, bool isMouseVisible) override;
|
virtual void SetAlpha(float alpha, uint32 destAlphaSrcMask, bool isMouseVisible) override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue