mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-06-02 11:36:30 +03:00
Minor refactor.
--HG-- branch : dev-font
This commit is contained in:
@@ -26,7 +26,7 @@ class EE_API Text {
|
||||
/** Create a text from a font */
|
||||
void create(Graphics::Font * font, const String& text = "", ColorA FontColor = ColorA(255,255,255,255), ColorA FontShadowColor = ColorA(0,0,0,255) , Uint32 characterSize = 12);
|
||||
|
||||
void setText(const String& string);
|
||||
void setString(const String& string);
|
||||
|
||||
void setFont(Font * font);
|
||||
|
||||
@@ -42,7 +42,7 @@ class EE_API Text {
|
||||
|
||||
void setOutlineThickness(Float thickness);
|
||||
|
||||
String& getText();
|
||||
String& getString();
|
||||
|
||||
Font * getFont() const;
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ void Console::draw() {
|
||||
if ( i < static_cast<Int16>( mCmdLog.size() ) && i >= 0 ) {
|
||||
CurY = mTempY + mY + mCurHeight - Pos * mFontSize - mFontSize * 2;
|
||||
|
||||
mTextCache.setText( mCmdLog[i] );
|
||||
mTextCache.setString( mCmdLog[i] );
|
||||
mTextCache.draw( mFontSize, CurY );
|
||||
|
||||
Pos++;
|
||||
@@ -208,19 +208,19 @@ void Console::draw() {
|
||||
CurY = mTempY + mY + mCurHeight - mFontSize - 1;
|
||||
|
||||
mTextCache.setColor( ColorA ( mFontLineColor.r(), mFontLineColor.g(), mFontLineColor.b(), static_cast<Uint8>(mA) ) );
|
||||
mTextCache.setText( "> " + mTBuf->getBuffer() );
|
||||
mTextCache.setString( "> " + mTBuf->getBuffer() );
|
||||
mTextCache.draw( mFontSize, CurY );
|
||||
|
||||
mTextCache.setColor( ColorA ( mFontLineColor.r(), mFontLineColor.g(), mFontLineColor.b(), static_cast<Uint8>(mCurAlpha) ) );
|
||||
|
||||
if ( (unsigned int)mTBuf->getCursorPos() == mTBuf->getBuffer().size() ) {
|
||||
Uint32 width = mTextCache.getTextWidth();
|
||||
mTextCache.setText( "_" );
|
||||
mTextCache.setString( "_" );
|
||||
mTextCache.draw( mFontSize + width, CurY );
|
||||
} else {
|
||||
mTextCache.setText( "> " + mTBuf->getBuffer().substr( 0, mTBuf->getCursorPos() ) );
|
||||
mTextCache.setString( "> " + mTBuf->getBuffer().substr( 0, mTBuf->getCursorPos() ) );
|
||||
Uint32 width = mFontSize + mTextCache.getTextWidth();
|
||||
mTextCache.setText( "_" );
|
||||
mTextCache.setString( "_" );
|
||||
mTextCache.draw( width, CurY );
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ void Console::draw() {
|
||||
if ( mShowFps && NULL != mFont ) {
|
||||
ColorA OldColor1( mTextCache.getColor() );
|
||||
mTextCache.setColor( ColorA () );
|
||||
mTextCache.setText( "FPS: " + String::toStr( mWindow->getFPS() ) );
|
||||
mTextCache.setString( "FPS: " + String::toStr( mWindow->getFPS() ) );
|
||||
mTextCache.draw( mWindow->getWidth() - mTextCache.getTextWidth() - 15, 6 );
|
||||
mTextCache.setColor( OldColor1 );
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ Uint32 FontTrueType::getFontHeight(const Uint32 & characterSize) {
|
||||
FT_Face face = static_cast<FT_Face>(mFace);
|
||||
|
||||
if (face && setCurrentSize(characterSize)) {
|
||||
return static_cast<Float>(face->height) / static_cast<Float>(1 << 6);
|
||||
return static_cast<Float>( eemax( (Float)face->height, (Float)face->size->metrics.height ) ) / static_cast<Float>(1 << 6);
|
||||
} else {
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ void Text::create(Font * font, const String & text, ColorA FontColor, ColorA Fon
|
||||
ensureGeometryUpdate();
|
||||
}
|
||||
|
||||
void Text::setText(const String& string) {
|
||||
void Text::setString(const String& string) {
|
||||
if (mString != string) {
|
||||
mString = string;
|
||||
mGeometryNeedUpdate = true;
|
||||
@@ -323,7 +323,7 @@ void Text::setOutlineThickness(Float thickness) {
|
||||
}
|
||||
}
|
||||
|
||||
String& Text::getText() {
|
||||
String& Text::getString() {
|
||||
return mString;
|
||||
}
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ Uint32 UIListBox::addListBoxItem( const String& text ) {
|
||||
|
||||
if ( NULL != mFontStyleConfig.Font ) {
|
||||
Text textCache( mFontStyleConfig.Font, mFontStyleConfig.FontCharacterSize );
|
||||
textCache.setText( text );
|
||||
textCache.setString( text );
|
||||
Uint32 twidth = textCache.getTextWidth();
|
||||
|
||||
if ( twidth > mMaxTextWidth ) {
|
||||
@@ -340,7 +340,7 @@ void UIListBox::findMaxWidth() {
|
||||
if ( NULL != mItems[i] ) {
|
||||
width = (Int32)mItems[i]->getTextWidth();
|
||||
} else {
|
||||
textCache.setText( mTexts[i] );
|
||||
textCache.setString( mTexts[i] );
|
||||
width = textCache.getTextWidth();
|
||||
}
|
||||
|
||||
|
||||
@@ -346,7 +346,7 @@ void UITextEdit::fixScrollToCursor() {
|
||||
Uint32 LineNum = mTextInput->getInputTextBuffer()->getCurPosLinePos( NLPos );
|
||||
|
||||
Text textCache( mTextInput->getTextCache()->getFont(), mTextInput->getFontStyleConfig().FontCharacterSize );
|
||||
textCache.setText(
|
||||
textCache.setString(
|
||||
mTextInput->getInputTextBuffer()->getBuffer().substr(
|
||||
NLPos, mTextInput->getInputTextBuffer()->getCursorPos() - NLPos
|
||||
)
|
||||
|
||||
@@ -161,7 +161,7 @@ void UITextInput::alignFix() {
|
||||
|
||||
Text textCache( mTextCache->getFont(), mTextCache->getCharacterSize() );
|
||||
|
||||
textCache.setText( mTextBuffer.getBuffer().substr( NLPos, mTextBuffer.getCursorPos() - NLPos ) );
|
||||
textCache.setString( mTextBuffer.getBuffer().substr( NLPos, mTextBuffer.getCursorPos() - NLPos ) );
|
||||
|
||||
Float tW = textCache.getTextWidth();
|
||||
Float tX = mRealAlignOffset.x + tW;
|
||||
@@ -239,11 +239,11 @@ const String& UITextInput::getText() {
|
||||
}
|
||||
|
||||
void UITextInput::shrinkText( const Uint32& MaxWidth ) {
|
||||
mTextCache->setText( mTextBuffer.getBuffer() );
|
||||
mTextCache->setString( mTextBuffer.getBuffer() );
|
||||
|
||||
UITextView::shrinkText( MaxWidth );
|
||||
|
||||
mTextBuffer.setBuffer( mTextCache->getText() );
|
||||
mTextBuffer.setBuffer( mTextCache->getString() );
|
||||
|
||||
alignFix();
|
||||
}
|
||||
@@ -257,7 +257,7 @@ Uint32 UITextInput::onMouseClick( const Vector2i& Pos, const Uint32 Flags ) {
|
||||
worldToControl( controlPos );
|
||||
controlPos = PixelDensity::dpToPxI( controlPos ) - Vector2i( (Int32)mRealAlignOffset.x, (Int32)mRealAlignOffset.y );
|
||||
|
||||
Int32 curPos = mTextCache->getFont()->findClosestCursorPosFromPoint( mTextCache->getText(), mTextCache->getCharacterSizePx(), mTextCache->getStyle() & Text::Bold, mTextCache->getOutlineThickness(), controlPos );
|
||||
Int32 curPos = mTextCache->getFont()->findClosestCursorPosFromPoint( mTextCache->getString(), mTextCache->getCharacterSizePx(), mTextCache->getStyle() & Text::Bold, mTextCache->getOutlineThickness(), controlPos );
|
||||
|
||||
if ( -1 != curPos ) {
|
||||
mTextBuffer.setCursorPos( curPos );
|
||||
|
||||
@@ -63,7 +63,7 @@ void UITextInputPassword::alignFix() {
|
||||
for ( size_t i = 0; i < curStr.size(); i++ )
|
||||
pasStr += '*';
|
||||
|
||||
mPassCache->setText( pasStr );
|
||||
mPassCache->setString( pasStr );
|
||||
|
||||
Float tW = mPassCache->getTextWidth();
|
||||
Float tX = mRealAlignOffset.x + tW;
|
||||
@@ -107,7 +107,7 @@ void UITextInputPassword::autoAlign() {
|
||||
}
|
||||
|
||||
void UITextInputPassword::updateText() {
|
||||
updatePass( mTextCache->getText() );
|
||||
updatePass( mTextCache->getString() );
|
||||
}
|
||||
|
||||
void UITextInputPassword::updatePass( const String& pass ) {
|
||||
@@ -117,7 +117,7 @@ void UITextInputPassword::updatePass( const String& pass ) {
|
||||
newTxt += '*';
|
||||
}
|
||||
|
||||
mPassCache->setText( newTxt );
|
||||
mPassCache->setString( newTxt );
|
||||
}
|
||||
|
||||
UITextView * UITextInputPassword::setText( const String& text ) {
|
||||
|
||||
@@ -153,15 +153,15 @@ const String& UITextView::getText() {
|
||||
if ( mFlags & UI_WORD_WRAP )
|
||||
return mString;
|
||||
|
||||
return mTextCache->getText();
|
||||
return mTextCache->getString();
|
||||
}
|
||||
|
||||
UITextView * UITextView::setText( const String& text ) {
|
||||
if ( mFlags & UI_WORD_WRAP ) {
|
||||
mString = text;
|
||||
mTextCache->setText( mString );
|
||||
mTextCache->setString( mString );
|
||||
} else {
|
||||
mTextCache->setText( text );
|
||||
mTextCache->setString( text );
|
||||
}
|
||||
|
||||
autoShrink();
|
||||
@@ -221,10 +221,10 @@ void UITextView::autoShrink() {
|
||||
|
||||
void UITextView::shrinkText( const Uint32& MaxWidth ) {
|
||||
if ( mFlags & UI_WORD_WRAP ) {
|
||||
mTextCache->setText( mString );
|
||||
mTextCache->setString( mString );
|
||||
}
|
||||
|
||||
mTextCache->getFont()->shrinkText( mTextCache->getText(), mTextCache->getCharacterSizePx(), mTextCache->getStyle() & Text::Bold, mTextCache->getOutlineThickness(), MaxWidth );
|
||||
mTextCache->getFont()->shrinkText( mTextCache->getString(), mTextCache->getCharacterSizePx(), mTextCache->getStyle() & Text::Bold, mTextCache->getOutlineThickness(), MaxWidth );
|
||||
mTextCache->cacheWidth();
|
||||
}
|
||||
|
||||
@@ -323,12 +323,12 @@ Uint32 UITextView::onMouseDoubleClick( const Vector2i& Pos, const Uint32 Flags )
|
||||
worldToControl( controlPos );
|
||||
controlPos = PixelDensity::dpToPxI( controlPos );
|
||||
|
||||
Int32 curPos = mTextCache->getFont()->findClosestCursorPosFromPoint( mTextCache->getText(), mTextCache->getCharacterSizePx(), mTextCache->getStyle() & Text::Bold, mTextCache->getOutlineThickness(), controlPos );
|
||||
Int32 curPos = mTextCache->getFont()->findClosestCursorPosFromPoint( mTextCache->getString(), mTextCache->getCharacterSizePx(), mTextCache->getStyle() & Text::Bold, mTextCache->getOutlineThickness(), controlPos );
|
||||
|
||||
if ( -1 != curPos ) {
|
||||
Int32 tSelCurInit, tSelCurEnd;
|
||||
|
||||
mTextCache->getFont()->selectSubStringFromCursor( mTextCache->getText(), curPos, tSelCurInit, tSelCurEnd );
|
||||
mTextCache->getFont()->selectSubStringFromCursor( mTextCache->getString(), curPos, tSelCurInit, tSelCurEnd );
|
||||
|
||||
selCurInit( tSelCurInit );
|
||||
selCurEnd( tSelCurEnd );
|
||||
@@ -359,7 +359,7 @@ Uint32 UITextView::onMouseDown( const Vector2i& Pos, const Uint32 Flags ) {
|
||||
worldToControl( controlPos );
|
||||
controlPos = PixelDensity::dpToPxI( controlPos ) - Vector2i( (Int32)mRealAlignOffset.x, (Int32)mRealAlignOffset.y );
|
||||
|
||||
Int32 curPos = mTextCache->getFont()->findClosestCursorPosFromPoint( mTextCache->getText(), mTextCache->getCharacterSizePx(), mTextCache->getStyle() & Text::Bold, mTextCache->getOutlineThickness(), controlPos );
|
||||
Int32 curPos = mTextCache->getFont()->findClosestCursorPosFromPoint( mTextCache->getString(), mTextCache->getCharacterSizePx(), mTextCache->getStyle() & Text::Bold, mTextCache->getOutlineThickness(), controlPos );
|
||||
|
||||
if ( -1 != curPos ) {
|
||||
if ( -1 == selCurInit() || !( mControlFlags & UI_CTRL_FLAG_SELECTING ) ) {
|
||||
@@ -381,7 +381,7 @@ void UITextView::drawSelection( Text * textCache ) {
|
||||
Int32 init = eemin( selCurInit(), selCurEnd() );
|
||||
Int32 end = eemax( selCurInit(), selCurEnd() );
|
||||
|
||||
if ( init < 0 && end > (Int32)textCache->getText().size() ) {
|
||||
if ( init < 0 && end > (Int32)textCache->getString().size() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -392,14 +392,14 @@ void UITextView::drawSelection( Text * textCache ) {
|
||||
P.setColor( mFontStyleConfig.FontSelectionBackColor );
|
||||
|
||||
do {
|
||||
initPos = textCache->getFont()->getCursorPos( textCache->getText(), textCache->getCharacterSizePx(), textCache->getStyle() & Text::Bold, textCache->getOutlineThickness(), init );
|
||||
lastEnd = textCache->getText().find_first_of( '\n', init );
|
||||
initPos = textCache->getFont()->getCursorPos( textCache->getString(), textCache->getCharacterSizePx(), textCache->getStyle() & Text::Bold, textCache->getOutlineThickness(), init );
|
||||
lastEnd = textCache->getString().find_first_of( '\n', init );
|
||||
|
||||
if ( lastEnd < end && -1 != lastEnd ) {
|
||||
endPos = textCache->getFont()->getCursorPos( textCache->getText(), textCache->getCharacterSizePx(), textCache->getStyle() & Text::Bold, textCache->getOutlineThickness(), lastEnd );
|
||||
endPos = textCache->getFont()->getCursorPos( textCache->getString(), textCache->getCharacterSizePx(), textCache->getStyle() & Text::Bold, textCache->getOutlineThickness(), lastEnd );
|
||||
init = lastEnd + 1;
|
||||
} else {
|
||||
endPos = textCache->getFont()->getCursorPos( textCache->getText(), textCache->getCharacterSizePx(), textCache->getStyle() & Text::Bold, textCache->getOutlineThickness(), end );
|
||||
endPos = textCache->getFont()->getCursorPos( textCache->getString(), textCache->getCharacterSizePx(), textCache->getStyle() & Text::Bold, textCache->getOutlineThickness(), end );
|
||||
lastEnd = end;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ void UITooltip::hide() {
|
||||
}
|
||||
|
||||
void UITooltip::draw() {
|
||||
if ( mVisible && 0.f != mAlpha && mTextCache->getText().size() > 0 ) {
|
||||
if ( mVisible && 0.f != mAlpha && mTextCache->getString().size() > 0 ) {
|
||||
UIControlAnim::draw();
|
||||
|
||||
if ( mTextCache->getTextWidth() ) {
|
||||
@@ -115,11 +115,11 @@ void UITooltip::setFont( Graphics::Font * font ) {
|
||||
}
|
||||
|
||||
const String& UITooltip::getText() {
|
||||
return mTextCache->getText();
|
||||
return mTextCache->getString();
|
||||
}
|
||||
|
||||
void UITooltip::setText( const String& text ) {
|
||||
mTextCache->setText( text );
|
||||
mTextCache->setString( text );
|
||||
autoPadding();
|
||||
onAutoSize();
|
||||
autoAlign();
|
||||
|
||||
@@ -81,7 +81,7 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
|
||||
text.setFillColor( 0xFFFFFFFF );
|
||||
text.setOutlineThickness( 2 );
|
||||
text.setFlags( FONT_DRAW_CENTER );
|
||||
text.setText( Txt );
|
||||
text.setString( Txt );
|
||||
|
||||
win->setBackColor( RGB(230,230,230) );
|
||||
|
||||
|
||||
@@ -1393,7 +1393,7 @@ void EETest::render() {
|
||||
);
|
||||
#endif
|
||||
|
||||
mInfoText.setText( mInfo );
|
||||
mInfoText.setString( mInfo );
|
||||
}
|
||||
|
||||
if ( !MultiViewportMode ) {
|
||||
|
||||
Reference in New Issue
Block a user