diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libadventure/adventure/splashscreen_state.c	Mon Oct 05 13:25:06 2020 +0200
@@ -0,0 +1,97 @@
+/*
+ * splashscreen_state.c -- splash screen state
+ *
+ * Copyright (c) 2020 David Demelier <markand@malikania.fr>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <core/font.h>
+#include <core/game.h>
+#include <core/image.h>
+#include <core/map.h>
+#include <core/map_state.h>
+#include <core/painter.h>
+#include <core/panic.h>
+#include <core/state.h>
+#include <core/sys.h>
+#include <core/texture.h>
+#include <core/window.h>
+
+#include "splashscreen_state.h"
+#include "mainmenu_state.h"
+
+#define DELAY 2000
+
+struct splashscreen_state_data splashscreen_state_data;
+
+static void
+enter(void)
+{
+	struct font font = {
+		.color = 0x000000ff
+	};
+
+	if (!(font_open(&font, sys_datapath("fonts/teutonic1.ttf"), 130)))
+		panic();
+	if (!(font_render(&font, &splashscreen_state_data.text, "Molko's Adventure")))
+		panic();
+
+	/* Compute position. */
+	const unsigned int w = splashscreen_state_data.text.w;
+	const unsigned int h = splashscreen_state_data.text.h;
+
+	splashscreen_state_data.x = (window.w / 2) - (w / 2);
+	splashscreen_state_data.y = (window.h / 2) - (h / 2);
+
+	font_finish(&font);
+}
+
+static void
+leave(void)
+{
+	/* We don't delete the texture because it is used by mainmenu_state. */
+}
+
+static void
+handle(const union event *event)
+{
+	(void)event;
+}
+
+static void
+update(unsigned int ticks)
+{
+	splashscreen_state_data.elapsed += ticks;
+
+	if (splashscreen_state_data.elapsed >= DELAY)
+		game_switch(&mainmenu_state, false);
+}
+
+static void
+draw(void)
+{
+	painter_set_color(0xffffffff);
+	painter_clear();
+	texture_draw(&splashscreen_state_data.text,
+		splashscreen_state_data.x,
+		splashscreen_state_data.y);
+}
+
+struct state splashscreen_state = {
+	.enter = enter,
+	.leave = leave,
+	.handle = handle,
+	.update = update,
+	.draw = draw
+};