Skip to content

Commit

Permalink
added MsgDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
bucanero committed Dec 9, 2021
1 parent 6077e41 commit ebb7cc5
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 235 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ CONTENT_ID := IV0000-APOL00004_00-APOLLO0000000PS4

# Libraries linked into the ELF.
LIBS := -lc -lkernel -lc++ -lSceAudioOut -lSceUserService -lSceVideoOut -lSceGnmDriver -lSceSysmodule -lSceFreeType \
-lScePad -lSceSystemService -lSceSaveData -lSDL2 -lapollo -ldbglogger -lpolarssl -lz -lzip
-lScePad -lSceSystemService -lSceSaveData -lSceCommonDialog -lSceMsgDialog \
-lSDL2 -lapollo -ldbglogger -lpolarssl -lz -lzip

# Additional compile flags.
EXTRAFLAGS := -DAPOLLO_ENABLE_LOGGING
EXTRAFLAGS := -DAPOLLO_ENABLE_LOGGING -fcolor-diagnostics

# Asset and module directories.
ASSETS := $(wildcard assets/**/*)
Expand Down
88 changes: 0 additions & 88 deletions include/backend.h

This file was deleted.

2 changes: 0 additions & 2 deletions include/ttf_render.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef TTF_RENDER_H
#define TTF_RENDER_H

//#include <tiny3d.h>


int TTFLoadFont(int set, const char * path, void * from_memory, int size_from_memory);
void TTFUnloadFont();
Expand Down
34 changes: 16 additions & 18 deletions source/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ int is_char_letter(char c)

int file_exists(const char *path)
{
struct stat sb;
if ((stat(path, &sb) == 0) && S_ISREG(sb.st_mode)) {
if (access(path, F_OK) == 0) {
return SUCCESS;
}

Expand All @@ -47,7 +46,7 @@ int file_exists(const char *path)
int dir_exists(const char *path)
{
struct stat sb;
if ((stat(path, &sb) == 0) && S_ISDIR(sb.st_mode)) {
if ((stat(path, &sb) == 0) && sb.st_mode & S_IFDIR) {
return SUCCESS;
}
return FAILED;
Expand All @@ -57,9 +56,8 @@ int unlink_secure(const char *path)
{
if(file_exists(path)==SUCCESS)
{
// sysLv2FsChmod(path, S_IFMT | 0777);
return unlink(path);
//return remove(path);
chmod(path, 0777);
return remove(path);
}
return FAILED;
}
Expand Down Expand Up @@ -105,18 +103,18 @@ int mkdirs(const char* dir)

int copy_file(const char* input, const char* output)
{
u64 read, written;
s32 fd, fd2;
size_t read, written;
FILE *fd, *fd2;

if (mkdirs(output) != SUCCESS)
return FAILED;
/*
if(sysLv2FsOpen(input, 0, &fd, SYS_O_RDONLY, NULL, 0) != SUCCESS)

if((fd = fopen(input, "rb")) == NULL)
return FAILED;

if(sysLv2FsOpen(output, SYS_O_WRONLY | SYS_O_CREAT | SYS_O_TRUNC, &fd2, 0777, NULL, 0) != SUCCESS)
if((fd2 = fopen(output, "wb")) == NULL)
{
sysLv2FsClose(fd);
fclose(fd);
return FAILED;
}

Expand All @@ -127,16 +125,16 @@ int copy_file(const char* input, const char* output)

do
{
sysLv2FsRead(fd, buffer, TMP_BUFF_SIZE, &read);
sysLv2FsWrite(fd2, buffer, read, &written);
read = fread(buffer, 1, TMP_BUFF_SIZE, fd);
written = fwrite(buffer, 1, read, fd2);
}
while ((read == written) && (read == TMP_BUFF_SIZE));

free(buffer);
sysLv2FsClose(fd);
sysLv2FsClose(fd2);
sysLv2FsChmod(output, S_IFMT | 0777);
*/
fclose(fd);
fclose(fd2);
chmod(output, 0777);

return (read - written);
}

Expand Down
158 changes: 44 additions & 114 deletions source/dialog.c
Original file line number Diff line number Diff line change
@@ -1,58 +1,70 @@
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>

#include <orbis/CommonDialog.h>
#include <orbis/MsgDialog.h>

#define MDIALOG_OK 0
#define MDIALOG_YESNO 1

void drawDialogBackground();

static float bar1_countparts;
volatile int msg_dialog_action = 0;
/*
void msg_dialog_event(msgButton button, void *userdata)

static inline void _orbisCommonDialogSetMagicNumber(uint32_t* magic, const OrbisCommonDialogBaseParam* param)
{
*magic = (uint32_t)(ORBIS_COMMON_DIALOG_MAGIC_NUMBER + (uint64_t)param);
}

static inline void _orbisCommonDialogBaseParamInit(OrbisCommonDialogBaseParam *param)
{
memset(param, 0x0, sizeof(OrbisCommonDialogBaseParam));
param->size = (uint32_t)sizeof(OrbisCommonDialogBaseParam);
_orbisCommonDialogSetMagicNumber(&(param->magic), param);
}

static inline void orbisMsgDialogParamInitialize(OrbisMsgDialogParam *param)
{
switch(button) {
case MSG_DIALOG_BTN_YES:
msg_dialog_action = 1;
break;
case MSG_DIALOG_BTN_NO:
case MSG_DIALOG_BTN_ESCAPE:
case MSG_DIALOG_BTN_NONE:
msg_dialog_action = 2;
break;
default:
break;
}
memset(param, 0x0, sizeof(OrbisMsgDialogParam));
_orbisCommonDialogBaseParamInit(&param->baseParam);
param->size = sizeof(OrbisMsgDialogParam);
}
*/

int show_dialog(int tdialog, const char * format, ...)
{
/*
msg_dialog_action = 0;
OrbisMsgDialogParam param;
OrbisMsgDialogUserMessageParam userMsgParam;
OrbisMsgDialogResult result;
char str[0x800];
va_list opt;

memset(str, 0, sizeof(str));
va_start(opt, format);
vsprintf((void*) str, format, opt);
va_end(opt);

msgType mtype = MSG_DIALOG_BKG_INVISIBLE | MSG_DIALOG_NORMAL;
mtype |= (tdialog ? (MSG_DIALOG_BTN_TYPE_YESNO | MSG_DIALOG_DEFAULT_CURSOR_NO) : MSG_DIALOG_BTN_TYPE_OK);
sceMsgDialogInitialize();
orbisMsgDialogParamInitialize(&param);
param.mode = ORBIS_MSG_DIALOG_MODE_USER_MSG;

msgDialogOpen2(mtype, str, msg_dialog_event, NULL, NULL);
memset(&userMsgParam, 0, sizeof(userMsgParam));
userMsgParam.msg = str;
userMsgParam.buttonType = (tdialog ? ORBIS_MSG_DIALOG_BUTTON_TYPE_YESNO_FOCUS_NO : ORBIS_MSG_DIALOG_BUTTON_TYPE_OK);
param.userMsgParam = &userMsgParam;

while(!msg_dialog_action)
{
drawDialogBackground();
}
msgDialogAbort();
usleep(100 *1000);
if (sceMsgDialogOpen(&param) < 0)
return 0;

do { } while (sceMsgDialogUpdateStatus() != ORBIS_COMMON_DIALOG_STATUS_FINISHED);
sceMsgDialogClose();

return (msg_dialog_action == 1);
*/
return 0;
memset(&result, 0, sizeof(result));
sceMsgDialogGetResult(&result);
sceMsgDialogTerminate();

return (result.buttonId == 1);
}

/*
Expand Down Expand Up @@ -89,86 +101,4 @@ void update_progress_bar(uint64_t* progress, const uint64_t total_size, const ch
drawDialogBackground();
}
/ *
#define TOTAL_OPT 3
void Xmsg_dialog_event(msgButton button, void *userdata)
{
uint32_t* bits = (uint32_t*) userdata;
switch(button) {
case MSG_DIALOG_BTN_YES:
*bits |= (1 << 31);
*bits ^= (1 << msg_dialog_action);
if (msg_dialog_action == TOTAL_OPT)
msg_dialog_action = -msg_dialog_action;
break;
case MSG_DIALOG_BTN_NO:
case MSG_DIALOG_BTN_ESCAPE:
case MSG_DIALOG_BTN_NONE:
*bits |= (1 << 31);
msg_dialog_action++;
if (msg_dialog_action > TOTAL_OPT)
msg_dialog_action = 1;
break;
default:
break;
}
}
#include <string.h>
//#include <stdio.h>
int Xshow_dialog()
{
uint32_t enabled = 0;
char str[1024];
const char text_options[4][32] = {
"--- MENU ---",
"Option 1",
"Option 2",
"Exit",
};
msg_dialog_action = 1;
msgType mtype = MSG_DIALOG_BKG_INVISIBLE | MSG_DIALOG_NORMAL | MSG_DIALOG_BTN_TYPE_OK;
while(msg_dialog_action >= 0)
{
strcpy(str, text_options[0]);
strcat(str, "\n\n");
for (int i = 1; i <= TOTAL_OPT; i++)
{
strcat(str, (i == msg_dialog_action) ? "> " : " ");
strcat(str, text_options[i]);
if (i < TOTAL_OPT)
strcat(str, (enabled & (1 << i)) ? ": ON" : ": OFF");
if (i == msg_dialog_action)
strcat(str, " <");
strcat(str, "\n");
}
msgDialogOpen2(mtype, str, Xmsg_dialog_event, &enabled, NULL);
while (!(enabled & (1 << 31)))
{
drawDialogBackground();
}
enabled ^= (1 << 31);
}
msgDialogAbort();
usleep(100 *1000);
return (msg_dialog_action == 1);
}
*/
Loading

0 comments on commit ebb7cc5

Please sign in to comment.