Files
aevolution/apps/evo-client/cellular_scene.hpp
T

48 lines
2.0 KiB
C++

#pragma once
#include "evo/client/camera.hpp"
#include "evo/render/frame.hpp"
#include <algorithm>
#include <vector>
namespace evo::client_app {
inline constexpr std::size_t patch_rectangles = 3;
// The border keeps the 1 mm contact footprint readable; the inset is decorative.
// No stock percentage is invented: the centre mark means some stock remains.
inline void patch_box(std::vector<render::Rectangle>& out, client::ScreenPoint low,
client::ScreenPoint high, bool stocked, bool selected, double width,
double height, bool stale = false) {
const double minimum = selected ? 5 : 3;
const double hx = std::max((high.x - low.x) / 2, minimum);
const double hy = std::max((low.y - high.y) / 2, minimum);
const double x = (low.x + high.x) / 2, y = (low.y + high.y) / 2;
const auto rect = [&](double l, double t, double r, double b, render::Color color) {
l = std::max(l, 0.0);
t = std::max(t, 0.0);
r = std::min(r, width);
b = std::min(b, height);
if (stale) {
color.red /= 2;
color.green /= 2;
color.blue /= 2;
}
if (r > l && b > t)
out.push_back({static_cast<float>(l), static_cast<float>(t), static_cast<float>(r - l),
static_cast<float>(b - t), color});
};
rect(x - hx, y - hy, x + hx, y + hy,
selected ? render::Color{233, 182, 85, 255}
: stocked ? render::Color{49, 112, 105, 255}
: render::Color{58, 69, 77, 255});
if (hx <= 6 || hy <= 6)
return;
const double border = selected ? 2 : 1;
rect(x - hx + border, y - hy + border, x + hx - border, y + hy - border,
selected ? render::Color{53, 49, 31, 255} : render::Color{17, 40, 43, 255});
if (stocked) {
const double mark = std::clamp(std::min(hx, hy) * 0.08, 2.0, 5.0);
rect(x - mark, y - mark, x + mark, y + mark,
selected ? render::Color{233, 182, 85, 255} : render::Color{90, 185, 150, 255});
}
}
} // namespace evo::client_app