Backend abstraction

This commit is contained in:
AlexandreRouma
2022-01-29 20:35:08 +01:00
parent 3c19081561
commit 9969ce018b
18 changed files with 410 additions and 315 deletions

View File

@ -2,8 +2,8 @@
#include <config.h>
#include <gui/style.h>
#include <gui/gui.h>
#include <glfw_window.h>
#include <GLFW/glfw3.h>
#include <backend.h>
#include <keybinds.h>
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
@ -87,9 +87,9 @@ void FrequencySelect::decrementDigit(int i) {
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);
backend::getMouseScreenPos(xpos, ypos);
double nxpos = (digitTopMaxs[i].x + digitTopMins[i].x) / 2.0;
backend::setMouseScreenPos(nxpos, ypos);
}
void FrequencySelect::draw() {
@ -165,23 +165,23 @@ void FrequencySelect::draw() {
}
if (onDigit) {
hovered = true;
if (rightClick || (ImGui::IsKeyPressed(GLFW_KEY_DELETE) || ImGui::IsKeyPressed(GLFW_KEY_ENTER) || ImGui::IsKeyPressed(GLFW_KEY_KP_ENTER))) {
if (rightClick || (ImGui::IsKeyPressed(KB_KEY_DEL) || ImGui::IsKeyPressed(KB_KEY_ENTER) || ImGui::IsKeyPressed(KB_KEY_KP_ENTER))) {
for (int j = i; j < 12; j++) {
digits[j] = 0;
}
frequencyChanged = true;
}
if (ImGui::IsKeyPressed(GLFW_KEY_UP)) {
if (ImGui::IsKeyPressed(KB_KEY_UP)) {
incrementDigit(i);
}
if (ImGui::IsKeyPressed(GLFW_KEY_DOWN)) {
if (ImGui::IsKeyPressed(KB_KEY_DOWN)) {
decrementDigit(i);
}
if ((ImGui::IsKeyPressed(GLFW_KEY_LEFT) || ImGui::IsKeyPressed(GLFW_KEY_BACKSPACE)) && i > 0) {
if ((ImGui::IsKeyPressed(KB_KEY_LEFT) || ImGui::IsKeyPressed(KB_KEY_BACKSPACE)) && i > 0) {
moveCursorToDigit(i - 1);
}
if (ImGui::IsKeyPressed(GLFW_KEY_RIGHT) && i < 11) {
if (ImGui::IsKeyPressed(KB_KEY_RIGHT) && i < 11) {
moveCursorToDigit(i + 1);
}

View File

@ -4,9 +4,9 @@
#include <imutils.h>
#include <algorithm>
#include <volk/volk.h>
#include <GLFW/glfw3.h>
#include <spdlog/spdlog.h>
#include <gui/gui.h>
#include <keybinds.h>
float DEFAULT_COLOR_MAP[][3] = {
{ 0x00, 0x00, 0x20 },
@ -387,8 +387,8 @@ 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) {
bool leftKeyPressed = ImGui::IsKeyPressed(KB_KEY_LEFT);
if ((leftKeyPressed || ImGui::IsKeyPressed(KB_KEY_RIGHT)) && mouseInFreq) {
viewOffset += leftKeyPressed ? (viewBandwidth / 20.0) : (-viewBandwidth / 20.0);
if (viewOffset + (viewBandwidth / 2.0) > wholeBandwidth / 2.0) {
@ -435,7 +435,7 @@ namespace ImGui {
ImGui::TextUnformatted(name.c_str());
if (ImGui::IsKeyDown(GLFW_KEY_LEFT_CONTROL) || ImGui::IsKeyDown(GLFW_KEY_RIGHT_CONTROL)) {
if (ImGui::IsKeyDown(KB_KEY_LCTRL) || ImGui::IsKeyDown(KB_KEY_RCTRL)) {
ImGui::Separator();
printAndScale(_vfo->generalOffset + centerFreq, buf);
ImGui::Text("Frequency: %sHz", buf);
@ -461,7 +461,7 @@ namespace ImGui {
}
// Handle Page Up to cycle through VFOs
if (ImGui::IsKeyPressed(GLFW_KEY_PAGE_UP) && selVfo != NULL) {
if (ImGui::IsKeyPressed(KB_KEY_PG_UP) && selVfo != NULL) {
std::string next = (--vfos.end())->first;
std::string lowest = "";
double lowestOffset = INFINITY;
@ -484,7 +484,7 @@ namespace ImGui {
}
// Handle Page Down to cycle through VFOs
if (ImGui::IsKeyPressed(GLFW_KEY_PAGE_DOWN) && selVfo != NULL) {
if (ImGui::IsKeyPressed(KB_KEY_PG_DOWN) && selVfo != NULL) {
std::string next = (--vfos.end())->first;
std::string highest = "";
double highestOffset = -INFINITY;