teichgraf's picture

Prevent resize + Mouse-Leave event

Hello

Is it possible to prevent the resize of the GameWindow?
Something like gameWindow.IsResizable = false.

Does an event exists, witch is fired when the user leaves the GameWindow? Or does a mouse-move event exists?
I am asking, because I have the following case at the moment: When the user leaves the GameWindow and pressed the mouse button, no event like MouseButtonUp or LeaveWindow is fired. Outside the windowe he releases the button and after that re-enters the window -> the state of the mouse button is pressed.

Thanks in advance!


Comments

Comment viewing options

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

There's no way currently to prevent the window from resizing, but this feature is planned (along with mouse "grabbing").

From OpenTK 0.9.1 onwards, mouse (and keyboard) buttons will be automatically cleared when the window loses focus, to avoid issues with stuck keys.

I am currently testing the performance impact of mouse movement events - if it turns out to be reasonable, they will be enabled by default. Otherwise, you may have to maunally turn them on (something like Mouse.GenerateMoveEvents = true). This feature is unlikely to make it in 0.9.1, though.

teichgraf's picture

Thanks for the fast answer.

What I am doing now:

private MouseButton? mouseBtn;
 
void Mouse_ButtonUp(MouseDevice sender, MouseButton button)
{
   mouseBtn = null;
}
 
void Mouse_ButtonDown(MouseDevice sender, MouseButton button)
{
   mouseBtn = button;
}
 
public override void OnUpdateFrame(UpdateFrameEventArgs e)
{
   base.OnUpdateFrame(e);
   if (mouseBtn.HasValue)
   {
      if (mouseBtn == MouseButton.Left)
      {
          // Do something with Mouse.X and Mouse.Y
      }
   }
}

So, when you say...
From OpenTK 0.9.1 onwards, mouse (and keyboard) buttons will be automatically cleared when the window loses focus, to avoid issues with stuck keys.

... how will this be done in 0.9.1? Or does the Mouse instance will have a Mouse.Buttons property?

the Fiddler's picture

... how will this be done in 0.9.1? Or does the Mouse instance will have a Mouse.Buttons property?
Actually it does. Hm, maybe this isn't discoverable enough, but you can just do:

if (Mouse[MouseButton.Left])
{
    ...
}
teichgraf's picture

Sorry,
...
It is consequent to handle this like the Keyboard.

Thanks!

the Fiddler's picture

No problem. :)

Do you think a function like Mouse.IsButtonPressed(MouseButton b) would be more intuitive? The other solution is to have Left, Right, Middle, etc boolean properties - but this is going to be tedious to implement for Keyboard (too many keys!)

teichgraf's picture

I think it would be nice to have both Mouse.IsButtonPressed(MouseButton b) and Mouse[b]. The Intellisense would support Mouse. -> Mouse.IsButtonPressed(MouseButton b).

objarni's picture

What about this:

int mx = Mouse.X;
int my = Mouse.Y;
bool left = Mouse.ButtonLeft;
bool middle = Mouse.ButtonMiddle;

.. or maybe ..

bool left = Mouse.Button.Left;
bool right = Mouse.Button.Right;

It seems more consistent than having special methods for button-properties but not coordinate-properties of the mouse.

the Fiddler's picture

Any other people wishing to share their preference?

I won't cast my vote yet, to avoid affecting the results. :)