added transition interface
This commit is contained in:
parent
0799f127e8
commit
1416a40451
5 changed files with 92 additions and 6 deletions
|
@ -31,6 +31,7 @@ set(SRCs
|
|||
stageutils.c
|
||||
matrix.c
|
||||
video.c
|
||||
transition.c
|
||||
menu/menu.c
|
||||
menu/mainmenu.c
|
||||
menu/options.c
|
||||
|
|
|
@ -24,11 +24,8 @@ void create_ingame_menu(MenuData *m) {
|
|||
add_menu_entry(m, "Return to Title", return_to_title, NULL);
|
||||
}
|
||||
|
||||
void draw_ingame_menu(MenuData *menu) {
|
||||
float rad = (1.0-menu_fade(menu))*IMENU_BLUR;
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(VIEWPORT_X, VIEWPORT_Y, 0);
|
||||
void draw_ingame_menu_bg(float f) {
|
||||
float rad = f*IMENU_BLUR;
|
||||
|
||||
if(!tconfig.intval[NO_SHADER]) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
@ -41,13 +38,19 @@ void draw_ingame_menu(MenuData *menu) {
|
|||
|
||||
glUseProgram(0);
|
||||
}
|
||||
}
|
||||
|
||||
void draw_ingame_menu(MenuData *menu) {
|
||||
glPushMatrix();
|
||||
glTranslatef(VIEWPORT_X, VIEWPORT_Y, 0);
|
||||
|
||||
draw_ingame_menu_bg(1.0-menu_fade(menu));
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(VIEWPORT_W/2, VIEWPORT_H/4, 0);
|
||||
|
||||
draw_menu_selector(0, menu->drawdata[0], menu->drawdata[1]/45.0, 0.25, menu->frames);
|
||||
|
||||
// cirno's perfect math class #2: Euler Sign ~ Differential Fun
|
||||
menu->drawdata[0] += (menu->cursor*35 - menu->drawdata[0])/7.0;
|
||||
menu->drawdata[1] += (strlen(menu->entries[menu->cursor].name)*5 - menu->drawdata[1])/10.0;
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
#include "menu.h"
|
||||
|
||||
void draw_ingame_menu_bg(float f);
|
||||
|
||||
void create_ingame_menu(MenuData *menu);
|
||||
void draw_ingame_menu(MenuData *menu);
|
||||
int ingame_menu_loop(MenuData *menu);
|
||||
|
|
50
src/transition.c
Normal file
50
src/transition.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* This software is licensed under the terms of the MIT-License
|
||||
* See COPYING for further information.
|
||||
* ---
|
||||
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
|
||||
*/
|
||||
|
||||
#include "transition.h"
|
||||
#include "menu/ingamemenu.h"
|
||||
#include "global.h"
|
||||
|
||||
static Transition transition;
|
||||
|
||||
float trans_fade(Transition *t) {
|
||||
if(t->frames <= t->dur1)
|
||||
return t->frames/(float)t->dur1;
|
||||
else
|
||||
return (t->dur1+t->dur2-t->frames)/(float)t->dur2;
|
||||
}
|
||||
|
||||
void TransFadeBlack(Transition *t) {
|
||||
fade_out(trans_fade(t));
|
||||
}
|
||||
|
||||
void TransFadeWhite(Transition *t) {
|
||||
colorfill(1,1,1,trans_fade(t));
|
||||
}
|
||||
|
||||
void TransIngame(Transition *t) {
|
||||
draw_ingame_menu_bg(trans_fade(t));
|
||||
}
|
||||
|
||||
void set_transition(TransitionRule rule, int dur1, int dur2) {
|
||||
memset(&transition, 0, sizeof(Transition));
|
||||
transition.rule = rule;
|
||||
transition.dur1 = dur1;
|
||||
transition.dur2 = dur2;
|
||||
}
|
||||
|
||||
void draw_transition(void) {
|
||||
if(transition.rule)
|
||||
transition.rule(&transition);
|
||||
|
||||
transition.frames++;
|
||||
|
||||
if(transition.frames > transition.dur1 + transition.dur2)
|
||||
memset(&transition, 0, sizeof(Transition));
|
||||
}
|
||||
|
||||
|
30
src/transition.h
Normal file
30
src/transition.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* This software is licensed under the terms of the MIT-License
|
||||
* See COPYING for further information.
|
||||
* ---
|
||||
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
|
||||
*/
|
||||
|
||||
#ifndef TRANSITION_H
|
||||
#define TRANSITION_H
|
||||
|
||||
typedef struct Transition Transition;
|
||||
typedef void (*TransitionRule)(Transition *t);
|
||||
|
||||
struct Transition {
|
||||
int frames;
|
||||
int dur1; // first half
|
||||
int dur2; // second half
|
||||
|
||||
TransitionRule rule;
|
||||
};
|
||||
|
||||
void TransFadeBlack(Transition *t);
|
||||
void TransFadeWhite(Transition *t);
|
||||
|
||||
void TransIngame(Transition *t);
|
||||
|
||||
void set_transition(TransitionRule rule, int dur1, int dur2);
|
||||
void draw_transition(void);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue