123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- import 'dart:typed_data';
- import 'package:vid/us/vid_us_data_reader.dart';
- import 'package:vid/us/vid_us_data_writer.dart';
- import 'package:vid/us/vid_us_display_mode.dart';
- import 'package:vid/us/vid_us_logical_coordinate.dart';
- import 'package:vid/us/vid_us_mode.dart';
- import 'package:vid/us/vid_us_physical_coordinate.dart';
- import 'package:vid/us/vid_us_visual.dart';
- import 'package:vid/us/vid_us_visual_area_type.dart';
- import 'package:vid/us/vid_us_visual_indicator.dart';
- import 'package:vid/us/vid_us_visual_type.dart';
- class VidUs2DVisual extends VidUsVisual {
- late Map<VidUsVisualAreaType, VidUsLogicalCoordinate> _logicalCoordinates;
- late Map<VidUsVisualAreaType, VidUsPhysicalCoordinate> _physicalCoordinates;
- /// Get all LogicalCoordinates of this visual.
- Map<VidUsVisualAreaType, VidUsLogicalCoordinate> get logicalCoordinates =>
- _logicalCoordinates;
- ///Get all PhysicalCoordinates of this visual.
- Map<VidUsVisualAreaType, VidUsPhysicalCoordinate> get physicalCoordinates =>
- _physicalCoordinates;
- VidUs2DVisual() {
- setVisualType(VidUsVisualType.V2D);
- _logicalCoordinates =
- new Map<VidUsVisualAreaType, VidUsLogicalCoordinate>();
- _physicalCoordinates =
- new Map<VidUsVisualAreaType, VidUsPhysicalCoordinate>();
- }
- ///Convert VidUs2DVisual to binary data.
- @override
- Uint8List toBytes() {
- var writer = new VidUsDataWriter();
- var baseData = super.toBytes();
- writer.writeBytes(baseData);
- writer.writeByte(_physicalCoordinates.length);
- _physicalCoordinates.forEach((key, value) {
- writer.writeByte(key.index);
- writer.writeBytes(value.toBytes());
- });
- writer.writeByte(_logicalCoordinates.length);
- _logicalCoordinates.forEach((key, value) {
- writer.writeByte(key.index);
- writer.writeBytes(value.toBytes());
- });
- return writer.data;
- }
- ///Convert binary data to VidUs2DVisual.
- static VidUsVisual fromBytes(Uint8List bytes) {
- var reader = new VidUsDataReader(bytes);
- var visualType = VidUsVisualType.values[reader.readByte()];
- var displayMode = VidUsDisplayMode.values[reader.readByte()];
- if (visualType == VidUsVisualType.V2D) {
- var indicator = VidUsVisualIndicator.values[reader.readByte()];
- var activeModeType = VidUsModeType.values[reader.readByte()];
- var modeCount = reader.readByte();
- List<VidUsMode> modes = [];
- for (var i = 0; i < modeCount; i++) {
- var mode = VidUsMode.fromBytes(reader.readBytes());
- modes.add(mode);
- }
- var visual = new VidUs2DVisual();
- visual.setIndicator(indicator);
- modes.forEach((mode) {
- visual.modes.add(mode);
- });
- visual..setActiveModeType(activeModeType);
- var physicalCoordinateCount = reader.readByte();
- for (var i = 0; i < physicalCoordinateCount; i++) {
- var visualAreaType = VidUsVisualAreaType.values[reader.readByte()];
- var physicalCoordinate =
- VidUsPhysicalCoordinate.fromBytes(reader.readBytes());
- visual._physicalCoordinates[visualAreaType] = physicalCoordinate;
- }
- var logicalCoordinateCount = reader.readByte();
- for (var i = 0; i < logicalCoordinateCount; i++) {
- var visualAreaType = VidUsVisualAreaType.values[reader.readByte()];
- var logicalCoordinate =
- VidUsLogicalCoordinate.fromBytes(reader.readBytes());
- visual._logicalCoordinates[visualAreaType] = logicalCoordinate;
- }
- visual.setDisplayMode(displayMode);
- return visual;
- }
- throw new Exception(
- "Can not restore visual data from $visualType to VidUs2DVisual.");
- }
- }
|