Skip to content

Commit

Permalink
buttons and colors
Browse files Browse the repository at this point in the history
  • Loading branch information
richonguzman committed Nov 17, 2024
1 parent 89a2526 commit 44aa605
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 15 deletions.
21 changes: 21 additions & 0 deletions src/custom_colors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef CUSTOM_COLORS_H_
#define CUSTOM_COLORS_H_

#include <Arduino.h>


// COLORS https://rgbcolorpicker.com/565

uint16_t redColor = 0xc8a2;
uint16_t redColorLight = 0xd8c4;
uint16_t redColorDark = 0xa082;

uint16_t greyColor = 0x7BEF;
uint16_t greyColorLight = 0xBDF7;
uint16_t greyColorDark = 0x39E7;

uint16_t greenColor = 0x1482;
uint16_t greenColorLight = 0x1d63;
uint16_t greenColorDark = 0x0b22;

#endif
82 changes: 67 additions & 15 deletions src/display.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <logger.h>
#include <Wire.h>
#include "custom_characters.h"
#include "custom_colors.h"
#include "configuration.h"
#include "boards_pinout.h"
#include "display.h"
Expand All @@ -13,10 +14,10 @@
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite sprite = TFT_eSprite(&tft);

#define red 0xB061
int brightnessValues[6] = {70, 90, 120, 160, 200, 250};
int tftBrightness = 5;
unsigned short grays[13];

int brightnessValues[6] = {70, 90, 120, 160, 200, 250};
int tftBrightness = 5;
unsigned short grays[13];

#ifdef HELTEC_WIRELESS_TRACKER
#define bigSizeFont 2
Expand Down Expand Up @@ -80,28 +81,73 @@ bool symbolAvailable = true;

extern logging::Logger logger;

void drawButton(int xPos, int yPos, int wide, int height, String buttonText, int color) {
uint16_t baseColor, lightColor, darkColor;
switch (color) {
case 0: // Grey Theme
baseColor = greyColor;
lightColor = greyColorLight;
darkColor = greyColorDark;
break;
case 1: // Green Theme
baseColor = greenColor;
lightColor = greenColorLight;
darkColor = greenColorDark;
break;
case 2: // Red Theme
baseColor = redColor;
lightColor = redColorLight;
darkColor = redColorDark;
break;
default: // Fallback color
baseColor = 0x0000; // Black
lightColor = 0xFFFF; // White
darkColor = 0x0000; // Black
break;
}

sprite.fillRect(xPos, yPos, wide, height, baseColor); // Dibuja el fondo del botón
sprite.fillRect(xPos, yPos + height - 2, wide, 2, darkColor); // Línea inferior
sprite.fillRect(xPos, yPos, wide, 2, lightColor); // Línea superior
sprite.fillRect(xPos, yPos, 2, height, lightColor); // Línea izquierda
sprite.fillRect(xPos + wide - 2, yPos, 2, height, darkColor); // Línea derecha

sprite.setTextSize(2);
sprite.setTextColor(TFT_WHITE, baseColor);

// Calcula la posición del texto para que esté centrado
int textWidth = sprite.textWidth(buttonText); // Ancho del texto
int textHeight = 16; // Altura aproximada (depende de `setTextSize`)
int textX = xPos + (wide - textWidth) / 2; // Centrado horizontal
int textY = yPos + (height - textHeight) / 2; // Centrado vertical

sprite.drawString(buttonText, textX, textY);
}

#if defined(HAS_TFT) && (defined(TTGO_T_DECK_PLUS) || defined(TTGO_T_DECK_GPS))
void draw_T_DECK_Top(const String& header, const String& datetime, const String& location) {
sprite.fillSprite(TFT_BLACK);
sprite.fillRect(0, 0, 320, 38, red);
sprite.fillRect(0, 0, 320, 38, redColor);
sprite.setTextFont(0);
sprite.setTextSize(bigSizeFont);
sprite.setTextColor(TFT_WHITE, red);
sprite.setTextColor(TFT_WHITE, redColor);
sprite.drawString(currentBeacon->callsign, 3, 5);

sprite.setTextSize(smallSizeFont);
sprite.setTextColor(TFT_WHITE, red);
sprite.setTextColor(TFT_WHITE, redColor);
String date = datetime.substring(0, datetime.indexOf(" "));
sprite.drawString(date, 258, 5);
String time = datetime.substring(datetime.indexOf(" ") + 3);
sprite.drawString("UTC:" + time, 246, 15);

sprite.fillRect(0, 38, 320, 2, TFT_ORANGE);
sprite.fillRect(0, 38, 320, 2, redColorDark);//TFT_ORANGE);

sprite.fillRect(0, 40, 320, 22, TFT_DARKGREY);
sprite.fillRect(0, 40, 320, 2, greyColorLight);
sprite.fillRect(0, 42, 320, 20, greyColor);
sprite.setTextSize(2);
sprite.setTextColor(TFT_WHITE, TFT_DARKGREY);
sprite.setTextColor(TFT_WHITE, greyColor);
sprite.drawString(location, 8, 44);
sprite.fillRect(0, 60, 320, 2, greyColorDark);
}

void draw_T_DECK_Body(const String& line1, const String& line2, const String& line3, const String& line4, const String& line5, const String& line6) {
Expand All @@ -112,14 +158,20 @@ void draw_T_DECK_Body(const String& line1, const String& line2, const String& li
for (int i = 0; i < 6; i++) {
sprite.drawString(*lines[i], 3, 70 + (i * 20));
}

//drawButton(125, 210, 80, 28, "Menu", 0);

drawButton(30, 210, 80, 28, "Send", 1);
drawButton(125, 210, 80, 28, "Menu", 0);
drawButton(210, 210, 95, 28, "Cancel", 2);
}
#endif

//sprite.fillRect(0, 38, 320, 2, TFT_DARKGREY);
//sprite.fillRect(0, 20, 320, 2, color2); // linea bajo techo
//sprite.fillRect(0, 202, 320, 2, 0xBC81); // linea abajo amarilla

//sprite.fillSmoothRoundRect( 0, 218, 320, 22 , 2, red, TFT_BLACK); // piso
//sprite.fillSmoothRoundRect( 0, 218, 320, 22 , 2, redColor, TFT_BLACK); // piso

//sprite.fillSmoothRoundRect( 4, 2, 56, 14 , 2, grays[6], grays[9]); // cuadrado gris izquierda arriba
//sprite.fillSmoothRoundRect( 2, 2, 16, 14 , 2, TFT_BLUE, grays[9]); // cuadrado rojo izquierda arriba
Expand Down Expand Up @@ -280,10 +332,10 @@ void displayShow(const String& header, const String& line1, const String& line2,
#endif
#if defined(HELTEC_WIRELESS_TRACKER)
sprite.fillSprite(TFT_BLACK);
sprite.fillRect(0, 0, 160, 19, red);
sprite.fillRect(0, 0, 160, 19, redColor);
sprite.setTextFont(0);
sprite.setTextSize(bigSizeFont);
sprite.setTextColor(TFT_WHITE, red);
sprite.setTextColor(TFT_WHITE, redColor);
sprite.drawString(header, 3, 3);

const String* const lines[] = {&line1, &line2};
Expand Down Expand Up @@ -349,10 +401,10 @@ void displayShow(const String& header, const String& line1, const String& line2,
#endif
#if defined(HELTEC_WIRELESS_TRACKER)
sprite.fillSprite(TFT_BLACK);
sprite.fillRect(0, 0, 160, 19, red);
sprite.fillRect(0, 0, 160, 19, redColor);
sprite.setTextFont(0);
sprite.setTextSize(bigSizeFont);
sprite.setTextColor(TFT_WHITE, red);
sprite.setTextColor(TFT_WHITE, redColor);
sprite.drawString(header, 3, 3);

const String* const lines[] = {&line1, &line2, &line3, &line4, &line5};
Expand Down

0 comments on commit 44aa605

Please sign in to comment.