@@ -5,24 +5,46 @@ class SnowFlakeAnimation extends BadgeAnimation {
55 void processAnimation (int badgeHeight, int badgeWidth, int animationIndex,
66 List <List <bool >> processGrid, List <List <bool >> canvas) {
77 int newWidth = processGrid[0 ].length;
8- int totalAnimationLength = badgeHeight * 16 ;
9- int frame = animationIndex % totalAnimationLength;
108
11- int horizontalOffset = (badgeWidth - newWidth) ~ / 2 ;
9+ bool isTextTooLong = newWidth > badgeWidth ;
1210
13- bool phase1 = frame < badgeHeight * 4 ;
14- bool phase2 = frame >= badgeHeight * 4 && frame < badgeHeight * 8 ;
11+ int totalPages = 1 ;
12+ int currentPage = 0 ;
13+ int startColOffset = 0 ;
14+ int horizontalOffset = 0 ;
15+
16+ if (isTextTooLong) {
17+ totalPages = (newWidth / badgeWidth).ceil ();
18+ if (totalPages == 0 ) totalPages = 1 ;
19+
20+ int singlePageDuration = badgeHeight * 8 ;
21+ currentPage = (animationIndex ~ / singlePageDuration) % totalPages;
22+ startColOffset = currentPage * badgeWidth;
23+ } else {
24+ horizontalOffset = (badgeWidth - newWidth) ~ / 2 ;
25+ }
26+
27+ int singlePageDuration = badgeHeight * 8 ;
28+ int localFrame = isTextTooLong
29+ ? (animationIndex % singlePageDuration)
30+ : (animationIndex % (badgeHeight * 16 ));
31+
32+ bool phase1 = localFrame < badgeHeight * 4 ;
33+ bool phase2 = localFrame >= badgeHeight * 4 && localFrame < badgeHeight * 8 ;
1534
1635 if (phase1) {
1736 for (int row = badgeHeight - 1 ; row >= 0 ; row-- ) {
18- int fallPosition = frame - (badgeHeight - 1 - row) * 2 ;
37+ int fallPosition = localFrame - (badgeHeight - 1 - row) * 2 ;
1938 int stoppingPosition = row;
2039 fallPosition =
2140 fallPosition >= stoppingPosition ? stoppingPosition : fallPosition;
2241
2342 if (fallPosition >= 0 && fallPosition < badgeHeight) {
2443 for (int col = 0 ; col < badgeWidth; col++ ) {
25- int sourceCol = col - horizontalOffset;
44+ int sourceCol = isTextTooLong
45+ ? (startColOffset + col)
46+ : (col - horizontalOffset);
47+
2648 bool isWithinNewGrid = sourceCol >= 0 && sourceCol < newWidth;
2749 if (isWithinNewGrid) {
2850 canvas[fallPosition][col] = processGrid[row][sourceCol];
@@ -34,11 +56,13 @@ class SnowFlakeAnimation extends BadgeAnimation {
3456 for (int row = badgeHeight - 1 ; row >= 0 ; row-- ) {
3557 int fallOutStartFrame = (badgeHeight - 1 - row) * 2 ;
3658 int fallOutPosition =
37- row + (frame - badgeHeight * 4 - fallOutStartFrame);
59+ row + (localFrame - badgeHeight * 4 - fallOutStartFrame);
3860
3961 if (fallOutPosition < row) {
4062 for (int col = 0 ; col < badgeWidth; col++ ) {
41- int sourceCol = col - horizontalOffset;
63+ int sourceCol = isTextTooLong
64+ ? (startColOffset + col)
65+ : (col - horizontalOffset);
4266 bool isWithinNewGrid = sourceCol >= 0 && sourceCol < newWidth;
4367 if (isWithinNewGrid) {
4468 canvas[row][col] = processGrid[row][sourceCol];
@@ -52,7 +76,9 @@ class SnowFlakeAnimation extends BadgeAnimation {
5276 }
5377
5478 for (int col = 0 ; col < badgeWidth; col++ ) {
55- int sourceCol = col - horizontalOffset;
79+ int sourceCol = isTextTooLong
80+ ? (startColOffset + col)
81+ : (col - horizontalOffset);
5682 bool isWithinNewGrid = sourceCol >= 0 && sourceCol < newWidth;
5783 if (isWithinNewGrid && fallOutPosition < badgeHeight) {
5884 canvas[fallOutPosition][col] = processGrid[row][sourceCol];
0 commit comments