mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-01-24 00:34:44 +01:00
More keyboard controls
This commit is contained in:
parent
d43f501819
commit
b8347fd254
@ -14,6 +14,7 @@
|
|||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <core.h>
|
#include <core.h>
|
||||||
|
#include <glfw_window.h>
|
||||||
#include <options.h>
|
#include <options.h>
|
||||||
#include <duktape/duktape.h>
|
#include <duktape/duktape.h>
|
||||||
#include <duktape/duk_console.h>
|
#include <duktape/duk_console.h>
|
||||||
@ -41,6 +42,7 @@ namespace core {
|
|||||||
ScriptManager scriptManager;
|
ScriptManager scriptManager;
|
||||||
ModuleManager moduleManager;
|
ModuleManager moduleManager;
|
||||||
ModuleComManager modComManager;
|
ModuleComManager modComManager;
|
||||||
|
GLFWwindow* window;
|
||||||
|
|
||||||
void setInputSampleRate(double samplerate) {
|
void setInputSampleRate(double samplerate) {
|
||||||
// NOTE: Zoom controls won't work
|
// NOTE: Zoom controls won't work
|
||||||
@ -242,17 +244,17 @@ int sdrpp_main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
// Create window with graphics context
|
// Create window with graphics context
|
||||||
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
||||||
GLFWwindow* window = glfwCreateWindow(winWidth, winHeight, "SDR++ v" VERSION_STR " (Built at " __TIME__ ", " __DATE__ ")", NULL, NULL);
|
core::window = glfwCreateWindow(winWidth, winHeight, "SDR++ v" VERSION_STR " (Built at " __TIME__ ", " __DATE__ ")", NULL, NULL);
|
||||||
if (window == NULL)
|
if (core::window == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(core::window);
|
||||||
|
|
||||||
#if (GLFW_VERSION_MAJOR == 3) && (GLFW_VERSION_MINOR >= 3)
|
#if (GLFW_VERSION_MAJOR == 3) && (GLFW_VERSION_MINOR >= 3)
|
||||||
if (maximized) {
|
if (maximized) {
|
||||||
glfwMaximizeWindow(window);
|
glfwMaximizeWindow(core::window);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowMaximizeCallback(window, maximized_callback);
|
glfwSetWindowMaximizeCallback(core::window, maximized_callback);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Load app icon
|
// Load app icon
|
||||||
@ -281,7 +283,7 @@ int sdrpp_main(int argc, char *argv[]) {
|
|||||||
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[7].pixels, 128, 128, 128 * 4, 4);
|
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[7].pixels, 128, 128, 128 * 4, 4);
|
||||||
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[8].pixels, 196, 196, 196 * 4, 4);
|
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[8].pixels, 196, 196, 196 * 4, 4);
|
||||||
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[9].pixels, 256, 256, 256 * 4, 4);
|
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[9].pixels, 256, 256, 256 * 4, 4);
|
||||||
glfwSetWindowIcon(window, 10, icons);
|
glfwSetWindowIcon(core::window, 10, icons);
|
||||||
stbi_image_free(icons[0].pixels);
|
stbi_image_free(icons[0].pixels);
|
||||||
for (int i = 1; i < 10; i++) {
|
for (int i = 1; i < 10; i++) {
|
||||||
free(icons[i].pixels);
|
free(icons[i].pixels);
|
||||||
@ -300,7 +302,7 @@ int sdrpp_main(int argc, char *argv[]) {
|
|||||||
io.IniFilename = NULL;
|
io.IniFilename = NULL;
|
||||||
|
|
||||||
// Setup Platform/Renderer bindings
|
// Setup Platform/Renderer bindings
|
||||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
ImGui_ImplGlfw_InitForOpenGL(core::window, true);
|
||||||
|
|
||||||
if (!ImGui_ImplOpenGL3_Init(glsl_version)) {
|
if (!ImGui_ImplOpenGL3_Init(glsl_version)) {
|
||||||
// If init fail, try to fall back on GLSL 1.2
|
// If init fail, try to fall back on GLSL 1.2
|
||||||
@ -313,7 +315,7 @@ int sdrpp_main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
if (!style::setDarkStyle(resDir)) { return -1; }
|
if (!style::setDarkStyle(resDir)) { return -1; }
|
||||||
|
|
||||||
LoadingScreen::setWindow(window);
|
LoadingScreen::setWindow(core::window);
|
||||||
|
|
||||||
LoadingScreen::show("Loading icons");
|
LoadingScreen::show("Loading icons");
|
||||||
spdlog::info("Loading icons");
|
spdlog::info("Loading icons");
|
||||||
@ -335,7 +337,7 @@ int sdrpp_main(int argc, char *argv[]) {
|
|||||||
int fsWidth, fsHeight, fsPosX, fsPosY;
|
int fsWidth, fsHeight, fsPosX, fsPosY;
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(core::window)) {
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
// Start the Dear ImGui frame
|
// Start the Dear ImGui frame
|
||||||
@ -350,13 +352,13 @@ int sdrpp_main(int argc, char *argv[]) {
|
|||||||
core::configManager.aquire();
|
core::configManager.aquire();
|
||||||
core::configManager.conf["maximized"]= _maximized;
|
core::configManager.conf["maximized"]= _maximized;
|
||||||
if (!maximized) {
|
if (!maximized) {
|
||||||
glfwSetWindowSize(window, core::configManager.conf["windowSize"]["w"], core::configManager.conf["windowSize"]["h"]);
|
glfwSetWindowSize(core::window, core::configManager.conf["windowSize"]["w"], core::configManager.conf["windowSize"]["h"]);
|
||||||
}
|
}
|
||||||
core::configManager.release(true);
|
core::configManager.release(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int _winWidth, _winHeight;
|
int _winWidth, _winHeight;
|
||||||
glfwGetWindowSize(window, &_winWidth, &_winHeight);
|
glfwGetWindowSize(core::window, &_winWidth, &_winHeight);
|
||||||
|
|
||||||
if (ImGui::IsKeyPressed(GLFW_KEY_F11)) {
|
if (ImGui::IsKeyPressed(GLFW_KEY_F11)) {
|
||||||
fullScreen = !fullScreen;
|
fullScreen = !fullScreen;
|
||||||
@ -364,13 +366,13 @@ int sdrpp_main(int argc, char *argv[]) {
|
|||||||
spdlog::info("Fullscreen: ON");
|
spdlog::info("Fullscreen: ON");
|
||||||
fsWidth = _winWidth;
|
fsWidth = _winWidth;
|
||||||
fsHeight = _winHeight;
|
fsHeight = _winHeight;
|
||||||
glfwGetWindowPos(window, &fsPosX, &fsPosY);
|
glfwGetWindowPos(core::window, &fsPosX, &fsPosY);
|
||||||
const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||||
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, 0);
|
glfwSetWindowMonitor(core::window, monitor, 0, 0, mode->width, mode->height, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
spdlog::info("Fullscreen: OFF");
|
spdlog::info("Fullscreen: OFF");
|
||||||
glfwSetWindowMonitor(window, nullptr, fsPosX, fsPosY, fsWidth, fsHeight, 0);
|
glfwSetWindowMonitor(core::window, nullptr, fsPosX, fsPosY, fsWidth, fsHeight, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,7 +394,7 @@ int sdrpp_main(int argc, char *argv[]) {
|
|||||||
// Rendering
|
// Rendering
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
int display_w, display_h;
|
int display_w, display_h;
|
||||||
glfwGetFramebufferSize(window, &display_w, &display_h);
|
glfwGetFramebufferSize(core::window, &display_w, &display_h);
|
||||||
glViewport(0, 0, display_w, display_h);
|
glViewport(0, 0, display_w, display_h);
|
||||||
glClearColor(0.0666f, 0.0666f, 0.0666f, 1.0f);
|
glClearColor(0.0666f, 0.0666f, 0.0666f, 1.0f);
|
||||||
//glClearColor(0.9f, 0.9f, 0.9f, 1.0f);
|
//glClearColor(0.9f, 0.9f, 0.9f, 1.0f);
|
||||||
@ -400,7 +402,7 @@ int sdrpp_main(int argc, char *argv[]) {
|
|||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|
||||||
glfwSwapInterval(1); // Enable vsync
|
glfwSwapInterval(1); // Enable vsync
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(core::window);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
@ -408,7 +410,7 @@ int sdrpp_main(int argc, char *argv[]) {
|
|||||||
ImGui_ImplGlfw_Shutdown();
|
ImGui_ImplGlfw_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
glfwDestroyWindow(window);
|
glfwDestroyWindow(core::window);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
6
core/src/glfw_window.h
Normal file
6
core/src/glfw_window.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <module.h>
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
SDRPP_EXPORT GLFWwindow* window;
|
||||||
|
};
|
@ -436,10 +436,10 @@ void drawWindow() {
|
|||||||
|
|
||||||
// Handle arrow keys
|
// Handle arrow keys
|
||||||
if (vfo != NULL) {
|
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);
|
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);
|
setVFO(gui::waterfall.getCenterFrequency() + vfo->generalOffset + vfo->snapInterval);
|
||||||
}
|
}
|
||||||
core::configManager.aquire();
|
core::configManager.aquire();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <gui/widgets/frequency_select.h>
|
#include <gui/widgets/frequency_select.h>
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <gui/style.h>
|
#include <gui/style.h>
|
||||||
|
#include <glfw_window.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#ifndef IMGUI_DEFINE_MATH_OPERATORS
|
#ifndef IMGUI_DEFINE_MATH_OPERATORS
|
||||||
@ -127,6 +128,7 @@ void FrequencySelect::draw() {
|
|||||||
bool rightClick = ImGui::IsMouseClicked(ImGuiMouseButton_Right);
|
bool rightClick = ImGui::IsMouseClicked(ImGuiMouseButton_Right);
|
||||||
int mw = ImGui::GetIO().MouseWheel;
|
int mw = ImGui::GetIO().MouseWheel;
|
||||||
bool onDigit = false;
|
bool onDigit = false;
|
||||||
|
bool hovered = false;
|
||||||
|
|
||||||
for (int i = 0; i < 12; i++) {
|
for (int i = 0; i < 12; i++) {
|
||||||
onDigit = false;
|
onDigit = false;
|
||||||
@ -145,6 +147,7 @@ void FrequencySelect::draw() {
|
|||||||
onDigit = true;
|
onDigit = true;
|
||||||
}
|
}
|
||||||
if (onDigit) {
|
if (onDigit) {
|
||||||
|
hovered = true;
|
||||||
if (rightClick) {
|
if (rightClick) {
|
||||||
for (int j = i; j < 12; j++) {
|
for (int j = i; j < 12; j++) {
|
||||||
digits[j] = 0;
|
digits[j] = 0;
|
||||||
@ -157,6 +160,19 @@ void FrequencySelect::draw() {
|
|||||||
if (ImGui::IsKeyPressed(GLFW_KEY_DOWN)) {
|
if (ImGui::IsKeyPressed(GLFW_KEY_DOWN)) {
|
||||||
decrementDigit(i);
|
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) {
|
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++) {
|
||||||
@ -166,6 +182,8 @@ void FrequencySelect::draw() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
digitHovered = hovered;
|
||||||
|
|
||||||
uint64_t freq = 0;
|
uint64_t freq = 0;
|
||||||
for (int i = 0; i < 12; i++) {
|
for (int i = 0; i < 12; i++) {
|
||||||
freq += digits[i] * pow(10, 11 - i);
|
freq += digits[i] * pow(10, 11 - i);
|
||||||
|
@ -12,6 +12,7 @@ public:
|
|||||||
|
|
||||||
uint64_t frequency;
|
uint64_t frequency;
|
||||||
bool frequencyChanged = false;
|
bool frequencyChanged = false;
|
||||||
|
bool digitHovered = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onPosChange();
|
void onPosChange();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user