Formatted the entire codebase and added a CI check for formatting

This commit is contained in:
AlexandreRouma
2021-12-19 22:11:44 +01:00
parent 8644957881
commit ea587db0cb
161 changed files with 3302 additions and 3393 deletions

View File

@ -21,10 +21,10 @@ namespace bandplan {
void to_json(json& j, const Band_t& b) {
j = json{
{"name", b.name},
{"type", b.type},
{"start", b.start},
{"end", b.end},
{ "name", b.name },
{ "type", b.type },
{ "start", b.start },
{ "end", b.end },
};
}
@ -37,12 +37,12 @@ namespace bandplan {
void to_json(json& j, const BandPlan_t& b) {
j = json{
{"name", b.name},
{"country_name", b.countryName},
{"country_code", b.countryCode},
{"author_name", b.authorName},
{"author_url", b.authorURL},
{"bands", b.bands}
{ "name", b.name },
{ "country_name", b.countryName },
{ "country_code", b.countryCode },
{ "author_name", b.authorName },
{ "author_url", b.authorURL },
{ "bands", b.bands }
};
}
@ -58,7 +58,7 @@ namespace bandplan {
void to_json(json& j, const BandPlanColor_t& ct) {
spdlog::error("ImGui color to JSON not implemented!!!");
}
void from_json(const json& j, BandPlanColor_t& ct) {
std::string col = j.get<std::string>();
if (col[0] != '#' || !std::all_of(col.begin() + 1, col.end(), ::isxdigit)) {
@ -99,7 +99,7 @@ namespace bandplan {
return;
}
bandplans.clear();
for (const auto & file : std::filesystem::directory_iterator(path)) {
for (const auto& file : std::filesystem::directory_iterator(path)) {
std::string path = file.path().generic_string();
if (file.path().extension().generic_string() != ".json") {
continue;

View File

@ -35,7 +35,7 @@ namespace bandplan {
void to_json(json& j, const BandPlanColor_t& ct);
void from_json(const json& j, BandPlanColor_t& ct);
void loadBandPlan(std::string path);
void loadFromDir(std::string path);
void loadColorTable(json table);

View File

@ -12,7 +12,7 @@ namespace ImGui {
float pad = style.FramePadding.y;
ImVec2 min = window->DC.CursorPos;
ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), CalcItemWidth());
ImRect bb(min, ImVec2(min.x+size.x, min.y+size.y));
ImRect bb(min, ImVec2(min.x + size.x, min.y + size.y));
float lineHeight = size.y;
ItemSize(size, style.FramePadding.y);
@ -20,13 +20,13 @@ namespace ImGui {
return;
}
window->DrawList->AddRectFilled(min, ImVec2(min.x+size.x, min.y+size.y), IM_COL32(0,0,0,255));
window->DrawList->AddRectFilled(min, ImVec2(min.x + size.x, min.y + size.y), IM_COL32(0, 0, 0, 255));
ImU32 col = ImGui::GetColorU32(ImGuiCol_CheckMark, 0.7f);
float increment = size.x / 1024.0f;
for (int i = 0; i < 1024; i++) {
if (buffer[i].re > 1.5f || buffer[i].re < -1.5f) { continue; }
if (buffer[i].im > 1.5f || buffer[i].im < -1.5f) { continue; }
window->DrawList->AddCircleFilled(ImVec2((((buffer[i].re / 1.5f) + 1) * (size.x*0.5f)) + min.x, (((buffer[i].im / 1.5f) + 1) * (size.y*0.5f)) + min.y), 2, col);
window->DrawList->AddCircleFilled(ImVec2((((buffer[i].re / 1.5f) + 1) * (size.x * 0.5f)) + min.x, (((buffer[i].im / 1.5f) + 1) * (size.y * 0.5f)) + min.y), 2, col);
}
}

View File

@ -20,6 +20,5 @@ namespace ImGui {
private:
std::mutex bufferMtx;
dsp::complex_t buffer[1024];
};
}

View File

@ -39,7 +39,7 @@ bool FileSelect::render(std::string id) {
if (workerThread.joinable()) { workerThread.join(); }
workerThread = std::thread(&FileSelect::worker, this);
}
_pathChanged |= pathChanged;
pathChanged = false;
return _pathChanged;
@ -63,15 +63,15 @@ bool FileSelect::pathIsValid() {
}
void FileSelect::worker() {
auto file = pfd::open_file("Open File", pathValid ? std::filesystem::path(expandString(path)).parent_path().string() : "", _filter);
std::vector<std::string> res = file.result();
auto file = pfd::open_file("Open File", pathValid ? std::filesystem::path(expandString(path)).parent_path().string() : "", _filter);
std::vector<std::string> res = file.result();
if (res.size() > 0) {
path = res[0];
strcpy(strPath, path.c_str());
pathChanged = true;
}
if (res.size() > 0) {
path = res[0];
strcpy(strPath, path.c_str());
pathChanged = true;
}
pathValid = std::filesystem::is_regular_file(expandString(path));
dialogOpen = false;
pathValid = std::filesystem::is_regular_file(expandString(path));
dialogOpen = false;
}

View File

@ -8,7 +8,7 @@
class FileSelect {
public:
FileSelect(std::string defaultPath, std::vector<std::string> filter = {"All Files", "*"});
FileSelect(std::string defaultPath, std::vector<std::string> filter = { "All Files", "*" });
bool render(std::string id);
void setPath(std::string path, bool markChanged = false);
bool pathIsValid();
@ -16,7 +16,7 @@ public:
std::string expandString(std::string input);
std::string path = "";
private:
void worker();

View File

@ -38,7 +38,7 @@ bool FolderSelect::render(std::string id) {
if (workerThread.joinable()) { workerThread.join(); }
workerThread = std::thread(&FolderSelect::worker, this);
}
_pathChanged |= pathChanged;
pathChanged = false;
return _pathChanged;
@ -62,15 +62,15 @@ bool FolderSelect::pathIsValid() {
}
void FolderSelect::worker() {
auto fold = pfd::select_folder("Select Folder", pathValid ? std::filesystem::path(expandString(path)).parent_path().string() : "");
std::string res = fold.result();
auto fold = pfd::select_folder("Select Folder", pathValid ? std::filesystem::path(expandString(path)).parent_path().string() : "");
std::string res = fold.result();
if (res != "") {
path = res;
strcpy(strPath, path.c_str());
pathChanged = true;
}
if (res != "") {
path = res;
strcpy(strPath, path.c_str());
pathChanged = true;
}
pathValid = std::filesystem::is_directory(expandString(path));
dialogOpen = false;
pathValid = std::filesystem::is_directory(expandString(path));
dialogOpen = false;
}

View File

@ -15,7 +15,7 @@ public:
std::string expandString(std::string input);
std::string path = "";
private:
void worker();

View File

@ -15,13 +15,11 @@ bool isInArea(ImVec2 val, ImVec2 min, ImVec2 max) {
}
FrequencySelect::FrequencySelect() {
}
void FrequencySelect::init() {
for (int i = 0; i < 12; i++) {
digits[i] = 0;
}
}
@ -45,7 +43,6 @@ void FrequencySelect::onPosChange() {
}
void FrequencySelect::onResize() {
}
void FrequencySelect::incrementDigit(int i) {
@ -126,7 +123,7 @@ void FrequencySelect::draw() {
int digitWidth = digitSz.x;
int commaOffset = 0;
bool zeros = true;
ImGui::ItemSize(ImRect(digitTopMins[0], ImVec2(digitBottomMaxs[11].x + 15, digitBottomMaxs[11].y)));
for (int i = 0; i < 12; i++) {
@ -134,12 +131,12 @@ void FrequencySelect::draw() {
zeros = false;
}
sprintf(buf, "%d", digits[i]);
window->DrawList->AddText(ImVec2(widgetPos.x + (i * digitWidth) + commaOffset, widgetPos.y),
zeros ? disabledColor : textColor, buf);
window->DrawList->AddText(ImVec2(widgetPos.x + (i * digitWidth) + commaOffset, widgetPos.y),
zeros ? disabledColor : textColor, buf);
if ((i + 1) % 3 == 0 && i < 11) {
commaOffset += commaSz.x;
window->DrawList->AddText(ImVec2(widgetPos.x + (i * digitWidth) + commaOffset + 11, widgetPos.y),
zeros ? disabledColor : textColor, ".");
window->DrawList->AddText(ImVec2(widgetPos.x + (i * digitWidth) + commaOffset + 11, widgetPos.y),
zeros ? disabledColor : textColor, ".");
}
}
@ -183,7 +180,7 @@ void FrequencySelect::draw() {
decrementDigit(i);
}
if ((ImGui::IsKeyPressed(GLFW_KEY_LEFT) || ImGui::IsKeyPressed(GLFW_KEY_BACKSPACE)) && i > 0) {
moveCursorToDigit(i - 1);
moveCursorToDigit(i - 1);
}
if (ImGui::IsKeyPressed(GLFW_KEY_RIGHT) && i < 11) {
moveCursorToDigit(i + 1);

View File

@ -30,7 +30,7 @@ namespace ImGui {
float height = roundf((width / (float)_width) * (float)_height);
ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), height);
ImRect bb(min, ImVec2(min.x+size.x, min.y+size.y));
ImRect bb(min, ImVec2(min.x + size.x, min.y + size.y));
float lineHeight = size.y;
ItemSize(size, style.FramePadding.y);
@ -42,7 +42,7 @@ namespace ImGui {
newData = false;
updateTexture();
}
window->DrawList->AddImage((void*)(intptr_t)textureId, min, ImVec2(min.x + width, min.y + height));
}

View File

@ -28,6 +28,5 @@ namespace ImGui {
GLuint textureId;
bool newData = false;
};
}

View File

@ -23,7 +23,7 @@ namespace ImGui {
float height = roundf((width / (float)_frameWidth) * (float)_lineCount);
ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), height);
ImRect bb(min, ImVec2(min.x+size.x, min.y+size.y));
ImRect bb(min, ImVec2(min.x + size.x, min.y + size.y));
float lineHeight = size.y;
// If there are no lines, there is no point in drawing anything
@ -38,7 +38,7 @@ namespace ImGui {
newData = false;
updateTexture();
}
window->DrawList->AddImage((void*)(intptr_t)textureId, min, ImVec2(min.x + width, min.y + height));
}

View File

@ -37,7 +37,5 @@ namespace ImGui {
GLuint textureId;
bool newData = false;
};
}

View File

@ -4,7 +4,6 @@
#include <gui/style.h>
Menu::Menu() {
}
void Menu::registerEntry(std::string name, void (*drawHandler)(void* ctx), void* ctx, ModuleManager::Instance* inst) {
@ -67,9 +66,9 @@ bool Menu::draw(bool updateStates) {
window->DrawList->AddRect(posMin, posMax, textColor);
}
displayedCount++;
MenuItem_t& item = items[opt.name];
ImRect orginalRect = window->WorkRect;
if (item.inst != NULL) {
@ -79,8 +78,8 @@ bool Menu::draw(bool updateStates) {
ImVec2 posMin = ImGui::GetCursorScreenPos();
ImVec2 posMax = ImVec2(posMin.x + menuWidth, posMin.y + ImGui::GetFrameHeight());
headerTops[displayedCount-1] = posMin.y;
optionIDs[displayedCount-1] = rawId-1;
headerTops[displayedCount - 1] = posMin.y;
optionIDs[displayedCount - 1] = rawId - 1;
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && ImGui::IsMouseHoveringRect(posMin, posMax)) {
menuClicked = true;
@ -89,7 +88,7 @@ bool Menu::draw(bool updateStates) {
if (menuClicked && ImGui::IsMouseDragging(ImGuiMouseButton_Left) && draggedMenuName.empty() && clickedMenuName == opt.name) {
draggedMenuName = opt.name;
draggedId = rawId-1;
draggedId = rawId - 1;
draggedOpt = opt;
continue;
}
@ -142,7 +141,7 @@ bool Menu::draw(bool updateStates) {
}
if (!ImGui::IsMouseDown(ImGuiMouseButton_Left) && menuClicked) {
if (!draggedMenuName.empty()) {
// Move menu
order.erase(order.begin() + draggedId);
@ -162,7 +161,7 @@ bool Menu::draw(bool updateStates) {
}
changed = true;
}
menuClicked = false;
draggedMenuName = "";
insertBeforeName = "";

View File

@ -4,7 +4,7 @@
#include <map>
#include <module.h>
#define MAX_MENU_COUNT 1024
#define MAX_MENU_COUNT 1024
class Menu {
public:

View File

@ -39,7 +39,7 @@ namespace ImGui {
window->DrawList->AddLine(min + ImVec2(roundf((float)i * it), 9), min + ImVec2(roundf((float)i * it), 14), text);
sprintf(buf, "%d", i * 10);
ImVec2 sz = ImGui::CalcTextSize(buf);
window->DrawList->AddText(min + ImVec2(roundf(((float)i * it) - (sz.x/2.0)) + 1, 16), text, buf);
window->DrawList->AddText(min + ImVec2(roundf(((float)i * it) - (sz.x / 2.0)) + 1, 16), text, buf);
}
}
}

View File

@ -13,8 +13,8 @@ namespace ImGui {
ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), display_format, *v);
// Map from [v_min,v_max] to [0,N]
const int countValues = int((v_max-v_min)/v_step);
int v_i = int((*v - v_min)/v_step);
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);
// Remap from [0,N] to [v_min,v_max]

View File

@ -21,7 +21,7 @@ namespace ImGui {
float pad = style.FramePadding.y;
ImVec2 min = window->DC.CursorPos;
ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), 100);
ImRect bb(min, ImVec2(min.x+size.x, min.y+size.y));
ImRect bb(min, ImVec2(min.x + size.x, min.y + size.y));
float lineHeight = size.y;
ItemSize(size, style.FramePadding.y);
@ -29,20 +29,20 @@ namespace ImGui {
return;
}
window->DrawList->AddRectFilled(min, ImVec2(min.x+size.x, min.y+size.y), IM_COL32(0,0,0,255));
window->DrawList->AddRectFilled(min, ImVec2(min.x + size.x, min.y + size.y), IM_COL32(0, 0, 0, 255));
ImU32 col = ImGui::GetColorU32(ImGuiCol_CheckMark, 0.7f);
ImU32 col2 = ImGui::GetColorU32(ImGuiCol_CheckMark, 0.7f);
float increment = size.x / (float)sampleCount;
float val;
for (auto l : lines) {
window->DrawList->AddLine(ImVec2(min.x, (((l * _scale) + 1) * (size.y*0.5f)) + min.y), ImVec2(min.x + size.x, (((l * _scale) + 1) * (size.y*0.5f)) + min.y), IM_COL32(80, 80, 80, 255));
window->DrawList->AddLine(ImVec2(min.x, (((l * _scale) + 1) * (size.y * 0.5f)) + min.y), ImVec2(min.x + size.x, (((l * _scale) + 1) * (size.y * 0.5f)) + min.y), IM_COL32(80, 80, 80, 255));
}
for (int i = 0; i < sampleCount; i++) {
val = buffer[i] * _scale;
if (val > 1.0f || val < -1.0f) { continue; }
window->DrawList->AddCircleFilled(ImVec2(((float)i * increment) + min.x, ((val + 1) * (size.y*0.5f)) + min.y), 2, col);
window->DrawList->AddCircleFilled(ImVec2(((float)i * increment) + min.x, ((val + 1) * (size.y * 0.5f)) + min.y), 2, col);
}
}

View File

@ -25,6 +25,5 @@ namespace ImGui {
float* buffer;
float _scale;
int sampleCount = 0;
};
}

View File

@ -29,25 +29,25 @@ namespace ImGui {
float zeroDb = roundf(((-val_min) / (val_max - val_min)) * size.x);
window->DrawList->AddRectFilled(min, min + ImVec2(zeroDb, lineHeight), IM_COL32( 9, 136, 9, 255 ));
window->DrawList->AddRectFilled(min + ImVec2(zeroDb, 0), min + ImVec2(size.x, lineHeight), IM_COL32( 136, 9, 9, 255 ));
window->DrawList->AddRectFilled(min, min + ImVec2(zeroDb, lineHeight), IM_COL32(9, 136, 9, 255));
window->DrawList->AddRectFilled(min + ImVec2(zeroDb, 0), min + ImVec2(size.x, lineHeight), IM_COL32(136, 9, 9, 255));
float end = roundf(((avg - val_min) / (val_max - val_min)) * size.x);
float endP = roundf(((peak - val_min) / (val_max - val_min)) * size.x);
if (avg <= 0) {
window->DrawList->AddRectFilled(min, min + ImVec2(end, lineHeight), IM_COL32( 0, 255, 0, 255 ));
window->DrawList->AddRectFilled(min, min + ImVec2(end, lineHeight), IM_COL32(0, 255, 0, 255));
}
else {
window->DrawList->AddRectFilled(min, min + ImVec2(zeroDb, lineHeight), IM_COL32( 0, 255, 0, 255 ));
window->DrawList->AddRectFilled(min + ImVec2(zeroDb, 0), min + ImVec2(end, lineHeight), IM_COL32( 255, 0, 0, 255 ));
window->DrawList->AddRectFilled(min, min + ImVec2(zeroDb, lineHeight), IM_COL32(0, 255, 0, 255));
window->DrawList->AddRectFilled(min + ImVec2(zeroDb, 0), min + ImVec2(end, lineHeight), IM_COL32(255, 0, 0, 255));
}
if (peak <= 0) {
window->DrawList->AddLine(min + ImVec2(endP, -1), min + ImVec2(endP, lineHeight - 1), IM_COL32( 127, 255, 127, 255 ));
window->DrawList->AddLine(min + ImVec2(endP, -1), min + ImVec2(endP, lineHeight - 1), IM_COL32(127, 255, 127, 255));
}
else {
window->DrawList->AddLine(min + ImVec2(endP, -1), min + ImVec2(endP, lineHeight - 1), IM_COL32( 255, 127, 127, 255 ));
window->DrawList->AddLine(min + ImVec2(endP, -1), min + ImVec2(endP, lineHeight - 1), IM_COL32(255, 127, 127, 255));
}
}
}

View File

@ -10,32 +10,32 @@
#include <gui/gui.h>
float DEFAULT_COLOR_MAP[][3] = {
{0x00, 0x00, 0x20},
{0x00, 0x00, 0x30},
{0x00, 0x00, 0x50},
{0x00, 0x00, 0x91},
{0x1E, 0x90, 0xFF},
{0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0x00},
{0xFE, 0x6D, 0x16},
{0xFF, 0x00, 0x00},
{0xC6, 0x00, 0x00},
{0x9F, 0x00, 0x00},
{0x75, 0x00, 0x00},
{0x4A, 0x00, 0x00}
{ 0x00, 0x00, 0x20 },
{ 0x00, 0x00, 0x30 },
{ 0x00, 0x00, 0x50 },
{ 0x00, 0x00, 0x91 },
{ 0x1E, 0x90, 0xFF },
{ 0xFF, 0xFF, 0xFF },
{ 0xFF, 0xFF, 0x00 },
{ 0xFE, 0x6D, 0x16 },
{ 0xFF, 0x00, 0x00 },
{ 0xC6, 0x00, 0x00 },
{ 0x9F, 0x00, 0x00 },
{ 0x75, 0x00, 0x00 },
{ 0x4A, 0x00, 0x00 }
};
// TODO: Fix this hacky BS
double freq_ranges[] = {
1.0, 2.0, 2.5, 5.0,
10.0, 20.0, 25.0, 50.0,
100.0, 200.0, 250.0, 500.0,
1000.0, 2000.0, 2500.0, 5000.0,
10000.0, 20000.0, 25000.0, 50000.0,
100000.0, 200000.0, 250000.0, 500000.0,
1000000.0, 2000000.0, 2500000.0, 5000000.0,
10000000.0, 20000000.0, 25000000.0, 50000000.0
1.0, 2.0, 2.5, 5.0,
10.0, 20.0, 25.0, 50.0,
100.0, 200.0, 250.0, 500.0,
1000.0, 2000.0, 2500.0, 5000.0,
10000.0, 20000.0, 25000.0, 50000.0,
100000.0, 200000.0, 250000.0, 500000.0,
1000000.0, 2000000.0, 2500000.0, 5000000.0,
10000000.0, 20000000.0, 25000000.0, 50000000.0
};
inline double findBestRange(double bandwidth, int maxSteps) {
@ -104,9 +104,9 @@ namespace ImGui {
// Vertical scale
for (float line = startLine; line > fftMin; line -= vRange) {
float yPos = widgetPos.y + fftHeight + 10 - ((line - fftMin) * scaleFactor);
window->DrawList->AddLine(ImVec2(roundf(widgetPos.x + 50), roundf(yPos)),
ImVec2(roundf(widgetPos.x + dataWidth + 50), roundf(yPos)),
IM_COL32(50, 50, 50, 255), 1.0);
window->DrawList->AddLine(ImVec2(roundf(widgetPos.x + 50), roundf(yPos)),
ImVec2(roundf(widgetPos.x + dataWidth + 50), roundf(yPos)),
IM_COL32(50, 50, 50, 255), 1.0);
sprintf(buf, "%d", (int)line);
ImVec2 txtSz = ImGui::CalcTextSize(buf);
window->DrawList->AddText(ImVec2(widgetPos.x + 40 - txtSz.x, roundf(yPos - (txtSz.y / 2.0))), text, buf);
@ -117,12 +117,12 @@ namespace ImGui {
double horizScale = (double)dataWidth / viewBandwidth;
for (double freq = startFreq; freq < upperFreq; freq += range) {
double xPos = widgetPos.x + 50 + ((freq - lowerFreq) * horizScale);
window->DrawList->AddLine(ImVec2(roundf(xPos), widgetPos.y + 10),
ImVec2(roundf(xPos), widgetPos.y + fftHeight + 10),
IM_COL32(50, 50, 50, 255), 1.0);
window->DrawList->AddLine(ImVec2(roundf(xPos), widgetPos.y + fftHeight + 10),
ImVec2(roundf(xPos), widgetPos.y + fftHeight + 17),
text, 1.0);
window->DrawList->AddLine(ImVec2(roundf(xPos), widgetPos.y + 10),
ImVec2(roundf(xPos), widgetPos.y + fftHeight + 10),
IM_COL32(50, 50, 50, 255), 1.0);
window->DrawList->AddLine(ImVec2(roundf(xPos), widgetPos.y + fftHeight + 10),
ImVec2(roundf(xPos), widgetPos.y + fftHeight + 17),
text, 1.0);
printAndScale(freq, buf);
ImVec2 txtSz = ImGui::CalcTextSize(buf);
window->DrawList->AddText(ImVec2(roundf(xPos - (txtSz.x / 2.0)), widgetPos.y + fftHeight + 10 + txtSz.y), text, buf);
@ -130,15 +130,15 @@ namespace ImGui {
// Data
if (latestFFT != NULL && fftLines != 0) {
for (int i = 1; i < dataWidth; i++) {
for (int i = 1; i < dataWidth; i++) {
double aPos = widgetPos.y + fftHeight + 10 - ((latestFFT[i - 1] - fftMin) * scaleFactor);
double bPos = widgetPos.y + fftHeight + 10 - ((latestFFT[i] - fftMin) * scaleFactor);
aPos = std::clamp<double>(aPos, widgetPos.y + 10, widgetPos.y + fftHeight + 10);
bPos = std::clamp<double>(bPos, widgetPos.y + 10, widgetPos.y + fftHeight + 10);
window->DrawList->AddLine(ImVec2(widgetPos.x + 49 + i, roundf(aPos)),
ImVec2(widgetPos.x + 50 + i, roundf(bPos)), trace, 1.0);
window->DrawList->AddLine(ImVec2(widgetPos.x + 50 + i, roundf(bPos)),
ImVec2(widgetPos.x + 50 + i, widgetPos.y + fftHeight + 10), shadow, 1.0);
window->DrawList->AddLine(ImVec2(widgetPos.x + 49 + i, roundf(aPos)),
ImVec2(widgetPos.x + 50 + i, roundf(bPos)), trace, 1.0);
window->DrawList->AddLine(ImVec2(widgetPos.x + 50 + i, roundf(bPos)),
ImVec2(widgetPos.x + 50 + i, widgetPos.y + fftHeight + 10), shadow, 1.0);
}
}
@ -153,13 +153,13 @@ namespace ImGui {
onFFTRedraw.emit(args);
// X Axis
window->DrawList->AddLine(ImVec2(widgetPos.x + 50, widgetPos.y + fftHeight + 10),
ImVec2(widgetPos.x + dataWidth + 50, widgetPos.y + fftHeight + 10),
text, 1.0);
window->DrawList->AddLine(ImVec2(widgetPos.x + 50, widgetPos.y + fftHeight + 10),
ImVec2(widgetPos.x + dataWidth + 50, widgetPos.y + fftHeight + 10),
text, 1.0);
// Y Axis
window->DrawList->AddLine(ImVec2(widgetPos.x + 50, widgetPos.y + 9),
ImVec2(widgetPos.x + 50, widgetPos.y + fftHeight + 9),
text, 1.0);
window->DrawList->AddLine(ImVec2(widgetPos.x + 50, widgetPos.y + 9),
ImVec2(widgetPos.x + 50, widgetPos.y + fftHeight + 9),
text, 1.0);
}
void WaterFall::drawWaterfall() {
@ -210,8 +210,8 @@ namespace ImGui {
ImVec2 dragOrigin(mousePos.x - drag.x, mousePos.y - drag.y);
bool mouseHovered, mouseHeld;
bool mouseClicked = ImGui::ButtonBehavior(ImRect(fftAreaMin, wfMax), GetID("WaterfallID"), &mouseHovered, &mouseHeld,
ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_PressedOnClick);
bool mouseClicked = ImGui::ButtonBehavior(ImRect(fftAreaMin, wfMax), GetID("WaterfallID"), &mouseHovered, &mouseHeld,
ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_PressedOnClick);
mouseInFFTResize = (dragOrigin.x > widgetPos.x && dragOrigin.x < widgetPos.x + widgetSize.x && dragOrigin.y >= widgetPos.y + newFFTAreaHeight - 2 && dragOrigin.y <= widgetPos.y + newFFTAreaHeight + 2);
mouseInFreq = IS_IN_AREA(dragOrigin, freqAreaMin, freqAreaMax);
@ -268,12 +268,16 @@ namespace ImGui {
bool resizing = false;
if (_vfo->reference != REF_LOWER) {
if (IS_IN_AREA(mousePos, _vfo->lbwSelMin, _vfo->lbwSelMax)) { resizing = true; }
else if (IS_IN_AREA(mousePos, _vfo->wfLbwSelMin, _vfo->wfLbwSelMax)) { resizing = true; }
else if (IS_IN_AREA(mousePos, _vfo->wfLbwSelMin, _vfo->wfLbwSelMax)) {
resizing = true;
}
}
if (_vfo->reference != REF_UPPER) {
if (IS_IN_AREA(mousePos, _vfo->rbwSelMin, _vfo->rbwSelMax)) { resizing = true; }
else if (IS_IN_AREA(mousePos, _vfo->wfRbwSelMin, _vfo->wfRbwSelMax)) { resizing = true; }
}
else if (IS_IN_AREA(mousePos, _vfo->wfRbwSelMin, _vfo->wfRbwSelMax)) {
resizing = true;
}
}
if (!resizing) { continue; }
relatedVfo = _vfo;
vfoBorderSelect = true;
@ -300,7 +304,7 @@ namespace ImGui {
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS);
newFFTAreaHeight = mousePos.y - widgetPos.y;
newFFTAreaHeight = std::clamp<float>(newFFTAreaHeight, 150, widgetSize.y - 50);
ImGui::GetForegroundDrawList()->AddLine(ImVec2(widgetPos.x, newFFTAreaHeight + widgetPos.y), ImVec2(widgetEndPos.x, newFFTAreaHeight + widgetPos.y),
ImGui::GetForegroundDrawList()->AddLine(ImVec2(widgetPos.x, newFFTAreaHeight + widgetPos.y), ImVec2(widgetEndPos.x, newFFTAreaHeight + widgetPos.y),
ImGui::GetColorU32(ImGuiCol_SeparatorActive));
return;
}
@ -386,7 +390,7 @@ namespace ImGui {
// If the left and right keys are pressed while hovering the freq scale, move it too
bool leftKeyPressed = ImGui::IsKeyPressed(GLFW_KEY_LEFT);
if ((leftKeyPressed || ImGui::IsKeyPressed(GLFW_KEY_RIGHT)) && mouseInFreq) {
viewOffset += leftKeyPressed ? (viewBandwidth / 20.0) : (-viewBandwidth / 20.0);
viewOffset += leftKeyPressed ? (viewBandwidth / 20.0) : (-viewBandwidth / 20.0);
if (viewOffset + (viewBandwidth / 2.0) > wholeBandwidth / 2.0) {
double freqOffset = (viewOffset + (viewBandwidth / 2.0)) - (wholeBandwidth / 2.0);
@ -412,7 +416,7 @@ namespace ImGui {
}
// Finally, if nothing else was selected, just move the VFO
if ((VFOMoveSingleClick ? ImGui::IsMouseClicked(ImGuiMouseButton_Left) : ImGui::IsMouseDown(ImGuiMouseButton_Left)) && (mouseInFFT|mouseInWaterfall) && (mouseMoved || hoveredVFOName == "")) {
if ((VFOMoveSingleClick ? ImGui::IsMouseClicked(ImGuiMouseButton_Left) : ImGui::IsMouseDown(ImGuiMouseButton_Left)) && (mouseInFFT | mouseInWaterfall) && (mouseMoved || hoveredVFOName == "")) {
if (selVfo != NULL) {
int refCenter = mousePos.x - (widgetPos.x + 50);
if (refCenter >= 0 && refCenter < dataWidth) {
@ -509,13 +513,13 @@ namespace ImGui {
// Calculate FFT index data
double vfoMinSizeFreq = _vfo->centerOffset - _vfo->bandwidth;
double vfoMinFreq = _vfo->centerOffset - (_vfo->bandwidth/2.0);
double vfoMaxFreq = _vfo->centerOffset + (_vfo->bandwidth/2.0);
double vfoMinFreq = _vfo->centerOffset - (_vfo->bandwidth / 2.0);
double vfoMaxFreq = _vfo->centerOffset + (_vfo->bandwidth / 2.0);
double vfoMaxSizeFreq = _vfo->centerOffset + _vfo->bandwidth;
int vfoMinSideOffset = std::clamp<int>(((vfoMinSizeFreq / (wholeBandwidth/2.0)) * (double)(rawFFTSize/2)) + (rawFFTSize/2), 0, rawFFTSize);
int vfoMinOffset = std::clamp<int>(((vfoMinFreq / (wholeBandwidth/2.0)) * (double)(rawFFTSize/2)) + (rawFFTSize/2), 0, rawFFTSize);
int vfoMaxOffset = std::clamp<int>(((vfoMaxFreq / (wholeBandwidth/2.0)) * (double)(rawFFTSize/2)) + (rawFFTSize/2), 0, rawFFTSize);
int vfoMaxSideOffset = std::clamp<int>(((vfoMaxSizeFreq / (wholeBandwidth/2.0)) * (double)(rawFFTSize/2)) + (rawFFTSize/2), 0, rawFFTSize);
int vfoMinSideOffset = std::clamp<int>(((vfoMinSizeFreq / (wholeBandwidth / 2.0)) * (double)(rawFFTSize / 2)) + (rawFFTSize / 2), 0, rawFFTSize);
int vfoMinOffset = std::clamp<int>(((vfoMinFreq / (wholeBandwidth / 2.0)) * (double)(rawFFTSize / 2)) + (rawFFTSize / 2), 0, rawFFTSize);
int vfoMaxOffset = std::clamp<int>(((vfoMaxFreq / (wholeBandwidth / 2.0)) * (double)(rawFFTSize / 2)) + (rawFFTSize / 2), 0, rawFFTSize);
int vfoMaxSideOffset = std::clamp<int>(((vfoMaxSizeFreq / (wholeBandwidth / 2.0)) * (double)(rawFFTSize / 2)) + (rawFFTSize / 2), 0, rawFFTSize);
double avg = 0;
float max = -INFINITY;
@ -601,7 +605,7 @@ namespace ImGui {
else {
bpBottom = widgetPos.y + height + 10;
}
for (int i = 0; i < count; i++) {
start = bandplan->bands[i].start;
@ -637,20 +641,20 @@ namespace ImGui {
bPos = widgetPos.x + 51;
}
if (width >= 1.0) {
window->DrawList->AddRectFilled(ImVec2(roundf(aPos), bpBottom - height),
ImVec2(roundf(bPos), bpBottom), colorTrans);
window->DrawList->AddRectFilled(ImVec2(roundf(aPos), bpBottom - height),
ImVec2(roundf(bPos), bpBottom), colorTrans);
if (startVis) {
window->DrawList->AddLine(ImVec2(roundf(aPos), bpBottom - height - 1),
ImVec2(roundf(aPos), bpBottom - 1), color);
window->DrawList->AddLine(ImVec2(roundf(aPos), bpBottom - height - 1),
ImVec2(roundf(aPos), bpBottom - 1), color);
}
if (endVis) {
window->DrawList->AddLine(ImVec2(roundf(bPos), bpBottom - height - 1),
ImVec2(roundf(bPos), bpBottom - 1), color);
window->DrawList->AddLine(ImVec2(roundf(bPos), bpBottom - height - 1),
ImVec2(roundf(bPos), bpBottom - 1), color);
}
}
if (txtSz.x <= width) {
window->DrawList->AddText(ImVec2(cPos - (txtSz.x / 2.0), bpBottom - (height / 2.0f) - (txtSz.y / 2.0f)),
IM_COL32(255, 255, 255, 255), bandplan->bands[i].name.c_str());
window->DrawList->AddText(ImVec2(cPos - (txtSz.x / 2.0), bpBottom - (height / 2.0f) - (txtSz.y / 2.0f)),
IM_COL32(255, 255, 255, 255), bandplan->bands[i].name.c_str());
}
}
}
@ -682,7 +686,7 @@ namespace ImGui {
waterfallHeight = widgetSize.y - fftHeight - 52;
}
else {
fftHeight = widgetSize.y - 50;
fftHeight = widgetSize.y - 50;
}
dataWidth = widgetSize.x - 60.0;
@ -766,7 +770,7 @@ namespace ImGui {
//window->DrawList->AddRectFilled(widgetPos, widgetEndPos, IM_COL32( 0, 0, 0, 255 ));
ImU32 bg = ImGui::ColorConvertFloat4ToU32(gui::themeManager.waterfallBg);
window->DrawList->AddRectFilled(widgetPos, widgetEndPos, bg);
window->DrawList->AddRect(widgetPos, widgetEndPos, IM_COL32( 50, 50, 50, 255 ));
window->DrawList->AddRect(widgetPos, widgetEndPos, IM_COL32(50, 50, 50, 255));
window->DrawList->AddLine(ImVec2(widgetPos.x, widgetPos.y + fftHeight + 50), ImVec2(widgetPos.x + widgetSize.x, widgetPos.y + fftHeight + 50), IM_COL32(50, 50, 50, 255), 1.0);
if (!gui::mainWindow.lockWaterfallControls) {
@ -787,7 +791,7 @@ namespace ImGui {
}
updateAllVFOs(true);
drawFFT();
if (waterfallVisible) {
drawWaterfall();
@ -823,7 +827,7 @@ namespace ImGui {
double offsetRatio = viewOffset / (wholeBandwidth / 2.0);
int drawDataSize = (viewBandwidth / wholeBandwidth) * rawFFTSize;
int drawDataStart = (((double)rawFFTSize / 2.0) * (offsetRatio + 1)) - (drawDataSize / 2);
// If in fast mode, apply IIR filtering
float* buf = &rawFFTs[currentFFTLine * rawFFTSize];
if (_fastFFT) {
@ -855,7 +859,7 @@ namespace ImGui {
float dummy;
calculateVFOSignalInfo(waterfallVisible ? &rawFFTs[currentFFTLine * rawFFTSize] : rawFFTs, vfos[selectedVFO], dummy, selectedVFOSNR);
}
buf_mtx.unlock();
}
@ -982,7 +986,7 @@ namespace ImGui {
double WaterFall::getViewOffset() {
return viewOffset;
}
void WaterFall::setFFTMin(float min) {
fftMin = min;
vRange = findBestRange(fftMax - fftMin, maxVSteps);
@ -1138,7 +1142,6 @@ namespace ImGui {
}
reference = ref;
setOffset(generalOffset);
}
void WaterfallVFO::updateDrawingVars(double viewBandwidth, float dataWidth, double viewOffset, ImVec2 widgetPos, int fftHeight) {
@ -1202,18 +1205,22 @@ namespace ImGui {
if (rectMax.x - rectMin.x < 10) { return; }
if (reference != REF_LOWER && !bandwidthLocked && !leftClamped) {
if (IS_IN_AREA(mousePos, lbwSelMin, lbwSelMax)) { ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW); }
else if (IS_IN_AREA(mousePos, wfLbwSelMin, wfLbwSelMax)) { ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW); }
else if (IS_IN_AREA(mousePos, wfLbwSelMin, wfLbwSelMax)) {
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW);
}
}
if (reference != REF_UPPER && !bandwidthLocked && !rightClamped) {
if (IS_IN_AREA(mousePos, rbwSelMin, rbwSelMax)) { ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW); }
else if (IS_IN_AREA(mousePos, wfRbwSelMin, wfRbwSelMax)) { ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW); }
else if (IS_IN_AREA(mousePos, wfRbwSelMin, wfRbwSelMax)) {
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW);
}
}
}
};
void WaterFall::showWaterfall() {
buf_mtx.lock();
if (rawFFTs == NULL) {
if (rawFFTs == NULL) {
spdlog::error("Null rawFFT");
}
waterfallVisible = true;
@ -1237,7 +1244,7 @@ namespace ImGui {
onResize();
buf_mtx.unlock();
}
int WaterFall::getFFTHeight() {
return FFTAreaHeight;
}
@ -1254,4 +1261,3 @@ namespace ImGui {
snapInterval = interval;
}
};

View File

@ -7,7 +7,7 @@
#include <GL/glew.h>
#include <utils/event.h>
#define WATERFALL_RESOLUTION 1000000
#define WATERFALL_RESOLUTION 1000000
namespace ImGui {
class WaterfallVFO {
@ -244,7 +244,7 @@ namespace ImGui {
bool waterfallUpdate = false;
uint32_t waterfallPallet[WATERFALL_RESOLUTION];
ImVec2 widgetPos;
ImVec2 widgetEndPos;
ImVec2 widgetSize;
@ -270,9 +270,9 @@ namespace ImGui {
int maxVSteps;
int maxHSteps;
int dataWidth; // Width of the FFT and waterfall
int fftHeight; // Height of the fft graph
int waterfallHeight = 0; // Height of the waterfall
int dataWidth; // Width of the FFT and waterfall
int fftHeight; // Height of the fft graph
int waterfallHeight = 0; // Height of the waterfall
double viewBandwidth;
double viewOffset;