1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-14 04:03:51 +02:00

Initial console support

This commit is contained in:
Brian Fiete 2024-07-19 10:31:33 +02:00
parent 45a5978611
commit 186c2125fa
21 changed files with 1244 additions and 29 deletions

View file

@ -7,10 +7,14 @@ namespace Beefy.widgets
{
public enum KeyFlags
{
None = 0,
Alt = 1,
Ctrl = 2,
Shift = 4
case None = 0,
Alt = 1,
Ctrl = 2,
Shift = 4,
CapsLock = 8,
NumLock = 0x10;
public KeyFlags HeldKeys => this & ~(CapsLock | NumLock);
}
}

View file

@ -691,6 +691,8 @@ namespace Beefy.gfx
public float GetWidth(char32 theChar)
{
CharData charData = GetCharData(theChar);
if (charData == null)
return 0;
return charData.mXAdvance;
}

View file

@ -2304,7 +2304,7 @@ namespace Beefy.widgets
int prevCursorPos;
bool gotCursorPos = TryGetCursorTextPos(out prevCursorPos);
if (mWidgetWindow.GetKeyFlags() == .Ctrl)
if (mWidgetWindow.GetKeyFlags(true) == .Ctrl)
{
switch (keyCode)
{
@ -2330,7 +2330,7 @@ namespace Beefy.widgets
}
}
if (mWidgetWindow.GetKeyFlags() == .Ctrl | .Shift)
if (mWidgetWindow.GetKeyFlags(true) == .Ctrl | .Shift)
{
switch (keyCode)
{

View file

@ -910,7 +910,7 @@ namespace Beefy.widgets
switch (keyCode)
{
case (KeyCode)'A':
if ((mAllowMultiSelect) && (mWidgetWindow.GetKeyFlags() == KeyFlags.Ctrl))
if ((mAllowMultiSelect) && (mWidgetWindow.GetKeyFlags(true) == KeyFlags.Ctrl))
{
mRoot.WithItems(scope (listViewItem) =>
{

View file

@ -747,18 +747,32 @@ namespace Beefy.widgets
}
}
public virtual void MouseWheel(MouseEvent evt)
{
if (!evt.mHandled)
{
MouseWheel(evt.mX, evt.mY, evt.mWheelDeltaX, evt.mWheelDeltaY);
MarkDirty();
if (mParent != null)
{
MouseEvent parentEvt = scope .();
parentEvt.mWheelDeltaX = evt.mWheelDeltaX;
parentEvt.mWheelDeltaY = evt.mWheelDeltaY;
parentEvt.mSender = evt.mSender;
// Keep passing it up until some is interested in using it...
SelfToParentTranslate(evt.mX, evt.mY, out parentEvt.mX, out parentEvt.mY);
mParent.MouseWheel(parentEvt);
}
}
}
public virtual void MouseWheel(float x, float y, float deltaX, float deltaY)
{
MarkDirty();
if (mParent != null)
{
// Keep passing it up until some is interested in using it...
float aX;
float aY;
SelfToParentTranslate(x, y, out aX, out aY);
mParent.MouseWheel(aX, aY, deltaX, deltaY);
}
}
public virtual void MouseUp(float x, float y, int32 btn)

View file

@ -17,6 +17,7 @@ namespace Beefy.widgets
public delegate void WindowMovedHandler(BFWindow window);
public delegate void MouseWheelHandler(MouseEvent mouseEvent);
public delegate void KeyDownHandler(KeyDownEvent keyboardEvent);
public delegate void KeyUpHandler(KeyCode keyCode);
//public delegate void CloseTemporaryHandler(WidgetWindow window);
public delegate void DragDropFileHandler(StringView filePath);
@ -33,6 +34,7 @@ namespace Beefy.widgets
public Event<MouseWheelHandler> mOnMouseWheel ~ _.Dispose();
public Event<MenuItemSelectedHandler> mOnMenuItemSelected ~ _.Dispose();
public Event<KeyDownHandler> mOnWindowKeyDown ~ _.Dispose();
public Event<KeyUpHandler> mOnWindowKeyUp ~ _.Dispose();
public Event<delegate HitTestResult(int32, int32)> mOnHitTest ~ _.Dispose();
public Event<DragDropFileHandler> mOnDragDropFile ~ _.Dispose();
@ -122,7 +124,12 @@ namespace Beefy.widgets
}
}
public KeyFlags GetKeyFlags()
#if BF_PLATFORM_WINDOWS
[CLink, CallingConvention(.Stdcall)]
static extern int16 GetKeyState(int nVirtKey);
#endif
public KeyFlags GetKeyFlags(bool onlyHeldKeys)
{
KeyFlags keyFlags = default;
if (IsKeyDown(KeyCode.Shift))
@ -131,6 +138,17 @@ namespace Beefy.widgets
keyFlags |= KeyFlags.Ctrl;
if (IsKeyDown(KeyCode.Menu))
keyFlags |= KeyFlags.Alt;
#if BF_PLATFORM_WINDOWS
if (!onlyHeldKeys)
{
if (GetKeyState((.)KeyCode.CapsLock) != 0)
keyFlags |= .CapsLock;
if (GetKeyState((.)KeyCode.Numlock) != 0)
keyFlags |= .NumLock;
}
#endif
return keyFlags;
}
@ -414,7 +432,7 @@ namespace Beefy.widgets
KeyDownEvent e = scope KeyDownEvent();
e.mSender = this;
e.mKeyFlags = GetKeyFlags();
e.mKeyFlags = GetKeyFlags(false);
e.mKeyCode = (KeyCode)keyCode;
e.mIsRepeat = isRepeat != 0;
@ -450,6 +468,8 @@ namespace Beefy.widgets
var fakeFocusWindow = GetFakeFocusWindow();
if (fakeFocusWindow != null)
fakeFocusWindow.KeyUp(keyCode);
mOnWindowKeyUp((.)keyCode);
}
public override HitTestResult HitTest(int32 x, int32 y)
@ -650,7 +670,7 @@ namespace Beefy.widgets
let oldFlags = mMouseFlags;
if (mMouseFlags == 0)
mMouseDownKeyFlags = GetKeyFlags();
mMouseDownKeyFlags = GetKeyFlags(true);
mMouseFlags |= (MouseFlag)(1 << btn);
if ((!mHasFocus) && (mParent == null))
@ -802,7 +822,14 @@ namespace Beefy.widgets
float childX;
float childY;
aWidget.RootToSelfTranslate(mMouseX, mMouseY, out childX, out childY);
aWidget.MouseWheel(childX, childY, deltaX, deltaY);
MouseEvent anEvent = scope MouseEvent();
anEvent.mX = childX;
anEvent.mY = childY;
anEvent.mWheelDeltaX = deltaX;
anEvent.mWheelDeltaY = deltaY;
anEvent.mSender = this;
aWidget.MouseWheel(anEvent);
}
}

View file

@ -35,6 +35,16 @@ namespace System.Diagnostics
}
}
public int ProcessId
{
get
{
if (mSpawn == null)
return -1;
return Platform.BfpSpawn_GetProcessId(mSpawn);
}
}
public this()
{
mSpawn = null;

View file

@ -243,6 +243,8 @@ namespace System
public static void BfpProcess_GetProcessName(BfpProcess* process, char8* outName, int32* inOutNameSize, BfpProcessResult* outResult) => Runtime.NotImplemented();
public static int32 BfpProcess_GetProcessId(BfpProcess* process) => Runtime.NotImplemented();
public static int BfpSpawn_GetProcessId(BfpSpawn* spawn) => Runtime.NotImplemented();;
#endif
public enum BfpSpawnFlags : int32
@ -286,6 +288,8 @@ namespace System
public static extern bool BfpSpawn_WaitFor(BfpSpawn* spawn, int waitMS, int* outExitCode, BfpSpawnResult* outResult);
[CallingConvention(.Stdcall), CLink]
public static extern void BfpSpawn_GetStdHandles(BfpSpawn* spawn, BfpFile** outStdIn, BfpFile** outStdOut, BfpFile** outStdErr);
[CallingConvention(.Stdcall), CLink]
public static extern int BfpSpawn_GetProcessId(BfpSpawn* spawn);
[CallingConvention(.Stdcall), CLink]
public static extern int BfpProcess_GetCurrentId();

View file

@ -101,6 +101,12 @@ namespace System
public function int WndProc(HWnd hWnd, int32 msg, int wParam, int lParam);
public delegate IntBool EnumThreadWindowsCallback(HWnd hWnd, void* extraParameter);
public struct Rect : this(int32 left, int32 top, int32 right, int32 bottom)
{
public int32 Width => right - left;
public int32 Height => bottom - top;
}
[CRepr]
public struct OpenFileName
{
@ -1737,6 +1743,9 @@ namespace System
public static extern int SetWindowLongPtrW(int hWnd, int32 nIndex, int value);
#endif
[Import("user32.lib"), CLink, CallingConvention(.Stdcall)]
public static extern IntBool SetWindowPos(HWnd hWnd, HWnd hWndAfter, int x, int y, int cx, int cy, int flags);
[Import("user32.lib"), CLink, CallingConvention(.Stdcall)]
public static extern IntBool PostMessageW(HWnd hWnd, int32 msg, int wParam, int lParam);
@ -1773,6 +1782,9 @@ namespace System
[Import("user32.lib"), CLink, CallingConvention(.Stdcall)]
public static extern int32 GetWindowTextA(HWnd hWnd, char8* ptr, int32 length);
[Import("user32.lib"), CLink, CallingConvention(.Stdcall)]
public static extern IntBool AdjustWindowRectEx(ref Rect rect, uint32 style, IntBool menu, uint32 exStyle);
[CLink, CallingConvention(.Stdcall)]
public static extern int32 GetWindowThreadProcessId(HWnd handle, out int32 processId);