I am developing a WPF application, where I need to allow user to rearrange objects by drag-drop. It is basically dragging objects within a canvas area and moving them to another area of the canvas. The mouse cursor would change to a drag cursor while dragging is happening.
The requirement is like the mouse pointer cannot leave the canvas area while the dragging is in progress. For that I am using the Win32 ClipCursor api to restrict the cursor to a certain boundary of the screen.
This is working fine when mouse is used. However, if touch is used, i.e. if the pointer is moved through touch, it is possible to take the cursor out of the bounding rectangle. Can anyone please help to understand why it is happening? I am handling the PreviewMouseMove and MouseLeftButtonUp events for starting and ending the drag. Do I need to handle the Touch and the Stylus events as well?
Thanks!
Related
Overview: I am making a 2D Tower Defense game with using Tilemaps as the environment and sprites as the towers and enemies. The mouse needs
Problem: I want to trigger different events/methods depending on which tile or sprite the mouse is hovering or clicking on.
Example - Hovering over buildable tiles shows a highlighted tile, but the highlight disappears when the mouse is over a "dead" un-buildable tile.
After 10+ hours of research, I think I need to use Raycasts, 2D Colliders, and Layers to detect when the mouse hovers over or clicks on a tile/object, but I don't know how to trigger different events/methods depending on which specific layer or tag the mouse is interacting with.
Question: How do I detect and access a tile or gameobject with a mouse hover/click? and is there a way to trigger different methods depending on tags/layers I assign to the things I want to detect on hover/click?
First of all you don't need raycasts or colliders to detect mouse events. There are many ways to do this, but you can create eventListener for use on multiple objects. Also as a simple solution you can consider using scripts(includes UnityEventListeners) attached to the objects you want to control.
I have a C# control that has an scroll.
When a user drag and drop, the scrolls are updated. I would like to animate the drag&drop movement like google maps does. The movement is smoothly animated.
What technique must I use if want to simulate a swipe in the control, and perform a smoothly animated?
What I was looking for was the easing equations: http://www.gizma.com/easing
I'm working on a miniature golf game in XNA, I originally had everything in Game.cs (main), but I now want it to be more object-oriented, so I made separate class for most of my stuff.
When I had everything in Game.cs, it was working fine, now it doesn't.
What is happening is this:
When my cursor is at the top left corner of the game window, it's like X=200, Y=50.
It's supposed to be X=0, Y=0.
Even when I look for the 0, 0 position, it's way outside the game window.
Does anyone know what could be causing this?
How is that possible? Your cursor position is the mouse position. Simply draw the cursor there.
Unless you are talking about the Windows cursor. In that case, yes, the input data in XNA will not match the Windows cursor movement. They probably apply some modifiers for acceleration, etc. You have to interprete the input data yourself. In other words, draw your own cursor.
I need help with mouse drag and drop. I would like to make something like mouse macro. You specify the XY coordinates of cursor and then drag something to another XY coordinates automatically. Is it possible?
I know how to simulate Mouse Click and Mouse Movement, but I am not sure with the Mouse Dragging.
WM_MOUSEDOWN, WM_MOUSEMOVE, WM_MOUSEUP -- use Spy++ to view windows messages
I'm working with a WPF app, more specifically a Canvas with draggable elements.
Once an item is being dragged, I'd like to limit the scope of cursor movement to inside the canvas where the items are being dragged about.
The event which can start a drag is shown below
private void WidgetCanvas_PreviewHeaderLeftMouseDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
... logic to figure out if this is a valid drag, blah blah blah ...
this.IsDragging = true;
// TODO: clip the available cursor movement to actual width of Canvas
}
On the Preview-MouseUp, I'd like to simply "unclip" the cursor movement back to it's normal state.
I'll be monitoring the movement of the mouse once I start dragging (PreviewMouseMove), so worst case, I could manually check the position of the mouse and keep it constrained to the canvas, but that seems a little ugly.
Anyone have a better way to limit the cursor boundaries?
There's no clean way to do this and the not-so-clean ways will make your mouse cursor "jitter" at the border of the clipping area.
Moreover, I'd question if this is really a good idea. The user should really own the mouse and he or she generally gets frustrated when you try to artificially limit things that he or she owns.
If you want to provide feedback when the mouse leaves your canvas, maybe you could leave the item being dragged stuck along the border while the mouse button is still down? This would tell the user that he or she has left the target area without trying to impose limitations on where the mouse can go.
Good luck!
You should be able to do it using the ClipCursor native API.