diff --git a/Makefile.am b/Makefile.am index af437a6..3c30345 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1 +1 @@ -SUBDIRS = src +SUBDIRS = src graphics fonts songs diff --git a/configure.ac b/configure.ac index 11a85b7..f053ddc 100644 --- a/configure.ac +++ b/configure.ac @@ -25,7 +25,12 @@ AC_CHECK_HEADERS([string string.h iostream algorithm locale vector sstream queue PKG_CHECK_MODULES(SFML, sfml-graphics) +# Flags +datdir=$datadir/$PACKAGE +AC_SUBST(datdir) + CXXFLAGS="$CXXFLAGS -std=c++11" +CXXFLAGS="$CXXFLAGS -DDATADIR=\\\"$datdir\\\"" # Checks for typedefs, structures, and compiler characteristics. AC_CHECK_HEADER_STDBOOL @@ -36,5 +41,10 @@ AC_TYPE_UINT32_T # Checks for library functions. AC_CHECK_FUNCS([gettimeofday]) -AC_CONFIG_FILES([Makefile src/Makefile]) +AC_CONFIG_FILES([ + Makefile + src/Makefile + graphics/Makefile + fonts/Makefile + songs/Makefile]) AC_OUTPUT diff --git a/fonts/Makefile.am b/fonts/Makefile.am new file mode 100644 index 0000000..3279593 --- /dev/null +++ b/fonts/Makefile.am @@ -0,0 +1,7 @@ +EXTRA_DIST = FaunaOne-Regular.ttf + +install-data-local: + $(mkinstalldirs) $(DESTDOR)$(datdir)/fonts + @for file in $(EXTRA_DIST); do\ + $(INSTALL_DATA) $$file $(DESTDIR)$(datdir)/fonts/$$file;\ + done diff --git a/graphics/Makefile.am b/graphics/Makefile.am new file mode 100644 index 0000000..37e62d8 --- /dev/null +++ b/graphics/Makefile.am @@ -0,0 +1,9 @@ +EXTRA_DIST = button.png button2line.png InterfaceButtons.tga \ +keyboard_top_separator.png longbutton.png star.png thumb_down.png \ +title_Logo.png trackbox.png + +install-data-local: + $(mkinstalldirs) $(DESTDOR)$(datdir)/graphics + @for file in $(EXTRA_DIST); do\ + $(INSTALL_DATA) $$file $(DESTDIR)$(datdir)/graphics/$$file;\ + done diff --git a/songs/Aria-Notebook AM Bach.mid b/songs/Aria-Notebook_AM_Bach.mid similarity index 100% rename from songs/Aria-Notebook AM Bach.mid rename to songs/Aria-Notebook_AM_Bach.mid diff --git a/songs/Clementi Opus 36 no 1 First Movement.mid b/songs/Clementi_Opus_36_no_1_First_Movement.mid similarity index 100% rename from songs/Clementi Opus 36 no 1 First Movement.mid rename to songs/Clementi_Opus_36_no_1_First_Movement.mid diff --git a/songs/Fur Elise-Beethoven.mid b/songs/Fur_Elise-Beethoven.mid similarity index 100% rename from songs/Fur Elise-Beethoven.mid rename to songs/Fur_Elise-Beethoven.mid diff --git a/songs/Makefile.am b/songs/Makefile.am new file mode 100644 index 0000000..0b32edd --- /dev/null +++ b/songs/Makefile.am @@ -0,0 +1,11 @@ +EXTRA_DIST = Aria-Notebook_AM_Bach.mid Fur_Elise-Beethoven.mid \ +Minuet_in_F-Leopold_Mozart.mid Rondino-Rameau.mid Sonatina_in_C-Latour.mid \ +Clementi_Opus_36_no_1_First_Movement.mid Minuet_in_G-JS_Bach.mid \ +Russian_Folksong-Beethoven.mid + + +install-data-local: + $(mkinstalldirs) $(DESTDOR)$(datdir)/songs + @for file in $(EXTRA_DIST); do\ + $(INSTALL_DATA) $$file $(DESTDIR)$(datdir)/songs/$$file;\ + done diff --git a/songs/Minuet in F-Leopold Mozart.mid b/songs/Minuet_in_F-Leopold_Mozart.mid similarity index 100% rename from songs/Minuet in F-Leopold Mozart.mid rename to songs/Minuet_in_F-Leopold_Mozart.mid diff --git a/songs/Minuet in G-JS Bach.mid b/songs/Minuet_in_G-JS_Bach.mid similarity index 100% rename from songs/Minuet in G-JS Bach.mid rename to songs/Minuet_in_G-JS_Bach.mid diff --git a/songs/Russian Folksong-Beethoven.mid b/songs/Russian_Folksong-Beethoven.mid similarity index 100% rename from songs/Russian Folksong-Beethoven.mid rename to songs/Russian_Folksong-Beethoven.mid diff --git a/songs/Sonatina in C-Latour.mid b/songs/Sonatina_in_C-Latour.mid similarity index 100% rename from songs/Sonatina in C-Latour.mid rename to songs/Sonatina_in_C-Latour.mid diff --git a/src/Makefile.am b/src/Makefile.am index a4dc0a6..cdaca69 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -32,7 +32,8 @@ linthesia_SOURCES = main.cpp \ screens/one_player_screen/black_note_to_play.cpp \ screens/file_select_screen/file_select_screen.cpp \ screens/select_track_screen/track_box.cpp \ - screens/select_track_screen/select_track_screen.cpp + screens/select_track_screen/select_track_screen.cpp \ + utilities/util.c linthesia_DEPENDENCIES = libmidi.la diff --git a/src/assets/path.h b/src/assets/path.h index 3aa54d7..9bf1192 100644 --- a/src/assets/path.h +++ b/src/assets/path.h @@ -1,8 +1,10 @@ #ifndef LINTHESIA_ASSET_PATH_H #define LINTHESIA_ASSET_PATH_H -#define GRAPHICS_DIR "../graphics/" -#define FONTS_DIR "../fonts/" -#define DEFAULT_FONT FONTS_DIR "FaunaOne-Regular.ttf" +#define GRAPHICS_DIR DATADIR "/graphics/" +#define LOCAL_GRAPHICS_DIR "../graphics/" +#define FONTS_DIR DATADIR "/fonts/" +#define LOCAL_FONTS_DIR "../fonts/" +#define DEFAULT_FONT "FaunaOne-Regular.ttf" #endif diff --git a/src/buttons/long_one_line_button.cpp b/src/buttons/long_one_line_button.cpp index 34b6ed7..b4f01a7 100644 --- a/src/buttons/long_one_line_button.cpp +++ b/src/buttons/long_one_line_button.cpp @@ -1,10 +1,12 @@ #include +#include #include #include #include #include +#include "utilities/util.h" #include "assets/path.h" #include "long_one_line_button.h" @@ -19,7 +21,18 @@ sf::Font LongOneLineButton::font = sf::Font(); */ void LongOneLineButton::init() { - const std::string BUTTON = GRAPHICS_DIR "longbutton.png"; + std::string actual_graphics_dir_path; + std::string actual_fonts_dir_path; + + if (dirExists(GRAPHICS_DIR)) + { + actual_graphics_dir_path = GRAPHICS_DIR; + } + else + { + actual_graphics_dir_path = LOCAL_GRAPHICS_DIR; + } + const std::string BUTTON = actual_graphics_dir_path + "longbutton.png"; if (!texture.loadFromFile(BUTTON)) { std::cerr << "Can't load " @@ -29,10 +42,18 @@ void LongOneLineButton::init() { } texture.setSmooth(true); - if (!font.loadFromFile(DEFAULT_FONT)) { + if (dirExists(FONTS_DIR)) + { + actual_fonts_dir_path = FONTS_DIR; + } + else + { + actual_fonts_dir_path = LOCAL_FONTS_DIR; + } + if (!font.loadFromFile(actual_fonts_dir_path + DEFAULT_FONT)) { std::cerr << "Can't load " - << DEFAULT_FONT + << actual_fonts_dir_path + DEFAULT_FONT << std::endl ; } diff --git a/src/buttons/short_one_line_button.cpp b/src/buttons/short_one_line_button.cpp index 2afca4d..2583343 100644 --- a/src/buttons/short_one_line_button.cpp +++ b/src/buttons/short_one_line_button.cpp @@ -5,6 +5,7 @@ #include #include +#include "utilities/util.h" #include "assets/path.h" #include "short_one_line_button.h" @@ -18,7 +19,18 @@ sf::Font ShortOneLineButton::font = sf::Font(); * */ void ShortOneLineButton::init() { - const std::string BUTTON = GRAPHICS_DIR "button.png"; + std::string actual_graphics_dir_path; + std::string actual_fonts_dir_path; + + if (dirExists(GRAPHICS_DIR)) + { + actual_graphics_dir_path = GRAPHICS_DIR; + } + else + { + actual_graphics_dir_path = LOCAL_GRAPHICS_DIR; + } + const std::string BUTTON = actual_graphics_dir_path + "button.png"; if (!texture.loadFromFile(BUTTON)) { std::cerr << "Can't load " @@ -28,10 +40,18 @@ void ShortOneLineButton::init() { } texture.setSmooth(true); - if (!font.loadFromFile(DEFAULT_FONT)) { + if (dirExists(FONTS_DIR)) + { + actual_fonts_dir_path = FONTS_DIR; + } + else + { + actual_fonts_dir_path = LOCAL_FONTS_DIR; + } + if (!font.loadFromFile(actual_fonts_dir_path + DEFAULT_FONT)) { std::cerr << "Can't load " - << DEFAULT_FONT + << actual_fonts_dir_path + DEFAULT_FONT << std::endl ; } diff --git a/src/buttons/two_lines_button.cpp b/src/buttons/two_lines_button.cpp index d0ad428..fb525c9 100644 --- a/src/buttons/two_lines_button.cpp +++ b/src/buttons/two_lines_button.cpp @@ -5,6 +5,7 @@ #include #include +#include "utilities/util.h" #include "assets/path.h" #include "two_lines_button.h" @@ -25,7 +26,18 @@ TwoLinesButton::TwoLinesButton( const unsigned INTER_LINE_SPACE = 15; currentState = ButtonStates::NORMAL; - const std::string BUTTON = GRAPHICS_DIR "button2line.png"; + std::string actual_graphics_dir_path; + std::string actual_fonts_dir_path; + + if (dirExists(GRAPHICS_DIR)) + { + actual_graphics_dir_path = GRAPHICS_DIR; + } + else + { + actual_graphics_dir_path = LOCAL_GRAPHICS_DIR; + } + const std::string BUTTON = actual_graphics_dir_path + "button2line.png"; if (!texture.loadFromFile(BUTTON)) { std::cerr << "Can't load " @@ -33,13 +45,22 @@ TwoLinesButton::TwoLinesButton( << std::endl ; } + texture.setSmooth(true); sprite.setTexture(texture); - if (!font.loadFromFile(DEFAULT_FONT)) { + if (dirExists(FONTS_DIR)) + { + actual_fonts_dir_path = FONTS_DIR; + } + else + { + actual_fonts_dir_path = LOCAL_FONTS_DIR; + } + if (!font.loadFromFile(actual_fonts_dir_path + DEFAULT_FONT)) { std::cerr << "Can't load " - << DEFAULT_FONT + << actual_fonts_dir_path + DEFAULT_FONT << std::endl ; } diff --git a/src/icons/icon.cpp b/src/icons/icon.cpp index 6f31406..a2b9724 100644 --- a/src/icons/icon.cpp +++ b/src/icons/icon.cpp @@ -6,6 +6,7 @@ #include #include +#include "utilities/util.h" #include "assets/path.h" #include "icon.h" @@ -17,7 +18,18 @@ sf::Texture Icon::iconsTexture = sf::Texture(); * */ void Icon::init() { - const std::string INTERFACE_BUTTONS = GRAPHICS_DIR "InterfaceButtons.tga"; + std::string actual_graphics_dir_path; + std::string actual_fonts_dir_path; + + if (dirExists(GRAPHICS_DIR)) + { + actual_graphics_dir_path = GRAPHICS_DIR; + } + else + { + actual_graphics_dir_path = LOCAL_GRAPHICS_DIR; + } + const std::string INTERFACE_BUTTONS = actual_graphics_dir_path + "InterfaceButtons.tga"; if (!iconsTexture.loadFromFile(INTERFACE_BUTTONS)) { std::cerr << "Can't load " diff --git a/src/keyboard/trail.cpp b/src/keyboard/trail.cpp index 8e64f42..77d5f57 100644 --- a/src/keyboard/trail.cpp +++ b/src/keyboard/trail.cpp @@ -3,6 +3,7 @@ #include #include +#include "utilities/util.h" #include "assets/path.h" #include "trail.h" @@ -11,10 +12,17 @@ namespace linthesia { * */ KeyboardTrail::KeyboardTrail() { - const std::string TOP_SEPARATOR = - GRAPHICS_DIR - "keyboard_top_separator.png" - ; + std::string actual_graphics_dir_path; + + if (dirExists(GRAPHICS_DIR)) + { + actual_graphics_dir_path = GRAPHICS_DIR; + } + else + { + actual_graphics_dir_path = LOCAL_GRAPHICS_DIR; + } + const std::string TOP_SEPARATOR = actual_graphics_dir_path + "keyboard_top_separator.png"; if (!texture.loadFromFile(TOP_SEPARATOR)) { std::cerr << "Can't load " @@ -22,6 +30,7 @@ KeyboardTrail::KeyboardTrail() { << std::endl ; } + texture.setSmooth(true); texture.setRepeated(true); sprite.setTexture(texture); diff --git a/src/screens/file_select_screen/file_select_screen.cpp b/src/screens/file_select_screen/file_select_screen.cpp index 1b2272a..fd1afc4 100644 --- a/src/screens/file_select_screen/file_select_screen.cpp +++ b/src/screens/file_select_screen/file_select_screen.cpp @@ -2,6 +2,7 @@ #include #include "utilities/tinydir.h" +#include "utilities/util.h" #include "file_select_screen.h" #include "context/context.h" @@ -16,7 +17,9 @@ const ScreenIndex FileSelectScreen::INDEX = "file_select_screen"; /** * */ -const static std::string MIDI_DIR_PATH("../songs/"); +const static std::string MIDI_DIR_PATH(DATADIR"/songs/"); +const static std::string LOCAL_MIDI_DIR_PATH("../songs/"); + /** * @@ -87,9 +90,20 @@ ScreenIndex FileSelectScreen::run( sf::Event event; // we initalize the file selector list - midiFileNames = get_midi_files(MIDI_DIR_PATH); + std::string actual_midi_dir_path; + if (dirExists(MIDI_DIR_PATH.c_str())) + { + actual_midi_dir_path = MIDI_DIR_PATH; + } + else + { + actual_midi_dir_path = LOCAL_MIDI_DIR_PATH; + } + + midiFileNames = get_midi_files(actual_midi_dir_path); fileButtons.clear(); for (auto fileName : midiFileNames) { + std::replace( fileName.begin(), fileName.end(), '_', ' '); // replace all '_' to ' ' fileButtons.push_back(LongOneLineButton(fileName)); } updateIterators(app); diff --git a/src/screens/main_screen/main_screen.cpp b/src/screens/main_screen/main_screen.cpp index c4efa45..6adf780 100644 --- a/src/screens/main_screen/main_screen.cpp +++ b/src/screens/main_screen/main_screen.cpp @@ -5,6 +5,7 @@ #include "screens/file_select_screen/file_select_screen.h" #include "screens/select_track_screen/select_track_screen.h" +#include "utilities/util.h" #include "assets/path.h" #include "context/context.h" @@ -34,7 +35,16 @@ MainScreen::MainScreen() : selectTrackButton("play"), chooseSongButton("song:", "no song selected yet") { - const std::string LOGO = GRAPHICS_DIR "title_Logo.png"; + std::string actual_graphics_dir_path; + if (dirExists(GRAPHICS_DIR)) + { + actual_graphics_dir_path = GRAPHICS_DIR; + } + else + { + actual_graphics_dir_path = LOCAL_GRAPHICS_DIR; + } + const std::string LOGO = actual_graphics_dir_path + "title_Logo.png"; if (!logoTexture.loadFromFile(LOGO)) { std::cerr << "Can't load " diff --git a/src/screens/main_screen/select_midi_in.cpp b/src/screens/main_screen/select_midi_in.cpp index 51e1322..8f7bb2b 100644 --- a/src/screens/main_screen/select_midi_in.cpp +++ b/src/screens/main_screen/select_midi_in.cpp @@ -9,6 +9,7 @@ #include "libmidi/midi_util.h" +#include "utilities/util.h" #include "assets/path.h" #include "context/context.h" #include "select_midi_in.h" @@ -47,7 +48,18 @@ SelectMidiIn::SelectMidiIn() : INTER_LINE_SPACE; - const std::string BUTTON = GRAPHICS_DIR "button2line.png"; + std::string actual_graphics_dir_path; + std::string actual_fonts_dir_path; + + if (dirExists(GRAPHICS_DIR)) + { + actual_graphics_dir_path = GRAPHICS_DIR; + } + else + { + actual_graphics_dir_path = LOCAL_GRAPHICS_DIR; + } + const std::string BUTTON = actual_graphics_dir_path + "button2line.png"; if (!backgroundTexture.loadFromFile(BUTTON)) { std::cerr << "Can't load " @@ -76,10 +88,18 @@ SelectMidiIn::SelectMidiIn() : SECOND_LINE_Y ); - if (!font.loadFromFile(DEFAULT_FONT)) { + if (dirExists(FONTS_DIR)) + { + actual_fonts_dir_path = FONTS_DIR; + } + else + { + actual_fonts_dir_path = LOCAL_FONTS_DIR; + } + if (!font.loadFromFile(actual_fonts_dir_path + DEFAULT_FONT)) { std::cerr << "Can't load " - << DEFAULT_FONT + << actual_fonts_dir_path + DEFAULT_FONT << std::endl ; } diff --git a/src/screens/main_screen/select_midi_out.cpp b/src/screens/main_screen/select_midi_out.cpp index 97b27d5..cae95ea 100644 --- a/src/screens/main_screen/select_midi_out.cpp +++ b/src/screens/main_screen/select_midi_out.cpp @@ -7,6 +7,7 @@ #include #include +#include "utilities/util.h" #include "assets/path.h" #include "context/context.h" #include "select_midi_out.h" @@ -47,7 +48,18 @@ SelectMidiOut::SelectMidiOut() : CHARACTER_SIZE + INTER_LINE_SPACE; - const std::string BUTTON = GRAPHICS_DIR "button2line.png"; + std::string actual_graphics_dir_path; + std::string actual_fonts_dir_path; + + if (dirExists(GRAPHICS_DIR)) + { + actual_graphics_dir_path = GRAPHICS_DIR; + } + else + { + actual_graphics_dir_path = LOCAL_GRAPHICS_DIR; + } + const std::string BUTTON = actual_graphics_dir_path + "button2line.png"; if (!backgroundTexture.loadFromFile(BUTTON)) { std::cerr << "Can't load " @@ -83,10 +95,18 @@ SelectMidiOut::SelectMidiOut() : ); - if (!font.loadFromFile(DEFAULT_FONT)) { + if (dirExists(FONTS_DIR)) + { + actual_fonts_dir_path = FONTS_DIR; + } + else + { + actual_fonts_dir_path = LOCAL_FONTS_DIR; + } + if (!font.loadFromFile(actual_fonts_dir_path + DEFAULT_FONT)) { std::cerr << "Can't load " - << DEFAULT_FONT + << actual_fonts_dir_path + DEFAULT_FONT << std::endl ; } diff --git a/src/screens/one_player_screen/one_player_screen.cpp b/src/screens/one_player_screen/one_player_screen.cpp index b39e17d..54a49d6 100644 --- a/src/screens/one_player_screen/one_player_screen.cpp +++ b/src/screens/one_player_screen/one_player_screen.cpp @@ -3,6 +3,7 @@ #include +#include "utilities/util.h" #include "assets/path.h" #include "libmidi/midi.h" #include "one_player_screen.h" @@ -62,8 +63,24 @@ ScreenIndex OnePlayerScreen::run( //TODO move all these "init*" in a function made for that // and or see a better way to avoid that polluating this // function - font.loadFromFile(DEFAULT_FONT); - sf::Event event; + std::string actual_fonts_dir_path; + + if (dirExists(FONTS_DIR)) + { + actual_fonts_dir_path = FONTS_DIR; + } + else + { + actual_fonts_dir_path = LOCAL_FONTS_DIR; + } + if (!font.loadFromFile(actual_fonts_dir_path + DEFAULT_FONT)) { + std::cerr + << "Can't load " + << actual_fonts_dir_path + DEFAULT_FONT + << std::endl + ; + } + sf::Event event; sf::Clock clock; sf::Time currentElapsed = clock.getElapsedTime(); @@ -406,10 +423,20 @@ void OnePlayerScreen::scrollNoteGround( */ void OnePlayerScreen::initSpeedLabel(const sf::RenderWindow &app) { - if (!font.loadFromFile(DEFAULT_FONT)) { + std::string actual_fonts_dir_path; + + if (dirExists(FONTS_DIR)) + { + actual_fonts_dir_path = FONTS_DIR; + } + else + { + actual_fonts_dir_path = LOCAL_FONTS_DIR; + } + if (!font.loadFromFile(actual_fonts_dir_path + DEFAULT_FONT)) { std::cerr << "Can't load " - << DEFAULT_FONT + << actual_fonts_dir_path + DEFAULT_FONT << std::endl ; } @@ -430,10 +457,20 @@ void OnePlayerScreen::initSpeedLabel(const sf::RenderWindow &app) { */ void OnePlayerScreen::initInfoLabel(const sf::RenderWindow &app) { - if (!font.loadFromFile(DEFAULT_FONT)) { + std::string actual_fonts_dir_path; + + if (dirExists(FONTS_DIR)) + { + actual_fonts_dir_path = FONTS_DIR; + } + else + { + actual_fonts_dir_path = LOCAL_FONTS_DIR; + } + if (!font.loadFromFile(actual_fonts_dir_path + DEFAULT_FONT)) { std::cerr << "Can't load " - << DEFAULT_FONT + << actual_fonts_dir_path + DEFAULT_FONT << std::endl ; } diff --git a/src/screens/one_player_screen/score_display.cpp b/src/screens/one_player_screen/score_display.cpp index d319369..ea0cd3c 100644 --- a/src/screens/one_player_screen/score_display.cpp +++ b/src/screens/one_player_screen/score_display.cpp @@ -8,6 +8,7 @@ #include #include +#include "utilities/util.h" #include "assets/path.h" #include "score_display.h" @@ -28,15 +29,34 @@ static std::string padZero(unsigned number) { * */ void ScoreDisplay::init() { + std::string actual_graphics_dir_path; + std::string actual_fonts_dir_path; - if (!font.loadFromFile(DEFAULT_FONT)) { + if (dirExists(FONTS_DIR)) + { + actual_fonts_dir_path = FONTS_DIR; + } + else + { + actual_fonts_dir_path = LOCAL_FONTS_DIR; + } + if (!font.loadFromFile(actual_fonts_dir_path + DEFAULT_FONT)) { std::cerr << "Can't load " - << DEFAULT_FONT + << actual_fonts_dir_path + DEFAULT_FONT << std::endl ; } - const std::string STAR = GRAPHICS_DIR "star.png"; + + if (dirExists(GRAPHICS_DIR)) + { + actual_graphics_dir_path = GRAPHICS_DIR; + } + else + { + actual_graphics_dir_path = LOCAL_GRAPHICS_DIR; + } + const std::string STAR = actual_graphics_dir_path + "star.png"; if (!star.loadFromFile(STAR)) { std::cerr << "Can't load " @@ -44,10 +64,11 @@ void ScoreDisplay::init() { << std::endl ; } + //star.setSmooth(true); starSprite.setTexture(star); - const std::string THUMB_DOWN = GRAPHICS_DIR "thumb_down.png"; + const std::string THUMB_DOWN = actual_graphics_dir_path + "thumb_down.png"; if (!thumbdown.loadFromFile(THUMB_DOWN)) { std::cerr << "Can't load " diff --git a/src/screens/select_track_screen/track_box.cpp b/src/screens/select_track_screen/track_box.cpp index 690667f..852547f 100644 --- a/src/screens/select_track_screen/track_box.cpp +++ b/src/screens/select_track_screen/track_box.cpp @@ -7,6 +7,7 @@ #include #include +#include "utilities/util.h" #include "assets/path.h" #include "track_options/track_options.h" #include "track_box.h" @@ -20,7 +21,18 @@ sf::Font TrackBox::font = sf::Font(); * */ void TrackBox::init() { - const std::string TRACKBOX_FILE = GRAPHICS_DIR "trackbox.png"; + std::string actual_fonts_dir_path; + std::string actual_graphics_dir_path; + + if (dirExists(GRAPHICS_DIR)) + { + actual_graphics_dir_path = GRAPHICS_DIR; + } + else + { + actual_graphics_dir_path = LOCAL_GRAPHICS_DIR; + } + const std::string TRACKBOX_FILE = actual_graphics_dir_path + "trackbox.png"; if (!backgroundTexture.loadFromFile(TRACKBOX_FILE)) { std::cerr << "Can't load " @@ -28,12 +40,21 @@ void TrackBox::init() { << std::endl ; } + backgroundTexture.setSmooth(true); - if (!font.loadFromFile(DEFAULT_FONT)) { + if (dirExists(FONTS_DIR)) + { + actual_fonts_dir_path = FONTS_DIR; + } + else + { + actual_fonts_dir_path = LOCAL_FONTS_DIR; + } + if (!font.loadFromFile(actual_fonts_dir_path + DEFAULT_FONT)) { std::cerr << "Can't load " - << DEFAULT_FONT + << actual_fonts_dir_path + DEFAULT_FONT << std::endl ; } diff --git a/src/utilities/util.c b/src/utilities/util.c new file mode 100644 index 0000000..ddc22e8 --- /dev/null +++ b/src/utilities/util.c @@ -0,0 +1,17 @@ +#include +#include +#include +#include +#include "util.h" + +int dirExists(char const *path) +{ + struct stat info; + + if(stat( path, &info ) != 0) + return 0; + else if(info.st_mode & S_IFDIR) + return 1; + else + return 0; +} diff --git a/src/utilities/util.h b/src/utilities/util.h new file mode 100644 index 0000000..6446074 --- /dev/null +++ b/src/utilities/util.h @@ -0,0 +1,14 @@ +#ifndef UTIL_H +#define UTIL_H + +#ifdef __cplusplus +extern "C"{ +#endif + +int dirExists(const char *path); + +#ifdef __cplusplus +} +#endif + +#endif // UTIL_H \ No newline at end of file