Skip to content

Commit

Permalink
set IniFilename
Browse files Browse the repository at this point in the history
  • Loading branch information
Lecrapouille committed Dec 30, 2023
1 parent 2a4297d commit 520dc02
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ INCLUDES += -I$(P)/include -I$(P)/src -I$(P)/external
###################################################
# Project defines
#
DEFINES += -DDATADIR=\"$(DATADIR)\"
DEFINES += -DDATADIR=\"$(DATADIR):$(abspath $(P))/data/\"

###################################################
# Reduce warnings
Expand Down Expand Up @@ -201,19 +201,23 @@ OBJS += DearUtils.o Drawable.o Application.o PetriEditor.o main.o
###################################################
# Compile the project, the static and shared libraries
.PHONY: all
all: copy-emscripten-assets $(STATIC_LIB_TARGET) $(SHARED_LIB_TARGET) $(PKG_FILE) $(TARGET)
all: copy-assets $(STATIC_LIB_TARGET) $(SHARED_LIB_TARGET) $(PKG_FILE) $(TARGET)

###################################################
#
.PHONY: copy-emscripten-assets
copy-emscripten-assets: | $(BUILD)
# Copy data inside BUILD to allow emscripten to embedded them
.PHONY: copy-assets
copy-assets: | $(BUILD)
ifeq ($(ARCHI),Emscripten)
@$(call print-to,"Copying assets","$(TARGET)","$(BUILD)","")
@mkdir -p $(BUILD)/data
@mkdir -p $(BUILD)/examples
@cp $(P)/data/examples/*.json $(BUILD)/examples
@cp $(P)/data/font.ttf $(BUILD)/data
@cp $(P)/imgui.ini $(BUILD)
@cp $(P)/imgui.ini $(BUILD)/data
else ifeq ($(ARCHI),Darwin)
# FIXME the data folder is copied automatically but missing rule
# for other path
@cp $(P)/imgui.ini $(P)/data
endif

###################################################
Expand Down
8 changes: 7 additions & 1 deletion src/Editor/PetriEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ void Editor::startUp(std::string const& filepath)
# define FONT_SIZE 13.0f
#endif

// Setup fonts
std::cout << "Path: " << m_path.toString() << std::endl;

// Set imgui.ini loading/saving location
ImGuiIO &io = ImGui::GetIO();
io.IniFilename = m_path.expand("imgui.ini").c_str();
std::cout << "imgui.ini path: " << io.IniFilename << std::endl;

// Setup fonts
io.Fonts->AddFontFromFileTTF(m_path.expand("font.ttf").c_str(), FONT_SIZE);
reloadFonts();

Expand Down
13 changes: 13 additions & 0 deletions src/Utils/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ bool Path::open(std::string& filename, std::fstream& fs, std::ios_base::openmode
return false;
}

//------------------------------------------------------------------------------
std::vector<std::string> Path::pathes() const
{
std::vector<std::string> res;
res.reserve(m_search_paths.size());
for (auto const& it: m_search_paths)
{
res.push_back(it);
}

return res;
}

//------------------------------------------------------------------------------
std::string Path::toString() const
{
Expand Down
14 changes: 11 additions & 3 deletions src/Utils/Path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ std::string osx_get_resources_dir(std::string const& file);
# endif

//------------------------------------------------------------------------------
# ifndef DATADIR
# define GET_DATA_PATH project::info::data_path
# endif
# if defined(__APPLE__)
# define GET_DATA_PATH osx_get_resources_dir("")
# define GET_DATA_PATH DATADIR":" + osx_get_resources_dir("")
# elif defined(__EMSCRIPTEN__)
# define GET_DATA_PATH "data/"
# else
# define GET_DATA_PATH project::info::data_path
# define GET_DATA_PATH DATADIR
# endif

// *****************************************************************************
Expand Down Expand Up @@ -107,10 +110,15 @@ class Path
//--------------------------------------------------------------------------
std::string expand(std::string const& filename) const;

//--------------------------------------------------------------------------
//! \brief Return the container of path
//--------------------------------------------------------------------------
std::vector<std::string> pathes() const;

//--------------------------------------------------------------------------
//! \brief Return pathes as string. The first path is always ".:"
//--------------------------------------------------------------------------
std::string toString() const;
std::string toString() const;

bool open(std::string& filename, std::ifstream& ifs,
std::ios_base::openmode mode = std::ios_base::in) const;
Expand Down

0 comments on commit 520dc02

Please sign in to comment.