dev: utilsconsole: merge c and cpp files

This commit is contained in:
Zy 2024-10-12 15:40:32 +02:00
parent 236cb9a780
commit 3f5e13b2f2
6 changed files with 21 additions and 73 deletions

View file

@ -1,15 +1,18 @@
/** /**
* utilsconsole.hpp * utilsconsole.h
* by Zy * by Zy
*/ */
/** /**
* utilsconsole.hpp (uc_*() functions) * utilsconsole.h (uc_*() functions)
* Utility functions for the 3DS console. * Utility functions for the 3DS console.
*/ */
#pragma once #pragma once
#ifdef __cplusplus
extern "C++" {
#include <string> #include <string>
#include <vector> #include <vector>
@ -40,6 +43,9 @@ typedef struct {
/// @return The index of the confirmed element. If none, return -1. /// @return The index of the confirmed element. If none, return -1.
int uc_menu(vector<s_uc_menu_element> &elements); int uc_menu(vector<s_uc_menu_element> &elements);
}
#endif
/// @brief Display a menu quickly using only confirm buttons. /// @brief Display a menu quickly using only confirm buttons.
/// @details /// @details
/// Blocking function. Will return -1 if aptMainLoop() becomes false. /// Blocking function. Will return -1 if aptMainLoop() becomes false.

View file

@ -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

View file

@ -2,11 +2,10 @@ extern "C" {
#include "mlx.h" #include "mlx.h"
#include "3ds.h" #include "3ds.h"
#include "mlx3ds.h" #include "mlx3ds.h"
#include "utilsconsole.h"
} }
#include <iostream> #include <iostream>
#include <string.h> #include <string.h>
#include "utilsconsole.hpp"
#include "utilsconsole.hpp"
#include "firsk.xpm" #include "firsk.xpm"
#include <sys/dirent.h> #include <sys/dirent.h>
#include <fcntl.h> #include <fcntl.h>

View file

@ -7,9 +7,9 @@
// TODO mlx_internal.cpp: embed uc_pause() and change to .c file // TODO mlx_internal.cpp: embed uc_pause() and change to .c file
#include "utilsconsole.hpp"
extern "C" { extern "C" {
#include "utilsconsole.h"
#include "mlx_internal.h" #include "mlx_internal.h"
#include "3ds.h" #include "3ds.h"

View file

@ -3,12 +3,15 @@
* by Zy * by Zy
*/ */
#include "utilsconsole.hpp"
#include <3ds.h>
#include <iostream> #include <iostream>
#include <stdarg.h>
#include <cstring> #include <cstring>
extern "C" {
#include "utilsconsole.h"
#include <3ds.h>
#include <stdarg.h>
}
using namespace std;
int uc_menu(vector<s_uc_menu_element> &elements) { int uc_menu(vector<s_uc_menu_element> &elements) {
static void *lastElements = NULL; static void *lastElements = NULL;
@ -71,6 +74,8 @@ int uc_menu(vector<s_uc_menu_element> &elements) {
return confirmed ? selected : -1; return confirmed ? selected : -1;
} }
extern "C" {
int uc_menu_quick(const char *str, ...) { int uc_menu_quick(const char *str, ...) {
va_list arguments; va_list arguments;
auto elements = vector<s_uc_menu_element>(); auto elements = vector<s_uc_menu_element>();
@ -106,3 +111,5 @@ char *uc_keyboard(const char *def)
swkbdInputText(&swkbd, buf, 1000); swkbdInputText(&swkbd, buf, 1000);
return (buf); return (buf);
} }
}

View file

@ -1,42 +0,0 @@
/**
* utilsconsole_extern_c.cpp
* by Zy
*/
#include <iostream>
extern "C" {
#include "utilsconsole_extern_c.h"
#include <3ds.h>
#include <stdarg.h>
#include <string.h>
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);
}
}