Skip to content

Commit 513bfd1

Browse files
committed
feat: canvas objects border
1 parent 7a5990e commit 513bfd1

File tree

7 files changed

+47
-34
lines changed

7 files changed

+47
-34
lines changed

lib/features/models/canvas_models/canvas_object.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:convert';
22
import 'dart:math';
3+
import 'package:cookethflow/core/theme/colors.dart';
34
import 'package:cookethflow/features/models/canvas_models/objects/circle_object.dart';
45
import 'package:cookethflow/features/models/canvas_models/objects/connector_object.dart';
56
import 'package:cookethflow/features/models/canvas_models/objects/cylinder_object.dart';
@@ -17,7 +18,9 @@ import 'package:flutter/material.dart';
1718

1819
extension RandomColor on Color {
1920
static Color getRandom() {
20-
return Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
21+
final random = Random();
22+
final index = random.nextInt(secondaryColors.length);
23+
return secondaryColors[index];
2124
}
2225

2326
static Color getRandomFromUserId(String id) {

lib/features/models/canvas_models/canvas_painter.dart

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import 'package:cookethflow/features/models/canvas_models/user_cursor.dart';
1818
import 'package:flutter/material.dart';
1919
import 'package:path_drawing/path_drawing.dart';
2020

21+
2122
class CanvasPainter extends CustomPainter {
2223
final Map<String, UserCursor> userCursors;
2324
final Map<String, CanvasObject> canvasObjects;
@@ -44,7 +45,6 @@ class CanvasPainter extends CustomPainter {
4445
this.connectorDragPosition,
4546
});
4647

47-
// ... (_parseColor, _getFontSize, _getTextStyle methods remain the same)
4848
Color _parseColor(String? colorString) {
4949
if (colorString == null) return Colors.black;
5050
try {
@@ -158,12 +158,14 @@ class CanvasPainter extends CustomPainter {
158158

159159
// 2. Draw all shapes and their decorations
160160
for (final canvasObject in shapeObjects) {
161-
final paint = Paint()..color = canvasObject.color;
161+
final fillColor = canvasObject.color;
162+
final fillPaint = Paint()..color = fillColor;
163+
162164
Rect rect;
163165

164166
// ... (existing shape drawing logic remains the same)
165167
if (canvasObject is Circle) {
166-
canvas.drawCircle(canvasObject.center, canvasObject.radius, paint);
168+
canvas.drawCircle(canvasObject.center, canvasObject.radius, fillPaint);
167169
rect =
168170
Rect.fromCircle(center: canvasObject.center, radius: canvasObject.radius);
169171
} else if (canvasObject is StickyNoteObject) {
@@ -183,41 +185,40 @@ class CanvasPainter extends CustomPainter {
183185
} else if (canvasObject is TextBoxObject) {
184186
rect = canvasObject.getBounds();
185187
if (canvasObject.color != Colors.transparent) {
186-
canvas.drawRect(rect, paint);
188+
canvas.drawRect(rect, fillPaint);
187189
}
188190
} else {
189191
rect = canvasObject.getBounds();
190192
if (canvasObject is Rectangle) {
191-
canvas.drawRect(rect, paint);
193+
canvas.drawRect(rect, fillPaint);
192194
} else if (canvasObject is Square) {
193-
canvas.drawRect(rect, paint);
195+
canvas.drawRect(rect, fillPaint);
194196
} else if (canvasObject is RoundedSquare) {
195-
canvas.drawRRect(
196-
RRect.fromRectAndRadius(
197-
rect, Radius.circular(canvasObject.cornerRadius)),
198-
paint);
197+
final rrect = RRect.fromRectAndRadius(
198+
rect, Radius.circular(canvasObject.cornerRadius));
199+
canvas.drawRRect(rrect, fillPaint);
199200
} else if (canvasObject is Diamond) {
200201
final path = Path()
201202
..moveTo(rect.center.dx, rect.top)
202203
..lineTo(rect.right, rect.center.dy)
203204
..lineTo(rect.center.dx, rect.bottom)
204205
..lineTo(rect.left, rect.center.dy)
205206
..close();
206-
canvas.drawPath(path, paint);
207+
canvas.drawPath(path, fillPaint);
207208
} else if (canvasObject is Triangle) {
208209
final path = Path()
209210
..moveTo(rect.center.dx, rect.top)
210211
..lineTo(rect.right, rect.bottom)
211212
..lineTo(rect.left, rect.bottom)
212213
..close();
213-
canvas.drawPath(path, paint);
214+
canvas.drawPath(path, fillPaint);
214215
} else if (canvasObject is InvertedTriangle) {
215216
final path = Path()
216217
..moveTo(rect.left, rect.top)
217218
..lineTo(rect.right, rect.top)
218219
..lineTo(rect.center.dx, rect.bottom)
219220
..close();
220-
canvas.drawPath(path, paint);
221+
canvas.drawPath(path, fillPaint);
221222
} else if (canvasObject is Parallelogram) {
222223
final skew = rect.width * 0.25;
223224
final path = Path()
@@ -226,24 +227,34 @@ class CanvasPainter extends CustomPainter {
226227
..lineTo(rect.right - skew, rect.bottom)
227228
..lineTo(rect.left, rect.bottom)
228229
..close();
229-
canvas.drawPath(path, paint);
230+
canvas.drawPath(path, fillPaint);
230231
} else if (canvasObject is Cylinder) {
231232
final ellipseHeight = min(rect.height * 0.3, 40.0);
232233
final bodyRect = Rect.fromLTRB(rect.left,
233234
rect.top + ellipseHeight / 2, rect.right, rect.bottom - ellipseHeight / 2);
234-
canvas.drawRect(bodyRect, paint);
235-
canvas.drawOval(
236-
Rect.fromCenter(
237-
center: bodyRect.topCenter,
238-
width: rect.width,
239-
height: ellipseHeight),
240-
paint);
241-
canvas.drawOval(
242-
Rect.fromCenter(
243-
center: bodyRect.bottomCenter,
244-
width: rect.width,
245-
height: ellipseHeight),
246-
paint);
235+
236+
// Draw body
237+
canvas.drawRect(bodyRect, fillPaint);
238+
239+
// Draw ellipses
240+
final topEllipseRect = Rect.fromCenter(
241+
center: bodyRect.topCenter,
242+
width: rect.width,
243+
height: ellipseHeight);
244+
final bottomEllipseRect = Rect.fromCenter(
245+
center: bodyRect.bottomCenter,
246+
width: rect.width,
247+
height: ellipseHeight);
248+
249+
canvas.drawOval(topEllipseRect, fillPaint);
250+
canvas.drawOval(bottomEllipseRect, fillPaint);
251+
252+
// Draw the white line for the top of the cylinder
253+
final whitePaint = Paint()
254+
..color = Colors.white
255+
..style = PaintingStyle.stroke
256+
..strokeWidth = 2.0;
257+
canvas.drawOval(topEllipseRect, whitePaint);
247258
}
248259
}
249260

lib/features/models/canvas_models/objects/circle_object.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ class Circle extends CanvasObject {
9090
final newRadius = (max(newWidth, newHeight)) / 2;
9191
return copyWith(center: newCenter, radius: newRadius);
9292
}
93-
}
93+
}

lib/features/models/canvas_models/objects/cylinder_object.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,4 @@ class Cylinder extends CanvasObject {
9797
bottomRight: correctedBottomRight,
9898
);
9999
}
100-
}
100+
}

lib/features/models/canvas_models/objects/diamond_object.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'dart:math';
2-
32
import 'package:cookethflow/features/models/canvas_models/canvas_object.dart';
43
import 'package:flutter/material.dart';
54
import 'package:uuid/uuid.dart';
@@ -98,4 +97,4 @@ class Diamond extends CanvasObject {
9897
bottomRight: correctedBottomRight,
9998
);
10099
}
101-
}
100+
}

lib/features/models/canvas_models/objects/inverted_triangle_object.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,4 @@ class InvertedTriangle extends CanvasObject {
9797
bottomRight: correctedBottomRight,
9898
);
9999
}
100-
}
100+
}

lib/features/models/canvas_models/objects/parallelogram_object.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,4 @@ class Parallelogram extends CanvasObject {
9797
bottomRight: correctedBottomRight,
9898
);
9999
}
100-
}
100+
}

0 commit comments

Comments
 (0)