vtk-m/vtkm/rendering/ColorLegendAnnotation.cxx

75 lines
2.0 KiB
C++
Raw Normal View History

//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
2019-04-15 23:24:21 +00:00
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/rendering/ColorLegendAnnotation.h>
namespace vtkm
{
namespace rendering
{
ColorLegendAnnotation::ColorLegendAnnotation()
{
this->FontScale = 0.05f;
this->LabelColor = vtkm::rendering::Color::white;
}
void ColorLegendAnnotation::Clear()
{
this->Labels.clear();
this->ColorSwatchList.clear();
}
void ColorLegendAnnotation::AddItem(const std::string& label, vtkm::rendering::Color color)
{
this->Labels.push_back(label);
this->ColorSwatchList.push_back(color);
}
void ColorLegendAnnotation::Render(const vtkm::rendering::Camera& camera,
const vtkm::rendering::WorldAnnotator& annotator,
vtkm::rendering::Canvas& canvas)
{
vtkm::Float32 l = -0.95f, r = -0.90f;
vtkm::Float32 b = +0.90f, t = +0.95f;
2023-06-05 15:02:27 +00:00
for (auto& color : this->ColorSwatchList)
{
2023-06-05 15:02:27 +00:00
canvas.AddColorSwatch(l, b, l, t, r, t, r, b, color);
b -= 0.07f;
t -= 0.07f;
}
// reset positions
l = -0.95f;
r = -0.90f;
b = +0.90f;
t = +0.95f;
while (this->Annot.size() < this->Labels.size())
{
2023-06-05 17:20:49 +00:00
this->Annot.push_back(std::make_unique<TextAnnotationScreen>(
2023-06-05 19:08:38 +00:00
"test", this->LabelColor, this->FontScale, vtkm::Vec2f_32(0, 0)));
}
for (unsigned int i = 0; i < this->Annot.size(); ++i)
{
2018-04-03 13:26:00 +00:00
TextAnnotationScreen* txt = Annot[i].get();
txt->SetText(Labels[i]);
txt->SetPosition(r + .02f, (b + t) / 2.f);
txt->SetAlignment(TextAnnotationScreen::Left, TextAnnotationScreen::VCenter);
txt->Render(camera, annotator, canvas);
b -= 0.07f;
t -= 0.07f;
}
}
}
} // namespace vtkm::rendering