From ac4f9a6765eb04d7fe9cf1ef0374d97f2f1cf7fe Mon Sep 17 00:00:00 2001 From: Jhalakupadhyay Date: Mon, 9 Sep 2024 19:52:04 +0530 Subject: [PATCH] feat: Updated the code and created the right animation. --- lib/badge_animation/ani_right.dart | 32 +++++++++++++++++++++++++++ lib/badge_animation/anim_left.dart | 21 +++++++++--------- lib/providers/badgeview_provider.dart | 5 +++-- 3 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 lib/badge_animation/ani_right.dart diff --git a/lib/badge_animation/ani_right.dart b/lib/badge_animation/ani_right.dart new file mode 100644 index 000000000..2da0b7985 --- /dev/null +++ b/lib/badge_animation/ani_right.dart @@ -0,0 +1,32 @@ +import 'package:badgemagic/badge_animation/animation_abstract.dart'; + +class RightAnimation extends BadgeAnimation { + @override + void animation( + List> grid, + List> newGrid, + int animationIndex, + bool validMarquee, + bool flashLEDOn, + int currentcountFrame, + int i, + int j, + int newHeight, + int newWidth, + int badgeHeight, + int badgeWidth) { + // Calculate the scroll offset to move from left to right + int scrollOffset = animationIndex % (newWidth + badgeWidth); + + // Get the corresponding column in the new grid based on the reversed scroll position + int sourceCol = newWidth - scrollOffset + j; + + // If sourceCol is within bounds of the new grid, display it, else blank space + if (sourceCol >= 0 && sourceCol < newWidth) { + grid[i][j] = + validMarquee || flashLEDOn && newGrid[i % newHeight][sourceCol] == 1; + } else { + validMarquee ? grid[i][j] = true : grid[i][j] = false; + } + } +} diff --git a/lib/badge_animation/anim_left.dart b/lib/badge_animation/anim_left.dart index 6ed88a2b3..4b6869cfd 100644 --- a/lib/badge_animation/anim_left.dart +++ b/lib/badge_animation/anim_left.dart @@ -18,15 +18,16 @@ class LeftAnimation extends BadgeAnimation { // Calculate how much of the new grid is currently visible in the grid int scrollOffset = animationIndex % (newWidth + badgeWidth); - // Get the corresponding column in the new grid based on the scroll position - int sourceCol = j + scrollOffset - badgeWidth; - - // If sourceCol is negative, display blank space (off-screen part of the grid) - if (sourceCol >= 0 && sourceCol < newWidth) { - // Ensure flashLEDOn and validMarquee effects are applied - grid[i][j] = flashLEDOn && newGrid[i % newHeight][sourceCol] == 1; - } else { - grid[i][j] = false; - } + // Get the corresponding column in the new grid based on the scroll position + int sourceCol = j + scrollOffset - badgeWidth; + + // If sourceCol is negative, display blank space (off-screen part of the grid) + if (sourceCol >= 0 && sourceCol < newWidth) { + // Ensure flashLEDOn and validMarquee effects are applied + grid[i][j] = + validMarquee || flashLEDOn && newGrid[i % newHeight][sourceCol] == 1; + } else { + validMarquee ? grid[i][j] = true : grid[i][j] = false; + } } } diff --git a/lib/providers/badgeview_provider.dart b/lib/providers/badgeview_provider.dart index dc6e27625..6453a174a 100644 --- a/lib/providers/badgeview_provider.dart +++ b/lib/providers/badgeview_provider.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:badgemagic/bademagic_module/utils/byte_array_utils.dart'; +import 'package:badgemagic/badge_animation/ani_right.dart'; import 'package:badgemagic/badge_animation/anim_left.dart'; import 'package:badgemagic/badge_animation/animation_abstract.dart'; import 'package:badgemagic/constants.dart'; @@ -62,7 +63,7 @@ class DrawBadgeProvider extends ChangeNotifier { //function to calculate duration for the animation void calculateDuration() { - int newSpeed = aniSpeedStrategy(cardData.getOuterValue()-1); + int newSpeed = aniSpeedStrategy(cardData.getOuterValue() - 1); if (newSpeed != animationSpeed) { animationSpeed = newSpeed; timer?.cancel(); @@ -119,7 +120,7 @@ class DrawBadgeProvider extends ChangeNotifier { currentAnimation = LeftAnimation(); break; case 1: - // currentAnimation = RightAnimation(); + currentAnimation = RightAnimation(); break; case 2: // currentAnimation = UpAnimation();