subsoap / defos

Extra native OS functions for games written using the Defold game engine
Creative Commons Zero v1.0 Universal
119 stars 16 forks source link

Too difficult logic for set_cursor #72

Closed AGulev closed 6 years ago

AGulev commented 6 years ago

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:

`

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?

chaosddp commented 6 years ago

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.

dapetcu21 commented 6 years ago

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.

AGulev commented 6 years ago

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