Skip to content

Commit

Permalink
Replace slide transition with Maximus32's fade transition
Browse files Browse the repository at this point in the history
  • Loading branch information
Tupakaveli committed Jul 24, 2019
1 parent 00ab656 commit acb9b19
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 71 deletions.
7 changes: 1 addition & 6 deletions include/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ int guiFrameId;
#define GUI_SCREEN_MENU 1
#define GUI_SCREEN_INFO 2

#define TRANSITION_LEFT 0
#define TRANSITION_RIGHT 1
#define TRANSITION_UP 2
#define TRANSITION_DOWN 3

void guiSwitchScreen(int target, int transition);
void guiSwitchScreen(int target);

void guiReloadScreenExtents();

Expand Down
3 changes: 0 additions & 3 deletions include/renderman.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ int rmUnScaleX(int x);
/** Scale y from native to 480 resolution */
int rmUnScaleY(int y);

/** sets the transposition coordiantes (all content is transposed with these values) */
void rmSetTransposition(float x, float y);

//Returns H-sync frequency in KHz
unsigned char rmGetHsync(void);

Expand Down
61 changes: 25 additions & 36 deletions src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static gui_screen_handler_t *screenHandler = &screenHandlers[GUI_SCREEN_MENU];

// screen transition handling
static gui_screen_handler_t *screenHandlerTarget = NULL;
static int transIndex, transMax, transitionX, transitionY;
static int transIndex;

// Helper perlin noise data
#define PLASMA_H 32
Expand Down Expand Up @@ -2057,31 +2057,35 @@ static void guiReadPads()
}

// renders the screen and handles inputs. Also handles screen transitions between numerous
// screen handlers. For now we only have left-to right screen transition
// screen handlers. Fade transition code written by Maximus32
static void guiShow()
{
// is there a transmission effect going on or are
// we in a normal rendering state?
if (screenHandlerTarget) {
// advance the effect

// render the old screen, transposed
rmSetTransposition(transIndex * transitionX, transIndex * transitionY);
screenHandler->renderScreen();

// render new screen transposed again
rmSetTransposition((transIndex - transMax) * transitionX, (transIndex - transMax) * transitionY);
screenHandlerTarget->renderScreen();

// reset transposition to zero
rmSetTransposition(0, 0);
u8 alpha;
const u8 transition_frames = 26;
if (transIndex < (transition_frames/2)) {
// Fade-out old screen
// index: 0..7
// alpha: 1..8 * transition_step
screenHandler->renderScreen();
alpha = fade((float)(transIndex + 1) / (transition_frames / 2)) * 0x80;
}
else {
// Fade-in new screen
// index: 8..15
// alpha: 8..1 * transition_step
screenHandlerTarget->renderScreen();
alpha = fade((float)(transition_frames - transIndex) / (transition_frames / 2)) * 0x80;
}

// move the transition indicator forward
transIndex += (min(transIndex, transMax - transIndex) >> 1) + 1;
// Overlay the actual "fade"
rmDrawRect(0, 0, screenWidth, screenHeight, GS_SETREG_RGBA(0x00, 0x00, 0x00, alpha));

if (transIndex > transMax) {
transitionX = 0;
transitionY = 0;
// Advance the effect
transIndex++;
if (transIndex >= transition_frames) {
screenHandler = screenHandlerTarget;
screenHandlerTarget = NULL;
}
Expand Down Expand Up @@ -2167,24 +2171,9 @@ void guiSetFrameHook(gui_callback_t cback)
gFrameHook = cback;
}

void guiSwitchScreen(int target, int transition)
{
sfxPlay(SFX_TRANSITION);
if (transition == TRANSITION_LEFT) {
transitionX = 1;
transMax = screenWidth;
} else if (transition == TRANSITION_RIGHT) {
transitionX = -1;
transMax = screenWidth;
} else if (transition == TRANSITION_UP) {
transitionY = 1;
transMax = screenHeight;
} else if (transition == TRANSITION_DOWN) {
transitionY = -1;
transMax = screenHeight;
}
void guiSwitchScreen(int target)
{
transIndex = 0;

screenHandlerTarget = &screenHandlers[target];
}

Expand Down
12 changes: 6 additions & 6 deletions src/menusys.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ void menuHandleInputMenu()
if (getKeyOn(KEY_START) || getKeyOn(gSelectButton == KEY_CIRCLE ? KEY_CROSS : KEY_CIRCLE)) {
//Check if there is anything to show the user, at all.
if (gAPPStartMode || gETHStartMode || gUSBStartMode || gHDDStartMode)
guiSwitchScreen(GUI_SCREEN_MAIN, TRANSITION_LEFT);
guiSwitchScreen(GUI_SCREEN_MAIN);
}
}

Expand Down Expand Up @@ -766,22 +766,22 @@ void menuHandleInputMain()
menuNextV();
} else if (getKeyOn(KEY_CROSS)) {
if (gSelectButton == KEY_CROSS && (selected_item->item->current && gUseInfoScreen && gTheme->infoElems.first))
guiSwitchScreen(GUI_SCREEN_INFO, TRANSITION_DOWN);
guiSwitchScreen(GUI_SCREEN_INFO);
else
selected_item->item->execCross(selected_item->item);
} else if (getKeyOn(KEY_TRIANGLE)) {
selected_item->item->execTriangle(selected_item->item);
} else if (getKeyOn(KEY_CIRCLE)) {
if (gSelectButton == KEY_CIRCLE && (selected_item->item->current && gUseInfoScreen && gTheme->infoElems.first))
guiSwitchScreen(GUI_SCREEN_INFO, TRANSITION_DOWN);
guiSwitchScreen(GUI_SCREEN_INFO);
else
selected_item->item->execCircle(selected_item->item);
} else if (getKeyOn(KEY_SQUARE)) {
selected_item->item->execSquare(selected_item->item);
} else if (getKeyOn(KEY_START)) {
// reinit main menu - show/hide items valid in the active context
menuInitMainMenu();
guiSwitchScreen(GUI_SCREEN_MENU, TRANSITION_RIGHT);
guiSwitchScreen(GUI_SCREEN_MENU);
} else if (getKeyOn(KEY_SELECT)) {
selected_item->item->refresh(selected_item->item);
} else if (getKey(KEY_L1)) {
Expand Down Expand Up @@ -828,7 +828,7 @@ void menuHandleInputInfo()
{
if (getKeyOn(KEY_CROSS)) {
if (gSelectButton == KEY_CIRCLE)
guiSwitchScreen(GUI_SCREEN_MAIN, TRANSITION_UP);
guiSwitchScreen(GUI_SCREEN_MAIN);
else
selected_item->item->execCross(selected_item->item);
} else if (getKey(KEY_UP)) {
Expand All @@ -837,7 +837,7 @@ void menuHandleInputInfo()
menuNextV();
} else if (getKeyOn(KEY_CIRCLE)) {
if (gSelectButton == KEY_CROSS)
guiSwitchScreen(GUI_SCREEN_MAIN, TRANSITION_UP);
guiSwitchScreen(GUI_SCREEN_MAIN);
else
selected_item->item->execCircle(selected_item->item);
} else if (getKey(KEY_L1)) {
Expand Down
26 changes: 6 additions & 20 deletions src/renderman.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ static int iDisplayHeight;
static int iDisplayXOff;
static int iDisplayYOff;

// Transposition values - all rendering will be transposed (moved on screen) by these
static float transX = 0.0f;
static float transY = 0.0f;

// Transposition values including overscan compensation
static float fRenderXOff = 0.0f;
static float fRenderYOff = 0.0f;
Expand Down Expand Up @@ -478,29 +474,19 @@ int rmUnScaleY(int y)
return (y*480)/iDisplayHeight;
}

static void rmUpdateRenderOffsets()
{
fRenderXOff = (float)iDisplayXOff + transX - 0.5f;
fRenderYOff = (float)iDisplayYOff + transY - 0.5f;

if (rmGetInterlacedFrameMode() == 1)
fRenderYOff += 0.25f;
}

void rmSetOverscan(int overscan)
{
iDisplayXOff = (gsGlobal->Width * overscan) / (2 * 1000);
iDisplayYOff = (gsGlobal->Height * overscan) / (2 * 1000);
iDisplayWidth = gsGlobal->Width - (2 * iDisplayXOff);
iDisplayHeight = gsGlobal->Height - (2 * iDisplayYOff);
rmUpdateRenderOffsets();
}

void rmSetTransposition(float x, float y)
{
transX = X_SCALE(x);
transY = Y_SCALE(y);
rmUpdateRenderOffsets();
fRenderXOff = (float)iDisplayXOff - 0.5f;
fRenderYOff = (float)iDisplayYOff - 0.5f;

if (rmGetInterlacedFrameMode() == 1)
fRenderYOff += 0.25f;

}

unsigned char rmGetHsync(void)
Expand Down

0 comments on commit acb9b19

Please sign in to comment.