Loading...
Searching...
No Matches
TextureLayers.hpp
1#pragma once
2#include <Process/Monitoring/Monitor.hpp>
3
4#include <Gfx/Graph/TextureKind.hpp>
5
6#include <QPointF>
7#include <QStringList>
8
9#include <Ui/Monitor/LayerHelpers.hpp>
10#include <Ui/Monitor/TextureShapeMonitor.hpp>
11#include <halp/controls.hpp>
12#include <halp/meta.hpp>
13
14#include <algorithm>
15#include <atomic>
16#include <cstdint>
17#include <optional>
18
24namespace Ui::Monitor
25{
26enum class Layout
27{
28 Single,
29 Overview
30};
31
32struct LayoutControl : halp::combobox_t<"Layout", Layout>
33{
34 halp_meta(
35 description,
36 "For a 3D texture, an array or a cube map: one slice, layer or face, or "
37 "all of them side by side")
38 struct range
39 {
40 std::string_view values[2]{"Single", "Overview"};
41 Layout init{Layout::Single};
42 };
43};
44
45struct SliceControl : halp::hslider_f32<"Slice", halp::range{0., 1., 0.5}>
46{
47 halp_meta(
48 description, "Depth of the slice of a 3D texture shown in Single, from 0 to 1")
49};
50
51struct LayerControl : halp::spinbox_i32<"Layer", halp::range{0, 2047, 0}>
52{
53 halp_meta(
54 description,
55 "Layer of an array shown in Single, or face of a cube map: 0 to 5 for "
56 "+X, -X, +Y, -Y, +Z, -Z")
57};
58
60inline void publish(TextureShapeMonitor& m, const score::gfx::TextureShape& s) noexcept
61{
62 m.shape.store(s.pack(), std::memory_order_relaxed);
63}
64inline score::gfx::TextureShape latestShape(const TextureShapeMonitor& m) noexcept
65{
66 return score::gfx::TextureShape::unpack(m.shape.load(std::memory_order_relaxed));
67}
68
69inline score::gfx::ShownTexture shownTexture(
70 const score::gfx::TextureShape& shape, Layout layout, float slice,
71 int layer) noexcept
72{
74 shape,
75 layout == Layout::Overview ? score::gfx::TextureLayout::Overview
76 : score::gfx::TextureLayout::Single,
77 slice, layer);
78}
79
82inline score::gfx::ShownTexture shownTexture(
83 const Process::ProcessModel& p, const score::gfx::TextureShape& shape) noexcept
84{
85 std::size_t first = p.inlets().size();
86 for(std::size_t i = 0; i < p.inlets().size(); i++)
87 if(p.inlets()[i]->name() == QStringLiteral("Layout"))
88 {
89 first = i;
90 break;
91 }
92 const auto* slice = controlInlet(p, first + 1);
93 const auto* layer = controlInlet(p, first + 2);
94 return shownTexture(
95 shape, enumValue(controlInlet(p, first), Layout::Single, Layout::Overview),
96 floatValue(slice, 0.5f), layer ? ossia::convert<int>(layer->value()) : 0);
97}
98
103inline QStringList
104describeShown(const score::gfx::ShownTexture& shown, std::optional<QPointF> at = {})
105{
106 QStringList lines;
107 if(!shown.layered() || shown.shape.empty())
108 return lines;
109 lines << shown.shape.description();
110 const auto pt
111 = at ? shown.locate(at->x(), at->y()) : score::gfx::ShownTexture::Point{};
112 if(pt.layer >= 0)
113 {
114 const int w = shown.shape.width, h = shown.shape.height;
115 const int x = std::clamp(int(pt.u * w), 0, w - 1);
116 const int y = std::clamp(int(pt.v * h), 0, h - 1);
117 lines << QStringLiteral("%1: %2, %3").arg(shown.shape.layerName(pt.layer)).arg(x).arg(y);
118 }
119 else if(!shown.overview())
120 lines << shown.shape.layerName(shown.index);
121 return lines;
122}
123}
The Process class.
Definition score-lib-process/Process/Process.hpp:82
Definition BufferDecode.hpp:16
const Process::ControlInlet * controlInlet(const Process::ProcessModel &p, std::size_t index) noexcept
Definition LayerHelpers.hpp:36
QStringList describeShown(const score::gfx::ShownTexture &shown, std::optional< QPointF > at={})
Definition TextureLayers.hpp:104
void publish(TextureShapeMonitor &m, const score::gfx::TextureShape &s) noexcept
The node tells the views the texture it got.
Definition TextureLayers.hpp:60
Base toolkit upon which the software is built.
Definition Application.cpp:83
Definition TextureLayers.hpp:52
Definition TextureLayers.hpp:33
Definition TextureLayers.hpp:46
Definition TextureShapeMonitor.hpp:12
Definition MIDISync.hpp:149
Definition TextureKind.hpp:110
Definition TextureKind.hpp:77
static ShownTexture of(TextureShape shape, TextureLayout layout, double slice, int layer) noexcept
Definition TextureKind.cpp:89
QSize size(int max_side) const noexcept
Size of the image shown, at most max_side pixels wide and high.
Definition TextureKind.cpp:137
Definition TextureKind.hpp:31