How to track the position of the second pointer - c#

I will like to know what can I do to track down the position of a second pointer which enter in the canvas.
I added a counter in the PointerEntered event handler. It's able to track how many pointers are there, but I don't know how to track the position of the second(or more) pointer as it moves.
Thank you in advance for any help.

The corresponding event provides event arguments that hold a reference to the Pointer. Each pointer instance has a separate pointer id:
Pointer Properties on MSDN
You need to also register with the PointerMoved event to get updates of the pointer location. Using the pointer ids, you can index into your local data structure to update the location of your visual on the canvas.
You cannot register for the events bound to a specific pointer ID. All events will be triggered for all pointers. So you only register once with the events, normally. You need to keep track (e.g. via a Dictionary from pointer id to your pointer data) of each pointer in your own code if you need to handle each pointer input differently. The MSDN Pointer Tutorial has a nice example that shows exactly that.

Related

Is there a way to link an object in the hierarchy to the onclick() method of a panel that I instantiate runtime?

Simplifying, I am creating a surveyeditor: in the game, the player must be able to enter n questions and, for each question, 4 different answers.
You can also insert an image for each question / answer and that is the problem! The panel where he can declare these informations is a prefab that is instantiated n times, according to the number of questions indicated by the user.
However, the method by which he can insert an image (ie opening a further panel where he can choose the image to instantiate) is present in a Gameobject present in the hierarchy (NOT a prefab).
Currently, it does not seem possible to insert this object in the onckick () function of the button through which the user should choose the image. Is there actually a way?
I don't believe there is a way to directly attach the image to the onClick() event. A method that comes to mind (if I understand your use case), would be a listener approach. So once the user clicks the button to attach an image, store that image in a variable. Then another object is checking if this image in this variable is not null. If so, it will grab that image, and attach it to wherever you need it to go, and then set the image variable to null so that it may again listen for more images.

HOW to get LOW touch point argument for each touch point in UWP by C#

I need to filtrate touch point in an UWP app. I need to filtrate touch point according to timestamp of a touch point, and get coordinate or id of the touch point.
In a WPF application , I can get necessary data of touch point by using TouchFrameEventArgs class, and using the method GetTouchPoints().
But, In UWP app, what should I use? I want to get the first occurred touch point after a specific event occurs.
First, generally speaking, touhc, mouse and pen input in UWP is abstracted to a single event set dealing with pointers.
When you handle a pointer event like PointerDown, you get an instance of PointerRoutedEventArgs class. This class will help you identify a specific pointer using the Pointer.PointerId property. This a unique identification you can use to check for the pointer that raised this event. You can store the pointer IDs you have encountered in time which should provide you with the behavior you are requesting.

Executing function based on pointer location

I am working with ArcGIS SDK for dot net. I am programming using vc#. I want to execute a piece of code as soon as the mouse pointer enters a particular longitude/latitude on map or if mouse is clicked on that location. there are many event handlers but I don't know how to retrieve the location the mouse pointer is at. e.g I want to display some picture as soon as mouse pointer is at longitude 25 and lat 33.
Add a MouseMove listener to your MapView.
Your listener method will have a parameter of type MouseEventArgs. Call GetPosition(null) on that parameter to get the screen point.
Use MapView.ScreenToLocation(Point) to get the MapPoint in map coordinates.
If your map isn't in longitude/latitude, use GeometryEngine.Project(Geometry, SpatialReference.Create(4326)) to convert to longitude/latitude.
Check the longitude and latitude to see if they're in the range you want.
I tried posting my source code here but Stack Overflow gave me an error, so here it is as a screenshot:

Mouse.GetPostion(null) Equivalent in WinRT

What would be the equivalent for Mouse.GetPostion(null) which is in WPF.
I can get the position of pointer from the pointer event args. but how do i get the position without any event. like "Mouse.GetPostion(null)" in WPF. where mouse is a static class.
Any idea?
There is a PointerPoint.Position property - PointerPoint is a general input abstraction that also inludes touch and stylus input so you have to get a focus on mouse input first - this can be done with a static
PointerPoint PointerPoint.GetCurrentPoint(uint pointerId)
method where pointerId is a system generated number identifying the input device. I don't know if there is any other way but you can get the mouse PointerId through
PointerRoutedEventArgs.Pointer.PointerId
if you handle some mouse Pointer event like PointerPressed or PointerReleased first.

Correct/Incorrect usage of delegates for achieving extensibility

I'm trying to give users of my GUI library unrestricted customization of in/out transition effects while still maintaining simplicity / preventing misuse (for when a Control enters or exits the view).
To do so, I added a delegate to the Control class, which would take a Control reference and a transition-completion percent, so that the user would be able to smoothly translate a control's position / opacity in any way he wanted, based on the given percent. All he'd have to do is subscribe a transition function before control entrance/exit.
However, I realized it would be impossible to transition / animate the controls using only the current completion percent, because you'd have to store and compare the control's initial position as well.
In order make this storage requirement apparent, should I force usage of a delegate-functor?
If so, how might I do that in a minimalistic / clean way?
Feel free to suggest another way to allow users to apply custom transition animations!
If I understood you correctly, your Control invokes Animation(calculation) delegate (from time to time, probably on each frame) and passes transition Competition percent.
The Animation delegate then calculates and returns/applies translation and position to the Control.
Is this correct?
Assuming that above is correct there are several solutions:
When animating only position and opacity:
Beside competition percent, you must also send initial state of control's position and opacity when calling delegate. Initial state must be remembered on the transition start and sent into delegate in each call.
When animating arbitrarily properties in general:
Beside competition percent, you also provide State property (type of Object or even better Dictionary). This State property is fully controlled by delegate and it's animation logic.
To your Control, State property would not have any semantics or meaning.
Your Control only MUST retain value of State property between subsequent calls to delegate.
Putting it all together, The Delegate fills the State with the initial values on the first call, uses these values on subsequent calls - does anything it wants. Delegate also applies calculated values to Control. Note that all properties that can be used in delegate must be public.
IMO you don't have to provide the user of the control with the initial position of the control since he can position it relatively to the initial position:
negative numbers are for left and top, and positive numbers are for right and bottom.
The following code is a function for a fast transition:
Point FastTranDiagonial(float Percentage){
Thread.Sleep(10);
int pixelsDist = (1 - Percentage)* 300;//300 is the maximum distance
return new Point(-pixelsDist ,pixelsDist);
}
When you invoke the delegate you have to add the Point to the initial position of the control. You have to notice that the delegate contains a Thread.Sleep(X), this must be in control of the user since he might want to do a fast or a slow transaction.
You might also want to consider adding sequential transitions like jQuery so one transition starts after an other's completion.
good luck
I think you need to pass in at least the following parameters to the delegate:-
the control itself
the container that contains the control (eg. a panel)
the completion percent
By passing the control itself, the user will have all its initial state information (such as position). Also, if the user need to set any property of the control, he will definitely need the reference to the control itself.
The container may be needed by the user if he needs its size/position information, or if he needs to do something special to it for the control.

Categories

Resources