The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
intro.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  * Introduction sequence at start of a scenario, End-screen after end of
18  * campaign.
19  */
20 
21 #include "global.hpp"
22 
23 #include "intro.hpp"
24 
25 #include "video.hpp"
26 #include "gettext.hpp"
27 #include "marked-up_text.hpp"
28 #include "sdl/rect.hpp"
29 #include "font.hpp"
30 
31 void the_end(CVideo &video, std::string text, unsigned int duration)
32 {
33  //
34  // Some sane defaults.
35  //
36  if(text.empty())
37  text = _("The End");
38  if(!duration)
39  duration = 3500;
40 
41  SDL_Rect area = screen_area();
42  sdl::fill_rect(video.getSurface(),&area,0);
43 
44  video.flip();
45 
46  const size_t font_size = font::SIZE_XLARGE;
47 
48  area = font::text_area(text,font_size);
49  area.x = screen_area().w/2 - area.w/2;
50  area.y = screen_area().h/2 - area.h/2;
51 
52  for(size_t n = 0; n < 255; n += 5) {
53  if(n)
54  sdl::fill_rect(video.getSurface(),&area,0);
55 
56  const SDL_Color col = create_color(uint8_t(n), uint8_t(n), uint8_t(n), uint8_t(n));
57  font::draw_text(&video,area,font_size,col,text,area.x,area.y);
58  update_rect(area);
59 
60  events::pump();
63  video.flip();
64  CVideo::delay(10);
65  }
66 
67  //
68  // Delay after the end of fading.
69  // Rounded to multiples of 10.
70  //
71  unsigned int count = duration/10;
72  while(count) {
73  events::pump();
76  video.flip();
77  CVideo::delay(10);
78  --count;
79  }
80 }
-file gamestatus.hpp
SDL_Rect text_area(const std::string &text, int size, int style)
Calculate the size of a text (in pixels) if it were to be drawn.
void fill_rect(surface &dst, SDL_Rect *dst_rect, const Uint32 color)
Fill a rectangle on a given surface.
Definition: rect.hpp:143
SDL_Color create_color(const unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
Definition: utils.cpp:89
Definition: video.hpp:58
void flip()
Definition: video.cpp:496
void the_end(CVideo &video, std::string text, unsigned int duration)
Displays a simple fading screen with any user-provided text.
Definition: intro.cpp:31
-file util.hpp
surface & getSurface()
Definition: dummy_video.cpp:22
SDL_Rect screen_area()
Definition: video.cpp:135
const int SIZE_XLARGE
Definition: font.hpp:68
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
void raise_draw_event()
Definition: events.cpp:565
GLuint GLuint GLsizei count
Definition: glew.h:1221
void pump()
Definition: events.cpp:336
SDL_Rect draw_text(surface &dst, const SDL_Rect &area, int size, const SDL_Color &color, const std::string &txt, int x, int y, bool use_tooltips, int style)
Function to draw text on a surface.
void raise_process_event()
Definition: events.cpp:539
GLclampd n
Definition: glew.h:5903
Contains the SDL_Rect helper code.
static void delay(unsigned int milliseconds)
Definition: video.cpp:490
const int font_size
void update_rect(const SDL_Rect &)
Definition: dummy_video.cpp:27
GLsizei const GLcharARB ** string
Definition: glew.h:4503