Added em and rem units support.

Fixed a bug in tooltips.
This commit is contained in:
Martín Lucas Golini
2020-03-25 03:19:56 -03:00
parent 162a7efde9
commit a3afe7a8e2
16 changed files with 193 additions and 78 deletions

View File

@@ -42,7 +42,7 @@ class EE_API Text {
void setFont( Font* font );
void setCharacterSize( unsigned int size );
void setFontSize( unsigned int size );
void setStyle( Uint32 style );
@@ -151,10 +151,10 @@ class EE_API Text {
Vector2f position;
};
String mString; ///< String to display
Font* mFont; ///< FontTrueType used to display the string
unsigned int mCharacterSize; ///< Base size of characters, in pixels
unsigned int mRealCharacterSize;
String mString; ///< String to display
Font* mFont; ///< FontTrueType used to display the string
unsigned int mFontSize; ///< Base size of characters, in pixels
unsigned int mRealFontSize;
Uint32 mStyle; ///< Text style (see Style enum)
Color mFillColor; ///< Text fill color
Color mOutlineColor; ///< Text outline color

View File

@@ -31,7 +31,7 @@ class EE_API UITextView : public UIWidget {
Uint32 getCharacterSize() const;
UITextView* setCharacterSize( const Uint32& characterSize );
UITextView* setFontSize( const Uint32& characterSize );
const Uint32& getFontStyle() const;

View File

@@ -71,12 +71,17 @@ class EE_API UITheme : protected ResourceManager<UISkin> {
void setStyleSheet( const CSS::StyleSheet& styleSheet );
const Float& getDefaultFontSize() const;
void setDefaultFontSize( const Float& defaultFontSize );
protected:
std::string mName;
Uint32 mNameHash;
std::string mAbbr;
Graphics::TextureAtlas* mTextureAtlas;
Font* mDefaultFont;
Float mDefaultFontSize;
CSS::StyleSheet mStyleSheet;
void setTextureAtlas( Graphics::TextureAtlas* SG );

View File

@@ -18,6 +18,10 @@ class EE_API UIThemeManager : public ResourceManager<UITheme> {
Font* getDefaultFont() const;
UIThemeManager* setDefaultFontSize( const Float& fontSize );
const Float& getDefaultFontSize() const;
UIThemeManager* setDefaultTheme( UITheme* Theme );
UIThemeManager* setDefaultTheme( const std::string& Theme );
@@ -56,6 +60,7 @@ class EE_API UIThemeManager : public ResourceManager<UITheme> {
protected:
Font* mFont;
Float mFontSize;
UITheme* mThemeDefault;
bool mAutoApplyDefaultTheme;

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.11.1, 2020-03-13T05:08:12. -->
<!-- Written by QtCreator 4.11.1, 2020-03-25T03:19:26. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@@ -259,7 +259,7 @@ void Console::draw() {
Text& text = mTextCache[Pos];
text.setFont( mFontStyleConfig.Font );
text.setCharacterSize( mFontStyleConfig.CharacterSize );
text.setFontSize( mFontStyleConfig.CharacterSize );
text.setStyle( mFontStyleConfig.Style );
text.setOutlineThickness( mFontStyleConfig.OutlineThickness );
text.setOutlineColor( mFontStyleConfig.OutlineColor );
@@ -277,7 +277,7 @@ void Console::draw() {
Text& text = mTextCache[mTextCache.size() - 1];
text.setFont( mFontStyleConfig.Font );
text.setCharacterSize( mFontStyleConfig.CharacterSize );
text.setFontSize( mFontStyleConfig.CharacterSize );
text.setStyle( mFontStyleConfig.Style );
text.setOutlineThickness( mFontStyleConfig.OutlineThickness );
text.setOutlineColor( mFontStyleConfig.OutlineColor );
@@ -288,7 +288,7 @@ void Console::draw() {
Text& text2 = mTextCache[mTextCache.size() - 2];
text2.setFont( mFontStyleConfig.Font );
text2.setCharacterSize( mFontStyleConfig.CharacterSize );
text2.setFontSize( mFontStyleConfig.CharacterSize );
text2.setStyle( mFontStyleConfig.Style );
text2.setOutlineThickness( mFontStyleConfig.OutlineThickness );
text2.setOutlineColor( mFontStyleConfig.OutlineColor );

View File

@@ -81,8 +81,8 @@ Text* Text::New( Font* font, unsigned int characterSize ) {
Text::Text() :
mString(),
mFont( NULL ),
mCharacterSize( 12 ),
mRealCharacterSize( PixelDensity::dpToPxI( mCharacterSize ) ),
mFontSize( 12 ),
mRealFontSize( PixelDensity::dpToPxI( mFontSize ) ),
mStyle( Regular ),
mFillColor( 255, 255, 255, 255 ),
mOutlineColor( 0, 0, 0, 255 ),
@@ -101,8 +101,8 @@ Text::Text() :
Text::Text( const String& string, Font* font, unsigned int characterSize ) :
mString( string ),
mFont( font ),
mCharacterSize( characterSize ),
mRealCharacterSize( PixelDensity::dpToPxI( mCharacterSize ) ),
mFontSize( characterSize ),
mRealFontSize( PixelDensity::dpToPxI( mFontSize ) ),
mStyle( Regular ),
mFillColor( 255, 255, 255, 255 ),
mOutlineColor( 0, 0, 0, 255 ),
@@ -115,13 +115,13 @@ Text::Text( const String& string, Font* font, unsigned int characterSize ) :
mLargestLineCharCount( 0 ),
mFontShadowColor( Color( 0, 0, 0, 255 ) ),
mAlign( 0 ),
mFontHeight( mFont->getFontHeight( mRealCharacterSize ) ),
mFontHeight( mFont->getFontHeight( mRealFontSize ) ),
mTabWidth( 4 ) {}
Text::Text( Font* font, unsigned int characterSize ) :
mFont( font ),
mCharacterSize( characterSize ),
mRealCharacterSize( PixelDensity::dpToPxI( mCharacterSize ) ),
mFontSize( characterSize ),
mRealFontSize( PixelDensity::dpToPxI( mFontSize ) ),
mStyle( Regular ),
mFillColor( 255, 255, 255, 255 ),
mOutlineColor( 0, 0, 0, 255 ),
@@ -134,15 +134,15 @@ Text::Text( Font* font, unsigned int characterSize ) :
mLargestLineCharCount( 0 ),
mFontShadowColor( Color( 0, 0, 0, 255 ) ),
mAlign( 0 ),
mFontHeight( mFont->getFontHeight( mRealCharacterSize ) ),
mFontHeight( mFont->getFontHeight( mRealFontSize ) ),
mTabWidth( 4 ) {}
void Text::create( Font* font, const String& text, Color FontColor, Color FontShadowColor,
Uint32 characterSize ) {
mFont = font;
mString = text;
mCharacterSize = characterSize;
mRealCharacterSize = PixelDensity::dpToPxI( mCharacterSize );
mFontSize = characterSize;
mRealFontSize = PixelDensity::dpToPxI( mFontSize );
setFillColor( FontColor );
setShadowColor( FontShadowColor );
mGeometryNeedUpdate = true;
@@ -165,20 +165,20 @@ void Text::setFont( Font* font ) {
if ( NULL != font && mFont != font ) {
mFont = font;
mRealCharacterSize = PixelDensity::dpToPxI( mCharacterSize );
mFontHeight = mFont->getFontHeight( mRealCharacterSize );
mRealFontSize = PixelDensity::dpToPxI( mFontSize );
mFontHeight = mFont->getFontHeight( mRealFontSize );
mGeometryNeedUpdate = true;
mCachedWidthNeedUpdate = true;
}
}
void Text::setCharacterSize( unsigned int size ) {
if ( NULL != mFont && mCharacterSize != size ) {
mCharacterSize = size;
void Text::setFontSize( unsigned int size ) {
if ( NULL != mFont && mFontSize != size ) {
mFontSize = size;
mRealCharacterSize = PixelDensity::dpToPxI( mCharacterSize );
mFontHeight = mFont->getFontHeight( mRealCharacterSize );
mRealFontSize = PixelDensity::dpToPxI( mFontSize );
mFontHeight = mFont->getFontHeight( mRealFontSize );
mGeometryNeedUpdate = true;
mCachedWidthNeedUpdate = true;
@@ -230,11 +230,11 @@ Font* Text::getFont() const {
}
unsigned int Text::getCharacterSize() const {
return mCharacterSize;
return mFontSize;
}
unsigned int Text::getCharacterSizePx() const {
return mRealCharacterSize;
return mRealFontSize;
}
const Uint32& Text::getFontHeight() const {
@@ -285,23 +285,23 @@ Int32 Text::findCharacterFromPos( const Vector2i& pos ) {
if ( NULL == mFont )
return 0;
Float vspace = mFont->getLineSpacing( mRealCharacterSize );
Float vspace = mFont->getLineSpacing( mRealFontSize );
Float Width = 0, lWidth = 0, Height = vspace, lHeight = 0;
Uint32 CharID;
Uint32 prevChar = 0;
std::size_t tSize = mString.size();
bool bold = ( mStyle & Bold ) != 0;
Float hspace = static_cast<Float>( mFont->getGlyph( L' ', mRealCharacterSize, bold ).advance );
Float hspace = static_cast<Float>( mFont->getGlyph( L' ', mRealFontSize, bold ).advance );
for ( std::size_t i = 0; i < tSize; ++i ) {
CharID = mString[i];
Glyph glyph = mFont->getGlyph( CharID, mRealCharacterSize, bold, mOutlineThickness );
Glyph glyph = mFont->getGlyph( CharID, mRealFontSize, bold, mOutlineThickness );
lWidth = Width;
if ( CharID != '\r' && CharID != '\t' ) {
Width += mFont->getKerning( prevChar, CharID, mRealCharacterSize );
Width += mFont->getKerning( prevChar, CharID, mRealFontSize );
prevChar = CharID;
Width += glyph.advance;
}
@@ -396,14 +396,14 @@ void Text::getWidthInfo( std::vector<Float>& LinesWidth, Float& CachedWidth, int
LargestLineCharCount = 0;
bool bold = ( mStyle & Bold ) != 0;
Float hspace = static_cast<Float>( mFont->getGlyph( L' ', mRealCharacterSize, bold ).advance );
Float hspace = static_cast<Float>( mFont->getGlyph( L' ', mRealFontSize, bold ).advance );
for ( std::size_t i = 0; i < mString.size(); ++i ) {
CharID = static_cast<Int32>( mString.at( i ) );
Glyph glyph = mFont->getGlyph( CharID, mRealCharacterSize, bold, mOutlineThickness );
Glyph glyph = mFont->getGlyph( CharID, mRealFontSize, bold, mOutlineThickness );
if ( CharID != '\r' && CharID != '\t' ) {
Width += mFont->getKerning( prevChar, CharID, mRealCharacterSize );
Width += mFont->getKerning( prevChar, CharID, mRealFontSize );
prevChar = CharID;
Width += glyph.advance;
}
@@ -412,7 +412,8 @@ void Text::getWidthInfo( std::vector<Float>& LinesWidth, Float& CachedWidth, int
if ( CharID == '\t' ) {
Width += hspace * mTabWidth;
} if ( CharID == '\n' ) {
}
if ( CharID == '\n' ) {
Lines++;
LinesWidth.push_back( Width - glyph.advance );
@@ -449,10 +450,10 @@ void Text::shrinkText( const Uint32& MaxWidth ) {
Uint32 prevChar = 0;
bool bold = ( mStyle & Bold ) != 0;
Float hspace = static_cast<Float>( mFont->getGlyph( L' ', mRealCharacterSize, bold ).advance );
Float hspace = static_cast<Float>( mFont->getGlyph( L' ', mRealFontSize, bold ).advance );
while ( *tChar ) {
Glyph pChar = mFont->getGlyph( *tChar, mRealCharacterSize, bold, mOutlineThickness );
Glyph pChar = mFont->getGlyph( *tChar, mRealFontSize, bold, mOutlineThickness );
Float fCharWidth = (Float)pChar.advance;
@@ -465,7 +466,7 @@ void Text::shrinkText( const Uint32& MaxWidth ) {
tWordWidth += fCharWidth;
if ( *tChar != '\r' ) {
tWordWidth += mFont->getKerning( prevChar, *tChar, mRealCharacterSize );
tWordWidth += mFont->getKerning( prevChar, *tChar, mRealFontSize );
prevChar = *tChar;
}
@@ -553,7 +554,7 @@ Float Text::getTextHeight() {
cacheWidth();
return NULL != mFont
? mFont->getLineSpacing( mRealCharacterSize ) * ( 0 == mNumLines ? 1 : mNumLines )
? mFont->getLineSpacing( mRealFontSize ) * ( 0 == mNumLines ? 1 : mNumLines )
: 0;
}
@@ -570,7 +571,7 @@ void Text::draw( const Float& X, const Float& Y, const Vector2f& Scale, const Fl
return;
GlobalBatchRenderer::instance()->draw();
TextureFactory::instance()->bind( mFont->getTexture( mRealCharacterSize ),
TextureFactory::instance()->bind( mFont->getTexture( mRealFontSize ),
Texture::CoordinateType::Pixels );
BlendMode::setMode( Effect );
@@ -694,24 +695,24 @@ void Text::ensureGeometryUpdate() {
bool underlined = ( mStyle & Underlined ) != 0;
bool strikeThrough = ( mStyle & StrikeThrough ) != 0;
Float italic = ( mStyle & Italic ) ? 0.208f : 0.f; // 12 degrees
Float underlineOffset = mFont->getUnderlinePosition( mRealCharacterSize );
Float underlineThickness = mFont->getUnderlineThickness( mRealCharacterSize );
Float underlineOffset = mFont->getUnderlinePosition( mRealFontSize );
Float underlineThickness = mFont->getUnderlineThickness( mRealFontSize );
// Compute the location of the strike through dynamically
// We use the center point of the lowercase 'x' glyph as the reference
// We reuse the underline thickness as the thickness of the strike through as well
Rectf xBounds = mFont->getGlyph( L'x', mRealCharacterSize, bold ).bounds;
Rectf xBounds = mFont->getGlyph( L'x', mRealFontSize, bold ).bounds;
Float strikeThroughOffset = xBounds.Top + xBounds.Bottom / 2.f;
// Precompute the variables needed by the algorithm
Float hspace = static_cast<Float>( mFont->getGlyph( L' ', mRealCharacterSize, bold ).advance );
Float vspace = static_cast<Float>( mFont->getLineSpacing( mRealCharacterSize ) );
Float hspace = static_cast<Float>( mFont->getGlyph( L' ', mRealFontSize, bold ).advance );
Float vspace = static_cast<Float>( mFont->getLineSpacing( mRealFontSize ) );
Float x = 0.f;
Float y = static_cast<Float>( mRealCharacterSize );
Float y = static_cast<Float>( mRealFontSize );
// Create one quad for each character
Float minX = static_cast<Float>( mRealCharacterSize );
Float minY = static_cast<Float>( mRealCharacterSize );
Float minX = static_cast<Float>( mRealFontSize );
Float minY = static_cast<Float>( mRealFontSize );
Float maxX = 0.f;
Float maxY = 0.f;
Uint32 prevChar = 0;
@@ -734,7 +735,7 @@ void Text::ensureGeometryUpdate() {
Uint32 curChar = mString[i];
// Apply the kerning offset
x += mFont->getKerning( prevChar, curChar, mRealCharacterSize );
x += mFont->getKerning( prevChar, curChar, mRealFontSize );
prevChar = curChar;
// If we're using the underlined style and there's a new line, draw a line
@@ -777,7 +778,7 @@ void Text::ensureGeometryUpdate() {
minX = std::min( minX, x );
minY = std::min( minY, y );
mGlyphPos.push_back( Vector2f( x, y - mRealCharacterSize ) );
mGlyphPos.push_back( Vector2f( x, y - mRealFontSize ) );
switch ( curChar ) {
case ' ':
@@ -804,8 +805,7 @@ void Text::ensureGeometryUpdate() {
// Apply the outline
if ( mOutlineThickness != 0 ) {
const Glyph& glyph =
mFont->getGlyph( curChar, mRealCharacterSize, bold, mOutlineThickness );
const Glyph& glyph = mFont->getGlyph( curChar, mRealFontSize, bold, mOutlineThickness );
Float left = glyph.bounds.Left;
Float top = glyph.bounds.Top;
@@ -824,7 +824,7 @@ void Text::ensureGeometryUpdate() {
}
// Extract the current glyph's description
const Glyph& glyph = mFont->getGlyph( curChar, mRealCharacterSize, bold );
const Glyph& glyph = mFont->getGlyph( curChar, mRealFontSize, bold );
// Add the glyph to the vertices
addGlyphQuad( mVertices, Vector2f( x, y ), glyph, italic, 0, centerDiffX );
@@ -842,13 +842,13 @@ void Text::ensureGeometryUpdate() {
maxY = std::max( maxY, y + bottom );
}
mGlyphPos.push_back( Vector2f( x, y - mRealCharacterSize ) );
mGlyphPos.push_back( Vector2f( x, y - mRealFontSize ) );
// Advance to the next character
x += glyph.advance;
}
mGlyphPos.push_back( Vector2f( x, y - mRealCharacterSize ) );
mGlyphPos.push_back( Vector2f( x, y - mRealFontSize ) );
// If we're using the underlined style, add the last line
if ( underlined && ( x > 0 ) ) {
@@ -940,7 +940,7 @@ void Text::cacheWidth() {
void Text::setStyleConfig( const FontStyleConfig& styleConfig ) {
setFont( styleConfig.Font );
setCharacterSize( styleConfig.CharacterSize );
setFontSize( styleConfig.CharacterSize );
setFillColor( styleConfig.FontColor );
setStyle( styleConfig.Style );
setOutlineThickness( styleConfig.OutlineThickness );

View File

@@ -11,6 +11,7 @@
#include <eepp/scene/actions/scale.hpp>
#include <eepp/scene/scenemanager.hpp>
#include <eepp/scene/scenenode.hpp>
#include <eepp/ui/css/stylesheetspecification.hpp>
#include <eepp/ui/uiborderdrawable.hpp>
#include <eepp/ui/uinode.hpp>
#include <eepp/ui/uinodedrawable.hpp>
@@ -1173,9 +1174,82 @@ Uint32 UINode::onFocusLoss() {
}
Float UINode::convertLength( const CSS::StyleSheetLength& length, const Float& containerLength ) {
// TODO: Fix asPixels parameters
Float elFontSize = 12;
Float rootFontSize = 12;
if ( length.getUnit() == CSS::StyleSheetLength::Unit::Rem ) {
if ( getUISceneNode() != NULL ) {
std::string fontSizeStr( getUISceneNode()->getRoot()->getPropertyString(
CSS::StyleSheetSpecification::instance()->getProperty(
(Uint32)PropertyId::FontSize ) ) );
if ( !fontSizeStr.empty() ) {
Float num;
if ( String::fromString( num, fontSizeStr ) ) {
rootFontSize = num;
}
} else if ( NULL != getUISceneNode() &&
NULL != getUISceneNode()->getUIThemeManager() ) {
UIThemeManager* themeManager = getUISceneNode()->getUIThemeManager();
if ( NULL != themeManager->getDefaultTheme() ) {
rootFontSize = getUISceneNode()
->getUIThemeManager()
->getDefaultTheme()
->getDefaultFontSize();
} else {
rootFontSize = themeManager->getDefaultFontSize();
}
}
}
} else if ( length.getUnit() == CSS::StyleSheetLength::Unit::Em ) {
if ( isWidget() ) {
std::string fontSizeStr( asType<UIWidget>()->getPropertyString(
CSS::StyleSheetSpecification::instance()->getProperty(
(Uint32)PropertyId::FontSize ) ) );
if ( !fontSizeStr.empty() ) {
Float num;
if ( String::fromString( num, fontSizeStr ) ) {
elFontSize = num;
}
} else {
Node* node = getParent();
while ( NULL != node ) {
if ( node->isWidget() ) {
std::string fontSizeStr( node->asType<UIWidget>()->getPropertyString(
CSS::StyleSheetSpecification::instance()->getProperty(
(Uint32)PropertyId::FontSize ) ) );
if ( !fontSizeStr.empty() ) {
Float num;
if ( String::fromString( num, fontSizeStr ) ) {
elFontSize = num;
break;
}
}
}
node = node->getParent();
}
if ( node == NULL ) {
if ( NULL != getUISceneNode() &&
NULL != getUISceneNode()->getUIThemeManager() ) {
UIThemeManager* themeManager = getUISceneNode()->getUIThemeManager();
if ( NULL != themeManager->getDefaultTheme() ) {
elFontSize = getUISceneNode()
->getUIThemeManager()
->getDefaultTheme()
->getDefaultFontSize();
} else {
elFontSize = themeManager->getDefaultFontSize();
}
}
}
}
}
}
return length.asPixels( containerLength, getSceneNode()->getPixelsSize(),
getSceneNode()->getDPI(), 12, 12 );
getSceneNode()->getDPI(), elFontSize, rootFontSize );
}
Float UINode::convertLengthAsDp( const CSS::StyleSheetLength& length,

View File

@@ -621,7 +621,7 @@ Uint32 UITextInput::getHintCharacterSize() const {
UITextView* UITextInput::setHintCharacterSize( const Uint32& characterSize ) {
if ( mHintCache->getCharacterSize() != characterSize ) {
mHintCache->setCharacterSize( characterSize );
mHintCache->setFontSize( characterSize );
mHintStyleConfig.CharacterSize = characterSize;
invalidateDraw();
}

View File

@@ -147,7 +147,7 @@ Text* UITextInputPassword::getPassCache() const {
}
void UITextInputPassword::updateFontStyleConfig() {
mPassCache->setCharacterSize( mFontStyleConfig.CharacterSize );
mPassCache->setFontSize( mFontStyleConfig.CharacterSize );
mPassCache->setFont( mFontStyleConfig.getFont() );
mPassCache->setFillColor( mFontStyleConfig.getFontColor() );
mPassCache->setShadowColor( mFontStyleConfig.getFontShadowColor() );

View File

@@ -39,11 +39,18 @@ UITextView::UITextView( const std::string& tag ) :
setFont( theme->getDefaultFont() );
}
if ( NULL != theme ) {
setFontSize( theme->getDefaultFontSize() );
} else {
mTextCache->setFontSize( getUISceneNode()->getUIThemeManager()->getDefaultFontSize() );
}
if ( NULL == getFont() ) {
if ( NULL != getUISceneNode()->getUIThemeManager()->getDefaultFont() )
if ( NULL != getUISceneNode()->getUIThemeManager()->getDefaultFont() ) {
setFont( getUISceneNode()->getUIThemeManager()->getDefaultFont() );
else
} else {
eePRINTL( "UITextView::UITextView : Created a without a defined font." );
}
}
alignFix();
@@ -113,10 +120,10 @@ Uint32 UITextView::getCharacterSize() const {
return mTextCache->getCharacterSize();
}
UITextView* UITextView::setCharacterSize( const Uint32& characterSize ) {
UITextView* UITextView::setFontSize( const Uint32& characterSize ) {
if ( mTextCache->getCharacterSize() != characterSize ) {
mFontStyleConfig.CharacterSize = characterSize;
mTextCache->setCharacterSize( characterSize );
mTextCache->setFontSize( characterSize );
recalculate();
onFontStyleChanged();
notifyLayoutAttrChange();
@@ -510,7 +517,7 @@ const UIFontStyleConfig& UITextView::getFontStyleConfig() const {
void UITextView::setFontStyleConfig( const UIFontStyleConfig& fontStyleConfig ) {
mFontStyleConfig = fontStyleConfig;
setFont( fontStyleConfig.getFont() );
setCharacterSize( fontStyleConfig.getFontCharacterSize() );
setFontSize( fontStyleConfig.getFontCharacterSize() );
setFontColor( fontStyleConfig.getFontColor() );
setFontShadowColor( fontStyleConfig.getFontShadowColor() );
setOutlineThickness( fontStyleConfig.getOutlineThickness() );
@@ -615,7 +622,7 @@ bool UITextView::applyProperty( const StyleSheetProperty& attribute ) {
break;
}
case PropertyId::FontSize:
setCharacterSize( attribute.asDpDimensionI() );
setFontSize( attribute.asDpDimensionI() );
break;
case PropertyId::FontStyle: {
Uint32 flags = attribute.asFontStyle();

View File

@@ -258,7 +258,8 @@ UITheme::UITheme( const std::string& name, const std::string& Abbr, Graphics::Fo
mNameHash( String::hash( mName ) ),
mAbbr( Abbr ),
mTextureAtlas( NULL ),
mDefaultFont( defaultFont ) {}
mDefaultFont( defaultFont ),
mDefaultFontSize( 12 ) {}
UITheme::~UITheme() {}
@@ -310,6 +311,14 @@ void UITheme::setStyleSheet( const CSS::StyleSheet& styleSheet ) {
mStyleSheet = styleSheet;
}
const Float& UITheme::getDefaultFontSize() const {
return mDefaultFontSize;
}
void UITheme::setDefaultFontSize( const Float& defaultFontSize ) {
mDefaultFontSize = defaultFontSize;
}
Font* UITheme::getDefaultFont() const {
return mDefaultFont;
}

View File

@@ -10,6 +10,7 @@ UIThemeManager* UIThemeManager::New() {
UIThemeManager::UIThemeManager() :
ResourceManager<UITheme>( true ),
mFont( NULL ),
mFontSize( 12 ),
mThemeDefault( NULL ),
mAutoApplyDefaultTheme( true ),
mEnableDefaultEffects( false ),
@@ -35,6 +36,15 @@ Font* UIThemeManager::getDefaultFont() const {
return mFont;
}
UIThemeManager* UIThemeManager::setDefaultFontSize( const Float& fontSize ) {
mFontSize = fontSize;
return this;
}
const Float& UIThemeManager::getDefaultFontSize() const {
return mFontSize;
}
UIThemeManager* UIThemeManager::setDefaultTheme( UITheme* Theme ) {
mThemeDefault = Theme;

View File

@@ -261,7 +261,7 @@ Uint32 UITooltip::getCharacterSize() const {
UITooltip* UITooltip::setCharacterSize( const Uint32& characterSize ) {
if ( mTextCache->getCharacterSize() != characterSize ) {
mStyleConfig.CharacterSize = characterSize;
mTextCache->setCharacterSize( characterSize );
mTextCache->setFontSize( characterSize );
onAutoSize();
autoAlign();
invalidateDraw();
@@ -321,7 +321,7 @@ void UITooltip::setFontStyleConfig( const UIFontStyleConfig& styleConfig ) {
setFont( mStyleConfig.Font );
setFontColor( mStyleConfig.FontColor );
setFontShadowColor( mStyleConfig.ShadowColor );
mTextCache->setCharacterSize( mStyleConfig.CharacterSize );
mTextCache->setFontSize( mStyleConfig.CharacterSize );
mTextCache->setStyle( mStyleConfig.Style );
mTextCache->setOutlineThickness( mStyleConfig.OutlineThickness );
mTextCache->setOutlineColor( mStyleConfig.OutlineColor );

View File

@@ -264,7 +264,9 @@ Uint32 UIWidget::onMouseOver( const Vector2i& position, const Uint32& flags ) {
EventDispatcher* eventDispatcher = getEventDispatcher();
if ( NULL != eventDispatcher && eventDispatcher->getOverControl() == this ) {
updateDebugData();
if ( NULL != mSceneNode && mSceneNode->getDrawDebugData() ) {
updateDebugData();
}
if ( mVisible && NULL != mTooltip && !mTooltip->getText().empty() ) {
UIThemeManager* themeManager = getUISceneNode()->getUIThemeManager();
@@ -279,7 +281,7 @@ Uint32 UIWidget::onMouseOver( const Vector2i& position, const Uint32& flags ) {
} else {
runAction( Actions::Runnable::New(
[&] {
if ( isMouseOver() ) {
if ( getEventDispatcher()->getOverControl() == this ) {
mTooltip->setPixelsPosition( getTooltipPosition() );
mTooltip->show();
}
@@ -331,6 +333,9 @@ String UIWidget::getTooltipText() {
}
void UIWidget::tooltipRemove() {
if ( NULL != mTooltip ) {
mTooltip->close();
}
mTooltip = NULL;
}

View File

@@ -64,7 +64,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) {
fontTest->loadFromFile( "assets/fonts/DejaVuSansMono.ttf" );
text.setFont( fontTest );
text.setCharacterSize( 24 );
text.setFontSize( 24 );
text.setAlign( TEXT_ALIGN_CENTER );
text.setString( Txt );
text.shrinkText( win->getWidth() - 96 );
@@ -82,13 +82,13 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) {
text2.setFont( fontTest2 );
text2.setString( "Lorem ipsum dolor sit amet, consectetur adipisicing elit." );
text2.setCharacterSize( 32 );
text2.setFontSize( 32 );
text2.setFillColor( Color::Black );
text3.setFont( fontTest );
text3.setString( text2.getString() );
text3.setOutlineThickness( 2 );
text3.setCharacterSize( 24 );
text3.setFontSize( 24 );
text3.setFillColor( Color( 255, 255, 255, 255 ) );
text3.setOutlineColor( Color( 0, 0, 0, 255 ) );
@@ -97,7 +97,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) {
text4.setFont( fontBMFont );
text4.setString( "Lorem ipsum dolor sit amet, consectetur adipisicing elit." );
text4.setCharacterSize( 45 );
text4.setFontSize( 45 );
text4.setFillColor( Color::Black );
fontSprite = FontSprite::New(
@@ -106,7 +106,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) {
text5.setFont( fontSprite );
text5.setString( "Lorem ipsum dolor sit amet, consectetur adipisicing elit." );
text5.setCharacterSize( 38 );
text5.setFontSize( 38 );
// Application loop
win->runMainLoop( &mainLoop );