mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-06-28 21:37:50 +02:00
removed scrolling due to bug + Fixed file source
This commit is contained in:
@ -26,7 +26,7 @@ namespace LoadingScreen {
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20.0f, 20.0f));
|
||||
ImGui::OpenPopup("Credits");
|
||||
ImGui::PushStyleColor(ImGuiCol_ModalWindowDarkening, ImVec4(0.0f, 0.0f, 0.0f, 0.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ModalWindowDimBg, ImVec4(0.0f, 0.0f, 0.0f, 0.0f));
|
||||
ImGui::BeginPopupModal("Credits", NULL, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground);
|
||||
|
||||
ImGui::PushFont(style::hugeFont);
|
||||
|
@ -32,10 +32,12 @@
|
||||
#include <gui/dialogs/loading_screen.h>
|
||||
#include <options.h>
|
||||
#include <gui/colormaps.h>
|
||||
#include <gui/widgets/scroll_behavior.h>
|
||||
|
||||
|
||||
#include <gui/widgets/file_select.h>
|
||||
FileSelect fileSelect("%ROOT/recordings", "Alllll\0*.*\0Text\0*.TXT\0");
|
||||
#include <gui/widgets/folder_select.h>
|
||||
FileSelect fileSelect("D:/Downloads/unicast.wav");
|
||||
FolderSelect foldSelect("%ROOT/recordings");
|
||||
|
||||
// const int FFTSizes[] = {
|
||||
// 65536,
|
||||
@ -114,11 +116,21 @@ bool centerTuning = false;
|
||||
dsp::stream<dsp::complex_t> dummyStream;
|
||||
bool demoWindow = false;
|
||||
|
||||
COMDLG_FILTERSPEC rgSpec[] ={
|
||||
{ L"Wav File", L"*.wav" },
|
||||
{ L"All", L"*.*" },
|
||||
};
|
||||
|
||||
void windowInit() {
|
||||
LoadingScreen::show("Initializing UI");
|
||||
gui::waterfall.init();
|
||||
gui::waterfall.setRawFFTSize(fftSize);
|
||||
|
||||
// TEMP TEST
|
||||
|
||||
fileSelect.setWindowsFilter(rgSpec, 2);
|
||||
// ==========
|
||||
|
||||
tempFFT = new float[fftSize];
|
||||
FFTdata = new float[fftSize];
|
||||
|
||||
@ -558,6 +570,9 @@ void drawWindow() {
|
||||
ImGui::Checkbox("Show demo window", &demoWindow);
|
||||
ImGui::Checkbox("Experimental zoom", &experimentalZoom);
|
||||
fileSelect.render("##_testfile");
|
||||
foldSelect.render("##_testfold");
|
||||
ImGui::Text("ImGui version: %s", ImGui::GetVersion());
|
||||
|
||||
ImGui::Spacing();
|
||||
}
|
||||
|
||||
@ -589,8 +604,7 @@ void drawWindow() {
|
||||
ImGui::SetCursorPosX((ImGui::GetWindowSize().x / 2.0) - (ImGui::CalcTextSize("Zoom").x / 2.0));
|
||||
ImGui::Text("Zoom");
|
||||
ImGui::SetCursorPosX((ImGui::GetWindowSize().x / 2.0) - 10);
|
||||
if (ImGui::VSliderFloat("##_7_", ImVec2(20.0, 150.0), &bw, gui::waterfall.getBandwidth(), 1000.0, "", (experimentalZoom ? 2.0 : 1.0)) ||
|
||||
ImGui::AllowScrollwheel<float>(bw, 20, gui::waterfall.getBandwidth(), 1000.0)) {
|
||||
if (ImGui::VSliderFloat("##_7_", ImVec2(20.0, 150.0), &bw, gui::waterfall.getBandwidth(), 1000.0, "", (experimentalZoom ? 2.0 : 1.0))) {
|
||||
gui::waterfall.setViewBandwidth(bw);
|
||||
if (vfo != NULL) {
|
||||
gui::waterfall.setViewOffset(vfo->centerOffset); // center vfo on screen
|
||||
@ -602,7 +616,7 @@ void drawWindow() {
|
||||
ImGui::SetCursorPosX((ImGui::GetWindowSize().x / 2.0) - (ImGui::CalcTextSize("Max").x / 2.0));
|
||||
ImGui::Text("Max");
|
||||
ImGui::SetCursorPosX((ImGui::GetWindowSize().x / 2.0) - 10);
|
||||
if (ImGui::VSliderFloat("##_8_", ImVec2(20.0, 150.0), &fftMax, 0.0, -100.0, "") || ImGui::AllowScrollwheel<float>(fftMax, 20, -100, 0)) {
|
||||
if (ImGui::VSliderFloat("##_8_", ImVec2(20.0, 150.0), &fftMax, 0.0, -100.0, "")) {
|
||||
fftMax = std::max<float>(fftMax, fftMin + 10);
|
||||
core::configManager.aquire();
|
||||
core::configManager.conf["max"] = fftMax;
|
||||
@ -614,7 +628,7 @@ void drawWindow() {
|
||||
ImGui::SetCursorPosX((ImGui::GetWindowSize().x / 2.0) - (ImGui::CalcTextSize("Min").x / 2.0));
|
||||
ImGui::Text("Min");
|
||||
ImGui::SetCursorPosX((ImGui::GetWindowSize().x / 2.0) - 10);
|
||||
if (ImGui::VSliderFloat("##_9_", ImVec2(20.0, 150.0), &fftMin, 0.0, -100.0, "") || ImGui::AllowScrollwheel<float>(fftMin, 20, -100, 0)) {
|
||||
if (ImGui::VSliderFloat("##_9_", ImVec2(20.0, 150.0), &fftMin, 0.0, -100.0, "")) {
|
||||
fftMin = std::min<float>(fftMax - 10, fftMin);
|
||||
core::configManager.aquire();
|
||||
core::configManager.conf["min"] = fftMin;
|
||||
|
@ -99,7 +99,7 @@ namespace style {
|
||||
colors[ImGuiCol_PlotHistogram] = ImVec4(0.73f, 0.60f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.87f, 0.87f, 0.87f, 0.35f);
|
||||
colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
|
||||
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
|
||||
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
|
||||
colors[ImGuiCol_NavHighlight] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
|
||||
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
|
||||
|
@ -3,14 +3,14 @@
|
||||
#include <options.h>
|
||||
#include <filesystem>
|
||||
|
||||
FileSelect::FileSelect(std::string defaultPath, char* filter) {
|
||||
FileSelect::FileSelect(std::string defaultPath) {
|
||||
path = defaultPath;
|
||||
strcpy(_filter, filter);
|
||||
pathValid = std::filesystem::is_regular_file(path);
|
||||
strcpy(strPath, path.c_str());
|
||||
}
|
||||
|
||||
void FileSelect::render(std::string id) {
|
||||
bool FileSelect::render(std::string id) {
|
||||
bool _pathChanged = false;
|
||||
#ifdef _WIN32
|
||||
float menuColumnWidth = ImGui::GetContentRegionAvailWidth();
|
||||
float buttonWidth = ImGui::CalcTextSize("...").x + 20.0f;
|
||||
@ -59,6 +59,15 @@ void FileSelect::render(std::string id) {
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
#endif
|
||||
_pathChanged |= pathChanged;
|
||||
pathChanged = false;
|
||||
return _pathChanged;
|
||||
}
|
||||
|
||||
void FileSelect::setPath(std::string path) {
|
||||
this->path = path;
|
||||
pathValid = std::filesystem::is_regular_file(path);
|
||||
strcpy(strPath, path.c_str());
|
||||
}
|
||||
|
||||
std::string FileSelect::expandString(std::string input) {
|
||||
@ -70,45 +79,35 @@ bool FileSelect::pathIsValid() {
|
||||
return pathValid;
|
||||
}
|
||||
|
||||
bool FileSelect::pathChanged() {
|
||||
if (_pathChanged) {
|
||||
_pathChanged = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#ifdef _WIN32
|
||||
|
||||
void FileSelect::setWindowsFilter(COMDLG_FILTERSPEC* filt, int n) {
|
||||
filter = filt;
|
||||
filterCount = n;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
void FileSelect::windowsWorker() {
|
||||
OPENFILENAMEA ofn; // common dialog box structure
|
||||
char szFile[2048]; // buffer for file name
|
||||
HWND hwnd; // owner window
|
||||
HANDLE hf; // file handle
|
||||
IFileOpenDialog *pFileOpen;
|
||||
HRESULT hr;
|
||||
|
||||
// Initialize OPENFILENAME
|
||||
ZeroMemory(&ofn, sizeof(ofn));
|
||||
ofn.lStructSize = sizeof(ofn);
|
||||
ofn.hwndOwner = GetFocus();
|
||||
ofn.lpstrFile = (LPSTR)szFile;
|
||||
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
|
||||
// use the contents of szFile to initialize itself.
|
||||
ofn.lpstrFile[0] = '\0';
|
||||
ofn.nMaxFile = sizeof(szFile);
|
||||
ofn.lpstrFilter = (LPCSTR)_filter;
|
||||
ofn.nFilterIndex = 1;
|
||||
ofn.lpstrFileTitle = NULL;
|
||||
ofn.nMaxFileTitle = 0;
|
||||
ofn.lpstrInitialDir = NULL;
|
||||
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXTENSIONDIFFERENT;
|
||||
// Create the FileOpenDialog object.
|
||||
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
|
||||
|
||||
if (filter != NULL) { pFileOpen->SetFileTypes(filterCount, filter); }
|
||||
|
||||
// Display the Open dialog box.
|
||||
|
||||
if (GetOpenFileNameA(&ofn)==TRUE) {
|
||||
strcpy(strPath, szFile);
|
||||
_pathChanged = true;
|
||||
hr = pFileOpen->Show(NULL);
|
||||
if (SUCCEEDED(hr)) {
|
||||
PWSTR pszFilePath;
|
||||
IShellItem *pItem;
|
||||
hr = pFileOpen->GetResult(&pItem);
|
||||
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
|
||||
wcstombs(strPath, pszFilePath, 2048);
|
||||
CoTaskMemFree(pszFilePath);
|
||||
path = std::string(strPath);
|
||||
pathChanged = true;
|
||||
}
|
||||
|
||||
pathValid = std::filesystem::is_regular_file(strPath);
|
||||
pathValid = std::filesystem::is_regular_file(path);
|
||||
dialogOpen = false;
|
||||
}
|
||||
#endif
|
@ -7,28 +7,35 @@
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#include <thread>
|
||||
#include <ShObjIdl.h>
|
||||
#endif
|
||||
|
||||
class FileSelect {
|
||||
public:
|
||||
FileSelect(std::string defaultPath, char* filter = "All\0*.*");
|
||||
void render(std::string id);
|
||||
FileSelect(std::string defaultPath);
|
||||
bool render(std::string id);
|
||||
void setPath(std::string path);
|
||||
bool pathIsValid();
|
||||
bool pathChanged();
|
||||
|
||||
std::string expandString(std::string input);
|
||||
|
||||
std::string path = "";
|
||||
|
||||
#ifdef _WIN32
|
||||
void setWindowsFilter(COMDLG_FILTERSPEC* filt, int n);
|
||||
#endif
|
||||
|
||||
private:
|
||||
#ifdef _WIN32
|
||||
void windowsWorker();
|
||||
std::thread workerThread;
|
||||
COMDLG_FILTERSPEC* filter = NULL;
|
||||
int filterCount = 0;
|
||||
#endif
|
||||
|
||||
char _filter[2048];
|
||||
bool pathValid = false;
|
||||
bool dialogOpen = false;
|
||||
char strPath[2048];
|
||||
bool _pathChanged = false;
|
||||
bool pathChanged = false;
|
||||
};
|
108
core/src/gui/widgets/folder_select.cpp
Normal file
108
core/src/gui/widgets/folder_select.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
#include <gui/widgets/folder_select.h>
|
||||
#include <regex>
|
||||
#include <options.h>
|
||||
#include <filesystem>
|
||||
|
||||
FolderSelect::FolderSelect(std::string defaultPath) {
|
||||
setPath(defaultPath);
|
||||
}
|
||||
|
||||
bool FolderSelect::render(std::string id) {
|
||||
bool _pathChanged = false;
|
||||
#ifdef _WIN32
|
||||
float menuColumnWidth = ImGui::GetContentRegionAvailWidth();
|
||||
float buttonWidth = ImGui::CalcTextSize("...").x + 20.0f;
|
||||
bool lastPathValid = pathValid;
|
||||
if (!lastPathValid) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
|
||||
}
|
||||
ImGui::SetNextItemWidth(menuColumnWidth - buttonWidth);
|
||||
if (ImGui::InputText(id.c_str(), strPath, 2047)) {
|
||||
path = std::string(strPath);
|
||||
std::string expandedPath = expandString(strPath);
|
||||
if (!std::filesystem::is_directory(expandedPath)) {
|
||||
pathValid = false;
|
||||
}
|
||||
else {
|
||||
pathValid = true;
|
||||
_pathChanged = true;
|
||||
}
|
||||
}
|
||||
if (!lastPathValid) {
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(("..." + id + "_winselect").c_str(), ImVec2(buttonWidth - 8.0f, 0)) && !dialogOpen) {
|
||||
dialogOpen = true;
|
||||
if (workerThread.joinable()) { workerThread.join(); }
|
||||
workerThread = std::thread(&FolderSelect::windowsWorker, this);
|
||||
}
|
||||
#else
|
||||
bool lastPathValid = pathValid;
|
||||
if (!lastPathValid) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
|
||||
}
|
||||
if (ImGui::InputText(id.c_str(), strPath, 2047)) {
|
||||
path = std::string(strPath);
|
||||
std::string expandedPath = expandString(strPath);
|
||||
if (!std::filesystem::is_directory(expandedPath)) {
|
||||
pathValid = false;
|
||||
}
|
||||
else {
|
||||
pathValid = true;
|
||||
_pathChanged = true;
|
||||
}
|
||||
}
|
||||
if (!lastPathValid) {
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
#endif
|
||||
_pathChanged |= pathChanged;
|
||||
pathChanged = false;
|
||||
return _pathChanged;
|
||||
}
|
||||
|
||||
void FolderSelect::setPath(std::string path) {
|
||||
this->path = path;
|
||||
std::string expandedPath = expandString(path);
|
||||
pathValid = std::filesystem::is_directory(expandedPath);
|
||||
strcpy(strPath, path.c_str());
|
||||
}
|
||||
|
||||
std::string FolderSelect::expandString(std::string input) {
|
||||
input = std::regex_replace(input, std::regex("%ROOT%"), options::opts.root);
|
||||
return std::regex_replace(input, std::regex("//"), "/");
|
||||
}
|
||||
|
||||
bool FolderSelect::pathIsValid() {
|
||||
return pathValid;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
void FolderSelect::windowsWorker() {
|
||||
IFileOpenDialog *pFileOpen;
|
||||
HRESULT hr;
|
||||
|
||||
// Create the FileOpenDialog object.
|
||||
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
|
||||
|
||||
DWORD options;
|
||||
pFileOpen->GetOptions(&options);
|
||||
pFileOpen->SetOptions(options | FOS_PICKFOLDERS);
|
||||
|
||||
hr = pFileOpen->Show(NULL);
|
||||
if (SUCCEEDED(hr)) {
|
||||
PWSTR pszFilePath;
|
||||
IShellItem *pItem;
|
||||
hr = pFileOpen->GetResult(&pItem);
|
||||
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
|
||||
wcstombs(strPath, pszFilePath, 2048);
|
||||
CoTaskMemFree(pszFilePath);
|
||||
path = std::string(strPath);
|
||||
pathChanged = true;
|
||||
}
|
||||
|
||||
pathValid = std::filesystem::is_directory(path);
|
||||
dialogOpen = false;
|
||||
}
|
||||
#endif
|
35
core/src/gui/widgets/folder_select.h
Normal file
35
core/src/gui/widgets/folder_select.h
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#include <ShlObj_core.h>
|
||||
#include <thread>
|
||||
#endif
|
||||
|
||||
class FolderSelect {
|
||||
public:
|
||||
FolderSelect(std::string defaultPath);
|
||||
bool render(std::string id);
|
||||
void setPath(std::string path);
|
||||
bool pathIsValid();
|
||||
|
||||
std::string expandString(std::string input);
|
||||
|
||||
std::string path = "";
|
||||
|
||||
|
||||
private:
|
||||
#ifdef _WIN32
|
||||
void windowsWorker();
|
||||
std::thread workerThread;
|
||||
#endif
|
||||
|
||||
bool pathValid = false;
|
||||
bool dialogOpen = false;
|
||||
char strPath[2048];
|
||||
bool pathChanged = false;
|
||||
};
|
@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
|
||||
namespace ImGui {
|
||||
template<class T>
|
||||
inline bool AllowScrollwheel(T& value, int stepCount, T min, T max) {
|
||||
if(!ImGui::IsItemHovered()) { return false; }
|
||||
T lastVal = value;
|
||||
T step = (max - min) / (T)stepCount;
|
||||
value = std::clamp<T>(value + ((T)ImGui::GetIO().MouseWheel * step), (min < max) ? min : max, (max > min) ? max : min);
|
||||
return (value != lastVal);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline bool AllowScrollwheelStSz(T& value, T step, T min, T max) {
|
||||
if(!ImGui::IsItemHovered()) { return false; }
|
||||
T lastVal = value;
|
||||
value = std::clamp<T>(value + ((T)ImGui::GetIO().MouseWheel * step), (min < max) ? min : max, (max > min) ? max : min);
|
||||
return (value != lastVal);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#include <gui/widgets/stepped_slider.h>
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <gui/widgets/scroll_behavior.h>
|
||||
|
||||
|
||||
namespace ImGui {
|
||||
bool SliderFloatWithSteps(const char* label, float* v, float v_min, float v_max, float v_step, const char* display_format) {
|
||||
@ -16,7 +16,6 @@ namespace ImGui {
|
||||
const int countValues = int((v_max-v_min)/v_step);
|
||||
int v_i = int((*v - v_min)/v_step);
|
||||
bool value_changed = ImGui::SliderInt(label, &v_i, 0, countValues, text_buf);
|
||||
value_changed |= ImGui::AllowScrollwheelStSz<int>(v_i, 1, 0, countValues);
|
||||
|
||||
// Remap from [0,N] to [v_min,v_max]
|
||||
*v = v_min + float(v_i) * v_step;
|
||||
|
Reference in New Issue
Block a user