Can't change cursor bitmap
by Amjad Yahya · in Torque 2D Beginner · 06/21/2013 (6:29 am) · 25 replies
I'm trying to change the cursor bitmap with no luck.
in main.cs which resides in myGame/modules/Game folder I wrote the following code:
cursor image file resides here: myGame/modules/Game/assets/images
Am I missing something?
in main.cs which resides in myGame/modules/Game folder I wrote the following code:
new GuiCursor(DefaultCursor)
{
hotSpot = "1 1";
renderOffset = "0 0";
bitmapName = "./assets/images/defaultCursor.png";
};
canvas.setCursor(DefaultCursor);cursor image file resides here: myGame/modules/Game/assets/images
Am I missing something?
About the author
#2
06/21/2013 (8:28 am)
Thanks, but that did not work either, strange, right? And the funny thing that the engine is not giving me any errors.
#3
One alternative is creating a joint similar to the 'Pull' Manipulation present in the Sandbox, making a sprite follow the cursor.
Not ideal, but it's one way to do it.
06/21/2013 (10:16 am)
I did tests on that earlier as well, no matter if you change the bitmap, call Canvas.setcursor, the cursor doesn't change.One alternative is creating a joint similar to the 'Pull' Manipulation present in the Sandbox, making a sprite follow the cursor.
Not ideal, but it's one way to do it.
#4
06/21/2013 (10:23 am)
Somebody file an issue! This dang bug has come and gone so many times. It's getting tiresome.
#5
Are you guys on Windows OS as well?
06/21/2013 (10:26 am)
Good point, Richard! It's been around forever.Are you guys on Windows OS as well?
#7
Click "New Issue".
Feel free to flag any error you find as an official issue!
06/21/2013 (10:42 am)
https://github.com/GarageGames/Torque2D/issues?state=openClick "New Issue".
Feel free to flag any error you find as an official issue!
#8
06/21/2013 (10:43 am)
Make sure to mention that it's only been confirmed on Windows OS, too! :)
#9
First, define your new Cursor in your custom guiprofiles.cs (or wherever)
Then, you must call Canvas.showCursor();, which displays your new cursor correctly BUT it still displays the platform cursor above it! Which makes very little sense.
More on this as it develops. :)
06/21/2013 (12:58 pm)
I've been playing around with this and figured out part of the problem.First, define your new Cursor in your custom guiprofiles.cs (or wherever)
new GuiCursor(NewCursor)
{
hotSpot = "12 8";
renderOffset = "0 0";
bitmapName = "^SCM/gui/images/NewCursor";
};Then, you must call Canvas.showCursor();, which displays your new cursor correctly BUT it still displays the platform cursor above it! Which makes very little sense.
Canvas.showCursor(); Canvas.setCursor(NewCursor);
More on this as it develops. :)
#10
06/21/2013 (2:26 pm)
There is a UseHardwareCursor (or something similar) flag that is set somewhere.... Ask Mich!
#11
@Amjad : this is very simple, inserting only 1 line of code into the C++ solution. It disables rendering of the hardware cursor and shows only the custom cursor
In the file /engine/source/gui/GuiCanvas.cc
In the function GuiCanvas::renderFrame at line 1604, add the following line
That's it! Compile the solution, copy your new .exe to your project and you're good to go!
Just to make sure you insert the line at the right place, your code should now look like the following
It is far from an elegant solution, thus I won't push it back into the official repo.
06/21/2013 (3:33 pm)
@Richard: Can't find that flag anywhere in the source, however, I found a solution!@Amjad : this is very simple, inserting only 1 line of code into the C++ solution. It disables rendering of the hardware cursor and shows only the custom cursor
In the file /engine/source/gui/GuiCanvas.cc
In the function GuiCanvas::renderFrame at line 1604, add the following line
Input::setCursorState(false);
That's it! Compile the solution, copy your new .exe to your project and you're good to go!
Just to make sure you insert the line at the right place, your code should now look like the following
... lastCursorON = cursorVisible; lastCursor = mouseCursor; lastCursorPt = cursorPos; Input::setCursorState(false); RectI updateUnion; ...
It is far from an elegant solution, thus I won't push it back into the official repo.
#12
06/21/2013 (4:08 pm)
Well, perhaps add that flag as a system global. Then you can use it in setCursorState(). I'm betting it was T3D where I saw that....
#13
06/22/2013 (4:58 am)
@Simon: thanks, it's working now and I have filed an issue about this.
#14
github.com/capnlove/Torque2D/commit/76a007981f0739b129722edd8ca179dbc7e652cb
Basicaly, set $pref::T2D::showNativeCursor to true and the Windows cursor displays alongside with your custom cursor, set it to false and the platform cursor disappears.
If anyone wants to test if the custom gui cursor issues also occur on other platforms, maybe we could get to a solution that might make it into the official repo.
08/14/2013 (1:44 am)
I know it's been a while but i've taken another look at this, while I haven't found a way that's performance-friendly, here's a more controllable way to show the custom cursor.github.com/capnlove/Torque2D/commit/76a007981f0739b129722edd8ca179dbc7e652cb
Basicaly, set $pref::T2D::showNativeCursor to true and the Windows cursor displays alongside with your custom cursor, set it to false and the platform cursor disappears.
If anyone wants to test if the custom gui cursor issues also occur on other platforms, maybe we could get to a solution that might make it into the official repo.
#15
I tried it also on OSX, the platform cursor does not hide when setting "$pref::T2D::showNativeCursor" to false, and the custom cursor does not move along side the platform cursor, I'm not sure why this is happening, maybe someone else with an access to Mac OS could confirm it.
08/14/2013 (4:34 am)
@Simon: It worked perfectly on Windows.I tried it also on OSX, the platform cursor does not hide when setting "$pref::T2D::showNativeCursor" to false, and the custom cursor does not move along side the platform cursor, I'm not sure why this is happening, maybe someone else with an access to Mac OS could confirm it.
#16
something along the line of:
if(Msg == WM_SETCURSOR)
{
if(LOWORD(lParam) == HTCLIENT && some_flag_telling_us_to_nuke_the_cursor)
{
SetCursor(NULL);
return TRUE;
}
return FALSE;
}
SetCursor() also only work from the main ui thread, but the message pump should already be running from there. This will also insure that the cursor will show over the windows border and bar in windowed mode.
08/14/2013 (9:57 am)
In winInput.cc at line 542 there is a call to ShowCursor(), this winapi function is tricky to use correctly, first it will not work in windowed mode properly and secondly it will only work if called from the window main thread, the proper way to do this and insure the request to be respected is to catch WM_SETCURSOR in the message pump and to manually nuke the cursor with SetCursor(NULL);something along the line of:
if(Msg == WM_SETCURSOR)
{
if(LOWORD(lParam) == HTCLIENT && some_flag_telling_us_to_nuke_the_cursor)
{
SetCursor(NULL);
return TRUE;
}
return FALSE;
}
SetCursor() also only work from the main ui thread, but the message pump should already be running from there. This will also insure that the cursor will show over the windows border and bar in windowed mode.
#17
@Amjad : I've managed to fix it elegantly for Windows platforms, not sure about Mac builds though. Instead of hijacking critical stuff, it simply skips the rendering part of the mouse cursor if needed.
This removes all the previous nonsense.
Check out the necessary changes here.
You simply need to call Canvas.setcursor(%MyguiCursor);, nothing else (no need for Canvas.showcursor or anything like that).
This makes the Windows cursor disappear except that it does reappear over the windows border (for resizing) or over the minimize/maximize/close buttons.
When you want to use the Windows cursor again, simply call Canvas.resetCursor();
You can switch between modes at will, it works fine with Canvas.setCursorOn(); Canvas.setCursorOff(); as well.
Note : It still uses $pref::T2D::showNativeCursor for the moment but you don't have to manually set it. I'm thinking that this should simply be a Canvas-level variable instead of a more costly Console variable.
But it works exactly as I would like, so I'm a happy man.
08/14/2013 (7:36 pm)
@Jon : Dude, you know your stuff. Thanks for lighting the way.@Amjad : I've managed to fix it elegantly for Windows platforms, not sure about Mac builds though. Instead of hijacking critical stuff, it simply skips the rendering part of the mouse cursor if needed.
This removes all the previous nonsense.
Check out the necessary changes here.
You simply need to call Canvas.setcursor(%MyguiCursor);, nothing else (no need for Canvas.showcursor or anything like that).
This makes the Windows cursor disappear except that it does reappear over the windows border (for resizing) or over the minimize/maximize/close buttons.
When you want to use the Windows cursor again, simply call Canvas.resetCursor();
You can switch between modes at will, it works fine with Canvas.setCursorOn(); Canvas.setCursorOff(); as well.
Note : It still uses $pref::T2D::showNativeCursor for the moment but you don't have to manually set it. I'm thinking that this should simply be a Canvas-level variable instead of a more costly Console variable.
But it works exactly as I would like, so I'm a happy man.
#18
08/14/2013 (10:12 pm)
Addendum : Set $pref::T2D::showNativeCursor to 'true' at the start of your project if you're not using a custom cursor.
#19
08/15/2013 (2:43 am)
@Simon: thanks, it worked on Windows. I will test it on OSX and let you know.
#20
The variable used (UseNativeCursor) is a protected Canvas variable, no need for users to even know about it, i.e. it's not exposed to the console.
As before, just call Canvas.setcursor(%MyguiCursor); and Canvas.resetCursor();.
Changes listed here
There ya go! No more changes from me I promise!
08/15/2013 (9:30 am)
Ok, I've just replaced using $pref::T2D::showNativeCursor.The variable used (UseNativeCursor) is a protected Canvas variable, no need for users to even know about it, i.e. it's not exposed to the console.
As before, just call Canvas.setcursor(%MyguiCursor); and Canvas.resetCursor();.
Changes listed here
There ya go! No more changes from me I promise!
Torque Owner Richard Ranft
Roostertail Games
That should let the engine find the correct expando.