diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-12-21 23:18:11 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-12-21 23:18:11 +0300 |
commit | dca5154e6690286b04a8cb7c7c6f2ef63e0b56df (patch) | |
tree | 6a6a0f3119f96228053f85acdbebde0fbb4fd0bc | |
parent | 6addecc3615d5e3f9caaafd39aa639c8ff49115b (diff) | |
download | plus-dca5154e6690286b04a8cb7c7c6f2ef63e0b56df.tar.gz plus-dca5154e6690286b04a8cb7c7c6f2ef63e0b56df.tar.bz2 plus-dca5154e6690286b04a8cb7c7c6f2ef63e0b56df.tar.xz plus-dca5154e6690286b04a8cb7c7c6f2ef63e0b56df.zip |
Move buildhex macro into separate file.
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/resources/dye/dye_unittest.cc | 12 | ||||
-rw-r--r-- | src/resources/dye/dyecolor.h | 15 | ||||
-rw-r--r-- | src/utils/buildhex.h | 41 |
5 files changed, 48 insertions, 22 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d0a8e0e97..98b8f9d98 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -830,6 +830,7 @@ SET(SRCS utils/base64.cpp utils/base64.h utils/booleanoptions.h + utils/buildhex.h utils/chatutils.cpp utils/chatutils.h utils/checkutils.cpp diff --git a/src/Makefile.am b/src/Makefile.am index e0b1a50d0..ea40cb1ba 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -480,6 +480,7 @@ SRC += events/actionevent.h \ utils/base64.cpp \ utils/base64.h \ utils/booleanoptions.h \ + utils/buildhex.h \ utils/checkutils.cpp \ utils/checkutils.h \ utils/copynpaste.cpp \ diff --git a/src/resources/dye/dye_unittest.cc b/src/resources/dye/dye_unittest.cc index e72609329..c06d0aacb 100644 --- a/src/resources/dye/dye_unittest.cc +++ b/src/resources/dye/dye_unittest.cc @@ -48,20 +48,8 @@ #include <SDL.h> #endif // USE_SDL2 -#ifndef SDL_BIG_ENDIAN -#include <SDL_endian.h> -#endif // SDL_BYTEORDER - #include "debug.h" -#if SDL_BYTEORDER == SDL_BIG_ENDIAN -#define buildHex(a, b, c, d) \ - (d) * 16777216U + (c) * 65536U + (b) * 256U + CAST_U32(a) -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN -#define buildHex(a, b, c, d) \ - (a) * 16777216U + (b) * 65536U + (c) * 256U + CAST_U32(d) -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - #ifdef USE_OPENGL TEST_CASE("Dye replaceSOGLColor 1 1") diff --git a/src/resources/dye/dyecolor.h b/src/resources/dye/dyecolor.h index 11257fc22..a3558a4c3 100644 --- a/src/resources/dye/dyecolor.h +++ b/src/resources/dye/dyecolor.h @@ -21,21 +21,16 @@ #ifndef RESOURCES_DYE_DYECOLOR_H #define RESOURCES_DYE_DYECOLOR_H -#ifndef SDL_BIG_ENDIAN -#include <SDL_endian.h> -#endif // SDL_BYTEORDER +#include "utils/buildhex.h" #include "localconsts.h" -#define buildHex(a, b, c, d) \ - (a) * 16777216U + (b) * 65536U + (c) * 256U + CAST_U32(d) - struct DyeColor final { DyeColor() noexcept2 : valueA(buildHex(0, 0, 0, 255)), valueS(buildHex(0, 0, 0, 0)), - valueSOgl(buildHex(0, 0, 0, 0)) + valueSOgl(buildHexOgl(0, 0, 0, 0)) { value[3] = 255; } @@ -45,7 +40,7 @@ struct DyeColor final const uint8_t b) noexcept2 : valueA(buildHex(r, g, b, 255)), valueS(buildHex(r, g, b, 0)), - valueSOgl(buildHex(0, b, g, r)) + valueSOgl(buildHexOgl(0, b, g, r)) { value[0] = r; value[1] = g; @@ -59,7 +54,7 @@ struct DyeColor final const uint8_t a) noexcept2 : valueA(buildHex(r, g, b, a)), valueS(buildHex(r, g, b, 0)), - valueSOgl(buildHex(0, b, g, r)) + valueSOgl(buildHexOgl(0, b, g, r)) { value[0] = r; value[1] = g; @@ -71,7 +66,7 @@ struct DyeColor final { valueA = buildHex(value[0], value[1], value[2], value[3]); valueS = buildHex(value[0], value[1], value[2], 0); - valueSOgl = buildHex(0, value[2], value[1], value[0]); + valueSOgl = buildHexOgl(0, value[2], value[1], value[0]); } union diff --git a/src/utils/buildhex.h b/src/utils/buildhex.h new file mode 100644 index 000000000..f33295d30 --- /dev/null +++ b/src/utils/buildhex.h @@ -0,0 +1,41 @@ +/* + * The ManaPlus Client + * Copyright (C) 2016 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef UTILS_BUILDHEX_H +#define UTILS_BUILDHEX_H + +#ifndef SDL_BIG_ENDIAN +#include <SDL_endian.h> +#endif // SDL_BYTEORDER + +#include "localconsts.h" + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN +#define buildHex(a, b, c, d) \ + (d) * 16777216U + (c) * 65536U + (b) * 256U + CAST_U32(a) +#else // SDL_BYTEORDER == SDL_BIG_ENDIAN +#define buildHex(a, b, c, d) \ + (a) * 16777216U + (b) * 65536U + (c) * 256U + CAST_U32(d) +#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN + +#define buildHexOgl(a, b, c, d) \ + (a) * 16777216U + (b) * 65536U + (c) * 256U + CAST_U32(d) + +#endif // UTILS_BUILDHEX_H |