Skip to content

Commit

Permalink
new icons, separete book search and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
karwler committed Jun 3, 2018
1 parent 6ab69f3 commit 0673fd3
Show file tree
Hide file tree
Showing 36 changed files with 255 additions and 228 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Settings files are being saved in "%AppData%\VertiRead".

## How to use it
The idea is that you have a library directory in which you have your comics saved in form of pictures. The location of this directory can be changed in the settings.
The last button in the book list allows you to navigate through files outside of the library directory.
Left clicking on a book in the book list wil take you to the file explorer, while right clicking on a book will take you to the last viewed page.
The reader has a hidden side panel on the left.

Expand Down
1 change: 0 additions & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
advanced book adding
multiple scroll modes for reader
Binary file removed rsc/data/textures/back.png
Binary file not shown.
Binary file removed rsc/data/textures/center.png
Binary file not shown.
Binary file added rsc/data/textures/circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rsc/data/textures/cross.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rsc/data/textures/left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rsc/data/textures/minus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed rsc/data/textures/next_dir.png
Binary file not shown.
Binary file added rsc/data/textures/plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed rsc/data/textures/prev_dir.png
Binary file not shown.
Binary file added rsc/data/textures/right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rsc/data/textures/search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rsc/data/textures/square.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed rsc/data/textures/zoom_in.png
Binary file not shown.
Binary file removed rsc/data/textures/zoom_out.png
Binary file not shown.
Binary file removed rsc/data/textures/zoom_reset.png
Binary file not shown.
4 changes: 3 additions & 1 deletion rsc/data/themes.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ dark=60 60 60 255
light=120 120 120 255
select=105 105 105 255
text=210 210 210 255
texture=210 210 210 255

[Light]
background=250 250 250 255
normal=210 210 210 255
dark=180 180 180 255
light=230 230 230 255
select=220 220 220 255
text=60 60 60 255
text=60 60 60 255
texture=60 60 60 255
11 changes: 8 additions & 3 deletions src/engine/drawSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ void DrawSys::drawSlider(Slider* wgt) {
}

void DrawSys::drawPicture(Picture* wgt) {
drawImage(wgt->tex, wgt->getRes(), wgt->rect(), wgt->parentFrame());
if (wgt->showBG)
drawRect(overlapRect(wgt->rect(), wgt->parentFrame()), wgt->color());
drawImage(wgt->tex, wgt->getRes(), wgt->texRect(), wgt->parentFrame());
}

void DrawSys::drawLabel(Label* wgt) {
Expand Down Expand Up @@ -217,9 +219,12 @@ SDL_Texture* DrawSys::renderText(const string& text, int height, vec2i& size) {

SDL_Texture* DrawSys::loadTexture(const string& file, vec2i& res) {
SDL_Texture* tex = IMG_LoadTexture(renderer, file.c_str());
if (tex)
if (tex) {
SDL_QueryTexture(tex, nullptr, nullptr, &res.x, &res.y);
else {
SDL_Color clr = colors[static_cast<uint8>(Color::texture)];
SDL_SetTextureColorMod(tex, clr.r, clr.g, clr.b);
SDL_SetTextureAlphaMod(tex, clr.a);
} else {
cerr << "Couldn't load texture " << file << endl << IMG_GetError << endl;
res = 0;
}
Expand Down
156 changes: 72 additions & 84 deletions src/engine/filer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,32 @@ IniLine::IniLine() :
type(Type::empty)
{}

IniLine::IniLine(const string& ARG, const string& VAL) :
type(Type::argVal),
arg(ARG),
val(VAL)
{}

IniLine::IniLine(const string& ARG, const string& KEY, const string& VAL) :
type(Type::argKeyVal),
arg(ARG),
key(KEY),
val(VAL)
{}

IniLine::IniLine(const string& TIT) :
type(Type::title),
arg(TIT)
{}
IniLine::IniLine(const string& line) {
setLine(line);
}

string IniLine::line() const {
if (type == Type::argVal)
return arg + '=' + val;
return line(arg, val);
if (type == Type::argKeyVal)
return arg + '[' + key + "]=" + val;
return line(arg, key, val);
if (type == Type::title)
return '[' + arg + ']';
return line(arg);
return "";
}

string IniLine::line(const string& title) {
return '[' + title + ']';
}

string IniLine::line(const string& arg, const string& val) {
return arg + '=' + val;
}

string IniLine::line(const string& arg, const string& key, const string& val) {
return arg + '[' + key + "]=" + val;
}

void IniLine::setVal(const string& ARG, const string& VAL) {
type = Type::argVal;
arg = ARG;
Expand All @@ -63,23 +61,26 @@ void IniLine::setTitle(const string& TIT) {
val.clear();
}

bool IniLine::setLine(const string& str) {
// clear line in case the function will return false
clear();
if (str.empty())
return false;
IniLine::Type IniLine::setLine(const string& str) {
if (str.empty()) {
clear();
return type;
}

// check if title
if (str[0] == '[' && str.back() == ']') {
arg = str.substr(1, str.length()-2);
type = Type::title;
return true;
key.clear();
val.clear();
return type = Type::title;
}

// find position of the '=' to split line into argument and value
sizt i0 = str.find_first_of('=');
if (i0 == string::npos)
return false;
if (i0 == string::npos) {
clear();
return type;
}
val = str.substr(i0+1);

// get arg and key if availible
Expand All @@ -88,12 +89,11 @@ bool IniLine::setLine(const string& str) {
if (i1 < i2 && i2 < i0) { // if '[' preceeds ']' and both preceed '='
arg = str.substr(0, i1);
key = str.substr(i1+1, i2-i1-1);
type = Type::argKeyVal;
} else {
arg = str.substr(0, i0);
type = Type::argVal;
return type = Type::argKeyVal;
}
return true;
arg = str.substr(0, i0);
key.clear();
return type = Type::argVal;
}

void IniLine::clear() {
Expand All @@ -106,15 +106,13 @@ void IniLine::clear() {
// FILER

const string Filer::dirExec = appendDsep(Filer::getDirExec());

#ifdef _WIN32
const vector<string> Filer::dirFonts = {Filer::dirExec, string(std::getenv("SystemDrive")) + "\\Windows\\Fonts\\"};
const string Filer::dirSets = string(std::getenv("AppData")) + "\\"+Default::titleDefault+"\\";
#else
const vector<string> Filer::dirFonts = {Filer::dirExec, "/usr/share/fonts/", string(std::getenv("HOME")) + "/.fonts/"};
const string Filer::dirSets = string(std::getenv("HOME")) + "/."+Default::titleExtra+"/";
#endif

const string Filer::dirLangs = Filer::dirExec + Default::dirLanguages + dsep;
const string Filer::dirTexs = Filer::dirExec + Default::dirTextures + dsep;

Expand All @@ -125,8 +123,8 @@ vector<string> Filer::getAvailibleThemes() {

vector<string> themes;
for (string& line : lines) {
IniLine il;
if (il.setLine(line) && il.getType() == IniLine::Type::title)
IniLine il(line);
if (il.getType() == IniLine::Type::title)
themes.push_back(il.getArg());
}
return themes;
Expand All @@ -135,24 +133,24 @@ vector<string> Filer::getAvailibleThemes() {
vector<SDL_Color> Filer::getColors(const string& theme) {
vector<SDL_Color> colors = Default::colors;
vector<string> lines;
if (!readTextFile(dirExec + Default::fileThemes, lines), false)
if (!readTextFile(dirExec + Default::fileThemes, lines))
return colors;

// find title equal to theme
IniLine il;
sizt i = 0;
while (i < lines.size()) {
il.setLine(lines[i]);
if (il.getType() == IniLine::Type::title && il.getArg() == theme)
if (il.setLine(lines[i]) == IniLine::Type::title && il.getArg() == theme)
break;
i++;
}

// read colors until the end of the file or another title
while (++i < lines.size()) {
il.setLine(lines[i]);
if (il.getType() == IniLine::Type::title)
if (il.setLine(lines[i]) == IniLine::Type::title)
break;
if (il.getType() != IniLine::Type::argVal)
continue;

sizt cid = strToEnum<sizt>(Default::colorNames, il.getArg());
if (cid < colors.size()) {
Expand Down Expand Up @@ -187,46 +185,44 @@ umap<string, string> Filer::getTranslations(const string& language) {

umap<string, string> translation;
for (string& line : lines) {
IniLine il;
if (il.setLine(line) && il.getType() != IniLine::Type::title)
IniLine il(line);
if (il.getType() == IniLine::Type::argVal)
translation.insert(make_pair(il.getArg(), il.getVal()));
}
return translation;
}

string Filer::getLastPage(const string& book) {
vector<string> lines;
if (!readTextFile(dirSets + Default::fileLastPages, lines, false))
if (!readTextFile(dirSets + Default::fileBooks, lines, false))
return "";

for (string& line : lines) {
IniLine il;
if (il.setLine(line) && il.getType() != IniLine::Type::title && il.getArg() == book)
IniLine il(line);
if (il.getType() == IniLine::Type::argVal && il.getArg() == book)
return il.getVal();
}
return "";
}

void Filer::saveLastPage(const string& file) {
vector<string> lines;
readTextFile(dirSets + Default::fileLastPages, lines, false);
readTextFile(dirSets + Default::fileBooks, lines, false);

// find line to replace or push back
sizt id = lines.size();
string book = getBook(file);
for (sizt i=0; i!=lines.size(); i++) {
IniLine il;
if (il.setLine(lines[i]) && il.getType() != IniLine::Type::title && il.getArg() == book) {
IniLine il(lines[i]);
if (il.getType() == IniLine::Type::argVal && il.getArg() == book) {
id = i;
break;
}
}
if (id == lines.size())
lines.push_back(IniLine(book, file).line());
lines.push_back(IniLine::line(book, file));
else
lines[id] = IniLine(book, file).line();

writeTextFile(dirSets + Default::fileLastPages, lines);
lines[id] = IniLine::line(book, file);
writeTextFile(dirSets + Default::fileBooks, lines);
}

Settings Filer::getSettings() {
Expand All @@ -236,8 +232,8 @@ Settings Filer::getSettings() {
return sets;

for (string& line : lines) {
IniLine il;
if (!il.setLine(line) || il.getType() == IniLine::Type::title)
IniLine il(line);
if (il.getType() != IniLine::Type::argVal)
continue;

if (il.getArg() == Default::iniKeywordMaximized)
Expand Down Expand Up @@ -266,16 +262,16 @@ Settings Filer::getSettings() {

void Filer::saveSettings(const Settings& sets) {
vector<string> lines = {
IniLine(Default::iniKeywordMaximized, btos(sets.maximized)).line(),
IniLine(Default::iniKeywordFullscreen, btos(sets.fullscreen)).line(),
IniLine(Default::iniKeywordResolution, sets.getResolutionString()).line(),
IniLine(Default::iniKeywordFont, sets.getFont()).line(),
IniLine(Default::iniKeywordLanguage, sets.getLang()).line(),
IniLine(Default::iniKeywordTheme, sets.getTheme()).line(),
IniLine(Default::iniKeywordLibrary, sets.getDirLib()).line(),
IniLine(Default::iniKeywordRenderer, sets.renderer).line(),
IniLine(Default::iniKeywordScrollSpeed, sets.getScrollSpeedString()).line(),
IniLine(Default::iniKeywordDeadzone, ntos(sets.getDeadzone())).line()
IniLine::line(Default::iniKeywordMaximized, btos(sets.maximized)),
IniLine::line(Default::iniKeywordFullscreen, btos(sets.fullscreen)),
IniLine::line(Default::iniKeywordResolution, sets.getResolutionString()),
IniLine::line(Default::iniKeywordFont, sets.getFont()),
IniLine::line(Default::iniKeywordLanguage, sets.getLang()),
IniLine::line(Default::iniKeywordTheme, sets.getTheme()),
IniLine::line(Default::iniKeywordLibrary, sets.getDirLib()),
IniLine::line(Default::iniKeywordRenderer, sets.renderer),
IniLine::line(Default::iniKeywordScrollSpeed, sets.getScrollSpeedString()),
IniLine::line(Default::iniKeywordDeadzone, ntos(sets.getDeadzone()))
};
writeTextFile(dirSets + Default::fileSettings, lines);
}
Expand All @@ -290,8 +286,8 @@ vector<Binding> Filer::getBindings() {
return bindings;

for (string& line : lines) {
IniLine il;
if (!il.setLine(line) || il.getType() == IniLine::Type::title || il.getVal().size() < 3)
IniLine il(line);
if (il.getType() != IniLine::Type::argKeyVal || il.getVal().size() < 3)
continue;

sizt bid = strToEnum<sizt>(Default::bindingNames, il.getArg());
Expand Down Expand Up @@ -327,19 +323,19 @@ void Filer::saveBindings(const vector<Binding>& bindings) {
for (sizt i=0; i<bindings.size(); i++) {
string name = enumToStr(Default::bindingNames, i);
if (bindings[i].keyAssigned())
lines.push_back(IniLine(name, "K_" + string(SDL_GetScancodeName(bindings[i].getKey()))).line());
lines.push_back(IniLine::line(name, "K_" + string(SDL_GetScancodeName(bindings[i].getKey()))));

if (bindings[i].jbuttonAssigned())
lines.push_back(IniLine(name, "B_" + ntos(bindings[i].getJctID())).line());
lines.push_back(IniLine::line(name, "B_" + ntos(bindings[i].getJctID())));
else if (bindings[i].jhatAssigned())
lines.push_back(IniLine(name, "H_" + ntos(bindings[i].getJctID()) + "_" + jtHatToStr(bindings[i].getJhatVal())).line());
lines.push_back(IniLine::line(name, "H_" + ntos(bindings[i].getJctID()) + "_" + jtHatToStr(bindings[i].getJhatVal())));
else if (bindings[i].jaxisAssigned())
lines.push_back(IniLine(name, string(bindings[i].jposAxisAssigned() ? "A_+" : "A_-") + ntos(bindings[i].getJctID())).line());
lines.push_back(IniLine::line(name, string(bindings[i].jposAxisAssigned() ? "A_+" : "A_-") + ntos(bindings[i].getJctID())));

if (bindings[i].gbuttonAssigned())
lines.push_back(IniLine(name, "G_" + enumToStr(Default::gbuttonNames, bindings[i].getGbutton())).line());
lines.push_back(IniLine::line(name, "G_" + enumToStr(Default::gbuttonNames, bindings[i].getGbutton())));
else if (bindings[i].gbuttonAssigned())
lines.push_back(IniLine(name, string(bindings[i].gposAxisAssigned() ? "X_+" : "X_-") + enumToStr(Default::gaxisNames, bindings[i].getGaxis())).line());
lines.push_back(IniLine::line(name, string(bindings[i].gposAxisAssigned() ? "X_+" : "X_-") + enumToStr(Default::gaxisNames, bindings[i].getGaxis())));
}
writeTextFile(dirSets + Default::fileBindings, lines);
}
Expand Down Expand Up @@ -465,14 +461,6 @@ FileType Filer::fileType(const string& path) {
return FTYPE_FILE;
}

bool Filer::isPicture(const string& file) {
if (SDL_Surface* img = IMG_Load(file.c_str())) {
SDL_FreeSurface(img);
return true;
}
return false;
}

#ifdef _WIN32
vector<char> Filer::listDrives() {
vector<char> letters;
Expand Down
Loading

0 comments on commit 0673fd3

Please sign in to comment.