Skip to content

Commit

Permalink
Fix various drawing issues with linear bar graphs
Browse files Browse the repository at this point in the history
Fixed un-filled linear bar graphs not properly drawn.
Added rendering of target line on linear bar graphs.
  • Loading branch information
ad3154 committed Nov 1, 2024
1 parent 5047f6e commit bfb9230
Showing 1 changed file with 60 additions and 2 deletions.
62 changes: 60 additions & 2 deletions src/OutputLinearBarGraphComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ OutputLinearBarGraphComponent::OutputLinearBarGraphComponent(std::shared_ptr<iso
void OutputLinearBarGraphComponent::paint(Graphics &g)
{
float valueRatioToMax = static_cast<float>(get_value()) / static_cast<float>(get_max_value());
float targetRatioToMax = static_cast<float>(get_target_value()) / static_cast<float>(get_max_value());
auto vtBackgroundColour = parentWorkingSet->get_colour(get_colour());
auto vtTargetLineColour = parentWorkingSet->get_colour(get_target_line_colour());
g.setColour(Colour::fromFloatRGBA(vtBackgroundColour.r, vtBackgroundColour.g, vtBackgroundColour.b, 1.0));

if (get_option(Options::DrawBorder))
{
g.drawRect(0, 0, getWidth(), getHeight(), 3);
}

if (isobus::NULL_OBJECT_ID != get_variable_reference())
{
auto child = get_object_by_id(get_variable_reference(), parentWorkingSet->get_object_tree());
Expand All @@ -42,22 +48,50 @@ void OutputLinearBarGraphComponent::paint(Graphics &g)
if (get_option(Options::Direction))
{
// From left
g.drawLine(static_cast<float>(get_width()) * valueRatioToMax, 0.0f, static_cast<float>(get_width()) * valueRatioToMax, static_cast<float>(get_height()), 3);

if (get_option(Options::DrawTargetLine))
{
g.setColour(Colour::fromFloatRGBA(vtTargetLineColour.r, vtTargetLineColour.g, vtTargetLineColour.b, 1.0));
g.drawVerticalLine(static_cast<float>(get_width()) * targetRatioToMax, 0.0f, static_cast<float>(get_height()));
}
}
else
{
// From right
g.drawLine(static_cast<float>(get_width()) * (1.0f - valueRatioToMax), 0.0f, static_cast<float>(get_width()) * (1.0f - valueRatioToMax), static_cast<float>(get_height()), 3);

if (get_option(Options::DrawTargetLine))
{
g.setColour(Colour::fromFloatRGBA(vtTargetLineColour.r, vtTargetLineColour.g, vtTargetLineColour.b, 1.0));
g.drawVerticalLine(static_cast<float>(get_width()) * (1.0f - targetRatioToMax), 0.0f, static_cast<float>(get_height()));
}
}
}
else
{
// Y Axis
if (get_option(Options::Direction))
{
// From left
// From bottom
g.drawLine(0, (1.0f - valueRatioToMax) * getHeight(), getWidth(), (1.0f - valueRatioToMax) * getHeight(), 3);

if (get_option(Options::DrawTargetLine))
{
g.setColour(Colour::fromFloatRGBA(vtTargetLineColour.r, vtTargetLineColour.g, vtTargetLineColour.b, 1.0));
g.drawHorizontalLine(static_cast<float>(get_height() * (1.0f - targetRatioToMax)), 0.0f, static_cast<float>(get_width()));
}
}
else
{
// From right
// From top
g.drawLine(0, valueRatioToMax * getHeight(), getWidth(), valueRatioToMax * getHeight(), 3);

if (get_option(Options::DrawTargetLine))
{
g.setColour(Colour::fromFloatRGBA(vtTargetLineColour.r, vtTargetLineColour.g, vtTargetLineColour.b, 1.0));
g.drawHorizontalLine(static_cast<float>(get_height() * targetRatioToMax), 0.0f, static_cast<float>(get_width()));
}
}
}
}
Expand All @@ -72,11 +106,23 @@ void OutputLinearBarGraphComponent::paint(Graphics &g)
{
// From left
g.fillRect(0.0f, 0.0f, static_cast<float>(get_width()) * valueRatioToMax, static_cast<float>(get_height()));

if (get_option(Options::DrawTargetLine))
{
g.setColour(Colour::fromFloatRGBA(vtTargetLineColour.r, vtTargetLineColour.g, vtTargetLineColour.b, 1.0));
g.drawVerticalLine(static_cast<float>(get_width()) * targetRatioToMax, 0.0f, static_cast<float>(get_height()));
}
}
else
{
// From right
g.fillRect(static_cast<float>(get_width()) * (1 - valueRatioToMax), 0.0f, static_cast<float>(get_width()) * valueRatioToMax, static_cast<float>(get_height()));

if (get_option(Options::DrawTargetLine))
{
g.setColour(Colour::fromFloatRGBA(vtTargetLineColour.r, vtTargetLineColour.g, vtTargetLineColour.b, 1.0));
g.drawVerticalLine(static_cast<float>(get_width()) * (1 - targetRatioToMax), 0.0f, static_cast<float>(get_height()));
}
}
}
else
Expand All @@ -86,11 +132,23 @@ void OutputLinearBarGraphComponent::paint(Graphics &g)
{
// From bottom
g.fillRect(0.0f, static_cast<float>(get_height() * (1 - valueRatioToMax)), static_cast<float>(get_width()), static_cast<float>(get_height()) * valueRatioToMax);

if (get_option(Options::DrawTargetLine))
{
g.setColour(Colour::fromFloatRGBA(vtTargetLineColour.r, vtTargetLineColour.g, vtTargetLineColour.b, 1.0));
g.drawHorizontalLine(static_cast<float>(get_height() * (1 - targetRatioToMax)), 0.0f, static_cast<float>(get_width()));
}
}
else
{
// From top
g.fillRect(0.0f, 0.0f, static_cast<float>(get_width()), static_cast<float>(get_height()) * valueRatioToMax);

if (get_option(Options::DrawTargetLine))
{
g.setColour(Colour::fromFloatRGBA(vtTargetLineColour.r, vtTargetLineColour.g, vtTargetLineColour.b, 1.0));
g.drawHorizontalLine(static_cast<float>(get_height() * targetRatioToMax), 0.0f, static_cast<float>(get_width()));
}
}
}
}
Expand Down

0 comments on commit bfb9230

Please sign in to comment.