Allow changing font size live
This commit is contained in:
parent
d7a66f72e8
commit
660a35a468
@ -36,6 +36,8 @@
|
|||||||
#include "GlyphLayout.h"
|
#include "GlyphLayout.h"
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
#include "../lib/irrlicht/source/Irrlicht/CGUISpriteBank.h"
|
||||||
|
|
||||||
#ifndef SERVER_ONLY
|
#ifndef SERVER_ONLY
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
@ -51,11 +53,7 @@ extern "C"
|
|||||||
*/
|
*/
|
||||||
FontWithFace::FontWithFace(const std::string& name)
|
FontWithFace::FontWithFace(const std::string& name)
|
||||||
{
|
{
|
||||||
m_spritebank = irr_driver->getGUI()->addEmptySpriteBank(name.c_str());
|
m_spritebank = new irr::gui::CGUISpriteBank(irr_driver->getGUI());
|
||||||
|
|
||||||
assert(m_spritebank != NULL);
|
|
||||||
m_spritebank->grab();
|
|
||||||
|
|
||||||
m_fallback_font = NULL;
|
m_fallback_font = NULL;
|
||||||
m_fallback_font_scale = 1.0f;
|
m_fallback_font_scale = 1.0f;
|
||||||
m_glyph_max_height = 0;
|
m_glyph_max_height = 0;
|
||||||
@ -63,6 +61,7 @@ FontWithFace::FontWithFace(const std::string& name)
|
|||||||
m_face_dpi = 40;
|
m_face_dpi = 40;
|
||||||
m_inverse_shaping = 1.0f;
|
m_inverse_shaping = 1.0f;
|
||||||
} // FontWithFace
|
} // FontWithFace
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** Destructor. Clears the glyph page and sprite bank.
|
/** Destructor. Clears the glyph page and sprite bank.
|
||||||
*/
|
*/
|
||||||
@ -74,7 +73,6 @@ FontWithFace::~FontWithFace()
|
|||||||
static_cast<STKTexture*>(m_spritebank->getTexture(i)));
|
static_cast<STKTexture*>(m_spritebank->getTexture(i)));
|
||||||
}
|
}
|
||||||
m_spritebank->drop();
|
m_spritebank->drop();
|
||||||
m_spritebank = NULL;
|
|
||||||
|
|
||||||
delete m_face_ttf;
|
delete m_face_ttf;
|
||||||
} // ~FontWithFace
|
} // ~FontWithFace
|
||||||
|
@ -1038,7 +1038,7 @@ namespace GUIEngine
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
void init(IrrlichtDevice* device_a, IVideoDriver* driver_a,
|
void init(IrrlichtDevice* device_a, IVideoDriver* driver_a,
|
||||||
AbstractStateManager* state_manager )
|
AbstractStateManager* state_manager, bool loading)
|
||||||
{
|
{
|
||||||
g_env = device_a->getGUIEnvironment();
|
g_env = device_a->getGUIEnvironment();
|
||||||
g_device = device_a;
|
g_device = device_a;
|
||||||
@ -1117,10 +1117,13 @@ namespace GUIEngine
|
|||||||
// set event receiver
|
// set event receiver
|
||||||
g_device->setEventReceiver(EventHandler::get());
|
g_device->setEventReceiver(EventHandler::get());
|
||||||
|
|
||||||
|
if (loading)
|
||||||
|
{
|
||||||
g_device->getVideoDriver()
|
g_device->getVideoDriver()
|
||||||
->beginScene(true, true, video::SColor(255,100,101,140));
|
->beginScene(true, true, video::SColor(255,100,101,140));
|
||||||
renderLoading();
|
renderLoading();
|
||||||
g_device->getVideoDriver()->endScene();
|
g_device->getVideoDriver()->endScene();
|
||||||
|
}
|
||||||
} // init
|
} // init
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
@ -107,8 +107,10 @@ namespace GUIEngine
|
|||||||
* \param device An initialized irrlicht device object
|
* \param device An initialized irrlicht device object
|
||||||
* \param driver An initialized irrlicht driver object
|
* \param driver An initialized irrlicht driver object
|
||||||
* \param state_manager An instance of a class derived from abstract base AbstractStateManager
|
* \param state_manager An instance of a class derived from abstract base AbstractStateManager
|
||||||
|
* \param loading if it's (re-)loading the GUIEngine
|
||||||
*/
|
*/
|
||||||
void init(irr::IrrlichtDevice* device, irr::video::IVideoDriver* driver, AbstractStateManager* state_manager);
|
void init(irr::IrrlichtDevice* device, irr::video::IVideoDriver* driver,
|
||||||
|
AbstractStateManager* state_manager, bool loading = true);
|
||||||
|
|
||||||
void cleanUp();
|
void cleanUp();
|
||||||
|
|
||||||
|
@ -212,7 +212,6 @@ void OptionsScreenUI::init()
|
|||||||
GUIEngine::SpinnerWidget* font_size = getWidget<GUIEngine::SpinnerWidget>("font_size");
|
GUIEngine::SpinnerWidget* font_size = getWidget<GUIEngine::SpinnerWidget>("font_size");
|
||||||
assert( font_size != NULL );
|
assert( font_size != NULL );
|
||||||
|
|
||||||
m_prev_font_size = UserConfigParams::m_font_size;
|
|
||||||
int size_int = (int)roundf(UserConfigParams::m_font_size);
|
int size_int = (int)roundf(UserConfigParams::m_font_size);
|
||||||
if (size_int < 0 || size_int > 6)
|
if (size_int < 0 || size_int > 6)
|
||||||
size_int = 3;
|
size_int = 3;
|
||||||
@ -333,6 +332,22 @@ void OptionsScreenUI::eventCallback(Widget* widget, const std::string& name, con
|
|||||||
GUIEngine::SpinnerWidget* font_size = getWidget<GUIEngine::SpinnerWidget>("font_size");
|
GUIEngine::SpinnerWidget* font_size = getWidget<GUIEngine::SpinnerWidget>("font_size");
|
||||||
assert( font_size != NULL );
|
assert( font_size != NULL );
|
||||||
UserConfigParams::m_font_size = font_size->getValue();
|
UserConfigParams::m_font_size = font_size->getValue();
|
||||||
|
GUIEngine::clear();
|
||||||
|
GUIEngine::cleanUp();
|
||||||
|
GUIEngine::clearScreenCache();
|
||||||
|
delete font_manager;
|
||||||
|
font_manager = new FontManager();
|
||||||
|
font_manager->loadFonts();
|
||||||
|
GUIEngine::init(irr_driver->getDevice(), irr_driver->getVideoDriver(),
|
||||||
|
StateManager::get(), false/*loading*/);
|
||||||
|
Screen* screen_list[] =
|
||||||
|
{
|
||||||
|
MainMenuScreen::getInstance(),
|
||||||
|
OptionsScreenUI::getInstance(),
|
||||||
|
nullptr
|
||||||
|
};
|
||||||
|
GUIEngine::switchToScreen(MainMenuScreen::getInstance());
|
||||||
|
StateManager::get()->resetAndSetStack(screen_list);
|
||||||
}
|
}
|
||||||
else if (name == "split_screen_horizontally")
|
else if (name == "split_screen_horizontally")
|
||||||
{
|
{
|
||||||
@ -354,11 +369,6 @@ void OptionsScreenUI::eventCallback(Widget* widget, const std::string& name, con
|
|||||||
|
|
||||||
void OptionsScreenUI::tearDown()
|
void OptionsScreenUI::tearDown()
|
||||||
{
|
{
|
||||||
if (m_prev_font_size != UserConfigParams::m_font_size)
|
|
||||||
{
|
|
||||||
irr_driver->sameRestart();
|
|
||||||
}
|
|
||||||
|
|
||||||
Screen::tearDown();
|
Screen::tearDown();
|
||||||
// save changes when leaving screen
|
// save changes when leaving screen
|
||||||
user_config->saveConfig();
|
user_config->saveConfig();
|
||||||
|
@ -35,7 +35,6 @@ class OptionsScreenUI : public GUIEngine::Screen, public GUIEngine::ScreenSingle
|
|||||||
{
|
{
|
||||||
OptionsScreenUI();
|
OptionsScreenUI();
|
||||||
bool m_inited;
|
bool m_inited;
|
||||||
float m_prev_font_size;
|
|
||||||
|
|
||||||
std::map<core::stringw, std::string> m_skins;
|
std::map<core::stringw, std::string> m_skins;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user