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 native.setProperty("mouseCursor", cursorName) Api #83

Merged
merged 2 commits into from Jun 7, 2020

Conversation

DanS2D
Copy link
Contributor

@DanS2D DanS2D commented Jun 6, 2020

This Api allows the Solar developer to change the current operating system mouse cursor within their program on Desktop (Mac/Windows) to the cursor style of their choosing.

Shared cursors
The following cursors are available on both platforms:

  • "crosshair",
  • "pointingHand",
  • "beam",
  • "notAllowed",
  • "resizeLeftRight",
  • "resizeUpDown",
  • "arrow"

Windows Cursors
The following cursors are available on Windows only:

  • "appStarting",
  • "resizeAll",
  • "resizeNorthEastSouthWest",
  • "resizeNorthWestSouthEast",
  • "upArrow",
  • "hourglass"

Mac Cursors
The following cursors are available on MacOS only:

  • "closedHand",
  • "openHand",
  • "resizeRight",
  • "resizeLeft",
  • "resizeUp",
  • "resizeDown",
  • "disappearingItem",
  • "beamHorizontal",
  • "dragLink",
  • "dragCopy",
  • "contextMenu"

Documentation

I will be submitting a pull request with an updated native.setProperty() Api doc once this pull request has been approved, incase there are any changes to cursor names etc.

Test code:

local currentCursor = 0
local cursors = {
	"crosshair",
	"pointingHand",
	"beam",
	"notAllowed",
	"resizeLeftRight",
	"resizeUpDown",
	"arrow"
}
local windowsCursors = {
	"appStarting",
	"resizeAll",
	"resizeNorthEastSouthWest",
	"resizeNorthWestSouthEast",
	"upArrow",
	"hourglass"
}
local macCursors = {
	"closedHand", 
	"openHand",
	"resizeRight", 
	"resizeLeft",
	"resizeUp", 
	"resizeDown",
	"disappearingItem", 
	"beamHorizontal", 
	"dragLink", 
	"dragCopy", 
	"contextMenu",
}
local isWindows = system.getInfo("platform") == "win32"

if (isWindows) then
	for i = #windowsCursors, 1, -1 do
		table.insert(cursors, 1, windowsCursors[i])
	end
else
	for i = #macCursors, 1, -1 do
		table.insert(cursors, 1, macCursors[i])
	end
end

local cursorText =
	display.newText(
	{
		text = "",
		fontSize = 24
	}
)
cursorText.x = display.contentCenterX
cursorText.y = display.contentCenterY

local function changeCursor(event)
	currentCursor = currentCursor + 1

	if (currentCursor > #cursors) then
		timer.cancel(event.source)
		return
	end

	cursorText.text = cursors[currentCursor]
	native.setProperty("mouseCursor", cursors[currentCursor])
end

timer.performWithDelay(800, changeCursor, 0)

Danny Glover added 2 commits June 6, 2020 18:41
- Windows: Added `native.setProperty("mouseCursor", cursorName) Api. It allows you to change between all of the supported OS cursors on Windows.
- MAC: Added `native.setProperty("mouseCursor", cursorName) Api. It allows you to change between all of the supported OS cursors on MacOS.
@CLAassistant
Copy link

CLAassistant commented Jun 6, 2020

CLA assistant check
All committers have signed the CLA.

@Shchvova Shchvova merged commit c2bd23a into coronalabs:master Jun 7, 2020
Shchvova added a commit that referenced this pull request Jul 8, 2020
fixes #104
Reverting some of the changes in #83
@DanS2D DanS2D deleted the native-set-cursor branch July 21, 2020 00:16
ggcrunchy pushed a commit to ggcrunchy/corona that referenced this pull request Jul 8, 2021
coronalabs#83)

* WIN: Added native.setProperty("mouseCursor") API

- Windows: Added `native.setProperty("mouseCursor", cursorName) Api. It allows you to change between all of the supported OS cursors on Windows.

* MAC: Added native.setProperty("mouseCursor") API

- MAC: Added `native.setProperty("mouseCursor", cursorName) Api. It allows you to change between all of the supported OS cursors on MacOS.
ggcrunchy pushed a commit to ggcrunchy/corona that referenced this pull request Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants