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.

This commit is contained in:
kinect-bot committed 2026-11-27 01:03:44 -05:00
1 parent 86722b0379
commit 449cb2d749
1 file changed
+41 -1
+41 -1
View File
@@ -7,6 +7,7 @@
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <fstream>
#include <mutex>
#include <string>
#include <thread>
@@ -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<LPARAM>("[ 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<int>(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;