mirror of
https://onedev.site.tesses.net/tesses-framework/tessesframework-gfx
synced 2026-02-08 08:25:46 +00:00
65 lines
2.3 KiB
C++
65 lines
2.3 KiB
C++
#pragma once
|
|
#include "Color.hpp"
|
|
#include "Rectangle.hpp"
|
|
|
|
#include <vector>
|
|
namespace Tesses::Framework::Graphics {
|
|
class Font;
|
|
constexpr int32_t CharHeight = 16;
|
|
constexpr int64_t CharWidth = 16;
|
|
constexpr int32_t GetCharWidth(const int32_t chars)
|
|
{
|
|
return chars * 18;
|
|
}
|
|
enum class TextAlign {
|
|
TopLeft,
|
|
TopMiddle,
|
|
TopRight,
|
|
CenterLeft,
|
|
CenterMiddle,
|
|
CenterRight,
|
|
BottomLeft,
|
|
BottomMiddle,
|
|
BottomRight
|
|
};
|
|
enum class ImageCopyEffect {
|
|
Overwrite,
|
|
Invert,
|
|
InvertIfNotTransparent
|
|
};
|
|
enum class ScaleAlgorithm {
|
|
None,
|
|
NearestNeighbor
|
|
};
|
|
class Image {
|
|
uint32_t w=0;
|
|
uint32_t h=0;
|
|
std::vector<Color> data={};
|
|
void PlotLineLow(const Color& col, int32_t x1, int32_t y1, int32_t x2, int32_t y2);
|
|
void PlotLineHigh(const Color& col, int32_t x1, int32_t y1, int32_t x2, int32_t y2);
|
|
public:
|
|
Image();
|
|
Image(uint32_t w, uint32_t h);
|
|
Image(uint32_t w,uint32_t h,std::vector<Color> data);
|
|
uint32_t Width();
|
|
uint32_t Height();
|
|
void SetSize(uint32_t w, uint32_t h);
|
|
void SetSize(uint32_t w, uint32_t h, Color c);
|
|
void SetPixel(uint32_t x, uint32_t y, Color c);
|
|
Color GetPixel(uint32_t x, uint32_t y);
|
|
|
|
std::vector<Color>& Data();
|
|
|
|
void DrawRectangle(const Rectangle& rect, const Color& col, int borderSize=1);
|
|
void FillRectangle(const Rectangle& rect, const Color& col);
|
|
|
|
void DrawLine(const Point& pt1, const Point& pt2, const Color& col, int borderSize=1);
|
|
//text is 16x16
|
|
void DrawChar(char c, const Point& location, const Color& col);
|
|
void DrawString(std::string text, const Point& location, const Color& col);
|
|
//void RenderText(std::string text, const Font& font, const Color& col, const Point& loc);
|
|
//void RenderTextAligned(std::string text, const Font& font, const Color& col, const Rectangle& rect, TextAlign align);
|
|
void DrawImage(Image* src, const Point& pt, ImageCopyEffect copyEffect=ImageCopyEffect::Overwrite);
|
|
void Resize(Image* dest, const Size& sz, ScaleAlgorithm algo=ScaleAlgorithm::NearestNeighbor);
|
|
};
|
|
} |