Skip to content

Commit fe7284f

Browse files
committed
Finalized GUI
1 parent 9f9abc8 commit fe7284f

9 files changed

Lines changed: 81 additions & 34 deletions

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 `wx-config-gtk3 --cxxflags`
6+
CXXFLAGS := -c -g `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: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void parse(std::vector<std::string> tokens)
5454
{
5555
int cline = nDotWarn;
5656

57-
if(Global::_PRESENT == nullptr)
57+
if(Global::_PRESENT[Global::_CPRESENT] == nullptr)
5858
{
5959
gprintf("[ERROR]: Presentation object does not exist\n");
6060
return;
@@ -81,7 +81,7 @@ void parse(std::vector<std::string> tokens)
8181
i += 1;
8282
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());
8383
if (Global::_CSLIDE < 0) gprintf("[WARNING]: '.image' used outside of a slide. Ignoring...\n");
84-
else Global::_PRESENT->slides[Global::_CSLIDE].image = tokens[i];
84+
else Global::_PRESENT[Global::_CPRESENT]->slides[Global::_CSLIDE].image = tokens[i];
8585
continue;
8686
}
8787

@@ -116,29 +116,36 @@ void parse(std::vector<std::string> tokens)
116116
//Check for other defining Tokens
117117
if (tokens[i][0] == '<' && tokens[i][tokens[i].length() - 1] == '>')
118118
{
119-
Global::_PRESENT->slides.push_back(Slide());
119+
Global::_PRESENT[Global::_CPRESENT]->slides.push_back(Slide());
120120
Global::_CSLIDE = Global::_CSLIDE + 1;
121121
Global::_CPOINT = -1;
122122

123-
Global::_PRESENT->slides[Global::_CSLIDE].titleSlide = true;
124-
Global::_PRESENT->slides[Global::_CSLIDE].title = tokens[i].substr(1, tokens[i].length() - 2);
123+
Global::_PRESENT[Global::_CPRESENT]->slides[Global::_CSLIDE].titleSlide = true;
124+
125+
std::string tmp = tokens[i].substr(1, tokens[i].length() - 2);
126+
Global::_PRESENT[Global::_CPRESENT]->slides[Global::_CSLIDE].title = tmp;
125127
continue;
126128
}
127129

128130
if (tokens[i][0] == '[' && tokens[i][tokens[i].length() - 1] == ']')
129131
{
130-
Global::_PRESENT->slides.push_back(Slide());
132+
Global::_PRESENT[Global::_CPRESENT]->slides.push_back(Slide());
131133
Global::_CSLIDE = Global::_CSLIDE + 1;
132134
Global::_CPOINT = -1;
133135

134-
Global::_PRESENT->slides[Global::_CSLIDE].title = tokens[i].substr(1, tokens[i].length() - 2);
136+
std::string tmp = tokens[i].substr(1, tokens[i].length() - 2);
137+
Global::_PRESENT[Global::_CPRESENT]->slides[Global::_CSLIDE].title = tmp;
135138
continue;
136139
}
137140

138141
if (tokens[i][0] == '-' && tokens[i][tokens[i].length() - 1] == '-')
139142
{
140143
if (Global::_CSLIDE < 0) gprintf("[WARNING](Line %d): Defined subtitle outside of a slide. Ignoring...\n", cline);
141-
else Global::_PRESENT->slides[Global::_CSLIDE].subtitle = tokens[i].substr(1, tokens[i].length() - 2);
144+
else
145+
{
146+
std::string tmp = tokens[i].substr(1, tokens[i].length() - 2);
147+
Global::_PRESENT[Global::_CPRESENT]->slides[Global::_CSLIDE].subtitle = tmp;
148+
}
142149
continue;
143150
}
144151

@@ -150,7 +157,7 @@ void parse(std::vector<std::string> tokens)
150157
{
151158
int cutoff = 1;
152159
if (tokens[i][1] == ' ') cutoff = 2;
153-
Global::_PRESENT->slides[Global::_CSLIDE].points[Global::_CPOINT].subPoints.push_back(tokens[i].substr(cutoff, tokens[i].length() - 1));
160+
Global::_PRESENT[Global::_CPRESENT]->slides[Global::_CSLIDE].points[Global::_CPOINT].subPoints.push_back(tokens[i].substr(cutoff, tokens[i].length() - 1));
154161
}
155162
continue;
156163
}
@@ -159,8 +166,10 @@ void parse(std::vector<std::string> tokens)
159166
if (Global::_CSLIDE < 0) gprintf("[WARNING](Line %d): Defined point outside of a slide. Ignoring...\n", cline);
160167
else
161168
{
162-
Global::_PRESENT->slides[Global::_CSLIDE].points.push_back(Point(tokens[i]));
169+
Global::_PRESENT[Global::_CPRESENT]->slides[Global::_CSLIDE].points.push_back(Point(tokens[i]));
163170
Global::_CPOINT = Global::_CPOINT + 1;
164171
}
165172
}
173+
174+
tokens.clear();
166175
}

Linux/src/gui.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,18 @@ void guiMain::OnCreateBtnClicked(wxCommandEvent &evt)
9393
{
9494
if(inputPathBox->GetValue() == wxEmptyString) wxMessageBox(wxT("Please specify an input file and try again"), wxT("No input file specified"), wxICON_WARNING);
9595
else if(outputPathBox->GetValue() == wxEmptyString) wxMessageBox(wxT("Please specify an output file and try again"), wxT("No output file specified"), wxICON_WARNING);
96-
else createPresent((std::string) inputPathBox->GetValue(), (std::string) outputPathBox->GetValue());
96+
else
97+
{
98+
createPresent((std::string) inputPathBox->GetValue(), (std::string) outputPathBox->GetValue());
99+
terminal->SetDefaultStyle(wxTextAttr(*wxGREEN));
100+
gprintf("You may now close this application\n");
101+
102+
inputPathBox->Enable(false);
103+
outputPathBox->Enable(false);
104+
inputBrowseBtn->Enable(false);
105+
outputBrowseBtn->Enable(false);
106+
createBtn->Enable(false);
107+
}
97108
evt.Skip();
98109
}
99110

Linux/src/imageGenerator.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ SDL_Surface* generateSurface(int slide)
2323
SDL_Rect dst;
2424

2525
//Draw Content
26-
if (Global::_PRESENT->slides[slide].titleSlide)
26+
if (Global::_PRESENT[Global::_CPRESENT]->slides[slide].titleSlide)
2727
{
2828
//Title
29-
text = TTF_RenderUTF8_Blended_Wrapped(Global::_FONT["title"], Global::_PRESENT->slides[slide].title.c_str(), *Global::_TEXTCOLOR, Global::_WIDTH - 2 * Global::_BORDERS);
29+
text = TTF_RenderUTF8_Blended_Wrapped(Global::_FONT["title"], Global::_PRESENT[Global::_CPRESENT]->slides[slide].title.c_str(), *Global::_TEXTCOLOR, Global::_WIDTH - 2 * Global::_BORDERS);
3030
if (text == NULL) gprintf("[ERROR]: Rendering Title: %s\n", TTF_GetError());
3131
else
3232
{
@@ -36,9 +36,9 @@ SDL_Surface* generateSurface(int slide)
3636
}
3737

3838
//Subtitle
39-
if (Global::_PRESENT->slides[slide].subtitle.length() > 0)
39+
if (Global::_PRESENT[Global::_CPRESENT]->slides[slide].subtitle.length() > 0)
4040
{
41-
text = TTF_RenderUTF8_Blended_Wrapped(Global::_FONT["subtitle"], Global::_PRESENT->slides[slide].subtitle.c_str(), *Global::_TEXTCOLOR, Global::_WIDTH - 2 * Global::_BORDERS);
41+
text = TTF_RenderUTF8_Blended_Wrapped(Global::_FONT["subtitle"], Global::_PRESENT[Global::_CPRESENT]->slides[slide].subtitle.c_str(), *Global::_TEXTCOLOR, Global::_WIDTH - 2 * Global::_BORDERS);
4242
if (text == NULL) gprintf("[ERROR]: Rendering Subtitle: %s\n", TTF_GetError());
4343
else
4444
{
@@ -49,7 +49,7 @@ SDL_Surface* generateSurface(int slide)
4949
}
5050

5151
//Render "Created with BitPresent"
52-
if (slide == Global::_PRESENT->slides.size() - 1)
52+
if (slide == Global::_PRESENT[Global::_CPRESENT]->slides.size() - 1)
5353
{
5454
text = TTF_RenderUTF8_Blended(Global::_FONT["footer"], "Created with BitPresent", *Global::_TEXTCOLOR);
5555
if (text == NULL) gprintf("[ERROR]: Rendering Footer: %s\n", TTF_GetError());
@@ -64,7 +64,7 @@ SDL_Surface* generateSurface(int slide)
6464
else
6565
{
6666
//Title
67-
text = TTF_RenderUTF8_Blended_Wrapped(Global::_FONT["title"], Global::_PRESENT->slides[slide].title.c_str(), *Global::_TEXTCOLOR, Global::_WIDTH - 2 * Global::_BORDERS);
67+
text = TTF_RenderUTF8_Blended_Wrapped(Global::_FONT["title"], Global::_PRESENT[Global::_CPRESENT]->slides[slide].title.c_str(), *Global::_TEXTCOLOR, Global::_WIDTH - 2 * Global::_BORDERS);
6868
if (text == NULL) gprintf("[ERROR]: Rendering Title: %s\n", TTF_GetError());
6969
else
7070
{
@@ -74,9 +74,9 @@ SDL_Surface* generateSurface(int slide)
7474
}
7575

7676
//Subtitle
77-
if (Global::_PRESENT->slides[slide].subtitle.length() > 0)
77+
if (Global::_PRESENT[Global::_CPRESENT]->slides[slide].subtitle.length() > 0)
7878
{
79-
text = TTF_RenderUTF8_Blended_Wrapped(Global::_FONT["subtitle"], Global::_PRESENT->slides[slide].subtitle.c_str(), *Global::_TEXTCOLOR, Global::_WIDTH - 2 * Global::_BORDERS);
79+
text = TTF_RenderUTF8_Blended_Wrapped(Global::_FONT["subtitle"], Global::_PRESENT[Global::_CPRESENT]->slides[slide].subtitle.c_str(), *Global::_TEXTCOLOR, Global::_WIDTH - 2 * Global::_BORDERS);
8080
if (text == NULL) gprintf("[ERROR]: Rendering Subtitle: %s\n", TTF_GetError());
8181
else
8282
{
@@ -90,9 +90,9 @@ SDL_Surface* generateSurface(int slide)
9090
int contentHeight = dst.y + dst.h * 2;
9191
int imgPosX = Global::_WIDTH;
9292

93-
if (Global::_PRESENT->slides[slide].image != "none")
93+
if (Global::_PRESENT[Global::_CPRESENT]->slides[slide].image != "none")
9494
{
95-
image = IMG_Load(Global::_PRESENT->slides[slide].image.c_str());
95+
image = IMG_Load(Global::_PRESENT[Global::_CPRESENT]->slides[slide].image.c_str());
9696
if (image == NULL) gprintf("[ERROR]: Rendering Image: %s\n", SDL_GetError());
9797
else
9898
{
@@ -119,7 +119,7 @@ SDL_Surface* generateSurface(int slide)
119119
}
120120

121121
//Points
122-
for (int i = 0; i < Global::_PRESENT->slides[slide].points.size(); i++)
122+
for (int i = 0; i < Global::_PRESENT[Global::_CPRESENT]->slides[slide].points.size(); i++)
123123
{
124124
//Render Dashes
125125
text = TTF_RenderUTF8_Blended(Global::_FONT["normal"], "- ", *Global::_TEXTCOLOR);
@@ -132,7 +132,7 @@ SDL_Surface* generateSurface(int slide)
132132
}
133133

134134
//Render Text
135-
text = TTF_RenderUTF8_Blended_Wrapped(Global::_FONT["normal"], Global::_PRESENT->slides[slide].points[i].text.c_str(), *Global::_TEXTCOLOR, imgPosX - 2 * Global::_BORDERS - dst.x);
135+
text = TTF_RenderUTF8_Blended_Wrapped(Global::_FONT["normal"], Global::_PRESENT[Global::_CPRESENT]->slides[slide].points[i].text.c_str(), *Global::_TEXTCOLOR, imgPosX - 2 * Global::_BORDERS - dst.x);
136136
if (text == NULL) gprintf("[ERROR]: Rendering Points: %s\n", TTF_GetError());
137137
else
138138
{
@@ -143,7 +143,7 @@ SDL_Surface* generateSurface(int slide)
143143
}
144144

145145
//Render Subpoints
146-
for(int j = 0; j < Global::_PRESENT->slides[slide].points[i].subPoints.size(); j++)
146+
for(int j = 0; j < Global::_PRESENT[Global::_CPRESENT]->slides[slide].points[i].subPoints.size(); j++)
147147
{
148148
//Render Dots
149149
text = TTF_RenderUTF8_Blended(Global::_FONT["normal"], "> ", *Global::_TEXTCOLOR);
@@ -156,7 +156,7 @@ SDL_Surface* generateSurface(int slide)
156156
}
157157

158158
//Render Text
159-
text = TTF_RenderUTF8_Blended_Wrapped(Global::_FONT["normal"], Global::_PRESENT->slides[slide].points[i].subPoints[j].c_str(), *Global::_TEXTCOLOR, imgPosX - 2 * Global::_BORDERS - dst.x);
159+
text = TTF_RenderUTF8_Blended_Wrapped(Global::_FONT["normal"], Global::_PRESENT[Global::_CPRESENT]->slides[slide].points[i].subPoints[j].c_str(), *Global::_TEXTCOLOR, imgPosX - 2 * Global::_BORDERS - dst.x);
160160
if (text == NULL) gprintf("[ERROR]: Rendering Points: %s\n", TTF_GetError());
161161
else
162162
{
@@ -169,7 +169,7 @@ SDL_Surface* generateSurface(int slide)
169169
}
170170

171171
//Render "Created with BitPresent"
172-
if (slide == Global::_PRESENT->slides.size() - 1)
172+
if (slide == Global::_PRESENT[Global::_CPRESENT]->slides.size() - 1)
173173
{
174174
text = TTF_RenderUTF8_Blended(Global::_FONT["footer"], "Created with BitPresent", *Global::_TEXTCOLOR);
175175
if (text == NULL) gprintf("[ERROR]: Rendering Footer: %s\n", TTF_GetError());

Linux/src/lib/globals.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ struct Global
1818
static bool useGUI;
1919
static guiApp* gApp;
2020

21-
static Presentation* _PRESENT;
21+
static std::vector<Presentation*> _PRESENT;
22+
static int _CPRESENT;
2223
static int _CSLIDE;
2324
static int _CPOINT;
2425

Linux/src/lib/objects.hh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ struct Point
99

1010
std::string text;
1111
std::vector<std::string> subPoints;
12+
13+
void clean()
14+
{
15+
text.clear();
16+
17+
for(int i = 0; i < subPoints.size(); i++) subPoints[i].clear();
18+
subPoints.clear();
19+
}
1220
};
1321

1422
struct Slide
@@ -18,9 +26,25 @@ struct Slide
1826
std::string subtitle;
1927
std::string image = "none";
2028
std::vector<Point> points;
29+
30+
void clean()
31+
{
32+
titleSlide = false;
33+
title.clear();
34+
subtitle.clear();
35+
image = "none";
36+
37+
for(int i = 0; i < points.size(); i++) points[i].clean();
38+
points.clear();
39+
}
2140
};
2241

2342
struct Presentation
2443
{
2544
std::vector<Slide> slides;
45+
void clean()
46+
{
47+
for(int i = 0; i < slides.size(); i++) slides[i].clean();
48+
slides.clear();
49+
}
2650
};

Linux/src/main.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ int Global::_HEIGHT = 1080;
1313
int Global::_BORDERS = 20;
1414
int Global::_INDENT = 40;
1515

16-
Presentation* Global::_PRESENT = nullptr;
16+
std::vector<Presentation*> Global::_PRESENT;
17+
int Global::_CPRESENT = -1;
1718
int Global::_CSLIDE = -1;
1819
int Global::_CPOINT = -1;
1920

Linux/src/pdfCreator.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int createPDF(std::string outpath)
2828
if(Global::useGUI) progress();
2929

3030
std::vector<HPDF_Page> pages;
31-
for(int i = 0; i < Global::_PRESENT->slides.size(); i++)
31+
for(int i = 0; i < Global::_PRESENT[Global::_CPRESENT]->slides.size(); i++)
3232
{
3333
pages.push_back(HPDF_AddPage(pdf));
3434
HPDF_Page_SetWidth(pages[i], Global::_WIDTH);

Linux/src/presentCreator.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ int createPresent(std::string inpath, std::string outpath)
2525
}
2626

2727
//Create global Presentation object
28-
Global::_PRESENT = new Presentation();
28+
Global::_PRESENT.push_back(new Presentation());
29+
Global::_CPRESENT += 1;
2930

3031
//Parse tokens to global Presentation object
3132
parse(tokens);
@@ -35,9 +36,10 @@ int createPresent(std::string inpath, std::string outpath)
3536
changeStatus("Creating Images");
3637
progress();
3738
}
39+
tokens.clear();
3840

3941
//Generate images for each Slide
40-
for (int i = 0; i < Global::_PRESENT->slides.size(); i++)
42+
for (int i = 0; i < Global::_PRESENT[Global::_CPRESENT]->slides.size(); i++)
4143
{
4244
SDL_Surface* surface = generateSurface(i);
4345
if (surface == nullptr) return -1;
@@ -59,9 +61,8 @@ int createPresent(std::string inpath, std::string outpath)
5961
if(Global::useGUI) changeStatus("Finished");
6062

6163
//Cleanup
62-
delete Global::_PRESENT;
64+
Global::_PRESENT[Global::_CPRESENT]->clean();
6365

6466
gprintf("[FINISHED]: Done creating presentation\n");
65-
6667
return 0;
6768
}

0 commit comments

Comments
 (0)