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

Add support for custom mouse cursor images #798

Open
MoritzBrueckner opened this issue May 16, 2023 · 0 comments
Open

Add support for custom mouse cursor images #798

MoritzBrueckner opened this issue May 16, 2023 · 0 comments

Comments

@MoritzBrueckner
Copy link

Is your feature request related to a problem? Please describe.
Kinc already allows to change the mouse cursor to common system cursors, but currently there is no way to set a custom cursor image. Kha's cursor API allows something a la mouse.setSystemCursor(MouseCursor.Custom(myCustomImage)), but because it's not implemented in Kinc this currently only takes effect on html5 (and maybe on some less commonly used targets as well) as far as I can see. However, it should be possible to implement a similar functionality also for the Kinc backends.

Describe the solution you'd like
Some functionality to set a custom cursor image, similar to Kha's API. Two ideas how this could look like:

  • Two separate functions:
    // This function already exists, no change in functionality here
    KINC_FUNC void kinc_mouse_set_cursor(int cursor);
    
    // Calling this function will overwrite the cursor image with a custom image,
    // calling kinc_mouse_set_cursor() would go back to a non-custom cursor image.
    KINC_FUNC void kinc_mouse_set_cursor_custom(kinc_image_t *image); 
  • A unified function that behaves differently based on the first parameter (this would be a breaking change):
    // If cursor == -1 (or a special define for -1 like KINC_CUSTOM_CURSOR), use the custom image, else ignore it.
    // E.g.
    //    kinc_mouse_set_cursor(1, NULL);
    //    kinc_mouse_set_cursor(KINC_CUSTOM_CURSOR, myImage);
    KINC_FUNC void kinc_mouse_set_cursor(int cursor, kinc_image_t *image);

Additional context

  • Kinc images have different formats and might be compressed, so the image data first needs to be converted to some representation that's understood by the individual system API's which probably complicates the implementation of this feature request a bit.
  • In the win32 API, I think the more common way of implementing this would not to be using loaded images, but instead resources embedded in the executable or some dll. However, this would likely require a completely different approach to the API, so I guess using Kinc images is the better approach. Luckily, using raw buffers seems to be perfectly possible, but I think they first need to be converted to bitmap objects.
  • At least on Windows you can specify custom cursor hot spot coordinates (that's the point in the cursor image that's aligned with the actual cursor position), integrating this into the Kinc API and eventually also to the Kha API would be a nice to have :)
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

No branches or pull requests

1 participant