fix S10 code-review findings: WM_CAPTURECHANGED, proportional drag, paintSetup root source, Add Zone dedup, strip-area helpers
This commit is contained in:
@@ -314,6 +314,26 @@ EditorBands computeBands(int w, int h) {
|
||||
b.content = Rect{0, toggleBot, w, h};
|
||||
return b;
|
||||
}
|
||||
|
||||
// The keyboard strip rectangle inside the setup area (single-capture root-drag face).
|
||||
// `area` is the full setup Rect; the strip is anchored at the bottom with an 8px horizontal
|
||||
// pad. All three call sites (paintSetup, onMouseDown, onMouseMove) use this single formula.
|
||||
Rect setupStripArea(const Rect& area) {
|
||||
constexpr int pad = 8;
|
||||
const int stripTop = area.bottom - kStripBandHeight;
|
||||
return Rect{area.left + pad, stripTop, area.right - pad, area.bottom - 4};
|
||||
}
|
||||
|
||||
// The keyboard strip rectangle inside the Zones panel content area. `bands.content` is the
|
||||
// mode-content Rect; the strip sits below the "+ Add Zone" affordance (top+4, height 20)
|
||||
// with a 12px gap, padded 8px horizontally. All three call sites (paintZones, onMouseDown,
|
||||
// onMouseMove) use this single formula — the inline arithmetic in onMouseMove was the drift.
|
||||
Rect zonesStripArea(const EditorBands& bands) {
|
||||
constexpr int pad = 8;
|
||||
const int stripTop = bands.content.top + 4 + 20 + 12; // addR.bottom + 12
|
||||
return Rect{bands.content.left + pad, stripTop, bands.content.right - pad,
|
||||
stripTop + kStripBandHeight};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void ReaSamplerEditor::paint(HDC hdc) {
|
||||
@@ -445,8 +465,10 @@ void ReaSamplerEditor::paintSetup(LICE_IBitmap* bmp, const Rect& area) {
|
||||
kColTitleBg, 1.0f, 0);
|
||||
|
||||
// Effective root: the picked sample's rootNote intrinsic (or middle C when unset).
|
||||
// Read from samples_ (the full unfiltered list) so a bank-filter that hides the
|
||||
// picked sample's bank doesn't mask its intrinsic root with the C4 default.
|
||||
int root = 60;
|
||||
for (const SampleChoice& s : visible_) {
|
||||
for (const SampleChoice& s : samples_) {
|
||||
if (s.id == selectedId_ && s.rootNote) root = *s.rootNote;
|
||||
}
|
||||
// If a matching one-zone override exists (opt-in from Zones), prefer it as the shown root.
|
||||
@@ -463,8 +485,7 @@ void ReaSamplerEditor::paintSetup(LICE_IBitmap* bmp, const Rect& area) {
|
||||
drawText(bmp, hintR, "Drag on the keyboard to set the root note.", kRgbDim);
|
||||
|
||||
// Keyboard strip with the root marker.
|
||||
const int stripTop = area.bottom - kStripBandHeight;
|
||||
Rect stripArea{area.left + pad, stripTop, area.right - pad, area.bottom - 4};
|
||||
const Rect stripArea = setupStripArea(area);
|
||||
const StripLayout sl = layoutStrip(stripArea.width(), stripArea.height());
|
||||
const int sx = stripArea.left;
|
||||
const int sy = stripArea.top;
|
||||
@@ -503,9 +524,7 @@ void ReaSamplerEditor::paintZones(LICE_IBitmap* bmp, int w, int h) {
|
||||
}
|
||||
|
||||
// The zones strip.
|
||||
const int stripTop = addR.bottom + 12;
|
||||
Rect stripArea{bands.content.left + pad, stripTop, bands.content.right - pad,
|
||||
stripTop + kStripBandHeight};
|
||||
const Rect stripArea = zonesStripArea(bands);
|
||||
const StripLayout sl = layoutStrip(stripArea.width(), stripArea.height());
|
||||
const int sx = stripArea.left;
|
||||
const int sy = stripArea.top;
|
||||
@@ -581,8 +600,7 @@ void ReaSamplerEditor::onMouseDown(int x, int y) {
|
||||
// The setup strip: grab the root marker (drag to set the picked capture's root).
|
||||
if (havePick) {
|
||||
const Rect area{bands.content.left, setupTop, bands.content.right, bands.content.bottom};
|
||||
const int stripTop = area.bottom - kStripBandHeight;
|
||||
const Rect stripArea{area.left + 8, stripTop, area.right - 8, area.bottom - 4};
|
||||
const Rect stripArea = setupStripArea(area);
|
||||
const StripLayout sl = layoutStrip(stripArea.width(), stripArea.height());
|
||||
const int note = keyAtPoint(sl, x - stripArea.left, y - stripArea.top);
|
||||
if (note >= 0) {
|
||||
@@ -603,11 +621,21 @@ void ReaSamplerEditor::onMouseDown(int x, int y) {
|
||||
Rect addR{bands.content.left + pad, bands.content.top + 4, bands.content.left + pad + 96,
|
||||
bands.content.top + 4 + 20};
|
||||
if (contains(addR, x, y)) {
|
||||
// Append a full-keyboard zone for the picked capture (or the first visible sample as a
|
||||
// sensible seed). No pick -> nothing to add.
|
||||
// Add a full-keyboard zone for the picked capture (or the first visible sample as a
|
||||
// sensible seed). No pick -> nothing to add. If a full-keyboard zone for the seed id
|
||||
// already exists, select it rather than appending a duplicate (mirrors the upsert the
|
||||
// root-marker drag path already performs, preventing overlapping identical zones).
|
||||
std::string seed = !selectedId_.empty() ? selectedId_
|
||||
: (!visible_.empty() ? visible_.front().id : std::string());
|
||||
if (seed.empty()) return;
|
||||
for (int i = 0; i < static_cast<int>(map_.zones.size()); ++i) {
|
||||
const PerformanceZone& z = map_.zones[static_cast<std::size_t>(i)];
|
||||
if (z.sampleId == seed && z.lowNote == 0 && z.highNote == 127) {
|
||||
selectedZone_ = i;
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
PerformanceZone z;
|
||||
z.sampleId = seed;
|
||||
z.lowNote = 0;
|
||||
@@ -627,9 +655,7 @@ void ReaSamplerEditor::onMouseDown(int x, int y) {
|
||||
|
||||
// The zones strip: hit-test a bar edge/body to start a drag, or a bare key to set the
|
||||
// selected zone's root.
|
||||
const int stripTop = addR.bottom + 12;
|
||||
const Rect stripArea{bands.content.left + pad, stripTop, bands.content.right - pad,
|
||||
stripTop + kStripBandHeight};
|
||||
const Rect stripArea = zonesStripArea(bands);
|
||||
const StripLayout sl = layoutStrip(stripArea.width(), stripArea.height());
|
||||
const int lx = x - stripArea.left;
|
||||
const int ly = y - stripArea.top;
|
||||
@@ -680,8 +706,7 @@ void ReaSamplerEditor::onMouseMove(int x, int y) {
|
||||
// The single-capture root strip lives in the setup band.
|
||||
const int setupTop = (std::max)(bands.content.top, bands.content.bottom - kSetupHeight);
|
||||
const Rect area{bands.content.left, setupTop, bands.content.right, bands.content.bottom};
|
||||
const Rect stripArea{area.left + 8, area.bottom - kStripBandHeight, area.right - 8,
|
||||
area.bottom - 4};
|
||||
const Rect stripArea = setupStripArea(area);
|
||||
const StripLayout sl = layoutStrip(stripArea.width(), stripArea.height());
|
||||
const int note = resolveDragNote(sl, dragStartRoot_, dx);
|
||||
// The performance map is the ONLY D-B override vehicle (rootOverride lives on a zone),
|
||||
@@ -708,10 +733,7 @@ void ReaSamplerEditor::onMouseMove(int x, int y) {
|
||||
|
||||
// Zone edits: recompute the grabbed field(s) against the pure resolver, live.
|
||||
if (selectedZone_ < 0 || selectedZone_ >= static_cast<int>(map_.zones.size())) return;
|
||||
const int pad = 8;
|
||||
const int stripTop = bands.content.top + 4 + 20 + 12; // addR.bottom + 12
|
||||
const Rect stripArea{bands.content.left + pad, stripTop, bands.content.right - pad,
|
||||
stripTop + kStripBandHeight};
|
||||
const Rect stripArea = zonesStripArea(bands);
|
||||
const StripLayout sl = layoutStrip(stripArea.width(), stripArea.height());
|
||||
PerformanceZone& z = map_.zones[static_cast<std::size_t>(selectedZone_)];
|
||||
if (drag_ == DragKind::kZoneLow) {
|
||||
@@ -765,6 +787,15 @@ LRESULT CALLBACK ReaSamplerEditor::wndProc(HWND hwnd, UINT msg, WPARAM wParam,
|
||||
ReleaseCapture();
|
||||
}
|
||||
return 0;
|
||||
case WM_CAPTURECHANGED:
|
||||
// Capture stolen mid-drag (modal dialog, alt-tab, etc.) — reset the drag
|
||||
// state machine so stale capture-less WM_MOUSEMOVEs don't keep editing.
|
||||
// Mirror of bank_panel.cpp's WM_CAPTURECHANGED handler.
|
||||
if (self && self->drag_ != DragKind::kNone) {
|
||||
self->drag_ = DragKind::kNone;
|
||||
self->invalidate();
|
||||
}
|
||||
return 0;
|
||||
case WM_ERASEBKGND:
|
||||
return 1; // fully repaint in WM_PAINT; skip the flicker-inducing erase
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user