More keyboard controls

This commit is contained in:
Ryzerth
2021-04-23 19:12:24 +02:00
parent d43f501819
commit b8347fd254
5 changed files with 46 additions and 19 deletions

View File

@ -436,10 +436,10 @@ void drawWindow() {
// Handle arrow keys
if (vfo != NULL) {
if (ImGui::IsKeyPressed(GLFW_KEY_LEFT)) {
if (ImGui::IsKeyPressed(GLFW_KEY_LEFT) && !gui::freqSelect.digitHovered) {
setVFO(gui::waterfall.getCenterFrequency() + vfo->generalOffset - vfo->snapInterval);
}
if (ImGui::IsKeyPressed(GLFW_KEY_RIGHT)) {
if (ImGui::IsKeyPressed(GLFW_KEY_RIGHT) && !gui::freqSelect.digitHovered) {
setVFO(gui::waterfall.getCenterFrequency() + vfo->generalOffset + vfo->snapInterval);
}
core::configManager.aquire();

View File

@ -1,6 +1,7 @@
#include <gui/widgets/frequency_select.h>
#include <config.h>
#include <gui/style.h>
#include <glfw_window.h>
#include <GLFW/glfw3.h>
#ifndef IMGUI_DEFINE_MATH_OPERATORS
@ -127,6 +128,7 @@ void FrequencySelect::draw() {
bool rightClick = ImGui::IsMouseClicked(ImGuiMouseButton_Right);
int mw = ImGui::GetIO().MouseWheel;
bool onDigit = false;
bool hovered = false;
for (int i = 0; i < 12; i++) {
onDigit = false;
@ -145,6 +147,7 @@ void FrequencySelect::draw() {
onDigit = true;
}
if (onDigit) {
hovered = true;
if (rightClick) {
for (int j = i; j < 12; j++) {
digits[j] = 0;
@ -157,6 +160,19 @@ void FrequencySelect::draw() {
if (ImGui::IsKeyPressed(GLFW_KEY_DOWN)) {
decrementDigit(i);
}
if (ImGui::IsKeyPressed(GLFW_KEY_LEFT) && i > 0) {
double xpos, ypos;
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) {
double xpos, ypos;
glfwGetCursorPos(core::window, &xpos, &ypos);
float nxpos = (digitTopMaxs[i + 1].x + digitTopMins[i + 1].x) / 2.0f;
glfwSetCursorPos(core::window, nxpos, ypos);
}
if (mw != 0) {
int count = abs(mw);
for (int j = 0; j < count; j++) {
@ -166,6 +182,8 @@ void FrequencySelect::draw() {
}
}
digitHovered = hovered;
uint64_t freq = 0;
for (int i = 0; i < 12; i++) {
freq += digits[i] * pow(10, 11 - i);

View File

@ -12,6 +12,7 @@ public:
uint64_t frequency;
bool frequencyChanged = false;
bool digitHovered = false;
private:
void onPosChange();