renderbase impl
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
#include "Plottable_Real_Time_Data.h"
|
||||
#include "Heatmap_Utils.h"
|
||||
#include "../render/Blend2D_Cache.h"
|
||||
#include "../renderable/Renderable_p.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <optional>
|
||||
namespace renderive {
|
||||
namespace detail {
|
||||
namespace {
|
||||
@@ -19,7 +21,7 @@ RectF axis_content_rect(const Axis_Transform& first, const Axis_Transform& secon
|
||||
return mapped_rect(first, second, first.coordinate_range, second.coordinate_range);
|
||||
}
|
||||
}
|
||||
struct Selection_Rectangle_Overlay_Control::Impl {
|
||||
struct Selection_Rectangle_Overlay_Control::Impl : Renderable::Impl {
|
||||
struct Prepared_Region {
|
||||
RectF pixels;
|
||||
std::string label;
|
||||
@@ -29,34 +31,40 @@ struct Selection_Rectangle_Overlay_Control::Impl {
|
||||
RectF active_selection;
|
||||
bool selecting{};
|
||||
};
|
||||
Impl(Selection_Rectangle_Overlay_Control& owner, renderive_Owner<Abs_Axis> horizontal, renderive_Owner<Abs_Axis> vertical)
|
||||
: horizontal_axis(std::move(horizontal)), vertical_axis(std::move(vertical)), regions(owner) {}
|
||||
Impl(renderive_Owner<Abs_Axis> horizontal,
|
||||
renderive_Owner<Abs_Axis> vertical)
|
||||
: horizontal_axis(std::move(horizontal)),
|
||||
vertical_axis(std::move(vertical)) {}
|
||||
renderive_Owner<Abs_Axis> horizontal_axis;
|
||||
renderive_Owner<Abs_Axis> vertical_axis;
|
||||
Plottable_History_Real_Time_Data<RectF, std::vector<RectF>> regions;
|
||||
std::optional<Plottable_History_Real_Time_Data<RectF,
|
||||
std::vector<RectF>>> regions;
|
||||
Selection_Interaction_State interaction;
|
||||
Prepare_Buffer prepare_buffer;
|
||||
};
|
||||
Selection_Rectangle_Overlay_Control::Selection_Rectangle_Overlay_Control(const Selection_Rectangle_Overlay_Properties& properties, renderive_Owner<Abs_Axis> horizontal_axis, renderive_Owner<Abs_Axis> vertical_axis)
|
||||
: Plottable_State(properties), impl_(std::make_unique<Impl>(*this, std::move(horizontal_axis), std::move(vertical_axis))) {}
|
||||
: Plottable_State(properties, std::make_unique<Impl>(
|
||||
std::move(horizontal_axis), std::move(vertical_axis))) {
|
||||
d_func<Impl>().regions.emplace(*this);
|
||||
}
|
||||
Selection_Rectangle_Overlay_Control::~Selection_Rectangle_Overlay_Control() = default;
|
||||
std::vector<RectF> Selection_Rectangle_Overlay_Control::selected_regions() const {
|
||||
return impl_->regions.snapshot();
|
||||
return d_func<Impl>().regions->snapshot();
|
||||
}
|
||||
void Selection_Rectangle_Overlay_Control::clear_selected_regions() {
|
||||
impl_->regions.clear();
|
||||
impl_->interaction.update([](Selection_Interaction& interaction) {
|
||||
d_func<Impl>().regions->clear();
|
||||
d_func<Impl>().interaction.update([](Selection_Interaction& interaction) {
|
||||
interaction.selecting = false;
|
||||
});
|
||||
changed();
|
||||
}
|
||||
void Selection_Rectangle_Overlay_Control::handle_event(const Event& event) {
|
||||
const RectF content = axis_content_rect(impl_->horizontal_axis->transform(), impl_->vertical_axis->transform());
|
||||
const RectF content = axis_content_rect(d_func<Impl>().horizontal_axis->transform(), d_func<Impl>().vertical_axis->transform());
|
||||
if(event.type == Event_Type::Pointer_Press) {
|
||||
const auto& pointer = static_cast<const Pointer_Event&>(event);
|
||||
if(pointer.button != Mouse_Button::Left || !content.contains(pointer.position))
|
||||
return;
|
||||
impl_->interaction.update([&](Selection_Interaction& interaction) {
|
||||
d_func<Impl>().interaction.update([&](Selection_Interaction& interaction) {
|
||||
interaction.selecting = true;
|
||||
interaction.selection_start = interaction.selection_current = pointer.position;
|
||||
});
|
||||
@@ -67,7 +75,7 @@ void Selection_Rectangle_Overlay_Control::handle_event(const Event& event) {
|
||||
if(event.type == Event_Type::Pointer_Move) {
|
||||
const auto& pointer = static_cast<const Pointer_Event&>(event);
|
||||
bool selecting{};
|
||||
impl_->interaction.update([&](Selection_Interaction& interaction) {
|
||||
d_func<Impl>().interaction.update([&](Selection_Interaction& interaction) {
|
||||
selecting = interaction.selecting;
|
||||
if(selecting)
|
||||
interaction.selection_current = pointer.position;
|
||||
@@ -83,7 +91,7 @@ void Selection_Rectangle_Overlay_Control::handle_event(const Event& event) {
|
||||
const auto& pointer = static_cast<const Pointer_Event&>(event);
|
||||
PointF start;
|
||||
bool selecting{};
|
||||
impl_->interaction.update([&](Selection_Interaction& interaction) {
|
||||
d_func<Impl>().interaction.update([&](Selection_Interaction& interaction) {
|
||||
selecting = interaction.selecting;
|
||||
if(!selecting)
|
||||
return;
|
||||
@@ -93,32 +101,32 @@ void Selection_Rectangle_Overlay_Control::handle_event(const Event& event) {
|
||||
});
|
||||
if(!selecting)
|
||||
return;
|
||||
const Axis_Transform horizontal = impl_->horizontal_axis->transform();
|
||||
const Axis_Transform vertical = impl_->vertical_axis->transform();
|
||||
const Axis_Transform horizontal = d_func<Impl>().horizontal_axis->transform();
|
||||
const Axis_Transform vertical = d_func<Impl>().vertical_axis->transform();
|
||||
const double first_start = horizontal.point_to_coord(start);
|
||||
const double second_start = vertical.point_to_coord(start);
|
||||
const RectF region{first_start, second_start,
|
||||
horizontal.point_to_coord(pointer.position) - first_start,
|
||||
vertical.point_to_coord(pointer.position) - second_start};
|
||||
if(std::abs(region.width) > 1e-9 && std::abs(region.height) > 1e-9)
|
||||
impl_->regions.update(region.normalized());
|
||||
d_func<Impl>().regions->update(region.normalized());
|
||||
event.accept();
|
||||
changed();
|
||||
}
|
||||
void Selection_Rectangle_Overlay_Control::publish() {
|
||||
publish_properties();
|
||||
impl_->interaction.publish();
|
||||
d_func<Impl>().interaction.publish();
|
||||
}
|
||||
void Selection_Rectangle_Overlay_Control::prepare_frame(
|
||||
const Prepare_Render_Context& context) {
|
||||
const auto& view = context.frame.render_state;
|
||||
const auto& state = render_properties(view);
|
||||
const auto& interaction = view.get(impl_->interaction);
|
||||
const auto horizontal = impl_->horizontal_axis->transform(view);
|
||||
const auto vertical = impl_->vertical_axis->transform(view);
|
||||
auto& output = impl_->prepare_buffer;
|
||||
const auto& interaction = view.get(d_func<Impl>().interaction);
|
||||
const auto horizontal = d_func<Impl>().horizontal_axis->transform(view);
|
||||
const auto vertical = d_func<Impl>().vertical_axis->transform(view);
|
||||
auto& output = d_func<Impl>().prepare_buffer;
|
||||
output = {};
|
||||
for (const RectF& region : view.get(impl_->regions)) {
|
||||
for (const RectF& region : view.get(*d_func<Impl>().regions)) {
|
||||
const RectF pixels = mapped_rect(horizontal, vertical,
|
||||
{region.x, region.right()},
|
||||
{region.y, region.bottom()});
|
||||
@@ -135,7 +143,7 @@ void Selection_Rectangle_Overlay_Control::prepare_frame(
|
||||
}
|
||||
void Selection_Rectangle_Overlay_Control::paint(
|
||||
Painter& painter, const Paint_Render_Context& context) {
|
||||
const auto& output = impl_->prepare_buffer;
|
||||
const auto& output = d_func<Impl>().prepare_buffer;
|
||||
const auto& view = context.frame.render_state;
|
||||
const auto& state = render_properties(view);
|
||||
for (const auto& region : output.regions) {
|
||||
|
||||
Reference in New Issue
Block a user