From 0dd82e14857132426d333dd2f4da3f4105312b76 Mon Sep 17 00:00:00 2001 From: Fraser Date: Fri, 21 Feb 2014 00:23:20 +0000 Subject: [PATCH] MouseCursor example. Small example to show how the MouseCursor class can be used. --- Source/Examples/Data/Textures/cursor.png | Bin 0 -> 3357 bytes Source/Examples/OpenTK.Examples.csproj | 3 + .../OpenTK/GameWindow/MouseCursorSimple.cs | 155 ++++++++++++++++++ .../OpenTK/GameWindow/MouseCursorSimple.rtf | Bin 0 -> 991 bytes 4 files changed, 158 insertions(+) create mode 100644 Source/Examples/Data/Textures/cursor.png create mode 100644 Source/Examples/OpenTK/GameWindow/MouseCursorSimple.cs create mode 100644 Source/Examples/OpenTK/GameWindow/MouseCursorSimple.rtf diff --git a/Source/Examples/Data/Textures/cursor.png b/Source/Examples/Data/Textures/cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..d0dc4a48f35d125aacd25d2f087e4537687dbe0d GIT binary patch literal 3357 zcmV+&4dU{NP)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*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Ox+E7LiCode + Code @@ -551,6 +552,7 @@ + @@ -635,6 +637,7 @@ Dependencies\x86\SDL2.dll + diff --git a/Source/Examples/OpenTK/GameWindow/MouseCursorSimple.cs b/Source/Examples/OpenTK/GameWindow/MouseCursorSimple.cs new file mode 100644 index 00000000..24d8eea3 --- /dev/null +++ b/Source/Examples/OpenTK/GameWindow/MouseCursorSimple.cs @@ -0,0 +1,155 @@ +// This code was written for the OpenTK library and has been released +// to the Public Domain. +// It is provided "as is" without express or implied warranty of any kind. + +using System; +using System.Drawing; +using OpenTK; +using OpenTK.Graphics.OpenGL; +using OpenTK.Input; + +namespace Examples.Tutorial +{ + /// + /// Demonstrates the MouseCursor class. + /// + [Example("MouseCursor Simple", ExampleCategory.OpenTK, "GameWindow", 1, Documentation = "MouseCursorSimple")] + public class MouseCursorSimple : GameWindow + { + public MouseCursorSimple() + : base(800, 600) + { + Keyboard.KeyDown += Keyboard_KeyDown; + + Bitmap bitmap = new Bitmap("D:/VisualStudio/Projects/opentk/Source/Examples/Data/Textures/cursor.png"); + + var rgba = new byte[bitmap.Width * bitmap.Height * 4]; + var data = bitmap.LockBits( + new Rectangle(0, 0, bitmap.Width, bitmap.Height), + System.Drawing.Imaging.ImageLockMode.ReadOnly, + System.Drawing.Imaging.PixelFormat.Format32bppArgb); + + for (int y = 0; y < bitmap.Height; ++y) + { + var offset = new IntPtr(data.Scan0.ToInt64() + (data.Stride * y)); + System.Runtime.InteropServices.Marshal.Copy( + offset, rgba, y * 4, bitmap.Width * 4); + } + + var cursor = new OpenTK.MouseCursor(rgba, bitmap.Width, bitmap.Height, 0, 0); + + this.Cursor = cursor; + } + + #region Keyboard_KeyDown + + /// + /// Occurs when a key is pressed. + /// + /// The KeyboardDevice which generated this event. + /// The key that was pressed. + void Keyboard_KeyDown(object sender, KeyboardKeyEventArgs e) + { + if (e.Key == Key.Escape) + this.Exit(); + + if (e.Key == Key.F11) + if (this.WindowState == WindowState.Fullscreen) + this.WindowState = WindowState.Normal; + else + this.WindowState = WindowState.Fullscreen; + } + + #endregion + + #region OnLoad + + /// + /// Setup OpenGL and load resources here. + /// + /// Not used. + protected override void OnLoad(EventArgs e) + { + GL.ClearColor(Color.MidnightBlue); + } + + #endregion + + #region OnResize + + /// + /// Respond to resize events here. + /// + /// Contains information on the new GameWindow size. + /// There is no need to call the base implementation. + protected override void OnResize(EventArgs e) + { + GL.Viewport(0, 0, Width, Height); + + GL.MatrixMode(MatrixMode.Projection); + GL.LoadIdentity(); + GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0); + } + + #endregion + + #region OnUpdateFrame + + /// + /// Add your game logic here. + /// + /// Contains timing information. + /// There is no need to call the base implementation. + protected override void OnUpdateFrame(FrameEventArgs e) + { + // Nothing to do! + } + + #endregion + + #region OnRenderFrame + + /// + /// Add your game rendering code here. + /// + /// Contains timing information. + /// There is no need to call the base implementation. + protected override void OnRenderFrame(FrameEventArgs e) + { + GL.Clear(ClearBufferMask.ColorBufferBit); + + GL.Begin(PrimitiveType.Triangles); + + GL.Color3(Color.MidnightBlue); + GL.Vertex2(-1.0f, 1.0f); + GL.Color3(Color.SpringGreen); + GL.Vertex2(0.0f, -1.0f); + GL.Color3(Color.Ivory); + GL.Vertex2(1.0f, 1.0f); + + GL.End(); + + this.SwapBuffers(); + } + + #endregion + + #region public static void Main() + + /// + /// Entry point of this example. + /// + [STAThread] + public static void Main() + { + using (MouseCursorSimple example = new MouseCursorSimple()) + { + // Get the title and category of this example using reflection. + Utilities.SetWindowTitle(example); + example.Run(30.0, 0.0); + } + } + + #endregion + } +} diff --git a/Source/Examples/OpenTK/GameWindow/MouseCursorSimple.rtf b/Source/Examples/OpenTK/GameWindow/MouseCursorSimple.rtf new file mode 100644 index 0000000000000000000000000000000000000000..18c0bdb6131382aa0341b3ba0170e4102a2c5ae5 GIT binary patch literal 991 zcmZuwTWi}e6y9@w#d$6zSWa6u^0bAu1eP&M$6oXzTStzlEP0X~w+sI7JCc*eg@UoJ z-_duGj@(DZxUfNUiAohmuAGgrGSn%!3WE-TtIq!|xvKZV2aN2F9r+bkR~X04J%e9uO{8)XV}{4o$TwVo#jlwC*E%&DcUTA#0FBjp~$^6;WRmux^o8va@J$e|0W$nW&wkadw8YD zpiNrdpOB6CMW6upj3pPMYZ`K@!Z=Wbpn78hDWq;vGu1>%wIqhA)&&0^>IBCZ9hYaP zl7kb~xrl9wqD31;4s2SQNjal4w^@3WVqaz3$?S{GnHQ<|UK1tIF~AQeDY=6 X(&^;XDe5WRI=$7)<&^oXaq;OtDg0gB literal 0 HcmV?d00001