Issues

Issue #741 resolved

`newCursor` accepting a filepath / `setCursor` accepting a CursorType?

hahawoo
created an issue

I mentioned some of this on the forums but I thought I'd mention it here since I just thought of another reason why this might maybe perhaps be a good idea.

So currently, newCursor can accept an ImageData or a CursorType, and setCursor accepts a Cursor or nothing to reset to the default cursor.

I see two issues with this:

1: I'm not really sure how to phrase this, but it's weird that the constructor can only create one thing from the CursorType. Like...

cursor1 = love.mouse.newCursor('arrow')
cursor2 = love.mouse.newCursor('arrow')

2: Image cursors could be created from a filepath which could be nice, except since newCursor accepts a CursorType string the argument would be ambiguous.

cursor = love.mouse.newCursor('cursor.png')

So, how about...

1: setCursor could accept a Cursor or a CursorType.

2: love.mouse.newCursor could also accept a filepath.

I think it might make things nicer to use:

custom = love.mouse.newCursor(love.image.newImageData('cursor.png'))
arrow = love.mouse.newCursor('arrow')

if hover() then
    love.mouse.setCursor(custom)
else
    love.mouse.setCursor(arrow)
end
custom = love.mouse.newCursor('cursor.png')

if hover() then
    love.mouse.setCursor(custom)
else
    love.mouse.setCursor('arrow')
end

Comments (7)

  1. Alex Szpakowski

    Deleting system cursors when the module destructor is called might be fine I think, as long as it's determined that system cursors on each OS don't use much RAM.

  2. hahawoo reporter

    I guess so, but whatever it returns would still be a valid thing for setCursor to accept.

    love.mouse.setCursor(love.mouse.getCursor())
    
  3. Alex Szpakowski

    I still feel weird about setCursor accepting and getCursor returning two completely different variable types. Even the internal code for it would be pretty weird.

    Splitting newCursor into newImageCursor and newSystemCursor would allow for newImageCursor to accept a file path, at least. Perhaps getSystemCursor could be implemented instead of newSystemCursor.

  4. Log in to comment