How to determine swipe direction from gtk gesture swipe signal - touch

I'm trying to implement touch support for elementaryOS' applications menu.
Unfortunately this means working on a dying language like Vala. Nonetheless I am working my way through very little documentation regarding GTK3's touch gestures support. So After adding the touch mask and connecting the touch event signal to the panel's eventBox I end up with a handler function that receives both the calling widget and a touchEvent. From here I am trying to use GtkGestureSwipe to determine if a swipe was completed (touch_begin, touch_update, touch_end). On the swipe signal's documentation there is mention that both velocity and direction are passed but only XY velocities are documented. I was wondering if there was a way to determine direction in a similar way as eventScroll which has a direction property or if the XY velocities can be interpreted as a sort of cartesian coordinate pair.

Related

Modifying smooth curve with Anchor points

I wish to emulate this effect in Xcode with Swift. After some research I managed to find some articles about drawing smooth curves using a set of points .But I am still unclear about how I could to dynamically modify curves when the user touches/holds the screen.
Question :
I know how to make a smooth Bezier curve, but how can I add gesture recognizers such that by dragging the curve its shape changes.
I only need someone to point me in the right direction. Is there a guide or article in particular that could be useful?
Create transparent ControlPointView for every control point of the curve with a size of 50*50pt, so that users can easily tap them and drag.
Add a small image in the middle of every ControlPointView, so that users can see where the control point is located.
Add UIPanGestureRecognizer on every ControlPointView and handle it in view controller.
Use centers of control points to rebuild UIBezierPath every time gesture recognizer's state is changed.

horizontal and vertical shake count using accelerometer in iPhone/iPad

I want to count number of shake horizontally and vertically, I have referred to UIAcceleration
I have also referred to Motion Events
But couldn't come up with better approach.
Any kind of help is highly appreciated , code , reference, or any type.
i just want to count the number of shake user make by shaking the iphone device, the shake can be vertically or horizontally holding iphone in normal way(home key at the bottom)
Try DiceShaker. You'll need to use the code for "Isolating Instantaneous Motion from Acceleration Data" given in Listing 4-6 of the motion events (also called high-pass filter computation) documentation to detect acceleration provided by user.
EDIT: The accelerometer constantly provides the gravity component readings because the accelerometer works with a bunch of springs that determine the force component (in the direction of each spring's length) by the increase/decrease in the spring's length. So just remove the constant gravity(the force that's ALWAYS working) component to detect the change provided by the user (hence the name high-pass). Luckily, we don't need to figure out how to because Apple has done the hard work and given the equations in their documentation!

How to detect circular gesture via Gesture Recognizer?

I am trying to implement a volume-control-like round button. Currently I can detect swipes by the Gesture Recognizer. How can I detect a circular gesture (clockwise and anti-clockwise) on the button? Thanks!
Are you looking for a one-touch gesture (like a circular slider), or a two-touch gesture (like grabbing and turning a real-world knob)? If the latter, take a look at UIRotationGestureRecognizer.
If the former, you're pretty much on your own. You can certainly implement your solution as your own custom gesture recognizer: this is expected by Apple, and there's some documentation to get you started (though I haven't seen many working examples out there). See also How to correctly subclass UIGestureRecognizer.
As a general approach, I'd think of the region for the gesture as a donut shape: a zone with center c, inner radius r1, and outer radius r2. When the user touches down you can calculate the distance from c using the Pythagorean theorem, and the angle with your favorite trig function. With that, you can determine whether the touch is within the zone. As the user drags, you can update the control value based on the angle. At some point, they'll either touch up, or drag outside of the zone, and that will end the gesture. I suggest allowing the touch to stray pretty far inside r1 or outside of r2: fingers are imprecise tools.
As failing to find a solution, and by logical inspiration from #sixten's answer, I've gone and created something useful, it's not bullet proof, but it seems to do what I need for now.
Please anyone, fork it, clone it, use it, improve it, it's open source, here's my repo link:
https://bitbucket.org/danielphillips/dpcirculargesturerecognizer
Have you tried writing your own gesture recognizer? There are detailed instructions in the docs.
Best Way would be implement Custom Gesture Recognizer. I do not know if you wish to detect a Discreet Gesture (Event Handling method would be called once the full circle has been detected) or a Continues Gesture (Event Handling method would be called every time you move your finger on a circular Path).
Probably, the user may not draw a perfect circle, and the solution provided by #Sixten Otto would be good.

How do you ignore the palm of the hand when doing multitouch drawing?

Several multitouch drawing applications have implemented features that prevent interference when a user rests their palm on the screen while drawing.
How do they filter out touch events from the palm of the hand, but allow the correct input from the drawing finger or stylus?
Ignore any multi-touch inputs that are close to each other, only taking the data from the single point (the finger).
Take the top y component from the group of touches.

Is there a class / method to handle dragging views?

I found a useful tutorial to get started in understanding how to Cocoa handles touch events. I've used this as a base to create a custom script, I'm trying to make a UIView draggable, very similar to the native Maps application.
I've written a custom script, using
the touchesBegan method it will
capture where the input began and
compare it to the centre point of the
UIView using some conditional
statements.
The touchesMoved method will do some
further conditional statements to
determine whether the touch start
point and the center of the view will
move positively or negative.
I've also captured the views
boundaries so it doesn't go too far
out.
it's lacking the polished finished found in other applications such as Maps, or scrolling a UITable, such as the ease effect after the user has released their fingers, and the snapping effect when it reaches the boundaries is horrible.
Is there a method that takes a view and makes it draggable like this? If not I'll continue to refine my script.
Many thanks!
Maybe you are looking for UIScrollView