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