Add two new title font presets

Fix #3577
This commit is contained in:
Maosen the Jellyfish
2020-08-13 23:09:15 +08:00
committed by GitHub
parent a8572a7582
commit f7bc0dfd90
6 changed files with 105 additions and 17 deletions

View File

@@ -710,6 +710,8 @@ namespace GUIEngine
ScalableFont *g_outline_font;
ScalableFont *g_large_font;
ScalableFont *g_title_font;
ScalableFont* g_small_title_font;
ScalableFont* g_tiny_title_font;
ScalableFont *g_small_font;
ScalableFont *g_digit_font;
@@ -723,6 +725,8 @@ namespace GUIEngine
int large_font_height;
int small_font_height;
int title_font_height;
int small_title_font_height;
int tiny_title_font_height;
#ifdef ANDROID
std::mutex m_gui_functions_mutex;
std::vector<std::function<void()> > m_gui_functions;
@@ -807,6 +811,16 @@ namespace GUIEngine
{
return Private::title_font_height;
} // getTitleFontHeight
// ------------------------------------------------------------------------
int getSmallTitleFontHeight()
{
return Private::small_title_font_height;
} // getTitleFontHeight
// ------------------------------------------------------------------------
int getTinyTitleFontHeight()
{
return Private::tiny_title_font_height;
} // getTitleFontHeight
// ------------------------------------------------------------------------
@@ -1001,6 +1015,18 @@ namespace GUIEngine
g_title_font->drop();
g_title_font = NULL;
}
if (g_small_title_font)
{
//delete g_small_title_font;
g_small_title_font->drop();
g_small_title_font = NULL;
}
if (g_tiny_title_font)
{
//delete g_tiny_title_font;
g_tiny_title_font->drop();
g_tiny_title_font = NULL;
}
if (g_small_font)
{
//delete g_small_font;
@@ -1129,8 +1155,18 @@ namespace GUIEngine
ScalableFont* sfont2 = new ScalableFont(bold);
g_title_font = sfont2;
ScalableFont* sfont3 = new ScalableFont(bold);
sfont3->setScale(0.8f);
g_small_title_font = sfont3;
ScalableFont* sfont4 = new ScalableFont(bold);
sfont4->setScale(0.6f);
g_tiny_title_font = sfont4;
Private::title_font_height =
g_title_font->getDimension( L"X" ).Height;
Private::small_title_font_height =
g_small_title_font->getDimension( L"X" ).Height;
Private::tiny_title_font_height =
g_tiny_title_font->getDimension( L"X" ).Height;
if (g_font != NULL) g_skin->setFont(g_font);
@@ -1185,6 +1221,10 @@ namespace GUIEngine
Private::small_font_height = g_small_font->getDimension( L"X" ).Height;
Private::title_font_height =
g_title_font->getDimension( L"X" ).Height;
Private::small_title_font_height =
g_small_title_font->getDimension( L"X" ).Height;
Private::tiny_title_font_height =
g_tiny_title_font->getDimension( L"X" ).Height;
StateManager::get()->onResize();
} // reloadForNewSize

View File

@@ -89,6 +89,8 @@ namespace GUIEngine
extern irr::gui::ScalableFont* g_outline_font;
extern irr::gui::ScalableFont* g_large_font;
extern irr::gui::ScalableFont* g_title_font;
extern irr::gui::ScalableFont* g_small_title_font;
extern irr::gui::ScalableFont* g_tiny_title_font;
extern irr::gui::ScalableFont* g_digit_font;
extern irr::IrrlichtDevice* g_device;
@@ -159,6 +161,16 @@ namespace GUIEngine
* \return the "title" font (it's bigger and orange, useful for headers/captions)
*/
inline irr::gui::ScalableFont* getTitleFont() { return Private::g_title_font; }
/**
* \return the "small title" font (it's bigger and orange, useful for sub headers/captions)
*/
inline irr::gui::ScalableFont* getSmallTitleFont() { return Private::g_small_title_font; }
/**
* \return the "tiny title" font (it's bigger and orange, useful for sub headers/captions)
*/
inline irr::gui::ScalableFont* getTinyTitleFont() { return Private::g_tiny_title_font; }
/**
* \return the currently shown screen, or NULL if none

View File

@@ -143,7 +143,7 @@ void Screen::parseScreenFileDiv(irr::io::IXMLReader* xml, PtrVector<Widget>& app
}
else if (wcscmp(L"bright", xml->getNodeName()) == 0)
{
append_to.push_back(new LabelWidget(false, true));
append_to.push_back(new LabelWidget(LabelWidget::BRIGHT));
}
else if (wcscmp(L"bubble", xml->getNodeName()) == 0)
{
@@ -151,7 +151,15 @@ void Screen::parseScreenFileDiv(irr::io::IXMLReader* xml, PtrVector<Widget>& app
}
else if (wcscmp(L"header", xml->getNodeName()) == 0)
{
append_to.push_back(new LabelWidget(true));
append_to.push_back(new LabelWidget(LabelWidget::TITLE));
}
else if (wcscmp(L"small-header", xml->getNodeName()) == 0)
{
append_to.push_back(new LabelWidget(LabelWidget::SMALL_TITLE));
}
else if (wcscmp(L"tiny-header", xml->getNodeName()) == 0)
{
append_to.push_back(new LabelWidget(LabelWidget::TINY_TITLE));
}
else if (wcscmp(L"spacer", xml->getNodeName()) == 0)
{

View File

@@ -35,14 +35,13 @@ using namespace irr;
// ----------------------------------------------------------------------------
LabelWidget::LabelWidget(bool title, bool bright) : Widget(WTYPE_LABEL)
LabelWidget::LabelWidget(LabelType type) : Widget(WTYPE_LABEL)
{
m_title_font = title;
m_type = type;
m_scroll_speed = 0;
m_scroll_offset = 0;
m_bright = bright;
if (m_bright)
if (m_type == BRIGHT)
{
m_has_color = true;
m_color = Skin::getColor("brighttext::neutral");
@@ -93,11 +92,21 @@ void LabelWidget::add()
irrwidget->setOverrideColor(m_color);
}
if (m_title_font)
if (m_type == TITLE)
{
irrwidget->setOverrideColor( video::SColor(255,255,255,255) );
irrwidget->setOverrideFont( GUIEngine::getTitleFont() );
}
else if (m_type == SMALL_TITLE)
{
irrwidget->setOverrideColor( video::SColor(255,255,255,255) );
irrwidget->setOverrideFont( GUIEngine::getSmallTitleFont() );
}
else if (m_type == TINY_TITLE)
{
irrwidget->setOverrideColor( video::SColor(255,255,255,255) );
irrwidget->setOverrideFont( GUIEngine::getTinyTitleFont() );
}
//irrwidget->setBackgroundColor( video::SColor(255,255,0,0) );
//irrwidget->setDrawBackground(true);
@@ -122,8 +131,15 @@ void LabelWidget::setText(const core::stringw& text, bool expandIfNeeded)
if (expandIfNeeded)
{
assert(m_element != NULL);
const int fwidth = (m_title_font ? GUIEngine::getTitleFont() : GUIEngine::getFont())
->getDimension(text.c_str()).Width;
int fwidth;
if(m_type == TITLE)
fwidth = GUIEngine::getTitleFont()->getDimension(text.c_str()).Width;
else if(m_type == SMALL_TITLE)
fwidth = GUIEngine::getSmallTitleFont()->getDimension(text.c_str()).Width;
else if(m_type == TINY_TITLE)
fwidth = GUIEngine::getTinyTitleFont()->getDimension(text.c_str()).Width;
else
fwidth = GUIEngine::getFont()->getDimension(text.c_str()).Width;
core::rect<s32> rect = m_element->getRelativePosition();
if (rect.getWidth() < fwidth)
@@ -189,7 +205,7 @@ void LabelWidget::setErrorColor()
void LabelWidget::setDefaultColor()
{
if (m_bright)
if (m_type == BRIGHT)
{
setColor(Skin::getColor("brighttext::neutral"));
}

View File

@@ -34,9 +34,23 @@ namespace GUIEngine
*/
class LabelWidget : public Widget
{
bool m_bright;
bool m_has_color;
public:
enum LabelType
{
NORMAL,
BRIGHT,
TITLE,
SMALL_TITLE,
TINY_TITLE,
COUNT
};
private:
LabelType m_type;
irr::video::SColor m_color;
bool m_has_color;
/** Scroll speed in characters/seconds (0 if no scrolling). */
float m_scroll_speed;
@@ -52,11 +66,9 @@ namespace GUIEngine
LEAK_CHECK()
/** Constructs the label widget. Parameter:
* \param title True if the special title font should be used.
* \param bright True if a bright color should be used
* \note \c title and \c bright are mutually exclusive
* \param type the text type of the label
*/
LabelWidget(bool title=false, bool bright=false);
LabelWidget(LabelType type = NORMAL);
virtual ~LabelWidget() {}

View File

@@ -238,7 +238,7 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent,
m_model_view->setRotateContinuously( 35.0f );
// ---- Kart name label
m_kart_name = new LabelWidget(false, true);
m_kart_name = new LabelWidget(LabelWidget::NORMAL);
m_kart_name->setText(props->getName(), false);
m_kart_name->m_properties[PROP_TEXT_ALIGN] = "center";
m_kart_name->m_properties[PROP_ID] =