mouse cursor icon

mouse cursor icon

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

mouse cursor icon

Post by gajop »

How can I programatically change the mouse cursor icon with Lua?

Please give code with examples, especially if it's using the spring commands (never learned that :roll:).
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: mouse cursor icon

Post by FLOZi »

From unsynced code:

Code: Select all

Spring.SetMouseCursor
 ( string cursorName [, number scale ] ) -> nil

Code: Select all

Spring.AssignMouseCursor changes/creates the cursor of a single CursorCmd 
 ( string "cmdName", string "iconFileName"
   [, boolean overwrite = true [, boolean hotSpotTopLeft = false] ] ) -> nil | boolean
Note, that iconFileName is not the full filename instead it is like this:
filename: Anims/cursorattack_0.bmp
iconFileName: cursorattack

Example of latter for a custom command: https://sourceforge.net/p/spring1944/co ... eClear.lua

Hopefully would work with a native engine command also.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: mouse cursor icon

Post by gajop »

So in order to change the mouse icon I must use a custom command which I have to create in a synced gadget?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: mouse cursor icon

Post by FLOZi »

No, you can just use the first API function there to change it whenever you wish to whatever you wish. :P
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: mouse cursor icon

Post by gajop »

I think I wasn't specific enough when I asked the question.
But I want to change the cursor to a custom icon, one not specified by one of the existing (default or mod) commands.

As you answered this I took a look at the code when I tried this some 1~year ago now, and it's mostly similar, except I'm not sure how you got the CMD_CLEARMINES in

Code: Select all

Spring.SetCustomCommandDrawData(CMD_CLEARMINES, "Clear Mines", {1,0.5,0,.8}, false)
A running version I have is this:
gadget:

Code: Select all

CMD_RESIZE_X = 30521

local myCustomDesc = {
    name    = "resize-x",
    action  = "resize-x",
    id      = CMD_RESIZE_X,
    type    = CMDTYPE.ICON_MAP, -- or whatever is suitable
    tooltip = "resizes x",
    cursor  = "resize-x",
}

function gadget:Initialize()
    gadgetHandler:RegisterCMDID(CMD_RESIZE_X)
    Spring.AssignMouseCursor("resize-x", "cursor-x", true, true)
    Spring.SetCustomCommandDrawData(CMD_RESIZE_X, "resize-x", {1,1,1,0.5}, false)
end

(don't have anything anymore in the unsynced widget, but it would be something like this)

Code: Select all

Spring.SetMouseCursor("resize-x")
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: mouse cursor icon

Post by FLOZi »

S44 generates custom command IDs on the fly as requested;

https://sourceforge.net/p/spring1944/co ... andler.lua
Post Reply

Return to “Lua Scripts”