added keyboard input to frequency select

This commit is contained in:
Ryzerth 2021-04-23 21:35:54 +02:00
parent b8347fd254
commit 75568a7bf7
3 changed files with 40 additions and 11 deletions

View File

@ -437,10 +437,14 @@ void drawWindow() {
// Handle arrow keys // Handle arrow keys
if (vfo != NULL) { if (vfo != NULL) {
if (ImGui::IsKeyPressed(GLFW_KEY_LEFT) && !gui::freqSelect.digitHovered) { if (ImGui::IsKeyPressed(GLFW_KEY_LEFT) && !gui::freqSelect.digitHovered) {
setVFO(gui::waterfall.getCenterFrequency() + vfo->generalOffset - vfo->snapInterval); double nfreq = gui::waterfall.getCenterFrequency() + vfo->generalOffset - vfo->snapInterval;
nfreq = roundl(nfreq / vfo->snapInterval) * vfo->snapInterval;
setVFO(nfreq);
} }
if (ImGui::IsKeyPressed(GLFW_KEY_RIGHT) && !gui::freqSelect.digitHovered) { if (ImGui::IsKeyPressed(GLFW_KEY_RIGHT) && !gui::freqSelect.digitHovered) {
setVFO(gui::waterfall.getCenterFrequency() + vfo->generalOffset + vfo->snapInterval); double nfreq = gui::waterfall.getCenterFrequency() + vfo->generalOffset + vfo->snapInterval;
nfreq = roundl(nfreq / vfo->snapInterval) * vfo->snapInterval;
setVFO(nfreq);
} }
core::configManager.aquire(); core::configManager.aquire();
core::configManager.conf["frequency"] = gui::waterfall.getCenterFrequency(); core::configManager.conf["frequency"] = gui::waterfall.getCenterFrequency();

View File

@ -75,6 +75,13 @@ void FrequencySelect::decrementDigit(int i) {
frequencyChanged = true; frequencyChanged = true;
} }
void FrequencySelect::moveCursorToDigit(int i) {
double xpos, ypos;
glfwGetCursorPos(core::window, &xpos, &ypos);
float nxpos = (digitTopMaxs[i].x + digitTopMins[i].x) / 2.0f;
glfwSetCursorPos(core::window, nxpos, ypos);
}
void FrequencySelect::draw() { void FrequencySelect::draw() {
window = ImGui::GetCurrentWindow(); window = ImGui::GetCurrentWindow();
widgetPos = ImGui::GetWindowContentRegionMin(); widgetPos = ImGui::GetWindowContentRegionMin();
@ -161,18 +168,35 @@ void FrequencySelect::draw() {
decrementDigit(i); decrementDigit(i);
} }
if (ImGui::IsKeyPressed(GLFW_KEY_LEFT) && i > 0) { if (ImGui::IsKeyPressed(GLFW_KEY_LEFT) && i > 0) {
double xpos, ypos; moveCursorToDigit(i - 1);
glfwGetCursorPos(core::window, &xpos, &ypos);
float nxpos = (digitTopMaxs[i - 1].x + digitTopMins[i - 1].x) / 2.0f;
glfwSetCursorPos(core::window, nxpos, ypos);
} }
if (ImGui::IsKeyPressed(GLFW_KEY_RIGHT) && i < 11) { if (ImGui::IsKeyPressed(GLFW_KEY_RIGHT) && i < 11) {
double xpos, ypos; moveCursorToDigit(i + 1);
glfwGetCursorPos(core::window, &xpos, &ypos);
float nxpos = (digitTopMaxs[i + 1].x + digitTopMins[i + 1].x) / 2.0f;
glfwSetCursorPos(core::window, nxpos, ypos);
} }
auto chars = ImGui::GetIO().InputQueueCharacters;
// For each keyboard characters, type it
for (int j = 0; j < chars.Size; j++) {
if (chars[j] >= '0' && chars[j] <= '9') {
digits[i + j] = chars[j] - '0';
}
if ((i + j) < 11) { moveCursorToDigit(i + j + 1); }
frequencyChanged = true;
}
// Check each digit
// if (ImGui::IsKeyPressed(GLFW_KEY_KP_0)) { digits[i] = 0; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } }
// if (ImGui::IsKeyPressed(GLFW_KEY_KP_1)) { digits[i] = 1; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } }
// if (ImGui::IsKeyPressed(GLFW_KEY_KP_2)) { digits[i] = 2; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } }
// if (ImGui::IsKeyPressed(GLFW_KEY_KP_3)) { digits[i] = 3; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } }
// if (ImGui::IsKeyPressed(GLFW_KEY_KP_4)) { digits[i] = 4; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } }
// if (ImGui::IsKeyPressed(GLFW_KEY_KP_5)) { digits[i] = 5; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } }
// if (ImGui::IsKeyPressed(GLFW_KEY_KP_6)) { digits[i] = 6; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } }
// if (ImGui::IsKeyPressed(GLFW_KEY_KP_7)) { digits[i] = 7; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } }
// if (ImGui::IsKeyPressed(GLFW_KEY_KP_8)) { digits[i] = 8; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } }
// if (ImGui::IsKeyPressed(GLFW_KEY_KP_9)) { digits[i] = 9; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } }
if (mw != 0) { if (mw != 0) {
int count = abs(mw); int count = abs(mw);
for (int j = 0; j < count; j++) { for (int j = 0; j < count; j++) {

View File

@ -19,6 +19,7 @@ private:
void onResize(); void onResize();
void incrementDigit(int i); void incrementDigit(int i);
void decrementDigit(int i); void decrementDigit(int i);
void moveCursorToDigit(int i);
ImVec2 widgetPos; ImVec2 widgetPos;
ImVec2 widgetEndPos; ImVec2 widgetEndPos;