Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fwig changes #28

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/src/controllers/drawables/shape/oval_drawable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ class OvalDrawable extends Sized2DDrawable implements ShapeDrawable {
@override
void drawObject(Canvas canvas, Size size) {
final drawingSize = this.size * scale;
canvas.drawOval(
Rect.fromCenter(
center: position,
width: drawingSize.width,
height: drawingSize.height),
paint);
canvas.drawCircle(position, drawingSize.width / 2, paint);
// canvas.drawOval(
// Rect.fromCenter(
// center: position,
// width: drawingSize.width,
// height: drawingSize.height),
// paint);
}

/// Creates a copy of this but with the given fields replaced with the new values.
Expand Down Expand Up @@ -83,7 +84,7 @@ class OvalDrawable extends Sized2DDrawable implements ShapeDrawable {
@override
Size getSize({double minWidth = 0.0, double maxWidth = double.infinity}) {
final size = super.getSize();
return Size(size.width, size.height);
return Size(size.width, size.width);
}

/// Compares two [OvalDrawable]s for equality.
Expand Down
104 changes: 104 additions & 0 deletions lib/src/controllers/drawables/shape/polygon_drawable.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import 'dart:ui';

import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';

import '../object_drawable.dart';
import 'shape_drawable.dart';
import '../sized2ddrawable.dart';

/// A drawable of an oval.
class PolygonDrawable extends Sized2DDrawable implements ShapeDrawable {
/// The paint to be used for the line drawable.
@override
Paint paint;

/// Creates a new [PolygonDrawable] with the given [size] and [paint].
PolygonDrawable({
Paint? paint,
required Size size,
required Offset position,
double rotationAngle = 0,
double scale = 1,
Set<ObjectDrawableAssist> assists = const <ObjectDrawableAssist>{},
Map<ObjectDrawableAssist, Paint> assistPaints =
const <ObjectDrawableAssist, Paint>{},
bool locked = false,
bool hidden = false,
}) : paint = paint ?? ShapeDrawable.defaultPaint,
super(
size: size,
position: position,
rotationAngle: rotationAngle,
scale: scale,
assists: assists,
assistPaints: assistPaints,
locked: locked,
hidden: hidden);

/// Getter for padding of drawable.
///
/// Add padding equal to the stroke width of the paint.
@protected
@override
EdgeInsets get padding => EdgeInsets.all(paint.strokeWidth / 2);

/// Draws the arrow on the provided [canvas] of size [size].
@override
void drawObject(Canvas canvas, Size size) {
final drawingSize = this.size * scale;
canvas.drawCircle(position, 5, paint);
}

/// Creates a copy of this but with the given fields replaced with the new values.
@override
PolygonDrawable copyWith({
bool? hidden,
Set<ObjectDrawableAssist>? assists,
Offset? position,
double? rotation,
double? scale,
Size? size,
Paint? paint,
bool? locked,
}) {
return PolygonDrawable(
hidden: hidden ?? this.hidden,
assists: assists ?? this.assists,
position: position ?? this.position,
rotationAngle: rotation ?? rotationAngle,
scale: scale ?? this.scale,
size: size ?? this.size,
locked: locked ?? this.locked,
paint: paint ?? this.paint,
);
}

/// Calculates the size of the rendered object.
@override
Size getSize({double minWidth = 0.0, double maxWidth = double.infinity}) {
final size = super.getSize();
return Size(10, 10);
}

/// Compares two [PolygonDrawable]s for equality.
// @override
// bool operator ==(Object other) {
// return other is PolygonDrawable &&
// super == other &&
// other.paint == paint &&
// other.size == size;
// }
//
// @override
// int get hashCode => hashValues(
// hidden,
// locked,
// hashList(assists),
// hashList(assistPaints.entries),
// position,
// rotationAngle,
// scale,
// paint,
// size);
}
1 change: 1 addition & 0 deletions lib/src/controllers/drawables/shape/shape_drawables.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export 'shape_drawable.dart';
export 'line_drawable.dart';
export 'arrow_drawable.dart';
export 'rectangle_drawable.dart';
export 'polygon_drawable.dart';
export 'oval_drawable.dart';
export 'double_arrow_drawable.dart';
16 changes: 16 additions & 0 deletions lib/src/controllers/factories/polygon_factory.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'dart:ui';

import '../drawables/shape/polygon_drawable.dart';
import 'shape_factory.dart';

/// A [PolygonDrawable] factory.
class PolygonFactory extends ShapeFactory<PolygonDrawable> {
/// Creates an instance of [PolygonFactory].
PolygonFactory() : super();

/// Creates and returns a [PolygonDrawable] of zero size and the passed [position] and [paint].
@override
PolygonDrawable create(Offset position, [Paint? paint]) {
return PolygonDrawable(size: Size.zero, position: position, paint: paint);
}
}