Skip to content

Commit

Permalink
fancy stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
karwler committed Apr 26, 2016
1 parent 62f041b commit 90e59be
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 29 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ $(TARGET): bindir $(OBJECTS)
mkdir -p $(TDIR)
$(CXX) $(LFLAGS) -o $(TDIR)/$(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
cp -r data $(TDIR)
cp rsc/vertiread.desktop $(TDIR)
@echo "executable '"$(TARGET)"' has been written to '"$(TDIR)"'"

bin/audioSys.o: src/engine/audioSys.cpp
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ The makefile is only made for Linux.
##Linux
For simple build just use the makefile.
It's currently configured for the g++ compiler.
If you want to use clang++ or set a specific architecture, just look in the top section of the makefile.
If you want to use clang++ or set a specific architecture, just look in the top section of the makefile.
There’s also a pre-made launcher, which is copied to the build directory after compilation.
You just need to add the executable’s and icon’s path to it.

All dependencies need to be installed manually:
sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libboost-filesystem1.55-dev
Expand Down
26 changes: 16 additions & 10 deletions VertiRead.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ CONFIG -= app_bundle qt
win32:TARGET = VertiRead
unix:TARGET = vertiread

DESTDIR = $$OUT_PWD/build/
OBJECTS_DIR = $$OUT_PWD/bin/
macx:DESTDIR = $$OUT_PWD/VertiRead.app/Contents/MacOS/
else:DESTDIR = $$OUT_PWD/build/

# copy data dir and dependencies
win32 {
Expand All @@ -24,16 +25,21 @@ win32 {
}
LIB_WIN ~= s,/,\\,g
copydll.commands = $$quote(cmd /c copy $$LIB_WIN\\*.dll $${DEST_WIN})
copydata.commands = $$quote(cmd /c xcopy /e/i/y $$PWD_WIN\\data $$DEST_WIN\\data)
QMAKE_EXTRA_TARGETS += copydll
POST_TARGETDEPS += copydll
postbuild.commands = $$quote(cmd /c copy $$LIB_WIN\\*.dll $${DEST_WIN}) && \
$$quote(cmd /c xcopy /e/i/y $$PWD_WIN\\data $$DEST_WIN\\data)
}
unix {
copydata.commands = cp -r $$PWD/data $$DESTDIR
macx {
postbuild.commands = mkdir -p $$DESTDIR/../Resources && \
cp $$PWD/rsc/Info.plist $$DESTDIR/../ && \
cp $$PWD/rsc/icon.icns $$DESTDIR/../Resources/ && \
cp -r $$PWD/data $$DESTDIR
}
linux {
postbuild.commands = cp $$PWD/rsc/vertiread.desktop $$DESTDIR && \
cp -r $$PWD/data $$DESTDIR
}
QMAKE_EXTRA_TARGETS += copydata
POST_TARGETDEPS += copydata
QMAKE_EXTRA_TARGETS += postbuild
POST_TARGETDEPS += postbuild

# includepaths
INCLUDEPATH += $$PWD/src/
Expand Down Expand Up @@ -112,4 +118,4 @@ HEADERS += src/engine/audioSys.h \
src/prog/library.h \
src/utils/capturers.h

win32:RC_FILE = src/resource.rc
win32:RC_FILE = rsc/resource.rc
4 changes: 2 additions & 2 deletions VertiRead.vcxproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
Expand Down Expand Up @@ -60,7 +60,7 @@
<ClInclude Include="src\utils\utils.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="src\resource.rc" />
<ResourceCompile Include="rsc\resource.rc" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{1E4D1B77-2222-4E3E-AE14-6AE698AF002F}</ProjectGuid>
Expand Down
4 changes: 2 additions & 2 deletions VertiRead.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source">
Expand Down Expand Up @@ -131,7 +131,7 @@
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="src\resource.rc">
<ResourceCompile Include="rsc\resource.rc">
<Filter>Source</Filter>
</ResourceCompile>
</ItemGroup>
Expand Down
Binary file added data/textures/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions rsc/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>VertiRead</string>
<key>CFBundleExecutable</key>
<string>vertiread</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>CFBundleIdentifier</key>
<string>com.nocompany.vertiread</string>
<key>CFBundleName</key>
<string>VertiRead</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleVersion</key>
<string>1.0</string>
</dict>
</plist>
File renamed without changes.
Binary file added rsc/resource.rc
Binary file not shown.
13 changes: 13 additions & 0 deletions rsc/vertiread.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Desktop Entry]
Version=1.0
Name=VertiRead
Exec=
Icon=
Comment=Read Mangas and listen to music
GenericName=Manga Reader
Keywords=Manga;Music;Reader
Categories=Utility
Type=Application
Terminal=false
X-MultipleArgs=false
StartupNotify=true
1 change: 1 addition & 0 deletions src/engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void Engine::Run() {
winSys->SetWindow();
Filer::CheckDirectories();
scene = new Scene; // initializes program and library
winSys->SetIcon(scene->getLibrary()->getTexPath("icon"));

// initialize scene and timer
scene->getProgram()->Event_OpenBookList();
Expand Down
52 changes: 48 additions & 4 deletions src/engine/filer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,11 @@ void Filer::SaveSettings(const ControlsSettings& sets) {
WriteTextFile(dirSets() + "controls.ini", lines);
}

#ifdef __APPLE__
string Filer::execDir(bool raw) {
#else
string Filer::execDir() {
#endif
const int MAX_LEN = 4096;
fs::path path;
#ifdef _WIN32
Expand All @@ -275,6 +279,14 @@ string Filer::execDir() {
path = buffer;
else
path = fs::initial_path().string() + "/" + World::args[0];

if (!raw) {
string test = path.string();
int pos = findString(test, ".app/"); // if running in a package
for (int i=pos; i>=0; i--)
if (test[i] == '/')
return test.substr(0, i+1);
}
#else
char buffer[MAX_LEN];
int len = readlink("/proc/self/exe", buffer, sizeof(buffer)-1);
Expand All @@ -297,23 +309,55 @@ string Filer::dirPlist() {
}

string Filer::dirSets() {
#ifdef __APPLE__
return execDir(true) + "settings/";
#else
return execDir() + "settings" + dsep;
#endif
}

string Filer::dirSnds() {
#ifdef __APPLE__
return execDir(true) + "data/sounds/";
#else
return execDir() + "data"+dsep+"sounds"+dsep;
#endif
}

string Filer::dirTexs() {
#ifdef __APPLE__
return execDir(true) + "data/textures/";
#else
return execDir() + "data"+dsep+"textures"+dsep;
#endif
}

string Filer::dirFonts() {
vector<string> Filer::dirFonts() {
#ifdef _WIN32
return string(getenv("SystemDrive")) + "\\Windows\\Fonts\\";
return {string(getenv("SystemDrive")) + "\\Windows\\Fonts\\"};
#elif __APPLE__
return "/Library/Fonts/";
return {string(getenv("HOME"))+"/Library/Fonts/", "/Library/Fonts/", "/System/Library/Fonts/", "/Network/Library/Fonts/"};
#else
return "/usr/share/fonts/truetype/msttcorefonts/";
return {"/usr/share/fonts/", "/usr/share/fonts/truetype/msttcorefonts/"};
#endif
}

bool Filer::findFont(string font, string* dir) {
if (fs::path(font).is_absolute()) { // check fontpath first
if (!fs::is_regular_file(font))
return false;

if (dir)
*dir = fs::path(font).parent_path().string() +dsep;
return true;
}

vector<string> paths = dirFonts(); // check global font directories
for (string& pt : paths)
if (fs::is_regular_file(pt + font)) {
if (dir)
*dir = pt;
return true;
}
return false;
}
8 changes: 7 additions & 1 deletion src/engine/filer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@ class Filer {
static ControlsSettings LoadControlsSettings();
static void SaveSettings(const ControlsSettings& sets);

#ifdef __APPLE__
static string execDir(bool raw=false);
#else
static string execDir();
#endif
static string dirLib();
static string dirPlist();
static string dirSets();
static string dirSnds();
static string dirTexs();
static string dirFonts();

static vector<string> dirFonts();
static bool findFont(string font, string *dir=nullptr);
};
13 changes: 8 additions & 5 deletions src/engine/windowSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ void WindowSys::SetWindow() {
if (!window)
throw Exception("couldn't create window" + string(SDL_GetError()), 3);

SDL_Surface* icon = IMG_Load(string(Filer::dirTexs()+"icon.ico").c_str());
if (icon) {
SDL_SetWindowIcon(window, icon);
SDL_FreeSurface(icon);
}
CreateRenderer();
}

Expand All @@ -50,6 +45,14 @@ void WindowSys::DestroyWindow() {
SDL_DestroyWindow(window);
}

void WindowSys::SetIcon(string file) {
SDL_Surface* icon = IMG_Load(file.c_str());
if (icon) {
SDL_SetWindowIcon(window, icon);
SDL_FreeSurface(icon);
}
}

void WindowSys::DrawObjects(vector<Object*> objects) {
SDL_SetRenderDrawColor(renderer, sets.colors[EColor::background].x, sets.colors[EColor::background].y, sets.colors[EColor::background].z, sets.colors[EColor::background].a);
SDL_RenderClear(renderer);
Expand Down
1 change: 1 addition & 0 deletions src/engine/windowSys.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class WindowSys {

void SetWindow();
void DestroyWindow();
void SetIcon(string file);
void DrawObjects(vector<Object*> objects);

SDL_Renderer* Renderer() const;
Expand Down
Binary file removed src/resource.rc
Binary file not shown.
7 changes: 4 additions & 3 deletions src/utils/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,15 @@ VideoSettings::VideoSettings(bool VS, bool MAX, bool FSC, vec2i RES, string FNT,
resolution(RES),
renderer(RNDR)
{
string tempFont = fs::path(FNT).is_absolute() ? FNT : Filer::dirFonts() + FNT;
font = fs::is_regular_file(tempFont) ? FNT : "Arial.ttf";
font = Filer::findFont(FNT) ? FNT : "Arial.ttf";

SetDefaultColors();
}

string VideoSettings::FontPath() const {
return fs::path(font).is_absolute() ? font : Filer::dirFonts() + font;
string dir;
Filer::findFont(font, &dir);
return dir+font;
}

void VideoSettings::SetDefaultColors() {
Expand Down
15 changes: 14 additions & 1 deletion src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,25 @@ bool isNumber(string str) {
}

int findChar(string str, char c) {
for (uint i = 0; i != str.size(); i++)
for (int i=0; i!=str.length(); i++)
if (str[i] == c)
return i;
return -1;
}

int findString(string str, string c) {
int check = 0;
for (int i=0; i!=str.length(); i++) {
if (str[i] == c[check]) {
if (++check == c.length())
return i-c.length();
}
else
check = 0;
}
return -1;
}

vector<string> getWords(string line, bool skipCommas) {
vector<string> words;
string word;
Expand Down
1 change: 1 addition & 0 deletions src/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ using vec4i = kvec4<int>;
// files and strings
bool isNumber(string str);
int findChar(string str, char c);
int findString(string str, string c);
vector<string> getWords(string line, bool skipCommas=false);
int splitIniLine(string line, string* arg, string* val, string* key = nullptr);
fs::path removeExtension(fs::path path);
Expand Down

0 comments on commit 90e59be

Please sign in to comment.