Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sizing cursors #2009

Merged
merged 1 commit into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Eto.Gtk/GtkConversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,24 @@ public static Gdk.CursorType ToGdk(this CursorType cursor)
return Gdk.CursorType.Fleur;
case CursorType.Pointer:
return Gdk.CursorType.Hand2;
case CursorType.SizeAll:
return Gdk.CursorType.Fleur;
case CursorType.SizeLeft:
return Gdk.CursorType.LeftSide;
case CursorType.SizeTop:
return Gdk.CursorType.TopSide;
case CursorType.SizeRight:
return Gdk.CursorType.RightSide;
case CursorType.SizeBottom:
return Gdk.CursorType.BottomSide;
case CursorType.SizeTopLeft:
return Gdk.CursorType.TopLeftCorner;
case CursorType.SizeTopRight:
return Gdk.CursorType.TopRightCorner;
case CursorType.SizeBottomLeft:
return Gdk.CursorType.BottomLeftCorner;
case CursorType.SizeBottomRight:
return Gdk.CursorType.BottomRightCorner;
default:
throw new NotSupportedException();
}
Expand Down
49 changes: 49 additions & 0 deletions src/Eto.Mac/Forms/CursorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,60 @@ public void Create(CursorType cursor)
case CursorType.VerticalSplit:
Control = NSCursor.ResizeLeftRightCursor;
break;
case CursorType.SizeAll:
Control = GetHICursor("move") ?? NSCursor.ArrowCursor;
break;
case CursorType.SizeLeft:
case CursorType.SizeRight:
Control = GetHICursor("resizeeastwest") ?? GetNonStandardCursor("_windowResizeEastWestCursor") ?? NSCursor.ResizeLeftRightCursor;
break;
case CursorType.SizeTop:
case CursorType.SizeBottom:
Control = GetHICursor("resizenorthsouth") ?? GetNonStandardCursor("_windowResizeNorthSouthCursor") ?? NSCursor.ResizeUpDownCursor;
break;
case CursorType.SizeTopLeft:
case CursorType.SizeBottomRight:
Control = GetHICursor("resizenorthwestsoutheast") ?? GetNonStandardCursor("_windowResizeNorthWestSouthEastCursor") ?? NSCursor.ArrowCursor;
break;
case CursorType.SizeTopRight:
case CursorType.SizeBottomLeft:
Control = GetHICursor("resizenortheastsouthwest") ?? GetNonStandardCursor("_windowResizeNorthEastSouthWestCursor") ?? NSCursor.ArrowCursor;
break;
default:
throw new NotSupportedException();
}
}

static IntPtr cursorClassHandle = Class.GetHandle(typeof(NSCursor));

static NSCursor GetNonStandardCursor(string name)
{
// note, using private apis here so won't work on sandboxed apps.
try
{
var handle = Messaging.IntPtr_objc_msgSend(cursorClassHandle, Selector.GetHandle(name));
if (handle == IntPtr.Zero)
return null;
return Runtime.GetNSObject<NSCursor>(handle);
}
catch
{
return null;
}
}

static NSCursor GetHICursor(string cursorName)
{
var cursorPath = Path.Combine("/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/Resources/cursors", cursorName);
var pdfPath = Path.Combine(cursorPath, "cursor.pdf");
var infoPath = Path.Combine(cursorPath, "info.plist");
if (!File.Exists(pdfPath) || !File.Exists(infoPath))
return null;
var image = new NSImage(pdfPath);
var info = new NSDictionary(infoPath);
return new NSCursor(image, new CGPoint(((NSNumber)info.ValueForKey((NSString)"hotx")).DoubleValue, ((NSNumber)info.ValueForKey((NSString)"hoty")).DoubleValue));
}

public void Create(Image image, PointF hotspot)
{
var nsimage = image.ToNS();
Expand Down
84 changes: 56 additions & 28 deletions src/Eto.WinForms/Forms/CursorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,63 @@ namespace Eto.WinForms.Forms
{
public class CursorHandler : WidgetHandler<swf.Cursor, Cursor>, Cursor.IHandler
{
public void Create (CursorType cursor)
public void Create(CursorType cursor)
{
switch (cursor) {
case CursorType.Arrow:
Control = swf.Cursors.Arrow;
break;
case CursorType.Crosshair:
Control = swf.Cursors.Cross;
break;
case CursorType.Default:
Control = swf.Cursors.Default;
break;
case CursorType.HorizontalSplit:
Control = swf.Cursors.HSplit;
break;
case CursorType.IBeam:
Control = swf.Cursors.IBeam;
break;
case CursorType.Move:
Control = swf.Cursors.SizeAll;
break;
case CursorType.Pointer:
Control = swf.Cursors.Hand;
break;
case CursorType.VerticalSplit:
Control = swf.Cursors.VSplit;
break;
default:
throw new NotSupportedException();
switch (cursor)
{
case CursorType.Arrow:
Control = swf.Cursors.Arrow;
break;
case CursorType.Crosshair:
Control = swf.Cursors.Cross;
break;
case CursorType.Default:
Control = swf.Cursors.Default;
break;
case CursorType.HorizontalSplit:
Control = swf.Cursors.HSplit;
break;
case CursorType.IBeam:
Control = swf.Cursors.IBeam;
break;
case CursorType.Move:
Control = swf.Cursors.SizeAll;
break;
case CursorType.Pointer:
Control = swf.Cursors.Hand;
break;
case CursorType.VerticalSplit:
Control = swf.Cursors.VSplit;
break;
case CursorType.SizeAll:
Control = swf.Cursors.SizeAll;
break;
case CursorType.SizeLeft:
Control = swf.Cursors.SizeWE;
break;
case CursorType.SizeTop:
Control = swf.Cursors.SizeNS;
break;
case CursorType.SizeRight:
Control = swf.Cursors.SizeWE;
break;
case CursorType.SizeBottom:
Control = swf.Cursors.SizeNS;
break;
case CursorType.SizeTopLeft:
Control = swf.Cursors.SizeNWSE;
break;
case CursorType.SizeTopRight:
Control = swf.Cursors.SizeNESW;
break;
case CursorType.SizeBottomLeft:
Control = swf.Cursors.SizeNESW;
break;
case CursorType.SizeBottomRight:
Control = swf.Cursors.SizeNWSE;
break;
default:
throw new NotSupportedException();
}
}

Expand Down
34 changes: 31 additions & 3 deletions src/Eto.Wpf/Forms/CursorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ namespace Eto.Wpf.Forms
{
public class CursorHandler : WidgetHandler<swi.Cursor, Cursor>, Cursor.IHandler
{
public void Create (CursorType cursor)
public void Create(CursorType cursor)
{
switch (cursor) {
switch (cursor)
{
case CursorType.Arrow:
Control = swi.Cursors.Arrow;
break;
Expand All @@ -36,8 +37,35 @@ public void Create (CursorType cursor)
case CursorType.VerticalSplit:
Control = swi.Cursors.SizeWE;
break;
case CursorType.SizeAll:
Control = swi.Cursors.SizeAll;
break;
case CursorType.SizeLeft:
Control = swi.Cursors.SizeWE;
break;
case CursorType.SizeTop:
Control = swi.Cursors.SizeNS;
break;
case CursorType.SizeRight:
Control = swi.Cursors.SizeWE;
break;
case CursorType.SizeBottom:
Control = swi.Cursors.SizeNS;
break;
case CursorType.SizeTopLeft:
Control = swi.Cursors.SizeNWSE;
break;
case CursorType.SizeTopRight:
Control = swi.Cursors.SizeNESW;
break;
case CursorType.SizeBottomLeft:
Control = swi.Cursors.SizeNESW;
break;
case CursorType.SizeBottomRight:
Control = swi.Cursors.SizeNWSE;
break;
default:
throw new NotSupportedException ();
throw new NotSupportedException();
}
}

Expand Down
47 changes: 46 additions & 1 deletion src/Eto/Forms/Cursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,52 @@ public enum CursorType
/// <summary>
/// Horizontal sizing cursor
/// </summary>
HorizontalSplit
HorizontalSplit,

/// <summary>
/// All direction sizing cursor
/// </summary>
SizeAll,

/// <summary>
/// Left side sizing cursor, which on some platforms is the same as <see cref="SizeRight"/>
/// </summary>
SizeLeft,

/// <summary>
/// Top side sizing cursor, which on some platforms is the same as <see cref="SizeBottom"/>
/// </summary>
SizeTop,

/// <summary>
/// Right side sizing cursor, which on some platforms is the same as <see cref="SizeLeft"/>
/// </summary>
SizeRight,

/// <summary>
/// Bottom side sizing cursor, which on some platforms is the same as <see cref="SizeTop"/>
/// </summary>
SizeBottom,

/// <summary>
/// Top-left corner sizing cursor, which on some platforms is the same as <see cref="SizeBottomRight"/>
/// </summary>
SizeTopLeft,

/// <summary>
/// Top-right corner sizing cursor, which on some platforms is the same as <see cref="SizeBottomLeft"/>
/// </summary>
SizeTopRight,

/// <summary>
/// Bottom-left corner sizing cursor, which on some platforms is the same as <see cref="SizeTopRight"/>
/// </summary>
SizeBottomLeft,

/// <summary>
/// Bottom-right corner sizing cursor, which on some platforms is the same as <see cref="SizeTopLeft"/>
/// </summary>
SizeBottomRight
}

/// <summary>
Expand Down
Loading