Mercurial > molko
comparison libadventure/adventure/splashscreen_state.c @ 121:789b23e01f52
misc: reorganize hierarchy, closes #2490
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 05 Oct 2020 13:25:06 +0200 |
parents | src/adventure/splashscreen_state.c@58133933ea17 |
children | c679e08b32b2 |
comparison
equal
deleted
inserted
replaced
120:b3429b26d60d | 121:789b23e01f52 |
---|---|
1 /* | |
2 * splashscreen_state.c -- splash screen state | |
3 * | |
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #include <core/font.h> | |
20 #include <core/game.h> | |
21 #include <core/image.h> | |
22 #include <core/map.h> | |
23 #include <core/map_state.h> | |
24 #include <core/painter.h> | |
25 #include <core/panic.h> | |
26 #include <core/state.h> | |
27 #include <core/sys.h> | |
28 #include <core/texture.h> | |
29 #include <core/window.h> | |
30 | |
31 #include "splashscreen_state.h" | |
32 #include "mainmenu_state.h" | |
33 | |
34 #define DELAY 2000 | |
35 | |
36 struct splashscreen_state_data splashscreen_state_data; | |
37 | |
38 static void | |
39 enter(void) | |
40 { | |
41 struct font font = { | |
42 .color = 0x000000ff | |
43 }; | |
44 | |
45 if (!(font_open(&font, sys_datapath("fonts/teutonic1.ttf"), 130))) | |
46 panic(); | |
47 if (!(font_render(&font, &splashscreen_state_data.text, "Molko's Adventure"))) | |
48 panic(); | |
49 | |
50 /* Compute position. */ | |
51 const unsigned int w = splashscreen_state_data.text.w; | |
52 const unsigned int h = splashscreen_state_data.text.h; | |
53 | |
54 splashscreen_state_data.x = (window.w / 2) - (w / 2); | |
55 splashscreen_state_data.y = (window.h / 2) - (h / 2); | |
56 | |
57 font_finish(&font); | |
58 } | |
59 | |
60 static void | |
61 leave(void) | |
62 { | |
63 /* We don't delete the texture because it is used by mainmenu_state. */ | |
64 } | |
65 | |
66 static void | |
67 handle(const union event *event) | |
68 { | |
69 (void)event; | |
70 } | |
71 | |
72 static void | |
73 update(unsigned int ticks) | |
74 { | |
75 splashscreen_state_data.elapsed += ticks; | |
76 | |
77 if (splashscreen_state_data.elapsed >= DELAY) | |
78 game_switch(&mainmenu_state, false); | |
79 } | |
80 | |
81 static void | |
82 draw(void) | |
83 { | |
84 painter_set_color(0xffffffff); | |
85 painter_clear(); | |
86 texture_draw(&splashscreen_state_data.text, | |
87 splashscreen_state_data.x, | |
88 splashscreen_state_data.y); | |
89 } | |
90 | |
91 struct state splashscreen_state = { | |
92 .enter = enter, | |
93 .leave = leave, | |
94 .handle = handle, | |
95 .update = update, | |
96 .draw = draw | |
97 }; |