How to create a new return type

Note: You need "TouchToolkit Oct CTP or higher version to create new return type(s)

Step 1: Create the return type & return type calculator classes (C# files) under the Return Types folder

folder.png
  1. Goto add new items
  2. Select the "ReturnType" template
  3. Specify the return type name
This will create 2 C# files (e.g. ReturnType1.cs & ReturnType1Calculator.cs)
returntype.png

Step 3: Update gesture definition language parser definition file
  1. Edit the "Extensions/Language Syntax/ReturnTypes.pd" file to add the new return type.
append_grammar.png

Step 4: Write code to calculate return type values

So far, we have created a new return type and also notified the language parser and compiler about it. Now its time to write C# code. Let's create a return type that will return the path (as an array of points) for each active touch.

The class that contains the data (i.e. TouchPaths.cs) could look like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace TouchToolkit.GestureProcessor.ReturnTypes
{
    public class TouchPaths : List<TouchPath>, IReturnType
    {

    }

    public class TouchPath
    {
        public int TouchDeviceId = 0;
        public List<Point> Points = new List<Point>();
    }
}


And, The class that does the calculation (i.e. TouchPathsCalculator.cs) could look like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TouchToolkit.GestureProcessor.Objects;
using TouchToolkit.GestureProcessor.Utility.TouchHelpers;

namespace TouchToolkit.GestureProcessor.ReturnTypes
{
    public class TouchPathsCalculator : IReturnTypeCalculator
    {
        public IReturnType Calculate(ValidSetOfTouchPoints set)
        {
            TouchPaths paths = new TouchPaths();

            foreach (var item in set)
            {
                paths.Add(item.Stroke.StylusPoints.ToTouchPath(item.TouchDeviceId));
            }

            return paths;
        }
    }
}

Last edited Oct 11, 2010 at 5:14 AM by shahed, version 12

Comments

No comments yet.