updates to Runtime::locate(), FontManager, and GUI loading
This commit is contained in:
parent
1effe27afb
commit
bdd28ab362
@ -1,22 +1,39 @@
|
||||
#include "FontManager.h"
|
||||
#include "jes/Runtime.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace jes
|
||||
{
|
||||
FontManager::FontManager()
|
||||
bool FontManager::load()
|
||||
{
|
||||
if (FT_Init_FreeType(&m_ft) != 0)
|
||||
{
|
||||
std::cerr << "Error initializing FreeType" << std::endl;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Load failsafe font */
|
||||
m_mono_font = load_font("FreeMono", 20);
|
||||
|
||||
if (m_mono_font.is_null())
|
||||
{
|
||||
std::cerr << "Error loading FreeMono font" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
FontRef FontManager::load_font(const char * fname, size_t size)
|
||||
{
|
||||
FontRef font = new Font();
|
||||
if (!font->load(m_ft, fname, size))
|
||||
PathRef font_path = Runtime::locate(Runtime::FONT, fname);
|
||||
if (font_path.is_null())
|
||||
return NULL;
|
||||
|
||||
FontRef font = new Font();
|
||||
if (!font->load(m_ft, font_path->to_s().c_str(), size))
|
||||
return NULL;
|
||||
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,11 @@ namespace jes
|
||||
class FontManager
|
||||
{
|
||||
public:
|
||||
FontManager();
|
||||
bool load();
|
||||
FontRef load_font(const char * fname, size_t size);
|
||||
protected:
|
||||
FT_Library m_ft;
|
||||
FontRef m_mono_font;
|
||||
};
|
||||
|
||||
typedef Ref<FontManager> FontManagerRef;
|
||||
|
@ -7,12 +7,12 @@
|
||||
|
||||
namespace jes
|
||||
{
|
||||
GUI::GUI()
|
||||
bool GUI::load()
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_VIDEO))
|
||||
{
|
||||
std::cerr << "Failed to initialize SDL!" << std::endl;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
atexit(SDL_Quit);
|
||||
@ -27,7 +27,7 @@ namespace jes
|
||||
{
|
||||
std::cerr << "Failed to create window!" << std::endl;
|
||||
SDL_Quit();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
(void)SDL_GL_CreateContext(m_window);
|
||||
@ -36,17 +36,24 @@ namespace jes
|
||||
{
|
||||
std::cerr << "Failed to gl3wInit()" << std::endl;
|
||||
SDL_Quit();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!gl3wIsSupported(3, 0))
|
||||
{
|
||||
std::cerr << "OpenGL 3.0 is not supported!" << std::endl;
|
||||
SDL_Quit();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
glClearColor (0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
m_font_manager = new FontManager();
|
||||
|
||||
if (!m_font_manager->load())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int GUI::run()
|
||||
|
@ -3,16 +3,18 @@
|
||||
|
||||
#include "jes/Ref.h"
|
||||
#include <SDL.h>
|
||||
#include "FontManager.h"
|
||||
|
||||
namespace jes
|
||||
{
|
||||
class GUI
|
||||
{
|
||||
public:
|
||||
GUI();
|
||||
bool load();
|
||||
int run();
|
||||
protected:
|
||||
SDL_Window * m_window;
|
||||
FontManagerRef m_font_manager;
|
||||
};
|
||||
|
||||
typedef Ref<GUI> GUIRef;
|
||||
|
@ -7,6 +7,9 @@ using namespace std;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
jes::Core::instance.init(argv[0]);
|
||||
jes::GUIRef gui = new jes::GUI();
|
||||
if (!gui->load())
|
||||
return 2;
|
||||
return gui->run();
|
||||
}
|
||||
|
@ -18,21 +18,29 @@ namespace jes
|
||||
break;
|
||||
case Runtime::FONT:
|
||||
{
|
||||
static const char * extensions[] = {
|
||||
"ttf",
|
||||
};
|
||||
std::vector<std::string> dirents = path->dir_entries();
|
||||
for (auto de : dirents)
|
||||
{
|
||||
PathRef test_path = path->join(de)->join(name);
|
||||
if (test_path->exists())
|
||||
return test_path;
|
||||
for (auto ext : extensions)
|
||||
{
|
||||
rv = test_path;
|
||||
break;
|
||||
test_path = test_path->ext(ext);
|
||||
if (test_path->exists())
|
||||
return test_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (rv->exists())
|
||||
|
||||
if ((!rv.is_null()) && (rv->exists()))
|
||||
return rv;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user