Skip to content

Commit

Permalink
[Examples] Test MouseCursor in GameWindowStates
Browse files Browse the repository at this point in the history
  • Loading branch information
thefiddler committed May 6, 2014
1 parent b1f6278 commit 7e86d34
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions Source/Examples/OpenTK/Test/GameWindowStates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class GameWindowStates : GameWindow
bool mouse_in_window = false;
bool viewport_changed = true;

MouseCursor Pencil;

// legacy GameWindow.Mouse.* events
Vector4 mousedevice_pos;
int mousedevice_buttons;
Expand Down Expand Up @@ -136,6 +138,10 @@ void KeyDownHandler(object sender, KeyboardKeyEventArgs e)
case Key.BracketRight: TargetUpdateFrequency++; break;
case Key.Comma: TargetRenderFrequency--; break;
case Key.Period: TargetRenderFrequency++; break;

case Key.Space:
CursorVisible = !CursorVisible;
break;
}

if (!keyboard_keys.ContainsKey(e.Key))
Expand Down Expand Up @@ -187,18 +193,15 @@ void MouseDeviceMoveHandler(object sender, MouseMoveEventArgs e)

void MouseDeviceButtonHandler(object sender, MouseButtonEventArgs e)
{
if (e.Button == MouseButton.Left && e.IsPressed)
{
CursorVisible = false;
}

if (e.IsPressed)
{
mousedevice_buttons |= 1 << (int)e.Button;
Cursor = Pencil;
}
else
{
mousedevice_buttons &= ~(1 << (int)e.Button);
Cursor = MouseCursor.Default;
}
mousedevice_state = e.Mouse;
}
Expand All @@ -225,11 +228,6 @@ void MouseMoveHandler(object sender, MouseMoveEventArgs e)

void MouseButtonHandler(object sender, MouseButtonEventArgs e)
{
if (e.Button == MouseButton.Left && e.IsPressed)
{
CursorVisible = false;
}

if (e.IsPressed)
{
mouse_buttons |= 1 << (int)e.Button;
Expand Down Expand Up @@ -588,6 +586,17 @@ protected override void OnLoad(EventArgs e)
{
watch.Start();

using (var bitmap = new Bitmap("Data/Textures/cursor.png"))
{
var data = bitmap.LockBits(
new Rectangle(0, 0, bitmap.Width, bitmap.Height),
System.Drawing.Imaging.ImageLockMode.ReadOnly,
System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

Pencil = new OpenTK.MouseCursor(
2, 21, data.Width, data.Height, data.Scan0);
}

GL.ClearColor(Color.MidnightBlue);

GL.Enable(EnableCap.Texture2D);
Expand Down

0 comments on commit 7e86d34

Please sign in to comment.