teichgraf's picture

Mouse cursor API

I am asking me right now, if point 7 for version 0.9.2
7. [0%] Mouse pointer grabbing/hiding.
also prevents the changing of the mouse icon, when you move from the border of the window to the center.
At the moment the mouse icon will be a double arrow after it was moved from the border or the window was resized:
Mouse Pointer

[Editor comment: Discussion moved from the Roadmap]


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Yes, the pointer will be fixed in 0.9.2. As always, if you happen to know the winapi calls that achieve this, you are welcome to submit a patch. :)

teichgraf's picture

I think there is no WinAPI call needed at all.
I just tried the following:

public override void OnUpdateFrame(UpdateFrameEventArgs e)
   // Set default mouse cursor
   System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
   // ...

And it seems to work.

It would be nicer to have events like EnterWindow, LeaveWindow. And set the above property just in EnterWindow and not everytime in UpdateFrame.

It would be even better, do have a user drawn OGL mouse pointer. GameWindow would have has a property
Bitmap Cursor, which will be used as a texture for a quad, representing the mouse cursor. And in each base.OnRender the mouse pointer is drawn.
Maybe I'll give it a try. What do you think?

the Fiddler's picture
   // Set default mouse cursor
   System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;

On one hand, this will tie us to Windows.Forms. On the other hand, this is supported everywhere (including the compact framework and Mono X11/OSX), so we might as well reuse existing code. I'll hack it internally for 0.9.1, to fix the ugly cursor, and see how to provide an API for this in 0.9.2.

Regarding OpenTK drawing the cursor, that's a no no :) The less OpenTK uses OpenGL, the better (what happens once GL3 is out? Do we rewrite everything?) The only part in OpenTK that actually calls OpenGL are Fonts, and even these have been moved outside the core library in 0.9.1.

In any case, it's trivial for the user to provide this functionality: just hide the cursor (through the API that will be provided in the future), and draw a quad on the correct position.

teichgraf's picture

You are right. I reconsidered my previous idea and I also thought that it is not the best idea. You have to set a projection matrix, Gl.Pop... and so on.

By the way, it is very easy to set a custom cursor using .Net:

System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap("cursor.png");
System.Windows.Forms.Cursor myCursor = new System.Windows.Forms.Cursor(bitmap.GetHicon());
System.Windows.Forms.Cursor.Current = myCursor;
// Don't forget to dispose later

Even alpha channel is supported.

the Fiddler's picture

This is quite cool. I'm currently trying to confirm what I said earlier (that the Cursor is available on all platforms). If it is, then this is awesome.