29#define INTRO_SPEED 30.
30#define SIDE_MARGIN 100.
31#define IMAGE_WIDTH 300.
34typedef struct intro_img_t_ {
42typedef enum intro_opcode_t_ {
49typedef struct intro_cmd_t_ {
60static int has_side_gfx = 0;
71static int intro_draw_text(
char **
const sb_list,
int sb_size,
int sb_index,
double offset,
double line_height );
79 char *cur_line, *rest_of_file;
91 while (rest_of_file) {
92 cur_line = rest_of_file;
93 rest_of_file = strchr(cur_line,
'\n');
95 if (rest_of_file != NULL) {
97 if (rest_of_file > cur_line && *(rest_of_file-1) ==
'\r')
98 *(rest_of_file-1) =
'\0';
99 *rest_of_file++ =
'\0';
102 if (strncmp( cur_line,
"[fadein ", 8 ) == 0) {
106 cur_line[strlen( cur_line ) - 1] =
'\0';
110 else if (strncmp( cur_line,
"[fadeout]", 9 ) == 0)
147 img->fade_rate = 0.0;
160 img->h = img->tex->h * img->w / img->tex->w;
162 img->y = (double)SCREEN_H / 2.0 - (img->h / 2.0);
164 img->fade_rate = 0.1;
175 const char *img_file )
177 if (NULL == side->tex)
188 if (NULL != transition->tex) {
190 WARN( _(
"Intro scrolling too fast!") );
194 if (side->fade_rate < 0.0)
195 transition->fade_rate = 0.0;
198 side->fade_rate = -0.1;
213 while (SDL_PollEvent(&event)) {
214 if (event.type == SDL_QUIT) {
221 if (event.type == SDL_WINDOWEVENT &&
222 event.window.event == SDL_WINDOWEVENT_RESIZED) {
227 if (event.type != SDL_KEYDOWN)
231 if (event.key.keysym.sym == SDLK_ESCAPE) {
237 else if (event.key.keysym.sym == SDLK_UP) {
244 else if (event.key.keysym.sym == SDLK_DOWN) {
251 else if ((event.key.keysym.sym == SDLK_SPACE) ||
252 (event.key.keysym.sym == SDLK_RETURN))
256 else if (event.key.keysym.sym == SDLK_BACKSPACE)
274static int intro_draw_text(
char **
const sb_list,
int sb_size,
int sb_index,
double offset,
double line_height )
278 register int stop = 1;
285 y = SCREEN_H + offset - line_height;
287 if ( sb_list[ i ] != NULL ) {
293 i = ( i + 1 ) % sb_size;
294 }
while ( i != sb_index );
310 int lines_per_screen;
315 unsigned int tcur, tlast, tlag;
336 lines_per_screen = (int)(SCREEN_H / line_height + 1.5);
341 sb_arr = calloc( lines_per_screen,
sizeof(
char * ) );
345 offset = line_height;
351 tlast = SDL_GetTicks();
353 tcur = SDL_GetTicks();
354 delta = (double)(tcur - tlast) / 1000.;
358 offset += vel * delta;
359 while (! (offset < line_height)) {
362 free( sb_arr[sb_index] );
363 sb_arr[sb_index] =
strndup( &iter.
text[iter.l_begin], iter.
l_end - iter.l_begin );
364 offset -= line_height;
365 sb_index = ( sb_index + 1 ) % lines_per_screen;
376 if (NULL == side_image.tex) {
377 WARN(_(
"Tried to fade out without an image.") );
380 side_image.fade_rate = -0.1;
381 side_image.c.a = 0.99;
386 free( sb_arr[sb_index] );
387 sb_arr[sb_index] = NULL;
388 offset -= line_height;
389 sb_index = ( sb_index + 1 ) % lines_per_screen;
394 if (side_image.tex != NULL && side_image.c.a < 1.0) {
395 side_image.c.a += delta * vel * side_image.fade_rate;
397 if (transition.tex != NULL && transition.fade_rate > 0.0)
398 transition.c.a += delta * vel * transition.fade_rate;
400 if (side_image.c.a > 1.0) {
402 side_image.c.a = 1.0;
403 side_image.fade_rate = 0.0;
405 else if (side_image.c.a < 0.0) {
408 if (transition.tex != NULL) {
409 side_image.tex = transition.tex;
410 side_image.c.a = transition.c.a;
411 side_image.w = transition.w;
412 side_image.h = transition.h;
413 side_image.y = transition.y;
414 side_image.fade_rate = 0.1;
415 transition.tex = NULL;
416 transition.c.a = 1.0;
419 side_image.c.a = 1.0;
420 side_image.tex = NULL;
421 side_image.fade_rate = 0.0;
427 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
433 stop =
intro_draw_text( sb_arr, lines_per_screen, sb_index, offset, line_height );
435 if (NULL != side_image.tex)
438 side_image.w, side_image.h, &side_image.c );
440 if (NULL != transition.tex && transition.c.a > 0.0)
443 transition.w, transition.h, &transition.c );
448 tlag = SDL_GetTicks() - tcur;
450 SDL_Delay( 25 - tlag );
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#define array_back(ptr_array)
Returns the last element in the array.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
int gl_printLineIteratorNext(glPrintLineIterator *iter)
Updates iter with the next line's information.
void gl_printRaw(const glFont *ft_font, double x, double y, const glColour *c, double outlineR, const char *text)
Prints text on screen.
void gl_freeFont(glFont *font)
Frees a loaded font. Caution: its glFontStash still has a slot in avail_fonts. At the time of writing...
void gl_printLineIteratorInit(glPrintLineIterator *iter, const glFont *ft_font, const char *text, int width)
Initialize an iterator object for breaking text into lines.
int gl_fontInit(glFont *font, const char *fname, const unsigned int h, const char *prefix, unsigned int flags)
Initializes a font.
static void initialize_image(intro_img_t *img)
Initialize an intro_img_t to default values.
static intro_cmd_t * intro_cmds
intro_opcode_t
The possible display operations.
static int intro_draw_text(char **const sb_list, int sb_size, int sb_index, double offset, double line_height)
Draw intro text onto the screen.
static int intro_event_handler(int *stop, double *offset, double *vel)
Handle user events (mouse clicks, key presses, etc.).
static int intro_load(const char *text)
Loads the intro stuff.
static void load_image(intro_img_t *img, const char *img_file)
Initialize an intro_img_t to default values.
static void intro_cleanup(void)
Cleans up the intro stuff.
int intro_display(const char *text, const char *mus)
Displays the introduction sequence.
static void intro_fade_image_in(intro_img_t *side, intro_img_t *transition, const char *img_file)
Fade an image in.
int music_choose(const char *situation)
Actually runs the music stuff, based on situation.
int music_stop(int disable)
Stops the loaded music.
void music_update(double dt)
Updates the music.
void naev_quit(void)
Flags naev to quit.
void naev_resize(void)
Wrapper for gl_resize that handles non-GL reinitialization.
int naev_isQuit(void)
Get if Naev is trying to quit.
Header file with generic functions and naev-specifics.
void * ndata_read(const char *path, size_t *filesize)
Reads a file from the ndata (will be NUL terminated).
char * strndup(const char *s, size_t n)
Return a pointer to a new string, which is a duplicate of the string s (or, if necessary,...
void gl_renderScale(const glTexture *texture, double bx, double by, double bw, double bh, const glColour *c)
Blits a texture scaling it.
glTexture * gl_newImage(const char *path, const unsigned int flags)
Loads an image as a texture.
void gl_freeTexture(glTexture *texture)
Frees a texture.
Represents a font in memory.
The state of a line iteration. This matches the process of rendering text into an on-screen box: An e...
Abstraction for rendering sprite sheets.
A display command (operation code and operand if applicable).
Intro Image: to be displayed to the side of the scrolling.