-
-#define glue3_aux(x,y,z) x ## y ## z
-#define glue3(x,y,z) glue3_aux(x,y,z)
-
-#define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,) = glue3(UINT,bits,_C) (0);
-#define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,) = glue3(INT,bits,_C) (0);
-
-#define DECL(us,bits) glue3(DECL,us,) (bits)
-
-#define TESTUMAX(bits) glue3(u,bits,) = ~glue3(u,bits,); if (glue3(UINT,bits,_MAX) != glue3(u,bits,)) printf ("Something wrong with UINT%d_MAX\n", bits)
-
-#define REPORTERROR(msg) { err_n++; if (err_first <= 0) err_first = __LINE__; printf msg; }
-
-#define X_SIZE_MAX ((size_t)-1)
-
-int main () {
- int err_n = 0;
- int err_first = 0;
- DECL(I,8)
- DECL(U,8)
- DECL(I,16)
- DECL(U,16)
- DECL(I,32)
- DECL(U,32)
-#ifdef INT64_MAX
- DECL(I,64)
- DECL(U,64)
-#endif
- intmax_t imax = INTMAX_C(0);
- uintmax_t umax = UINTMAX_C(0);
- char str0[256], str1[256];
-
- sprintf (str0, "%" PRINTF_INT32_MODIFIER "d", INT32_C(2147483647));
- if (0 != strcmp (str0, "2147483647")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str0));
- if (atoi(PRINTF_INT32_DEC_WIDTH) != (int) strlen(str0)) REPORTERROR (("Something wrong with PRINTF_INT32_DEC_WIDTH : %s\n", PRINTF_INT32_DEC_WIDTH));
- sprintf (str0, "%" PRINTF_INT32_MODIFIER "u", UINT32_C(4294967295));
- if (0 != strcmp (str0, "4294967295")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str0));
- if (atoi(PRINTF_UINT32_DEC_WIDTH) != (int) strlen(str0)) REPORTERROR (("Something wrong with PRINTF_UINT32_DEC_WIDTH : %s\n", PRINTF_UINT32_DEC_WIDTH));
-#ifdef INT64_MAX
- sprintf (str1, "%" PRINTF_INT64_MODIFIER "d", INT64_C(9223372036854775807));
- if (0 != strcmp (str1, "9223372036854775807")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str1));
- if (atoi(PRINTF_INT64_DEC_WIDTH) != (int) strlen(str1)) REPORTERROR (("Something wrong with PRINTF_INT64_DEC_WIDTH : %s, %d\n", PRINTF_INT64_DEC_WIDTH, (int) strlen(str1)));
- sprintf (str1, "%" PRINTF_INT64_MODIFIER "u", UINT64_C(18446744073709550591));
- if (0 != strcmp (str1, "18446744073709550591")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str1));
- if (atoi(PRINTF_UINT64_DEC_WIDTH) != (int) strlen(str1)) REPORTERROR (("Something wrong with PRINTF_UINT64_DEC_WIDTH : %s, %d\n", PRINTF_UINT64_DEC_WIDTH, (int) strlen(str1)));
-#endif
-
- sprintf (str0, "%d %x\n", 0, ~0);
-
- sprintf (str1, "%d %x\n", i8, ~0);
- if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i8 : %s\n", str1));
- sprintf (str1, "%u %x\n", u8, ~0);
- if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with u8 : %s\n", str1));
- sprintf (str1, "%d %x\n", i16, ~0);
- if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i16 : %s\n", str1));
- sprintf (str1, "%u %x\n", u16, ~0);
- if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with u16 : %s\n", str1));
- sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0);
- if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i32 : %s\n", str1));
- sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0);
- if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with u32 : %s\n", str1));
-#ifdef INT64_MAX
- sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0);
- if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i64 : %s\n", str1));
-#endif
- sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0);
- if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with imax : %s\n", str1));
- sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0);
- if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with umax : %s\n", str1));
-
- TESTUMAX(8);
- TESTUMAX(16);
- TESTUMAX(32);
-#ifdef INT64_MAX
- TESTUMAX(64);
-#endif
-
-#define STR(v) #v
-#define Q(v) printf ("sizeof " STR(v) " = %u\n", (unsigned) sizeof (v));
- if (err_n) {
- printf ("pstdint.h is not correct. Please use sizes below to correct it:\n");
- }
-
- Q(int)
- Q(unsigned)
- Q(long int)
- Q(short int)
- Q(int8_t)
- Q(int16_t)
- Q(int32_t)
-#ifdef INT64_MAX
- Q(int64_t)
-#endif
-
-#if UINT_MAX < X_SIZE_MAX
- printf ("UINT_MAX < X_SIZE_MAX\n");
-#else
- printf ("UINT_MAX >= X_SIZE_MAX\n");
-#endif
- printf ("%" PRINTF_INT64_MODIFIER "u vs %" PRINTF_INT64_MODIFIER "u\n", UINT_MAX, X_SIZE_MAX);
-
- return EXIT_SUCCESS;
-}
-
-#endif
diff --git a/tcod_sys/libtcod/include/fov.h b/tcod_sys/libtcod/include/fov.h
deleted file mode 100644
index 8387512ec..000000000
--- a/tcod_sys/libtcod/include/fov.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _TCOD_FOV_H
-#define _TCOD_FOV_H
-
-#include "libtcod_portability.h"
-#include "fov_types.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-/* allocate a new map */
-TCODLIB_API TCOD_map_t TCOD_map_new(int width, int height);
-/* set all cells as solid rock (cannot see through nor walk) */
-TCODLIB_API void TCOD_map_clear(TCOD_map_t map, bool transparent, bool walkable);
-/* copy a map to another, reallocating it when needed */
-TCODLIB_API void TCOD_map_copy(TCOD_map_t source, TCOD_map_t dest);
-/* change a cell properties */
-TCODLIB_API void TCOD_map_set_properties(TCOD_map_t map, int x, int y, bool is_transparent, bool is_walkable);
-/* destroy a map */
-TCODLIB_API void TCOD_map_delete(TCOD_map_t map);
-
-/* calculate the field of view (potentially visible cells from player_x,player_y) */
-TCODLIB_API void TCOD_map_compute_fov(TCOD_map_t map, int player_x, int player_y, int max_radius, bool light_walls, TCOD_fov_algorithm_t algo);
-/* check if a cell is in the last computed field of view */
-TCODLIB_API bool TCOD_map_is_in_fov(TCOD_map_t map, int x, int y);
-TCODLIB_API void TCOD_map_set_in_fov(TCOD_map_t map, int x, int y, bool fov);
-
-/* retrieve properties from the map */
-TCODLIB_API bool TCOD_map_is_transparent(TCOD_map_t map, int x, int y);
-TCODLIB_API bool TCOD_map_is_walkable(TCOD_map_t map, int x, int y);
-TCODLIB_API int TCOD_map_get_width(TCOD_map_t map);
-TCODLIB_API int TCOD_map_get_height(TCOD_map_t map);
-TCODLIB_API int TCOD_map_get_nb_cells(TCOD_map_t map);
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/tcod_sys/libtcod/include/fov_types.h b/tcod_sys/libtcod/include/fov_types.h
deleted file mode 100644
index 8d7e088f7..000000000
--- a/tcod_sys/libtcod/include/fov_types.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _TCOD_FOV_TYPES_H
-#define _TCOD_FOV_TYPES_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-typedef void *TCOD_map_t;
-
-/* FOV_BASIC : http://roguebasin.roguelikedevelopment.org/index.php?title=Ray_casting
- FOV_DIAMOND : http://www.geocities.com/temerra/los_rays.html
- FOV_SHADOW : http://roguebasin.roguelikedevelopment.org/index.php?title=FOV_using_recursive_shadowcasting
- FOV_PERMISSIVE : http://roguebasin.roguelikedevelopment.org/index.php?title=Precise_Permissive_Field_of_View
- FOV_RESTRICTIVE : Mingos' Restrictive Precise Angle Shadowcasting (contribution by Mingos) */
-
-typedef enum {
- FOV_BASIC,
- FOV_DIAMOND,
- FOV_SHADOW,
- FOV_PERMISSIVE_0,
- FOV_PERMISSIVE_1,
- FOV_PERMISSIVE_2,
- FOV_PERMISSIVE_3,
- FOV_PERMISSIVE_4,
- FOV_PERMISSIVE_5,
- FOV_PERMISSIVE_6,
- FOV_PERMISSIVE_7,
- FOV_PERMISSIVE_8,
- FOV_RESTRICTIVE,
- NB_FOV_ALGORITHMS } TCOD_fov_algorithm_t;
-#define FOV_PERMISSIVE(x) ((TCOD_fov_algorithm_t)(FOV_PERMISSIVE_0 + (x)))
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* _TCOD_FOV_TYPES_H */
diff --git a/tcod_sys/libtcod/include/howto.hpp b/tcod_sys/libtcod/include/howto.hpp
deleted file mode 100644
index 760f7ed96..000000000
--- a/tcod_sys/libtcod/include/howto.hpp
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-/* This file contains no code. It's only an input for doctcod */
-
-/**
- @PageName compile_libtcod
- @PageCategory Howtos
- @PageTitle How to compile libtcod
- @PageDesc This page contains howtos about how to get the latest libtcod source code and compile it.
-*/
-
-/**
- @PageName compile_libtcod_mingw
- @PageFather compile_libtcod
- @PageTitle On Windows with Mingw
- @PageDesc Mingw installation
- Download the latest version of Mingw from this address :
- http://sourceforge.net/projects/mingw/files/
-
- The latest installer should be at the top of the page with a name starting with mingw-get-inst..
-
-
-
- Download and run the program. Follow the installation steps. Be sure to check the "Use pre-packaged repository" option :
-
-
-
- The latest version might be less stable and might not work with a precompiled libtcod.
-
- When you arrive at the component selection screen, check C compiler, C++ compiler and MSys system :
-
-
-
- Keep on following the installation steps until the installation is finished. Now you have a "Mingw Shell" program in your start menu. This is the terminal you will use to compile and debug your game.
-
- TortoiseHg installation
- In order to get the latest version of libtcod, you need a mercurial client.
- Go to the download page and grab the client corresponding to your version of Windows :
- http://tortoisehg.bitbucket.org/download/index.html
-
- Follow the installation wizard using the default configuration. Once the installation is finished, restart your computer.
-
- Now you should be able to use mercurial (hg) from the Mingw Shell. To check if everything is ok, start a shell and type "which hg" :
-
-
-
- Getting libtcod source code
- In Mingw Shell, type :
- hg clone https://bitbucket.org/jice/libtcod
-
- This might take some time so grab a beer. Once it's finished, a libtcod directory has been created.
- You can check the documentation (the same you're currently reading) in libtcod/doc/index2.html.
- The headers are in libtcod/include.
- The source code in libtcod/src.
-
- Compiling libtcod
- Go in libtcod's main directory :
- cd libtcod
- And start the compilation :
- make -f makefiles/makefile-mingw
- The compilation make take a few seconds depending on your CPU speed. Once it's finished, compile the samples :
- make -f makefiles/makefile-samples-mingw
- Check that everything is ok by running the samples :
- ./samples_cpp
-*/
-
-/**
- @PageName compile_libtcod_linux
- @PageFather compile_libtcod
- @PageTitle On Linux
- @PageDesc Linux compilation
- On a freshly installed Ubuntu :
- Get the tools :
- sudo apt-get install gcc g++ make upx electric-fence libsdl1.2-dev mercurial
-
- Get the latest sources :
- hg clone https://bitbucket.org/jice/libtcod
-
- Compile the library :
- cd libtcod/
- make -f makefiles/makefile-linux clean all
-
- Compile the samples :
- make -f makefiles/makefile-samples-linux
-
- Enjoy :
- ./samples_cpp
-*/
-
-/**
- @PageName compile_libtcod_codelite
- @PageFather compile_libtcod
- @PageTitle Using CodeLite
- @PageDesc TODO
-*/
-
-/**
- @PageName compile_libtcod_haiku
- @PageFather compile_libtcod
- @PageTitle On Haiku
- @PageDesc TODO
-*/
-
-/**
- @PageName start_project
- @PageCategory Howtos
- @PageTitle How to start a project
- @PageDesc This page contains howtos about how to create a project from scratch
-*/
-
-/**
- @PageName start_mingw
- @PageFather start_project
- @PageTitle On Windows with Mingw
- @PageDesc TODO
-*/
-
-/**
- @PageName start_linux
- @PageFather start_project
- @PageTitle On Linux
- @PageDesc TODO
-*/
-
-/**
- @PageName start_codelite
- @PageFather start_project
- @PageTitle Using CodeLite
- @PageDesc TODO
-*/
diff --git a/tcod_sys/libtcod/include/image.h b/tcod_sys/libtcod/include/image.h
deleted file mode 100644
index 593ae30b4..000000000
--- a/tcod_sys/libtcod/include/image.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _TCOD_IMAGE_H
-#define _TCOD_IMAGE_H
-
-#include "color.h"
-
-#ifdef TCOD_IMAGE_SUPPORT
-
-#include "console_types.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-typedef void *TCOD_image_t;
-
-TCODLIB_API TCOD_image_t TCOD_image_new(int width, int height);
-#ifdef TCOD_CONSOLE_SUPPORT
-TCODLIB_API TCOD_image_t TCOD_image_from_console(TCOD_console_t console);
-TCODLIB_API void TCOD_image_refresh_console(TCOD_image_t image, TCOD_console_t console);
-#endif
-TCODLIB_API TCOD_image_t TCOD_image_load(const char *filename);
-TCODLIB_API void TCOD_image_clear(TCOD_image_t image, TCOD_color_t color);
-TCODLIB_API void TCOD_image_invert(TCOD_image_t image);
-TCODLIB_API void TCOD_image_hflip(TCOD_image_t image);
-TCODLIB_API void TCOD_image_rotate90(TCOD_image_t image, int numRotations);
-TCODLIB_API void TCOD_image_vflip(TCOD_image_t image);
-TCODLIB_API void TCOD_image_scale(TCOD_image_t image, int neww, int newh);
-TCODLIB_API void TCOD_image_save(TCOD_image_t image, const char *filename);
-TCODLIB_API void TCOD_image_get_size(TCOD_image_t image, int *w,int *h);
-TCODLIB_API TCOD_color_t TCOD_image_get_pixel(TCOD_image_t image,int x, int y);
-TCODLIB_API int TCOD_image_get_alpha(TCOD_image_t image,int x, int y);
-TCODLIB_API TCOD_color_t TCOD_image_get_mipmap_pixel(TCOD_image_t image,float x0,float y0, float x1, float y1);
-TCODLIB_API void TCOD_image_put_pixel(TCOD_image_t image,int x, int y,TCOD_color_t col);
-#ifdef TCOD_CONSOLE_SUPPORT
-TCODLIB_API void TCOD_image_blit(TCOD_image_t image, TCOD_console_t console, float x, float y,
- TCOD_bkgnd_flag_t bkgnd_flag, float scalex, float scaley, float angle);
-TCODLIB_API void TCOD_image_blit_rect(TCOD_image_t image, TCOD_console_t console, int x, int y, int w, int h,
- TCOD_bkgnd_flag_t bkgnd_flag);
-TCODLIB_API void TCOD_image_blit_2x(TCOD_image_t image, TCOD_console_t dest, int dx, int dy, int sx, int sy, int w, int h);
-#endif
-TCODLIB_API void TCOD_image_delete(TCOD_image_t image);
-TCODLIB_API void TCOD_image_set_key_color(TCOD_image_t image, TCOD_color_t key_color);
-TCODLIB_API bool TCOD_image_is_pixel_transparent(TCOD_image_t image, int x, int y);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* TCOD_IMAGE_SUPPORT */
-
-#endif /* _TCOD_IMAGE_H */
diff --git a/tcod_sys/libtcod/include/lex.hpp b/tcod_sys/libtcod/include/lex.hpp
deleted file mode 100644
index bdcbec53e..000000000
--- a/tcod_sys/libtcod/include/lex.hpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-/*
- * This is a libtcod internal module.
- * Use at your own risks...
- */
-#ifndef _TCOD_LEX_HPP
-#define _TCOD_LEX_HPP
-
-#include "lex.h"
-
-class TCODLIB_API TCODLex {
-public :
- TCODLex();
- TCODLex( const char **symbols, const char **keywords, const char *simpleComment="//",
- const char *commentStart="/*", const char *commentStop="*/", const char *javadocCommentStart="/**",
- const char *stringDelim="\"", int flags=TCOD_LEX_FLAG_NESTING_COMMENT);
- ~TCODLex();
-
- void setDataBuffer(char *dat);
- bool setDataFile(const char *filename);
-
- int parse(void);
- int parseUntil(int tokenType);
- int parseUntil(const char *tokenValue);
-
- bool expect(int tokenType);
- bool expect(int tokenType,const char *tokenValue);
-
- void savepoint(TCODLex *savept);
- void restore(TCODLex *savept);
- char *getLastJavadoc();
-
- int getFileLine() { return ((TCOD_lex_t *)data)->file_line; }
- int getTokenType() { return ((TCOD_lex_t *)data)->token_type; }
- int getTokenIntVal() { return ((TCOD_lex_t *)data)->token_int_val; }
- int getTokenIdx() { return ((TCOD_lex_t *)data)->token_idx; }
- float getTokenFloatVal() { return ((TCOD_lex_t *)data)->token_float_val; }
- char *getToken() { return ((TCOD_lex_t *)data)->tok; }
- char getStringLastDelimiter() { return ((TCOD_lex_t *)data)->lastStringDelim; }
- char *getPos() { return ((TCOD_lex_t *)data)->pos; }
- char *getBuf() { return ((TCOD_lex_t *)data)->buf; }
- char *getFilename() { return ((TCOD_lex_t *)data)->filename; }
- char *getLastJavadocComment() { return ((TCOD_lex_t *)data)->last_javadoc_comment; }
- static const char *getTokenName(int tokenType) { return TCOD_lex_get_token_name(tokenType); }
-protected :
- void *data;
-};
-
-#endif
diff --git a/tcod_sys/libtcod/include/libtcod.h b/tcod_sys/libtcod/include/libtcod.h
deleted file mode 100644
index f203a7aaa..000000000
--- a/tcod_sys/libtcod/include/libtcod.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _LIBTCOD_H
-#define _LIBTCOD_H
-
-#include "libtcod_portability.h"
-#include "libtcod_utility.h"
-#include "libtcod_version.h"
-
-#include "bresenham.h"
-#include "bsp.h"
-#include "color.h"
-#include "console.h"
-#include "fov.h"
-#include "heightmap.h"
-#include "image.h"
-#include "lex.h"
-#include "list.h"
-#include "mersenne.h"
-#include "mouse.h"
-#include "namegen.h"
-#include "noise.h"
-#include "path.h"
-#include "parser.h"
-#include "sys.h"
-#include "tree.h"
-#include "txtfield.h"
-#include "zip.h"
-
-#endif
diff --git a/tcod_sys/libtcod/include/libtcod.hpp b/tcod_sys/libtcod/include/libtcod.hpp
deleted file mode 100644
index 2655a6601..000000000
--- a/tcod_sys/libtcod/include/libtcod.hpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _LIBTCOD_HPP
-#define _LIBTCOD_HPP
-
-#include "libtcod.h"
-
-#include "bresenham.hpp"
-#include "bsp.hpp"
-#include "color.hpp"
-#include "console.hpp"
-#include "fov.hpp"
-#include "heightmap.hpp"
-#include "image.hpp"
-#include "lex.hpp"
-#include "list.hpp"
-#include "mersenne.hpp"
-#include "mouse.hpp"
-#include "namegen.hpp"
-#include "noise.hpp"
-#include "parser.hpp"
-#include "path.hpp"
-#include "sys.hpp"
-#include "tree.hpp"
-#include "txtfield.hpp"
-#include "zip.hpp"
-
-#endif
diff --git a/tcod_sys/libtcod/include/libtcod_portability.h b/tcod_sys/libtcod/include/libtcod_portability.h
deleted file mode 100644
index bace23f8a..000000000
--- a/tcod_sys/libtcod/include/libtcod_portability.h
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote
-* products derived from this software without specific prior written
-* permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#ifndef LIBTCOD_PORTABILITY_H
-#define LIBTCOD_PORTABILITY_H
-/* uncomment to disable unicode support */
-/*#define NO_UNICODE */
-
-/* uncomment to disable opengl support */
-/*#define NO_OPENGL */
-
-/* os identification
- TCOD_WINDOWS : OS is windows
- TCOD_LINUX : OS is Linux
- TCOD_MACOSX : OS is Mac OS X
- TCOD_HAIKU : OS is Haiku */
-
-/* compiler identification
- TCOD_VISUAL_STUDIO : compiler is Microsoft Visual Studio
- TCOD_MINGW32 : compiler is Mingw32
- TCOD_GCC : compiler is gcc/g++ */
-
-/* word size
- TCOD_64BITS : 64 bits OS
- TCOD_WIN64 : 64 bits Windows
- TCOD_WIN32 : 32 bits Windows
- TCOD_LINUX64 : 64 bits Linux
- TCOD_LINUX32 : 32 bits Linux
- TCOD_FREEBSD64 : 64 bits FreeBSD
- TCOD_FREEBSD32 : 32 bits FreeBSD */
-
-#if defined( _MSC_VER )
-# define TCOD_VISUAL_STUDIO
-# define TCOD_WINDOWS
-# ifdef _WIN64
-# define TCOD_WIN64
-# define TCOD_64BITS
-# else
-# define TCOD_WIN32
-# endif
-#elif defined( __MINGW32__ )
-# define TCOD_WINDOWS
-# define TCOD_MINGW32
-# ifdef _WIN64
-# define TCOD_WIN64
-# define TCOD_64BITS
-# else
-# define TCOD_WIN32
-# endif
-#elif defined( __HAIKU__ )
-# define TCOD_HAIKU
-# define TCOD_GCC
-# if __WORDSIZE == 64
-# define TCOD_64BITS
-# endif
-#elif defined( __linux )
-# define TCOD_LINUX
-# define TCOD_GCC
-# if __WORDSIZE == 64
-# define TCOD_LINUX64
-# define TCOD_64BITS
-# else
-# define TCOD_LINUX32
-# endif
-#elif defined( __FreeBSD__ )
-# define TCOD_FREEBSD
-# define TCOD_GCC
-# if __WORDSIZE == 64
-# define TCOD_FREEBSD64
-# define TCOD_64BITS
-# else
-# define TCOD_FREEBSD32
-# endif
-#elif defined (__APPLE__) && defined (__MACH__)
-# define TCOD_MACOSX
-# define TCOD_GCC
-#endif
-
-/* unicode rendering functions support */
-#ifndef NO_UNICODE
-#include
-#endif
-
-/* DLL export */
-#ifndef TCODLIB_API
-#ifdef TCOD_WINDOWS
-#ifdef LIBTCOD_EXPORTS
-#define TCODLIB_API __declspec(dllexport)
-#else
-#define TCODLIB_API __declspec(dllimport)
-#endif
-#else
-#define TCODLIB_API
-#endif
-#endif
-
-/* For now this encapsulates mouse, keyboard, and consoles themselves. */
-#undef TCOD_CONSOLE_SUPPORT
-#undef TCOD_IMAGE_SUPPORT
-#undef TCOD_OSUTIL_SUPPORT
-
-#ifdef TCOD_SDL2
-#define TCOD_CONSOLE_SUPPORT
-#define TCOD_IMAGE_SUPPORT
-#define TCOD_OSUTIL_SUPPORT
-#else
-#define TCOD_BARE
-#endif
-
-/* int types */
-#include "external/pstdint.h"
-
-/* bool type */
-#ifndef __bool_true_false_are_defined
-#ifndef __cplusplus
-#if defined(_MSC_VER) && _MSC_VER < 1800
-typedef uint8_t bool;
-#define true 1
-#define false 0
-#define __bool_true_false_are_defined 1
-#else
-#include
-#endif
-#endif /* __cplusplus */
-#endif /* __bool_true_false_are_defined */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* ansi C lacks support for those functions */
-TCODLIB_API char *TCOD_strdup(const char *s);
-TCODLIB_API int TCOD_strcasecmp(const char *s1, const char *s2);
-TCODLIB_API int TCOD_strncasecmp(const char *s1, const char *s2, size_t n);
-
-#if defined(TCOD_WINDOWS)
-char *strcasestr (const char *haystack, const char *needle);
-#endif
-#if defined(TCOD_LINUX) || defined(TCOD_HAIKU) || defined(TCOD_FREEBSD) || defined(TCOD_MACOSX)
-#define vsnwprintf vswprintf
-#endif
-#ifdef TCOD_WINDOWS
-#define vsnwprintf _vsnwprintf
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* LIBTCOD_PORTABILITY_H */
diff --git a/tcod_sys/libtcod/include/libtcod_utility.h b/tcod_sys/libtcod/include/libtcod_utility.h
deleted file mode 100644
index 14322e1cd..000000000
--- a/tcod_sys/libtcod/include/libtcod_utility.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote
-* products derived from this software without specific prior written
-* permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#ifndef LIBTCOD_UTILITY_H
-#define LIBTCOD_UTILITY_H
-/******************************************
- utility macros
- ******************************************/
-#define MAX(a,b) (((a)>(b))?(a):(b))
-#define MIN(a,b) (((a)<(b))?(a):(b))
-#define ABS(a) ((a)<0?-(a):(a))
-#define CLAMP(a, b, x) ((x) < (a) ? (a) : ((x) > (b) ? (b) : (x)))
-#define LERP(a, b, x) ( (a) + (x) * ((b) - (a)) )
-
-#endif
\ No newline at end of file
diff --git a/tcod_sys/libtcod/include/libtcod_version.h b/tcod_sys/libtcod/include/libtcod_version.h
deleted file mode 100644
index bae64637a..000000000
--- a/tcod_sys/libtcod/include/libtcod_version.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote
-* products derived from this software without specific prior written
-* permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#ifndef LIBTCOD_VERSION_H
-#define LIBTCOD_VERSION_H
-
-#define TCOD_HEXVERSION 0x010603
-#define TCOD_STRVERSION "1.6.3"
-#define TCOD_TECHVERSION 0x01060300
-
-#define TCOD_STRVERSIONNAME "libtcod "TCOD_STRVERSION
-
-#endif /* LIBTCOD_VERSION_H */
diff --git a/tcod_sys/libtcod/include/list.h b/tcod_sys/libtcod/include/list.h
deleted file mode 100644
index edaac0e51..000000000
--- a/tcod_sys/libtcod/include/list.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _TCOD_LIST_H
-#define _TCOD_LIST_H
-
-#include "libtcod_portability.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void *TCOD_list_t;
-
-TCODLIB_API TCOD_list_t TCOD_list_new(void);
-TCODLIB_API TCOD_list_t TCOD_list_allocate(int nb_elements);
-TCODLIB_API TCOD_list_t TCOD_list_duplicate(TCOD_list_t l);
-TCODLIB_API void TCOD_list_delete(TCOD_list_t l);
-TCODLIB_API void TCOD_list_push(TCOD_list_t l, const void * elt);
-TCODLIB_API void * TCOD_list_pop(TCOD_list_t l);
-TCODLIB_API void * TCOD_list_peek(TCOD_list_t l);
-TCODLIB_API void TCOD_list_add_all(TCOD_list_t l, TCOD_list_t l2);
-TCODLIB_API void * TCOD_list_get(TCOD_list_t l,int idx);
-TCODLIB_API void TCOD_list_set(TCOD_list_t l,const void *elt, int idx);
-TCODLIB_API void ** TCOD_list_begin(TCOD_list_t l);
-TCODLIB_API void ** TCOD_list_end(TCOD_list_t l);
-TCODLIB_API void TCOD_list_reverse(TCOD_list_t l);
-TCODLIB_API void **TCOD_list_remove_iterator(TCOD_list_t l, void **elt);
-TCODLIB_API void TCOD_list_remove(TCOD_list_t l, const void * elt);
-TCODLIB_API void **TCOD_list_remove_iterator_fast(TCOD_list_t l, void **elt);
-TCODLIB_API void TCOD_list_remove_fast(TCOD_list_t l, const void * elt);
-TCODLIB_API bool TCOD_list_contains(TCOD_list_t l,const void * elt);
-TCODLIB_API void TCOD_list_clear(TCOD_list_t l);
-TCODLIB_API void TCOD_list_clear_and_delete(TCOD_list_t l);
-TCODLIB_API int TCOD_list_size(TCOD_list_t l);
-TCODLIB_API void ** TCOD_list_insert_before(TCOD_list_t l,const void *elt,int before);
-TCODLIB_API bool TCOD_list_is_empty(TCOD_list_t l);
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/tcod_sys/libtcod/include/mersenne.h b/tcod_sys/libtcod/include/mersenne.h
deleted file mode 100644
index 198acccc1..000000000
--- a/tcod_sys/libtcod/include/mersenne.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _TCOD_RANDOM_H
-#define _TCOD_RANDOM_H
-
-#include "libtcod_portability.h"
-#include "mersenne_types.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-TCODLIB_API TCOD_random_t TCOD_random_get_instance(void);
-TCODLIB_API TCOD_random_t TCOD_random_new(TCOD_random_algo_t algo);
-TCODLIB_API TCOD_random_t TCOD_random_save(TCOD_random_t mersenne);
-TCODLIB_API void TCOD_random_restore(TCOD_random_t mersenne, TCOD_random_t backup);
-TCODLIB_API TCOD_random_t TCOD_random_new_from_seed(TCOD_random_algo_t algo, uint32_t seed);
-TCODLIB_API void TCOD_random_delete(TCOD_random_t mersenne);
-
-TCODLIB_API void TCOD_random_set_distribution (TCOD_random_t mersenne, TCOD_distribution_t distribution);
-
-TCODLIB_API int TCOD_random_get_int (TCOD_random_t mersenne, int min, int max);
-TCODLIB_API float TCOD_random_get_float (TCOD_random_t mersenne, float min, float max);
-TCODLIB_API double TCOD_random_get_double (TCOD_random_t mersenne, double min, double max);
-
-TCODLIB_API int TCOD_random_get_int_mean (TCOD_random_t mersenne, int min, int max, int mean);
-TCODLIB_API float TCOD_random_get_float_mean (TCOD_random_t mersenne, float min, float max, float mean);
-TCODLIB_API double TCOD_random_get_double_mean (TCOD_random_t mersenne, double min, double max, double mean);
-
-TCODLIB_API TCOD_dice_t TCOD_random_dice_new (const char * s);
-TCODLIB_API int TCOD_random_dice_roll (TCOD_random_t mersenne, TCOD_dice_t dice);
-TCODLIB_API int TCOD_random_dice_roll_s (TCOD_random_t mersenne, const char * s);
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/tcod_sys/libtcod/include/mersenne_types.h b/tcod_sys/libtcod/include/mersenne_types.h
deleted file mode 100644
index 99b21e27d..000000000
--- a/tcod_sys/libtcod/include/mersenne_types.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _TCOD_RANDOM_TYPES_H
-#define _TCOD_RANDOM_TYPES_H
-
-typedef void *TCOD_random_t;
-
-/* dice roll */
-typedef struct {
- int nb_rolls;
- int nb_faces;
- float multiplier;
- float addsub;
-} TCOD_dice_t;
-
-/* PRNG algorithms */
-typedef enum {
- TCOD_RNG_MT,
- TCOD_RNG_CMWC
-} TCOD_random_algo_t;
-
-typedef enum {
- TCOD_DISTRIBUTION_LINEAR,
- TCOD_DISTRIBUTION_GAUSSIAN,
- TCOD_DISTRIBUTION_GAUSSIAN_RANGE,
- TCOD_DISTRIBUTION_GAUSSIAN_INVERSE,
- TCOD_DISTRIBUTION_GAUSSIAN_RANGE_INVERSE
-} TCOD_distribution_t;
-#endif /* _TCOD_RANDOM_TYPES_H */
diff --git a/tcod_sys/libtcod/include/mouse.h b/tcod_sys/libtcod/include/mouse.h
deleted file mode 100644
index b0f1bdd34..000000000
--- a/tcod_sys/libtcod/include/mouse.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _TCOD_MOUSE_H
-#define _TCOD_MOUSE_H
-
-#include "libtcod_portability.h"
-
-#ifdef TCOD_CONSOLE_SUPPORT
-
-#include "mouse_types.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-TCODLIB_API void TCOD_mouse_show_cursor(bool visible);
-TCODLIB_API TCOD_mouse_t TCOD_mouse_get_status(void);
-TCODLIB_API bool TCOD_mouse_is_cursor_visible(void);
-TCODLIB_API void TCOD_mouse_move(int x, int y);
-TCODLIB_API void TCOD_mouse_includes_touch(bool enable);
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* TCOD_CONSOLE_SUPPORT */
-
-#endif /* _TCOD_MOUSE_H */
diff --git a/tcod_sys/libtcod/include/mouse_types.h b/tcod_sys/libtcod/include/mouse_types.h
deleted file mode 100644
index e8dd52b5f..000000000
--- a/tcod_sys/libtcod/include/mouse_types.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _TCOD_MOUSE_TYPES_H
-#define _TCOD_MOUSE_TYPES_H
-
-#include "libtcod_portability.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-/* mouse data */
-typedef struct {
- int x,y; /* absolute position */
- int dx,dy; /* movement since last update in pixels */
- int cx,cy; /* cell coordinates in the root console */
- int dcx,dcy; /* movement since last update in console cells */
- bool lbutton ; /* left button status */
- bool rbutton ; /* right button status */
- bool mbutton ; /* middle button status */
- bool lbutton_pressed ; /* left button pressed event */
- bool rbutton_pressed ; /* right button pressed event */
- bool mbutton_pressed ; /* middle button pressed event */
- bool wheel_up ; /* wheel up event */
- bool wheel_down ; /* wheel down event */
-} TCOD_mouse_t;
-#ifdef __cplusplus
-}
-#endif
-#endif /* _TCOD_MOUSE_TYPES_H */
diff --git a/tcod_sys/libtcod/include/namegen.h b/tcod_sys/libtcod/include/namegen.h
deleted file mode 100644
index 8f5b4813e..000000000
--- a/tcod_sys/libtcod/include/namegen.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-/*
-* Mingos' NameGen
-* This file was written by Dominik "Mingos" Marczuk.
-*/
-
-#ifndef _TCOD_NAMEGEN_H
-#define _TCOD_NAMEGEN_H
-
-#include "libtcod_portability.h"
-#include "list.h"
-#include "mersenne.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-/* the generator typedef */
-typedef void * TCOD_namegen_t;
-
-/* parse a file with syllable sets */
-TCODLIB_API void TCOD_namegen_parse (const char * filename, TCOD_random_t random);
-/* generate a name */
-TCODLIB_API char * TCOD_namegen_generate (char * name, bool allocate);
-/* generate a name using a custom generation rule */
-TCODLIB_API char * TCOD_namegen_generate_custom (char * name, char * rule, bool allocate);
-/* retrieve the list of all available syllable set names */
-TCODLIB_API TCOD_list_t TCOD_namegen_get_sets (void);
-/* delete a generator */
-TCODLIB_API void TCOD_namegen_destroy (void);
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/tcod_sys/libtcod/include/noise.h b/tcod_sys/libtcod/include/noise.h
deleted file mode 100644
index 3ba90d63f..000000000
--- a/tcod_sys/libtcod/include/noise.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _TCOD_PERLIN_H
-#define _TCOD_PERLIN_H
-
-#include "libtcod_portability.h"
-#include "mersenne_types.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-typedef void *TCOD_noise_t;
-
-typedef enum {
- TCOD_NOISE_PERLIN = 1,
- TCOD_NOISE_SIMPLEX = 2,
- TCOD_NOISE_WAVELET = 4,
- TCOD_NOISE_DEFAULT = 0
-} TCOD_noise_type_t;
-
-#include "noise_defaults.h"
-
-/* create a new noise object */
-TCODLIB_API TCOD_noise_t TCOD_noise_new(int dimensions, float hurst, float lacunarity, TCOD_random_t random);
-
-/* simplified API */
-TCODLIB_API void TCOD_noise_set_type (TCOD_noise_t noise, TCOD_noise_type_t type);
-TCODLIB_API float TCOD_noise_get_ex (TCOD_noise_t noise, float *f, TCOD_noise_type_t type);
-TCODLIB_API float TCOD_noise_get_fbm_ex (TCOD_noise_t noise, float *f, float octaves, TCOD_noise_type_t type);
-TCODLIB_API float TCOD_noise_get_turbulence_ex (TCOD_noise_t noise, float *f, float octaves, TCOD_noise_type_t type);
-TCODLIB_API float TCOD_noise_get (TCOD_noise_t noise, float *f);
-TCODLIB_API float TCOD_noise_get_fbm (TCOD_noise_t noise, float *f, float octaves);
-TCODLIB_API float TCOD_noise_get_turbulence (TCOD_noise_t noise, float *f, float octaves);
-/* delete the noise object */
-TCODLIB_API void TCOD_noise_delete(TCOD_noise_t noise);
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/tcod_sys/libtcod/include/noise_defaults.h b/tcod_sys/libtcod/include/noise_defaults.h
deleted file mode 100644
index 41a02fe78..000000000
--- a/tcod_sys/libtcod/include/noise_defaults.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef _TCOD_NOISE_DEFAULTS
-#define _TCOD_NOISE_DEFAULTS
-
-#define TCOD_NOISE_MAX_OCTAVES 128
-#define TCOD_NOISE_MAX_DIMENSIONS 4
-#define TCOD_NOISE_DEFAULT_HURST 0.5f
-#define TCOD_NOISE_DEFAULT_LACUNARITY 2.0f
-
-#endif /* _TCOD_NOISE_DEFAULTS */
diff --git a/tcod_sys/libtcod/include/tree.h b/tcod_sys/libtcod/include/tree.h
deleted file mode 100644
index bf44f1b54..000000000
--- a/tcod_sys/libtcod/include/tree.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _TCOD_TREE_H
-#define _TCOD_TREE_H
-
-#include "libtcod_portability.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-typedef struct _TCOD_tree_t {
- struct _TCOD_tree_t *next;
- struct _TCOD_tree_t *father;
- struct _TCOD_tree_t *sons;
-} TCOD_tree_t;
-
-TCODLIB_API TCOD_tree_t *TCOD_tree_new(void);
-TCODLIB_API void TCOD_tree_add_son(TCOD_tree_t *node, TCOD_tree_t *son);
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/tcod_sys/libtcod/include/tree.hpp b/tcod_sys/libtcod/include/tree.hpp
deleted file mode 100644
index 5e7f6b22f..000000000
--- a/tcod_sys/libtcod/include/tree.hpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _TCOD_TREE_HPP
-#define _TCOD_TREE_HPP
-
-#include "tree.h"
-
-class TCODLIB_API TCODTree {
-public :
- TCODTree *next;
- TCODTree *father;
- TCODTree *sons;
-
- TCODTree() : next(NULL),father(NULL),sons(NULL){}
- void addSon(TCODTree *data) {
- data->father=this;
- TCODTree *lastson = sons;
- while ( lastson && lastson->next ) lastson=lastson->next;
- if ( lastson ) {
- lastson->next=data;
- } else {
- sons=data;
- }
- }
-
-};
-
-#endif
diff --git a/tcod_sys/libtcod/include/txtfield.h b/tcod_sys/libtcod/include/txtfield.h
deleted file mode 100644
index 9d2399c3d..000000000
--- a/tcod_sys/libtcod/include/txtfield.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-
-#ifndef _TCOD_TEXT_H_
-#define _TCOD_TEXT_H_
-
-#include "libtcod_portability.h"
-
-#ifdef TCOD_CONSOLE_SUPPORT
-
-#include "color.h"
-#include "console_types.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-typedef void * TCOD_text_t;
-
-TCODLIB_API TCOD_text_t TCOD_text_init(int x, int y, int w, int h, int max_chars);
-TCODLIB_API TCOD_text_t TCOD_text_init2(int w, int h, int max_chars);
-TCODLIB_API void TCOD_text_set_pos(TCOD_text_t txt, int x, int y);
-TCODLIB_API void TCOD_text_set_properties(TCOD_text_t txt, int cursor_char, int blink_interval, const char * prompt, int tab_size);
-TCODLIB_API void TCOD_text_set_colors(TCOD_text_t txt, TCOD_color_t fore, TCOD_color_t back, float back_transparency);
-TCODLIB_API bool TCOD_text_update(TCOD_text_t txt, TCOD_key_t key);
-TCODLIB_API void TCOD_text_render(TCOD_text_t txt, TCOD_console_t con);
-TCODLIB_API const char * TCOD_text_get(TCOD_text_t txt);
-TCODLIB_API void TCOD_text_reset(TCOD_text_t txt);
-TCODLIB_API void TCOD_text_delete(TCOD_text_t txt);
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* TCOD_CONSOLE_SUPPORT */
-
-#endif /* _TCOD_TEXT_H_ */
diff --git a/tcod_sys/libtcod/include/txtfield.hpp b/tcod_sys/libtcod/include/txtfield.hpp
deleted file mode 100644
index 2a96883cf..000000000
--- a/tcod_sys/libtcod/include/txtfield.hpp
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _TCOD_TEXT_HPP_
-#define _TCOD_TEXT_HPP_
-
-#include "color.hpp"
-#include "console.hpp"
-#include "txtfield.h"
-
-#ifdef TCOD_CONSOLE_SUPPORT
-
-class TCODLIB_API TCODText {
-public :
- TCODText(int x, int y, int w, int h, int max_chars);
- TCODText(int w, int h, int max_chars);
- ~TCODText();
- void setProperties(int cursor_char, int blink_interval, const char * prompt, int tab_size);
- void setColors(TCODColor fore, TCODColor back, float back_transparency);
- void setPos(int x, int y);
- bool update(TCOD_key_t key);
- void render(TCODConsole * con);
- const char *getText();
- void reset();
-protected :
- TCOD_text_t data;
-};
-
-#endif /* TCOD_CONSOLE_SUPPORT */
-
-#endif
diff --git a/tcod_sys/libtcod/src/README.txt b/tcod_sys/libtcod/src/README.txt
index d7a6a6b7a..8b0d61471 100644
--- a/tcod_sys/libtcod/src/README.txt
+++ b/tcod_sys/libtcod/src/README.txt
@@ -1,7 +1,7 @@
This is the Doryen library source code.
-libtcod.h and libtcod.hpp are the main headers, included respectively by
-the C and C++ programs that use libtcod.
+libtcod.h and libtcod.hpp are the main headers, included respectively by
+the C and C++ programs that use libtcod.
Each "toolkit" is in a separate file set. For each toolkit, you may have :
* include/.h : the C header
@@ -25,19 +25,19 @@ noise : various noise generators.
parser : config file parser.
path : path finding module.
sys : system specific functions.
-txtfield : work-in-progress text input utility
+txtfield : work-in-progress text input utility
zip : compression module
-Note that some of the sys toolkits rely on system dependent functions.
+Note that some of the sys toolkits rely on system dependent functions.
They have currently a single working implementation relying on SDL : sys_sdl_c.c
As it is heavily system dependent, the mouse C implementation is in sys_sdl_c.c.
-As of 1.4, the image load/save functions are isolated in sys_sdl_XXX.c,
+As of 1.4, the image load/save functions are isolated in sys_sdl_XXX.c,
XXX being the image type (currently bmp and png).
As of 1.5.1, sys_opengl_c.c contains OpenGL and GLSL renderers. Those two
renderers are still dependent on SDL.
-libtcod_int.h contains everything that is exported by the toolkits
-(implemented in a toolkit and used in another one) but should not be seen
+libtcod_int.h contains everything that is exported by the toolkits
+(implemented in a toolkit and used in another one) but should not be seen
by the user of the library.
These are the private (or undocumented) modules :
diff --git a/tcod_sys/libtcod/src/bresenham.cpp b/tcod_sys/libtcod/src/bresenham.cpp
deleted file mode 100644
index 0b168a4cb..000000000
--- a/tcod_sys/libtcod/src/bresenham.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#include
-
-// ********** bresenham line drawing **********
-void TCODLine::init(int xFrom, int yFrom, int xTo, int yTo) {
- TCOD_line_init(xFrom,yFrom,xTo,yTo);
-}
-
-bool TCODLine::step(int *xCur, int *yCur) {
- return TCOD_line_step(xCur,yCur) != 0;
-}
-
-static TCODLineListener *listener=NULL;
-
-// C to C++ bridge
-extern "C" bool internalListener(int x,int y) {
- return listener->putPoint(x,y) ? 1 : 0;
-}
-
-bool TCODLine::line(int xFrom, int yFrom, int xTo, int yTo, TCODLineListener *plistener) {
- listener=plistener;
- return TCOD_line(xFrom,yFrom,xTo,yTo,internalListener) != 0;
-}
-
-
diff --git a/tcod_sys/libtcod/src/bresenham_c.c b/tcod_sys/libtcod/src/bresenham_c.c
deleted file mode 100644
index 611920922..000000000
--- a/tcod_sys/libtcod/src/bresenham_c.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#include
-
-static TCOD_bresenham_data_t bresenham_data;
-
-/* ********** bresenham line drawing ********** */
-void TCOD_line_init_mt(int xFrom, int yFrom, int xTo, int yTo, TCOD_bresenham_data_t *data) {
- data->origx=xFrom;
- data->origy=yFrom;
- data->destx=xTo;
- data->desty=yTo;
- data->deltax=xTo - xFrom;
- data->deltay=yTo - yFrom;
- if ( data->deltax > 0 ) {
- data->stepx=1;
- } else if ( data->deltax < 0 ){
- data->stepx=-1;
- } else data->stepx=0;
- if ( data->deltay > 0 ) {
- data->stepy=1;
- } else if ( data->deltay < 0 ){
- data->stepy=-1;
- } else data->stepy = 0;
- if ( data->stepx*data->deltax > data->stepy*data->deltay ) {
- data->e = data->stepx*data->deltax;
- data->deltax *= 2;
- data->deltay *= 2;
- } else {
- data->e = data->stepy*data->deltay;
- data->deltax *= 2;
- data->deltay *= 2;
- }
-}
-
-bool TCOD_line_step_mt(int *xCur, int *yCur, TCOD_bresenham_data_t *data) {
- if ( data->stepx*data->deltax > data->stepy*data->deltay ) {
- if ( data->origx == data->destx ) return true;
- data->origx+=data->stepx;
- data->e -= data->stepy*data->deltay;
- if ( data->e < 0) {
- data->origy+=data->stepy;
- data->e+=data->stepx*data->deltax;
- }
- } else {
- if ( data->origy == data->desty ) return true;
- data->origy+=data->stepy;
- data->e -= data->stepx*data->deltax;
- if ( data->e < 0) {
- data->origx+=data->stepx;
- data->e+=data->stepy*data->deltay;
- }
- }
- *xCur=data->origx;
- *yCur=data->origy;
- return false;
-}
-
-bool TCOD_line_mt(int xo, int yo, int xd, int yd, TCOD_line_listener_t listener, TCOD_bresenham_data_t *data) {
- TCOD_line_init_mt(xo,yo,xd,yd,data);
- do {
- if (! listener(xo,yo)) return false;
- } while (! TCOD_line_step_mt(&xo,&yo,data));
- return true;
-}
-
-void TCOD_line_init(int xFrom, int yFrom, int xTo, int yTo) {
- TCOD_line_init_mt(xFrom,yFrom,xTo,yTo,&bresenham_data);
-}
-
-bool TCOD_line_step(int *xCur, int *yCur) {
- return TCOD_line_step_mt(xCur,yCur,&bresenham_data);
-}
-
-bool TCOD_line(int xo, int yo, int xd, int yd, TCOD_line_listener_t listener) {
- return TCOD_line_mt(xo,yo,xd,yd,listener,&bresenham_data);
-}
-
diff --git a/tcod_sys/libtcod/src/console_c.c b/tcod_sys/libtcod/src/console_c.c
deleted file mode 100644
index c868deb97..000000000
--- a/tcod_sys/libtcod/src/console_c.c
+++ /dev/null
@@ -1,2294 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#include
-
-#include
-#include
-#include
-#include
-#include
-#ifndef NO_UNICODE
-#include
-#include
-#endif
-
-#include
-#include
-#include
-#include
-#include
-
-#ifdef TCOD_CONSOLE_SUPPORT
-
-#if defined( TCOD_VISUAL_STUDIO )
-static const char *version_string ="libtcod "TCOD_STRVERSION;
-#else
-static const char *version_string __attribute__((unused)) ="libtcod "TCOD_STRVERSION;
-#endif
-
-TCOD_internal_context_t TCOD_ctx={
- /* number of characters in the bitmap font */
- 16,16,
- /* font type and layout */
- false,false,false,
- /* character size in font */
- 8,8,
- "terminal.png","",
- NULL,NULL,NULL,0,false,0,0,0,0,0,0,
-#ifdef TCOD_SDL2
- /* default renderer to use */
- TCOD_RENDERER_GLSL,
- NULL,
-#endif
- /* fading data */
- {0,0,0},255,
- /*key state*/
- {0},
- /* window closed ? */
- false,
- /* mouse focus ? */
- false,
- /* application active ? */
- true,
-};
-
-static TCOD_color_t color_control_fore[TCOD_COLCTRL_NUMBER];
-static TCOD_color_t color_control_back[TCOD_COLCTRL_NUMBER];
-
-void TCOD_console_set_color_control(TCOD_colctrl_t con, TCOD_color_t fore, TCOD_color_t back) {
- TCOD_IFNOT(con >= TCOD_COLCTRL_1 && con <= TCOD_COLCTRL_NUMBER ) return;
- color_control_fore[con-1]=fore;
- color_control_back[con-1]=back;
-}
-
-TCOD_console_t TCOD_console_new(int w, int h) {
- TCOD_IFNOT(w > 0 && h > 0 ) {
- return NULL;
- } else {
- TCOD_console_data_t *con=(TCOD_console_data_t *)calloc(sizeof(TCOD_console_data_t),1);
- con->w=w;
- con->h=h;
- TCOD_console_init(con,NULL,false);
- if(TCOD_ctx.root) {
- con->alignment=TCOD_ctx.root->alignment;
- con->bkgnd_flag=TCOD_ctx.root->bkgnd_flag;
- }
- return (TCOD_console_t)con;
- }
-}
-
-TCOD_key_t TCOD_console_check_for_keypress(int flags) {
- return TCOD_sys_check_for_keypress(flags);
-}
-
-TCOD_key_t TCOD_console_wait_for_keypress(bool flush) {
- return TCOD_sys_wait_for_keypress(flush);
-}
-
-bool TCOD_console_is_window_closed(void) {
- return TCOD_ctx.is_window_closed;
-}
-
-bool TCOD_console_has_mouse_focus(void) {
- return TCOD_ctx.app_has_mouse_focus;
-}
-
-#ifdef TCOD_SDL2
-bool TCOD_console_is_active(void) {
- return TCOD_ctx.app_is_active;
-}
-#endif
-
-void TCOD_console_set_window_title(const char *title) {
- TCOD_sys_set_window_title(title);
-}
-
-void TCOD_console_set_fullscreen(bool fullscreen) {
- TCOD_IFNOT(TCOD_ctx.root != NULL) return;
- TCOD_sys_set_fullscreen(fullscreen);
- TCOD_ctx.fullscreen=fullscreen;
-}
-
-bool TCOD_console_is_fullscreen(void) {
- return TCOD_ctx.fullscreen;
-}
-
-void TCOD_console_set_background_flag(TCOD_console_t con,TCOD_bkgnd_flag_t flag) {
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT ( dat != NULL ) return;
- dat->bkgnd_flag=flag;
-}
-
-TCOD_bkgnd_flag_t TCOD_console_get_background_flag(TCOD_console_t con) {
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT ( dat != NULL ) return TCOD_BKGND_NONE;
- return dat->bkgnd_flag;
-}
-
-void TCOD_console_set_alignment(TCOD_console_t con,TCOD_alignment_t alignment) {
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT ( dat != NULL ) return;
- dat->alignment=alignment;
-}
-
-TCOD_alignment_t TCOD_console_get_alignment(TCOD_console_t con) {
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT ( dat != NULL ) return TCOD_LEFT;
- return dat->alignment;
-}
-
-static void TCOD_console_data_free(TCOD_console_data_t *dat) {
- if (dat->fg_colors) TCOD_image_delete(dat->fg_colors);
- if (dat->bg_colors) TCOD_image_delete(dat->bg_colors);
- free(dat->ch_array);
-}
-
-void TCOD_console_delete(TCOD_console_t con) {
- TCOD_console_data_t *dat=(TCOD_console_data_t *)(con);
- if (! dat ) {
- dat=TCOD_ctx.root;
- TCOD_sys_uninit();
- TCOD_ctx.root=NULL;
- }
- TCOD_console_data_free(dat);
- free(dat);
-}
-
-void TCOD_console_blit(TCOD_console_t srcCon, int xSrc, int ySrc, int wSrc, int hSrc,
- TCOD_console_t dstCon, int xDst, int yDst, float foreground_alpha, float background_alpha) {
- TCOD_console_data_t *src = srcCon ? (TCOD_console_data_t *)srcCon : TCOD_ctx.root;
- TCOD_console_data_t *dst = dstCon ? (TCOD_console_data_t *)dstCon : TCOD_ctx.root;
- TCOD_color_t *srcFgColors, *srcBgColors, *dstFgColors, *dstBgColors;
- bool srcHasKeyColor;
- TCOD_color_t srcKeyColor;
- int cx, cy;
- if (wSrc == 0) wSrc = src->w;
- if (hSrc == 0) hSrc = src->h;
- TCOD_IFNOT(wSrc > 0 && hSrc > 0) return;
- TCOD_IFNOT(xDst + wSrc >= 0 && yDst + hSrc >= 0 && xDst < dst->w && yDst < dst->h) return;
- TCOD_image_get_key_data(src->bg_colors, &srcHasKeyColor, &srcKeyColor);
- srcFgColors = TCOD_image_get_colors(src->fg_colors);
- srcBgColors = TCOD_image_get_colors(src->bg_colors);
- dstFgColors = TCOD_image_get_colors(dst->fg_colors);
- dstBgColors = TCOD_image_get_colors(dst->bg_colors);
- for (cx = xSrc; cx < xSrc + wSrc; cx++) {
- for (cy = ySrc; cy < ySrc + hSrc; cy++) {
- /* check if we're outside the dest console */
- int dx = cx - xSrc + xDst;
- int dy = cy - ySrc + yDst;
- int dst_idx = dy * dst->w + dx;
- int src_idx = cy * src->w + cx;
- int srcChar, dstChar;
- TCOD_color_t srcFgColor, srcBgColor, dstFgColor, dstBgColor;
- if ((unsigned)cx >= (unsigned)src->w || (unsigned)cy >= (unsigned)src->h) continue;
- if ((unsigned)dx >= (unsigned)dst->w || (unsigned)dy >= (unsigned)dst->h) continue;
- srcChar = src->ch_array[src_idx];
- srcFgColor = srcFgColors[src_idx];
- srcBgColor = srcBgColors[src_idx];
- /* check if source pixel is transparent */
- if (srcHasKeyColor &&
- srcBgColor.r == srcKeyColor.r && srcBgColor.g == srcKeyColor.g && srcBgColor.b == srcKeyColor.b)
- continue;
-
- if (foreground_alpha == 1.0f && background_alpha == 1.0f) {
- dstChar = srcChar;
- dstFgColor = srcFgColor;
- dstBgColor = srcBgColor;
- }
- else {
- dstChar = dst->ch_array[dst_idx];
- dstFgColor = dstFgColors[dst_idx];
- dstBgColor = dstBgColors[dst_idx];
-
- dstBgColor = TCOD_color_lerp(dstBgColor, srcBgColor, background_alpha);
- if (srcChar == ' ') {
- dstFgColor = TCOD_color_lerp(dstFgColor, srcBgColor, background_alpha);
- }
- else if (dstChar == ' ') {
- dstChar = srcChar;
- dstFgColor = TCOD_color_lerp(dstBgColor, srcFgColor, foreground_alpha);
- }
- else if (dstChar == srcChar) {
- dstFgColor = TCOD_color_lerp(dstFgColor, srcFgColor, foreground_alpha);
- }
- else {
- if (foreground_alpha < 0.5f) {
- dstFgColor = TCOD_color_lerp(dstFgColor, dstBgColor,
- foreground_alpha * 2);
- }
- else {
- dstChar = srcChar;
- dstFgColor = TCOD_color_lerp(dstBgColor, srcFgColor,
- (foreground_alpha - 0.5f) * 2);
- }
- }
- }
- dstFgColors[dst_idx] = dstFgColor;
- dstBgColors[dst_idx] = dstBgColor;
- dst->ch_array[dst_idx] = dstChar;
- }
- }
- TCOD_image_invalidate_mipmaps(dst->fg_colors);
- TCOD_image_invalidate_mipmaps(dst->bg_colors);
-}
-
-void TCOD_console_flush(void) {
- TCOD_IFNOT(TCOD_ctx.root != NULL) return;
- TCOD_sys_flush(true);
-}
-
-void TCOD_console_set_fade(uint8_t val, TCOD_color_t fadecol) {
- TCOD_ctx.fade=val;
- TCOD_ctx.fading_color=fadecol;
-}
-
-uint8_t TCOD_console_get_fade(void) {
- return TCOD_ctx.fade;
-}
-
-TCOD_color_t TCOD_console_get_fading_color(void) {
- return TCOD_ctx.fading_color;
-}
-
-void TCOD_console_put_char(TCOD_console_t con, int x, int y, int c, TCOD_bkgnd_flag_t flag) {
- int offset;
- TCOD_console_data_t *dat = con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL && (unsigned)(x) < (unsigned)dat->w && (unsigned)(y) < (unsigned)dat->h) return;
- TCOD_IFNOT(c >= 0 && c < TCOD_ctx.max_font_chars) return;
- offset = y * dat->w + x;
- dat->ch_array[offset] = c;
- TCOD_image_put_pixel(dat->fg_colors, x, y, dat->fore);
- TCOD_console_set_char_background(con, x, y, dat->back, (TCOD_bkgnd_flag_t)flag);
-}
-
-void TCOD_console_put_char_ex(TCOD_console_t con, int x, int y, int c, TCOD_color_t fore, TCOD_color_t back) {
- int offset;
- TCOD_console_data_t *dat = con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL && (unsigned)(x) < (unsigned)dat->w && (unsigned)(y) < (unsigned)dat->h) return;
- TCOD_IFNOT(c >= 0 && c < TCOD_ctx.max_font_chars) return;
- offset = y * dat->w + x;
- dat->ch_array[offset] = c;
- TCOD_image_put_pixel(dat->fg_colors, x, y, fore);
- TCOD_image_put_pixel(dat->bg_colors, x, y, back);
-}
-
-void TCOD_console_set_dirty(int dx, int dy, int dw, int dh) {
- TCOD_sys_set_dirty(dx, dy, dw, dh);
-}
-
-void TCOD_console_clear(TCOD_console_t con) {
- int i;
- TCOD_console_data_t *dat = con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL) return;
- for (i = 0; i < dat->w * dat->h; i++) {
- dat->ch_array[i] = ' ';
- }
- TCOD_image_clear(dat->fg_colors, dat->fore);
- TCOD_image_clear(dat->bg_colors, dat->back);
- /* clear the sdl renderer cache */
- TCOD_sys_set_dirty(0, 0, dat->w, dat->h);
-}
-
-TCOD_color_t TCOD_console_get_char_background(TCOD_console_t con, int x, int y) {
- TCOD_console_data_t *dat = con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL
- && (unsigned)(x) < (unsigned)dat->w && (unsigned)(y) < (unsigned)dat->h)
- return TCOD_black;
- return TCOD_image_get_pixel(dat->bg_colors, x, y);
-}
-
-void TCOD_console_set_char_foreground(TCOD_console_t con, int x, int y, TCOD_color_t col) {
- TCOD_console_data_t *dat = con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- if ((unsigned)(x) >= (unsigned)dat->w || (unsigned)(y) >= (unsigned)dat->h) return;
- TCOD_IFNOT(dat != NULL
- && (unsigned)(x) < (unsigned)dat->w && (unsigned)(y) < (unsigned)dat->h)
- return;
- TCOD_image_put_pixel(dat->fg_colors, x, y, col);
-}
-
-TCOD_color_t TCOD_console_get_char_foreground(TCOD_console_t con, int x, int y) {
- TCOD_console_data_t *dat = con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL
- && (unsigned)(x) < (unsigned)dat->w && (unsigned)(y) < (unsigned)dat->h)
- return TCOD_white;
- return TCOD_image_get_pixel(dat->fg_colors, x, y);
-}
-
-int TCOD_console_get_char(TCOD_console_t con, int x, int y) {
- TCOD_console_data_t *dat = con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL
- && (unsigned)(x) < (unsigned)dat->w && (unsigned)(y) < (unsigned)dat->h)
- return 0;
- return dat->ch_array[y * dat->w + x];
-}
-
-void TCOD_console_set_char_background(TCOD_console_t con, int x, int y, TCOD_color_t col, TCOD_bkgnd_flag_t flag) {
- TCOD_color_t *back;
- int newr, newg, newb;
- int alpha;
- TCOD_console_data_t *dat = con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL
- && (unsigned)(x) < (unsigned)dat->w && (unsigned)(y) < (unsigned)dat->h)
- return;
- back = &(TCOD_image_get_colors(dat->bg_colors)[y*dat->w + x]);
- if (flag == TCOD_BKGND_DEFAULT) flag = dat->bkgnd_flag;
- switch (flag & 0xff) {
- case TCOD_BKGND_SET: *back = col; break;
- case TCOD_BKGND_MULTIPLY: *back = TCOD_color_multiply(*back, col); break;
- case TCOD_BKGND_LIGHTEN:
- back->r = MAX(back->r, col.r);
- back->g = MAX(back->g, col.g);
- back->b = MAX(back->b, col.b);
- break;
- case TCOD_BKGND_DARKEN:
- back->r = MIN(back->r, col.r);
- back->g = MIN(back->g, col.g);
- back->b = MIN(back->b, col.b);
- break;
- case TCOD_BKGND_SCREEN:
- /* newbk = white - (white - oldbk) * (white - curbk) */
- back->r = (uint8_t)(255 - (int)(255 - back->r)*(255 - col.r) / 255);
- back->g = (uint8_t)(255 - (int)(255 - back->g)*(255 - col.g) / 255);
- back->b = (uint8_t)(255 - (int)(255 - back->b)*(255 - col.b) / 255);
- break;
- case TCOD_BKGND_COLOR_DODGE:
- /* newbk = curbk / (white - oldbk) */
- if (back->r != 255) newr = (int)(255 * col.r) / (255 - back->r);
- else newr = 255;
- if (back->g != 255) newg = (int)(255 * col.g) / (255 - back->g);
- else newg = 255;
- if (back->b != 255) newb = (int)(255 * col.b) / (255 - back->b);
- else newb = 255;
- back->r = (uint8_t)CLAMP(0, 255, newr);
- back->g = (uint8_t)CLAMP(0, 255, newg);
- back->b = (uint8_t)CLAMP(0, 255, newb);
- break;
- case TCOD_BKGND_COLOR_BURN:
- /* newbk = white - (white - oldbk) / curbk */
- if (col.r > 0) newr = 255 - (int)(255 * (255 - back->r)) / col.r;
- else newr = 0;
- if (col.g > 0) newg = 255 - (int)(255 * (255 - back->g)) / col.g;
- else newg = 0;
- if (col.b > 0) newb = 255 - (int)(255 * (255 - back->b)) / col.b;
- else newb = 0;
- back->r = (uint8_t)CLAMP(0, 255, newr);
- back->g = (uint8_t)CLAMP(0, 255, newg);
- back->b = (uint8_t)CLAMP(0, 255, newb);
- break;
- case TCOD_BKGND_ADD:
- /* newbk = oldbk + curbk */
- newr = (int)(back->r) + col.r;
- newg = (int)(back->g) + col.g;
- newb = (int)(back->b) + col.b;
- back->r = (uint8_t)CLAMP(0, 255, newr);
- back->g = (uint8_t)CLAMP(0, 255, newg);
- back->b = (uint8_t)CLAMP(0, 255, newb);
- break;
- case TCOD_BKGND_ADDA:
- alpha = (flag >> 8);
- /* newbk = oldbk + alpha * curbk */
- newr = (int)(back->r) + alpha * col.r / 255;
- newg = (int)(back->g) + alpha * col.g / 255;
- newb = (int)(back->b) + alpha * col.b / 255;
- back->r = (uint8_t)CLAMP(0, 255, newr);
- back->g = (uint8_t)CLAMP(0, 255, newg);
- back->b = (uint8_t)CLAMP(0, 255, newb);
- break;
- case TCOD_BKGND_BURN:
- /* newbk = oldbk + curbk - white */
- newr = (int)(back->r) + col.r - 255;
- newg = (int)(back->g) + col.g - 255;
- newb = (int)(back->b) + col.b - 255;
- back->r = (uint8_t)CLAMP(0, 255, newr);
- back->g = (uint8_t)CLAMP(0, 255, newg);
- back->b = (uint8_t)CLAMP(0, 255, newb);
- break;
- case TCOD_BKGND_OVERLAY:
- /* newbk = curbk.x <= 0.5 ? 2*curbk*oldbk : white - 2*(white-curbk)*(white-oldbk) */
- newr = col.r <= 128 ? 2 * (int)(col.r) * back->r / 255 : 255 - 2 * (int)(255 - col.r)*(255 - back->r) / 255;
- newg = col.g <= 128 ? 2 * (int)(col.g) * back->g / 255 : 255 - 2 * (int)(255 - col.g)*(255 - back->g) / 255;
- newb = col.b <= 128 ? 2 * (int)(col.b) * back->b / 255 : 255 - 2 * (int)(255 - col.b)*(255 - back->b) / 255;
- back->r = (uint8_t)CLAMP(0, 255, newr);
- back->g = (uint8_t)CLAMP(0, 255, newg);
- back->b = (uint8_t)CLAMP(0, 255, newb);
- break;
- case TCOD_BKGND_ALPH:
- /* newbk = (1.0f-alpha)*oldbk + alpha*(curbk-oldbk) */
- alpha = (flag >> 8);
- *back = TCOD_color_lerp(*back, col, (float)(alpha / 255.0f));
- break;
- default: break;
- }
-}
-
-void TCOD_console_set_char(TCOD_console_t con, int x, int y, int c) {
- TCOD_console_data_t *dat = con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- if ((unsigned)(x) >= (unsigned)dat->w || (unsigned)(y) >= (unsigned)dat->h) return;
- dat->ch_array[y * dat->w + x] = c;
-}
-
-static void TCOD_console_clamp(int cx, int cy, int cw, int ch, int *x, int *y, int *w, int *h) {
- if (*x + *w > cw) *w = cw - *x;
- if (*y + *h > ch) *h = ch - *y;
- if (*x < cx) {
- *w -= cx - *x;
- *x = cx;
- }
- if (*y < cy) {
- *h -= cy - *y;
- *y = cy;
- }
-}
-
-void TCOD_console_rect(TCOD_console_t con, int x, int y, int rw, int rh, bool clear, TCOD_bkgnd_flag_t flag) {
- int cx, cy;
- TCOD_console_data_t *dat = con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL) return;
- TCOD_ASSERT((unsigned)(x) < (unsigned)dat->w && (unsigned)(y) < (unsigned)dat->h);
- TCOD_ASSERT(x + rw <= dat->w && y + rh <= dat->h);
-
- TCOD_console_clamp(0, 0, dat->w, dat->h, &x, &y, &rw, &rh);
- TCOD_IFNOT(rw > 0 && rh > 0) return;
- for (cx = x; cx < x + rw; cx++) {
- for (cy = y; cyback, flag);
- if (clear) {
- dat->ch_array[cx + cy*dat->w] = ' ';
- }
- }
- }
-}
-
-void TCOD_console_hline(TCOD_console_t con,int x,int y, int l, TCOD_bkgnd_flag_t flag) {
- int i;
- for (i=x; i< x+l; i++) TCOD_console_put_char(con,i,y,TCOD_CHAR_HLINE,flag);
-}
-
-void TCOD_console_vline(TCOD_console_t con,int x,int y, int l, TCOD_bkgnd_flag_t flag) {
- int i;
- for (i=y; i< y+l; i++) TCOD_console_put_char(con,x,i,TCOD_CHAR_VLINE,flag);
-}
-
-char *TCOD_console_vsprint(const char *fmt, va_list ap) {
- #define NB_BUFFERS 10
- #define INITIAL_SIZE 512
- /* several static buffers in case the function is used more than once in a single function call */
- static char *msg[NB_BUFFERS]={NULL};
- static int buflen[NB_BUFFERS]={0};
- static int curbuf=0;
- char *ret;
- bool ok=false;
- if (!msg[0]) {
- int i;
- for (i=0; i < NB_BUFFERS; i++) {
- buflen[i]=INITIAL_SIZE;
- msg[i]=(char *)calloc(sizeof(char),INITIAL_SIZE);
- }
- }
- do {
- /* warning ! depending on the compiler, vsnprintf return -1 or
- the expected string length if the buffer is not big enough */
- int len = vsnprintf(msg[curbuf],buflen[curbuf],fmt,ap);
- ok=true;
- if (len < 0 || len >= buflen[curbuf]) {
- /* buffer too small. */
- if ( len > 0 ) {
- while ( buflen[curbuf] < len+1 ) buflen[curbuf]*=2;
- } else {
- buflen[curbuf]*=2;
- }
- free( msg[curbuf] );
- msg[curbuf]=(char *)calloc(sizeof(char),buflen[curbuf]);
- ok=false;
- }
- } while (! ok);
- ret=msg[curbuf];
- curbuf = (curbuf+1)%NB_BUFFERS;
- return ret;
-}
-
-void TCOD_console_print_frame(TCOD_console_t con,int x,int y,int w,int h, bool empty, TCOD_bkgnd_flag_t flag, const char *fmt, ...) {
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_console_put_char(con,x,y,TCOD_CHAR_NW,flag);
- TCOD_console_put_char(con,x+w-1,y,TCOD_CHAR_NE,flag);
- TCOD_console_put_char(con,x,y+h-1,TCOD_CHAR_SW,flag);
- TCOD_console_put_char(con,x+w-1,y+h-1,TCOD_CHAR_SE,flag);
- TCOD_console_hline(con,x+1,y,w-2,flag);
- TCOD_console_hline(con,x+1,y+h-1,w-2,flag);
- if ( h > 2 ) {
- TCOD_console_vline(con,x,y+1,h-2,flag);
- TCOD_console_vline(con,x+w-1,y+1,h-2,flag);
- if ( empty ) {
- TCOD_console_rect(con,x+1,y+1,w-2,h-2,true,flag);
- }
- }
- if (fmt) {
- va_list ap;
- int xs;
- TCOD_color_t tmp;
- char *title;
- va_start(ap,fmt);
- title = TCOD_console_vsprint(fmt,ap);
- va_end(ap);
- title[w-3]=0; /* truncate if needed */
- xs = x + (w-(int)strlen(title)-2)/2;
- tmp=dat->back; /* swap colors */
- dat->back=dat->fore;
- dat->fore=tmp;
- TCOD_console_print_ex(con,xs,y,TCOD_BKGND_SET,TCOD_LEFT," %s ",title);
- tmp=dat->back; /* swap colors */
- dat->back=dat->fore;
- dat->fore=tmp;
- }
-}
-
-void TCOD_console_print(TCOD_console_t con,int x, int y, const char *fmt, ...) {
- va_list ap;
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT ( dat != NULL ) return;
- va_start(ap,fmt);
- TCOD_console_print_internal(con,x,y,0,0,dat->bkgnd_flag,
- dat->alignment,TCOD_console_vsprint(fmt,ap), false, false);
- va_end(ap);
-}
-
-void TCOD_console_print_ex(TCOD_console_t con,int x, int y,
- TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, ...) {
- va_list ap;
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT ( dat != NULL ) return;
- va_start(ap,fmt);
- TCOD_console_print_internal(con,x,y,0,0,flag,alignment,
- TCOD_console_vsprint(fmt,ap), false, false);
- va_end(ap);
-}
-
-int TCOD_console_print_rect(TCOD_console_t con,int x, int y, int w, int h, const char *fmt, ...) {
- int ret;
- va_list ap;
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT ( dat != NULL ) return 0;
- va_start(ap,fmt);
- ret = TCOD_console_print_internal(con,x,y,w,h,dat->bkgnd_flag,dat->alignment,
- TCOD_console_vsprint(fmt,ap), true, false);
- va_end(ap);
- return ret;
-}
-
-int TCOD_console_print_rect_ex(TCOD_console_t con,int x, int y, int w, int h,
- TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment,const char *fmt, ...) {
- int ret;
- va_list ap;
- va_start(ap,fmt);
- ret = TCOD_console_print_internal(con,x,y,w,h,flag,alignment,TCOD_console_vsprint(fmt,ap), true, false);
- va_end(ap);
- return ret;
-}
-
-int TCOD_console_get_height_rect(TCOD_console_t con,int x, int y, int w, int h, const char *fmt, ...) {
- int ret;
- va_list ap;
- va_start(ap,fmt);
- ret = TCOD_console_print_internal(con,x,y,w,h,TCOD_BKGND_NONE,TCOD_LEFT,TCOD_console_vsprint(fmt,ap), true, true);
- va_end(ap);
- return ret;
-}
-
-/* non public methods */
-int TCOD_console_stringLength(const unsigned char *s) {
- int l=0;
- while (*s) {
- if ( *s == (int)TCOD_COLCTRL_FORE_RGB || *s == (int)TCOD_COLCTRL_BACK_RGB ) s+=3;
- else if ( (unsigned)(*s) > (unsigned)TCOD_COLCTRL_STOP ) l++;
- s++;
- }
- return l;
-}
-
-unsigned char * TCOD_console_forward(unsigned char *s,int l) {
- while ( *s && l > 0 ) {
- if ( *s == (int)TCOD_COLCTRL_FORE_RGB || *s == (int)TCOD_COLCTRL_BACK_RGB ) s+=3;
- else if ( *s > (int)TCOD_COLCTRL_STOP ) l--;
- s++;
- }
- return s;
-}
-
-unsigned char *TCOD_console_strchr(unsigned char *s, unsigned char c) {
- while ( *s && *s != c ) {
- if ( *s == (int)TCOD_COLCTRL_FORE_RGB || *s == (int)TCOD_COLCTRL_BACK_RGB ) s+=3;
- s++;
- }
- return (*s ? s : NULL);
-}
-
-int TCOD_console_print_internal(TCOD_console_t con,int x,int y, int rw, int rh, TCOD_bkgnd_flag_t flag,
- TCOD_alignment_t align, char *msg, bool can_split, bool count_only) {
- unsigned char *c=(unsigned char *)msg;
- int cx=0,cy=y;
- int minx,maxx,miny,maxy;
- TCOD_color_t oldFore;
- TCOD_color_t oldBack;
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT ( dat != NULL
- && (unsigned)(x) < (unsigned)dat->w && (unsigned)(y) < (unsigned)dat->h )
- return 0;
- TCOD_IFNOT(msg != NULL) return 0;
- if ( rh == 0 ) rh = dat->h-y;
- if ( rw == 0 ) switch(align) {
- case TCOD_LEFT : rw = dat->w-x; break;
- case TCOD_RIGHT : rw=x+1; break;
- case TCOD_CENTER : default : rw=dat->w; break;
- }
- oldFore=dat->fore;
- oldBack=dat->back;
- miny=y;
- maxy=dat->h-1;
- if (rh > 0) maxy=MIN(maxy,y+rh-1);
- switch (align) {
- case TCOD_LEFT : minx=MAX(0,x); maxx=MIN(dat->w-1,x+rw-1); break;
- case TCOD_RIGHT : minx=MAX(0,x-rw+1); maxx=MIN(dat->w-1,x); break;
- case TCOD_CENTER : default : minx=MAX(0,x-rw/2); maxx=MIN(dat->w-1,x+rw/2); break;
- }
-
- do {
- /* get \n delimited sub-message */
- unsigned char *end=TCOD_console_strchr(c,'\n');
- char bak=0;
- int cl;
- unsigned char *split=NULL;
- if ( end ) *end=0;
- cl= TCOD_console_stringLength(c);
- /* find starting x */
- switch (align) {
- case TCOD_LEFT : cx=x; break;
- case TCOD_RIGHT : cx=x-cl+1; break;
- case TCOD_CENTER : cx= x-cl/2;break;
- }
- /* check if the string is completely out of the minx,miny,maxx,maxy frame */
- if ( cy >= miny && cy <= maxy && cx <= maxx && cx+cl -1 >= minx ) {
- if ( can_split && cy <= maxy ) {
- /* if partially out of screen, try to split the sub-message */
- if ( cx < minx ) split = TCOD_console_forward(c, align == TCOD_CENTER ? cl-2*(minx-cx) : cl-(minx-cx));
- else if ( align == TCOD_CENTER ) {
- if ( cx + cl/2 > maxx+1 ) split = TCOD_console_forward(c, maxx+1 - cx);
- } else {
- if ( cx + cl > maxx+1 ) split = TCOD_console_forward(c, maxx+1 - cx);
- }
- }
- if ( split ) {
- unsigned char *oldsplit=split;
- while ( ! isspace(*split) && split > c ) split --;
- if (end) *end='\n';
- if (!isspace(*split) ) {
- split=oldsplit;
- }
- end=split;
- bak=*split;
- *split=0;
- cl=TCOD_console_stringLength(c);
- switch (align) {
- case TCOD_LEFT : cx=x; break;
- case TCOD_RIGHT : cx=x-cl+1; break;
- case TCOD_CENTER : cx= x-cl/2;break;
- }
- }
- if ( cx < minx ) {
- /* truncate left part */
- c += minx-cx;
- cl -= minx-cx;
- cx=minx;
- }
- if ( cx + cl > maxx+1 ) {
- /* truncate right part */
- split = TCOD_console_forward(c, maxx+1 - cx);
- *split=0;
- }
- /* render the sub-message */
- if ( cy >= 0 && cy < dat->h )
- while (*c) {
- if ( *c >= TCOD_COLCTRL_1 && *c <= TCOD_COLCTRL_NUMBER ) {
- dat->fore=color_control_fore[(int)(*c)-1];
- dat->back=color_control_back[(int)(*c)-1];
- } else if ( *c == TCOD_COLCTRL_FORE_RGB ) {
- c++;
- dat->fore.r=*c++;
- dat->fore.g=*c++;
- dat->fore.b=*c;
- } else if ( *c == TCOD_COLCTRL_BACK_RGB ) {
- c++;
- dat->back.r=*c++;
- dat->back.g=*c++;
- dat->back.b=*c;
- } else if ( *c == TCOD_COLCTRL_STOP ) {
- dat->fore=oldFore;
- dat->back=oldBack;
- } else {
- if (! count_only) TCOD_console_put_char(con,cx,cy,(int)(*c),flag);
- cx++;
- }
- c++;
- }
- }
- if ( end ) {
- /* next line */
- if ( split && ! isspace(bak) ) {
- *end=bak;
- c=end;
- } else {
- c=end+1;
- }
- cy++;
- } else c=NULL;
- } while ( c && cy < dat->h && (rh == 0 || cy < y+rh) );
- return cy-y+1;
-}
-
-#ifndef NO_UNICODE
-
-wchar_t *TCOD_console_strchr_utf(wchar_t *s, char c) {
- while ( *s && *s != c ) {
- if ( *s == (int)TCOD_COLCTRL_FORE_RGB || *s == (int)TCOD_COLCTRL_BACK_RGB ) s+=3;
- s++;
- }
- return (*s ? s : NULL);
-}
-
-void TCOD_console_map_string_to_font_utf(const wchar_t *s, int fontCharX, int fontCharY) {
- TCOD_IFNOT(s != NULL) return;
- while (*s) {
- TCOD_sys_map_ascii_to_font(*s, fontCharX, fontCharY);
- fontCharX++;
- if ( fontCharX == TCOD_ctx.fontNbCharHoriz ) {
- fontCharX=0;
- fontCharY++;
- }
- s++;
- }
-}
-
-wchar_t *TCOD_console_vsprint_utf(const wchar_t *fmt, va_list ap) {
- #define NB_BUFFERS 10
- #define INITIAL_SIZE 512
- /* several static buffers in case the function is used more than once in a single function call */
- static wchar_t *msg[NB_BUFFERS]={NULL};
- static int buflen[NB_BUFFERS]={0};
- static int curbuf=0;
- wchar_t *ret;
- bool ok=false;
- if (!msg[0]) {
- int i;
- for (i=0; i < NB_BUFFERS; i++) {
- buflen[i]=INITIAL_SIZE;
- msg[i]=(wchar_t *)calloc(sizeof(wchar_t),INITIAL_SIZE);
- }
- }
- do {
- /* warning ! depending on the compiler, vsnprintf return -1 or
- the expected string length if the buffer is not big enough */
- int len = vsnwprintf(msg[curbuf],buflen[curbuf],fmt,ap);
- ok=true;
- if (len < 0 || len >= buflen[curbuf]) {
- /* buffer too small. */
- if ( len > 0 ) {
- while ( buflen[curbuf] < len+1 ) buflen[curbuf]*=2;
- } else {
- buflen[curbuf]*=2;
- }
- free( msg[curbuf] );
- msg[curbuf]=(wchar_t *)calloc(sizeof(wchar_t),buflen[curbuf]);
- ok=false;
- }
- } while (! ok);
- ret=msg[curbuf];
- curbuf = (curbuf+1)%NB_BUFFERS;
- return ret;
-}
-
-
-int TCOD_console_stringLength_utf(const wchar_t *s) {
- int l=0;
- while (*s) {
- if ( *s == (int)TCOD_COLCTRL_FORE_RGB || *s == (int)TCOD_COLCTRL_BACK_RGB ) s+=3;
- else if ( *s > (int)TCOD_COLCTRL_STOP ) l++;
- s++;
- }
- return l;
-}
-
-wchar_t * TCOD_console_forward_utf(wchar_t *s,int l) {
- while ( *s && l > 0 ) {
- if ( *s == (int)TCOD_COLCTRL_FORE_RGB || *s == (int)TCOD_COLCTRL_BACK_RGB ) s+=3;
- else if ( *s > (int)TCOD_COLCTRL_STOP ) l--;
- s++;
- }
- return s;
-}
-
-int TCOD_console_print_internal_utf(TCOD_console_t con,int x,int y, int rw, int rh, TCOD_bkgnd_flag_t flag,
- TCOD_alignment_t align, wchar_t *msg, bool can_split, bool count_only) {
- wchar_t *c=msg;
- int cx=0,cy=y;
- int minx,maxx,miny,maxy;
- TCOD_color_t oldFore;
- TCOD_color_t oldBack;
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT ( dat != NULL
- && (unsigned)(x) < (unsigned)dat->w && (unsigned)(y) < (unsigned)dat->h )
- return 0;
- TCOD_IFNOT(msg != NULL) return 0;
- if ( rh == 0 ) rh = dat->h-y;
- if ( rw == 0 ) switch(align) {
- case TCOD_LEFT : rw = dat->w-x; break;
- case TCOD_RIGHT : rw=x+1; break;
- case TCOD_CENTER : default : rw=dat->w; break;
- }
- oldFore=dat->fore;
- oldBack=dat->back;
- miny=y;
- maxy=dat->h-1;
- if (rh > 0) maxy=MIN(maxy,y+rh-1);
- switch (align) {
- case TCOD_LEFT : minx=MAX(0,x); maxx=MIN(dat->w-1,x+rw-1); break;
- case TCOD_RIGHT : minx=MAX(0,x-rw+1); maxx=MIN(dat->w-1,x); break;
- case TCOD_CENTER : default : minx=MAX(0,x-rw/2); maxx=MIN(dat->w-1,x+rw/2); break;
- }
-
- do {
- /* get \n delimited sub-message */
- wchar_t *end=TCOD_console_strchr_utf(c,'\n');
- wchar_t bak=0;
- int cl;
- wchar_t *split=NULL;
- if ( end ) *end=0;
- cl= TCOD_console_stringLength_utf(c);
- /* find starting x */
- switch (align) {
- case TCOD_LEFT : cx=x; break;
- case TCOD_RIGHT : cx=x-cl+1; break;
- case TCOD_CENTER : cx= x-cl/2;break;
- }
- /* check if the string is completely out of the minx,miny,maxx,maxy frame */
- if ( cy >= miny && cy <= maxy && cx <= maxx && cx+cl -1 >= minx ) {
- if ( can_split && cy < maxy ) {
- /* if partially out of screen, try to split the sub-message */
- if ( cx < minx ) split = TCOD_console_forward_utf(c, align == TCOD_CENTER ? cl-2*(minx-cx) : cl-(minx-cx));
- else if ( align==TCOD_CENTER ) {
- if ( cx + cl/2 > maxx+1 ) split = TCOD_console_forward_utf(c, maxx+1 - cx);
- } else {
- if ( cx + cl > maxx+1 ) split = TCOD_console_forward_utf(c, maxx+1 - cx);
- }
- }
- if ( split ) {
- wchar_t *oldsplit=split;
- while ( ! iswspace(*split) && split > c ) split --;
- if (end) *end='\n';
- if (!iswspace(*split) ) {
- split=oldsplit;
- }
- end=split;
- bak=*split;
- *split=0;
- cl=TCOD_console_stringLength_utf(c);
- switch (align) {
- case TCOD_LEFT : cx=x; break;
- case TCOD_RIGHT : cx=x-cl+1; break;
- case TCOD_CENTER : cx= x-cl/2;break;
- }
- }
- if ( cx < minx ) {
- /* truncate left part */
- c += minx-cx;
- cl -= minx-cx;
- cx=minx;
- }
- if ( cx + cl > maxx+1 ) {
- /* truncate right part */
- split = TCOD_console_forward_utf(c, maxx+1 - cx);
- *split=0;
- }
- /* render the sub-message */
- if ( cy >= 0 && cy < dat->h )
- while (*c) {
- if ( *c >= TCOD_COLCTRL_1 && *c <= TCOD_COLCTRL_NUMBER ) {
- dat->fore=color_control_fore[(int)(*c)-1];
- dat->back=color_control_back[(int)(*c)-1];
- } else if ( *c == TCOD_COLCTRL_FORE_RGB ) {
- c++;
- dat->fore.r=(uint8_t)(*c++);
- dat->fore.g=(uint8_t)(*c++);
- dat->fore.b=(uint8_t)(*c);
- } else if ( *c == TCOD_COLCTRL_BACK_RGB ) {
- c++;
- dat->back.r=(uint8_t)(*c++);
- dat->back.g=(uint8_t)(*c++);
- dat->back.b=(uint8_t)(*c);
- } else if ( *c == TCOD_COLCTRL_STOP ) {
- dat->fore=oldFore;
- dat->back=oldBack;
- } else {
- if (! count_only) TCOD_console_put_char(con,cx,cy,(int)(*c),flag);
- cx++;
- }
- c++;
- }
- }
- if ( end ) {
- /* next line */
- if ( split && ! iswspace(bak) ) {
- *end=bak;
- c=end;
- } else {
- c=end+1;
- }
- cy++;
- } else c=NULL;
- } while ( c && cy < dat->h && (rh == 0 || cy < y+rh) );
- return cy-y+1;
-}
-
-void TCOD_console_print_utf(TCOD_console_t con,int x, int y, const wchar_t *fmt, ...) {
- va_list ap;
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT ( dat != NULL ) return;
- va_start(ap,fmt);
- TCOD_console_print_internal_utf(con,x,y,0,0,dat->bkgnd_flag,dat->alignment,
- TCOD_console_vsprint_utf(fmt,ap), false, false);
- va_end(ap);
-}
-
-void TCOD_console_print_ex_utf(TCOD_console_t con,int x, int y,
- TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...) {
- va_list ap;
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT ( dat != NULL ) return;
- va_start(ap,fmt);
- TCOD_console_print_internal_utf(con,x,y,0,0,flag,alignment,TCOD_console_vsprint_utf(fmt,ap), false, false);
- va_end(ap);
-}
-
-int TCOD_console_print_rect_utf(TCOD_console_t con,int x, int y, int w, int h,
- const wchar_t *fmt, ...) {
- int ret;
- va_list ap;
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT ( dat != NULL ) return 0;
- va_start(ap,fmt);
- ret = TCOD_console_print_internal_utf(con,x,y,w,h,dat->bkgnd_flag,dat->alignment,
- TCOD_console_vsprint_utf(fmt,ap), true, false);
- va_end(ap);
- return ret;
-}
-
-int TCOD_console_print_rect_ex_utf(TCOD_console_t con,int x, int y, int w, int h,
- TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...) {
- int ret;
- va_list ap;
- va_start(ap,fmt);
- ret=TCOD_console_print_internal_utf(con,x,y,w,h,flag,alignment,TCOD_console_vsprint_utf(fmt,ap), true, false);
- va_end(ap);
- return ret;
-}
-
-int TCOD_console_get_height_rect_utf(TCOD_console_t con,int x, int y, int w, int h, const wchar_t *fmt, ...) {
- int ret;
- va_list ap;
- va_start(ap,fmt);
- ret = TCOD_console_print_internal_utf(con,x,y,w,h,TCOD_BKGND_NONE,TCOD_LEFT,TCOD_console_vsprint_utf(fmt,ap), true, true);
- va_end(ap);
- return ret;
-}
-
-#endif
-
-void TCOD_console_init_root(int w, int h, const char*title, bool fullscreen, TCOD_renderer_t renderer) {
- TCOD_IF(w > 0 && h > 0) {
- TCOD_console_data_t *con=(TCOD_console_data_t *)calloc(sizeof(TCOD_console_data_t),1);
- int i;
- con->w=w;
- con->h=h;
- TCOD_ctx.root=con;
-#ifdef TCOD_SDL2
- TCOD_ctx.renderer=renderer;
-#endif
- for (i=0; i < TCOD_COLCTRL_NUMBER; i++) {
- color_control_fore[i]=TCOD_white;
- color_control_back[i]=TCOD_black;
- }
- TCOD_console_init((TCOD_console_t)con,title,fullscreen);
- }
-}
-
-static void TCOD_console_data_alloc(TCOD_console_data_t *dat) {
- dat->ch_array = (int *)calloc(sizeof(int), dat->w*dat->h);
- dat->fg_colors = TCOD_image_new(dat->w, dat->h);
- dat->bg_colors = TCOD_image_new(dat->w, dat->h);
-}
-
-bool TCOD_console_init(TCOD_console_t con,const char *title, bool fullscreen) {
- int i;
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL) return false;
- dat->fore=TCOD_white;
- dat->back=TCOD_black;
-
- TCOD_console_data_alloc(dat);
-
- dat->bkgnd_flag=TCOD_BKGND_NONE;
- dat->alignment=TCOD_LEFT;
- for (i=0; i< dat->w*dat->h; i++) {
- dat->ch_array[i] = ' ';
- }
- if ( title ) {
- if (! TCOD_sys_init(dat, fullscreen) ) return false;
- TCOD_sys_set_window_title(title);
- }
- return true;
-}
-
-void TCOD_console_set_default_foreground(TCOD_console_t con,TCOD_color_t col) {
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL) return;
- dat->fore=col;
-}
-
-void TCOD_console_set_default_background(TCOD_console_t con,TCOD_color_t col) {
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL) return;
- dat->back=col;
-}
-
-TCOD_color_t TCOD_console_get_default_foreground(TCOD_console_t con) {
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL) return TCOD_white;
- return dat->fore;
-}
-
-TCOD_color_t TCOD_console_get_default_background(TCOD_console_t con) {
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL) return TCOD_black;
- return dat->back;
-}
-
-int TCOD_console_get_width(TCOD_console_t con) {
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL) return 0;
- return dat->w;
-}
-
-int TCOD_console_get_height(TCOD_console_t con) {
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL) return 0;
- return dat->h;
-}
-
-TCOD_image_t TCOD_console_get_foreground_color_image(TCOD_console_t con) {
- TCOD_console_data_t *dat = con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL) return NULL;
- return dat->fg_colors;
-}
-
-TCOD_image_t TCOD_console_get_background_color_image(TCOD_console_t con) {
- TCOD_console_data_t *dat = con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL) return NULL;
- return dat->bg_colors;
-}
-
-void TCOD_console_set_custom_font(const char *fontFile, int flags,int nb_char_horiz, int nb_char_vertic) {
- TCOD_sys_set_custom_font(fontFile, nb_char_horiz, nb_char_vertic, flags);
-}
-
-void TCOD_console_map_ascii_code_to_font(int asciiCode, int fontCharX, int fontCharY) {
- /* cannot change mapping before initRoot is called */
- TCOD_IFNOT(TCOD_ctx.root != NULL) return;
- TCOD_sys_map_ascii_to_font(asciiCode, fontCharX, fontCharY);
-}
-
-void TCOD_console_map_ascii_codes_to_font(int asciiCode, int nbCodes, int fontCharX, int fontCharY) {
- int c;
- /* cannot change mapping before initRoot is called */
- TCOD_IFNOT(TCOD_ctx.root != NULL) return;
- TCOD_IFNOT(asciiCode >= 0 && asciiCode+nbCodes <= TCOD_ctx.max_font_chars) return;
- for (c=asciiCode; c < asciiCode+nbCodes; c++ ) {
- TCOD_sys_map_ascii_to_font(c, fontCharX, fontCharY);
- fontCharX++;
- if ( fontCharX == TCOD_ctx.fontNbCharHoriz ) {
- fontCharX=0;
- fontCharY++;
- }
- }
-}
-
-void TCOD_console_map_string_to_font(const char *s, int fontCharX, int fontCharY) {
- TCOD_IFNOT(s != NULL) return;
- /* cannot change mapping before initRoot is called */
- TCOD_IFNOT(TCOD_ctx.root != NULL) return;
- while (*s) {
- TCOD_console_map_ascii_code_to_font(*s, fontCharX, fontCharY);
- fontCharX++;
- if ( fontCharX == TCOD_ctx.fontNbCharHoriz ) {
- fontCharX=0;
- fontCharY++;
- }
- s++;
- }
-}
-
-bool TCOD_console_is_key_pressed(TCOD_keycode_t key) {
- return TCOD_sys_is_key_pressed(key);
-}
-void TCOD_console_set_key_color(TCOD_console_t con,TCOD_color_t col) {
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL) return;
- TCOD_image_set_key_color(dat->bg_colors, col);
-}
-
-void TCOD_console_credits(void) {
- bool end=false;
- int x=TCOD_console_get_width(NULL)/2-6;
- int y=TCOD_console_get_height(NULL)/2;
- int fade=260;
- TCOD_sys_save_fps();
- TCOD_sys_set_fps(25);
- while (!end ) {
- TCOD_key_t k;
- end=TCOD_console_credits_render(x,y,false);
- TCOD_sys_check_for_event(TCOD_EVENT_KEY_PRESS,&k,NULL);
- if ( fade == 260 && k.vk != TCODK_NONE ) {
- fade -= 10;
- }
- TCOD_console_flush();
- if ( fade < 260 ) {
- fade -= 10;
- TCOD_console_set_fade(fade,TCOD_black);
- if ( fade == 0 ) end=true;
- }
- }
- TCOD_console_set_fade(255,TCOD_black);
- TCOD_sys_restore_fps();
-}
-
-static bool init2=false;
-
-void TCOD_console_credits_reset(void) {
- init2=false;
-}
-
-bool TCOD_console_credits_render(int x, int y, bool alpha) {
- static char poweredby[128];
- static float char_heat[128];
- static int char_x[128];
- static int char_y[128];
- static bool init1=false;
- static int len,len1,cw=-1,ch=-1;
- static float xstr;
- static TCOD_color_t colmap[64];
- static TCOD_color_t colmap_light[64];
- static TCOD_noise_t noise;
- static TCOD_color_t colkeys[4] = {
- {255,255,204},
- {255,204,0},
- {255,102,0},
- {102,153,255},
- };
- static TCOD_color_t colkeys_light[4] = {
- {255,255,204},
- {128,128,77},
- {51,51,31},
- {0,0,0},
- };
- static int colpos[4]={
- 0,21,42,63
- };
- static TCOD_image_t img=NULL;
- int i,xc,yc,xi,yi,j;
- static int left,right,top,bottom;
- float sparklex,sparkley,sparklerad,sparklerad2,noisex;
- /* mini particule system */
-#define MAX_PARTICULES 50
- static float pheat[MAX_PARTICULES];
- static float px[MAX_PARTICULES],py[MAX_PARTICULES], pvx[MAX_PARTICULES],pvy[MAX_PARTICULES];
- static int nbpart=0, firstpart=0;
- static float partDelay=0.1f;
- float elapsed=TCOD_sys_get_last_frame_length();
- TCOD_color_t fbackup; /* backup fg color */
-
- if (!init1) {
- /* initialize all static data, colormaps, ... */
- TCOD_color_t col;
- TCOD_color_gen_map(colmap,4,colkeys,colpos);
- TCOD_color_gen_map(colmap_light,4,colkeys_light,colpos);
- sprintf(poweredby,"Powered by\n%s",version_string);
- noise=TCOD_noise_new(1,TCOD_NOISE_DEFAULT_HURST,TCOD_NOISE_DEFAULT_LACUNARITY,NULL);
- len=(int)strlen(poweredby);
- len1=11; /* sizeof "Powered by\n" */
- left=MAX(x-4,0);
- top=MAX(y-4,0);
- col= TCOD_console_get_default_background(NULL);
- TCOD_console_set_default_background(NULL,TCOD_black);
- TCOD_console_set_default_background(NULL,col);
- init1=true;
- }
- if (!init2) {
- /* reset the credits vars ... */
- int curx,cury;
- xstr=-4.0f;
- curx=x;
- cury=y;
- for (i=0; i < len ;i++) {
- char_heat[i]=-1;
- char_x[i]=curx;
- char_y[i]=cury;
- curx++;
- if ( poweredby[i] == '\n' ) {
- curx=x;
- cury++;
- }
- }
- nbpart=firstpart=0;
- init2=true;
- }
- if (TCOD_console_get_width(NULL) != cw || TCOD_console_get_height(NULL)!=ch) {
- /* console size has changed */
- int width,height;
- cw=TCOD_console_get_width(NULL);
- ch=TCOD_console_get_height(NULL);
- right=MIN(x+len,cw-1);
- bottom=MIN(y+6,ch-1);
- width=right - left + 1;
- height=bottom - top + 1;
- if ( img ) TCOD_image_delete(img);
- img = TCOD_image_new(width*2,height*2);
- }
- fbackup=TCOD_console_get_default_foreground(NULL);
- if ( xstr < (float)len1 ) {
- sparklex=x+xstr;
- sparkley=(float)y;
- } else {
- sparklex=x-len1+xstr;
- sparkley=(float)y+1;
- }
- noisex=xstr*6;
- sparklerad=3.0f+2*TCOD_noise_get(noise,&noisex);
- if ( xstr >= len-1 ) sparklerad -= (xstr-len+1)*4.0f;
- else if ( xstr < 0.0f ) sparklerad += xstr*4.0f;
- else if ( poweredby[ (int)(xstr+0.5f) ] == ' ' || poweredby[ (int)(xstr+0.5f) ] == '\n' ) sparklerad/=2;
- sparklerad2=sparklerad*sparklerad*4;
-
- /* draw the light */
- for (xc=left*2,xi=0; xc < (right+1)*2; xc++,xi++) {
- for (yc=top*2,yi=0; yc < (bottom+1)*2; yc++,yi++) {
- float dist=((xc-2*sparklex)*(xc-2*sparklex)+(yc-2*sparkley)*(yc-2*sparkley));
- TCOD_color_t pixcol;
- if ( sparklerad >= 0.0f && dist < sparklerad2 ) {
- int colidx=63-(int)(63*(sparklerad2-dist)/sparklerad2) + TCOD_random_get_int(NULL,-10,10);
- colidx=CLAMP(0,63,colidx);
- pixcol=colmap_light[colidx];
- } else {
- pixcol=TCOD_black;
- }
- if ( alpha ) {
- /* console cells have following flag values :
- 1 2
- 4 8
- flag indicates which subcell uses foreground color */
- static int asciiToFlag[] = {
- 1, /* TCOD_CHAR_SUBP_NW */
- 2, /* TCOD_CHAR_SUBP_NE */
- 3, /* TCOD_CHAR_SUBP_N */
- 8, /* TCOD_CHAR_SUBP_SE */
- 9, /* TCOD_CHAR_SUBP_DIAG */
- 10, /* TCOD_CHAR_SUBP_E */
- 4, /* TCOD_CHAR_SUBP_SW */
- };
- int conc= TCOD_console_get_char(NULL,xc/2,yc/2);
- TCOD_color_t bk=TCOD_console_get_char_background(NULL,xc/2,yc/2);
- if ( conc >= TCOD_CHAR_SUBP_NW && conc <= TCOD_CHAR_SUBP_SW ) {
- /* merge two subcell chars...
- get the flag for the existing cell on root console */
- int bkflag=asciiToFlag[conc - TCOD_CHAR_SUBP_NW ];
- int xflag = (xc & 1);
- int yflag = (yc & 1);
- /* get the flag for the current subcell */
- int credflag = (1+3*yflag) * (xflag+1);
- if ( (credflag & bkflag) != 0 ) {
- /* the color for this subcell on root console
- is foreground, not background */
- bk = TCOD_console_get_char_foreground(NULL,xc/2,yc/2);
- }
- }
- pixcol.r = MIN(255,(int)(bk.r)+pixcol.r);
- pixcol.g = MIN(255,(int)(bk.g)+pixcol.g);
- pixcol.b = MIN(255,(int)(bk.b)+pixcol.b);
- }
- TCOD_image_put_pixel(img,xi,yi,pixcol);
- }
- }
-
- /* draw and update the particules */
- j=nbpart;i=firstpart;
- while (j > 0) {
- int colidx=(int)(64*(1.0f-pheat[i]));
- TCOD_color_t col;
- colidx=MIN(63,colidx);
- col=colmap[colidx];
- if ( (int)py[i]< (bottom-top+1)*2 ) {
- int ipx = (int)px[i];
- int ipy = (int)py[i];
- float fpx = px[i]-ipx;
- float fpy = py[i]-ipy;
- TCOD_color_t col2=TCOD_image_get_pixel(img,ipx,ipy);
- col2=TCOD_color_lerp(col,col2,0.5f*(fpx+fpy));
- TCOD_image_put_pixel(img,ipx,ipy,col2);
- col2=TCOD_image_get_pixel(img,ipx+1,ipy);
- col2=TCOD_color_lerp(col2,col,fpx);
- TCOD_image_put_pixel(img,ipx+1,ipy,col2);
- col2=TCOD_image_get_pixel(img,ipx,ipy+1);
- col2=TCOD_color_lerp(col2,col,fpy);
- TCOD_image_put_pixel(img,ipx,ipy+1,col2);
- } else pvy[i]=-pvy[i] * 0.5f;
- pvx[i] *= (1.0f-elapsed);
- pvy[i] += (1.0f-pheat[i])*elapsed*300.0f;
- px[i] += pvx[i]*elapsed;
- py[i] += pvy[i]*elapsed;
- pheat[i] -= elapsed*0.3f;
- if ( pheat[i] < 0.0f ) {
- firstpart = (firstpart+1)%MAX_PARTICULES;
- nbpart--;
- }
- i = (i+1)%MAX_PARTICULES;
- j--;
- }
- partDelay -= elapsed;
- if ( partDelay < 0.0f && nbpart < MAX_PARTICULES && sparklerad > 2.0f ) {
- /* fire a new particule */
- int lastpart = firstpart;
- int nb=nbpart;
- while (nb > 0 ) {
- lastpart = ( lastpart + 1 )%MAX_PARTICULES;
- nb--;
- }
- nbpart++;
- px[lastpart] = 2*(sparklex-left);
- py[lastpart] = 2*(sparkley-top)+2;
- pvx[lastpart] = TCOD_random_get_float(NULL,-5.0f,5.0f);
- pvy[lastpart] = TCOD_random_get_float(NULL,-0.5f, -15.0f);
- pheat[lastpart] = 1.0f;
- partDelay += 0.1f;
- }
- TCOD_image_blit_2x(img,NULL,left,top,0,0,-1,-1);
- /* draw the text */
- for (i=0; i < len ;i++) {
- if ( char_heat[i] >= 0.0f && poweredby[i]!='\n') {
- int colidx=(int)(64*char_heat[i]);
- TCOD_color_t col;
- colidx=MIN(63,colidx);
- col=colmap[colidx];
- if ( xstr >= len ) {
- float coef=(xstr-len)/len;
- if ( alpha ) {
- TCOD_color_t fore=TCOD_console_get_char_background(NULL,char_x[i],char_y[i]);
- int r=(int)(coef*fore.r + (1.0f-coef)*col.r);
- int g=(int)(coef*fore.g + (1.0f-coef)*col.g);
- int b=(int)(coef*fore.b + (1.0f-coef)*col.b);
- col.r = CLAMP(0,255,r);
- col.g = CLAMP(0,255,g);
- col.b = CLAMP(0,255,b);
- TCOD_console_set_char_foreground(NULL,char_x[i],char_y[i],col);
- } else {
- col=TCOD_color_lerp(col,TCOD_black,coef);
- }
- }
- TCOD_console_set_char(NULL,char_x[i],char_y[i],poweredby[i]);
- TCOD_console_set_char_foreground(NULL,char_x[i],char_y[i],col);
- }
- }
- /* update letters heat */
- xstr += elapsed * 4;
- for (i=0; i < (int)(xstr+0.5f); i++) {
- char_heat[i]=(xstr-i)/(len/2);
- }
- /* restore fg color */
- TCOD_console_set_default_foreground(NULL,fbackup);
- if ( xstr <= 2*len ) return false;
- init2=false;
- return true;
-}
-
-static void TCOD_console_read_asc(TCOD_console_t con,FILE *f,int width, int height, float version) {
- int x,y;
- TCOD_console_data_t *dat=con ? (TCOD_console_data_t *)con : TCOD_ctx.root;
- TCOD_IFNOT(dat != NULL) return;
- while(fgetc(f) != '#');
- for(x = 0; x < width; x++) {
- for(y = 0; y < height; y++) {
- TCOD_color_t fore,back;
- int c = fgetc(f);
- fore.r = fgetc(f);
- fore.g = fgetc(f);
- fore.b = fgetc(f);
- back.r = fgetc(f);
- back.g = fgetc(f);
- back.b = fgetc(f);
- /* skip solid/walkable info */
- if ( version >= 0.3f ) {
- fgetc(f);
- fgetc(f);
- }
- TCOD_console_put_char_ex(con,x,y,c,fore,back);
- }
- }
- fclose(f);
-}
-
-static void TCOD_console_read_apf(TCOD_console_t con,FILE *f,int width, int height, float version) {
-}
-
-static int string_ends_with(const char *str, const char *suffix) {
- size_t str_len = strlen(str);
- size_t suffix_len = strlen(suffix);
- return
- (str_len >= suffix_len) &&
- (0 == strcmp(str + (str_len-suffix_len), suffix));
-}
-
-TCOD_console_t TCOD_console_from_file(const char *filename) {
- float version;
- int width,height;
- TCOD_console_t con;
- FILE *f;
- TCOD_IFNOT( filename != NULL ) {
- return NULL;
- }
- if (string_ends_with(filename, ".xp")) {
- return TCOD_console_from_xp(filename);
- }
- f=fopen(filename,"rb");
- TCOD_IFNOT( f!=NULL ) {
- return NULL;
- }
- if (fscanf(f, "ASCII-Paint v%g", &version) != 1 ) {
- fclose(f);
- return NULL;
- }
- if (fscanf(f, "%i %i", &width, &height) != 2 ) {
- fclose(f);
- return NULL;
- }
- TCOD_IFNOT ( width > 0 && height > 0) {
- fclose(f);
- return NULL;
- }
- con=TCOD_console_new(width,height);
- if (string_ends_with(filename, ".asc")) {
- TCOD_console_read_asc(con,f,width,height,version);
- } else {
- TCOD_console_read_apf(con,f,width,height,version);
- }
- return con;
-}
-
-bool TCOD_console_load_asc(TCOD_console_t pcon, const char *filename) {
- float version;
- int width,height;
- FILE *f;
- TCOD_console_data_t *con=pcon ? (TCOD_console_data_t *)pcon : TCOD_ctx.root;
- TCOD_IFNOT(con != NULL) return false;
- TCOD_IFNOT( filename != NULL ) {
- return false;
- }
- f=fopen(filename,"rb");
- TCOD_IFNOT( f!=NULL ) {
- return false;
- }
- if (fscanf(f, "ASCII-Paint v%g", &version) != 1 ) {
- fclose(f);
- return false;
- }
- if (fscanf(f, "%i %i", &width, &height) != 2 ) {
- fclose(f);
- return false;
- }
- TCOD_IFNOT ( width > 0 && height > 0) {
- fclose(f);
- return false;
- }
- if ( con->w != width || con->h != height ) {
- /* resize console */
- TCOD_console_data_free(con);
- con->w = width;
- con->h = height;
- TCOD_console_data_alloc(con);
- }
- TCOD_console_read_asc(con,f,width,height,version);
- return true;
-}
-
-bool TCOD_console_save_asc(TCOD_console_t pcon, const char *filename) {
- static float version = 0.3f;
- FILE *f;
- int x,y;
- TCOD_console_data_t *con=pcon ? (TCOD_console_data_t *)pcon : TCOD_ctx.root;
- TCOD_IFNOT(con != NULL) return false;
- TCOD_IFNOT( filename != NULL ) {
- return false;
- }
- TCOD_IFNOT(con->w > 0 && con->h > 0) return false;
- f=fopen(filename,"wb");
- TCOD_IFNOT( f != NULL ) return false;
- fprintf(f, "ASCII-Paint v%g\n", version);
- fprintf(f, "%i %i\n", con->w, con->h);
- fputc('#', f);
- for(x = 0; x < con->w; x++) {
- for(y = 0; y < con->h; y++) {
- TCOD_color_t fore,back;
- int c=TCOD_console_get_char(con,x,y);
- fore=TCOD_console_get_char_foreground(con,x,y);
- back=TCOD_console_get_char_background(con,x,y);
- fputc(c, f);
- fputc(fore.r,f);
- fputc(fore.g,f);
- fputc(fore.b,f);
- fputc(back.r,f);
- fputc(back.g,f);
- fputc(back.b,f);
- fputc(0,f); /* solid */
- fputc(1,f); /* walkable */
- }
- }
- fclose(f);
- return true;
-}
-
-static bool hasDetectedBigEndianness = false;
-static bool isBigEndian;
-void detectBigEndianness(void) {
- if (!hasDetectedBigEndianness){
- uint32_t Value32;
- uint8_t *VPtr = (uint8_t *)&Value32;
- VPtr[0] = VPtr[1] = VPtr[2] = 0; VPtr[3] = 1;
- if(Value32 == 1) isBigEndian = true;
- else isBigEndian = false;
- hasDetectedBigEndianness = true;
- }
-}
-
-uint16_t bswap16(uint16_t s){
- uint8_t* ps = (uint8_t*)&s;
- uint16_t res;
- uint8_t* pres = (uint8_t*)&res;
- pres[0] = ps[1];
- pres[1] = ps[0];
- return res;
-}
-
-uint32_t bswap32(uint32_t s){
- uint8_t *ps=(uint8_t *)(&s);
- uint32_t res;
- uint8_t *pres=(uint8_t *)&res;
- pres[0]=ps[3];
- pres[1]=ps[2];
- pres[2]=ps[1];
- pres[3]=ps[0];
- return res;
-}
-
-uint16_t l16(uint16_t s){
- if (isBigEndian) return bswap16(s); else return s;
-}
-
-uint32_t l32(uint32_t s){
- if (isBigEndian) return bswap32(s); else return s;
-}
-
-/* fix the endianness */
-void fix16(uint16_t* u){
- *u = l16(*u);
-}
-
-void fix32(uint32_t* u){
- *u = l32(*u);
-}
-
-/************ RIFF helpers */
-
-uint32_t fourCC(const char* c){
- return (*(uint32_t*)c);
-}
-
-/* checks if u equals str */
-bool fourCCequals(uint32_t u, const char* str){
- return fourCC(str)==u;
-}
-
-void fromFourCC(uint32_t u, char*s){
- const char* c = (const char*)(&u);
- s[0]=c[0];
- s[1]=c[1];
- s[2]=c[2];
- s[3]=c[3];
- s[4]=0;
-}
-
-void put8(uint8_t d, FILE* fp){
- fwrite(&d,1,1,fp);
-}
-
-void put16(uint16_t d, FILE* fp){
- fwrite(&d,2,1,fp);
-}
-
-void put32(uint32_t d, FILE* fp){
- fwrite(&d,4,1,fp);
-}
-
-void putFourCC(const char* c, FILE* fp){
- put32(fourCC(c),fp);
-}
-
-void putData(void* what, int length, FILE* fp){
- fwrite(what,length,1,fp);
-}
-
-bool get8(uint8_t* u, FILE* fp){
- return 1==fread((void*)u, sizeof(uint8_t),1,fp);
-}
-
-bool get16(uint16_t* u, FILE* fp){
- return 1==fread((void*)u, sizeof(uint16_t),1,fp);
-}
-
-bool get32(uint32_t* u, FILE* fp){
- return 1==fread((void*)u, sizeof(uint32_t),1,fp);
-}
-
-bool getData(void* u, size_t sz, FILE* fp){
- return 1==fread(u, sz,1,fp);
-}
-
-
-/********* APF RIFF structures */
-
-typedef struct {
- uint32_t show_grid;
- uint32_t grid_width;
- uint32_t grid_height;
-} SettingsDataV1;
-
-#define FILTER_TYPE_UNCOMPRESSED 0
-#define FORMAT_TYPE_CRGBRGB 0
-
-typedef struct {
- uint32_t width;
- uint32_t height;
- uint32_t filter;
- uint32_t format;
-} ImageDetailsV1;
-
-/* Layers */
-
-typedef struct {
- uint32_t name;
- uint32_t mode;
- uint32_t index;
- uint32_t dataSize;
-} LayerV1 ;
-
-typedef struct {
- uint32_t name;
- uint32_t mode;
- uint32_t fgalpha;
- uint32_t bgalpha;
- uint32_t visible;
- uint32_t index;
- uint32_t dataSize;
-} LayerV2;
-
-/* fix the endianness */
-void fixSettings(SettingsDataV1* s){
- fix32(&s->show_grid);
- fix32(&s->grid_width);
- fix32(&s->grid_height);
-}
-
-void fixImage(ImageDetailsV1* v){
- fix32(&v->width);
- fix32(&v->height);
- fix32(&v->filter);
- fix32(&v->format);
-}
-
-void fixLayerv1(LayerV1* l){
- fix32(&l->mode);
- fix32(&l->index);
- fix32(&l->dataSize);
-}
-
-void fixLayerv2(LayerV2* l){
- fix32(&l->mode);
- fix32(&l->fgalpha);
- fix32(&l->bgalpha);
- fix32(&l->visible);
- fix32(&l->index);
- fix32(&l->dataSize);
-}
-
-
-/*********** ApfFile */
-
-bool TCOD_console_save_apf(TCOD_console_t pcon, const char *filename) {
- TCOD_console_data_t *con=pcon ? (TCOD_console_data_t *)pcon : TCOD_ctx.root;
- FILE* fp ;
- TCOD_IFNOT(con != NULL) return false;
- detectBigEndianness();
-
- fp = fopen(filename, "wb");
- if(fp == NULL) {
- return false;
- }
- else {
- int x,y;
- uint32_t riffSize = 0;
- uint32_t imgDetailsSize ;
- SettingsDataV1 settingsData;
- ImageDetailsV1 imgData;
- fpos_t posRiffSize;
- uint32_t settingsSz ;
- uint32_t layerImageSize ;
- uint32_t layerChunkSize ;
- /* riff header*/
- putFourCC("RIFF",fp);
- fgetpos(fp,&posRiffSize);
- put32(0,fp);
-
- /* APF_ header */
- putFourCC("apf ",fp);
- riffSize += 4;
-
- /* settings */
- settingsData.show_grid = 0;
- settingsData.grid_width = 8;
- settingsData.grid_height = 8;
- settingsSz = sizeof(uint32_t) + sizeof settingsData;
- putFourCC("sett",fp);
- put32(l32(settingsSz),fp);
- put32(l32(1),fp);
- putData((void*)&settingsData,sizeof settingsData,fp);
- if (settingsSz&1){
- put8(0,fp);
- riffSize++;
- }
- riffSize += 4+4+settingsSz;
-
- /* image details */
- imgData.width = con->w;
- imgData.height = con->h;
- imgData.filter = 0;
- imgData.format = 0;
- imgDetailsSize = sizeof(uint32_t) + sizeof imgData;
- putFourCC("imgd",fp);
- put32(l32(imgDetailsSize),fp);
- put32(l32(1),fp);
- putData((void*)&imgData,sizeof imgData,fp);
- if (imgDetailsSize&1){
- put8(0,fp);
- riffSize++;
- }
- riffSize += 4+4+imgDetailsSize;
-
- /* now write the layers as a RIFF list
- the first layer is the lowest layer
- Assume imgData filter = uncompressed, and imgData format = CRGB */
- layerImageSize = imgData.width*imgData.height*7;
- layerChunkSize = sizeof(uint32_t) /* version */
- + sizeof(LayerV2) /* header */
- + layerImageSize; /* data */
-
- putFourCC("layr",fp); /* layer */
- put32(l32(layerChunkSize),fp);
- /* VERSION -> */
- put32(l32(2),fp);
- /* Data */
- putFourCC("LAY0",fp);
- put32(l32(0),fp);
- put32(l32(255),fp);
- put32(l32(255),fp);
- put32(l32(1),fp);
- put32(l32(0),fp);
- put32(l32(layerImageSize),fp);
-
- /* now write out the data */
-
- for(x = 0; x < con->w; x++) {
- for(y = 0; y < con->h; y++) {
- TCOD_color_t fore,back;
- int c=TCOD_console_get_char(con,x,y);
- fore=TCOD_console_get_char_foreground(con,x,y);
- back=TCOD_console_get_char_background(con,x,y);
- put8(c, fp);
- put8(fore.r,fp);
- put8(fore.g,fp);
- put8(fore.b,fp);
- put8(back.r,fp);
- put8(back.g,fp);
- put8(back.b,fp);
- }
- }
-
- if (layerChunkSize&1){
- put8(0,fp); /* padding bit */
- riffSize++;
- }
-
- riffSize += 2*sizeof(uint32_t)+layerChunkSize;
-
- fsetpos(fp,&posRiffSize);
- put32(l32(riffSize),fp);
- }
-
- fclose(fp);
- return true;
-}
-
-typedef struct {
- LayerV1 headerv1;
- LayerV2 headerv2;
- uint8_t* data; /* dynamically allocated */
-} LayerData;
-
-typedef struct {
- ImageDetailsV1 details;
- SettingsDataV1 settings;
- LayerData layer;
-} Data;
-
-bool TCOD_console_load_apf(TCOD_console_t pcon, const char *filename) {
- uint32_t sett = fourCC("sett");
- uint32_t imgd = fourCC("imgd");
- /*
- uint32_t LIST = fourCC("LIST");
- uint32_t LAYR = fourCC("LAYR");
- */
- uint32_t layr = fourCC("layr");
- FILE* fp ;
- Data data;
- TCOD_console_data_t *con=pcon ? (TCOD_console_data_t *)pcon : TCOD_ctx.root;
- TCOD_IFNOT(con != NULL) return false;
-
- detectBigEndianness();
- data.details.width = 1;
- data.details.height = 1;
- data.details.filter = 0;
- data.details.format = 0;
-
- data.settings.show_grid = true;
- data.settings.grid_width = 10;
- data.settings.grid_height = 10;
-
- #define ERR(x) {printf("Error: %s\n. Aborting operation.",x); return false;}
- #define ERR_NEWER(x) {printf("Error: It looks like this file was made with a newer version of Ascii-Paint\n. In particular the %s field. Aborting operation.",x); return false;}
-
- fp = fopen(filename, "rb");
- if(fp == NULL) {
- printf("The file %s could not be loaded.\n", filename);
- return false;
- }
- else {
- /* read the header */
- uint32_t riff;
- uint32_t riffSize;
- int index = 0;
- int x,y;
- uint8_t *imgData;
- bool keepGoing = true;
- if (! get32(&riff,fp) || ! fourCCequals(riff,"RIFF")){
- ERR("File doesn't have a RIFF header");
- }
- if (!get32(&riffSize,fp)) ERR("No RIFF size field!");
- fix32(&riffSize);
-
- while(keepGoing && fp){ /* for each subfield, try to find the APF_ field */
- uint32_t apf;
- if (! get32(&apf,fp)) break;
- if (fourCCequals(apf,"apf ") || fourCCequals(apf,"APF ")){
- /* Process APF segment */
- while(keepGoing && fp){
- uint32_t seg;
- if (! get32(&seg,fp)){
- keepGoing = false;
- break;
- }
- else {
- if (seg==sett){
- /* size */
- uint32_t sz;
- uint32_t ver;
- SettingsDataV1 settingsData;
-
- get32(&sz,fp);
- fix32(&sz);
- /* version */
- get32(&ver,fp);
- fix32(&ver);
- if (ver!=1) ERR_NEWER("settings");
- /* ver must be 1 */
- if (! getData((void*)&settingsData,sizeof settingsData,fp)) ERR("Can't read settings.");
- data.settings = settingsData;
- fixSettings(&data.settings);
-
- }
- else if (seg==imgd){
- /* sz */
- uint32_t sz;
- uint32_t ver;
- ImageDetailsV1 dets;
-
- get32(&sz,fp);
- fix32(&sz);
- /* version */
- get32(&ver,fp);
- fix32(&ver);
- if (ver!=1) ERR_NEWER("image details");
- /* ver must be 1 */
- if (! getData((void*)&dets, sizeof dets, fp)) ERR("Can't read image details.");
- data.details = dets;
- fixImage(&data.details);
-
- /* get canvas ready */
- TCOD_IFNOT ( data.details.width > 0 && data.details.height > 0) {
- fclose(fp);
- return false;
- }
- if ( con->w != data.details.width || con->h != data.details.height ) {
- /* resize console */
- TCOD_console_data_free(con);
- con->w = data.details.width;
- con->h = data.details.height;
- TCOD_console_data_alloc(con);
- }
-
- }
- else if (seg==layr){
- uint32_t sz;
- uint32_t ver;
-
- get32(&sz,fp);
- fix32(&sz);
- /* version */
- get32(&ver,fp);
- fix32(&ver);
- if (ver>2) ERR_NEWER("layer spec");
-
- if (ver==1){
- if (! getData((void*)&data.layer.headerv1, sizeof( LayerV1 ), fp)) ERR("Can't read layer header.");
- fixLayerv1(&data.layer.headerv1);
-
- /* Read in the data chunk*/
- data.layer.data = (uint8_t*)malloc(sizeof(uint8_t)*data.layer.headerv1.dataSize);
- getData((void*) data.layer.data, data.layer.headerv1.dataSize, fp);
- }
- else if (ver==2){
- if (! getData((void*)&data.layer.headerv2, sizeof( LayerV2 ), fp)) ERR("Can't read layer header.");
- fixLayerv2(&data.layer.headerv2);
-
- /* Read in the data chunk */
- data.layer.data = (uint8_t*)malloc(sizeof(uint8_t)*data.layer.headerv2.dataSize);
- getData((void*) data.layer.data, data.layer.headerv2.dataSize, fp);
-
- }
- }
- else {
- /* skip unknown segment */
- uint32_t sz;
- get32(&sz,fp);
- fix32(&sz);
- fseek(fp,sz,SEEK_CUR);
- }
- }
- }
-
- /* we're done! */
- keepGoing = false;
- }
- else {
- /* skip this segment */
- uint32_t sz;
- get32(&sz,fp);
- fseek(fp,sz,SEEK_CUR);
- }
- }
-
- imgData = data.layer.data;
- for(x = 0; x < con->w; x++) {
- for(y = 0; y < con->h; y++) {
- TCOD_color_t fore,back;
- int c = (unsigned char)(imgData[index++]);
- fore.r = (uint8_t)(imgData[index++]);
- fore.g = (uint8_t)(imgData[index++]);
- fore.b = (uint8_t)(imgData[index++]);
- back.r = (uint8_t)(imgData[index++]);
- back.g = (uint8_t)(imgData[index++]);
- back.b = (uint8_t)(imgData[index++]);
- TCOD_console_put_char_ex(con,x,y,c,fore,back);
- }
- }
-
- free (data.layer.data);
- }
- fclose(fp);
-
- return true;
-}
-/*
-
-bool ApfFile::Load(std::string filename){
- detectBigEndianness();
-
- uint32_t sett = fourCC("sett");
- uint32_t imgd = fourCC("imgd");
- uint32_t LIST = fourCC("LIST");
- uint32_t LAYR = fourCC("LAYR");
- uint32_t layr = fourCC("layr");
-
- Data data; // File data
-
- data.details.width = 1;
- data.details.height = 1;
- data.details.filter = FILTER_TYPE_UNCOMPRESSED;
- data.details.format = FORMAT_TYPE_CRGBRGB;
-
- data.settings.show_grid = true;
- data.settings.grid_width = 10;
- data.settings.grid_height = 10;
-
- data.currentLayer = NULL;
-
- #define ERR(x) {printf("Error: %s\n. Aborting operation.",x); return false;}
- #define ERR_NEWER(x) {printf("Error: It looks like this file was made with a newer version of Ascii-Paint\n. In particular the %s field. Aborting operation.",x); return false;}
-
- FILE* fp = fopen(filename.c_str(), "rb");
- if(fp == NULL) {
- printf("The file %s could not be loaded.\n", filename.c_str());
- return false;
- }
- else {
- // read the header
- uint32_t riff;
- if (not get32(&riff,fp)
- or
- not fourCCequals(riff,"RIFF")){
- ERR("File doesn't have a RIFF header");
- }
- // else
- uint32_t riffSize;
- if (!get32(&riffSize,fp)) ERR("No RIFF size field!");
- fix(&riffSize);
-
- bool keepGoing = true;
- while(keepGoing and fp){ // for each subfield, try to find the APF_ field
- uint32_t apf;
- if (not get32(&apf,fp)) break;
- if (fourCCequals(apf,"apf ") or fourCCequals(apf,"APF ")){
- // Process APF segment
- while(keepGoing and fp){
- uint32_t seg;
- if (not get32(&seg,fp)){
- keepGoing = false;
- break;
- }
- else {
- if (seg==sett){
- // size
- uint32_t sz;
- get32(&sz,fp);
- fix(&sz);
- // version
- uint32_t ver;
- get32(&ver,fp);
- fix(&ver);
- if (ver!=1) ERR_NEWER("settings");
- // ver must be 1
- SettingsDataV1 settingsData;
- if (not getData((void*)&settingsData,sizeof settingsData,fp)) ERR("Can't read settings.");
- data.settings = settingsData;
- fix(&data.settings);
-
- // Change app settings
- app->setGridDimensions(data.settings.grid_width,data.settings.grid_height);
- app->setShowGrid(data.settings.show_grid==1);
- }
- else if (seg==imgd){
- // sz
- uint32_t sz;
- get32(&sz,fp);
- fix(&sz);
- // version
- uint32_t ver;
- get32(&ver,fp);
- fix(&ver);
- if (ver!=1) ERR_NEWER("image details");
- // ver must be 1
- ImageDetailsV1 dets;
- if (not getData((void*)&dets, sizeof dets, fp)) ERR("Can't read image details.");
- data.details = dets;
- fix(&data.details);
-
- // get canvas ready
- app->canvasWidth = data.details.width;
- app->canvasHeight = data.details.height;
- app->initCanvas();
-
- // delete new layer
- app->deleteLayer(app->getCurrentLayer()->name);
-
- }
- else if (seg==layr){
- // printf("Found a layer\n");
-
- // sz
- uint32_t sz;
- get32(&sz,fp);
- fix(&sz);
- // version
- uint32_t ver;
- get32(&ver,fp);
- fix(&ver);
- if (ver>2) ERR_NEWER("layer spec");
-
- if (ver==1){
- LayerV1 layerHeader;
- if (not getData((void*)&layerHeader, sizeof layerHeader, fp)) ERR("Can't read layer header.");
- fix(&layerHeader);
-
- // creat new layer data
- LayerData* ld = new LayerData;
- ld->header = layerHeader; // already fix'd
- ld->data = new uint8[ld->header.dataSize];
-
- // Read in the data chunk
- getData((void*) ld->data, ld->header.dataSize, fp);
-
- // push layer onto the list
- data.currentLayer = ld;
- data.layers.push(ld);
- }
- else if (ver==2){
- LayerV2 layerHeader;
- if (not getData((void*)&layerHeader, sizeof layerHeader, fp)) ERR("Can't read layer header.");
- fix(&layerHeader);
-
- // creat new layer data
- LayerData* ld = new LayerData;
- ld->header = layerHeader; // already fix'd
- ld->data = new uint8[ld->header.dataSize];
-
- // Read in the data chunk
- getData((void*) ld->data, ld->header.dataSize, fp);
-
- // push layer onto the list
- data.currentLayer = ld;
- data.layers.push(ld);
- }
- }
- else {
- // skip unknown segment
- uint32_t sz;
- get32(&sz,fp);
- fix(&sz);
- fseek(fp,sz,SEEK_CUR);
- }
- }
- }
-
- // we're done!
- keepGoing = false;
- }
- else {
- // skip this segment
- uint32_t sz;
- get32(&sz,fp);
- fseek(fp,sz,SEEK_CUR);
- }
- }
-
- // finally, copy the layers into the current document
- for(int i=0;iaddNewLayer();
-
- // Parse layer header
- l->name = fromFourCC(ld->header.name);
- l->fgalpha = ld->header.fgalpha;
- l->bgalpha = ld->header.bgalpha;
- l->visible = (ld->header.visible==1);
- // l->compositingMode =
-
- // Copy data into currently selected canvas
- uint8_t* imgData = ld->data;
- CanvasImage *img = new CanvasImage;
- // Write the brush data for every brush in the image
- int index = 0;
- for(int x = 0; x < app->canvasWidth; x++) {
- for(int y = 0; y < app->canvasHeight; y++) {
- Brush b;
- b.symbol = (unsigned char)(imgData[index++]);
- b.fore.r = (uint8_t)(imgData[index++]);
- b.fore.g = (uint8_t)(imgData[index++]);
- b.fore.b = (uint8_t)(imgData[index++]);
- b.back.r = (uint8_t)(imgData[index++]);
- b.back.g = (uint8_t)(imgData[index++]);
- b.back.b = (uint8_t)(imgData[index++]);
- b.solid = true; // deprecated
- b.walkable = true; // deprecated
- img->push_back(b);
- }
- }
-
- app->setCanvasImage(*img);
- delete img;
- }
-
- // then free all the temporary layer data
- for(int i=0;idata;
- delete data.layers.get(i);
- }
-
- // and update the layer widget
- app->gui->layerWidget->regenerateLayerList();
- }
- fclose(fp);
-
- return true;
-}
-*/
-
-#endif /* TCOD_CONSOLE_SUPPORT */
diff --git a/tcod_sys/libtcod/src/console_rexpaint.c b/tcod_sys/libtcod/src/console_rexpaint.c
deleted file mode 100644
index 52bf5e017..000000000
--- a/tcod_sys/libtcod/src/console_rexpaint.c
+++ /dev/null
@@ -1,339 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote
-* products derived from this software without specific prior written
-* permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#include
-
-#ifdef TCOD_CONSOLE_SUPPORT
-
-#include
-
-/* Needed only for TCOD_fatal */
-#include
-
-#include
-#include
-
-/* Confirm that the current types are the same as what this code expects. */
-#if UINT_MAX != 0xffffffff
-#error int type must be 32-bit!
-#endif
-
-#ifdef TCOD_SDL2
-#include
-#if SDL_BYTEORDER != SDL_LIL_ENDIAN
-#error byte-order must be little endian!
-#endif
-#endif
-
-struct RexPaintHeader {
- int version;
- int layer_count;
-};
-struct RexPaintLayerChunk {
- int width;
- int height;
-};
-struct RexPaintTile {
- int ch;
- TCOD_color_t fg;
- TCOD_color_t bg;
-};
-/* Read data from a gz file, returns 0 on success, or -1 on any error. */
-static int load_gz_confirm(gzFile gz_file, void *data, size_t length) {
- if (gzread(gz_file, data, (int)length) != length) { return -1; }
- return 0;
-}
-static int load_header(gzFile gz_file, struct RexPaintHeader *xp_header) {
- return load_gz_confirm(gz_file, xp_header, sizeof(xp_header[0]));
-}
-static int load_layer(gzFile gz_file, struct RexPaintLayerChunk *xp_layer) {
- return load_gz_confirm(gz_file, xp_layer, sizeof(xp_layer[0]));
-}
-/* Read a single REXPaint tile, return 0 on success, or -1 on error. */
-static int load_tile(gzFile gz_file, struct RexPaintTile *tile) {
- return (
- load_gz_confirm(gz_file, &tile->ch, sizeof(tile->ch)) ||
- load_gz_confirm(gz_file, &tile->fg, sizeof(tile->fg)) ||
- load_gz_confirm(gz_file, &tile->bg, sizeof(tile->bg))
- );
-}
-/* Read a layer of REXPaint tiles onto a console.
- If transparent is true, then follow REXPaint's rules for transparency. */
-static int load_tiles(
- gzFile gz_file, TCOD_console_t console, int transparent) {
- int x, y;
- const int width = TCOD_console_get_width(console);
- const int height = TCOD_console_get_height(console);
- /* REXPaint tiles are in column-major order. */
- for (x = 0; x < width; ++x) {
- for (y = 0; y < height; ++y) {
- struct RexPaintTile tile;
- if (load_tile(gz_file, &tile)) {
- return -1;
- }
- /* REXPaint uses a magic pink background to mark transparency. */
- if (transparent &&
- tile.bg.r == 0xff &&
- tile.bg.g == 0x00 &&
- tile.bg.b == 0xff) { continue; }
- TCOD_console_set_char(console, x, y, tile.ch);
- TCOD_console_set_char_foreground(console, x, y, tile.fg);
- TCOD_console_set_char_background(console, x, y, tile.bg, TCOD_BKGND_SET);
- }
- }
- return 0;
-}
-/* Return the next REXPaint layer as a console. After reading the header you
- could just keep calling this function until it returns NULL. */
-static TCOD_console_t load_console(gzFile gz_file) {
- struct RexPaintLayerChunk xp_layer;
- TCOD_console_t console;
- if (load_layer(gz_file, &xp_layer)) { return NULL; }
- console = TCOD_console_new(xp_layer.width, xp_layer.height);
- if (!console) { return NULL; }
- if (load_tiles(gz_file, console, 0)) {
- TCOD_console_delete(console);
- return NULL;
- }
- return console;
-}
-/* Load all the contents of a REXPaint file into a list of consoles. */
-static TCOD_list_t load_consoleList(gzFile gz_file) {
- struct RexPaintHeader xp_header;
- TCOD_list_t console_list;
- int i;
- if (load_header(gz_file, &xp_header)) { return NULL; }
- console_list = TCOD_list_allocate(xp_header.layer_count);
- if (!console_list) { return NULL; }
- for (i = 0; i < xp_header.layer_count; ++i) {
- TCOD_console_t console = load_console(gz_file);
- if (!console) {
- /* There was an issue then delete everything so far and return NULL */
- while (!TCOD_list_is_empty(console_list)) {
- TCOD_console_delete(TCOD_list_pop(console_list));
- }
- TCOD_list_delete(console_list);
- return NULL;
- }
- TCOD_list_push(console_list, console);
- }
- return console_list;
-}
-/* Convert a list of consoles into a single console, deleting the list.
- Follows REXPaint's rules for transparency. */
-static TCOD_console_t combine_console_list(TCOD_list_t console_list) {
- TCOD_console_t main_console;
- if (!console_list) { return NULL; }
- /* Reverse the list so that elements will be dequeued. */
- TCOD_list_reverse(console_list);
- main_console = TCOD_list_pop(console_list);
- while (!TCOD_list_is_empty(console_list)) {
- TCOD_console_t console = TCOD_list_pop(console_list);
- /* Set key color to {255, 0, 255} before blit. */
- TCOD_console_set_key_color(console, TCOD_fuchsia);
- /* This blit may fail if the consoles do not match shapes. */
- TCOD_console_blit(console, 0, 0, 0, 0, main_console, 0, 0, 1.0f, 1.0f);
- TCOD_console_delete(console);
- }
- TCOD_list_delete(console_list);
- return main_console;
-}
-/**
- * \brief Return a list of consoles from a REXPaint file.
- *
- * \param [in] A path to the REXPaint file.
- * \return Returns a TCOD_list_t of TCOD_console_t objects. Or NULL on an
- * error. You will need to delete this list and each console individually.
- *
- * \details This function can load a REXPaint file with variable layer shapes,
- * which would cause issues for a function like TCOD_console_list_from_xp.
- */
-TCOD_list_t TCOD_console_list_from_xp(const char *filename) {
- int z_errno = Z_ERRNO;
- TCOD_list_t console_list;
- gzFile gz_file = gzopen(filename, "rb");
- if (!gz_file) {
- TCOD_fatal("Could not open file: '%s'", filename);
- return NULL;
- }
- console_list = load_consoleList(gz_file);
- if (!console_list){
- TCOD_fatal("Error parsing '%s'\n%s", filename, gzerror(gz_file, &z_errno));
- /* Could fall-through here and return NULL. */
- }
- gzclose(gz_file);
- return console_list;
-}
-/**
- * \brief Return a new console loaded from a REXPaint ``.xp`` file.
- *
- * \param [in] filename A path to the REXPaint file.
- * \param [in] layer The specific layer to return, or ``0`` to return a
- * console with all layers overlaid using REXPaint's rules for transparency.
- * \return A new TCOD_console_t object. New consoles will need
- * to be deleted with a call to :any:`TCOD_console_delete`.
- * Returns NULL on an error.
- *
- * \details REXPaint gives special treatment to tiles with a magic pink
- * ``{255, 0, 255}`` background color. You can processes this color
- * manually or set :any:`TCOD_console_set_key_color` to `TCOD_fuchsia`.
- */
-TCOD_console_t TCOD_console_from_xp(const char *filename) {
- return combine_console_list(TCOD_console_list_from_xp(filename));
-}
-/**
- * \brief Update a console from a REXPaint ``.xp`` file.
- *
- * \param [out] con A console instance to update from the REXPaint file.
- * \param [in] filename A path to the REXPaint file.
- *
- * \details REXPaint gives special treatment to tiles with a magic pink
- * ``{255, 0, 255}`` background color. You can processes this color
- * manually or set :any:`TCOD_console_set_key_color` to `TCOD_fuchsia`.
- */
-bool TCOD_console_load_xp(TCOD_console_t con, const char *filename) {
- TCOD_console_t xp_console = TCOD_console_from_xp(filename);
- if (!xp_console) { return false; }
- if (TCOD_console_get_width(con) != TCOD_console_get_width(xp_console) ||
- TCOD_console_get_height(con) != TCOD_console_get_height(xp_console)) {
- TCOD_console_delete(xp_console);
- return false;
- }
- TCOD_console_blit(xp_console, 0, 0, 0, 0, con, 0, 0, 1.0f, 1.0f);
- TCOD_console_delete(xp_console);
- return true;
-}
-static int write_header(gzFile gz_file, struct RexPaintHeader *xp_header) {
- if (!gzwrite(gz_file, xp_header, sizeof(xp_header[0]))) {
- return -1;
- }
- return 0;
-}
-static int write_layer(gzFile gz_file, struct RexPaintLayerChunk *xp_layer) {
- if (!gzwrite(gz_file, xp_layer, sizeof(xp_layer[0]))) {
- return -1;
- }
- return 0;
-}
-static int write_tile(gzFile gz_file, struct RexPaintTile *tile) {
- if (!gzwrite(gz_file, &tile->ch, sizeof(tile->ch)) ||
- !gzwrite(gz_file, &tile->fg, sizeof(tile->fg)) ||
- !gzwrite(gz_file, &tile->bg, sizeof(tile->bg))) {
- return -1;
- }
- return 0;
-}
-static int write_console(gzFile gz_file, TCOD_console_t console) {
- int x, y;
- struct RexPaintLayerChunk xp_layer;
- xp_layer.width = TCOD_console_get_width(console);
- xp_layer.height = TCOD_console_get_height(console);
- if (write_layer(gz_file, &xp_layer)) {
- return -1; /* error writing layer */
- }
- /* Write console data out in column-major order. */
- for (x = 0; x < xp_layer.width; ++x) {
- for (y = 0; y < xp_layer.height; ++y) {
- struct RexPaintTile tile;
- tile.ch = TCOD_console_get_char(console, x, y);
- tile.fg = TCOD_console_get_char_foreground(console, x, y);
- tile.bg = TCOD_console_get_char_background(console, x, y);
- if (write_tile(gz_file, &tile)) {
- return -1; /* error writing tile data */
- }
- }
- }
- return 0;
-}
-/**
- * \brief Save a console as a REXPaint ``.xp`` file.
- *
- * \param [in] con The console instance to save.
- * \param [in] filename The filepath to save to.
- * \param [in] compress_level A zlib compression level, from 0 to 9.
- * 1=fast, 6=balanced, 9=slowest, 0=uncompressed.
- * \return ``true`` when the file is saved succesfully, or ``false`` when an
- * issue is detected.
- *
- * \details REXPaint has enough fidelity to make a 1:1 copy of a libtcod
- * console.
- */
-bool TCOD_console_save_xp(
- TCOD_console_t con, const char *filename, int compress_level) {
- struct RexPaintHeader xp_header;
- gzFile gz_file = gzopen(filename, "wb");
- if (!gz_file) { return false; /* could not open file */ }
- gzsetparams(gz_file, compress_level, Z_DEFAULT_STRATEGY);
- xp_header.version = -1; /* REXPaint uses this version. */
- xp_header.layer_count = 1;
- if (write_header(gz_file, &xp_header) || write_console(gz_file, con)) {
- gzclose(gz_file);
- return false; /* error writing data */
- }
- if (gzclose(gz_file)) { return false; /* error writing to file */ }
- return true;
-}
-/**
- * \brief Save a list of consoles to a REXPaint file.
- *
- * \param [in] A TCOD_list_t of TCOD_console_t objects.
- * \param [in] Path to save to.
- * \param [in] zlib compression level.
- * \return true on success, false on a failure such as not being able to write
- * to the path provided.
- *
- * \details The REXPaint tool can only work on files with up to 4 layers where
- * all layers are the same size.
- *
- * This function can save any number of layers with multiple different sizes,
- * these files can be loaded without issues as long you use
- * :any:`TCOD_console_list_from_xp` for loading.
- */
-bool TCOD_console_list_save_xp(
- TCOD_list_t console_list, const char *filename, int compress_level) {
- int i;
- struct RexPaintHeader xp_header;
- gzFile gz_file = gzopen(filename, "wb");
- if (!gz_file) { return false; /* could not open file */ }
- gzsetparams(gz_file, compress_level, Z_DEFAULT_STRATEGY);
- xp_header.version = -1;
- xp_header.layer_count = TCOD_list_size(console_list);
- if (write_header(gz_file, &xp_header)) {
- gzclose(gz_file);
- return false; /* error writing metadata */
- }
- for (i = 0; i < xp_header.layer_count; ++i){
- if (write_console(gz_file, TCOD_list_get(console_list, i))) {
- gzclose(gz_file);
- return false; /* error writing out console data */
- }
- }
- if (gzclose(gz_file)) { return false; /* error writing to file */ }
- return true;
-}
-
-#endif /* TCOD_CONSOLE_SUPPORT */
diff --git a/tcod_sys/libtcod/src/fov.cpp b/tcod_sys/libtcod/src/fov.cpp
deleted file mode 100644
index 2bdf5ecd4..000000000
--- a/tcod_sys/libtcod/src/fov.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#include
-
-TCODMap::TCODMap(int width,int height) {
- data = TCOD_map_new(width,height);
-}
-
-void TCODMap::clear(bool transparent, bool walkable) {
- TCOD_map_clear(data,transparent,walkable);
-}
-
-void TCODMap::setProperties(int x, int y, bool isTransparent, bool isWalkable) {
- TCOD_map_set_properties(data,x,y,isTransparent,isWalkable);
-}
-
-void TCODMap::copy(const TCODMap *source) {
- TCOD_map_copy(source->data,data);
-}
-
-void TCODMap::computeFov(int x, int y, int maxRadius, bool light_walls, TCOD_fov_algorithm_t algo) {
- TCOD_map_compute_fov(data,x,y,maxRadius,light_walls, algo);
-}
-
-bool TCODMap::isInFov(int x, int y) const {
- return TCOD_map_is_in_fov(data,x,y) != 0;
-}
-
-void TCODMap::setInFov(int x,int y, bool fov) {
- TCOD_map_set_in_fov(data, x, y, fov);
-}
-
-bool TCODMap::isTransparent(int x, int y) const {
- return TCOD_map_is_transparent(data,x,y) != 0;
-}
-
-bool TCODMap::isWalkable(int x, int y) const {
- return TCOD_map_is_walkable(data,x,y) != 0;
-}
-
-int TCODMap::getWidth() const {
- return TCOD_map_get_width(data);
-}
-
-int TCODMap::getHeight() const {
- return TCOD_map_get_height(data);
-}
-
-int TCODMap::getNbCells() const {
- return TCOD_map_get_nb_cells(data);
-}
-
-TCODMap::~TCODMap() {
- TCOD_map_delete(data);
-}
diff --git a/tcod_sys/libtcod/src/fov_c.c b/tcod_sys/libtcod/src/fov_c.c
deleted file mode 100644
index 3bc17a696..000000000
--- a/tcod_sys/libtcod/src/fov_c.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#include
-
-#include
-#include
-
-#include
-
-TCOD_map_t TCOD_map_new(int width, int height) {
- map_t *map=NULL;
- TCOD_IFNOT(width > 0 && height > 0) return NULL;
- map=(map_t *)calloc(sizeof(map_t),1);
- map->width=width;
- map->height=height;
- map->nbcells=width*height;
- map->cells=(cell_t *)calloc(sizeof(cell_t),map->nbcells);
- return map;
-}
-
-void TCOD_map_copy(TCOD_map_t source, TCOD_map_t dest) {
- map_t *source_int = (map_t *)source;
- map_t *dest_int = (map_t *)dest;
- TCOD_IFNOT(source != NULL && dest != NULL) return;
- if ( dest_int->nbcells != source_int->nbcells ) {
- free(dest_int->cells);
- dest_int->cells=(cell_t *)malloc(sizeof(cell_t)*dest_int->nbcells);
- }
- dest_int->width=source_int->width;
- dest_int->height=source_int->height;
- dest_int->nbcells=source_int->nbcells;
- memcpy(dest_int->cells, source_int->cells, sizeof(cell_t) * source_int->nbcells);
-}
-
-void TCOD_map_clear(TCOD_map_t map, bool transparent, bool walkable) {
- int i;
- map_t *m = (map_t *)map;
- cell_t *cell;
- TCOD_IFNOT(map != NULL) return;
- cell=m->cells;
- for (i = 0; i < m->nbcells; i++) {
- cell->transparent = transparent;
- cell->walkable = walkable;
- cell->fov = 0;
- cell++;
- }
-}
-
-void TCOD_map_set_properties(TCOD_map_t map, int x, int y, bool is_transparent, bool is_walkable) {
- map_t *m = (map_t *)map;
- TCOD_IFNOT(map != NULL) return;
- TCOD_IFNOT((unsigned)x < (unsigned)m->width && (unsigned)y < (unsigned)m->height) return;
- m->cells[x+y*m->width].transparent=is_transparent;
- m->cells[x+y*m->width].walkable=is_walkable;
-}
-
-void TCOD_map_delete(TCOD_map_t map) {
- map_t *m = (map_t *)map;
- TCOD_IFNOT(map != NULL) return;
- free(m->cells);
- free(m);
-}
-
-void TCOD_map_compute_fov(TCOD_map_t map, int player_x, int player_y, int max_radius, bool light_walls, TCOD_fov_algorithm_t algo) {
- TCOD_IFNOT(map != NULL) return;
- switch(algo) {
- case FOV_BASIC : TCOD_map_compute_fov_circular_raycasting(map,player_x,player_y,max_radius,light_walls); break;
- case FOV_DIAMOND : TCOD_map_compute_fov_diamond_raycasting(map,player_x,player_y,max_radius,light_walls); break;
- case FOV_SHADOW : TCOD_map_compute_fov_recursive_shadowcasting(map,player_x,player_y,max_radius,light_walls); break;
- case FOV_PERMISSIVE_0 :
- case FOV_PERMISSIVE_1 :
- case FOV_PERMISSIVE_2 :
- case FOV_PERMISSIVE_3 :
- case FOV_PERMISSIVE_4 :
- case FOV_PERMISSIVE_5 :
- case FOV_PERMISSIVE_6 :
- case FOV_PERMISSIVE_7 :
- case FOV_PERMISSIVE_8 :
- TCOD_map_compute_fov_permissive2(map,player_x,player_y,max_radius,light_walls, algo-FOV_PERMISSIVE_0);
- break;
- case FOV_RESTRICTIVE : TCOD_map_compute_fov_restrictive_shadowcasting(map,player_x,player_y,max_radius,light_walls); break;
- default:break;
- }
-}
-
-bool TCOD_map_is_in_fov(TCOD_map_t map, int x, int y) {
- map_t *m = (map_t *)map;
- TCOD_IFNOT(map != NULL && (unsigned)x < (unsigned)m->width && (unsigned)y < (unsigned)m->height) return false;
- return m->cells[x+y*m->width].fov == 1;
-}
-
-void TCOD_map_set_in_fov(TCOD_map_t map, int x, int y, bool fov) {
- map_t *m = (map_t *)map;
- TCOD_IFNOT(map != NULL && (unsigned)x < (unsigned)m->width && (unsigned)y < (unsigned)m->height) return;
- m->cells[x+y*m->width].fov = fov ? 1:0;
-}
-
-bool TCOD_map_is_transparent(TCOD_map_t map, int x, int y) {
- map_t *m = (map_t *)map;
- TCOD_IFNOT(map != NULL && (unsigned)x < (unsigned)m->width && (unsigned)y < (unsigned)m->height) return false;
- return m->cells[x+y*m->width].transparent;
-}
-
-bool TCOD_map_is_walkable(TCOD_map_t map, int x, int y) {
- map_t *m = (map_t *)map;
- TCOD_IFNOT(map != NULL && (unsigned)x < (unsigned)m->width && (unsigned)y < (unsigned)m->height) return false;
- return m->cells[x+y*m->width].walkable;
-}
-int TCOD_map_get_width(TCOD_map_t map) {
- map_t *m = (map_t *)map;
- TCOD_IFNOT(map != NULL) return 0;
- return m->width;
-}
-
-int TCOD_map_get_height(TCOD_map_t map) {
- map_t *m = (map_t *)map;
- TCOD_IFNOT(map != NULL) return 0;
- return m->height;
-}
-
-int TCOD_map_get_nb_cells(TCOD_map_t map) {
- map_t *m = (map_t *)map;
- TCOD_IFNOT(map != NULL) return 0;
- return m->nbcells;
-}
-
diff --git a/tcod_sys/libtcod/src/image_c.c b/tcod_sys/libtcod/src/image_c.c
deleted file mode 100644
index 0bf579d58..000000000
--- a/tcod_sys/libtcod/src/image_c.c
+++ /dev/null
@@ -1,867 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#include
-
-#ifdef TCOD_IMAGE_SUPPORT
-
-#include
-#include
-#include
-
-#include
-#ifdef TCOD_CONSOLE_SUPPORT
-#include
-#endif
-#include
-#include
-
-typedef struct {
- int width,height;
- float fwidth,fheight;
- TCOD_color_t *buf;
- bool dirty;
-} mipmap_t;
-
-typedef struct {
- void *sys_img;
- int nb_mipmaps;
- mipmap_t *mipmaps;
- TCOD_color_t key_color;
- bool has_key_color;
-} image_data_t;
-
-/*
-Internal libtcod optimisation, direct colour manipulation in the images primary mipmap.
-*/
-TCOD_color_t *TCOD_image_get_colors(TCOD_image_t *image) {
- image_data_t *img = ((image_data_t *)image);
- return img->mipmaps[0].buf;
-}
-
-void TCOD_image_get_key_data(TCOD_image_t image, bool *has_key_color, TCOD_color_t *key_color) {
- image_data_t *img = ((image_data_t *)image);
- *has_key_color = img->has_key_color;
- *key_color = img->key_color;
-}
-
-void TCOD_image_invalidate_mipmaps(TCOD_image_t *image) {
- int i;
- image_data_t *img = ((image_data_t *)image);
- for (i = 1; i < img->nb_mipmaps; i++) {
- img->mipmaps[i].dirty = true;
- }
-}
-
-static int TCOD_image_get_mipmap_levels(int width, int height) {
- int curw=width;
- int curh=height;
- int nb_mipmap=0;
- while ( curw > 0 && curh > 0 ) {
- nb_mipmap++;
- curw >>= 1;
- curh >>= 1;
- }
- return nb_mipmap;
-}
-
-static void TCOD_image_generate_mip(image_data_t *img, int mip) {
- mipmap_t *orig=&img->mipmaps[0];
- mipmap_t *cur =&img->mipmaps[mip];
- int x,y;
- if (! cur->buf) {
- cur->buf=(TCOD_color_t *)calloc(sizeof(TCOD_color_t),cur->width*cur->height);
- }
- cur->dirty=false;
- for (x=0; x < cur->width; x++) {
- for (y=0; y < cur->height; y++) {
- int r=0,g=0,b=0, count=0;
- int sx,sy;
- TCOD_color_t *col;
- for (sx=(x << mip); sx < ((x+1)<width;
- count++;
- r+=orig->buf[offset].r;
- g+=orig->buf[offset].g;
- b+=orig->buf[offset].b;
- }
- }
- r /= count;
- g /= count;
- b /= count;
- col = &cur->buf[x+y*cur->width];
- col->r=r;
- col->g=g;
- col->b=b;
- }
- }
-}
-
-/*
-Internal way of copying rendering fg/bg color frame data.
-*/
-bool TCOD_image_mipmap_copy_internal(TCOD_image_t srcImage, TCOD_image_t dstImage) {
- int i;
- image_data_t *img_src = (image_data_t *)srcImage;
- image_data_t *img_dst = (image_data_t *)dstImage;
- if (!img_src->mipmaps || img_src->sys_img || !img_dst->mipmaps || img_dst->sys_img) /* Both internal images. */
- return false;
- if (img_src->mipmaps[0].width != img_dst->mipmaps[0].width || img_src->mipmaps[0].height != img_dst->mipmaps[0].height)
- return false;
- /* Copy all mipmaps? */
- img_dst->mipmaps[0].dirty = img_src->mipmaps[0].dirty;
- memcpy(img_dst->mipmaps[0].buf, img_src->mipmaps[0].buf, sizeof(TCOD_color_t)*(img_src->mipmaps[0].width)*(img_src->mipmaps[0].height));
- for (i = 1; i < img_src->nb_mipmaps; i++)
- img_dst->mipmaps[i].dirty = true;
- return true;
-}
-
-static void TCOD_image_init_mipmaps(image_data_t *img) {
- int w,h,i,x,y;
- float fw,fh;
- if (! img->sys_img ) return;
- TCOD_sys_get_image_size(img->sys_img,&w,&h);
- img->nb_mipmaps=TCOD_image_get_mipmap_levels(w,h);
- img->mipmaps = (mipmap_t *)calloc(sizeof(mipmap_t),img->nb_mipmaps);
- img->mipmaps[0].buf = (TCOD_color_t *)calloc(sizeof(TCOD_color_t),w*h);
- for (x=0; x < w; x++) {
- for (y=0;y < h; y++) {
- img->mipmaps[0].buf[x+y*w]=TCOD_sys_get_image_pixel(img->sys_img,x,y);
- }
- }
- fw=(float)w;
- fh=(float)h;
- for ( i=0; i < img->nb_mipmaps; i++) {
- img->mipmaps[i].width=w;
- img->mipmaps[i].height=h;
- img->mipmaps[i].fwidth=fw;
- img->mipmaps[i].fheight=fh;
- img->mipmaps[i].dirty=true;
- w >>= 1;
- h >>= 1;
- fw *= 0.5f;
- fh *= 0.5f;
- }
- img->mipmaps[0].dirty=false;
-}
-
-void TCOD_image_clear(TCOD_image_t image, TCOD_color_t color) {
- int i;
- image_data_t *img=(image_data_t *)image;
- if ( !img->mipmaps && !img->sys_img) return; /* no image data */
- if ( ! img->mipmaps ) {
- TCOD_image_init_mipmaps(img);
- }
- for (i=0; i< img->mipmaps[0].width*img->mipmaps[0].height; i++) {
- img->mipmaps[0].buf[i] = color;
- }
- for ( i=1; i < img->nb_mipmaps; i++) {
- img->mipmaps[i].dirty=true;
- }
-}
-
-TCOD_image_t TCOD_image_new(int width, int height) {
- int i;
- float fw,fh;
- image_data_t *ret=(image_data_t *)calloc(sizeof(image_data_t),1);
- ret->nb_mipmaps=TCOD_image_get_mipmap_levels(width,height);
- ret->mipmaps = (mipmap_t *)calloc(sizeof(mipmap_t),ret->nb_mipmaps);
- ret->mipmaps[0].buf = (TCOD_color_t *)calloc(sizeof(TCOD_color_t),width*height);
-
- for (i=0; i< width*height; i++) {
- ret->mipmaps[0].buf[i] = TCOD_black;
- }
- fw=(float)width;
- fh=(float)height;
- for ( i=0; i < ret->nb_mipmaps; i++) {
- ret->mipmaps[i].width=width;
- ret->mipmaps[i].height=height;
- ret->mipmaps[i].fwidth=fw;
- ret->mipmaps[i].fheight=fh;
- width >>= 1;
- height >>= 1;
- fw *= 0.5f;
- fh *= 0.5f;
- }
- return (TCOD_image_t)ret;
-}
-
-TCOD_image_t TCOD_image_load(const char *filename) {
- image_data_t *ret=(image_data_t *)calloc(sizeof(image_data_t),1);
- ret->sys_img=TCOD_sys_load_image(filename);
- return (TCOD_image_t)ret;
-}
-
-void TCOD_image_get_size(TCOD_image_t image, int *w,int *h) {
- image_data_t *img=(image_data_t *)image;
- if ( !img->mipmaps && !img->sys_img) return; /* no image data */
- if ( img->mipmaps ) {
- *w = img->mipmaps[0].width;
- *h = img->mipmaps[0].height;
- } else {
- TCOD_sys_get_image_size(img->sys_img,w,h);
- }
-}
-
-TCOD_color_t TCOD_image_get_pixel(TCOD_image_t image,int x, int y) {
- image_data_t *img=(image_data_t *)image;
- if ( !img->mipmaps && !img->sys_img) return TCOD_black; /* no image data */
- if ( img->mipmaps ) {
- if ( x >= 0 && x < img->mipmaps[0].width
- && y >= 0 && y < img->mipmaps[0].height ) {
- return img->mipmaps[0].buf[x+y*img->mipmaps[0].width];
- } else {
- return TCOD_black;
- }
- } else {
- return TCOD_sys_get_image_pixel(img->sys_img,x,y);
- }
-}
-
-int TCOD_image_get_alpha(TCOD_image_t image,int x, int y) {
- image_data_t *img=(image_data_t *)image;
- if ( img->sys_img ) {
- return TCOD_sys_get_image_alpha(img->sys_img,x,y);
- } else return 255;
-}
-
-TCOD_color_t TCOD_image_get_mipmap_pixel(TCOD_image_t image,float x0,float y0, float x1, float y1) {
- int texel_xsize,texel_ysize, texel_size, texel_x,texel_y;
- int cur_size=1;
- int mip=0;
- image_data_t *img=(image_data_t *)image;
- if ( !img->mipmaps && !img->sys_img) return TCOD_black; /* no image data */
- if (!img->mipmaps) TCOD_image_init_mipmaps(img);
- texel_xsize=(int)(x1-x0);
- texel_ysize=(int)(y1-y0);
- texel_size=texel_xsize < texel_ysize ? texel_ysize : texel_xsize;
- while ( mip < img->nb_mipmaps-1 && cur_size < texel_size ) {
- mip++;
- cur_size <<= 1;
- }
- if ( mip > 0 ) mip --;
- texel_x=(int)(x0*(img->mipmaps[mip].width)/img->mipmaps[0].fwidth);
- texel_y=(int)(y0*(img->mipmaps[mip].height)/img->mipmaps[0].fheight);
-
- if (img->mipmaps[mip].buf == NULL || img->mipmaps[mip].dirty) {
- TCOD_image_generate_mip(img,mip);
- }
- if ( texel_x < 0 || texel_y < 0 || texel_x >= img->mipmaps[mip].width || texel_y >= img->mipmaps[mip].height )
- return TCOD_black;
- return img->mipmaps[mip].buf[texel_x+texel_y*img->mipmaps[mip].width];
-}
-
-void TCOD_image_put_pixel(TCOD_image_t image,int x, int y,TCOD_color_t col) {
- image_data_t *img=(image_data_t *)image;
- if ( !img->mipmaps && !img->sys_img) return; /* no image data */
- if ( ! img->mipmaps ) {
- TCOD_image_init_mipmaps(img);
- }
- if ( x >= 0 && x < img->mipmaps[0].width
- && y >= 0 && y < img->mipmaps[0].height ) {
- int mip;
- img->mipmaps[0].buf[x+y*img->mipmaps[0].width] = col;
- for (mip=1; mip < img->nb_mipmaps; mip++) {
- img->mipmaps[mip].dirty=true;
- }
- }
-}
-
-void TCOD_image_delete_internal(TCOD_image_t image) {
- image_data_t *img=(image_data_t *)image;
- if ( img->mipmaps ) {
- int i;
- for ( i=0; i < img->nb_mipmaps; i++) {
- if ( img->mipmaps[i].buf ) free(img->mipmaps[i].buf);
- }
- free(img->mipmaps);
- }
- if ( img->sys_img ) {
-#ifdef TCOD_SDL2
- TCOD_sys_delete_bitmap(img->sys_img);
-#endif
- }
-}
-
-void TCOD_image_delete(TCOD_image_t image) {
- TCOD_image_delete_internal(image);
- free(image);
-}
-
-bool TCOD_image_is_pixel_transparent(TCOD_image_t image, int x, int y) {
- image_data_t *img=(image_data_t *)image;
- TCOD_color_t col=TCOD_image_get_pixel(image,x,y);
- if ( img->has_key_color && img->key_color.r == col.r
- && img->key_color.g == col.g && img->key_color.b == col.b ) {
- return true;
- }
- if ( TCOD_image_get_alpha(image,x,y) == 0 ) return true;
- return false;
-}
-
-#ifdef TCOD_CONSOLE_SUPPORT
-
-void TCOD_image_blit(TCOD_image_t image, TCOD_console_t console, float x, float y,
- TCOD_bkgnd_flag_t bkgnd_flag, float scalex, float scaley, float angle) {
- int width,height;
- float rx,ry;
- image_data_t *img=(image_data_t *)image;
- if ( scalex == 0.0f || scaley == 0.0f || bkgnd_flag == TCOD_BKGND_NONE ) return;
- TCOD_image_get_size(image,&width,&height);
- rx = x - width * 0.5f;
- ry = y - height * 0.5f;
- if ( scalex == 1.0f && scaley == 1.0f && angle == 0.0f && rx == ((int)rx) && ry == ((int)ry)) {
- /* clip the image */
- int ix = (int)(x - width*0.5f);
- int iy = (int)(y - height*0.5f);
- int minx=MAX(ix,0);
- int miny=MAX(iy,0);
- int maxx=MIN(ix+width,TCOD_console_get_width(console));
- int maxy=MIN(iy+height,TCOD_console_get_height(console));
- int offx=0,offy=0;
- int cx,cy;
- if ( ix < 0 ) offx=-ix;
- if ( iy < 0 ) offy=-iy;
- for (cx=minx; cx < maxx; cx ++) {
- for (cy=miny; cy < maxy; cy ++) {
- TCOD_color_t col=TCOD_image_get_pixel(image,cx-minx+offx,cy-miny+offy);
- if ( !img->has_key_color || img->key_color.r != col.r
- || img->key_color.g != col.g || img->key_color.b != col.b ) {
- TCOD_console_set_char_background(console,cx,cy,col,bkgnd_flag);
- }
- }
- }
- } else {
- float iw=width/2*scalex;
- float ih=height/2*scaley;
- /* get the coordinates of the image corners in the console */
- float newx_x = (float)cos(angle);
- float newx_y = -(float)sin(angle);
- float newy_x = newx_y;
- float newy_y = -newx_x;
- float x0,y0,x1,y1,x2,y2,x3,y3; /* image corners coordinates */
- int rx,ry,rw,rh; /* rectangular area in the console */
- int cx,cy;
- int minx,miny,maxx,maxy;
- float invscalex,invscaley;
- /* 0 = P - w/2 x' +h/2 y' */
- x0 = x-iw*newx_x+ih*newy_x;
- y0 = y-iw*newx_y+ih*newy_y;
- /* 1 = P + w/2 x' + h/2 y' */
- x1 = x+iw*newx_x+ih*newy_x;
- y1 = y+iw*newx_y+ih*newy_y;
- /* 2 = P + w/2 x' - h/2 y' */
- x2 = x+iw*newx_x-ih*newy_x;
- y2 = y+iw*newx_y-ih*newy_y;
- /* 3 = P - w/2 x' - h/2 y' */
- x3 = x-iw*newx_x-ih*newy_x;
- y3 = y-iw*newx_y-ih*newy_y;
- /* get the affected rectangular area in the console */
- rx=(int)(MIN(MIN(x0,x1),MIN(x2,x3)));
- ry=(int)(MIN(MIN(y0,y1),MIN(y2,y3)));
- rw=(int)(MAX(MAX(x0,x1),MAX(x2,x3))) - rx;
- rh=(int)(MAX(MAX(y0,y1),MAX(y2,y3))) - ry;
- /* clip it */
- minx=MAX(rx,0);
- miny=MAX(ry,0);
- maxx=MIN(rx+rw,TCOD_console_get_width(console));
- maxy=MIN(ry+rh,TCOD_console_get_height(console));
- invscalex=1.0f / scalex;
- invscaley=1.0f / scaley;
- for (cx=minx; cx < maxx; cx ++) {
- for (cy=miny; cy < maxy; cy ++) {
- float ix,iy;
- TCOD_color_t col;
- /* map the console pixel to the image world */
- ix = (iw+ (cx-x) * newx_x + (cy-y) *(-newy_x))*invscalex;
- iy = (ih + (cx-x) * (newx_y) - (cy-y)*newy_y)*invscaley;
- col = TCOD_image_get_pixel(image,(int)(ix),(int)(iy));
- if ( !img->has_key_color || img->key_color.r != col.r
- || img->key_color.g != col.g || img->key_color.b != col.b ) {
- if ( scalex < 1.0f || scaley < 1.0f ) {
- col = TCOD_image_get_mipmap_pixel(image,ix,iy,ix+1.0f,iy+1.0f);
- }
- TCOD_console_set_char_background(console,cx,cy,col,bkgnd_flag);
- }
- }
- }
- }
-}
-
-void TCOD_image_blit_rect(TCOD_image_t image, TCOD_console_t console, int x, int y,
- int w, int h, TCOD_bkgnd_flag_t bkgnd_flag) {
- int width,height;
- float scalex,scaley;
- TCOD_image_get_size(image,&width,&height);
- if ( w == -1 ) w=width;
- if ( h == -1 ) h=height;
- if ( w <= 0 || h <= 0 || bkgnd_flag == TCOD_BKGND_NONE ) return;
- scalex = (float)(w)/width;
- scaley = (float)(h)/height;
- TCOD_image_blit(image,console,x+w*0.5f,y+h*0.5f,bkgnd_flag,scalex,scaley,0.0f);
-}
-
-TCOD_image_t TCOD_image_from_console(TCOD_console_t console) {
- image_data_t *ret;
- void *bitmap=TCOD_sys_create_bitmap_for_console(console);
- ret=(image_data_t *)calloc(sizeof(image_data_t),1);
- ret->sys_img=bitmap;
- TCOD_image_refresh_console((TCOD_image_t)ret,console);
- return (TCOD_image_t)ret;
-}
-
-void TCOD_image_refresh_console(TCOD_image_t image, TCOD_console_t console) {
- image_data_t *img=(image_data_t *)image;
- console = (console?console:TCOD_ctx.root);
- /* We're copying the state and clearing part of the copy, no need to delete/free. */
- TCOD_sys_console_to_bitmap(
- img->sys_img, (TCOD_console_data_t*)console, NULL);
-}
-
-#endif /* TCOD_CONSOLE_SUPPORT */
-
-void TCOD_image_save(TCOD_image_t image, const char *filename) {
- image_data_t *img=(image_data_t *)image;
- void *bitmap=NULL;
- bool must_free=false;
- if ( img->sys_img ) {
- bitmap=img->sys_img;
- } else if ( img->mipmaps ){
- bitmap=TCOD_sys_create_bitmap(img->mipmaps[0].width, img->mipmaps[0].height, img->mipmaps[0].buf);
- must_free=true;
- }
- if (bitmap) {
- TCOD_sys_save_bitmap(bitmap, filename);
- if ( must_free ) {
- TCOD_sys_delete_bitmap(bitmap);
- }
- }
-}
-
-void TCOD_image_set_key_color(TCOD_image_t image, TCOD_color_t key_color) {
- image_data_t *img=(image_data_t *)image;
- img->has_key_color=true;
- img->key_color=key_color;
-}
-
-void TCOD_image_invert(TCOD_image_t image) {
- int i,mip;
- int width,height;
- image_data_t *img=(image_data_t *)image;
- if ( !img->mipmaps && !img->sys_img) return; /* no image data */
- if ( ! img->mipmaps ) {
- TCOD_image_init_mipmaps(img);
- }
- TCOD_image_get_size(image,&width,&height);
- for (i=0; i< width*height; i++) {
- TCOD_color_t col=img->mipmaps[0].buf[i];
- col.r=255-col.r;
- col.g=255-col.g;
- col.b=255-col.b;
- img->mipmaps[0].buf[i] = col;
- }
- for (mip=1; mip < img->nb_mipmaps; mip++) {
- img->mipmaps[mip].dirty=true;
- }
-}
-
-void TCOD_image_hflip(TCOD_image_t image) {
- int px,py;
- int width,height;
- TCOD_image_get_size(image,&width,&height);
- for (py = 0; py < height; py++ ) {
- for (px = 0; px < width/2; px++ ) {
- TCOD_color_t col1=TCOD_image_get_pixel(image,px,py);
- TCOD_color_t col2=TCOD_image_get_pixel(image,width-1-px,py);
- TCOD_image_put_pixel(image,px,py,col2);
- TCOD_image_put_pixel(image,width-1-px,py,col1);
- }
- }
-}
-
-void TCOD_image_vflip(TCOD_image_t image) {
- int px,py;
- int width,height;
- TCOD_image_get_size(image,&width,&height);
- for (px = 0; px < width; px++ ) {
- for (py = 0; py < height/2; py++ ) {
- TCOD_color_t col1=TCOD_image_get_pixel(image,px,py);
- TCOD_color_t col2=TCOD_image_get_pixel(image,px,height-1-py);
- TCOD_image_put_pixel(image,px,py,col2);
- TCOD_image_put_pixel(image,px,height-1-py,col1);
- }
- }
-}
-
-void TCOD_image_rotate90(TCOD_image_t image, int numRotations) {
- int px,py;
- int width,height;
- numRotations = numRotations % 4;
- if (numRotations == 0 ) return;
- if ( numRotations < 0 ) numRotations += 4;
- TCOD_image_get_size(image,&width,&height);
- if (numRotations == 1) {
- /* rotate 90 degrees */
- TCOD_image_t newImg=TCOD_image_new(height,width);
- image_data_t *img=(image_data_t *)image;
- image_data_t *img2=(image_data_t *)newImg;
- for (px = 0; px < width; px++ ) {
- for (py = 0; py < height; py++ ) {
- TCOD_color_t col1=TCOD_image_get_pixel(image,px,py);
- TCOD_image_put_pixel(newImg,height-1-py,px,col1);
- }
- }
- TCOD_image_delete_internal(image);
- /* update img with the new image content */
- img->mipmaps = img2->mipmaps;
- img->sys_img=NULL;
- img->nb_mipmaps=img2->nb_mipmaps;
- free(img2);
- } else if ( numRotations == 2 ) {
- /* rotate 180 degrees */
- int maxy=height/2 + ((height & 1) == 1? 1 : 0 );
- for (px = 0; px < width; px++ ) {
- for (py = 0; py < maxy; py++ ) {
- if ( py != height-1-py || px < width/2 ) {
- TCOD_color_t col1=TCOD_image_get_pixel(image,px,py);
- TCOD_color_t col2=TCOD_image_get_pixel(image,width-1-px,height-1-py);
- TCOD_image_put_pixel(image,px,py,col2);
- TCOD_image_put_pixel(image,width-1-px,height-1-py,col1);
- }
- }
- }
- } else if (numRotations == 3) {
- /* rotate 270 degrees */
- TCOD_image_t newImg=TCOD_image_new(height,width);
- image_data_t *img=(image_data_t *)image;
- image_data_t *img2=(image_data_t *)newImg;
- for (px = 0; px < width; px++ ) {
- for (py = 0; py < height; py++ ) {
- TCOD_color_t col1=TCOD_image_get_pixel(image,px,py);
- TCOD_image_put_pixel(newImg,py,width-1-px,col1);
- }
- }
- TCOD_image_delete_internal(image);
- /* update img with the new image content */
- img->mipmaps = img2->mipmaps;
- img->sys_img=NULL;
- img->nb_mipmaps=img2->nb_mipmaps;
- free(img2);
- }
-}
-
-void TCOD_image_scale(TCOD_image_t image, int neww, int newh) {
- image_data_t *img=(image_data_t *)image;
- int px,py;
- int width,height;
- image_data_t *newimg;
- TCOD_image_get_size(image,&width,&height);
- if ( neww==width && newh==height ) return;
- if ( neww == 0 || newh == 0 ) return;
- newimg=(image_data_t *)TCOD_image_new(neww,newh);
-
- if ( neww < width && newh < height ) {
- /* scale down image, using supersampling */
- for (py = 0; py < newh; py++ ) {
- float y0 = (float)(py) * height / newh;
- float y0floor = (float)floor(y0);
- float y0weight = 1.0f - (y0 - y0floor);
- int iy0 = (int)y0floor;
-
- float y1 = (float)(py+1) * height / newh;
- float y1floor = (float)floor(y1-0.00001);
- float y1weight = (y1 - y1floor);
- int iy1 = (int)y1floor;
-
- for (px = 0; px < neww; px++ ) {
- TCOD_color_t col;
- float x0 = (float)(px) * width / neww;
- float x0floor = (float)floor(x0);
- float x0weight = 1.0f - (x0 - x0floor);
- int ix0 = (int)x0floor;
-
- float x1 = (float)(px+1) * width / neww;
- float x1floor = (float)floor(x1- 0.00001);
- float x1weight = (x1 - x1floor);
- int ix1 = (int)x1floor;
-
- float r=0,g=0,b=0,sumweight=0.0f;
- int srcx,srcy;
- /* left & right fractional edges */
- for (srcy=(int)(y0+1); srcy < (int)y1; srcy++) {
- TCOD_color_t col_left=TCOD_image_get_pixel(image,ix0,srcy);
- TCOD_color_t col_right=TCOD_image_get_pixel(image,ix1,srcy);
- r += col_left.r * x0weight + col_right.r * x1weight;
- g += col_left.g * x0weight + col_right.g * x1weight;
- b += col_left.b * x0weight + col_right.b * x1weight;
- sumweight += x0weight+x1weight;
- }
- /* top & bottom fractional edges */
- for (srcx = (int)(x0+1); srcx < (int)x1; srcx++) {
- TCOD_color_t col_top=TCOD_image_get_pixel(image,srcx,iy0);
- TCOD_color_t col_bottom=TCOD_image_get_pixel(image,srcx,iy1);
- r += col_top.r * y0weight + col_bottom.r * y1weight;
- g += col_top.g * y0weight + col_bottom.g * y1weight;
- b += col_top.b * y0weight + col_bottom.b * y1weight;
- sumweight += y0weight+y1weight;
- }
- /* center */
- for (srcy=(int)(y0+1); srcy < (int)y1; srcy++) {
- for (srcx = (int)(x0+1); srcx < (int)x1; srcx++) {
- TCOD_color_t col=TCOD_image_get_pixel(image,srcx,srcy);
- r += col.r;
- g += col.g;
- b += col.b;
- sumweight += 1.0f;
- }
- }
- /* corners */
- col=TCOD_image_get_pixel(image,ix0,iy0);
- r += col.r * (x0weight * y0weight);
- g += col.g * (x0weight * y0weight);
- b += col.b * (x0weight * y0weight);
- sumweight += x0weight * y0weight;
- col=TCOD_image_get_pixel(image,ix0,iy1);
- r += col.r * (x0weight * y1weight);
- g += col.g * (x0weight * y1weight);
- b += col.b * (x0weight * y1weight);
- sumweight += x0weight * y1weight;
- col=TCOD_image_get_pixel(image,ix1,iy1);
- r += col.r * (x1weight * y1weight);
- g += col.g * (x1weight * y1weight);
- b += col.b * (x1weight * y1weight);
- sumweight += x1weight * y1weight;
- col=TCOD_image_get_pixel(image,ix1,iy0);
- r += col.r * (x1weight * y0weight);
- g += col.g * (x1weight * y0weight);
- b += col.b * (x1weight * y0weight);
- sumweight += x1weight * y0weight;
- sumweight = 1.0f / sumweight;
- r = r*sumweight + 0.5f;
- g = g*sumweight + 0.5f;
- b = b*sumweight + 0.5f;
- col.r=(int)r;
- col.g=(int)g;
- col.b=(int)b;
- TCOD_image_put_pixel(newimg,px,py,col);
- }
- }
- } else {
- /* scale up image, using nearest neightbor */
- for (py = 0; py < newh; py++ ) {
- int srcy = py * height / newh;
- for (px = 0; px < neww; px++ ) {
- int srcx = px * width / neww;
- TCOD_color_t col=TCOD_image_get_pixel(image,srcx,srcy);
- TCOD_image_put_pixel(newimg,px,py,col);
- }
- }
- }
-
- /* destroy old image */
- TCOD_image_delete_internal(image);
- /* update img with the new image content */
- img->mipmaps = newimg->mipmaps;
- img->sys_img=NULL;
- img->nb_mipmaps=newimg->nb_mipmaps;
- free(newimg);
-}
-
-
-/* distance between two colors */
-int rgbdist(const TCOD_color_t *c1,const TCOD_color_t *c2) {
- int dr=(int)(c1->r)-c2->r;
- int dg=(int)(c1->g)-c2->g;
- int db=(int)(c1->b)-c2->b;
- return dr*dr+dg*dg+db*db;
-}
-
-void getPattern(TCOD_color_t desired[4], TCOD_color_t palette[2], int *nbCols, int *ascii) {
- /* adapted from Jeff Lait's code posted on r.g.r.d */
- int flag=0;
- /*
- pixels have following flag values :
- X 1
- 2 4
- flag indicates which pixels uses foreground color (palette[1])
- */
- static int flagToAscii[8] = {
- 0,
- TCOD_CHAR_SUBP_NE,TCOD_CHAR_SUBP_SW,-TCOD_CHAR_SUBP_DIAG,TCOD_CHAR_SUBP_SE,
- TCOD_CHAR_SUBP_E,-TCOD_CHAR_SUBP_N,-TCOD_CHAR_SUBP_NW
- };
- int weight[2] = { 0, 0 };
- int i;
-
- /* First colour trivial. */
- palette[0] = desired[0];
-
- /* Ignore all duplicates... */
- for (i = 1; i < 4; i++) {
- if (desired[i].r != palette[0].r || desired[i].g != palette[0].g || desired[i].b != palette[0].b)
- break;
- }
-
- /* All the same. */
- if (i == 4) {
- *nbCols=1;
- return;
- }
- weight[0] = i;
-
- /* Found a second colour... */
- palette[1] = desired[i];
- weight[1] = 1;
- flag |= 1<<(i-1);
- *nbCols = 2;
- /* remaining colours */
- i++;
- while (i< 4) {
- if (desired[i].r == palette[0].r && desired[i].g == palette[0].g && desired[i].b == palette[0].b) {
- weight[0]++;
- } else if (desired[i].r == palette[1].r && desired[i].g == palette[1].g && desired[i].b == palette[1].b) {
- flag |= 1<<(i-1);
- weight[1]++;
- } else {
- /* Bah, too many colours, */
- /* merge the two nearest */
- int dist0i=rgbdist(&desired[i], &palette[0]);
- int dist1i=rgbdist(&desired[i], &palette[1]);
- int dist01=rgbdist(&palette[0],&palette[1]);
- if ( dist0i < dist1i ) {
- if ( dist0i <= dist01 ) {
- /* merge 0 and i */
- palette[0]=TCOD_color_lerp(desired[i],palette[0],weight[0]/(1.0f+weight[0]));
- weight[0]++;
- } else {
- /* merge 0 and 1 */
- palette[0]=TCOD_color_lerp(palette[0],palette[1],(float)(weight[1])/(weight[0]+weight[1]));
- weight[0]++;
- palette[1]=desired[i];
- flag=1<<(i-1);
- }
- } else {
- if ( dist1i <= dist01 ) {
- /* merge 1 and i */
- palette[1]=TCOD_color_lerp(desired[i],palette[1],weight[1]/(1.0f+weight[1]));
- weight[1]++;
- flag|=1<<(i-1);
- } else {
- /* merge 0 and 1 */
- palette[0]=TCOD_color_lerp(palette[0],palette[1],(float)(weight[1])/(weight[0]+weight[1]));
- weight[0]++;
- palette[1]=desired[i];
- flag=1<<(i-1);
- }
- }
- }
- i++;
- }
- *ascii=flagToAscii[flag];
-}
-
-#ifdef TCOD_CONSOLE_SUPPORT
-
-void TCOD_image_blit_2x(TCOD_image_t image, TCOD_console_t con, int dx, int dy, int sx, int sy, int w, int h) {
- TCOD_color_t grid[4];
- TCOD_color_t cols[2];
- int nbCols;
- int width,height,ascii,cx,cy;
- TCOD_console_data_t *dat = con ? (TCOD_console_data_t *)(con) : TCOD_ctx.root;
- image_data_t *img=(image_data_t *)image;
- int maxx,maxy;
- TCOD_IFNOT(image != NULL && dat != NULL) return;
-
- TCOD_image_get_size(image,&width,&height);
- if ( w == -1 ) w=width;
- if ( h == -1 ) h=height;
-
- /* check that the sx,sy/w,h rectangle is inside the image */
- TCOD_ASSERT(sx >= 0 && sy >= 0 && sx+w <= width && sy+h <= height);
- TCOD_IFNOT(w > 0 && h > 0) return;
-
- sx=MAX(0,sx);
- sy=MAX(0,sy);
- w = MIN(w,width-sx);
- h = MIN(h,height-sy);
-
- maxx=dx+w/2 <= dat->w ? w : (dat->w-dx)*2;
- maxy=dy+h/2 <= dat->h ? h : (dat->h-dy)*2;
- /* check that the image is not blitted outside the console */
- TCOD_IFNOT(dx+maxx/2 >= 0 && dy+maxy/2 >= 0 && dx < dat->w && dy < dat->h) return;
- maxx+=sx;
- maxy+=sy;
-
- for (cx=sx; cx < maxx; cx += 2) {
- for (cy=sy; cy < maxy; cy += 2) {
- /* get the 2x2 super pixel colors from the image */
- int conx=dx+(cx-sx)/2;
- int cony=dy+(cy-sy)/2;
- TCOD_color_t consoleBack=TCOD_console_get_char_background(con,conx,cony);
- grid[0]=TCOD_image_get_pixel(image,cx,cy);
- if ( img->has_key_color && grid[0].r == img->key_color.r && grid[0].g == img->key_color.g && grid[0].b == img->key_color.b)
- grid[0]=consoleBack;
- if ( cx < maxx-1 ) {
- grid[1]=TCOD_image_get_pixel(image,cx+1,cy);
- if ( img->has_key_color && grid[1].r == img->key_color.r && grid[1].g == img->key_color.g && grid[1].b == img->key_color.b)
- grid[1]=consoleBack;
- } else grid[1]=consoleBack;
- if ( cy < maxy-1 ) {
- grid[2]=TCOD_image_get_pixel(image,cx,cy+1);
- if ( img->has_key_color && grid[2].r == img->key_color.r && grid[2].g == img->key_color.g && grid[2].b == img->key_color.b)
- grid[2]=consoleBack;
- } else grid[2]=consoleBack;
- if ( cx < maxx-1 && cy < maxy-1 ) {
- grid[3]=TCOD_image_get_pixel(image,cx+1,cy+1);
- if ( img->has_key_color && grid[3].r == img->key_color.r && grid[3].g == img->key_color.g && grid[3].b == img->key_color.b)
- grid[3]=consoleBack;
- } else grid[3]=consoleBack;
- /* analyse color, posterize, get pattern */
- getPattern(grid,cols,&nbCols,&ascii);
- if ( nbCols == 1 ) {
- /* single color */
- TCOD_console_set_char_background(con,conx,cony,cols[0],TCOD_BKGND_SET);
- TCOD_console_set_char(con,conx,cony,' ');
- } else {
- if ( ascii >= 0 ) {
- TCOD_console_set_char_background(con,conx,cony,cols[0],TCOD_BKGND_SET);
- TCOD_console_set_char_foreground(con,conx,cony,cols[1]);
- TCOD_console_set_char(con,conx,cony,ascii);
- } else {
- /* negative ascii code means we need to invert back/fore colors */
- TCOD_console_set_char_background(con,conx,cony,cols[1],TCOD_BKGND_SET);
- TCOD_console_set_char_foreground(con,conx,cony,cols[0]);
- TCOD_console_set_char(con,conx,cony,-ascii);
- }
- }
- }
- }
-}
-
-#endif /* TCOD_CONSOLE_SUPPORT */
-
-#endif /* TCOD_IMAGE_SUPPORT */
diff --git a/tcod_sys/libtcod/src/lex.cpp b/tcod_sys/libtcod/src/lex.cpp
deleted file mode 100644
index a1858ee52..000000000
--- a/tcod_sys/libtcod/src/lex.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#include "lex.hpp"
-
-#include
-#include
-#include
-#include
-#include
-
-#include
-
-TCODLex::TCODLex( const char **_symbols, const char **_keywords, const char *simpleComment,
- const char *commentStart, const char *commentStop, const char *javadocCommentStart,
- const char *_stringDelim, int _flags)
-{
- data=(void *)TCOD_lex_new(_symbols,_keywords,simpleComment,commentStart,commentStop,javadocCommentStart,_stringDelim,_flags);
-
-}
-
-TCODLex::TCODLex()
-{
- data= (void *)TCOD_lex_new_intern();
-}
-
-TCODLex::~TCODLex()
-{
- TCOD_lex_delete((TCOD_lex_t *)data);
-}
-
-char *TCODLex::getLastJavadoc()
-{
- return TCOD_lex_get_last_javadoc((TCOD_lex_t *)data);
-}
-
-
-void TCODLex::setDataBuffer(char *dat)
-{
- TCOD_lex_set_data_buffer((TCOD_lex_t *)data,dat);
-}
-
-bool TCODLex::setDataFile(const char *_filename)
-{
- return TCOD_lex_set_data_file((TCOD_lex_t *)data,_filename) != 0;
-}
-
-int TCODLex::parse()
-{
- return TCOD_lex_parse((TCOD_lex_t *)data);
-}
-
-
-int TCODLex::parseUntil(int tokenType)
-{
- return TCOD_lex_parse_until_token_type((TCOD_lex_t *)data,tokenType);
-}
-
-int TCODLex::parseUntil(const char *tokenValue)
-{
- return TCOD_lex_parse_until_token_value((TCOD_lex_t *)data,tokenValue);
-}
-
-void TCODLex::savepoint(TCODLex *savepoint)
-{
- TCOD_lex_savepoint((TCOD_lex_t *)data,(TCOD_lex_t *)(savepoint->data));
-}
-
-void TCODLex::restore(TCODLex *savepoint)
-{
- TCOD_lex_restore((TCOD_lex_t *)data,(TCOD_lex_t *)(savepoint->data));
-}
-
-bool TCODLex::expect(int tokenType)
-{
- return TCOD_lex_expect_token_type((TCOD_lex_t *)data,tokenType) != 0;
-}
-
-bool TCODLex::expect(int tokenType, const char *tokenValue)
-{
- return TCOD_lex_expect_token_value((TCOD_lex_t *)data,tokenType,tokenValue) != 0;
-}
-
diff --git a/tcod_sys/libtcod/src/libtcod/bresenham.cpp b/tcod_sys/libtcod/src/libtcod/bresenham.cpp
new file mode 100644
index 000000000..406fc1e68
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/bresenham.cpp
@@ -0,0 +1,53 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "bresenham.hpp"
+
+// ********** bresenham line drawing **********
+void TCODLine::init(int xFrom, int yFrom, int xTo, int yTo) {
+ TCOD_line_init(xFrom,yFrom,xTo,yTo);
+}
+
+bool TCODLine::step(int *xCur, int *yCur) {
+ return TCOD_line_step(xCur,yCur) != 0;
+}
+
+static TCODLineListener *line_listener=NULL;
+
+// C to C++ bridge
+extern "C" bool internalListener(int x,int y) {
+ return line_listener->putPoint(x,y) ? 1 : 0;
+}
+
+bool TCODLine::line(int xFrom, int yFrom, int xTo, int yTo, TCODLineListener *plistener) {
+ line_listener=plistener;
+ return TCOD_line(xFrom,yFrom,xTo,yTo,internalListener) != 0;
+}
diff --git a/tcod_sys/libtcod/src/libtcod/bresenham.h b/tcod_sys/libtcod/src/libtcod/bresenham.h
new file mode 100644
index 000000000..9796feeab
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/bresenham.h
@@ -0,0 +1,85 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _TCOD_BRESENHAM_H
+#define _TCOD_BRESENHAM_H
+
+#include "portability.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+/**
+ * \brief A callback to be passed to TCOD_line
+ *
+ * The points given to the callback include both the starting and ending
+ * positions.
+ *
+ * \param x
+ * \param y
+ * \return As long as this callback returns true it will be called with the
+ * next x,y point on the line.
+ */
+typedef bool (*TCOD_line_listener_t) (int x, int y);
+
+TCODLIB_API TCOD_DEPRECATED(
+ "This function is not reentrant. Use TCOD_line_init_mt instead.")
+void TCOD_line_init(int xFrom, int yFrom, int xTo, int yTo);
+
+TCODLIB_API TCOD_DEPRECATED("This function is not reentrant.")
+bool TCOD_line_step(int *xCur, int *yCur); /* advance one step. returns true if we reach destination */
+
+/* atomic callback function. Stops when the callback returns false */
+TCODLIB_API bool TCOD_line(int xFrom, int yFrom, int xTo, int yTo, TCOD_line_listener_t listener);
+/**
+ * \brief A struct used for computing a bresenham line.
+ */
+typedef struct {
+ int stepx;
+ int stepy;
+ int e;
+ int deltax;
+ int deltay;
+ int origx;
+ int origy;
+ int destx;
+ int desty;
+} TCOD_bresenham_data_t;
+
+TCODLIB_API void TCOD_line_init_mt(int xFrom, int yFrom, int xTo, int yTo, TCOD_bresenham_data_t *data);
+TCODLIB_API bool TCOD_line_step_mt(int *xCur, int *yCur, TCOD_bresenham_data_t *data);
+
+TCOD_DEPRECATED("Use TCOD_line instead.")
+TCODLIB_API bool TCOD_line_mt(int xFrom, int yFrom, int xTo, int yTo, TCOD_line_listener_t listener, TCOD_bresenham_data_t *data);
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/tcod_sys/libtcod/include/bresenham.hpp b/tcod_sys/libtcod/src/libtcod/bresenham.hpp
similarity index 67%
rename from tcod_sys/libtcod/include/bresenham.hpp
rename to tcod_sys/libtcod/src/libtcod/bresenham.hpp
index 1fac4f1df..389d5c222 100644
--- a/tcod_sys/libtcod/include/bresenham.hpp
+++ b/tcod_sys/libtcod/src/libtcod/bresenham.hpp
@@ -1,30 +1,34 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
#ifndef _TCOD_BRESENHAM_HPP
#define _TCOD_BRESENHAM_HPP
@@ -54,7 +58,7 @@ public :
@Param xTo,yTo Coordinates of the line's ending point.
*/
static void init(int xFrom, int yFrom, int xTo, int yTo);
-
+
/**
@PageName line
@FuncTitle Walking the line
@@ -65,20 +69,20 @@ public :
@C# static bool TCODLine::step(ref int xCur, ref int yCur)
@Lua tcod.line.step(x,y) -- returns lineEnd,x,y
@Param xCur,yCur the coordinates of the next cell on the line are stored here when the function returns
- @CppEx
+ @CppEx
// Going from point 5,8 to point 13,4
int x = 5, y = 8;
TCODLine::init(x,y,13,4);
do {
// update cell x,y
} while (!TCODLine::step(&x,&y));
- @CEx
+ @CEx
int x = 5, y = 8;
TCOD_line_init(x,y,13,4);
do {
- // update cell x,y
+ // update cell x,y
} while (!TCOD_line_step(&x,&y));
- @PyEx
+ @PyEx
libtcod.line_init(5,8,13,4)
# update cell 5,8
x,y=libtcod.line_step()
@@ -92,8 +96,8 @@ public :
repeat
-- update cell x,y
lineEnd,x,y = tcod.line.step(x,y)
- until lineEnd
- */
+ until lineEnd
+ */
static bool step(int *xCur, int *yCur);
/**
@@ -133,7 +137,7 @@ TCOD_line_line(5,8,13,4,my_listener);
@PyEx def my_listener(x,y):
print x,y
return True
-libtcod.line_line(5,8,13,4,my_listener)
+libtcod.line_line(5,8,13,4,my_listener)
*/
static bool line(int xFrom, int yFrom, int xTo, int yTo, TCODLineListener *listener);
};
diff --git a/tcod_sys/libtcod/src/libtcod/bresenham_c.c b/tcod_sys/libtcod/src/libtcod/bresenham_c.c
new file mode 100644
index 000000000..8daab957f
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/bresenham_c.c
@@ -0,0 +1,193 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "bresenham.h"
+/**
+ * \file bresenham_c.c
+ * \brief bresenham line drawing
+ */
+/* This static variable is deprecated since 1.6 */
+static TCOD_bresenham_data_t bresenham_data;
+/**
+ * \brief Initialize a TCOD_bresenham_data_t struct.
+ *
+ * \param xFrom The starting x position.
+ * \param yFrom The starting y position.
+ * \param xTo The ending x position.
+ * \param yTo The ending y position.
+ * \param data Pointer to a TCOD_bresenham_data_t struct.
+ *
+ * After calling this function you use TCOD_line_step_mt to iterate
+ * over the individual points on the line.
+ */
+void TCOD_line_init_mt(int xFrom, int yFrom, int xTo, int yTo, TCOD_bresenham_data_t *data) {
+ data->origx=xFrom;
+ data->origy=yFrom;
+ data->destx=xTo;
+ data->desty=yTo;
+ data->deltax=xTo - xFrom;
+ data->deltay=yTo - yFrom;
+ if ( data->deltax > 0 ) {
+ data->stepx=1;
+ } else if ( data->deltax < 0 ){
+ data->stepx=-1;
+ } else data->stepx=0;
+ if ( data->deltay > 0 ) {
+ data->stepy=1;
+ } else if ( data->deltay < 0 ){
+ data->stepy=-1;
+ } else data->stepy = 0;
+ if ( data->stepx*data->deltax > data->stepy*data->deltay ) {
+ data->e = data->stepx*data->deltax;
+ data->deltax *= 2;
+ data->deltay *= 2;
+ } else {
+ data->e = data->stepy*data->deltay;
+ data->deltax *= 2;
+ data->deltay *= 2;
+ }
+}
+/**
+ * \brief Get the next point on a line, returns true once the line has ended.
+ *
+ * \param xCur An int pointer to fill with the next x position.
+ * \param yCur An int pointer to fill with the next y position.
+ * \param data Pointer to a initialized TCOD_bresenham_data_t struct.
+ * \return true after the ending point has been reached.
+ *
+ * The starting point is excluded by this function.
+ * After the ending point is reached, the next call will return true.
+ */
+bool TCOD_line_step_mt(int *xCur, int *yCur, TCOD_bresenham_data_t *data) {
+ if ( data->stepx*data->deltax > data->stepy*data->deltay ) {
+ if ( data->origx == data->destx ) return true;
+ data->origx+=data->stepx;
+ data->e -= data->stepy*data->deltay;
+ if ( data->e < 0) {
+ data->origy+=data->stepy;
+ data->e+=data->stepx*data->deltax;
+ }
+ } else {
+ if ( data->origy == data->desty ) return true;
+ data->origy+=data->stepy;
+ data->e -= data->stepx*data->deltax;
+ if ( data->e < 0) {
+ data->origx+=data->stepx;
+ data->e+=data->stepy*data->deltay;
+ }
+ }
+ *xCur=data->origx;
+ *yCur=data->origy;
+ return false;
+}
+/**
+ * \brief Iterate over a line using a callback.
+ *
+ * \param xo The origin x position.
+ * \param yo The origin y position.
+ * \param xd The destination x position.
+ * \param yd The destination y position.
+ * \param listener A TCOD_line_listener_t callback.
+ * \param data Pointer to a TCOD_bresenham_data_t struct.
+ * \return true if the line was completely exhausted by the callback.
+ *
+ * \verbatim embed:rst:leading-asterisk
+ * .. deprecated:: 1.6.6
+ * The `data` parameter for this call is redundant, you should call
+ * :any:`TCOD_line` instead.
+ * \endverbatim
+ */
+bool TCOD_line_mt(int xo, int yo, int xd, int yd, TCOD_line_listener_t listener, TCOD_bresenham_data_t *data) {
+ TCOD_line_init_mt(xo,yo,xd,yd,data);
+ do {
+ if (! listener(xo,yo)) return false;
+ } while (! TCOD_line_step_mt(&xo,&yo,data));
+ return true;
+}
+/**
+ * \brief Initialize a line using a global state.
+ *
+ * \param xFrom The starting x position.
+ * \param yFrom The starting y position.
+ * \param xTo The ending x position.
+ * \param yTo The ending y position.
+ *
+ * \verbatim embed:rst:leading-asterisk
+ * .. deprecated:: 1.6.6
+ * This function is not reentrant and will fail if a new line is started
+ * before the last is finished processing.
+ *
+ * Use :any:`TCOD_line_init_mt` instead.
+ * \endverbatim
+ */
+void TCOD_line_init(int xFrom, int yFrom, int xTo, int yTo) {
+ TCOD_line_init_mt(xFrom,yFrom,xTo,yTo,&bresenham_data);
+}
+/**
+ * \brief Get the next point in a line, returns true once the line has ended.
+ *
+ * \param xCur An int pointer to fill with the next x position.
+ * \param yCur An int pointer to fill with the next y position.
+ * \return true once the ending point has been reached.
+ *
+ * The starting point is excluded by this function.
+ * After the ending point is reached, the next call will return true.
+ *
+ * \verbatim embed:rst:leading-asterisk
+ * .. deprecated:: 1.6.6
+ * This function is not reentrant and will fail if a new line is started
+ * before the last is finished processing.
+ *
+ * Use :any:`TCOD_line_step_mt` instead.
+ * \endverbatim
+ */
+bool TCOD_line_step(int *xCur, int *yCur) {
+ return TCOD_line_step_mt(xCur,yCur,&bresenham_data);
+}
+/**
+ * \brief Iterate over a line using a callback.
+ *
+ * \param xo The origin x position.
+ * \param yo The origin y position.
+ * \param xd The destination x position.
+ * \param yd The destination y position.
+ * \param listener A TCOD_line_listener_t callback.
+ * \return true if the line was completely exhausted by the callback.
+ *
+ * \verbatim embed:rst:leading-asterisk
+ * .. versionchanged:: 1.6.6
+ * This function is now reentrant.
+ * \endverbatim
+ */
+bool TCOD_line(int xo, int yo, int xd, int yd, TCOD_line_listener_t listener) {
+ TCOD_bresenham_data_t bresenham_data;
+ return TCOD_line_mt(xo,yo,xd,yd,listener,&bresenham_data);
+}
diff --git a/tcod_sys/libtcod/src/bsp.cpp b/tcod_sys/libtcod/src/libtcod/bsp.cpp
similarity index 69%
rename from tcod_sys/libtcod/src/bsp.cpp
rename to tcod_sys/libtcod/src/libtcod/bsp.cpp
index 1b77d5368..e97b732c8 100644
--- a/tcod_sys/libtcod/src/bsp.cpp
+++ b/tcod_sys/libtcod/src/libtcod/bsp.cpp
@@ -1,168 +1,172 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#include
-
-TCODBsp::TCODBsp(TCODBsp *father, bool left) {
- if ( father->horizontal ) {
- x=father->x;
- w=father->w;
- y = left ? father->y : father->position;
- h = left ? father->position - y: father->y + father->h - father->position;
- } else {
- y=father->y;
- h=father->h;
- x = left ? father->x : father->position;
- w = left ? father->position - x: father->x + father->w - father->position;
- }
- level=father->level+1;
-}
-
-TCODBsp::~TCODBsp() {
- removeSons();
-}
-
-bool TCODBsp::traversePreOrder(ITCODBspCallback *listener, void *userData) {
- if (!listener->visitNode(this,userData)) return false;
- if ( getLeft() && !getLeft()->traversePreOrder(listener,userData) ) return false;
- if ( getRight() && !getRight()->traversePreOrder(listener,userData)) return false;
- return true;
-}
-
-bool TCODBsp::traverseInOrder(ITCODBspCallback *listener, void *userData) {
- if ( getLeft() && !getLeft()->traverseInOrder(listener,userData) ) return false;
- if (!listener->visitNode(this,userData)) return false;
- if ( getRight() && !getRight()->traverseInOrder(listener,userData)) return false;
- return true;
-}
-
-bool TCODBsp::traversePostOrder(ITCODBspCallback *listener,void *userData) {
- if ( getLeft() && !getLeft()->traversePostOrder(listener,userData)) return false;
- if ( getRight() && !getRight()->traversePostOrder(listener,userData)) return false;
- if (!listener->visitNode(this,userData)) return false;
- return true;
-}
-
-bool TCODBsp::traverseLevelOrder(ITCODBspCallback *listener, void *userData) {
- TCODList stack;
- stack.push(this);
- while ( ! stack.isEmpty() ) {
- TCODBsp *node=stack.get(0);
- stack.remove(node);
- if ( node->getLeft() ) stack.push(node->getLeft());
- if ( node->getRight() ) stack.push(node->getRight());
- if (!listener->visitNode(node,userData)) return false;
- }
- return true;
-}
-
-bool TCODBsp::traverseInvertedLevelOrder(ITCODBspCallback *listener, void *userData) {
- TCODList stack1;
- TCODList stack2;
- stack1.push(this);
- while ( ! stack1.isEmpty() ) {
- TCODBsp *node=stack1.get(0);
- stack2.push(node);
- stack1.remove(node);
- if ( node->getLeft() ) stack1.push(node->getLeft());
- if ( node->getRight() ) stack1.push(node->getRight());
- }
- while ( ! stack2.isEmpty() ) {
- TCODBsp *node=stack2.pop();
- if (!listener->visitNode(node,userData)) return false;
- }
- return true;
-}
-
-void TCODBsp::removeSons() {
- TCODBsp *node=(TCODBsp *)sons;
- while ( node ) {
- TCODBsp *nextNode=(TCODBsp *)node->next;
- node->removeSons();
- delete node;
- node=nextNode;
- }
- sons=NULL;
-}
-
-void TCODBsp::splitOnce(bool horizontal, int position) {
- this->horizontal = horizontal;
- this->position=position;
- addSon(new TCODBsp(this,true));
- addSon(new TCODBsp(this,false));
-}
-
-void TCODBsp::splitRecursive(TCODRandom *randomizer, int nb, int minHSize, int minVSize, float maxHRatio, float maxVRatio) {
- if ( nb == 0 || (w < 2*minHSize && h < 2*minVSize ) ) return;
- bool horiz;
- if (! randomizer ) randomizer=TCODRandom::getInstance();
- // promote square rooms
- if ( h < 2*minVSize || w > h * maxHRatio ) horiz = false;
- else if ( w < 2*minHSize || h > w * maxVRatio) horiz = true;
- else horiz = randomizer->getInt(0,1) == 0;
- int position;
- if ( horiz ) {
- position = randomizer->getInt(y+minVSize,y+h-minVSize);
- } else {
- position = randomizer->getInt(x+minHSize,x+w-minHSize);
- }
- splitOnce(horiz,position);
- getLeft()->splitRecursive(randomizer,nb-1,minHSize,minVSize,maxHRatio,maxVRatio);
- getRight()->splitRecursive(randomizer,nb-1,minHSize,minVSize,maxHRatio,maxVRatio);
-}
-
-void TCODBsp::resize(int x,int y, int w, int h) {
- this->x=x;
- this->y=y;
- this->w=w;
- this->h=h;
- if ( getLeft() ) {
- if ( horizontal ) {
- getLeft()->resize(x,y,w,position-y);
- getRight()->resize(x,position,w,y+h-position);
- } else {
- getLeft()->resize(x,y,position-x,h);
- getRight()->resize(position,y,x+w-position,h);
- }
- }
-}
-
-bool TCODBsp::contains(int px, int py) const {
- return (px >= x && py >= y && px < x+w && py < y+h);
-}
-
-TCODBsp *TCODBsp::findNode(int px, int py) {
- if ( ! contains(px,py) ) return NULL;
- if ( ! isLeaf() ) {
- TCODBsp *left,*right;
- left=getLeft();
- if ( left->contains(px,py) ) return left->findNode(px,py);
- right=getRight();
- if ( right->contains(px,py) ) return right->findNode(px,py);
- }
- return this;
-}
-
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "bsp.hpp"
+
+TCODBsp::TCODBsp(TCODBsp *father, bool left) {
+ if ( father->horizontal ) {
+ x=father->x;
+ w=father->w;
+ y = left ? father->y : father->position;
+ h = left ? father->position - y: father->y + father->h - father->position;
+ } else {
+ y=father->y;
+ h=father->h;
+ x = left ? father->x : father->position;
+ w = left ? father->position - x: father->x + father->w - father->position;
+ }
+ level=father->level+1;
+}
+
+TCODBsp::~TCODBsp() {
+ removeSons();
+}
+
+bool TCODBsp::traversePreOrder(ITCODBspCallback *listener, void *userData) {
+ if (!listener->visitNode(this,userData)) return false;
+ if ( getLeft() && !getLeft()->traversePreOrder(listener,userData) ) return false;
+ if ( getRight() && !getRight()->traversePreOrder(listener,userData)) return false;
+ return true;
+}
+
+bool TCODBsp::traverseInOrder(ITCODBspCallback *listener, void *userData) {
+ if ( getLeft() && !getLeft()->traverseInOrder(listener,userData) ) return false;
+ if (!listener->visitNode(this,userData)) return false;
+ if ( getRight() && !getRight()->traverseInOrder(listener,userData)) return false;
+ return true;
+}
+
+bool TCODBsp::traversePostOrder(ITCODBspCallback *listener,void *userData) {
+ if ( getLeft() && !getLeft()->traversePostOrder(listener,userData)) return false;
+ if ( getRight() && !getRight()->traversePostOrder(listener,userData)) return false;
+ if (!listener->visitNode(this,userData)) return false;
+ return true;
+}
+
+bool TCODBsp::traverseLevelOrder(ITCODBspCallback *listener, void *userData) {
+ TCODList stack;
+ stack.push(this);
+ while ( ! stack.isEmpty() ) {
+ TCODBsp *node=stack.get(0);
+ stack.remove(node);
+ if ( node->getLeft() ) stack.push(node->getLeft());
+ if ( node->getRight() ) stack.push(node->getRight());
+ if (!listener->visitNode(node,userData)) return false;
+ }
+ return true;
+}
+
+bool TCODBsp::traverseInvertedLevelOrder(ITCODBspCallback *listener, void *userData) {
+ TCODList stack1;
+ TCODList stack2;
+ stack1.push(this);
+ while ( ! stack1.isEmpty() ) {
+ TCODBsp *node=stack1.get(0);
+ stack2.push(node);
+ stack1.remove(node);
+ if ( node->getLeft() ) stack1.push(node->getLeft());
+ if ( node->getRight() ) stack1.push(node->getRight());
+ }
+ while ( ! stack2.isEmpty() ) {
+ TCODBsp *node=stack2.pop();
+ if (!listener->visitNode(node,userData)) return false;
+ }
+ return true;
+}
+
+void TCODBsp::removeSons() {
+ TCODBsp *node = static_cast(sons);
+ while ( node ) {
+ TCODBsp *nextNode = static_cast(node->next);
+ node->removeSons();
+ delete node;
+ node=nextNode;
+ }
+ sons=NULL;
+}
+
+void TCODBsp::splitOnce(bool horizontal, int position) {
+ this->horizontal = horizontal;
+ this->position=position;
+ addSon(new TCODBsp(this,true));
+ addSon(new TCODBsp(this,false));
+}
+
+void TCODBsp::splitRecursive(TCODRandom *randomizer, int nb, int minHSize, int minVSize, float maxHRatio, float maxVRatio) {
+ if ( nb == 0 || (w < 2*minHSize && h < 2*minVSize ) ) return;
+ bool horiz;
+ if (! randomizer ) randomizer=TCODRandom::getInstance();
+ // promote square rooms
+ if ( h < 2*minVSize || w > h * maxHRatio ) horiz = false;
+ else if ( w < 2*minHSize || h > w * maxVRatio) horiz = true;
+ else horiz = randomizer->getInt(0,1) == 0;
+ int position;
+ if ( horiz ) {
+ position = randomizer->getInt(y+minVSize,y+h-minVSize);
+ } else {
+ position = randomizer->getInt(x+minHSize,x+w-minHSize);
+ }
+ splitOnce(horiz,position);
+ getLeft()->splitRecursive(randomizer,nb-1,minHSize,minVSize,maxHRatio,maxVRatio);
+ getRight()->splitRecursive(randomizer,nb-1,minHSize,minVSize,maxHRatio,maxVRatio);
+}
+
+void TCODBsp::resize(int x,int y, int w, int h) {
+ this->x=x;
+ this->y=y;
+ this->w=w;
+ this->h=h;
+ if ( getLeft() ) {
+ if ( horizontal ) {
+ getLeft()->resize(x,y,w,position-y);
+ getRight()->resize(x,position,w,y+h-position);
+ } else {
+ getLeft()->resize(x,y,position-x,h);
+ getRight()->resize(position,y,x+w-position,h);
+ }
+ }
+}
+
+bool TCODBsp::contains(int px, int py) const {
+ return (px >= x && py >= y && px < x+w && py < y+h);
+}
+
+TCODBsp *TCODBsp::findNode(int px, int py) {
+ if ( ! contains(px,py) ) return NULL;
+ if ( ! isLeaf() ) {
+ TCODBsp *left,*right;
+ left=getLeft();
+ if ( left->contains(px,py) ) return left->findNode(px,py);
+ right=getRight();
+ if ( right->contains(px,py) ) return right->findNode(px,py);
+ }
+ return this;
+}
diff --git a/tcod_sys/libtcod/include/bsp.h b/tcod_sys/libtcod/src/libtcod/bsp.h
similarity index 53%
rename from tcod_sys/libtcod/include/bsp.h
rename to tcod_sys/libtcod/src/libtcod/bsp.h
index ae3a31326..1e5156144 100644
--- a/tcod_sys/libtcod/include/bsp.h
+++ b/tcod_sys/libtcod/src/libtcod/bsp.h
@@ -1,34 +1,38 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
#ifndef _TCOD_BSP_H
#define _TCOD_BSP_H
-#include "libtcod_portability.h"
+#include "portability.h"
#include "mersenne_types.h"
#include "tree.h"
@@ -63,7 +67,7 @@ TCODLIB_API bool TCOD_bsp_contains(TCOD_bsp_t *node, int x, int y);
TCODLIB_API TCOD_bsp_t * TCOD_bsp_find_node(TCOD_bsp_t *node, int x, int y);
TCODLIB_API void TCOD_bsp_resize(TCOD_bsp_t *node, int x,int y, int w, int h);
TCODLIB_API void TCOD_bsp_split_once(TCOD_bsp_t *node, bool horizontal, int position);
-TCODLIB_API void TCOD_bsp_split_recursive(TCOD_bsp_t *node, TCOD_random_t randomizer, int nb,
+TCODLIB_API void TCOD_bsp_split_recursive(TCOD_bsp_t *node, TCOD_random_t randomizer, int nb,
int minHSize, int minVSize, float maxHRatio, float maxVRatio);
TCODLIB_API void TCOD_bsp_remove_sons(TCOD_bsp_t *node);
#ifdef __cplusplus
diff --git a/tcod_sys/libtcod/include/bsp.hpp b/tcod_sys/libtcod/src/libtcod/bsp.hpp
similarity index 86%
rename from tcod_sys/libtcod/include/bsp.hpp
rename to tcod_sys/libtcod/src/libtcod/bsp.hpp
index d20c003be..6ebc3fec2 100644
--- a/tcod_sys/libtcod/include/bsp.hpp
+++ b/tcod_sys/libtcod/src/libtcod/bsp.hpp
@@ -1,30 +1,34 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
#ifndef _TCOD_BSP_HPP
#define _TCOD_BSP_HPP
@@ -50,11 +54,11 @@ public :
class TCODLIB_API TCODBsp : public TCODTree {
public :
- int x,y,w,h; //
+ int x,y,w,h; //
int position; // position of splitting
bool horizontal; // horizontal splitting ?
- uint8_t level; // level in the tree
-
+ uint8_t level; // level in the tree
+
/**
@PageName bsp_init
@PageFather bsp
@@ -82,20 +86,20 @@ public :
@Py bsp_remove_sons(node)
@C# TCODBsp::removeSons()
@Param node In the C version, the node reference.
- @CppEx
+ @CppEx
TCODBsp *myBSP = new TCODBsp(0,0,50,50);
// create a tree
- myBSP->splitRecursive(NULL,4,5,5,1.5f,1.5f);
+ myBSP->splitRecursive(NULL,4,5,5,1.5f,1.5f);
// clear it (keep only the root)
myBSP->removeSons();
// and rebuild another random tree
- myBSP->splitRecursive(NULL,4,5,5,1.5f,1.5f);
- @CEx
+ myBSP->splitRecursive(NULL,4,5,5,1.5f,1.5f);
+ @CEx
TCOD_bsp_t *my_bsp=TCOD_bsp_new_with_size(0,0,50,50);
TCOD_bsp_split_recursive(my_bsp,NULL,4,5,5,1.5f,1.5f);
TCOD_bsp_remove_sons(my_bsp);
TCOD_bsp_split_recursive(my_bsp,NULL,4,5,5,1.5f,1.5f);
- @PyEx
+ @PyEx
my_bsp=libtcod.bsp_new_with_size(0,0,50,50)
libtcod.bsp_split_recursive(my_bsp,0,4,5,5,1.5,1.5)
libtcod.bsp_remove_sons(my_bsp)
@@ -112,19 +116,19 @@ public :
@Py bsp_delete(node)
@C# void TCODBsp::Dispose()
@Param node In the C version, the node reference.
- @CppEx
+ @CppEx
TCODBsp *myBSP = new TCODBsp(0,0,50,50);
// create a tree
- myBSP->splitRecursive(NULL,4,5,5,1.5f,1.5f);
+ myBSP->splitRecursive(NULL,4,5,5,1.5f,1.5f);
// use the tree ...
// delete the tree
- delete myBSP;
- @CEx
+ delete myBSP;
+ @CEx
TCOD_bsp_t *my_bsp=TCOD_bsp_new_with_size(0,0,50,50);
TCOD_bsp_split_recursive(my_bsp,NULL,4,5,5,1.5f,1.5f);
- // use the tree ...
+ // use the tree ...
TCOD_bsp_delete(my_bsp);
- @PyEx
+ @PyEx
my_bsp=libtcod.bsp_new_with_size(0,0,50,50)
libtcod.bsp_split_recursive(my_bsp,0,4,5,5,1.5,1.5)
# use the tree ...
@@ -147,13 +151,13 @@ public :
@Param position Coordinate of the splitting position.
If horizontal is true, x <= position < x+w
Else, y <= position < y+h
- @CppEx
+ @CppEx
TCODBsp *myBSP = new TCODBsp(0,0,50,50);
myBSP->splitOnce(true,20); // horizontal split into two nodes : (0,0,50,20) and (0,20,50,30)
- @CEx
+ @CEx
TCOD_bsp_t *my_bsp=TCOD_bsp_new_with_size(0,0,50,50);
TCOD_bsp_split_once(my_bsp,false,20); // vertical split into two nodes : (0,0,20,50) and (20,0,30,50)
- @PyEx
+ @PyEx
my_bsp=libtcod.bsp_new_with_size(0,0,50,50)
libtcod.bsp_split_once(my_bsp,False,20) # vertical split into two nodes : (0,0,20,50) and (20,0,30,50)
*/
@@ -172,14 +176,14 @@ public :
@Param nb Number of recursion levels.
@Param minHSize, minVSize minimum values of w and h for a node. A node is split only if the resulting sub-nodes are bigger than minHSize x minVSize
@Param maxHRatio, maxVRation maximum values of w/h and h/w for a node. If a node does not conform, the splitting orientation is forced to reduce either the w/h or the h/w ratio. Use values near 1.0 to promote square nodes.
- @CppEx
+ @CppEx
// Do a 4 levels BSP tree (the region is split into a maximum of 2*2*2*2 sub-regions).
TCODBsp *myBSP = new TCODBsp(0,0,50,50);
- myBSP->splitRecursive(NULL,4,5,5,1.5f,1.5f);
- @CEx
+ myBSP->splitRecursive(NULL,4,5,5,1.5f,1.5f);
+ @CEx
TCOD_bsp_t *my_bsp=TCOD_bsp_new_with_size(0,0,50,50);
TCOD_bsp_split_recursive(my_bsp,NULL,4,5,5,1.5f,1.5f);
- @PyEx
+ @PyEx
my_bsp=libtcod.bsp_new_with_size(0,0,50,50)
libtcod.bsp_split_recursive(my_bsp,0,4,5,5,1.5,1.5)
*/
@@ -197,21 +201,21 @@ You can use it if you changed the nodes size and position while using the BSP tr
@C# void TCODBsp::resize(int x, int y, int w, int h)
@Param node In the C version, the root node created with TCOD_bsp_new_with_size, or a node obtained by splitting.
@Param x,y,w,h New position and size of the node. The original rectangular area covered by the node should be included in the new one to ensure that every splitting edge stay inside its node.
- @CppEx
+ @CppEx
// We create a BSP, do some processing that will modify the x,y,w,h fields of the tree nodes, then reset all the nodes to their original size.
TCODBsp *myBSP = new TCODBsp(0,0,50,50);
- myBSP->splitRecursive(NULL,4,5,5,1.5f,1.5f);
+ myBSP->splitRecursive(NULL,4,5,5,1.5f,1.5f);
// ... do something with the tree here
myBSP->resize(0,0,50,50);
- @CEx
+ @CEx
TCOD_bsp_t *my_bsp=TCOD_bsp_new_with_size(0,0,50,50);
TCOD_bsp_split_recursive(my_bsp,NULL,4,5,5,1.5f,1.5f);
- // ... do something with the tree here
+ // ... do something with the tree here
TCOD_bsp_resize(my_bsp,0,0,50,50);
- @PyEx
+ @PyEx
my_bsp=libtcod.bsp_new_with_size(0,0,50,50)
libtcod.bsp_split_recursive(my_bsp,0,4,5,5,1.5,1.5)
- # ... do something with the tree here
+ # ... do something with the tree here
libtcod.bsp_resize(my_bsp,0,0,50,50)
*/
void resize(int x,int y, int w, int h);
@@ -221,16 +225,16 @@ You can use it if you changed the nodes size and position while using the BSP tr
@PageFather bsp
@PageTitle Reading information from the tree
@FuncDesc Once you have built a BSP tree, you can retrieve information from any node. The node gives you free access to its fields :
- @Cpp
+ @Cpp
class TCODBsp {
public :
- int x,y,w,h; //
+ int x,y,w,h; //
int position; // position of splitting
bool horizontal; // horizontal splitting ?
- uint8_t level; // level in the tree
+ uint8_t level; // level in the tree
...
}
- @C
+ @C
typedef struct {
int x,y,w,h;
int position;
@@ -238,7 +242,7 @@ You can use it if you changed the nodes size and position while using the BSP tr
uint8_t level;
...
} TCOD_bsp_t;
- @C#
+ @C#
class TCODBsp
{
public int x { get; set; }
@@ -259,32 +263,32 @@ You can use it if you changed the nodes size and position while using the BSP tr
@PageName bsp_read
@FuncTitle Navigate in the tree
@FuncDesc You can navigate from a node to its sons or its parent using one of those functions. Each function returns NULL if the corresponding node does not exists (if the node is not split for getLeft and getRight, and if the node is the root node for getFather).
- @Cpp
+ @Cpp
TCODBsp *TCODBsp::getLeft() const
TCODBsp *TCODBsp::getRight() const
TCODBsp *TCODBsp::getFather() const
- @C
+ @C
TCOD_bsp_t * TCOD_bsp_left(TCOD_bsp_t *node)
TCOD_bsp_t * TCOD_bsp_right(TCOD_bsp_t *node)
TCOD_bsp_t * TCOD_bsp_father(TCOD_bsp_t *node)
- @Py
+ @Py
bsp_left(node)
bsp_right(node)
bsp_father(node)
- @C#
+ @C#
TCODBsp TCODBsp::getLeft()
TCODBsp TCODBsp::getRight()
TCODBsp TCODBsp::getFather()
@Param node In the C version, the node reference.
*/
TCODBsp *getLeft() const {
- return (TCODBsp *)sons;
+ return static_cast(sons);
}
TCODBsp *getRight() const {
- return sons ? (TCODBsp *)(sons->next) : NULL;
+ return sons ? static_cast(sons->next) : NULL;
}
TCODBsp *getFather() const {
- return (TCODBsp *)father;
+ return static_cast(father);
}
/**
@@ -339,28 +343,28 @@ You can use it if you changed the nodes size and position while using the BSP tr
Pre order | In order | Post order | Level order | Inverted level order |
| | | | |
- @Cpp
+ @Cpp
class ITCODBspCallback {
public :
virtual bool visitNode(TCODBsp *node, void *userData) = 0;
};
-
+
bool TCODBsp::traversePreOrder(ITCODBspCallback *callback, void *userData)
bool TCODBsp::traverseInOrder(ITCODBspCallback *callback, void *userData)
bool TCODBsp::traversePostOrder(ITCODBspCallback *callback, void *userData)
bool TCODBsp::traverseLevelOrder(ITCODBspCallback *callback, void *userData)
bool TCODBsp::traverseInvertedLevelOrder(ITCODBspCallback *callback, void *userData)
- @C
+ @C
typedef bool (*TCOD_bsp_callback_t)(TCOD_bsp_t *node, void *userData)
-
+
bool TCOD_bsp_traverse_pre_order(TCOD_bsp_t *node, TCOD_bsp_callback_t callback, void *userData)
bool TCOD_bsp_traverse_in_order(TCOD_bsp_t *node, TCOD_bsp_callback_t callback, void *userData)
bool TCOD_bsp_traverse_post_order(TCOD_bsp_t *node, TCOD_bsp_callback_t callback, void *userData)
bool TCOD_bsp_traverse_level_order(TCOD_bsp_t *node, TCOD_bsp_callback_t callback, void *userData)
bool TCOD_bsp_traverse_inverted_level_order(TCOD_bsp_t *node, TCOD_bsp_callback_t callback, void *userData)
- @Py
+ @Py
def bsp_callback(node, userData) : # ...
-
+
bsp_traverse_pre_order(node, callback, userData=0)
bsp_traverse_in_order(node, callback, userData=0)
bsp_traverse_post_order(node, callback, userData=0)
@@ -377,7 +381,7 @@ You can use it if you changed the nodes size and position while using the BSP tr
It receives the current node and the custom data as parameters
If it returns false, the traversal is interrupted.
@Param userData Custom data to pass to the callback.
- @CppEx
+ @CppEx
class MyCallback : public ITCODBspCallback {
public :
bool visitNode(TCODBsp *node, void *userData) {
@@ -386,13 +390,13 @@ You can use it if you changed the nodes size and position while using the BSP tr
}
};
myBSP->traversePostOrder(new MyListener(),NULL);
- @CEx
+ @CEx
bool my_callback(TCOD_bsp_t *node, void *userData) {
printf("node pos %dx%d size %dx%d level %d\n",node->x,node->y,node->w,node->h,node->level);
return true;
}
TCOD_bsp_traverse_post_order(my_bsp,my_callback,NULL);
- @PyEx
+ @PyEx
def my_callback(node, userData) :
print "node pos %dx%d size %dx%d level %d"%(node.x,node.y,node.w,node.h,node.level))
return True
diff --git a/tcod_sys/libtcod/src/bsp_c.c b/tcod_sys/libtcod/src/libtcod/bsp_c.c
similarity index 70%
rename from tcod_sys/libtcod/src/bsp_c.c
rename to tcod_sys/libtcod/src/libtcod/bsp_c.c
index ac9a5d12c..abacd3df5 100644
--- a/tcod_sys/libtcod/src/bsp_c.c
+++ b/tcod_sys/libtcod/src/libtcod/bsp_c.c
@@ -1,217 +1,220 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#include
-
-#include
-
-#include
-#include
-
-TCOD_bsp_t *TCOD_bsp_new(void) {
- return (TCOD_bsp_t *)calloc(sizeof(TCOD_bsp_t),1);
-}
-
-TCOD_bsp_t *TCOD_bsp_new_with_size(int x,int y,int w, int h) {
- TCOD_bsp_t *bsp=(TCOD_bsp_t *)calloc(sizeof(TCOD_bsp_t),1);
- bsp->x=x;
- bsp->y=y;
- bsp->w=w;
- bsp->h=h;
- return bsp;
-}
-
-TCOD_bsp_t * TCOD_bsp_left(TCOD_bsp_t *node) {
- return (TCOD_bsp_t *)node->tree.sons;
-}
-
-TCOD_bsp_t * TCOD_bsp_right(TCOD_bsp_t *node) {
- return node->tree.sons ? (TCOD_bsp_t *)node->tree.sons->next : NULL;
-}
-
-TCOD_bsp_t * TCOD_bsp_father(TCOD_bsp_t *node) {
- return (TCOD_bsp_t *)node->tree.father;
-}
-
-bool TCOD_bsp_is_leaf(TCOD_bsp_t *node) {
- return node->tree.sons==NULL;
-}
-
-void TCOD_bsp_delete(TCOD_bsp_t *node) {
- TCOD_bsp_remove_sons(node);
- free(node);
-}
-
-static TCOD_bsp_t *TCOD_bsp_new_intern(TCOD_bsp_t *father, bool left) {
- TCOD_bsp_t *bsp=(TCOD_bsp_t *)calloc(sizeof(TCOD_bsp_t),1);
- if ( father->horizontal ) {
- bsp->x=father->x;
- bsp->w=father->w;
- bsp->y = left ? father->y : father->position;
- bsp->h = left ? father->position - bsp->y: father->y + father->h - father->position;
- } else {
- bsp->y=father->y;
- bsp->h=father->h;
- bsp->x = left ? father->x : father->position;
- bsp->w = left ? father->position - bsp->x: father->x + father->w - father->position;
- }
- bsp->level=father->level+1;
- return bsp;
-}
-
-bool TCOD_bsp_traverse_pre_order(TCOD_bsp_t *node, TCOD_bsp_callback_t listener, void *userData) {
- if (!listener(node,userData)) return false;
- if ( TCOD_bsp_left(node) && !TCOD_bsp_traverse_pre_order(TCOD_bsp_left(node),listener,userData)) return false;
- if ( TCOD_bsp_right(node) && !TCOD_bsp_traverse_pre_order(TCOD_bsp_right(node),listener,userData)) return false;
- return true;
-}
-
-bool TCOD_bsp_traverse_in_order(TCOD_bsp_t *node, TCOD_bsp_callback_t listener, void *userData) {
- if ( TCOD_bsp_left(node) && !TCOD_bsp_traverse_in_order(TCOD_bsp_left(node),listener,userData)) return false;
- if (!listener(node,userData)) return false;
- if ( TCOD_bsp_right(node) && !TCOD_bsp_traverse_in_order(TCOD_bsp_right(node),listener,userData)) return false;
- return true;
-}
-
-bool TCOD_bsp_traverse_post_order(TCOD_bsp_t *node, TCOD_bsp_callback_t listener, void *userData) {
- if ( TCOD_bsp_left(node) && !TCOD_bsp_traverse_post_order(TCOD_bsp_left(node),listener,userData)) return false;
- if ( TCOD_bsp_right(node) && !TCOD_bsp_traverse_post_order(TCOD_bsp_right(node),listener,userData)) return false;
- if (!listener(node,userData)) return false;
- return true;
-}
-
-bool TCOD_bsp_traverse_level_order(TCOD_bsp_t *node, TCOD_bsp_callback_t listener, void *userData) {
- TCOD_list_t stack=TCOD_list_new();
- TCOD_list_push(stack,node);
- while ( ! TCOD_list_is_empty(stack) ) {
- TCOD_bsp_t *node=(TCOD_bsp_t *)TCOD_list_get(stack,0);
- TCOD_list_remove(stack,node);
- if ( TCOD_bsp_left(node) ) TCOD_list_push(stack,TCOD_bsp_left(node));
- if ( TCOD_bsp_right(node) ) TCOD_list_push(stack,TCOD_bsp_right(node));
- if (!listener(node,userData)) {
- TCOD_list_delete(stack);
- return false;
- }
- }
- TCOD_list_delete(stack);
- return true;
-}
-
-bool TCOD_bsp_traverse_inverted_level_order(TCOD_bsp_t *node, TCOD_bsp_callback_t listener, void *userData) {
- TCOD_list_t stack1=TCOD_list_new();
- TCOD_list_t stack2=TCOD_list_new();
- TCOD_list_push(stack1,node);
- while ( ! TCOD_list_is_empty(stack1) ) {
- TCOD_bsp_t *node=(TCOD_bsp_t *)TCOD_list_get(stack1,0);
- TCOD_list_push(stack2,node);
- TCOD_list_remove(stack1,node);
- if ( TCOD_bsp_left(node) ) TCOD_list_push(stack1,TCOD_bsp_left(node));
- if ( TCOD_bsp_right(node) ) TCOD_list_push(stack1,TCOD_bsp_right(node));
- }
- while ( ! TCOD_list_is_empty(stack2) ) {
- TCOD_bsp_t *node=(TCOD_bsp_t *)TCOD_list_pop(stack2);
- if (!listener(node,userData)) {
- TCOD_list_delete(stack1);
- TCOD_list_delete(stack2);
- return false;
- }
- }
- TCOD_list_delete(stack1);
- TCOD_list_delete(stack2);
- return true;
-}
-
-void TCOD_bsp_remove_sons(TCOD_bsp_t *root) {
- TCOD_bsp_t *node=(TCOD_bsp_t *)root->tree.sons;
- while ( node ) {
- TCOD_bsp_t *nextNode=(TCOD_bsp_t *)node->tree.next;
- TCOD_bsp_remove_sons(node);
- free( node );
- node=nextNode;
- }
- root->tree.sons=NULL;
-}
-
-void TCOD_bsp_split_once(TCOD_bsp_t *node, bool horizontal, int position) {
- node->horizontal = horizontal;
- node->position=position;
- TCOD_tree_add_son(&node->tree,&TCOD_bsp_new_intern(node,true)->tree);
- TCOD_tree_add_son(&node->tree,&TCOD_bsp_new_intern(node,false)->tree);
-}
-
-void TCOD_bsp_split_recursive(TCOD_bsp_t *node, TCOD_random_t randomizer, int nb,
- int minHSize, int minVSize, float maxHRatio, float maxVRatio) {
- bool horiz;
- int position;
- if ( nb == 0 || (node->w < 2*minHSize && node->h < 2*minVSize ) ) return;
- if (! randomizer ) randomizer=TCOD_random_get_instance();
- /* promote square rooms */
- if ( node->h < 2*minVSize || node->w > node->h * maxHRatio ) horiz = false;
- else if ( node->w < 2*minHSize || node->h > node->w * maxVRatio) horiz = true;
- else horiz = (TCOD_random_get_int(randomizer,0,1) == 0);
- if ( horiz ) {
- position = TCOD_random_get_int(randomizer,node->y+minVSize,node->y+node->h-minVSize);
- } else {
- position = TCOD_random_get_int(randomizer,node->x+minHSize,node->x+node->w-minHSize);
- }
- TCOD_bsp_split_once(node,horiz,position);
- TCOD_bsp_split_recursive(TCOD_bsp_left(node),randomizer,nb-1,minHSize,minVSize,maxHRatio,maxVRatio);
- TCOD_bsp_split_recursive(TCOD_bsp_right(node),randomizer,nb-1,minHSize,minVSize,maxHRatio,maxVRatio);
-}
-
-void TCOD_bsp_resize(TCOD_bsp_t *node, int x,int y, int w, int h) {
- node->x=x;
- node->y=y;
- node->w=w;
- node->h=h;
- if ( TCOD_bsp_left(node) ) {
- if ( node->horizontal ) {
- TCOD_bsp_resize(TCOD_bsp_left(node),x,y,w,node->position-y);
- TCOD_bsp_resize(TCOD_bsp_right(node),x,node->position,w,y+h-node->position);
- } else {
- TCOD_bsp_resize(TCOD_bsp_left(node),x,y,node->position-x,h);
- TCOD_bsp_resize(TCOD_bsp_right(node),node->position,y,x+w-node->position,h);
- }
- }
-}
-
-bool TCOD_bsp_contains(TCOD_bsp_t *node, int x, int y) {
- return (x >= node->x && y >= node->y && x < node->x+node->w && y < node->y+node->h);
-}
-
-TCOD_bsp_t * TCOD_bsp_find_node(TCOD_bsp_t *node, int x, int y) {
- if ( ! TCOD_bsp_contains(node,x,y) ) return NULL;
- if ( ! TCOD_bsp_is_leaf(node) ) {
- TCOD_bsp_t *left,*right;
- left=TCOD_bsp_left(node);
- if ( TCOD_bsp_contains(left,x,y) ) return TCOD_bsp_find_node(left,x,y);
- right=TCOD_bsp_right(node);
- if ( TCOD_bsp_contains(right,x,y) ) return TCOD_bsp_find_node(right,x,y);
- }
- return node;
-}
-
-
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "bsp.h"
+
+#include
+
+#include "list.h"
+#include "mersenne.h"
+
+TCOD_bsp_t *TCOD_bsp_new(void) {
+ return (TCOD_bsp_t *)calloc(sizeof(TCOD_bsp_t),1);
+}
+
+TCOD_bsp_t *TCOD_bsp_new_with_size(int x,int y,int w, int h) {
+ TCOD_bsp_t *bsp=(TCOD_bsp_t *)calloc(sizeof(TCOD_bsp_t),1);
+ bsp->x=x;
+ bsp->y=y;
+ bsp->w=w;
+ bsp->h=h;
+ return bsp;
+}
+
+TCOD_bsp_t * TCOD_bsp_left(TCOD_bsp_t *node) {
+ return (TCOD_bsp_t *)node->tree.sons;
+}
+
+TCOD_bsp_t * TCOD_bsp_right(TCOD_bsp_t *node) {
+ return node->tree.sons ? (TCOD_bsp_t *)node->tree.sons->next : NULL;
+}
+
+TCOD_bsp_t * TCOD_bsp_father(TCOD_bsp_t *node) {
+ return (TCOD_bsp_t *)node->tree.father;
+}
+
+bool TCOD_bsp_is_leaf(TCOD_bsp_t *node) {
+ return node->tree.sons==NULL;
+}
+
+void TCOD_bsp_delete(TCOD_bsp_t *node) {
+ TCOD_bsp_remove_sons(node);
+ free(node);
+}
+
+static TCOD_bsp_t *TCOD_bsp_new_intern(TCOD_bsp_t *father, bool left) {
+ TCOD_bsp_t *bsp=(TCOD_bsp_t *)calloc(sizeof(TCOD_bsp_t),1);
+ if ( father->horizontal ) {
+ bsp->x=father->x;
+ bsp->w=father->w;
+ bsp->y = left ? father->y : father->position;
+ bsp->h = left ? father->position - bsp->y: father->y + father->h - father->position;
+ } else {
+ bsp->y=father->y;
+ bsp->h=father->h;
+ bsp->x = left ? father->x : father->position;
+ bsp->w = left ? father->position - bsp->x: father->x + father->w - father->position;
+ }
+ bsp->level=father->level+1;
+ return bsp;
+}
+
+bool TCOD_bsp_traverse_pre_order(TCOD_bsp_t *node, TCOD_bsp_callback_t listener, void *userData) {
+ if (!listener(node,userData)) return false;
+ if ( TCOD_bsp_left(node) && !TCOD_bsp_traverse_pre_order(TCOD_bsp_left(node),listener,userData)) return false;
+ if ( TCOD_bsp_right(node) && !TCOD_bsp_traverse_pre_order(TCOD_bsp_right(node),listener,userData)) return false;
+ return true;
+}
+
+bool TCOD_bsp_traverse_in_order(TCOD_bsp_t *node, TCOD_bsp_callback_t listener, void *userData) {
+ if ( TCOD_bsp_left(node) && !TCOD_bsp_traverse_in_order(TCOD_bsp_left(node),listener,userData)) return false;
+ if (!listener(node,userData)) return false;
+ if ( TCOD_bsp_right(node) && !TCOD_bsp_traverse_in_order(TCOD_bsp_right(node),listener,userData)) return false;
+ return true;
+}
+
+bool TCOD_bsp_traverse_post_order(TCOD_bsp_t *node, TCOD_bsp_callback_t listener, void *userData) {
+ if ( TCOD_bsp_left(node) && !TCOD_bsp_traverse_post_order(TCOD_bsp_left(node),listener,userData)) return false;
+ if ( TCOD_bsp_right(node) && !TCOD_bsp_traverse_post_order(TCOD_bsp_right(node),listener,userData)) return false;
+ if (!listener(node,userData)) return false;
+ return true;
+}
+
+bool TCOD_bsp_traverse_level_order(TCOD_bsp_t *node, TCOD_bsp_callback_t listener, void *userData) {
+ TCOD_list_t stack=TCOD_list_new();
+ TCOD_list_push(stack,node);
+ while ( ! TCOD_list_is_empty(stack) ) {
+ TCOD_bsp_t *node_=(TCOD_bsp_t *)TCOD_list_get(stack,0);
+ TCOD_list_remove(stack,node_);
+ if ( TCOD_bsp_left(node_) ) TCOD_list_push(stack,TCOD_bsp_left(node_));
+ if ( TCOD_bsp_right(node_) ) TCOD_list_push(stack,TCOD_bsp_right(node_));
+ if (!listener(node_,userData)) {
+ TCOD_list_delete(stack);
+ return false;
+ }
+ }
+ TCOD_list_delete(stack);
+ return true;
+}
+
+bool TCOD_bsp_traverse_inverted_level_order(TCOD_bsp_t *node, TCOD_bsp_callback_t listener, void *userData) {
+ TCOD_list_t stack1=TCOD_list_new();
+ TCOD_list_t stack2=TCOD_list_new();
+ TCOD_list_push(stack1,node);
+ while ( ! TCOD_list_is_empty(stack1) ) {
+ TCOD_bsp_t *node_ = (TCOD_bsp_t *)TCOD_list_get(stack1,0);
+ TCOD_list_push(stack2,node_);
+ TCOD_list_remove(stack1,node_);
+ if (TCOD_bsp_left(node_)) TCOD_list_push(stack1,TCOD_bsp_left(node_));
+ if (TCOD_bsp_right(node_)) TCOD_list_push(stack1,TCOD_bsp_right(node_));
+ }
+ while ( ! TCOD_list_is_empty(stack2) ) {
+ TCOD_bsp_t *node_ = (TCOD_bsp_t *)TCOD_list_pop(stack2);
+ if (!listener(node_, userData)) {
+ TCOD_list_delete(stack1);
+ TCOD_list_delete(stack2);
+ return false;
+ }
+ }
+ TCOD_list_delete(stack1);
+ TCOD_list_delete(stack2);
+ return true;
+}
+
+void TCOD_bsp_remove_sons(TCOD_bsp_t *root) {
+ TCOD_bsp_t *node=(TCOD_bsp_t *)root->tree.sons;
+ while ( node ) {
+ TCOD_bsp_t *nextNode=(TCOD_bsp_t *)node->tree.next;
+ TCOD_bsp_remove_sons(node);
+ free( node );
+ node=nextNode;
+ }
+ root->tree.sons=NULL;
+}
+
+void TCOD_bsp_split_once(TCOD_bsp_t *node, bool horizontal, int position) {
+ node->horizontal = horizontal;
+ node->position=position;
+ TCOD_tree_add_son(&node->tree,&TCOD_bsp_new_intern(node,true)->tree);
+ TCOD_tree_add_son(&node->tree,&TCOD_bsp_new_intern(node,false)->tree);
+}
+
+void TCOD_bsp_split_recursive(TCOD_bsp_t *node, TCOD_random_t randomizer, int nb,
+ int minHSize, int minVSize, float maxHRatio, float maxVRatio) {
+ bool horiz;
+ int position;
+ if ( nb == 0 || (node->w < 2*minHSize && node->h < 2*minVSize ) ) return;
+ if (! randomizer ) randomizer=TCOD_random_get_instance();
+ /* promote square rooms */
+ if ( node->h < 2*minVSize || node->w > node->h * maxHRatio ) horiz = false;
+ else if ( node->w < 2*minHSize || node->h > node->w * maxVRatio) horiz = true;
+ else horiz = (TCOD_random_get_int(randomizer,0,1) == 0);
+ if ( horiz ) {
+ position = TCOD_random_get_int(randomizer,node->y+minVSize,node->y+node->h-minVSize);
+ } else {
+ position = TCOD_random_get_int(randomizer,node->x+minHSize,node->x+node->w-minHSize);
+ }
+ TCOD_bsp_split_once(node,horiz,position);
+ TCOD_bsp_split_recursive(TCOD_bsp_left(node),randomizer,nb-1,minHSize,minVSize,maxHRatio,maxVRatio);
+ TCOD_bsp_split_recursive(TCOD_bsp_right(node),randomizer,nb-1,minHSize,minVSize,maxHRatio,maxVRatio);
+}
+
+void TCOD_bsp_resize(TCOD_bsp_t *node, int x,int y, int w, int h) {
+ node->x=x;
+ node->y=y;
+ node->w=w;
+ node->h=h;
+ if ( TCOD_bsp_left(node) ) {
+ if ( node->horizontal ) {
+ TCOD_bsp_resize(TCOD_bsp_left(node),x,y,w,node->position-y);
+ TCOD_bsp_resize(TCOD_bsp_right(node),x,node->position,w,y+h-node->position);
+ } else {
+ TCOD_bsp_resize(TCOD_bsp_left(node),x,y,node->position-x,h);
+ TCOD_bsp_resize(TCOD_bsp_right(node),node->position,y,x+w-node->position,h);
+ }
+ }
+}
+
+bool TCOD_bsp_contains(TCOD_bsp_t *node, int x, int y) {
+ return (x >= node->x && y >= node->y && x < node->x+node->w && y < node->y+node->h);
+}
+
+TCOD_bsp_t * TCOD_bsp_find_node(TCOD_bsp_t *node, int x, int y) {
+ if ( ! TCOD_bsp_contains(node,x,y) ) return NULL;
+ if ( ! TCOD_bsp_is_leaf(node) ) {
+ TCOD_bsp_t *left,*right;
+ left=TCOD_bsp_left(node);
+ if ( TCOD_bsp_contains(left,x,y) ) return TCOD_bsp_find_node(left,x,y);
+ right=TCOD_bsp_right(node);
+ if ( TCOD_bsp_contains(right,x,y) ) return TCOD_bsp_find_node(right,x,y);
+ }
+ return node;
+}
diff --git a/tcod_sys/libtcod/src/color.cpp b/tcod_sys/libtcod/src/libtcod/color.cpp
similarity index 88%
rename from tcod_sys/libtcod/src/color.cpp
rename to tcod_sys/libtcod/src/libtcod/color.cpp
index 7880557ef..14ea79338 100644
--- a/tcod_sys/libtcod/src/color.cpp
+++ b/tcod_sys/libtcod/src/libtcod/color.cpp
@@ -1,349 +1,358 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#include
-
-#include
-
-// grey levels
-const TCODColor TCODColor::black(TCOD_BLACK);
-const TCODColor TCODColor::darkestGrey(TCOD_DARKEST_GREY);
-const TCODColor TCODColor::darkerGrey(TCOD_DARKER_GREY);
-const TCODColor TCODColor::darkGrey(TCOD_DARK_GREY);
-const TCODColor TCODColor::grey(TCOD_GREY);
-const TCODColor TCODColor::lightGrey(TCOD_LIGHT_GREY);
-const TCODColor TCODColor::lighterGrey(TCOD_LIGHTER_GREY);
-const TCODColor TCODColor::lightestGrey(TCOD_LIGHTEST_GREY);
-const TCODColor TCODColor::white(TCOD_WHITE);
-
-//sepia
-const TCODColor TCODColor::darkestSepia(TCOD_DARKEST_SEPIA);
-const TCODColor TCODColor::darkerSepia(TCOD_DARKER_SEPIA);
-const TCODColor TCODColor::darkSepia(TCOD_DARK_SEPIA);
-const TCODColor TCODColor::sepia(TCOD_SEPIA);
-const TCODColor TCODColor::lightSepia(TCOD_LIGHT_SEPIA);
-const TCODColor TCODColor::lighterSepia(TCOD_LIGHTER_SEPIA);
-const TCODColor TCODColor::lightestSepia(TCOD_LIGHTEST_SEPIA);
-
-// standard colors
-const TCODColor TCODColor::red(TCOD_RED);
-const TCODColor TCODColor::flame(TCOD_FLAME);
-const TCODColor TCODColor::orange(TCOD_ORANGE);
-const TCODColor TCODColor::amber(TCOD_AMBER);
-const TCODColor TCODColor::yellow(TCOD_YELLOW);
-const TCODColor TCODColor::lime(TCOD_LIME);
-const TCODColor TCODColor::chartreuse(TCOD_CHARTREUSE);
-const TCODColor TCODColor::green(TCOD_GREEN);
-const TCODColor TCODColor::sea(TCOD_SEA);
-const TCODColor TCODColor::turquoise(TCOD_TURQUOISE);
-const TCODColor TCODColor::cyan(TCOD_CYAN);
-const TCODColor TCODColor::sky(TCOD_SKY);
-const TCODColor TCODColor::azure(TCOD_AZURE);
-const TCODColor TCODColor::blue(TCOD_BLUE);
-const TCODColor TCODColor::han(TCOD_HAN);
-const TCODColor TCODColor::violet(TCOD_VIOLET);
-const TCODColor TCODColor::purple(TCOD_PURPLE);
-const TCODColor TCODColor::fuchsia(TCOD_FUCHSIA);
-const TCODColor TCODColor::magenta(TCOD_MAGENTA);
-const TCODColor TCODColor::pink(TCOD_PINK);
-const TCODColor TCODColor::crimson(TCOD_CRIMSON);
-
-// dark colors
-const TCODColor TCODColor::darkRed(TCOD_DARK_RED);
-const TCODColor TCODColor::darkFlame(TCOD_DARK_FLAME);
-const TCODColor TCODColor::darkOrange(TCOD_DARK_ORANGE);
-const TCODColor TCODColor::darkAmber(TCOD_DARK_AMBER);
-const TCODColor TCODColor::darkYellow(TCOD_DARK_YELLOW);
-const TCODColor TCODColor::darkLime(TCOD_DARK_LIME);
-const TCODColor TCODColor::darkChartreuse(TCOD_DARK_CHARTREUSE);
-const TCODColor TCODColor::darkGreen(TCOD_DARK_GREEN);
-const TCODColor TCODColor::darkSea(TCOD_DARK_SEA);
-const TCODColor TCODColor::darkTurquoise(TCOD_DARK_TURQUOISE);
-const TCODColor TCODColor::darkCyan(TCOD_DARK_CYAN);
-const TCODColor TCODColor::darkSky(TCOD_DARK_SKY);
-const TCODColor TCODColor::darkAzure(TCOD_DARK_AZURE);
-const TCODColor TCODColor::darkBlue(TCOD_DARK_BLUE);
-const TCODColor TCODColor::darkHan(TCOD_DARK_HAN);
-const TCODColor TCODColor::darkViolet(TCOD_DARK_VIOLET);
-const TCODColor TCODColor::darkPurple(TCOD_DARK_PURPLE);
-const TCODColor TCODColor::darkFuchsia(TCOD_DARK_FUCHSIA);
-const TCODColor TCODColor::darkMagenta(TCOD_DARK_MAGENTA);
-const TCODColor TCODColor::darkPink(TCOD_DARK_PINK);
-const TCODColor TCODColor::darkCrimson(TCOD_DARK_CRIMSON);
-
-// darker colors
-const TCODColor TCODColor::darkerRed(TCOD_DARKER_RED);
-const TCODColor TCODColor::darkerFlame(TCOD_DARKER_FLAME);
-const TCODColor TCODColor::darkerOrange(TCOD_DARKER_ORANGE);
-const TCODColor TCODColor::darkerAmber(TCOD_DARKER_AMBER);
-const TCODColor TCODColor::darkerYellow(TCOD_DARKER_YELLOW);
-const TCODColor TCODColor::darkerLime(TCOD_DARKER_LIME);
-const TCODColor TCODColor::darkerChartreuse(TCOD_DARKER_CHARTREUSE);
-const TCODColor TCODColor::darkerGreen(TCOD_DARKER_GREEN);
-const TCODColor TCODColor::darkerSea(TCOD_DARKER_SEA);
-const TCODColor TCODColor::darkerTurquoise(TCOD_DARKER_TURQUOISE);
-const TCODColor TCODColor::darkerCyan(TCOD_DARKER_CYAN);
-const TCODColor TCODColor::darkerSky(TCOD_DARKER_SKY);
-const TCODColor TCODColor::darkerAzure(TCOD_DARKER_AZURE);
-const TCODColor TCODColor::darkerBlue(TCOD_DARKER_BLUE);
-const TCODColor TCODColor::darkerHan(TCOD_DARKER_HAN);
-const TCODColor TCODColor::darkerViolet(TCOD_DARKER_VIOLET);
-const TCODColor TCODColor::darkerPurple(TCOD_DARKER_PURPLE);
-const TCODColor TCODColor::darkerFuchsia(TCOD_DARKER_FUCHSIA);
-const TCODColor TCODColor::darkerMagenta(TCOD_DARKER_MAGENTA);
-const TCODColor TCODColor::darkerPink(TCOD_DARKER_PINK);
-const TCODColor TCODColor::darkerCrimson(TCOD_DARKER_CRIMSON);
-
-// darkest colors
-const TCODColor TCODColor::darkestRed(TCOD_DARKEST_RED);
-const TCODColor TCODColor::darkestFlame(TCOD_DARKEST_FLAME);
-const TCODColor TCODColor::darkestOrange(TCOD_DARKEST_ORANGE);
-const TCODColor TCODColor::darkestAmber(TCOD_DARKEST_AMBER);
-const TCODColor TCODColor::darkestYellow(TCOD_DARKEST_YELLOW);
-const TCODColor TCODColor::darkestLime(TCOD_DARKEST_LIME);
-const TCODColor TCODColor::darkestChartreuse(TCOD_DARKEST_CHARTREUSE);
-const TCODColor TCODColor::darkestGreen(TCOD_DARKEST_GREEN);
-const TCODColor TCODColor::darkestSea(TCOD_DARKEST_SEA);
-const TCODColor TCODColor::darkestTurquoise(TCOD_DARKEST_TURQUOISE);
-const TCODColor TCODColor::darkestCyan(TCOD_DARKEST_CYAN);
-const TCODColor TCODColor::darkestSky(TCOD_DARKEST_SKY);
-const TCODColor TCODColor::darkestAzure(TCOD_DARKEST_AZURE);
-const TCODColor TCODColor::darkestBlue(TCOD_DARKEST_BLUE);
-const TCODColor TCODColor::darkestHan(TCOD_DARKEST_HAN);
-const TCODColor TCODColor::darkestViolet(TCOD_DARKEST_VIOLET);
-const TCODColor TCODColor::darkestPurple(TCOD_DARKEST_PURPLE);
-const TCODColor TCODColor::darkestFuchsia(TCOD_DARKEST_FUCHSIA);
-const TCODColor TCODColor::darkestMagenta(TCOD_DARKEST_MAGENTA);
-const TCODColor TCODColor::darkestPink(TCOD_DARKEST_PINK);
-const TCODColor TCODColor::darkestCrimson(TCOD_DARKEST_CRIMSON);
-
-// light colors
-const TCODColor TCODColor::lightRed(TCOD_LIGHT_RED);
-const TCODColor TCODColor::lightFlame(TCOD_LIGHT_FLAME);
-const TCODColor TCODColor::lightOrange(TCOD_LIGHT_ORANGE);
-const TCODColor TCODColor::lightAmber(TCOD_LIGHT_AMBER);
-const TCODColor TCODColor::lightYellow(TCOD_LIGHT_YELLOW);
-const TCODColor TCODColor::lightLime(TCOD_LIGHT_LIME);
-const TCODColor TCODColor::lightChartreuse(TCOD_LIGHT_CHARTREUSE);
-const TCODColor TCODColor::lightGreen(TCOD_LIGHT_GREEN);
-const TCODColor TCODColor::lightSea(TCOD_LIGHT_SEA);
-const TCODColor TCODColor::lightTurquoise(TCOD_LIGHT_TURQUOISE);
-const TCODColor TCODColor::lightCyan(TCOD_LIGHT_CYAN);
-const TCODColor TCODColor::lightSky(TCOD_LIGHT_SKY);
-const TCODColor TCODColor::lightAzure(TCOD_LIGHT_AZURE);
-const TCODColor TCODColor::lightBlue(TCOD_LIGHT_BLUE);
-const TCODColor TCODColor::lightHan(TCOD_LIGHT_HAN);
-const TCODColor TCODColor::lightViolet(TCOD_LIGHT_VIOLET);
-const TCODColor TCODColor::lightPurple(TCOD_LIGHT_PURPLE);
-const TCODColor TCODColor::lightFuchsia(TCOD_LIGHT_FUCHSIA);
-const TCODColor TCODColor::lightMagenta(TCOD_LIGHT_MAGENTA);
-const TCODColor TCODColor::lightPink(TCOD_LIGHT_PINK);
-const TCODColor TCODColor::lightCrimson(TCOD_LIGHT_CRIMSON);
-
-// lighter colors
-const TCODColor TCODColor::lighterRed(TCOD_LIGHTER_RED);
-const TCODColor TCODColor::lighterFlame(TCOD_LIGHTER_FLAME);
-const TCODColor TCODColor::lighterOrange(TCOD_LIGHTER_ORANGE);
-const TCODColor TCODColor::lighterAmber(TCOD_LIGHTER_AMBER);
-const TCODColor TCODColor::lighterYellow(TCOD_LIGHTER_YELLOW);
-const TCODColor TCODColor::lighterLime(TCOD_LIGHTER_LIME);
-const TCODColor TCODColor::lighterChartreuse(TCOD_LIGHTER_CHARTREUSE);
-const TCODColor TCODColor::lighterGreen(TCOD_LIGHTER_GREEN);
-const TCODColor TCODColor::lighterSea(TCOD_LIGHTER_SEA);
-const TCODColor TCODColor::lighterTurquoise(TCOD_LIGHTER_TURQUOISE);
-const TCODColor TCODColor::lighterCyan(TCOD_LIGHTER_CYAN);
-const TCODColor TCODColor::lighterSky(TCOD_LIGHTER_SKY);
-const TCODColor TCODColor::lighterAzure(TCOD_LIGHTER_AZURE);
-const TCODColor TCODColor::lighterBlue(TCOD_LIGHTER_BLUE);
-const TCODColor TCODColor::lighterHan(TCOD_LIGHTER_HAN);
-const TCODColor TCODColor::lighterViolet(TCOD_LIGHTER_VIOLET);
-const TCODColor TCODColor::lighterPurple(TCOD_LIGHTER_PURPLE);
-const TCODColor TCODColor::lighterFuchsia(TCOD_LIGHTER_FUCHSIA);
-const TCODColor TCODColor::lighterMagenta(TCOD_LIGHTER_MAGENTA);
-const TCODColor TCODColor::lighterPink(TCOD_LIGHTER_PINK);
-const TCODColor TCODColor::lighterCrimson(TCOD_LIGHTER_CRIMSON);
-
-// lightest colors
-const TCODColor TCODColor::lightestRed(TCOD_LIGHTEST_RED);
-const TCODColor TCODColor::lightestFlame(TCOD_LIGHTEST_FLAME);
-const TCODColor TCODColor::lightestOrange(TCOD_LIGHTEST_ORANGE);
-const TCODColor TCODColor::lightestAmber(TCOD_LIGHTEST_AMBER);
-const TCODColor TCODColor::lightestYellow(TCOD_LIGHTEST_YELLOW);
-const TCODColor TCODColor::lightestLime(TCOD_LIGHTEST_LIME);
-const TCODColor TCODColor::lightestChartreuse(TCOD_LIGHTEST_CHARTREUSE);
-const TCODColor TCODColor::lightestGreen(TCOD_LIGHTEST_GREEN);
-const TCODColor TCODColor::lightestSea(TCOD_LIGHTEST_SEA);
-const TCODColor TCODColor::lightestTurquoise(TCOD_LIGHTEST_TURQUOISE);
-const TCODColor TCODColor::lightestCyan(TCOD_LIGHTEST_CYAN);
-const TCODColor TCODColor::lightestSky(TCOD_LIGHTEST_SKY);
-const TCODColor TCODColor::lightestAzure(TCOD_LIGHTEST_AZURE);
-const TCODColor TCODColor::lightestBlue(TCOD_LIGHTEST_BLUE);
-const TCODColor TCODColor::lightestHan(TCOD_LIGHTEST_HAN);
-const TCODColor TCODColor::lightestViolet(TCOD_LIGHTEST_VIOLET);
-const TCODColor TCODColor::lightestPurple(TCOD_LIGHTEST_PURPLE);
-const TCODColor TCODColor::lightestFuchsia(TCOD_LIGHTEST_FUCHSIA);
-const TCODColor TCODColor::lightestMagenta(TCOD_LIGHTEST_MAGENTA);
-const TCODColor TCODColor::lightestPink(TCOD_LIGHTEST_PINK);
-const TCODColor TCODColor::lightestCrimson(TCOD_LIGHTEST_CRIMSON);
-
-// desaturated colors
-const TCODColor TCODColor::desaturatedRed(TCOD_DESATURATED_RED);
-const TCODColor TCODColor::desaturatedFlame(TCOD_DESATURATED_FLAME);
-const TCODColor TCODColor::desaturatedOrange(TCOD_DESATURATED_ORANGE);
-const TCODColor TCODColor::desaturatedAmber(TCOD_DESATURATED_AMBER);
-const TCODColor TCODColor::desaturatedYellow(TCOD_DESATURATED_YELLOW);
-const TCODColor TCODColor::desaturatedLime(TCOD_DESATURATED_LIME);
-const TCODColor TCODColor::desaturatedChartreuse(TCOD_DESATURATED_CHARTREUSE);
-const TCODColor TCODColor::desaturatedGreen(TCOD_DESATURATED_GREEN);
-const TCODColor TCODColor::desaturatedSea(TCOD_DESATURATED_SEA);
-const TCODColor TCODColor::desaturatedTurquoise(TCOD_DESATURATED_TURQUOISE);
-const TCODColor TCODColor::desaturatedCyan(TCOD_DESATURATED_CYAN);
-const TCODColor TCODColor::desaturatedSky(TCOD_DESATURATED_SKY);
-const TCODColor TCODColor::desaturatedAzure(TCOD_DESATURATED_AZURE);
-const TCODColor TCODColor::desaturatedBlue(TCOD_DESATURATED_BLUE);
-const TCODColor TCODColor::desaturatedHan(TCOD_DESATURATED_HAN);
-const TCODColor TCODColor::desaturatedViolet(TCOD_DESATURATED_VIOLET);
-const TCODColor TCODColor::desaturatedPurple(TCOD_DESATURATED_PURPLE);
-const TCODColor TCODColor::desaturatedFuchsia(TCOD_DESATURATED_FUCHSIA);
-const TCODColor TCODColor::desaturatedMagenta(TCOD_DESATURATED_MAGENTA);
-const TCODColor TCODColor::desaturatedPink(TCOD_DESATURATED_PINK);
-const TCODColor TCODColor::desaturatedCrimson(TCOD_DESATURATED_CRIMSON);
-
-//special
-const TCODColor TCODColor::brass(TCOD_BRASS);
-const TCODColor TCODColor::copper(TCOD_COPPER);
-const TCODColor TCODColor::gold(TCOD_GOLD);
-const TCODColor TCODColor::silver(TCOD_SILVER);
-
-//miscellaneous
-const TCODColor TCODColor::celadon(TCOD_CELADON);
-const TCODColor TCODColor::peach(TCOD_PEACH);
-
-#ifndef TCOD_HAIKU
-// color array
-const TCODColor TCODColor::colors[TCOD_COLOR_NB][TCOD_COLOR_LEVELS] = {
- {TCODColor(TCOD_DESATURATED_RED),TCODColor(TCOD_LIGHTEST_RED),TCODColor(TCOD_LIGHTER_RED),TCODColor(TCOD_LIGHT_RED),TCODColor(TCOD_RED),TCODColor(TCOD_DARK_RED),TCODColor(TCOD_DARKER_RED),TCODColor(TCOD_DARKEST_RED)},
- {TCODColor(TCOD_DESATURATED_FLAME),TCODColor(TCOD_LIGHTEST_FLAME),TCODColor(TCOD_LIGHTER_FLAME),TCODColor(TCOD_LIGHT_FLAME),TCODColor(TCOD_FLAME),TCODColor(TCOD_DARK_FLAME),TCODColor(TCOD_DARKER_FLAME),TCODColor(TCOD_DARKEST_FLAME)},
- {TCODColor(TCOD_DESATURATED_ORANGE),TCODColor(TCOD_LIGHTEST_ORANGE),TCODColor(TCOD_LIGHTER_ORANGE),TCODColor(TCOD_LIGHT_ORANGE),TCODColor(TCOD_ORANGE),TCODColor(TCOD_DARK_ORANGE),TCODColor(TCOD_DARKER_ORANGE),TCODColor(TCOD_DARKEST_ORANGE)},
- {TCODColor(TCOD_DESATURATED_AMBER),TCODColor(TCOD_LIGHTEST_AMBER),TCODColor(TCOD_LIGHTER_AMBER),TCODColor(TCOD_LIGHT_AMBER),TCODColor(TCOD_AMBER),TCODColor(TCOD_DARK_AMBER),TCODColor(TCOD_DARKER_AMBER),TCODColor(TCOD_DARKEST_AMBER)},
- {TCODColor(TCOD_DESATURATED_YELLOW),TCODColor(TCOD_LIGHTEST_YELLOW),TCODColor(TCOD_LIGHTER_YELLOW),TCODColor(TCOD_LIGHT_YELLOW),TCODColor(TCOD_YELLOW),TCODColor(TCOD_DARK_YELLOW),TCODColor(TCOD_DARKER_YELLOW),TCODColor(TCOD_DARKEST_YELLOW)},
- {TCODColor(TCOD_DESATURATED_LIME),TCODColor(TCOD_LIGHTEST_LIME),TCODColor(TCOD_LIGHTER_LIME),TCODColor(TCOD_LIGHT_LIME),TCODColor(TCOD_LIME),TCODColor(TCOD_DARK_LIME),TCODColor(TCOD_DARKER_LIME),TCODColor(TCOD_DARKEST_LIME)},
- {TCODColor(TCOD_DESATURATED_CHARTREUSE),TCODColor(TCOD_LIGHTEST_CHARTREUSE),TCODColor(TCOD_LIGHTER_CHARTREUSE),TCODColor(TCOD_LIGHT_CHARTREUSE),TCODColor(TCOD_CHARTREUSE),TCODColor(TCOD_DARK_CHARTREUSE),TCODColor(TCOD_DARKER_CHARTREUSE),TCODColor(TCOD_DARKEST_CHARTREUSE)},
- {TCODColor(TCOD_DESATURATED_GREEN),TCODColor(TCOD_LIGHTEST_GREEN),TCODColor(TCOD_LIGHTER_GREEN),TCODColor(TCOD_LIGHT_GREEN),TCODColor(TCOD_GREEN),TCODColor(TCOD_DARK_GREEN),TCODColor(TCOD_DARKER_GREEN),TCODColor(TCOD_DARKEST_GREEN)},
- {TCODColor(TCOD_DESATURATED_SEA),TCODColor(TCOD_LIGHTEST_SEA),TCODColor(TCOD_LIGHTER_SEA),TCODColor(TCOD_LIGHT_SEA),TCODColor(TCOD_SEA),TCODColor(TCOD_DARK_SEA),TCODColor(TCOD_DARKER_SEA),TCODColor(TCOD_DARKEST_SEA)},
- {TCODColor(TCOD_DESATURATED_TURQUOISE),TCODColor(TCOD_LIGHTEST_TURQUOISE),TCODColor(TCOD_LIGHTER_TURQUOISE),TCODColor(TCOD_LIGHT_TURQUOISE),TCODColor(TCOD_TURQUOISE),TCODColor(TCOD_DARK_TURQUOISE),TCODColor(TCOD_DARKER_TURQUOISE),TCODColor(TCOD_DARKEST_TURQUOISE)},
- {TCODColor(TCOD_DESATURATED_CYAN),TCODColor(TCOD_LIGHTEST_CYAN),TCODColor(TCOD_LIGHTER_CYAN),TCODColor(TCOD_LIGHT_CYAN),TCODColor(TCOD_CYAN),TCODColor(TCOD_DARK_CYAN),TCODColor(TCOD_DARKER_CYAN),TCODColor(TCOD_DARKEST_CYAN)},
- {TCODColor(TCOD_DESATURATED_SKY),TCODColor(TCOD_LIGHTEST_SKY),TCODColor(TCOD_LIGHTER_SKY),TCODColor(TCOD_LIGHT_SKY),TCODColor(TCOD_SKY),TCODColor(TCOD_DARK_SKY),TCODColor(TCOD_DARKER_SKY),TCODColor(TCOD_DARKEST_SKY)},
- {TCODColor(TCOD_DESATURATED_AZURE),TCODColor(TCOD_LIGHTEST_AZURE),TCODColor(TCOD_LIGHTER_AZURE),TCODColor(TCOD_LIGHT_AZURE),TCODColor(TCOD_AZURE),TCODColor(TCOD_DARK_AZURE),TCODColor(TCOD_DARKER_AZURE),TCODColor(TCOD_DARKEST_AZURE)},
- {TCODColor(TCOD_DESATURATED_BLUE),TCODColor(TCOD_LIGHTEST_BLUE),TCODColor(TCOD_LIGHTER_BLUE),TCODColor(TCOD_LIGHT_BLUE),TCODColor(TCOD_BLUE),TCODColor(TCOD_DARK_BLUE),TCODColor(TCOD_DARKER_BLUE),TCODColor(TCOD_DARKEST_BLUE)},
- {TCODColor(TCOD_DESATURATED_HAN),TCODColor(TCOD_LIGHTEST_HAN),TCODColor(TCOD_LIGHTER_HAN),TCODColor(TCOD_LIGHT_HAN),TCODColor(TCOD_HAN),TCODColor(TCOD_DARK_HAN),TCODColor(TCOD_DARKER_HAN),TCODColor(TCOD_DARKEST_HAN)},
- {TCODColor(TCOD_DESATURATED_VIOLET),TCODColor(TCOD_LIGHTEST_VIOLET),TCODColor(TCOD_LIGHTER_VIOLET),TCODColor(TCOD_LIGHT_VIOLET),TCODColor(TCOD_VIOLET),TCODColor(TCOD_DARK_VIOLET),TCODColor(TCOD_DARKER_VIOLET),TCODColor(TCOD_DARKEST_VIOLET)},
- {TCODColor(TCOD_DESATURATED_PURPLE),TCODColor(TCOD_LIGHTEST_PURPLE),TCODColor(TCOD_LIGHTER_PURPLE),TCODColor(TCOD_LIGHT_PURPLE),TCODColor(TCOD_PURPLE),TCODColor(TCOD_DARK_PURPLE),TCODColor(TCOD_DARKER_PURPLE),TCODColor(TCOD_DARKEST_PURPLE)},
- {TCODColor(TCOD_DESATURATED_FUCHSIA),TCODColor(TCOD_LIGHTEST_FUCHSIA),TCODColor(TCOD_LIGHTER_FUCHSIA),TCODColor(TCOD_LIGHT_FUCHSIA),TCODColor(TCOD_FUCHSIA),TCODColor(TCOD_DARK_FUCHSIA),TCODColor(TCOD_DARKER_FUCHSIA),TCODColor(TCOD_DARKEST_FUCHSIA)},
- {TCODColor(TCOD_DESATURATED_MAGENTA),TCODColor(TCOD_LIGHTEST_MAGENTA),TCODColor(TCOD_LIGHTER_MAGENTA),TCODColor(TCOD_LIGHT_MAGENTA),TCODColor(TCOD_MAGENTA),TCODColor(TCOD_DARK_MAGENTA),TCODColor(TCOD_DARKER_MAGENTA),TCODColor(TCOD_DARKEST_MAGENTA)},
- {TCODColor(TCOD_DESATURATED_PINK),TCODColor(TCOD_LIGHTEST_PINK),TCODColor(TCOD_LIGHTER_PINK),TCODColor(TCOD_LIGHT_PINK),TCODColor(TCOD_PINK),TCODColor(TCOD_DARK_PINK),TCODColor(TCOD_DARKER_PINK),TCODColor(TCOD_DARKEST_PINK)},
- {TCODColor(TCOD_DESATURATED_CRIMSON),TCODColor(TCOD_LIGHTEST_CRIMSON),TCODColor(TCOD_LIGHTER_CRIMSON),TCODColor(TCOD_LIGHT_CRIMSON),TCODColor(TCOD_CRIMSON),TCODColor(TCOD_DARK_CRIMSON),TCODColor(TCOD_DARKER_CRIMSON),TCODColor(TCOD_DARKEST_CRIMSON)}
-};
-#endif
-
-TCODColor::TCODColor(float h, float s, float v) {
- //setHSV(h,s,v);
- TCOD_color_t c = TCOD_color_HSV(h,s,v);
- r = c.r; g = c.g; b = c.b;
-}
-
-void TCODColor::setHSV(float h, float s, float v) {
- TCOD_color_t c;
- TCOD_color_set_HSV(&c,h,s,v);
- r = c.r; g = c.g; b = c.b;
-}
-
-void TCODColor::setHue (float h) {
- TCOD_color_t c = { r, g, b };
- TCOD_color_set_hue (&c, h);
- r = c.r; g = c.g; b = c.b;
-}
-
-void TCODColor::setSaturation (float s) {
- TCOD_color_t c = { r, g, b };
- TCOD_color_set_saturation (&c, s);
- r = c.r; g = c.g; b = c.b;
-}
-
-void TCODColor::setValue (float v) {
- TCOD_color_t c = { r, g, b };
- TCOD_color_set_value (&c, v);
- r = c.r; g = c.g; b = c.b;
-}
-
-void TCODColor::getHSV(float *h, float *s, float *v) const {
- TCOD_color_t c={r,g,b};
- TCOD_color_get_HSV(c,h,s,v);
-}
-
-float TCODColor::getHue () {
- TCOD_color_t c = { r, g, b };
- return TCOD_color_get_hue(c);
-}
-
-float TCODColor::getSaturation () {
- TCOD_color_t c = { r, g, b };
- return TCOD_color_get_saturation(c);
-}
-
-float TCODColor::getValue () {
- TCOD_color_t c = { r, g, b };
- return TCOD_color_get_value(c);
-}
-
-void TCODColor::shiftHue (float hshift) {
- TCOD_color_t c = { r, g, b };
- TCOD_color_shift_hue (&c, hshift);
- r = c.r; g = c.g; b = c.b;
-}
-
-void TCODColor::scaleHSV (float sscale, float vscale) {
- TCOD_color_t c = {r,g,b};
- TCOD_color_scale_HSV(&c,sscale,vscale);
- r = c.r; g = c.g; b = c.b;
-}
-
-// non member operators
-TCODColor operator *(float value, const TCODColor &c) {
- return c*value;
-}
-
-void TCODColor::genMap(TCODColor *map, int nbKey, TCODColor const *keyColor, int const *keyIndex) {
- for (int segment=0; segment < nbKey-1; segment++) {
- int idxStart=keyIndex[segment];
- int idxEnd=keyIndex[segment+1];
- int idx;
- for ( idx=idxStart;idx <= idxEnd; idx++) {
- map[idx]=TCODColor::lerp(keyColor[segment],keyColor[segment+1],(float)(idx-idxStart)/(idxEnd-idxStart));
- }
- }
-}
-
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "color.hpp"
+
+#include "libtcod_int.h"
+
+// grey levels
+const TCODColor TCODColor::black(TCOD_BLACK);
+const TCODColor TCODColor::darkestGrey(TCOD_DARKEST_GREY);
+const TCODColor TCODColor::darkerGrey(TCOD_DARKER_GREY);
+const TCODColor TCODColor::darkGrey(TCOD_DARK_GREY);
+const TCODColor TCODColor::grey(TCOD_GREY);
+const TCODColor TCODColor::lightGrey(TCOD_LIGHT_GREY);
+const TCODColor TCODColor::lighterGrey(TCOD_LIGHTER_GREY);
+const TCODColor TCODColor::lightestGrey(TCOD_LIGHTEST_GREY);
+const TCODColor TCODColor::white(TCOD_WHITE);
+
+//sepia
+const TCODColor TCODColor::darkestSepia(TCOD_DARKEST_SEPIA);
+const TCODColor TCODColor::darkerSepia(TCOD_DARKER_SEPIA);
+const TCODColor TCODColor::darkSepia(TCOD_DARK_SEPIA);
+const TCODColor TCODColor::sepia(TCOD_SEPIA);
+const TCODColor TCODColor::lightSepia(TCOD_LIGHT_SEPIA);
+const TCODColor TCODColor::lighterSepia(TCOD_LIGHTER_SEPIA);
+const TCODColor TCODColor::lightestSepia(TCOD_LIGHTEST_SEPIA);
+
+// standard colors
+const TCODColor TCODColor::red(TCOD_RED);
+const TCODColor TCODColor::flame(TCOD_FLAME);
+const TCODColor TCODColor::orange(TCOD_ORANGE);
+const TCODColor TCODColor::amber(TCOD_AMBER);
+const TCODColor TCODColor::yellow(TCOD_YELLOW);
+const TCODColor TCODColor::lime(TCOD_LIME);
+const TCODColor TCODColor::chartreuse(TCOD_CHARTREUSE);
+const TCODColor TCODColor::green(TCOD_GREEN);
+const TCODColor TCODColor::sea(TCOD_SEA);
+const TCODColor TCODColor::turquoise(TCOD_TURQUOISE);
+const TCODColor TCODColor::cyan(TCOD_CYAN);
+const TCODColor TCODColor::sky(TCOD_SKY);
+const TCODColor TCODColor::azure(TCOD_AZURE);
+const TCODColor TCODColor::blue(TCOD_BLUE);
+const TCODColor TCODColor::han(TCOD_HAN);
+const TCODColor TCODColor::violet(TCOD_VIOLET);
+const TCODColor TCODColor::purple(TCOD_PURPLE);
+const TCODColor TCODColor::fuchsia(TCOD_FUCHSIA);
+const TCODColor TCODColor::magenta(TCOD_MAGENTA);
+const TCODColor TCODColor::pink(TCOD_PINK);
+const TCODColor TCODColor::crimson(TCOD_CRIMSON);
+
+// dark colors
+const TCODColor TCODColor::darkRed(TCOD_DARK_RED);
+const TCODColor TCODColor::darkFlame(TCOD_DARK_FLAME);
+const TCODColor TCODColor::darkOrange(TCOD_DARK_ORANGE);
+const TCODColor TCODColor::darkAmber(TCOD_DARK_AMBER);
+const TCODColor TCODColor::darkYellow(TCOD_DARK_YELLOW);
+const TCODColor TCODColor::darkLime(TCOD_DARK_LIME);
+const TCODColor TCODColor::darkChartreuse(TCOD_DARK_CHARTREUSE);
+const TCODColor TCODColor::darkGreen(TCOD_DARK_GREEN);
+const TCODColor TCODColor::darkSea(TCOD_DARK_SEA);
+const TCODColor TCODColor::darkTurquoise(TCOD_DARK_TURQUOISE);
+const TCODColor TCODColor::darkCyan(TCOD_DARK_CYAN);
+const TCODColor TCODColor::darkSky(TCOD_DARK_SKY);
+const TCODColor TCODColor::darkAzure(TCOD_DARK_AZURE);
+const TCODColor TCODColor::darkBlue(TCOD_DARK_BLUE);
+const TCODColor TCODColor::darkHan(TCOD_DARK_HAN);
+const TCODColor TCODColor::darkViolet(TCOD_DARK_VIOLET);
+const TCODColor TCODColor::darkPurple(TCOD_DARK_PURPLE);
+const TCODColor TCODColor::darkFuchsia(TCOD_DARK_FUCHSIA);
+const TCODColor TCODColor::darkMagenta(TCOD_DARK_MAGENTA);
+const TCODColor TCODColor::darkPink(TCOD_DARK_PINK);
+const TCODColor TCODColor::darkCrimson(TCOD_DARK_CRIMSON);
+
+// darker colors
+const TCODColor TCODColor::darkerRed(TCOD_DARKER_RED);
+const TCODColor TCODColor::darkerFlame(TCOD_DARKER_FLAME);
+const TCODColor TCODColor::darkerOrange(TCOD_DARKER_ORANGE);
+const TCODColor TCODColor::darkerAmber(TCOD_DARKER_AMBER);
+const TCODColor TCODColor::darkerYellow(TCOD_DARKER_YELLOW);
+const TCODColor TCODColor::darkerLime(TCOD_DARKER_LIME);
+const TCODColor TCODColor::darkerChartreuse(TCOD_DARKER_CHARTREUSE);
+const TCODColor TCODColor::darkerGreen(TCOD_DARKER_GREEN);
+const TCODColor TCODColor::darkerSea(TCOD_DARKER_SEA);
+const TCODColor TCODColor::darkerTurquoise(TCOD_DARKER_TURQUOISE);
+const TCODColor TCODColor::darkerCyan(TCOD_DARKER_CYAN);
+const TCODColor TCODColor::darkerSky(TCOD_DARKER_SKY);
+const TCODColor TCODColor::darkerAzure(TCOD_DARKER_AZURE);
+const TCODColor TCODColor::darkerBlue(TCOD_DARKER_BLUE);
+const TCODColor TCODColor::darkerHan(TCOD_DARKER_HAN);
+const TCODColor TCODColor::darkerViolet(TCOD_DARKER_VIOLET);
+const TCODColor TCODColor::darkerPurple(TCOD_DARKER_PURPLE);
+const TCODColor TCODColor::darkerFuchsia(TCOD_DARKER_FUCHSIA);
+const TCODColor TCODColor::darkerMagenta(TCOD_DARKER_MAGENTA);
+const TCODColor TCODColor::darkerPink(TCOD_DARKER_PINK);
+const TCODColor TCODColor::darkerCrimson(TCOD_DARKER_CRIMSON);
+
+// darkest colors
+const TCODColor TCODColor::darkestRed(TCOD_DARKEST_RED);
+const TCODColor TCODColor::darkestFlame(TCOD_DARKEST_FLAME);
+const TCODColor TCODColor::darkestOrange(TCOD_DARKEST_ORANGE);
+const TCODColor TCODColor::darkestAmber(TCOD_DARKEST_AMBER);
+const TCODColor TCODColor::darkestYellow(TCOD_DARKEST_YELLOW);
+const TCODColor TCODColor::darkestLime(TCOD_DARKEST_LIME);
+const TCODColor TCODColor::darkestChartreuse(TCOD_DARKEST_CHARTREUSE);
+const TCODColor TCODColor::darkestGreen(TCOD_DARKEST_GREEN);
+const TCODColor TCODColor::darkestSea(TCOD_DARKEST_SEA);
+const TCODColor TCODColor::darkestTurquoise(TCOD_DARKEST_TURQUOISE);
+const TCODColor TCODColor::darkestCyan(TCOD_DARKEST_CYAN);
+const TCODColor TCODColor::darkestSky(TCOD_DARKEST_SKY);
+const TCODColor TCODColor::darkestAzure(TCOD_DARKEST_AZURE);
+const TCODColor TCODColor::darkestBlue(TCOD_DARKEST_BLUE);
+const TCODColor TCODColor::darkestHan(TCOD_DARKEST_HAN);
+const TCODColor TCODColor::darkestViolet(TCOD_DARKEST_VIOLET);
+const TCODColor TCODColor::darkestPurple(TCOD_DARKEST_PURPLE);
+const TCODColor TCODColor::darkestFuchsia(TCOD_DARKEST_FUCHSIA);
+const TCODColor TCODColor::darkestMagenta(TCOD_DARKEST_MAGENTA);
+const TCODColor TCODColor::darkestPink(TCOD_DARKEST_PINK);
+const TCODColor TCODColor::darkestCrimson(TCOD_DARKEST_CRIMSON);
+
+// light colors
+const TCODColor TCODColor::lightRed(TCOD_LIGHT_RED);
+const TCODColor TCODColor::lightFlame(TCOD_LIGHT_FLAME);
+const TCODColor TCODColor::lightOrange(TCOD_LIGHT_ORANGE);
+const TCODColor TCODColor::lightAmber(TCOD_LIGHT_AMBER);
+const TCODColor TCODColor::lightYellow(TCOD_LIGHT_YELLOW);
+const TCODColor TCODColor::lightLime(TCOD_LIGHT_LIME);
+const TCODColor TCODColor::lightChartreuse(TCOD_LIGHT_CHARTREUSE);
+const TCODColor TCODColor::lightGreen(TCOD_LIGHT_GREEN);
+const TCODColor TCODColor::lightSea(TCOD_LIGHT_SEA);
+const TCODColor TCODColor::lightTurquoise(TCOD_LIGHT_TURQUOISE);
+const TCODColor TCODColor::lightCyan(TCOD_LIGHT_CYAN);
+const TCODColor TCODColor::lightSky(TCOD_LIGHT_SKY);
+const TCODColor TCODColor::lightAzure(TCOD_LIGHT_AZURE);
+const TCODColor TCODColor::lightBlue(TCOD_LIGHT_BLUE);
+const TCODColor TCODColor::lightHan(TCOD_LIGHT_HAN);
+const TCODColor TCODColor::lightViolet(TCOD_LIGHT_VIOLET);
+const TCODColor TCODColor::lightPurple(TCOD_LIGHT_PURPLE);
+const TCODColor TCODColor::lightFuchsia(TCOD_LIGHT_FUCHSIA);
+const TCODColor TCODColor::lightMagenta(TCOD_LIGHT_MAGENTA);
+const TCODColor TCODColor::lightPink(TCOD_LIGHT_PINK);
+const TCODColor TCODColor::lightCrimson(TCOD_LIGHT_CRIMSON);
+
+// lighter colors
+const TCODColor TCODColor::lighterRed(TCOD_LIGHTER_RED);
+const TCODColor TCODColor::lighterFlame(TCOD_LIGHTER_FLAME);
+const TCODColor TCODColor::lighterOrange(TCOD_LIGHTER_ORANGE);
+const TCODColor TCODColor::lighterAmber(TCOD_LIGHTER_AMBER);
+const TCODColor TCODColor::lighterYellow(TCOD_LIGHTER_YELLOW);
+const TCODColor TCODColor::lighterLime(TCOD_LIGHTER_LIME);
+const TCODColor TCODColor::lighterChartreuse(TCOD_LIGHTER_CHARTREUSE);
+const TCODColor TCODColor::lighterGreen(TCOD_LIGHTER_GREEN);
+const TCODColor TCODColor::lighterSea(TCOD_LIGHTER_SEA);
+const TCODColor TCODColor::lighterTurquoise(TCOD_LIGHTER_TURQUOISE);
+const TCODColor TCODColor::lighterCyan(TCOD_LIGHTER_CYAN);
+const TCODColor TCODColor::lighterSky(TCOD_LIGHTER_SKY);
+const TCODColor TCODColor::lighterAzure(TCOD_LIGHTER_AZURE);
+const TCODColor TCODColor::lighterBlue(TCOD_LIGHTER_BLUE);
+const TCODColor TCODColor::lighterHan(TCOD_LIGHTER_HAN);
+const TCODColor TCODColor::lighterViolet(TCOD_LIGHTER_VIOLET);
+const TCODColor TCODColor::lighterPurple(TCOD_LIGHTER_PURPLE);
+const TCODColor TCODColor::lighterFuchsia(TCOD_LIGHTER_FUCHSIA);
+const TCODColor TCODColor::lighterMagenta(TCOD_LIGHTER_MAGENTA);
+const TCODColor TCODColor::lighterPink(TCOD_LIGHTER_PINK);
+const TCODColor TCODColor::lighterCrimson(TCOD_LIGHTER_CRIMSON);
+
+// lightest colors
+const TCODColor TCODColor::lightestRed(TCOD_LIGHTEST_RED);
+const TCODColor TCODColor::lightestFlame(TCOD_LIGHTEST_FLAME);
+const TCODColor TCODColor::lightestOrange(TCOD_LIGHTEST_ORANGE);
+const TCODColor TCODColor::lightestAmber(TCOD_LIGHTEST_AMBER);
+const TCODColor TCODColor::lightestYellow(TCOD_LIGHTEST_YELLOW);
+const TCODColor TCODColor::lightestLime(TCOD_LIGHTEST_LIME);
+const TCODColor TCODColor::lightestChartreuse(TCOD_LIGHTEST_CHARTREUSE);
+const TCODColor TCODColor::lightestGreen(TCOD_LIGHTEST_GREEN);
+const TCODColor TCODColor::lightestSea(TCOD_LIGHTEST_SEA);
+const TCODColor TCODColor::lightestTurquoise(TCOD_LIGHTEST_TURQUOISE);
+const TCODColor TCODColor::lightestCyan(TCOD_LIGHTEST_CYAN);
+const TCODColor TCODColor::lightestSky(TCOD_LIGHTEST_SKY);
+const TCODColor TCODColor::lightestAzure(TCOD_LIGHTEST_AZURE);
+const TCODColor TCODColor::lightestBlue(TCOD_LIGHTEST_BLUE);
+const TCODColor TCODColor::lightestHan(TCOD_LIGHTEST_HAN);
+const TCODColor TCODColor::lightestViolet(TCOD_LIGHTEST_VIOLET);
+const TCODColor TCODColor::lightestPurple(TCOD_LIGHTEST_PURPLE);
+const TCODColor TCODColor::lightestFuchsia(TCOD_LIGHTEST_FUCHSIA);
+const TCODColor TCODColor::lightestMagenta(TCOD_LIGHTEST_MAGENTA);
+const TCODColor TCODColor::lightestPink(TCOD_LIGHTEST_PINK);
+const TCODColor TCODColor::lightestCrimson(TCOD_LIGHTEST_CRIMSON);
+
+// desaturated colors
+const TCODColor TCODColor::desaturatedRed(TCOD_DESATURATED_RED);
+const TCODColor TCODColor::desaturatedFlame(TCOD_DESATURATED_FLAME);
+const TCODColor TCODColor::desaturatedOrange(TCOD_DESATURATED_ORANGE);
+const TCODColor TCODColor::desaturatedAmber(TCOD_DESATURATED_AMBER);
+const TCODColor TCODColor::desaturatedYellow(TCOD_DESATURATED_YELLOW);
+const TCODColor TCODColor::desaturatedLime(TCOD_DESATURATED_LIME);
+const TCODColor TCODColor::desaturatedChartreuse(TCOD_DESATURATED_CHARTREUSE);
+const TCODColor TCODColor::desaturatedGreen(TCOD_DESATURATED_GREEN);
+const TCODColor TCODColor::desaturatedSea(TCOD_DESATURATED_SEA);
+const TCODColor TCODColor::desaturatedTurquoise(TCOD_DESATURATED_TURQUOISE);
+const TCODColor TCODColor::desaturatedCyan(TCOD_DESATURATED_CYAN);
+const TCODColor TCODColor::desaturatedSky(TCOD_DESATURATED_SKY);
+const TCODColor TCODColor::desaturatedAzure(TCOD_DESATURATED_AZURE);
+const TCODColor TCODColor::desaturatedBlue(TCOD_DESATURATED_BLUE);
+const TCODColor TCODColor::desaturatedHan(TCOD_DESATURATED_HAN);
+const TCODColor TCODColor::desaturatedViolet(TCOD_DESATURATED_VIOLET);
+const TCODColor TCODColor::desaturatedPurple(TCOD_DESATURATED_PURPLE);
+const TCODColor TCODColor::desaturatedFuchsia(TCOD_DESATURATED_FUCHSIA);
+const TCODColor TCODColor::desaturatedMagenta(TCOD_DESATURATED_MAGENTA);
+const TCODColor TCODColor::desaturatedPink(TCOD_DESATURATED_PINK);
+const TCODColor TCODColor::desaturatedCrimson(TCOD_DESATURATED_CRIMSON);
+
+//special
+const TCODColor TCODColor::brass(TCOD_BRASS);
+const TCODColor TCODColor::copper(TCOD_COPPER);
+const TCODColor TCODColor::gold(TCOD_GOLD);
+const TCODColor TCODColor::silver(TCOD_SILVER);
+
+//miscellaneous
+const TCODColor TCODColor::celadon(TCOD_CELADON);
+const TCODColor TCODColor::peach(TCOD_PEACH);
+
+#ifndef TCOD_HAIKU
+// color array
+const TCODColor TCODColor::colors[TCOD_COLOR_NB][TCOD_COLOR_LEVELS] = {
+ {TCODColor(TCOD_DESATURATED_RED),TCODColor(TCOD_LIGHTEST_RED),TCODColor(TCOD_LIGHTER_RED),TCODColor(TCOD_LIGHT_RED),TCODColor(TCOD_RED),TCODColor(TCOD_DARK_RED),TCODColor(TCOD_DARKER_RED),TCODColor(TCOD_DARKEST_RED)},
+ {TCODColor(TCOD_DESATURATED_FLAME),TCODColor(TCOD_LIGHTEST_FLAME),TCODColor(TCOD_LIGHTER_FLAME),TCODColor(TCOD_LIGHT_FLAME),TCODColor(TCOD_FLAME),TCODColor(TCOD_DARK_FLAME),TCODColor(TCOD_DARKER_FLAME),TCODColor(TCOD_DARKEST_FLAME)},
+ {TCODColor(TCOD_DESATURATED_ORANGE),TCODColor(TCOD_LIGHTEST_ORANGE),TCODColor(TCOD_LIGHTER_ORANGE),TCODColor(TCOD_LIGHT_ORANGE),TCODColor(TCOD_ORANGE),TCODColor(TCOD_DARK_ORANGE),TCODColor(TCOD_DARKER_ORANGE),TCODColor(TCOD_DARKEST_ORANGE)},
+ {TCODColor(TCOD_DESATURATED_AMBER),TCODColor(TCOD_LIGHTEST_AMBER),TCODColor(TCOD_LIGHTER_AMBER),TCODColor(TCOD_LIGHT_AMBER),TCODColor(TCOD_AMBER),TCODColor(TCOD_DARK_AMBER),TCODColor(TCOD_DARKER_AMBER),TCODColor(TCOD_DARKEST_AMBER)},
+ {TCODColor(TCOD_DESATURATED_YELLOW),TCODColor(TCOD_LIGHTEST_YELLOW),TCODColor(TCOD_LIGHTER_YELLOW),TCODColor(TCOD_LIGHT_YELLOW),TCODColor(TCOD_YELLOW),TCODColor(TCOD_DARK_YELLOW),TCODColor(TCOD_DARKER_YELLOW),TCODColor(TCOD_DARKEST_YELLOW)},
+ {TCODColor(TCOD_DESATURATED_LIME),TCODColor(TCOD_LIGHTEST_LIME),TCODColor(TCOD_LIGHTER_LIME),TCODColor(TCOD_LIGHT_LIME),TCODColor(TCOD_LIME),TCODColor(TCOD_DARK_LIME),TCODColor(TCOD_DARKER_LIME),TCODColor(TCOD_DARKEST_LIME)},
+ {TCODColor(TCOD_DESATURATED_CHARTREUSE),TCODColor(TCOD_LIGHTEST_CHARTREUSE),TCODColor(TCOD_LIGHTER_CHARTREUSE),TCODColor(TCOD_LIGHT_CHARTREUSE),TCODColor(TCOD_CHARTREUSE),TCODColor(TCOD_DARK_CHARTREUSE),TCODColor(TCOD_DARKER_CHARTREUSE),TCODColor(TCOD_DARKEST_CHARTREUSE)},
+ {TCODColor(TCOD_DESATURATED_GREEN),TCODColor(TCOD_LIGHTEST_GREEN),TCODColor(TCOD_LIGHTER_GREEN),TCODColor(TCOD_LIGHT_GREEN),TCODColor(TCOD_GREEN),TCODColor(TCOD_DARK_GREEN),TCODColor(TCOD_DARKER_GREEN),TCODColor(TCOD_DARKEST_GREEN)},
+ {TCODColor(TCOD_DESATURATED_SEA),TCODColor(TCOD_LIGHTEST_SEA),TCODColor(TCOD_LIGHTER_SEA),TCODColor(TCOD_LIGHT_SEA),TCODColor(TCOD_SEA),TCODColor(TCOD_DARK_SEA),TCODColor(TCOD_DARKER_SEA),TCODColor(TCOD_DARKEST_SEA)},
+ {TCODColor(TCOD_DESATURATED_TURQUOISE),TCODColor(TCOD_LIGHTEST_TURQUOISE),TCODColor(TCOD_LIGHTER_TURQUOISE),TCODColor(TCOD_LIGHT_TURQUOISE),TCODColor(TCOD_TURQUOISE),TCODColor(TCOD_DARK_TURQUOISE),TCODColor(TCOD_DARKER_TURQUOISE),TCODColor(TCOD_DARKEST_TURQUOISE)},
+ {TCODColor(TCOD_DESATURATED_CYAN),TCODColor(TCOD_LIGHTEST_CYAN),TCODColor(TCOD_LIGHTER_CYAN),TCODColor(TCOD_LIGHT_CYAN),TCODColor(TCOD_CYAN),TCODColor(TCOD_DARK_CYAN),TCODColor(TCOD_DARKER_CYAN),TCODColor(TCOD_DARKEST_CYAN)},
+ {TCODColor(TCOD_DESATURATED_SKY),TCODColor(TCOD_LIGHTEST_SKY),TCODColor(TCOD_LIGHTER_SKY),TCODColor(TCOD_LIGHT_SKY),TCODColor(TCOD_SKY),TCODColor(TCOD_DARK_SKY),TCODColor(TCOD_DARKER_SKY),TCODColor(TCOD_DARKEST_SKY)},
+ {TCODColor(TCOD_DESATURATED_AZURE),TCODColor(TCOD_LIGHTEST_AZURE),TCODColor(TCOD_LIGHTER_AZURE),TCODColor(TCOD_LIGHT_AZURE),TCODColor(TCOD_AZURE),TCODColor(TCOD_DARK_AZURE),TCODColor(TCOD_DARKER_AZURE),TCODColor(TCOD_DARKEST_AZURE)},
+ {TCODColor(TCOD_DESATURATED_BLUE),TCODColor(TCOD_LIGHTEST_BLUE),TCODColor(TCOD_LIGHTER_BLUE),TCODColor(TCOD_LIGHT_BLUE),TCODColor(TCOD_BLUE),TCODColor(TCOD_DARK_BLUE),TCODColor(TCOD_DARKER_BLUE),TCODColor(TCOD_DARKEST_BLUE)},
+ {TCODColor(TCOD_DESATURATED_HAN),TCODColor(TCOD_LIGHTEST_HAN),TCODColor(TCOD_LIGHTER_HAN),TCODColor(TCOD_LIGHT_HAN),TCODColor(TCOD_HAN),TCODColor(TCOD_DARK_HAN),TCODColor(TCOD_DARKER_HAN),TCODColor(TCOD_DARKEST_HAN)},
+ {TCODColor(TCOD_DESATURATED_VIOLET),TCODColor(TCOD_LIGHTEST_VIOLET),TCODColor(TCOD_LIGHTER_VIOLET),TCODColor(TCOD_LIGHT_VIOLET),TCODColor(TCOD_VIOLET),TCODColor(TCOD_DARK_VIOLET),TCODColor(TCOD_DARKER_VIOLET),TCODColor(TCOD_DARKEST_VIOLET)},
+ {TCODColor(TCOD_DESATURATED_PURPLE),TCODColor(TCOD_LIGHTEST_PURPLE),TCODColor(TCOD_LIGHTER_PURPLE),TCODColor(TCOD_LIGHT_PURPLE),TCODColor(TCOD_PURPLE),TCODColor(TCOD_DARK_PURPLE),TCODColor(TCOD_DARKER_PURPLE),TCODColor(TCOD_DARKEST_PURPLE)},
+ {TCODColor(TCOD_DESATURATED_FUCHSIA),TCODColor(TCOD_LIGHTEST_FUCHSIA),TCODColor(TCOD_LIGHTER_FUCHSIA),TCODColor(TCOD_LIGHT_FUCHSIA),TCODColor(TCOD_FUCHSIA),TCODColor(TCOD_DARK_FUCHSIA),TCODColor(TCOD_DARKER_FUCHSIA),TCODColor(TCOD_DARKEST_FUCHSIA)},
+ {TCODColor(TCOD_DESATURATED_MAGENTA),TCODColor(TCOD_LIGHTEST_MAGENTA),TCODColor(TCOD_LIGHTER_MAGENTA),TCODColor(TCOD_LIGHT_MAGENTA),TCODColor(TCOD_MAGENTA),TCODColor(TCOD_DARK_MAGENTA),TCODColor(TCOD_DARKER_MAGENTA),TCODColor(TCOD_DARKEST_MAGENTA)},
+ {TCODColor(TCOD_DESATURATED_PINK),TCODColor(TCOD_LIGHTEST_PINK),TCODColor(TCOD_LIGHTER_PINK),TCODColor(TCOD_LIGHT_PINK),TCODColor(TCOD_PINK),TCODColor(TCOD_DARK_PINK),TCODColor(TCOD_DARKER_PINK),TCODColor(TCOD_DARKEST_PINK)},
+ {TCODColor(TCOD_DESATURATED_CRIMSON),TCODColor(TCOD_LIGHTEST_CRIMSON),TCODColor(TCOD_LIGHTER_CRIMSON),TCODColor(TCOD_LIGHT_CRIMSON),TCODColor(TCOD_CRIMSON),TCODColor(TCOD_DARK_CRIMSON),TCODColor(TCOD_DARKER_CRIMSON),TCODColor(TCOD_DARKEST_CRIMSON)}
+};
+#endif
+
+TCODColor::TCODColor(float h, float s, float v) {
+ //setHSV(h,s,v);
+ TCOD_color_t c = TCOD_color_HSV(h,s,v);
+ r = c.r; g = c.g; b = c.b;
+}
+
+void TCODColor::setHSV(float h, float s, float v) {
+ TCOD_color_t c;
+ TCOD_color_set_HSV(&c,h,s,v);
+ r = c.r; g = c.g; b = c.b;
+}
+
+void TCODColor::setHue (float h) {
+ TCOD_color_t c = { r, g, b };
+ TCOD_color_set_hue (&c, h);
+ r = c.r; g = c.g; b = c.b;
+}
+
+void TCODColor::setSaturation (float s) {
+ TCOD_color_t c = { r, g, b };
+ TCOD_color_set_saturation (&c, s);
+ r = c.r; g = c.g; b = c.b;
+}
+
+void TCODColor::setValue (float v) {
+ TCOD_color_t c = { r, g, b };
+ TCOD_color_set_value (&c, v);
+ r = c.r; g = c.g; b = c.b;
+}
+
+void TCODColor::getHSV(float *h, float *s, float *v) const {
+ TCOD_color_t c={r,g,b};
+ TCOD_color_get_HSV(c,h,s,v);
+}
+
+float TCODColor::getHue () {
+ TCOD_color_t c = { r, g, b };
+ return TCOD_color_get_hue(c);
+}
+
+float TCODColor::getSaturation () {
+ TCOD_color_t c = { r, g, b };
+ return TCOD_color_get_saturation(c);
+}
+
+float TCODColor::getValue () {
+ TCOD_color_t c = { r, g, b };
+ return TCOD_color_get_value(c);
+}
+
+void TCODColor::shiftHue (float hshift) {
+ TCOD_color_t c = { r, g, b };
+ TCOD_color_shift_hue (&c, hshift);
+ r = c.r; g = c.g; b = c.b;
+}
+
+void TCODColor::scaleHSV (float sscale, float vscale) {
+ TCOD_color_t c = {r,g,b};
+ TCOD_color_scale_HSV(&c,sscale,vscale);
+ r = c.r; g = c.g; b = c.b;
+}
+
+// non member operators
+TCODColor operator *(float value, const TCODColor &c) {
+ return c*value;
+}
+
+void TCODColor::genMap(TCODColor *map, int nbKey, TCODColor const *keyColor,
+ int const *keyIndex)
+{
+ for (int segment = 0; segment < nbKey - 1; ++segment) {
+ int idxStart = keyIndex[segment];
+ int idxEnd = keyIndex[segment + 1];
+ for (int idx = idxStart; idx <= idxEnd; ++idx) {
+ map[idx] = TCODColor::lerp(
+ keyColor[segment],
+ keyColor[segment + 1],
+ static_cast(idx - idxStart) / (idxEnd - idxStart)
+ );
+ }
+ }
+}
diff --git a/tcod_sys/libtcod/include/color.h b/tcod_sys/libtcod/src/libtcod/color.h
similarity index 78%
rename from tcod_sys/libtcod/include/color.h
rename to tcod_sys/libtcod/src/libtcod/color.h
index 3050f5c53..27817f187 100644
--- a/tcod_sys/libtcod/include/color.h
+++ b/tcod_sys/libtcod/src/libtcod/color.h
@@ -1,66 +1,75 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
#ifndef _TCOD_COLOR_H
#define _TCOD_COLOR_H
-#include "libtcod_portability.h"
+#include "portability.h"
+#include "color/color.h"
#ifdef __cplusplus
extern "C" {
#endif
-
-typedef struct {
- uint8_t r,g,b;
-} TCOD_color_t;
-
/* constructors */
TCODLIB_API TCOD_color_t TCOD_color_RGB(uint8_t r, uint8_t g, uint8_t b);
-TCODLIB_API TCOD_color_t TCOD_color_HSV(float h, float s, float v);
+TCODLIB_API TCOD_color_t TCOD_color_HSV(float hue, float saturation,
+ float value);
/* basic operations */
-TCODLIB_API bool TCOD_color_equals (TCOD_color_t c1, TCOD_color_t c2);
-TCODLIB_API TCOD_color_t TCOD_color_add (TCOD_color_t c1, TCOD_color_t c2);
-TCODLIB_API TCOD_color_t TCOD_color_subtract (TCOD_color_t c1, TCOD_color_t c2);
-TCODLIB_API TCOD_color_t TCOD_color_multiply (TCOD_color_t c1, TCOD_color_t c2);
-TCODLIB_API TCOD_color_t TCOD_color_multiply_scalar (TCOD_color_t c1, float value);
-TCODLIB_API TCOD_color_t TCOD_color_lerp (TCOD_color_t c1, TCOD_color_t c2, float coef);
+TCODLIB_API bool TCOD_color_equals(TCOD_color_t c1, TCOD_color_t c2);
+TCODLIB_API TCOD_color_t TCOD_color_add(TCOD_color_t c1, TCOD_color_t c2);
+TCODLIB_API TCOD_color_t TCOD_color_subtract(TCOD_color_t c1, TCOD_color_t c2);
+TCODLIB_API TCOD_color_t TCOD_color_multiply(TCOD_color_t c1, TCOD_color_t c2);
+TCODLIB_API TCOD_color_t TCOD_color_multiply_scalar(TCOD_color_t c1,
+ float value);
+TCODLIB_API TCOD_color_t TCOD_color_lerp(TCOD_color_t c1, TCOD_color_t c2,
+ float coef);
/* HSV transformations */
-TCODLIB_API void TCOD_color_set_HSV (TCOD_color_t *c,float h, float s, float v);
-TCODLIB_API void TCOD_color_get_HSV (TCOD_color_t c,float * h, float * s, float * v);
-TCODLIB_API float TCOD_color_get_hue (TCOD_color_t c);
-TCODLIB_API void TCOD_color_set_hue (TCOD_color_t *c, float h);
-TCODLIB_API float TCOD_color_get_saturation (TCOD_color_t c);
-TCODLIB_API void TCOD_color_set_saturation (TCOD_color_t *c, float s);
-TCODLIB_API float TCOD_color_get_value (TCOD_color_t c);
-TCODLIB_API void TCOD_color_set_value (TCOD_color_t *c, float v);
-TCODLIB_API void TCOD_color_shift_hue (TCOD_color_t *c, float hshift);
-TCODLIB_API void TCOD_color_scale_HSV (TCOD_color_t *c, float scoef, float vcoef);
+TCODLIB_API void TCOD_color_set_HSV(TCOD_color_t *color,
+ float hue, float saturation, float value);
+TCODLIB_API void TCOD_color_get_HSV(
+ TCOD_color_t color, float *hue, float *saturation, float *value);
+TCODLIB_API float TCOD_color_get_hue(TCOD_color_t color);
+TCODLIB_API void TCOD_color_set_hue(TCOD_color_t *color, float hue);
+TCODLIB_API float TCOD_color_get_saturation(TCOD_color_t color);
+TCODLIB_API void TCOD_color_set_saturation(TCOD_color_t *color,
+ float saturation);
+TCODLIB_API float TCOD_color_get_value(TCOD_color_t color);
+TCODLIB_API void TCOD_color_set_value(TCOD_color_t *color, float value);
+TCODLIB_API void TCOD_color_shift_hue(TCOD_color_t *color, float hshift);
+TCODLIB_API void TCOD_color_scale_HSV(TCOD_color_t *color,
+ float saturation_coef, float value_coef);
/* color map */
-TCODLIB_API void TCOD_color_gen_map(TCOD_color_t *map, int nb_key, TCOD_color_t const *key_color, int const *key_index);
+TCODLIB_API void TCOD_color_gen_map(TCOD_color_t *map, int nb_key,
+ const TCOD_color_t *key_color,
+ const int *key_index);
/* color names */
enum {
diff --git a/tcod_sys/libtcod/include/color.hpp b/tcod_sys/libtcod/src/libtcod/color.hpp
similarity index 86%
rename from tcod_sys/libtcod/include/color.hpp
rename to tcod_sys/libtcod/src/libtcod/color.hpp
index df567cd5b..202a37a90 100644
--- a/tcod_sys/libtcod/include/color.hpp
+++ b/tcod_sys/libtcod/src/libtcod/color.hpp
@@ -1,35 +1,41 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
#ifndef _TCOD_COLOR_HPP
#define _TCOD_COLOR_HPP
+#include
+
#include "color.h"
-#include "libtcod_utility.h"
+#include "utility.h"
// color constants uses to generate @ColorTable
/**
@ColorCategory STANDARD COLORS
@@ -78,7 +84,7 @@
A color is defined by its red, green and blue component between 0 and 255.
You can use the following predefined colors (hover over a color to see its full name and R,G,B values):
@ColorTable
- @CppEx
+ @CppEx
TCODColor::desaturatedRed
TCODColor::lightestRed
TCODColor::lighterRed
@@ -87,7 +93,7 @@ You can use the following predefined colors (hover over a color to see its full
TCODColor::darkRed
TCODColor::darkerRed
TCODColor::darkestRed
- @CEx
+ @CEx
TCOD_desaturated_red
TCOD_lightest_red
TCOD_lighter_red
@@ -96,7 +102,7 @@ You can use the following predefined colors (hover over a color to see its full
TCOD_dark_red
TCOD_darker_red
TCOD_darkest_red
- @PyEx
+ @PyEx
libtcod.desaturated_red
libtcod.lightest_red
libtcod.lighter_red
@@ -105,7 +111,7 @@ You can use the following predefined colors (hover over a color to see its full
libtcod.dark_red
libtcod.darker_red
libtcod.darkest_red
- @C#Ex
+ @C#Ex
TCODColor::desaturatedRed
TCODColor::lightestRed
TCODColor::lighterRed
@@ -134,10 +140,10 @@ public :
@PageName color
@FuncTitle Create your own colors
@FuncDesc You can create your own colours using a set of constructors, both for RGB and HSV values.
- @CppEx
+ @CppEx
TCODColor myColor(24,64,255); //RGB
TCODColor myOtherColor(321.0f,0.7f,1.0f); //HSV
- @CEx
+ @CEx
TCOD_color_t my_color={24,64,255}; /* RGB */
TCOD_color_t my_other_color = TCOD_color_RGB(24,64,255); /* RGB too */
TCOD_color_t my_yet_another_color = TCOD_color_HSV(321.0f,0.7f,1.0f); /* HSV */
@@ -146,35 +152,41 @@ public :
TCODColor myColor = new TCODColor(321.0f,0.7f,1.0f); //HSV
@LuaEx myColor = tcod.Color(24,24,255)
*/
- TCODColor(uint8_t r, uint8_t g, uint8_t b): r(r), g(g), b(b) {}
- TCODColor(int r, int g, int b): r(r), g(g), b(b) {}
+ TCODColor(uint8_t r_, uint8_t g_, uint8_t b_)
+ : r(r_), g(g_), b(b_)
+ {}
+ TCODColor(int r_, int g_, int b_)
+ : r(r_), g(g_), b(b_)
+ {}
TCODColor(const TCOD_color_t &col): r(col.r), g(col.g), b(col.b) {}
TCODColor(float h, float s, float v);
/**
@PageName color
@FuncTitle Compare two colors
- @CppEx
+ @CppEx
if (myColor == TCODColor::yellow) { ... }
if (myColor != TCODColor::white) { ... }
- @CEx
+ @CEx
if (TCOD_color_equals(my_color,TCOD_yellow)) { ... }
if (!TCOD_color_equals(my_color,TCOD_white)) { ... }
- @PyEx
+ @PyEx
if my_color == libtcod.yellow : ...
if my_color != litbcod.white : ...
- @C#Ex
+ @C#Ex
if (myColor.Equal(TCODColor.yellow)) { ... }
if (myColor.NotEqual(TCODColor.white)) { ... }
- @LuaEx
+ @LuaEx
if myColor == tcod.color.yellow then ... end
*/
- bool operator == (const TCODColor & c) const {
- return (c.r == r && c.g == g && c.b == b);
- }
- bool operator != (const TCODColor & c) const {
- return (c.r != r || c.g != g || c.b != b);
- }
+ bool operator == (const TCODColor& c) const
+ {
+ return (c.r == r && c.g == g && c.b == b);
+ }
+ bool operator != (const TCODColor& c) const
+ {
+ return !(*this == c);
+ }
/**
@PageName color
@@ -191,13 +203,10 @@ public :
@C#Ex TCODColor myDarkishRed = TCODColor.darkGrey.Multiply(TCODColor.lightRed);
@LuaEx myDarkishRed = tcod.color.darkGrey * tcod.color.lightRed
*/
- TCODColor operator * (const TCODColor & a) const {
- TCODColor ret;
- ret.r=(uint8_t)(((int)r)*a.r/255);
- ret.g=(uint8_t)(((int)g)*a.g/255);
- ret.b=(uint8_t)(((int)b)*a.b/255);
- return ret;
- }
+ TCODColor operator*(const TCODColor& rhs) const
+ {
+ return TCODColor(*this, rhs, [](int c1, int c2){ return c1 * c2 / 255; });
+ }
/**
@PageName color
@@ -215,20 +224,10 @@ public :
@C#Ex TCODColor myDarkishRed = TCODColor.lightRed.Multiply(0.5f);
@LuaEx myDarkishRed = tcod.color.lightRed * 0.5
*/
- TCODColor operator *(float value) const {
- TCOD_color_t ret;
- int r,g,b;
- r = (int)(this->r * value);
- g = (int)(this->g * value);
- b = (int)(this->b * value);
- r = CLAMP(0,255,r);
- g = CLAMP(0,255,g);
- b = CLAMP(0,255,b);
- ret.r=(uint8_t)r;
- ret.g=(uint8_t)g;
- ret.b=(uint8_t)b;
- return ret;
- }
+ TCODColor operator*(float value) const
+ {
+ return TCODColor(*this, [=](int c){ return static_cast(c * value); });
+ }
/**
@PageName color
@@ -244,19 +243,10 @@ public :
@C#Ex TCODColor myLightishRed = TCODColor.red.Plus(TCODColor.darkGrey)
@LuaEx myLightishRed = tcod.color.red + tcod.color.darkGrey
*/
- TCODColor operator + (const TCODColor & a) const {
- TCODColor ret;
- int r=(int)(this->r)+a.r;
- int g=(int)(this->g)+a.g;
- int b=(int)(this->b)+a.b;
- r = MIN(255,r);
- g = MIN(255,g);
- b = MIN(255,b);
- ret.r=(uint8_t)r;
- ret.g=(uint8_t)g;
- ret.b=(uint8_t)b;
- return ret;
- }
+ TCODColor operator+(const TCODColor & rhs) const
+ {
+ return TCODColor(*this, rhs, [](int c1, int c2){ return c1 + c2; });
+ }
/**
@PageName color
@@ -272,19 +262,10 @@ public :
@C#Ex TCODColor myRedish = TCODColor.red.Minus(TCODColor.darkGrey)
@LuaEx myRedish = tcod.color.red - tcod.color.darkGrey
*/
- TCODColor operator - (const TCODColor & a) const {
- TCODColor ret;
- int r=(int)(this->r)-a.r;
- int g=(int)(this->g)-a.g;
- int b=(int)(this->b)-a.b;
- r = MAX(0,r);
- g = MAX(0,g);
- b = MAX(0,b);
- ret.r=(uint8_t)r;
- ret.g=(uint8_t)g;
- ret.b=(uint8_t)b;
- return ret;
- }
+ TCODColor operator-(const TCODColor& rhs) const
+ {
+ return TCODColor(*this, rhs, [](int c1, int c2){ return c1 - c2; });
+ }
/**
@PageName color
@@ -305,13 +286,10 @@ coef should be between 0.0 and 1.0 but you can as well use other values
@C#Ex TCODColor myColor = TCODColor.Interpolate( TCODColor.darkGrey, TCODColor.lightRed, coef );
@LuaEx myColor = tcod.color.Interpolate( tcod.color.darkGrey, tcod.color.lightRed, coef )
*/
- static TCODColor lerp(const TCODColor &a, const TCODColor &b, float coef) {
- TCODColor ret;
- ret.r=(uint8_t)(a.r+(b.r-a.r)*coef);
- ret.g=(uint8_t)(a.g+(b.g-a.g)*coef);
- ret.b=(uint8_t)(a.b+(b.b-a.b)*coef);
- return ret;
- }
+ static TCODColor lerp(const TCODColor &c1, const TCODColor &c2, float coef)
+ {
+ return TCODColor(c1, c2, [=](int c, int d){ return c + (d - c) * coef; });
+ }
/**
@PageName color
@@ -334,15 +312,15 @@ coef should be between 0.0 and 1.0 but you can as well use other values
@PageName color
@FuncTitle Define a color's hue, saturation or lightness
@FuncDesc These functions set only a single component in the HSV color space.
- @Cpp
+ @Cpp
void TCODColor::setHue (float h)
void TCODColor::setSaturation (float s)
void TCODColor::setValue (float v)
- @C
+ @C
void TCOD_color_set_hue (TCOD_color_t *c, float h)
void TCOD_color_set_saturation (TCOD_color_t *c, float s)
void TCOD_color_set_value (TCOD_color_t *c, float v)
- @Lua
+ @Lua
Color:setHue(h)
Color:setSaturation(s)
Color:setValue(v)
@@ -373,11 +351,11 @@ coef should be between 0.0 and 1.0 but you can as well use other values
@PageName color
@FuncTitle Get a color's hue, saturation or value
@FuncDesc Should you need to extract only one of the HSV components, these functions are what you should call. Note that if you need all three values, it's way less burdensome for the CPU to call TCODColor::getHSV().
- @Cpp
+ @Cpp
float TCODColor::getHue ()
float TCODColor::getSaturation ()
float TCODColor::getValue ()
- @C
+ @C
float TCOD_color_get_hue (TCOD_color_t c)
float TCOD_color_get_saturation (TCOD_color_t c)
float TCOD_color_get_value (TCOD_color_t c)
@@ -452,17 +430,17 @@ coef should be between 0.0 and 1.0 but you can as well use other values
@Param keyColor Array of nbKey colors containing the color of each key
@Param keyIndex Array of nbKey integers containing the index of each key.
If you want to fill the map array, keyIndex[0] must be 0 and keyIndex[nbKey-1] is the number of elements in map minus 1 but you can also use the function to fill only a part of the map array.
- @CppEx
+ @CppEx
int idx[] = { 0, 4, 8 }; // indexes of the keys
TCODColor col[] = { TCODColor( 0,0,0 ), TCODColor(255,0,0), TCODColor(255,255,255) }; // colors : black, red, white
TCODColor map[9];
TCODColor::genMap(map,3,col,idx);
- @CEx
+ @CEx
int idx[] = { 0, 4, 8 }; // indexes of the keys
TCOD_color_t col[] = { { 0,0,0 }, {255,0,0}, {255,255,255} }; // colors : black, red, white
TCOD_color_t map[9];
TCOD_color_gen_map(map,3,col,idx);
- @PyEx
+ @PyEx
idx = [ 0, 4, 8 ] # indexes of the keys
col = [ libtcod.Color( 0,0,0 ), libtcod.Color( 255,0,0 ), libtcod.Color(255,255,255) ] # colors : black, red, white
map=libtcod.color_gen_map(col,idx)
@@ -685,6 +663,33 @@ coef should be between 0.0 and 1.0 but you can as well use other values
// miscellaneous
static const TCODColor celadon;
static const TCODColor peach;
+ private:
+ /**
+ * Return a color transformed by a lambda.
+ */
+ template
+ TCODColor(const TCODColor& color, const F& lambda)
+ : r(clamp_(lambda(color.r))),
+ g(clamp_(lambda(color.g))),
+ b(clamp_(lambda(color.b)))
+ {}
+ /**
+ * Return a color from two colors combined using a lambda.
+ */
+ template
+ TCODColor(const TCODColor& color1, const TCODColor& color2, const F& lambda)
+ : r(clamp_(lambda(color1.r, color2.r))),
+ g(clamp_(lambda(color1.g, color2.g))),
+ b(clamp_(lambda(color1.b, color2.b)))
+ {}
+ /**
+ * Return a color value clamped between 0 to 255.
+ */
+ template
+ static constexpr uint8_t clamp_(const T& value) noexcept
+ {
+ return static_cast(std::max(0, std::min(value, 255)));
+ }
};
TCODLIB_API TCODColor operator *(float value, const TCODColor &c);
diff --git a/tcod_sys/libtcod/src/libtcod/color/canvas.cpp b/tcod_sys/libtcod/src/libtcod/color/canvas.cpp
new file mode 100644
index 000000000..191836f8d
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/color/canvas.cpp
@@ -0,0 +1,82 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "canvas.h"
+
+#include
+
+#include
+#include
+
+#include "../../vendor/lodepng.h"
+
+namespace tcod {
+namespace image {
+/**
+ * Return true if the file at `path` exists.
+ */
+static bool file_exists(const std::string& path)
+{
+ struct stat buffer;
+ return stat(path.c_str(), &buffer) == 0;
+}
+Image load(const std::string& filename)
+{
+ if (!file_exists(filename)) {
+ throw std::runtime_error("File does not exist: " + filename);
+ }
+ unsigned img_width, img_height;
+ std::vector img_data;
+ if (auto err=lodepng::decode(img_data, img_width, img_height, filename)) {
+ throw std::runtime_error(lodepng_error_text(err));
+ }
+ Image image(img_width, img_height);
+ std::vector::iterator img_iter = img_data.begin();
+ for (int y = 0; y < image.height(); ++y) {
+ for (int x = 0; x < image.width(); ++x) {
+ image.atf(x, y) = ColorRGBA{
+ img_iter[0], img_iter[1], img_iter[2], img_iter[3]};
+ img_iter += 4;
+ }
+ }
+ return image;
+}
+void save(const Image& image, const std::string& filename)
+{
+ const unsigned char* buffer =
+ reinterpret_cast(image.data());
+ if (auto err=lodepng::encode(filename, buffer,
+ image.width(), image.height())) {
+ throw std::runtime_error(lodepng_error_text(err));
+ }
+}
+} // namespace image
+} // namespace tcod
diff --git a/tcod_sys/libtcod/src/libtcod/color/canvas.h b/tcod_sys/libtcod/src/libtcod/color/canvas.h
new file mode 100644
index 000000000..205742811
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/color/canvas.h
@@ -0,0 +1,52 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef LIBTCOD_COLOR_CANVAS_H_
+#define LIBTCOD_COLOR_CANVAS_H_
+#ifdef __cplusplus
+#include
+#endif // __cplusplus
+
+#include "color.h"
+#include "../utility/vector2.h"
+#ifdef __cplusplus
+namespace tcod {
+namespace image {
+/**
+ * A Common Vector2 type used for 2d images.
+ */
+typedef Vector2 Image;
+Image load(const std::string& filename);
+void save(const Image& image, const std::string& filename);
+} // namespace image
+} // namespace tcod
+#endif /* __cplusplus */
+#endif /* LIBTCOD_COLOR_CANVAS_H_ */
diff --git a/tcod_sys/libtcod/src/libtcod/color/color.h b/tcod_sys/libtcod/src/libtcod/color/color.h
new file mode 100644
index 000000000..8a9fa3e12
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/color/color.h
@@ -0,0 +1,102 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef LIBTCOD_COLOR_COLOR_H_
+#define LIBTCOD_COLOR_COLOR_H_
+#include
+/**
+ * A three channel color struct.
+ */
+struct TCOD_ColorRGB {
+#ifdef __cplusplus
+ bool operator==(const TCOD_ColorRGB& rhs) const noexcept
+ {
+ return r == rhs.r && g == rhs.g && b == rhs.b;
+ }
+ bool operator!=(const TCOD_ColorRGB& rhs) const noexcept
+ {
+ return !(*this == rhs);
+ }
+#endif // __cplusplus
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+};
+typedef struct TCOD_ColorRGB TCOD_color_t;
+/**
+ * A four channel color struct.
+ */
+struct TCOD_ColorRGBA {
+#ifdef __cplusplus
+ bool operator==(const TCOD_ColorRGBA& rhs) const noexcept
+ {
+ return r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a;
+ }
+ bool operator!=(const TCOD_ColorRGBA& rhs) const noexcept
+ {
+ return !(*this == rhs);
+ }
+#endif // __cplusplus
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+ uint8_t a;
+};
+#ifdef __cplusplus
+namespace tcod {
+ struct ColorRGB: TCOD_ColorRGB {
+ ColorRGB() = default;
+ ColorRGB(uint8_t red, uint8_t green, uint8_t blue)
+ : TCOD_ColorRGB{red, green, blue}
+ {}
+ ColorRGB(const struct TCOD_ColorRGB& rhs)
+ : TCOD_ColorRGB{rhs}
+ {}
+ explicit ColorRGB(const struct TCOD_ColorRGBA& rhs)
+ : TCOD_ColorRGB{rhs.r, rhs.g, rhs.b}
+ {}
+ };
+ struct ColorRGBA: TCOD_ColorRGBA {
+ ColorRGBA() = default;
+ ColorRGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha=0xff)
+ : TCOD_ColorRGBA{red, green, blue, alpha}
+ {}
+ explicit ColorRGBA(const struct TCOD_ColorRGB& color,
+ uint8_t alpha=0xff)
+ : TCOD_ColorRGBA{color.r, color.g, color.b, alpha}
+ {}
+ ColorRGBA(const struct TCOD_ColorRGBA& rhs)
+ : TCOD_ColorRGBA{rhs}
+ {}
+ };
+} // namespace tcod
+#endif /* __cplusplus */
+#endif /* LIBTCOD_COLOR_COLOR_H_ */
diff --git a/tcod_sys/libtcod/src/color_c.c b/tcod_sys/libtcod/src/libtcod/color_c.c
similarity index 55%
rename from tcod_sys/libtcod/src/color_c.c
rename to tcod_sys/libtcod/src/libtcod/color_c.c
index b7146e330..444fd691d 100644
--- a/tcod_sys/libtcod/src/color_c.c
+++ b/tcod_sys/libtcod/src/libtcod/color_c.c
@@ -1,563 +1,616 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#include
-
-#include
-
-#include
-#include
-
-/* grey levels */
-const TCOD_color_t TCOD_black={TCOD_BLACK};
-const TCOD_color_t TCOD_darkest_grey={TCOD_DARKEST_GREY};
-const TCOD_color_t TCOD_darker_grey={TCOD_DARKER_GREY};
-const TCOD_color_t TCOD_dark_grey={TCOD_DARK_GREY};
-const TCOD_color_t TCOD_grey={TCOD_GREY};
-const TCOD_color_t TCOD_light_grey={TCOD_LIGHT_GREY};
-const TCOD_color_t TCOD_lighter_grey={TCOD_LIGHTER_GREY};
-const TCOD_color_t TCOD_lightest_grey={TCOD_LIGHTEST_GREY};
-const TCOD_color_t TCOD_darkest_gray={TCOD_DARKEST_GREY};
-const TCOD_color_t TCOD_darker_gray={TCOD_DARKER_GREY};
-const TCOD_color_t TCOD_dark_gray={TCOD_DARK_GREY};
-const TCOD_color_t TCOD_gray={TCOD_GREY};
-const TCOD_color_t TCOD_light_gray={TCOD_LIGHT_GREY};
-const TCOD_color_t TCOD_lighter_gray={TCOD_LIGHTER_GREY};
-const TCOD_color_t TCOD_lightest_gray={TCOD_LIGHTEST_GREY};
-const TCOD_color_t TCOD_white={TCOD_WHITE};
-
-/* sepia */
-const TCOD_color_t TCOD_darkest_sepia={TCOD_DARKEST_SEPIA};
-const TCOD_color_t TCOD_darker_sepia={TCOD_DARKER_SEPIA};
-const TCOD_color_t TCOD_dark_sepia={TCOD_DARK_SEPIA};
-const TCOD_color_t TCOD_sepia={TCOD_SEPIA};
-const TCOD_color_t TCOD_light_sepia={TCOD_LIGHT_SEPIA};
-const TCOD_color_t TCOD_lighter_sepia={TCOD_LIGHTER_SEPIA};
-const TCOD_color_t TCOD_lightest_sepia={TCOD_LIGHTEST_SEPIA};
-
-/* standard colors */
-const TCOD_color_t TCOD_red = {TCOD_RED};
-const TCOD_color_t TCOD_flame = {TCOD_FLAME};
-const TCOD_color_t TCOD_orange = {TCOD_ORANGE};
-const TCOD_color_t TCOD_amber = {TCOD_AMBER};
-const TCOD_color_t TCOD_yellow = {TCOD_YELLOW};
-const TCOD_color_t TCOD_lime = {TCOD_LIME};
-const TCOD_color_t TCOD_chartreuse = {TCOD_CHARTREUSE};
-const TCOD_color_t TCOD_green = {TCOD_GREEN};
-const TCOD_color_t TCOD_sea = {TCOD_SEA};
-const TCOD_color_t TCOD_turquoise = {TCOD_TURQUOISE};
-const TCOD_color_t TCOD_cyan = {TCOD_CYAN};
-const TCOD_color_t TCOD_sky = {TCOD_SKY};
-const TCOD_color_t TCOD_azure = {TCOD_AZURE};
-const TCOD_color_t TCOD_blue = {TCOD_BLUE};
-const TCOD_color_t TCOD_han = {TCOD_HAN};
-const TCOD_color_t TCOD_violet = {TCOD_VIOLET};
-const TCOD_color_t TCOD_purple = {TCOD_PURPLE};
-const TCOD_color_t TCOD_fuchsia = {TCOD_FUCHSIA};
-const TCOD_color_t TCOD_magenta = {TCOD_MAGENTA};
-const TCOD_color_t TCOD_pink = {TCOD_PINK};
-const TCOD_color_t TCOD_crimson = {TCOD_CRIMSON};
-
-/* dark colors */
-const TCOD_color_t TCOD_dark_red = {TCOD_DARK_RED};
-const TCOD_color_t TCOD_dark_flame = {TCOD_DARK_FLAME};
-const TCOD_color_t TCOD_dark_orange = {TCOD_DARK_ORANGE};
-const TCOD_color_t TCOD_dark_amber = {TCOD_DARK_AMBER};
-const TCOD_color_t TCOD_dark_yellow = {TCOD_DARK_YELLOW};
-const TCOD_color_t TCOD_dark_lime = {TCOD_DARK_LIME};
-const TCOD_color_t TCOD_dark_chartreuse = {TCOD_DARK_CHARTREUSE};
-const TCOD_color_t TCOD_dark_green = {TCOD_DARK_GREEN};
-const TCOD_color_t TCOD_dark_sea = {TCOD_DARK_SEA};
-const TCOD_color_t TCOD_dark_turquoise = {TCOD_DARK_TURQUOISE};
-const TCOD_color_t TCOD_dark_cyan = {TCOD_DARK_CYAN};
-const TCOD_color_t TCOD_dark_sky = {TCOD_DARK_SKY};
-const TCOD_color_t TCOD_dark_azure = {TCOD_DARK_AZURE};
-const TCOD_color_t TCOD_dark_blue = {TCOD_DARK_BLUE};
-const TCOD_color_t TCOD_dark_han = {TCOD_DARK_HAN};
-const TCOD_color_t TCOD_dark_violet = {TCOD_DARK_VIOLET};
-const TCOD_color_t TCOD_dark_purple = {TCOD_DARK_PURPLE};
-const TCOD_color_t TCOD_dark_fuchsia = {TCOD_DARK_FUCHSIA};
-const TCOD_color_t TCOD_dark_magenta = {TCOD_DARK_MAGENTA};
-const TCOD_color_t TCOD_dark_pink = {TCOD_DARK_PINK};
-const TCOD_color_t TCOD_dark_crimson = {TCOD_DARK_CRIMSON};
-
-/* darker colors */
-const TCOD_color_t TCOD_darker_red = {TCOD_DARKER_RED};
-const TCOD_color_t TCOD_darker_flame = {TCOD_DARKER_FLAME};
-const TCOD_color_t TCOD_darker_orange = {TCOD_DARKER_ORANGE};
-const TCOD_color_t TCOD_darker_amber = {TCOD_DARKER_AMBER};
-const TCOD_color_t TCOD_darker_yellow = {TCOD_DARKER_YELLOW};
-const TCOD_color_t TCOD_darker_lime = {TCOD_DARKER_LIME};
-const TCOD_color_t TCOD_darker_chartreuse = {TCOD_DARKER_CHARTREUSE};
-const TCOD_color_t TCOD_darker_green = {TCOD_DARKER_GREEN};
-const TCOD_color_t TCOD_darker_sea = {TCOD_DARKER_SEA};
-const TCOD_color_t TCOD_darker_turquoise = {TCOD_DARKER_TURQUOISE};
-const TCOD_color_t TCOD_darker_cyan = {TCOD_DARKER_CYAN};
-const TCOD_color_t TCOD_darker_sky = {TCOD_DARKER_SKY};
-const TCOD_color_t TCOD_darker_azure = {TCOD_DARKER_AZURE};
-const TCOD_color_t TCOD_darker_blue = {TCOD_DARKER_BLUE};
-const TCOD_color_t TCOD_darker_han = {TCOD_DARKER_HAN};
-const TCOD_color_t TCOD_darker_violet = {TCOD_DARKER_VIOLET};
-const TCOD_color_t TCOD_darker_purple = {TCOD_DARKER_PURPLE};
-const TCOD_color_t TCOD_darker_fuchsia = {TCOD_DARKER_FUCHSIA};
-const TCOD_color_t TCOD_darker_magenta = {TCOD_DARKER_MAGENTA};
-const TCOD_color_t TCOD_darker_pink = {TCOD_DARKER_PINK};
-const TCOD_color_t TCOD_darker_crimson = {TCOD_DARKER_CRIMSON};
-
-/* darkest colors */
-const TCOD_color_t TCOD_darkest_red = {TCOD_DARKEST_RED};
-const TCOD_color_t TCOD_darkest_flame = {TCOD_DARKEST_FLAME};
-const TCOD_color_t TCOD_darkest_orange = {TCOD_DARKEST_ORANGE};
-const TCOD_color_t TCOD_darkest_amber = {TCOD_DARKEST_AMBER};
-const TCOD_color_t TCOD_darkest_yellow = {TCOD_DARKEST_YELLOW};
-const TCOD_color_t TCOD_darkest_lime = {TCOD_DARKEST_LIME};
-const TCOD_color_t TCOD_darkest_chartreuse = {TCOD_DARKEST_CHARTREUSE};
-const TCOD_color_t TCOD_darkest_green = {TCOD_DARKEST_GREEN};
-const TCOD_color_t TCOD_darkest_sea = {TCOD_DARKEST_SEA};
-const TCOD_color_t TCOD_darkest_turquoise = {TCOD_DARKEST_TURQUOISE};
-const TCOD_color_t TCOD_darkest_cyan = {TCOD_DARKEST_CYAN};
-const TCOD_color_t TCOD_darkest_sky = {TCOD_DARKEST_SKY};
-const TCOD_color_t TCOD_darkest_azure = {TCOD_DARKEST_AZURE};
-const TCOD_color_t TCOD_darkest_blue = {TCOD_DARKEST_BLUE};
-const TCOD_color_t TCOD_darkest_han = {TCOD_DARKEST_HAN};
-const TCOD_color_t TCOD_darkest_violet = {TCOD_DARKEST_VIOLET};
-const TCOD_color_t TCOD_darkest_purple = {TCOD_DARKEST_PURPLE};
-const TCOD_color_t TCOD_darkest_fuchsia = {TCOD_DARKEST_FUCHSIA};
-const TCOD_color_t TCOD_darkest_magenta = {TCOD_DARKEST_MAGENTA};
-const TCOD_color_t TCOD_darkest_pink = {TCOD_DARKEST_PINK};
-const TCOD_color_t TCOD_darkest_crimson = {TCOD_DARKEST_CRIMSON};
-
-/* light colors */
-const TCOD_color_t TCOD_light_red = {TCOD_LIGHT_RED};
-const TCOD_color_t TCOD_light_flame = {TCOD_LIGHT_FLAME};
-const TCOD_color_t TCOD_light_orange = {TCOD_LIGHT_ORANGE};
-const TCOD_color_t TCOD_light_amber = {TCOD_LIGHT_AMBER};
-const TCOD_color_t TCOD_light_yellow = {TCOD_LIGHT_YELLOW};
-const TCOD_color_t TCOD_light_lime = {TCOD_LIGHT_LIME};
-const TCOD_color_t TCOD_light_chartreuse = {TCOD_LIGHT_CHARTREUSE};
-const TCOD_color_t TCOD_light_green = {TCOD_LIGHT_GREEN};
-const TCOD_color_t TCOD_light_sea = {TCOD_LIGHT_SEA};
-const TCOD_color_t TCOD_light_turquoise = {TCOD_LIGHT_TURQUOISE};
-const TCOD_color_t TCOD_light_cyan = {TCOD_LIGHT_CYAN};
-const TCOD_color_t TCOD_light_sky = {TCOD_LIGHT_SKY};
-const TCOD_color_t TCOD_light_azure = {TCOD_LIGHT_AZURE};
-const TCOD_color_t TCOD_light_blue = {TCOD_LIGHT_BLUE};
-const TCOD_color_t TCOD_light_han = {TCOD_LIGHT_HAN};
-const TCOD_color_t TCOD_light_violet = {TCOD_LIGHT_VIOLET};
-const TCOD_color_t TCOD_light_purple = {TCOD_LIGHT_PURPLE};
-const TCOD_color_t TCOD_light_fuchsia = {TCOD_LIGHT_FUCHSIA};
-const TCOD_color_t TCOD_light_magenta = {TCOD_LIGHT_MAGENTA};
-const TCOD_color_t TCOD_light_pink = {TCOD_LIGHT_PINK};
-const TCOD_color_t TCOD_light_crimson = {TCOD_LIGHT_CRIMSON};
-
-/*lighter colors */
-const TCOD_color_t TCOD_lighter_red = {TCOD_LIGHTER_RED};
-const TCOD_color_t TCOD_lighter_flame = {TCOD_LIGHTER_FLAME};
-const TCOD_color_t TCOD_lighter_orange = {TCOD_LIGHTER_ORANGE};
-const TCOD_color_t TCOD_lighter_amber = {TCOD_LIGHTER_AMBER};
-const TCOD_color_t TCOD_lighter_yellow = {TCOD_LIGHTER_YELLOW};
-const TCOD_color_t TCOD_lighter_lime = {TCOD_LIGHTER_LIME};
-const TCOD_color_t TCOD_lighter_chartreuse = {TCOD_LIGHTER_CHARTREUSE};
-const TCOD_color_t TCOD_lighter_green = {TCOD_LIGHTER_GREEN};
-const TCOD_color_t TCOD_lighter_sea = {TCOD_LIGHTER_SEA};
-const TCOD_color_t TCOD_lighter_turquoise = {TCOD_LIGHTER_TURQUOISE};
-const TCOD_color_t TCOD_lighter_cyan = {TCOD_LIGHTER_CYAN};
-const TCOD_color_t TCOD_lighter_sky = {TCOD_LIGHTER_SKY};
-const TCOD_color_t TCOD_lighter_azure = {TCOD_LIGHTER_AZURE};
-const TCOD_color_t TCOD_lighter_blue = {TCOD_LIGHTER_BLUE};
-const TCOD_color_t TCOD_lighter_han = {TCOD_LIGHTER_HAN};
-const TCOD_color_t TCOD_lighter_violet = {TCOD_LIGHTER_VIOLET};
-const TCOD_color_t TCOD_lighter_purple = {TCOD_LIGHTER_PURPLE};
-const TCOD_color_t TCOD_lighter_fuchsia = {TCOD_LIGHTER_FUCHSIA};
-const TCOD_color_t TCOD_lighter_magenta = {TCOD_LIGHTER_MAGENTA};
-const TCOD_color_t TCOD_lighter_pink = {TCOD_LIGHTER_PINK};
-const TCOD_color_t TCOD_lighter_crimson = {TCOD_LIGHTER_CRIMSON};
-
-/* lightest colors */
-const TCOD_color_t TCOD_lightest_red = {TCOD_LIGHTEST_RED};
-const TCOD_color_t TCOD_lightest_flame = {TCOD_LIGHTEST_FLAME};
-const TCOD_color_t TCOD_lightest_orange = {TCOD_LIGHTEST_ORANGE};
-const TCOD_color_t TCOD_lightest_amber = {TCOD_LIGHTEST_AMBER};
-const TCOD_color_t TCOD_lightest_yellow = {TCOD_LIGHTEST_YELLOW};
-const TCOD_color_t TCOD_lightest_lime = {TCOD_LIGHTEST_LIME};
-const TCOD_color_t TCOD_lightest_chartreuse = {TCOD_LIGHTEST_CHARTREUSE};
-const TCOD_color_t TCOD_lightest_green = {TCOD_LIGHTEST_GREEN};
-const TCOD_color_t TCOD_lightest_sea = {TCOD_LIGHTEST_SEA};
-const TCOD_color_t TCOD_lightest_turquoise = {TCOD_LIGHTEST_TURQUOISE};
-const TCOD_color_t TCOD_lightest_cyan = {TCOD_LIGHTEST_CYAN};
-const TCOD_color_t TCOD_lightest_sky = {TCOD_LIGHTEST_SKY};
-const TCOD_color_t TCOD_lightest_azure = {TCOD_LIGHTEST_AZURE};
-const TCOD_color_t TCOD_lightest_blue = {TCOD_LIGHTEST_BLUE};
-const TCOD_color_t TCOD_lightest_han = {TCOD_LIGHTEST_HAN};
-const TCOD_color_t TCOD_lightest_violet = {TCOD_LIGHTEST_VIOLET};
-const TCOD_color_t TCOD_lightest_purple = {TCOD_LIGHTEST_PURPLE};
-const TCOD_color_t TCOD_lightest_fuchsia = {TCOD_LIGHTEST_FUCHSIA};
-const TCOD_color_t TCOD_lightest_magenta = {TCOD_LIGHTEST_MAGENTA};
-const TCOD_color_t TCOD_lightest_pink = {TCOD_LIGHTEST_PINK};
-const TCOD_color_t TCOD_lightest_crimson = {TCOD_LIGHTEST_CRIMSON};
-
-/* desaturated colors */
-const TCOD_color_t TCOD_desaturated_red = {TCOD_DESATURATED_RED};
-const TCOD_color_t TCOD_desaturated_flame = {TCOD_DESATURATED_FLAME};
-const TCOD_color_t TCOD_desaturated_orange = {TCOD_DESATURATED_ORANGE};
-const TCOD_color_t TCOD_desaturated_amber = {TCOD_DESATURATED_AMBER};
-const TCOD_color_t TCOD_desaturated_yellow = {TCOD_DESATURATED_YELLOW};
-const TCOD_color_t TCOD_desaturated_lime = {TCOD_DESATURATED_LIME};
-const TCOD_color_t TCOD_desaturated_chartreuse = {TCOD_DESATURATED_CHARTREUSE};
-const TCOD_color_t TCOD_desaturated_green = {TCOD_DESATURATED_GREEN};
-const TCOD_color_t TCOD_desaturated_sea = {TCOD_DESATURATED_SEA};
-const TCOD_color_t TCOD_desaturated_turquoise = {TCOD_DESATURATED_TURQUOISE};
-const TCOD_color_t TCOD_desaturated_cyan = {TCOD_DESATURATED_CYAN};
-const TCOD_color_t TCOD_desaturated_sky = {TCOD_DESATURATED_SKY};
-const TCOD_color_t TCOD_desaturated_azure = {TCOD_DESATURATED_AZURE};
-const TCOD_color_t TCOD_desaturated_blue = {TCOD_DESATURATED_BLUE};
-const TCOD_color_t TCOD_desaturated_han = {TCOD_DESATURATED_HAN};
-const TCOD_color_t TCOD_desaturated_violet = {TCOD_DESATURATED_VIOLET};
-const TCOD_color_t TCOD_desaturated_purple = {TCOD_DESATURATED_PURPLE};
-const TCOD_color_t TCOD_desaturated_fuchsia = {TCOD_DESATURATED_FUCHSIA};
-const TCOD_color_t TCOD_desaturated_magenta = {TCOD_DESATURATED_MAGENTA};
-const TCOD_color_t TCOD_desaturated_pink = {TCOD_DESATURATED_PINK};
-const TCOD_color_t TCOD_desaturated_crimson = {TCOD_DESATURATED_CRIMSON};
-
-/* metallic */
-const TCOD_color_t TCOD_brass = {TCOD_BRASS};
-const TCOD_color_t TCOD_copper = {TCOD_COPPER};
-const TCOD_color_t TCOD_gold = {TCOD_GOLD};
-const TCOD_color_t TCOD_silver = {TCOD_SILVER};
-
-/* miscellaneous */
-const TCOD_color_t TCOD_celadon = {TCOD_CELADON};
-const TCOD_color_t TCOD_peach = {TCOD_PEACH};
-
-/* color array */
-const TCOD_color_t TCOD_colors[TCOD_COLOR_NB][TCOD_COLOR_LEVELS] = {
- {{TCOD_DESATURATED_RED},{TCOD_LIGHTEST_RED},{TCOD_LIGHTER_RED},{TCOD_LIGHT_RED},{TCOD_RED},{TCOD_DARK_RED},{TCOD_DARKER_RED},{TCOD_DARKEST_RED}},
- {{TCOD_DESATURATED_FLAME},{TCOD_LIGHTEST_FLAME},{TCOD_LIGHTER_FLAME},{TCOD_LIGHT_FLAME},{TCOD_FLAME},{TCOD_DARK_FLAME},{TCOD_DARKER_FLAME},{TCOD_DARKEST_FLAME}},
- {{TCOD_DESATURATED_ORANGE},{TCOD_LIGHTEST_ORANGE},{TCOD_LIGHTER_ORANGE},{TCOD_LIGHT_ORANGE},{TCOD_ORANGE},{TCOD_DARK_ORANGE},{TCOD_DARKER_ORANGE},{TCOD_DARKEST_ORANGE}},
- {{TCOD_DESATURATED_AMBER},{TCOD_LIGHTEST_AMBER},{TCOD_LIGHTER_AMBER},{TCOD_LIGHT_AMBER},{TCOD_AMBER},{TCOD_DARK_AMBER},{TCOD_DARKER_AMBER},{TCOD_DARKEST_AMBER}},
- {{TCOD_DESATURATED_YELLOW},{TCOD_LIGHTEST_YELLOW},{TCOD_LIGHTER_YELLOW},{TCOD_LIGHT_YELLOW},{TCOD_YELLOW},{TCOD_DARK_YELLOW},{TCOD_DARKER_YELLOW},{TCOD_DARKEST_YELLOW}},
- {{TCOD_DESATURATED_LIME},{TCOD_LIGHTEST_LIME},{TCOD_LIGHTER_LIME},{TCOD_LIGHT_LIME},{TCOD_LIME},{TCOD_DARK_LIME},{TCOD_DARKER_LIME},{TCOD_DARKEST_LIME}},
- {{TCOD_DESATURATED_CHARTREUSE},{TCOD_LIGHTEST_CHARTREUSE},{TCOD_LIGHTER_CHARTREUSE},{TCOD_LIGHT_CHARTREUSE},{TCOD_CHARTREUSE},{TCOD_DARK_CHARTREUSE},{TCOD_DARKER_CHARTREUSE},{TCOD_DARKEST_CHARTREUSE}},
- {{TCOD_DESATURATED_GREEN},{TCOD_LIGHTEST_GREEN},{TCOD_LIGHTER_GREEN},{TCOD_LIGHT_GREEN},{TCOD_GREEN},{TCOD_DARK_GREEN},{TCOD_DARKER_GREEN},{TCOD_DARKEST_GREEN}},
- {{TCOD_DESATURATED_SEA},{TCOD_LIGHTEST_SEA},{TCOD_LIGHTER_SEA},{TCOD_LIGHT_SEA},{TCOD_SEA},{TCOD_DARK_SEA},{TCOD_DARKER_SEA},{TCOD_DARKEST_SEA}},
- {{TCOD_DESATURATED_TURQUOISE},{TCOD_LIGHTEST_TURQUOISE},{TCOD_LIGHTER_TURQUOISE},{TCOD_LIGHT_TURQUOISE},{TCOD_TURQUOISE},{TCOD_DARK_TURQUOISE},{TCOD_DARKER_TURQUOISE},{TCOD_DARKEST_TURQUOISE}},
- {{TCOD_DESATURATED_CYAN},{TCOD_LIGHTEST_CYAN},{TCOD_LIGHTER_CYAN},{TCOD_LIGHT_CYAN},{TCOD_CYAN},{TCOD_DARK_CYAN},{TCOD_DARKER_CYAN},{TCOD_DARKEST_CYAN}},
- {{TCOD_DESATURATED_SKY},{TCOD_LIGHTEST_SKY},{TCOD_LIGHTER_SKY},{TCOD_LIGHT_SKY},{TCOD_SKY},{TCOD_DARK_SKY},{TCOD_DARKER_SKY},{TCOD_DARKEST_SKY}},
- {{TCOD_DESATURATED_AZURE},{TCOD_LIGHTEST_AZURE},{TCOD_LIGHTER_AZURE},{TCOD_LIGHT_AZURE},{TCOD_AZURE},{TCOD_DARK_AZURE},{TCOD_DARKER_AZURE},{TCOD_DARKEST_AZURE}},
- {{TCOD_DESATURATED_BLUE},{TCOD_LIGHTEST_BLUE},{TCOD_LIGHTER_BLUE},{TCOD_LIGHT_BLUE},{TCOD_BLUE},{TCOD_DARK_BLUE},{TCOD_DARKER_BLUE},{TCOD_DARKEST_BLUE}},
- {{TCOD_DESATURATED_HAN},{TCOD_LIGHTEST_HAN},{TCOD_LIGHTER_HAN},{TCOD_LIGHT_HAN},{TCOD_HAN},{TCOD_DARK_HAN},{TCOD_DARKER_HAN},{TCOD_DARKEST_HAN}},
- {{TCOD_DESATURATED_VIOLET},{TCOD_LIGHTEST_VIOLET},{TCOD_LIGHTER_VIOLET},{TCOD_LIGHT_VIOLET},{TCOD_VIOLET},{TCOD_DARK_VIOLET},{TCOD_DARKER_VIOLET},{TCOD_DARKEST_VIOLET}},
- {{TCOD_DESATURATED_PURPLE},{TCOD_LIGHTEST_PURPLE},{TCOD_LIGHTER_PURPLE},{TCOD_LIGHT_PURPLE},{TCOD_PURPLE},{TCOD_DARK_PURPLE},{TCOD_DARKER_PURPLE},{TCOD_DARKEST_PURPLE}},
- {{TCOD_DESATURATED_FUCHSIA},{TCOD_LIGHTEST_FUCHSIA},{TCOD_LIGHTER_FUCHSIA},{TCOD_LIGHT_FUCHSIA},{TCOD_FUCHSIA},{TCOD_DARK_FUCHSIA},{TCOD_DARKER_FUCHSIA},{TCOD_DARKEST_FUCHSIA}},
- {{TCOD_DESATURATED_MAGENTA},{TCOD_LIGHTEST_MAGENTA},{TCOD_LIGHTER_MAGENTA},{TCOD_LIGHT_MAGENTA},{TCOD_MAGENTA},{TCOD_DARK_MAGENTA},{TCOD_DARKER_MAGENTA},{TCOD_DARKEST_MAGENTA}},
- {{TCOD_DESATURATED_PINK},{TCOD_LIGHTEST_PINK},{TCOD_LIGHTER_PINK},{TCOD_LIGHT_PINK},{TCOD_PINK},{TCOD_DARK_PINK},{TCOD_DARKER_PINK},{TCOD_DARKEST_PINK}},
- {{TCOD_DESATURATED_CRIMSON},{TCOD_LIGHTEST_CRIMSON},{TCOD_LIGHTER_CRIMSON},{TCOD_LIGHT_CRIMSON},{TCOD_CRIMSON},{TCOD_DARK_CRIMSON},{TCOD_DARKER_CRIMSON},{TCOD_DARKEST_CRIMSON}}
-};
-
-TCOD_color_t TCOD_color_RGB(uint8_t r, uint8_t g, uint8_t b) {
- TCOD_color_t ret = { r, g, b };
- return ret;
-}
-
-TCOD_color_t TCOD_color_HSV(float h, float s, float v) {
- TCOD_color_t ret;
- int i;
- float f, p, q, t;
-
- if( s == 0 ) {
- /* achromatic (grey) */
- ret.r = ret.g = ret.b = (uint8_t)(v*255.0f+0.5f);
- }
- else {
- while (h < 0.0f) h += 360.0f; /*for H < 0 */
- while (h >= 360.0f) h -= 360.0f; /*for H >= 360 */
- h /= 60;
- i = (int)(h); /*hue sector 0-5 */
- f = h - i; /* factorial part of h */
- p = v * ( 1 - s );
- q = v * ( 1 - s * f );
- t = v * ( 1 - s * ( 1 - f ) );
-
- switch (i) {
- case 0:
- ret.r = (uint8_t)(v*255.0f+0.5f);
- ret.g = (uint8_t)(t*255.0f+0.5f);
- ret.b = (uint8_t)(p*255.0f+0.5f);
- break;
- case 1:
- ret.r = (uint8_t)(q*255.0f+0.5f);
- ret.g = (uint8_t)(v*255.0f+0.5f);
- ret.b = (uint8_t)(p*255.0f+0.5f);
- break;
- case 2:
- ret.r = (uint8_t)(p*255.0f+0.5f);
- ret.g = (uint8_t)(v*255.0f+0.5f);
- ret.b = (uint8_t)(t*255.0f+0.5f);
- break;
- case 3:
- ret.r = (uint8_t)(p*255.0f+0.5f);
- ret.g = (uint8_t)(q*255.0f+0.5f);
- ret.b = (uint8_t)(v*255.0f+0.5f);
- break;
- case 4:
- ret.r = (uint8_t)(t*255.0f+0.5f);
- ret.g = (uint8_t)(p*255.0f+0.5f);
- ret.b = (uint8_t)(v*255.0f+0.5f);
- break;
- default:
- ret.r = (uint8_t)(v*255.0f+0.5f);
- ret.g = (uint8_t)(p*255.0f+0.5f);
- ret.b = (uint8_t)(q*255.0f+0.5f);
- break;
- }
- }
- return ret;
-}
-
-bool TCOD_color_equals (TCOD_color_t c1, TCOD_color_t c2) {
- return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
-}
-
-TCOD_color_t TCOD_color_add (TCOD_color_t c1, TCOD_color_t c2) {
- TCOD_color_t ret;
- int r,g,b;
- r = (int)(c1.r) + c2.r;
- g = (int)(c1.g) + c2.g;
- b = (int)(c1.b) + c2.b;
- r=MIN(255,r);
- g=MIN(255,g);
- b=MIN(255,b);
- ret.r=(uint8_t)r;
- ret.g=(uint8_t)g;
- ret.b=(uint8_t)b;
- return ret;
-}
-
-TCOD_color_t TCOD_color_subtract (TCOD_color_t c1, TCOD_color_t c2) {
- TCOD_color_t ret;
- int r,g,b;
- r = (int)(c1.r) - c2.r;
- g = (int)(c1.g) - c2.g;
- b = (int)(c1.b) - c2.b;
- r=MAX(0,r);
- g=MAX(0,g);
- b=MAX(0,b);
- ret.r=(uint8_t)r;
- ret.g=(uint8_t)g;
- ret.b=(uint8_t)b;
- return ret;
-}
-
-TCOD_color_t TCOD_color_multiply (TCOD_color_t c1, TCOD_color_t c2) {
- TCOD_color_t ret;
- ret.r=(uint8_t)(((int)c1.r)*c2.r/255);
- ret.g=(uint8_t)(((int)c1.g)*c2.g/255);
- ret.b=(uint8_t)(((int)c1.b)*c2.b/255);
- return ret;
-}
-
-TCOD_color_t TCOD_color_multiply_scalar (TCOD_color_t c1, float value) {
- TCOD_color_t ret;
- int r,g,b;
- r = (int)(c1.r * value);
- g = (int)(c1.g * value);
- b = (int)(c1.b * value);
- ret.r=(uint8_t)CLAMP(0,255,r);
- ret.g=(uint8_t)CLAMP(0,255,g);
- ret.b=(uint8_t)CLAMP(0,255,b);
- return ret;
-}
-
-TCOD_color_t TCOD_color_lerp(TCOD_color_t c1, TCOD_color_t c2, float coef) {
- TCOD_color_t ret;
- ret.r=(uint8_t)(c1.r+(c2.r-c1.r)*coef);
- ret.g=(uint8_t)(c1.g+(c2.g-c1.g)*coef);
- ret.b=(uint8_t)(c1.b+(c2.b-c1.b)*coef);
- return ret;
-}
-
-/* 0<= h < 360, 0 <= s <= 1, 0 <= v <= 1 */
-void TCOD_color_set_HSV(TCOD_color_t *c, float h, float s, float v)
-{
- int i;
- float f, p, q, t;
-
- if( s == 0.0f ) {
- /* achromatic (grey) */
- c->r = c->g = c->b = (uint8_t)(v*255.0f+0.5f);
- return;
- }
-
- while (h < 0.0f) h += 360.0f; /*for H < 0 */
- while (h >= 360.0f) h -= 360.0f; /*for H >= 360 */
- h /= 60.0f; /* sector 0 to 5 */
- i = (int)floor( h );
- f = h - i; /* factorial part of h */
- p = v * ( 1 - s );
- q = v * ( 1 - s * f );
- t = v * ( 1 - s * ( 1 - f ) );
-
- switch( i ) {
- case 0:
- c->r = (uint8_t)(v*255.0f+0.5f);
- c->g = (uint8_t)(t*255.0f+0.5f);
- c->b = (uint8_t)(p*255.0f+0.5f);
- break;
- case 1:
- c->r = (uint8_t)(q*255.0f+0.5f);
- c->g = (uint8_t)(v*255.0f+0.5f);
- c->b = (uint8_t)(p*255.0f+0.5f);
- break;
- case 2:
- c->r = (uint8_t)(p*255.0f+0.5f);
- c->g = (uint8_t)(v*255.0f+0.5f);
- c->b = (uint8_t)(t*255.0f+0.5f);
- break;
- case 3:
- c->r = (uint8_t)(p*255.0f+0.5f);
- c->g = (uint8_t)(q*255.0f+0.5f);
- c->b = (uint8_t)(v*255.0f+0.5f);
- break;
- case 4:
- c->r = (uint8_t)(t*255.0f+0.5f);
- c->g = (uint8_t)(p*255.0f+0.5f);
- c->b = (uint8_t)(v*255.0f+0.5f);
- break;
- default:
- c->r = (uint8_t)(v*255.0f+0.5f);
- c->g = (uint8_t)(p*255.0f+0.5f);
- c->b = (uint8_t)(q*255.0f+0.5f);
- break;
- }
-}
-
-void TCOD_color_get_HSV(TCOD_color_t c, float *h, float *s, float *v)
-{
- uint8_t imax,imin;
- float min, max, delta;
-
- imax = ( c.r > c.g ?
- ( c.r > c.b ? c.r : c.b )
- : ( c.g > c.b ? c.g : c.b) );
- imin = ( c.r < c.g ?
- ( c.r < c.b ? c.r : c.b )
- : ( c.g < c.b ? c.g : c.b) );
- max = imax/255.0f;
- min = imin/255.0f;
- *v = max; /* v */
-
- delta = max - min;
- if( max != 0.0f ) *s = delta / max; /* s */
- else
- {
- *s = 0.0f; /* s */
- *h = 0.0f; /* h */
- return;
- }
-
- if( c.r == imax ) *h = ( c.g - c.b ) / (255.0f * delta); /* between yellow & magenta */
- else if( c.g == imax ) *h = 2.0f + ( c.b - c.r ) / (255.0f * delta); /* between cyan & yellow */
- else *h = 4.0f + ( c.r - c.g ) / (255.0f * delta); /* between magenta & cyan */
-
- *h *= 60.0f; /* degrees */
- if( *h < 0 ) *h += 360.0f;
-}
-
-float TCOD_color_get_hue (TCOD_color_t c) {
- uint8_t max = MAX(c.r,MAX(c.g,c.b));
- uint8_t min = MIN(c.r,MIN(c.g,c.b));
- float delta = (float)max - (float)min;
- float ret;
- if (delta == 0.0f) ret = 0.0f; /*achromatic, including black */
- else {
- if (c.r == max) ret = (float)(c.g - c.b) / delta;
- else if (c.g == max) ret = 2.0f + (float)(c.b - c.r) / delta;
- else ret = 4.0f + (float)(c.r - c.g) / delta;
- ret *= 60.0f;
- if (ret < 0.0f) ret += 360.0f;
- if (ret >= 360.0f) ret -= 360.0f;
- }
- return ret;
-}
-
-void TCOD_color_set_hue (TCOD_color_t *c, float h) {
- float obsolete, s, v;
- TCOD_color_get_HSV(*c,&obsolete,&s,&v);
- *c = TCOD_color_HSV(h,s,v);
-}
-
-float TCOD_color_get_saturation (TCOD_color_t c) {
- float max = (float)(MAX(c.r,MAX(c.g,c.b)))/255.0f;
- float min = (float)(MIN(c.r,MIN(c.g,c.b)))/255.0f;
- float delta = max - min;
- if (max == 0.0f) return 0.0f;
- else return delta/max;
-}
-
-void TCOD_color_set_saturation (TCOD_color_t *c, float s) {
- float h, obsolete, v;
- TCOD_color_get_HSV(*c,&h,&obsolete,&v);
- *c = TCOD_color_HSV(h,s,v);
-}
-
-float TCOD_color_get_value (TCOD_color_t c) {
- return (float)(MAX(c.r,MAX(c.g,c.b)))/255.0f;
-}
-
-void TCOD_color_set_value (TCOD_color_t *c, float v) {
- float h, s, obsolete;
- TCOD_color_get_HSV(*c,&h,&s,&obsolete);
- *c = TCOD_color_HSV(h,s,v);
-}
-
-void TCOD_color_shift_hue (TCOD_color_t *c, float hshift) {
- float h, s, v;
- if (hshift == 0.0f) return;
- TCOD_color_get_HSV(*c,&h,&s,&v);
- *c = TCOD_color_HSV(h+hshift,s,v);
-}
-
-void TCOD_color_scale_HSV (TCOD_color_t *c, float scoef, float vcoef) {
- float h, s, v;
- TCOD_color_get_HSV(*c,&h,&s,&v);
- s = CLAMP(0.0f,1.0f,s*scoef);
- v = CLAMP(0.0f,1.0f,v*vcoef);
- *c = TCOD_color_HSV(h,s,v);
-}
-
-void TCOD_color_gen_map(TCOD_color_t *map, int nb_key, TCOD_color_t const *key_color, int const *key_index) {
- int segment=0;
- for (segment=0; segment < nb_key-1; segment++) {
- int idx_start=key_index[segment];
- int idx_end=key_index[segment+1];
- int idx;
- for ( idx=idx_start;idx <= idx_end; idx++) {
- map[idx]=TCOD_color_lerp(key_color[segment],key_color[segment+1],(float)(idx-idx_start)/(idx_end-idx_start));
- }
- }
-}
-
-
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "color.h"
+
+#include
+
+#include "libtcod_int.h"
+#include "utility.h"
+
+/* grey levels */
+const TCOD_color_t TCOD_black={TCOD_BLACK};
+const TCOD_color_t TCOD_darkest_grey={TCOD_DARKEST_GREY};
+const TCOD_color_t TCOD_darker_grey={TCOD_DARKER_GREY};
+const TCOD_color_t TCOD_dark_grey={TCOD_DARK_GREY};
+const TCOD_color_t TCOD_grey={TCOD_GREY};
+const TCOD_color_t TCOD_light_grey={TCOD_LIGHT_GREY};
+const TCOD_color_t TCOD_lighter_grey={TCOD_LIGHTER_GREY};
+const TCOD_color_t TCOD_lightest_grey={TCOD_LIGHTEST_GREY};
+const TCOD_color_t TCOD_darkest_gray={TCOD_DARKEST_GREY};
+const TCOD_color_t TCOD_darker_gray={TCOD_DARKER_GREY};
+const TCOD_color_t TCOD_dark_gray={TCOD_DARK_GREY};
+const TCOD_color_t TCOD_gray={TCOD_GREY};
+const TCOD_color_t TCOD_light_gray={TCOD_LIGHT_GREY};
+const TCOD_color_t TCOD_lighter_gray={TCOD_LIGHTER_GREY};
+const TCOD_color_t TCOD_lightest_gray={TCOD_LIGHTEST_GREY};
+const TCOD_color_t TCOD_white={TCOD_WHITE};
+
+/* sepia */
+const TCOD_color_t TCOD_darkest_sepia={TCOD_DARKEST_SEPIA};
+const TCOD_color_t TCOD_darker_sepia={TCOD_DARKER_SEPIA};
+const TCOD_color_t TCOD_dark_sepia={TCOD_DARK_SEPIA};
+const TCOD_color_t TCOD_sepia={TCOD_SEPIA};
+const TCOD_color_t TCOD_light_sepia={TCOD_LIGHT_SEPIA};
+const TCOD_color_t TCOD_lighter_sepia={TCOD_LIGHTER_SEPIA};
+const TCOD_color_t TCOD_lightest_sepia={TCOD_LIGHTEST_SEPIA};
+
+/* standard colors */
+const TCOD_color_t TCOD_red = {TCOD_RED};
+const TCOD_color_t TCOD_flame = {TCOD_FLAME};
+const TCOD_color_t TCOD_orange = {TCOD_ORANGE};
+const TCOD_color_t TCOD_amber = {TCOD_AMBER};
+const TCOD_color_t TCOD_yellow = {TCOD_YELLOW};
+const TCOD_color_t TCOD_lime = {TCOD_LIME};
+const TCOD_color_t TCOD_chartreuse = {TCOD_CHARTREUSE};
+const TCOD_color_t TCOD_green = {TCOD_GREEN};
+const TCOD_color_t TCOD_sea = {TCOD_SEA};
+const TCOD_color_t TCOD_turquoise = {TCOD_TURQUOISE};
+const TCOD_color_t TCOD_cyan = {TCOD_CYAN};
+const TCOD_color_t TCOD_sky = {TCOD_SKY};
+const TCOD_color_t TCOD_azure = {TCOD_AZURE};
+const TCOD_color_t TCOD_blue = {TCOD_BLUE};
+const TCOD_color_t TCOD_han = {TCOD_HAN};
+const TCOD_color_t TCOD_violet = {TCOD_VIOLET};
+const TCOD_color_t TCOD_purple = {TCOD_PURPLE};
+const TCOD_color_t TCOD_fuchsia = {TCOD_FUCHSIA};
+const TCOD_color_t TCOD_magenta = {TCOD_MAGENTA};
+const TCOD_color_t TCOD_pink = {TCOD_PINK};
+const TCOD_color_t TCOD_crimson = {TCOD_CRIMSON};
+
+/* dark colors */
+const TCOD_color_t TCOD_dark_red = {TCOD_DARK_RED};
+const TCOD_color_t TCOD_dark_flame = {TCOD_DARK_FLAME};
+const TCOD_color_t TCOD_dark_orange = {TCOD_DARK_ORANGE};
+const TCOD_color_t TCOD_dark_amber = {TCOD_DARK_AMBER};
+const TCOD_color_t TCOD_dark_yellow = {TCOD_DARK_YELLOW};
+const TCOD_color_t TCOD_dark_lime = {TCOD_DARK_LIME};
+const TCOD_color_t TCOD_dark_chartreuse = {TCOD_DARK_CHARTREUSE};
+const TCOD_color_t TCOD_dark_green = {TCOD_DARK_GREEN};
+const TCOD_color_t TCOD_dark_sea = {TCOD_DARK_SEA};
+const TCOD_color_t TCOD_dark_turquoise = {TCOD_DARK_TURQUOISE};
+const TCOD_color_t TCOD_dark_cyan = {TCOD_DARK_CYAN};
+const TCOD_color_t TCOD_dark_sky = {TCOD_DARK_SKY};
+const TCOD_color_t TCOD_dark_azure = {TCOD_DARK_AZURE};
+const TCOD_color_t TCOD_dark_blue = {TCOD_DARK_BLUE};
+const TCOD_color_t TCOD_dark_han = {TCOD_DARK_HAN};
+const TCOD_color_t TCOD_dark_violet = {TCOD_DARK_VIOLET};
+const TCOD_color_t TCOD_dark_purple = {TCOD_DARK_PURPLE};
+const TCOD_color_t TCOD_dark_fuchsia = {TCOD_DARK_FUCHSIA};
+const TCOD_color_t TCOD_dark_magenta = {TCOD_DARK_MAGENTA};
+const TCOD_color_t TCOD_dark_pink = {TCOD_DARK_PINK};
+const TCOD_color_t TCOD_dark_crimson = {TCOD_DARK_CRIMSON};
+
+/* darker colors */
+const TCOD_color_t TCOD_darker_red = {TCOD_DARKER_RED};
+const TCOD_color_t TCOD_darker_flame = {TCOD_DARKER_FLAME};
+const TCOD_color_t TCOD_darker_orange = {TCOD_DARKER_ORANGE};
+const TCOD_color_t TCOD_darker_amber = {TCOD_DARKER_AMBER};
+const TCOD_color_t TCOD_darker_yellow = {TCOD_DARKER_YELLOW};
+const TCOD_color_t TCOD_darker_lime = {TCOD_DARKER_LIME};
+const TCOD_color_t TCOD_darker_chartreuse = {TCOD_DARKER_CHARTREUSE};
+const TCOD_color_t TCOD_darker_green = {TCOD_DARKER_GREEN};
+const TCOD_color_t TCOD_darker_sea = {TCOD_DARKER_SEA};
+const TCOD_color_t TCOD_darker_turquoise = {TCOD_DARKER_TURQUOISE};
+const TCOD_color_t TCOD_darker_cyan = {TCOD_DARKER_CYAN};
+const TCOD_color_t TCOD_darker_sky = {TCOD_DARKER_SKY};
+const TCOD_color_t TCOD_darker_azure = {TCOD_DARKER_AZURE};
+const TCOD_color_t TCOD_darker_blue = {TCOD_DARKER_BLUE};
+const TCOD_color_t TCOD_darker_han = {TCOD_DARKER_HAN};
+const TCOD_color_t TCOD_darker_violet = {TCOD_DARKER_VIOLET};
+const TCOD_color_t TCOD_darker_purple = {TCOD_DARKER_PURPLE};
+const TCOD_color_t TCOD_darker_fuchsia = {TCOD_DARKER_FUCHSIA};
+const TCOD_color_t TCOD_darker_magenta = {TCOD_DARKER_MAGENTA};
+const TCOD_color_t TCOD_darker_pink = {TCOD_DARKER_PINK};
+const TCOD_color_t TCOD_darker_crimson = {TCOD_DARKER_CRIMSON};
+
+/* darkest colors */
+const TCOD_color_t TCOD_darkest_red = {TCOD_DARKEST_RED};
+const TCOD_color_t TCOD_darkest_flame = {TCOD_DARKEST_FLAME};
+const TCOD_color_t TCOD_darkest_orange = {TCOD_DARKEST_ORANGE};
+const TCOD_color_t TCOD_darkest_amber = {TCOD_DARKEST_AMBER};
+const TCOD_color_t TCOD_darkest_yellow = {TCOD_DARKEST_YELLOW};
+const TCOD_color_t TCOD_darkest_lime = {TCOD_DARKEST_LIME};
+const TCOD_color_t TCOD_darkest_chartreuse = {TCOD_DARKEST_CHARTREUSE};
+const TCOD_color_t TCOD_darkest_green = {TCOD_DARKEST_GREEN};
+const TCOD_color_t TCOD_darkest_sea = {TCOD_DARKEST_SEA};
+const TCOD_color_t TCOD_darkest_turquoise = {TCOD_DARKEST_TURQUOISE};
+const TCOD_color_t TCOD_darkest_cyan = {TCOD_DARKEST_CYAN};
+const TCOD_color_t TCOD_darkest_sky = {TCOD_DARKEST_SKY};
+const TCOD_color_t TCOD_darkest_azure = {TCOD_DARKEST_AZURE};
+const TCOD_color_t TCOD_darkest_blue = {TCOD_DARKEST_BLUE};
+const TCOD_color_t TCOD_darkest_han = {TCOD_DARKEST_HAN};
+const TCOD_color_t TCOD_darkest_violet = {TCOD_DARKEST_VIOLET};
+const TCOD_color_t TCOD_darkest_purple = {TCOD_DARKEST_PURPLE};
+const TCOD_color_t TCOD_darkest_fuchsia = {TCOD_DARKEST_FUCHSIA};
+const TCOD_color_t TCOD_darkest_magenta = {TCOD_DARKEST_MAGENTA};
+const TCOD_color_t TCOD_darkest_pink = {TCOD_DARKEST_PINK};
+const TCOD_color_t TCOD_darkest_crimson = {TCOD_DARKEST_CRIMSON};
+
+/* light colors */
+const TCOD_color_t TCOD_light_red = {TCOD_LIGHT_RED};
+const TCOD_color_t TCOD_light_flame = {TCOD_LIGHT_FLAME};
+const TCOD_color_t TCOD_light_orange = {TCOD_LIGHT_ORANGE};
+const TCOD_color_t TCOD_light_amber = {TCOD_LIGHT_AMBER};
+const TCOD_color_t TCOD_light_yellow = {TCOD_LIGHT_YELLOW};
+const TCOD_color_t TCOD_light_lime = {TCOD_LIGHT_LIME};
+const TCOD_color_t TCOD_light_chartreuse = {TCOD_LIGHT_CHARTREUSE};
+const TCOD_color_t TCOD_light_green = {TCOD_LIGHT_GREEN};
+const TCOD_color_t TCOD_light_sea = {TCOD_LIGHT_SEA};
+const TCOD_color_t TCOD_light_turquoise = {TCOD_LIGHT_TURQUOISE};
+const TCOD_color_t TCOD_light_cyan = {TCOD_LIGHT_CYAN};
+const TCOD_color_t TCOD_light_sky = {TCOD_LIGHT_SKY};
+const TCOD_color_t TCOD_light_azure = {TCOD_LIGHT_AZURE};
+const TCOD_color_t TCOD_light_blue = {TCOD_LIGHT_BLUE};
+const TCOD_color_t TCOD_light_han = {TCOD_LIGHT_HAN};
+const TCOD_color_t TCOD_light_violet = {TCOD_LIGHT_VIOLET};
+const TCOD_color_t TCOD_light_purple = {TCOD_LIGHT_PURPLE};
+const TCOD_color_t TCOD_light_fuchsia = {TCOD_LIGHT_FUCHSIA};
+const TCOD_color_t TCOD_light_magenta = {TCOD_LIGHT_MAGENTA};
+const TCOD_color_t TCOD_light_pink = {TCOD_LIGHT_PINK};
+const TCOD_color_t TCOD_light_crimson = {TCOD_LIGHT_CRIMSON};
+
+/*lighter colors */
+const TCOD_color_t TCOD_lighter_red = {TCOD_LIGHTER_RED};
+const TCOD_color_t TCOD_lighter_flame = {TCOD_LIGHTER_FLAME};
+const TCOD_color_t TCOD_lighter_orange = {TCOD_LIGHTER_ORANGE};
+const TCOD_color_t TCOD_lighter_amber = {TCOD_LIGHTER_AMBER};
+const TCOD_color_t TCOD_lighter_yellow = {TCOD_LIGHTER_YELLOW};
+const TCOD_color_t TCOD_lighter_lime = {TCOD_LIGHTER_LIME};
+const TCOD_color_t TCOD_lighter_chartreuse = {TCOD_LIGHTER_CHARTREUSE};
+const TCOD_color_t TCOD_lighter_green = {TCOD_LIGHTER_GREEN};
+const TCOD_color_t TCOD_lighter_sea = {TCOD_LIGHTER_SEA};
+const TCOD_color_t TCOD_lighter_turquoise = {TCOD_LIGHTER_TURQUOISE};
+const TCOD_color_t TCOD_lighter_cyan = {TCOD_LIGHTER_CYAN};
+const TCOD_color_t TCOD_lighter_sky = {TCOD_LIGHTER_SKY};
+const TCOD_color_t TCOD_lighter_azure = {TCOD_LIGHTER_AZURE};
+const TCOD_color_t TCOD_lighter_blue = {TCOD_LIGHTER_BLUE};
+const TCOD_color_t TCOD_lighter_han = {TCOD_LIGHTER_HAN};
+const TCOD_color_t TCOD_lighter_violet = {TCOD_LIGHTER_VIOLET};
+const TCOD_color_t TCOD_lighter_purple = {TCOD_LIGHTER_PURPLE};
+const TCOD_color_t TCOD_lighter_fuchsia = {TCOD_LIGHTER_FUCHSIA};
+const TCOD_color_t TCOD_lighter_magenta = {TCOD_LIGHTER_MAGENTA};
+const TCOD_color_t TCOD_lighter_pink = {TCOD_LIGHTER_PINK};
+const TCOD_color_t TCOD_lighter_crimson = {TCOD_LIGHTER_CRIMSON};
+
+/* lightest colors */
+const TCOD_color_t TCOD_lightest_red = {TCOD_LIGHTEST_RED};
+const TCOD_color_t TCOD_lightest_flame = {TCOD_LIGHTEST_FLAME};
+const TCOD_color_t TCOD_lightest_orange = {TCOD_LIGHTEST_ORANGE};
+const TCOD_color_t TCOD_lightest_amber = {TCOD_LIGHTEST_AMBER};
+const TCOD_color_t TCOD_lightest_yellow = {TCOD_LIGHTEST_YELLOW};
+const TCOD_color_t TCOD_lightest_lime = {TCOD_LIGHTEST_LIME};
+const TCOD_color_t TCOD_lightest_chartreuse = {TCOD_LIGHTEST_CHARTREUSE};
+const TCOD_color_t TCOD_lightest_green = {TCOD_LIGHTEST_GREEN};
+const TCOD_color_t TCOD_lightest_sea = {TCOD_LIGHTEST_SEA};
+const TCOD_color_t TCOD_lightest_turquoise = {TCOD_LIGHTEST_TURQUOISE};
+const TCOD_color_t TCOD_lightest_cyan = {TCOD_LIGHTEST_CYAN};
+const TCOD_color_t TCOD_lightest_sky = {TCOD_LIGHTEST_SKY};
+const TCOD_color_t TCOD_lightest_azure = {TCOD_LIGHTEST_AZURE};
+const TCOD_color_t TCOD_lightest_blue = {TCOD_LIGHTEST_BLUE};
+const TCOD_color_t TCOD_lightest_han = {TCOD_LIGHTEST_HAN};
+const TCOD_color_t TCOD_lightest_violet = {TCOD_LIGHTEST_VIOLET};
+const TCOD_color_t TCOD_lightest_purple = {TCOD_LIGHTEST_PURPLE};
+const TCOD_color_t TCOD_lightest_fuchsia = {TCOD_LIGHTEST_FUCHSIA};
+const TCOD_color_t TCOD_lightest_magenta = {TCOD_LIGHTEST_MAGENTA};
+const TCOD_color_t TCOD_lightest_pink = {TCOD_LIGHTEST_PINK};
+const TCOD_color_t TCOD_lightest_crimson = {TCOD_LIGHTEST_CRIMSON};
+
+/* desaturated colors */
+const TCOD_color_t TCOD_desaturated_red = {TCOD_DESATURATED_RED};
+const TCOD_color_t TCOD_desaturated_flame = {TCOD_DESATURATED_FLAME};
+const TCOD_color_t TCOD_desaturated_orange = {TCOD_DESATURATED_ORANGE};
+const TCOD_color_t TCOD_desaturated_amber = {TCOD_DESATURATED_AMBER};
+const TCOD_color_t TCOD_desaturated_yellow = {TCOD_DESATURATED_YELLOW};
+const TCOD_color_t TCOD_desaturated_lime = {TCOD_DESATURATED_LIME};
+const TCOD_color_t TCOD_desaturated_chartreuse = {TCOD_DESATURATED_CHARTREUSE};
+const TCOD_color_t TCOD_desaturated_green = {TCOD_DESATURATED_GREEN};
+const TCOD_color_t TCOD_desaturated_sea = {TCOD_DESATURATED_SEA};
+const TCOD_color_t TCOD_desaturated_turquoise = {TCOD_DESATURATED_TURQUOISE};
+const TCOD_color_t TCOD_desaturated_cyan = {TCOD_DESATURATED_CYAN};
+const TCOD_color_t TCOD_desaturated_sky = {TCOD_DESATURATED_SKY};
+const TCOD_color_t TCOD_desaturated_azure = {TCOD_DESATURATED_AZURE};
+const TCOD_color_t TCOD_desaturated_blue = {TCOD_DESATURATED_BLUE};
+const TCOD_color_t TCOD_desaturated_han = {TCOD_DESATURATED_HAN};
+const TCOD_color_t TCOD_desaturated_violet = {TCOD_DESATURATED_VIOLET};
+const TCOD_color_t TCOD_desaturated_purple = {TCOD_DESATURATED_PURPLE};
+const TCOD_color_t TCOD_desaturated_fuchsia = {TCOD_DESATURATED_FUCHSIA};
+const TCOD_color_t TCOD_desaturated_magenta = {TCOD_DESATURATED_MAGENTA};
+const TCOD_color_t TCOD_desaturated_pink = {TCOD_DESATURATED_PINK};
+const TCOD_color_t TCOD_desaturated_crimson = {TCOD_DESATURATED_CRIMSON};
+
+/* metallic */
+const TCOD_color_t TCOD_brass = {TCOD_BRASS};
+const TCOD_color_t TCOD_copper = {TCOD_COPPER};
+const TCOD_color_t TCOD_gold = {TCOD_GOLD};
+const TCOD_color_t TCOD_silver = {TCOD_SILVER};
+
+/* miscellaneous */
+const TCOD_color_t TCOD_celadon = {TCOD_CELADON};
+const TCOD_color_t TCOD_peach = {TCOD_PEACH};
+
+/* color array */
+const TCOD_color_t TCOD_colors[TCOD_COLOR_NB][TCOD_COLOR_LEVELS] = {
+ {{TCOD_DESATURATED_RED},{TCOD_LIGHTEST_RED},{TCOD_LIGHTER_RED},{TCOD_LIGHT_RED},{TCOD_RED},{TCOD_DARK_RED},{TCOD_DARKER_RED},{TCOD_DARKEST_RED}},
+ {{TCOD_DESATURATED_FLAME},{TCOD_LIGHTEST_FLAME},{TCOD_LIGHTER_FLAME},{TCOD_LIGHT_FLAME},{TCOD_FLAME},{TCOD_DARK_FLAME},{TCOD_DARKER_FLAME},{TCOD_DARKEST_FLAME}},
+ {{TCOD_DESATURATED_ORANGE},{TCOD_LIGHTEST_ORANGE},{TCOD_LIGHTER_ORANGE},{TCOD_LIGHT_ORANGE},{TCOD_ORANGE},{TCOD_DARK_ORANGE},{TCOD_DARKER_ORANGE},{TCOD_DARKEST_ORANGE}},
+ {{TCOD_DESATURATED_AMBER},{TCOD_LIGHTEST_AMBER},{TCOD_LIGHTER_AMBER},{TCOD_LIGHT_AMBER},{TCOD_AMBER},{TCOD_DARK_AMBER},{TCOD_DARKER_AMBER},{TCOD_DARKEST_AMBER}},
+ {{TCOD_DESATURATED_YELLOW},{TCOD_LIGHTEST_YELLOW},{TCOD_LIGHTER_YELLOW},{TCOD_LIGHT_YELLOW},{TCOD_YELLOW},{TCOD_DARK_YELLOW},{TCOD_DARKER_YELLOW},{TCOD_DARKEST_YELLOW}},
+ {{TCOD_DESATURATED_LIME},{TCOD_LIGHTEST_LIME},{TCOD_LIGHTER_LIME},{TCOD_LIGHT_LIME},{TCOD_LIME},{TCOD_DARK_LIME},{TCOD_DARKER_LIME},{TCOD_DARKEST_LIME}},
+ {{TCOD_DESATURATED_CHARTREUSE},{TCOD_LIGHTEST_CHARTREUSE},{TCOD_LIGHTER_CHARTREUSE},{TCOD_LIGHT_CHARTREUSE},{TCOD_CHARTREUSE},{TCOD_DARK_CHARTREUSE},{TCOD_DARKER_CHARTREUSE},{TCOD_DARKEST_CHARTREUSE}},
+ {{TCOD_DESATURATED_GREEN},{TCOD_LIGHTEST_GREEN},{TCOD_LIGHTER_GREEN},{TCOD_LIGHT_GREEN},{TCOD_GREEN},{TCOD_DARK_GREEN},{TCOD_DARKER_GREEN},{TCOD_DARKEST_GREEN}},
+ {{TCOD_DESATURATED_SEA},{TCOD_LIGHTEST_SEA},{TCOD_LIGHTER_SEA},{TCOD_LIGHT_SEA},{TCOD_SEA},{TCOD_DARK_SEA},{TCOD_DARKER_SEA},{TCOD_DARKEST_SEA}},
+ {{TCOD_DESATURATED_TURQUOISE},{TCOD_LIGHTEST_TURQUOISE},{TCOD_LIGHTER_TURQUOISE},{TCOD_LIGHT_TURQUOISE},{TCOD_TURQUOISE},{TCOD_DARK_TURQUOISE},{TCOD_DARKER_TURQUOISE},{TCOD_DARKEST_TURQUOISE}},
+ {{TCOD_DESATURATED_CYAN},{TCOD_LIGHTEST_CYAN},{TCOD_LIGHTER_CYAN},{TCOD_LIGHT_CYAN},{TCOD_CYAN},{TCOD_DARK_CYAN},{TCOD_DARKER_CYAN},{TCOD_DARKEST_CYAN}},
+ {{TCOD_DESATURATED_SKY},{TCOD_LIGHTEST_SKY},{TCOD_LIGHTER_SKY},{TCOD_LIGHT_SKY},{TCOD_SKY},{TCOD_DARK_SKY},{TCOD_DARKER_SKY},{TCOD_DARKEST_SKY}},
+ {{TCOD_DESATURATED_AZURE},{TCOD_LIGHTEST_AZURE},{TCOD_LIGHTER_AZURE},{TCOD_LIGHT_AZURE},{TCOD_AZURE},{TCOD_DARK_AZURE},{TCOD_DARKER_AZURE},{TCOD_DARKEST_AZURE}},
+ {{TCOD_DESATURATED_BLUE},{TCOD_LIGHTEST_BLUE},{TCOD_LIGHTER_BLUE},{TCOD_LIGHT_BLUE},{TCOD_BLUE},{TCOD_DARK_BLUE},{TCOD_DARKER_BLUE},{TCOD_DARKEST_BLUE}},
+ {{TCOD_DESATURATED_HAN},{TCOD_LIGHTEST_HAN},{TCOD_LIGHTER_HAN},{TCOD_LIGHT_HAN},{TCOD_HAN},{TCOD_DARK_HAN},{TCOD_DARKER_HAN},{TCOD_DARKEST_HAN}},
+ {{TCOD_DESATURATED_VIOLET},{TCOD_LIGHTEST_VIOLET},{TCOD_LIGHTER_VIOLET},{TCOD_LIGHT_VIOLET},{TCOD_VIOLET},{TCOD_DARK_VIOLET},{TCOD_DARKER_VIOLET},{TCOD_DARKEST_VIOLET}},
+ {{TCOD_DESATURATED_PURPLE},{TCOD_LIGHTEST_PURPLE},{TCOD_LIGHTER_PURPLE},{TCOD_LIGHT_PURPLE},{TCOD_PURPLE},{TCOD_DARK_PURPLE},{TCOD_DARKER_PURPLE},{TCOD_DARKEST_PURPLE}},
+ {{TCOD_DESATURATED_FUCHSIA},{TCOD_LIGHTEST_FUCHSIA},{TCOD_LIGHTER_FUCHSIA},{TCOD_LIGHT_FUCHSIA},{TCOD_FUCHSIA},{TCOD_DARK_FUCHSIA},{TCOD_DARKER_FUCHSIA},{TCOD_DARKEST_FUCHSIA}},
+ {{TCOD_DESATURATED_MAGENTA},{TCOD_LIGHTEST_MAGENTA},{TCOD_LIGHTER_MAGENTA},{TCOD_LIGHT_MAGENTA},{TCOD_MAGENTA},{TCOD_DARK_MAGENTA},{TCOD_DARKER_MAGENTA},{TCOD_DARKEST_MAGENTA}},
+ {{TCOD_DESATURATED_PINK},{TCOD_LIGHTEST_PINK},{TCOD_LIGHTER_PINK},{TCOD_LIGHT_PINK},{TCOD_PINK},{TCOD_DARK_PINK},{TCOD_DARKER_PINK},{TCOD_DARKEST_PINK}},
+ {{TCOD_DESATURATED_CRIMSON},{TCOD_LIGHTEST_CRIMSON},{TCOD_LIGHTER_CRIMSON},{TCOD_LIGHT_CRIMSON},{TCOD_CRIMSON},{TCOD_DARK_CRIMSON},{TCOD_DARKER_CRIMSON},{TCOD_DARKEST_CRIMSON}}
+};
+/**
+ * \brief Return a new TCOD_color_t from RGB values.
+ *
+ * This function is redundant, you should use a braced initializer instead:
+ *
+ * TCOD_color_t white = {255, 255, 255};
+ */
+TCOD_color_t TCOD_color_RGB(uint8_t r, uint8_t g, uint8_t b) {
+ TCOD_color_t new_color = {r, g, b};
+ return new_color;
+}
+/**
+ * \brief Return a new TCOD_color_t from HSV values.
+ *
+ * \param hue The colors hue (in degrees.)
+ * \param saturation The colors saturation (from 0 to 1)
+ * \param value The colors value (from 0 to 1)
+ * \return A new TCOD_color_t struct.
+ *
+ * The saturation and value parameters are automatically clamped to 0 and 1.
+ *
+ * TCOD_color_t light_blue = TCOD_color_HSV(240.0f, 0.75f, 1.0f);
+ *
+ * Use TCOD_color_set_HSV to fill an existing struct with HSV values.
+ */
+TCOD_color_t TCOD_color_HSV(float hue, float saturation, float value) {
+ TCOD_color_t new_color;
+ TCOD_color_set_HSV(&new_color, hue, saturation, value);
+ return new_color;
+}
+/**
+ * \brief Return a true value if c1 and c2 are equal.
+ */
+bool TCOD_color_equals(TCOD_color_t c1, TCOD_color_t c2) {
+ return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
+}
+/**
+ * \brief Add two colors together and return the result.
+ *
+ * \param c1 The first color.
+ * \param c2 The second color.
+ * \return A new TCOD_color_t struct with the result.
+ */
+TCOD_color_t TCOD_color_add(TCOD_color_t c1, TCOD_color_t c2) {
+ TCOD_color_t new_color = {
+ (uint8_t)MIN(255, (int)c1.r + c2.r),
+ (uint8_t)MIN(255, (int)c1.g + c2.g),
+ (uint8_t)MIN(255, (int)c1.b + c2.b)};
+ return new_color;
+}
+/**
+ * \brief Subtract c2 from c1 and return the result.
+ *
+ * \param c1 The first color.
+ * \param c2 The second color.
+ * \return A new TCOD_color_t struct with the result.
+ */
+TCOD_color_t TCOD_color_subtract(TCOD_color_t c1, TCOD_color_t c2) {
+ TCOD_color_t new_color = {
+ (uint8_t)MAX(0, (int)c1.r - c2.r),
+ (uint8_t)MAX(0, (int)c1.g - c2.g),
+ (uint8_t)MAX(0, (int)c1.b - c2.b)};
+ return new_color;
+}
+/**
+ * \brief Multiply two colors together and return the result.
+ *
+ * \param c1 The first color.
+ * \param c2 The second color.
+ * \return A new TCOD_color_t struct with the result.
+ */
+TCOD_color_t TCOD_color_multiply(TCOD_color_t c1, TCOD_color_t c2) {
+ TCOD_color_t new_color = {
+ (uint8_t)(((int)c1.r) * c2.r / 255),
+ (uint8_t)(((int)c1.g) * c2.g / 255),
+ (uint8_t)(((int)c1.b) * c2.b / 255)};
+ return new_color;
+}
+/**
+ * \brief Multiply a color with a scalar value and return the result.
+ *
+ * \param c1 The color to multiply.
+ * \param value The scalar float.
+ * \return A new TCOD_color_t struct with the result.
+ */
+TCOD_color_t TCOD_color_multiply_scalar(TCOD_color_t c1, float value) {
+ TCOD_color_t new_color = {
+ (uint8_t)CLAMP(0.0f, 255.0f, (float)c1.r * value),
+ (uint8_t)CLAMP(0.0f, 255.0f, (float)c1.g * value),
+ (uint8_t)CLAMP(0.0f, 255.0f, (float)c1.b * value)};
+ return new_color;
+}
+/**
+ * \brief Interpolate two colors together and return the result.
+ *
+ * \param c1 The first color (where coef if 0)
+ * \param c2 The second color (where coef if 1)
+ * \param coef The coefficient.
+ * \return A new TCOD_color_t struct with the result.
+ */
+TCOD_color_t TCOD_color_lerp(TCOD_color_t c1, TCOD_color_t c2, float coef) {
+ TCOD_color_t new_color = {
+ (uint8_t)(c1.r + (c2.r - c1.r) * coef),
+ (uint8_t)(c1.g + (c2.g - c1.g) * coef),
+ (uint8_t)(c1.b + (c2.b - c1.b) * coef)};
+ return new_color;
+}
+/* Return floor modulo for double values. */
+static double fabsmod(double x, double n) {
+ double m = fmod(x, n);
+ return m < 0 ? m+n : m;
+}
+
+/**
+ * \brief Sets a colors values from HSV values.
+ *
+ * \param color The color to be changed.
+ * \param hue The colors hue (in degrees.)
+ * \param saturation The colors saturation (from 0 to 1)
+ * \param value The colors value (from 0 to 1)
+ */
+void TCOD_color_set_HSV(TCOD_color_t *color,
+ float hue, float saturation, float value) {
+ int hue_section;
+ float hue_fraction, p, q, t;
+
+ saturation = CLAMP(0.0f, 1.0f, saturation);
+ value = CLAMP(0.0f, 1.0f, value);
+ if( saturation == 0.0f ) { /* achromatic (grey) */
+ color->r = color->g = color->b = (uint8_t)(value * 255.0f + 0.5f);
+ return;
+ }
+
+ hue = (float)fabsmod(hue, 360.0f);
+ hue /= 60.0f; /* sector 0 to 5 */
+ hue_section = (int)floor(hue);
+ hue_fraction = hue - hue_section; /* fraction between sections */
+ p = value * (1 - saturation);
+ q = value * (1 - saturation * hue_fraction);
+ t = value * (1 - saturation * (1 - hue_fraction));
+
+ switch (hue_section) {
+ default:
+ case 0: /* red/yellow */
+ color->r = (uint8_t)(value * 255.0f + 0.5f);
+ color->g = (uint8_t)(t * 255.0f + 0.5f);
+ color->b = (uint8_t)(p * 255.0f + 0.5f);
+ break;
+ case 1: /* yellow/green */
+ color->r = (uint8_t)(q * 255.0f + 0.5f);
+ color->g = (uint8_t)(value * 255.0f + 0.5f);
+ color->b = (uint8_t)(p * 255.0f + 0.5f);
+ break;
+ case 2: /* green/cyan */
+ color->r = (uint8_t)(p * 255.0f + 0.5f);
+ color->g = (uint8_t)(value * 255.0f + 0.5f);
+ color->b = (uint8_t)(t * 255.0f + 0.5f);
+ break;
+ case 3: /* cyan/blue */
+ color->r = (uint8_t)(p * 255.0f + 0.5f);
+ color->g = (uint8_t)(q * 255.0f + 0.5f);
+ color->b = (uint8_t)(value * 255.0f + 0.5f);
+ break;
+ case 4: /* blue/purple */
+ color->r = (uint8_t)(t * 255.0f + 0.5f);
+ color->g = (uint8_t)(p * 255.0f + 0.5f);
+ color->b = (uint8_t)(value * 255.0f + 0.5f);
+ break;
+ case 5: /* purple/red */
+ color->r = (uint8_t)(value * 255.0f + 0.5f);
+ color->g = (uint8_t)(p * 255.0f + 0.5f);
+ color->b = (uint8_t)(q * 255.0f + 0.5f);
+ break;
+ }
+}
+/**
+ * \brief Get a set of HSV values from a color.
+ *
+ * \param color The color
+ * \param hue Pointer to a float, filled with the hue. (degrees)
+ * \param saturation Pointer to a float, filled with the saturation. (0 to 1)
+ * \param value Pointer to a float, filled with the value. (0 to 1)
+ *
+ * The hue, saturation, and value parameters can not be NULL pointers,
+ */
+void TCOD_color_get_HSV(TCOD_color_t color,
+ float *hue, float *saturation, float *value) {
+ *hue = TCOD_color_get_hue(color);
+ *saturation = TCOD_color_get_saturation(color);
+ *value = TCOD_color_get_value(color);
+ return;
+}
+/**
+ * \brief Return a colors hue.
+ *
+ * \param color A color struct.
+ * \return The colors hue. (degrees)
+ */
+float TCOD_color_get_hue(TCOD_color_t color) {
+ uint8_t max = MAX(color.r, MAX(color.g, color.b));
+ uint8_t min = MIN(color.r, MIN(color.g, color.b));
+ float delta = (float)max - (float)min;
+ float hue; /* degrees */
+ if (delta == 0.0f) { return 0.0f; } /* achromatic, including black */
+ if (color.r == max) {
+ hue = (float)(color.g - color.b) / delta;
+ } else if (color.g == max) {
+ hue = 2.0f + (float)(color.b - color.r) / delta;
+ } else {
+ hue = 4.0f + (float)(color.r - color.g) / delta;
+ }
+ hue *= 60.0f;
+ hue = (float)fabsmod(hue, 360.0f);
+ return hue;
+}
+/**
+ * \brief Change a colors hue.
+ *
+ * \param color Pointer to a color struct.
+ * \param hue The hue in degrees.
+ */
+void TCOD_color_set_hue(TCOD_color_t *color, float hue) {
+ TCOD_color_set_HSV(color,
+ hue,
+ TCOD_color_get_saturation(*color),
+ TCOD_color_get_value(*color));
+}
+/**
+ * \brief Return a colors saturation.
+ *
+ * \param color A color struct.
+ * \return The colors saturation. (0 to 1)
+ */
+float TCOD_color_get_saturation (TCOD_color_t color) {
+ float max = (float)(MAX(color.r, MAX(color.g, color.b))) / 255.0f;
+ float min = (float)(MIN(color.r, MIN(color.g, color.b))) / 255.0f;
+ float delta = max - min;
+ if (max == 0.0f) { return 0.0f; }
+ return delta / max;
+}
+/**
+ * \brief Change a colors saturation.
+ *
+ * \param color Pointer to a color struct.
+ * \param saturation The desired saturation value.
+ */
+void TCOD_color_set_saturation(TCOD_color_t *color, float saturation) {
+ TCOD_color_set_HSV(color,
+ TCOD_color_get_hue(*color),
+ saturation,
+ TCOD_color_get_value(*color));
+}
+/**
+ * \brief Get a colors value.
+ *
+ * \param color A color struct.
+ * \return The colors value. (0 to 1)
+ */
+float TCOD_color_get_value(TCOD_color_t color) {
+ return (float)(MAX(color.r, MAX(color.g, color.b))) / 255.0f;
+}
+/**
+ * \brief Change a colors value.
+ *
+ * \param color Pointer to a color struct.
+ * \param value The desired value.
+ */
+void TCOD_color_set_value(TCOD_color_t *color, float value) {
+ TCOD_color_set_HSV(color,
+ TCOD_color_get_hue(*color),
+ TCOD_color_get_saturation(*color),
+ value);
+}
+/**
+ * \brief Shift a colors hue by an amount.
+ *
+ * \param color Pointer to a color struct.
+ * \param hue_shift The distance to shift the hue, in degrees.
+ */
+void TCOD_color_shift_hue(TCOD_color_t *color, float hue_shift) {
+ if (hue_shift == 0.0f) { return; }
+ TCOD_color_set_HSV(color,
+ TCOD_color_get_hue(*color) + hue_shift,
+ TCOD_color_get_saturation(*color),
+ TCOD_color_get_value(*color));
+}
+/**
+ * \brief Scale a colors saturation and value.
+ *
+ * \param color Pointer to a color struct.
+ * \param saturation_coef Multiplier for this colors saturation.
+ * \param value_coef Multiplier for this colors value.
+ */
+void TCOD_color_scale_HSV(TCOD_color_t *color,
+ float saturation_coef, float value_coef) {
+ TCOD_color_set_HSV(color,
+ TCOD_color_get_hue(*color),
+ TCOD_color_get_saturation(*color) * saturation_coef,
+ TCOD_color_get_value(*color) * value_coef);
+}
+/**
+ * \brief Generate an interpolated gradient of colors.
+ *
+ * \param map Array to fill with the new gradient.
+ * \param nb_key The array size of the key_color and key_index parameters.
+ * \param key_color An array of colors to use, in order.
+ * \param key_index An array mapping key_color items to the map array.
+ *
+ * \verbatim embed:rst:leading-asterisk
+ * .. code-block:: c
+ *
+ * TCOD_color_t[256] gradient;
+ * TCOD_color_t[4] key_color = {TCOD_black, TCOD_dark_amber,
+ * TCOD_cyan, TCOD_white};
+ * int[4] key_index = {0, 64, 192, 255};
+ * TCOD_color_gen_map(&gradient, 4, &key_color, &key_index);
+ * \endverbatim
+ */
+void TCOD_color_gen_map(TCOD_color_t *map, int nb_key,
+ const TCOD_color_t *key_color, const int *key_index) {
+ int segment = 0;
+ for (segment = 0; segment < nb_key - 1; ++segment) {
+ int idx_start = key_index[segment];
+ int idx_end = key_index[segment + 1];
+ int idx;
+ for (idx = idx_start; idx <= idx_end; ++idx) {
+ map[idx] = TCOD_color_lerp(
+ key_color[segment],
+ key_color[segment + 1],
+ (float)(idx - idx_start) / (idx_end - idx_start));
+ }
+ }
+}
diff --git a/tcod_sys/libtcod/src/console.cpp b/tcod_sys/libtcod/src/libtcod/console.cpp
similarity index 65%
rename from tcod_sys/libtcod/src/console.cpp
rename to tcod_sys/libtcod/src/libtcod/console.cpp
index 01b8b0d78..d98414fa3 100644
--- a/tcod_sys/libtcod/src/console.cpp
+++ b/tcod_sys/libtcod/src/libtcod/console.cpp
@@ -1,440 +1,464 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#include
-
-#include
-#include
-#include
-
-#include
-#include
-
-#ifdef TCOD_CONSOLE_SUPPORT
-
-TCODConsole * TCODConsole::root = NULL;
-
-TCODConsole::TCODConsole() {}
-TCODConsole::TCODConsole(int w, int h) {
- data = TCOD_console_new(w,h);
-}
-
-TCODConsole::TCODConsole(const char *filename) {
- data = TCOD_console_from_file(filename);
-}
-
-bool TCODConsole::loadAsc(const char *filename) {
- return TCOD_console_load_asc(data,filename) != 0;
-}
-bool TCODConsole::saveAsc(const char *filename) const {
- return TCOD_console_save_asc(data,filename) != 0;
-}
-bool TCODConsole::saveApf(const char *filename) const {
- return TCOD_console_save_apf(data,filename) != 0;
-}
-bool TCODConsole::loadApf(const char *filename) {
- return TCOD_console_load_apf(data,filename) != 0;
-}
-
-void TCODConsole::setCustomFont(const char *fontFile, int flags,int nbCharHoriz, int nbCharVertic) {
- TCOD_console_set_custom_font(fontFile,flags,nbCharHoriz,nbCharVertic);
-}
-
-void TCODConsole::mapAsciiCodeToFont(int asciiCode, int fontCharX, int fontCharY) {
- TCOD_console_map_ascii_code_to_font(asciiCode,fontCharX,fontCharY);
-}
-
-void TCODConsole::mapAsciiCodesToFont(int firstAsciiCode, int nbCodes, int fontCharX, int fontCharY) {
- TCOD_console_map_ascii_codes_to_font(firstAsciiCode,nbCodes,fontCharX,fontCharY);
-}
-
-void TCODConsole::mapStringToFont(const char *s, int fontCharX, int fontCharY) {
- TCOD_console_map_string_to_font(s, fontCharX, fontCharY);
-}
-
-void TCODConsole::setDirty(int x, int y, int w, int h) {
- TCOD_console_set_dirty(x,y,w,h);
-}
-
-TCOD_key_t TCODConsole::checkForKeypress(int flags) {
- return TCOD_sys_check_for_keypress(flags);
-}
-
-TCOD_key_t TCODConsole::waitForKeypress(bool flush) {
- return TCOD_sys_wait_for_keypress(flush);
-}
-
-bool TCODConsole::isWindowClosed() {
- return TCOD_console_is_window_closed() != 0;
-}
-
-bool TCODConsole::hasMouseFocus() {
- return TCOD_console_has_mouse_focus() != 0;
-}
-
-bool TCODConsole::isActive() {
- return TCOD_console_is_active() != 0;
-}
-
-int TCODConsole::getWidth() const {
- return TCOD_console_get_width(data);
-}
-
-int TCODConsole::getHeight() const {
- return TCOD_console_get_height(data);
-}
-
-void TCODConsole::setColorControl(TCOD_colctrl_t con, const TCODColor &fore, const TCODColor &back) {
- TCOD_color_t b={back.r,back.g,back.b},f={fore.r,fore.g,fore.b};
- TCOD_console_set_color_control(con,f,b);
-}
-
-TCODColor TCODConsole::getDefaultBackground() const {
- TCOD_color_t c= TCOD_console_get_default_background(data);
- TCODColor ret;
- ret.r=c.r;
- ret.g=c.g;
- ret.b=c.b;
- return ret;
-}
-TCODColor TCODConsole::getDefaultForeground() const {
- return TCOD_console_get_default_foreground(data);
-}
-void TCODConsole::setDefaultBackground(TCODColor back) {
- TCOD_color_t b={back.r,back.g,back.b};
- TCOD_console_set_default_background(data,b);
-}
-void TCODConsole::setDefaultForeground(TCODColor fore) {
- TCOD_color_t b={fore.r,fore.g,fore.b};
- TCOD_console_set_default_foreground(data,b);
-}
-
-#ifndef TCOD_BARE
-void TCODConsole::setWindowTitle(const char *title) {
- TCOD_sys_set_window_title(title);
-}
-#endif
-
-void TCODConsole::initRoot(int w, int h, const char *title, bool fullscreen, TCOD_renderer_t renderer) {
- TCODConsole *con=new TCODConsole();
- TCOD_console_init_root(w,h,title,fullscreen,renderer);
- con->data=TCOD_ctx.root;
- TCODConsole::root=con;
-}
-
-void TCODConsole::setFullscreen(bool fullscreen) {
- TCOD_console_set_fullscreen(fullscreen);
-}
-
-bool TCODConsole::isFullscreen() {
- return TCOD_console_is_fullscreen() != 0;
-}
-
-void TCODConsole::setBackgroundFlag(TCOD_bkgnd_flag_t bkgnd_flag) {
- TCOD_console_set_background_flag(data,bkgnd_flag);
-}
-
-TCOD_bkgnd_flag_t TCODConsole::getBackgroundFlag() const {
- return TCOD_console_get_background_flag(data);
-}
-
-void TCODConsole::setAlignment(TCOD_alignment_t alignment) {
- TCOD_console_set_alignment(data,alignment);
-}
-
-TCOD_alignment_t TCODConsole::getAlignment() const {
- return TCOD_console_get_alignment(data);
-}
-
-TCODConsole::~TCODConsole() {
- TCOD_console_delete(data);
-}
-
-void TCODConsole::blit(const TCODConsole *srcCon,int xSrc, int ySrc, int wSrc, int hSrc,
- TCODConsole *dstCon, int xDst, int yDst, float foreground_alpha, float background_alpha) {
- TCOD_console_blit(srcCon->data,xSrc,ySrc,wSrc,hSrc,dstCon->data,xDst,yDst,foreground_alpha, background_alpha);
-}
-
-
-void TCODConsole::flush() {
- TCOD_console_flush();
-}
-
-void TCODConsole::setFade(uint8_t val, const TCODColor &fade) {
- TCOD_color_t f= {fade.r,fade.g,fade.b};
- TCOD_console_set_fade(val,f);
-}
-
-uint8_t TCODConsole::getFade() {
- return TCOD_console_get_fade();
-}
-
-TCODColor TCODConsole::getFadingColor() {
- return TCOD_console_get_fading_color();
-}
-
-void TCODConsole::putChar(int x, int y, int c, TCOD_bkgnd_flag_t flag) {
- TCOD_console_put_char(data,x,y,c,flag);
-}
-
-void TCODConsole::putCharEx(int x, int y, int c, const TCODColor &fore, const TCODColor &back) {
- TCOD_color_t f={fore.r,fore.g,fore.b};
- TCOD_color_t b={back.r,back.g,back.b};
- TCOD_console_put_char_ex(data,x,y,c,f,b);
-}
-
-void TCODConsole::clear() {
- TCOD_console_clear(data);
-}
-
-TCODColor TCODConsole::getCharBackground(int x, int y) const {
- return TCOD_console_get_char_background(data,x,y);
-}
-void TCODConsole::setCharForeground(int x,int y, const TCODColor &col) {
- TCOD_color_t c={col.r,col.g,col.b};
- TCOD_console_set_char_foreground(data,x,y,c);
-}
-TCODColor TCODConsole::getCharForeground(int x, int y) const {
- return TCOD_console_get_char_foreground(data,x,y);
-}
-
-int TCODConsole::getChar(int x, int y) const {
- return TCOD_console_get_char(data,x,y);
-}
-
-void TCODConsole::setCharBackground(int x, int y, const TCODColor &col, TCOD_bkgnd_flag_t flag) {
- TCOD_color_t c={col.r,col.g,col.b};
- TCOD_console_set_char_background(data,x,y,c,flag);
-}
-
-void TCODConsole::setChar(int x, int y, int c) {
- TCOD_console_set_char(data,x,y,c);
-}
-
-void TCODConsole::rect(int x,int y, int rw, int rh, bool clear, TCOD_bkgnd_flag_t flag) {
- TCOD_console_rect(data,x,y,rw,rh,clear,flag);
-}
-
-void TCODConsole::hline(int x,int y, int l, TCOD_bkgnd_flag_t flag) {
- TCOD_console_hline(data,x,y,l,flag);
-}
-
-void TCODConsole::vline(int x,int y, int l, TCOD_bkgnd_flag_t flag) {
- TCOD_console_vline(data,x,y,l,flag);
-}
-
-/*
-TCODImage *TCODConsole::getForegroundColorImage() {
- return new TCODImage(TCOD_console_get_foreground_color_image(data));
-}
-
-TCODImage *TCODConsole::getBackgroundColorImage() {
- return new TCODImage(TCOD_console_get_background_color_image(data));
-}
-*/
-
-void TCODConsole::printFrame(int x,int y,int w,int h, bool empty, TCOD_bkgnd_flag_t flag, const char *fmt , ...) {
- if ( fmt ) {
- va_list ap;
- va_start(ap,fmt);
- TCOD_console_print_frame(data,x,y,w,h,empty,flag,TCOD_console_vsprint(fmt,ap));
- va_end(ap);
- } else {
- TCOD_console_print_frame(data,x,y,w,h,empty,flag,NULL);
- }
-}
-
-void TCODConsole::print(int x, int y, const char *fmt, ...) {
- va_list ap;
- TCOD_console_data_t *dat=(TCOD_console_data_t *)data;
- TCOD_IFNOT ( dat != NULL ) return;
- va_start(ap,fmt);
- TCOD_console_print_internal(data,x,y,0,0,dat->bkgnd_flag,dat->alignment,
- TCOD_console_vsprint(fmt,ap),false,false);
- va_end(ap);
-}
-
-void TCODConsole::printEx(int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, ...) {
- va_list ap;
- va_start(ap,fmt);
- TCOD_console_print_internal(data,x,y,0,0,flag,alignment,TCOD_console_vsprint(fmt,ap),false,false);
- va_end(ap);
-}
-
-
-/*
-void TCODConsole::printLine(int x, int y, TCOD_bkgnd_flag_t flag, TCOD_print_location_t location, const char *fmt, ...) {
- va_list ap;
- va_start(ap,fmt);
- switch(location)
- {
- case TCOD_PRINT_LEFT:
- TCOD_console_print(data,x,y,getWidth()-x,getHeight()-y,flag,LEFT,TCOD_console_vsprint(fmt,ap),false,false);
- break;
- case TCOD_PRINT_RIGHT:
- TCOD_console_print(data,x,y,x+1,getHeight()-y,flag,RIGHT,TCOD_console_vsprint(fmt,ap),false,false);
- break;
- case TCOD_PRINT_CENTER:
- TCOD_console_print(data,x,y,getWidth(),getHeight()-y,flag,CENTER,TCOD_console_vsprint(fmt,ap),false,false);
- break;
- default:
- TCOD_ASSERT(0);
- break;
- }
- va_end(ap);
-}
-*/
-
-int TCODConsole::printRect(int x, int y, int w, int h, const char *fmt, ...) {
- va_list ap;
- TCOD_console_data_t *dat=(TCOD_console_data_t *)data;
- TCOD_IFNOT ( dat != NULL ) return 0;
- va_start(ap,fmt);
- int ret = TCOD_console_print_internal(data,x,y,w,h,dat->bkgnd_flag,dat->alignment,TCOD_console_vsprint(fmt,ap),true,false);
- va_end(ap);
- return ret;
-}
-
-int TCODConsole::printRectEx(int x, int y, int w, int h, TCOD_bkgnd_flag_t flag,
- TCOD_alignment_t alignment, const char *fmt, ...) {
- va_list ap;
- va_start(ap,fmt);
- int ret = TCOD_console_print_internal(data,x,y,w,h,flag,alignment,TCOD_console_vsprint(fmt,ap),true,false);
- va_end(ap);
- return ret;
-}
-
-int TCODConsole::getHeightRect(int x, int y, int w, int h, const char *fmt, ...) {
- va_list ap;
- va_start(ap,fmt);
- int ret = TCOD_console_print_internal(data,x,y,w,h,TCOD_BKGND_NONE,TCOD_LEFT,TCOD_console_vsprint(fmt,ap),true,true);
- va_end(ap);
- return ret;
-}
-
-bool TCODConsole::isKeyPressed(TCOD_keycode_t key) {
- return TCOD_console_is_key_pressed(key) != 0;
-}
-void TCODConsole::setKeyColor(const TCODColor &col) {
- TCOD_color_t c={col.r,col.g,col.b};
- TCOD_console_set_key_color(data,c);
-}
-
-void TCODConsole::credits() {
- TCOD_console_credits();
-}
-
-void TCODConsole::resetCredits() {
- TCOD_console_credits_reset();
-}
-
-bool TCODConsole::renderCredits(int x, int y, bool alpha) {
- return TCOD_console_credits_render(x,y,alpha) != 0;
-}
-
-#ifndef NO_UNICODE
-void TCODConsole::mapStringToFont(const wchar_t *s, int fontCharX, int fontCharY) {
- TCOD_console_map_string_to_font_utf(s, fontCharX, fontCharY);
-}
-
-void TCODConsole::print(int x, int y, const wchar_t *fmt, ...) {
- va_list ap;
- TCOD_console_data_t *dat=(TCOD_console_data_t *)data;
- TCOD_IFNOT ( dat != NULL ) return;
- va_start(ap,fmt);
- TCOD_console_print_internal_utf(data,x,y,0,0,dat->bkgnd_flag,dat->alignment,TCOD_console_vsprint_utf(fmt,ap),false,false);
- va_end(ap);
-}
-
-void TCODConsole::printEx(int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...) {
- va_list ap;
- va_start(ap,fmt);
- TCOD_console_print_internal_utf(data,x,y,0,0,flag,alignment,TCOD_console_vsprint_utf(fmt,ap),false,false);
- va_end(ap);
-}
-
-int TCODConsole::printRect(int x, int y, int w, int h, const wchar_t *fmt, ...) {
- va_list ap;
- TCOD_console_data_t *dat=(TCOD_console_data_t *)data;
- TCOD_IFNOT ( dat != NULL ) return 0;
- va_start(ap,fmt);
- int ret = TCOD_console_print_internal_utf(data,x,y,w,h,dat->bkgnd_flag,dat->alignment,
- TCOD_console_vsprint_utf(fmt,ap),true,false);
- va_end(ap);
- return ret;
-}
-
-int TCODConsole::printRectEx(int x, int y, int w, int h, TCOD_bkgnd_flag_t flag,
- TCOD_alignment_t alignment, const wchar_t *fmt, ...) {
- va_list ap;
- va_start(ap,fmt);
- int ret = TCOD_console_print_internal_utf(data,x,y,w,h,flag,alignment,
- TCOD_console_vsprint_utf(fmt,ap),true,false);
- va_end(ap);
- return ret;
-}
-
-int TCODConsole::getHeightRect(int x, int y, int w, int h, const wchar_t *fmt, ...) {
- va_list ap;
- va_start(ap,fmt);
- int ret = TCOD_console_print_internal_utf(data,x,y,w,h,TCOD_BKGND_NONE,TCOD_LEFT,TCOD_console_vsprint_utf(fmt,ap),true,true);
- va_end(ap);
- return ret;
-}
-
-// color control string formatting utilities for swigged language
-
-// ctrl = TCOD_COLCTRL_1...TCOD_COLCTRL_5 or TCOD_COLCTRL_STOP
-#define NB_BUFFERS 10
-const char *TCODConsole::getColorControlString( TCOD_colctrl_t ctrl ) {
- static char buf[NB_BUFFERS][2];
- static int buf_nb=0;
- const char *ret;
- buf[buf_nb][0]=ctrl;
- buf[buf_nb][1]=0;
- ret = (const char *)(&buf[buf_nb][0]);
- buf_nb = (buf_nb+1) % NB_BUFFERS;
- return ret;
-}
-
-// ctrl = TCOD_COLCTRL_FORE_RGB or TCOD_COLCTRL_BACK_RGB
-const char *TCODConsole::getRGBColorControlString( TCOD_colctrl_t ctrl, const TCODColor & col ) {
- static char buf[NB_BUFFERS][5];
- static int buf_nb=0;
- const char *ret;
- buf[buf_nb][0]=ctrl;
- buf[buf_nb][1]=col.r;
- buf[buf_nb][2]=col.g;
- buf[buf_nb][3]=col.b;
- buf[buf_nb][4]=0;
- ret = (const char *)(&buf[buf_nb][0]);
- buf_nb = (buf_nb+1) % NB_BUFFERS;
- return ret;
-}
-
-#endif
-
-#endif /* TCOD_CONSOLE_SUPPORT */
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "console.hpp"
+
+#include
+#include
+#include
+
+#include "libtcod_int.h"
+#include "image.hpp"
+#include "engine/display.h"
+
+#ifdef TCOD_CONSOLE_SUPPORT
+
+TCODConsole* TCODConsole::root = new TCODConsole();
+
+TCODConsole::TCODConsole() {}
+TCODConsole::TCODConsole(int w, int h) {
+ data = TCOD_console_new(w,h);
+}
+
+TCODConsole::TCODConsole(const char *filename) {
+ data = TCOD_console_from_file(filename);
+}
+
+bool TCODConsole::loadAsc(const char *filename) {
+ return TCOD_console_load_asc(data,filename) != 0;
+}
+bool TCODConsole::saveAsc(const char *filename) const {
+ return TCOD_console_save_asc(data,filename) != 0;
+}
+bool TCODConsole::saveApf(const char *filename) const {
+ return TCOD_console_save_apf(data,filename) != 0;
+}
+bool TCODConsole::loadApf(const char *filename) {
+ return TCOD_console_load_apf(data,filename) != 0;
+}
+
+void TCODConsole::setCustomFont(const char *fontFile, int flags,int nbCharHoriz, int nbCharVertic) {
+ TCOD_console_set_custom_font(fontFile,flags,nbCharHoriz,nbCharVertic);
+}
+
+void TCODConsole::mapAsciiCodeToFont(int asciiCode, int fontCharX, int fontCharY) {
+ TCOD_console_map_ascii_code_to_font(asciiCode,fontCharX,fontCharY);
+}
+
+void TCODConsole::mapAsciiCodesToFont(int firstAsciiCode, int nbCodes, int fontCharX, int fontCharY) {
+ TCOD_console_map_ascii_codes_to_font(firstAsciiCode,nbCodes,fontCharX,fontCharY);
+}
+
+void TCODConsole::mapStringToFont(const char *s, int fontCharX, int fontCharY) {
+ TCOD_console_map_string_to_font(s, fontCharX, fontCharY);
+}
+
+void TCODConsole::setDirty(int x, int y, int w, int h) {
+ TCOD_console_set_dirty(x,y,w,h);
+}
+
+TCOD_key_t TCODConsole::checkForKeypress(int flags) {
+ return TCOD_sys_check_for_keypress(flags);
+}
+
+TCOD_key_t TCODConsole::waitForKeypress(bool flush) {
+ return TCOD_sys_wait_for_keypress(flush);
+}
+
+bool TCODConsole::isWindowClosed() {
+ return TCOD_console_is_window_closed() != 0;
+}
+
+bool TCODConsole::hasMouseFocus() {
+ return TCOD_console_has_mouse_focus() != 0;
+}
+
+bool TCODConsole::isActive() {
+ return TCOD_console_is_active() != 0;
+}
+
+int TCODConsole::getWidth() const {
+ return TCOD_console_get_width(data);
+}
+
+int TCODConsole::getHeight() const {
+ return TCOD_console_get_height(data);
+}
+
+void TCODConsole::setColorControl(TCOD_colctrl_t con, const TCODColor &fore, const TCODColor &back) {
+ TCOD_color_t b={back.r,back.g,back.b},f={fore.r,fore.g,fore.b};
+ TCOD_console_set_color_control(con,f,b);
+}
+
+TCODColor TCODConsole::getDefaultBackground() const {
+ TCOD_color_t c= TCOD_console_get_default_background(data);
+ TCODColor ret;
+ ret.r=c.r;
+ ret.g=c.g;
+ ret.b=c.b;
+ return ret;
+}
+TCODColor TCODConsole::getDefaultForeground() const {
+ return TCOD_console_get_default_foreground(data);
+}
+void TCODConsole::setDefaultBackground(TCODColor back) {
+ TCOD_color_t b={back.r,back.g,back.b};
+ TCOD_console_set_default_background(data,b);
+}
+void TCODConsole::setDefaultForeground(TCODColor fore) {
+ TCOD_color_t b={fore.r,fore.g,fore.b};
+ TCOD_console_set_default_foreground(data,b);
+}
+
+#ifndef TCOD_BARE
+void TCODConsole::setWindowTitle(const char *title) {
+ TCOD_sys_set_window_title(title);
+}
+#endif
+
+void TCODConsole::initRoot(int w, int h, const char *title, bool fullscreen,
+ TCOD_renderer_t renderer)
+{
+ tcod::console::init_root(w, h, title ? title : "", fullscreen, renderer);
+}
+
+void TCODConsole::setFullscreen(bool fullscreen) {
+ TCOD_console_set_fullscreen(fullscreen);
+}
+
+bool TCODConsole::isFullscreen() {
+ return TCOD_console_is_fullscreen() != 0;
+}
+
+void TCODConsole::setBackgroundFlag(TCOD_bkgnd_flag_t bkgnd_flag) {
+ TCOD_console_set_background_flag(data,bkgnd_flag);
+}
+
+TCOD_bkgnd_flag_t TCODConsole::getBackgroundFlag() const {
+ return TCOD_console_get_background_flag(data);
+}
+
+void TCODConsole::setAlignment(TCOD_alignment_t alignment) {
+ TCOD_console_set_alignment(data,alignment);
+}
+
+TCOD_alignment_t TCODConsole::getAlignment() const {
+ return TCOD_console_get_alignment(data);
+}
+
+TCODConsole::~TCODConsole() {
+ TCOD_console_delete(data);
+}
+
+void TCODConsole::blit(const TCODConsole *srcCon,int xSrc, int ySrc, int wSrc, int hSrc,
+ TCODConsole *dstCon, int xDst, int yDst, float foreground_alpha, float background_alpha) {
+ TCOD_console_blit(srcCon->data,xSrc,ySrc,wSrc,hSrc,dstCon->data,xDst,yDst,foreground_alpha, background_alpha);
+}
+
+
+void TCODConsole::flush() {
+ TCOD_console_flush();
+}
+
+void TCODConsole::setFade(uint8_t val, const TCODColor &fade) {
+ TCOD_color_t f= {fade.r,fade.g,fade.b};
+ TCOD_console_set_fade(val,f);
+}
+
+uint8_t TCODConsole::getFade() {
+ return TCOD_console_get_fade();
+}
+
+TCODColor TCODConsole::getFadingColor() {
+ return TCOD_console_get_fading_color();
+}
+
+void TCODConsole::putChar(int x, int y, int c, TCOD_bkgnd_flag_t flag) {
+ TCOD_console_put_char(data,x,y,c,flag);
+}
+
+void TCODConsole::putCharEx(int x, int y, int c, const TCODColor &fore, const TCODColor &back) {
+ TCOD_color_t f={fore.r,fore.g,fore.b};
+ TCOD_color_t b={back.r,back.g,back.b};
+ TCOD_console_put_char_ex(data,x,y,c,f,b);
+}
+
+void TCODConsole::clear() {
+ TCOD_console_clear(data);
+}
+
+TCODColor TCODConsole::getCharBackground(int x, int y) const {
+ return TCOD_console_get_char_background(data,x,y);
+}
+void TCODConsole::setCharForeground(int x,int y, const TCODColor &col) {
+ TCOD_color_t c={col.r,col.g,col.b};
+ TCOD_console_set_char_foreground(data,x,y,c);
+}
+TCODColor TCODConsole::getCharForeground(int x, int y) const {
+ return TCOD_console_get_char_foreground(data,x,y);
+}
+
+int TCODConsole::getChar(int x, int y) const {
+ return TCOD_console_get_char(data,x,y);
+}
+
+void TCODConsole::setCharBackground(int x, int y, const TCODColor &col, TCOD_bkgnd_flag_t flag) {
+ TCOD_color_t c={col.r,col.g,col.b};
+ TCOD_console_set_char_background(data,x,y,c,flag);
+}
+
+void TCODConsole::setChar(int x, int y, int c) {
+ TCOD_console_set_char(data,x,y,c);
+}
+
+void TCODConsole::rect(int x,int y, int rw, int rh, bool clear, TCOD_bkgnd_flag_t flag) {
+ TCOD_console_rect(data,x,y,rw,rh,clear,flag);
+}
+
+void TCODConsole::hline(int x,int y, int l, TCOD_bkgnd_flag_t flag) {
+ TCOD_console_hline(data,x,y,l,flag);
+}
+
+void TCODConsole::vline(int x,int y, int l, TCOD_bkgnd_flag_t flag) {
+ TCOD_console_vline(data,x,y,l,flag);
+}
+
+void TCODConsole::printFrame(int x,int y,int w,int h, bool empty, TCOD_bkgnd_flag_t flag, const char *fmt , ...) {
+ if ( fmt ) {
+ va_list ap;
+ va_start(ap,fmt);
+ TCOD_console_print_frame(data,x,y,w,h,empty,flag,TCOD_console_vsprint(fmt,ap));
+ va_end(ap);
+ } else {
+ TCOD_console_print_frame(data,x,y,w,h,empty,flag,NULL);
+ }
+}
+/** Deprecated EASCII function. */
+void TCODConsole::print(int x, int y, const char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ TCOD_console_print_internal(
+ data, x, y, 0, 0, data->bkgnd_flag, data->alignment,
+ TCOD_console_vsprint(fmt, ap), false, false);
+ va_end(ap);
+}
+void TCODConsole::print(int x, int y, const std::string &str) {
+ this->print(x, y, str, data->alignment, data->bkgnd_flag);
+}
+void TCODConsole::print(int x, int y, const std::string &str,
+ TCOD_alignment_t alignment, TCOD_bkgnd_flag_t flag) {
+ tcod::console::print(data, x, y, str,
+ &data->fore, &data->back, flag, alignment);
+}
+void TCODConsole::printf(int x, int y, const char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ this->print(x, y, std::string(TCOD_console_vsprint(fmt, ap)));
+ va_end(ap);
+}
+void TCODConsole::printf(int x, int y, TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t alignment, const char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ this->print(x, y, std::string(TCOD_console_vsprint(fmt, ap)),
+ alignment, flag);
+ va_end(ap);
+}
+/** Deprecated EASCII function. */
+void TCODConsole::printEx(int x, int y, TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t alignment, const char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ TCOD_console_print_internal(data, x, y, 0, 0, flag, alignment,
+ TCOD_console_vsprint(fmt,ap), false, false);
+ va_end(ap);
+}
+
+
+/*
+void TCODConsole::printLine(int x, int y, TCOD_bkgnd_flag_t flag, TCOD_print_location_t location, const char *fmt, ...) {
+ va_list ap;
+ va_start(ap,fmt);
+ switch(location)
+ {
+ case TCOD_PRINT_LEFT:
+ TCOD_console_print(data,x,y,getWidth()-x,getHeight()-y,flag,LEFT,TCOD_console_vsprint(fmt,ap),false,false);
+ break;
+ case TCOD_PRINT_RIGHT:
+ TCOD_console_print(data,x,y,x+1,getHeight()-y,flag,RIGHT,TCOD_console_vsprint(fmt,ap),false,false);
+ break;
+ case TCOD_PRINT_CENTER:
+ TCOD_console_print(data,x,y,getWidth(),getHeight()-y,flag,CENTER,TCOD_console_vsprint(fmt,ap),false,false);
+ break;
+ default:
+ TCOD_ASSERT(0);
+ break;
+ }
+ va_end(ap);
+}
+*/
+
+int TCODConsole::printRect(int x, int y, int w, int h, const char *fmt, ...)
+{
+ va_list ap;
+ TCOD_IFNOT (data != NULL) { return 0; }
+ va_start(ap,fmt);
+ int ret = TCOD_console_print_internal(
+ data, x, y, w, h, data->bkgnd_flag, data->alignment,
+ TCOD_console_vsprint(fmt, ap), true, false);
+ va_end(ap);
+ return ret;
+}
+
+int TCODConsole::printRectEx(int x, int y, int w, int h, TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t alignment, const char *fmt, ...) {
+ va_list ap;
+ va_start(ap,fmt);
+ int ret = TCOD_console_print_internal(data,x,y,w,h,flag,alignment,TCOD_console_vsprint(fmt,ap),true,false);
+ va_end(ap);
+ return ret;
+}
+
+int TCODConsole::getHeightRect(int x, int y, int w, int h, const char *fmt, ...) {
+ va_list ap;
+ va_start(ap,fmt);
+ int ret = TCOD_console_print_internal(data,x,y,w,h,TCOD_BKGND_NONE,TCOD_LEFT,TCOD_console_vsprint(fmt,ap),true,true);
+ va_end(ap);
+ return ret;
+}
+
+bool TCODConsole::isKeyPressed(TCOD_keycode_t key) {
+ return TCOD_console_is_key_pressed(key) != 0;
+}
+void TCODConsole::setKeyColor(const TCODColor &col) {
+ TCOD_color_t c={col.r,col.g,col.b};
+ TCOD_console_set_key_color(data,c);
+}
+
+void TCODConsole::credits() {
+ TCOD_console_credits();
+}
+
+void TCODConsole::resetCredits() {
+ TCOD_console_credits_reset();
+}
+
+bool TCODConsole::renderCredits(int x, int y, bool alpha) {
+ return TCOD_console_credits_render(x,y,alpha) != 0;
+}
+
+#ifndef NO_UNICODE
+void TCODConsole::mapStringToFont(const wchar_t *s, int fontCharX, int fontCharY) {
+ TCOD_console_map_string_to_font_utf(s, fontCharX, fontCharY);
+}
+
+void TCODConsole::print(int x, int y, const wchar_t *fmt, ...)
+{
+ va_list ap;
+ TCOD_IFNOT (data != NULL) { return; }
+ va_start(ap, fmt);
+ TCOD_console_print_internal_utf(
+ data, x, y, 0, 0, data->bkgnd_flag, data->alignment,
+ TCOD_console_vsprint_utf(fmt, ap), false, false);
+ va_end(ap);
+}
+
+void TCODConsole::printEx(int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...) {
+ va_list ap;
+ va_start(ap,fmt);
+ TCOD_console_print_internal_utf(data,x,y,0,0,flag,alignment,TCOD_console_vsprint_utf(fmt,ap),false,false);
+ va_end(ap);
+}
+
+int TCODConsole::printRect(int x, int y, int w, int h, const wchar_t *fmt, ...)
+{
+ va_list ap;
+ TCOD_IFNOT (data != NULL) { return 0; }
+ va_start(ap,fmt);
+ int ret = TCOD_console_print_internal_utf(
+ data, x, y, w, h, data->bkgnd_flag, data->alignment,
+ TCOD_console_vsprint_utf(fmt, ap), true, false);
+ va_end(ap);
+ return ret;
+}
+
+int TCODConsole::printRectEx(int x, int y, int w, int h, TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t alignment, const wchar_t *fmt, ...) {
+ va_list ap;
+ va_start(ap,fmt);
+ int ret = TCOD_console_print_internal_utf(data,x,y,w,h,flag,alignment,
+ TCOD_console_vsprint_utf(fmt,ap),true,false);
+ va_end(ap);
+ return ret;
+}
+
+int TCODConsole::getHeightRect(int x, int y, int w, int h, const wchar_t *fmt, ...) {
+ va_list ap;
+ va_start(ap,fmt);
+ int ret = TCOD_console_print_internal_utf(data,x,y,w,h,TCOD_BKGND_NONE,TCOD_LEFT,TCOD_console_vsprint_utf(fmt,ap),true,true);
+ va_end(ap);
+ return ret;
+}
+
+// color control string formatting utilities for swigged language
+
+// ctrl = TCOD_COLCTRL_1...TCOD_COLCTRL_5 or TCOD_COLCTRL_STOP
+#define NB_BUFFERS 10
+const char *TCODConsole::getColorControlString(TCOD_colctrl_t ctrl)
+{
+ static char buf[NB_BUFFERS][2];
+ static int buf_nb = 0;
+ buf[buf_nb][0] = ctrl;
+ buf[buf_nb][1] = 0;
+ const char* ret = buf[buf_nb];
+ buf_nb = (buf_nb + 1) % NB_BUFFERS;
+ return ret;
+}
+
+// ctrl = TCOD_COLCTRL_FORE_RGB or TCOD_COLCTRL_BACK_RGB
+const char *TCODConsole::getRGBColorControlString(TCOD_colctrl_t ctrl,
+ const TCODColor& col)
+{
+ static char buf[NB_BUFFERS][5];
+ static int buf_nb = 0;
+ buf[buf_nb][0] = ctrl;
+ buf[buf_nb][1] = col.r;
+ buf[buf_nb][2] = col.g;
+ buf[buf_nb][3] = col.b;
+ buf[buf_nb][4] = 0;
+ const char* ret = buf[buf_nb];
+ buf_nb = (buf_nb + 1) % NB_BUFFERS;
+ return ret;
+}
+
+#endif
+
+#endif /* TCOD_CONSOLE_SUPPORT */
diff --git a/tcod_sys/libtcod/src/libtcod/console.h b/tcod_sys/libtcod/src/libtcod/console.h
new file mode 100644
index 000000000..e01059da4
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/console.h
@@ -0,0 +1,99 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _TCOD_CONSOLE_H
+#define _TCOD_CONSOLE_H
+
+#include "portability.h"
+
+#ifdef TCOD_CONSOLE_SUPPORT
+
+#include "console/console.h"
+#include "console/drawing.h"
+#include "console/printing.h"
+#include "console/rexpaint.h"
+#include "color.h"
+#include "console_types.h"
+#include "image.h"
+#include "list.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define TCOD_BKGND_ALPHA(alpha) ((TCOD_bkgnd_flag_t)(TCOD_BKGND_ALPH|(((uint8_t)(alpha*255))<<8)))
+#define TCOD_BKGND_ADDALPHA(alpha) ((TCOD_bkgnd_flag_t)(TCOD_BKGND_ADDA|(((uint8_t)(alpha*255))<<8)))
+
+TCODLIB_API int TCOD_console_set_custom_font(
+ const char *fontFile,
+ int flags,
+ int nb_char_horiz,
+ int nb_char_vertic);
+TCODLIB_API void TCOD_console_map_ascii_code_to_font(int asciiCode, int fontCharX, int fontCharY);
+TCODLIB_API void TCOD_console_map_ascii_codes_to_font(int asciiCode, int nbCodes, int fontCharX, int fontCharY);
+TCODLIB_API void TCOD_console_map_string_to_font(const char *s, int fontCharX, int fontCharY);
+#ifndef NO_UNICODE
+TCODLIB_API void TCOD_console_map_string_to_font_utf(const wchar_t *s, int fontCharX, int fontCharY);
+#endif
+
+TCODLIB_API void TCOD_console_set_dirty(int x, int y, int w, int h);
+
+TCODLIB_API void TCOD_console_flush(void);
+
+TCODLIB_API void TCOD_console_set_color_control(TCOD_colctrl_t con, TCOD_color_t fore, TCOD_color_t back);
+
+TCODLIB_API TCOD_key_t TCOD_console_check_for_keypress(int flags);
+TCODLIB_API TCOD_key_t TCOD_console_wait_for_keypress(bool flush);
+TCODLIB_API bool TCOD_console_is_key_pressed(TCOD_keycode_t key);
+
+/* ASCII paint file support */
+TCODLIB_API TCOD_console_t TCOD_console_from_file(const char *filename);
+TCODLIB_API bool TCOD_console_load_asc(TCOD_console_t con, const char *filename);
+TCODLIB_API bool TCOD_console_load_apf(TCOD_console_t con, const char *filename);
+TCODLIB_API bool TCOD_console_save_asc(TCOD_console_t con, const char *filename);
+TCODLIB_API bool TCOD_console_save_apf(TCOD_console_t con, const char *filename);
+
+TCODLIB_API void TCOD_console_credits(void);
+TCODLIB_API void TCOD_console_credits_reset(void);
+TCODLIB_API bool TCOD_console_credits_render(int x, int y, bool alpha);
+
+TCOD_DEPRECATED("This function is a stub and will do nothing.")
+TCODLIB_API void TCOD_console_set_keyboard_repeat(int initial_delay,
+ int interval);
+TCOD_DEPRECATED("This function is a stub and will do nothing.")
+TCODLIB_API void TCOD_console_disable_keyboard_repeat();
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TCOD_CONSOLE_SUPPORT */
+
+#endif /* _TCOD_CONSOLE_H */
diff --git a/tcod_sys/libtcod/include/console.hpp b/tcod_sys/libtcod/src/libtcod/console.hpp
similarity index 92%
rename from tcod_sys/libtcod/include/console.hpp
rename to tcod_sys/libtcod/src/libtcod/console.hpp
index 3f6d92f59..73ffc53da 100644
--- a/tcod_sys/libtcod/include/console.hpp
+++ b/tcod_sys/libtcod/src/libtcod/console.hpp
@@ -1,1790 +1,1816 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _TCOD_CONSOLE_HPP
-#define _TCOD_CONSOLE_HPP
-
-#include "console.h"
-
-#ifdef TCOD_CONSOLE_SUPPORT
-
-#include "image.hpp"
-#include "color.hpp"
-
-class TCODImage;
-/**
- @PageName console
- @PageCategory Core
- @PageTitle Console
- @PageDesc The console emulator handles the rendering of the game screen and the keyboard input.
-Classic real time game loop:
- @Cpp
- TCODConsole::initRoot(80,50,"my game",false);
- TCODSystem::setFps(25); // limit framerate to 25 frames per second
- while (!endGame && !TCODConsole::isWindowClosed()) {
- TCOD_key_t key;
- TCODSystem::checkForEvent(TCOD_EVENT_KEY_PRESS,&key,NULL);
- updateWorld (key, TCODSystem::getLastFrameLength());
- // updateWorld(TCOD_key_t key, float elapsed) (using key if key.vk != TCODK_NONE)
- // use elapsed to scale any update that is time dependent.
- // ... draw world+GUI on TCODConsole::root
- TCODConsole::flush();
- }
- @Lua
- tcod.console.initRoot(80,50,"my game", false)
- root=libtcod.TCODConsole_root
- tcod.system.setFps(25)
- while not tcod.console.isWindowClosed() do
- -- ... draw on root
- tcod.console.flush()
- key=tcod.console.checkForKeypress()
- -- ... update world, using key and tcod.system.getLastFrameLength
- end
-
-*/
-/**
- @PageName console
- @FuncDesc Classic turn by turn game loop:
- @Cpp
- TCODConsole::initRoot(80,50,"my game",false);
- while (!endGame && !TCODConsole::isWindowClosed()) {
- // ... draw on TCODConsole::root
- TCODConsole::flush();
- TCOD_key_t key;
- TCODConsole::waitForEvent(TCOD_EVENT_KEY_PRESS,&key,NULL,true);
- //... update world, using key
- }
-*/
-
-class TCODLIB_API TCODConsole {
-public :
- /**
- @PageName console_init
- @PageTitle Initializing the console
- @PageFather console
- */
-
- static TCODConsole *root;
-
- /**
- @PageName console_init_root
- @PageTitle Creating the game window
- @PageFather console_init
- @Cpp static void TCODConsole::initRoot (int w, int h, const char * title, bool fullscreen = false, TCOD_renderer_t renderer = TCOD_RENDERER_SDL)
- @C void TCOD_console_init_root (int w, int h, const char * title, bool fullscreen, TCOD_renderer_t renderer)
- @Py console_init_root (w, h, title, fullscreen = False, renderer = RENDERER_SDL)
- @C#
- static void TCODConsole::initRoot(int w, int h, string title)
- static void TCODConsole::initRoot(int w, int h, string title, bool fullscreen)
- static void TCODConsole::initRoot(int w, int h, string title, bool fullscreen, TCODRendererType renderer)
- @Lua
- tcod.console.initRoot(w,h,title) -- fullscreen = false, renderer = SDL
- tcod.console.initRoot(w,h,title,fullscreen) -- renderer = SDL
- tcod.console.initRoot(w,h,title,fullscreen,renderer)
- -- renderers : tcod.GLSL, tcod.OpenGL, tcod.SDL
- @Param w,h size of the console(in characters). The default font in libtcod (./terminal.png) uses 8x8 pixels characters.
- You can change the font by calling TCODConsole::setCustomFont before calling initRoot.
- @Param title title of the window. It's not visible when you are in fullscreen.
- Note 1 : you can dynamically change the window title with TCODConsole::setWindowTitle
- @Param fullscreen whether you start in windowed or fullscreen mode.
- Note 1 : you can dynamically change this mode with TCODConsole::setFullscreen
- Note 2 : you can get current mode with TCODConsole::isFullscreen
- @Param renderer which renderer to use. Possible values are :
- * TCOD_RENDERER_GLSL : works only on video cards with pixel shaders
- * TCOD_RENDERER_OPENGL : works on all video cards supporting OpenGL 1.4
- * TCOD_RENDERER_SDL : should work everywhere!
- Note 1: if you select a renderer that is not supported by the player's machine, libtcod scan the lower renderers until it finds a working one.
- Note 2: on recent video cards, GLSL results in up to 900% increase of framerates in the true color sample compared to SDL renderer.
- Note 3: whatever renderer you use, it can always be overridden by the player through the libtcod.cfg file.
- Note 4: you can dynamically change the renderer after calling initRoot with TCODSystem::setRenderer.
- Note 5: you can get current renderer with TCODSystem::getRenderer. It might be different from the one you set in initRoot in case it's not supported on the player's computer.
- @CppEx TCODConsole::initRoot(80, 50, "The Chronicles Of Doryen v0.1");
- @CEx TCOD_console_init_root(80, 50, "The Chronicles Of Doryen v0.1", false, TCOD_RENDERER_OPENGL);
- @PyEx libtcod.console_init_root(80, 50, 'The Chronicles Of Doryen v0.1')
- @LuaEx tcod.console.initRoot(80,50,"The Chronicles Of Doryen v0.1")
- */
- static void initRoot(int w, int h, const char * title, bool fullscreen = false, TCOD_renderer_t renderer=TCOD_RENDERER_SDL);
-
- /**
- @PageName console_set_custom_font
- @PageTitle Using a custom bitmap font
- @PageFather console_init
- @FuncTitle setCustomFont
- @FuncDesc This function allows you to use a bitmap font (png or bmp) with custom character size or layout.
- It should be called before initializing the root console with initRoot.
- Once this function is called, you can define your own custom mappings using mapping functions
- Different font layouts
-
- ASCII_INROW | ASCII_INCOL | TCOD |
-
- | | |
-
-
- - ascii, in columns : characters 0 to 15 are in the first column. The space character is at coordinates 2,0.
- - ascii, in rows : characters 0 to 15 are in the first row. The space character is at coordinates 0,2.
- - tcod : special mapping. Not all ascii values are mapped. The space character is at coordinates 0,0.
-
- Different font types
-
- standard (non antialiased) | antialiased (32 bits PNG) | antialiased (greyscale) |
-
- | | |
-
-
- - standard : transparency is given by a key color automatically detected by looking at the color of the space character
- - 32 bits : transparency is given by the png alpha layer. The font color does not matter but it must be desaturated
- - greyscale : transparency is given by the pixel value. You can use white characters on black background or black characters on white background. The background color is automatically detected by looking at the color of the space character
-
- Examples of fonts can be found in libtcod's fonts directory. Check the Readme file there.
- @Cpp static void TCODConsole::setCustomFont(const char *fontFile, int flags=TCOD_FONT_LAYOUT_ASCII_INCOL,int nbCharHoriz=0, int nbCharVertic=0)
- @C void TCOD_console_set_custom_font(const char *fontFile, int flags,int nb_char_horiz, int nb_char_vertic)
- @Py console_set_custom_font(fontFile, flags=FONT_LAYOUT_ASCII_INCOL,nb_char_horiz=0, nb_char_vertic=0)
- @C#
- static void TCODConsole::setCustomFont(string fontFile)
- static void TCODConsole::setCustomFont(string fontFile, int flags)
- static void TCODConsole::setCustomFont(string fontFile, int flags, int nbCharHoriz)
- static void TCODConsole::setCustomFont(string fontFile, int flags, int nbCharHoriz, int nbCharVertic)
- @Lua
- tcod.console.setCustomFont(fontFile)
- tcod.console.setCustomFont(fontFile, flags)
- tcod.console.setCustomFont(fontFile, nbCharHoriz)
- tcod.console.setCustomFont(fontFile, flags, nbCharHoriz, nbCharVertic)
- -- flags : tcod.LayoutAsciiInColumn, tcod.LayoutAsciiInRow, tcod.LayoutTCOD, tcod.Greyscale
- @Param fontFile Name of a .bmp or .png file containing the font.
- @Param flags Used to define the characters layout in the bitmap and the font type :
- TCOD_FONT_LAYOUT_ASCII_INCOL : characters in ASCII order, code 0-15 in the first column
- TCOD_FONT_LAYOUT_ASCII_INROW : characters in ASCII order, code 0-15 in the first row
- TCOD_FONT_LAYOUT_TCOD : simplified layout. See examples below.
- TCOD_FONT_TYPE_GREYSCALE : create an anti-aliased font from a greyscale bitmap
- For Python, remove TCOD _ :
- libtcod.FONT_LAYOUT_ASCII_INCOL
- @Param nbCharHoriz,nbCharVertic Number of characters in the font.
- Should be 16x16 for ASCII layouts, 32x8 for TCOD layout.
- But you can use any other layout.
- If set to 0, there are deduced from the font layout flag.
- @CppEx
- TCODConsole::setCustomFont("standard_8x8_ascii_in_col_font.bmp",TCOD_FONT_LAYOUT_ASCII_INCOL);
- TCODConsole::setCustomFont("32bits_8x8_ascii_in_row_font.png",TCOD_FONT_LAYOUT_ASCII_INROW);
- TCODConsole::setCustomFont("greyscale_8x8_tcod_font.png",TCOD_FONT_LAYOUT_TCOD | TCOD_FONT_TYPE_GREYSCALE);
- @CEx
- TCOD_console_set_custom_font("standard_8x8_ascii_in_col_font.bmp",TCOD_FONT_LAYOUT_ASCII_INCOL,16,16);
- TCOD_console_set_custom_font("32bits_8x8_ascii_in_row_font.png",TCOD_FONT_LAYOUT_ASCII_INROW,32,8);
- TCOD_console_set_custom_font("greyscale_8x8_tcod_font.png",TCOD_FONT_LAYOUT_TCOD | TCOD_FONT_TYPE_GREYSCALE,32,8);
- @PyEx
- libtcod.console_set_custom_font("standard_8x8_ascii_in_col_font.bmp",libtcod.FONT_LAYOUT_ASCII_INCOL)
- libtcod.console_set_custom_font("32bits_8x8_ascii_in_row_font.png",libtcod.FONT_LAYOUT_ASCII_INROW)
- libtcod.console_set_custom_font("greyscale_8x8_tcod_font.png",libtcod.FONT_LAYOUT_TCOD | libtcod.FONT_TYPE_GREYSCALE)
- @LuaEx
- tcod.console.setCustomFont("standard_8x8_ascii_in_col_font.bmp",tcod.LayoutAsciiInColumn);
- tcod.console.setCustomFont("32bits_8x8_ascii_in_row_font.png",tcod.LayoutAsciiInRow);
- tcod.console.setCustomFont("greyscale_8x8_tcod_font.png",tcod.LayoutTCOD + tcod.Greyscale);
- */
- static void setCustomFont(const char *fontFile, int flags=TCOD_FONT_LAYOUT_ASCII_INCOL,int nbCharHoriz=0, int nbCharVertic=0);
-
- /**
- @PageName console_map
- @PageTitle Using custom characters mapping
- @PageFather console_init
- @FuncTitle Mapping a single ASCII code to a character
- @PageDesc These functions allow you to map characters in the bitmap font to ASCII codes.
- They should be called after initializing the root console with initRoot.
- You can dynamically change the characters mapping at any time, allowing to use several fonts in the same screen.
- @Cpp static void TCODConsole::mapAsciiCodeToFont(int asciiCode, int fontCharX, int fontCharY)
- @C void TCOD_console_map_ascii_code_to_font(int asciiCode, int fontCharX, int fontCharY)
- @Py console_map_ascii_code_to_font(asciiCode, fontCharX, fontCharY)
- @C# static void TCODConsole::mapAsciiCodeToFont(int asciiCode, int fontCharX, int fontCharY)
- @Lua tcod.console.mapAsciiCodeToFont(asciiCode, fontCharX, fontCharY)
- @Param asciiCode ASCII code to map.
- @Param fontCharX,fontCharY Coordinate of the character in the bitmap font (in characters, not pixels).
- */
- static void mapAsciiCodeToFont(int asciiCode, int fontCharX, int fontCharY);
-
- /**
- @PageName console_map
- @FuncTitle Mapping consecutive ASCII codes to consecutive characters
- @Cpp static void TCODConsole::mapAsciiCodesToFont(int firstAsciiCode, int nbCodes, int fontCharX, int fontCharY)
- @C void TCOD_console_map_ascii_codes_to_font(int firstAsciiCode, int nbCodes, int fontCharX, int fontCharY)
- @Py console_map_ascii_codes_to_font(firstAsciiCode, nbCodes, fontCharX, fontCharY)
- @C# static void TCODConsole::mapAsciiCodesToFont(int firstAsciiCode, int nbCodes, int fontCharX, int fontCharY)
- @Lua tcod.console.mapAsciiCodesToFont(firstAsciiCode, nbCodes, fontCharX, fontCharY)
- @Param firstAsciiCode first ASCII code to map
- @Param nbCodes number of consecutive ASCII codes to map
- @Param fontCharX,fontCharY coordinate of the character in the bitmap font (in characters, not pixels) corresponding to the first ASCII code
- */
- static void mapAsciiCodesToFont(int firstAsciiCode, int nbCodes, int fontCharX, int fontCharY);
-
- /**
- @PageName console_map
- @FuncTitle Mapping ASCII code from a string to consecutive characters
- @Cpp static void TCODConsole::mapStringToFont(const char *s, int fontCharX, int fontCharY)
- @C void TCOD_console_map_string_to_font(const char *s, int fontCharX, int fontCharY)
- @Py console_map_string_to_font(s, fontCharX, fontCharY)
- @C# static void TCODConsole::mapStringToFont(string s, int fontCharX, int fontCharY)
- @Lua tcod.console.mapStringToFont(s, fontCharX, fontCharY)
- @Param s string containing the ASCII codes to map
- @Param fontCharX,fontCharY coordinate of the character in the bitmap font (in characters, not pixels) corresponding to the first ASCII code in the string
- */
- static void mapStringToFont(const char *s, int fontCharX, int fontCharY);
-
- /**
- @PageName console_fullscreen
- @PageTitle Fullscreen mode
- @PageFather console_init
- @FuncTitle Getting the current mode
- @FuncDesc This function returns true if the current mode is fullscreen.
- @Cpp static bool TCODConsole::isFullscreen()
- @C bool TCOD_console_is_fullscreen()
- @Py console_is_fullscreen()
- @C# static bool TCODConsole::isFullscreen()
- @Lua tcod.console.isFullscreen()
- */
- static bool isFullscreen();
- /**
- @PageName console_fullscreen
- @FuncTitle Switching between windowed and fullscreen modes
- @FuncDesc This function switches the root console to fullscreen or windowed mode.
- Note that there is no predefined key combination to switch to/from fullscreen. You have to do this in your own code.
- @Cpp static void TCODConsole::setFullscreen(bool fullscreen)
- @C void TCOD_console_set_fullscreen(bool fullscreen)
- @Py console_set_fullscreen(fullscreen)
- @C# static void TCODConsole::setFullscreen(bool fullscreen)
- @Lua tcod.console.setFullscreen(fullscreen)
- @Param fullscreen true to switch to fullscreen mode.
- false to switch to windowed mode.
- @CppEx
- TCOD_key_t key;
- TCODConsole::checkForEvent(TCOD_EVENT_KEY_PRESS,&key,NULL);
- if ( key.vk == TCODK_ENTER && key.lalt )
- TCODConsole::setFullscreen(!TCODConsole::isFullscreen());
- @CEx
- TCOD_key_t key;
- TCOD_console_check_for_event(TCOD_EVENT_KEY_PRESS,&key,NULL);
- if ( key.vk == TCODK_ENTER && key.lalt )
- TCOD_console_set_fullscreen(!TCOD_console_is_fullscreen());
- @PyEx
- key=Key()
- libtcod.console_check_for_event(libtcod.EVENT_KEY_PRESS,key,0)
- if key.vk == libtcod.KEY_ENTER and key.lalt :
- libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
- @LuaEx
- key=tcod.console.checkForKeypress()
- if key.KeyCode == tcod.Enter and key.LeftAlt then
- tcod.console.setFullscreen(not tcod.console.isFullscreen())
- end
- */
- static void setFullscreen(bool fullscreen);
-
- /**
- @PageName console_window
- @PageFather console_init
- @PageTitle Communicate with the window manager
- @FuncTitle Changing the window title
- @FuncDesc This function dynamically changes the title of the game window.
- Note that the window title is not visible while in fullscreen.
- @Cpp static void TCODConsole::setWindowTitle(const char *title)
- @C void TCOD_console_set_window_title(const char *title)
- @Py console_set_window_title(title)
- @C# static void TCODConsole::setWindowTitle(string title)
- @Lua tcod.console.setWindowTitle(title)
- @Param title New title of the game window
- */
- static void setWindowTitle(const char *title);
-
- /**
- @PageName console_window
- @FuncTitle Handling "close window" events
- @FuncDesc When you start the program, this returns false. Once a "close window" event has been sent by the window manager, it will always return true. You're supposed to exit cleanly the game.
- @Cpp static bool TCODConsole::isWindowClosed()
- @C bool TCOD_console_is_window_closed()
- @Py console_is_window_closed()
- @C# static bool TCODConsole::isWindowClosed()
- @Lua tcod.console.isWindowClosed()
- */
- static bool isWindowClosed();
-
- /**
- @PageName console_window
- @FuncTitle Check if the mouse cursor is inside the game window
- @FuncDesc Returns true if the mouse cursor is inside the game window area and the game window is the active application.
- @Cpp static bool TCODConsole::hasMouseFocus()
- @C bool TCOD_console_has_mouse_focus()
- @Py console_has_mouse_focus()
- */
- static bool hasMouseFocus();
-
- /**
- @PageName console_window
- @FuncTitle Check if the game application is active
- @FuncDesc Returns false if the game window is not the active window or is iconified.
- @Cpp static bool TCODConsole::isActive()
- @C bool TCOD_console_is_active()
- @Py console_is_active()
- */
- static bool isActive();
-
- /**
- @PageName console_credits
- @PageTitle libtcod's credits
- @PageFather console_init
- @PageDesc Use these functions to display credits, as seen in the samples.
- @FuncTitle Using a separate credit page
- @FuncDesc You can print a "Powered by libtcod x.y.z" screen during your game startup simply by calling this function after initRoot.
- The credits screen can be skipped by pressing any key.
- @Cpp static void TCODConsole::credits()
- @C void TCOD_console_credits()
- @Py console_credits()
- @C# static void TCODConsole::credits()
- @Lua tcod.console.credits()
- */
- static void credits();
-
- /**
- @PageName console_credits
- @FuncTitle Embedding credits in an existing page
- @FuncDesc You can also print the credits on one of your game screens (your main menu for example) by calling this function in your main loop.
- This function returns true when the credits screen is finished, indicating that you no longer need to call it.
- @Cpp static bool TCODConsole::renderCredits(int x, int y, bool alpha)
- @C bool TCOD_console_credits_render(int x, int y, bool alpha)
- @Py bool TCOD_console_credits_render(int x, int y, bool alpha)
- @C# static bool TCODConsole::renderCredits(int x, int y, bool alpha)
- @Lua tcod.console.renderCredits(x, y, alpha)
- @Param x,y Position of the credits text in your root console
- @Param alpha If true, credits are transparently added on top of the existing screen.
- For this to work, this function must be placed between your screen rendering code and the console flush.
- @CppEx
- TCODConsole::initRoot(80,50,"The Chronicles Of Doryen v0.1",false); // initialize the root console
- bool endCredits=false;
- while ( ! TCODConsole::isWindowClosed() ) { // your game loop
- // your game rendering here...
- // render transparent credits near the center of the screen
- if (! endCredits ) endCredits=TCODConsole::renderCredits(35,25,true);
- TCODConsole::flush();
- }
- @CEx
- TCOD_console_init_root(80,50,"The Chronicles Of Doryen v0.1",false);
- bool end_credits=false;
- while ( ! TCOD_console_is_window_closed() ) {
- // your game rendering here...
- // render transparent credits near the center of the screen
- if (! end_credits ) end_credits=TCOD_console_credits_render(35,25,true);
- TCOD_console_flush();
- }
- @PyEx
- libtcod.console_init_root(80,50,"The Chronicles Of Doryen v0.1",False)
- end_credits=False
- while not libtcod.console_is_window_closed() :
- // your game rendering here...
- // render transparent credits near the center of the screen
- if (not end_credits ) : end_credits=libtcod.console_credits_render(35,25,True)
- libtcod.console_flush()
- @LuaEx
- tcod.console.initRoot(80,50,"The Chronicles Of Doryen v0.1") -- initialize the root console
- endCredits=false
- while not tcod.console.isWindowClosed() do -- your game loop
- -- your game rendering here...
- -- render transparent credits near the center of the screen
- if not endCredits then endCredits=tcod.console.renderCredits(35,25,true) end
- tcod.console.flush()
- end
- */
- static bool renderCredits(int x, int y, bool alpha);
-
- /**
- @PageName console_credits
- @FuncTitle Restart the credits animation
- @FuncDesc When using rederCredits, you can restart the credits animation from the beginning before it's finished by calling this function.
- @Cpp static void TCODConsole::resetCredits()
- @C void TCOD_console_credits_reset()
- @Py console_credits_reset()
- @C# static void TCODConsole::resetCredits()
- @Lua tcod.console.resetCredits()
- */
- static void resetCredits();
-
- /**
- @PageName console_draw
- @PageTitle Drawing on the root console
- @PageFather console
- */
-
- /**
- @PageName console_draw_basic
- @PageTitle Basic printing functions
- @PageFather console_draw
- @FuncTitle Setting the default background color
- @FuncDesc This function changes the default background color for a console. The default background color is used by several drawing functions like clear, putChar, ...
- @Cpp void TCODConsole::setDefaultBackground(TCODColor back)
- @C void TCOD_console_set_default_background(TCOD_console_t con,TCOD_color_t back)
- @Py console_set_default_background(con,back)
- @C# void TCODConsole::setBackgroundColor(TCODColor back)
- @Lua Console:setBackgroundColor(back)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param back the new default background color for this console
- @CppEx TCODConsole::root->setDefaultBackground(myColor)
- @CEx TCOD_console_set_default_background(NULL, my_color)
- @PyEx litbcod.console_set_default_background(0, my_color)
- @Lua libtcod.TCODConsole_root:setBackgroundColor( myColor )
- */
- void setDefaultBackground(TCODColor back);
-
- /**
- @PageName console_draw_basic
- @FuncTitle Setting the default foreground color
- @FuncDesc This function changes the default foreground color for a console. The default foreground color is used by several drawing functions like clear, putChar, ...
- @Cpp void TCODConsole::setDefaultForeground(TCODColor fore)
- @C void TCOD_console_set_default_foreground(TCOD_console_t con,TCOD_color_t fore)
- @Py console_set_default_foreground(con, fore)
- @C# void TCODConsole::setForegroundColor(TCODColor fore)
- @Lua Console:setForegroundColor(fore)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param fore the new default foreground color for this console
- @CppEx TCODConsole::root->setDefaultForeground(myColor)
- @CEx TCOD_console_set_default_foreground(NULL, my_color)
- @PyEx litbcod.console_set_default_foreground(0, my_color)
- @LuaEx libtcod.TCODConsole_root:setForegroundColor( myColor )
- */
- void setDefaultForeground(TCODColor fore);
-
- /**
- @PageName console_draw_basic
- @FuncTitle Clearing a console
- @FuncDesc This function modifies all cells of a console :
- * set the cell's background color to the console default background color
- * set the cell's foreground color to the console default foreground color
- * set the cell's ASCII code to 32 (space)
- @Cpp void TCODConsole::clear()
- @C void TCOD_console_clear(TCOD_console_t con)
- @Py console_clear(con)
- @C# void TCODConsole::clear()
- @Lua Console:clear()
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- */
- void clear();
-
- /**
- @PageName console_draw_basic
- @FuncTitle Setting the background color of a cell
- @FuncDesc This function modifies the background color of a cell, leaving other properties (foreground color and ASCII code) unchanged.
- @Cpp void TCODConsole::setCharBackground(int x, int y, const TCODColor &col, TCOD_bkgnd_flag_t flag = TCOD_BKGND_SET)
- @C void TCOD_console_set_char_background(TCOD_console_t con,int x, int y, TCOD_color_t col, TCOD_bkgnd_flag_t flag)
- @Py console_set_char_background(con, x, y, col, flag=BKGND_SET)
- @C#
- void TCODConsole::setCharBackground(int x, int y, TCODColor col)
- void TCODConsole::setCharBackground(int x, int y, TCODColor col, TCODBackgroundFlag flag)
- @Lua
- Console:setCharBackground(x, y, col)
- Console:setCharBackground(x, y, col, flag)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y coordinates of the cell in the console.
- 0 <= x < console width
- 0 <= y < console height
- @Param col the background color to use. You can use color constants
- @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
- */
- void setCharBackground(int x, int y, const TCODColor &col, TCOD_bkgnd_flag_t flag = TCOD_BKGND_SET);
- /**
- @PageName console_draw_basic
- @FuncTitle Setting the foreground color of a cell
- @FuncDesc This function modifies the foreground color of a cell, leaving other properties (background color and ASCII code) unchanged.
- @Cpp void TCODConsole::setCharForeground(int x, int y, const TCODColor &col)
- @C void TCOD_console_set_char_foreground(TCOD_console_t con,int x, int y, TCOD_color_t col)
- @Py console_set_char_foreground(con, x, y, col)
- @C# void TCODConsole::setCharForeground(int x, int y, TCODColor col)
- @Lua Console:setCharForeground(x, y, col)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y coordinates of the cell in the console.
- 0 <= x < console width
- 0 <= y < console height
- @Param col the foreground color to use. You can use color constants
- */
- void setCharForeground(int x, int y, const TCODColor &col);
-
- /**
- @PageName console_draw_basic
- @FuncTitle Setting the ASCII code of a cell
- @FuncDesc This function modifies the ASCII code of a cell, leaving other properties (background and foreground colors) unchanged.
- Note that since a clear console has both background and foreground colors set to black for every cell, using setchar will produce black characters on black background. Use putchar instead.
- @Cpp void TCODConsole::setChar(int x, int y, int c)
- @C void TCOD_console_set_char(TCOD_console_t con,int x, int y, int c)
- @Py console_set_char(con, x, y, c)
- @C# void TCODConsole::setChar(int x, int y, int c)
- @Lua Console:setChar(x, y, c)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y coordinates of the cell in the console.
- 0 <= x < console width
- 0 <= y < console height
- @Param c the new ASCII code for the cell. You can use ASCII constants
- */
- void setChar(int x, int y, int c);
-
- /**
- @PageName console_draw_basic
- @FuncTitle Setting every property of a cell using default colors
- @FuncDesc This function modifies every property of a cell :
- * update the cell's background color according to the console default background color (see TCOD_bkgnd_flag_t).
- * set the cell's foreground color to the console default foreground color
- * set the cell's ASCII code to c
- @Cpp void TCODConsole::putChar(int x, int y, int c, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT)
- @C void TCOD_console_put_char(TCOD_console_t con,int x, int y, int c, TCOD_bkgnd_flag_t flag)
- @Py console_put_char( con, x, y, c, flag=BKGND_DEFAULT)
- @C#
- void TCODConsole::putChar(int x, int y, int c)
- void TCODConsole::putChar(int x, int y, int c, TCODBackgroundFlag flag)
- @Lua
- Console:putChar(x, y, c)
- Console:putChar(x, y, c, flag)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y coordinates of the cell in the console.
- 0 <= x < console width
- 0 <= y < console height
- @Param c the new ASCII code for the cell. You can use ASCII constants
- @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
- */
- void putChar(int x, int y, int c, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT);
-
- /**
- @PageName console_draw_basic
- @FuncTitle Setting every property of a cell using specific colors
- @FuncDesc This function modifies every property of a cell :
- * set the cell's background color to back.
- * set the cell's foreground color to fore.
- * set the cell's ASCII code to c.
- @Cpp void TCODConsole::putCharEx(int x, int y, int c, const TCODColor & fore, const TCODColor & back)
- @C void TCOD_console_put_char_ex(TCOD_console_t con,int x, int y, int c, TCOD_color_t fore, TCOD_color_t back)
- @Py console_put_char_ex( con, x, y, c, fore, back)
- @C# void TCODConsole::putCharEx(int x, int y, int c, TCODColor fore, TCODColor back)
- @Lua Console:putCharEx(x, y, c, fore, back)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y coordinates of the cell in the console.
- 0 <= x < console width
- 0 <= y < console height
- @Param c the new ASCII code for the cell. You can use ASCII constants
- @Param fore,back new foreground and background colors for this cell
- */
- void putCharEx(int x, int y, int c, const TCODColor &fore, const TCODColor &back);
-
- /**
- @PageName console_bkgnd_flag_t
- @PageTitle Background effect flags
- @PageFather console_draw
- @PageDesc This flag is used by most functions that modify a cell background color. It defines how the console's current background color is used to modify the cell's existing background color :
- TCOD_BKGND_NONE : the cell's background color is not modified.
- TCOD_BKGND_SET : the cell's background color is replaced by the console's default background color : newbk = curbk.
- TCOD_BKGND_MULTIPLY : the cell's background color is multiplied by the console's default background color : newbk = oldbk * curbk
- TCOD_BKGND_LIGHTEN : newbk = MAX(oldbk,curbk)
- TCOD_BKGND_DARKEN : newbk = MIN(oldbk,curbk)
- TCOD_BKGND_SCREEN : newbk = white - (white - oldbk) * (white - curbk) // inverse of multiply : (1-newbk) = (1-oldbk)*(1-curbk)
- TCOD_BKGND_COLOR_DODGE : newbk = curbk / (white - oldbk)
- TCOD_BKGND_COLOR_BURN : newbk = white - (white - oldbk) / curbk
- TCOD_BKGND_ADD : newbk = oldbk + curbk
- TCOD_BKGND_ADDALPHA(alpha) : newbk = oldbk + alpha*curbk
- TCOD_BKGND_BURN : newbk = oldbk + curbk - white
- TCOD_BKGND_OVERLAY : newbk = curbk.x <= 0.5 ? 2*curbk*oldbk : white - 2*(white-curbk)*(white-oldbk)
- TCOD_BKGND_ALPHA(alpha) : newbk = (1.0f-alpha)*oldbk + alpha*(curbk-oldbk)
- TCOD_BKGND_DEFAULT : use the console's default background flag
- Note that TCOD_BKGND_ALPHA and TCOD_BKGND_ADDALPHA are MACROS that needs a float parameter between (0.0 and 1.0). TCOD_BKGND_ALPH and TCOD_BKGND_ADDA should not be used directly (else they will have the same effect as TCOD_BKGND_NONE).
- For Python, remove TCOD_ : libtcod.BKGND_NONE
- For C# : None, Set, Multiply, Lighten, Darken, Screen, ColodDodge, ColorBurn, Add, Burn Overlay, Default
- With lua, use tcod.None, ..., tcod.Default, BUT tcod.console.Alpha(value) and tcod.console.AddAlpha(value)
- */
-
- /**
- @PageName console_print
- @PageTitle String drawing functions
- @PageFather console_draw
- @FuncTitle Setting the default background flag
- @FuncDesc This function defines the background mode (see TCOD_bkgnd_flag_t) for the console.
- This default mode is used by several functions (print, printRect, ...)
- @Cpp void TCODConsole::setBackgroundFlag(TCOD_bkgnd_flag_t flag)
- @C void TCOD_console_set_background_flag(TCOD_console_t con,TCOD_bkgnd_flag_t flag)
- @Py console_set_background_flag(con, flag)
- @C# void TCODConsole::setBackgroundFlag(TCODBackgroundFlag flag)
- @Lua Console:setBackgroundFlag(flag)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
- */
- void setBackgroundFlag(TCOD_bkgnd_flag_t flag);
-
- /**
- @PageName console_print
- @FuncTitle Getting the default background flag
- @FuncDesc This function returns the background mode (see TCOD_bkgnd_flag_t) for the console.
- This default mode is used by several functions (print, printRect, ...)
- @Cpp TCOD_bkgnd_flag_t TCODConsole::getBackgroundFlag() const
- @C TCOD_bkgnd_flag_t TCOD_console_get_background_flag(TCOD_console_t con)
- @Py console_get_background_flag(con)
- @C# TCODBackgroundFlag TCODConsole::getBackgroundFlag()
- @Lua Console:getBackgroundFlag()
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- */
- TCOD_bkgnd_flag_t getBackgroundFlag() const;
-
- /**
- @PageName console_print
- @FuncTitle Setting the default alignment
- @FuncDesc This function defines the default alignment (see TCOD_alignment_t) for the console.
- This default alignment is used by several functions (print, printRect, ...).
- Values for alignment : TCOD_LEFT, TCOD_CENTER, TCOD_RIGHT (in Python, remove TCOD_ : libtcod.LEFT).
- For C# and Lua : LeftAlignment, RightAlignment, CenterAlignment
- @Cpp void TCODConsole::setAlignment(TCOD_alignment_t alignment)
- @C void TCOD_console_set_alignment(TCOD_console_t con,TCOD_bkgnd_flag_t alignment)
- @Py console_set_alignment(con, alignment)
- @C# void TCODConsole::setAlignment(TCODAlignment alignment)
- @Lua Console:setAlignment(alignment)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param alignment defines how the strings are printed on screen.
- */
- void setAlignment(TCOD_alignment_t alignment);
-
- /**
- @PageName console_print
- @FuncTitle Getting the default alignment
- @FuncDesc This function returns the default alignment (see TCOD_alignment_t) for the console.
- This default mode is used by several functions (print, printRect, ...).
- Values for alignment : TCOD_LEFT, TCOD_CENTER, TCOD_RIGHT (in Python, remove TCOD_ : libtcod.LEFT).
- For C# and Lua : LeftAlignment, RightAlignment, CenterAlignment
- @Cpp TCOD_alignment_t TCODConsole::getAlignment() const
- @C TCOD_alignment_t TCOD_console_get_alignment(TCOD_console_t con)
- @Py console_get_alignment(con)
- @C# TCODAlignment TCODConsole::getAlignment()
- @Lua Console:getAlignment()
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- */
- TCOD_alignment_t getAlignment() const;
-
- /**
- @PageName console_print
- @FuncTitle Printing a string with default parameters
- @FuncDesc This function print a string at a specific position using current default alignment, background flag, foreground and background colors.
- @Cpp void TCODConsole::print(int x, int y, const char *fmt, ...)
- @C void TCOD_console_print(TCOD_console_t con,int x, int y, const char *fmt, ...)
- @Py console_print(con, x, y, fmt)
- @C# void TCODConsole::print(int x, int y, string fmt)
- @Lua Console:print(x, y, fmt)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y coordinate of the character in the console, depending on the default alignment for this console :
- * TCOD_LEFT : leftmost character of the string
- * TCOD_CENTER : center character of the string
- * TCOD_RIGHT : rightmost character of the string
- @Param fmt printf-like format string, eventually followed by parameters. You can use control codes to change the colors inside the string, except in C#.
- */
- void print(int x, int y, const char *fmt, ...);
-
- /**
- @PageName console_print
- @FuncTitle Printing a string with specific alignment and background mode
- @FuncDesc This function print a string at a specific position using specific alignment and background flag, but default foreground and background colors.
- @Cpp void TCODConsole::printEx(int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, ...)
- @C void TCOD_console_print_ex(TCOD_console_t con,int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, ...)
- @Py console_print_ex(con, x, y, flag, alignment, fmt)
- @C# void TCODConsole::printEx(int x, int y, TCODBackgroundFlag flag, TCODAlignment alignment, string fmt)
- @Lua Console::printEx(x, y, flag, alignment, fmt)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y coordinate of the character in the console, depending on the alignment :
- * TCOD_LEFT : leftmost character of the string
- * TCOD_CENTER : center character of the string
- * TCOD_RIGHT : rightmost character of the string
- @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
- @Param alignment defines how the strings are printed on screen.
- @Param fmt printf-like format string, eventually followed by parameters. You can use control codes to change the colors inside the string, except in C#.
- */
- void printEx(int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, ...);
-
- /**
- @PageName console_print
- @FuncTitle Printing a string with default parameters and autowrap
- @FuncDesc This function draws a string in a rectangle inside the console, using default colors, alignment and background mode.
- If the string reaches the borders of the rectangle, carriage returns are inserted.
- If h > 0 and the bottom of the rectangle is reached, the string is truncated. If h = 0, the string is only truncated if it reaches the bottom of the console.
- The function returns the height (number of console lines) of the printed string.
- @Cpp int TCODConsole::printRect(int x, int y, int w, int h, const char *fmt, ...)
- @C int TCOD_console_print_rect(TCOD_console_t con,int x, int y, int w, int h, const char *fmt, ...)
- @Py console_print_rect(con, x, y, w, h, fmt)
- @C# int TCODConsole::printRect(int x, int y, int w, int h, string fmt)
- @Lua Console:printRect(x, y, w, h, fmt)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y coordinate of the character in the console, depending on the alignment :
- * TCOD_LEFT : leftmost character of the string
- * TCOD_CENTER : center character of the string
- * TCOD_RIGHT : rightmost character of the string
- @Param w,h size of the rectangle
- x <= x+w < console width
- y <= y+h < console height
- @Param fmt printf-like format string, eventually followed by parameters. You can use control codes to change the colors inside the string, except in C#.
- */
- int printRect(int x, int y, int w, int h, const char *fmt, ...);
-
- /**
- @PageName console_print
- @FuncTitle Printing a string with specific alignment and background mode and autowrap
- @FuncDesc This function draws a string in a rectangle inside the console, using default colors, but specific alignment and background mode.
- If the string reaches the borders of the rectangle, carriage returns are inserted.
- If h > 0 and the bottom of the rectangle is reached, the string is truncated. If h = 0, the string is only truncated if it reaches the bottom of the console.
- The function returns the height (number of console lines) of the printed string.
- @Cpp int TCODConsole::printRectEx(int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, ...)
- @C int TCOD_console_print_rect_ex(TCOD_console_t con,int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, ...)
- @Py console_print_rect_ex(con, x, y, w, h, flag, alignment, fmt)
- @C# int TCODConsole::printRectEx(int x, int y, int w, int h, TCODBackgroundFlag flag, TCODAlignment alignment, string fmt)
- @Lua Console:printRectEx(x, y, w, h, flag, alignment, fmt)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y coordinate of the character in the console, depending on the alignment :
- * TCOD_LEFT : leftmost character of the string
- * TCOD_CENTER : center character of the string
- * TCOD_RIGHT : rightmost character of the string
- @Param w,h size of the rectangle
- x <= x+w < console width
- y <= y+h < console height
- @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
- @Param alignment defines how the strings are printed on screen.
- @Param fmt printf-like format string, eventually followed by parameters. You can use control codes to change the colors inside the string, except in C#.
- */
- int printRectEx(int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, ...);
-
- /**
- @PageName console_print
- @FuncTitle Compute the height of an autowrapped string
- @FuncDesc This function returns the expected height of an autowrapped string without actually printing the string with printRect or printRectEx
- @Cpp int TCODConsole::getHeightRect(int x, int y, int w, int h, const char *fmt, ...)
-
- @C int TCOD_console_get_height_rect(TCOD_console_t con,int x, int y, int w, int h, const char *fmt, ...)
- @Py console_get_height_rect(con, x, y, w, h, fmt)
- @C# int TCODConsole::getHeightRect(int x, int y, int w, int h, string fmt)
- @Lua Console:getHeightRect(x, y, w, h, fmt)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y coordinate of the rectangle upper-left corner in the console
- @Param w,h size of the rectangle
- x <= x+w < console width
- y <= y+h < console height
- @Param fmt printf-like format string, eventually followed by parameters. You can use control codes to change the colors inside the string, except in C#.
- */
- int getHeightRect(int x, int y, int w, int h, const char *fmt, ...);
-
- /**
- @PageName console_print
- @FuncTitle Changing the colors while printing a string
- @FuncDesc If you want to draw a string using different colors for each word, the basic solution is to call a string printing function several times, changing the default colors between each call.
- The TCOD library offers a simpler way to do this, allowing you to draw a string using different colors in a single call. For this, you have to insert color control codes in your string.
- A color control code is associated with a color set (a foreground color and a background color). If you insert this code in your string, the next characters will use the colors associated with the color control code.
- There are 5 predefined color control codes :
- For Python, remove TCOD_ : libtcod.COLCTRL_1
- TCOD_COLCTRL_1
- TCOD_COLCTRL_2
- TCOD_COLCTRL_3
- TCOD_COLCTRL_4
- TCOD_COLCTRL_5
- To associate a color with a code, use setColorControl.
- To go back to the console's default colors, insert in your string the color stop control code :
- TCOD_COLCTRL_STOP
-
- You can also use any color without assigning it to a control code, using the generic control codes :
- TCOD_COLCTRL_FORE_RGB
- TCOD_COLCTRL_BACK_RGB
-
- Those controls respectively change the foreground and background color used to print the string characters. In the string, you must insert the r,g,b components of the color (between 1 and 255. The value 0 is forbidden because it represents the end of the string in C/C++) immediately after this code.
- @Cpp static void TCODConsole::setColorControl(TCOD_colctrl_t con, const TCODColor &fore, const TCODColor &back)
- @C void TCOD_console_set_color_control(TCOD_colctrl_t con, TCOD_color_t fore, TCOD_color_t back)
- @Py console_set_color_control(con,fore,back)
- @C# Not supported directly, use getRGBColorControlString and getColorControlString.
- @Lua Not supported
- @Param con the color control TCOD_COLCTRL_x, 1<=x<=5
- @Param fore foreground color when this control is activated
- @Param back background color when this control is activated
- @CppEx
- // A string with a red over black word, using predefined color control codes
- TCODConsole::setColorControl(TCOD_COLCTRL_1,TCODColor::red,TCODColor::black);
- TCODConsole::root->print(1,1,"String with a %cred%c word.",TCOD_COLCTRL_1,TCOD_COLCTRL_STOP);
- // A string with a red over black word, using generic color control codes
- TCODConsole::root->print(1,1,"String with a %c%c%c%c%c%c%c%cred%c word.",
- TCOD_COLCTRL_FORE_RGB,255,1,1,TCOD_COLCTRL_BACK_RGB,1,1,1,TCOD_COLCTRL_STOP);
- // A string with a red over black word, using generic color control codes
- TCODConsole::root->print(1,1,"String with a %c%c%c%c%c%c%c%cred%c word.",
- TCOD_COLCTRL_FORE_RGB,255,1,1,TCOD_COLCTRL_BACK_RGB,1,1,1,TCOD_COLCTRL_STOP);
- @CEx
- // A string with a red over black word, using predefined color control codes
- TCOD_console_set_color_control(TCOD_COLCTRL_1,red,black);
- TCOD_console_print(NULL,1,1,"String with a %cred%c word.",TCOD_COLCTRL_1,TCOD_COLCTRL_STOP);
- // A string with a red word (over default background color), using generic color control codes
- TCOD_console_print(NULL,1,1,"String with a %c%c%c%cred%c word.",
- TCOD_COLCTRL_FORE_RGB,255,1,1,TCOD_COLCTRL_STOP);
- // A string with a red over black word, using generic color control codes
- TCOD_console_print(NULL,1,1,"String with a %c%c%c%c%c%c%c%cred%c word.",
- TCOD_COLCTRL_FORE_RGB,255,1,1,TCOD_COLCTRL_BACK_RGB,1,1,1,TCOD_COLCTRL_STOP);
- @PyEx
- # A string with a red over black word, using predefined color control codes
- libtcod.console_set_color_control(libtcod.COLCTRL_1,litbcod.red,litbcod.black)
- libtcod.console_print(0,1,1,"String with a %cred%c word."%(libtcod.COLCTRL_1,libtcod.COLCTRL_STOP))
- # A string with a red word (over default background color), using generic color control codes
- litbcod.console_print(0,1,1,"String with a %c%c%c%cred%c word."%(libtcod.COLCTRL_FORE_RGB,255,1,1,libtcod.COLCTRL_STOP))
- # A string with a red over black word, using generic color control codes
- libtcod.console_print(0,1,1,"String with a %c%c%c%c%c%c%c%cred%c word."%
- (libtcod.COLCTRL_FORE_RGB,255,1,1,libtcod.COLCTRL_BACK_RGB,1,1,1,libtcod.COLCTRL_STOP))
-
- @C#Ex
- TCODConsole.root.print(1,1,String.Format("String with a {0}red{1} word.",
- TCODConsole.getRGBColorControlString(ColorControlForeground,TCODColor.red),
- TCODConsole.getColorControlString(ColorControlStop));
- */
- static void setColorControl(TCOD_colctrl_t con, const TCODColor &fore, const TCODColor &back);
-
-#ifndef NO_UNICODE
- /**
- @PageName console_print
- @FuncTitle Unicode functions
- @FuncDesc those functions are similar to their ASCII equivalent, but work with unicode strings (wchar_t in C/C++).
- Note that unicode is not supported in the Python wrapper.
- @Cpp static void TCODConsole::mapStringToFont(const wchar_t *s, int fontCharX, int fontCharY)
- @C void TCOD_console_map_string_to_font_utf(const wchar_t *s, int fontCharX, int fontCharY)
- */
- static void mapStringToFont(const wchar_t *s, int fontCharX, int fontCharY);
- /**
- @PageName console_print
- @Cpp void TCODConsole::print(int x, int y, const wchar_t *fmt, ...)
- @C void TCOD_console_print_utf(TCOD_console_t con,int x, int y, const wchar_t *fmt, ...)
- */
- void print(int x, int y, const wchar_t *fmt, ...);
- /**
- @PageName console_print
- @Cpp void TCODConsole::printEx(int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...)
- @C void TCOD_console_print_ex_utf(TCOD_console_t con,int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...)
- */
- void printEx(int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...);
- /**
- @PageName console_print
- @Cpp int TCODConsole::printRect(int x, int y, int w, int h, const wchar_t *fmt, ...)
- @C int TCOD_console_print_rect_utf(TCOD_console_t con,int x, int y, int w, int h, const wchar_t *fmt, ...)
- */
- int printRect(int x, int y, int w, int h, const wchar_t *fmt, ...);
-
- /**
- @PageName console_print
- @Cpp int TCODConsole::printRectEx(int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...)
- @C int TCOD_console_print_rect_ex_utf(TCOD_console_t con,int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...)
- */
- int printRectEx(int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...);
-
- /**
- @PageName console_print
- @Cpp int TCODConsole::getHeightRect(int x, int y, int w, int h, const wchar_t *fmt, ...)
- @C int TCOD_console_get_height_rect_utf(TCOD_console_t con,int x, int y, int w, int h, const wchar_t *fmt, ...)
- */
- int getHeightRect(int x, int y, int w, int h, const wchar_t *fmt, ...);
-#endif
-
- /**
- @PageName console_advanced
- @PageFather console_draw
- @PageTitle Advanced printing functions
- @FuncTitle Filling a rectangle with the background color
- @FuncDesc Fill a rectangle inside a console. For each cell in the rectangle :
- * set the cell's background color to the console default background color
- * if clear is true, set the cell's ASCII code to 32 (space)
- @Cpp void TCODConsole::rect(int x, int y, int w, int h, bool clear, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT)
- @C void TCOD_console_rect(TCOD_console_t con,int x, int y, int w, int h, bool clear, TCOD_bkgnd_flag_t flag)
- @Py console_rect(con,x, y, w, h, clear, flag=BKGND_DEFAULT)
- @C#
- void TCODConsole::rect(int x, int y, int w, int h, bool clear)
- void TCODConsole::rect(int x, int y, int w, int h, bool clear, TCODBackgroundFlag flag)
- @Lua
- Console:rect(x, y, w, h, clear)
- Console:rect(x, y, w, h, clear, flag)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y coordinates of rectangle upper-left corner in the console.
- 0 <= x < console width
- 0 <= y < console height
- @Param w,h size of the rectangle in the console.
- x <= x+w < console width
- y <= y+h < console height
- @Param clear if true, all characters inside the rectangle are set to ASCII code 32 (space).
- If false, only the background color is modified
- @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
- */
- void rect(int x, int y, int w, int h, bool clear, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT);
-
- /**
- @PageName console_advanced
- @FuncTitle Drawing an horizontal line
- @FuncDesc Draws an horizontal line in the console, using ASCII code TCOD_CHAR_HLINE (196), and the console's default background/foreground colors.
- @Cpp void TCODConsole::hline(int x,int y, int l, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT)
- @C void TCOD_console_hline(TCOD_console_t con,int x,int y, int l, TCOD_bkgnd_flag_t flag)
- @Py console_hline(con,x,y,l,flag=BKGND_DEFAULT)
- @C#
- void TCODConsole::hline(int x,int y, int l)
- void TCODConsole::hline(int x,int y, int l, TCODBackgroundFlag flag)
- @Lua
- Console:hline(x,y, l)
- Console:hline(x,y, l, flag)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y Coordinates of the line's left end in the console.
- 0 <= x < console width
- 0 <= y < console height
- @Param l The length of the line in cells 1 <= l <= console width - x
- @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
- */
- void hline(int x,int y, int l, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT);
-
- /**
- @PageName console_advanced
- @FuncTitle Drawing an vertical line
- @FuncDesc Draws an vertical line in the console, using ASCII code TCOD_CHAR_VLINE (179), and the console's default background/foreground colors.
- @Cpp void TCODConsole::vline(int x,int y, int l, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT)
- @C void TCOD_console_vline(TCOD_console_t con,int x,int y, int l, TCOD_bkgnd_flag_t flag)
- @Py console_vline(con,x,y,l,flag=BKGND_DEFAULT)
- @C#
- void TCODConsole::vline(int x,int y, int l)
- void TCODConsole::vline(int x,int y, int l, TCODBackgroundFlag flag)
- @Lua
- Console:vline(x,y, l)
- Console:vline(x,y, l, flag)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y Coordinates of the line's upper end in the console.
- 0 <= x < console width
- 0 <= y < console height
- @Param l The length of the line in cells 1 <= l <= console height - y
- @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
- */
- void vline(int x,int y, int l, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT);
-
- /**
- @PageName console_advanced
- @FuncTitle Drawing a window frame
- @FuncDesc This function calls the rect function using the supplied background mode flag, then draws a rectangle with the console's default foreground color. If fmt is not NULL, it is printed on the top of the rectangle, using inverted colors.
- @Cpp void TCODConsole::printFrame(int x,int y,int w,int h, bool clear=true, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT, const char *fmt=NULL, ...)
- @C void TCOD_console_print_frame(TCOD_console_t con,int x,int y,int w,int h, bool clear, TCOD_bkgnd_flag_t flag, const char *fmt, ...)
- @Py console_print_frame(con,x, y, w, h, clear=True, flag=BKGND_DEFAULT, fmt=0)
- @C#
- void TCODConsole::printFrame(int x,int y, int w,int h)
- void TCODConsole::printFrame(int x,int y, int w,int h, bool clear)
- void TCODConsole::printFrame(int x,int y, int w,int h, bool clear, TCODBackgroundFlag flag)
- void TCODConsole::printFrame(int x,int y, int w,int h, bool clear, TCODBackgroundFlag flag, string fmt)
- @Lua
- Console:printFrame(x,y, w,h)
- Console:printFrame(x,y, w,h, clear)
- Console:printFrame(x,y, w,h, clear, flag)
- Console:printFrame(x,y, w,h, clear, flag, fmt)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y Coordinates of the rectangle's upper-left corner in the console.
- 0 <= x < console width
- 0 <= y < console height
- @Param w,h size of the rectangle in the console.
- x <= x+w < console width
- y <= y+h < console height
- @Param clear if true, all characters inside the rectangle are set to ASCII code 32 (space).
- If false, only the background color is modified
- @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
- @Param fmt if NULL, the function only draws a rectangle.
- Else, printf-like format string, eventually followed by parameters. You can use control codes to change the colors inside the string.
- */
- void printFrame(int x,int y,int w,int h, bool clear=true, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT, const char *fmt=NULL, ...);
-
- /**
- @PageName console_advanced
- @FuncTitle Manipulating foreground colors as an image
- @FuncDesc This function obtains the image containing the console foreground colors.
- @Cpp TCODImage *TCODConsole::getForegroundImage()
- @C TCOD_image_t TCOD_console_get_foreground_color_image(TCOD_console_t con)
- @Py console_get_foreground_image(con)
- */
- TCODImage *getForegroundColorImage();
-
- /**
- @PageName console_advanced
- @FuncTitle Manipulating background colors as an image
- @FuncDesc This function obtains the image containing the console background colors.
- @Cpp TCODImage *TCODConsole::getBackgroundImage()
- @C TCOD_image_t TCOD_console_get_background_color_image(TCOD_console_t con)
- @Py console_get_background_image(con)
- */
- TCODImage *getBackgroundColorImage();
-
- /**
- @PageName console_read
- @PageTitle Reading the content of the console
- @PageFather console_draw
- @FuncTitle Get the console's width
- @FuncDesc This function returns the width of a console (either the root console or an offscreen console)
- @Cpp int TCODConsole::getWidth() const
- @C int TCOD_console_get_width(TCOD_console_t con)
- @Py console_get_width(con)
- @C# int TCODConsole::getWidth()
- @Lua Console:getWidth()
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- */
- int getWidth() const;
-
- /**
- @PageName console_read
- @FuncTitle Get the console's height
- @FuncDesc This function returns the height of a console (either the root console or an offscreen console)
- @Cpp int TCODConsole::getHeight() const
- @C int TCOD_console_get_height(TCOD_console_t con)
- @Py console_get_height(con)
- @C# int TCODConsole::getHeight()
- @Lua Console:getHeight()
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- */
- int getHeight() const;
-
- /**
- @PageName console_read
- @FuncTitle Reading the default background color
- @FuncDesc This function returns the default background color of a console.
- @Cpp TCODColor TCODConsole::getDefaultBackground() const
- @C TCOD_color_t TCOD_console_get_default_background(TCOD_console_t con)
- @Py console_get_default_background(con)
- @C# TCODColor TCODConsole::getBackgroundColor()
- @Lua Console:getBackgroundColor()
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- */
- TCODColor getDefaultBackground() const;
-
- /**
- @PageName console_read
- @FuncTitle Reading the default foreground color
- @FuncDesc This function returns the default foreground color of a console.
- @Cpp TCODColor TCODConsole::getDefaultForeground() const
- @C TCOD_color_t TCOD_console_get_default_foreground(TCOD_console_t con)
- @Py console_get_default_foreground(con)
- @C# TCODColor TCODConsole::getForegroundColor()
- @Lua Console:getForegroundColor()
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- */
- TCODColor getDefaultForeground() const;
-
- /**
- @PageName console_read
- @FuncTitle Reading the background color of a cell
- @FuncDesc This function returns the background color of a cell.
- @Cpp TCODColor TCODConsole::getCharBackground(int x, int y) const
- @C TCOD_color_t TCOD_console_get_char_background(TCOD_console_t con,int x, int y)
- @Py console_get_char_background(con,x,y)
- @C# TCODColor TCODConsole::getCharBackground(int x, int y)
- @Lua Console::getCharBackground(x, y)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y coordinates of the cell in the console.
- 0 <= x < console width
- 0 <= y < console height
- */
- TCODColor getCharBackground(int x, int y) const;
-
- /**
- @PageName console_read
- @FuncTitle Reading the foreground color of a cell
- @FuncDesc This function returns the foreground color of a cell.
- @Cpp TCODColor TCODConsole::getCharForeground(int x, int y) const
- @C TCOD_color_t TCOD_console_get_char_foreground(TCOD_console_t con,int x, int y)
- @Py console_get_char_foreground(con,x,y)
- @C# TCODColor TCODConsole::getCharForeground(int x, int y)
- @Lua Console::getCharForeground(x, y)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y coordinates of the cell in the console.
- 0 <= x < console width
- 0 <= y < console height
- */
- TCODColor getCharForeground(int x, int y) const;
-
- /**
- @PageName console_read
- @FuncTitle Reading the ASCII code of a cell
- @FuncDesc This function returns the ASCII code of a cell.
- @Cpp int TCODConsole::getChar(int x, int y) const
- @C int TCOD_console_get_char(TCOD_console_t con,int x, int y)
- @Py console_get_char(con,x,y)
- @C# int TCODConsole::getChar(int x, int y)
- @Lua Console::getChar(x, y)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param x,y coordinates of the cell in the console.
- 0 <= x < console width
- 0 <= y < console height
- */
- int getChar(int x, int y) const;
-
- /**
- @PageName console_fading
- @PageTitle Screen fading functions
- @PageFather console_draw
- @PageDesc Use these functions to easily fade to/from a color
- @FuncTitle Changing the fading parameters
- @FuncDesc This function defines the fading parameters, allowing to easily fade the game screen to/from a color. Once they are defined, the fading parameters are valid for ever. You don't have to call setFade for each rendered frame (unless you change the fading parameters).
- @Cpp static void TCODConsole::setFade(uint8_t fade, const TCODColor &fadingColor)
- @C void TCOD_console_set_fade(uint8_t fade, TCOD_color_t fadingColor)
- @Py console_set_fade(fade, fadingColor)
- @C# static void TCODConsole::setFade(byte fade, TCODColor fadingColor)
- @Lua tcod.console.setFade(fade, fadingColor)
- @Param fade the fading amount. 0 => the screen is filled with the fading color. 255 => no fading effect
- @Param fadingColor the color to use during the console flushing operation
- @CppEx
- for (int fade=255; fade >= 0; fade --) {
- TCODConsole::setFade(fade,TCODColor::black);
- TCODConsole::flush();
- }
- @CEx
- int fade;
- for (fade=255; fade >= 0; fade --) {
- TCOD_console_setFade(fade,TCOD_black);
- TCOD_console_flush();
- }
- @PyEx
- for fade in range(255,0) :
- libtcod.console_setFade(fade,libtcod.black)
- libtcod.console_flush()
- @LuaEx
- for fade=255,0,-1 do
- tcod.console.setFade(fade,tcod.color.black)
- tcod.console.flush()
- end
- */
- static void setFade(uint8_t fade, const TCODColor &fadingColor);
-
- /**
- @PageName console_fading
- @FuncTitle Reading the fade amount
- @FuncDesc This function returns the current fade amount, previously defined by setFade.
- @Cpp static uint8_t TCODConsole::getFade()
- @C uint8_t TCOD_console_get_fade()
- @Py console_get_fade()
- @C# static byte TCODConsole::getFade()
- @Lua tcod.console.getFade()
- */
- static uint8_t getFade();
-
- /**
- @PageName console_fading
- @FuncTitle Reading the fading color
- @FuncDesc This function returns the current fading color, previously defined by setFade.
- @Cpp static TCODColor TCODConsole::getFadingColor()
- @C TCOD_color_t TCOD_console_get_fading_color()
- @Py console_get_fading_color()
- @C# static TCODColor TCODConsole::getFadingColor()
- @Lua tcod.console.getFadingColor()
- */
- static TCODColor getFadingColor();
-
- /**
- @PageName console_flush
- @PageFather console
- @PageTitle Flushing the root console
- @FuncDesc Once the root console is initialized, you can use one of the printing functions to change the background colors, the foreground colors or the ASCII characters on the console.
- Once you've finished rendering the root console, you have to actually apply the updates to the screen with this function.
- @Cpp static void TCODConsole::flush()
- @C void TCOD_console_flush()
- @Py console_flush()
- @C# static void TCODConsole::flush()
- @Lua tcod.console.flush()
- */
- static void flush();
-
- /**
- @PageName console_ascii
- @PageTitle ASCII constants
- @PageFather console_draw
- @FuncDesc Some useful graphic characters in the terminal.bmp font. For the Python version, remove TCOD_ from the constants. C# and Lua is in parenthesis :
- Single line walls:
- TCOD_CHAR_HLINE=196 (HorzLine)
- TCOD_CHAR_VLINE=179 (VertLine)
- TCOD_CHAR_NE=191 (NE)
- TCOD_CHAR_NW=218 (NW)
- TCOD_CHAR_SE=217 (SE)
- TCOD_CHAR_SW=192 (SW)
-
- Double lines walls:
- TCOD_CHAR_DHLINE=205 (DoubleHorzLine)
- TCOD_CHAR_DVLINE=186 (DoubleVertLine)
- TCOD_CHAR_DNE=187 (DoubleNE)
- TCOD_CHAR_DNW=201 (DoubleNW)
- TCOD_CHAR_DSE=188 (DoubleSE)
- TCOD_CHAR_DSW=200 (DoubleSW)
-
- Single line vertical/horizontal junctions (T junctions):
- TCOD_CHAR_TEEW=180 (TeeWest)
- TCOD_CHAR_TEEE=195 (TeeEast)
- TCOD_CHAR_TEEN=193 (TeeNorth)
- TCOD_CHAR_TEES=194 (TeeSouth)
-
- Double line vertical/horizontal junctions (T junctions):
- TCOD_CHAR_DTEEW=185 (DoubleTeeWest)
- TCOD_CHAR_DTEEE=204 (DoubleTeeEast)
- TCOD_CHAR_DTEEN=202 (DoubleTeeNorth)
- TCOD_CHAR_DTEES=203 (DoubleTeeSouth)
-
- Block characters:
- TCOD_CHAR_BLOCK1=176 (Block1)
- TCOD_CHAR_BLOCK2=177 (Block2)
- TCOD_CHAR_BLOCK3=178 (Block3)
-
- Cross-junction between two single line walls:
- TCOD_CHAR_CROSS=197 (Cross)
-
- Arrows:
- TCOD_CHAR_ARROW_N=24 (ArrowNorth)
- TCOD_CHAR_ARROW_S=25 (ArrowSouth)
- TCOD_CHAR_ARROW_E=26 (ArrowEast)
- TCOD_CHAR_ARROW_W=27 (ArrowWest)
-
- Arrows without tail:
- TCOD_CHAR_ARROW2_N=30 (ArrowNorthNoTail)
- TCOD_CHAR_ARROW2_S=31 (ArrowSouthNoTail)
- TCOD_CHAR_ARROW2_E=16 (ArrowEastNoTail)
- TCOD_CHAR_ARROW2_W=17 (ArrowWestNoTail)
-
- Double arrows:
- TCOD_CHAR_DARROW_H=29 (DoubleArrowHorz)
- TCOD_CHAR_ARROW_V=18 (DoubleArrowVert)
-
- GUI stuff:
- TCOD_CHAR_CHECKBOX_UNSET=224
- TCOD_CHAR_CHECKBOX_SET=225
- TCOD_CHAR_RADIO_UNSET=9
- TCOD_CHAR_RADIO_SET=10
-
- Sub-pixel resolution kit:
- TCOD_CHAR_SUBP_NW=226 (SubpixelNorthWest)
- TCOD_CHAR_SUBP_NE=227 (SubpixelNorthEast)
- TCOD_CHAR_SUBP_N=228 (SubpixelNorth)
- TCOD_CHAR_SUBP_SE=229 (SubpixelSouthEast)
- TCOD_CHAR_SUBP_DIAG=230 (SubpixelDiagonal)
- TCOD_CHAR_SUBP_E=231 (SubpixelEast)
- TCOD_CHAR_SUBP_SW=232 (SubpixelSouthWest)
-
- Miscellaneous characters:
- TCOD_CHAR_SMILY = 1 (Smilie)
- TCOD_CHAR_SMILY_INV = 2 (SmilieInv)
- TCOD_CHAR_HEART = 3 (Heart)
- TCOD_CHAR_DIAMOND = 4 (Diamond)
- TCOD_CHAR_CLUB = 5 (Club)
- TCOD_CHAR_SPADE = 6 (Spade)
- TCOD_CHAR_BULLET = 7 (Bullet)
- TCOD_CHAR_BULLET_INV = 8 (BulletInv)
- TCOD_CHAR_MALE = 11 (Male)
- TCOD_CHAR_FEMALE = 12 (Female)
- TCOD_CHAR_NOTE = 13 (Note)
- TCOD_CHAR_NOTE_DOUBLE = 14 (NoteDouble)
- TCOD_CHAR_LIGHT = 15 (Light)
- TCOD_CHAR_EXCLAM_DOUBLE = 19 (ExclamationDouble)
- TCOD_CHAR_PILCROW = 20 (Pilcrow)
- TCOD_CHAR_SECTION = 21 (Section)
- TCOD_CHAR_POUND = 156 (Pound)
- TCOD_CHAR_MULTIPLICATION = 158 (Multiplication)
- TCOD_CHAR_FUNCTION = 159 (Function)
- TCOD_CHAR_RESERVED = 169 (Reserved)
- TCOD_CHAR_HALF = 171 (Half)
- TCOD_CHAR_ONE_QUARTER = 172 (OneQuarter)
- TCOD_CHAR_COPYRIGHT = 184 (Copyright)
- TCOD_CHAR_CENT = 189 (Cent)
- TCOD_CHAR_YEN = 190 (Yen)
- TCOD_CHAR_CURRENCY = 207 (Currency)
- TCOD_CHAR_THREE_QUARTERS = 243 (ThreeQuarters)
- TCOD_CHAR_DIVISION = 246 (Division)
- TCOD_CHAR_GRADE = 248 (Grade)
- TCOD_CHAR_UMLAUT = 249 (Umlaut)
- TCOD_CHAR_POW1 = 251 (Pow1)
- TCOD_CHAR_POW3 = 252 (Pow2)
- TCOD_CHAR_POW2 = 253 (Pow3)
- TCOD_CHAR_BULLET_SQUARE = 254 (BulletSquare)
- */
-
- /**
- @PageName console_input
- @PageTitle Handling user input
- @PageDesc The user handling functions allow you to get keyboard and mouse input from the user, either for turn by turn games (the function wait until the user press a key or a mouse button), or real time games (non blocking function).
- WARNING : those functions also handle screen redraw event, so TCODConsole::flush function won't redraw screen if no user input function is called !
- @PageFather console
- */
-
- /* deprecated as of 1.5.1 */
- static TCOD_key_t waitForKeypress(bool flush);
- /* deprecated as of 1.5.1 */
- static TCOD_key_t checkForKeypress(int flags=TCOD_KEY_RELEASED);
-
- /**
- @PageName console_blocking_input
- @PageCategory Core
- @PageFather console_input
- @PageTitle Blocking user input
- @PageDesc This function stops the application until an event occurs.
- */
-
- /**
- @PageName console_non_blocking_input
- @PageTitle Non blocking user input
- @PageFather console_input
- @FuncDesc The preferred way to check for user input is to use checkForEvent below, but you can also get the status of any special key at any time with :
- @Cpp static bool TCODConsole::isKeyPressed(TCOD_keycode_t key)
- @C bool TCOD_console_is_key_pressed(TCOD_keycode_t key)
- @Py console_is_key_pressed(key)
- @C# static bool TCODConsole::isKeyPressed(TCODKeyCode key)
- @Lua tcod.console.isKeyPressed(key)
- @Param key Any key code defined in keycode_t except TCODK_CHAR (Char) and TCODK_NONE (NoKey)
- */
- static bool isKeyPressed(TCOD_keycode_t key);
-
- /**
- @PageName console_key_t
- @PageTitle Keyboard event structure
- @PageFather console_input
- @PageDesc This structure contains information about a key pressed/released by the user.
- @C
- typedef struct {
- TCOD_keycode_t vk;
- char c;
- char text[32];
- bool pressed;
- bool lalt;
- bool lctrl;
- bool lmeta;
- bool ralt;
- bool rctrl;
- bool rmeta;
- bool shift;
- } TCOD_key_t;
- @Lua
- key.KeyCode
- key.Character
- key.Text
- key.Pressed
- key.LeftAlt
- key.LeftControl
- key.LeftMeta
- key.RightAlt
- key.RightControl
- key.RightMeta
- key.Shift
- @Param vk An arbitrary value representing the physical key on the keyboard. Possible values are stored in the TCOD_keycode_t enum. If no key was pressed, the value is TCODK_NONE
- @Param c If the key correspond to a printable character, the character is stored in this field. Else, this field contains 0.
- @Param text If vk is TCODK_TEXT, this will contain the text entered by the user.
- @Param pressed true if the event is a key pressed, or false for a key released.
- @Param lalt This field represents the status of the left Alt key : true => pressed, false => released.
- @Param lctrl This field represents the status of the left Control key : true => pressed, false => released.
- @Param lmeta This field represents the status of the left Meta (Windows/Command/..) key : true => pressed, false => released.
- @Param ralt This field represents the status of the right Alt key : true => pressed, false => released.
- @Param rctrl This field represents the status of the right Control key : true => pressed, false => released.
- @Param rmeta This field represents the status of the right Meta (Windows/Command/..) key : true => pressed, false => released.
- @Param shift This field represents the status of the shift key : true => pressed, false => released.
- */
-
- /**
- @PageName console_mouse_t
- @PageTitle Mouse event structure
- @PageFather console_input
- @PageDesc This structure contains information about a mouse move/press/release event.
- @C
- typedef struct {
- int x,y;
- int dx,dy;
- int cx,cy;
- int dcx,dcy;
- bool lbutton;
- bool rbutton;
- bool mbutton;
- bool lbutton_pressed;
- bool rbutton_pressed;
- bool mbutton_pressed;
- bool wheel_up;
- bool wheel_down;
- } TCOD_mouse_t;
- @Param x,y Absolute position of the mouse cursor in pixels relative to the window top-left corner.
- @Param dx,dy Movement of the mouse cursor since the last call in pixels.
- @Param cx,cy Coordinates of the console cell under the mouse cursor (pixel coordinates divided by the font size).
- @Param dcx,dcy Movement of the mouse since the last call in console cells (pixel coordinates divided by the font size).
- @Param lbutton true if the left button is pressed.
- @Param rbutton true if the right button is pressed.
- @Param mbutton true if the middle button (or the wheel) is pressed.
- @Param lbutton_pressed true if the left button was pressed and released.
- @Param rbutton_pressed true if the right button was pressed and released.
- @Param mbutton_pressed true if the middle button was pressed and released.
- @Param wheel_up true if the wheel was rolled up.
- @Param wheel_down true if the wheel was rolled down.
- */
-
- /**
- @PageName console_keycode_t
- @PageTitle Key codes
- @PageFather console_input
- @PageDesc TCOD_keycode_t is a libtcod specific code representing a key on the keyboard.
- For Python, replace TCODK by KEY: libtcod.KEY_NONE. C# and Lua, the value is in parenthesis. Possible values are :
- When no key was pressed (see checkForEvent) : TCOD_NONE (NoKey)
- Special keys :
- TCODK_ESCAPE (Escape)
- TCODK_BACKSPACE (Backspace)
- TCODK_TAB (Tab)
- TCODK_ENTER (Enter)
- TCODK_SHIFT (Shift)
- TCODK_CONTROL (Control)
- TCODK_ALT (Alt)
- TCODK_PAUSE (Pause)
- TCODK_CAPSLOCK (CapsLock)
- TCODK_PAGEUP (PageUp)
- TCODK_PAGEDOWN (PageDown)
- TCODK_END (End)
- TCODK_HOME (Home)
- TCODK_UP (Up)
- TCODK_LEFT (Left)
- TCODK_RIGHT (Right)
- TCODK_DOWN (Down)
- TCODK_PRINTSCREEN (Printscreen)
- TCODK_INSERT (Insert)
- TCODK_DELETE (Delete)
- TCODK_LWIN (Lwin)
- TCODK_RWIN (Rwin)
- TCODK_APPS (Apps)
- TCODK_KPADD (KeypadAdd)
- TCODK_KPSUB (KeypadSubtract)
- TCODK_KPDIV (KeypadDivide)
- TCODK_KPMUL (KeypadMultiply)
- TCODK_KPDEC (KeypadDecimal)
- TCODK_KPENTER (KeypadEnter)
- TCODK_F1 (F1)
- TCODK_F2 (F2)
- TCODK_F3 (F3)
- TCODK_F4 (F4)
- TCODK_F5 (F5)
- TCODK_F6 (F6)
- TCODK_F7 (F7)
- TCODK_F8 (F8)
- TCODK_F9 (F9)
- TCODK_F10 (F10)
- TCODK_F11 (F11)
- TCODK_F12 (F12)
- TCODK_NUMLOCK (Numlock)
- TCODK_SCROLLLOCK (Scrolllock)
- TCODK_SPACE (Space)
-
- numeric keys :
-
- TCODK_0 (Zero)
- TCODK_1 (One)
- TCODK_2 (Two)
- TCODK_3 (Three)
- TCODK_4 (Four)
- TCODK_5 (Five)
- TCODK_6 (Six)
- TCODK_7 (Seven)
- TCODK_8 (Eight)
- TCODK_9 (Nine)
- TCODK_KP0 (KeypadZero)
- TCODK_KP1 (KeypadOne)
- TCODK_KP2 (KeypadTwo)
- TCODK_KP3 (KeypadThree)
- TCODK_KP4 (KeypadFour)
- TCODK_KP5 (KeypadFive)
- TCODK_KP6 (KeypadSix)
- TCODK_KP7 (KeypadSeven)
- TCODK_KP8 (KeypadEight)
- TCODK_KP9 (KeypadNine)
-
- Any other (printable) key :
-
- TCODK_CHAR (Char)
-
- Codes starting with TCODK_KP represents keys on the numeric keypad (if available).
- */
-
- /**
- @PageName console_offscreen
- @PageFather console
- @PageTitle Using off-screen consoles
- @PageDesc The offscreen consoles allow you to draw on secondary consoles as you would do with the root console. You can then blit those secondary consoles on the root console. This allows you to use local coordinate space while rendering a portion of the final screen, and easily move components of the screen without modifying the rendering functions.
- @FuncTitle Creating an offscreen console
- @FuncDesc You can create as many off-screen consoles as you want by using this function. You can draw on them as you would do with the root console, but you cannot flush them to the screen. Else, you can blit them on other consoles, including the root console. See blit. The C version of this function returns a console handler that you can use in most console drawing functions.
- @Cpp TCODConsole::TCODConsole(int w, int h)
- @C TCOD_console_t TCOD_console_new(int w, int h)
- @Py console_new(w,h)
- @C# TCODConsole::TCODConsole(int w, int h)
- @Lua tcod.Console(w,h)
- @Param w,h the console size.
- 0 < w
- 0 < h
- @CppEx
- // Creating a 40x20 offscreen console, filling it with red and blitting it on the root console at position 5,5
- TCODConsole *offscreenConsole = new TCODConsole(40,20);
- offscreenConsole->setDefaultBackground(TCODColor::red);
- offscreenConsole->clear();
- TCODConsole::blit(offscreenConsole,0,0,40,20,TCODConsole::root,5,5,255);
- @CEx
- TCOD_console_t offscreen_console = TCOD_console_new(40,20);
- TCOD_console_set_default_background(offscreen_console,TCOD_red);
- TCOD_console_clear(offscreen_console);
- TCOD_console_blit(offscreen_console,0,0,40,20,NULL,5,5,255);
- @PyEx
- offscreen_console = libtcod.console_new(40,20)
- libtcod.console_set_background_color(offscreen_console,libtcod.red)
- libtcod.console_clear(offscreen_console)
- libtcod.console_blit(offscreen_console,0,0,40,20,0,5,5,255)
- @LuaEx
- -- Creating a 40x20 offscreen console, filling it with red and blitting it on the root console at position 5,5
- offscreenConsole = tcod.Console(40,20)
- offscreenConsole:setBackgroundColor(tcod.color.red)
- offscreenConsole:clear()
- tcod.console.blit(offscreenConsole,0,0,40,20,libtcod.TCODConsole_root,5,5,255)
- */
- TCODConsole(int w, int h);
-
- /**
- @PageName console_offscreen
- @FuncTitle Creating an offscreen console from a .asc or .apf file
- @FuncDesc You can create an offscreen console from a file created with Ascii Paint with this constructor
- @Cpp TCODConsole::TCODConsole(const char *filename)
- @C TCOD_console_t TCOD_console_from_file(const char *filename)
- @Param filename path to the .asc or .apf file created with Ascii Paint
- @CppEx
- // Creating an offscreen console, filling it with data from the .asc file
- TCODConsole *offscreenConsole = new TCODConsole("myfile.asc");
- @CEx
- TCOD_console_t offscreen_console = TCOD_console_from_file("myfile.apf");
- */
- TCODConsole(const char *filename);
-
- /**
- @PageName console_offscreen
- @FuncTitle Loading an offscreen console from a .asc file
- @FuncDesc You can load data from a file created with Ascii Paint with this function. When needed, the console will be resized to fit the file size. The function returns false if it couldn't read the file.
- @Cpp bool TCODConsole::loadAsc(const char *filename)
- @C bool TCOD_console_load_asc(TCOD_console_t con, const char *filename)
- @Param con in the C and Python versions, the offscreen console handler
- @Param filename path to the .asc file created with Ascii Paint
- @CppEx
- // Creating a 40x20 offscreen console
- TCODConsole *offscreenConsole = new TCODConsole(40,20);
- // possibly resizing it and filling it with data from the .asc file
- offscreenConsole->loadAsc("myfile.asc");
- @CEx
- TCOD_console_t offscreen_console = TCOD_console_new(40,20);
- TCOD_console_load_asc(offscreen_console,"myfile.asc");
- */
- bool loadAsc(const char *filename);
- /**
- @PageName console_offscreen
- @FuncTitle Loading an offscreen console from a .apf file
- @FuncDesc You can load data from a file created with Ascii Paint with this function. When needed, the console will be resized to fit the file size. The function returns false if it couldn't read the file.
- @Cpp bool TCODConsole::loadApf(const char *filename)
- @C bool TCOD_console_load_apf(TCOD_console_t con, const char *filename)
- @Param con in the C and Python versions, the offscreen console handler
-
- @Param filename path to the .apf file created with Ascii Paint
-
- @CppEx
- // Creating a 40x20 offscreen console
- TCODConsole *offscreenConsole = new TCODConsole(40,20);
- // possibly resizing it and filling it with data from the .apf file
- offscreenConsole->loadApf("myfile.apf");
- @CEx
- TCOD_console_t offscreen_console = TCOD_console_new(40,20);
- TCOD_console_load_apf(offscreen_console,"myfile.asc");
- */
- bool loadApf(const char *filename);
-
- /**
- @PageName console_offscreen
- @FuncTitle Saving a console to a .asc file
- @FuncDesc You can save data from a console to Ascii Paint format with this function. The function returns false if it couldn't write the file. This is the only ASC function that works also with the root console !
- @Cpp bool TCODConsole::saveAsc(const char *filename) const
- @C bool TCOD_console_save_asc(TCOD_console_t con, const char *filename)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param filename path to the .asc file to be created
- @CppEx
- console->saveAsc("myfile.asc");
- @CEx
- TCOD_console_save_asc(console,"myfile.asc");
- */
- bool saveAsc(const char *filename) const;
-
- /**
- @PageName console_offscreen
- @FuncTitle Saving a console to a .apf file
- @FuncDesc You can save data from a console to Ascii Paint format with this function. The function returns false if it couldn't write the file. This is the only ASC function that works also with the root console !
- @Cpp bool TCODConsole::saveApf(const char *filename) const
- @C bool TCOD_console_save_apf(TCOD_console_t con, const char *filename)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param filename path to the .apf file to be created
- @CppEx
- console->saveApf("myfile.apf");
- @CEx
- TCOD_console_save_apf(console,"myfile.apf");
- */
- bool saveApf(const char *filename) const;
-
- bool loadXp(const char *filename) {
- return TCOD_console_load_xp(data, filename) != 0;
- }
- bool saveXp(const char *filename, int compress_level) {
- return TCOD_console_save_xp(data, filename, compress_level) != 0;
- }
-
- /**
- @PageName console_offscreen
- @FuncTitle Blitting a console on another one
- @FuncDesc This function allows you to blit a rectangular area of the source console at a specific position on a destination console. It can also simulate alpha transparency with the fade parameter.
- @Cpp static void blit(const TCODConsole *src,int xSrc, int ySrc, int wSrc, int hSrc, TCODConsole *dst, int xDst, int yDst, float foregroundAlpha=1.0f, float backgroundAlpha=1.0f)
- @C void TCOD_console_blit(TCOD_console_t src,int xSrc, int ySrc, int wSrc, int hSrc, TCOD_console_t dst, int xDst, int yDst, float foreground_alpha, float background_alpha)
- @Py console_blit(src,xSrc,ySrc,xSrc,hSrc,dst,xDst,yDst,foregroundAlpha=1.0,backgroundAlpha=1.0)
- @C#
- static void TCODConsole::blit(TCODConsole src, int xSrc, int ySrc, int wSrc, int hSrc, TCODConsole dst, int xDst, int yDst)
- static void TCODConsole::blit(TCODConsole src, int xSrc, int ySrc, int wSrc, int hSrc, TCODConsole dst, int xDst, int yDst, float foreground_alpha)
- static void TCODConsole::blit(TCODConsole src, int xSrc, int ySrc, int wSrc, int hSrc, TCODConsole dst, int xDst, int yDst, float foreground_alpha, float background_alpha)
- @Lua
- tcod.console.blit(src, xSrc, ySrc, wSrc, hSrc, dst, xDst, yDst)
- tcod.console.blit(src, xSrc, ySrc, wSrc, hSrc, dst, xDst, yDst, foreground_alpha)
- tcod.console.blit(src, xSrc, ySrc, wSrc, hSrc, dst, xDst, yDst, foreground_alpha, background_alpha)
- @Param src The source console that must be blitted on another one.
- @Param xSrc,ySrc,wSrc,hSrc The rectangular area of the source console that will be blitted. If wSrc and/or hSrc == 0, the source console width/height are used
- @Param dst The destination console.
- @Param xDst,yDst Where to blit the upper-left corner of the source area in the destination console.
- @Param foregroundAlpha,backgroundAlpha Alpha transparency of the blitted console.
- 0.0 => The source console is completely transparent. This function does nothing.
- 1.0 => The source console is opaque. Its cells replace the destination cells.
- 0 < fade < 1.0 => The source console is partially blitted, simulating real transparency.
- @CppEx
- // Cross-fading between two offscreen consoles. We use two offscreen consoles with the same size as the root console. We render a different screen on each offscreen console. When the user hits a key, we do a cross-fading from the first screen to the second screen.
- TCODConsole *off1 = new TCODConsole(80,50);
- TCODConsole *off2 = new TCODConsole(80,50);
- ... print screen1 on off1
- ... print screen2 of off2
- // render screen1 in the game window
- TCODConsole::blit(off1,0,0,80,50,TCODConsole::root,0,0);
- TCODConsole::flush();
- // wait or a keypress
- TCODConsole::waitForKeypress(true);
- // do a cross-fading from off1 to off2
- for (int i=1; i <= 255; i++) {
- TCODConsole::blit(off1,0,0,80,50,TCODConsole::root,0,0); // renders the first screen (opaque)
- TCODConsole::blit(off2,0,0,80,50,TCODConsole::root,0,0,i/255.0,i/255.0); // renders the second screen (transparent)
- TCODConsole::flush();
- }
- @CEx
- TCOD_console_t off1 = TCOD_console_new(80,50);
- TCOD_console_t off2 = TCOD_console_new(80,50);
- int i;
- ... print screen1 on off1
- ... print screen2 of off2
- // render screen1 in the game window
- TCOD_console_blit(off1,0,0,80,50,NULL,0,0,1.0,1.0);
- TCOD_console_flush();
- // wait or a keypress
- TCOD_console_wait_for_keypress(true);
- // do a cross-fading from off1 to off2
- for (i=1; i <= 255; i++) {
- TCOD_console_blit(off1,0,0,80,50,NULL,0,0,1.0,1.0); // renders the first screen (opaque)
- TCOD_console_blit(off2,0,0,80,50,NULL,0,0,i/255.0,i/255.0); // renders the second screen (transparent)
- TCOD_console_flush();
- }
- @PyEx
- off1 = libtcod.console_new(80,50)
- off2 = libtcod.console_new(80,50)
- ... print screen1 on off1
- ... print screen2 of off2
- # render screen1 in the game window
- libtcod.console_blit(off1,0,0,80,50,0,0,0)
- libtcod.console_flush()
- # wait or a keypress
- libtcod.console_wait_for_keypress(True)
- # do a cross-fading from off1 to off2
- for i in range(1,256) :
- litbcod.console_blit(off1,0,0,80,50,0,0,0) # renders the first screen (opaque)
- litbcod.console_blit(off2,0,0,80,50,0,0,0,i/255.0,i/255.0) # renders the second screen (transparent)
- litbcod.console_flush()
- @LuaEx
- -- Cross-fading between two offscreen consoles. We use two offscreen consoles with the same size as the root console. We render a different screen on each offscreen console. When the user hits a key, we do a cross-fading from the first screen to the second screen.
- off1 = tcod.Console(80,50)
- off2 = tcod.Console(80,50)
- ... print screen1 on off1
- ... print screen2 of off2
- -- render screen1 in the game window
- root=libtcod.TCODConsole_root
- tcod.console.blit(off1,0,0,80,50,root,0,0)
- tcod.console.flush()
- -- wait or a keypress
- tcod.console.waitForKeypress(true)
- -- do a cross-fading from off1 to off2
- for i=1,255,1 do
- tcod.console.blit(off1,0,0,80,50,root,0,0) -- renders the first screen (opaque)
- tcod.console.blit(off2,0,0,80,50,root,0,0,i/255,i/255) -- renders the second screen (transparent)
- tcod.console.flush()
- end
- */
- static void blit(const TCODConsole *src,int xSrc, int ySrc, int wSrc, int hSrc, TCODConsole *dst, int xDst, int yDst, float foreground_alpha=1.0f, float background_alpha=1.0f);
- /**
- @PageName console_offscreen
- @FuncTitle Define a blit-transparent color
- @FuncDesc This function defines a transparent background color for an offscreen console. All cells with this background color are ignored by the blit operation. You can use it to blit only some parts of the console.
- @Cpp void TCODConsole::setKeyColor(const TCODColor &col)
- @C void TCOD_console_set_key_color(TCOD_console_t con,TCOD_color_t col)
- @Py console_set_key_color(con,col)
- @C# void TCODConsole::setKeyColor(TCODColor col)
- @Lua Console:setKeyColor(col)
- @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
- @Param col the transparent background color
- */
- void setKeyColor(const TCODColor &col);
- /**
- @PageName console_offscreen
- @FuncTitle Destroying an offscreen console
- @FuncDesc Use this function to destroy an offscreen console and release any resources allocated. Don't use it on the root console.
- @Cpp TCODConsole::~TCODConsole()
- @C void TCOD_console_delete(TCOD_console_t con)
- @Py console_delete(con)
- @C# void TCODConsole::Dispose()
- @Lua through garbage collector
- @Param con in the C and Python versions, the offscreen console handler
- @CppEx
- TCODConsole *off1 = new TCODConsole(80,50);
- ... use off1
- delete off1; // destroy the offscreen console
- @CEx
- TCOD_console_t off1 = TCOD_console_new(80,50);
- ... use off1
- TCOD_console_delete(off1); // destroy the offscreen console
- @PyEx
- off1 = libtcod.console_new(80,50)
- ... use off1
- libtcod.console_delete(off1) # destroy the offscreen console
- @LuaEx
- off1 = tcod.Console(80,50)
- ... use off1
- off1=nil -- release the reference
- */
- virtual ~TCODConsole();
-
- void setDirty(int x, int y, int w, int h);
-
-
- TCODConsole(TCOD_console_t con) : data(con) {}
-
- // ctrl = TCOD_COLCTRL_1...TCOD_COLCTRL_5 or TCOD_COLCTRL_STOP
- static const char *getColorControlString( TCOD_colctrl_t ctrl );
- // ctrl = TCOD_COLCTRL_FORE_RGB or TCOD_COLCTRL_BACK_RGB
- static const char *getRGBColorControlString( TCOD_colctrl_t ctrl, const TCODColor & col );
-
-protected :
- friend class TCODImage;
- friend class TCODZip;
- friend class TCODText;
- TCODConsole();
- TCOD_console_t data;
-};
-
-#endif /* TCOD_CONSOLE_SUPPORT */
-
-#endif /* _TCOD_CONSOLE_HPP */
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _TCOD_CONSOLE_HPP
+#define _TCOD_CONSOLE_HPP
+
+#include
+
+#include "console.h"
+#include "console/drawing.h"
+#include "console/printing.h"
+#include "console/rexpaint.h"
+#include "engine/display.h"
+
+#ifdef TCOD_CONSOLE_SUPPORT
+
+#include "image.hpp"
+#include "color.hpp"
+
+class TCODImage;
+/**
+ @PageName console
+ @PageCategory Core
+ @PageTitle Console
+ @PageDesc The console emulator handles the rendering of the game screen and the keyboard input.
+Classic real time game loop:
+ @Cpp
+ TCODConsole::initRoot(80,50,"my game",false);
+ TCODSystem::setFps(25); // limit framerate to 25 frames per second
+ while (!endGame && !TCODConsole::isWindowClosed()) {
+ TCOD_key_t key;
+ TCODSystem::checkForEvent(TCOD_EVENT_KEY_PRESS,&key,NULL);
+ updateWorld (key, TCODSystem::getLastFrameLength());
+ // updateWorld(TCOD_key_t key, float elapsed) (using key if key.vk != TCODK_NONE)
+ // use elapsed to scale any update that is time dependent.
+ // ... draw world+GUI on TCODConsole::root
+ TCODConsole::flush();
+ }
+ @Lua
+ tcod.console.initRoot(80,50,"my game", false)
+ root=libtcod.TCODConsole_root
+ tcod.system.setFps(25)
+ while not tcod.console.isWindowClosed() do
+ -- ... draw on root
+ tcod.console.flush()
+ key=tcod.console.checkForKeypress()
+ -- ... update world, using key and tcod.system.getLastFrameLength
+ end
+
+*/
+/**
+ @PageName console
+ @FuncDesc Classic turn by turn game loop:
+ @Cpp
+ TCODConsole::initRoot(80,50,"my game",false);
+ while (!endGame && !TCODConsole::isWindowClosed()) {
+ // ... draw on TCODConsole::root
+ TCODConsole::flush();
+ TCOD_key_t key;
+ TCODConsole::waitForEvent(TCOD_EVENT_KEY_PRESS,&key,NULL,true);
+ //... update world, using key
+ }
+*/
+
+class TCODLIB_API TCODConsole {
+public :
+ /**
+ @PageName console_init
+ @PageTitle Initializing the console
+ @PageFather console
+ */
+
+ static TCODConsole *root;
+
+ /**
+ @PageName console_init_root
+ @PageTitle Creating the game window
+ @PageFather console_init
+ @Cpp static void TCODConsole::initRoot (int w, int h, const char * title, bool fullscreen = false, TCOD_renderer_t renderer = TCOD_RENDERER_SDL)
+ @C void TCOD_console_init_root (int w, int h, const char * title, bool fullscreen, TCOD_renderer_t renderer)
+ @Py console_init_root (w, h, title, fullscreen = False, renderer = RENDERER_SDL)
+ @C#
+ static void TCODConsole::initRoot(int w, int h, string title)
+ static void TCODConsole::initRoot(int w, int h, string title, bool fullscreen)
+ static void TCODConsole::initRoot(int w, int h, string title, bool fullscreen, TCODRendererType renderer)
+ @Lua
+ tcod.console.initRoot(w,h,title) -- fullscreen = false, renderer = SDL
+ tcod.console.initRoot(w,h,title,fullscreen) -- renderer = SDL
+ tcod.console.initRoot(w,h,title,fullscreen,renderer)
+ -- renderers : tcod.GLSL, tcod.OpenGL, tcod.SDL
+ @Param w,h size of the console(in characters). The default font in libtcod (./terminal.png) uses 8x8 pixels characters.
+ You can change the font by calling TCODConsole::setCustomFont before calling initRoot.
+ @Param title title of the window. It's not visible when you are in fullscreen.
+ Note 1 : you can dynamically change the window title with TCODConsole::setWindowTitle
+ @Param fullscreen whether you start in windowed or fullscreen mode.
+ Note 1 : you can dynamically change this mode with TCODConsole::setFullscreen
+ Note 2 : you can get current mode with TCODConsole::isFullscreen
+ @Param renderer which renderer to use. Possible values are :
+ * TCOD_RENDERER_GLSL : works only on video cards with pixel shaders
+ * TCOD_RENDERER_OPENGL : works on all video cards supporting OpenGL 1.4
+ * TCOD_RENDERER_SDL : should work everywhere!
+ Note 1: if you select a renderer that is not supported by the player's machine, libtcod scan the lower renderers until it finds a working one.
+ Note 2: on recent video cards, GLSL results in up to 900% increase of framerates in the true color sample compared to SDL renderer.
+ Note 3: whatever renderer you use, it can always be overridden by the player through the libtcod.cfg file.
+ Note 4: you can dynamically change the renderer after calling initRoot with TCODSystem::setRenderer.
+ Note 5: you can get current renderer with TCODSystem::getRenderer. It might be different from the one you set in initRoot in case it's not supported on the player's computer.
+ @CppEx TCODConsole::initRoot(80, 50, "The Chronicles Of Doryen v0.1");
+ @CEx TCOD_console_init_root(80, 50, "The Chronicles Of Doryen v0.1", false, TCOD_RENDERER_OPENGL);
+ @PyEx libtcod.console_init_root(80, 50, 'The Chronicles Of Doryen v0.1')
+ @LuaEx tcod.console.initRoot(80,50,"The Chronicles Of Doryen v0.1")
+ */
+ static void initRoot(int w, int h, const char * title, bool fullscreen = false, TCOD_renderer_t renderer=TCOD_RENDERER_SDL);
+
+ /**
+ @PageName console_set_custom_font
+ @PageTitle Using a custom bitmap font
+ @PageFather console_init
+ @FuncTitle setCustomFont
+ @FuncDesc This function allows you to use a bitmap font (png or bmp) with custom character size or layout.
+ It should be called before initializing the root console with initRoot.
+ Once this function is called, you can define your own custom mappings using mapping functions
+ Different font layouts
+
+ ASCII_INROW | ASCII_INCOL | TCOD |
+
+ | | |
+
+
+ - ascii, in columns : characters 0 to 15 are in the first column. The space character is at coordinates 2,0.
+ - ascii, in rows : characters 0 to 15 are in the first row. The space character is at coordinates 0,2.
+ - tcod : special mapping. Not all ascii values are mapped. The space character is at coordinates 0,0.
+
+ Different font types
+
+ standard (non antialiased) | antialiased (32 bits PNG) | antialiased (greyscale) |
+
+ | | |
+
+
+ - standard : transparency is given by a key color automatically detected by looking at the color of the space character
+ - 32 bits : transparency is given by the png alpha layer. The font color does not matter but it must be desaturated
+ - greyscale : transparency is given by the pixel value. You can use white characters on black background or black characters on white background. The background color is automatically detected by looking at the color of the space character
+
+ Examples of fonts can be found in libtcod's fonts directory. Check the Readme file there.
+ @Cpp static void TCODConsole::setCustomFont(const char *fontFile, int flags=TCOD_FONT_LAYOUT_ASCII_INCOL,int nbCharHoriz=0, int nbCharVertic=0)
+ @C void TCOD_console_set_custom_font(const char *fontFile, int flags,int nb_char_horiz, int nb_char_vertic)
+ @Py console_set_custom_font(fontFile, flags=FONT_LAYOUT_ASCII_INCOL,nb_char_horiz=0, nb_char_vertic=0)
+ @C#
+ static void TCODConsole::setCustomFont(string fontFile)
+ static void TCODConsole::setCustomFont(string fontFile, int flags)
+ static void TCODConsole::setCustomFont(string fontFile, int flags, int nbCharHoriz)
+ static void TCODConsole::setCustomFont(string fontFile, int flags, int nbCharHoriz, int nbCharVertic)
+ @Lua
+ tcod.console.setCustomFont(fontFile)
+ tcod.console.setCustomFont(fontFile, flags)
+ tcod.console.setCustomFont(fontFile, nbCharHoriz)
+ tcod.console.setCustomFont(fontFile, flags, nbCharHoriz, nbCharVertic)
+ -- flags : tcod.LayoutAsciiInColumn, tcod.LayoutAsciiInRow, tcod.LayoutTCOD, tcod.Greyscale
+ @Param fontFile Name of a .bmp or .png file containing the font.
+ @Param flags Used to define the characters layout in the bitmap and the font type :
+ TCOD_FONT_LAYOUT_ASCII_INCOL : characters in ASCII order, code 0-15 in the first column
+ TCOD_FONT_LAYOUT_ASCII_INROW : characters in ASCII order, code 0-15 in the first row
+ TCOD_FONT_LAYOUT_TCOD : simplified layout. See examples below.
+ TCOD_FONT_TYPE_GREYSCALE : create an anti-aliased font from a greyscale bitmap
+ For Python, remove TCOD _ :
+ libtcod.FONT_LAYOUT_ASCII_INCOL
+ @Param nbCharHoriz,nbCharVertic Number of characters in the font.
+ Should be 16x16 for ASCII layouts, 32x8 for TCOD layout.
+ But you can use any other layout.
+ If set to 0, there are deduced from the font layout flag.
+ @CppEx
+ TCODConsole::setCustomFont("standard_8x8_ascii_in_col_font.bmp",TCOD_FONT_LAYOUT_ASCII_INCOL);
+ TCODConsole::setCustomFont("32bits_8x8_ascii_in_row_font.png",TCOD_FONT_LAYOUT_ASCII_INROW);
+ TCODConsole::setCustomFont("greyscale_8x8_tcod_font.png",TCOD_FONT_LAYOUT_TCOD | TCOD_FONT_TYPE_GREYSCALE);
+ @CEx
+ TCOD_console_set_custom_font("standard_8x8_ascii_in_col_font.bmp",TCOD_FONT_LAYOUT_ASCII_INCOL,16,16);
+ TCOD_console_set_custom_font("32bits_8x8_ascii_in_row_font.png",TCOD_FONT_LAYOUT_ASCII_INROW,32,8);
+ TCOD_console_set_custom_font("greyscale_8x8_tcod_font.png",TCOD_FONT_LAYOUT_TCOD | TCOD_FONT_TYPE_GREYSCALE,32,8);
+ @PyEx
+ libtcod.console_set_custom_font("standard_8x8_ascii_in_col_font.bmp",libtcod.FONT_LAYOUT_ASCII_INCOL)
+ libtcod.console_set_custom_font("32bits_8x8_ascii_in_row_font.png",libtcod.FONT_LAYOUT_ASCII_INROW)
+ libtcod.console_set_custom_font("greyscale_8x8_tcod_font.png",libtcod.FONT_LAYOUT_TCOD | libtcod.FONT_TYPE_GREYSCALE)
+ @LuaEx
+ tcod.console.setCustomFont("standard_8x8_ascii_in_col_font.bmp",tcod.LayoutAsciiInColumn);
+ tcod.console.setCustomFont("32bits_8x8_ascii_in_row_font.png",tcod.LayoutAsciiInRow);
+ tcod.console.setCustomFont("greyscale_8x8_tcod_font.png",tcod.LayoutTCOD + tcod.Greyscale);
+ */
+ static void setCustomFont(const char *fontFile, int flags=TCOD_FONT_LAYOUT_ASCII_INCOL,int nbCharHoriz=0, int nbCharVertic=0);
+
+ /**
+ @PageName console_map
+ @PageTitle Using custom characters mapping
+ @PageFather console_init
+ @FuncTitle Mapping a single ASCII code to a character
+ @PageDesc These functions allow you to map characters in the bitmap font to ASCII codes.
+ They should be called after initializing the root console with initRoot.
+ You can dynamically change the characters mapping at any time, allowing to use several fonts in the same screen.
+ @Cpp static void TCODConsole::mapAsciiCodeToFont(int asciiCode, int fontCharX, int fontCharY)
+ @C void TCOD_console_map_ascii_code_to_font(int asciiCode, int fontCharX, int fontCharY)
+ @Py console_map_ascii_code_to_font(asciiCode, fontCharX, fontCharY)
+ @C# static void TCODConsole::mapAsciiCodeToFont(int asciiCode, int fontCharX, int fontCharY)
+ @Lua tcod.console.mapAsciiCodeToFont(asciiCode, fontCharX, fontCharY)
+ @Param asciiCode ASCII code to map.
+ @Param fontCharX,fontCharY Coordinate of the character in the bitmap font (in characters, not pixels).
+ */
+ static void mapAsciiCodeToFont(int asciiCode, int fontCharX, int fontCharY);
+
+ /**
+ @PageName console_map
+ @FuncTitle Mapping consecutive ASCII codes to consecutive characters
+ @Cpp static void TCODConsole::mapAsciiCodesToFont(int firstAsciiCode, int nbCodes, int fontCharX, int fontCharY)
+ @C void TCOD_console_map_ascii_codes_to_font(int firstAsciiCode, int nbCodes, int fontCharX, int fontCharY)
+ @Py console_map_ascii_codes_to_font(firstAsciiCode, nbCodes, fontCharX, fontCharY)
+ @C# static void TCODConsole::mapAsciiCodesToFont(int firstAsciiCode, int nbCodes, int fontCharX, int fontCharY)
+ @Lua tcod.console.mapAsciiCodesToFont(firstAsciiCode, nbCodes, fontCharX, fontCharY)
+ @Param firstAsciiCode first ASCII code to map
+ @Param nbCodes number of consecutive ASCII codes to map
+ @Param fontCharX,fontCharY coordinate of the character in the bitmap font (in characters, not pixels) corresponding to the first ASCII code
+ */
+ static void mapAsciiCodesToFont(int firstAsciiCode, int nbCodes, int fontCharX, int fontCharY);
+
+ /**
+ @PageName console_map
+ @FuncTitle Mapping ASCII code from a string to consecutive characters
+ @Cpp static void TCODConsole::mapStringToFont(const char *s, int fontCharX, int fontCharY)
+ @C void TCOD_console_map_string_to_font(const char *s, int fontCharX, int fontCharY)
+ @Py console_map_string_to_font(s, fontCharX, fontCharY)
+ @C# static void TCODConsole::mapStringToFont(string s, int fontCharX, int fontCharY)
+ @Lua tcod.console.mapStringToFont(s, fontCharX, fontCharY)
+ @Param s string containing the ASCII codes to map
+ @Param fontCharX,fontCharY coordinate of the character in the bitmap font (in characters, not pixels) corresponding to the first ASCII code in the string
+ */
+ static void mapStringToFont(const char *s, int fontCharX, int fontCharY);
+
+ /**
+ @PageName console_fullscreen
+ @PageTitle Fullscreen mode
+ @PageFather console_init
+ @FuncTitle Getting the current mode
+ @FuncDesc This function returns true if the current mode is fullscreen.
+ @Cpp static bool TCODConsole::isFullscreen()
+ @C bool TCOD_console_is_fullscreen()
+ @Py console_is_fullscreen()
+ @C# static bool TCODConsole::isFullscreen()
+ @Lua tcod.console.isFullscreen()
+ */
+ static bool isFullscreen();
+ /**
+ @PageName console_fullscreen
+ @FuncTitle Switching between windowed and fullscreen modes
+ @FuncDesc This function switches the root console to fullscreen or windowed mode.
+ Note that there is no predefined key combination to switch to/from fullscreen. You have to do this in your own code.
+ @Cpp static void TCODConsole::setFullscreen(bool fullscreen)
+ @C void TCOD_console_set_fullscreen(bool fullscreen)
+ @Py console_set_fullscreen(fullscreen)
+ @C# static void TCODConsole::setFullscreen(bool fullscreen)
+ @Lua tcod.console.setFullscreen(fullscreen)
+ @Param fullscreen true to switch to fullscreen mode.
+ false to switch to windowed mode.
+ @CppEx
+ TCOD_key_t key;
+ TCODConsole::checkForEvent(TCOD_EVENT_KEY_PRESS,&key,NULL);
+ if ( key.vk == TCODK_ENTER && key.lalt )
+ TCODConsole::setFullscreen(!TCODConsole::isFullscreen());
+ @CEx
+ TCOD_key_t key;
+ TCOD_console_check_for_event(TCOD_EVENT_KEY_PRESS,&key,NULL);
+ if ( key.vk == TCODK_ENTER && key.lalt )
+ TCOD_console_set_fullscreen(!TCOD_console_is_fullscreen());
+ @PyEx
+ key=Key()
+ libtcod.console_check_for_event(libtcod.EVENT_KEY_PRESS,key,0)
+ if key.vk == libtcod.KEY_ENTER and key.lalt :
+ libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
+ @LuaEx
+ key=tcod.console.checkForKeypress()
+ if key.KeyCode == tcod.Enter and key.LeftAlt then
+ tcod.console.setFullscreen(not tcod.console.isFullscreen())
+ end
+ */
+ static void setFullscreen(bool fullscreen);
+
+ /**
+ @PageName console_window
+ @PageFather console_init
+ @PageTitle Communicate with the window manager
+ @FuncTitle Changing the window title
+ @FuncDesc This function dynamically changes the title of the game window.
+ Note that the window title is not visible while in fullscreen.
+ @Cpp static void TCODConsole::setWindowTitle(const char *title)
+ @C void TCOD_console_set_window_title(const char *title)
+ @Py console_set_window_title(title)
+ @C# static void TCODConsole::setWindowTitle(string title)
+ @Lua tcod.console.setWindowTitle(title)
+ @Param title New title of the game window
+ */
+ static void setWindowTitle(const char *title);
+
+ /**
+ @PageName console_window
+ @FuncTitle Handling "close window" events
+ @FuncDesc When you start the program, this returns false. Once a "close window" event has been sent by the window manager, it will always return true. You're supposed to exit cleanly the game.
+ @Cpp static bool TCODConsole::isWindowClosed()
+ @C bool TCOD_console_is_window_closed()
+ @Py console_is_window_closed()
+ @C# static bool TCODConsole::isWindowClosed()
+ @Lua tcod.console.isWindowClosed()
+ */
+ static bool isWindowClosed();
+
+ /**
+ @PageName console_window
+ @FuncTitle Check if the mouse cursor is inside the game window
+ @FuncDesc Returns true if the mouse cursor is inside the game window area and the game window is the active application.
+ @Cpp static bool TCODConsole::hasMouseFocus()
+ @C bool TCOD_console_has_mouse_focus()
+ @Py console_has_mouse_focus()
+ */
+ static bool hasMouseFocus();
+
+ /**
+ @PageName console_window
+ @FuncTitle Check if the game application is active
+ @FuncDesc Returns false if the game window is not the active window or is iconified.
+ @Cpp static bool TCODConsole::isActive()
+ @C bool TCOD_console_is_active()
+ @Py console_is_active()
+ */
+ static bool isActive();
+
+ /**
+ @PageName console_credits
+ @PageTitle libtcod's credits
+ @PageFather console_init
+ @PageDesc Use these functions to display credits, as seen in the samples.
+ @FuncTitle Using a separate credit page
+ @FuncDesc You can print a "Powered by libtcod x.y.z" screen during your game startup simply by calling this function after initRoot.
+ The credits screen can be skipped by pressing any key.
+ @Cpp static void TCODConsole::credits()
+ @C void TCOD_console_credits()
+ @Py console_credits()
+ @C# static void TCODConsole::credits()
+ @Lua tcod.console.credits()
+ */
+ static void credits();
+
+ /**
+ @PageName console_credits
+ @FuncTitle Embedding credits in an existing page
+ @FuncDesc You can also print the credits on one of your game screens (your main menu for example) by calling this function in your main loop.
+ This function returns true when the credits screen is finished, indicating that you no longer need to call it.
+ @Cpp static bool TCODConsole::renderCredits(int x, int y, bool alpha)
+ @C bool TCOD_console_credits_render(int x, int y, bool alpha)
+ @Py bool TCOD_console_credits_render(int x, int y, bool alpha)
+ @C# static bool TCODConsole::renderCredits(int x, int y, bool alpha)
+ @Lua tcod.console.renderCredits(x, y, alpha)
+ @Param x,y Position of the credits text in your root console
+ @Param alpha If true, credits are transparently added on top of the existing screen.
+ For this to work, this function must be placed between your screen rendering code and the console flush.
+ @CppEx
+ TCODConsole::initRoot(80,50,"The Chronicles Of Doryen v0.1",false); // initialize the root console
+ bool endCredits=false;
+ while ( ! TCODConsole::isWindowClosed() ) { // your game loop
+ // your game rendering here...
+ // render transparent credits near the center of the screen
+ if (! endCredits ) endCredits=TCODConsole::renderCredits(35,25,true);
+ TCODConsole::flush();
+ }
+ @CEx
+ TCOD_console_init_root(80,50,"The Chronicles Of Doryen v0.1",false);
+ bool end_credits=false;
+ while ( ! TCOD_console_is_window_closed() ) {
+ // your game rendering here...
+ // render transparent credits near the center of the screen
+ if (! end_credits ) end_credits=TCOD_console_credits_render(35,25,true);
+ TCOD_console_flush();
+ }
+ @PyEx
+ libtcod.console_init_root(80,50,"The Chronicles Of Doryen v0.1",False)
+ end_credits=False
+ while not libtcod.console_is_window_closed() :
+ // your game rendering here...
+ // render transparent credits near the center of the screen
+ if (not end_credits ) : end_credits=libtcod.console_credits_render(35,25,True)
+ libtcod.console_flush()
+ @LuaEx
+ tcod.console.initRoot(80,50,"The Chronicles Of Doryen v0.1") -- initialize the root console
+ endCredits=false
+ while not tcod.console.isWindowClosed() do -- your game loop
+ -- your game rendering here...
+ -- render transparent credits near the center of the screen
+ if not endCredits then endCredits=tcod.console.renderCredits(35,25,true) end
+ tcod.console.flush()
+ end
+ */
+ static bool renderCredits(int x, int y, bool alpha);
+
+ /**
+ @PageName console_credits
+ @FuncTitle Restart the credits animation
+ @FuncDesc When using rederCredits, you can restart the credits animation from the beginning before it's finished by calling this function.
+ @Cpp static void TCODConsole::resetCredits()
+ @C void TCOD_console_credits_reset()
+ @Py console_credits_reset()
+ @C# static void TCODConsole::resetCredits()
+ @Lua tcod.console.resetCredits()
+ */
+ static void resetCredits();
+
+ /**
+ @PageName console_draw
+ @PageTitle Drawing on the root console
+ @PageFather console
+ */
+
+ /**
+ @PageName console_draw_basic
+ @PageTitle Basic printing functions
+ @PageFather console_draw
+ @FuncTitle Setting the default background color
+ @FuncDesc This function changes the default background color for a console. The default background color is used by several drawing functions like clear, putChar, ...
+ @Cpp void TCODConsole::setDefaultBackground(TCODColor back)
+ @C void TCOD_console_set_default_background(TCOD_console_t con,TCOD_color_t back)
+ @Py console_set_default_background(con,back)
+ @C# void TCODConsole::setBackgroundColor(TCODColor back)
+ @Lua Console:setBackgroundColor(back)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param back the new default background color for this console
+ @CppEx TCODConsole::root->setDefaultBackground(myColor)
+ @CEx TCOD_console_set_default_background(NULL, my_color)
+ @PyEx litbcod.console_set_default_background(0, my_color)
+ @Lua libtcod.TCODConsole_root:setBackgroundColor( myColor )
+ */
+ void setDefaultBackground(TCODColor back);
+
+ /**
+ @PageName console_draw_basic
+ @FuncTitle Setting the default foreground color
+ @FuncDesc This function changes the default foreground color for a console. The default foreground color is used by several drawing functions like clear, putChar, ...
+ @Cpp void TCODConsole::setDefaultForeground(TCODColor fore)
+ @C void TCOD_console_set_default_foreground(TCOD_console_t con,TCOD_color_t fore)
+ @Py console_set_default_foreground(con, fore)
+ @C# void TCODConsole::setForegroundColor(TCODColor fore)
+ @Lua Console:setForegroundColor(fore)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param fore the new default foreground color for this console
+ @CppEx TCODConsole::root->setDefaultForeground(myColor)
+ @CEx TCOD_console_set_default_foreground(NULL, my_color)
+ @PyEx litbcod.console_set_default_foreground(0, my_color)
+ @LuaEx libtcod.TCODConsole_root:setForegroundColor( myColor )
+ */
+ void setDefaultForeground(TCODColor fore);
+
+ /**
+ @PageName console_draw_basic
+ @FuncTitle Clearing a console
+ @FuncDesc This function modifies all cells of a console :
+ * set the cell's background color to the console default background color
+ * set the cell's foreground color to the console default foreground color
+ * set the cell's ASCII code to 32 (space)
+ @Cpp void TCODConsole::clear()
+ @C void TCOD_console_clear(TCOD_console_t con)
+ @Py console_clear(con)
+ @C# void TCODConsole::clear()
+ @Lua Console:clear()
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ */
+ void clear();
+
+ /**
+ @PageName console_draw_basic
+ @FuncTitle Setting the background color of a cell
+ @FuncDesc This function modifies the background color of a cell, leaving other properties (foreground color and ASCII code) unchanged.
+ @Cpp void TCODConsole::setCharBackground(int x, int y, const TCODColor &col, TCOD_bkgnd_flag_t flag = TCOD_BKGND_SET)
+ @C void TCOD_console_set_char_background(TCOD_console_t con,int x, int y, TCOD_color_t col, TCOD_bkgnd_flag_t flag)
+ @Py console_set_char_background(con, x, y, col, flag=BKGND_SET)
+ @C#
+ void TCODConsole::setCharBackground(int x, int y, TCODColor col)
+ void TCODConsole::setCharBackground(int x, int y, TCODColor col, TCODBackgroundFlag flag)
+ @Lua
+ Console:setCharBackground(x, y, col)
+ Console:setCharBackground(x, y, col, flag)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param x,y coordinates of the cell in the console.
+ 0 <= x < console width
+ 0 <= y < console height
+ @Param col the background color to use. You can use color constants
+ @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
+ */
+ void setCharBackground(int x, int y, const TCODColor &col, TCOD_bkgnd_flag_t flag = TCOD_BKGND_SET);
+ /**
+ @PageName console_draw_basic
+ @FuncTitle Setting the foreground color of a cell
+ @FuncDesc This function modifies the foreground color of a cell, leaving other properties (background color and ASCII code) unchanged.
+ @Cpp void TCODConsole::setCharForeground(int x, int y, const TCODColor &col)
+ @C void TCOD_console_set_char_foreground(TCOD_console_t con,int x, int y, TCOD_color_t col)
+ @Py console_set_char_foreground(con, x, y, col)
+ @C# void TCODConsole::setCharForeground(int x, int y, TCODColor col)
+ @Lua Console:setCharForeground(x, y, col)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param x,y coordinates of the cell in the console.
+ 0 <= x < console width
+ 0 <= y < console height
+ @Param col the foreground color to use. You can use color constants
+ */
+ void setCharForeground(int x, int y, const TCODColor &col);
+
+ /**
+ @PageName console_draw_basic
+ @FuncTitle Setting the ASCII code of a cell
+ @FuncDesc This function modifies the ASCII code of a cell, leaving other properties (background and foreground colors) unchanged.
+ Note that since a clear console has both background and foreground colors set to black for every cell, using setchar will produce black characters on black background. Use putchar instead.
+ @Cpp void TCODConsole::setChar(int x, int y, int c)
+ @C void TCOD_console_set_char(TCOD_console_t con,int x, int y, int c)
+ @Py console_set_char(con, x, y, c)
+ @C# void TCODConsole::setChar(int x, int y, int c)
+ @Lua Console:setChar(x, y, c)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param x,y coordinates of the cell in the console.
+ 0 <= x < console width
+ 0 <= y < console height
+ @Param c the new ASCII code for the cell. You can use ASCII constants
+ */
+ void setChar(int x, int y, int c);
+
+ /**
+ @PageName console_draw_basic
+ @FuncTitle Setting every property of a cell using default colors
+ @FuncDesc This function modifies every property of a cell :
+ * update the cell's background color according to the console default background color (see TCOD_bkgnd_flag_t).
+ * set the cell's foreground color to the console default foreground color
+ * set the cell's ASCII code to c
+ @Cpp void TCODConsole::putChar(int x, int y, int c, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT)
+ @C void TCOD_console_put_char(TCOD_console_t con,int x, int y, int c, TCOD_bkgnd_flag_t flag)
+ @Py console_put_char( con, x, y, c, flag=BKGND_DEFAULT)
+ @C#
+ void TCODConsole::putChar(int x, int y, int c)
+ void TCODConsole::putChar(int x, int y, int c, TCODBackgroundFlag flag)
+ @Lua
+ Console:putChar(x, y, c)
+ Console:putChar(x, y, c, flag)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param x,y coordinates of the cell in the console.
+ 0 <= x < console width
+ 0 <= y < console height
+ @Param c the new ASCII code for the cell. You can use ASCII constants
+ @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
+ */
+ void putChar(int x, int y, int c, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT);
+
+ /**
+ @PageName console_draw_basic
+ @FuncTitle Setting every property of a cell using specific colors
+ @FuncDesc This function modifies every property of a cell :
+ * set the cell's background color to back.
+ * set the cell's foreground color to fore.
+ * set the cell's ASCII code to c.
+ @Cpp void TCODConsole::putCharEx(int x, int y, int c, const TCODColor & fore, const TCODColor & back)
+ @C void TCOD_console_put_char_ex(TCOD_console_t con,int x, int y, int c, TCOD_color_t fore, TCOD_color_t back)
+ @Py console_put_char_ex( con, x, y, c, fore, back)
+ @C# void TCODConsole::putCharEx(int x, int y, int c, TCODColor fore, TCODColor back)
+ @Lua Console:putCharEx(x, y, c, fore, back)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param x,y coordinates of the cell in the console.
+ 0 <= x < console width
+ 0 <= y < console height
+ @Param c the new ASCII code for the cell. You can use ASCII constants
+ @Param fore,back new foreground and background colors for this cell
+ */
+ void putCharEx(int x, int y, int c, const TCODColor &fore, const TCODColor &back);
+
+ /**
+ @PageName console_bkgnd_flag_t
+ @PageTitle Background effect flags
+ @PageFather console_draw
+ @PageDesc This flag is used by most functions that modify a cell background color. It defines how the console's current background color is used to modify the cell's existing background color :
+ TCOD_BKGND_NONE : the cell's background color is not modified.
+ TCOD_BKGND_SET : the cell's background color is replaced by the console's default background color : newbk = curbk.
+ TCOD_BKGND_MULTIPLY : the cell's background color is multiplied by the console's default background color : newbk = oldbk * curbk
+ TCOD_BKGND_LIGHTEN : newbk = MAX(oldbk,curbk)
+ TCOD_BKGND_DARKEN : newbk = MIN(oldbk,curbk)
+ TCOD_BKGND_SCREEN : newbk = white - (white - oldbk) * (white - curbk) // inverse of multiply : (1-newbk) = (1-oldbk)*(1-curbk)
+ TCOD_BKGND_COLOR_DODGE : newbk = curbk / (white - oldbk)
+ TCOD_BKGND_COLOR_BURN : newbk = white - (white - oldbk) / curbk
+ TCOD_BKGND_ADD : newbk = oldbk + curbk
+ TCOD_BKGND_ADDALPHA(alpha) : newbk = oldbk + alpha*curbk
+ TCOD_BKGND_BURN : newbk = oldbk + curbk - white
+ TCOD_BKGND_OVERLAY : newbk = curbk.x <= 0.5 ? 2*curbk*oldbk : white - 2*(white-curbk)*(white-oldbk)
+ TCOD_BKGND_ALPHA(alpha) : newbk = (1.0f-alpha)*oldbk + alpha*(curbk-oldbk)
+ TCOD_BKGND_DEFAULT : use the console's default background flag
+ Note that TCOD_BKGND_ALPHA and TCOD_BKGND_ADDALPHA are MACROS that needs a float parameter between (0.0 and 1.0). TCOD_BKGND_ALPH and TCOD_BKGND_ADDA should not be used directly (else they will have the same effect as TCOD_BKGND_NONE).
+ For Python, remove TCOD_ : libtcod.BKGND_NONE
+ For C# : None, Set, Multiply, Lighten, Darken, Screen, ColodDodge, ColorBurn, Add, Burn Overlay, Default
+ With lua, use tcod.None, ..., tcod.Default, BUT tcod.console.Alpha(value) and tcod.console.AddAlpha(value)
+ */
+
+ /**
+ @PageName console_print
+ @PageTitle String drawing functions
+ @PageFather console_draw
+ @FuncTitle Setting the default background flag
+ @FuncDesc This function defines the background mode (see TCOD_bkgnd_flag_t) for the console.
+ This default mode is used by several functions (print, printRect, ...)
+ @Cpp void TCODConsole::setBackgroundFlag(TCOD_bkgnd_flag_t flag)
+ @C void TCOD_console_set_background_flag(TCOD_console_t con,TCOD_bkgnd_flag_t flag)
+ @Py console_set_background_flag(con, flag)
+ @C# void TCODConsole::setBackgroundFlag(TCODBackgroundFlag flag)
+ @Lua Console:setBackgroundFlag(flag)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
+ */
+ void setBackgroundFlag(TCOD_bkgnd_flag_t flag);
+
+ /**
+ @PageName console_print
+ @FuncTitle Getting the default background flag
+ @FuncDesc This function returns the background mode (see TCOD_bkgnd_flag_t) for the console.
+ This default mode is used by several functions (print, printRect, ...)
+ @Cpp TCOD_bkgnd_flag_t TCODConsole::getBackgroundFlag() const
+ @C TCOD_bkgnd_flag_t TCOD_console_get_background_flag(TCOD_console_t con)
+ @Py console_get_background_flag(con)
+ @C# TCODBackgroundFlag TCODConsole::getBackgroundFlag()
+ @Lua Console:getBackgroundFlag()
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ */
+ TCOD_bkgnd_flag_t getBackgroundFlag() const;
+
+ /**
+ @PageName console_print
+ @FuncTitle Setting the default alignment
+ @FuncDesc This function defines the default alignment (see TCOD_alignment_t) for the console.
+ This default alignment is used by several functions (print, printRect, ...).
+ Values for alignment : TCOD_LEFT, TCOD_CENTER, TCOD_RIGHT (in Python, remove TCOD_ : libtcod.LEFT).
+ For C# and Lua : LeftAlignment, RightAlignment, CenterAlignment
+ @Cpp void TCODConsole::setAlignment(TCOD_alignment_t alignment)
+ @C void TCOD_console_set_alignment(TCOD_console_t con,TCOD_bkgnd_flag_t alignment)
+ @Py console_set_alignment(con, alignment)
+ @C# void TCODConsole::setAlignment(TCODAlignment alignment)
+ @Lua Console:setAlignment(alignment)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param alignment defines how the strings are printed on screen.
+ */
+ void setAlignment(TCOD_alignment_t alignment);
+
+ /**
+ @PageName console_print
+ @FuncTitle Getting the default alignment
+ @FuncDesc This function returns the default alignment (see TCOD_alignment_t) for the console.
+ This default mode is used by several functions (print, printRect, ...).
+ Values for alignment : TCOD_LEFT, TCOD_CENTER, TCOD_RIGHT (in Python, remove TCOD_ : libtcod.LEFT).
+ For C# and Lua : LeftAlignment, RightAlignment, CenterAlignment
+ @Cpp TCOD_alignment_t TCODConsole::getAlignment() const
+ @C TCOD_alignment_t TCOD_console_get_alignment(TCOD_console_t con)
+ @Py console_get_alignment(con)
+ @C# TCODAlignment TCODConsole::getAlignment()
+ @Lua Console:getAlignment()
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ */
+ TCOD_alignment_t getAlignment() const;
+ /**
+ * Print an EASCII formatted string to the console.
+ * \rst
+ * .. deprecated:: 1.8
+ * EASCII is being phased out. Use TCODConsole::printf or one of the
+ * UTF-8 overloads.
+ * \endrst
+ */
+ TCOD_DEPRECATED("Use TCODConsole::printf or the std::string overload for"
+ " this function.")
+ void print(int x, int y, const char *fmt, ...);
+ /**
+ * Print a UTF-8 string to the console.
+ *
+ * This method will use this consoles default alignment, blend mode, and
+ * colors.
+ * \rst
+ * .. versionadded:: 1.8
+ * \endrst
+ */
+ void print(int x, int y, const std::string &str);
+ /**
+ * Print a UTF-8 string to the console with specific alignment and blend
+ * mode.
+ * \rst
+ * .. versionadded:: 1.8
+ * \endrst
+ */
+ void print(int x, int y, const std::string &str,
+ TCOD_alignment_t alignment, TCOD_bkgnd_flag_t flag);
+ /**
+ * Format and print a UTF-8 string to the console.
+ *
+ * This method will use this consoles default alignment, blend mode, and
+ * colors.
+ * \rst
+ * .. versionadded:: 1.8
+ * \endrst
+ */
+ TCODLIB_FORMAT(4, 5)
+ void printf(int x, int y, const char *fmt, ...);
+ /**
+ * Format and print a UTF-8 string to the console with specific alignment
+ * and blend mode.
+ * \rst
+ * .. versionadded:: 1.8
+ * \endrst
+ */
+ TCODLIB_FORMAT(6, 7)
+ void printf(int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment,
+ const char *fmt, ...);
+ /**
+ * Print an EASCII formatted string to the console.
+ * \rst
+ * .. deprecated:: 1.8
+ * Use `TCODConsole::print` or `TCODConsole::printf`.
+ * These functions have overloads for specifying flag and alignment.
+ * \endrst
+ */
+ TCOD_DEPRECATED("Use TCODConsole::print or TCODConsole::printf instead of"
+ " this function.")
+ void printEx(int x, int y, TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t alignment, const char *fmt, ...);
+ /**
+ @PageName console_print
+ @FuncTitle Printing a string with default parameters and autowrap
+ @FuncDesc This function draws a string in a rectangle inside the console, using default colors, alignment and background mode.
+ If the string reaches the borders of the rectangle, carriage returns are inserted.
+ If h > 0 and the bottom of the rectangle is reached, the string is truncated. If h = 0, the string is only truncated if it reaches the bottom of the console.
+ The function returns the height (number of console lines) of the printed string.
+ @Cpp int TCODConsole::printRect(int x, int y, int w, int h, const char *fmt, ...)
+ @C int TCOD_console_print_rect(TCOD_console_t con,int x, int y, int w, int h, const char *fmt, ...)
+ @Py console_print_rect(con, x, y, w, h, fmt)
+ @C# int TCODConsole::printRect(int x, int y, int w, int h, string fmt)
+ @Lua Console:printRect(x, y, w, h, fmt)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param x,y coordinate of the character in the console, depending on the alignment :
+ * TCOD_LEFT : leftmost character of the string
+ * TCOD_CENTER : center character of the string
+ * TCOD_RIGHT : rightmost character of the string
+ @Param w,h size of the rectangle
+ x <= x+w < console width
+ y <= y+h < console height
+ @Param fmt printf-like format string, eventually followed by parameters. You can use control codes to change the colors inside the string, except in C#.
+ */
+ TCODLIB_FORMAT(6, 7)
+ int printRect(int x, int y, int w, int h, const char *fmt, ...);
+
+ /**
+ @PageName console_print
+ @FuncTitle Printing a string with specific alignment and background mode and autowrap
+ @FuncDesc This function draws a string in a rectangle inside the console, using default colors, but specific alignment and background mode.
+ If the string reaches the borders of the rectangle, carriage returns are inserted.
+ If h > 0 and the bottom of the rectangle is reached, the string is truncated. If h = 0, the string is only truncated if it reaches the bottom of the console.
+ The function returns the height (number of console lines) of the printed string.
+ @Cpp int TCODConsole::printRectEx(int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, ...)
+ @C int TCOD_console_print_rect_ex(TCOD_console_t con,int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, ...)
+ @Py console_print_rect_ex(con, x, y, w, h, flag, alignment, fmt)
+ @C# int TCODConsole::printRectEx(int x, int y, int w, int h, TCODBackgroundFlag flag, TCODAlignment alignment, string fmt)
+ @Lua Console:printRectEx(x, y, w, h, flag, alignment, fmt)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param x,y coordinate of the character in the console, depending on the alignment :
+ * TCOD_LEFT : leftmost character of the string
+ * TCOD_CENTER : center character of the string
+ * TCOD_RIGHT : rightmost character of the string
+ @Param w,h size of the rectangle
+ x <= x+w < console width
+ y <= y+h < console height
+ @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
+ @Param alignment defines how the strings are printed on screen.
+ @Param fmt printf-like format string, eventually followed by parameters. You can use control codes to change the colors inside the string, except in C#.
+ */
+ TCODLIB_FORMAT(8, 9)
+ int printRectEx(int x, int y, int w, int h, TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t alignment, const char *fmt, ...);
+
+ /**
+ @PageName console_print
+ @FuncTitle Compute the height of an autowrapped string
+ @FuncDesc This function returns the expected height of an autowrapped string without actually printing the string with printRect or printRectEx
+ @Cpp int TCODConsole::getHeightRect(int x, int y, int w, int h, const char *fmt, ...)
+
+ @C int TCOD_console_get_height_rect(TCOD_console_t con,int x, int y, int w, int h, const char *fmt, ...)
+ @Py console_get_height_rect(con, x, y, w, h, fmt)
+ @C# int TCODConsole::getHeightRect(int x, int y, int w, int h, string fmt)
+ @Lua Console:getHeightRect(x, y, w, h, fmt)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param x,y coordinate of the rectangle upper-left corner in the console
+ @Param w,h size of the rectangle
+ x <= x+w < console width
+ y <= y+h < console height
+ @Param fmt printf-like format string, eventually followed by parameters. You can use control codes to change the colors inside the string, except in C#.
+ */
+ TCODLIB_FORMAT(6, 7)
+ int getHeightRect(int x, int y, int w, int h, const char *fmt, ...);
+
+ /**
+ @PageName console_print
+ @FuncTitle Changing the colors while printing a string
+ @FuncDesc If you want to draw a string using different colors for each word, the basic solution is to call a string printing function several times, changing the default colors between each call.
+ The TCOD library offers a simpler way to do this, allowing you to draw a string using different colors in a single call. For this, you have to insert color control codes in your string.
+ A color control code is associated with a color set (a foreground color and a background color). If you insert this code in your string, the next characters will use the colors associated with the color control code.
+ There are 5 predefined color control codes :
+ For Python, remove TCOD_ : libtcod.COLCTRL_1
+ TCOD_COLCTRL_1
+ TCOD_COLCTRL_2
+ TCOD_COLCTRL_3
+ TCOD_COLCTRL_4
+ TCOD_COLCTRL_5
+ To associate a color with a code, use setColorControl.
+ To go back to the console's default colors, insert in your string the color stop control code :
+ TCOD_COLCTRL_STOP
+
+ You can also use any color without assigning it to a control code, using the generic control codes :
+ TCOD_COLCTRL_FORE_RGB
+ TCOD_COLCTRL_BACK_RGB
+
+ Those controls respectively change the foreground and background color used to print the string characters. In the string, you must insert the r,g,b components of the color (between 1 and 255. The value 0 is forbidden because it represents the end of the string in C/C++) immediately after this code.
+ @Cpp static void TCODConsole::setColorControl(TCOD_colctrl_t con, const TCODColor &fore, const TCODColor &back)
+ @C void TCOD_console_set_color_control(TCOD_colctrl_t con, TCOD_color_t fore, TCOD_color_t back)
+ @Py console_set_color_control(con,fore,back)
+ @C# Not supported directly, use getRGBColorControlString and getColorControlString.
+ @Lua Not supported
+ @Param con the color control TCOD_COLCTRL_x, 1<=x<=5
+ @Param fore foreground color when this control is activated
+ @Param back background color when this control is activated
+ @CppEx
+ // A string with a red over black word, using predefined color control codes
+ TCODConsole::setColorControl(TCOD_COLCTRL_1,TCODColor::red,TCODColor::black);
+ TCODConsole::root->print(1,1,"String with a %cred%c word.",TCOD_COLCTRL_1,TCOD_COLCTRL_STOP);
+ // A string with a red over black word, using generic color control codes
+ TCODConsole::root->print(1,1,"String with a %c%c%c%c%c%c%c%cred%c word.",
+ TCOD_COLCTRL_FORE_RGB,255,1,1,TCOD_COLCTRL_BACK_RGB,1,1,1,TCOD_COLCTRL_STOP);
+ // A string with a red over black word, using generic color control codes
+ TCODConsole::root->print(1,1,"String with a %c%c%c%c%c%c%c%cred%c word.",
+ TCOD_COLCTRL_FORE_RGB,255,1,1,TCOD_COLCTRL_BACK_RGB,1,1,1,TCOD_COLCTRL_STOP);
+ @CEx
+ // A string with a red over black word, using predefined color control codes
+ TCOD_console_set_color_control(TCOD_COLCTRL_1,red,black);
+ TCOD_console_print(NULL,1,1,"String with a %cred%c word.",TCOD_COLCTRL_1,TCOD_COLCTRL_STOP);
+ // A string with a red word (over default background color), using generic color control codes
+ TCOD_console_print(NULL,1,1,"String with a %c%c%c%cred%c word.",
+ TCOD_COLCTRL_FORE_RGB,255,1,1,TCOD_COLCTRL_STOP);
+ // A string with a red over black word, using generic color control codes
+ TCOD_console_print(NULL,1,1,"String with a %c%c%c%c%c%c%c%cred%c word.",
+ TCOD_COLCTRL_FORE_RGB,255,1,1,TCOD_COLCTRL_BACK_RGB,1,1,1,TCOD_COLCTRL_STOP);
+ @PyEx
+ # A string with a red over black word, using predefined color control codes
+ libtcod.console_set_color_control(libtcod.COLCTRL_1,litbcod.red,litbcod.black)
+ libtcod.console_print(0,1,1,"String with a %cred%c word."%(libtcod.COLCTRL_1,libtcod.COLCTRL_STOP))
+ # A string with a red word (over default background color), using generic color control codes
+ litbcod.console_print(0,1,1,"String with a %c%c%c%cred%c word."%(libtcod.COLCTRL_FORE_RGB,255,1,1,libtcod.COLCTRL_STOP))
+ # A string with a red over black word, using generic color control codes
+ libtcod.console_print(0,1,1,"String with a %c%c%c%c%c%c%c%cred%c word."%
+ (libtcod.COLCTRL_FORE_RGB,255,1,1,libtcod.COLCTRL_BACK_RGB,1,1,1,libtcod.COLCTRL_STOP))
+
+ @C#Ex
+ TCODConsole.root.print(1,1,String.Format("String with a {0}red{1} word.",
+ TCODConsole.getRGBColorControlString(ColorControlForeground,TCODColor.red),
+ TCODConsole.getColorControlString(ColorControlStop));
+ */
+ static void setColorControl(TCOD_colctrl_t con, const TCODColor &fore, const TCODColor &back);
+
+#ifndef NO_UNICODE
+ /**
+ @PageName console_print
+ @FuncTitle Unicode functions
+ @FuncDesc those functions are similar to their ASCII equivalent, but work with unicode strings (wchar_t in C/C++).
+ Note that unicode is not supported in the Python wrapper.
+ @Cpp static void TCODConsole::mapStringToFont(const wchar_t *s, int fontCharX, int fontCharY)
+ @C void TCOD_console_map_string_to_font_utf(const wchar_t *s, int fontCharX, int fontCharY)
+ */
+ static void mapStringToFont(const wchar_t *s, int fontCharX, int fontCharY);
+ /**
+ @PageName console_print
+ @Cpp void TCODConsole::print(int x, int y, const wchar_t *fmt, ...)
+ @C void TCOD_console_print_utf(TCOD_console_t con,int x, int y, const wchar_t *fmt, ...)
+ */
+ void print(int x, int y, const wchar_t *fmt, ...);
+ /**
+ @PageName console_print
+ @Cpp void TCODConsole::printEx(int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...)
+ @C void TCOD_console_print_ex_utf(TCOD_console_t con,int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...)
+ */
+ void printEx(int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...);
+ /**
+ @PageName console_print
+ @Cpp int TCODConsole::printRect(int x, int y, int w, int h, const wchar_t *fmt, ...)
+ @C int TCOD_console_print_rect_utf(TCOD_console_t con,int x, int y, int w, int h, const wchar_t *fmt, ...)
+ */
+ int printRect(int x, int y, int w, int h, const wchar_t *fmt, ...);
+
+ /**
+ @PageName console_print
+ @Cpp int TCODConsole::printRectEx(int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...)
+ @C int TCOD_console_print_rect_ex_utf(TCOD_console_t con,int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...)
+ */
+ int printRectEx(int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...);
+
+ /**
+ @PageName console_print
+ @Cpp int TCODConsole::getHeightRect(int x, int y, int w, int h, const wchar_t *fmt, ...)
+ @C int TCOD_console_get_height_rect_utf(TCOD_console_t con,int x, int y, int w, int h, const wchar_t *fmt, ...)
+ */
+ int getHeightRect(int x, int y, int w, int h, const wchar_t *fmt, ...);
+#endif
+
+ /**
+ @PageName console_advanced
+ @PageFather console_draw
+ @PageTitle Advanced printing functions
+ @FuncTitle Filling a rectangle with the background color
+ @FuncDesc Fill a rectangle inside a console. For each cell in the rectangle :
+ * set the cell's background color to the console default background color
+ * if clear is true, set the cell's ASCII code to 32 (space)
+ @Cpp void TCODConsole::rect(int x, int y, int w, int h, bool clear, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT)
+ @C void TCOD_console_rect(TCOD_console_t con,int x, int y, int w, int h, bool clear, TCOD_bkgnd_flag_t flag)
+ @Py console_rect(con,x, y, w, h, clear, flag=BKGND_DEFAULT)
+ @C#
+ void TCODConsole::rect(int x, int y, int w, int h, bool clear)
+ void TCODConsole::rect(int x, int y, int w, int h, bool clear, TCODBackgroundFlag flag)
+ @Lua
+ Console:rect(x, y, w, h, clear)
+ Console:rect(x, y, w, h, clear, flag)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param x,y coordinates of rectangle upper-left corner in the console.
+ 0 <= x < console width
+ 0 <= y < console height
+ @Param w,h size of the rectangle in the console.
+ x <= x+w < console width
+ y <= y+h < console height
+ @Param clear if true, all characters inside the rectangle are set to ASCII code 32 (space).
+ If false, only the background color is modified
+ @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
+ */
+ void rect(int x, int y, int w, int h, bool clear, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT);
+
+ /**
+ @PageName console_advanced
+ @FuncTitle Drawing an horizontal line
+ @FuncDesc Draws an horizontal line in the console, using ASCII code TCOD_CHAR_HLINE (196), and the console's default background/foreground colors.
+ @Cpp void TCODConsole::hline(int x,int y, int l, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT)
+ @C void TCOD_console_hline(TCOD_console_t con,int x,int y, int l, TCOD_bkgnd_flag_t flag)
+ @Py console_hline(con,x,y,l,flag=BKGND_DEFAULT)
+ @C#
+ void TCODConsole::hline(int x,int y, int l)
+ void TCODConsole::hline(int x,int y, int l, TCODBackgroundFlag flag)
+ @Lua
+ Console:hline(x,y, l)
+ Console:hline(x,y, l, flag)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param x,y Coordinates of the line's left end in the console.
+ 0 <= x < console width
+ 0 <= y < console height
+ @Param l The length of the line in cells 1 <= l <= console width - x
+ @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
+ */
+ void hline(int x,int y, int l, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT);
+
+ /**
+ @PageName console_advanced
+ @FuncTitle Drawing an vertical line
+ @FuncDesc Draws an vertical line in the console, using ASCII code TCOD_CHAR_VLINE (179), and the console's default background/foreground colors.
+ @Cpp void TCODConsole::vline(int x,int y, int l, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT)
+ @C void TCOD_console_vline(TCOD_console_t con,int x,int y, int l, TCOD_bkgnd_flag_t flag)
+ @Py console_vline(con,x,y,l,flag=BKGND_DEFAULT)
+ @C#
+ void TCODConsole::vline(int x,int y, int l)
+ void TCODConsole::vline(int x,int y, int l, TCODBackgroundFlag flag)
+ @Lua
+ Console:vline(x,y, l)
+ Console:vline(x,y, l, flag)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param x,y Coordinates of the line's upper end in the console.
+ 0 <= x < console width
+ 0 <= y < console height
+ @Param l The length of the line in cells 1 <= l <= console height - y
+ @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
+ */
+ void vline(int x,int y, int l, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT);
+
+ /**
+ @PageName console_advanced
+ @FuncTitle Drawing a window frame
+ @FuncDesc This function calls the rect function using the supplied background mode flag, then draws a rectangle with the console's default foreground color. If fmt is not NULL, it is printed on the top of the rectangle, using inverted colors.
+ @Cpp void TCODConsole::printFrame(int x,int y,int w,int h, bool clear=true, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT, const char *fmt=NULL, ...)
+ @C void TCOD_console_print_frame(TCOD_console_t con,int x,int y,int w,int h, bool clear, TCOD_bkgnd_flag_t flag, const char *fmt, ...)
+ @Py console_print_frame(con,x, y, w, h, clear=True, flag=BKGND_DEFAULT, fmt=0)
+ @C#
+ void TCODConsole::printFrame(int x,int y, int w,int h)
+ void TCODConsole::printFrame(int x,int y, int w,int h, bool clear)
+ void TCODConsole::printFrame(int x,int y, int w,int h, bool clear, TCODBackgroundFlag flag)
+ void TCODConsole::printFrame(int x,int y, int w,int h, bool clear, TCODBackgroundFlag flag, string fmt)
+ @Lua
+ Console:printFrame(x,y, w,h)
+ Console:printFrame(x,y, w,h, clear)
+ Console:printFrame(x,y, w,h, clear, flag)
+ Console:printFrame(x,y, w,h, clear, flag, fmt)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param x,y Coordinates of the rectangle's upper-left corner in the console.
+ 0 <= x < console width
+ 0 <= y < console height
+ @Param w,h size of the rectangle in the console.
+ x <= x+w < console width
+ y <= y+h < console height
+ @Param clear if true, all characters inside the rectangle are set to ASCII code 32 (space).
+ If false, only the background color is modified
+ @Param flag this flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
+ @Param fmt if NULL, the function only draws a rectangle.
+ Else, printf-like format string, eventually followed by parameters. You can use control codes to change the colors inside the string.
+ */
+ void printFrame(int x,int y,int w,int h, bool clear=true, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT, const char *fmt=NULL, ...);
+
+ /**
+ @PageName console_read
+ @PageTitle Reading the content of the console
+ @PageFather console_draw
+ @FuncTitle Get the console's width
+ @FuncDesc This function returns the width of a console (either the root console or an offscreen console)
+ @Cpp int TCODConsole::getWidth() const
+ @C int TCOD_console_get_width(TCOD_console_t con)
+ @Py console_get_width(con)
+ @C# int TCODConsole::getWidth()
+ @Lua Console:getWidth()
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ */
+ int getWidth() const;
+
+ /**
+ @PageName console_read
+ @FuncTitle Get the console's height
+ @FuncDesc This function returns the height of a console (either the root console or an offscreen console)
+ @Cpp int TCODConsole::getHeight() const
+ @C int TCOD_console_get_height(TCOD_console_t con)
+ @Py console_get_height(con)
+ @C# int TCODConsole::getHeight()
+ @Lua Console:getHeight()
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ */
+ int getHeight() const;
+
+ /**
+ @PageName console_read
+ @FuncTitle Reading the default background color
+ @FuncDesc This function returns the default background color of a console.
+ @Cpp TCODColor TCODConsole::getDefaultBackground() const
+ @C TCOD_color_t TCOD_console_get_default_background(TCOD_console_t con)
+ @Py console_get_default_background(con)
+ @C# TCODColor TCODConsole::getBackgroundColor()
+ @Lua Console:getBackgroundColor()
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ */
+ TCODColor getDefaultBackground() const;
+
+ /**
+ @PageName console_read
+ @FuncTitle Reading the default foreground color
+ @FuncDesc This function returns the default foreground color of a console.
+ @Cpp TCODColor TCODConsole::getDefaultForeground() const
+ @C TCOD_color_t TCOD_console_get_default_foreground(TCOD_console_t con)
+ @Py console_get_default_foreground(con)
+ @C# TCODColor TCODConsole::getForegroundColor()
+ @Lua Console:getForegroundColor()
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ */
+ TCODColor getDefaultForeground() const;
+
+ /**
+ @PageName console_read
+ @FuncTitle Reading the background color of a cell
+ @FuncDesc This function returns the background color of a cell.
+ @Cpp TCODColor TCODConsole::getCharBackground(int x, int y) const
+ @C TCOD_color_t TCOD_console_get_char_background(TCOD_console_t con,int x, int y)
+ @Py console_get_char_background(con,x,y)
+ @C# TCODColor TCODConsole::getCharBackground(int x, int y)
+ @Lua Console::getCharBackground(x, y)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param x,y coordinates of the cell in the console.
+ 0 <= x < console width
+ 0 <= y < console height
+ */
+ TCODColor getCharBackground(int x, int y) const;
+
+ /**
+ @PageName console_read
+ @FuncTitle Reading the foreground color of a cell
+ @FuncDesc This function returns the foreground color of a cell.
+ @Cpp TCODColor TCODConsole::getCharForeground(int x, int y) const
+ @C TCOD_color_t TCOD_console_get_char_foreground(TCOD_console_t con,int x, int y)
+ @Py console_get_char_foreground(con,x,y)
+ @C# TCODColor TCODConsole::getCharForeground(int x, int y)
+ @Lua Console::getCharForeground(x, y)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param x,y coordinates of the cell in the console.
+ 0 <= x < console width
+ 0 <= y < console height
+ */
+ TCODColor getCharForeground(int x, int y) const;
+
+ /**
+ @PageName console_read
+ @FuncTitle Reading the ASCII code of a cell
+ @FuncDesc This function returns the ASCII code of a cell.
+ @Cpp int TCODConsole::getChar(int x, int y) const
+ @C int TCOD_console_get_char(TCOD_console_t con,int x, int y)
+ @Py console_get_char(con,x,y)
+ @C# int TCODConsole::getChar(int x, int y)
+ @Lua Console::getChar(x, y)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param x,y coordinates of the cell in the console.
+ 0 <= x < console width
+ 0 <= y < console height
+ */
+ int getChar(int x, int y) const;
+
+ /**
+ @PageName console_fading
+ @PageTitle Screen fading functions
+ @PageFather console_draw
+ @PageDesc Use these functions to easily fade to/from a color
+ @FuncTitle Changing the fading parameters
+ @FuncDesc This function defines the fading parameters, allowing to easily fade the game screen to/from a color. Once they are defined, the fading parameters are valid for ever. You don't have to call setFade for each rendered frame (unless you change the fading parameters).
+ @Cpp static void TCODConsole::setFade(uint8_t fade, const TCODColor &fadingColor)
+ @C void TCOD_console_set_fade(uint8_t fade, TCOD_color_t fadingColor)
+ @Py console_set_fade(fade, fadingColor)
+ @C# static void TCODConsole::setFade(byte fade, TCODColor fadingColor)
+ @Lua tcod.console.setFade(fade, fadingColor)
+ @Param fade the fading amount. 0 => the screen is filled with the fading color. 255 => no fading effect
+ @Param fadingColor the color to use during the console flushing operation
+ @CppEx
+ for (int fade=255; fade >= 0; fade --) {
+ TCODConsole::setFade(fade,TCODColor::black);
+ TCODConsole::flush();
+ }
+ @CEx
+ int fade;
+ for (fade=255; fade >= 0; fade --) {
+ TCOD_console_setFade(fade,TCOD_black);
+ TCOD_console_flush();
+ }
+ @PyEx
+ for fade in range(255,0) :
+ libtcod.console_setFade(fade,libtcod.black)
+ libtcod.console_flush()
+ @LuaEx
+ for fade=255,0,-1 do
+ tcod.console.setFade(fade,tcod.color.black)
+ tcod.console.flush()
+ end
+ */
+ static void setFade(uint8_t fade, const TCODColor &fadingColor);
+
+ /**
+ @PageName console_fading
+ @FuncTitle Reading the fade amount
+ @FuncDesc This function returns the current fade amount, previously defined by setFade.
+ @Cpp static uint8_t TCODConsole::getFade()
+ @C uint8_t TCOD_console_get_fade()
+ @Py console_get_fade()
+ @C# static byte TCODConsole::getFade()
+ @Lua tcod.console.getFade()
+ */
+ static uint8_t getFade();
+
+ /**
+ @PageName console_fading
+ @FuncTitle Reading the fading color
+ @FuncDesc This function returns the current fading color, previously defined by setFade.
+ @Cpp static TCODColor TCODConsole::getFadingColor()
+ @C TCOD_color_t TCOD_console_get_fading_color()
+ @Py console_get_fading_color()
+ @C# static TCODColor TCODConsole::getFadingColor()
+ @Lua tcod.console.getFadingColor()
+ */
+ static TCODColor getFadingColor();
+
+ /**
+ @PageName console_flush
+ @PageFather console
+ @PageTitle Flushing the root console
+ @FuncDesc Once the root console is initialized, you can use one of the printing functions to change the background colors, the foreground colors or the ASCII characters on the console.
+ Once you've finished rendering the root console, you have to actually apply the updates to the screen with this function.
+ @Cpp static void TCODConsole::flush()
+ @C void TCOD_console_flush()
+ @Py console_flush()
+ @C# static void TCODConsole::flush()
+ @Lua tcod.console.flush()
+ */
+ static void flush();
+
+ /**
+ @PageName console_ascii
+ @PageTitle ASCII constants
+ @PageFather console_draw
+ @FuncDesc Some useful graphic characters in the terminal.bmp font. For the Python version, remove TCOD_ from the constants. C# and Lua is in parenthesis :
+ Single line walls:
+ TCOD_CHAR_HLINE=196 (HorzLine)
+ TCOD_CHAR_VLINE=179 (VertLine)
+ TCOD_CHAR_NE=191 (NE)
+ TCOD_CHAR_NW=218 (NW)
+ TCOD_CHAR_SE=217 (SE)
+ TCOD_CHAR_SW=192 (SW)
+
+ Double lines walls:
+ TCOD_CHAR_DHLINE=205 (DoubleHorzLine)
+ TCOD_CHAR_DVLINE=186 (DoubleVertLine)
+ TCOD_CHAR_DNE=187 (DoubleNE)
+ TCOD_CHAR_DNW=201 (DoubleNW)
+ TCOD_CHAR_DSE=188 (DoubleSE)
+ TCOD_CHAR_DSW=200 (DoubleSW)
+
+ Single line vertical/horizontal junctions (T junctions):
+ TCOD_CHAR_TEEW=180 (TeeWest)
+ TCOD_CHAR_TEEE=195 (TeeEast)
+ TCOD_CHAR_TEEN=193 (TeeNorth)
+ TCOD_CHAR_TEES=194 (TeeSouth)
+
+ Double line vertical/horizontal junctions (T junctions):
+ TCOD_CHAR_DTEEW=185 (DoubleTeeWest)
+ TCOD_CHAR_DTEEE=204 (DoubleTeeEast)
+ TCOD_CHAR_DTEEN=202 (DoubleTeeNorth)
+ TCOD_CHAR_DTEES=203 (DoubleTeeSouth)
+
+ Block characters:
+ TCOD_CHAR_BLOCK1=176 (Block1)
+ TCOD_CHAR_BLOCK2=177 (Block2)
+ TCOD_CHAR_BLOCK3=178 (Block3)
+
+ Cross-junction between two single line walls:
+ TCOD_CHAR_CROSS=197 (Cross)
+
+ Arrows:
+ TCOD_CHAR_ARROW_N=24 (ArrowNorth)
+ TCOD_CHAR_ARROW_S=25 (ArrowSouth)
+ TCOD_CHAR_ARROW_E=26 (ArrowEast)
+ TCOD_CHAR_ARROW_W=27 (ArrowWest)
+
+ Arrows without tail:
+ TCOD_CHAR_ARROW2_N=30 (ArrowNorthNoTail)
+ TCOD_CHAR_ARROW2_S=31 (ArrowSouthNoTail)
+ TCOD_CHAR_ARROW2_E=16 (ArrowEastNoTail)
+ TCOD_CHAR_ARROW2_W=17 (ArrowWestNoTail)
+
+ Double arrows:
+ TCOD_CHAR_DARROW_H=29 (DoubleArrowHorz)
+ TCOD_CHAR_ARROW_V=18 (DoubleArrowVert)
+
+ GUI stuff:
+ TCOD_CHAR_CHECKBOX_UNSET=224
+ TCOD_CHAR_CHECKBOX_SET=225
+ TCOD_CHAR_RADIO_UNSET=9
+ TCOD_CHAR_RADIO_SET=10
+
+ Sub-pixel resolution kit:
+ TCOD_CHAR_SUBP_NW=226 (SubpixelNorthWest)
+ TCOD_CHAR_SUBP_NE=227 (SubpixelNorthEast)
+ TCOD_CHAR_SUBP_N=228 (SubpixelNorth)
+ TCOD_CHAR_SUBP_SE=229 (SubpixelSouthEast)
+ TCOD_CHAR_SUBP_DIAG=230 (SubpixelDiagonal)
+ TCOD_CHAR_SUBP_E=231 (SubpixelEast)
+ TCOD_CHAR_SUBP_SW=232 (SubpixelSouthWest)
+
+ Miscellaneous characters:
+ TCOD_CHAR_SMILY = 1 (Smilie)
+ TCOD_CHAR_SMILY_INV = 2 (SmilieInv)
+ TCOD_CHAR_HEART = 3 (Heart)
+ TCOD_CHAR_DIAMOND = 4 (Diamond)
+ TCOD_CHAR_CLUB = 5 (Club)
+ TCOD_CHAR_SPADE = 6 (Spade)
+ TCOD_CHAR_BULLET = 7 (Bullet)
+ TCOD_CHAR_BULLET_INV = 8 (BulletInv)
+ TCOD_CHAR_MALE = 11 (Male)
+ TCOD_CHAR_FEMALE = 12 (Female)
+ TCOD_CHAR_NOTE = 13 (Note)
+ TCOD_CHAR_NOTE_DOUBLE = 14 (NoteDouble)
+ TCOD_CHAR_LIGHT = 15 (Light)
+ TCOD_CHAR_EXCLAM_DOUBLE = 19 (ExclamationDouble)
+ TCOD_CHAR_PILCROW = 20 (Pilcrow)
+ TCOD_CHAR_SECTION = 21 (Section)
+ TCOD_CHAR_POUND = 156 (Pound)
+ TCOD_CHAR_MULTIPLICATION = 158 (Multiplication)
+ TCOD_CHAR_FUNCTION = 159 (Function)
+ TCOD_CHAR_RESERVED = 169 (Reserved)
+ TCOD_CHAR_HALF = 171 (Half)
+ TCOD_CHAR_ONE_QUARTER = 172 (OneQuarter)
+ TCOD_CHAR_COPYRIGHT = 184 (Copyright)
+ TCOD_CHAR_CENT = 189 (Cent)
+ TCOD_CHAR_YEN = 190 (Yen)
+ TCOD_CHAR_CURRENCY = 207 (Currency)
+ TCOD_CHAR_THREE_QUARTERS = 243 (ThreeQuarters)
+ TCOD_CHAR_DIVISION = 246 (Division)
+ TCOD_CHAR_GRADE = 248 (Grade)
+ TCOD_CHAR_UMLAUT = 249 (Umlaut)
+ TCOD_CHAR_POW1 = 251 (Pow1)
+ TCOD_CHAR_POW3 = 252 (Pow2)
+ TCOD_CHAR_POW2 = 253 (Pow3)
+ TCOD_CHAR_BULLET_SQUARE = 254 (BulletSquare)
+ */
+
+ /**
+ @PageName console_input
+ @PageTitle Handling user input
+ @PageDesc The user handling functions allow you to get keyboard and mouse input from the user, either for turn by turn games (the function wait until the user press a key or a mouse button), or real time games (non blocking function).
+ WARNING : those functions also handle screen redraw event, so TCODConsole::flush function won't redraw screen if no user input function is called !
+ @PageFather console
+ */
+
+ /* deprecated as of 1.5.1 */
+ static TCOD_key_t waitForKeypress(bool flush);
+ /* deprecated as of 1.5.1 */
+ static TCOD_key_t checkForKeypress(int flags=TCOD_KEY_RELEASED);
+
+ /**
+ @PageName console_blocking_input
+ @PageCategory Core
+ @PageFather console_input
+ @PageTitle Blocking user input
+ @PageDesc This function stops the application until an event occurs.
+ */
+
+ /**
+ @PageName console_non_blocking_input
+ @PageTitle Non blocking user input
+ @PageFather console_input
+ @FuncDesc The preferred way to check for user input is to use checkForEvent below, but you can also get the status of any special key at any time with :
+ @Cpp static bool TCODConsole::isKeyPressed(TCOD_keycode_t key)
+ @C bool TCOD_console_is_key_pressed(TCOD_keycode_t key)
+ @Py console_is_key_pressed(key)
+ @C# static bool TCODConsole::isKeyPressed(TCODKeyCode key)
+ @Lua tcod.console.isKeyPressed(key)
+ @Param key Any key code defined in keycode_t except TCODK_CHAR (Char) and TCODK_NONE (NoKey)
+ */
+ static bool isKeyPressed(TCOD_keycode_t key);
+
+ /**
+ @PageName console_key_t
+ @PageTitle Keyboard event structure
+ @PageFather console_input
+ @PageDesc This structure contains information about a key pressed/released by the user.
+ @C
+ typedef struct {
+ TCOD_keycode_t vk;
+ char c;
+ char text[32];
+ bool pressed;
+ bool lalt;
+ bool lctrl;
+ bool lmeta;
+ bool ralt;
+ bool rctrl;
+ bool rmeta;
+ bool shift;
+ } TCOD_key_t;
+ @Lua
+ key.KeyCode
+ key.Character
+ key.Text
+ key.Pressed
+ key.LeftAlt
+ key.LeftControl
+ key.LeftMeta
+ key.RightAlt
+ key.RightControl
+ key.RightMeta
+ key.Shift
+ @Param vk An arbitrary value representing the physical key on the keyboard. Possible values are stored in the TCOD_keycode_t enum. If no key was pressed, the value is TCODK_NONE
+ @Param c If the key correspond to a printable character, the character is stored in this field. Else, this field contains 0.
+ @Param text If vk is TCODK_TEXT, this will contain the text entered by the user.
+ @Param pressed true if the event is a key pressed, or false for a key released.
+ @Param lalt This field represents the status of the left Alt key : true => pressed, false => released.
+ @Param lctrl This field represents the status of the left Control key : true => pressed, false => released.
+ @Param lmeta This field represents the status of the left Meta (Windows/Command/..) key : true => pressed, false => released.
+ @Param ralt This field represents the status of the right Alt key : true => pressed, false => released.
+ @Param rctrl This field represents the status of the right Control key : true => pressed, false => released.
+ @Param rmeta This field represents the status of the right Meta (Windows/Command/..) key : true => pressed, false => released.
+ @Param shift This field represents the status of the shift key : true => pressed, false => released.
+ */
+
+ /**
+ @PageName console_mouse_t
+ @PageTitle Mouse event structure
+ @PageFather console_input
+ @PageDesc This structure contains information about a mouse move/press/release event.
+ @C
+ typedef struct {
+ int x,y;
+ int dx,dy;
+ int cx,cy;
+ int dcx,dcy;
+ bool lbutton;
+ bool rbutton;
+ bool mbutton;
+ bool lbutton_pressed;
+ bool rbutton_pressed;
+ bool mbutton_pressed;
+ bool wheel_up;
+ bool wheel_down;
+ } TCOD_mouse_t;
+ @Param x,y Absolute position of the mouse cursor in pixels relative to the window top-left corner.
+ @Param dx,dy Movement of the mouse cursor since the last call in pixels.
+ @Param cx,cy Coordinates of the console cell under the mouse cursor (pixel coordinates divided by the font size).
+ @Param dcx,dcy Movement of the mouse since the last call in console cells (pixel coordinates divided by the font size).
+ @Param lbutton true if the left button is pressed.
+ @Param rbutton true if the right button is pressed.
+ @Param mbutton true if the middle button (or the wheel) is pressed.
+ @Param lbutton_pressed true if the left button was pressed and released.
+ @Param rbutton_pressed true if the right button was pressed and released.
+ @Param mbutton_pressed true if the middle button was pressed and released.
+ @Param wheel_up true if the wheel was rolled up.
+ @Param wheel_down true if the wheel was rolled down.
+ */
+
+ /**
+ @PageName console_keycode_t
+ @PageTitle Key codes
+ @PageFather console_input
+ @PageDesc TCOD_keycode_t is a libtcod specific code representing a key on the keyboard.
+ For Python, replace TCODK by KEY: libtcod.KEY_NONE. C# and Lua, the value is in parenthesis. Possible values are :
+ When no key was pressed (see checkForEvent) : TCOD_NONE (NoKey)
+ Special keys :
+ TCODK_ESCAPE (Escape)
+ TCODK_BACKSPACE (Backspace)
+ TCODK_TAB (Tab)
+ TCODK_ENTER (Enter)
+ TCODK_SHIFT (Shift)
+ TCODK_CONTROL (Control)
+ TCODK_ALT (Alt)
+ TCODK_PAUSE (Pause)
+ TCODK_CAPSLOCK (CapsLock)
+ TCODK_PAGEUP (PageUp)
+ TCODK_PAGEDOWN (PageDown)
+ TCODK_END (End)
+ TCODK_HOME (Home)
+ TCODK_UP (Up)
+ TCODK_LEFT (Left)
+ TCODK_RIGHT (Right)
+ TCODK_DOWN (Down)
+ TCODK_PRINTSCREEN (Printscreen)
+ TCODK_INSERT (Insert)
+ TCODK_DELETE (Delete)
+ TCODK_LWIN (Lwin)
+ TCODK_RWIN (Rwin)
+ TCODK_APPS (Apps)
+ TCODK_KPADD (KeypadAdd)
+ TCODK_KPSUB (KeypadSubtract)
+ TCODK_KPDIV (KeypadDivide)
+ TCODK_KPMUL (KeypadMultiply)
+ TCODK_KPDEC (KeypadDecimal)
+ TCODK_KPENTER (KeypadEnter)
+ TCODK_F1 (F1)
+ TCODK_F2 (F2)
+ TCODK_F3 (F3)
+ TCODK_F4 (F4)
+ TCODK_F5 (F5)
+ TCODK_F6 (F6)
+ TCODK_F7 (F7)
+ TCODK_F8 (F8)
+ TCODK_F9 (F9)
+ TCODK_F10 (F10)
+ TCODK_F11 (F11)
+ TCODK_F12 (F12)
+ TCODK_NUMLOCK (Numlock)
+ TCODK_SCROLLLOCK (Scrolllock)
+ TCODK_SPACE (Space)
+
+ numeric keys :
+
+ TCODK_0 (Zero)
+ TCODK_1 (One)
+ TCODK_2 (Two)
+ TCODK_3 (Three)
+ TCODK_4 (Four)
+ TCODK_5 (Five)
+ TCODK_6 (Six)
+ TCODK_7 (Seven)
+ TCODK_8 (Eight)
+ TCODK_9 (Nine)
+ TCODK_KP0 (KeypadZero)
+ TCODK_KP1 (KeypadOne)
+ TCODK_KP2 (KeypadTwo)
+ TCODK_KP3 (KeypadThree)
+ TCODK_KP4 (KeypadFour)
+ TCODK_KP5 (KeypadFive)
+ TCODK_KP6 (KeypadSix)
+ TCODK_KP7 (KeypadSeven)
+ TCODK_KP8 (KeypadEight)
+ TCODK_KP9 (KeypadNine)
+
+ Any other (printable) key :
+
+ TCODK_CHAR (Char)
+
+ Codes starting with TCODK_KP represents keys on the numeric keypad (if available).
+ */
+
+ /**
+ @PageName console_offscreen
+ @PageFather console
+ @PageTitle Using off-screen consoles
+ @PageDesc The offscreen consoles allow you to draw on secondary consoles as you would do with the root console. You can then blit those secondary consoles on the root console. This allows you to use local coordinate space while rendering a portion of the final screen, and easily move components of the screen without modifying the rendering functions.
+ @FuncTitle Creating an offscreen console
+ @FuncDesc You can create as many off-screen consoles as you want by using this function. You can draw on them as you would do with the root console, but you cannot flush them to the screen. Else, you can blit them on other consoles, including the root console. See blit. The C version of this function returns a console handler that you can use in most console drawing functions.
+ @Cpp TCODConsole::TCODConsole(int w, int h)
+ @C TCOD_console_t TCOD_console_new(int w, int h)
+ @Py console_new(w,h)
+ @C# TCODConsole::TCODConsole(int w, int h)
+ @Lua tcod.Console(w,h)
+ @Param w,h the console size.
+ 0 < w
+ 0 < h
+ @CppEx
+ // Creating a 40x20 offscreen console, filling it with red and blitting it on the root console at position 5,5
+ TCODConsole *offscreenConsole = new TCODConsole(40,20);
+ offscreenConsole->setDefaultBackground(TCODColor::red);
+ offscreenConsole->clear();
+ TCODConsole::blit(offscreenConsole,0,0,40,20,TCODConsole::root,5,5,255);
+ @CEx
+ TCOD_console_t offscreen_console = TCOD_console_new(40,20);
+ TCOD_console_set_default_background(offscreen_console,TCOD_red);
+ TCOD_console_clear(offscreen_console);
+ TCOD_console_blit(offscreen_console,0,0,40,20,NULL,5,5,255);
+ @PyEx
+ offscreen_console = libtcod.console_new(40,20)
+ libtcod.console_set_background_color(offscreen_console,libtcod.red)
+ libtcod.console_clear(offscreen_console)
+ libtcod.console_blit(offscreen_console,0,0,40,20,0,5,5,255)
+ @LuaEx
+ -- Creating a 40x20 offscreen console, filling it with red and blitting it on the root console at position 5,5
+ offscreenConsole = tcod.Console(40,20)
+ offscreenConsole:setBackgroundColor(tcod.color.red)
+ offscreenConsole:clear()
+ tcod.console.blit(offscreenConsole,0,0,40,20,libtcod.TCODConsole_root,5,5,255)
+ */
+ TCODConsole(int w, int h);
+
+ /**
+ @PageName console_offscreen
+ @FuncTitle Creating an offscreen console from a .asc or .apf file
+ @FuncDesc You can create an offscreen console from a file created with Ascii Paint with this constructor
+ @Cpp TCODConsole::TCODConsole(const char *filename)
+ @C TCOD_console_t TCOD_console_from_file(const char *filename)
+ @Param filename path to the .asc or .apf file created with Ascii Paint
+ @CppEx
+ // Creating an offscreen console, filling it with data from the .asc file
+ TCODConsole *offscreenConsole = new TCODConsole("myfile.asc");
+ @CEx
+ TCOD_console_t offscreen_console = TCOD_console_from_file("myfile.apf");
+ */
+ TCODConsole(const char *filename);
+
+ /**
+ @PageName console_offscreen
+ @FuncTitle Loading an offscreen console from a .asc file
+ @FuncDesc You can load data from a file created with Ascii Paint with this function. When needed, the console will be resized to fit the file size. The function returns false if it couldn't read the file.
+ @Cpp bool TCODConsole::loadAsc(const char *filename)
+ @C bool TCOD_console_load_asc(TCOD_console_t con, const char *filename)
+ @Param con in the C and Python versions, the offscreen console handler
+ @Param filename path to the .asc file created with Ascii Paint
+ @CppEx
+ // Creating a 40x20 offscreen console
+ TCODConsole *offscreenConsole = new TCODConsole(40,20);
+ // possibly resizing it and filling it with data from the .asc file
+ offscreenConsole->loadAsc("myfile.asc");
+ @CEx
+ TCOD_console_t offscreen_console = TCOD_console_new(40,20);
+ TCOD_console_load_asc(offscreen_console,"myfile.asc");
+ */
+ bool loadAsc(const char *filename);
+ /**
+ @PageName console_offscreen
+ @FuncTitle Loading an offscreen console from a .apf file
+ @FuncDesc You can load data from a file created with Ascii Paint with this function. When needed, the console will be resized to fit the file size. The function returns false if it couldn't read the file.
+ @Cpp bool TCODConsole::loadApf(const char *filename)
+ @C bool TCOD_console_load_apf(TCOD_console_t con, const char *filename)
+ @Param con in the C and Python versions, the offscreen console handler
+
+ @Param filename path to the .apf file created with Ascii Paint
+
+ @CppEx
+ // Creating a 40x20 offscreen console
+ TCODConsole *offscreenConsole = new TCODConsole(40,20);
+ // possibly resizing it and filling it with data from the .apf file
+ offscreenConsole->loadApf("myfile.apf");
+ @CEx
+ TCOD_console_t offscreen_console = TCOD_console_new(40,20);
+ TCOD_console_load_apf(offscreen_console,"myfile.asc");
+ */
+ bool loadApf(const char *filename);
+
+ /**
+ @PageName console_offscreen
+ @FuncTitle Saving a console to a .asc file
+ @FuncDesc You can save data from a console to Ascii Paint format with this function. The function returns false if it couldn't write the file. This is the only ASC function that works also with the root console !
+ @Cpp bool TCODConsole::saveAsc(const char *filename) const
+ @C bool TCOD_console_save_asc(TCOD_console_t con, const char *filename)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param filename path to the .asc file to be created
+ @CppEx
+ console->saveAsc("myfile.asc");
+ @CEx
+ TCOD_console_save_asc(console,"myfile.asc");
+ */
+ bool saveAsc(const char *filename) const;
+
+ /**
+ @PageName console_offscreen
+ @FuncTitle Saving a console to a .apf file
+ @FuncDesc You can save data from a console to Ascii Paint format with this function. The function returns false if it couldn't write the file. This is the only ASC function that works also with the root console !
+ @Cpp bool TCODConsole::saveApf(const char *filename) const
+ @C bool TCOD_console_save_apf(TCOD_console_t con, const char *filename)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param filename path to the .apf file to be created
+ @CppEx
+ console->saveApf("myfile.apf");
+ @CEx
+ TCOD_console_save_apf(console,"myfile.apf");
+ */
+ bool saveApf(const char *filename) const;
+
+ bool loadXp(const char *filename) {
+ return TCOD_console_load_xp(data, filename) != 0;
+ }
+ bool saveXp(const char *filename, int compress_level) {
+ return TCOD_console_save_xp(data, filename, compress_level) != 0;
+ }
+
+ /**
+ @PageName console_offscreen
+ @FuncTitle Blitting a console on another one
+ @FuncDesc This function allows you to blit a rectangular area of the source console at a specific position on a destination console. It can also simulate alpha transparency with the fade parameter.
+ @Cpp static void blit(const TCODConsole *src,int xSrc, int ySrc, int wSrc, int hSrc, TCODConsole *dst, int xDst, int yDst, float foregroundAlpha=1.0f, float backgroundAlpha=1.0f)
+ @C void TCOD_console_blit(TCOD_console_t src,int xSrc, int ySrc, int wSrc, int hSrc, TCOD_console_t dst, int xDst, int yDst, float foreground_alpha, float background_alpha)
+ @Py console_blit(src,xSrc,ySrc,xSrc,hSrc,dst,xDst,yDst,foregroundAlpha=1.0,backgroundAlpha=1.0)
+ @C#
+ static void TCODConsole::blit(TCODConsole src, int xSrc, int ySrc, int wSrc, int hSrc, TCODConsole dst, int xDst, int yDst)
+ static void TCODConsole::blit(TCODConsole src, int xSrc, int ySrc, int wSrc, int hSrc, TCODConsole dst, int xDst, int yDst, float foreground_alpha)
+ static void TCODConsole::blit(TCODConsole src, int xSrc, int ySrc, int wSrc, int hSrc, TCODConsole dst, int xDst, int yDst, float foreground_alpha, float background_alpha)
+ @Lua
+ tcod.console.blit(src, xSrc, ySrc, wSrc, hSrc, dst, xDst, yDst)
+ tcod.console.blit(src, xSrc, ySrc, wSrc, hSrc, dst, xDst, yDst, foreground_alpha)
+ tcod.console.blit(src, xSrc, ySrc, wSrc, hSrc, dst, xDst, yDst, foreground_alpha, background_alpha)
+ @Param src The source console that must be blitted on another one.
+ @Param xSrc,ySrc,wSrc,hSrc The rectangular area of the source console that will be blitted. If wSrc and/or hSrc == 0, the source console width/height are used
+ @Param dst The destination console.
+ @Param xDst,yDst Where to blit the upper-left corner of the source area in the destination console.
+ @Param foregroundAlpha,backgroundAlpha Alpha transparency of the blitted console.
+ 0.0 => The source console is completely transparent. This function does nothing.
+ 1.0 => The source console is opaque. Its cells replace the destination cells.
+ 0 < fade < 1.0 => The source console is partially blitted, simulating real transparency.
+ @CppEx
+ // Cross-fading between two offscreen consoles. We use two offscreen consoles with the same size as the root console. We render a different screen on each offscreen console. When the user hits a key, we do a cross-fading from the first screen to the second screen.
+ TCODConsole *off1 = new TCODConsole(80,50);
+ TCODConsole *off2 = new TCODConsole(80,50);
+ ... print screen1 on off1
+ ... print screen2 of off2
+ // render screen1 in the game window
+ TCODConsole::blit(off1,0,0,80,50,TCODConsole::root,0,0);
+ TCODConsole::flush();
+ // wait or a keypress
+ TCODConsole::waitForKeypress(true);
+ // do a cross-fading from off1 to off2
+ for (int i=1; i <= 255; i++) {
+ TCODConsole::blit(off1,0,0,80,50,TCODConsole::root,0,0); // renders the first screen (opaque)
+ TCODConsole::blit(off2,0,0,80,50,TCODConsole::root,0,0,i/255.0,i/255.0); // renders the second screen (transparent)
+ TCODConsole::flush();
+ }
+ @CEx
+ TCOD_console_t off1 = TCOD_console_new(80,50);
+ TCOD_console_t off2 = TCOD_console_new(80,50);
+ int i;
+ ... print screen1 on off1
+ ... print screen2 of off2
+ // render screen1 in the game window
+ TCOD_console_blit(off1,0,0,80,50,NULL,0,0,1.0,1.0);
+ TCOD_console_flush();
+ // wait or a keypress
+ TCOD_console_wait_for_keypress(true);
+ // do a cross-fading from off1 to off2
+ for (i=1; i <= 255; i++) {
+ TCOD_console_blit(off1,0,0,80,50,NULL,0,0,1.0,1.0); // renders the first screen (opaque)
+ TCOD_console_blit(off2,0,0,80,50,NULL,0,0,i/255.0,i/255.0); // renders the second screen (transparent)
+ TCOD_console_flush();
+ }
+ @PyEx
+ off1 = libtcod.console_new(80,50)
+ off2 = libtcod.console_new(80,50)
+ ... print screen1 on off1
+ ... print screen2 of off2
+ # render screen1 in the game window
+ libtcod.console_blit(off1,0,0,80,50,0,0,0)
+ libtcod.console_flush()
+ # wait or a keypress
+ libtcod.console_wait_for_keypress(True)
+ # do a cross-fading from off1 to off2
+ for i in range(1,256) :
+ litbcod.console_blit(off1,0,0,80,50,0,0,0) # renders the first screen (opaque)
+ litbcod.console_blit(off2,0,0,80,50,0,0,0,i/255.0,i/255.0) # renders the second screen (transparent)
+ litbcod.console_flush()
+ @LuaEx
+ -- Cross-fading between two offscreen consoles. We use two offscreen consoles with the same size as the root console. We render a different screen on each offscreen console. When the user hits a key, we do a cross-fading from the first screen to the second screen.
+ off1 = tcod.Console(80,50)
+ off2 = tcod.Console(80,50)
+ ... print screen1 on off1
+ ... print screen2 of off2
+ -- render screen1 in the game window
+ root=libtcod.TCODConsole_root
+ tcod.console.blit(off1,0,0,80,50,root,0,0)
+ tcod.console.flush()
+ -- wait or a keypress
+ tcod.console.waitForKeypress(true)
+ -- do a cross-fading from off1 to off2
+ for i=1,255,1 do
+ tcod.console.blit(off1,0,0,80,50,root,0,0) -- renders the first screen (opaque)
+ tcod.console.blit(off2,0,0,80,50,root,0,0,i/255,i/255) -- renders the second screen (transparent)
+ tcod.console.flush()
+ end
+ */
+ static void blit(const TCODConsole *src,int xSrc, int ySrc, int wSrc, int hSrc, TCODConsole *dst, int xDst, int yDst, float foreground_alpha=1.0f, float background_alpha=1.0f);
+ /**
+ @PageName console_offscreen
+ @FuncTitle Define a blit-transparent color
+ @FuncDesc This function defines a transparent background color for an offscreen console. All cells with this background color are ignored by the blit operation. You can use it to blit only some parts of the console.
+ @Cpp void TCODConsole::setKeyColor(const TCODColor &col)
+ @C void TCOD_console_set_key_color(TCOD_console_t con,TCOD_color_t col)
+ @Py console_set_key_color(con,col)
+ @C# void TCODConsole::setKeyColor(TCODColor col)
+ @Lua Console:setKeyColor(col)
+ @Param con in the C and Python versions, the offscreen console handler or NULL for the root console
+ @Param col the transparent background color
+ */
+ void setKeyColor(const TCODColor &col);
+ /**
+ @PageName console_offscreen
+ @FuncTitle Destroying an offscreen console
+ @FuncDesc Use this function to destroy an offscreen console and release any resources allocated. Don't use it on the root console.
+ @Cpp TCODConsole::~TCODConsole()
+ @C void TCOD_console_delete(TCOD_console_t con)
+ @Py console_delete(con)
+ @C# void TCODConsole::Dispose()
+ @Lua through garbage collector
+ @Param con in the C and Python versions, the offscreen console handler
+ @CppEx
+ TCODConsole *off1 = new TCODConsole(80,50);
+ ... use off1
+ delete off1; // destroy the offscreen console
+ @CEx
+ TCOD_console_t off1 = TCOD_console_new(80,50);
+ ... use off1
+ TCOD_console_delete(off1); // destroy the offscreen console
+ @PyEx
+ off1 = libtcod.console_new(80,50)
+ ... use off1
+ libtcod.console_delete(off1) # destroy the offscreen console
+ @LuaEx
+ off1 = tcod.Console(80,50)
+ ... use off1
+ off1=nil -- release the reference
+ */
+ TCOD_DEPRECATED("This function is a stub and will do nothing.")
+ static void setKeyboardRepeat(int initialDelay,int interval);
+ TCOD_DEPRECATED("This function is a stub and will do nothing.")
+ static void disableKeyboardRepeat();
+
+ virtual ~TCODConsole();
+
+ void setDirty(int x, int y, int w, int h);
+
+
+ TCODConsole(TCOD_console_t con) : data(con) {}
+
+ // ctrl = TCOD_COLCTRL_1...TCOD_COLCTRL_5 or TCOD_COLCTRL_STOP
+ static const char *getColorControlString( TCOD_colctrl_t ctrl );
+ // ctrl = TCOD_COLCTRL_FORE_RGB or TCOD_COLCTRL_BACK_RGB
+ static const char *getRGBColorControlString( TCOD_colctrl_t ctrl, const TCODColor & col );
+
+protected :
+ friend class TCODImage;
+ friend class TCODZip;
+ friend class TCODText;
+ friend TCODLIB_API void tcod::console::init_root(
+ int w, int h, const std::string& title,
+ bool fullscreen, TCOD_renderer_t renderer, bool vsync);
+ TCODConsole();
+ TCOD_Console* data;
+};
+
+#endif /* TCOD_CONSOLE_SUPPORT */
+
+#endif /* _TCOD_CONSOLE_HPP */
diff --git a/tcod_sys/libtcod/src/libtcod/console/console.h b/tcod_sys/libtcod/src/libtcod/console/console.h
new file mode 100644
index 000000000..43fdff373
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/console/console.h
@@ -0,0 +1,427 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef TCOD_CONSOLE_CONSOLE_H_
+#define TCOD_CONSOLE_CONSOLE_H_
+
+#ifdef __cplusplus
+#include
+#include
+#include
+#endif // __cplusplus
+
+#include "../portability.h"
+#include "../color/color.h"
+#include "../utility/matrix.h"
+/**
+ * \enum TCOD_bkgnd_flag_t
+ *
+ * Background color blend modes.
+ */
+typedef enum {
+ TCOD_BKGND_NONE,
+ TCOD_BKGND_SET,
+ TCOD_BKGND_MULTIPLY,
+ TCOD_BKGND_LIGHTEN,
+ TCOD_BKGND_DARKEN,
+ TCOD_BKGND_SCREEN,
+ TCOD_BKGND_COLOR_DODGE,
+ TCOD_BKGND_COLOR_BURN,
+ TCOD_BKGND_ADD,
+ TCOD_BKGND_ADDA,
+ TCOD_BKGND_BURN,
+ TCOD_BKGND_OVERLAY,
+ TCOD_BKGND_ALPH,
+ TCOD_BKGND_DEFAULT
+} TCOD_bkgnd_flag_t;
+/**
+ * \enum TCOD_alignment_t
+ *
+ * Print justification options.
+ */
+typedef enum {
+ TCOD_LEFT,
+ TCOD_RIGHT,
+ TCOD_CENTER
+} TCOD_alignment_t;
+/**
+ * A console tile.
+ */
+struct TCOD_ConsoleTile {
+#ifdef __cplusplus
+ bool operator==(const TCOD_ConsoleTile& rhs) const noexcept
+ {
+ return ch == rhs.ch && fg == rhs.fg && bg == rhs.bg;
+ }
+ bool operator!=(const TCOD_ConsoleTile& rhs) const noexcept
+ {
+ return !(*this == rhs);
+ }
+#endif // __cplusplus
+ /**
+ * The Unicode codepoint for this tile.
+ */
+ int ch;
+ /**
+ * The tile glyph color, rendered on top of the background.
+ */
+ struct TCOD_ColorRGBA fg;
+ /**
+ * The tile background color, rendered behind the glyph.
+ */
+ struct TCOD_ColorRGBA bg;
+};
+/**
+ * The libtcod console struct.
+ *
+ * All attributes should be considered private.
+ *
+ * All C++ methods should be considered provisional, and are subject to
+ * change.
+ */
+struct TCOD_Console {
+#ifdef __cplusplus
+ struct TCOD_ConsoleTile* begin() noexcept
+ {
+ return tiles;
+ }
+ const struct TCOD_ConsoleTile* begin() const noexcept
+ {
+ return tiles;
+ }
+ struct TCOD_ConsoleTile* end() noexcept
+ {
+ return tiles + w * h;
+ }
+ const struct TCOD_ConsoleTile* end() const noexcept
+ {
+ return tiles + w * h;
+ }
+ auto operator[](const std::array& yx) noexcept
+ -> struct TCOD_ConsoleTile&
+ {
+ return tiles[w * yx[0] + yx[1]];
+ }
+ auto operator[](const std::array& yx) const noexcept
+ -> const struct TCOD_ConsoleTile&
+ {
+ return tiles[w * yx[0] + yx[1]];
+ }
+ struct TCOD_ConsoleTile& at(int y, int x)
+ {
+ range_check_(y, x);
+ return (*this)[{y, x}];
+ }
+ const struct TCOD_ConsoleTile& at(int y, int x) const
+ {
+ range_check_(y, x);
+ return (*this)[{y, x}];
+ }
+ int size() const
+ {
+ return w * h;
+ }
+ void range_check_(int y, int x) const
+ {
+ if (!in_bounds(y, x)) {
+ throw std::out_of_range(
+ std::string("Out of bounds lookup {x=")
+ + std::to_string(x)
+ + ", y="
+ + std::to_string(y)
+ + "} on console of shape {"
+ + std::to_string(w)
+ + ", "
+ + std::to_string(h)
+ + "}.");
+ }
+ }
+ bool in_bounds(int y, int x) const noexcept
+ {
+ return 0 <= x && x < w && 0 <= y && y < h;
+ }
+#endif // __cplusplus
+ /** Console width and height (in characters, not pixels.) */
+ int w,h;
+ /** A contiguous array of console tiles. */
+ struct TCOD_ConsoleTile* tiles;
+ /** Default background operator for print & print_rect functions. */
+ TCOD_bkgnd_flag_t bkgnd_flag;
+ /** Default alignment for print & print_rect functions. */
+ TCOD_alignment_t alignment;
+ /** Foreground (text) and background colors. */
+ TCOD_color_t fore, back;
+ /** True if a key color is being used. */
+ bool has_key_color;
+ /** The current key color for this console. */
+ TCOD_color_t key_color;
+};
+typedef struct TCOD_Console TCOD_Console;
+typedef struct TCOD_Console *TCOD_console_t;
+/**
+ * Return a new console with a specific number of columns and rows.
+ *
+ * \param w Number of columns.
+ * \param h Number of columns.
+ * \return A pointer to the new console, or NULL on error.
+ */
+TCODLIB_CAPI TCOD_Console* TCOD_console_new(int w, int h);
+/**
+ * Return the width of a console.
+ */
+TCODLIB_CAPI int TCOD_console_get_width(const TCOD_Console* con);
+/**
+ * Return the height of a console.
+ */
+TCODLIB_CAPI int TCOD_console_get_height(const TCOD_Console* con);
+TCODLIB_CAPI void TCOD_console_set_key_color(
+ TCOD_Console* con, TCOD_color_t col);
+/**
+ * Blit from one console to another.
+ *
+ * \param srcCon Pointer to the source console.
+ * \param xSrc The left region of the source console to blit from.
+ * \param ySrc The top region of the source console to blit from.
+ * \param wSrc The width of the region to blit from.
+ * If 0 then it will fill to the maximum width.
+ * \param hSrc The height of the region to blit from.
+ * If 0 then it will fill to the maximum height.
+ * \param dstCon Pointer to the destination console.
+ * \param xDst The left corner to blit onto the destination console.
+ * \param yDst The top corner to blit onto the destination console.
+ * \param foreground_alpha Foreground blending alpha.
+ * \param background_alpha Background blending alpha.
+ *
+ * If the source console has a key color, this function will use it.
+ */
+TCODLIB_CAPI void TCOD_console_blit(
+ const TCOD_Console* src,
+ int xSrc,
+ int ySrc,
+ int wSrc,
+ int hSrc,
+ TCOD_Console* dst,
+ int xDst,
+ int yDst,
+ float foreground_alpha,
+ float background_alpha);
+TCODLIB_CAPI void TCOD_console_blit_key_color(
+ const TCOD_Console* src,
+ int xSrc,
+ int ySrc,
+ int wSrc,
+ int hSrc,
+ TCOD_Console* dst,
+ int xDst,
+ int yDst,
+ float foreground_alpha,
+ float background_alpha,
+ const TCOD_color_t *key_color);
+/**
+ * Delete a console.
+ *
+ * \param con A console pointer.
+ *
+ * If the console being deleted is the root console, then the display will be
+ * uninitialized.
+ */
+TCODLIB_CAPI void TCOD_console_delete(TCOD_Console* console);
+
+TCODLIB_CAPI void TCOD_console_set_default_background(
+ TCOD_Console* con, TCOD_color_t col);
+TCODLIB_CAPI void TCOD_console_set_default_foreground(
+ TCOD_Console* con, TCOD_color_t col);
+/**
+ * Clear a console to its default colors and the space character code.
+ */
+TCODLIB_CAPI void TCOD_console_clear(TCOD_Console* con);
+/**
+ * Blend a background color onto a console tile.
+ *
+ * \param con A console pointer.
+ * \param x The X coordinate, the left-most position being 0.
+ * \param y The Y coordinate, the top-most position being 0.
+ * \param col The background color to blend.
+ * \param flag The blend mode to use.
+ */
+TCODLIB_CAPI void TCOD_console_set_char_background(
+ TCOD_Console* con,
+ int x,
+ int y,
+ TCOD_color_t col,
+ TCOD_bkgnd_flag_t flag);
+/**
+ * Change the foreground color of a console tile.
+ *
+ * \param con A console pointer.
+ * \param x The X coordinate, the left-most position being 0.
+ * \param y The Y coordinate, the top-most position being 0.
+ * \param col The foreground color to set.
+ */
+TCODLIB_CAPI void TCOD_console_set_char_foreground(
+ TCOD_Console* con, int x, int y, TCOD_color_t col);
+/**
+ * Change a character on a console tile, without changing its colors.
+ *
+ * \param con A console pointer.
+ * \param x The X coordinate, the left-most position being 0.
+ * \param y The Y coordinate, the top-most position being 0.
+ * \param c The character code to set.
+ */
+TCODLIB_CAPI void TCOD_console_set_char(
+ TCOD_Console* con, int x, int y, int c);
+/**
+ * Draw a character on a console using the default colors.
+ *
+ * \param con A console pointer.
+ * \param x The X coordinate, the left-most position being 0.
+ * \param y The Y coordinate, the top-most position being 0.
+ * \param c The character code to place.
+ * \param flag A TCOD_bkgnd_flag_t flag.
+ */
+TCODLIB_CAPI void TCOD_console_put_char(
+ TCOD_Console* con, int x, int y, int c, TCOD_bkgnd_flag_t flag);
+/**
+ * Draw a character on the console with the given colors.
+ *
+ * \param con A console pointer.
+ * \param x The X coordinate, the left-most position being 0.
+ * \param y The Y coordinate, the top-most position being 0.
+ * \param c The character code to place.
+ * \param fore The foreground color.
+ * \param back The background color. This color will not be blended.
+ */
+TCODLIB_CAPI void TCOD_console_put_char_ex(
+ TCOD_Console* con,
+ int x,
+ int y,
+ int c,
+ TCOD_color_t fore, TCOD_color_t back);
+/**
+ * Set a consoles default background flag.
+ *
+ * \param con A console pointer.
+ * \param flag One of `TCOD_bkgnd_flag_t`.
+ */
+TCODLIB_CAPI void TCOD_console_set_background_flag(
+ TCOD_Console* con,
+ TCOD_bkgnd_flag_t flag);
+/**
+ * Return a consoles default background flag.
+ */
+TCODLIB_CAPI TCOD_bkgnd_flag_t TCOD_console_get_background_flag(
+ TCOD_Console* con);
+/**
+ * Set a consoles default alignment.
+ *
+ * \param con A console pointer.
+ * \param alignment One of TCOD_alignment_t
+ */
+TCODLIB_CAPI void TCOD_console_set_alignment(
+ TCOD_Console* con,
+ TCOD_alignment_t alignment);
+/**
+ * Return a consoles default alignment.
+ */
+TCODLIB_CAPI TCOD_alignment_t TCOD_console_get_alignment(TCOD_Console* con);
+
+TCODLIB_CAPI TCOD_color_t TCOD_console_get_default_background(
+ TCOD_Console* con);
+TCODLIB_CAPI TCOD_color_t TCOD_console_get_default_foreground(
+ TCOD_Console* con);
+/**
+ * Return the background color of a console at x,y
+ *
+ * \param con A console pointer.
+ * \param x The X coordinate, the left-most position being 0.
+ * \param y The Y coordinate, the top-most position being 0.
+ * \return A TCOD_color_t struct with a copy of the background color.
+ */
+TCODLIB_CAPI TCOD_color_t TCOD_console_get_char_background(
+ const TCOD_Console* con, int x, int y);
+/**
+ * Return the foreground color of a console at x,y
+ *
+ * \param con A console pointer.
+ * \param x The X coordinate, the left-most position being 0.
+ * \param y The Y coordinate, the top-most position being 0.
+ * \return A TCOD_color_t struct with a copy of the foreground color.
+ */
+TCODLIB_CAPI TCOD_color_t TCOD_console_get_char_foreground(
+ const TCOD_Console* con, int x, int y);
+/**
+ * Return a character code of a console at x,y
+ *
+ * \param con A console pointer.
+ * \param x The X coordinate, the left-most position being 0.
+ * \param y The Y coordinate, the top-most position being 0.
+ * \return The character code.
+ */
+TCODLIB_CAPI int TCOD_console_get_char(const TCOD_Console* con, int x, int y);
+/**
+ * Fade the color of the display.
+ *
+ * \param val Where at 255 colors are normal and at 0 colors are completely
+ * faded.
+ * \param fadecol Color to fade towards.
+ */
+TCODLIB_CAPI void TCOD_console_set_fade(uint8_t val, TCOD_color_t fade);
+/**
+ * Return the fade value.
+ *
+ * \return At 255 colors are normal and at 0 colors are completely faded.
+ */
+TCODLIB_CAPI uint8_t TCOD_console_get_fade(void);
+/**
+ * Return the fade color.
+ *
+ * \return The current fading color.
+ */
+TCODLIB_CAPI TCOD_color_t TCOD_console_get_fading_color(void);
+TCODLIB_CAPI void TCOD_console_resize_(
+ TCOD_Console* console, int width, int height);
+#ifdef __cplusplus
+namespace tcod {
+namespace console {
+ typedef struct TCOD_ConsoleTile Tile;
+ typedef MatrixView ConsoleView;
+ inline ConsoleView as_view_(struct TCOD_Console& console)
+ {
+ return {console.tiles, {console.h, console.w}};
+ }
+ inline const ConsoleView as_view_(const struct TCOD_Console& console)
+ {
+ return {console.tiles, {console.h, console.w}};
+ }
+} // namespace console
+} // namespace tcod
+#endif // __cplusplus
+#endif // TCOD_CONSOLE_CONSOLE_H_
diff --git a/tcod_sys/libtcod/src/libtcod/console/console_clobbered.cpp b/tcod_sys/libtcod/src/libtcod/console/console_clobbered.cpp
new file mode 100644
index 000000000..106c2d2c7
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/console/console_clobbered.cpp
@@ -0,0 +1,431 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "console.h"
+#include "../libtcod_int.h"
+TCOD_Console* TCOD_console_new(int w, int h)
+{
+ TCOD_IFNOT(w > 0 && h > 0 ) { return NULL; }
+ struct TCOD_Console *con = new TCOD_Console{};
+ if (!con) { return NULL; }
+ con->w = w;
+ con->h = h;
+ TCOD_console_init(con);
+ if (TCOD_ctx.root) {
+ con->alignment = TCOD_ctx.root->alignment;
+ con->bkgnd_flag = TCOD_ctx.root->bkgnd_flag;
+ }
+ return con;
+}
+static void TCOD_console_data_alloc(struct TCOD_Console& console)
+{
+ int size = console.w * console.h;
+ if (!console.tiles) { console.tiles = new struct TCOD_ConsoleTile[size](); }
+}
+static void TCOD_console_data_free(struct TCOD_Console *con)
+{
+ if (!con) { return; }
+ delete[] con->tiles;
+ con->tiles = nullptr;
+}
+bool TCOD_console_init(TCOD_Console* con)
+{
+ con = TCOD_console_validate_(con);
+ TCOD_IFNOT(con) { return false; }
+ con->fore = TCOD_white;
+ con->back = TCOD_black;
+
+ TCOD_console_data_alloc(*con);
+
+ con->bkgnd_flag = TCOD_BKGND_NONE;
+ con->alignment = TCOD_LEFT;
+ TCOD_console_clear(con);
+ return true;
+}
+bool TCOD_console_init(TCOD_Console* con, const std::string& title,
+ bool fullscreen)
+{
+ if (!TCOD_console_init(con)) { return false; }
+ if (!TCOD_sys_init(con, fullscreen) ) { return false; }
+ TCOD_sys_set_window_title(title.c_str());
+ return true;
+}
+void TCOD_console_delete(TCOD_Console* con)
+{
+ TCOD_Console* console = (con ? con : TCOD_ctx.root);
+ if (!console) { return; }
+ TCOD_console_data_free(console);
+ delete console;
+ if (console == TCOD_ctx.root) {
+ TCOD_ctx.root = nullptr;
+ }
+ if (con == nullptr) {
+ TCOD_sys_shutdown();
+ }
+}
+void TCOD_console_resize_(TCOD_Console* console, int width, int height)
+{
+ console = TCOD_console_validate_(console);
+ if (!console) { return; }
+ if (console->w == width && console->h == height) { return; }
+ TCOD_console_data_free(console);
+ console->w = width;
+ console->h = height;
+ TCOD_console_data_alloc(*console);
+}
+int TCOD_console_get_width(const TCOD_Console* con)
+{
+ con = TCOD_console_validate_(con);
+ return (con ? con->w : 0);
+}
+int TCOD_console_get_height(const TCOD_Console* con)
+{
+ con = TCOD_console_validate_(con);
+ return (con ? con->h : 0);
+}
+void TCOD_console_set_background_flag(TCOD_Console* con,
+ TCOD_bkgnd_flag_t flag)
+{
+ con = TCOD_console_validate_(con);
+ if (con) { con->bkgnd_flag = flag; }
+}
+TCOD_bkgnd_flag_t TCOD_console_get_background_flag(TCOD_Console* con)
+{
+ con = TCOD_console_validate_(con);
+ return (con ? con->bkgnd_flag : TCOD_BKGND_NONE);
+}
+void TCOD_console_set_alignment(TCOD_Console* con, TCOD_alignment_t alignment)
+{
+ con = TCOD_console_validate_(con);
+ if (con) { con->alignment = alignment; }
+}
+TCOD_alignment_t TCOD_console_get_alignment(TCOD_console_t con)
+{
+ con = TCOD_console_validate_(con);
+ return (con ? con->alignment : TCOD_LEFT);
+}
+/**
+ * A modified lerp operation which can accept RGBA types.
+ */
+static auto TCOD_console_blit_lerp_(
+ const struct TCOD_ColorRGBA color1,
+ const struct TCOD_ColorRGBA color2,
+ float interp)
+-> struct TCOD_ColorRGBA
+{
+ return tcod::ColorRGBA{
+ TCOD_color_lerp(tcod::ColorRGB(color1), tcod::ColorRGB(color2), interp),
+ color1.a,
+ };
+}
+/**
+ * Return the tile for a blit operation between src and dst.
+ */
+static auto TCOD_console_blit_cell_(
+ const struct TCOD_ConsoleTile& src,
+ const struct TCOD_ConsoleTile& dst,
+ float fg_alpha,
+ float bg_alpha,
+ const TCOD_ColorRGB* key_color)
+-> struct TCOD_ConsoleTile
+{
+ if (key_color && tcod::ColorRGB(src.bg) == *key_color) {
+ return dst; // Source pixel is transparent.
+ }
+ if (fg_alpha >= 1.0f && bg_alpha >= 1.0f) {
+ return src; // No alpha. Perform a plain copy.
+ }
+ int ch = dst.ch;
+ tcod::ColorRGBA bg(dst.bg);
+ tcod::ColorRGBA fg(dst.fg);
+ bg = TCOD_console_blit_lerp_(bg, src.bg, bg_alpha);
+ if (src.ch == ' ') {
+ // Source is space, so keep the current glyph.
+ fg = TCOD_console_blit_lerp_(fg, src.bg, bg_alpha);
+ } else if (ch == ' ') {
+ // Destination is space, so use the glyph from source.
+ ch = src.ch;
+ fg = TCOD_console_blit_lerp_(bg, src.fg, fg_alpha);
+ } else if (ch == src.ch) {
+ fg = TCOD_console_blit_lerp_(fg, src.fg, fg_alpha);
+ } else {
+ /* Pick the glyph based on foreground_alpha. */
+ if (fg_alpha < 0.5f) {
+ fg = TCOD_console_blit_lerp_(fg, bg, fg_alpha * 2);
+ } else {
+ ch = src.ch;
+ fg = TCOD_console_blit_lerp_(bg, src.fg, (fg_alpha - 0.5f) * 2);
+ }
+ }
+ return {ch, fg, bg};
+}
+void TCOD_console_blit_key_color(
+ const TCOD_Console* src,
+ int xSrc,
+ int ySrc,
+ int wSrc,
+ int hSrc,
+ TCOD_Console* dst,
+ int xDst,
+ int yDst,
+ float foreground_alpha,
+ float background_alpha,
+ const TCOD_color_t* key_color)
+{
+ src = TCOD_console_validate_(src);
+ dst = TCOD_console_validate_(dst);
+ if (!src || !dst) { return; }
+ if (wSrc == 0) { wSrc = src->w; }
+ if (hSrc == 0) { hSrc = src->h; }
+ TCOD_IFNOT(wSrc > 0 && hSrc > 0) { return; }
+ TCOD_IFNOT(xDst + wSrc >= 0 && yDst + hSrc >= 0
+ && xDst < dst->w && yDst < dst->h) { return; }
+ for (int cx = xSrc; cx < xSrc + wSrc; ++cx) {
+ for (int cy = ySrc; cy < ySrc + hSrc; ++cy) {
+ /* Check if we're outside the dest console. */
+ int dx = cx - xSrc + xDst;
+ int dy = cy - ySrc + yDst;
+ if (!src->in_bounds(cy, cx)) { continue; }
+ if (!dst->in_bounds(dy, dx)) { continue; }
+ dst->at(dy, dx) = TCOD_console_blit_cell_(
+ src->at(cy, cx),
+ dst->at(dy, dx),
+ foreground_alpha,
+ background_alpha,
+ key_color);
+ }
+ }
+}
+void TCOD_console_blit(
+ const TCOD_Console* src,
+ int xSrc,
+ int ySrc,
+ int wSrc,
+ int hSrc,
+ TCOD_Console* dst,
+ int xDst,
+ int yDst,
+ float foreground_alpha,
+ float background_alpha)
+{
+ src = TCOD_console_validate_(src);
+ if (!src) { return; }
+ TCOD_console_blit_key_color(
+ src, xSrc, ySrc, wSrc, hSrc, dst, xDst, yDst,
+ foreground_alpha, background_alpha,
+ (src->has_key_color ? &src->key_color : NULL));
+}
+void TCOD_console_put_char(TCOD_Console* con, int x, int y, int c,
+ TCOD_bkgnd_flag_t flag)
+{
+ con = TCOD_console_validate_(con);
+ if (!TCOD_console_is_index_valid_(con, x, y)) { return; }
+ con->tiles[y * con->w + x].ch = c;
+ TCOD_console_set_char_foreground(con, x, y, con->fore);
+ TCOD_console_set_char_background(con, x, y, con->back, flag);
+}
+void TCOD_console_put_char_ex(TCOD_console_t con, int x, int y, int c,
+ TCOD_color_t fore, TCOD_color_t back)
+{
+ con = TCOD_console_validate_(con);
+ if (!TCOD_console_is_index_valid_(con, x, y)) { return; }
+ con->tiles[y * con->w + x].ch = c;
+ TCOD_console_set_char_foreground(con, x, y, fore);
+ TCOD_console_set_char_background(con, x, y, back, TCOD_BKGND_SET);
+}
+void TCOD_console_clear(TCOD_console_t con)
+{
+ con = TCOD_console_validate_(con);
+ TCOD_IFNOT(con) { return; }
+ for (auto& tile : *con) {
+ tile = {' ', tcod::ColorRGBA(con->fore), tcod::ColorRGBA(con->back)};
+ }
+ /* clear the sdl renderer cache */
+ TCOD_sys_set_dirty(0, 0, con->w, con->h);
+}
+TCOD_color_t TCOD_console_get_char_background(const TCOD_Console* con,
+ int x, int y)
+{
+ con = TCOD_console_validate_(con);
+ if (!TCOD_console_is_index_valid_(con, x, y)) { return TCOD_black; }
+ return tcod::ColorRGB(con->tiles[y * con->w + x].bg);
+}
+void TCOD_console_set_char_foreground(TCOD_Console* con,
+ int x, int y, TCOD_color_t col)
+{
+ con = TCOD_console_validate_(con);
+ if (!TCOD_console_is_index_valid_(con, x, y)) { return; }
+ con->tiles[y * con->w + x].fg = tcod::ColorRGBA(col);
+}
+TCOD_color_t TCOD_console_get_char_foreground(const TCOD_Console* con,
+ int x, int y)
+{
+ con = TCOD_console_validate_(con);
+ if (!TCOD_console_is_index_valid_(con, x, y)) { return TCOD_white; }
+ return tcod::ColorRGB(con->tiles[y * con->w + x].fg);
+}
+int TCOD_console_get_char(const TCOD_Console* con, int x, int y)
+{
+ con = TCOD_console_validate_(con);
+ if (!TCOD_console_is_index_valid_(con, x, y)) { return 0; }
+ return con->tiles[y * con->w + x].ch;
+}
+/**
+ * Clamp colors channels that are outside of uint8_t's range.
+ */
+static constexpr uint8_t clamp_color_(uint8_t c) noexcept { return c; }
+static constexpr uint8_t clamp_color_(int c) noexcept
+{
+ return static_cast(std::max(0, std::min(c, 255)));
+}
+/**
+ * Mix two colors using a lambda.
+ */
+template
+static constexpr TCOD_ColorRGBA blend_color_(
+ const TCOD_ColorRGBA& bg, const TCOD_color_t& fg, const F& lambda)
+{
+ return {
+ clamp_color_(lambda(bg.r, fg.r)),
+ clamp_color_(lambda(bg.g, fg.g)),
+ clamp_color_(lambda(bg.b, fg.b)),
+ bg.a,
+ };
+}
+void TCOD_console_set_char_background(
+ TCOD_Console* con, int x, int y, TCOD_color_t col, TCOD_bkgnd_flag_t flag)
+{
+ con = TCOD_console_validate_(con);
+ if (!TCOD_console_is_index_valid_(con, x, y)) { return; }
+ TCOD_ColorRGBA& bg = con->tiles[y * con->w + x].bg;
+ if (flag == TCOD_BKGND_DEFAULT) { flag = con->bkgnd_flag; }
+ int alpha = flag >> 8;
+ switch (flag & 0xff) {
+ case TCOD_BKGND_SET:
+ bg = tcod::ColorRGBA(col, bg.a);
+ break;
+ case TCOD_BKGND_MULTIPLY:
+ bg = tcod::ColorRGBA(TCOD_color_multiply(tcod::ColorRGB(bg), col), bg.a);
+ break;
+ case TCOD_BKGND_LIGHTEN:
+ bg = blend_color_(bg, col,
+ [](uint8_t a, uint8_t b){ return std::max(a, b); });
+ break;
+ case TCOD_BKGND_DARKEN:
+ bg = blend_color_(bg, col,
+ [](uint8_t a, uint8_t b){ return std::min(a, b); });
+ break;
+ case TCOD_BKGND_SCREEN:
+ // newbk = white - (white - oldbk) * (white - curbk)
+ bg = blend_color_(bg, col,
+ [](int a, int b){ return 255 - (255 - a) * (255 - b) / 255; });
+ break;
+ case TCOD_BKGND_COLOR_DODGE:
+ // newbk = curbk / (white - oldbk)
+ bg = blend_color_(bg, col,
+ [](int a, int b){ return (a == 255 ? 255 : 255 * b / (255 - a)); });
+ break;
+ case TCOD_BKGND_COLOR_BURN:
+ // newbk = white - (white - oldbk) / curbk
+ bg = blend_color_(bg, col,
+ [](int a, int b){
+ return (b == 0 ? 0 : 255 - (255 * (255 - a)) / b); });
+ break;
+ case TCOD_BKGND_ADD:
+ // newbk = oldbk + curbk
+ bg = blend_color_(bg, col, [](int a, int b){ return a + b; });
+ break;
+ case TCOD_BKGND_ADDA:
+ // newbk = oldbk + alpha * curbk
+ bg = blend_color_(bg, col,
+ [=](int a, int b){ return a + alpha * b / 255; });
+ break;
+ case TCOD_BKGND_BURN:
+ // newbk = oldbk + curbk - white
+ bg = blend_color_(bg, col, [](int a, int b){ return a + b - 255; });
+ break;
+ case TCOD_BKGND_OVERLAY:
+ // newbk = curbk.x <= 0.5 ? 2*curbk*oldbk
+ // : white - 2*(white-curbk)*(white-oldbk)
+ bg = blend_color_(bg, col, [](int a, int b){
+ return (b <= 128 ? 2 * b * a / 255
+ : 255 - 2 * (255 - b) * (255 - a) / 255); });
+ break;
+ case TCOD_BKGND_ALPH:
+ // newbk = (1.0f-alpha)*oldbk + alpha*(curbk-oldbk)
+ bg = tcod::ColorRGBA(TCOD_color_lerp(tcod::ColorRGB(bg), col, alpha / 255.0f), bg.a);
+ break;
+ default: break;
+ }
+}
+void TCOD_console_set_char(TCOD_console_t con, int x, int y, int c)
+{
+ con = TCOD_console_validate_(con);
+ if (!TCOD_console_is_index_valid_(con, x, y)) { return; }
+ con->tiles[y * con->w + x].ch = c;
+}
+void TCOD_console_set_default_foreground(TCOD_Console* con, TCOD_color_t col)
+{
+ con = TCOD_console_validate_(con);
+ TCOD_IFNOT(con) { return; }
+ con->fore = col;
+}
+void TCOD_console_set_default_background(TCOD_Console* con,TCOD_color_t col)
+{
+ con = TCOD_console_validate_(con);
+ TCOD_IFNOT(con) { return; }
+ con->back = col;
+}
+TCOD_color_t TCOD_console_get_default_foreground(TCOD_Console* con)
+{
+ con = TCOD_console_validate_(con);
+ TCOD_IFNOT(con) { return TCOD_white; }
+ return con->fore;
+}
+TCOD_color_t TCOD_console_get_default_background(TCOD_Console* con)
+{
+ con = TCOD_console_validate_(con);
+ TCOD_IFNOT(con) { return TCOD_black; }
+ return con->back;
+}
+void TCOD_console_set_fade(uint8_t val, TCOD_color_t fadecol)
+{
+ TCOD_ctx.fade = val;
+ TCOD_ctx.fading_color = fadecol;
+}
+uint8_t TCOD_console_get_fade(void)
+{
+ return TCOD_ctx.fade;
+}
+TCOD_color_t TCOD_console_get_fading_color(void)
+{
+ return TCOD_ctx.fading_color;
+}
diff --git a/tcod_sys/libtcod/src/libtcod/console/drawing.cpp b/tcod_sys/libtcod/src/libtcod/console/drawing.cpp
new file mode 100644
index 000000000..6972f487f
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/console/drawing.cpp
@@ -0,0 +1,118 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "drawing.h"
+
+#include "../libtcod_int.h"
+#include "../console.h"
+namespace tcod {
+namespace console {
+/**
+ * Clamp the given values to fit within a console.
+ */
+static void clamp_rect_(int cx, int cy, int cw, int ch,
+ int& x, int& y, int& w, int& h)
+{
+ if (x + w > cw) { w = cw - x; }
+ if (y + h > ch) { h = ch - y; }
+ if (x < cx) {
+ w -= cx - x;
+ x = cx;
+ }
+ if (y < cy) {
+ h -= cy - y;
+ y = cy;
+ }
+}
+void put(
+ TCOD_Console* console,
+ int x,
+ int y,
+ int ch,
+ const TCOD_color_t* fg,
+ const TCOD_color_t* bg,
+ TCOD_bkgnd_flag_t flag)
+{
+ console = TCOD_console_validate_(console);
+ if (!console) { return; }
+ if (!TCOD_console_is_index_valid_(console, x, y)) { return; }
+ int console_index = y * console->w + x;
+ if (ch > 0) { console->tiles[console_index].ch = ch; }
+ if (fg) { TCOD_console_set_char_foreground(console, x, y, *fg); }
+ if (bg) { TCOD_console_set_char_background(console, x, y, *bg, flag); }
+}
+void draw_rect(
+ TCOD_Console* console,
+ int x,
+ int y,
+ int width,
+ int height,
+ int ch,
+ const TCOD_color_t* fg,
+ const TCOD_color_t* bg,
+ TCOD_bkgnd_flag_t flag)
+{
+ console = TCOD_console_validate_(console);
+ if (!console) { return; }
+ clamp_rect_(0, 0, console->w, console->h, x, y, width, height);
+ TCOD_ASSERT(x + width <= console->w && y + height <= console->h);
+ for (int console_y = y; console_y < y + height; ++console_y) {
+ for (int console_x = x; console_x < x + width; ++console_x) {
+ put(console, console_x, console_y, ch, fg, bg, flag);
+ }
+ }
+}
+} // namespace console
+} // namespace tcod
+void TCOD_console_rect(TCOD_Console* console, int x, int y, int rw, int rh,
+ bool clear, TCOD_bkgnd_flag_t flag)
+{
+ console = TCOD_console_validate_(console);
+ if (!console) { return; }
+ tcod::console::draw_rect(console, x, y, rw, rh,
+ clear ? 0x20 : 0, nullptr, &console->back, flag);
+}
+void TCOD_console_hline(TCOD_Console* console,int x, int y, int l,
+ TCOD_bkgnd_flag_t flag)
+{
+ console = TCOD_console_validate_(console);
+ if (!console) { return; }
+ tcod::console::draw_rect(console, x, y, l, 1,
+ 0x2500, &console->fore, &console->back, flag); // ─
+}
+void TCOD_console_vline(TCOD_Console* console,int x, int y, int l,
+ TCOD_bkgnd_flag_t flag)
+{
+ console = TCOD_console_validate_(console);
+ if (!console) { return; }
+ tcod::console::draw_rect(console, x, y, 1, l,
+ 0x2502, &console->fore, &console->back, flag); // │
+}
diff --git a/tcod_sys/libtcod/src/libtcod/console/drawing.h b/tcod_sys/libtcod/src/libtcod/console/drawing.h
new file mode 100644
index 000000000..d26f42687
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/console/drawing.h
@@ -0,0 +1,117 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef TCOD_CONSOLE_DRAWING_H_
+#define TCOD_CONSOLE_DRAWING_H_
+#include "../console_types.h"
+#include "../portability.h"
+/**
+ * Draw a rectangle onto a console.
+ *
+ * \param con A console pointer.
+ * \param x The starting region, the left-most position being 0.
+ * \param y The starting region, the top-most position being 0.
+ * \param rw The width of the rectangle.
+ * \param rh The height of the rectangle.
+ * \param clear If true the drawing region will be filled with spaces.
+ * \param flag The blending flag to use.
+ */
+TCODLIB_CAPI void TCOD_console_rect(
+ TCOD_Console* con, int x, int y, int w, int h, bool clear,
+ TCOD_bkgnd_flag_t flag);
+/**
+ * Draw a horizontal line using the default colors.
+ *
+ * \param con A console pointer.
+ * \param x The starting X coordinate, the left-most position being 0.
+ * \param y The starting Y coordinate, the top-most position being 0.
+ * \param l The width of the line.
+ * \param flag The blending flag.
+ *
+ * This function makes assumptions about the fonts character encoding.
+ * It will fail if the font encoding is not `cp437`.
+ */
+TCODLIB_CAPI void TCOD_console_hline(
+ TCOD_Console* con, int x, int y, int l, TCOD_bkgnd_flag_t flag);
+/**
+ * Draw a vertical line using the default colors.
+ *
+ * \param con A console pointer.
+ * \param x The starting X coordinate, the left-most position being 0.
+ * \param y The starting Y coordinate, the top-most position being 0.
+ * \param l The height of the line.
+ * \param flag The blending flag.
+ *
+ * This function makes assumptions about the fonts character encoding.
+ * It will fail if the font encoding is not `cp437`.
+ */
+TCODLIB_CAPI void TCOD_console_vline(
+ TCOD_Console* con, int x, int y, int l, TCOD_bkgnd_flag_t flag);
+#ifdef __cplusplus
+namespace tcod {
+namespace console {
+// All functions here are provisional unless given an added version.
+/**
+ * Place a single tile on a `console` at `x`,`y`.
+ *
+ * If `ch` is 0 then the character code will not be updated.
+ *
+ * If `fg`,`bg` is nullptr then their respective colors will not be updated.
+ */
+TCODLIB_API void put(
+ TCOD_Console* console,
+ int x,
+ int y,
+ int ch,
+ const TCOD_color_t* fg = &TCOD_white,
+ const TCOD_color_t* bg = &TCOD_black,
+ TCOD_bkgnd_flag_t flag = TCOD_BKGND_SET);
+/**
+ * Draw a rectangle on a `console` with a shape of `x`,`y`,`width`,`height`.
+ *
+ * If `ch` is 0 then the character code will not be updated.
+ *
+ * If `fg`,`bg` is nullptr then their respective colors will not be updated.
+ */
+TCODLIB_API void draw_rect(
+ TCOD_Console* console,
+ int x,
+ int y,
+ int width,
+ int height,
+ int ch,
+ const TCOD_color_t* fg = &TCOD_white,
+ const TCOD_color_t* bg = &TCOD_black,
+ TCOD_bkgnd_flag_t flag = TCOD_BKGND_SET);
+} // namespace console
+} // namespace tcod
+#endif // __cplusplus
+#endif // TCOD_CONSOLE_DRAWING_H_
diff --git a/tcod_sys/libtcod/src/libtcod/console/printing.cpp b/tcod_sys/libtcod/src/libtcod/console/printing.cpp
new file mode 100644
index 000000000..accfec81d
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/console/printing.cpp
@@ -0,0 +1,1399 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "printing.h"
+
+#include
+#ifndef NO_UNICODE
+#include
+#include
+#endif
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "drawing.h"
+#include "../console.h"
+#include "../libtcod_int.h"
+#include "../utility.h"
+#include "../../vendor/utf8proc/utf8proc.h"
+static TCOD_color_t color_control_fore[TCOD_COLCTRL_NUMBER] = {
+ {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255},
+ {255, 255, 255}};
+static TCOD_color_t color_control_back[TCOD_COLCTRL_NUMBER];
+/**
+ * Assign a foreground and background color to a color control index.
+ *
+ * \param con Index to change, e.g. `TCOD_COLCTRL_1`
+ * \param fore Foreground color to assign to this index.
+ * \param back Background color to assign to this index.
+ */
+void TCOD_console_set_color_control(
+ TCOD_colctrl_t con, TCOD_color_t fore, TCOD_color_t back)
+{
+ TCOD_IFNOT(con >= TCOD_COLCTRL_1 && con <= TCOD_COLCTRL_NUMBER) return;
+ color_control_fore[con - 1] = fore;
+ color_control_back[con - 1] = back;
+}
+char *TCOD_console_vsprint(const char *fmt, va_list ap)
+{
+ #define NB_BUFFERS 10
+ #define INITIAL_SIZE 512
+ /* several static buffers in case the function is used more than once in a single function call */
+ static char *msg[NB_BUFFERS] = {NULL};
+ static int buflen[NB_BUFFERS] = {0};
+ static int curbuf = 0;
+ char *ret;
+ bool ok = false;
+ if (!msg[0]) {
+ int i;
+ for (i = 0; i < NB_BUFFERS; i++) {
+ buflen[i] = INITIAL_SIZE;
+ msg[i] = static_cast(calloc(sizeof(char), INITIAL_SIZE));
+ }
+ }
+ do {
+ /* warning ! depending on the compiler, vsnprintf return -1 or
+ the expected string length if the buffer is not big enough */
+ va_list ap_clone;
+ va_copy(ap_clone, ap);
+ int len = std::vsnprintf(msg[curbuf], buflen[curbuf], fmt, ap_clone);
+ va_end(ap_clone);
+ ok=true;
+ if (len < 0 || len >= buflen[curbuf]) {
+ /* buffer too small. */
+ if (len > 0) {
+ while (buflen[curbuf] < len + 1) { buflen[curbuf] *= 2; }
+ } else {
+ buflen[curbuf] *= 2;
+ }
+ free(msg[curbuf]);
+ msg[curbuf] = static_cast(calloc(sizeof(char), buflen[curbuf]));
+ ok = false;
+ }
+ } while (!ok);
+ ret = msg[curbuf];
+ curbuf = (curbuf + 1) % NB_BUFFERS;
+ return ret;
+}
+/**
+ * Print a titled, framed region on a console, using default colors and
+ * alignment.
+ *
+ * \param con A console pointer.
+ * \param x The starting X coordinate, the left-most position being 0.
+ * \param y The starting Y coordinate, the top-most position being 0.
+ * \param w The width of the frame.
+ * \param h The height of the frame.
+ * \param empty If true the characters inside of the frame will be cleared
+ * with spaces.
+ * \param flag The blending flag.
+ * \param fmt A format string as if passed to printf.
+ * \param ... Variadic arguments as if passed to printf.
+ *
+ * This function makes assumptions about the fonts character encoding.
+ * It will fail if the font encoding is not `cp437`.
+ */
+void TCOD_console_print_frame(
+ TCOD_Console* con,int x, int y, int w, int h,
+ bool empty, TCOD_bkgnd_flag_t flag, const char* fmt, ...)
+{
+ con = TCOD_console_validate_(con);
+ if (!con) { return; }
+ TCOD_console_put_char(con, x, y, TCOD_CHAR_NW, flag);
+ TCOD_console_put_char(con, x + w - 1, y, TCOD_CHAR_NE, flag);
+ TCOD_console_put_char(con, x, y + h - 1 , TCOD_CHAR_SW, flag);
+ TCOD_console_put_char(con, x + w - 1, y + h - 1, TCOD_CHAR_SE, flag);
+ TCOD_console_hline(con, x + 1, y, w - 2, flag);
+ TCOD_console_hline(con, x + 1, y + h - 1, w - 2, flag);
+ if (h > 2) {
+ TCOD_console_vline(con, x,y + 1, h - 2, flag);
+ TCOD_console_vline(con, x + w - 1, y + 1, h - 2, flag);
+ if (empty) {
+ TCOD_console_rect(con, x + 1, y + 1, w - 2, h - 2, true, flag);
+ }
+ }
+ if (fmt) {
+ va_list ap;
+ int xs;
+ char *title;
+ va_start(ap, fmt);
+ title = TCOD_console_vsprint(fmt, ap);
+ va_end(ap);
+ title[w - 3] = 0; /* truncate if needed */
+ xs = x + (w - static_cast(strlen(title)) - 2) / 2;
+ std::swap(con->fore, con->back);
+ TCOD_console_print_ex(con, xs, y, TCOD_BKGND_SET, TCOD_LEFT,
+ " %s ", title);
+ std::swap(con->fore, con->back);
+ }
+}
+/**
+ * Print a string on a console, using default colors and alignment.
+ *
+ * \param con A console pointer.
+ * \param x The starting X coordinate, the left-most position being 0.
+ * \param y The starting Y coordinate, the top-most position being 0.
+ * \param fmt A format string as if passed to printf.
+ * \param ... Variadic arguments as if passed to printf.
+ */
+void TCOD_console_print(TCOD_Console* con, int x, int y, const char* fmt, ...)
+{
+ va_list ap;
+ con = TCOD_console_validate_(con);
+ if (!con) { return; }
+ va_start(ap, fmt);
+ TCOD_console_print_internal(con, x, y, 0, 0, con->bkgnd_flag,
+ con->alignment, TCOD_console_vsprint(fmt, ap), false, false);
+ va_end(ap);
+}
+/**
+ * Print a string on a console, using default colors.
+ *
+ * \param con A console pointer.
+ * \param x The starting X coordinate, the left-most position being 0.
+ * \param y The starting Y coordinate, the top-most position being 0.
+ * \param flag The blending flag.
+ * \param alignment The font alignment to use.
+ * \param fmt A format string as if passed to printf.
+ * \param ... Variadic arguments as if passed to printf.
+ */
+void TCOD_console_print_ex(TCOD_Console* con,int x, int y,
+ TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ TCOD_console_print_internal(con, x, y, 0, 0, flag, alignment,
+ TCOD_console_vsprint(fmt, ap), false, false);
+ va_end(ap);
+}
+/**
+ * Print a string on a console constrained to a rectangle, using default
+ * colors and alignment.
+ *
+ * \param con A console pointer.
+ * \param x The starting X coordinate, the left-most position being 0.
+ * \param y The starting Y coordinate, the top-most position being 0.
+ * \param w The width of the region.
+ * If 0 then the maximum width will be used.
+ * \param h The height of the region.
+ * If 0 then the maximum height will be used.
+ * \param fmt A format string as if passed to printf.
+ * \param ... Variadic arguments as if passed to printf.
+ * \return The number of lines actually printed.
+ */
+int TCOD_console_print_rect(TCOD_Console* con, int x, int y, int w, int h,
+ const char *fmt, ...)
+{
+ int ret;
+ va_list ap;
+ con = TCOD_console_validate_(con);
+ if (!con) { return 0; }
+ va_start(ap, fmt);
+ ret = TCOD_console_print_internal(con, x, y, w, h, con->bkgnd_flag,
+ con->alignment, TCOD_console_vsprint(fmt, ap), true, false);
+ va_end(ap);
+ return ret;
+}
+/**
+ * Print a string on a console constrained to a rectangle, using default
+ * colors.
+ *
+ * \param con A console pointer.
+ * \param x The starting X coordinate, the left-most position being 0.
+ * \param y The starting Y coordinate, the top-most position being 0.
+ * \param w The width of the region.
+ * If 0 then the maximum width will be used.
+ * \param h The height of the region.
+ * If 0 then the maximum height will be used.
+ * \param flag The blending flag.
+ * \param alignment The font alignment to use.
+ * \param fmt A format string as if passed to printf.
+ * \param ... Variadic arguments as if passed to printf.
+ * \return The number of lines actually printed.
+ */
+int TCOD_console_print_rect_ex(TCOD_Console* con, int x, int y, int w, int h,
+ TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, ...)
+{
+ int ret;
+ va_list ap;
+ va_start(ap, fmt);
+ ret = TCOD_console_print_internal(con, x, y, w, h, flag, alignment,
+ TCOD_console_vsprint(fmt, ap), true, false);
+ va_end(ap);
+ return ret;
+}
+/**
+ * Return the number of lines that would be printed by the
+ *
+ * \param con A console pointer.
+ * \param x The starting X coordinate, the left-most position being 0.
+ * \param y The starting Y coordinate, the top-most position being 0.
+ * \param w The width of the region.
+ * If 0 then the maximum width will be used.
+ * \param h The height of the region.
+ * If 0 then the maximum height will be used.
+ * \param fmt A format string as if passed to printf.
+ * \param ... Variadic arguments as if passed to printf.
+ * \return The number of lines that would have been printed.
+ */
+int TCOD_console_get_height_rect(TCOD_Console* con,
+ int x, int y, int w, int h, const char *fmt, ...)
+{
+ int ret;
+ va_list ap;
+ va_start(ap, fmt);
+ ret = TCOD_console_print_internal(con, x, y, w, h, TCOD_BKGND_NONE,
+ TCOD_LEFT, TCOD_console_vsprint(fmt, ap), true, true);
+ va_end(ap);
+ return ret;
+}
+/* non public methods */
+int TCOD_console_stringLength(const unsigned char *s)
+{
+ int l = 0;
+ while (*s) {
+ if (*s == TCOD_COLCTRL_FORE_RGB || *s == TCOD_COLCTRL_BACK_RGB) {
+ s += 3;
+ } else if (*s > TCOD_COLCTRL_STOP) {
+ l++;
+ }
+ s++;
+ }
+ return l;
+}
+unsigned char * TCOD_console_forward(unsigned char *s,int l)
+{
+ while (*s && l > 0) {
+ if (*s == TCOD_COLCTRL_FORE_RGB || *s == TCOD_COLCTRL_BACK_RGB) {
+ s += 3;
+ } else if (*s > TCOD_COLCTRL_STOP) {
+ l--;
+ }
+ s++;
+ }
+ return s;
+}
+unsigned char *TCOD_console_strchr(unsigned char *s, unsigned char c)
+{
+ while (*s && *s != c) {
+ if (*s == TCOD_COLCTRL_FORE_RGB || *s == TCOD_COLCTRL_BACK_RGB) {
+ s += 3;
+ }
+ s++;
+ }
+ return (*s ? s : NULL);
+}
+
+int TCOD_console_print_internal(
+ TCOD_Console* con, int x,int y, int rw, int rh, TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t align, char *msg, bool can_split, bool count_only)
+{
+ unsigned char *c = reinterpret_cast(msg);
+ int cx = 0;
+ int cy = y;
+ int minx, maxx, miny, maxy;
+ TCOD_color_t oldFore;
+ TCOD_color_t oldBack;
+ con = TCOD_console_validate_(con);
+ if (!con) { return 0; }
+ TCOD_IFNOT(TCOD_console_is_index_valid_(con, x, y)) { return 0; }
+ TCOD_IFNOT(msg != NULL) { return 0; }
+ if (rh == 0) { rh = con->h - y; }
+ if (rw == 0) {
+ switch(align) {
+ case TCOD_LEFT: rw = con->w - x; break;
+ case TCOD_RIGHT: rw = x + 1; break;
+ case TCOD_CENTER: default: rw = con->w; break;
+ }
+ }
+ oldFore = con->fore;
+ oldBack = con->back;
+ miny = y;
+ maxy = con->h - 1;
+ if (rh > 0) { maxy = std::min(maxy, y + rh - 1); }
+ switch (align) {
+ case TCOD_LEFT:
+ minx = std::max(0,x);
+ maxx = std::min(con->w - 1, x + rw - 1);
+ break;
+ case TCOD_RIGHT:
+ minx = std::max(0, x - rw + 1);
+ maxx = std::min(con->w - 1, x);
+ break;
+ case TCOD_CENTER: default:
+ minx = std::max(0, x - rw / 2);
+ maxx = std::min(con->w - 1, x + rw / 2);
+ break;
+ }
+
+ do {
+ /* get \n delimited sub-message */
+ unsigned char *end = TCOD_console_strchr(c, '\n');
+ char bak = 0;
+ int cl;
+ unsigned char *split = NULL;
+ if (end) { *end=0; }
+ cl = TCOD_console_stringLength(c);
+ /* find starting x */
+ switch (align) {
+ case TCOD_LEFT : cx = x; break;
+ case TCOD_RIGHT : cx = x - cl + 1; break;
+ case TCOD_CENTER : cx = x - cl / 2; break;
+ }
+ /* check if the string is completely out of the minx,miny,maxx,maxy frame */
+ if (cy >= miny && cy <= maxy && cx <= maxx && cx + cl -1 >= minx) {
+ if (can_split && cy <= maxy) {
+ /* if partially out of screen, try to split the sub-message */
+ if (cx < minx) {
+ split = TCOD_console_forward(c, (align == TCOD_CENTER
+ ? cl - 2 * (minx - cx)
+ : cl - (minx - cx)));
+ } else if (align == TCOD_CENTER) {
+ if (cx + cl / 2 > maxx + 1) {
+ split = TCOD_console_forward(c, maxx + 1 - cx);
+ }
+ } else {
+ if (cx + cl > maxx + 1) {
+ split = TCOD_console_forward(c, maxx + 1 - cx);
+ }
+ }
+ }
+ if (split) {
+ unsigned char *oldsplit = split;
+ while (!isspace(*split) && split > c) { split--; }
+ if (end) { *end = '\n'; }
+ if (!isspace(*split)) {
+ split = oldsplit;
+ }
+ end = split;
+ bak = *split;
+ *split = 0;
+ cl = TCOD_console_stringLength(c);
+ switch (align) {
+ case TCOD_LEFT : cx = x; break;
+ case TCOD_RIGHT : cx = x - cl + 1; break;
+ case TCOD_CENTER : cx = x - cl / 2; break;
+ }
+ }
+ if (cx < minx) {
+ /* truncate left part */
+ c += minx-cx;
+ cl -= minx-cx;
+ cx = minx;
+ }
+ if (cx + cl > maxx + 1) {
+ /* truncate right part */
+ split = TCOD_console_forward(c, maxx + 1 - cx);
+ *split = 0;
+ }
+ /* render the sub-message */
+ if (cy >= 0 && cy < con->h) {
+ while (*c) {
+ if (*c >= TCOD_COLCTRL_1 && *c <= TCOD_COLCTRL_NUMBER) {
+ con->fore = color_control_fore[*c - 1];
+ con->back = color_control_back[*c - 1];
+ } else if (*c == TCOD_COLCTRL_FORE_RGB) {
+ c++;
+ con->fore.r = *c++;
+ con->fore.g = *c++;
+ con->fore.b = *c;
+ } else if (*c == TCOD_COLCTRL_BACK_RGB) {
+ c++;
+ con->back.r = *c++;
+ con->back.g = *c++;
+ con->back.b = *c;
+ } else if (*c == TCOD_COLCTRL_STOP) {
+ con->fore = oldFore;
+ con->back = oldBack;
+ } else {
+ if (!count_only) {
+ TCOD_console_put_char(con, cx, cy, *c, flag);
+ }
+ cx++;
+ }
+ c++;
+ }
+ }
+ }
+ if (end) {
+ /* next line */
+ if (split && ! isspace(bak)) {
+ *end = bak;
+ c = end;
+ } else {
+ c = end + 1;
+ }
+ cy++;
+ } else {
+ c = NULL;
+ }
+ } while (c && cy < con->h && (rh == 0 || cy < y + rh));
+ return cy - y + 1;
+}
+#ifndef NO_UNICODE
+wchar_t *TCOD_console_strchr_utf(wchar_t *s, char c)
+{
+ while (*s && *s != c) {
+ if (*s == TCOD_COLCTRL_FORE_RGB || *s == TCOD_COLCTRL_BACK_RGB) {
+ s += 3;
+ }
+ s++;
+ }
+ return (*s ? s : NULL);
+}
+void TCOD_console_map_string_to_font_utf(const wchar_t *s,
+ int fontCharX, int fontCharY)
+{
+ TCOD_IFNOT(s != NULL) return;
+ while (*s) {
+ TCOD_sys_map_ascii_to_font(*s, fontCharX, fontCharY);
+ fontCharX++;
+ if (fontCharX == TCOD_ctx.fontNbCharHoriz) {
+ fontCharX = 0;
+ fontCharY++;
+ }
+ s++;
+ }
+}
+wchar_t *TCOD_console_vsprint_utf(const wchar_t *fmt, va_list ap)
+{
+ #define NB_BUFFERS 10
+ #define INITIAL_SIZE 512
+ /* several static buffers in case the function is used more than once in a single function call */
+ static wchar_t *msg[NB_BUFFERS] = {NULL};
+ static int buflen[NB_BUFFERS] = {0};
+ static int curbuf = 0;
+ wchar_t *ret;
+ bool ok = false;
+ if (!msg[0]) {
+ int i;
+ for (i = 0; i < NB_BUFFERS; i++) {
+ buflen[i] = INITIAL_SIZE;
+ msg[i] = static_cast(calloc(sizeof(wchar_t), INITIAL_SIZE));
+ }
+ }
+ do {
+ /* warning ! depending on the compiler, vsnprintf return -1 or
+ the expected string length if the buffer is not big enough */
+ int len = vswprintf(msg[curbuf], buflen[curbuf], fmt, ap);
+ ok = true;
+ if (len < 0 || len >= buflen[curbuf]) {
+ /* buffer too small. */
+ if (len > 0) {
+ while (buflen[curbuf] < len + 1) { buflen[curbuf] *= 2; }
+ } else {
+ buflen[curbuf] *= 2;
+ }
+ free(msg[curbuf]);
+ msg[curbuf] = static_cast(
+ calloc(sizeof(wchar_t), buflen[curbuf]));
+ ok = false;
+ }
+ } while (!ok);
+ ret = msg[curbuf];
+ curbuf = (curbuf + 1) % NB_BUFFERS;
+ return ret;
+}
+int TCOD_console_stringLength_utf(const wchar_t *s)
+{
+ int l = 0;
+ while (*s) {
+ if (*s == TCOD_COLCTRL_FORE_RGB || *s == TCOD_COLCTRL_BACK_RGB) {
+ s += 3;
+ } else if (*s > TCOD_COLCTRL_STOP) {
+ l++;
+ }
+ s++;
+ }
+ return l;
+}
+wchar_t * TCOD_console_forward_utf(wchar_t *s,int l)
+{
+ while (*s && l > 0) {
+ if (*s == TCOD_COLCTRL_FORE_RGB || *s == TCOD_COLCTRL_BACK_RGB) {
+ s+=3;
+ } else if (*s > TCOD_COLCTRL_STOP) {
+ l--;
+ }
+ s++;
+ }
+ return s;
+}
+int TCOD_console_print_internal_utf(
+ TCOD_Console* con,int x,int y, int rw, int rh, TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t align, wchar_t *msg, bool can_split, bool count_only)
+{
+ wchar_t *c = msg;
+ int cx = 0;
+ int cy = y;
+ int minx, maxx, miny, maxy;
+ TCOD_color_t oldFore;
+ TCOD_color_t oldBack;
+ con = TCOD_console_validate_(con);
+ if (!con) { return 0; }
+ if (!TCOD_console_is_index_valid_(con, x, y)) { return 0; }
+ TCOD_IFNOT(msg != NULL) { return 0; }
+ if (rh == 0) { rh = con->h - y; }
+ if (rw == 0) {
+ switch(align) {
+ case TCOD_LEFT: rw = con->w - x; break;
+ case TCOD_RIGHT: rw = x + 1; break;
+ case TCOD_CENTER: default: rw = con->w; break;
+ }
+ }
+ oldFore = con->fore;
+ oldBack = con->back;
+ miny = y;
+ maxy = con->h - 1;
+ if (rh > 0) maxy = std::min(maxy, y + rh - 1);
+ switch (align) {
+ case TCOD_LEFT:
+ minx = std::max(0,x);
+ maxx = std::min(con->w-1,x+rw-1);
+ break;
+ case TCOD_RIGHT:
+ minx = std::max(0, x - rw + 1);
+ maxx = std::min(con->w - 1, x);
+ break;
+ case TCOD_CENTER: default:
+ minx = std::max(0, x - rw / 2);
+ maxx = std::min(con->w - 1, x + rw / 2);
+ break;
+ }
+
+ do {
+ /* get \n delimited sub-message */
+ wchar_t *end = TCOD_console_strchr_utf(c, '\n');
+ wchar_t bak = 0;
+ int cl;
+ wchar_t *split = NULL;
+ if (end) { *end = 0; }
+ cl = TCOD_console_stringLength_utf(c);
+ /* find starting x */
+ switch (align) {
+ case TCOD_LEFT: cx = x; break;
+ case TCOD_RIGHT: cx = x - cl + 1; break;
+ case TCOD_CENTER: cx = x - cl / 2; break;
+ }
+ /* check if the string is completely out of the minx,miny,maxx,maxy frame */
+ if (cy >= miny && cy <= maxy && cx <= maxx && cx + cl - 1 >= minx) {
+ if (can_split && cy < maxy) {
+ /* if partially out of screen, try to split the sub-message */
+ if (cx < minx) {
+ split = TCOD_console_forward_utf(c, (align == TCOD_CENTER
+ ? cl - 2 * (minx - cx)
+ : cl - (minx - cx)));
+ } else if (align == TCOD_CENTER) {
+ if (cx + cl / 2 > maxx + 1) {
+ split = TCOD_console_forward_utf(c, maxx + 1 - cx);
+ }
+ } else {
+ if (cx + cl > maxx + 1) {
+ split = TCOD_console_forward_utf(c, maxx + 1 - cx);
+ }
+ }
+ }
+ if (split) {
+ wchar_t *oldsplit = split;
+ while (!iswspace(*split) && split > c) { split--; }
+ if (end) { *end='\n'; }
+ if (!iswspace(*split)) {
+ split = oldsplit;
+ }
+ end = split;
+ bak = *split;
+ *split = 0;
+ cl = TCOD_console_stringLength_utf(c);
+ switch (align) {
+ case TCOD_LEFT: cx = x; break;
+ case TCOD_RIGHT: cx = x - cl + 1; break;
+ case TCOD_CENTER: cx = x - cl / 2; break;
+ }
+ }
+ if (cx < minx) {
+ /* truncate left part */
+ c += minx - cx;
+ cl -= minx - cx;
+ cx = minx;
+ }
+ if (cx + cl > maxx + 1) {
+ /* truncate right part */
+ split = TCOD_console_forward_utf(c, maxx + 1 - cx);
+ *split = 0;
+ }
+ /* render the sub-message */
+ if (cy >= 0 && cy < con->h)
+ while (*c) {
+ if (*c >= TCOD_COLCTRL_1 && *c <= TCOD_COLCTRL_NUMBER) {
+ con->fore = color_control_fore[static_cast(*c) - 1];
+ con->back = color_control_back[static_cast(*c) - 1];
+ } else if (*c == TCOD_COLCTRL_FORE_RGB) {
+ c++;
+ con->fore.r = static_cast(*c++);
+ con->fore.g = static_cast(*c++);
+ con->fore.b = static_cast(*c);
+ } else if (*c == TCOD_COLCTRL_BACK_RGB) {
+ c++;
+ con->back.r = static_cast(*c++);
+ con->back.g = static_cast(*c++);
+ con->back.b = static_cast(*c);
+ } else if (*c == TCOD_COLCTRL_STOP) {
+ con->fore = oldFore;
+ con->back = oldBack;
+ } else {
+ if (!count_only) {
+ TCOD_console_put_char(con, cx, cy, static_cast(*c), flag);
+ }
+ cx++;
+ }
+ c++;
+ }
+ }
+ if (end) {
+ /* next line */
+ if (split && !iswspace(bak)) {
+ *end = bak;
+ c = end;
+ } else {
+ c = end + 1;
+ }
+ cy++;
+ } else {
+ c = NULL;
+ }
+ } while (c && cy < con->h && (rh == 0 || cy < y + rh));
+ return cy - y + 1;
+}
+/**
+ * \rst
+ * .. deprecated:: 1.8
+ * Use :any:`TCOD_console_printf` instead.
+ * \endrst
+ */
+void TCOD_console_print_utf(TCOD_Console* con, int x, int y,
+ const wchar_t *fmt, ...)
+{
+ va_list ap;
+ con = TCOD_console_validate_(con);
+ if (!con) { return; }
+ va_start(ap, fmt);
+ TCOD_console_print_internal_utf(con, x, y, 0, 0, con->bkgnd_flag,
+ con->alignment, TCOD_console_vsprint_utf(fmt, ap), false, false);
+ va_end(ap);
+}
+/**
+ * \rst
+ * .. deprecated:: 1.8
+ * Use :any:`TCOD_console_printf_ex` instead.
+ * \endrst
+ */
+void TCOD_console_print_ex_utf(
+ TCOD_Console* con, int x, int y, TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t alignment, const wchar_t *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ TCOD_console_print_internal_utf(
+ con, x, y, 0, 0, flag, alignment, TCOD_console_vsprint_utf(fmt, ap),
+ false, false);
+ va_end(ap);
+}
+
+int TCOD_console_print_rect_utf(TCOD_Console* con, int x, int y, int w, int h,
+ const wchar_t *fmt, ...)
+{
+ con = TCOD_console_validate_(con);
+ if (!con) { return 0; }
+ va_list ap;
+ va_start(ap, fmt);
+ int ret = TCOD_console_print_internal_utf(
+ con, x, y, w, h, con->bkgnd_flag, con->alignment,
+ TCOD_console_vsprint_utf(fmt, ap), true, false);
+ va_end(ap);
+ return ret;
+}
+/**
+ * \rst
+ * .. deprecated:: 1.8
+ * Use :any:`TCOD_console_printf_rect_ex` instead.
+ * \endrst
+ */
+int TCOD_console_print_rect_ex_utf(
+ TCOD_Console* con,int x, int y, int w, int h, TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t alignment, const wchar_t *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ int ret = TCOD_console_print_internal_utf(
+ con, x, y, w, h, flag, alignment,
+ TCOD_console_vsprint_utf(fmt, ap), true, false);
+ va_end(ap);
+ return ret;
+}
+/**
+ * \rst
+ * .. deprecated:: 1.8
+ * \endrst
+ */
+int TCOD_console_get_height_rect_utf(
+ TCOD_Console* con,int x, int y, int w, int h, const wchar_t *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ int ret = TCOD_console_print_internal_utf(
+ con, x, y, w, h, TCOD_BKGND_NONE, TCOD_LEFT,
+ TCOD_console_vsprint_utf(fmt, ap), true, true);
+ va_end(ap);
+ return ret;
+}
+
+#endif /* NO_UNICODE */
+namespace tcod {
+namespace console {
+static auto vsprint_(const char *fmt, va_list ap) -> std::string
+{
+ if (!fmt) { return ""; }
+ va_list ap_clone;
+ va_copy(ap_clone, ap);
+ std::string result(std::vsnprintf(nullptr, 0, fmt, ap_clone), 0);
+ va_end(ap_clone);
+ std::vsnprintf(&result[0], result.size() + 1, fmt, ap);
+ return result;
+}
+class UnicodeIterator: public std::iterator {
+ public:
+ UnicodeIterator()
+ : p_(nullptr), end_(nullptr)
+ {}
+ UnicodeIterator(const utf8proc_uint8_t* start, const utf8proc_uint8_t* end)
+ : p_(start), end_(end)
+ {
+ parse_unicode();
+ }
+ UnicodeIterator(const char* start, const char* end)
+ : UnicodeIterator(reinterpret_cast(start),
+ reinterpret_cast(end))
+ {}
+ UnicodeIterator(const std::string& str)
+ : UnicodeIterator(str.empty() ? nullptr : &str.front(),
+ str.empty() ? nullptr : &str.back() + 1)
+ {}
+ UnicodeIterator& operator++()
+ {
+ if (p_ >= end_) {
+ throw std::out_of_range("Moved past the end of the string.");
+ }
+ p_ += code_size_;
+ parse_unicode();
+ return *this;
+ }
+ UnicodeIterator operator++(int)
+ {
+ UnicodeIterator tmp(*this);
+ operator++();
+ return tmp;
+ }
+ bool operator==(const UnicodeIterator& rhs) const noexcept
+ {
+ return p_ == rhs.p_;
+ }
+ bool operator!=(const UnicodeIterator& rhs) const noexcept
+ {
+ return p_ != rhs.p_;
+ }
+ bool operator<(const UnicodeIterator& rhs) const noexcept
+ {
+ return p_ < rhs.p_;
+ }
+ int operator*() const
+ {
+ if (p_ == end_) {
+ throw std::out_of_range("Dereferenced past the end of the iterator.");
+ }
+ return codepoint_;
+ }
+ auto get_property() const noexcept -> const utf8proc_property_t*
+ {
+ return utf8proc_get_property(codepoint_);
+ }
+ bool empty() const noexcept
+ {
+ return p_ == end_;
+ }
+ auto end() const -> const UnicodeIterator
+ {
+ return UnicodeIterator(end_, end_);
+ }
+ /*
+ * Check if the specified character is any line-break character
+ */
+ bool is_newline() const noexcept
+ {
+ switch (get_property()->category) {
+ case UTF8PROC_CATEGORY_ZL: /* Separator, line */
+ case UTF8PROC_CATEGORY_ZP: /* Separator, paragraph */
+ return true;
+ case UTF8PROC_CATEGORY_CC: /* Other, control */
+ switch(get_property()->boundclass) {
+ case UTF8PROC_BOUNDCLASS_CR: // carriage return - \r
+ case UTF8PROC_BOUNDCLASS_LF: // line feed - \n
+ return true;
+ default: break;
+ }
+ break;
+ default: break;
+ }
+ return false;
+ }
+ private:
+ void parse_unicode()
+ {
+ if (p_ == end_) {
+ codepoint_ = 0;
+ code_size_ = 1;
+ return;
+ }
+ code_size_ = utf8proc_iterate(p_, end_ - p_, &codepoint_);
+ if (code_size_ < 0) {
+ throw std::logic_error(utf8proc_errmsg(code_size_));
+ }
+ }
+ const utf8proc_uint8_t* p_;
+ const utf8proc_uint8_t* end_;
+ utf8proc_int32_t codepoint_;
+ utf8proc_ssize_t code_size_;
+};
+class FormattedUnicodeIterator: public UnicodeIterator {
+ public:
+ FormattedUnicodeIterator()
+ : UnicodeIterator(), default_fg_(nullptr), default_bg_(nullptr),
+ fg_(nullptr), bg_(nullptr)
+ {}
+ FormattedUnicodeIterator(const std::string& str,
+ const TCOD_color_t* fg, const TCOD_color_t* bg)
+ : UnicodeIterator(str), default_fg_(fg), default_bg_(bg), fg_(fg), bg_(bg)
+ {
+ parse_special_codes();
+ }
+ FormattedUnicodeIterator(const UnicodeIterator& mit,
+ const TCOD_color_t* fg, const TCOD_color_t* bg)
+ : UnicodeIterator(mit), default_fg_(fg), default_bg_(bg), fg_(fg), bg_(bg)
+ {
+ parse_special_codes();
+ }
+ FormattedUnicodeIterator(const FormattedUnicodeIterator& rhs)
+ : UnicodeIterator(rhs),
+ default_fg_(rhs.default_fg_), default_bg_(rhs.default_bg_),
+ fg_(rhs.fg_), bg_(rhs.bg_)
+ {
+ // Avoid pointing to the temporary colors of other iterators.
+ if (fg_ == &rhs.temp_fg_) { temp_fg_ = rhs.temp_fg_; fg_ = &temp_fg_; }
+ if (bg_ == &rhs.temp_bg_) { temp_bg_ = rhs.temp_bg_; bg_ = &temp_bg_; }
+ }
+ FormattedUnicodeIterator& operator++()
+ {
+ UnicodeIterator::operator++();
+ parse_special_codes();
+ return *this;
+ }
+ auto get_fg() const noexcept -> const TCOD_color_t*
+ {
+ return fg_;
+ }
+ auto get_bg() const noexcept -> const TCOD_color_t*
+ {
+ return bg_;
+ }
+ private:
+ auto parse_rgb() -> TCOD_color_t {
+ TCOD_color_t color;
+ UnicodeIterator::operator++();
+ color.r = **this;
+ UnicodeIterator::operator++();
+ color.g = **this;
+ UnicodeIterator::operator++();
+ color.b = **this;
+ return color;
+ }
+ void parse_special_codes()
+ {
+ if (*this == (*this).end()) { return; }
+ if (TCOD_COLCTRL_1 <= **this && **this <= TCOD_COLCTRL_NUMBER) {
+ // Read colors from the color control array.
+ int color_index = (**this) - TCOD_COLCTRL_1;
+ fg_ = &color_control_fore[color_index];
+ bg_ = &color_control_back[color_index];
+ ++(*this);
+ return;
+ } else if (**this == TCOD_COLCTRL_STOP) {
+ // Return colors to their original color.
+ fg_ = default_fg_;
+ bg_ = default_bg_;
+ ++(*this);
+ return;
+ } else if (**this == TCOD_COLCTRL_FORE_RGB) {
+ temp_fg_ = parse_rgb();
+ fg_ = &temp_fg_;
+ ++(*this);
+ return;
+ } else if (**this == TCOD_COLCTRL_BACK_RGB) {
+ temp_bg_ = parse_rgb();
+ bg_ = &temp_bg_;
+ ++(*this);
+ return;
+ }
+ }
+ // Original colors
+ const TCOD_color_t* default_fg_;
+ const TCOD_color_t* default_bg_;
+ // Current active colors.
+ const TCOD_color_t* fg_;
+ const TCOD_color_t* bg_;
+ // Colors generated from RGB codes.
+ TCOD_color_t temp_fg_;
+ TCOD_color_t temp_bg_;
+};
+/**
+ * Get the next line-break or null terminator, or break the string before
+ * `max_width`.
+ *
+ * Returns {break_point, line_width, status}
+ */
+static std::tuple next_split_(
+ FormattedUnicodeIterator it,
+ const UnicodeIterator& end,
+ int max_width,
+ int can_split)
+{
+ // The break point and width of the line.
+ UnicodeIterator break_point(end);
+ int break_width = 0;
+ // The current line width.
+ int char_width = 0;
+ bool separating = false; // True if the last iteration was breakable.
+ while (it != end) {
+ if (can_split && char_width > 0) {
+ switch (it.get_property()->category) {
+ default:
+ if (char_width + it.get_property()->charwidth > max_width) {
+ // The next character would go over the max width, so return now.
+ if (break_point != end) {
+ // Use latest line break if one exists.
+ return {break_point, break_width, 1};
+ } else {
+ // Force a line break here.
+ return {it, char_width, 1};
+ }
+ }
+ separating = false;
+ break;
+ case UTF8PROC_CATEGORY_PD: // Punctuation, dash
+ if (char_width + it.get_property()->charwidth > max_width) {
+ return {it, char_width, 1};
+ } else {
+ break_point = it;
+ ++break_point;
+ break_width = char_width + it.get_property()->charwidth;
+ separating = true;
+ }
+ break;
+ case UTF8PROC_CATEGORY_ZS: // Separator, space
+ if (!separating) {
+ break_point = it;
+ break_width = char_width;
+ separating = true;
+ }
+ break;
+ }
+ }
+ if (it.is_newline()) {
+ // Always break on newlines.
+ return {it, char_width, 0};
+ }
+ char_width += it.get_property()->charwidth;
+ ++it;
+ }
+ // Return end of iteration.
+ return {it, char_width, 0};
+}
+static int print_internal_(
+ TCOD_Console& con,
+ int x,
+ int y,
+ int width,
+ int height,
+ const std::string& string,
+ const TCOD_color_t* fg,
+ const TCOD_color_t* bg,
+ TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t align,
+ int can_split,
+ int count_only)
+{
+ FormattedUnicodeIterator it(string, fg, bg);
+ UnicodeIterator end = it.end();
+ if (!can_split && align == TCOD_RIGHT) {
+ // In general `can_split = false` is deprecated.
+ x -= con.w - 1;
+ width = con.w;
+ }
+ // Expand the width/height of 0 to the edge of the console.
+ if (!width) { width = con.w - x; }
+ if (!height) { height = con.h - y; }
+ // Print bounding box.
+ int left = x;
+ int right = x + width;
+ int top = y;
+ int bottom = y + height;
+ width = right - left;
+ height = bottom - top;
+ if (can_split && (width <= 0 || height <= 0)) {
+ return 0; // The bounding box is invalid.
+ }
+ while (it != end && top < bottom && top < con.h) {
+ // Check for newlines.
+ if(it.is_newline()) {
+ if(it.get_property()->category == UTF8PROC_CATEGORY_ZP) {
+ top += 2;
+ } else {
+ top += 1;
+ }
+ ++it;
+ continue;
+ }
+ // Get the next line of characters.
+ UnicodeIterator line_break;
+ int line_width;
+ int split_status;
+ std::tie(line_break, line_width, split_status) =
+ next_split_(it, end, width, can_split);
+ // Set cursor_x from alignment.
+ int cursor_x = 0;
+ switch (align) {
+ default:
+ case TCOD_LEFT:
+ cursor_x = left;
+ break;
+ case TCOD_RIGHT:
+ cursor_x = right - line_width;
+ break;
+ case TCOD_CENTER:
+ if (can_split) {
+ cursor_x = left + (width - line_width) / 2;
+ } else {
+ cursor_x = left - (line_width / 2); // Deprecated.
+ }
+ break;
+ }
+ for (; it < line_break; cursor_x += it.get_property()->charwidth, ++it) {
+ if(count_only) { continue; }
+ if (can_split && (left > cursor_x || cursor_x >= right)) { continue; }
+ if (!can_split && (0 > cursor_x || cursor_x >= con.w)) { continue; }
+ // Actually render this line of characters.
+ put(&con, cursor_x, top, *it, it.get_fg(), it.get_bg(), flag);
+ }
+ // Ignore any extra spaces.
+ while (it != end) {
+ // Separator, space
+ if (it.get_property()->category != UTF8PROC_CATEGORY_ZS) { break; }
+ ++it;
+ }
+ // If there was an automatic split earlier then the top is moved down.
+ if (split_status == 1) { top += 1; }
+ }
+ return std::min(top, bottom) - y + 1;
+}
+/**
+ * Normalize rectangle values using old libtcod rules where alignment can move
+ * the rectangle position.
+ */
+static void normalize_old_rect_(
+ TCOD_Console& console,
+ TCOD_alignment_t alignment,
+ int& x,
+ int& y,
+ int& width,
+ int& height)
+{
+ // Set default width/height if either is zero.
+ if (width == 0) { width = console.w; }
+ if (height == 0) { height = console.h - y; }
+ switch(alignment) {
+ default:
+ case TCOD_LEFT:
+ break;
+ case TCOD_RIGHT:
+ x -= width;
+ break;
+ case TCOD_CENTER:
+ x -= width / 2;
+ break;
+ }
+ return;
+}
+void print(
+ TCOD_Console* con,
+ int x,
+ int y,
+ const std::string& str,
+ const TCOD_color_t* fg,
+ const TCOD_color_t* bg,
+ TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t alignment)
+{
+ con = TCOD_console_validate_(con);
+ if (!con) { return; }
+ print_internal_(*con, x, y, con->w, con->h, str, fg, bg, flag, alignment,
+ false, false);
+}
+int print_rect(
+ struct TCOD_Console *con,
+ int x,
+ int y,
+ int width,
+ int height,
+ const std::string& str,
+ const TCOD_color_t* fg,
+ const TCOD_color_t* bg,
+ TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t alignment)
+{
+ con = TCOD_console_validate_(con);
+ if (!con) { return 0; }
+ return print_internal_(*con, x, y, width, height, str, fg, bg,
+ flag, alignment, true, false);
+}
+int get_height_rect(
+ std::array console_size,
+ int x,
+ int y,
+ int width,
+ int height,
+ const std::string& str)
+{
+ struct TCOD_Console console{};
+ console.w = console_size[0];
+ console.h = console_size[1];
+ return print_internal_(console, x, y, width, height, str, nullptr, nullptr,
+ TCOD_BKGND_NONE, TCOD_LEFT, true, true);
+}
+int get_height_rect(
+ int width,
+ const std::string& str)
+{
+ auto MAX_INT = std::numeric_limits::max();
+ return get_height_rect({width, MAX_INT}, 0, 0, width, MAX_INT, str);
+}
+int get_height_rect(
+ struct TCOD_Console *con,
+ int x,
+ int y,
+ int width,
+ int height,
+ const std::string& str)
+{
+ con = TCOD_console_validate_(con);
+ if (!con) { return 0; }
+ return get_height_rect({con->w, con->h}, x, y, width, height, str);
+}
+void print_frame(
+ struct TCOD_Console *con,
+ int x,
+ int y,
+ int width,
+ int height,
+ const std::string& title,
+ const TCOD_color_t* fg,
+ const TCOD_color_t* bg,
+ TCOD_bkgnd_flag_t flag,
+ bool empty)
+{
+ const int left = x;
+ const int right = x + width - 1;
+ const int top = y;
+ const int bottom = y + height - 1;
+ con = TCOD_console_validate_(con);
+ if (!con) { return; }
+ put(con, left, top, 0x250C, fg, bg, flag); // ┌
+ put(con, right, top, 0x2510, fg, bg, flag); // â”
+ put(con, left, bottom, 0x2514, fg, bg, flag); // â””
+ put(con, right, bottom, 0x2518, fg, bg, flag); // â”
+ draw_rect(con, x + 1, y, width - 2, 1,
+ 0x2500, &con->fore, &con->back, flag); // ─
+ draw_rect(con, x + 1, y + height - 1, width - 2, 1,
+ 0x2500, &con->fore, &con->back, flag);
+ draw_rect(con, x, y + 1, 1, height - 2,
+ 0x2502, &con->fore, &con->back, flag); // │
+ draw_rect(con, x + width - 1, y + 1, 1, height - 2,
+ 0x2502, &con->fore, &con->back, flag);
+ if (empty) {
+ draw_rect(con, x + 1, y + 1, width -2, height - 2,
+ 0x20, &con->fore, &con->back, flag);
+ }
+ if (!title.empty()) {
+ print_rect(con, x, y, width, 1,
+ " " + title + " ", bg, fg, TCOD_BKGND_SET, TCOD_CENTER);
+ }
+}
+} // namespace console
+} // namespace tcod
+/**
+ * Format and print a UTF-8 string to a console.
+ * \rst
+ * .. versionadded:: 1.8
+ * \endrst
+ */
+void TCOD_console_printf_ex(
+ TCOD_Console* con,
+ int x,
+ int y,
+ TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t alignment,
+ const char *fmt, ...)
+{
+ con = TCOD_console_validate_(con);
+ if (!con) { return; }
+ va_list ap;
+ va_start(ap, fmt);
+ tcod::console::print(con, x, y, tcod::console::vsprint_(fmt, ap),
+ &con->fore, &con->back, flag, alignment);
+ va_end(ap);
+}
+/**
+ * Format and print a UTF-8 string to a console.
+ * \rst
+ * .. versionadded:: 1.8
+ * \endrst
+ */
+void TCOD_console_printf(TCOD_Console* con, int x, int y, const char *fmt, ...)
+{
+ con = TCOD_console_validate_(con);
+ if (!con) { return; }
+ va_list ap;
+ va_start(ap, fmt);
+ tcod::console::print(
+ con, x, y, tcod::console::vsprint_(fmt, ap),
+ &con->fore, &con->back, con->bkgnd_flag, con->alignment);
+ va_end(ap);
+}
+/**
+ * Format and print a UTF-8 string to a console.
+ * \rst
+ * .. versionadded:: 1.8
+ * \endrst
+ */
+int TCOD_console_printf_rect_ex(
+ struct TCOD_Console* con,
+ int x, int y, int w, int h,
+ TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, ...)
+{
+ con = TCOD_console_validate_(con);
+ if (!con) { return 0; }
+ tcod::console::normalize_old_rect_(*con, alignment, x, y, w, h);
+ va_list ap;
+ va_start(ap, fmt);
+ int ret = tcod::console::print_rect(
+ con, x, y, w, h, tcod::console::vsprint_(fmt, ap),
+ &con->fore, &con->back, flag, alignment);
+ va_end(ap);
+ return ret;
+}
+/**
+ * Format and print a UTF-8 string to a console.
+ * \rst
+ * .. versionadded:: 1.8
+ * \endrst
+ */
+int TCOD_console_printf_rect(
+ struct TCOD_Console* con, int x, int y, int w, int h, const char *fmt, ...)
+{
+ con = TCOD_console_validate_(con);
+ if (!con) { return 0; }
+ tcod::console::normalize_old_rect_(*con, con->alignment, x, y, w, h);
+ va_list ap;
+ va_start(ap, fmt);
+ int ret = tcod::console::print_rect(
+ con, x, y, w, h, tcod::console::vsprint_(fmt, ap),
+ &con->fore, &con->back, con->bkgnd_flag, con->alignment);
+ va_end(ap);
+ return ret;
+}
+/**
+ * Return the number of lines that would be printed by this formatted string.
+ * \rst
+ * .. versionadded:: 1.8
+ * \endrst
+ */
+int TCOD_console_get_height_rect_fmt(
+ struct TCOD_Console* con, int x, int y, int w, int h, const char *fmt, ...)
+{
+ con = TCOD_console_validate_(con);
+ if (!con) { return 0; }
+ tcod::console::normalize_old_rect_(*con, TCOD_LEFT, x, y, w, h);
+ va_list ap;
+ va_start(ap, fmt);
+ int ret = tcod::console::get_height_rect(con, x, y, w, h,
+ tcod::console::vsprint_(fmt, ap));
+ va_end(ap);
+ return ret;
+}
+/**
+ * Print a framed and optionally titled region to a console, using default
+ * colors and alignment.
+ *
+ * This function uses Unicode box-drawing characters and a UTF-8 formatted
+ * string.
+ * \rst
+ * .. versionadded:: 1.8
+ * \endrst
+ */
+void TCOD_console_printf_frame(struct TCOD_Console *con,
+ int x, int y, int width, int height, int empty,
+ TCOD_bkgnd_flag_t flag, const char *fmt, ...)
+{
+ con = TCOD_console_validate_(con);
+ if (!con) { return; }
+ va_list ap;
+ va_start(ap, fmt);
+ tcod::console::print_frame(
+ con, x, y, width, height, tcod::console::vsprint_(fmt, ap),
+ &con->fore, &con->back, flag, empty);
+ va_end(ap);
+}
diff --git a/tcod_sys/libtcod/src/libtcod/console/printing.h b/tcod_sys/libtcod/src/libtcod/console/printing.h
new file mode 100644
index 000000000..46e325872
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/console/printing.h
@@ -0,0 +1,153 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef TCOD_CONSOLE_PRINTING_H_
+#define TCOD_CONSOLE_PRINTING_H_
+
+#ifdef __cplusplus
+#include
+#include
+#include
+#endif
+#include "../portability.h"
+#include "../console_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+TCOD_DEPRECATED("Use TCOD_console_printf instead.")
+TCODLIB_API void TCOD_console_print(TCOD_Console* con,int x, int y, const char *fmt, ...);
+TCOD_DEPRECATED("Use TCOD_console_printf_ex instead.")
+TCODLIB_API void TCOD_console_print_ex(TCOD_Console* con,int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, ...);
+TCOD_DEPRECATED("Use TCOD_console_printf_rect instead.")
+TCODLIB_API int TCOD_console_print_rect(TCOD_Console* con,int x, int y, int w, int h, const char *fmt, ...);
+TCOD_DEPRECATED("Use TCOD_console_printf_rect_ex instead.")
+TCODLIB_API int TCOD_console_print_rect_ex(TCOD_Console* con,int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, ...);
+TCOD_DEPRECATED("Use TCOD_console_printf_frame instead.")
+TCODLIB_API void TCOD_console_print_frame(TCOD_console_t con,int x,int y,int w,int h, bool empty, TCOD_bkgnd_flag_t flag, const char *fmt, ...);
+TCOD_DEPRECATED("Use TCOD_console_get_height_rect_fmt instead.")
+TCODLIB_API int TCOD_console_get_height_rect(TCOD_Console* con,int x, int y, int w, int h, const char *fmt, ...);
+
+#ifndef NO_UNICODE
+TCOD_DEPRECATED("Use TCOD_console_printf instead.")
+TCODLIB_API void TCOD_console_print_utf(TCOD_Console* con,int x, int y, const wchar_t *fmt, ...);
+TCOD_DEPRECATED("Use TCOD_console_printf_ex instead.")
+TCODLIB_API void TCOD_console_print_ex_utf(TCOD_Console* con,int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...);
+TCOD_DEPRECATED("Use TCOD_console_printf_rect instead.")
+TCODLIB_API int TCOD_console_print_rect_utf(TCOD_Console* con,int x, int y, int w, int h, const wchar_t *fmt, ...);
+TCOD_DEPRECATED("Use TCOD_console_printf_rect_ex instead.")
+TCODLIB_API int TCOD_console_print_rect_ex_utf(TCOD_Console* con,int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt, ...);
+TCOD_DEPRECATED("Use TCOD_console_get_height_rect_fmt instead.")
+TCODLIB_API int TCOD_console_get_height_rect_utf(TCOD_Console* con,int x, int y, int w, int h, const wchar_t *fmt, ...);
+#endif
+
+/* UTF-8 functions */
+TCODLIB_API TCODLIB_FORMAT(4, 5) void TCOD_console_printf(
+ TCOD_Console* con, int x, int y, const char *fmt, ...);
+TCODLIB_API TCODLIB_FORMAT(6, 7) void TCOD_console_printf_ex(
+ TCOD_Console* con, int x, int y, TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t alignment, const char *fmt, ...);
+TCODLIB_API TCODLIB_FORMAT(6, 7) int TCOD_console_printf_rect(
+ TCOD_Console* con, int x, int y, int w, int h, const char *fmt, ...);
+TCODLIB_API TCODLIB_FORMAT(8, 9) int TCOD_console_printf_rect_ex(
+ TCOD_Console* con,int x, int y, int w, int h,
+ TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, ...);
+TCODLIB_API TCODLIB_FORMAT(8, 9)
+void TCOD_console_printf_frame(struct TCOD_Console *con,
+ int x, int y, int w, int h, int empty,
+ TCOD_bkgnd_flag_t flag, const char *fmt, ...);
+TCODLIB_API TCODLIB_FORMAT(6, 7)
+int TCOD_console_get_height_rect_fmt(struct TCOD_Console *con,
+ int x, int y, int w, int h,
+ const char *fmt, ...);
+#ifdef __cplusplus
+}
+#endif
+#ifdef __cplusplus
+namespace tcod {
+namespace console {
+// All functions here are provisional unless given an added version.
+TCODLIB_API void print(
+ TCOD_Console* con,
+ int x,
+ int y,
+ const std::string& str,
+ const TCOD_color_t* fg,
+ const TCOD_color_t* bg,
+ TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t alignment);
+TCODLIB_API int print_rect(
+ struct TCOD_Console *con,
+ int x,
+ int y,
+ int width,
+ int height,
+ const std::string& str,
+ const TCOD_color_t* fg,
+ const TCOD_color_t* bg,
+ TCOD_bkgnd_flag_t flag,
+ TCOD_alignment_t alignment);
+/**
+ * Return the total number lines that a function with similar arguments would
+ * print.
+ */
+TCODLIB_API int get_height_rect(
+ std::array console_size,
+ int x,
+ int y,
+ int width,
+ int height,
+ const std::string& str);
+TCODLIB_API int get_height_rect(
+ int width,
+ const std::string& str);
+TCODLIB_API int get_height_rect(
+ struct TCOD_Console *con,
+ int x,
+ int y,
+ int width,
+ int height,
+ const std::string& str);
+TCODLIB_API void print_frame(
+ struct TCOD_Console *con,
+ int x,
+ int y,
+ int width,
+ int height,
+ const std::string& title,
+ const TCOD_color_t* fg,
+ const TCOD_color_t* bg,
+ TCOD_bkgnd_flag_t flag,
+ bool empty);
+} // namespace console
+} // namespace tcod
+#endif // __cplusplus
+#endif /* TCOD_CONSOLE_PRINTING_H_ */
diff --git a/tcod_sys/libtcod/src/libtcod/console/rexpaint.cpp b/tcod_sys/libtcod/src/libtcod/console/rexpaint.cpp
new file mode 100644
index 000000000..1cf8bdccd
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/console/rexpaint.cpp
@@ -0,0 +1,361 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "rexpaint.h"
+
+#ifdef TCOD_CONSOLE_SUPPORT
+
+#include
+
+#include
+
+#include "../console.h"
+#include "../libtcod_int.h" /* Needed only for TCOD_fatal */
+#include "../console_types.h"
+#include "../color.h"
+
+/* Convert a little-endian number to native memory order. */
+static uint32_t decode_little_endian(uint32_t data)
+{
+ uint32_t result = 0;
+ const uint8_t* p = reinterpret_cast(&data);
+ for(int i = 0; i < static_cast(sizeof(result)); ++i) {
+ result += p[i] << (std::numeric_limits::digits * i);
+ }
+ return result;
+}
+/* Byte swaps a number into little-endian order to be saved to disk. */
+static uint32_t encode_little_endian(uint32_t number) {
+ uint32_t result = 0;
+ uint8_t* p = reinterpret_cast(&result);
+ for(int i = 0; i < static_cast(sizeof(result)); ++i) {
+ p[i] = number & std::numeric_limits::max();
+ number >>= std::numeric_limits::digits;
+ }
+ return result;
+}
+/* RexPaint structs */
+struct RexPaintHeader {
+ int32_t version;
+ int32_t layer_count;
+};
+struct RexPaintLayerChunk {
+ int32_t width;
+ int32_t height;
+};
+struct RexPaintTile {
+ int32_t ch;
+ TCOD_color_t fg;
+ TCOD_color_t bg;
+};
+/* Read data from a gz file, returns 0 on success, or -1 on any error. */
+static int load_gz_confirm(gzFile gz_file, void *data, size_t length) {
+ int length_ = static_cast(length);
+ if (gzread(gz_file, data, length_) != length_) { return -1; }
+ return 0;
+}
+/* Loads a little-endian 32 bit signed int into memory. */
+static int load_int32(gzFile gz_file, int32_t *out) {
+ if (load_gz_confirm(gz_file, out, sizeof(out[0]))) { return -1; }
+ *out = static_cast(
+ decode_little_endian(static_cast(out[0]))
+ );
+ return 0;
+}
+static int load_header(gzFile gz_file, struct RexPaintHeader *xp_header) {
+ return (load_int32(gz_file, &xp_header->version) ||
+ load_int32(gz_file, &xp_header->layer_count));
+}
+static int load_layer(gzFile gz_file, struct RexPaintLayerChunk *xp_layer) {
+ return (load_int32(gz_file, &xp_layer->width) ||
+ load_int32(gz_file, &xp_layer->height));
+}
+/* Read a single REXPaint tile, return 0 on success, or -1 on error. */
+static int load_tile(gzFile gz_file, struct RexPaintTile *tile) {
+ return (load_int32(gz_file, &tile->ch) ||
+ load_gz_confirm(gz_file, &tile->fg, sizeof(tile->fg)) ||
+ load_gz_confirm(gz_file, &tile->bg, sizeof(tile->bg)));
+}
+/* Read a layer of REXPaint tiles onto a console.
+ If transparent is true, then follow REXPaint's rules for transparency. */
+static int load_tiles(
+ gzFile gz_file, TCOD_Console* console, int transparent) {
+ int x, y;
+ const int width = TCOD_console_get_width(console);
+ const int height = TCOD_console_get_height(console);
+ /* REXPaint tiles are in column-major order. */
+ for (x = 0; x < width; ++x) {
+ for (y = 0; y < height; ++y) {
+ struct RexPaintTile tile;
+ if (load_tile(gz_file, &tile)) {
+ return -1;
+ }
+ /* REXPaint uses a magic pink background to mark transparency. */
+ if (transparent &&
+ tile.bg.r == 0xff &&
+ tile.bg.g == 0x00 &&
+ tile.bg.b == 0xff) { continue; }
+ TCOD_console_set_char(console, x, y, tile.ch);
+ TCOD_console_set_char_foreground(console, x, y, tile.fg);
+ TCOD_console_set_char_background(console, x, y, tile.bg, TCOD_BKGND_SET);
+ }
+ }
+ return 0;
+}
+/* Return the next REXPaint layer as a console. After reading the header you
+ could just keep calling this function until it returns NULL. */
+static TCOD_console_t load_console(gzFile gz_file) {
+ struct RexPaintLayerChunk xp_layer;
+ TCOD_console_t console;
+ if (load_layer(gz_file, &xp_layer)) { return NULL; }
+ console = TCOD_console_new(xp_layer.width, xp_layer.height);
+ if (!console) { return NULL; }
+ if (load_tiles(gz_file, console, 0)) {
+ TCOD_console_delete(console);
+ return NULL;
+ }
+ return console;
+}
+/* Load all the contents of a REXPaint file into a list of consoles. */
+static TCOD_list_t load_consoleList(gzFile gz_file) {
+ struct RexPaintHeader xp_header;
+ TCOD_list_t console_list;
+ int i;
+ if (load_header(gz_file, &xp_header)) { return NULL; }
+ console_list = TCOD_list_allocate(xp_header.layer_count);
+ if (!console_list) { return NULL; }
+ for (i = 0; i < xp_header.layer_count; ++i) {
+ TCOD_console_t console = load_console(gz_file);
+ if (!console) {
+ /* There was an issue then delete everything so far and return NULL */
+ while (!TCOD_list_is_empty(console_list)) {
+ TCOD_console_delete(
+ static_cast(TCOD_list_pop(console_list)));
+ }
+ TCOD_list_delete(console_list);
+ return NULL;
+ }
+ TCOD_list_push(console_list, console);
+ }
+ return console_list;
+}
+/* Convert a list of consoles into a single console, deleting the list.
+ Follows REXPaint's rules for transparency. */
+static TCOD_console_t combine_console_list(TCOD_list_t console_list) {
+ TCOD_console_t main_console;
+ if (!console_list) { return NULL; }
+ /* Reverse the list so that elements will be dequeued. */
+ TCOD_list_reverse(console_list);
+ main_console = static_cast(TCOD_list_pop(console_list));
+ while (!TCOD_list_is_empty(console_list)) {
+ TCOD_console_t console =
+ static_cast(TCOD_list_pop(console_list));
+ /* Set key color to {255, 0, 255} before blit. */
+ TCOD_console_set_key_color(console, TCOD_fuchsia);
+ /* This blit may fail if the consoles do not match shapes. */
+ TCOD_console_blit(console, 0, 0, 0, 0, main_console, 0, 0, 1.0f, 1.0f);
+ TCOD_console_delete(console);
+ }
+ TCOD_list_delete(console_list);
+ return main_console;
+}
+/**
+ * \brief Return a list of consoles from a REXPaint file.
+ *
+ * \param [in] filename A path to the REXPaint file.
+ * \return Returns a TCOD_list_t of TCOD_console_t objects. Or NULL on an
+ * error. You will need to delete this list and each console individually.
+ *
+ * This function can load a REXPaint file with variable layer shapes,
+ * which would cause issues for a function like TCOD_console_list_from_xp.
+ */
+TCOD_list_t TCOD_console_list_from_xp(const char *filename) {
+ int z_errno = Z_ERRNO;
+ TCOD_list_t console_list;
+ gzFile gz_file = gzopen(filename, "rb");
+ if (!gz_file) {
+ TCOD_fatal("Could not open file: '%s'", filename);
+ return NULL;
+ }
+ console_list = load_consoleList(gz_file);
+ if (!console_list){
+ TCOD_fatal("Error parsing '%s'\n%s", filename, gzerror(gz_file, &z_errno));
+ /* Could fall-through here and return NULL. */
+ }
+ gzclose(gz_file);
+ return console_list;
+}
+/**
+ * \brief Return a new console loaded from a REXPaint ``.xp`` file.
+ *
+ * \param [in] filename A path to the REXPaint file.
+ * \return A new TCOD_console_t object. New consoles will need
+ * to be deleted with a call to :any:`TCOD_console_delete`.
+ * Returns NULL on an error.
+ *
+ */
+TCOD_console_t TCOD_console_from_xp(const char *filename) {
+ return combine_console_list(TCOD_console_list_from_xp(filename));
+}
+/**
+ * \brief Update a console from a REXPaint ``.xp`` file.
+ *
+ * \param [out] con A console instance to update from the REXPaint file.
+ * \param [in] filename A path to the REXPaint file.
+ *
+ * In C++, you can pass the filepath directly to the :any:`TCODConsole`
+ * constructor to load a REXPaint file.
+ */
+bool TCOD_console_load_xp(TCOD_console_t con, const char *filename) {
+ TCOD_console_t xp_console = TCOD_console_from_xp(filename);
+ if (!xp_console) { return false; }
+ if (TCOD_console_get_width(con) != TCOD_console_get_width(xp_console) ||
+ TCOD_console_get_height(con) != TCOD_console_get_height(xp_console)) {
+ TCOD_console_delete(xp_console);
+ return false;
+ }
+ TCOD_console_blit(xp_console, 0, 0, 0, 0, con, 0, 0, 1.0f, 1.0f);
+ TCOD_console_delete(xp_console);
+ return true;
+}
+/* Saves a 32-bit signed int encoded as little-endian to gz_file. */
+static int write_int32(gzFile gz_file, int32_t number) {
+ uint32_t encoded = encode_little_endian(static_cast(number));
+ if (!gzwrite(gz_file, &encoded, sizeof(encoded))) {
+ return -1;
+ }
+ return 0;
+}
+static int write_header(gzFile gz_file, struct RexPaintHeader *xp_header) {
+ return (write_int32(gz_file, xp_header->version) ||
+ write_int32(gz_file, xp_header->layer_count));
+}
+static int write_layer(gzFile gz_file, struct RexPaintLayerChunk *xp_layer) {
+ return (write_int32(gz_file, xp_layer->width) ||
+ write_int32(gz_file, xp_layer->height));
+}
+static int write_tile(gzFile gz_file, struct RexPaintTile *tile) {
+ if (write_int32(gz_file, tile->ch) ||
+ !gzwrite(gz_file, &tile->fg, sizeof(tile->fg)) ||
+ !gzwrite(gz_file, &tile->bg, sizeof(tile->bg))) {
+ return -1;
+ }
+ return 0;
+}
+static int write_console(gzFile gz_file, const TCOD_Console* console) {
+ int x, y;
+ struct RexPaintLayerChunk xp_layer;
+ xp_layer.width = TCOD_console_get_width(console);
+ xp_layer.height = TCOD_console_get_height(console);
+ if (write_layer(gz_file, &xp_layer)) {
+ return -1; /* error writing layer */
+ }
+ /* Write console data out in column-major order. */
+ for (x = 0; x < xp_layer.width; ++x) {
+ for (y = 0; y < xp_layer.height; ++y) {
+ struct RexPaintTile tile;
+ tile.ch = TCOD_console_get_char(console, x, y);
+ tile.fg = TCOD_console_get_char_foreground(console, x, y);
+ tile.bg = TCOD_console_get_char_background(console, x, y);
+ if (write_tile(gz_file, &tile)) {
+ return -1; /* error writing tile data */
+ }
+ }
+ }
+ return 0;
+}
+/**
+ * \brief Save a console as a REXPaint ``.xp`` file.
+ *
+ * \param [in] con The console instance to save.
+ * \param [in] filename The filepath to save to.
+ * \param [in] compress_level A zlib compression level, from 0 to 9.
+ * 1=fast, 6=balanced, 9=slowest, 0=uncompressed.
+ * \return ``true`` when the file is saved succesfully, or ``false`` when an
+ * issue is detected.
+ *
+ * The REXPaint format can support a 1:1 copy of a libtcod console.
+ */
+bool TCOD_console_save_xp(
+ const TCOD_Console* con, const char *filename, int compress_level) {
+ struct RexPaintHeader xp_header;
+ gzFile gz_file = gzopen(filename, "wb");
+ if (!gz_file) { return false; /* could not open file */ }
+ gzsetparams(gz_file, compress_level, Z_DEFAULT_STRATEGY);
+ xp_header.version = -1; /* REXPaint uses this version. */
+ xp_header.layer_count = 1;
+ if (write_header(gz_file, &xp_header) || write_console(gz_file, con)) {
+ gzclose(gz_file);
+ return false; /* error writing data */
+ }
+ if (gzclose(gz_file)) { return false; /* error writing to file */ }
+ return true;
+}
+/**
+ * \brief Save a list of consoles to a REXPaint file.
+ *
+ * \param [in] console_list A TCOD_list_t of TCOD_console_t objects.
+ * \param [in] filename Path to save to.
+ * \param [in] compress_level zlib compression level.
+ * \return true on success, false on a failure such as not being able to write
+ * to the path provided.
+ *
+ * This function can save any number of layers with multiple
+ * different sizes.
+ *
+ * The REXPaint tool only supports files with up to 9 layers where
+ * all layers are the same size.
+ */
+bool TCOD_console_list_save_xp(
+ TCOD_list_t console_list, const char *filename, int compress_level) {
+ int i;
+ struct RexPaintHeader xp_header;
+ gzFile gz_file = gzopen(filename, "wb");
+ if (!gz_file) { return false; /* could not open file */ }
+ gzsetparams(gz_file, compress_level, Z_DEFAULT_STRATEGY);
+ xp_header.version = -1;
+ xp_header.layer_count = TCOD_list_size(console_list);
+ if (write_header(gz_file, &xp_header)) {
+ gzclose(gz_file);
+ return false; /* error writing metadata */
+ }
+ for (i = 0; i < xp_header.layer_count; ++i){
+ if (write_console(
+ gz_file, static_cast(TCOD_list_get(console_list, i)))) {
+ gzclose(gz_file);
+ return false; /* error writing out console data */
+ }
+ }
+ if (gzclose(gz_file)) { return false; /* error writing to file */ }
+ return true;
+}
+
+#endif /* TCOD_CONSOLE_SUPPORT */
diff --git a/tcod_sys/libtcod/src/libtcod/console/rexpaint.h b/tcod_sys/libtcod/src/libtcod/console/rexpaint.h
new file mode 100644
index 000000000..cda87b904
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/console/rexpaint.h
@@ -0,0 +1,46 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef TCOD_CONSOLE_REXPAINT_H_
+#define TCOD_CONSOLE_REXPAINT_H_
+
+#include "../portability.h"
+#include "../console_types.h"
+#include "../list.h"
+TCODLIB_CAPI TCOD_console_t TCOD_console_from_xp(const char *filename);
+TCODLIB_CAPI bool TCOD_console_load_xp(TCOD_Console* con,
+ const char *filename);
+TCODLIB_CAPI bool TCOD_console_save_xp(
+ const TCOD_Console* con, const char *filename, int compress_level);
+TCODLIB_CAPI TCOD_list_t TCOD_console_list_from_xp(const char *filename);
+TCODLIB_CAPI bool TCOD_console_list_save_xp(
+ TCOD_list_t console_list, const char *filename, int compress_level);
+#endif /* TCOD_CONSOLE_REXPAINT_H_ */
diff --git a/tcod_sys/libtcod/src/libtcod/console_c.cpp b/tcod_sys/libtcod/src/libtcod/console_c.cpp
new file mode 100644
index 000000000..a7b12515b
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/console_c.cpp
@@ -0,0 +1,1381 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "console.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include "console.hpp"
+#include "noise.h"
+#include "mersenne.h"
+#include "libtcod_int.h"
+#include "utility.h"
+#include "version.h"
+#include "console/drawing.h"
+#include "engine/error.h"
+#include "engine/globals.h"
+#include "tileset/tileset.h"
+#include "tileset/tilesheet.h"
+
+#ifdef TCOD_CONSOLE_SUPPORT
+
+#if defined( TCOD_VISUAL_STUDIO )
+static const char *version_string = "libtcod " TCOD_STRVERSION;
+#else
+static const char *version_string __attribute__((unused)) = "libtcod " TCOD_STRVERSION;
+#endif
+
+TCOD_internal_context_t TCOD_ctx={
+ /* number of characters in the bitmap font */
+ 16,16,
+ /* font type and layout */
+ false,false,false,
+ 0,
+ /* character size in font */
+ 0, 0,
+ "terminal.png","",
+ NULL,NULL,NULL,0,false,0,0,0,0,0,0,
+#ifndef TCOD_BARE
+ /* default renderer to use */
+ TCOD_RENDERER_GLSL,
+ NULL,
+#endif
+ /* fading data */
+ {0,0,0},255,
+ /*key state*/
+ {},
+ /* window closed ? */
+ false,
+ /* mouse focus ? */
+ false,
+ /* application active ? */
+ true,
+};
+/**
+ * Wait for a key press event, then return it.
+ *
+ * \param flush If 1 then the event queue will be cleared before waiting for
+ * the next event. This should always be 0.
+ * \return A TCOD_key_t struct with the most recent key data.
+ *
+ * Do not solve input lag issues by arbitrarily dropping events!
+ */
+TCOD_key_t TCOD_console_wait_for_keypress(bool flush) {
+ return TCOD_sys_wait_for_keypress(flush);
+}
+/**
+ * Return immediately with a recently pressed key.
+ *
+ * \param flags A TCOD_event_t bit-field, for example: `TCOD_EVENT_KEY_PRESS`
+ * \return A TCOD_key_t struct with a recently pressed key.
+ * If no event exists then the `vk` attribute will be `TCODK_NONE`
+ */
+TCOD_key_t TCOD_console_check_for_keypress(int flags) {
+ return TCOD_sys_check_for_keypress(flags);
+}
+/**
+ * Render and present the root console to the active display.
+ */
+void TCOD_console_flush(void) {
+ TCOD_sys_flush(true);
+}
+/**
+ * Manually mark a region of a console as dirty.
+ */
+void TCOD_console_set_dirty(int dx, int dy, int dw, int dh) {
+ TCOD_sys_set_dirty(dx, dy, dw, dh);
+}
+/**
+ * \brief Set a font image to be loaded during initialization.
+ *
+ * \param fontFile The path to a font image.
+ * \param flags A TCOD_font_flags_t bit-field describing the font image
+ * contents.
+ * \param nb_char_horiz The number of columns in the font image.
+ * \param nb_char_vertic The number of rows in the font image.
+ *
+ * `fontFile` will be case-sensitive depending on the platform.
+ *
+ * Returns 0 on success, or -1 on an error, you can check the error with
+ * TCOD_sys_get_error()
+ * \rst
+ * .. versionchanged:: 1.12
+ * Now returns -1 on error instead of crashing.
+ * \endrst
+ */
+int TCOD_console_set_custom_font(
+ const char *fontFile,
+ int flags,
+ int nb_char_horiz,
+ int nb_char_vertic)
+{
+ strcpy(TCOD_ctx.font_file, fontFile);
+ /* if layout not defined, assume ASCII_INCOL */
+ if (!(flags & (TCOD_FONT_LAYOUT_ASCII_INCOL
+ | TCOD_FONT_LAYOUT_ASCII_INROW | TCOD_FONT_LAYOUT_TCOD))) {
+ flags |= TCOD_FONT_LAYOUT_ASCII_INCOL;
+ }
+ TCOD_ctx.font_in_row = ((flags & TCOD_FONT_LAYOUT_ASCII_INROW) != 0);
+ TCOD_ctx.font_greyscale = ((flags & TCOD_FONT_TYPE_GREYSCALE) != 0);
+ TCOD_ctx.font_tcod_layout = ((flags & TCOD_FONT_LAYOUT_TCOD) != 0);
+ TCOD_ctx.font_flags = flags;
+ if (nb_char_horiz > 0 && nb_char_vertic > 0) {
+ TCOD_ctx.fontNbCharHoriz = nb_char_horiz;
+ TCOD_ctx.fontNbCharVertic = nb_char_vertic;
+ } else {
+ if (flags & TCOD_FONT_LAYOUT_TCOD) {
+ TCOD_ctx.fontNbCharHoriz = nb_char_horiz = 32;
+ TCOD_ctx.fontNbCharVertic = nb_char_vertic = 8;
+ } else {
+ TCOD_ctx.fontNbCharHoriz = nb_char_horiz = 16;
+ TCOD_ctx.fontNbCharVertic = nb_char_vertic = 16;
+ }
+ }
+ if (TCOD_ctx.font_tcod_layout) { TCOD_ctx.font_in_row = true; }
+ TCOD_sys_set_custom_font(fontFile, nb_char_horiz, nb_char_vertic, flags);
+
+ using tcod::image::Image;
+ using tcod::tileset::Tileset;
+ using tcod::tileset::Tilesheet;
+
+ try {
+ Image image = tcod::image::load(TCOD_ctx.font_file);
+ auto tilesheet = std::make_shared(
+ image, std::make_pair(nb_char_horiz, nb_char_vertic));
+ tcod::engine::set_tilesheet(tilesheet);
+
+ auto tileset = std::make_shared(tilesheet->get_tile_width(),
+ tilesheet->get_tile_height());
+ tcod::engine::set_tileset(tileset);
+ } catch (const std::exception& e) {
+ return tcod::set_error(e);
+ }
+ TCOD_sys_decode_font_();
+ return 0;
+}
+/**
+ * \brief Remap a character code to a tile.
+ *
+ * \param asciiCode Character code to modify.
+ * \param fontCharX X tile-coordinate, starting from the left at zero.
+ * \param fontCharY Y tile-coordinate, starting from the top at zero.
+ *
+ * X,Y parameters are the coordinate of the tile, not pixel-coordinates.
+ */
+void TCOD_console_map_ascii_code_to_font(int asciiCode,
+ int fontCharX, int fontCharY)
+{
+ /* cannot change mapping before initRoot is called */
+ TCOD_IFNOT(TCOD_ctx.root) { return; }
+ TCOD_sys_map_ascii_to_font(asciiCode, fontCharX, fontCharY);
+}
+/**
+ * \brief Remap a series of character codes to a row of tiles.
+ *
+ * \param asciiCode The starting character code.
+ * \param nbCodes Number of character codes to assign.
+ * \param fontCharX First X tile-coordinate, starting from the left at zero.
+ * \param fontCharY First Y tile-coordinate, starting from the top at zero.
+ *
+ * This function always assigns tiles in row-major order, even if the
+ * TCOD_FONT_LAYOUT_ASCII_INCOL flag was set.
+ */
+void TCOD_console_map_ascii_codes_to_font(int asciiCode, int nbCodes,
+ int fontCharX, int fontCharY)
+{
+ /* cannot change mapping before initRoot is called */
+ TCOD_IFNOT(TCOD_ctx.root) { return; }
+ TCOD_IFNOT(asciiCode >= 0 && asciiCode+nbCodes <= TCOD_ctx.max_font_chars) {
+ return;
+ }
+ for (int c = asciiCode; c < asciiCode + nbCodes; ++c) {
+ TCOD_sys_map_ascii_to_font(c, fontCharX, fontCharY);
+ ++fontCharX;
+ if (fontCharX == TCOD_ctx.fontNbCharHoriz) {
+ fontCharX = 0;
+ ++fontCharY;
+ }
+ }
+}
+/**
+ * \brief Remap a string of character codes to a row of tiles.
+ *
+ * \param s A null-terminated string.
+ * \param fontCharX First X tile-coordinate, starting from the left at zero.
+ * \param fontCharY First Y tile-coordinate, starting from the top at zero.
+ *
+ * This function always assigns tiles in row-major order, even if the
+ * TCOD_FONT_LAYOUT_ASCII_INCOL flag was set.
+ */
+void TCOD_console_map_string_to_font(const char *s,
+ int fontCharX, int fontCharY)
+{
+ TCOD_IFNOT(s) { return; }
+ /* cannot change mapping before initRoot is called */
+ TCOD_IFNOT(TCOD_ctx.root) { return; }
+ while (*s) {
+ TCOD_console_map_ascii_code_to_font(*s, fontCharX, fontCharY);
+ ++fontCharX;
+ if (fontCharX == TCOD_ctx.fontNbCharHoriz) {
+ fontCharX = 0;
+ ++fontCharY;
+ }
+ ++s;
+ }
+}
+
+bool TCOD_console_is_key_pressed(TCOD_keycode_t key) {
+ return TCOD_sys_is_key_pressed(key);
+}
+void TCOD_console_set_key_color(TCOD_Console* con,TCOD_color_t col) {
+ con = TCOD_console_validate_(con);
+ if (!con) { return; }
+ con->has_key_color = 1;
+ con->key_color = col;
+}
+
+void TCOD_console_credits(void) {
+ bool end=false;
+ int x=TCOD_console_get_width(NULL)/2-6;
+ int y=TCOD_console_get_height(NULL)/2;
+ int fade=260;
+ TCOD_sys_save_fps();
+ TCOD_sys_set_fps(25);
+ while (!end ) {
+ TCOD_key_t k;
+ end=TCOD_console_credits_render(x,y,false);
+ TCOD_sys_check_for_event(TCOD_EVENT_KEY_PRESS,&k,NULL);
+ if ( fade == 260 && k.vk != TCODK_NONE ) {
+ fade -= 10;
+ }
+ TCOD_console_flush();
+ if ( fade < 260 ) {
+ fade -= 10;
+ TCOD_console_set_fade(fade,TCOD_black);
+ if ( fade == 0 ) end=true;
+ }
+ }
+ TCOD_console_set_fade(255,TCOD_black);
+ TCOD_sys_restore_fps();
+}
+
+static bool init2=false;
+
+void TCOD_console_credits_reset(void) {
+ init2=false;
+}
+
+bool TCOD_console_credits_render(int x, int y, bool alpha) {
+ static char poweredby[128];
+ static float char_heat[128];
+ static int char_x[128];
+ static int char_y[128];
+ static bool init1=false;
+ static int len,len1,cw=-1,ch=-1;
+ static float xstr;
+ static TCOD_color_t colmap[64];
+ static TCOD_color_t colmap_light[64];
+ static TCOD_noise_t noise;
+ static TCOD_color_t colkeys[4] = {
+ {255,255,204},
+ {255,204,0},
+ {255,102,0},
+ {102,153,255},
+ };
+ static TCOD_color_t colkeys_light[4] = {
+ {255,255,204},
+ {128,128,77},
+ {51,51,31},
+ {0,0,0},
+ };
+ static int colpos[4]={
+ 0,21,42,63
+ };
+ static TCOD_image_t img=NULL;
+ int i,xc,yc,xi,yi,j;
+ static int left,right,top,bottom;
+ float sparklex,sparkley,sparklerad,sparklerad2,noisex;
+ /* mini particule system */
+#define MAX_PARTICULES 50
+ static float pheat[MAX_PARTICULES];
+ static float px[MAX_PARTICULES],py[MAX_PARTICULES], pvx[MAX_PARTICULES],pvy[MAX_PARTICULES];
+ static int nbpart=0, firstpart=0;
+ static float partDelay=0.1f;
+ float elapsed=TCOD_sys_get_last_frame_length();
+ TCOD_color_t fbackup; /* backup fg color */
+
+ if (!init1) {
+ /* initialize all static data, colormaps, ... */
+ TCOD_color_t col;
+ TCOD_color_gen_map(colmap,4,colkeys,colpos);
+ TCOD_color_gen_map(colmap_light,4,colkeys_light,colpos);
+ sprintf(poweredby,"Powered by\n%s",version_string);
+ noise=TCOD_noise_new(1,TCOD_NOISE_DEFAULT_HURST,TCOD_NOISE_DEFAULT_LACUNARITY,NULL);
+ len=static_cast(strlen(poweredby));
+ len1=11; /* sizeof "Powered by\n" */
+ left=MAX(x-4,0);
+ top=MAX(y-4,0);
+ col= TCOD_console_get_default_background(NULL);
+ TCOD_console_set_default_background(NULL,TCOD_black);
+ TCOD_console_set_default_background(NULL,col);
+ init1=true;
+ }
+ if (!init2) {
+ /* reset the credits vars ... */
+ int curx,cury;
+ xstr=-4.0f;
+ curx=x;
+ cury=y;
+ for (i=0; i < len ;i++) {
+ char_heat[i]=-1;
+ char_x[i]=curx;
+ char_y[i]=cury;
+ curx++;
+ if ( poweredby[i] == '\n' ) {
+ curx=x;
+ cury++;
+ }
+ }
+ nbpart=firstpart=0;
+ init2=true;
+ }
+ if (TCOD_console_get_width(NULL) != cw || TCOD_console_get_height(NULL)!=ch) {
+ /* console size has changed */
+ int width,height;
+ cw=TCOD_console_get_width(NULL);
+ ch=TCOD_console_get_height(NULL);
+ right=MIN(x+len,cw-1);
+ bottom=MIN(y+6,ch-1);
+ width=right - left + 1;
+ height=bottom - top + 1;
+ if ( img ) TCOD_image_delete(img);
+ img = TCOD_image_new(width*2,height*2);
+ }
+ fbackup=TCOD_console_get_default_foreground(NULL);
+ if ( xstr < len1 ) {
+ sparklex=x+xstr;
+ sparkley=y;
+ } else {
+ sparklex=x-len1+xstr;
+ sparkley=y+1;
+ }
+ noisex=xstr*6;
+ sparklerad=3.0f+2*TCOD_noise_get(noise,&noisex);
+ if ( xstr >= len-1 ) sparklerad -= (xstr-len+1)*4.0f;
+ else if ( xstr < 0.0f ) sparklerad += xstr*4.0f;
+ else if ( poweredby[ static_cast(xstr+0.5f) ] == ' ' || poweredby[ static_cast(xstr+0.5f) ] == '\n' ) sparklerad/=2;
+ sparklerad2=sparklerad*sparklerad*4;
+
+ /* draw the light */
+ for (xc=left*2,xi=0; xc < (right+1)*2; xc++,xi++) {
+ for (yc=top*2,yi=0; yc < (bottom+1)*2; yc++,yi++) {
+ float dist=((xc-2*sparklex)*(xc-2*sparklex)+(yc-2*sparkley)*(yc-2*sparkley));
+ TCOD_color_t pixcol;
+ if ( sparklerad >= 0.0f && dist < sparklerad2 ) {
+ int colidx=63-static_cast(63*(sparklerad2-dist)/sparklerad2) + TCOD_random_get_int(NULL,-10,10);
+ colidx=CLAMP(0,63,colidx);
+ pixcol=colmap_light[colidx];
+ } else {
+ pixcol=TCOD_black;
+ }
+ if ( alpha ) {
+ /* console cells have following flag values :
+ 1 2
+ 4 8
+ flag indicates which subcell uses foreground color */
+ static int asciiToFlag[] = {
+ 1, /* TCOD_CHAR_SUBP_NW */
+ 2, /* TCOD_CHAR_SUBP_NE */
+ 3, /* TCOD_CHAR_SUBP_N */
+ 8, /* TCOD_CHAR_SUBP_SE */
+ 9, /* TCOD_CHAR_SUBP_DIAG */
+ 10, /* TCOD_CHAR_SUBP_E */
+ 4, /* TCOD_CHAR_SUBP_SW */
+ };
+ int conc= TCOD_console_get_char(NULL,xc/2,yc/2);
+ TCOD_color_t bk=TCOD_console_get_char_background(NULL,xc/2,yc/2);
+ if ( conc >= TCOD_CHAR_SUBP_NW && conc <= TCOD_CHAR_SUBP_SW ) {
+ /* merge two subcell chars...
+ get the flag for the existing cell on root console */
+ int bkflag=asciiToFlag[conc - TCOD_CHAR_SUBP_NW ];
+ int xflag = (xc & 1);
+ int yflag = (yc & 1);
+ /* get the flag for the current subcell */
+ int credflag = (1+3*yflag) * (xflag+1);
+ if ( (credflag & bkflag) != 0 ) {
+ /* the color for this subcell on root console
+ is foreground, not background */
+ bk = TCOD_console_get_char_foreground(NULL,xc/2,yc/2);
+ }
+ }
+ pixcol.r = std::min(255, bk.r + pixcol.r);
+ pixcol.g = std::min(255, bk.g + pixcol.g);
+ pixcol.b = std::min(255, bk.b + pixcol.b);
+ }
+ TCOD_image_put_pixel(img,xi,yi,pixcol);
+ }
+ }
+
+ /* draw and update the particules */
+ j=nbpart;i=firstpart;
+ while (j > 0) {
+ int colidx = static_cast(64 * (1.0f - pheat[i]));
+ TCOD_color_t col;
+ colidx=std::min(63, colidx);
+ col=colmap[colidx];
+ if (py[i] < (bottom - top + 1) * 2) {
+ int ipx = static_cast(px[i]);
+ int ipy = static_cast(py[i]);
+ float fpx = px[i]-ipx;
+ float fpy = py[i]-ipy;
+ TCOD_color_t col2=TCOD_image_get_pixel(img,ipx,ipy);
+ col2=TCOD_color_lerp(col,col2,0.5f*(fpx+fpy));
+ TCOD_image_put_pixel(img,ipx,ipy,col2);
+ col2=TCOD_image_get_pixel(img,ipx+1,ipy);
+ col2=TCOD_color_lerp(col2,col,fpx);
+ TCOD_image_put_pixel(img,ipx+1,ipy,col2);
+ col2=TCOD_image_get_pixel(img,ipx,ipy+1);
+ col2=TCOD_color_lerp(col2,col,fpy);
+ TCOD_image_put_pixel(img,ipx,ipy+1,col2);
+ } else pvy[i]=-pvy[i] * 0.5f;
+ pvx[i] *= (1.0f-elapsed);
+ pvy[i] += (1.0f-pheat[i])*elapsed*300.0f;
+ px[i] += pvx[i]*elapsed;
+ py[i] += pvy[i]*elapsed;
+ pheat[i] -= elapsed*0.3f;
+ if ( pheat[i] < 0.0f ) {
+ firstpart = (firstpart+1)%MAX_PARTICULES;
+ nbpart--;
+ }
+ i = (i+1)%MAX_PARTICULES;
+ j--;
+ }
+ partDelay -= elapsed;
+ if ( partDelay < 0.0f && nbpart < MAX_PARTICULES && sparklerad > 2.0f ) {
+ /* fire a new particule */
+ int lastpart = firstpart;
+ int nb=nbpart;
+ while (nb > 0 ) {
+ lastpart = ( lastpart + 1 )%MAX_PARTICULES;
+ nb--;
+ }
+ nbpart++;
+ px[lastpart] = 2*(sparklex-left);
+ py[lastpart] = 2*(sparkley-top)+2;
+ pvx[lastpart] = TCOD_random_get_float(NULL,-5.0f,5.0f);
+ pvy[lastpart] = TCOD_random_get_float(NULL,-0.5f, -15.0f);
+ pheat[lastpart] = 1.0f;
+ partDelay += 0.1f;
+ }
+ TCOD_image_blit_2x(img,NULL,left,top,0,0,-1,-1);
+ /* draw the text */
+ for (i=0; i < len ;i++) {
+ if ( char_heat[i] >= 0.0f && poweredby[i]!='\n') {
+ int colidx = static_cast(64 * char_heat[i]);
+ TCOD_color_t col;
+ colidx=MIN(63,colidx);
+ col=colmap[colidx];
+ if ( xstr >= len ) {
+ float coef=(xstr-len)/len;
+ if ( alpha ) {
+ TCOD_color_t fore=TCOD_console_get_char_background(NULL,char_x[i],char_y[i]);
+ int r = static_cast(coef * fore.r + (1.0f - coef) * col.r);
+ int g = static_cast(coef * fore.g + (1.0f - coef) * col.g);
+ int b = static_cast(coef * fore.b + (1.0f - coef) * col.b);
+ col.r = std::max(0, std::min(r, 255));
+ col.g = std::max(0, std::min(g, 255));
+ col.b = std::max(0, std::min(b, 255));
+ TCOD_console_set_char_foreground(NULL,char_x[i],char_y[i],col);
+ } else {
+ col=TCOD_color_lerp(col,TCOD_black,coef);
+ }
+ }
+ TCOD_console_set_char(NULL,char_x[i],char_y[i],poweredby[i]);
+ TCOD_console_set_char_foreground(NULL,char_x[i],char_y[i],col);
+ }
+ }
+ /* update letters heat */
+ xstr += elapsed * 4;
+ for (i = 0; i < static_cast(xstr+0.5f); ++i) {
+ char_heat[i]=(xstr-i)/(len/2);
+ }
+ /* restore fg color */
+ TCOD_console_set_default_foreground(NULL,fbackup);
+ if ( xstr <= 2*len ) return false;
+ init2=false;
+ return true;
+}
+
+static void TCOD_console_read_asc(TCOD_console_t con, FILE *f,
+ int width, int height, float version)
+{
+ con = TCOD_console_validate_(con);
+ TCOD_IFNOT(con) { return; }
+ while(fgetc(f) != '#');
+ for(int x = 0; x < width; ++x) {
+ for(int y = 0; y < height; ++y) {
+ TCOD_color_t fore, back;
+ int c = fgetc(f);
+ fore.r = fgetc(f);
+ fore.g = fgetc(f);
+ fore.b = fgetc(f);
+ back.r = fgetc(f);
+ back.g = fgetc(f);
+ back.b = fgetc(f);
+ /* skip solid/walkable info */
+ if (version >= 0.3f) {
+ fgetc(f);
+ fgetc(f);
+ }
+ TCOD_console_put_char_ex(con, x, y, c, fore, back);
+ }
+ }
+ fclose(f);
+}
+
+static int string_ends_with(const char *str, const char *suffix) {
+ size_t str_len = strlen(str);
+ size_t suffix_len = strlen(suffix);
+ return
+ (str_len >= suffix_len) &&
+ (0 == strcmp(str + (str_len-suffix_len), suffix));
+}
+
+TCOD_console_t TCOD_console_from_file(const char *filename) {
+ float version;
+ int width,height;
+ TCOD_console_t con;
+ FILE *f;
+ TCOD_IFNOT( filename != NULL ) {
+ return NULL;
+ }
+ if (string_ends_with(filename, ".xp")) {
+ return TCOD_console_from_xp(filename);
+ }
+ f=fopen(filename,"rb");
+ TCOD_IFNOT( f!=NULL ) {
+ return NULL;
+ }
+ if (fscanf(f, "ASCII-Paint v%g", &version) != 1 ) {
+ fclose(f);
+ return NULL;
+ }
+ if (fscanf(f, "%i %i", &width, &height) != 2 ) {
+ fclose(f);
+ return NULL;
+ }
+ TCOD_IFNOT ( width > 0 && height > 0) {
+ fclose(f);
+ return NULL;
+ }
+ con=TCOD_console_new(width,height);
+ if (string_ends_with(filename, ".asc")) {
+ TCOD_console_read_asc(con,f,width,height,version);
+ }
+ return con;
+}
+
+bool TCOD_console_load_asc(TCOD_console_t pcon, const char *filename) {
+ float version;
+ int width,height;
+ FILE *f;
+ struct TCOD_Console *con = TCOD_console_validate_(pcon);
+ TCOD_IFNOT(con != NULL) return false;
+ TCOD_IFNOT( filename != NULL ) {
+ return false;
+ }
+ f=fopen(filename,"rb");
+ TCOD_IFNOT( f!=NULL ) {
+ return false;
+ }
+ if (fscanf(f, "ASCII-Paint v%g", &version) != 1 ) {
+ fclose(f);
+ return false;
+ }
+ if (fscanf(f, "%i %i", &width, &height) != 2 ) {
+ fclose(f);
+ return false;
+ }
+ TCOD_IFNOT ( width > 0 && height > 0) {
+ fclose(f);
+ return false;
+ }
+ TCOD_console_resize_(con, width, height);
+ TCOD_console_read_asc(con,f,width,height,version);
+ return true;
+}
+
+bool TCOD_console_save_asc(TCOD_console_t pcon, const char *filename) {
+ static float version = 0.3f;
+ FILE *f;
+ int x,y;
+ struct TCOD_Console *con = TCOD_console_validate_(pcon);
+ TCOD_IFNOT(con != NULL) return false;
+ TCOD_IFNOT( filename != NULL ) {
+ return false;
+ }
+ TCOD_IFNOT(con->w > 0 && con->h > 0) return false;
+ f=fopen(filename,"wb");
+ TCOD_IFNOT( f != NULL ) return false;
+ fprintf(f, "ASCII-Paint v%g\n", static_cast(version));
+ fprintf(f, "%i %i\n", con->w, con->h);
+ fputc('#', f);
+ for(x = 0; x < con->w; x++) {
+ for(y = 0; y < con->h; y++) {
+ TCOD_color_t fore,back;
+ int c=TCOD_console_get_char(con,x,y);
+ fore=TCOD_console_get_char_foreground(con,x,y);
+ back=TCOD_console_get_char_background(con,x,y);
+ fputc(c, f);
+ fputc(fore.r,f);
+ fputc(fore.g,f);
+ fputc(fore.b,f);
+ fputc(back.r,f);
+ fputc(back.g,f);
+ fputc(back.b,f);
+ fputc(0,f); /* solid */
+ fputc(1,f); /* walkable */
+ }
+ }
+ fclose(f);
+ return true;
+}
+
+static bool hasDetectedBigEndianness = false;
+static bool isBigEndian;
+void detectBigEndianness(void) {
+ if (!hasDetectedBigEndianness){
+ uint32_t Value32;
+ uint8_t *VPtr = reinterpret_cast(&Value32);
+ VPtr[0] = VPtr[1] = VPtr[2] = 0; VPtr[3] = 1;
+ if(Value32 == 1) isBigEndian = true;
+ else isBigEndian = false;
+ hasDetectedBigEndianness = true;
+ }
+}
+#ifndef bswap16
+static uint16_t bswap16(uint16_t s)
+{
+ uint8_t* ps = reinterpret_cast(&s);
+ uint16_t res;
+ uint8_t* pres = reinterpret_cast(&res);
+ pres[0] = ps[1];
+ pres[1] = ps[0];
+ return res;
+}
+#endif
+#ifndef bswap32
+static uint32_t bswap32(uint32_t s)
+{
+ uint8_t *ps = reinterpret_cast(&s);
+ uint32_t res;
+ uint8_t *pres = reinterpret_cast(&res);
+ pres[0]=ps[3];
+ pres[1]=ps[2];
+ pres[2]=ps[1];
+ pres[3]=ps[0];
+ return res;
+}
+#endif
+uint16_t l16(uint16_t s){
+ if (isBigEndian) return bswap16(s); else return s;
+}
+
+uint32_t l32(uint32_t s){
+ if (isBigEndian) return bswap32(s); else return s;
+}
+
+/* fix the endianness */
+void fix16(uint16_t* u){
+ *u = l16(*u);
+}
+
+void fix32(uint32_t* u){
+ *u = l32(*u);
+}
+
+/************ RIFF helpers */
+
+uint32_t fourCC(const char* c){
+ return (*reinterpret_cast(c));
+}
+
+/* checks if u equals str */
+bool fourCCequals(uint32_t u, const char* str){
+ return fourCC(str)==u;
+}
+
+void fromFourCC(uint32_t u, char*s){
+ const char* c = reinterpret_cast(&u);
+ s[0]=c[0];
+ s[1]=c[1];
+ s[2]=c[2];
+ s[3]=c[3];
+ s[4]=0;
+}
+
+void put8(uint8_t d, FILE* fp){
+ fwrite(&d,1,1,fp);
+}
+
+void put16(uint16_t d, FILE* fp){
+ fwrite(&d,2,1,fp);
+}
+
+void put32(uint32_t d, FILE* fp){
+ fwrite(&d,4,1,fp);
+}
+
+void putFourCC(const char* c, FILE* fp){
+ put32(fourCC(c),fp);
+}
+
+void putData(void* what, int length, FILE* fp){
+ fwrite(what,length,1,fp);
+}
+
+bool get8(uint8_t* u, FILE* fp){
+ return 1==fread(u, sizeof(uint8_t),1,fp);
+}
+
+bool get16(uint16_t* u, FILE* fp){
+ return 1==fread(u, sizeof(uint16_t),1,fp);
+}
+
+bool get32(uint32_t* u, FILE* fp){
+ return 1==fread(u, sizeof(uint32_t),1,fp);
+}
+
+bool getData(void* u, size_t sz, FILE* fp){
+ return 1==fread(u, sz,1,fp);
+}
+
+
+/********* APF RIFF structures */
+
+typedef struct {
+ uint32_t show_grid;
+ uint32_t grid_width;
+ uint32_t grid_height;
+} SettingsDataV1;
+
+#define FILTER_TYPE_UNCOMPRESSED 0
+#define FORMAT_TYPE_CRGBRGB 0
+
+typedef struct {
+ uint32_t width;
+ uint32_t height;
+ uint32_t filter;
+ uint32_t format;
+} ImageDetailsV1;
+
+/* Layers */
+
+typedef struct {
+ uint32_t name;
+ uint32_t mode;
+ uint32_t index;
+ uint32_t dataSize;
+} LayerV1 ;
+
+typedef struct {
+ uint32_t name;
+ uint32_t mode;
+ uint32_t fgalpha;
+ uint32_t bgalpha;
+ uint32_t visible;
+ uint32_t index;
+ uint32_t dataSize;
+} LayerV2;
+
+/* fix the endianness */
+void fixSettings(SettingsDataV1* s){
+ fix32(&s->show_grid);
+ fix32(&s->grid_width);
+ fix32(&s->grid_height);
+}
+
+void fixImage(ImageDetailsV1* v){
+ fix32(&v->width);
+ fix32(&v->height);
+ fix32(&v->filter);
+ fix32(&v->format);
+}
+
+void fixLayerv1(LayerV1* l){
+ fix32(&l->mode);
+ fix32(&l->index);
+ fix32(&l->dataSize);
+}
+
+void fixLayerv2(LayerV2* l){
+ fix32(&l->mode);
+ fix32(&l->fgalpha);
+ fix32(&l->bgalpha);
+ fix32(&l->visible);
+ fix32(&l->index);
+ fix32(&l->dataSize);
+}
+
+
+/*********** ApfFile */
+
+bool TCOD_console_save_apf(TCOD_console_t pcon, const char *filename) {
+ struct TCOD_Console *con = TCOD_console_validate_(pcon);
+ FILE* fp ;
+ TCOD_IFNOT(con != NULL) return false;
+ detectBigEndianness();
+
+ fp = fopen(filename, "wb");
+ if(fp == NULL) {
+ return false;
+ }
+ else {
+ int x,y;
+ uint32_t riffSize = 0;
+ uint32_t imgDetailsSize ;
+ SettingsDataV1 settingsData;
+ ImageDetailsV1 imgData;
+ fpos_t posRiffSize;
+ uint32_t settingsSz ;
+ uint32_t layerImageSize ;
+ uint32_t layerChunkSize ;
+ /* riff header*/
+ putFourCC("RIFF",fp);
+ fgetpos(fp,&posRiffSize);
+ put32(0,fp);
+
+ /* APF_ header */
+ putFourCC("apf ",fp);
+ riffSize += 4;
+
+ /* settings */
+ settingsData.show_grid = 0;
+ settingsData.grid_width = 8;
+ settingsData.grid_height = 8;
+ settingsSz = sizeof(uint32_t) + sizeof settingsData;
+ putFourCC("sett",fp);
+ put32(l32(settingsSz),fp);
+ put32(l32(1),fp);
+ putData(&settingsData,sizeof settingsData,fp);
+ if (settingsSz&1){
+ put8(0,fp);
+ riffSize++;
+ }
+ riffSize += 4+4+settingsSz;
+
+ /* image details */
+ imgData.width = con->w;
+ imgData.height = con->h;
+ imgData.filter = 0;
+ imgData.format = 0;
+ imgDetailsSize = sizeof(uint32_t) + sizeof imgData;
+ putFourCC("imgd",fp);
+ put32(l32(imgDetailsSize),fp);
+ put32(l32(1),fp);
+ putData(&imgData,sizeof imgData,fp);
+ if (imgDetailsSize&1){
+ put8(0,fp);
+ riffSize++;
+ }
+ riffSize += 4+4+imgDetailsSize;
+
+ /* now write the layers as a RIFF list
+ the first layer is the lowest layer
+ Assume imgData filter = uncompressed, and imgData format = CRGB */
+ layerImageSize = imgData.width*imgData.height*7;
+ layerChunkSize = sizeof(uint32_t) /* version */
+ + sizeof(LayerV2) /* header */
+ + layerImageSize; /* data */
+
+ putFourCC("layr",fp); /* layer */
+ put32(l32(layerChunkSize),fp);
+ /* VERSION -> */
+ put32(l32(2),fp);
+ /* Data */
+ putFourCC("LAY0",fp);
+ put32(l32(0),fp);
+ put32(l32(255),fp);
+ put32(l32(255),fp);
+ put32(l32(1),fp);
+ put32(l32(0),fp);
+ put32(l32(layerImageSize),fp);
+
+ /* now write out the data */
+
+ for(x = 0; x < con->w; x++) {
+ for(y = 0; y < con->h; y++) {
+ TCOD_color_t fore,back;
+ int c=TCOD_console_get_char(con,x,y);
+ fore=TCOD_console_get_char_foreground(con,x,y);
+ back=TCOD_console_get_char_background(con,x,y);
+ put8(c, fp);
+ put8(fore.r,fp);
+ put8(fore.g,fp);
+ put8(fore.b,fp);
+ put8(back.r,fp);
+ put8(back.g,fp);
+ put8(back.b,fp);
+ }
+ }
+
+ if (layerChunkSize&1){
+ put8(0,fp); /* padding bit */
+ riffSize++;
+ }
+
+ riffSize += 2*sizeof(uint32_t)+layerChunkSize;
+
+ fsetpos(fp,&posRiffSize);
+ put32(l32(riffSize),fp);
+ }
+
+ fclose(fp);
+ return true;
+}
+
+typedef struct {
+ LayerV1 headerv1;
+ LayerV2 headerv2;
+ uint8_t* data; /* dynamically allocated */
+} LayerData;
+
+typedef struct {
+ ImageDetailsV1 details;
+ SettingsDataV1 settings;
+ LayerData layer;
+} Data;
+
+bool TCOD_console_load_apf(TCOD_console_t pcon, const char *filename) {
+ uint32_t sett = fourCC("sett");
+ uint32_t imgd = fourCC("imgd");
+ /*
+ uint32_t LIST = fourCC("LIST");
+ uint32_t LAYR = fourCC("LAYR");
+ */
+ uint32_t layr = fourCC("layr");
+ FILE* fp ;
+ Data data;
+ struct TCOD_Console *con = TCOD_console_validate_(pcon);
+ TCOD_IFNOT(con != NULL) return false;
+
+ detectBigEndianness();
+ data.details.width = 1;
+ data.details.height = 1;
+ data.details.filter = 0;
+ data.details.format = 0;
+
+ data.settings.show_grid = true;
+ data.settings.grid_width = 10;
+ data.settings.grid_height = 10;
+
+ #define ERR(x) {printf("Error: %s\n. Aborting operation.",x); return false;}
+ #define ERR_NEWER(x) {printf("Error: It looks like this file was made with a newer version of Ascii-Paint\n. In particular the %s field. Aborting operation.",x); return false;}
+
+ fp = fopen(filename, "rb");
+ if(fp == NULL) {
+ printf("The file %s could not be loaded.\n", filename);
+ return false;
+ }
+ else {
+ /* read the header */
+ uint32_t riff;
+ uint32_t riffSize;
+ int index = 0;
+ int x,y;
+ uint8_t *imgData;
+ bool keepGoing = true;
+ if (! get32(&riff,fp) || ! fourCCequals(riff,"RIFF")){
+ ERR("File doesn't have a RIFF header");
+ }
+ if (!get32(&riffSize,fp)) ERR("No RIFF size field!");
+ fix32(&riffSize);
+
+ while(keepGoing && fp){ /* for each subfield, try to find the APF_ field */
+ uint32_t apf;
+ if (! get32(&apf,fp)) break;
+ if (fourCCequals(apf,"apf ") || fourCCequals(apf,"APF ")){
+ /* Process APF segment */
+ while(keepGoing && fp){
+ uint32_t seg;
+ if (! get32(&seg,fp)){
+ keepGoing = false;
+ break;
+ }
+ else {
+ if (seg==sett){
+ /* size */
+ uint32_t sz;
+ uint32_t ver;
+ SettingsDataV1 settingsData;
+
+ get32(&sz,fp);
+ fix32(&sz);
+ /* version */
+ get32(&ver,fp);
+ fix32(&ver);
+ if (ver!=1) ERR_NEWER("settings");
+ /* ver must be 1 */
+ if (! getData(&settingsData,sizeof settingsData,fp)) ERR("Can't read settings.");
+ data.settings = settingsData;
+ fixSettings(&data.settings);
+
+ }
+ else if (seg==imgd){
+ /* sz */
+ uint32_t sz;
+ uint32_t ver;
+ ImageDetailsV1 dets;
+
+ get32(&sz,fp);
+ fix32(&sz);
+ /* version */
+ get32(&ver,fp);
+ fix32(&ver);
+ if (ver!=1) ERR_NEWER("image details");
+ /* ver must be 1 */
+ if (! getData(&dets, sizeof dets, fp)) ERR("Can't read image details.");
+ data.details = dets;
+ fixImage(&data.details);
+
+ /* get canvas ready */
+ TCOD_IFNOT ( data.details.width > 0 && data.details.height > 0) {
+ fclose(fp);
+ return false;
+ }
+ TCOD_console_resize_(
+ con, data.details.width, data.details.height);
+ }
+ else if (seg==layr){
+ uint32_t sz;
+ uint32_t ver;
+
+ get32(&sz,fp);
+ fix32(&sz);
+ /* version */
+ get32(&ver,fp);
+ fix32(&ver);
+ if (ver>2) ERR_NEWER("layer spec");
+
+ if (ver==1){
+ if (! getData(static_cast(&data.layer.headerv1), sizeof( LayerV1 ), fp)) ERR("Can't read layer header.");
+ fixLayerv1(&data.layer.headerv1);
+
+ /* Read in the data chunk*/
+ data.layer.data = static_cast(malloc(sizeof(uint8_t)*data.layer.headerv1.dataSize));
+ getData(static_cast(data.layer.data), data.layer.headerv1.dataSize, fp);
+ }
+ else if (ver==2){
+ if (! getData(static_cast(&data.layer.headerv2), sizeof( LayerV2 ), fp)) ERR("Can't read layer header.");
+ fixLayerv2(&data.layer.headerv2);
+
+ /* Read in the data chunk */
+ data.layer.data = static_cast(malloc(sizeof(uint8_t)*data.layer.headerv2.dataSize));
+ getData(static_cast(data.layer.data), data.layer.headerv2.dataSize, fp);
+
+ }
+ }
+ else {
+ /* skip unknown segment */
+ uint32_t sz;
+ get32(&sz,fp);
+ fix32(&sz);
+ fseek(fp,sz,SEEK_CUR);
+ }
+ }
+ }
+
+ /* we're done! */
+ keepGoing = false;
+ }
+ else {
+ /* skip this segment */
+ uint32_t sz;
+ get32(&sz,fp);
+ fseek(fp,sz,SEEK_CUR);
+ }
+ }
+
+ imgData = data.layer.data;
+ for(x = 0; x < con->w; x++) {
+ for(y = 0; y < con->h; y++) {
+ TCOD_color_t fore,back;
+ int c = imgData[index++];
+ fore.r = imgData[index++];
+ fore.g = imgData[index++];
+ fore.b = imgData[index++];
+ back.r = imgData[index++];
+ back.g = imgData[index++];
+ back.b = imgData[index++];
+ TCOD_console_put_char_ex(con,x,y,c,fore,back);
+ }
+ }
+
+ free (data.layer.data);
+ }
+ fclose(fp);
+
+ return true;
+}
+/*
+
+bool ApfFile::Load(std::string filename){
+ detectBigEndianness();
+
+ uint32_t sett = fourCC("sett");
+ uint32_t imgd = fourCC("imgd");
+ uint32_t LIST = fourCC("LIST");
+ uint32_t LAYR = fourCC("LAYR");
+ uint32_t layr = fourCC("layr");
+
+ Data data; // File data
+
+ data.details.width = 1;
+ data.details.height = 1;
+ data.details.filter = FILTER_TYPE_UNCOMPRESSED;
+ data.details.format = FORMAT_TYPE_CRGBRGB;
+
+ data.settings.show_grid = true;
+ data.settings.grid_width = 10;
+ data.settings.grid_height = 10;
+
+ data.currentLayer = NULL;
+
+ #define ERR(x) {printf("Error: %s\n. Aborting operation.",x); return false;}
+ #define ERR_NEWER(x) {printf("Error: It looks like this file was made with a newer version of Ascii-Paint\n. In particular the %s field. Aborting operation.",x); return false;}
+
+ FILE* fp = fopen(filename.c_str(), "rb");
+ if(fp == NULL) {
+ printf("The file %s could not be loaded.\n", filename.c_str());
+ return false;
+ }
+ else {
+ // read the header
+ uint32_t riff;
+ if (not get32(&riff,fp)
+ or
+ not fourCCequals(riff,"RIFF")){
+ ERR("File doesn't have a RIFF header");
+ }
+ // else
+ uint32_t riffSize;
+ if (!get32(&riffSize,fp)) ERR("No RIFF size field!");
+ fix(&riffSize);
+
+ bool keepGoing = true;
+ while(keepGoing and fp){ // for each subfield, try to find the APF_ field
+ uint32_t apf;
+ if (not get32(&apf,fp)) break;
+ if (fourCCequals(apf,"apf ") or fourCCequals(apf,"APF ")){
+ // Process APF segment
+ while(keepGoing and fp){
+ uint32_t seg;
+ if (not get32(&seg,fp)){
+ keepGoing = false;
+ break;
+ }
+ else {
+ if (seg==sett){
+ // size
+ uint32_t sz;
+ get32(&sz,fp);
+ fix(&sz);
+ // version
+ uint32_t ver;
+ get32(&ver,fp);
+ fix(&ver);
+ if (ver!=1) ERR_NEWER("settings");
+ // ver must be 1
+ SettingsDataV1 settingsData;
+ if (not getData((void*)&settingsData,sizeof settingsData,fp)) ERR("Can't read settings.");
+ data.settings = settingsData;
+ fix(&data.settings);
+
+ // Change app settings
+ app->setGridDimensions(data.settings.grid_width,data.settings.grid_height);
+ app->setShowGrid(data.settings.show_grid==1);
+ }
+ else if (seg==imgd){
+ // sz
+ uint32_t sz;
+ get32(&sz,fp);
+ fix(&sz);
+ // version
+ uint32_t ver;
+ get32(&ver,fp);
+ fix(&ver);
+ if (ver!=1) ERR_NEWER("image details");
+ // ver must be 1
+ ImageDetailsV1 dets;
+ if (not getData((void*)&dets, sizeof dets, fp)) ERR("Can't read image details.");
+ data.details = dets;
+ fix(&data.details);
+
+ // get canvas ready
+ app->canvasWidth = data.details.width;
+ app->canvasHeight = data.details.height;
+ app->initCanvas();
+
+ // delete new layer
+ app->deleteLayer(app->getCurrentLayer()->name);
+
+ }
+ else if (seg==layr){
+ // printf("Found a layer\n");
+
+ // sz
+ uint32_t sz;
+ get32(&sz,fp);
+ fix(&sz);
+ // version
+ uint32_t ver;
+ get32(&ver,fp);
+ fix(&ver);
+ if (ver>2) ERR_NEWER("layer spec");
+
+ if (ver==1){
+ LayerV1 layerHeader;
+ if (not getData((void*)&layerHeader, sizeof layerHeader, fp)) ERR("Can't read layer header.");
+ fix(&layerHeader);
+
+ // creat new layer data
+ LayerData* ld = new LayerData;
+ ld->header = layerHeader; // already fix'd
+ ld->data = new uint8[ld->header.dataSize];
+
+ // Read in the data chunk
+ getData((void*) ld->data, ld->header.dataSize, fp);
+
+ // push layer onto the list
+ data.currentLayer = ld;
+ data.layers.push(ld);
+ }
+ else if (ver==2){
+ LayerV2 layerHeader;
+ if (not getData((void*)&layerHeader, sizeof layerHeader, fp)) ERR("Can't read layer header.");
+ fix(&layerHeader);
+
+ // creat new layer data
+ LayerData* ld = new LayerData;
+ ld->header = layerHeader; // already fix'd
+ ld->data = new uint8[ld->header.dataSize];
+
+ // Read in the data chunk
+ getData((void*) ld->data, ld->header.dataSize, fp);
+
+ // push layer onto the list
+ data.currentLayer = ld;
+ data.layers.push(ld);
+ }
+ }
+ else {
+ // skip unknown segment
+ uint32_t sz;
+ get32(&sz,fp);
+ fix(&sz);
+ fseek(fp,sz,SEEK_CUR);
+ }
+ }
+ }
+
+ // we're done!
+ keepGoing = false;
+ }
+ else {
+ // skip this segment
+ uint32_t sz;
+ get32(&sz,fp);
+ fseek(fp,sz,SEEK_CUR);
+ }
+ }
+
+ // finally, copy the layers into the current document
+ for(int i=0;iaddNewLayer();
+
+ // Parse layer header
+ l->name = fromFourCC(ld->header.name);
+ l->fgalpha = ld->header.fgalpha;
+ l->bgalpha = ld->header.bgalpha;
+ l->visible = (ld->header.visible==1);
+ // l->compositingMode =
+
+ // Copy data into currently selected canvas
+ uint8_t* imgData = ld->data;
+ CanvasImage *img = new CanvasImage;
+ // Write the brush data for every brush in the image
+ int index = 0;
+ for(int x = 0; x < app->canvasWidth; x++) {
+ for(int y = 0; y < app->canvasHeight; y++) {
+ Brush b;
+ b.symbol = (unsigned char)(imgData[index++]);
+ b.fore.r = (uint8_t)(imgData[index++]);
+ b.fore.g = (uint8_t)(imgData[index++]);
+ b.fore.b = (uint8_t)(imgData[index++]);
+ b.back.r = (uint8_t)(imgData[index++]);
+ b.back.g = (uint8_t)(imgData[index++]);
+ b.back.b = (uint8_t)(imgData[index++]);
+ b.solid = true; // deprecated
+ b.walkable = true; // deprecated
+ img->push_back(b);
+ }
+ }
+
+ app->setCanvasImage(*img);
+ delete img;
+ }
+
+ // then free all the temporary layer data
+ for(int i=0;idata;
+ delete data.layers.get(i);
+ }
+
+ // and update the layer widget
+ app->gui->layerWidget->regenerateLayerList();
+ }
+ fclose(fp);
+
+ return true;
+}
+*/
+
+#endif /* TCOD_CONSOLE_SUPPORT */
diff --git a/tcod_sys/libtcod/include/console_types.h b/tcod_sys/libtcod/src/libtcod/console_types.h
similarity index 54%
rename from tcod_sys/libtcod/include/console_types.h
rename to tcod_sys/libtcod/src/libtcod/console_types.h
index fa3d29dab..85aa109b5 100644
--- a/tcod_sys/libtcod/include/console_types.h
+++ b/tcod_sys/libtcod/src/libtcod/console_types.h
@@ -1,270 +1,304 @@
-/*
-* libtcod 1.6.3
-* Copyright (c) 2008,2009,2010,2012,2013,2016,2017 Jice & Mingos & rmtew
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * The name of Jice or Mingos may not be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY JICE, MINGOS AND RMTEW ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL JICE, MINGOS OR RMTEW BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _TCOD_CONSOLE_TYPES_H
-#define _TCOD_CONSOLE_TYPES_H
-
-#include "libtcod_portability.h"
-
-typedef void * TCOD_console_t;
-
-typedef enum {
- TCODK_NONE,
- TCODK_ESCAPE,
- TCODK_BACKSPACE,
- TCODK_TAB,
- TCODK_ENTER,
- TCODK_SHIFT,
- TCODK_CONTROL,
- TCODK_ALT,
- TCODK_PAUSE,
- TCODK_CAPSLOCK,
- TCODK_PAGEUP,
- TCODK_PAGEDOWN,
- TCODK_END,
- TCODK_HOME,
- TCODK_UP,
- TCODK_LEFT,
- TCODK_RIGHT,
- TCODK_DOWN,
- TCODK_PRINTSCREEN,
- TCODK_INSERT,
- TCODK_DELETE,
- TCODK_LWIN,
- TCODK_RWIN,
- TCODK_APPS,
- TCODK_0,
- TCODK_1,
- TCODK_2,
- TCODK_3,
- TCODK_4,
- TCODK_5,
- TCODK_6,
- TCODK_7,
- TCODK_8,
- TCODK_9,
- TCODK_KP0,
- TCODK_KP1,
- TCODK_KP2,
- TCODK_KP3,
- TCODK_KP4,
- TCODK_KP5,
- TCODK_KP6,
- TCODK_KP7,
- TCODK_KP8,
- TCODK_KP9,
- TCODK_KPADD,
- TCODK_KPSUB,
- TCODK_KPDIV,
- TCODK_KPMUL,
- TCODK_KPDEC,
- TCODK_KPENTER,
- TCODK_F1,
- TCODK_F2,
- TCODK_F3,
- TCODK_F4,
- TCODK_F5,
- TCODK_F6,
- TCODK_F7,
- TCODK_F8,
- TCODK_F9,
- TCODK_F10,
- TCODK_F11,
- TCODK_F12,
- TCODK_NUMLOCK,
- TCODK_SCROLLLOCK,
- TCODK_SPACE,
- TCODK_CHAR,
- TCODK_TEXT
-} TCOD_keycode_t;
-
-#define TCOD_KEY_TEXT_SIZE 32
-
-/* key data : special code or character or text */
-typedef struct {
- TCOD_keycode_t vk; /* key code */
- char c; /* character if vk == TCODK_CHAR else 0 */
- char text[TCOD_KEY_TEXT_SIZE]; /* text if vk == TCODK_TEXT else text[0] == '\0' */
- bool pressed ; /* does this correspond to a key press or key release event ? */
- bool lalt ;
- bool lctrl ;
- bool lmeta ;
- bool ralt ;
- bool rctrl ;
- bool rmeta ;
- bool shift ;
-} TCOD_key_t;
-
-typedef enum {
- /* single walls */
- TCOD_CHAR_HLINE=196,
- TCOD_CHAR_VLINE=179,
- TCOD_CHAR_NE=191,
- TCOD_CHAR_NW=218,
- TCOD_CHAR_SE=217,
- TCOD_CHAR_SW=192,
- TCOD_CHAR_TEEW=180,
- TCOD_CHAR_TEEE=195,
- TCOD_CHAR_TEEN=193,
- TCOD_CHAR_TEES=194,
- TCOD_CHAR_CROSS=197,
- /* double walls */
- TCOD_CHAR_DHLINE=205,
- TCOD_CHAR_DVLINE=186,
- TCOD_CHAR_DNE=187,
- TCOD_CHAR_DNW=201,
- TCOD_CHAR_DSE=188,
- TCOD_CHAR_DSW=200,
- TCOD_CHAR_DTEEW=185,
- TCOD_CHAR_DTEEE=204,
- TCOD_CHAR_DTEEN=202,
- TCOD_CHAR_DTEES=203,
- TCOD_CHAR_DCROSS=206,
- /* blocks */
- TCOD_CHAR_BLOCK1=176,
- TCOD_CHAR_BLOCK2=177,
- TCOD_CHAR_BLOCK3=178,
- /* arrows */
- TCOD_CHAR_ARROW_N=24,
- TCOD_CHAR_ARROW_S=25,
- TCOD_CHAR_ARROW_E=26,
- TCOD_CHAR_ARROW_W=27,
- /* arrows without tail */
- TCOD_CHAR_ARROW2_N=30,
- TCOD_CHAR_ARROW2_S=31,
- TCOD_CHAR_ARROW2_E=16,
- TCOD_CHAR_ARROW2_W=17,
- /* double arrows */
- TCOD_CHAR_DARROW_H=29,
- TCOD_CHAR_DARROW_V=18,
- /* GUI stuff */
- TCOD_CHAR_CHECKBOX_UNSET=224,
- TCOD_CHAR_CHECKBOX_SET=225,
- TCOD_CHAR_RADIO_UNSET=9,
- TCOD_CHAR_RADIO_SET=10,
- /* sub-pixel resolution kit */
- TCOD_CHAR_SUBP_NW=226,
- TCOD_CHAR_SUBP_NE=227,
- TCOD_CHAR_SUBP_N=228,
- TCOD_CHAR_SUBP_SE=229,
- TCOD_CHAR_SUBP_DIAG=230,
- TCOD_CHAR_SUBP_E=231,
- TCOD_CHAR_SUBP_SW=232,
- /* miscellaneous */
- TCOD_CHAR_SMILIE = 1,
- TCOD_CHAR_SMILIE_INV = 2,
- TCOD_CHAR_HEART = 3,
- TCOD_CHAR_DIAMOND = 4,
- TCOD_CHAR_CLUB = 5,
- TCOD_CHAR_SPADE = 6,
- TCOD_CHAR_BULLET = 7,
- TCOD_CHAR_BULLET_INV = 8,
- TCOD_CHAR_MALE = 11,
- TCOD_CHAR_FEMALE = 12,
- TCOD_CHAR_NOTE = 13,
- TCOD_CHAR_NOTE_DOUBLE = 14,
- TCOD_CHAR_LIGHT = 15,
- TCOD_CHAR_EXCLAM_DOUBLE = 19,
- TCOD_CHAR_PILCROW = 20,
- TCOD_CHAR_SECTION = 21,
- TCOD_CHAR_POUND = 156,
- TCOD_CHAR_MULTIPLICATION = 158,
- TCOD_CHAR_FUNCTION = 159,
- TCOD_CHAR_RESERVED = 169,
- TCOD_CHAR_HALF = 171,
- TCOD_CHAR_ONE_QUARTER = 172,
- TCOD_CHAR_COPYRIGHT = 184,
- TCOD_CHAR_CENT = 189,
- TCOD_CHAR_YEN = 190,
- TCOD_CHAR_CURRENCY = 207,
- TCOD_CHAR_THREE_QUARTERS = 243,
- TCOD_CHAR_DIVISION = 246,
- TCOD_CHAR_GRADE = 248,
- TCOD_CHAR_UMLAUT = 249,
- TCOD_CHAR_POW1 = 251,
- TCOD_CHAR_POW3 = 252,
- TCOD_CHAR_POW2 = 253,
- TCOD_CHAR_BULLET_SQUARE = 254,
- /* diacritics */
-} TCOD_chars_t;
-
-typedef enum {
- TCOD_COLCTRL_1 = 1,
- TCOD_COLCTRL_2,
- TCOD_COLCTRL_3,
- TCOD_COLCTRL_4,
- TCOD_COLCTRL_5,
- TCOD_COLCTRL_NUMBER=5,
- TCOD_COLCTRL_FORE_RGB,
- TCOD_COLCTRL_BACK_RGB,
- TCOD_COLCTRL_STOP
-} TCOD_colctrl_t;
-
-typedef enum {
- TCOD_BKGND_NONE,
- TCOD_BKGND_SET,
- TCOD_BKGND_MULTIPLY,
- TCOD_BKGND_LIGHTEN,
- TCOD_BKGND_DARKEN,
- TCOD_BKGND_SCREEN,
- TCOD_BKGND_COLOR_DODGE,
- TCOD_BKGND_COLOR_BURN,
- TCOD_BKGND_ADD,
- TCOD_BKGND_ADDA,
- TCOD_BKGND_BURN,
- TCOD_BKGND_OVERLAY,
- TCOD_BKGND_ALPH,
- TCOD_BKGND_DEFAULT
-} TCOD_bkgnd_flag_t;
-
-typedef enum {
- TCOD_KEY_PRESSED=1,
- TCOD_KEY_RELEASED=2,
-} TCOD_key_status_t;
-
-/* custom font flags */
-typedef enum {
- TCOD_FONT_LAYOUT_ASCII_INCOL=1,
- TCOD_FONT_LAYOUT_ASCII_INROW=2,
- TCOD_FONT_TYPE_GREYSCALE=4,
- TCOD_FONT_TYPE_GRAYSCALE=4,
- TCOD_FONT_LAYOUT_TCOD=8,
-} TCOD_font_flags_t;
-
-typedef enum {
- TCOD_RENDERER_GLSL,
- TCOD_RENDERER_OPENGL,
- TCOD_RENDERER_SDL,
- TCOD_NB_RENDERERS,
-} TCOD_renderer_t;
-
-typedef enum {
- TCOD_LEFT,
- TCOD_RIGHT,
- TCOD_CENTER
-} TCOD_alignment_t;
-#endif /* _TCOD_CONSOLE_TYPES_H */
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _TCOD_CONSOLE_TYPES_H
+#define _TCOD_CONSOLE_TYPES_H
+
+#include "portability.h"
+#include "color.h"
+#include "console/console.h"
+
+typedef enum {
+ TCODK_NONE,
+ TCODK_ESCAPE,
+ TCODK_BACKSPACE,
+ TCODK_TAB,
+ TCODK_ENTER,
+ TCODK_SHIFT,
+ TCODK_CONTROL,
+ TCODK_ALT,
+ TCODK_PAUSE,
+ TCODK_CAPSLOCK,
+ TCODK_PAGEUP,
+ TCODK_PAGEDOWN,
+ TCODK_END,
+ TCODK_HOME,
+ TCODK_UP,
+ TCODK_LEFT,
+ TCODK_RIGHT,
+ TCODK_DOWN,
+ TCODK_PRINTSCREEN,
+ TCODK_INSERT,
+ TCODK_DELETE,
+ TCODK_LWIN,
+ TCODK_RWIN,
+ TCODK_APPS,
+ TCODK_0,
+ TCODK_1,
+ TCODK_2,
+ TCODK_3,
+ TCODK_4,
+ TCODK_5,
+ TCODK_6,
+ TCODK_7,
+ TCODK_8,
+ TCODK_9,
+ TCODK_KP0,
+ TCODK_KP1,
+ TCODK_KP2,
+ TCODK_KP3,
+ TCODK_KP4,
+ TCODK_KP5,
+ TCODK_KP6,
+ TCODK_KP7,
+ TCODK_KP8,
+ TCODK_KP9,
+ TCODK_KPADD,
+ TCODK_KPSUB,
+ TCODK_KPDIV,
+ TCODK_KPMUL,
+ TCODK_KPDEC,
+ TCODK_KPENTER,
+ TCODK_F1,
+ TCODK_F2,
+ TCODK_F3,
+ TCODK_F4,
+ TCODK_F5,
+ TCODK_F6,
+ TCODK_F7,
+ TCODK_F8,
+ TCODK_F9,
+ TCODK_F10,
+ TCODK_F11,
+ TCODK_F12,
+ TCODK_NUMLOCK,
+ TCODK_SCROLLLOCK,
+ TCODK_SPACE,
+ TCODK_CHAR,
+ TCODK_TEXT
+} TCOD_keycode_t;
+
+#define TCOD_KEY_TEXT_SIZE 32
+
+/* key data : special code or character or text */
+typedef struct {
+ TCOD_keycode_t vk; /* key code */
+ char c; /* character if vk == TCODK_CHAR else 0 */
+ char text[TCOD_KEY_TEXT_SIZE]; /* text if vk == TCODK_TEXT else text[0] == '\0' */
+ bool pressed ; /* does this correspond to a key press or key release event ? */
+ bool lalt ;
+ bool lctrl ;
+ bool lmeta ;
+ bool ralt ;
+ bool rctrl ;
+ bool rmeta ;
+ bool shift ;
+} TCOD_key_t;
+
+typedef enum {
+ /* single walls */
+ TCOD_CHAR_HLINE=196,
+ TCOD_CHAR_VLINE=179,
+ TCOD_CHAR_NE=191,
+ TCOD_CHAR_NW=218,
+ TCOD_CHAR_SE=217,
+ TCOD_CHAR_SW=192,
+ TCOD_CHAR_TEEW=180,
+ TCOD_CHAR_TEEE=195,
+ TCOD_CHAR_TEEN=193,
+ TCOD_CHAR_TEES=194,
+ TCOD_CHAR_CROSS=197,
+ /* double walls */
+ TCOD_CHAR_DHLINE=205,
+ TCOD_CHAR_DVLINE=186,
+ TCOD_CHAR_DNE=187,
+ TCOD_CHAR_DNW=201,
+ TCOD_CHAR_DSE=188,
+ TCOD_CHAR_DSW=200,
+ TCOD_CHAR_DTEEW=185,
+ TCOD_CHAR_DTEEE=204,
+ TCOD_CHAR_DTEEN=202,
+ TCOD_CHAR_DTEES=203,
+ TCOD_CHAR_DCROSS=206,
+ /* blocks */
+ TCOD_CHAR_BLOCK1=176,
+ TCOD_CHAR_BLOCK2=177,
+ TCOD_CHAR_BLOCK3=178,
+ /* arrows */
+ TCOD_CHAR_ARROW_N=24,
+ TCOD_CHAR_ARROW_S=25,
+ TCOD_CHAR_ARROW_E=26,
+ TCOD_CHAR_ARROW_W=27,
+ /* arrows without tail */
+ TCOD_CHAR_ARROW2_N=30,
+ TCOD_CHAR_ARROW2_S=31,
+ TCOD_CHAR_ARROW2_E=16,
+ TCOD_CHAR_ARROW2_W=17,
+ /* double arrows */
+ TCOD_CHAR_DARROW_H=29,
+ TCOD_CHAR_DARROW_V=18,
+ /* GUI stuff */
+ TCOD_CHAR_CHECKBOX_UNSET=224,
+ TCOD_CHAR_CHECKBOX_SET=225,
+ TCOD_CHAR_RADIO_UNSET=9,
+ TCOD_CHAR_RADIO_SET=10,
+ /* sub-pixel resolution kit */
+ TCOD_CHAR_SUBP_NW=226,
+ TCOD_CHAR_SUBP_NE=227,
+ TCOD_CHAR_SUBP_N=228,
+ TCOD_CHAR_SUBP_SE=229,
+ TCOD_CHAR_SUBP_DIAG=230,
+ TCOD_CHAR_SUBP_E=231,
+ TCOD_CHAR_SUBP_SW=232,
+ /* miscellaneous */
+ TCOD_CHAR_SMILIE = 1,
+ TCOD_CHAR_SMILIE_INV = 2,
+ TCOD_CHAR_HEART = 3,
+ TCOD_CHAR_DIAMOND = 4,
+ TCOD_CHAR_CLUB = 5,
+ TCOD_CHAR_SPADE = 6,
+ TCOD_CHAR_BULLET = 7,
+ TCOD_CHAR_BULLET_INV = 8,
+ TCOD_CHAR_MALE = 11,
+ TCOD_CHAR_FEMALE = 12,
+ TCOD_CHAR_NOTE = 13,
+ TCOD_CHAR_NOTE_DOUBLE = 14,
+ TCOD_CHAR_LIGHT = 15,
+ TCOD_CHAR_EXCLAM_DOUBLE = 19,
+ TCOD_CHAR_PILCROW = 20,
+ TCOD_CHAR_SECTION = 21,
+ TCOD_CHAR_POUND = 156,
+ TCOD_CHAR_MULTIPLICATION = 158,
+ TCOD_CHAR_FUNCTION = 159,
+ TCOD_CHAR_RESERVED = 169,
+ TCOD_CHAR_HALF = 171,
+ TCOD_CHAR_ONE_QUARTER = 172,
+ TCOD_CHAR_COPYRIGHT = 184,
+ TCOD_CHAR_CENT = 189,
+ TCOD_CHAR_YEN = 190,
+ TCOD_CHAR_CURRENCY = 207,
+ TCOD_CHAR_THREE_QUARTERS = 243,
+ TCOD_CHAR_DIVISION = 246,
+ TCOD_CHAR_GRADE = 248,
+ TCOD_CHAR_UMLAUT = 249,
+ TCOD_CHAR_POW1 = 251,
+ TCOD_CHAR_POW3 = 252,
+ TCOD_CHAR_POW2 = 253,
+ TCOD_CHAR_BULLET_SQUARE = 254,
+ /* diacritics */
+} TCOD_chars_t;
+
+typedef enum {
+ TCOD_COLCTRL_1 = 1,
+ TCOD_COLCTRL_2,
+ TCOD_COLCTRL_3,
+ TCOD_COLCTRL_4,
+ TCOD_COLCTRL_5,
+ TCOD_COLCTRL_NUMBER=5,
+ TCOD_COLCTRL_FORE_RGB,
+ TCOD_COLCTRL_BACK_RGB,
+ TCOD_COLCTRL_STOP
+} TCOD_colctrl_t;
+
+typedef enum {
+ TCOD_KEY_PRESSED=1,
+ TCOD_KEY_RELEASED=2,
+} TCOD_key_status_t;
+/**
+ * These font flags can be OR'd together into a bit-field and passed to
+ * TCOD_console_set_custom_font
+ */
+typedef enum {
+ /** Tiles are arranged in column-major order.
+ *
+ * 0 3 6
+ * 1 4 7
+ * 2 5 8
+ */
+ TCOD_FONT_LAYOUT_ASCII_INCOL=1,
+ /** Tiles are arranged in row-major order.
+ *
+ * 0 1 2
+ * 3 4 5
+ * 6 7 8
+ */
+ TCOD_FONT_LAYOUT_ASCII_INROW=2,
+ /** Converts all tiles into a monochrome gradient. */
+ TCOD_FONT_TYPE_GREYSCALE=4,
+ TCOD_FONT_TYPE_GRAYSCALE=4,
+ /** A unique layout used by some of libtcod's fonts. */
+ TCOD_FONT_LAYOUT_TCOD=8,
+ /**
+ * Decode a code page 437 tileset into Unicode code-points.
+ * \rst
+ * .. versionadded:: 1.10
+ * \endrst
+ */
+ TCOD_FONT_LAYOUT_CP437=16,
+} TCOD_font_flags_t;
+/**
+ * The available renderers.
+ */
+typedef enum {
+ /** An OpenGL implementation using a shader. */
+ TCOD_RENDERER_GLSL,
+ /**
+ * An OpenGL implementation without a shader.
+ *
+ * Performs worse than TCOD_RENDERER_GLSL without many benefits.
+ */
+ TCOD_RENDERER_OPENGL,
+ /**
+ * A software based renderer.
+ *
+ * The font file is loaded into RAM instead of VRAM in this implementation.
+ */
+ TCOD_RENDERER_SDL,
+ /**
+ * A new SDL2 renderer. Allows the window to be resized.
+ * \rst
+ * .. versionadded:: 1.8
+ * \endrst
+ */
+ TCOD_RENDERER_SDL2,
+ /**
+ * A new OpenGL 2.0 core renderer. Allows the window to be resized.
+ * \rst
+ * .. versionadded:: 1.9
+ *
+ * .. versionchanged:: 1.11.0
+ * This renderer now uses OpenGL 2.0 instead of 2.1.
+ * \endrst
+ */
+ TCOD_RENDERER_OPENGL2,
+ TCOD_NB_RENDERERS,
+} TCOD_renderer_t;
+#endif /* _TCOD_CONSOLE_TYPES_H */
diff --git a/tcod_sys/libtcod/src/libtcod/deprecated.cpp b/tcod_sys/libtcod/src/libtcod/deprecated.cpp
new file mode 100644
index 000000000..53bd8d9c9
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/deprecated.cpp
@@ -0,0 +1,38 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "console.h"
+#include "console.hpp"
+
+void TCOD_console_set_keyboard_repeat(int, int) {}
+void TCOD_console_disable_keyboard_repeat() {}
+void TCODConsole::setKeyboardRepeat(int, int) {}
+void TCODConsole::disableKeyboardRepeat() {}
diff --git a/tcod_sys/libtcod/src/libtcod/engine/backend.cpp b/tcod_sys/libtcod/src/libtcod/engine/backend.cpp
new file mode 100644
index 000000000..62579c5a9
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/engine/backend.cpp
@@ -0,0 +1,32 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "backend.h"
diff --git a/tcod_sys/libtcod/src/libtcod/engine/backend.h b/tcod_sys/libtcod/src/libtcod/engine/backend.h
new file mode 100644
index 000000000..edb42393c
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/engine/backend.h
@@ -0,0 +1,63 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef LIBTCOD_ENGINE_BACKEND_H_
+#define LIBTCOD_ENGINE_BACKEND_H_
+
+#ifdef __cplusplus
+#include
+#endif /* __cplusplus */
+
+#include "../console_types.h"
+#include "../mouse_types.h"
+#include "../sys.h"
+
+#ifdef __cplusplus
+namespace tcod {
+namespace engine {
+class Backend {
+ public:
+ virtual ~Backend() = default;
+ /**
+ * Legacy wait for event virtual function.
+ */
+ virtual TCOD_event_t legacy_wait_for_event(
+ int eventMask, TCOD_key_t *key, TCOD_mouse_t *mouse, bool flush) = 0;
+ /**
+ * Legacy check for event virtual function.
+ */
+ virtual TCOD_event_t legacy_check_for_event(
+ int eventMask, TCOD_key_t *key, TCOD_mouse_t *mouse) = 0;
+};
+} // namespace engine
+} // namespace tcod
+#endif /* __cplusplus */
+#endif /* LIBTCOD_ENGINE_BACKEND_H_ */
diff --git a/tcod_sys/libtcod/src/libtcod/engine/display.cpp b/tcod_sys/libtcod/src/libtcod/engine/display.cpp
new file mode 100644
index 000000000..ea26cd89a
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/engine/display.cpp
@@ -0,0 +1,237 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "display.h"
+
+#include
+#include
+#include
+
+#include
+#include "error.h"
+#include "globals.h"
+#include "../console.h"
+#include "../console.hpp"
+#include "../libtcod_int.h"
+#include "../sdl2/sdl2_display.h"
+#include "../sdl2/gl2_display.h"
+#include "../tileset/fallback.h"
+namespace tcod {
+static auto ensure_tileset() -> std::shared_ptr
+{
+ using tcod::engine::get_tileset;
+ using tcod::engine::set_tileset;
+ using tcod::tileset::new_fallback_tileset;
+ if (!get_tileset()) {
+ try {
+ set_tileset(new_fallback_tileset());
+ }
+ catch (const std::runtime_error& e) {
+ throw std::runtime_error(
+ std::string()
+ + "Couldn't load a fallback font for the SDL2/OPENGL2 renderer: "
+ + e.what());
+ }
+ }
+ return get_tileset();
+}
+/**
+ * Initialize the display using one of the new renderers.
+ */
+template
+static void init_display(int w, int h, const std::string& title,
+ int fullscreen, Args... args)
+{
+ auto tileset = ensure_tileset();
+ std::array display_size{tileset->get_tile_width() * w,
+ tileset->get_tile_height() * h};
+ int display_flags = (SDL_WINDOW_RESIZABLE |
+ (fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0));
+ tcod::engine::set_display(
+ std::make_shared(tileset, display_size, display_flags, title, args...));
+}
+namespace console {
+void init_root(int w, int h, const std::string& title, bool fullscreen,
+ TCOD_renderer_t renderer, bool vsync)
+{
+ if (w <= 0 || h <= 0) {
+ throw std::invalid_argument("Width and height must be greater than zero.");
+ }
+ TCOD_console_delete(NULL);
+ TCODConsole::root->data = TCOD_ctx.root = TCOD_console_new(w, h);
+#ifndef TCOD_BARE
+ TCOD_ctx.renderer=renderer;
+#endif
+ strncpy(TCOD_ctx.window_title, title.c_str(),
+ sizeof(TCOD_ctx.window_title) - 1);
+ TCOD_ctx.window_title[sizeof(TCOD_ctx.window_title) - 1] = '\0';
+ TCOD_ctx.fullscreen = fullscreen;
+ switch (renderer) {
+ case TCOD_RENDERER_SDL2: {
+ using tcod::sdl2::SDL2Display;
+ int renderer_flags = SDL_RENDERER_PRESENTVSYNC * vsync;
+ init_display(w, h, title, fullscreen, renderer_flags);
+ break;
+ }
+ case TCOD_RENDERER_OPENGL2:
+ init_display(w, h, title, fullscreen, vsync);
+ break;
+ default:
+ if(!TCOD_console_init(TCOD_ctx.root, title, fullscreen)) {
+ throw std::runtime_error(TCOD_get_error());
+ }
+ break;
+ }
+}
+void init_root(int w, int h, const std::string& title, bool fullscreen,
+ TCOD_renderer_t renderer)
+{
+ init_root(w, h, title, fullscreen, renderer, false);
+}
+} // namespace console
+} // namespace tcod
+int TCOD_console_init_root_(
+ int w,
+ int h,
+ const char* title,
+ bool fullscreen,
+ TCOD_renderer_t renderer,
+ bool vsync)
+{
+ using tcod::console::init_root;
+ try {
+ init_root(w, h, title ? title : "", fullscreen, renderer, vsync);
+ } catch (const std::exception& e) {
+ return tcod::set_error(e);
+ }
+ return 0;
+}
+int TCOD_console_init_root(int w, int h, const char* title, bool fullscreen,
+ TCOD_renderer_t renderer)
+{
+ return TCOD_console_init_root_(w, h, title, fullscreen, renderer, false);
+}
+void TCOD_quit(void)
+{
+ TCOD_console_delete(NULL);
+}
+void TCOD_console_set_window_title(const char *title)
+{
+ if (auto display = tcod::engine::get_display()) {
+ display->set_title(title);
+ } else { // Deprecated renderer.
+ TCOD_sys_set_window_title(title);
+ }
+}
+void TCOD_console_set_fullscreen(bool fullscreen)
+{
+ if (auto display = tcod::engine::get_display()) {
+ display->set_fullscreen(fullscreen);
+ } else { // Deprecated renderer.
+ TCOD_IFNOT(TCOD_ctx.root != NULL) { return; }
+ TCOD_sys_set_fullscreen(fullscreen);
+ TCOD_ctx.fullscreen = fullscreen;
+ }
+}
+bool TCOD_console_is_fullscreen(void)
+{
+ if (auto display = tcod::engine::get_display()) {
+ return display->get_fullscreen() == 1;
+ } else { // Deprecated renderer.
+ return TCOD_ctx.fullscreen;
+ }
+}
+bool TCOD_console_has_mouse_focus(void)
+{
+ if (auto display = tcod::engine::get_display()) {
+ if (auto window = display->get_sdl_window()) {
+ return (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS) != 0;
+ }
+ }
+ return TCOD_ctx.app_has_mouse_focus;
+}
+bool TCOD_console_is_active(void)
+{
+ if (auto display = tcod::engine::get_display()) {
+ if (auto window = display->get_sdl_window()) {
+ return (SDL_GetWindowFlags(window) & SDL_WINDOW_INPUT_FOCUS) != 0;
+ }
+ }
+ return TCOD_ctx.app_is_active;
+}
+bool TCOD_console_is_window_closed(void) {
+ return TCOD_ctx.is_window_closed;
+}
+struct SDL_Window* TCOD_sys_get_sdl_window(void)
+{
+ if (auto display = tcod::engine::get_display()) {
+ return display->get_sdl_window();
+ }
+ return TCOD_sys_get_sdl_window_();
+}
+struct SDL_Renderer* TCOD_sys_get_sdl_renderer(void)
+{
+ if (auto display = tcod::engine::get_display()) {
+ return display->get_sdl_renderer();
+ }
+ return TCOD_sys_get_sdl_renderer_();
+}
+int TCOD_sys_accumulate_console(const TCOD_Console* console)
+{
+ return TCOD_sys_accumulate_console_(console, nullptr);
+}
+int TCOD_sys_accumulate_console_(const TCOD_Console* console, const struct SDL_Rect* viewport)
+{
+ console = tcod::console::validate_(console);
+ auto display = tcod::engine::get_display();
+ if (!console || !display) { return -1; }
+ display->accumulate(console, viewport);
+ return 0;
+}
+int TCOD_sys_init_sdl2_renderer_(
+ int width,
+ int height,
+ const char* title,
+ int window_flags,
+ int renderer_flags)
+{
+ using tcod::sdl2::SDL2Display;
+ try {
+ auto tileset = tcod::ensure_tileset();
+ std::array window_size{ width, height };
+ auto display = std::make_shared(
+ tileset, window_size, window_flags, title, renderer_flags);
+ tcod::engine::set_display(display);
+ } catch (const std::exception& e) {
+ return tcod::set_error(e);
+ }
+ return 0;
+}
diff --git a/tcod_sys/libtcod/src/libtcod/engine/display.h b/tcod_sys/libtcod/src/libtcod/engine/display.h
new file mode 100644
index 000000000..44e3205a4
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/engine/display.h
@@ -0,0 +1,271 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef LIBTCOD_ENGINE_DISPLAY_H_
+#define LIBTCOD_ENGINE_DISPLAY_H_
+
+#ifdef __cplusplus
+#include
+#include
+#endif // __cplusplus
+
+#include "../color/canvas.h"
+#include "../tileset/tileset.h"
+#include "../console_types.h"
+
+struct SDL_Rect;
+struct SDL_Window;
+struct SDL_Renderer;
+#ifdef __cplusplus
+namespace tcod {
+namespace engine {
+using tcod::image::Image;
+using tcod::tileset::Tileset;
+class Display {
+ public:
+ virtual ~Display() = default;
+ virtual void set_tileset(std::shared_ptr tileset) = 0;
+ virtual void set_title(const std::string& title) = 0;
+ virtual std::string get_title() = 0;
+ /**
+ * Set the fullscreen status if the display supports it.
+ *
+ * If it is supported this can be used to switch between a window and
+ * borderless fullscreen window.
+ */
+ virtual void set_fullscreen(bool fullscreen) = 0;
+ /**
+ * Return true if the display is in fullscreen mode.
+ *
+ * Returns a negative number if the display does not support fullscreen.
+ */
+ virtual int get_fullscreen() = 0;
+ /**
+ * Render a console over this display.
+ */
+ virtual void accumulate(const TCOD_Console*) = 0;
+ virtual void accumulate(const TCOD_Console*, const struct SDL_Rect* viewport) = 0;
+ /**
+ * Render a console and present the display.
+ */
+ virtual void present(const TCOD_Console*) = 0;
+ virtual auto pixel_to_tile(const std::array& xy)
+ -> std::array = 0;
+
+ virtual auto read_pixels() const -> Image = 0;
+ /**
+ * Return the pointer to an SDL2 window, if this display uses SDL.
+ *
+ * Could return nullptr.
+ */
+ virtual auto get_sdl_window() -> struct SDL_Window* = 0;
+ /**
+ * Return the pointer to an SDL2 renderer, if this display uses SDL's
+ * renderer.
+ *
+ * Could return nullptr.
+ */
+ virtual auto get_sdl_renderer() -> struct SDL_Renderer* = 0;
+};
+/**
+ * Incomplete interface for subclasses which don't need an SDL2 window.
+ */
+class TerminalDisplay: public Display {
+ public:
+ using Display::accumulate;
+ virtual void set_tileset(std::shared_ptr) override
+ {}
+ virtual void set_title(const std::string&) override
+ {}
+ virtual std::string get_title() override
+ {
+ return {};
+ }
+ /**
+ * Terminals do not support fullscreen modes.
+ */
+ virtual void set_fullscreen(bool) override
+ {}
+ /**
+ * Return a negative error code.
+ */
+ virtual int get_fullscreen() override
+ {
+ return -1;
+ }
+ virtual auto pixel_to_tile(const std::array& xy)
+ -> std::array override
+ {
+ return xy;
+ }
+ virtual auto get_sdl_window() -> struct SDL_Window* override
+ {
+ return nullptr;
+ }
+ virtual auto get_sdl_renderer() -> struct SDL_Renderer* override
+ {
+ return nullptr;
+ }
+ virtual void accumulate(const TCOD_Console* console, const struct SDL_Rect*) override
+ {
+ accumulate(console);
+ }
+};
+} // namespace sdl2
+namespace console {
+TCODLIB_API void init_root(int w, int h, const std::string& title,
+ bool fullscreen, TCOD_renderer_t renderer);
+TCODLIB_API void init_root(
+ int w,
+ int h,
+ const std::string& title,
+ bool fullscreen,
+ TCOD_renderer_t renderer,
+ bool vsync);
+} // namespace console
+} // namespace tcod
+#endif // __cplusplus
+/**
+ * \brief Initialize the libtcod graphical engine.
+ *
+ * \param w The width in tiles.
+ * \param h The height in tiles.
+ * \param title The title for the window.
+ * \param fullscreen Fullscreen option.
+ * \param renderer Which renderer to use when rendering the console.
+ *
+ * You may want to call TCOD_console_set_custom_font BEFORE calling this
+ * function. By default this function loads libtcod's `terminal.png` image
+ * from the working directory.
+ *
+ * Afterwards TCOD_quit must be called before the program exits.
+ *
+ * Returns 0 on success, or -1 on an error, you can check the error with
+ * TCOD_sys_get_error()
+ * \rst
+ * .. versionchanged:: 1.12
+ * Now returns -1 on error instead of crashing.
+ * \endrst
+ */
+TCODLIB_CAPI int TCOD_console_init_root(int w, int h, const char* title,
+ bool fullscreen,
+ TCOD_renderer_t renderer);
+TCODLIB_CAPI int TCOD_console_init_root_(
+ int w,
+ int h,
+ const char* title,
+ bool fullscreen,
+ TCOD_renderer_t renderer,
+ bool vsync);
+/**
+ * Shutdown libtcod. This must be called before your program exits.
+ * \rst
+ * .. versionadded:: 1.8
+ * \endrst
+ */
+TCODLIB_CAPI void TCOD_quit(void);
+/**
+ * Change the title string of the active window.
+ *
+ * \param title A utf8 string.
+ */
+TCODLIB_CAPI void TCOD_console_set_window_title(const char *title);
+/**
+ * Set the display to be full-screen or windowed.
+ *
+ * \param fullscreen If true the display will go full-screen.
+ */
+TCODLIB_CAPI void TCOD_console_set_fullscreen(bool fullscreen);
+/**
+ * Return true if the display is full-screen.
+ */
+TCODLIB_CAPI bool TCOD_console_is_fullscreen(void);
+/**
+ * Return true if the window has mouse focus.
+ */
+TCODLIB_CAPI bool TCOD_console_has_mouse_focus(void);
+/**
+ * Return true if the window has keyboard focus.
+ *
+ * \verbatim embed:rst:leading-asterisk
+ * .. versionchanged: 1.7
+ * This function was previously broken. It now keeps track of keyboard
+ * focus.
+ * \endverbatim
+ */
+TCODLIB_CAPI bool TCOD_console_is_active(void);
+/**
+ * Return true if the window is closing.
+ */
+TCODLIB_CAPI bool TCOD_console_is_window_closed(void);
+/**
+ * Return an SDL_Window pointer if one is in use, returns NULL otherwise.
+ * \rst
+ * .. versionadded:: 1.11
+ * \endrst
+ */
+TCODLIB_CAPI struct SDL_Window* TCOD_sys_get_sdl_window(void);
+/**
+ * Return an SDL_Renderer pointer if one is in use, returns NULL otherwise.
+ * \rst
+ * .. versionadded:: 1.11
+ * \endrst
+ */
+TCODLIB_CAPI struct SDL_Renderer* TCOD_sys_get_sdl_renderer(void);
+/**
+ * Render a console over the display.
+ * \rst
+ * `console` can be any size, the active render will try to scale it to fit
+ * the screen.
+ *
+ * The function will only work for the SDL2/OPENGL2 renderers.
+ *
+ * Unlike :any:`TCOD_console_flush` this will not present the display.
+ * You will need to do that manually, likely with the SDL API.
+ *
+ * Returns 0 on success, or a negative number on a failure such as the
+ * incorrect renderer being active.
+ *
+ * .. versionadded:: 1.11
+ *
+ * .. seealso::
+ * :any:`TCOD_sys_get_sdl_window` :any:`TCOD_sys_get_sdl_renderer`
+ * \endrst
+ */
+TCODLIB_CAPI int TCOD_sys_accumulate_console(const TCOD_Console* console);
+TCODLIB_CAPI int TCOD_sys_accumulate_console_(const TCOD_Console* console, const struct SDL_Rect* viewport);
+TCODLIB_CAPI int TCOD_sys_init_sdl2_renderer_(
+ int width,
+ int height,
+ const char* title,
+ int window_flags,
+ int renderer_flags);
+#endif // LIBTCOD_ENGINE_DISPLAY_H_
diff --git a/tcod_sys/libtcod/src/libtcod/engine/error.cpp b/tcod_sys/libtcod/src/libtcod/engine/error.cpp
new file mode 100644
index 000000000..b3b2836da
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/engine/error.cpp
@@ -0,0 +1,69 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "error.h"
+
+#include
+#include
+#include
+
+namespace tcod {
+static thread_local char error_msg_[256] = {};
+int set_errorf(const char* fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(error_msg_, sizeof(error_msg_) - 1, fmt, ap);
+ va_end(ap);
+ return -1;
+}
+int set_error(const char* msg)
+{
+ std::strncpy(error_msg_, msg, sizeof(error_msg_) - 1);
+ return -1;
+}
+int set_error(const std::string& msg)
+{
+ return set_error(msg.c_str());
+}
+int set_error(const std::exception& e)
+{
+ return set_error(e.what());
+}
+} // namespace tcod
+const char* TCOD_get_error()
+{
+ return tcod::error_msg_;
+}
+int TCOD_set_error(const char* msg)
+{
+ return tcod::set_error(msg);
+}
diff --git a/tcod_sys/libtcod/src/libtcod/engine/error.h b/tcod_sys/libtcod/src/libtcod/engine/error.h
new file mode 100644
index 000000000..c32c226f1
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/engine/error.h
@@ -0,0 +1,73 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef LIBTCOD_ENGINE_ERROR_H_
+#define LIBTCOD_ENGINE_ERROR_H_
+
+#ifdef __cplusplus
+#include
+#include
+#endif // __cplusplus
+
+#include "../portability.h"
+
+#ifdef __cplusplus
+namespace tcod {
+/**
+ * Set an error message and return a relevant error code, usually -1.
+ *
+ * Used internally.
+ */
+TCODLIB_FORMAT(1, 2)
+int set_errorf(const char* fmt, ...);
+int set_error(const char* msg);
+int set_error(const std::string& msg);
+int set_error(const std::exception& e);
+} // namespace tcod
+#endif // __cplusplus
+/**
+ * Return the last error message. If there is no error then the string will
+ * have a length of zero.
+ *
+ * The error state is thread specific.
+ * \rst
+ * .. versionadded:: 1.12
+ * \endrst
+ */
+TCODLIB_CAPI const char* TCOD_get_error();
+/**
+ * Set an error message and return -1.
+ * \rst
+ * .. versionadded:: 1.12
+ * \endrst
+ */
+TCODLIB_CAPI int TCOD_set_error(const char*);
+#endif // LIBTCOD_ENGINE_ERROR_H_
diff --git a/tcod_sys/libtcod/src/libtcod/engine/globals.cpp b/tcod_sys/libtcod/src/libtcod/engine/globals.cpp
new file mode 100644
index 000000000..76c886103
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/engine/globals.cpp
@@ -0,0 +1,87 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "globals.h"
+
+#include
+
+namespace tcod {
+namespace engine {
+std::shared_ptr active_backend = nullptr;
+std::shared_ptr active_display = nullptr;
+std::shared_ptr active_tileset = nullptr;
+std::shared_ptr active_tilesheet = nullptr;
+
+void set_backend(std::shared_ptr backend)
+{
+ active_backend = backend;
+}
+std::shared_ptr get_backend()
+{
+ return active_backend;
+}
+void set_display(std::shared_ptr display)
+{
+ active_display = display;
+}
+std::shared_ptr get_display()
+{
+ return active_display;
+}
+void set_tileset(std::shared_ptr tileset)
+{
+ active_tileset = tileset;
+ if (tileset && active_display) {
+ active_display->set_tileset(tileset);
+ }
+}
+auto get_tileset() -> std::shared_ptr
+{
+ return active_tileset;
+}
+void set_tilesheet(std::shared_ptr sheet)
+{
+ active_tilesheet = sheet;
+}
+auto get_tilesheet() -> std::shared_ptr
+{
+ return active_tilesheet;
+}
+} // namespace engine
+} // namespace tcod
+TCODLIB_CAPI TCOD_Tileset* TCOD_get_default_tileset(void)
+{
+ return new TCOD_Tileset(tcod::engine::get_tileset());
+}
+TCODLIB_CAPI void TCOD_set_default_tileset(TCOD_Tileset* tileset)
+{
+ tcod::engine::set_tileset(tileset ? (*tileset) : nullptr);
+}
diff --git a/tcod_sys/libtcod/src/libtcod/engine/globals.h b/tcod_sys/libtcod/src/libtcod/engine/globals.h
new file mode 100644
index 000000000..dd3ce974a
--- /dev/null
+++ b/tcod_sys/libtcod/src/libtcod/engine/globals.h
@@ -0,0 +1,96 @@
+/* BSD 3-Clause License
+ *
+ * Copyright © 2008-2019, Jice and the libtcod contributors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef LIBTCOD_ENGINE_GLOBALS_H_
+#define LIBTCOD_ENGINE_GLOBALS_H_
+
+#ifdef __cplusplus
+#include