#include "Selection_Rectangle_Overlay_p.h" #include "../base/Memory.h" namespace renderive { RENDERIVE_DEFINE_RENDERABLE_BINDING(Selection_Rectangle_Overlay, Selection_Rectangle_Overlay_Private, Selection_Rectangle_Overlay_Render_State, Selection_Rectangle_Overlay_Input_Data, "Selection_Rectangle_Overlay") Selection_Rectangle_Overlay::Builder::Builder(std::shared_ptr parent, std::shared_ptr key_axis, std::shared_ptr value_axis) { ASSERT(parent && parent->attached_to_plot(), "Selection_Rectangle_Overlay build error! parent invalid"); ASSERT(key_axis && value_axis, "Selection_Rectangle_Overlay build error! axis == nullptr"); ASSERT(key_axis->attached_to_plot(), "Selection_Rectangle_Overlay build error! key_axis->plot == nullptr"); ASSERT(key_axis->shares_plot_with(*value_axis), "Selection_Rectangle_Overlay build error! key_axis->plot != value_axis->plot"); ASSERT(parent->shares_plot_with(*key_axis), "Selection_Rectangle_Overlay build error! parent->plot != key_axis->plot"); ASSERT(key_axis->orientation() != value_axis->orientation(), "Selection_Rectangle_Overlay build error! axes must be orthogonal"); this->parent = parent; this->domain_axis = key_axis; this->value_axis = value_axis; } std::shared_ptr Selection_Rectangle_Overlay::Builder::build() { auto ret = renderive::make_shared(); ret->init(parent); Selection_Rectangle_Overlay_Private* pd = ret->d(); Render_Edit_Lease edit(pd); Selection_Rectangle_Overlay_Render_State* sc = edit.operator->(); sc->horizontal_axis = domain_axis; sc->vertical_axis = value_axis; sc->label_font = font; sc->label_pen = font_pen; sc->selection_brush = rect_brush; sc->selection_border_pen = border_pen; return ret; } void Selection_Rectangle_Overlay::set_horizontal_axis(std::shared_ptr axis) { Selection_Rectangle_Overlay_Private* pd = d(); Render_Edit_Lease edit(pd); edit->horizontal_axis = std::weak_ptr(axis); pd->invalidate_interaction_mapping(); } void Selection_Rectangle_Overlay::set_vertical_axis(std::shared_ptr axis) { Selection_Rectangle_Overlay_Private* pd = d(); Render_Edit_Lease edit(pd); edit->vertical_axis = std::weak_ptr(axis); pd->invalidate_interaction_mapping(); } Font Selection_Rectangle_Overlay::label_font() { return d()->edit_state_value(&Selection_Rectangle_Overlay_Render_State::label_font); } Pen Selection_Rectangle_Overlay::label_pen() { return d()->edit_state_value(&Selection_Rectangle_Overlay_Render_State::label_pen); } Brush Selection_Rectangle_Overlay::selection_brush() { return d()->edit_state_value(&Selection_Rectangle_Overlay_Render_State::selection_brush); } Pen Selection_Rectangle_Overlay::selection_border_pen() { return d()->edit_state_value(&Selection_Rectangle_Overlay_Render_State::selection_border_pen); } void Selection_Rectangle_Overlay::set_label_font(const Font& font) { Render_Edit_Lease edit(d()); edit->label_font = font; } void Selection_Rectangle_Overlay::set_label_pen(const Pen& pen) { Render_Edit_Lease edit(d()); edit->label_pen = pen.color.a != 0 ? pen : Pen{.style = Line_Style::None}; } void Selection_Rectangle_Overlay::set_selection_brush(const Brush& brush) { Render_Edit_Lease edit(d()); edit->selection_brush = brush.color.a != 0 ? brush : Brush{}; } void Selection_Rectangle_Overlay::set_selection_border_pen(const Pen& pen) { Render_Edit_Lease edit(d()); edit->selection_border_pen = pen.color.a != 0 ? pen : Pen{.style = Line_Style::None}; } std::vector Selection_Rectangle_Overlay::selected_regions() { return d()->edit_state_value(&Selection_Rectangle_Overlay_Render_State::rects); } void Selection_Rectangle_Overlay::clear_selected_regions() { Render_Edit_Lease edit(d()); edit->rects.clear(); d()->active.store(false, std::memory_order_release); } } // namespace renderive