Commit 05ad96a1 authored by Jason Simmons's avatar Jason Simmons

Merge pull request #308 from jason-simmons/pointer_raw_examples

Update the raw examples to handle PointerPacket events
parents b1435e29 c94e4c41
......@@ -5,6 +5,10 @@
import 'dart:ui' as ui;
import 'dart:typed_data';
import 'package:mojo/bindings.dart' as bindings;
import 'package:mojo/core.dart' as core;
import 'package:sky_services/pointer/pointer.mojom.dart';
ui.Color color;
ui.Picture paint(ui.Rect paintBounds) {
......@@ -42,25 +46,26 @@ void beginFrame(Duration timeStamp) {
ui.window.render(scene);
}
bool handleEvent(ui.Event event) {
if (event.type == 'pointerdown') {
color = new ui.Color.fromARGB(255, 0, 0, 255);
ui.window.scheduleFrame();
return true;
void handleEvent(String eventType, double timeStamp) {
if (eventType == 'back') {
print('Pressed back button.');
}
}
if (event.type == 'pointerup') {
color = new ui.Color.fromARGB(255, 0, 255, 0);
ui.window.scheduleFrame();
return true;
}
void handlePointerPacket(ByteData serializedPacket) {
bindings.Message message = new bindings.Message(
serializedPacket, <core.MojoHandle>[]);
PointerPacket packet = PointerPacket.deserialize(message);
if (event.type == 'back') {
print('Pressed back button.');
return true;
for (Pointer pointer in packet.pointers) {
if (pointer.type == PointerType.DOWN) {
color = new ui.Color.fromARGB(255, 0, 0, 255);
ui.window.scheduleFrame();
} else if (pointer.type == PointerType.UP) {
color = new ui.Color.fromARGB(255, 0, 255, 0);
ui.window.scheduleFrame();
}
}
return false;
}
void main() {
......@@ -68,5 +73,6 @@ void main() {
color = new ui.Color.fromARGB(255, 0, 255, 0);
ui.window.onBeginFrame = beginFrame;
ui.window.onEvent = handleEvent;
ui.window.onPointerPacket = handlePointerPacket;
ui.window.scheduleFrame();
}
......@@ -7,6 +7,9 @@ import 'dart:ui' as ui;
import 'dart:typed_data';
import 'package:flutter/services.dart';
import 'package:mojo/bindings.dart' as bindings;
import 'package:mojo/core.dart' as core;
import 'package:sky_services/pointer/pointer.mojom.dart';
Duration timeBase = null;
......@@ -78,21 +81,20 @@ void handleImageLoad(result) {
}
}
bool handleEvent(ui.Event event) {
if (event.type == "pointerdown") {
return true;
}
void handlePointerPacket(ByteData serializedPacket) {
bindings.Message message = new bindings.Message(
serializedPacket, <core.MojoHandle>[]);
PointerPacket packet = PointerPacket.deserialize(message);
if (event.type == "pointerup") {
imageCache.load(url2).first.then(handleImageLoad);
return true;
for (Pointer pointer in packet.pointers) {
if (pointer.type == PointerType.UP) {
imageCache.load(url2).first.then(handleImageLoad);
}
}
return false;
}
void main() {
imageCache.load(url1).first.then(handleImageLoad);
ui.window.onEvent = handleEvent;
ui.window.onPointerPacket = handlePointerPacket;
ui.window.onBeginFrame = beginFrame;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment