Add more cursors

This commit is contained in:
Simon Lübeß
2024-10-31 00:03:17 +01:00
parent 2e60f13c02
commit 61bc3ed0bb
15 changed files with 53 additions and 25 deletions
@@ -0,0 +1 @@
https://hg.mozilla.org/mozilla-central/file/tip/widget/windows/res
Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

@@ -25,7 +25,7 @@ abstract class UltralightWindow
{ {
WindowDescription windowDesc = .Default; WindowDescription windowDesc = .Default;
windowDesc.Title = title; windowDesc.Title = title;
windowDesc.WindowStyle = .Borderless; windowDesc.WindowStyle = .CustomTitle;
_window = new Window(windowDesc); _window = new Window(windowDesc);
_window.EventCallback = new => EventHandler; _window.EventCallback = new => EventHandler;
@@ -327,11 +327,9 @@ abstract class UltralightWindow
cursor = .ResizeNorthWestSouthEast; cursor = .ResizeNorthWestSouthEast;
case .kCursor_ColumnResize: case .kCursor_ColumnResize:
// TODO use cursor file
cursor = .ResizeColumn; cursor = .ResizeColumn;
case .kCursor_RowResize: case .kCursor_RowResize:
// TODO use cursor file
cursor = .ResizeRow; cursor = .ResizeRow;
case .kCursor_MiddlePanning: case .kCursor_MiddlePanning:
@@ -11,6 +11,7 @@ using System.Diagnostics;
using GlitchyEngine.Math; using GlitchyEngine.Math;
using GlitchyEngine.Renderer; using GlitchyEngine.Renderer;
using DirectX.Windows.Winuser.RawInput; using DirectX.Windows.Winuser.RawInput;
using System.Collections;
using static System.Windows; using static System.Windows;
using internal GlitchyEngine; using internal GlitchyEngine;
@@ -634,11 +635,36 @@ namespace GlitchyEngine.UI
_title = new String(titleSpan); _title = new String(titleSpan);
} }
[CLink]
private static extern HCURSOR LoadCursorFromFileW(LPCWSTR lpFileName);
[CLink]
private static extern IntBool DestroyCursor(HCURSOR hCursor);
private static HCURSOR ResizeColumnCursor = 0 ~ DestroyCursor(_);
private static HCURSOR VerticalTextCursor = 0 ~ DestroyCursor(_);
private static HCURSOR ColResizeCursor = 0 ~ DestroyCursor(_);
private static HCURSOR RowResizeCursor = 0 ~ DestroyCursor(_);
private static HCURSOR CellCursor = 0 ~ DestroyCursor(_);
private static HCURSOR AliasCursor = 0 ~ DestroyCursor(_);
private static HCURSOR CopyCursor = 0 ~ DestroyCursor(_);
private static HCURSOR ZoomInCursor = 0 ~ DestroyCursor(_);
private static HCURSOR ZoomOutCursor = 0 ~ DestroyCursor(_);
private static HCURSOR GrabCursor = 0 ~ DestroyCursor(_);
private static HCURSOR GrabbingCursor = 0 ~ DestroyCursor(_);
public override Result<void> SetCursor(CursorImage cursorImage) public override Result<void> SetCursor(CursorImage cursorImage)
{ {
LPCTSTR cursor = null; LPCTSTR cursor = null;
Handle hCursor = 0;
// Firefox cursors: https://hg.mozilla.org/mozilla-central/file/tip/widget/windows/res void UseCustomCursor(ref HCURSOR cursor, StringView path)
{
if (cursor == 0)
cursor = LoadCursorFromFileW(path.ToScopedNativeWChar!());
hCursor = cursor;
}
switch (cursorImage) switch (cursorImage)
{ {
@@ -673,12 +699,10 @@ namespace GlitchyEngine.UI
cursor = Winuser.IDC_SIZENWSE; cursor = Winuser.IDC_SIZENWSE;
case .ResizeColumn: case .ResizeColumn:
// TODO use cursor file UseCustomCursor(ref ColResizeCursor, "Resources/Cursors/col_resize.cur");
cursor = Winuser.IDC_SIZEWE;
case .ResizeRow: case .ResizeRow:
// TODO use cursor file UseCustomCursor(ref RowResizeCursor, "Resources/Cursors/row_resize.cur");
cursor = Winuser.IDC_SIZENS;
case .PanMiddle: case .PanMiddle:
cursor = Winuser.MAKEINTRESOURCEW(32654); cursor = Winuser.MAKEINTRESOURCEW(32654);
@@ -703,16 +727,17 @@ namespace GlitchyEngine.UI
cursor = Winuser.IDC_SIZEALL; cursor = Winuser.IDC_SIZEALL;
case .VerticalText: case .VerticalText:
// TODO UseCustomCursor(ref VerticalTextCursor, "Resources/Cursors/vertical_text.cur");
case .Cell: case .Cell:
// TODO UseCustomCursor(ref CellCursor, "Resources/Cursors/cell.cur");
case .ContextMenu: case .ContextMenu:
// TODO // TODO
cursor = Winuser.IDC_ARROW;
case .Alias: case .Alias:
// TODO UseCustomCursor(ref AliasCursor, "Resources/Cursors/aliasb.cur");
case .Progress: case .Progress:
cursor = Winuser.IDC_APPSTARTING; cursor = Winuser.IDC_APPSTARTING;
@@ -721,26 +746,30 @@ namespace GlitchyEngine.UI
cursor = Winuser.IDC_NO; cursor = Winuser.IDC_NO;
case .Copy: case .Copy:
UseCustomCursor(ref CopyCursor, "Resources/Cursors/copy.cur");
case .ZoomIn:
UseCustomCursor(ref ZoomInCursor, "Resources/Cursors/zoom_in.cur");
case .ZoomOut:
UseCustomCursor(ref ZoomOutCursor, "Resources/Cursors/zoom_out.cur");
case .Grab:
UseCustomCursor(ref GrabCursor, "Resources/Cursors/grab.cur");
case .Grabbing:
UseCustomCursor(ref GrabbingCursor, "Resources/Cursors/grabbing.cur");
case .Custom:
// TODO // TODO
cursor = Winuser.IDC_ARROW;
case .None: case .None:
cursor = null; cursor = null;
case .ZoomIn:
// TODO
case .ZoomOut:
case .Grab:
// TODO
case .Grabbing:
// TODO
case .Custom:
// TODO: Use cursor file specified by user
} }
var hCursor = Winuser.LoadCursorW((.)0, cursor); if (hCursor == 0)
{
hCursor = Winuser.LoadCursorW((.)0, cursor);
}
_cursor = hCursor; _cursor = hCursor;
Winuser.SetCursor(hCursor); Winuser.SetCursor(hCursor);