diff --git a/meson.build b/meson.build index d10fbee4..e567118f 100644 --- a/meson.build +++ b/meson.build @@ -313,6 +313,7 @@ src_common_ui = files( src_canvas = files( 'src/canvas/canvas.cpp', + 'src/canvas/canvas_layer_provider.cpp', 'src/canvas/appearance.cpp', 'src/canvas/render.cpp', 'src/canvas/draw.cpp', diff --git a/src/canvas/canvas.cpp b/src/canvas/canvas.cpp index 1dfca201..2c9ad9e8 100644 --- a/src/canvas/canvas.cpp +++ b/src/canvas/canvas.cpp @@ -201,7 +201,7 @@ void Canvas::add_triangle(int layer, const Coordf &p0, const Coordf &p1, const C void Canvas::update(const Symbol &sym, const Placement &tr, SymbolMode mode) { clear(); - layer_provider = &sym; + layer_provider.update(sym); transform = tr; render(sym, mode); request_push(); @@ -210,7 +210,7 @@ void Canvas::update(const Symbol &sym, const Placement &tr, SymbolMode mode) void Canvas::update(const Sheet &sheet) { clear(); - layer_provider = &sheet; + layer_provider.update(sheet); update_markers(); render(sheet); request_push(); @@ -219,7 +219,7 @@ void Canvas::update(const Sheet &sheet) void Canvas::update(const Padstack &padstack, bool edit) { clear(); - layer_provider = &padstack; + layer_provider.update(padstack); render(padstack, edit); request_push(); } @@ -227,7 +227,7 @@ void Canvas::update(const Padstack &padstack, bool edit) void Canvas::update(const Package &pkg, bool edit) { clear(); - layer_provider = &pkg; + layer_provider.update(pkg); render(pkg, edit); request_push(); } @@ -235,14 +235,14 @@ void Canvas::update(const Package &pkg, bool edit) void Canvas::update(const Board &brd, PanelMode mode) { clear(); - layer_provider = &brd; + layer_provider.update(brd); render(brd, true, mode); request_push(); } void Canvas::update(const class Frame &fr, bool edit) { clear(); - layer_provider = &fr; + layer_provider.update(fr); render(fr, !edit); request_push(); } @@ -250,7 +250,7 @@ void Canvas::update(const class Frame &fr, bool edit) void Canvas::update(const class Decal &dec, bool edit) { clear(); - layer_provider = &dec; + layer_provider.update(dec); render(dec, edit); request_push(); } @@ -258,7 +258,7 @@ void Canvas::update(const class Decal &dec, bool edit) void Canvas::update(const class BlockSymbol &sym, bool edit) { clear(); - layer_provider = &sym; + layer_provider.update(sym); render(sym, !edit); request_push(); } diff --git a/src/canvas/canvas.hpp b/src/canvas/canvas.hpp index ec61085e..a8bb7173 100644 --- a/src/canvas/canvas.hpp +++ b/src/canvas/canvas.hpp @@ -20,6 +20,7 @@ #include "util/vector_pair.hpp" #include "text_renderer.hpp" #include "show_via_span.hpp" +#include "canvas_layer_provider.hpp" namespace horizon { class Canvas { @@ -244,7 +245,7 @@ class Canvas { std::vector targets; Target target_current; - const class LayerProvider *layer_provider = nullptr; + CanvasLayerProvider layer_provider; std::map layer_colors; Color get_layer_color(int layer) const; int work_layer = 0; diff --git a/src/canvas/canvas_layer_provider.cpp b/src/canvas/canvas_layer_provider.cpp new file mode 100644 index 00000000..f6b16055 --- /dev/null +++ b/src/canvas/canvas_layer_provider.cpp @@ -0,0 +1,16 @@ +#include "canvas_layer_provider.hpp" + +namespace horizon { + +void CanvasLayerProvider::update(const LayerProvider &other) +{ + layers = other.get_layers(); +} + +const std::map &CanvasLayerProvider::get_layers() const +{ + return layers; +} + + +} // namespace horizon diff --git a/src/canvas/canvas_layer_provider.hpp b/src/canvas/canvas_layer_provider.hpp new file mode 100644 index 00000000..41256a79 --- /dev/null +++ b/src/canvas/canvas_layer_provider.hpp @@ -0,0 +1,13 @@ +#pragma once +#include "common/layer_provider.hpp" + +namespace horizon { +class CanvasLayerProvider : public LayerProvider { +public: + void update(const LayerProvider &other); + const std::map &get_layers() const override; + +private: + std::map layers; +}; +} // namespace horizon diff --git a/src/canvas/render.cpp b/src/canvas/render.cpp index ffcc26bd..c44d735c 100644 --- a/src/canvas/render.cpp +++ b/src/canvas/render.cpp @@ -778,7 +778,7 @@ void Canvas::render(const SchematicSymbol &sym) void Canvas::render(const Text &text, bool interactive, ColorP co) { - const bool rev = layer_provider->get_layers().at(text.layer).reverse; + const bool rev = layer_provider.get_layers().at(text.layer).reverse; img_patch_type(PatchType::TEXT); triangle_type_current = TriangleInfo::Type::TEXT; img_text(&text); diff --git a/src/canvas/triangle_renderer.cpp b/src/canvas/triangle_renderer.cpp index eba21314..0ad3ddaa 100644 --- a/src/canvas/triangle_renderer.cpp +++ b/src/canvas/triangle_renderer.cpp @@ -300,7 +300,7 @@ void TriangleRenderer::render_layer_batch(int layer, HighlightMode highlight_mod if (ca.appearance.colors.count(k)) buf.colors[i] = apply_highlight(ca.appearance.colors.at(k), highlight_mode, layer); } - auto lc = ca.get_layer_color(ca.layer_provider ? ca.layer_provider->get_color_layer(layer) : layer); + auto lc = ca.get_layer_color(ca.layer_provider.get_color_layer(layer)); buf.colors[static_cast(ColorP::AIRWIRE_ROUTER)] = gl_array_from_color(ca.appearance.colors.at(ColorP::AIRWIRE_ROUTER)); buf.colors[static_cast(ColorP::FROM_LAYER)] = apply_highlight(lc, highlight_mode, layer); @@ -371,14 +371,10 @@ void TriangleRenderer::render() layers.push_back(it.first); } - if (ca.layer_provider) { - std::sort(layers.begin(), layers.end(), [this](auto la, auto lb) { - return ca.layer_provider->get_layer_position(la) < ca.layer_provider->get_layer_position(lb); - }); - } - else { - std::sort(layers.begin(), layers.end()); - } + std::sort(layers.begin(), layers.end(), [this](auto la, auto lb) { + return ca.layer_provider.get_layer_position(la) < ca.layer_provider.get_layer_position(lb); + }); + if (ca.work_layer < 0) { std::reverse(layers.begin(), layers.end()); }