armory3d/armory

Support for SetCustomCursor in Krom

PHandradee opened this issue · 2 comments

Krom dont supports change the cursor via kha.input.Mouse.setSystemCursor().

It was nice to have this possibility.

`package arm;

import kha.Image;

class MouseCursorHandler extends iron.Trait {

var current_mouse = kha.input.Mouse.get();
var custom_mouse_image: Image;

public function new() {
	super();

	notifyOnInit(OnInit);

}

function OnInit() {
	iron.data.Data.getImage("DefaultCursor.png", (image: Image) -> {
		custom_mouse_image = image;

		current_mouse.setSystemCursor(kha.input.Mouse.MouseCursor.Custom(custom_mouse_image));

	});
}

}
`
With this code above the mouse cursor is changed when exporting to Web, but in Krom this don't work.

Hi. I had the same question and @ MoritzBrueckner gave me a working solution, although it requires some manual source tweaking.

RPaladin — Kha related, but people who use Kha claim that this code works fine in Kha but it doesn't for me in Armory - it also doesn't throw any errors for me so they may be well right. Why doesn't this code work in Armory it seems?
kha.input.Mouse.get().setSystemCursor(Crosshair);

Reference: https://github.com/Kode/Kha/blob/main/Sources/kha/input/Mouse.hx#L12-L28

timodriaan — Do you use Krom? The code looks correct to me, will try to reproduce it now (or do you already have a small example file)?
RPaladin —
  1. I'm using Krom Player (Armory).

  2. Using a default blend with no cache.

The cursor stays the same "Default" icon/image.

timodriaan — Also doesn't work for me, will investigate. It definitely worked before (~ 1 1/2 years ago when I worked on my game jam game), but Armory's Krom.hx needed to be modified back then, perhaps it's a similar issue...

Even sillier, it's not implemented in Kha's Krom backend

timodriaan — It's only implemented in Armorcore, which is too bad because any change made to Kha would be overwritten when Lubos updates Kha. It's the same problem as always 😄

I will write it in the Kha discord server, for now you need to add static function setMouseCursor(id: Int): Void; to <sdk>/Kha/Backends/Krom/Krom.hx and then call Krom.setMouseCursor(cursorValue) in your Haxe code #if kha_krom where cursorValue is an integer representing the cursor you want (Kha's implementation uses an enum so you can't just use the enum values). It's really messy 😄

Discord message ID, if you're interested: https://discord.com/channels/486771218599510021/486773417316450305/1053045903293939722

@MoritzBrueckner in reference to asking Rob, were you able to get something implemented for Kha?

@MoritzBrueckner in reference to asking Rob, were you able to get something implemented for Kha?

I sadly don't remember this anymore (I don't even remember anymore whether I even asked), but there are essentially two issues here:

  1. Kha supports changing the mouse cursor and Armory's version of Krom does as well, but these functionalities currently aren't implemented in the Krom backend of Kha (that's what my Discord message above was about). However, I think the Kode/Krom version doesn't allow to change the mouse cursor at the moment, so this needs to be implemented first before we can implement it in Kha (otherwise Rob wouldn't merge it and we can't PR to Armory's version of Kha, as explained above).
  2. Kinc doesn't support custom cursor images (contrary to a predefined set of system cursor images), but there is a Kha API for it. This is what is done in the code example above. I opened a feature request on the Kinc repository for it: Kode/Kinc#798.