mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 03:28:20 +02:00
Beefy2D windows enhancements
This commit is contained in:
parent
6045137bce
commit
2428fe8e57
9 changed files with 125 additions and 52 deletions
|
@ -48,7 +48,8 @@ namespace Beefy
|
|||
ShowMinimized = 0x0200'0000,
|
||||
ShowMaximized = 0x0400'0000,
|
||||
AllowFullscreen = 0x0800'0000,
|
||||
AcceptFiles = 0x1000'0000
|
||||
AcceptFiles = 0x1000'0000,
|
||||
NoShow = 0x2000'0000,
|
||||
};
|
||||
|
||||
[AllowDuplicates]
|
||||
|
@ -84,6 +85,18 @@ namespace Beefy
|
|||
Zoom = 9
|
||||
}
|
||||
|
||||
public enum ShowKind
|
||||
{
|
||||
Hide,
|
||||
Normal,
|
||||
Minimized,
|
||||
Maximized,
|
||||
Show,
|
||||
ShowNormal,
|
||||
ShowMinimized,
|
||||
ShowMaximized
|
||||
}
|
||||
|
||||
public SysMenu mSysMenu ~ delete _;
|
||||
public Dictionary<int, SysMenu> mSysMenuMap = new Dictionary<int, SysMenu>() ~ delete _;
|
||||
public DrawLayer mDefaultDrawLayer ~ delete _;
|
||||
|
@ -108,9 +121,14 @@ namespace Beefy
|
|||
{
|
||||
public enum ShowKind
|
||||
{
|
||||
Hide,
|
||||
Normal,
|
||||
Minimized,
|
||||
Maximized
|
||||
Maximized,
|
||||
Show,
|
||||
ShowNormal,
|
||||
ShowMinimized,
|
||||
ShowMaximized
|
||||
}
|
||||
|
||||
delegate void NativeMovedDelegate(void* window);
|
||||
|
@ -147,6 +165,7 @@ namespace Beefy
|
|||
public int32 mNormY;
|
||||
public int32 mNormWidth;
|
||||
public int32 mNormHeight;
|
||||
public bool mVisible = true;
|
||||
public ShowKind mShowKind;
|
||||
public int32 mClientX;
|
||||
public int32 mClientY;
|
||||
|
@ -154,7 +173,6 @@ namespace Beefy
|
|||
public int32 mClientHeight;
|
||||
public float mAlpha = 1.0f;
|
||||
public Flags mWindowFlags;
|
||||
public bool mVisible = true;
|
||||
private bool mMouseVisible;
|
||||
public bool mHasFocus = false;
|
||||
public bool mHasClosed;
|
||||
|
@ -213,6 +231,9 @@ namespace Beefy
|
|||
[CallingConvention(.Stdcall), CLink]
|
||||
static extern void BFWindow_Close(void* window, int32 force);
|
||||
|
||||
[CallingConvention(.Stdcall), CLink]
|
||||
static extern void BFWindow_Show(void* window, ShowKind showKind);
|
||||
|
||||
[CallingConvention(.Stdcall), CLink]
|
||||
static extern void BFWindow_SetForeground(void* window);
|
||||
|
||||
|
@ -334,6 +355,9 @@ namespace Beefy
|
|||
useFlags |= .NoMouseActivate;
|
||||
}*/
|
||||
|
||||
if (windowFlags.HasFlag(.NoShow))
|
||||
mVisible = false;
|
||||
|
||||
mNativeWindow = BFApp_CreateWindow((parent != null) ? (parent.mNativeWindow) : null, title, (int32)x, (int32)y, (int32)width, (int32)height, (int32)useFlags);
|
||||
sWindowDictionary[(int)mNativeWindow] = this;
|
||||
|
||||
|
@ -461,6 +485,12 @@ namespace Beefy
|
|||
GotFocus();
|
||||
}
|
||||
|
||||
public void Show(ShowKind showKind)
|
||||
{
|
||||
mShowKind = showKind;
|
||||
BFWindow_Show(mNativeWindow, showKind);
|
||||
}
|
||||
|
||||
public void SetNonExclusiveMouseCapture()
|
||||
{
|
||||
// Does checking of mouse coords against all window even when this window has mouse capture,
|
||||
|
|
|
@ -1005,6 +1005,7 @@ namespace Beefy.widgets
|
|||
mouseEvent.mSender = selectedItem;
|
||||
mouseEvent.mBtnCount = 2;
|
||||
selectedItem.mOnMouseDown(mouseEvent);
|
||||
mOnItemMouseDown(selectedItem, 0, 0, 0, 2);
|
||||
default:
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ using Beefy.geom;
|
|||
namespace Beefy.widgets
|
||||
{
|
||||
public delegate void MouseLeftWindowHandler(BFWindow window);
|
||||
public delegate void WindowGotFocusHandler(BFWindow window);
|
||||
public delegate void WindowLostFocusHandler(BFWindow window, BFWindow newFocus);
|
||||
public delegate bool WindowCloseQueryHandler(BFWindow window);
|
||||
public delegate void WindowClosedHandler(BFWindow window);
|
||||
|
@ -22,7 +23,8 @@ namespace Beefy.widgets
|
|||
public class WidgetWindow : BFWindow
|
||||
{
|
||||
public Event<MouseLeftWindowHandler> mOnMouseLeftWindow ~ _.Dispose();
|
||||
public Event<WindowLostFocusHandler> mOnWindowLostFocus ~ _.Dispose();
|
||||
public Event<WindowGotFocusHandler> mOnWindowGotFocus ~ _.Dispose();
|
||||
public Event<WindowLostFocusHandler> mOnWindowLostFocus ~ _.Dispose();
|
||||
public Event<MouseEventHandler> mOnMouseDown ~ _.Dispose();
|
||||
public Event<MouseEventHandler> mOnMouseUp ~ _.Dispose();
|
||||
public Event<WindowCloseQueryHandler> mOnWindowCloseQuery ~ _.Dispose();
|
||||
|
@ -319,6 +321,8 @@ namespace Beefy.widgets
|
|||
if (!mFocusWidget.mHasFocus)
|
||||
mFocusWidget.GotFocus();
|
||||
}
|
||||
|
||||
mOnWindowGotFocus(this);
|
||||
}
|
||||
|
||||
public override void LostFocus(BFWindow newFocus)
|
||||
|
@ -363,6 +367,8 @@ namespace Beefy.widgets
|
|||
|
||||
public override void KeyChar(char32 c)
|
||||
{
|
||||
//Debug.WriteLine($"KeyChar {c}");
|
||||
|
||||
var fakeFocusWindow = GetFakeFocusWindow();
|
||||
if (fakeFocusWindow != null)
|
||||
{
|
||||
|
@ -815,6 +821,7 @@ namespace Beefy.widgets
|
|||
mOverWidget = null;
|
||||
}
|
||||
|
||||
mIsDirty = true;
|
||||
mOnMouseLeftWindow(this);
|
||||
sOnMouseLeftWindow(this);
|
||||
}
|
||||
|
|
|
@ -55,10 +55,11 @@ enum
|
|||
BFWINDOW_SHOWMINIMIZED = 0x2000000,
|
||||
BFWINDOW_SHOWMAXIMIZED = 0x4000000,
|
||||
BFWINDOW_ALLOW_FULLSCREEN = 0x8000000,
|
||||
BFWINDOW_ACCEPTFILES = 0x10000000
|
||||
|
||||
BFWINDOW_ACCEPTFILES = 0x10000000,
|
||||
BFWINDOW_NOSHOW = 0x20000000
|
||||
|
||||
};
|
||||
|
||||
|
||||
class RenderWindow;
|
||||
|
||||
class BFMenu
|
||||
|
@ -66,7 +67,7 @@ class BFMenu
|
|||
public:
|
||||
BFMenu* mParent;
|
||||
Array<BFMenu*> mBFMenuList;
|
||||
|
||||
|
||||
uint32 mKeyCode;
|
||||
bool mKeyCtrl;
|
||||
bool mKeyAlt;
|
||||
|
@ -94,9 +95,22 @@ struct BFCoord
|
|||
|
||||
class BFWindow
|
||||
{
|
||||
public:
|
||||
enum ShowKind : int8
|
||||
{
|
||||
ShowKind_Hide,
|
||||
ShowKind_Normal,
|
||||
ShowKind_Minimized,
|
||||
ShowKind_Maximized,
|
||||
ShowKind_Show,
|
||||
ShowKind_ShowNormal,
|
||||
ShowKind_ShowMinimized,
|
||||
ShowKind_ShowMaximized
|
||||
};
|
||||
|
||||
public:
|
||||
BFWindow* mParent;
|
||||
Array<BFWindow*> mChildren;
|
||||
Array<BFWindow*> mChildren;
|
||||
int mFlags;
|
||||
bool mIsKeyDown[KEYCODE_MAX];
|
||||
bool mIsMouseDown[MOUSEBUTTON_MAX];
|
||||
|
@ -124,7 +138,7 @@ public:
|
|||
BFWindow_MouseLeave mMouseLeaveFunc;
|
||||
BFWindow_MenuItemSelectedFunc mMenuItemSelectedFunc;
|
||||
BFWindow_DragDropFileFunc mDragDropFileFunc;
|
||||
|
||||
|
||||
public:
|
||||
BFWindow();
|
||||
virtual ~BFWindow();
|
||||
|
@ -134,17 +148,18 @@ public:
|
|||
virtual bool TryClose() = 0;
|
||||
virtual void SetTitle(const char* title) = 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 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 Resize(int x, int y, int width, int height, ShowKind showKind) = 0;
|
||||
virtual void SetClientPosition(int x, int y) = 0;
|
||||
virtual void SetMouseVisible(bool isMouseVisible) = 0;
|
||||
virtual void SetAlpha(float alpha, uint32 destAlphaSrcMask, bool isMouseVisible) = 0;
|
||||
virtual void SetForeground() = 0;
|
||||
virtual void Show(ShowKind showKind) = 0;
|
||||
virtual void SetForeground() = 0;
|
||||
virtual void SetNonExclusiveMouseCapture() { mNonExclusiveMouseCapture = true; }
|
||||
virtual void CaptureMouse() {}
|
||||
virtual void CaptureMouse() {}
|
||||
virtual bool IsMouseCaptured() { return false; }
|
||||
virtual void LostFocus(BFWindow* newFocus) = 0;
|
||||
virtual void LostFocus(BFWindow* newFocus) = 0;
|
||||
virtual int GetDPI() { return 0; }
|
||||
|
||||
virtual BFMenu* AddMenuItem(BFMenu* parent, int insertIdx, const char* text, const char* hotKey, BFSysBitmap* bitmap, bool enabled, int checkState, bool radioCheck) = 0;
|
||||
|
|
|
@ -364,7 +364,12 @@ BF_EXPORT void BF_CALLTYPE BFWindow_GetPlacement(BFWindow* window, int* normX, i
|
|||
|
||||
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);
|
||||
window->Resize(x, y, width, height, (BFWindow::ShowKind)showKind);
|
||||
}
|
||||
|
||||
BF_EXPORT void BF_CALLTYPE BFWindow_Show(BFWindow* window, BFWindow::ShowKind showKind)
|
||||
{
|
||||
window->Show(showKind);
|
||||
}
|
||||
|
||||
BF_EXPORT void BF_CALLTYPE BFWindow_SetForeground(BFWindow* window)
|
||||
|
|
|
@ -87,11 +87,12 @@ static int SDLConvertScanCode(int scanCode)
|
|||
{
|
||||
if ((scanCode >= SDL_SCANCODE_A) && (scanCode <= SDL_SCANCODE_Z))
|
||||
return (scanCode - SDL_SCANCODE_A) + 'A';
|
||||
if ((scanCode >= SDL_SCANCODE_0) && (scanCode <= SDL_SCANCODE_9))
|
||||
return (scanCode - SDL_SCANCODE_0) + '0';
|
||||
if ((scanCode >= SDL_SCANCODE_1) && (scanCode <= SDL_SCANCODE_9))
|
||||
return (scanCode - SDL_SCANCODE_1) + '1';
|
||||
|
||||
switch (scanCode)
|
||||
{
|
||||
case SDL_SCANCODE_9: return '0';
|
||||
case SDL_SCANCODE_CANCEL: return 0x03;
|
||||
case SDL_SCANCODE_AC_BACK: return 0x08;
|
||||
case SDL_SCANCODE_TAB: return 0x09;
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
virtual void SetTitle(const char* title) override {}
|
||||
virtual void SetMinimumSize(int minWidth, int minHeight, bool clientSized) 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 Resize(int x, int y, int width, int height, ShowKind showKind) override {}
|
||||
virtual void SetMouseVisible(bool isMouseVisible) override {}
|
||||
|
||||
virtual bool TryClose() override;
|
||||
|
@ -43,6 +43,7 @@ public:
|
|||
|
||||
virtual void ModalsRemoved() override;
|
||||
|
||||
virtual void Show(ShowKind showKind) {}
|
||||
virtual void SetForeground() override {};
|
||||
};
|
||||
|
||||
|
|
|
@ -243,6 +243,9 @@ WinBFWindow::WinBFWindow(BFWindow* parent, const StringImpl& title, int x, int y
|
|||
mSoftHasFocus = false;
|
||||
}
|
||||
|
||||
if ((windowFlags & BFWINDOW_NOSHOW))
|
||||
showFlags = SWP_HIDEWINDOW;
|
||||
|
||||
if (windowFlags & (BFWINDOW_SHOWMINIMIZED | BFWINDOW_SHOWMAXIMIZED))
|
||||
{
|
||||
WINDOWPLACEMENT wndPlacement = { sizeof(WINDOWPLACEMENT), 0 };
|
||||
|
@ -353,6 +356,27 @@ void WinBFWindow::SetTitle(const char* title)
|
|||
SetWindowTextA(mHWnd, title);
|
||||
}
|
||||
|
||||
static int ToWShow(BFWindow::ShowKind showKind)
|
||||
{
|
||||
switch (showKind)
|
||||
{
|
||||
case BFWindow::ShowKind_Hide: return SW_HIDE;
|
||||
case BFWindow::ShowKind_Normal: return SW_NORMAL;
|
||||
case BFWindow::ShowKind_Minimized: return SW_MINIMIZE;
|
||||
case BFWindow::ShowKind_Maximized: return SW_MAXIMIZE;
|
||||
case BFWindow::ShowKind_Show: return SW_SHOW;
|
||||
case BFWindow::ShowKind_ShowNormal: return SW_SHOWNORMAL;
|
||||
case BFWindow::ShowKind_ShowMinimized: return SW_SHOWMINIMIZED;
|
||||
case BFWindow::ShowKind_ShowMaximized: return SW_SHOWMAXIMIZED;
|
||||
}
|
||||
return SW_SHOW;
|
||||
}
|
||||
|
||||
void WinBFWindow::Show(ShowKind showKind)
|
||||
{
|
||||
::ShowWindow(mHWnd, ToWShow(showKind));
|
||||
}
|
||||
|
||||
void WinBFWindow::LostFocus(BFWindow* newFocus)
|
||||
{
|
||||
///OutputDebugStrF("Lost focus\n");
|
||||
|
@ -1607,35 +1631,23 @@ void WinBFWindow::GetPlacement(int* normX, int* normY, int* normWidth, int* norm
|
|||
switch (wndPlacement.showCmd)
|
||||
{
|
||||
case SW_SHOWMINIMIZED:
|
||||
*showKind = 1;
|
||||
*showKind = ShowKind_ShowMinimized;
|
||||
break;
|
||||
case SW_SHOWMAXIMIZED:
|
||||
*showKind = 2;
|
||||
*showKind = ShowKind_ShowMaximized;
|
||||
break;
|
||||
default:
|
||||
*showKind = 0;
|
||||
*showKind = ShowKind_Hide;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void WinBFWindow::Resize(int x, int y, int width, int height, int showKind)
|
||||
void WinBFWindow::Resize(int x, int y, int width, int height, ShowKind 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.showCmd = ToWShow(showKind);
|
||||
wndPlacement.rcNormalPosition.left = x;
|
||||
wndPlacement.rcNormalPosition.top = y;
|
||||
wndPlacement.rcNormalPosition.right = x + width;
|
||||
|
|
|
@ -17,10 +17,10 @@ typedef Dictionary<String, uint32> StringToUIntMap;
|
|||
|
||||
class WinBFMenu : public BFMenu
|
||||
{
|
||||
public:
|
||||
public:
|
||||
HMENU mMenu;
|
||||
uint32 mMenuId;
|
||||
static int mMenuCount;
|
||||
static int mMenuCount;
|
||||
bool mIsPlaceholder;
|
||||
|
||||
public:
|
||||
|
@ -32,9 +32,9 @@ typedef Dictionary<HMENU, WinBFMenu*> WinHMenuMap;
|
|||
|
||||
class WinBFWindow : public BFWindow
|
||||
{
|
||||
public:
|
||||
HWND mHWnd;
|
||||
bool mIsMouseInside;
|
||||
public:
|
||||
HWND mHWnd;
|
||||
bool mIsMouseInside;
|
||||
WinMenuIDMap mMenuIDMap;
|
||||
WinHMenuMap mHMenuMap;
|
||||
|
||||
|
@ -49,7 +49,7 @@ public:
|
|||
int mMinHeight;
|
||||
bool mMouseVisible;
|
||||
bool mHasFocus;
|
||||
bool mSoftHasFocus; // Mostly tracks mHasFocus except for when we get an explicit 'LostFocus' callback
|
||||
bool mSoftHasFocus; // Mostly tracks mHasFocus except for when we get an explicit 'LostFocus' callback
|
||||
bool mAwaitKeyReleases;
|
||||
int mAwaitKeyReleasesCheckIdx;
|
||||
DWORD mAwaitKeyReleasesEventTick;
|
||||
|
@ -72,12 +72,13 @@ public:
|
|||
virtual void Destroy() override;
|
||||
virtual bool TryClose() override;
|
||||
virtual void SetTitle(const char* title) override;
|
||||
virtual void SetForeground() override;
|
||||
virtual void Show(ShowKind showKind) override;
|
||||
virtual void SetForeground() override;
|
||||
virtual void LostFocus(BFWindow* newFocus) 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 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 Resize(int x, int y, int width, int height, ShowKind showKind) override;
|
||||
virtual void SetClientPosition(int x, int y) override;
|
||||
virtual void SetMouseVisible(bool isMouseVisible) override;
|
||||
virtual void SetAlpha(float alpha, uint32 destAlphaSrcMask, bool isMouseVisible) override;
|
||||
|
@ -93,36 +94,36 @@ public:
|
|||
|
||||
class WinBFApp : public BFApp
|
||||
{
|
||||
public:
|
||||
public:
|
||||
bool mInMsgProc;
|
||||
StringToUIntMap mClipboardFormatMap;
|
||||
DSoundManager* mDSoundManager;
|
||||
DInputManager* mDInputManager;
|
||||
BfpThreadId mVSyncThreadId;
|
||||
BfpThread* mVSyncThread;
|
||||
BfpThread* mVSyncThread;
|
||||
volatile bool mClosing;
|
||||
|
||||
protected:
|
||||
void VSyncThreadProc();
|
||||
static void BFP_CALLTYPE VSyncThreadProcThunk(void* ptr);
|
||||
|
||||
virtual void Draw() override;
|
||||
virtual void Draw() override;
|
||||
virtual void PhysSetCursor() override;
|
||||
|
||||
|
||||
uint32 GetClipboardFormat(const StringImpl& format);
|
||||
|
||||
public:
|
||||
WinBFApp();
|
||||
virtual ~WinBFApp();
|
||||
virtual ~WinBFApp();
|
||||
|
||||
virtual void Init() override;
|
||||
virtual void Run() override;
|
||||
virtual void Run() override;
|
||||
virtual void Process() override;
|
||||
|
||||
virtual void GetDesktopResolution(int& width, int& height) override;
|
||||
virtual void GetWorkspaceRect(int& x, int& y, int& width, int& height) override;
|
||||
virtual void GetWorkspaceRectFrom(int fromX, int fromY, int fromWidth, int fromHeight, int& outX, int& outY, int& outWidth, int& outHeight) override;
|
||||
virtual BFWindow* CreateNewWindow(BFWindow* parent, const StringImpl& title, int x, int y, int width, int height, int windowFlags) override;
|
||||
virtual BFWindow* CreateNewWindow(BFWindow* parent, const StringImpl& title, int x, int y, int width, int height, int windowFlags) override;
|
||||
virtual DrawLayer* CreateDrawLayer(BFWindow* window);
|
||||
|
||||
virtual void* GetClipboardData(const StringImpl& format, int* size) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue