@@ -19,16 +19,13 @@ import 'package:cookethflow/features/models/canvas_models/user_cursor.dart';
1919import 'package:flutter/material.dart' ;
2020import 'package:path_drawing/path_drawing.dart' ;
2121
22-
2322class CanvasPainter extends CustomPainter {
2423 final Map <String , UserCursor > userCursors;
2524 final Map <String , CanvasObject > canvasObjects;
2625 final String ? currentlySelectedObjectId;
2726 final double handleRadius;
2827 final InteractionMode interactionMode;
29- final Color workspaceColor; // NEW: Added workspace color
30-
31- // NEW: Connector-related properties
28+ final Color workspaceColor;
3229 final double connectionPointRadius;
3330 final String ? connectorSourceId;
3431 final Alignment ? connectorSourceAlignment;
@@ -40,9 +37,7 @@ class CanvasPainter extends CustomPainter {
4037 this .currentlySelectedObjectId,
4138 this .handleRadius = 8.0 ,
4239 required this .interactionMode,
43- // NEW: Initialize workspace color
4440 required this .workspaceColor,
45- // NEW: Initialize connector properties
4641 this .connectionPointRadius = 6.0 ,
4742 this .connectorSourceId,
4843 this .connectorSourceAlignment,
@@ -152,7 +147,6 @@ class CanvasPainter extends CustomPainter {
152147 canvas.drawLine (startPoint, endPoint, paint);
153148 _drawArrowhead (canvas, startPoint, endPoint, paint);
154149
155- // NEW: Draw a circle at the start point
156150 final originPaint = Paint ()
157151 ..color = Colors .black87
158152 ..style = PaintingStyle .fill;
@@ -167,14 +161,12 @@ class CanvasPainter extends CustomPainter {
167161
168162 Rect rect;
169163
170- // ... (existing shape drawing logic remains the same)
171164 if (canvasObject is Circle ) {
172165 canvas.drawCircle (canvasObject.center, canvasObject.radius, fillPaint);
173166 rect =
174167 Rect .fromCircle (center: canvasObject.center, radius: canvasObject.radius);
175168 } else if (canvasObject is StickyNoteObject ) {
176169 rect = canvasObject.getBounds ();
177- // The image shows a darker, thinner border
178170 final double borderThickness = 2.0 ;
179171 final borderPaint = Paint ()
180172 ..color = Color .lerp (canvasObject.color, Colors .black, 0.3 )!
@@ -241,10 +233,8 @@ class CanvasPainter extends CustomPainter {
241233 final bodyRect = Rect .fromLTRB (rect.left,
242234 rect.top + ellipseHeight / 2 , rect.right, rect.bottom - ellipseHeight / 2 );
243235
244- // Draw body
245236 canvas.drawRect (bodyRect, fillPaint);
246237
247- // Draw ellipses
248238 final topEllipseRect = Rect .fromCenter (
249239 center: bodyRect.topCenter,
250240 width: rect.width,
@@ -257,7 +247,6 @@ class CanvasPainter extends CustomPainter {
257247 canvas.drawOval (topEllipseRect, fillPaint);
258248 canvas.drawOval (bottomEllipseRect, fillPaint);
259249
260- // Use the workspaceColor for the "hollow" border
261250 final borderPaint = Paint ()
262251 ..color = workspaceColor
263252 ..style = PaintingStyle .stroke
@@ -266,7 +255,6 @@ class CanvasPainter extends CustomPainter {
266255 }
267256 }
268257
269- // ... (existing text drawing logic remains the same)
270258 final bool isEditingText =
271259 interactionMode == InteractionMode .editingText &&
272260 currentlySelectedObjectId == canvasObject.id;
@@ -277,7 +265,7 @@ class CanvasPainter extends CustomPainter {
277265 final List <dynamic > delta = jsonDecode (canvasObject.textDelta! );
278266 double textPadding = 8.0 ;
279267 if (canvasObject is StickyNoteObject ) {
280- textPadding = 12.0 ; // Adjusted padding for the new sticky note style
268+ textPadding = 12.0 ;
281269 }
282270 double yOffset = rect.top + textPadding;
283271 final List <Map <String , dynamic >> lines = [];
@@ -351,13 +339,17 @@ class CanvasPainter extends CustomPainter {
351339 ...lineSpans
352340 ]),
353341 textDirection: TextDirection .ltr,
354- textAlign: TextAlign .start,
342+ textAlign: TextAlign .center, // Center-align text for all objects
355343 );
356344 final availableWidth = rect.width - (2 * textPadding) - indent;
357345 if (availableWidth > 0 ) {
358346 textPainter.layout (maxWidth: availableWidth);
359347 textPainter.paint (
360- canvas, Offset (rect.left + textPadding + indent, yOffset));
348+ canvas,
349+ Offset (
350+ rect.left + textPadding + indent + (availableWidth - textPainter.width) / 2 ,
351+ yOffset,
352+ ));
361353 yOffset += textPainter.height;
362354 }
363355 }
@@ -366,7 +358,6 @@ class CanvasPainter extends CustomPainter {
366358 }
367359 }
368360
369- // Draw resize handles and connection points for the selected object
370361 if (canvasObject.id == currentlySelectedObjectId && ! isEditingText) {
371362 final handlePaint = Paint ()
372363 ..color = Colors .blue
@@ -385,7 +376,6 @@ class CanvasPainter extends CustomPainter {
385376 dashPath (path, dashArray: CircularIntervalList <double >([5.0 , 3.0 ])),
386377 borderPaint);
387378
388- // NEW: Draw connection points for the selected object
389379 final connectionPointPaint = Paint ()
390380 ..color = Colors .white
391381 ..style = PaintingStyle .fill;
@@ -409,7 +399,6 @@ class CanvasPainter extends CustomPainter {
409399 }
410400 }
411401
412- // 3. Draw the temporary connector line while dragging
413402 if (interactionMode == InteractionMode .drawingConnector &&
414403 connectorSourceId != null &&
415404 connectorDragPosition != null ) {
@@ -433,7 +422,6 @@ class CanvasPainter extends CustomPainter {
433422 }
434423 }
435424
436- // 4. Draw user cursors on top of everything
437425 for (final userCursor in userCursors.values) {
438426 final position = userCursor.position;
439427 final paint = Paint ()
@@ -456,10 +444,9 @@ class CanvasPainter extends CustomPainter {
456444 oldPainter.canvasObjects.length != canvasObjects.length ||
457445 oldPainter.currentlySelectedObjectId != currentlySelectedObjectId ||
458446 oldPainter.interactionMode != interactionMode ||
459- oldPainter.workspaceColor != workspaceColor || // NEW: Added color check
447+ oldPainter.workspaceColor != workspaceColor ||
460448 _hasCanvasObjectsChanged (oldPainter.canvasObjects, canvasObjects) ||
461- oldPainter.connectorDragPosition !=
462- connectorDragPosition; // Add check for connector drag
449+ oldPainter.connectorDragPosition != connectorDragPosition;
463450 }
464451
465452 bool _hasCanvasObjectsChanged (
@@ -469,11 +456,9 @@ class CanvasPainter extends CustomPainter {
469456 final newObj = newObjects[id];
470457 final oldObj = oldObjects[id];
471458 if (oldObj == null || newObj == null ) return true ;
472- // Added color check for color updates
473459 if (newObj.color != oldObj.color) return true ;
474460 if (newObj.getBounds () != oldObj.getBounds ()) return true ;
475461 if (newObj.textDelta != oldObj.textDelta) return true ;
476- // Added a check for object type for shape changes
477462 if (newObj.runtimeType != oldObj.runtimeType) return true ;
478463 }
479464 return false ;
0 commit comments