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

Author Topic: Change hardware cursor?  (Read 4568 times)

0 Members and 1 Guest are viewing this topic.

smguyk

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
Change hardware cursor?
« on: July 19, 2015, 10:16:40 am »
I want to have a custom mouse cursor in my game, and instead of hiding the cursor and drawing a sprite at its position I want to change the hardware cursor.

Something like this: https://love2d.org/wiki/Cursor

Is that possible?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Change hardware cursor?
« Reply #1 on: July 19, 2015, 10:20:49 am »
Not (yet) with SFML directly.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

smguyk

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
Re: Change hardware cursor?
« Reply #2 on: July 19, 2015, 10:25:07 am »
Okay, thanks!

GalakTozawr

  • Newbie
  • *
  • Posts: 17
  • You must create more game that oneself.
    • View Profile
    • My SFML lesson for russian language
    • Email
Re: Change hardware cursor?
« Reply #3 on: July 19, 2015, 10:55:50 am »
You must using winapi and unsubscribe from standart cursor. Next step create sprite end draw his on coordinate mouse.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Change hardware cursor?
« Reply #4 on: July 19, 2015, 12:50:33 pm »
You must using winapi and unsubscribe from standart cursor. Next step create sprite end draw his on coordinate mouse.
That's essentially a "software cursor". And you don't have to use the WinAPI with that, because SFML can just hide the cursor.

Forceofaqua

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Change hardware cursor?
« Reply #5 on: July 24, 2015, 12:22:08 am »
You can do what I did and implement a sprite as the cursor.

call
<window name>.setMouseCursorVisible(false);
to turn off cursor while inside the window.

Then within your window make a sprite with the cursor texture you would like.

Now all you have to do is set the sprite origin to the cursors location
sf::vector2i mouse = sf::Mouse::getPosition(<window name>);
<cursor sprite>.setOrigin(mouse.x, mouse.y);

For me personally I had to change the coordinates to negatives before I saw the cursor flying around my window. I'm not that knowledgeable in SFML so I don't know if that's how its supposed to be.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Change hardware cursor?
« Reply #6 on: July 24, 2015, 01:00:30 am »
You are (again) describing a software cursor. OP asked about changing the hardware cursor.
« Last Edit: July 24, 2015, 10:09:58 am by Jesper Juhl »

Mörkö

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: Change hardware cursor?
« Reply #7 on: July 24, 2015, 06:05:54 am »
I want this as well, because even at its most basic there is a noticeable delay in a software rendered cursor, see attached video.

#include <SFML/Graphics.hpp>
int main() {
    sf::RenderWindow win{sf::VideoMode{1600, 900}, "Cursor test"};
    while (win.isOpen()) {
        sf::Event e;
        while (win.pollEvent(e))
            if (e.type == sf::Event::KeyPressed) { win.close(); }
        sf::RectangleShape rect{sf::Vector2f{50, 50}};
        rect.setPosition(sf::Vector2f{sf::Mouse::getPosition(win)});
        win.clear();
        win.draw(rect);
        win.display();
    }
}

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Change hardware cursor?
« Reply #8 on: July 24, 2015, 05:48:50 pm »
even at its most basic there is a noticeable delay in a software rendered cursor
It's only noticable because you can see the hardware cursor. The actual location of the software cursor is in fact the location that you are using in any mouse position calculations.

That said, you'll need OS-specific code to change the hardware cursor, although it shouldn't be too complicated.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*