From 3f5e13b2f24764e7048a2c130b14da434a57ec6f Mon Sep 17 00:00:00 2001 From: Zy Date: Sat, 12 Oct 2024 15:40:32 +0200 Subject: [PATCH] dev: utilsconsole: merge c and cpp files --- include/{utilsconsole.hpp => utilsconsole.h} | 10 ++++- include/utilsconsole_extern_c.h | 22 ---------- source/main.cpp | 3 +- source/mlx_internal.cpp | 2 +- source/utilsconsole.cpp | 15 +++++-- source/utilsconsole_extern_c.cpp | 42 -------------------- 6 files changed, 21 insertions(+), 73 deletions(-) rename include/{utilsconsole.hpp => utilsconsole.h} (94%) delete mode 100644 include/utilsconsole_extern_c.h delete mode 100644 source/utilsconsole_extern_c.cpp diff --git a/include/utilsconsole.hpp b/include/utilsconsole.h similarity index 94% rename from include/utilsconsole.hpp rename to include/utilsconsole.h index 52a8fd4..858472e 100644 --- a/include/utilsconsole.hpp +++ b/include/utilsconsole.h @@ -1,15 +1,18 @@ /** - * utilsconsole.hpp + * utilsconsole.h * by Zy */ /** - * utilsconsole.hpp (uc_*() functions) + * utilsconsole.h (uc_*() functions) * Utility functions for the 3DS console. */ #pragma once +#ifdef __cplusplus +extern "C++" { + #include #include @@ -40,6 +43,9 @@ typedef struct { /// @return The index of the confirmed element. If none, return -1. int uc_menu(vector &elements); +} +#endif + /// @brief Display a menu quickly using only confirm buttons. /// @details /// Blocking function. Will return -1 if aptMainLoop() becomes false. diff --git a/include/utilsconsole_extern_c.h b/include/utilsconsole_extern_c.h deleted file mode 100644 index 0e9965c..0000000 --- a/include/utilsconsole_extern_c.h +++ /dev/null @@ -1,22 +0,0 @@ -/** - * utilsconsole_extern_c.h - * by Zy - */ - -/** - * utilsconsole_extern_c.h (uc_*() functions) - */ - -#ifndef UTILSCONSOLE_EXTERN_C_H -# define UTILSCONSOLE_EXTERN_C_H - -/// @brief Blocks the program until the user presses A. -/// @details Will also return if aptMainLoop() becomes false. -void uc_pause(void); - -/// @brief Show the 3DS keyboard to ask the user for a text. -/// @param def The default text to show the user. -/// @return A freeable address to the text prompted by the user. NULL if error. -char *uc_keyboard(const char *def); - -#endif diff --git a/source/main.cpp b/source/main.cpp index 0b6dea3..3963f33 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -2,11 +2,10 @@ extern "C" { #include "mlx.h" #include "3ds.h" #include "mlx3ds.h" +#include "utilsconsole.h" } #include #include -#include "utilsconsole.hpp" -#include "utilsconsole.hpp" #include "firsk.xpm" #include #include diff --git a/source/mlx_internal.cpp b/source/mlx_internal.cpp index e65fbc0..4a5fa64 100644 --- a/source/mlx_internal.cpp +++ b/source/mlx_internal.cpp @@ -7,9 +7,9 @@ // TODO mlx_internal.cpp: embed uc_pause() and change to .c file -#include "utilsconsole.hpp" extern "C" { +#include "utilsconsole.h" #include "mlx_internal.h" #include "3ds.h" diff --git a/source/utilsconsole.cpp b/source/utilsconsole.cpp index a555921..833dd07 100644 --- a/source/utilsconsole.cpp +++ b/source/utilsconsole.cpp @@ -3,12 +3,15 @@ * by Zy */ -#include "utilsconsole.hpp" - -#include <3ds.h> #include -#include #include +extern "C" { +#include "utilsconsole.h" +#include <3ds.h> +#include +} + +using namespace std; int uc_menu(vector &elements) { static void *lastElements = NULL; @@ -71,6 +74,8 @@ int uc_menu(vector &elements) { return confirmed ? selected : -1; } +extern "C" { + int uc_menu_quick(const char *str, ...) { va_list arguments; auto elements = vector(); @@ -106,3 +111,5 @@ char *uc_keyboard(const char *def) swkbdInputText(&swkbd, buf, 1000); return (buf); } + +} diff --git a/source/utilsconsole_extern_c.cpp b/source/utilsconsole_extern_c.cpp deleted file mode 100644 index 9a2442f..0000000 --- a/source/utilsconsole_extern_c.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/** - * utilsconsole_extern_c.cpp - * by Zy - */ - - -#include - -extern "C" { - -#include "utilsconsole_extern_c.h" -#include <3ds.h> -#include -#include - -using namespace std; - -void uc_pause(void) { - cout << "\e[0;2mPress (A) to continue...\e[0m" << endl; - while (aptMainLoop()) { - hidScanInput(); - if (hidKeysDown() & KEY_A) - break; - gfxFlushBuffers(); - } -} - -char *uc_keyboard(const char *def) -{ - char *buf; - SwkbdState swkbd; - - buf = new char[1000]; - if (!buf) - return (NULL); - swkbdInit(&swkbd, SWKBD_TYPE_NORMAL, 1, -1); - swkbdSetInitialText(&swkbd, def); - swkbdInputText(&swkbd, buf, 1000); - return (buf); -} - -}