@@ -2,24 +2,66 @@ import 'package:badgemagic/badge_animation/ani_left.dart';
2
2
import 'package:badgemagic/badge_animation/animation_abstract.dart' ;
3
3
import 'package:flutter/material.dart' ;
4
4
5
+ // Optional: shape enum, doesn't affect freehand
6
+ enum DrawShape { freehand, square, rectangle, circle, triangle }
7
+
5
8
class DrawBadgeProvider extends ChangeNotifier {
6
- //List that contains the state of each cell of the badge for draw view
9
+ // 11x44 LED grid, default all false (off)
7
10
List <List <bool >> _drawViewGrid =
8
11
List .generate (11 , (i) => List .generate (44 , (j) => false ));
9
12
10
- //getter for the drawViewGrid
13
+ // Drawing mode (true = draw, false = erase)
14
+ bool isDrawing = true ;
15
+
16
+ // Currently selected shape
17
+ DrawShape _selectedShape = DrawShape .freehand;
18
+
19
+ // Animation used in badge (not part of drawing)
20
+ BadgeAnimation currentAnimation = LeftAnimation ();
21
+
22
+ // Return the current grid
11
23
List <List <bool >> getDrawViewGrid () => _drawViewGrid;
12
24
13
- //setter for the drawViewGrid
14
- void setDrawViewGrid (int row, int col) {
15
- _drawViewGrid[row][col] = isDrawing;
25
+ // Return current drawing mode
26
+ bool getIsDrawing () => isDrawing;
27
+
28
+ // Return selected shape
29
+ DrawShape get selectedShape => _selectedShape;
30
+
31
+ // Toggle between drawing and erasing
32
+ void toggleIsDrawing (bool drawing) {
33
+ isDrawing = drawing;
16
34
notifyListeners ();
17
35
}
18
36
19
- BadgeAnimation currentAnimation = LeftAnimation ();
37
+ // Set selected shape
38
+ void setShape (DrawShape shape) {
39
+ _selectedShape = shape;
40
+ notifyListeners ();
41
+ }
42
+
43
+ // Set a single LED (used by gesture drawing)
44
+ void setDrawViewGrid (int row, int col) {
45
+ // Only allow grid update for freehand drawing
46
+ if (_selectedShape == DrawShape .freehand) {
47
+ if (row >= 0 &&
48
+ row < _drawViewGrid.length &&
49
+ col >= 0 &&
50
+ col < _drawViewGrid[0 ].length) {
51
+ _drawViewGrid[row][col] = isDrawing;
52
+ notifyListeners ();
53
+ }
54
+ }
55
+ }
20
56
57
+ // Reset the grid to all OFF
58
+ void resetDrawViewGrid () {
59
+ _drawViewGrid = List .generate (11 , (i) => List .generate (44 , (j) => false ));
60
+ notifyListeners ();
61
+ }
62
+
63
+ // Load a grid into the draw view
21
64
void updateDrawViewGrid (List <List <bool >> badgeData) {
22
- //copy the badgeData to the drawViewGrid and all the drawViewGrid after badgeData will remain unchanged
23
65
for (int i = 0 ; i < _drawViewGrid.length; i++ ) {
24
66
for (int j = 0 ; j < _drawViewGrid[0 ].length; j++ ) {
25
67
if (j < badgeData[0 ].length) {
@@ -31,22 +73,4 @@ class DrawBadgeProvider extends ChangeNotifier {
31
73
}
32
74
notifyListeners ();
33
75
}
34
-
35
- //function to reset the state of the cell
36
- void resetDrawViewGrid () {
37
- _drawViewGrid = List .generate (11 , (i) => List .generate (44 , (j) => false ));
38
- notifyListeners ();
39
- }
40
-
41
- //boolean variable to check for isDrawing on Draw badge screen
42
- bool isDrawing = true ;
43
-
44
- //function to toggle the isDrawing variable
45
- void toggleIsDrawing (bool drawing) {
46
- isDrawing = drawing;
47
- notifyListeners ();
48
- }
49
-
50
- //function to get the isDrawing variable
51
- bool getIsDrawing () => isDrawing;
52
76
}
0 commit comments