mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-28 07:39:36 +08:00
ImageModel
This commit is contained in:
parent
63930918f6
commit
0d4c85b3df
@ -7,6 +7,7 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
class RgbaFrame extends Struct {
|
||||
@Uint32()
|
||||
@ -50,6 +51,17 @@ class FfiModel with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
class ImageModel with ChangeNotifier {
|
||||
ui.Image _image;
|
||||
|
||||
ui.Image get image => _image;
|
||||
|
||||
void update(ui.Image image) {
|
||||
_image = image;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
class FFI {
|
||||
static F1 _freeCString;
|
||||
static F2 _getByName;
|
||||
@ -57,6 +69,8 @@ class FFI {
|
||||
static F4 _freeRgba;
|
||||
static F5 _getRgba;
|
||||
static Pointer<RgbaFrame> _lastRgbaFrame;
|
||||
static final imageModel = ImageModel();
|
||||
static final ffiModel = FfiModel();
|
||||
|
||||
static String getId() {
|
||||
return getByName('remote_id');
|
||||
@ -115,6 +129,7 @@ class FFI {
|
||||
|
||||
static void close() {
|
||||
setByName('close', '');
|
||||
FFI.imageModel.update(null);
|
||||
}
|
||||
|
||||
static void setByName(String name, String value) {
|
||||
|
@ -10,16 +10,17 @@ void main() {
|
||||
class App extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var ffi = FfiModel();
|
||||
return ChangeNotifierProvider.value(
|
||||
value: ffi,
|
||||
child: MaterialApp(
|
||||
title: 'RustDesk',
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.blue,
|
||||
visualDensity: VisualDensity.adaptivePlatformDensity,
|
||||
),
|
||||
home: HomePage(title: 'RustDesk'),
|
||||
));
|
||||
value: FFI.ffiModel,
|
||||
child: ChangeNotifierProvider.value(
|
||||
value: FFI.imageModel,
|
||||
child: MaterialApp(
|
||||
title: 'RustDesk',
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.blue,
|
||||
visualDensity: VisualDensity.adaptivePlatformDensity,
|
||||
),
|
||||
home: HomePage(title: 'RustDesk'),
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'common.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'dart:ui' as ui;
|
||||
@ -18,7 +19,6 @@ class RemotePage extends StatefulWidget {
|
||||
// https://github.com/hanxu317317/flutter_plan_demo/blob/master/lib/src/enter.dart
|
||||
class _RemotePageState extends State<RemotePage> {
|
||||
Timer _interval;
|
||||
ui.Image _image;
|
||||
PeerInfo _pi = PeerInfo();
|
||||
Display _display = Display();
|
||||
bool _decoding = false;
|
||||
@ -64,13 +64,11 @@ class _RemotePageState extends State<RemotePage> {
|
||||
_decoding = true;
|
||||
ui.decodeImageFromPixels(
|
||||
rgba, _display.width, _display.height, ui.PixelFormat.bgra8888,
|
||||
(__image) {
|
||||
(image) {
|
||||
FFI.clearRgbaFrame();
|
||||
if (_decoding == null) return;
|
||||
_decoding = false;
|
||||
setState(() {
|
||||
_image = __image;
|
||||
});
|
||||
FFI.imageModel.update(image);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -133,17 +131,23 @@ class _RemotePageState extends State<RemotePage> {
|
||||
onInteractionUpdate: (details) {
|
||||
print("$details");
|
||||
},
|
||||
child: Container(
|
||||
child: CustomPaint(
|
||||
painter: new ImageEditor(image: _image),
|
||||
),
|
||||
color: MyTheme.grayBg),
|
||||
child: Container(child: ImagePaint(), color: MyTheme.grayBg),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
class ImageEditor extends CustomPainter {
|
||||
ImageEditor({
|
||||
class ImagePaint extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final m = Provider.of<ImageModel>(context);
|
||||
return CustomPaint(
|
||||
painter: new ImagePainter(image: m.image),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ImagePainter extends CustomPainter {
|
||||
ImagePainter({
|
||||
this.image,
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user