From 449cb2d749eacc19d2d7b33b8eae4ffce1cab13d Mon Sep 17 00:00:00 2001 From: kinect-bot Date: Fri, 27 Nov 2026 01:03:44 -0500 Subject: [PATCH] feat(tracker): remember the last-selected camera + resolution in kinect_tracker_last.txt next to the exe; the dropdowns default to it on next launch (falls back to the first camera if it's gone). User rebuilds the tracker. --- tracker-native/src/win_main.cpp | 42 ++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/tracker-native/src/win_main.cpp b/tracker-native/src/win_main.cpp index 3aaf00a..ecfb6d7 100644 --- a/tracker-native/src/win_main.cpp +++ b/tracker-native/src/win_main.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -65,6 +66,21 @@ std::wstring ExeDir() { return slash == std::wstring::npos ? L"." : p.substr(0, slash); } +// Remember the camera + resolution the user last started, in a small text file +// next to the exe, so the dropdowns default to it on the next launch. +std::wstring LastSelectionPath() { return ExeDir() + L"\\kinect_tracker_last.txt"; } + +void SaveLastSelection(const std::string& device_name, int width, int height) { + std::ofstream f(LastSelectionPath().c_str()); + if (f) f << device_name << '\n' << width << ' ' << height << '\n'; +} + +bool LoadLastSelection(std::string& device_name, int& width, int& height) { + std::ifstream f(LastSelectionPath().c_str()); + return f && std::getline(f, device_name) && (f >> width >> height) && + !device_name.empty(); +} + std::string ModelPath() { const std::wstring dir = ExeDir(); const wchar_t* candidates[] = {L"\\", L"\\models\\"}; @@ -453,6 +469,7 @@ void StartCapture() { res.width, res.height); g_app.worker = std::thread(WorkerLoop, false, g_app.devices[dsel].symbolic_link, res.width, res.height); + SaveLastSelection(g_app.devices[dsel].name, res.width, res.height); SetWindowTextA(g_app.start_btn, "Stop"); SetStatus("Starting..."); } @@ -551,9 +568,32 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { } SendMessageA(g_app.device_combo, CB_ADDSTRING, 0, reinterpret_cast("[ Test image file... ]")); + // Default the dropdowns to whatever was selected last time, if that + // camera is still present; otherwise fall back to the first camera. + std::string last_name; + int last_w = 0, last_h = 0; + const bool has_last = LoadLastSelection(last_name, last_w, last_h); + int dev_sel = 0; + if (has_last) { + for (size_t i = 0; i < g_app.devices.size(); ++i) { + if (g_app.devices[i].name == last_name) { + dev_sel = static_cast(i); + break; + } + } + } if (!g_app.devices.empty()) { - SendMessage(g_app.device_combo, CB_SETCURSEL, 0, 0); + SendMessage(g_app.device_combo, CB_SETCURSEL, dev_sel, 0); PopulateResolutions(); + if (has_last) { + for (size_t i = 0; i < g_app.resolutions.size(); ++i) { + if (g_app.resolutions[i].width == last_w && + g_app.resolutions[i].height == last_h) { + SendMessage(g_app.res_combo, CB_SETCURSEL, i, 0); + break; + } + } + } } SetTimer(hwnd, 1, 33, nullptr); return 0;