diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e20ceb..5237267 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,14 +149,14 @@ ENDIF(ENABLE_OPENGL AND OPENGL_FOUND) # The Guisan SDL extension library OPTION(ENABLE_SDL "Enable the Guisan SDL extension" ON) +OPTION(ENABLE_SDL_TTF "Enable the Guisan SDL TTF extension" ON) OPTION(BUILD_GUISAN_SDL_SHARED "Build the Guisan SDL extension library as a shared library." ON) IF(ENABLE_SDL) FIND_PACKAGE(SDL2 REQUIRED) FIND_PACKAGE(SDL2_image REQUIRED) - FIND_PACKAGE(SDL2_ttf REQUIRED) - INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIR}) + INCLUDE_DIRECTORIES(SYSTEM ${SDL2_INCLUDE_DIR}) # The Guichan SDL extension source FILE(GLOB GUISAN_SDL_HEADER include/guisan/sdl.hpp) @@ -188,7 +188,13 @@ IF(ENABLE_SDL) MESSAGE(STATUS "MINGW32_LIBRARY: ${MINGW32_LIBRARY}") TARGET_LINK_LIBRARIES(${PROJECT_NAME}_sdl ${MINGW32_LIBRARY}) ENDIF(MINGW) - TARGET_LINK_LIBRARIES(${PROJECT_NAME}_sdl PRIVATE SDL2::SDL2 SDL2_image::SDL2_image SDL2_ttf::SDL2_ttf ${PROJECT_NAME}) + TARGET_LINK_LIBRARIES(${PROJECT_NAME}_sdl PRIVATE SDL2::SDL2 SDL2_image::SDL2_image ${PROJECT_NAME}) + IF(ENABLE_SDL_TTF) + FIND_PACKAGE(SDL2_ttf REQUIRED) + TARGET_LINK_LIBRARIES(${PROJECT_NAME}_sdl PRIVATE SDL2_ttf::SDL2_ttf) + TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME}_sdl PUBLIC USE_SDL2_TTF) + ENDIF(ENABLE_SDL_TTF) + TARGET_LINK_LIBRARIES(${PROJECT_NAME}_sdl PRIVATE ${PROJECT_NAME}) SET_TARGET_PROPERTIES(${PROJECT_NAME}_sdl PROPERTIES VERSION ${${PROJECT_NAME}_VERSION} diff --git a/Doxyfile b/Doxyfile index 8c49ce1..f128b29 100644 --- a/Doxyfile +++ b/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = "Guisan" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.0.0 +PROJECT_NUMBER = 1.1.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/SConstruct b/SConstruct index 3cd57e2..ade8d19 100644 --- a/SConstruct +++ b/SConstruct @@ -6,7 +6,7 @@ env["CC"] = os.getenv("CC") or env["CC"] env["CXX"] = os.getenv("CXX") or env["CXX"] env["ENV"].update(x for x in os.environ.items() if x[0].startswith("CCC_")) -env["LIBVER"] = "1.0.0" +env["LIBVER"] = "1.1.0" env["PREFIX_PATH"] = ARGUMENTS.get('prefix', "/usr/local") env["INCLUDE_PATH"] = ARGUMENTS.get('include', env['PREFIX_PATH'] + "/include") @@ -32,14 +32,15 @@ if not conf.CheckPKGConfig('0.15.0'): env['HAVE_OPENGL'] = conf.CheckPKG('gl') env['HAVE_SDL2'] = conf.CheckPKG('sdl2') +env['HAVE_SDL2_TTF'] = conf.CheckPKG('SDL2_ttf') if env['HAVE_SDL2']: if not conf.CheckPKG('SDL2_image'): print('SDL2_image not found. Disabling SDL2 support.') env['HAVE_SDL2'] = 0 - if not conf.CheckPKG('SDL2_ttf'): - print('SDL2_ttf not found. Disabling SDL2 support.') - env['HAVE_SDL2'] = 0 + +if env['HAVE_SDL2_TTF']: + env.Append(CPPDEFINES = ['USE_SDL2_TTF']) env = conf.Finish() diff --git a/demo/ff/SConstruct b/demo/ff/SConstruct index ea7697d..fd65efb 100644 --- a/demo/ff/SConstruct +++ b/demo/ff/SConstruct @@ -25,6 +25,7 @@ if not conf.CheckPKGConfig('0.15.0'): Exit(1) env['HAVE_SDL2'] = conf.CheckPKG('sdl2') +env['HAVE_SDL2_TTF'] = conf.CheckPKG('SDL2_ttf') if env['HAVE_SDL2']: if not conf.CheckPKG('SDL2_image'): @@ -41,6 +42,9 @@ env.Append(CPPPATH = ['#../../include']) env.Append(CFLAGS = ['-g']) env.Append(CPPFLAGS = ['-g']) +if env['HAVE_SDL2_TTF']: + env.Append(CPPDEFINES = ['USE_SDL2_TTF']) + Export("env") # Main program diff --git a/include/guisan/sdl.hpp b/include/guisan/sdl.hpp index ec7d5c4..d328855 100644 --- a/include/guisan/sdl.hpp +++ b/include/guisan/sdl.hpp @@ -57,12 +57,15 @@ #ifndef GCN_SDL_HPP #define GCN_SDL_HPP -#include #include +#include #include #include #include -#include + +#if USE_SDL2_TTF +# include +#endif #include "platform.hpp" diff --git a/include/guisan/sdl/sdltruetypefont.hpp b/include/guisan/sdl/sdltruetypefont.hpp index cd185d5..0c38e59 100644 --- a/include/guisan/sdl/sdltruetypefont.hpp +++ b/include/guisan/sdl/sdltruetypefont.hpp @@ -44,15 +44,18 @@ #ifndef GCN_CONTRIB_SDLTRUETYPEFONT_HPP #define GCN_CONTRIB_SDLTRUETYPEFONT_HPP -#include -#include +#if !USE_SDL2_TTF +# error "USE_SDL2_TTF not activated" +#endif -#include "SDL_ttf.h" #include "guisan/color.hpp" - #include "guisan/font.hpp" #include "guisan/platform.hpp" +#include +#include +#include + namespace gcn { class Graphics; diff --git a/premake5.lua b/premake5.lua index 236bb32..3725594 100644 --- a/premake5.lua +++ b/premake5.lua @@ -4,6 +4,13 @@ newoption { description = "Set the output location for the generated files" } +newoption { + trigger = "use-sdl_ttf", + value = "bool", + description = "Use SDL_TTF (for font)", + default = true +} + if (_ACTION == nil) then return end @@ -13,14 +20,20 @@ local locationDir = _OPTIONS["to"] or path.join("solution", _ACTION, "stratagus" local nugetPackages = { "sdl2.nuget:2.28.0", "sdl2.nuget.redist:2.28.0", "sdl2_image.nuget:2.6.3", "sdl2_image.nuget.redist:2.6.3", - "sdl2_mixer.nuget:2.6.3", "sdl2_mixer.nuget.redist:2.6.3", - "sdl2_net.nuget:2.2.0", "sdl2_net.nuget.redist:2.2.0", - "sdl2_ttf.nuget:2.20.2", "sdl2_ttf.nuget.redist:2.20.2" + "sdl2_mixer.nuget:2.6.3", "sdl2_mixer.nuget.redist:2.6.3" -- Sound for demo } +if _OPTIONS["use-sdl_ttf"] then + nugetPackages = table.join(nugetPackages, {"sdl2_ttf.nuget:2.20.2", "sdl2_ttf.nuget.redist:2.20.2"}) +end + function useGuisan() includedirs { "include/" } links { "guisan" } + + if _OPTIONS["use-sdl_ttf"] then + defines { "USE_SDL2_TTF" } + end end -- ---------------------------------------------------------------------------- @@ -81,6 +94,10 @@ project "guisan" files { "src/SConscript" } files { "*.*"} + if _OPTIONS["use-sdl_ttf"] then + defines { "USE_SDL2_TTF" } + end + includedirs { "include" } -- ---------------------------------------------------------------------------- @@ -92,9 +109,8 @@ project "opengl_helloworld" files { "examples/openglhelloworld.cpp", "examples/opengl_helper.hpp", "examples/helloworld_example.hpp" } - includedirs { "include" } - links { "guisan" } - links {"opengl32"} + useGuisan() + links { "opengl32" } debugdir "examples" @@ -105,9 +121,8 @@ project "opengl_widgets" files { "examples/openglwidgets.cpp", "examples/opengl_helper.hpp", "examples/widgets_example.hpp" } - includedirs { "include" } - links { "guisan" } - links {"opengl32"} + useGuisan() + links { "opengl32" } debugdir "examples" @@ -118,8 +133,7 @@ project "sdl_action" files { "examples/sdlaction.cpp", "examples/sdl_helper.hpp", "examples/action_example.hpp" } - includedirs { "include" } - links { "guisan" } + useGuisan() debugdir "examples" @@ -130,8 +144,7 @@ project "sdl_hello" files { "examples/sdlhelloworld.cpp", "examples/sdl_helper.hpp", "examples/helloworld_example.hpp" } - includedirs { "include" } - links { "guisan" } + useGuisan() debugdir "examples" @@ -142,8 +155,7 @@ project "sdl_rickroll" files { "examples/sdlrickroll.cpp", "examples/sdl_helper.hpp", "examples/rickroll_example.hpp" } - includedirs { "include" } - links { "guisan" } + useGuisan() debugdir "examples" @@ -154,8 +166,7 @@ project "sdl_widgets" files { "examples/sdlwidgets.cpp", "examples/sdl_helper.hpp", "examples/widgets_example.hpp" } - includedirs { "include" } - links { "guisan" } + useGuisan() debugdir "examples" @@ -166,8 +177,7 @@ project "sdl2_widgets" files { "examples/sdl2widgets.cpp", "examples/sdl2_helper.hpp", "examples/widgets_example.hpp" } - includedirs { "include" } - links { "guisan" } + useGuisan() debugdir "examples" @@ -181,9 +191,7 @@ project "Demo_ff" files { "Demo/ff/**.*" } includedirs { "Demo/ff/include" } - includedirs { "include" } - links { "guisan" } - + useGuisan() links {"opengl32"} debugdir "Demo/ff" diff --git a/src/SConscript b/src/SConscript index bab7509..67a863d 100644 --- a/src/SConscript +++ b/src/SConscript @@ -92,6 +92,7 @@ guisan = env.Clone() if env['HAVE_SDL2']: guisan.ParseConfig('pkg-config --cflags --libs sdl2') guisan.ParseConfig('pkg-config --cflags --libs SDL2_image') +if env['HAVE_SDL2_TTF']: guisan.ParseConfig('pkg-config --cflags --libs SDL2_ttf') if env['HAVE_OPENGL']: @@ -101,6 +102,7 @@ print("=========================================") print(" Guisan build") print("") print(" SDL 2.0 support.............. " + str(env['HAVE_SDL2'])) +print(" SDL 2.0 TTF support..........." + str(env['HAVE_SDL2_TTF'])) print(" OpenGL support............... " + str(env['HAVE_OPENGL'])) print("-----------------------------------------") print(" Installation target") diff --git a/src/guisan.cpp b/src/guisan.cpp index 43b9bc2..de78470 100644 --- a/src/guisan.cpp +++ b/src/guisan.cpp @@ -63,6 +63,6 @@ extern "C" { const char* gcnGuisanVersion() { - return "1.0.0"; + return "1.1.0"; } } diff --git a/src/sdl/sdltruetypefont.cpp b/src/sdl/sdltruetypefont.cpp index 915159c..ac5e1f5 100644 --- a/src/sdl/sdltruetypefont.cpp +++ b/src/sdl/sdltruetypefont.cpp @@ -42,16 +42,17 @@ */ /* - * For comments regarding functions please see the header file. + * For comments regarding functions please see the header file. */ -#include "guisan/sdl/sdltruetypefont.hpp" +#if USE_SDL2_TTF +# include "guisan/sdl/sdltruetypefont.hpp" -#include "guisan/exception.hpp" -#include "guisan/image.hpp" -#include "guisan/graphics.hpp" -#include "guisan/sdl/sdlgraphics.hpp" -#include "guisan/sdl/sdl2graphics.hpp" +# include "guisan/exception.hpp" +# include "guisan/graphics.hpp" +# include "guisan/image.hpp" +# include "guisan/sdl/sdl2graphics.hpp" +# include "guisan/sdl/sdlgraphics.hpp" namespace gcn { @@ -61,7 +62,7 @@ namespace gcn { if (mFont == nullptr) { - throw GCN_EXCEPTION("SDLTrueTypeFont::SDLTrueTypeFont. "+std::string(TTF_GetError())); + throw GCN_EXCEPTION("SDLTrueTypeFont::SDLTrueTypeFont. " + std::string(TTF_GetError())); } } @@ -83,8 +84,8 @@ namespace gcn return TTF_FontHeight(mFont) + mRowSpacing; } - void SDLTrueTypeFont::drawString(Graphics* graphics, const std::string& text, const int x, const int y, - bool enabled) + void SDLTrueTypeFont::drawString( + Graphics* graphics, const std::string& text, const int x, const int y, bool enabled) { if (text.empty()) { @@ -94,11 +95,10 @@ namespace gcn auto sdlGraphics = dynamic_cast(graphics); auto sdl2Graphics = dynamic_cast(graphics); - if (sdlGraphics == nullptr && sdl2Graphics == nullptr) { - throw GCN_EXCEPTION("SDLTrueTypeFont::drawString. Graphics object not an SDL graphics object!"); - return; + throw GCN_EXCEPTION( + "SDLTrueTypeFont::drawString. Graphics object not an SDL graphics object!"); } // This is needed for drawing the Glyph in the middle if we have spacing @@ -185,4 +185,6 @@ namespace gcn { mColor = color; } -} +} // namespace gcn + +#endif