diff --git a/src/sdldrv.cpp b/src/sdldrv.cpp index 2b04aef79..e30a033ab 100755 --- a/src/sdldrv.cpp +++ b/src/sdldrv.cpp @@ -38,6 +38,7 @@ #include "projectile_manager.hpp" #include "file_manager.hpp" #include "gui/menu_manager.hpp" +#include "widget_manager.hpp" #include "player.hpp" #include "gui/font.hpp" #include "user_config.hpp" @@ -205,6 +206,10 @@ void setVideoMode(bool resetTextures) //Reinit fonts delete_fonts(); init_fonts(); + + //TODO: this function probably will get deleted in the future; if + //so, the widget_manager.hpp include has no other reason to be here. + widget_manager->reloadFonts(); } #endif } diff --git a/src/widget.cpp b/src/widget.cpp index 414e0e77e..136cb33d6 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -501,6 +501,10 @@ void Widget::setFont( const WidgetFont FONT ) m_font = font_race; break; }; + + //TODO: the curr_widget_font variable exists only for a bug around; after + //some restructuration, it should be fine to remove this. + m_curr_widget_font = FONT; } /** Initialize a display list containing a rectangle that can have rounded diff --git a/src/widget.hpp b/src/widget.hpp index 6dcfc7f5d..a7cbabe91 100644 --- a/src/widget.hpp +++ b/src/widget.hpp @@ -149,6 +149,10 @@ class Widget std::string m_text; WidgetFontSize m_text_size; + //TODO: This variable exists only to go around a bug; should be removed + //after better restructuration. + WidgetFont m_curr_widget_font; + static const int MAX_SCROLL; bool m_enable_scroll; float m_scroll_pos_x; diff --git a/src/widget_manager.cpp b/src/widget_manager.cpp index 813954b15..c64c1d84f 100644 --- a/src/widget_manager.cpp +++ b/src/widget_manager.cpp @@ -1658,3 +1658,19 @@ int WidgetManager::findBottomWidget(const int START_WGT) const return closest_wgt; } +/** reloadFonts() sets the pointers to the fonts of the guis + * to their choosen fonts; it's useful in cases where you + * free the font's memory (which makes the pointers invalid), + * then reload the fonts, like it happens when you change resolution + * on the Macs or Windows. + */ +void WidgetManager::reloadFonts() +{ + const int NUM_WIDGETS = (int)m_widgets.size(); + for( int i = 0; i < NUM_WIDGETS; ++i ) + { + m_widgets[i].widget->setFont( + m_widgets[i].widget->m_curr_widget_font ); + } +} + diff --git a/src/widget_manager.hpp b/src/widget_manager.hpp index e2ac219aa..c611568ce 100644 --- a/src/widget_manager.hpp +++ b/src/widget_manager.hpp @@ -232,6 +232,7 @@ public: void setWgtFont( const int TOKEN, const WidgetFont FONT); void showWgtText( const int TOKEN ); void hideWgtText( const int TOKEN ); + void reloadFonts(); //FIXME: change to enableWgtScrolling, since it enables or disables //FIXME: maybe all that enabling the scrolling should do, is to allow