Skip to content

Commit 7eb22b2

Browse files
committed
Added support for relative paths
1 parent fe7284f commit 7eb22b2

6 files changed

Lines changed: 42 additions & 1 deletion

File tree

Linux/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ vpath %.cc src
33
PRODUCT := bitPresent
44

55
CXX := g++
6-
CXXFLAGS := -c -g `wx-config-gtk3 --cxxflags`
6+
CXXFLAGS := -c -std=c++17 `wx-config-gtk3 --cxxflags`
77
CXXLIBS := -lSDL2 -lSDL2_ttf -lSDL2_image -lhpdf `wx-config-gtk3 --libs`
88
CXXINCDIRS := -I.
99

Linux/src/fileParser.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#include <vector>
33
#include <fstream>
44

5+
#include <filesystem>
6+
namespace fs = std::filesystem;
7+
58
#include "lib/fileParser.hh"
69
#include "lib/objects.hh"
710
#include "lib/gui.hh"
@@ -89,6 +92,14 @@ void parse(std::vector<std::string> tokens)
8992
{
9093
i += 1;
9194
if (tokens[i][0] == '<' || tokens[i][0] == '[' || tokens[i][0] == '-') gprintf("[WARNING](Line %d): Using instruction(\"%s\") as argument for '.image'\n", cline, tokens[i].c_str());
95+
96+
if(fs::path(tokens[i]).is_relative())
97+
{
98+
std::string tmp;
99+
tmp = Global::_INPATH + tokens[i];
100+
tokens[i] = tmp;
101+
}
102+
92103
Global::_FONT = { {"title", TTF_OpenFont(tokens[i].c_str(), 68)}, {"subtitle", TTF_OpenFont(tokens[i].c_str(), 50)}, {"normal", TTF_OpenFont(tokens[i].c_str(), 34)} };
93104
if (Global::_FONT["title"] == NULL || Global::_FONT["subtitle"] == NULL || Global::_FONT["normal"] == NULL)
94105
{

Linux/src/gui.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ void guiMain::OnCreateBtnClicked(wxCommandEvent &evt)
9595
else if(outputPathBox->GetValue() == wxEmptyString) wxMessageBox(wxT("Please specify an output file and try again"), wxT("No output file specified"), wxICON_WARNING);
9696
else
9797
{
98+
Global::_INPATH = inputPathBox->GetValue();
99+
int lastDirSep = Global::_INPATH.find_last_of("/\\");
100+
std::string tmp = Global::_INPATH.substr(0, lastDirSep + 1);
101+
Global::_INPATH = tmp;
102+
98103
createPresent((std::string) inputPathBox->GetValue(), (std::string) outputPathBox->GetValue());
99104
terminal->SetDefaultStyle(wxTextAttr(*wxGREEN));
100105
gprintf("You may now close this application\n");

Linux/src/imageGenerator.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "lib/imageGenerator.hh"
22

3+
#include <filesystem>
4+
namespace fs = std::filesystem;
5+
36
#include "lib/objects.hh"
47
#include "lib/globals.hh"
58
#include "lib/gui.hh"
@@ -13,6 +16,13 @@ SDL_Surface* generateSurface(int slide)
1316
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, 255, 255, 255));
1417
if (Global::_BACKGROUND != "none" && Global::_BACKGROUND != "default")
1518
{
19+
if(fs::path(Global::_BACKGROUND).is_relative())
20+
{
21+
std::string tmp;
22+
tmp = Global::_INPATH + Global::_BACKGROUND;
23+
Global::_BACKGROUND = tmp;
24+
}
25+
1626
image = IMG_Load(Global::_BACKGROUND.c_str());
1727
if (image == NULL) gprintf("[ERROR]: Rendering Background: %s\n", SDL_GetError());
1828
else SDL_BlitScaled(image, NULL, surface, NULL);
@@ -92,6 +102,13 @@ SDL_Surface* generateSurface(int slide)
92102

93103
if (Global::_PRESENT[Global::_CPRESENT]->slides[slide].image != "none")
94104
{
105+
if(fs::path(Global::_PRESENT[Global::_CPRESENT]->slides[slide].image).is_relative())
106+
{
107+
std::string tmp;
108+
tmp = Global::_INPATH + Global::_PRESENT[Global::_CPRESENT]->slides[slide].image;
109+
Global::_PRESENT[Global::_CPRESENT]->slides[slide].image = tmp;
110+
}
111+
95112
image = IMG_Load(Global::_PRESENT[Global::_CPRESENT]->slides[slide].image.c_str());
96113
if (image == NULL) gprintf("[ERROR]: Rendering Image: %s\n", SDL_GetError());
97114
else

Linux/src/lib/globals.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct Global
1717

1818
static bool useGUI;
1919
static guiApp* gApp;
20+
static std::string _INPATH;
2021

2122
static std::vector<Presentation*> _PRESENT;
2223
static int _CPRESENT;

Linux/src/main.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ std::string Global::_DEFAULTBACKGROUND = "";
2727

2828
bool Global::useGUI = false;
2929
guiApp* Global::gApp = nullptr;
30+
std::string Global::_INPATH = "";
3031

3132
std::string Global::_STATUS = "Ready";
3233
int Global::_MAXPROGRESS = 7;
@@ -49,6 +50,12 @@ int main(int argc, char* argv[])
4950
else
5051
{
5152
inpath = argv[1];
53+
int lastDirSep = inpath.find_last_of("/\\");
54+
std::string tmp = inpath.substr(0, lastDirSep + 1);
55+
inpath = tmp;
56+
57+
Global::_INPATH = inpath;
58+
5259
if (argc == 3) outpath = argv[2];
5360
else outpath = "presentation.pdf";
5461
}

0 commit comments

Comments
 (0)