private void SetGameCursor(OpenTK.MouseCursor cursor) { if (game.Cursor != cursor) { game.Cursor = cursor; } }
private void SetGameCursor(OpenTK.MouseCursor cursor) { if (game.Cursor != cursor) { CurrentCursor = cursor; game.UpdateCursor(); } }
public AGSInput(GameWindow game, AGS.API.Size virtualResolution, IGameState state, IAGSRoomTransitions roomTransitions, IGameWindowSize windowSize) { _windowSize = windowSize; this._roomTransitions = roomTransitions; this._virtualWidth = virtualResolution.Width; this._virtualHeight = virtualResolution.Height; this._state = state; this._keysDown = new AGSConcurrentHashSet<Key>(); this._game = game; this._originalOSCursor = _game.Cursor; MouseDown = new AGSEvent<AGS.API.MouseButtonEventArgs>(); MouseUp = new AGSEvent<AGS.API.MouseButtonEventArgs>(); MouseMove = new AGSEvent<MousePositionEventArgs>(); KeyDown = new AGSEvent<KeyboardEventArgs>(); KeyUp = new AGSEvent<KeyboardEventArgs>(); game.MouseDown += async (sender, e) => { if (isInputBlocked()) return; var button = convert(e.Button); if (button == AGS.API.MouseButton.Left) LeftMouseButtonDown = true; else if (button == AGS.API.MouseButton.Right) RightMouseButtonDown = true; await MouseDown.InvokeAsync(sender, new AGS.API.MouseButtonEventArgs(button, convertX(e.X), convertY(e.Y))); }; game.MouseUp += async (sender, e) => { if (isInputBlocked()) return; var button = convert(e.Button); if (button == AGS.API.MouseButton.Left) LeftMouseButtonDown = false; else if (button == AGS.API.MouseButton.Right) RightMouseButtonDown = false; await MouseUp.InvokeAsync(sender, new AGS.API.MouseButtonEventArgs(button, convertX(e.X), convertY(e.Y))); }; game.MouseMove += async (sender, e) => { if (isInputBlocked()) return; await MouseMove.InvokeAsync(sender, new MousePositionEventArgs(convertX(e.X), convertY(e.Y))); }; game.KeyDown += async (sender, e) => { Key key = convert(e.Key); _keysDown.Add(key); if (isInputBlocked()) return; await KeyDown.InvokeAsync(sender, new KeyboardEventArgs(key)); }; game.KeyUp += async (sender, e) => { Key key = convert(e.Key); _keysDown.Remove(key); if (isInputBlocked()) return; await KeyUp.InvokeAsync(sender, new KeyboardEventArgs(key)); }; }
/// <summary> /// Creates a <see cref="MouseCursor"/> based on the specified image /// </summary> /// <param name="cursorUri">The <see cref="Uri"/> of the image</param> /// <returns>A <see cref="MouseCursor"/></returns> public static MouseCursor FromUri(Uri cursorUri) { Stream bitmapStream; Bitmap bitmap; OpenTK.MouseCursor cursorObject; MouseCursor cursor; bitmapStream = Application.GetResourceStream(cursorUri); bitmap = new Bitmap(bitmapStream); var data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, 32, 32), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); cursorObject = new OpenTK.MouseCursor(0,0,32, 32, data.Scan0); bitmap.UnlockBits(data); cursor = new MouseCursor(cursorObject); return cursor; }
public MouseCursorSimple() : base(800, 600) { Keyboard.KeyDown += Keyboard_KeyDown; using (Bitmap 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); MyCursor = new OpenTK.MouseCursor( 2, 21, data.Width, data.Height, data.Scan0); Cursor = MyCursor; } Mouse.Move += Mouse_Move; Mouse.ButtonDown += Mouse_ButtonDown; }
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); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcColor); texture = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, texture); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, TextBitmap.Width, TextBitmap.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Nearest); }