Skip to content

Commit

Permalink
- Initial boxart hackery
Browse files Browse the repository at this point in the history
  • Loading branch information
emukidid committed Feb 1, 2024
1 parent 401e47d commit 823de3f
Show file tree
Hide file tree
Showing 13 changed files with 782 additions and 18 deletions.
2 changes: 2 additions & 0 deletions cube/swiss/include/swiss.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define FILES_PER_PAGE 8
#define FILES_PER_PAGE_FULLWIDTH 7
#define FILES_PER_PAGE_CAROUSEL 9
#define FILES_PER_PAGE_BOXART 16
extern int current_view_start;
extern int current_view_end;
extern int curMenuSelection; //menu selection
Expand Down Expand Up @@ -166,6 +167,7 @@ enum fileBrowserTypes
{
BROWSER_STANDARD=0,
BROWSER_FULLWIDTH,
BROWSER_BOXART,
BROWSER_CAROUSEL,
BROWSER_MAX
};
Expand Down
2 changes: 1 addition & 1 deletion cube/swiss/source/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ void config_parse_legacy(char *configData, void (*progress_indicator)(char*, int
}
}
else if(!strcmp("FileBrowserType", name)) {
for(int i = 0; i < 3; i++) {
for(int i = 0; i < 4; i++) {
if(!strcmp(fileBrowserStr[i], value)) {
swissSettings.fileBrowserType = i;
break;
Expand Down
3 changes: 3 additions & 0 deletions cube/swiss/source/devices/deviceHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ typedef struct {
GXTexObj bannerTexObj;
GXTlutObj bannerTlutObj;
BNRDesc bannerDesc;
u8 *boxartSpine;
u8 *boxartFront;
u8 *boxartBack;
} file_meta;

typedef struct {
Expand Down
37 changes: 34 additions & 3 deletions cube/swiss/source/devices/filemeta.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
#include "swiss.h"
#include "deviceHandler.h"
#include "FrameBufferMagic.h"
#include "../gui/boxart.h"

//this is the blank banner that will be shown if no banner is found on a disc
extern BNR blankbanner;

// TODO meta size is lame as it only takes the struct into consideration and not the texture data, needs fixing cause 512 * texture == Out of memory.
#define NUM_META_MAX (512)
#define META_CACHE_SIZE (sizeof(file_meta) * NUM_META_MAX)

Expand All @@ -36,6 +38,18 @@ void meta_free(file_meta* meta) {
free(meta->banner);
meta->banner = NULL;
}
if(meta->boxartBack) {
free(meta->boxartBack);
meta->boxartBack = NULL;
}
if(meta->boxartFront) {
free(meta->boxartFront);
meta->boxartFront = NULL;
}
if(meta->boxartSpine) {
free(meta->boxartSpine);
meta->boxartSpine = NULL;
}
__lwp_heap_free(meta_cache, meta);
}
}
Expand Down Expand Up @@ -195,7 +209,7 @@ void populate_game_meta(file_handle *f, u32 bannerOffset, u32 bannerSize) {
meta_create_direct_texture(f->meta);
}

void populate_meta(file_handle *f) {
void populate_meta(file_handle *f, int boxart) {
// If the meta hasn't been created, lets read it.
if(!f->meta) {
f->meta = meta_alloc();
Expand Down Expand Up @@ -345,12 +359,29 @@ void populate_meta(file_handle *f) {
f->meta->displayName = "Up to parent directory";
}
}

if(f->meta && (f->meta->diskId.magic == DVD_MAGIC || f->meta->diskId.gamename[0])) {
// Boxart
BOXART_Init(); // TODO make this nicer, internal and not a pain when a user doesn't have boxart.bin avail.
if (boxart == BOX_SPINE && !f->meta->boxartSpine) {
f->meta->boxartSpine = memalign(32, BOXART_TEX_SPINE_SIZE);
BOXART_LoadTexture((char*)&f->meta->diskId, f->meta->boxartSpine, boxart);
}
else if (boxart == BOX_FRONT && !f->meta->boxartFront) {
f->meta->boxartFront = memalign(32, BOXART_TEX_FRONT_SIZE);
BOXART_LoadTexture((char*)&f->meta->diskId, f->meta->boxartFront, boxart);
}
else if (boxart == BOX_BACK && !f->meta->boxartBack) {
f->meta->boxartBack = memalign(32, BOXART_TEX_BACK_SIZE);
BOXART_LoadTexture((char*)&f->meta->diskId, f->meta->boxartBack, boxart);
}
}
}

void repopulate_meta(file_handle *f) {
meta_free(f->meta);
f->meta = NULL;
populate_meta(f);
populate_meta(f, -1);
}

file_handle* meta_find_disc2(file_handle *f) {
Expand All @@ -361,7 +392,7 @@ file_handle* meta_find_disc2(file_handle *f) {
for(int j = 0; j < getCurrentDirEntryCount(); j++) {
if(!dirEntries[j].meta) {
if(i == 0) continue;
populate_meta(&dirEntries[j]);
populate_meta(&dirEntries[j] ,-1);
}
if(dirEntries[j].meta) {
if(strncmp((const char*)dirEntries[j].meta->diskId.gamename, (const char*)f->meta->diskId.gamename, 4)) {
Expand Down
2 changes: 1 addition & 1 deletion cube/swiss/source/devices/filemeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <stdio.h>
#include "deviceHandler.h"

void populate_meta(file_handle *f);
void populate_meta(file_handle *f, int boxart);
void repopulate_meta(file_handle *f);
file_handle* meta_find_disc2(file_handle *f);
void meta_free(file_meta* meta);
Expand Down
133 changes: 128 additions & 5 deletions cube/swiss/source/gui/FrameBufferMagic.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "btns.h"
#include "dolparameters.h"
#include "cheats.h"
#include "boxart.h"

#define GUI_MSGBOX_ALPHA 225

Expand Down Expand Up @@ -100,11 +101,12 @@ enum VideoEventType
EV_CONTAINER,
EV_MENUBUTTONS,
EV_TOOLTIP,
EV_TITLEBAR
EV_TITLEBAR,
EV_3DBOXART
};

char * typeStrings[] = {"TexObj", "MsgBox", "Image", "Progress", "SelectableButton", "EmptyBox", "TransparentBox",
"FileBrowserButton", "VertScrollbar", "StyledLabel", "Container", "MenuButtons", "Tooltip", "TitleBar"};
"FileBrowserButton", "VertScrollbar", "StyledLabel", "Container", "MenuButtons", "Tooltip", "TitleBar", "3DBoxArt"};

typedef struct drawTexObjEvent {
GXTexObj *texObj;
Expand Down Expand Up @@ -207,6 +209,15 @@ typedef struct drawProgressEvent {
int timeremain;
} drawProgressEvent_t;

typedef struct draw3DBoxArtEvent {
GXTexObj *texture;
float zoom;
int x_pan;
int y_pan;
int type;
// TODO position so we can rotate
} draw3DBoxArtEvent_t;

typedef struct uiDrawObjQueue {
struct uiDrawObj *event;
struct uiDrawObjQueue *next;
Expand Down Expand Up @@ -281,6 +292,12 @@ static void clearNestedEvent(uiDrawObj_t *event) {
free(((drawTooltipEvent_t*)event->data)->tooltip);
}
}
else if(event->type == EV_3DBOXART) {
if(((draw3DBoxArtEvent_t*)event->data)->texture) {
//printf("Clear Nested EV_3DBOXART\r\n");
free(((draw3DBoxArtEvent_t*)event->data)->texture);
}
}
//printf("Clear Nested event->data\r\n");
free(event->data);
}
Expand All @@ -304,14 +321,14 @@ static void disposeEvent(uiDrawObj_t *event) {
if(current->event == event) {
//print_gecko("Disposing event %08X\r\n", (u32)current);
clearNestedEvent(current->event);
previous->next = current->next;
previous->next = current->next;
free(current);
}
}
else {
previous = current;
}
current = previous->next;
}
}
}


Expand Down Expand Up @@ -1407,6 +1424,109 @@ uiDrawObj_t* DrawTitleBar()
return event;
}


// Internal
static void _Draw3DBoxArt(uiDrawObj_t *evt) {
draw3DBoxArtEvent_t *data = (draw3DBoxArtEvent_t*)evt->data;

GX_InvalidateTexAll();
GX_LoadTexObj(data->texture, GX_TEXMAP0);
GXColor color = (GXColor) {255,255,255,255};
float x = (float)data->x_pan;
float y = (float)data->y_pan;
float depth = 0.0f;
int rawWidth = 0;
switch(data->type) {
case BOX_FRONT:
rawWidth = BOXART_FRONT_WIDTH;
break;

case BOX_SPINE:
rawWidth = BOXART_SPINE_WIDTH;
break;

case BOX_BACK:
rawWidth = BOXART_BACK_WIDTH;
break;

case BOX_ALL:
default:
rawWidth = BOXART_WIDTH;
break;
}
float width = (rawWidth*data->zoom);
float height = (BOXART_HEIGHT*data->zoom);
GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
GX_Position3f32(x, y, depth);
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_TexCoord2f32(0.0f, 1.0f); // s1 t0
GX_Position3f32((x+width),y, depth );
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_TexCoord2f32(0.0f, 0.0f); // s0 t0
GX_Position3f32((x+width), (y+height), depth );
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_TexCoord2f32(1.0f,0.0f); // s0 t1
GX_Position3f32(x,(y+height),depth );
GX_Color4u8(color.r, color.g, color.b, color.a);
GX_TexCoord2f32(1.0f,1.0f); // s1 t1
GX_End();
}

// External
uiDrawObj_t* Draw3DBoxArt(void* texture, int textureBytes, int x, int y, int exp_width, int exp_height, int type) {
draw3DBoxArtEvent_t *eventData = calloc(1, sizeof(draw3DBoxArtEvent_t));
eventData->texture = calloc(1, sizeof(GXTexObj));
eventData->x_pan = x;
eventData->y_pan = y;
eventData->type = type;
// width and height are all flipped so we can load partial textures (front, spine, back)
int textureSize, width = BOXART_HEIGHT, height;
switch(type) {
case BOX_FRONT:
textureSize = BOXART_TEX_FRONT_SIZE;
height = BOXART_FRONT_WIDTH; // 486
break;

case BOX_SPINE:
textureSize = BOXART_TEX_SPINE_SIZE;
height = BOXART_SPINE_WIDTH; // 48
break;

case BOX_BACK:
textureSize = BOXART_TEX_BACK_SIZE;
height = BOXART_BACK_WIDTH; // 490
break;

case BOX_ALL:
default:
textureSize = BOXART_TEX_SIZE;
height = BOXART_WIDTH;
break;
}
// TODO get rid of this if we're going with fixed sizing.
// Calculate zoom based on size expected, keep it within ratio.
float widthRatio = ((float)exp_width / (float)height);
float heightRatio = ((float)exp_height / (float)width);
eventData->zoom = ((float)widthRatio * (float)width > (float)exp_width) ? heightRatio : widthRatio;

DCFlushRange(texture, textureSize);
GX_InitTexObj(eventData->texture, texture, width, height, BOXART_TEX_FMT, GX_CLAMP, GX_CLAMP, GX_FALSE);
uiDrawObj_t *event = calloc(1, sizeof(uiDrawObj_t));
event->type = EV_3DBOXART;
event->data = eventData;
return event;
}

// External
void DrawUpdate3DBoxArt(uiDrawObj_t *evt, float zoom, int x_pan, int y_pan) {
LWP_MutexLock(_videomutex);
draw3DBoxArtEvent_t *data = (draw3DBoxArtEvent_t*)evt->data;
data->zoom = zoom;
data->x_pan = x_pan;
data->y_pan = y_pan;
LWP_MutexUnlock(_videomutex);
}

// Internal
static void _DrawMenuButtons(uiDrawObj_t *evt) {

Expand Down Expand Up @@ -2025,6 +2145,9 @@ static void videoDrawEvent(uiDrawObj_t *videoEvent) {
case EV_TITLEBAR:
_DrawTitleBar(videoEvent);
break;
case EV_3DBOXART:
_Draw3DBoxArt(videoEvent);
break;
default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions cube/swiss/source/gui/FrameBufferMagic.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ uiDrawObj_t* DrawFadingLabel(int x, int y, const char *string, float size);
uiDrawObj_t* DrawMenuButtons(int selection);
uiDrawObj_t* DrawTooltip(const char *tooltip);
uiDrawObj_t* DrawTitleBar();
uiDrawObj_t* Draw3DBoxArt(void* texture, int textureBytes, int x, int y, int exp_width, int exp_height, int type);
void DrawUpdate3DBoxArt(uiDrawObj_t *evt, float zoom, int x_pan, int y_pan);
void DrawUpdateProgressBar(uiDrawObj_t *evt, int percent);
void DrawUpdateProgressBarDetail(uiDrawObj_t *evt, int percent, int speed, int timestart, int timeremain);
void DrawUpdateMenuButtons(int selection);
Expand Down

0 comments on commit 823de3f

Please sign in to comment.