mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Update the raw examples to handle PointerPacket events
This commit is contained in:
parent
b1435e2973
commit
c94e4c4154
@ -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) {
|
|||||||
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);
|
|
||||||
ui.window.scheduleFrame();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.type == 'pointerup') {
|
|
||||||
color = new ui.Color.fromARGB(255, 0, 255, 0);
|
|
||||||
ui.window.scheduleFrame();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.type == 'back') {
|
|
||||||
print('Pressed back button.');
|
print('Pressed back button.');
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
void handlePointerPacket(ByteData serializedPacket) {
|
||||||
|
bindings.Message message = new bindings.Message(
|
||||||
|
serializedPacket, <core.MojoHandle>[]);
|
||||||
|
PointerPacket packet = PointerPacket.deserialize(message);
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
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;
|
|||||||
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) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
imageCache.load(url2).first.then(handleImageLoad);
|
if (pointer.type == PointerType.UP) {
|
||||||
return true;
|
imageCache.load(url2).first.then(handleImageLoad);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user