mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-08 22:00:46 +00:00
[Examples] Improved MouseCursor example
This commit is contained in:
parent
9ee728d4fc
commit
9bd94c1f13
Binary file not shown.
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 925 B |
|
@ -3,6 +3,7 @@
|
||||||
// It is provided "as is" without express or implied warranty of any kind.
|
// It is provided "as is" without express or implied warranty of any kind.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics.OpenGL;
|
using OpenTK.Graphics.OpenGL;
|
||||||
|
@ -17,6 +18,7 @@ namespace Examples.Tutorial
|
||||||
public class MouseCursorSimple : GameWindow
|
public class MouseCursorSimple : GameWindow
|
||||||
{
|
{
|
||||||
readonly MouseCursor MyCursor;
|
readonly MouseCursor MyCursor;
|
||||||
|
List<Vector2> lines = new List<Vector2>();
|
||||||
|
|
||||||
public MouseCursorSimple()
|
public MouseCursorSimple()
|
||||||
: base(800, 600)
|
: base(800, 600)
|
||||||
|
@ -26,7 +28,7 @@ namespace Examples.Tutorial
|
||||||
using (Bitmap bitmap = new Bitmap("Data/Textures/cursor.png"))
|
using (Bitmap bitmap = new Bitmap("Data/Textures/cursor.png"))
|
||||||
{
|
{
|
||||||
var data = bitmap.LockBits(
|
var data = bitmap.LockBits(
|
||||||
new Rectangle(0, 0, bitmap.Width, bitmap.Height),
|
new Rectangle(2, 21, bitmap.Width, bitmap.Height),
|
||||||
System.Drawing.Imaging.ImageLockMode.ReadOnly,
|
System.Drawing.Imaging.ImageLockMode.ReadOnly,
|
||||||
System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
|
System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
|
||||||
|
|
||||||
|
@ -34,8 +36,49 @@ namespace Examples.Tutorial
|
||||||
0, 0, data.Width, data.Height, data.Scan0);
|
0, 0, data.Width, data.Height, data.Scan0);
|
||||||
Cursor = MyCursor;
|
Cursor = MyCursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mouse.Move += Mouse_Move;
|
||||||
|
Mouse.ButtonDown += Mouse_ButtonDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddLine(float x, float y)
|
||||||
|
{
|
||||||
|
// Scale mouse coordinates from
|
||||||
|
// (0, 0):(Width, Height) to
|
||||||
|
// (-1, -1):(+1, +1)
|
||||||
|
// Note, we must flip the y-coordinate
|
||||||
|
// since mouse is reported with (0, 0)
|
||||||
|
// at top-left and our projection uses
|
||||||
|
// (-1, -1) at bottom left.
|
||||||
|
x = (x- Width) / (float)Width;
|
||||||
|
y = (Height - y) / (float)Height;
|
||||||
|
lines.Add(new Vector2(2 * x + 1, 2 * y - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Mouse_ButtonDown
|
||||||
|
|
||||||
|
void Mouse_ButtonDown(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Button == MouseButton.Left)
|
||||||
|
{
|
||||||
|
AddLine(e.X, e.Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Mouse_Move
|
||||||
|
|
||||||
|
void Mouse_Move(object sender, MouseMoveEventArgs e)
|
||||||
|
{
|
||||||
|
if (Mouse[MouseButton.Left])
|
||||||
|
{
|
||||||
|
AddLine(e.X, i.Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Keyboard_KeyDown
|
#region Keyboard_KeyDown
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -144,6 +187,14 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
GL.End();
|
GL.End();
|
||||||
|
|
||||||
|
GL.Begin(PrimitiveType.LineStrip);
|
||||||
|
foreach (var p in lines)
|
||||||
|
{
|
||||||
|
GL.Color4(Color.White);
|
||||||
|
GL.Vertex2(p);
|
||||||
|
}
|
||||||
|
GL.End();
|
||||||
|
|
||||||
this.SwapBuffers();
|
this.SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue