Skip to content

Commit

Permalink
fix: rotate bitmaps over the correct corner (#200)
Browse files Browse the repository at this point in the history
* fix: rotate bitmaps over the correct corner

* BitmapPainter: Implement drawing of black/white bitmaps on black/white bitmaps
  • Loading branch information
richardapeters authored Oct 11, 2024
1 parent 384d2c3 commit 3ad1593
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
21 changes: 14 additions & 7 deletions preview/interfaces/BitmapPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,26 @@ namespace hal

void BitmapPainterCanonical::DrawBitmap(infra::Bitmap& bitmap, infra::Point position, const infra::Bitmap& sourceBitmap, infra::Region boundingBox)
{
assert(bitmap.pixelFormat == sourceBitmap.pixelFormat);
auto bitmapDestination = infra::Region(position, sourceBitmap.size);
auto boundedDestination = bitmapDestination & boundingBox;

if (!boundedDestination.Empty())
{
WaitUntilDrawingFinished();
for (auto y = boundedDestination.Top() - bitmapDestination.Top(); y != boundedDestination.Bottom() - bitmapDestination.Top(); ++y)
for (auto x = boundedDestination.Left() - bitmapDestination.Left(); x != boundedDestination.Right() - bitmapDestination.Left(); ++x)
{
auto colour = sourceBitmap.PixelColour(infra::Point(x, y));
DrawPixel(bitmap, bitmapDestination.TopLeft() + infra::Vector(x, y), colour);
}
if (bitmap.pixelFormat == infra::PixelFormat::blackandwhite)
for (auto y = boundedDestination.Top() - bitmapDestination.Top(); y != boundedDestination.Bottom() - bitmapDestination.Top(); ++y)
for (auto x = boundedDestination.Left() - bitmapDestination.Left(); x != boundedDestination.Right() - bitmapDestination.Left(); ++x)
{
bool colour = sourceBitmap.BlackAndWhitePixel(infra::Point(x, y));
DrawPixel(bitmap, bitmapDestination.TopLeft() + infra::Vector(x, y), colour);
}
else
for (auto y = boundedDestination.Top() - bitmapDestination.Top(); y != boundedDestination.Bottom() - bitmapDestination.Top(); ++y)
for (auto x = boundedDestination.Left() - bitmapDestination.Left(); x != boundedDestination.Right() - bitmapDestination.Left(); ++x)
{
auto colour = sourceBitmap.PixelColour(infra::Point(x, y));
DrawPixel(bitmap, bitmapDestination.TopLeft() + infra::Vector(x, y), colour);
}
}
}

Expand Down
9 changes: 5 additions & 4 deletions preview/views/ViewRotating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ namespace services
if (subView)
{
subView->ResetSize();
ResizeWithoutTrigger(infra::RotatedVectorInRegion(subView->ViewRegion().Size(), angle, rotatedRegion));
rotatedRegion = infra::RotatedRegionInRegion(subView->ViewRegion(), -angle, subView->ViewRegion());
ResizeWithoutTrigger(rotatedRegion.Size());
}
else
ResizeWithoutTrigger(infra::Vector());
Expand Down Expand Up @@ -125,17 +126,17 @@ namespace services

void ViewRotating::CanvasRotating::DrawBitmap(infra::Point position, const infra::Bitmap& sourceBitmap, infra::Region boundingBox)
{
canvas.DrawBitmap(Rotated(position), sourceBitmap, Rotated(boundingBox));
canvas.DrawBitmap(Rotated(infra::Region(position, sourceBitmap.size)).TopLeft(), sourceBitmap, Rotated(boundingBox));
}

void ViewRotating::CanvasRotating::DrawTransparentBitmap(infra::Point position, const infra::Bitmap& sourceBitmap, uint32_t transparencyColour, infra::Region boundingBox)
{
canvas.DrawTransparentBitmap(Rotated(position), sourceBitmap, transparencyColour, Rotated(boundingBox));
canvas.DrawTransparentBitmap(Rotated(infra::Region(position, sourceBitmap.size)).TopLeft(), sourceBitmap, transparencyColour, Rotated(boundingBox));
}

void ViewRotating::CanvasRotating::DrawIcon(infra::Point position, const infra::Bitmap& sourceBitmap, infra::Colour colour, infra::Region boundingBox)
{
canvas.DrawIcon(Rotated(position), sourceBitmap, colour, Rotated(boundingBox));
canvas.DrawIcon(Rotated(infra::Region(position, sourceBitmap.size)).TopLeft(), sourceBitmap, colour, Rotated(boundingBox));
}

void ViewRotating::CanvasRotating::DrawString(infra::Point position, infra::BoundedConstString string, const infra::Font& font, infra::Colour colour, infra::RightAngle direction, infra::Region boundingBox)
Expand Down

0 comments on commit 3ad1593

Please sign in to comment.