Skip to content

Commit 2ca8cc1

Browse files
feat: added a feature for shapes in draw clipart
1 parent 155006c commit 2ca8cc1

File tree

3 files changed

+371
-232
lines changed

3 files changed

+371
-232
lines changed

lib/providers/draw_badge_provider.dart

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,66 @@ import 'package:badgemagic/badge_animation/ani_left.dart';
22
import 'package:badgemagic/badge_animation/animation_abstract.dart';
33
import 'package:flutter/material.dart';
44

5+
// Optional: shape enum, doesn't affect freehand
6+
enum DrawShape { freehand, square, rectangle, circle, triangle }
7+
58
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)
710
List<List<bool>> _drawViewGrid =
811
List.generate(11, (i) => List.generate(44, (j) => false));
912

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
1123
List<List<bool>> getDrawViewGrid() => _drawViewGrid;
1224

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;
1634
notifyListeners();
1735
}
1836

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+
}
2056

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
2164
void updateDrawViewGrid(List<List<bool>> badgeData) {
22-
//copy the badgeData to the drawViewGrid and all the drawViewGrid after badgeData will remain unchanged
2365
for (int i = 0; i < _drawViewGrid.length; i++) {
2466
for (int j = 0; j < _drawViewGrid[0].length; j++) {
2567
if (j < badgeData[0].length) {
@@ -31,22 +73,4 @@ class DrawBadgeProvider extends ChangeNotifier {
3173
}
3274
notifyListeners();
3375
}
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;
5276
}

0 commit comments

Comments
 (0)