PocketPutr/Desktop_Test/tft_handler.cpp
2026-01-17 11:13:34 +01:00

67 lines
2.0 KiB
C++

#include "GLOBALS.h"
#include "tft_handler.h"
#include <Arduino.h>
void TFT_Handler::init(DISPLAY_STATE* display_state) {
_display_state = display_state;
tft.setColorDepth(16);
tft.init();
tft.setRotation(3);
//tft.fillScreen(0x0000);
sprite.setColorDepth(16);
sprite.setPsram(true);
sprite.createSprite(480, 320);
sprite.fillScreen(0x0000);
}
void TFT_Handler::draw_box(short x, short y, short size_x, short size_y, short color) {
sprite.fillRect(x, y, size_x, size_y, color);
}
void TFT_Handler::draw_rect(short x, short y, short size_x, short size_y, short thickness, short color) {
sprite.drawRect(x, y, size_x, size_y, color);
}
void TFT_Handler::draw_line(short x1, short y1, short x2, short y2, short color) {
sprite.drawLine(x1, y1, x2, y2, color);
}
void TFT_Handler::draw_text(short x, short y, const std::string& str, short color, short size) {
sprite.setTextColor(color);
sprite.setTextSize(size);
sprite.drawString(str.c_str(), x, y);
}
void TFT_Handler::draw_button(short x, short y, short size_x, short size_y, short color, bool pressed, std::string str) {
if (pressed) {
sprite.fillRect(x - 2, y - 2, size_x + 2, size_y + 2, COL_BLACK);
sprite.fillRect(x - 1, y - 1, size_x + 1, size_y + 1, COL_DARK_GREY);
sprite.fillRect(x, y, size_x, size_y, color);
sprite.setTextColor(COL_BLACK);
sprite.setTextSize(1);
sprite.drawString(str.c_str(), x, y);
} else {
sprite.fillRect(x, y, size_x + 2, size_y + 2, COL_BLACK);
sprite.fillRect(x, y, size_x + 1, size_y + 1, COL_DARK_GREY);
sprite.fillRect(x, y, size_x, size_y, color);
sprite.setTextColor(COL_BLACK);
sprite.setTextSize(1);
sprite.drawString(str.c_str(), x, y);
}
}
void TFT_Handler::fill_screen(short color) {
sprite.fillScreen(color);
}
void TFT_Handler::push_sprite() {
sprite.pushSprite(0, 0);
}
void TFT_Handler::get_text_bounds(const std::string& str, short size, short& width, short& height) {
sprite.setTextSize(size);
width = sprite.textWidth(str.c_str());
height = sprite.fontHeight() * size;
}