Skip to content

Commit

Permalink
Fix fillable shape to use its provided size
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake-Madden committed Sep 18, 2023
1 parent 1c6b102 commit 8bcf726
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
22 changes: 13 additions & 9 deletions src/base/fillableshape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ namespace Wisteria::GraphItems
assert(GetBrush().IsOk() && L"Fillable shape must have a valid brush!");
if (!GetBrush().IsOk())
{ return wxRect(); }
const auto drawArea = GetBoundingBox(dc);
auto bBox = GetBoundingBox(dc);
auto drawRect = wxRect(ScaleToScreenAndCanvas(m_shapeSizeDIPs));
// keep drawing area inside of the full area
drawRect.SetWidth(std::min(drawRect.GetWidth(), bBox.GetWidth()));
drawRect.SetHeight(std::min(drawRect.GetHeight(), bBox.GetHeight()));

// draw the full shape to a bitmap
wxBitmap bmp(drawArea.GetSize());
wxBitmap ghostedBmp(drawArea.GetSize());
wxBitmap bmp(drawRect.GetSize());
wxBitmap ghostedBmp(drawRect.GetSize());

// main image
{
Expand All @@ -33,7 +37,7 @@ namespace Wisteria::GraphItems
gdc.SetBrush(*wxTRANSPARENT_BRUSH);
gdc.Clear();

Shape::Draw(wxRect(drawArea.GetSize()), gdc);
Shape::Draw(wxRect(drawRect.GetSize()), gdc);
memDC.SelectObject(wxNullBitmap);
}
// ghosted image (brush is translucent, the pen remains the same to show an outline/skeleton of the shape)
Expand All @@ -49,21 +53,21 @@ namespace Wisteria::GraphItems
shapeInfo.GetBrush().GetStyle()));
Shape ghostShape(shapeInfo, GetShape(), GetSizeDIPS());

ghostShape.Draw(wxRect(drawArea.GetSize()), gdc);
ghostShape.Draw(wxRect(drawRect.GetSize()), gdc);
memDC.SelectObject(wxNullBitmap);
}

// if 100% "filled," then just draw the regular bitmap
if (compare_doubles_greater_or_equal(m_fillPercent, math_constants::full))
{
dc.DrawBitmap(bmp, drawArea.GetLeftTop(), true);
dc.DrawBitmap(bmp, drawRect.GetLeftTop(), true);
}
else
{
const auto yCutOff = bmp.GetHeight() * (math_constants::full - m_fillPercent);

ghostedBmp = ghostedBmp.GetSubBitmap(wxSize(bmp.GetWidth(), yCutOff));
dc.DrawBitmap(ghostedBmp, drawArea.GetLeftTop(), true);
dc.DrawBitmap(ghostedBmp, drawRect.GetLeftTop(), true);

// nothing to draw above the ghosted image if empty
if (compare_doubles_greater(m_fillPercent, math_constants::empty))
Expand All @@ -72,7 +76,7 @@ namespace Wisteria::GraphItems
wxRect(wxPoint(0, yCutOff),
wxSize(bmp.GetWidth(), bmp.GetHeight() * m_fillPercent)));
dc.DrawBitmap(filledBmp,
drawArea.GetLeftTop() + wxPoint(0, yCutOff), true);
drawRect.GetLeftTop() + wxPoint(0, yCutOff), true);
}
}

Expand All @@ -81,7 +85,7 @@ namespace Wisteria::GraphItems
{
wxDCBrushChanger bc(dc, *wxTRANSPARENT_BRUSH);
wxDCPenChanger pc(dc, wxPen(*wxBLACK, 2, wxPENSTYLE_DOT));
dc.DrawRectangle(drawArea);
dc.DrawRectangle(drawRect);
}

return wxRect(dc.GetSize());
Expand Down
5 changes: 3 additions & 2 deletions src/base/shapes.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ namespace Wisteria::GraphItems
/// @returns The renderer.
ShapeRenderer& GetRenderer() noexcept
{ return m_renderer; }
protected:
wxSize m_shapeSizeDIPs{ 0, 0 };
wxSize m_sizeDIPs{ 0, 0 };
private:
[[nodiscard]]
GraphItemInfo& GetGraphItemInfo() final
Expand All @@ -409,8 +412,6 @@ namespace Wisteria::GraphItems
bool HitTest(const wxPoint pt, wxDC& dc) const noexcept final
{ return GetBoundingBox(dc).Contains(pt); }

wxSize m_shapeSizeDIPs{ 0, 0 };
wxSize m_sizeDIPs{ 0, 0 };
Icons::IconShape m_shape;
mutable ShapeRenderer m_renderer;
mutable bool m_rendererNeedsUpdating{ true };
Expand Down

0 comments on commit 8bcf726

Please sign in to comment.