ELEC2645 (2018/19) / Mbed 2 deprecated el17ajf

Dependencies:   mbed

Fork of el17ajf by Angus Findlay

Revision:
26:baa7077449e7
Parent:
21:62d2b5b73160
Child:
27:2ed9e3c9f4e9
--- a/Menus/UI/UI.cpp	Thu Apr 04 15:53:06 2019 +0000
+++ b/Menus/UI/UI.cpp	Thu Apr 04 18:39:45 2019 +0000
@@ -1,5 +1,7 @@
 #include "UI.h"
 #include "Graphics.h"
+#include "Math.h"
+
 namespace Menus {
     UI::UI() {
         reset();
@@ -31,6 +33,8 @@
         nextY();
     }
     
+    int oldBorderX1,oldBorderY1, oldBorderX2, oldBorderY2;
+    
     bool UI::drawAndCheckButton(const char * text) {
         buttonCurrentlyDrawing++;
         
@@ -43,12 +47,20 @@
         int wordWidth = strlen(text) * (Graphics::UI::CHAR_WIDTH + Graphics::UI::CHAR_SPACE) - 1;
         
         if (selected) {
+            int borderX1 = PADDING_X - 2;
+            int borderY1 = y - 2;
+            int borderX2 = PADDING_X + wordWidth + 2;
+            int borderY2 = y + Graphics::UI::CHAR_HEIGHT + 1;
             Graphics::UI::drawBorder(
-                PADDING_X - 2,
-                y - 2,
-                PADDING_X + wordWidth + 2,
-                y + Graphics::UI::CHAR_HEIGHT + 1
+                Math::lerp(oldBorderX1, borderX1),
+                Math::lerp(oldBorderY1, borderY1),
+                Math::lerp(oldBorderX2, borderX2),
+                Math::lerp(oldBorderY2, borderY2)
             );
+            oldBorderX1 = Math::lerp(oldBorderX1, borderX1);
+            oldBorderY1 = Math::lerp(oldBorderY1, borderY1);
+            oldBorderX2 = Math::lerp(oldBorderX2, borderX2);
+            oldBorderY2 = Math::lerp(oldBorderY2, borderY2);
         }
     
         return buttonPressedFrame && selected;