WiiUPluginLoaderBackend/source/utils/DrawUtils.h

93 lines
2.6 KiB
C
Raw Normal View History

#pragma once
#include "schrift.h"
#include <cstdint>
2024-08-09 19:43:11 +02:00
#include <functional>
// visible screen sizes
2022-02-04 16:25:44 +01:00
#define SCREEN_WIDTH 854
#define SCREEN_HEIGHT 480
2024-08-09 19:43:11 +02:00
#define COLOR_BACKGROUND Color(238, 238, 238, 255)
#define COLOR_BACKGROUND_WARN Color(255, 251, 4, 255)
#define COLOR_TEXT Color(51, 51, 51, 255)
#define COLOR_TEXT2 Color(72, 72, 72, 255)
#define COLOR_DISABLED Color(255, 0, 0, 255)
#define COLOR_BORDER Color(204, 204, 204, 255)
#define COLOR_BORDER_HIGHLIGHTED Color(0x3478e4FF)
#define COLOR_WHITE Color(0xFFFFFFFF)
#define COLOR_BLACK Color(0, 0, 0, 255)
#define COLOR_WARNING COLOR_BLACK
union Color {
2024-11-27 20:44:36 +01:00
explicit Color(const uint32_t color) {
2021-09-25 14:26:18 +02:00
this->color = color;
}
2021-09-25 14:26:18 +02:00
2024-11-27 20:44:36 +01:00
Color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a) {
2021-09-25 14:26:18 +02:00
this->r = r;
this->g = g;
this->b = b;
this->a = a;
}
uint32_t color{};
struct {
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
};
};
class DrawUtils {
public:
2021-09-25 14:26:18 +02:00
static void initBuffers(void *tvBuffer, uint32_t tvSize, void *drcBuffer, uint32_t drcSize);
static void beginDraw();
2021-09-25 14:26:18 +02:00
static void endDraw();
2021-09-25 14:26:18 +02:00
static void clear(Color col);
2021-09-25 14:26:18 +02:00
static void drawPixel(uint32_t x, uint32_t y, Color col) { drawPixel(x, y, col.r, col.g, col.b, col.a); }
2021-09-25 14:26:18 +02: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);
2021-09-25 14:26:18 +02:00
static void drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t borderSize, Color col);
2021-09-25 14:26:18 +02:00
static void drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32_t target_height, const uint8_t *data);
static void drawPNG(uint32_t x, uint32_t y, const uint8_t *data);
static bool initFont();
2021-09-25 14:26:18 +02:00
static void deinitFont();
2021-09-25 14:26:18 +02:00
static void setFontSize(uint32_t size);
2021-09-25 14:26:18 +02:00
static void setFontColor(Color col);
2021-09-25 14:26:18 +02:00
static void print(uint32_t x, uint32_t y, const char *string, bool alignRight = false);
static void print(uint32_t x, uint32_t y, const wchar_t *string, bool alignRight = false);
static uint32_t getTextWidth(const char *string);
static uint32_t getTextWidth(const wchar_t *string);
2024-08-09 19:43:11 +02:00
static void RenderScreen(const std::function<void()>& callback);
private:
2024-11-27 20:44:36 +01:00
static bool mIsBackBuffer;
static uint8_t *mTVBuffer;
static uint32_t mTVSize;
static uint8_t *mDRCBuffer;
static uint32_t mDRCSize;
static uint32_t mUsedTVWidth;
static float mUsedTVScale;
};