Color names, sort out cmake wackiness
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
cmake_minimum_required (VERSION 3.0)
|
||||
cmake_policy(VERSION 3.0)
|
||||
project (mazemaker VERSION 1.3)
|
||||
project (mazemaker VERSION 1.4)
|
||||
|
||||
SET(EXEC_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Installation prefix for executables and object code libraries" FORCE)
|
||||
SET(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include CACHE PATH "Installation prefix for C header files" FORCE)
|
||||
|
||||
@@ -27,9 +27,7 @@ set_target_properties(mazemaker_static PROPERTIES
|
||||
)
|
||||
install (TARGETS mazemaker_shared mazemaker_static DESTINATION ${LIB_INSTALL_DIR})
|
||||
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/../include/mazemaker.h DESTINATION ${INCLUDE_INSTALL_DIR})
|
||||
target_link_libraries(mazemaker_shared PUBLIC ${PNG_LIBRARIES} m)
|
||||
target_include_directories(mazemaker_shared PUBLIC ${PNG_INCLUDE_DIRS} ../include)
|
||||
target_include_directories(mazemaker_static PUBLIC ${PNG_INCLUDE_DIRS} ../include)
|
||||
target_compile_options(mazemaker_shared PUBLIC ${PNG_CFLAGS_OTHER})
|
||||
target_compile_options(mazemaker_static PUBLIC ${PNG_CFLAGS_OTHER})
|
||||
target_link_options(mazemaker_shared PUBLIC -L${PNG_LIBDIR})
|
||||
target_link_libraries(mazemaker_shared PUBLIC ${PNG_LIBRARIES};m)
|
||||
target_link_directories(mazemaker_shared PUBLIC ${PNG_LIBRARY_DIRS})
|
||||
target_include_directories(mazemaker_shared PUBLIC ${PNG_INCLUDE_DIRS};../include)
|
||||
target_include_directories(mazemaker_static PUBLIC ${PNG_INCLUDE_DIRS};../include)
|
||||
|
||||
@@ -18,8 +18,33 @@ void mazemaker_options_free(mazeoptions_t* options) {
|
||||
free(options);
|
||||
}
|
||||
|
||||
static int interpretColorName(char const* color_desc, rgb_color_t dst) {
|
||||
if (0 == strcasecmp(color_desc, "black")) { dst[0] = dst[1] = dst[2] = 0; }
|
||||
else if (0 == strcasecmp(color_desc, "white")) { dst[0] = dst[1] = dst[2] = 0xff; }
|
||||
else if (0 == strcasecmp(color_desc, "red")) { dst[0] = 0xff; dst[1] = dst[2] = 0; }
|
||||
else if (0 == strcasecmp(color_desc, "blue")) { dst[0] = dst[1] = 0; dst[2] = 0xff; }
|
||||
else if (0 == strcasecmp(color_desc, "green")) { dst[0] = dst[2] = 0; dst[1] = 0xff; }
|
||||
else if (0 == strcasecmp(color_desc, "yellow")) { dst[2] = 0; dst[0] = dst[1] = 0xff; }
|
||||
else if ((0 == strcasecmp(color_desc, "magenta")) ||
|
||||
(0 == strcasecmp(color_desc, "purple"))) { dst[1] = 0; dst[0] = dst[2] = 0xff; }
|
||||
else if (0 == strcasecmp(color_desc, "cyan")) { dst[0] = 0; dst[1] = dst[2] = 0xff; }
|
||||
else if (0 == strcasecmp(color_desc, "orange")) { dst[0] = 0xff; dst[1] = 0x7f; dst[2] = 0; }
|
||||
else if (0 == strcasecmp(color_desc, "brown")) { dst[0] = 0x7f; dst[1] = 0x3f; dst[2] = 0; }
|
||||
else if ((0 == strcasecmp(color_desc, "gray")) ||
|
||||
(0 == strcasecmp(color_desc, "grey"))) { dst[0] = dst[1] = dst[2] = 0x7f; }
|
||||
else if (0 == strcasecmp(color_desc, "darkblue")) { dst[0] = dst[1] = 0; dst[2] = 0x7f; }
|
||||
else if (0 == strcasecmp(color_desc, "darkgreen")) { dst[0] = dst[2] = 0; dst[1] = 0x7f; }
|
||||
else if (0 == strcasecmp(color_desc, "darkred")) { dst[0] = 0x7f; dst[1] = dst[2] = 0; }
|
||||
else if (0 == strcasecmp(color_desc, "pink")) { dst[0] = 0xff; dst[1] = 0xa0; dst[2] = 0xbf; }
|
||||
else if ((0 == strcasecmp(color_desc, "darkmagenta")) ||
|
||||
(0 == strcasecmp(color_desc, "darkpurple"))) { dst[1] = 0; dst[0] = dst[2] = 0x7f; }
|
||||
else if (0 == strcasecmp(color_desc, "darkcyan")) { dst[0] = 0; dst[1] = dst[2] = 0x7f; }
|
||||
else return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int stringToColor(char const* color_desc, rgb_color_t dst) {
|
||||
if (color_desc[0] != '#') return -1; // bad format
|
||||
if (color_desc[0] != '#') return interpretColorName(color_desc, dst);
|
||||
|
||||
size_t l;
|
||||
for (l = 1; color_desc[l] != '\0'; l++) if (!isxdigit(color_desc[l])) return -1; // bad format
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_search_module(POPT REQUIRED popt)
|
||||
|
||||
add_executable(mazemaker)
|
||||
target_sources(mazemaker PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/mazemaker.c)
|
||||
target_link_libraries(mazemaker PUBLIC mazemaker_shared ${POPT_LIBRARIES})
|
||||
target_include_directories(mazemaker PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include PUBLIC ${POPT_INCLUDE_DIRS})
|
||||
target_compile_options(mazemaker PUBLIC ${POPT_CFLAGS_OTHER})
|
||||
include_directories("../include" ${POPT_INCLUDE_DIRS})
|
||||
|
||||
add_executable(mazemaker mazemaker.c)
|
||||
target_link_libraries(mazemaker mazemaker_shared ${POPT_LIBRARIES})
|
||||
|
||||
install (TARGETS mazemaker DESTINATION bin)
|
||||
|
||||
@@ -41,8 +41,18 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
mazegrid_t maze;
|
||||
mazeoptions_t* options = mazemaker_options_new();
|
||||
if (fg_color != NULL) mazemaker_options_set_wall_color(options, fg_color);
|
||||
if (bg_color != NULL) mazemaker_options_set_background_color(options, bg_color);
|
||||
if (fg_color != NULL) {
|
||||
if (0 > mazemaker_options_set_wall_color(options, fg_color)) {
|
||||
fprintf(stderr, "Unknown color: \"%s\"\n", fg_color);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (bg_color != NULL) {
|
||||
if (0 > mazemaker_options_set_background_color(options, bg_color)) {
|
||||
fprintf(stderr, "Unknown color: \"%s\"\n", bg_color);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
mazemaker_generate_maze(width, height, &maze);
|
||||
mazemaker_maze_to_png_opt(&maze, filename, options);
|
||||
mazemaker_free_maze(&maze);
|
||||
|
||||
Reference in New Issue
Block a user