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_ {
62static int has_side_gfx = 0;
73 const char *img_file );
74static int intro_draw_text(
char **
const sb_list,
int sb_size,
int sb_index,
75 double offset,
double line_height );
83 char *cur_line, *rest_of_file;
92 FONT_PATH_PREFIX, 0 );
96 while ( rest_of_file ) {
97 cur_line = rest_of_file;
98 rest_of_file = strchr( cur_line,
'\n' );
101 if ( rest_of_file != NULL ) {
103 if ( rest_of_file > cur_line && *( rest_of_file - 1 ) ==
'\r' )
104 *( rest_of_file - 1 ) =
'\0';
105 *rest_of_file++ =
'\0';
108 if ( strncmp( cur_line,
"[fadein ", 8 ) == 0 ) {
112 cur_line[strlen( cur_line ) - 1] =
'\0';
115 }
else if ( strncmp( cur_line,
"[fadeout]", 9 ) == 0 )
121 ( cur_line[0] ==
'\0' ? cur_line : _( cur_line ) );
153 img->fade_rate = 0.0;
166 img->h = img->tex->h * img->w / img->tex->w;
168 img->y = (double)SCREEN_H / 2.0 - ( img->h / 2.0 );
170 img->fade_rate = 0.1;
181 const char *img_file )
183 if ( NULL == side->tex )
194 if ( NULL != transition->tex ) {
196 WARN( _(
"Intro scrolling too fast!" ) );
200 if ( side->fade_rate < 0.0 )
201 transition->fade_rate = 0.0;
204 side->fade_rate = -0.1;
219 while ( SDL_PollEvent( &event ) ) {
220 if ( event.type == SDL_QUIT ) {
227 if ( event.type == SDL_WINDOWEVENT &&
228 event.window.event == SDL_WINDOWEVENT_RESIZED ) {
233 if ( event.type != SDL_KEYDOWN )
237 if ( event.key.keysym.sym == SDLK_ESCAPE ) {
243 else if ( event.key.keysym.sym == SDLK_UP ) {
250 else if ( event.key.keysym.sym == SDLK_DOWN ) {
257 else if ( ( event.key.keysym.sym == SDLK_SPACE ) ||
258 ( event.key.keysym.sym == SDLK_RETURN ) )
262 else if ( event.key.keysym.sym == SDLK_BACKSPACE )
281 double offset,
double line_height )
285 register int stop = 1;
292 y = SCREEN_H + offset - line_height;
294 if ( sb_list[i] != NULL ) {
296 if ( y < 2 * line_height ) {
297 glColour fadedColour = cFontGreen;
298 fadedColour.a = y / ( (double)line_height * 2. );
300 }
else if ( y > SCREEN_H - 2 * line_height ) {
301 glColour fadedColour = cFontGreen;
303 ( (double)SCREEN_H - y ) / ( (
double)line_height * 2. );
310 i = ( i + 1 ) % sb_size;
311 }
while ( i != sb_index );
327 int lines_per_screen;
332 unsigned int tcur, tlast, tlag;
354 lines_per_screen = (int)( SCREEN_H / line_height + 1.5 );
360 sb_arr = calloc( lines_per_screen,
sizeof(
char *) );
364 offset = line_height;
370 tlast = SDL_GetTicks();
372 tcur = SDL_GetTicks();
373 delta = (double)( tcur - tlast ) / 1000.;
377 offset += vel * delta;
378 while ( !( offset < line_height ) ) {
381 free( sb_arr[sb_index] );
384 offset -= line_height;
385 sb_index = ( sb_index + 1 ) % lines_per_screen;
398 if ( NULL == side_image.tex ) {
399 WARN( _(
"Tried to fade out without an image." ) );
402 side_image.fade_rate = -0.1;
403 side_image.c.a = 0.99;
408 free( sb_arr[sb_index] );
409 sb_arr[sb_index] = NULL;
410 offset -= line_height;
411 sb_index = ( sb_index + 1 ) % lines_per_screen;
416 if ( side_image.tex != NULL && side_image.c.a < 1.0 ) {
417 side_image.c.a += delta * vel * side_image.fade_rate;
419 if ( transition.tex != NULL && transition.fade_rate > 0.0 )
420 transition.c.a += delta * vel * transition.fade_rate;
422 if ( side_image.c.a > 1.0 ) {
424 side_image.c.a = 1.0;
425 side_image.fade_rate = 0.0;
426 }
else if ( side_image.c.a < 0.0 ) {
429 if ( transition.tex != NULL ) {
430 side_image.tex = transition.tex;
431 side_image.c.a = transition.c.a;
432 side_image.w = transition.w;
433 side_image.h = transition.h;
434 side_image.y = transition.y;
435 side_image.fade_rate = 0.1;
436 transition.tex = NULL;
437 transition.c.a = 1.0;
439 side_image.c.a = 1.0;
440 side_image.tex = NULL;
441 side_image.fade_rate = 0.0;
447 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
456 if ( NULL != side_image.tex )
459 side_image.w, side_image.h, &side_image.c );
461 if ( NULL != transition.tex && transition.c.a > 0.0 )
464 transition.w, transition.h, &transition.c );
469 tlag = SDL_GetTicks() - tcur;
472 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.