Commit f773ae33 authored by PoroCYon's avatar PoroCYon Committed by Gargaj
Browse files

slightly fix font selection on Linux (#50)

parent 62b85d9e
...@@ -14,7 +14,7 @@ The tool was originally conceived and implemented after the Revision 2014 demosc ...@@ -14,7 +14,7 @@ The tool was originally conceived and implemented after the Revision 2014 demosc
- F2: toggle texture preview - F2: toggle texture preview
- F5 or Ctrl-R: recompile shader - F5 or Ctrl-R: recompile shader
- F11 or Ctrl/Cmd-f: hide shader overlay - F11 or Ctrl/Cmd-f: hide shader overlay
- Alt-F4: exbobolate your planet - Alt-F4 or Shift+Escape: exbobolate your planet
## Configuration ## Configuration
Create a ```config.json``` with e.g. the following contents: (all fields are optional) Create a ```config.json``` with e.g. the following contents: (all fields are optional)
......
...@@ -143,19 +143,27 @@ int main(int argc, char *argv[]) ...@@ -143,19 +143,27 @@ int main(int argc, char *argv[])
editorOptions.sFontPath = "/Library/Fonts/Courier New.ttf"; editorOptions.sFontPath = "/Library/Fonts/Courier New.ttf";
#else #else
// Linux case // Linux case
const std::string fontPaths[2] = { // TODO: use fonts.conf(5) or X resources or something like that
const char* fontPaths[] = {
"/usr/share/fonts/TTF/DejaVuSansMono.ttf",
"/usr/share/fonts/TTF/FreeMono.ttf",
"/usr/share/fonts/TTF/LiberationMono-Regular.ttf",
"/usr/share/fonts/TTF/VeraMono.ttf",
"/usr/share/fonts/corefonts/cour.ttf", "/usr/share/fonts/corefonts/cour.ttf",
"/usr/share/fonts/truetype/msttcorefonts/cour.ttf" "/usr/share/fonts/truetype/msttcorefonts/cour.ttf",
NULL
}; };
editorOptions.sFontPath = ""; editorOptions.sFontPath = "";
int step = 0; for (int i = 0; fontPaths[i]; ++i)
while( step < 2 && editorOptions.sFontPath.size() == 0 ) { {
const std::string & current = fontPaths[step++]; if (access(fontPaths[i], R_OK) != -1)
{
if (access(current.c_str(), R_OK) != -1) { editorOptions.sFontPath = fontPaths[i];
editorOptions.sFontPath = current; break;
} }
} }
// aiee - no font found, but don't report yet, it might still get changed
// though config.json
#endif #endif
editorOptions.nOpacity = 0xC0; editorOptions.nOpacity = 0xC0;
editorOptions.bUseSpacesForTabs = true; editorOptions.bUseSpacesForTabs = true;
...@@ -199,7 +207,24 @@ int main(int argc, char *argv[]) ...@@ -199,7 +207,24 @@ int main(int argc, char *argv[])
if (options.get<jsonxx::Object>("font").has<jsonxx::Number>("size")) if (options.get<jsonxx::Object>("font").has<jsonxx::Number>("size"))
editorOptions.nFontSize = options.get<jsonxx::Object>("font").get<jsonxx::Number>("size"); editorOptions.nFontSize = options.get<jsonxx::Object>("font").get<jsonxx::Number>("size");
if (options.get<jsonxx::Object>("font").has<jsonxx::String>("file")) if (options.get<jsonxx::Object>("font").has<jsonxx::String>("file"))
editorOptions.sFontPath = options.get<jsonxx::Object>("font").get<jsonxx::String>("file"); {
std::string fontpath = options.get<jsonxx::Object>("font").get<jsonxx::String>("file");
// TODO: port this to other platforms
#if !defined(_WIN32) && !defined(__APPLE__)
if (access(fontpath.c_str(), R_OK) != -1)
editorOptions.sFontPath = fontpath;
else
{
printf("Couldn't open the font file '%s'.\n", fontpath.c_str());
return -1;
}
#endif
}
else if (!editorOptions.sFontPath.size()) // coudn't find a default font
{
printf("Couldn't find any of the default fonts. Please specify one in config.json\n");
return -1;
}
} }
if (options.has<jsonxx::Object>("gui")) if (options.has<jsonxx::Object>("gui"))
{ {
...@@ -230,7 +255,7 @@ int main(int argc, char *argv[]) ...@@ -230,7 +255,7 @@ int main(int argc, char *argv[])
} }
Capture::LoadSettings( options ); Capture::LoadSettings( options );
} }
if ( !Capture::Open( settings ) ) if (!Capture::Open(settings))
{ {
printf("Initializing capture system failed!\n"); printf("Initializing capture system failed!\n");
return 0; return 0;
...@@ -256,6 +281,9 @@ int main(int argc, char *argv[]) ...@@ -256,6 +281,9 @@ int main(int argc, char *argv[])
printf("Last shader works fine.\n"); printf("Last shader works fine.\n");
shaderInitSuccessful = true; shaderInitSuccessful = true;
} }
else {
printf("Shader error:\n%s\n", szError);
}
} }
if (!shaderInitSuccessful) if (!shaderInitSuccessful)
{ {
......
#include <cstdio>
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#endif #endif
...@@ -411,7 +414,7 @@ namespace Renderer ...@@ -411,7 +414,7 @@ namespace Renderer
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{ {
if (action == GLFW_PRESS || action == GLFW_REPEAT) { if (action == GLFW_PRESS || action == GLFW_REPEAT) {
if ((key==GLFW_KEY_F4) && (mods&GLFW_MOD_ALT)) { if ((key==GLFW_KEY_F4 && (mods&GLFW_MOD_ALT)) || (key==GLFW_KEY_ESCAPE&&(mods&GLFW_MOD_SHIFT))) {
run = false; run = false;
} }
int sciKey = 0; int sciKey = 0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment