subsoap/defos

Too difficult logic for set_cursor

AGulev opened this issue · 3 comments

As I think would be better to have one simple method for every platform set_cursor(nil or CONSTANT or path) where user can set path to the image .

I think those constructions are difficult:

  • On HTML5, an URL to an image (data URLs work as well)
  • On Windows, a path to an .ani or .cur file on the file system.
  • On macOS, a table of the form

`

if system_name == "Windows" then
	for i, v in ipairs({ "cursor_01.ani", "cursor_02.ani" }) do
		-- load source file and write them to save folder, so that we can access them with fullpath
		local cursor_resource = resource.load("/resources/"..v)
		local raw_bytes = buffer.get_bytes(cursor_resource, hash("data"))

		local cursor_path = sys.get_save_file(appname, v)
		local f = io.open(cursor_path, "wb")
		f:write(raw_bytes)
		f:flush()
		f:close()

		print(cursor_path)
		table.insert(self.cursors, cursor_path)
	end
end

if system_name == "Darwin" then
	table.insert(self.cursors, {
		image = resource.load("/resources/cursor_mac.tiff"),
		hot_spot_x = 18,
		hot_spot_y = 2,
	})
end

if system_name == "HTML5" then
	table.insert(self.cursors, cursor_url)
end`

Developer can include cursor file "as is" into the bundle using hidden parameter: bundle_resources (I made it with icons). https://www.defold.com/manuals/project-settings/#_project

Thanks to @dapecthu I made:
defos.get_bundle_root() - method that returns path to bundle,
defos.PATH_SEP - path separator depends of platform.
Those methods can help with this remaking.

I can make it after merging my current set_icon pull-request. What do you think about it?

I think we'd better to leave the choice to developer, not bind it to bundle_resources, but we can provide a helper method like yours.
The windows example is made by me, and i do not know the bundle resource at that time.

The problem with this is that on macOS a file path would not suffice. The hotspot X and Y are also needed. I can make it so that you can also pass in a file path on macOS, if you want to. Cursors are implemented very differently on all these platforms and trying to unify them is hard.

no, I don't need it.
no problem.
I just wanted to do it simpler for users.