From 3a142b0d85a3f6f5a95f89693061562ac41677d2 Mon Sep 17 00:00:00 2001 From: Cam K <28871190+Starman0620@users.noreply.github.com> Date: Mon, 19 Apr 2021 20:58:47 -0400 Subject: [PATCH] Added boilerplate code for Discord module --- CMakeLists.txt | 5 +++ discord/CMakeLists.txt | 21 ++++++++++++ discord/src/main.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 discord/CMakeLists.txt create mode 100644 discord/src/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 67aca2d5..5b8a28be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ option(OPT_BUILD_AUDIO_SINK "Build Audio Sink Module (Depedencies: rtaudio)" ON) option(OPT_BUILD_FALCON9_DECODER "Build the falcon9 live decoder (Dependencies: ffplay)" OFF) option(OPT_BUILD_METEOR_DEMODULATOR "Build the meteor demodulator module (no dependencies required)" ON) option(OPT_BUILD_WEATHER_SAT_DECODER "Build the HRPT decoder module (no dependencies required)" ON) +option(OPT_BUILD_DISCORD_PRESENCE "Build the Discord Rich Presence module" ON) # Core of SDR++ add_subdirectory("core") @@ -87,6 +88,10 @@ if (OPT_BUILD_WEATHER_SAT_DECODER) add_subdirectory("weather_sat_decoder") endif (OPT_BUILD_WEATHER_SAT_DECODER) +if (OPT_BUILD_DISCORD_PRESENCE) +add_subdirectory("discord") +endif (OPT_BUILD_DISCORD_PRESENCE) + if (MSVC) set(CMAKE_CXX_FLAGS "-O2 /std:c++17 /EHsc") elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") diff --git a/discord/CMakeLists.txt b/discord/CMakeLists.txt new file mode 100644 index 00000000..e7ebc097 --- /dev/null +++ b/discord/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.13) +project(discord) + +if (MSVC) + set(CMAKE_CXX_FLAGS "-O2 /std:c++17 /EHsc") +elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_CXX_FLAGS "-O3 -std=c++17 -Wno-unused-command-line-argument -undefined dynamic_lookup") +else () + set(CMAKE_CXX_FLAGS "-O3 -std=c++17") +endif () + +file(GLOB SRC "src/*.cpp") + +include_directories("src/") + +add_library(discord SHARED ${SRC}) +target_link_libraries(discord PRIVATE sdrpp_core) +set_target_properties(discord PROPERTIES PREFIX "") + +# Install directives +install(TARGETS discord DESTINATION lib/sdrpp/plugins) \ No newline at end of file diff --git a/discord/src/main.cpp b/discord/src/main.cpp new file mode 100644 index 00000000..79a87187 --- /dev/null +++ b/discord/src/main.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include + +SDRPP_MOD_INFO { + /* Name: */ "discord", + /* Description: */ "Discord Rich Presence module for SDR++", + /* Author: */ "Starman0620", + /* Version: */ 0, 0, 1, + /* Max instances */ -1 +}; + +class PresenceModule : public ModuleManager::Instance { +public: + PresenceModule(std::string name) { + this->name = name; + gui::menu.registerEntry(name, menuHandler, this, this); + } + + ~PresenceModule() { + + } + + void enable() { + enabled = true; + } + + void disable() { + enabled = false; + } + + bool isEnabled() { + return enabled; + } + +private: + static void menuHandler(void* ctx) { + PresenceModule* _this = (PresenceModule*)ctx; + if(!_this->enabled) { style::beginDisabled(); } + + float menuWidth = ImGui::GetContentRegionAvailWidth(); + ImGui::BeginGroup(); + + ImGui::Text("Hello, SDR++ world! - Starman0620"); + + ImGui::EndGroup(); + + if(!_this->enabled) { style::endDisabled(); } + } + + std::string name; + bool enabled = true; +}; + +MOD_EXPORT void _INIT_() { + +} + +MOD_EXPORT ModuleManager::Instance* _CREATE_INSTANCE_(std::string name) { + return new PresenceModule(name); +} + +MOD_EXPORT void _DELETE_INSTANCE_(void* instance) { + delete (PresenceModule*)instance; +} + +MOD_EXPORT void _END_() { + +} \ No newline at end of file