From 4789fcfe8420e9cc9747dc71f7dadb9270a2e7b6 Mon Sep 17 00:00:00 2001 From: hsaturn Date: Tue, 13 Apr 2021 20:43:16 +0200 Subject: [PATCH 1/2] Vector media buttons Instead of having hard-coded coordinates, let's compute the coords. I was tired of seeing too large buttons for my 0.96 oled display. --- examples/graphicstest/graphicstest.ino | 41 ++++++++++++++------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/examples/graphicstest/graphicstest.ino b/examples/graphicstest/graphicstest.ino index d0a7a5e..b08d2da 100644 --- a/examples/graphicstest/graphicstest.ino +++ b/examples/graphicstest/graphicstest.ino @@ -338,23 +338,26 @@ void tftPrintTest() { tft.print(" seconds."); } -void mediabuttons() { - // play - tft.fillScreen(ST77XX_BLACK); - tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE); - tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED); - delay(500); - // pause - tft.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE); - tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN); - tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN); - delay(500); - // play color - tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE); - delay(50); - // pause color - tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED); - tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED); - // play color - tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN); +void mediabuttons() +{ + const int border = 6; // border around screen + const int margin = 14; // margin inside button + static int w = tft.width(); + static int h = tft.height(); + + const int bh = (h-3*border) / 2; // button height + const int bw = (w-2*border); // button width + const int br = 6; // border radius + + // Play button + tft.fillScreen(ST7735_BLACK); + tft.fillRoundRect(border, border, bw, bh, br, ST7735_WHITE); + tft.fillTriangle(border+margin, border+margin, border+margin, border+bh-margin, w-border-margin, border+bh/2, ST7735_RED); + + // Pause button + const int h2 = h/2; + const int barw = (bw-3*margin)/2; // bar width + tft.fillRoundRect(border, h2+border, bw, bh, br, ST7735_WHITE); + tft.fillRoundRect(border+margin, h2+border+margin, barw, bh-2*margin, br/2, ST7735_GREEN); + tft.fillRoundRect(border+margin+barw+margin, h2+border+margin, barw, bh-2*margin, br/2, ST7735_GREEN); } From ee39c98c8cdd905b1864fff2f7dd0a53ff4a7eee Mon Sep 17 00:00:00 2001 From: hsaturn Date: Tue, 13 Apr 2021 21:19:33 +0200 Subject: [PATCH 2/2] Update graphicstest.ino --- examples/graphicstest/graphicstest.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/graphicstest/graphicstest.ino b/examples/graphicstest/graphicstest.ino index b08d2da..51ec0f9 100644 --- a/examples/graphicstest/graphicstest.ino +++ b/examples/graphicstest/graphicstest.ino @@ -350,14 +350,14 @@ void mediabuttons() const int br = 6; // border radius // Play button - tft.fillScreen(ST7735_BLACK); - tft.fillRoundRect(border, border, bw, bh, br, ST7735_WHITE); - tft.fillTriangle(border+margin, border+margin, border+margin, border+bh-margin, w-border-margin, border+bh/2, ST7735_RED); + tft.fillScreen(ST77XX_BLACK); + tft.fillRoundRect(border, border, bw, bh, br, ST77XX_WHITE); + tft.fillTriangle(border+margin, border+margin, border+margin, border+bh-margin, w-border-margin, border+bh/2, ST77XX_RED); // Pause button const int h2 = h/2; const int barw = (bw-3*margin)/2; // bar width - tft.fillRoundRect(border, h2+border, bw, bh, br, ST7735_WHITE); - tft.fillRoundRect(border+margin, h2+border+margin, barw, bh-2*margin, br/2, ST7735_GREEN); - tft.fillRoundRect(border+margin+barw+margin, h2+border+margin, barw, bh-2*margin, br/2, ST7735_GREEN); + tft.fillRoundRect(border, h2+border, bw, bh, br, ST77XX_WHITE); + tft.fillRoundRect(border+margin, h2+border+margin, barw, bh-2*margin, br/2, ST77XX_GREEN); + tft.fillRoundRect(border+margin+barw+margin, h2+border+margin, barw, bh-2*margin, br/2, ST77XX_GREEN); }