add: VirtualDisplay

This commit is contained in:
Simon Hardt
2022-03-04 21:44:18 +01:00
parent 10c8a1fbf7
commit ae18232853
12 changed files with 261 additions and 36 deletions

View File

@@ -12,7 +12,8 @@ namespace frame::render
void RenderTarget::DrawPixel(Vector const& position, Color color)
{
if(position.x < 0 || position.y < 0 || position.x >= image.getWidth() || position.y > image.getHeight())
if(position.x < 0 || position.y < 0 || position.x >= image.getWidth()
|| position.y >= image.getHeight())
return;
image.at(position.x, position.y) = color;
}
@@ -85,7 +86,8 @@ namespace frame::render
while(pos.x <= radius / std::sqrt(2.f))
{
float E = pos.x * pos.x + ((float)pos.y + 0.5f) * ((float)pos.y + 0.5f) - r_2;
float E = pos.x * pos.x
+ ((float)pos.y + 0.5f) * ((float)pos.y + 0.5f) - r_2;
if(E <= 0)
{
@@ -104,23 +106,28 @@ namespace frame::render
}
}
void RenderTarget::DrawRectFilled(Vector const& LeftTop, Vector const& BottomRight, Color color)
void RenderTarget::DrawRectFilled(Vector const& LeftTop,
Vector const& BottomRight,
Color color)
{
auto pos = LeftTop;
auto pos = LeftTop;
while(pos.y <= BottomRight.y)
{
while(pos.x <= BottomRight.x)
{
DrawPixel(pos, color);
pos.x++;
}
pos.x = LeftTop.x;
pos.y++;
}
while(pos.y <= BottomRight.y)
{
while(pos.x <= BottomRight.x)
{
DrawPixel(pos, color);
pos.x++;
}
pos.x = LeftTop.x;
pos.y++;
}
}
void RenderTarget::DrawRect(Vector const& TopLeft, Vector const& BottomRight, uint8_t LineWidth, Color color)
void RenderTarget::DrawRect(Vector const& TopLeft,
Vector const& BottomRight,
uint8_t LineWidth,
Color color)
{
auto pos = TopLeft;
@@ -129,13 +136,15 @@ namespace frame::render
DrawRectFilled(TopLeft, {BottomRight.x, TopLeft.y + lw}, color);
DrawRectFilled({TopLeft.x, BottomRight.y - lw}, BottomRight);
DrawRectFilled({TopLeft.x , TopLeft.y + lw},
{TopLeft.x + lw, BottomRight.y - lw});
DrawRectFilled({BottomRight.x - lw, TopLeft.y + lw},
{BottomRight.x , BottomRight.y - lw});
DrawRectFilled({TopLeft.x, TopLeft.y + lw},
{TopLeft.x + lw, BottomRight.y - lw});
DrawRectFilled({BottomRight.x - lw, TopLeft.y + lw},
{BottomRight.x, BottomRight.y - lw});
}
void RenderTarget::DrawPointsMirrorCircle(Vector const& center, Vector const& pos, Color color)
void RenderTarget::DrawPointsMirrorCircle(Vector const& center,
Vector const& pos,
Color color)
{
DrawPixel(center + pos, color);
DrawPixel(center + Vector{pos.x, pos.y * -1}, color);