zoukankan      html  css  js  c++  java
  • Windows 8里的标准化输入 GIS

    http://blogs.msdn.com/b/windowsappdev/archive/2012/07/02/modernizing-input-in-windows-8.aspx

    支持的输入类型:(mouse, touch, pen, touchpads)

    输入来源(slate(平板), all-in-one(一体机), desktop, laptops(笔记本), convertibles)

    The layers at the top of the input platform forcus on mainline scenarios, and lower layers progressively add flexibility and power

    Finally, the Windows Runtime input APIs are at the bottom layer of the stack. These APIs (GestureRecognizer, PointerPoint, PointerDevice) provide complete flexibility and control, letting you have full access to the raw input data and its associated properties

    there was “pointing input” like mouse, touch, and pen, “text input”, like keyboards and handwriting or speech recognition, and so forth

    Take for example a very basic painting app – it wants to handle down, move, and up events from various inputs. If you want it to respond to touch, pen, and mouse, a naïve platform might force you to write 9 separate and redundant event handlers. Here’s what you might start with in this naïve platform:

    // BAD! Don’t do this in your code.
    class NaivePlatform
    {
    Dictionary<uint, Polyline> strokes = new Dictionary <uint, Polyline>();
    Canvas PaintArea = new Canvas();

    void OnMouseDown(MouseEventArgs e) { CommonDownHandler(e.Id, e.Position); }
    void OnMouseMove(MouseEventArgs e) { CommonMoveHandler(e.Id, e.Position); }
    void OnMouseUp(MouseEventArgs e) { CommonUpHandler(e.Id, e.Position); }

    void OnPenDown(PenEventArgs e) { CommonDownHandler(e.Id, e.Position); }
    void OnPenMove(PenEventArgs e) { CommonMoveHandler(e.Id, e.Position); }
    void OnPenUp(PenEventArgs e) { CommonUpHandler(e.Id, e.Position); }

    void OnTouchDown(TouchEventArgs e) { CommonDownHandler(e.Id, e.Position); }
    void OnTouchMove(TouchEventArgs e) { CommonMoveHandler(e.Id, e.Position); }
    void OnTouchUp(TouchEventArgs e) { CommonUpHandler(e.Id, e.Position); }

    void CommonDownHandler(uint pointerId, Point position)
    {
    // Create a new stroke for this pointer and set its basic properties
    var stroke = new Polyline();
    stroke.Points.Add(position);
    stroke.Stroke = new SolidColorBrush(Colors.Red);
    stroke.StrokeThickness = 3;

    // Add the stroke to dictionary so we can update it in CommonMoveHandler
    strokes[pointerId] = stroke;

    // Add the stroke to the canvas so that it is rendered
    PaintArea.Children.Add(stroke);
    }

    void CommonMoveHandler(uint pointerId, Point position)
    {
    try
    {
    // Update the stroke associated to this pointer with the new point
    strokes[pointerId].Points.Add(position);
    }
    catch (KeyNotFoundException)
    {
    // this pointer is not painting - ignore it
    }
    }

    void CommonUpHandler(uint pointerId, Point position)
    {
    // This stroke is completed, so remove it from the dictionary.
    // It will still be rendered because we are not removing it from the canvas.
    strokes.Remove(pointerId);
    }
    }
    上面的代码非常混乱,我们不需要根据输入的类型是mouse 还是pen ,我们应该采用输入的是pointing类型还是text

    In the pointer version of the painting app, you instead have a simple set of down, move, and up handlers:

    // GOOD! Do this instead of the previous code.
    void OnPointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
    {
    // Retrieve current point, in the coordinate system of the painting area
    var currentPoint = e.GetCurrentPoint(PaintArea);

    // Create new stroke for this pointer and set its basic properties
    var stroke = new Windows.UI.Xaml.Shapes.Polyline();
    stroke.Points.Add(currentPoint.Position);
    stroke.Stroke = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Red);
    stroke.StrokeThickness = 3;

    // Add the stroke to dictionary so we can update it in PointerMoved event handler
    strokes[currentPoint.PointerId] = stroke;

    // Add the stroke to the painting area so that it is rendered
    PaintArea.Children.Add(stroke);
    }

    void OnPointerMoved(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
    {
    // Retrieve current point, in the coordinate system of the painting area
    var currentPoint = e.GetCurrentPoint(PaintArea);

    try
    {
    // Update the stroke associated to this pointer with the new point
    strokes[currentPoint.PointerId].Points.Add(currentPoint.Position);
    }
    catch (System.Collections.Generic.KeyNotFoundException)
    {
    // this pointer is not painting - ignore it
    }
    }

    void OnPointerReleased(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
    {
    // Retrieve current point, in the coordinate system of the painting area
    var currentPoint = e.GetCurrentPoint(PaintArea);

    // This stroke is completed, remove it from the dictionary.
    // It will still be rendered because we are not removing it from PaintArea.
    strokes.Remove(currentPoint.PointerId);
    }
  • 相关阅读:
    linux添加开机启动项、登陆启动项、定时启动项、关机执行项等的方法
    linux下/etc/rc.d目录的介绍及redhat启动顺序
    Linux开机自动挂载存储的两种方式
    Linux中环境变量文件profile、bashrc、bash_profile之间的区别和联系
    linux命令详解——yum
    linux命令详解——ftp
    Shell脚本之sed详解
    shell awk读取文件中的指定行的指定字段
    MySQL的字符集
    shell脚本中的数组
  • 原文地址:https://www.cnblogs.com/gisbeginner/p/2669913.html
Copyright © 2011-2022 走看看