Created
June 3, 2017 18:32
-
-
Save eXpl0it3r/9fa3b0771f243f9e6cdcda7230523e3b to your computer and use it in GitHub Desktop.
SFML System Cursor Test Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SFML/Graphics.hpp> | |
int main() | |
{ | |
sf::RenderWindow window{{1024, 756}, "Hello World"}; | |
window.setVerticalSyncEnabled(true); | |
sf::Cursor cursor; | |
cursor.loadFromSystem(sf::Cursor::Arrow); | |
window.setMouseCursor(cursor); | |
sf::Image cursor_img1; | |
cursor_img1.loadFromFile("cursor1.png"); | |
sf::Image cursor_img2; | |
cursor_img2.loadFromFile("cursor2.png"); | |
while(window.isOpen()) | |
{ | |
sf::Event event; | |
while(window.pollEvent(event)) | |
{ | |
if(event.type == sf::Event::Closed) | |
window.close(); | |
else if(event.type == sf::Event::KeyPressed) | |
{ | |
if(event.key.code == sf::Keyboard::Num1) | |
cursor.loadFromSystem(sf::Cursor::Arrow); | |
else if(event.key.code == sf::Keyboard::Num2) | |
cursor.loadFromSystem(sf::Cursor::ArrowWait); | |
else if(event.key.code == sf::Keyboard::Num3) | |
cursor.loadFromSystem(sf::Cursor::Wait); | |
else if(event.key.code == sf::Keyboard::Num4) | |
cursor.loadFromSystem(sf::Cursor::Text); | |
else if(event.key.code == sf::Keyboard::Num5) | |
cursor.loadFromSystem(sf::Cursor::Hand); | |
else if(event.key.code == sf::Keyboard::Num6) | |
cursor.loadFromSystem(sf::Cursor::SizeHorizontal); | |
else if(event.key.code == sf::Keyboard::Num7) | |
cursor.loadFromSystem(sf::Cursor::SizeVertical); | |
else if(event.key.code == sf::Keyboard::Num8) | |
cursor.loadFromSystem(sf::Cursor::SizeTopLeftBottomRight); | |
else if(event.key.code == sf::Keyboard::Num9) | |
cursor.loadFromSystem(sf::Cursor::SizeBottomLeftTopRight); | |
else if(event.key.code == sf::Keyboard::Num0) | |
cursor.loadFromSystem(sf::Cursor::SizeAll); | |
else if(event.key.code == sf::Keyboard::Q) | |
cursor.loadFromSystem(sf::Cursor::Cross); | |
else if(event.key.code == sf::Keyboard::W) | |
cursor.loadFromSystem(sf::Cursor::Help); | |
else if(event.key.code == sf::Keyboard::E) | |
cursor.loadFromSystem(sf::Cursor::NotAllowed); | |
else if(event.key.code == sf::Keyboard::R) | |
cursor.loadFromPixels(cursor_img1.getPixelsPtr(), cursor_img1.getSize(), {20, 20}); | |
else if(event.key.code == sf::Keyboard::T) | |
cursor.loadFromPixels(cursor_img2.getPixelsPtr(), cursor_img2.getSize(), {75, 75}); | |
window.setMouseCursor(cursor); | |
} | |
} | |
window.clear(sf::Color(0x440544FF)); | |
window.display(); | |
} | |
} |
What OS are you using?
I'm on fedora 30.
I also found a post on the SFML forum of someone who seems to have the same issue.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I have a problem with cursor loaded from images, the image is not set properly.
Here is the image:
and here is the cursor:
Even a 10x10 black square image has display problems.
Here is my code:
Can you please send the source images ?
Do you know why I have this problem ?
Thanks,