Skip to content

Commit

Permalink
add reading direction aka. horizontal scrolling, window resizing and …
Browse files Browse the repository at this point in the history
…settings reset button
  • Loading branch information
karwler committed Jul 22, 2018
1 parent 07df50d commit a64d328
Show file tree
Hide file tree
Showing 30 changed files with 641 additions and 396 deletions.
42 changes: 41 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,44 @@ ASALocalRun/
*.binlog
*.nvuser
.mfractor/
*.pubxml.user
*.pubxml.user

# Linux
*~
.fuse_hidden*
.directory
.Trash-*
.nfs*

# OS X
.DS_Store
.AppleDouble
.LSOverride
Icon
._*
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Windows
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
*.stackdump
[Dd]esktop.ini
$RECYCLE.BIN/
*.cab
*.msi
*.msix
*.msm
*.msp
*.lnk
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ Left clicking on a book in the book list wil take you to the file explorer, whil
The last button in the book list allows you to navigate through files outside of the library directory. When in the book list or browser view, you can drag and drop a folder or file into the window to browse/open it. It's also possible to start the program with a file/directory path as a command line argument to start in the page browser or reader.
The reader has a hidden side panel on the left.

The direction in which pictures in the reader are stacked can be set in the settings menu.
The program supports keyboard and controller bindings. DirectInput and XInput are handled separately. The bindings can be changed in the settings.
To reset certain groups of settings, edit or delete the corresponding ini files in the settings directory.
To reset certain settings, edit or delete the corresponding ini files in the settings directory or use the reset button in the settings menu to reset all settings.
1 change: 0 additions & 1 deletion TODO.txt

This file was deleted.

9 changes: 8 additions & 1 deletion rsc/data/languages/Deutsch.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ back=zurück
ok=ok
set=einstellen
up=hoch
direction=Richtung
fullscreen=Vollbild
size=Größe
portrait=Porträt
landscape=Landschaft
square=Quadrat
fill=füllen
theme=Aussehen
language=Sprache
font=Schriftart
library=Bibliothek
renderer=Renderer
scroll speed=Scrollgeschwindigkeit
deadzone=Deadzone
deadzone=Deadzone
reset=zurücksetzen
9 changes: 8 additions & 1 deletion rsc/data/languages/Polski.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ back=wróć
ok=ok
set=ustaw
up=do góry
direction=kierunek
fullscreen=pełny ekran
size=rozmiar
portrait=portret
landscape=krajobraz
square=kwadrat
fill=wypełnij
theme=wygląd
language=język
font=czcionka
library=biblioteka
renderer=render
scroll speed=prędkość przewijania
deadzone=martwa strefa
deadzone=martwa strefa
reset=zresetuj
9 changes: 8 additions & 1 deletion rsc/data/languages/Русский.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ back=назад
ok=хорошо
set=устанавливай
up=вверх
direction=направление
fullscreen=полноэкранный
size=размер
portrait=портрет
landscape=пейзаж
square=квадрат
fill=заполний
theme=внешний вид
language=язык
font=шрифт
library=библиотека
renderer=визуализатор
scroll speed=скорость прокрутки
deadzone=мертвая зона
deadzone=мертвая зона
reset=сбросий
12 changes: 6 additions & 6 deletions src/engine/drawSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void DrawSys::drawLabel(Label* wgt) {

void DrawSys::drawScrollArea(ScrollArea* box) {
vec2t vis = box->visibleWidgets(); // get index interval of items on screen and draw children
for (sizt i=vis.l; i<vis.u; i++)
for (sizt i = vis.l; i < vis.u; i++)
box->getWidget(i)->drawSelf();

drawRect(box->barRect(), Color::dark); // draw scroll bar
Expand All @@ -182,7 +182,7 @@ void DrawSys::drawScrollArea(ScrollArea* box) {

void DrawSys::drawReaderBox(ReaderBox* box) {
vec2t vis = box->visibleWidgets();
for (sizt i=vis.l; i<vis.u; i++)
for (sizt i = vis.l; i < vis.u; i++)
box->getWidget(i)->drawSelf();

if (box->showBar()) {
Expand Down Expand Up @@ -236,11 +236,11 @@ SDL_Texture* DrawSys::renderText(const string& text, int height) {
return tex;
}

vector<pair<string, SDL_Texture*>> DrawSys::loadTextures(string dir) {
dir = appendDsep(dir);
vector<pair<string, SDL_Texture*>> DrawSys::loadTextures(string drc) {
drc = appendDsep(drc);
vector<pair<string, SDL_Texture*>> pics;
for (string& it : Filer::listDir(dir, FTYPE_FILE))
if (SDL_Texture* tex = IMG_LoadTexture(renderer, string(dir + it).c_str()))
for (string& it : Filer::listDir(drc, FTYPE_FILE))
if (SDL_Texture* tex = IMG_LoadTexture(renderer, string(drc + it).c_str()))
pics.push_back(make_pair(it, tex));
return pics;
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/drawSys.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class DrawSys {
void drawPopup(Popup* box);

SDL_Texture* renderText(const string& text, int height);
vector<pair<string, SDL_Texture*>> loadTextures(string dir);
vector<pair<string, SDL_Texture*>> loadTextures(string drc);

SDL_Renderer* renderer;
private:
Expand Down
39 changes: 21 additions & 18 deletions src/engine/filer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void Filer::saveLastPage(const string& file) {

sizt id = lines.size();
string book = getBook(file);
for (sizt i=0; i!=lines.size(); i++) {
for (sizt i = 0; i < lines.size(); i++) {
IniLine il(lines[i]);
if (il.getType() == IniLine::Type::argVal && il.getArg() == book) {
id = i;
Expand Down Expand Up @@ -242,6 +242,8 @@ Settings Filer::getSettings() {
sets.fullscreen = stob(il.getVal());
else if (il.getArg() == Default::iniKeywordResolution)
sets.setResolution(il.getVal());
else if (il.getArg() == Default::iniKeywordDirection)
sets.direction = strToEnum<Direction::Dir>(Default::directionNames, il.getVal());
else if (il.getArg() == Default::iniKeywordFont)
sets.setFont(il.getVal());
else if (il.getArg() == Default::iniKeywordLanguage)
Expand All @@ -265,6 +267,7 @@ void Filer::saveSettings(const Settings& sets) {
IniLine::line(Default::iniKeywordMaximized, btos(sets.maximized)),
IniLine::line(Default::iniKeywordFullscreen, btos(sets.fullscreen)),
IniLine::line(Default::iniKeywordResolution, sets.getResolutionString()),
IniLine::line(Default::iniKeywordDirection, enumToStr(Default::directionNames, sets.direction)),
IniLine::line(Default::iniKeywordFont, sets.getFont()),
IniLine::line(Default::iniKeywordLanguage, sets.getLang()),
IniLine::line(Default::iniKeywordTheme, sets.getTheme()),
Expand All @@ -278,7 +281,7 @@ void Filer::saveSettings(const Settings& sets) {

vector<Binding> Filer::getBindings() {
vector<Binding> bindings(static_cast<sizt>(Binding::Type::numBindings));
for (sizt i=0; i<bindings.size(); i++)
for (sizt i = 0; i < bindings.size(); i++)
bindings[i].setDefaultSelf(static_cast<Binding::Type>(i));

vector<string> lines;
Expand All @@ -299,7 +302,7 @@ vector<Binding> Filer::getBindings() {
bindings[bid].setJbutton(stoi(il.getVal().substr(2)));
break;
case 'H': // joystick hat
for (sizt i=2; i<il.getVal().size(); i++)
for (sizt i = 2; i < il.getVal().size(); i++)
if (il.getVal()[i] < '0' || il.getVal()[i] > '9') {
bindings[bid].setJhat(stoi(il.getVal().substr(2, i-2)), jtStrToHat(il.getVal().substr(i+1)));
break;
Expand All @@ -320,7 +323,7 @@ vector<Binding> Filer::getBindings() {

void Filer::saveBindings(const vector<Binding>& bindings) {
vector<string> lines;
for (sizt i=0; i<bindings.size(); i++) {
for (sizt i = 0; i < bindings.size(); i++) {
string name = enumToStr(Default::bindingNames, i);
if (bindings[i].keyAssigned())
lines.push_back(IniLine::line(name, "K_" + string(SDL_GetScancodeName(bindings[i].getKey()))));
Expand Down Expand Up @@ -374,11 +377,11 @@ bool Filer::mkDir(const string& path) {
#endif
}

vector<string> Filer::listDir(const string& dir, FileType filter) {
vector<string> Filer::listDir(const string& drc, FileType filter) {
vector<string> entries;
#ifdef _WIN32
WIN32_FIND_DATAW data;
HANDLE hFind = FindFirstFileW(stow(appendDsep(dir) + "*").c_str(), &data);
HANDLE hFind = FindFirstFileW(stow(appendDsep(drc) + "*").c_str(), &data);
if (hFind == INVALID_HANDLE_VALUE)
return entries;

Expand All @@ -389,7 +392,7 @@ vector<string> Filer::listDir(const string& dir, FileType filter) {
} while (FindNextFileW(hFind, &data));
FindClose(hFind);
#else
DIR* directory = opendir(dir.c_str());
DIR* directory = opendir(drc.c_str());
if (!directory)
return entries;

Expand All @@ -403,12 +406,12 @@ vector<string> Filer::listDir(const string& dir, FileType filter) {
return entries;
}

vector<string> Filer::listDirRecursively(string dir) {
dir = appendDsep(dir);
vector<string> Filer::listDirRecursively(string drc) {
drc = appendDsep(drc);
vector<string> entries;
#ifdef _WIN32
WIN32_FIND_DATAW data;
HANDLE hFind = FindFirstFileW(stow(dir + "*").c_str(), &data);
HANDLE hFind = FindFirstFileW(stow(drc + "*").c_str(), &data);
if (hFind == INVALID_HANDLE_VALUE)
return entries;

Expand All @@ -418,14 +421,14 @@ vector<string> Filer::listDirRecursively(string dir) {

string name = wtos(data.cFileName);
if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // append subdirectoy's files to entries
vector<string> newEs = listDirRecursively(dir + name);
vector<string> newEs = listDirRecursively(drc + name);
entries.insert(entries.end(), newEs.begin(), newEs.end());
} else
entries.push_back(dir + name);
entries.push_back(drc + name);
} while (FindNextFileW(hFind, &data));
FindClose(hFind);
#else
DIR* directory = opendir(dir.c_str());
DIR* directory = opendir(drc.c_str());
if (!directory)
return entries;

Expand All @@ -434,10 +437,10 @@ vector<string> Filer::listDirRecursively(string dir) {
continue;

if (data->d_type == DT_DIR) { // append subdirectoy's files to entries
vector<string> newEs = listDirRecursively(dir + data->d_name);
vector<string> newEs = listDirRecursively(drc + data->d_name);
entries.insert(entries.end(), newEs.begin(), newEs.end());
} else
entries.push_back(dir + data->d_name);
entries.push_back(drc + data->d_name);
}
closedir(directory);
#endif
Expand Down Expand Up @@ -483,7 +486,7 @@ vector<char> Filer::listDrives() {
vector<char> letters;
DWORD drives = GetLogicalDrives();

for (char i=0; i<26; i++)
for (char i = 0; i < 26; i++)
if (drives & (1 << i))
letters.push_back('A'+i);
return letters;
Expand Down Expand Up @@ -519,8 +522,8 @@ string Filer::findFont(const string& font) {
if (isAbsolute(font) && isFont(font)) // check if font refers to a file
return font;

for (const string& dir : dirFonts) // check font directories
for (string& it : listDirRecursively(dir))
for (const string& drc : dirFonts) // check font directories
for (string& it : listDirRecursively(drc))
if (strcmpCI(hasExt(it) ? delExt(filename(it)) : filename(it), font) && isFont(it))
return it;
return ""; // nothing found
Expand Down
4 changes: 2 additions & 2 deletions src/engine/filer.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class Filer {
static bool readTextFile(const string& file, vector<string>& lines, bool printMessage=true);
static bool writeTextFile(const string& file, const vector<string>& lines);
static bool mkDir(const string& path);
static vector<string> listDir(const string& dir, FileType filter=FTYPE_ANY);
static vector<string> listDirRecursively(string dir);
static vector<string> listDir(const string& drc, FileType filter=FTYPE_ANY);
static vector<string> listDirRecursively(string drc);
static FileType fileType(const string& path);
static bool isPicture(const string& file);
static bool isFont(const string& file);
Expand Down
17 changes: 11 additions & 6 deletions src/engine/inputSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void InputSys::Controller::close() {
InputSys::InputSys() :
bindings(Filer::getBindings())
{
for (int i=0; i<SDL_NumJoysticks(); i++)
for (int i = 0; i < SDL_NumJoysticks(); i++)
addController(i);
}

Expand Down Expand Up @@ -203,7 +203,7 @@ bool InputSys::isPressedG(SDL_GameControllerButton gbutton) const {
bool InputSys::isPressedH(uint8 jhat, uint8 val) const {
for (const Controller& it : controllers)
if (!it.gamepad)
for (int i=0; i!=SDL_JoystickNumHats(it.joystick); i++)
for (int i = 0; i < SDL_JoystickNumHats(it.joystick); i++)
if (jhat == i && SDL_JoystickGetHat(it.joystick, i) == val)
return true;
return false;
Expand Down Expand Up @@ -234,9 +234,14 @@ bool InputSys::isPressedM(uint8 mbutton) {
}

vec2i InputSys::mousePos() {
vec2i pos;
SDL_GetMouseState(&pos.x, &pos.y);
return pos;
int px, py;
SDL_GetMouseState(&px, &py);
return vec2i(px, py);
}

void InputSys::resetBindings() {
for (sizt i = 0; i < bindings.size(); i++)
bindings[i].setDefaultSelf(static_cast<Binding::Type>(i));
}

void InputSys::addController(int id) {
Expand All @@ -246,7 +251,7 @@ void InputSys::addController(int id) {
}

void InputSys::removeController(int id) {
for (vector<Controller>::iterator it=controllers.begin(); it!=controllers.end(); it++)
for (vector<Controller>::iterator it = controllers.begin(); it != controllers.end(); it++)
if (it->index == id) {
it->close();
controllers.erase(it);
Expand Down
1 change: 1 addition & 0 deletions src/engine/inputSys.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class InputSys {
const vec2i& getMouseMove() const { return mouseMove; }
Binding& getBinding(Binding::Type type) { return bindings[static_cast<sizt>(type)]; }
const vector<Binding>& getBindings() const { return bindings; }
void resetBindings();
void addController(int id);
void removeController(int id);

Expand Down
Loading

0 comments on commit a64d328

Please sign in to comment.