ManipulationMode explained - windows-8

Can someone explain the meaning of manipulation modes such as TranslateX, TranslateRailsX, TranslateInertia ?
What is a rail mode? And what inertia they are talking about?

With rails - when the input processor detects whether the manipulation is mostly vertical or mostly horizontal it sticks to the respective axis when reporting translation delta/cumulative values. If not - it just allows to freely manipulate whatever you are manipulating. Rails flags have to be used in combination with the non-rails flags, so just TranslateRailsX doesn't work. You need both that and TranslateX to get anything going.
The TranslateInertia flag allows for simple handling for flicks or inertial rotations/scales in case of the other inertia flags. Basically if you add that flag to the TranslateX one for example and you do a quick flick gesture - you will keep getting the input events (ManipulationDelta) for a while even after the gesture is completed. You also get the ManipulationInertiaStarting event when you flick once the input stream ends, so you get to control how far the flick goes if you want to. You can check out my extensions to the argument of that event in WinRT XAML Toolkit to get some more control over the ballistics of the flick too.
Your ManipulationDeltaEventArgs have an IsIntertial property you can also use to check if the events you are getting are directly from input events or a result of a flick and also call Complete() if for some reason you don't want to continue getting the delta events for the flick.

Here is a simple example that shows how I implemented TranslateRailsX/Y.
I wanted it to only register horizontal swipe but with just using TranslateX/Y it was picking up the left or right even if I was just swiping up or down.
So just a simple XAML and as in my instance I only want horizontal swipes not the vertical swipes.
xaml file:
<Grid Background="WhiteSmoke">
<WebView Name="webview" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
</Grid>
xaml.cs file:
int x1;
int x2;
int y1;
int y2;
public MainPage()
{
this.InitializeComponent();
webview.ManipulationMode = ManipulationModes.TranslateRailsX | ManipulationModes.TranslateRailsY;
webview.ManipulationStarted += (s, e) => x1 = (int)e.Position.X;
webview.ManipulationStarted += (s, e) => y1 = (int)e.Position.Y;
webview.ManipulationCompleted += (s, e) =>
{
x2 = (int)e.Position.X;
y2 = (int)e.Position.Y;
System.Diagnostics.Debug.WriteLine(x1);
System.Diagnostics.Debug.WriteLine(x2);
System.Diagnostics.Debug.WriteLine(y1);
System.Diagnostics.Debug.WriteLine(y2);
if (x1 > x2)
{
System.Diagnostics.Debug.WriteLine("right");
};
if (x1 < x2 )
{
System.Diagnostics.Debug.WriteLine("left");
}
};
And now I get the following on a vertical swipe
x1 180
x2 180
y1 201
y2 386
And horizontal swipe
x1 89
x2 293
y1 371
y2 371
left or right
Hope this helps someone in the same predicament.

Related

How to have tooltip follow cursor when hovering on bar

Here's my code in sandbox
The code in sandbox is fully working,(component based) but when i transfer it in actual it's not working
would be best if you share a working example of your code in a Sandbox/JSBin or similar. Then it is easier to help.
But one thing:
in v4 of d3
d3.mouse(container)
Returns the x and y coordinates of the current event relative to the
specified container.
What you want is d3.event.pageX which gives you:
An integer value, in pixels, indicating the X coordinate at which the mouse pointer was located when the event occurred. This value is relative to the left edge of the entire document, regardless of the current horizontal scrolling offset of the document.
But to be certain I would need to see a working example to try this out.
For D3 v4 specifically:
Append a div using d3:
const tooltip = d3
.select('body')
.append('div')
.attr('class', 'tooltip');
Now Add a mousemove and mouseout listener:
d3.on('mousemove', () => {
return tooltip
.style('top', d3.event.pageY - 30 + 'px')
.style('left', d3.event.pageX + 'px');
})
.on('mouseout', function() {
d3.select(this)
.transition()
.duration(this.transitionDuration * 0.2)
.style('fill', `green`);
return tooltip.style('visibility', 'hidden');
});

How can I detect if the touch is over the border of a View from PanResponder?

I'm working on a Image cropper, I have somehow figure out how to move the cropper even it's not a perfect solution but it works, but now I want to respond to the border touches/moves of a given View
I'm using this module for the corpping, but actually I'm still stuck at how to respond to border touches/moves
gestureState parameter is sufficient for the task.
x0 and y0 are the top-left coordinates of the responder view, further, moveX and moveY holds the current coordinates of touch.
So moveX === x0 means current touch is at left edge.
Similarly moveY === y0 means current touch is at top edge.
For handling right and bottom edge I suggest you use onLayout in the <View> tag and assign height and width of the view to some variable or in state variable( take care of performances optimisations)
And then use it in similar way:
onPanresponderMove(evt, {x0, y0, moveX, moveY) {
...
if(moveX=== x0 || moveX === x0 + this.state._currentWidth) {
// task for left and right edge response
...
}
...
}
To get view width:
<View {...this._myResponder.panHandlers}
onLayout={ ({width, height}) => this.state._currentWidth = width } />

Haxe: Handling horizontal scroll events

I recently started using Haxe, so pardon me if my question has an obvious answer or if my description of the problem is a little sloppy, but I'm going to try my best to explain it.
I'm working on a laptop that has a multitouch-supported track pad, and a normal optical mouse with only a vertical scroll wheel (no horizontal clicking available on there). I'm looking for a way to handle horizontal scroll input / events. OpenFL's mouse events support vertical scrolling well enough. Both the mouse scrolling and the two-finger track pad scrolling work fine for the vertical axis. It looks like the same event is generated when either of those input methods are used, which is understandable. But I can't seem to find an event that would be generated when a horizontal scroll is performed. The track pad allows for horizontal scrolling, since web browsers respond to the command, but I can't find any way to make my program respond to this input. Lime's "onMouseWheel" function doesn't respond to the input either. Do you guys have any suggestions for capturing this kind of input for an app targeted for Windows?
Thanks in advance
UPDATE: What I'm looking for here is not a question of how to scroll the screen horizontally, but how to recognize the horizontal scroll event coming from hardware, for example two fingers on the track pad or a sideways click of the middle mouse wheel. Lime's onMouseWheel has two params, deltaX and deltaY, but no events are triggered that give back a non-zero deltaX value. Vertical scrolling fires an event that returns deltaX = 0 and deltaY = +/- 1, but horizontal scrolling doesn't even trigger an event.
This can be done in several ways. The first is to add an event handler to mouse wheel for the object instance that you want to attach the event handler to, so MouseEvent.MOUSE_WHEEL and use the delta variable to determine the scroll direction. What you may also need to do is handle a key down event which enables horizontal scrolling instead of vertical.
Some example code:
mySprite.addEventHandler(MouseEvent.MOUSE_WHEEL, onScroll);
mySprite.addEventHandler(KeyboardEvent.KEY_DOWN, onKeyDown);
mySprite.addEventHandler(KeyboardEvent.KEY_UP, onKeyUp);
...
private var horizontal:Bool;
private function onScroll(e:MouseEvent):Void
{
if (e.delta > 0 && horizontal)
mySprite.scrollRect.x++;
else if (e.delta < 0 && horizontal)
mySprite.scrollRect.x--;
}
private function onKeyDown(e:KeyboardEvent):Void
{
if (e.keyCode == 18)
horizontal = true;
}
private function onKeyUp(e:KeyboardEvent):Void
{
if (e.keyCode == 18)
horizontal = false;
}
You will need to define the scrollRect in your constructor somewhere to specify the scrolling bounds of the sprite.

Binding Event to View Model, Rotation of Image

I want to have a Rotation of an Image, but I don't want to Code the Events inside the Codebehind but in the View Model.
By now everything works fine, BUT the code is in the CodeBehind...
(It's based on this tutorial)
I tried
XAML:
[...]
ManipulationDelta="{Binding RotateManipulationDelta}"
[...]
<RotateTransform x:Name="{Binding RotateTransform}" />
ViewModel:
private void RotateManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
// Alternatively, use Triangle Cosines Law.
// It uses just one trigonometric function (Acos), but you first need to calculate the lengths of all sides.
var x = this.RotateTransform.CenterX - e.Position.X;
var y = this.RotateTransform.CenterY - e.Position.Y;
double a1 = Math.Atan(y / x);
double a2 = Math.Atan((e.Delta.Translation.Y - y) / (x - e.Delta.Translation.X));
this.RotateTransform.Angle += a1 - a2;
}
But C# obviously doesn't know "RotateTransform" or the Method itself.
Is there a possibility to do so? I have no clue.
And please try to explain it as simple as possible. I just started with Windows Apps and XAML. :D
I hope you can help me.
You may want to look at something like this Storyboarded animations for visual states or this XAML animation.
I don't get why you want to do something like this... Can you give us more infos ? It will be much more easy to do it in C# than in XAML. The point of the code behind is to do that stuff.

Zooming in and out in Grid, Images on WinRT (Metro style app)

I'm trying to implement something in my app, I need to show an image, and let the user pinch in and out of the images.
I think its possible using the ScrollViewer, but I couldnt get it to work, help?
I hate to oversimplify this, but the WinRT XAML ScrollViewer has gesture manipulation built in.
You can see what I mean here. This might not be what you want. But it's sure a simple approach and might fit a certain % of scenarios. Maybe even yours.
Controls that incorporate a ScrollViewer in compositing often set a value for ZoomMode in the default template and starting visual states, and it is this templated value that you will typically start with. Controls with a ScrollViewer as part of their composition typically use template binding such that setting the attached property at the level of the control will change the scroll behavior of the ScrollViewer part within the control. Otherwise, it may be necessary to replace the template in order to change the scroll behavior of a ScrollViewer part.
Check out Morten Nielsen's article on Building A Multi-Touch Photo Viewer Control. It's for Silverlight/Windows Phone, but if you just enable manipulations on the image and change a few types in manipulation events - it should work great.
A simple solution that might be enough for you is to just put the image in a ScrollViewer, although to see it working - you need a touch screen or run it in a simulator (use the pinch tool, then drag and scroll on the image to zoom in/out).
You can also zoom it with code:
<Grid
Background="{StaticResource ApplicationPageBackgroundBrush}">
<ScrollViewer
x:Name="myScrollViewer">
<Image
Source="/Assets/SplashScreen.png" />
</ScrollViewer>
</Grid>
.
public BlankPage()
{
this.InitializeComponent();
myScrollViewer.ZoomMode = ZoomMode.Enabled; // default
Test();
}
private async void Test()
{
while (true)
{
for (double x = 0; x < 2 * Math.PI; x += Math.PI / 30)
{
await Task.Delay(1000 / 30);
float factor = (float)(1.0 + Math.Sin(x) / 10);
myScrollViewer.ZoomToFactor(factor);
}
}
}