Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Change Cursor to Image  (Read 2324 times)

0 Members and 1 Guest are viewing this topic.

littles

  • Newbie
  • *
  • Posts: 1
    • View Profile
Change Cursor to Image
« on: December 11, 2018, 03:38:34 pm »
I currently struggle a bit with changing the mouse cursor with the new Cursor API. I use an image which loads its content from a file. The image never gets out of scope, it is always loaded. So this is definitely not the problem.

[...]
mouse_cursor_1_image.loadFromFile("img/cursor_1.png");
[...]
mouse_cursor_1.loadFromPixels(
        mouse_cursor_1_image.getPixelsPtr(),
        Vector2u(mouse_cursor_1_image.getSize().x, mouse_cursor_1_image.getSize().x),
        Vector2u(0, 0)
);
[...]

This almost works as expected. The mouse cursor changed, the shape is correct, but the cursor itself is only transparent, black and white (not even grey).

I am using Linux and I think the problem is related to the warning on this site:
https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Cursor.php#ac24ecf82ac7d9ba6703389397f948b3a
"Warning
On Unix, the pixels are mapped into a monochrome bitmap: pixels with an alpha channel to 0 are transparent, black if the RGB channel are close to zero, and white otherwise."

The really weird thing is that even some black pixels aren't black anymore. Some black pixels became white.

Is there any workaround? Besides using a texture+sprite instead of the real system mouse cursor? Because this turned out to not be as fast as I want it to be. I found this tutorial from SFML:
https://github.com/SFML/SFML/wiki/Tutorial:-Change-Cursor
Would the last solution work for me with pictures which have colours?
« Last Edit: December 11, 2018, 03:54:44 pm by littles »

mikesinclair66

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Change Cursor to Image
« Reply #1 on: October 18, 2020, 08:44:24 pm »
Too bad no one answered this sooner. Your structure is correct, the only thing is your second argument to mouse_cursor_1.loadFromPixels() is a vector with the wrong y coordinate. The y coordinate should be mouse_cursor_1_image.getSize().y.

 

anything