Commit c94e4c41 authored by Jason Simmons's avatar Jason Simmons

Update the raw examples to handle PointerPacket events

parent b1435e29
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'dart:typed_data'; 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.Color color;
ui.Picture paint(ui.Rect paintBounds) { ui.Picture paint(ui.Rect paintBounds) {
...@@ -42,25 +46,26 @@ void beginFrame(Duration timeStamp) { ...@@ -42,25 +46,26 @@ void beginFrame(Duration timeStamp) {
ui.window.render(scene); ui.window.render(scene);
} }
bool handleEvent(ui.Event event) { void handleEvent(String eventType, double timeStamp) {
if (event.type == 'pointerdown') { if (eventType == 'back') {
color = new ui.Color.fromARGB(255, 0, 0, 255); print('Pressed back button.');
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 == 'pointerup') { 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); color = new ui.Color.fromARGB(255, 0, 255, 0);
ui.window.scheduleFrame(); ui.window.scheduleFrame();
return true;
} }
if (event.type == 'back') {
print('Pressed back button.');
return true;
} }
return false;
} }
void main() { void main() {
...@@ -68,5 +73,6 @@ void main() { ...@@ -68,5 +73,6 @@ void main() {
color = new ui.Color.fromARGB(255, 0, 255, 0); color = new ui.Color.fromARGB(255, 0, 255, 0);
ui.window.onBeginFrame = beginFrame; ui.window.onBeginFrame = beginFrame;
ui.window.onEvent = handleEvent; ui.window.onEvent = handleEvent;
ui.window.onPointerPacket = handlePointerPacket;
ui.window.scheduleFrame(); ui.window.scheduleFrame();
} }
...@@ -7,6 +7,9 @@ import 'dart:ui' as ui; ...@@ -7,6 +7,9 @@ import 'dart:ui' as ui;
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flutter/services.dart'; 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; Duration timeBase = null;
...@@ -78,21 +81,20 @@ void handleImageLoad(result) { ...@@ -78,21 +81,20 @@ void handleImageLoad(result) {
} }
} }
bool handleEvent(ui.Event event) { void handlePointerPacket(ByteData serializedPacket) {
if (event.type == "pointerdown") { bindings.Message message = new bindings.Message(
return true; serializedPacket, <core.MojoHandle>[]);
} PointerPacket packet = PointerPacket.deserialize(message);
if (event.type == "pointerup") { for (Pointer pointer in packet.pointers) {
if (pointer.type == PointerType.UP) {
imageCache.load(url2).first.then(handleImageLoad); imageCache.load(url2).first.then(handleImageLoad);
return true;
} }
}
return false;
} }
void main() { void main() {
imageCache.load(url1).first.then(handleImageLoad); imageCache.load(url1).first.then(handleImageLoad);
ui.window.onEvent = handleEvent; ui.window.onPointerPacket = handlePointerPacket;
ui.window.onBeginFrame = beginFrame; 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