refactor: group selection state into a Selection sub-struct + ClearSelection()

The box-selection state was 11 fields spread across three comment blocks
(time sel, freq sel, drag state). Consolidate them into one Selection
sub-struct (app.sel.*) and extract the 4-line 'clear to full range' block —
duplicated in 5 places — into a ClearSelection() helper.

Pure mechanical rename (anchored to app./spa-> so the ScopeView fields of the
same name are untouched) + behavior-identical dedup. Fully-settled render
verified pixel-identical (AE=0).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-25 09:15:50 -07:00
parent ab7a6bc71c
commit 8e4250ae63
5 changed files with 103 additions and 107 deletions
+5 -8
View File
@@ -266,10 +266,10 @@ void ExportPNG(const SpectrogramApp* spa, const char* dirPath)
int imgH = spa->spectrogramImage.height;
// Selection region in image-pixel coordinates
int selX0 = (int)(spa->timeSelectionStart * imgW);
int selX1 = (int)(spa->timeSelectionEnd * imgW);
int selY0 = (int)((1.0f - spa->freqSelectionEnd) * imgH);
int selY1 = (int)((1.0f - spa->freqSelectionStart) * imgH);
int selX0 = (int)(spa->sel.timeStart * imgW);
int selX1 = (int)(spa->sel.timeEnd * imgW);
int selY0 = (int)((1.0f - spa->sel.freqEnd) * imgH);
int selY1 = (int)((1.0f - spa->sel.freqStart) * imgH);
// Clamp to image bounds
selX0 = Clamp(selX0, 0, imgW);
@@ -468,10 +468,7 @@ void DrawSidebar(void)
// Clear selection (identical to the Esc key)
Rectangle clearButton = { x, y, sidebarWidth - 10 * scale, 25 * scale };
if (Clicked(clearButton)) {
app.timeSelectionStart = 0.0f;
app.timeSelectionEnd = 1.0f;
app.freqSelectionStart = 0.0f;
app.freqSelectionEnd = 1.0f;
ClearSelection();
}
DrawPanelBox(clearButton, (Color){ 80, 50, 50, 255 }, RED);
DrawTextScaled("Clear Selection (ESC)", clearButton.x + 10 * scale, clearButton.y + 6 * scale, 14, WHITE);