Files
reasampler/src/shell/instrument/editor_stroke.h
T
daniel 3fb77027c6 fix: close Θ-W7-T1 review — scaling guard, opacity claims, two vacuous test fixes
Guards the stroke blend against LICE_EXT_GET_SCALING, tightens the analytic-stroker's boxes and NaN handling, corrects the opaque-core threshold and inner-dial rationale in the docs, and re-derives two review-flagged tautological tests so they actually fail against the bugs they claim to catch.
2026-08-01 13:45:43 -04:00

60 lines
2.8 KiB
C++

// editor_stroke.h — the editor's LICE side of the analytic stroker: build a coverage mask with
// the pure `core/ui/stroke_aa` module, blend it into the bitmap ONCE.
//
// Every radial and spline stroke on the editor goes through here. LICE's own primitives cannot
// serve these two shapes: LICE_Arc rasterizes a whole circle clipped per 90-degree box and splits
// one unit of ink across two pixels by the radius's fractional part (so a stacked-radii arc never
// reaches an opaque core), and LICE_ThickFLine lays its width along the MINOR axis (so a curve's
// perpendicular weight falls off as cos(theta) and thins at every diagonal).
#pragma once
#ifdef _WIN32
#include <cstddef>
#include <vector>
#include "lice/lice.h"
#include "wdltypes.h"
#include "core/ui/rect.h"
#include "core/ui/stroke_aa.h"
namespace reasampler::vst {
// Blends a polyline as one antialiased stroke of `widthPx`. Clipped to the bitmap. Takes a raw
// span so a short stroke (a knob needle) can pass a stack array and cost no allocation.
void strokePolylineAA(LICE_IBitmap* bmp, const ui::StrokePoint* pts, std::size_t count,
float widthPx, LICE_pixel color, float alpha = 1.0f);
inline void strokePolylineAA(LICE_IBitmap* bmp, const std::vector<ui::StrokePoint>& pts,
float widthPx, LICE_pixel color, float alpha = 1.0f) {
strokePolylineAA(bmp, pts.data(), pts.size(), widthPx, color, alpha);
}
// A single antialiased segment — the two-point polyline, spelled out for the call sites that
// have exactly two endpoints.
inline void strokeLineAA(LICE_IBitmap* bmp, float x0, float y0, float x1, float y1, float widthPx,
LICE_pixel color, float alpha = 1.0f) {
const ui::StrokePoint pts[2] = {{x0, y0}, {x1, y1}};
strokePolylineAA(bmp, pts, 2, widthPx, color, alpha);
}
// Blends a circular arc as one antialiased stroke of `widthPx`. Angles are radians in LICE's
// convention (0 = 12 o'clock, increasing clockwise), matching what LICE_Arc took.
void strokeArcAA(LICE_IBitmap* bmp, float cx, float cy, float radius, float startRad, float endRad,
float widthPx, LICE_pixel color, float alpha = 1.0f);
// The draw-thread-only point-list scratch, shared by every paint site that builds a polyline
// column-by-column before one strokePolylineAA call (the curve thumbnail, the curve-popup
// trace, the two waveform-overlay traces). Reuse only: `clear()` and refill before each use,
// never read across paint calls. This module already owns the draw-thread scratch (the mask +
// the arc point list this header's own functions use internally); routing every external
// point-list consumer through the same accessor keeps that ownership one fact in one place
// instead of four independent function-local statics.
std::vector<ui::StrokePoint>& scratchPoints();
} // namespace reasampler::vst
#endif // _WIN32