From db44e33496a7217fa2c837d432e49a253a6d4568 Mon Sep 17 00:00:00 2001 From: florianf Date: Thu, 11 Feb 2010 14:54:15 +0000 Subject: [PATCH] src/util/reader.[ch]pp: Add "reader_get_layer" ... ... a utility function to read and sanitize the "layer" and "z-pos" options. References: #527. git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6320 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/util/reader.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/util/reader.hpp | 2 ++ 2 files changed, 47 insertions(+) create mode 100644 src/util/reader.cpp diff --git a/src/util/reader.cpp b/src/util/reader.cpp new file mode 100644 index 000000000..ae9cd9fb9 --- /dev/null +++ b/src/util/reader.cpp @@ -0,0 +1,45 @@ +/* + * src/util/reader.cpp - Utility functions for config handling. + * Copyright (C) 2010 Florian Forster + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Authors: + * Florian "octo" Forster + */ + +#include "util/reader.hpp" +#include "video/drawing_request.hpp" /* LAYER_GUI */ + +int reader_get_layer (const Reader& reader, int def) +{ + int tmp = 0; + bool status; + + status = reader.get ("z-pos", tmp); + + if (!status) + status = reader.get ("layer", tmp); + + if (!status) + tmp = def; + + if (tmp > (LAYER_GUI - 100)) + tmp = LAYER_GUI - 100; + + return (tmp); +} /* int reader_get_layer */ + +/* vim: set sw=2 et sts=2 : */ diff --git a/src/util/reader.hpp b/src/util/reader.hpp index be7ec5e3c..788f7ba3b 100644 --- a/src/util/reader.hpp +++ b/src/util/reader.hpp @@ -21,6 +21,8 @@ typedef lisp::Lisp Reader; +int reader_get_layer (const Reader& reader, int def); + #endif /* EOF */ -- 2.11.0