WiiUPluginSystem/src/overlay.c
Maschell 0d46322cbb Add support for plugins that use wut libraries.
Add the requirement to have wut installed
Modify the plugin makefile, now you need to enable malloc wrapping manually
Change the calling behaviour of the "WUPS_APP_STATUS_CLOSED" hook. PPCExit does NOT get called when opening an application from the system menu.
Add error output to the UDPLogger on failure.
2018-06-17 12:47:45 +02:00

90 lines
2.6 KiB
C

#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <wups.h>
extern void (*OSScreenInit)(void);
extern void (*OSScreenShutdown)(void);
extern u32 (*OSScreenGetBufferSizeEx)(u32 bufferNum);
extern s32 (*OSScreenSetBufferEx)(u32 bufferNum, void * addr);
extern s32 (*OSScreenClearBufferEx)(u32 bufferNum, u32 temp);
extern s32 (*OSScreenFlipBuffersEx)(u32 bufferNum);
extern s32 (*OSScreenPutFontEx)(u32 bufferNum, u32 posX, u32 posY, const char * buffer);
extern s32 (*OSScreenEnableEx)(u32 bufferNum, s32 enable);
extern u32 (*OSScreenPutPixelEx)(u32 bufferNum, u32 posX, u32 posY, u32 color);
static void * overlayfunction_ptr __attribute__((section(".data"))) = NULL;
#ifdef __cplusplus
extern "C" {
#endif
void WUPS_InitOverlay(wups_loader_init_overlay_args_t args) {
overlayfunction_ptr = (void*) args.overlayfunction_ptr;
}
void WUPS_Overlay_PrintTextOnScreen(wups_overlay_options_type_t screen, int x,int y, const char * msg, ...) {
if(screen == WUPS_OVERLAY_NONE) {
return;
}
char * tmp = NULL;
va_list va;
va_start(va, msg);
if((vasprintf(&tmp, msg, va) >= 0) && tmp) {
if(screen != WUPS_OVERLAY_DRC_ONLY) { // Draw TV if it's not DRC exclusive.
OSScreenPutFontEx(0, x, y, tmp);
}
if(screen != WUPS_OVERLAY_TV_ONLY) { // Draw DRC if it's not TV exclusive.
OSScreenPutFontEx(1, x, y, tmp);
}
}
va_end(va);
if(tmp) {
free(tmp);
}
}
void WUPS_Overlay_OSScreenClear(wups_overlay_options_type_t screen) {
if(screen == WUPS_OVERLAY_NONE) {
return;
}
if(screen != WUPS_OVERLAY_DRC_ONLY) { // Clear TV if it's not DRC exclusive.
OSScreenClearBufferEx(0, 0);
}
if(screen != WUPS_OVERLAY_TV_ONLY) { // Clear DRC if it's not TV exclusive.
OSScreenClearBufferEx(1, 0);
}
}
void WUPS_Overlay_FlipBuffers(wups_overlay_options_type_t screen) {
if(screen == WUPS_OVERLAY_NONE) {
return;
}
if(screen != WUPS_OVERLAY_DRC_ONLY) { // Flip TV buffer if it's not DRC exclusive.
OSScreenFlipBuffersEx(0);
}
if(screen != WUPS_OVERLAY_TV_ONLY) { // Flip DRC buffer if it's not TV exclusive.
OSScreenFlipBuffersEx(1);
}
}
void WUPS_OpenOverlay(wups_overlay_options_type_t screen, overlay_callback callback) {
if(overlayfunction_ptr != NULL) {
( (void (*)(wups_overlay_options_type_t, overlay_callback))((unsigned int*)overlayfunction_ptr) )(screen,callback);
}
}
#ifdef __cplusplus
}
#endif