EnvironmentLoader/source/utils/DrawUtils.h

87 lines
2.4 KiB
C
Raw Permalink Normal View History

#pragma once
2023-01-05 16:45:52 +01:00
#include "schrift.h"
#include <cstdint>
#define COLOR_WHITE Color(0xffffffff)
#define COLOR_BLACK Color(0, 0, 0, 255)
#define COLOR_RED Color(237, 28, 36, 255)
#define COLOR_BACKGROUND Color(0, 40, 100, 255)
#define COLOR_TEXT COLOR_WHITE
#define COLOR_TEXT2 Color(0xB3ffffff)
#define COLOR_AUTOBOOT Color(0xaeea00ff)
#define COLOR_BORDER Color(204, 204, 204, 255)
#define COLOR_BORDER_HIGHLIGHTED Color(0x3478e4ff)
// visible screen sizes
#define SCREEN_WIDTH 854
#define SCREEN_HEIGHT 480
union Color {
2023-01-05 16:45:52 +01:00
explicit Color(uint32_t color) {
this->color = color;
}
2023-01-05 16:45:52 +01:00
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
this->r = r;
this->g = g;
this->b = b;
this->a = a;
}
2023-01-05 16:45:52 +01:00
uint32_t color{};
struct {
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
};
};
class DrawUtils {
public:
static void initBuffers(void *tvBuffer, uint32_t tvSize, void *drcBuffer, uint32_t drcSize);
2023-01-05 16:45:52 +01:00
static void beginDraw();
2023-01-05 16:45:52 +01:00
static void endDraw();
2023-01-05 16:45:52 +01:00
static void clear(Color col);
2023-01-05 16:45:52 +01:00
static void drawPixel(uint32_t x, uint32_t y, Color col) { drawPixel(x, y, col.r, col.g, col.b, col.a); }
2023-01-05 16:45:52 +01:00
static void drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
static void drawRectFilled(uint32_t x, uint32_t y, uint32_t w, uint32_t h, Color col);
2023-01-05 16:45:52 +01:00
static void drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t borderSize, Color col);
static void drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32_t target_height, const uint8_t *data);
2023-01-05 16:45:52 +01:00
static void drawPNG(uint32_t x, uint32_t y, const uint8_t *data);
2023-01-05 16:45:52 +01:00
static bool initFont();
static void deinitFont();
2023-01-05 16:45:52 +01:00
static void setFontSize(uint32_t size);
2023-01-05 16:45:52 +01:00
static void setFontColor(Color col);
2023-01-05 16:45:52 +01:00
static void print(uint32_t x, uint32_t y, const char *string, bool alignRight = false);
2023-01-05 16:45:52 +01:00
static void print(uint32_t x, uint32_t y, const wchar_t *string, bool alignRight = false);
2023-01-05 16:45:52 +01:00
static uint32_t getTextWidth(const char *string);
2023-01-05 16:45:52 +01:00
static uint32_t getTextWidth(const wchar_t *string);
private:
static bool isBackBuffer;
static uint8_t *tvBuffer;
static uint32_t tvSize;
static uint8_t *drcBuffer;
static uint32_t drcSize;
};