Show pausefader.cpp syntax highlighted
#include <pausefader.h>
#include <display.h>
PauseFader::PauseFader(int m, int t): type(FADED_IN),
max(m), duration(t) {
}
void PauseFader::pause() {
if (type != FADED_OUT && type != FADING_OUT) {
if (type == FADING_IN) {
start = 2 * SDL_GetTicks() - duration - start;
} else {
start = SDL_GetTicks();
}
type = FADING_OUT;
}
}
void PauseFader::unPause() {
if (type != FADED_IN && type != FADING_IN) {
if (type == FADING_OUT) {
start = 2 * SDL_GetTicks() - duration - start;
} else {
start = SDL_GetTicks();
}
type = FADING_IN;
}
}
void PauseFader::doStep() {
if (type == FADED_IN || type == FADED_OUT)
return;
int ticks = SDL_GetTicks() - start;
int level;
if (ticks >= duration) {
if (type == FADING_IN) {
level = 0;
type = FADED_IN;
} else {
level = max;
type = FADED_OUT;
}
} else {
if (type == FADING_OUT) {
level = ticks * max / duration;
} else {
level = (duration - ticks) * max / duration;
}
}
/* do the fade */
KrColorTransform t;
t.Darken(level);
Display::get().getViewNode().SetColor(t);
}
See more files for this project here