Code for touch, get mouse and pen for free Pointer API captures pen motion, passing coordinates to Ink API Ink API helps render and stores motion.

Slides:



Advertisements
Similar presentations
CS 142 Lecture Notes: EventsSlide 1 Access to Event Object ● event variable (HTML): ● Passed as argument to function (DOM/Firefox): element.onclick = mouseClick;
Advertisements

Introduction to Tablet PC Development Gaurav Khanna Developer Evangelist Microsoft India.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
Understanding Mobile App Development Concepts and Working with APIs Lesson 6.
Neal Stublen Why Use a Canvas?  Flexibility… Use of drawing primitives (lines, arcs, text) Direct access to element display pixels.
Programming Club IIT Kanpur
HTML 5 Previous version: HTML4.01, 1999 Still work in progress, most browsers support some of it.
Nov Jason Hong and James Landay University of California Berkeley Group for User Interface Research.
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Tablet PC Platform Advanced Topics Software Design Engineer/Test Lead
Canvas, SVG, Workers Doncho Minkov Telerik Corporation
How to Create Your First
Design Considerations & User Experience Guidelines for Mobile Tablet Applications Arnie Lund Director, User Experience David Hale Developer Experience.
Copyright 2007, Information Builders. Slide 1 Maintain & JavaScript: Two Great Tools that Work Great Together Mark Derwin and Mark Rawls Information Builders.
Windows Store apps with HTML + Facebook integration
Beautiful Sites and Apps Easy-to-build, Touch-First Interactivity Engaging Page Layouts Better Client/Server Data Transfer Powerful Local Data and Offline.
Doodlz App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
Getting Started with Canvas IDIA Spring 2013 Bridget M. Blodgett.
HTML5 CANVAS. SAVING INFORMATION BETWEEN FUNCTION CALLS.
Session: 17. © Aptech Ltd. 2Canvas and JavaScript / Session 17  Describe Canvas in HTML5  Explain the procedure to draw lines  Explain the procedure.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
NoteSearch - Find what you’re looking for. Prototype Team B.
Chapter 9 Fireworks: Part I The Web Warrior Guide to Web Design Technologies.
Build advanced touch apps in Windows 8
Creating User Interfaces Recap HTML/HTML5 JavaScript features Homework: keep working on user observation studies. Review JavaScript.
CSS 2D Transforms CSS 3D Transforms CSS Animations CSS Backgrounds & Borders CSS Color CSS Flexbox CSS Fonts CSS Grid CSS Hyphenation CSS Image Values.
Async everywhere: creating responsive APIs & apps
Provides a rich set of media features in easy-to-use APIs Allows you to build cutting-edge apps with advanced media functionality taking full advantage.
Event JavaScript's interaction with HTML is handled through events that occur when the user or browser manipulates a page. When the page loads, that is.
The Web Wizard’s Guide To JavaScript Chapter 8 Working with Windows and Frames.
Event-Driven Programming Chapter Page Section: Section or division of an HTML page Generic block element Example: What's the difference between.
CHAPTER 22 ADVANCED CANVAS PROGRAMMING. LEARNING OBJECTIVES How the HTML 5 canvas supports linear and radial gradients How to fill a shape with a pattern.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
web Metadata Properties Thumbnails Properties by Kind MRU Change Notifications Bulk Access File broker functions Search Deep/Shallow Enumeration.
Lab 5: More on Events and Introduction to the Canvas Tag User Interface Lab: GUI Lab Sep. 23 rd, 2013.
The State of WebDynamo: An AgentCubes Web API Scott Keller Erin Rowland Stuart Reed Michael Wally George McCabe dy· na· mo: (n.) A generator 1Erin Rowland.
Metro Style Applications Metro style design and Inspirations.
Pen Based User Interface Issues CSE 490RA January 25, 2005.
Can SAS Do Canvas? Creating Graphs Using HTML 5 Canvas Elements Edwin J. van Stein Astellas Pharma Global Development.
07 – HTML5 Canvas (1) Informatics Department Parahyangan Catholic University.
Windows 8: XAML or HTML? Karl Davies-Barrett CEE DPE Tech Lead, Microsoft 
What is the Windows Runtime? Devices Sensor s Geolocation Portabl e NFC Communications & Data Contracts XML Web SMS Networking Notifications Local.
Developing Windows 8 Style Application With HTML and JavaScript Lino Tadros | Falafel Software.
4.3. Code animations by using JavaScript Access data access by using JavaScript. Creating Animations, Working with Graphics, and Accessing Data.
REEM ALMOTIRI Information Technology Department Majmaah University.
Developing Windows 8 Style Application With HTML and JavaScript
What is a Function Expression?
Internet of the Past.
Platform for Metro Style Apps
Modern JavaScript Luke Hoban Program Manager — JavaScript
14 A Brief Look at JavaScript and jQuery.
Make great Metro style apps that are touch-optimized using HTML5
Integrating with the Windows Device Experience
ISC440: Web Programming II Ch14: HTML5 Canvas
JavaScript Selection Statement Creating Array
Using the Windows Runtime from JavaScript
Bring apps to life with Metro style animations in HTML5
Anatomy of HTML5 sites and Metro style apps using HTML5
Progress <progress value="22" max="100"></progress>
Simple Canvas Example Your browser doesn’t support canvases var canvas = document.getElementById("canvas1"); var context.
The Web Wizard’s Guide To JavaScript
Code Topic 9 Standard JavaScript Events Laura Friedman
Creating User Interfaces
Jeremy Foster Michael Palermo
02 | Building Windows Store Apps with XAML Part 2
JavaScript – Let’s Draw!
HTML5 – A few features L. Grewe.
Presentation transcript:

Code for touch, get mouse and pen for free

Pointer API captures pen motion, passing coordinates to Ink API Ink API helps render and stores motion as ink. Ink manipulation. Ink API groups strokes and passes them to recognizer Reco API returns interpreted combination of strokes from recognizer (rich recognition results) HI! Hi! Hit Hid hi!

Metro style app Windows.UI.Input. Inking stroke builder, rendering helper, ink manipulation, handwriting recognition with rich recognition results with alernates, clipboard, serialization Input Render Obtains Raw Data position, id and pressure using MSPointer (JavaScript / ICoreWindow (XAML) and passes this to stroke builder: Begin/Append/End Stroke methods Obtains Raw Data position, id and pressure using MSPointer (JavaScript / ICoreWindow (XAML) and passes this to stroke builder: Begin/Append/End Stroke methods Renders Strokes render using rendering helper method: InkRenderingSegment does not return packets but stroke rendering segments such as Bezier curves

Code Snippets Register for events ProcessPointerDown ProcessPointerUpdate ProcessPointerUp Render everything

Register for events html: <canvas id="myCanvas" width="1000" height="1000"></canvas> js: var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); canvas.addEventListener("MSPointerDown", handlePointerDown, false); canvas.addEventListener("MSPointerMove", handlePointerMove, false); canvas.addEventListener("MSPointerUp", handlePointerUp, false); var inkManager = new Windows.UI.Input.Inking.InkManager();

ProcessPointerDown function handlePointerDown(evt) { if ((evt.pointerType === 3) || ((evt.pointerType === 4) && (evt.button === 1))) { evt.preventManipulation(); inkManager.processPointerDown(evt.currentPoint); context.beginPath(); context.moveTo(evt.currentPoint.rawPosition.x, evt.currentPoint.rawPosition.y); } else if ((evt.pointerType === 2) || ((evt.pointerType === 4) && (evt.button === 2))) { // Handle touch down } }

ProcessPointerUpdate function handlePointerMove(evt) { if ((evt.pointerType === 3) || ((evt.pointerType === 4) && (evt.button === 1))) { evt.preventManipulation(); inkManager.processPointerUpdate(evt.currentPoint); context.lineTo(evt.currentPoint.rawPosition.x, evt.currentPoint.rawPosition.y); context.stroke(); } else if ((evt.pointerType === 2) || ((evt.pointerType === 4) && (evt.button === 2))) { // Handle touch move } }

ProcessPointerUp function handlePointerUp(evt) { if ((evt.pointerType === 3) || ((evt.pointerType === 4) && (evt.button === 1))) { evt.preventManipulation(); inkManager.processPointerUp(evt.currentPoint); context.lineTo(evt.currentPoint.rawPosition.x, evt.currentPoint.rawPosition.y); context.stroke(); context.closePath(); } else if ((evt.pointerType === 2) || ((evt.pointerType === 4) && (evt.button === 2))) { // Handle touch up } renderAllStrokes(); }

Render everything function renderAllStrokes() { inkManager.getStrokes().forEach(function (stroke) { var first = true; stroke.getRenderingSegments().forEach(function (segment) { if (first) { context.moveTo(segment.position.x, segment.position.y); first = false; } else { context.bezierCurveTo(segment.bezierControlPoint1.x, segment.bezierControlPoint1.y, segment.bezierControlPoint2.x, segment.bezierControlPoint2.y, segment.position.x, segment.position.y); } }); }); context.stroke(); context.closePath(); }

Code Snippets Select strokes using Touch Moving selected strokes Selecting and Erasing modes Deleting selected strokes

Selecting individual strokes (using touch) function handlePointerDown(evt) {... else if ((evt.pointerType === 2) || ((evt.pointerType === 4) && (evt.button === 2))) { var hit = false; inkManager.getRecognitionResults().forEach(function (result) { if (inRect(evt.offsetX, evt.offsetY, result.boundingRect)) { result.getStrokes().forEach(function (stroke) { stroke.selected = true; hit = true; }); } }); if (hit) { evt.preventManipulation(); prevX = evt.offsetX; prevY = evt.offsetY; } } }

Moving selected strokes function handlePointerMove(evt) { if ((evt.pointerType === 3) || ((evt.pointerType === 4) && (evt.button === 1))) { // Handle pen move } else if ((evt.pointerType === 2) || ((evt.pointerType === 4) && (evt.button === 2))) { evt.preventManipulation(); var shift = {x: evt.offsetX - prevX, y: evt.offsetY - prevY}; inkManager.moveSelected(shift); renderAllStrokes(); prevX = evt.offsetX; prevY = evt.offsetY; } }

Selecting mode (Lasso) and erasing mode inkManager.mode = Windows.UI.Input.Inking.InkManipulationMode.selecting; inkManager.mode = Windows.UI.Input.Inking.InkManipulationMode.erasing; inkManager.mode = Windows.UI.Input.Inking.InkManipulationMode.inking; // These 3 modes all use the same down/move/up handlers inkManager.deleteSelected();

Code Snippets Recognition Find and select all strokes

Recognition function recognize() { inkManager.recognizeAsync(Windows.UI.Input.Inking.InkRecognitionTarget.all).then( function (results) { inkManager.updateRecognitionResults(results); }); }

Find and select all strokes function recognizeThenFindAndSelect(target) { inkManager.recognizeAsync(Windows.UI.Input.Inking.InkRecognitionTarget.all).then(function (results) { results.forEach(function (result) { result.getTextCandidates().forEach(function (candidate) { if (target.toLowerCase() === candidate.toLowerCase()) { result.getStrokes().forEach(function (stroke) { stroke.selected = true; }); } }); }); }); }

Metro style app built for Windows using JavaScript / C++ or C# runtime environment Metro style app Windows runtime Windows.UI.Input.Inking namespace for ink management Windows.Graphics namespace for rendering IE events for JavaScript / Windows.Foundation namespace for ICoreWindow (C++ / C#) obtains position, id, & pressure from MSPointer (JavaScript) / ICoreWindow (C++/C#) obtains position, id, & pressure from MSPointer (JavaScript) / ICoreWindow (C++/C#) manages ink with calls to Windows.UI.Input.Inking renders using HTML5 Canvas (JavaScript), D2D and DUI

Save function saveToFile() { var picker = new Windows.Storage.Pickers.FileSavePicker(); picker.pickSingleFileAsync().then(function (file) { file.openAsync(Windows.Storage.FileAccessMode.readWrite).then(function (stream) { var outputStream = fileStream.getOutputStreamAt(0); inkManager.saveAsync(outputStream).then(function() { outputStream.flushAsync().then(function() { }); }); }); }); }

Load function loadFromFile() { var picker = new Windows.Storage.Pickers.FileOpenPicker(); picker.pickSingleFileAsync().then(function (file) { file.openAsync(Windows.Storage.FileAccessMode.read).then(function (stream) { var inputStream = fileStream.getInputStreamAt(0); inkManager.Load(inputStream); renderAllStrokes(); }); }); }

Copy and Paste function copySelectedToClipboard() { inkManager.copySelectedToClipboard(); } function pasteFromClipboard(point) { inkManager.pasteFromClipboard(point); }

Select with Recent Recognition function recognizeRecentThenFindAndSelect(target) { inkManager.recognizeAsync(Windows.UI.Input.Inking.InkRecognitionTarget.recent).then(function (results) { inkManager.updateRecognitionResults(results); inkManager.getRecognitionResults().forEach(function (result) { result.getTextCandidates().forEach(function (candidate) { if (target.toLowerCase() === candidate. toLowerCase()) { result.getStrokes().forEach(function (stroke) { stroke.selected = true; }); } }); }); }); }