From e5744e349c0328fcbebfe40dc75d1de6f4bd966c Mon Sep 17 00:00:00 2001 From: spartanj Date: Mon, 18 Oct 2010 04:38:24 -0300 Subject: [PATCH] Added a mutex on HaikuTTF, to fix a problem ( a.k.a. bug ) with multiple concurrence on FT calls. Added Icon possibility to cUIPushButton. Added default fonts for ui themes and global default font for all ui themes. Changed how cUIGfx get shapes, now accept a new instance without shape. Fixed how padding works on cUITextBox and cUITextInput. Fixed font rendering in cTextCache when some text rendered with angle or/and scale ( it was breaking the model view matrix ). Fixed a miscounting of the number of vertex for the cached text. Fixed HaikuTTF destroy singleton ( now release fine the memory ). --- ee.linux.cbp | 2 + src/base.hpp | 2 +- src/graphics/cfont.cpp | 71 ++++++++------- src/graphics/cfontmanager.cpp | 4 + src/graphics/cfontmanager.hpp | 2 + src/graphics/ctextcache.cpp | 46 +++++----- src/graphics/ctextcache.hpp | 5 ++ src/graphics/cttffont.cpp | 7 -- src/graphics/cttffont.hpp | 1 - src/helper/SOIL/stb_image.c | 2 +- src/helper/haikuttf/hkbase.hpp | 28 ++++++ src/helper/haikuttf/hkfont.cpp | 11 ++- src/helper/haikuttf/hkfontmanager.cpp | 36 ++++++-- src/helper/haikuttf/hkfontmanager.hpp | 11 ++- src/helper/haikuttf/hkmutex.cpp | 48 +++++++++++ src/helper/haikuttf/hkmutex.hpp | 28 ++++++ src/system/cmutex.cpp | 10 +-- src/test/ee.cpp | 119 +++++++++++--------------- src/ui/cuicontrol.cpp | 4 +- src/ui/cuigfx.cpp | 10 ++- src/ui/cuigfx.hpp | 2 + src/ui/cuiprogressbar.cpp | 2 + src/ui/cuipushbutton.cpp | 74 +++++++++++++++- src/ui/cuipushbutton.hpp | 51 ++++++++++- src/ui/cuiskin.cpp | 2 +- src/ui/cuiskinstate.hpp | 2 +- src/ui/cuispinbox.cpp | 2 + src/ui/cuitextbox.cpp | 21 ++++- src/ui/cuitextbox.hpp | 6 +- src/ui/cuitextinput.cpp | 4 +- src/ui/cuitheme.cpp | 13 ++- src/ui/cuitheme.hpp | 9 +- src/ui/cuithememanager.cpp | 11 ++- src/ui/cuithememanager.hpp | 6 ++ src/ui/uihelper.hpp | 1 + src/window/cengine.cpp | 3 + src/window/cinputtextbuffer.cpp | 4 + src/window/cinputtextbuffer.hpp | 3 + 38 files changed, 492 insertions(+), 171 deletions(-) create mode 100644 src/helper/haikuttf/hkmutex.cpp create mode 100644 src/helper/haikuttf/hkmutex.hpp diff --git a/ee.linux.cbp b/ee.linux.cbp index 97ff86adb..e0b18eb2e 100644 --- a/ee.linux.cbp +++ b/ee.linux.cbp @@ -202,6 +202,8 @@ + + diff --git a/src/base.hpp b/src/base.hpp index 71e24a36b..0024e9a20 100644 --- a/src/base.hpp +++ b/src/base.hpp @@ -48,7 +48,7 @@ #elif defined( __APPLE_CC__) || defined ( __APPLE__ ) # define EE_PLATFORM EE_PLATFORM_MACOSX -#else +#elif defined ( linux ) || defined( __linux__ ) # define EE_PLATFORM EE_PLATFORM_LINUX #endif diff --git a/src/graphics/cfont.cpp b/src/graphics/cfont.cpp index a63048826..0124287d4 100644 --- a/src/graphics/cfont.cpp +++ b/src/graphics/cfont.cpp @@ -160,11 +160,13 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con glRotatef( Angle, 0.0f, 0.0f, 1.0f ); glScalef( Scale, Scale, 1.0f ); glTranslatef( -Center.x, -Center.y, 0.f ); + + glTranslatef( X, Y, 0.f ); } std::vector& RenderCoords = TextCache.VertextCoords(); std::vector& Colors = TextCache.Colors(); - + #ifndef EE_GLES if ( !TextCache.CachedCoords() ) { #else @@ -191,21 +193,26 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con if ( Char >= 0 && Char < tGlyphSize ) { eeTexCoords* C = &mTexCoords[ Char ]; - + switch(Char) { case L'\v': + { if (mVerticalDraw) nY += GetFontHeight(); else nX += mGlyphs[ Char ].Advance; break; + } case L'\t': + { if (mVerticalDraw) nY += GetFontHeight() * 4; else nX += mGlyphs[ Char ].Advance * 4; break; + } case L'\n': + { if (mVerticalDraw) { nX += (GetFontSize() * Scale); nY = 0; @@ -228,36 +235,38 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con } break; + } default: - if ( Char >= 0 && Char < tGlyphSize ) { - for ( Uint8 z = 0; z < 8; z+=2 ) { - RenderCoords[ numvert ].TexCoords[0] = C->TexCoords[z]; - RenderCoords[ numvert ].TexCoords[1] = C->TexCoords[ z + 1 ]; - RenderCoords[ numvert ].Vertex[0] = cX + C->Vertex[z] + nX; - RenderCoords[ numvert ].Vertex[1] = cY + C->Vertex[ z + 1 ] + nY; - numvert++; - } - - #ifdef EE_GLES - glColorPointer( 4, GL_UNSIGNED_BYTE, 0, reinterpret_cast( &Colors[0] ) ); - glTexCoordPointer( 2, GL_FLOAT, sizeof(eeVertexCoords), reinterpret_cast( &RenderCoords[ numvert - 4 ] ) ); - glVertexPointer( 2, GL_FLOAT, sizeof(eeVertexCoords), reinterpret_cast( &RenderCoords[ numvert - 4 ] ) + sizeof(eeFloat) * 2 ); - - glDrawElements( GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, EE_GLES_INDICES ); - #endif - - if (mVerticalDraw) - nY += GetFontHeight(); - else - nX += mGlyphs[ Char ].Advance; + { + for ( Uint8 z = 0; z < 8; z+=2 ) { + RenderCoords[ numvert ].TexCoords[0] = C->TexCoords[z]; + RenderCoords[ numvert ].TexCoords[1] = C->TexCoords[ z + 1 ]; + RenderCoords[ numvert ].Vertex[0] = cX + C->Vertex[z] + nX; + RenderCoords[ numvert ].Vertex[1] = cY + C->Vertex[ z + 1 ] + nY; + numvert++; } + + #ifdef EE_GLES + glColorPointer( 4, GL_UNSIGNED_BYTE, 0, reinterpret_cast( &Colors[0] ) ); + glTexCoordPointer( 2, GL_FLOAT, sizeof(eeVertexCoords), reinterpret_cast( &RenderCoords[ numvert - 4 ] ) ); + glVertexPointer( 2, GL_FLOAT, sizeof(eeVertexCoords), reinterpret_cast( &RenderCoords[ numvert - 4 ] ) + sizeof(eeFloat) * 2 ); + + glDrawElements( GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, EE_GLES_INDICES ); + #endif + + if (mVerticalDraw) + nY += GetFontHeight(); + else + nX += mGlyphs[ Char ].Advance; + } } } } TextCache.CachedCoords( true ); + TextCache.CachedVerts( numvert ); } else { - numvert = (eeUint)TextCache.Text().size() * 4; + numvert = TextCache.CachedVerts(); } #ifndef EE_GLES @@ -268,8 +277,9 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con glDrawArrays( GL_QUADS, 0, numvert ); #endif - if ( Angle != 0.0f || Scale != 1.0f ) + if ( Angle != 0.0f || Scale != 1.0f ) { glPopMatrix(); + } } void cFont::SubDraw( const std::wstring& Text, const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, const bool& Cached, const EE_PRE_BLEND_FUNC& Effect ) { @@ -414,11 +424,13 @@ void cFont::CacheWidth( const std::wstring& Text, std::vector& LinesWid eeFloat Width = 0, MaxWidth = 0; Int32 CharID; Int32 Lines = 1; - + + Int32 tGlyphSize = (Int32)mGlyphs.size(); + for (std::size_t i = 0; i < Text.size(); ++i) { CharID = static_cast( Text.at(i) ); - if ( CharID >= 0 && CharID < (Int32)mGlyphs.size() ) { + if ( CharID >= 0 && CharID < tGlyphSize ) { Width += mGlyphs[CharID].Advance; if ( CharID == L'\t' ) @@ -458,9 +470,10 @@ void cFont::ShrinkText( std::string& Str, const Uint32& MaxWidth ) { Int32 tPrev = -1; char * tStringLoop = &Str[0]; char * tLastSpace = NULL; - + Uint32 tGlyphSize = (Uint32)mGlyphs.size(); + while ( *tStringLoop ) { - if ( (Uint32)( *tStringLoop ) < mGlyphs.size() ) { + if ( (Uint32)( *tStringLoop ) < tGlyphSize ) { eeGlyph * pChar = &mGlyphs[ ( *tStringLoop ) ]; eeFloat fCharWidth = (eeFloat)pChar->Advance; diff --git a/src/graphics/cfontmanager.cpp b/src/graphics/cfontmanager.cpp index 1319e5736..10c086ead 100644 --- a/src/graphics/cfontmanager.cpp +++ b/src/graphics/cfontmanager.cpp @@ -8,4 +8,8 @@ cFontManager::cFontManager() { cFontManager::~cFontManager() { } +cFont * cFontManager::Add( cFont * Font ) { + return tResourceManager::Add( Font ); +} + }} diff --git a/src/graphics/cfontmanager.hpp b/src/graphics/cfontmanager.hpp index f2c3d0411..6e21e78be 100644 --- a/src/graphics/cfontmanager.hpp +++ b/src/graphics/cfontmanager.hpp @@ -12,6 +12,8 @@ class EE_API cFontManager : public tResourceManager, public tSingletonCacheWidth( mText, mLinesWidth, mCachedWidth, mNumLines ); - else + }else { mCachedWidth = 0; + } mCachedCoords = false; } @@ -129,25 +132,20 @@ const std::vector& cTextCache::LinesWidth() { void cTextCache::Draw( const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, const EE_PRE_BLEND_FUNC& Effect ) { if ( NULL != mFont ) { - eeColorA FontColor = mFont->Color(); - eeColorA FontShadowColor = mFont->ShadowColor(); - - mFont->Color( mFontColor ); - mFont->ShadowColor( mFontShadowColor ); - if ( mFlags != Flags ) { mFlags = Flags; mCachedCoords = false; } - - glTranslatef( X, Y, 0.f ); - - mFont->Draw( *this, 0, 0, Flags, Scale, Angle, Effect ); - - glTranslatef( -X, -Y, 0.f ); - - mFont->Color( FontColor ); - mFont->ShadowColor( FontShadowColor ); + + if ( Angle != 0.0f || Scale != 1.0f ) { + mFont->Draw( *this, X, Y, Flags, Scale, Angle, Effect ); + } else { + glTranslatef( X, Y, 0.f ); + + mFont->Draw( *this, 0, 0, Flags, Scale, Angle, Effect ); + + glTranslatef( -X, -Y, 0.f ); + } } } @@ -163,4 +161,12 @@ cFont * cTextCache::GetFont() const { return mFont; } +const eeUint& cTextCache::CachedVerts() const { + return mVertexNumCached; +} + +void cTextCache::CachedVerts( const eeUint& num ) { + mVertexNumCached = num; +} + }} diff --git a/src/graphics/ctextcache.hpp b/src/graphics/ctextcache.hpp index 6584d1f92..c3b801a30 100644 --- a/src/graphics/ctextcache.hpp +++ b/src/graphics/ctextcache.hpp @@ -74,12 +74,17 @@ class EE_API cTextCache { std::vector mColors; bool mCachedCoords; Uint32 mFlags; + Uint32 mVertexNumCached; void UpdateCoords(); const bool& CachedCoords() const; void CachedCoords( const bool& cached ); + + const eeUint& CachedVerts() const; + + void CachedVerts( const eeUint& num ); }; }} diff --git a/src/graphics/cttffont.cpp b/src/graphics/cttffont.cpp index 2b874137c..068aaf2ca 100755 --- a/src/graphics/cttffont.cpp +++ b/src/graphics/cttffont.cpp @@ -9,10 +9,6 @@ cTTFFont::cTTFFont( const std::string FontName ) : mThreadedLoading(false), mTexReady(false) { - if ( hkFontManager::instance()->Init() ) - mTTFInit = false; - else - mTTFInit = true; } cTTFFont::~cTTFFont() { @@ -70,9 +66,6 @@ bool cTTFFont::iLoad( const eeUint& Size, EE_TTF_FONTSTYLE Style, const bool& Ve Uint8 OutlineTotal = OutlineSize * 2; Uint32 TexSize; - if ( !mTTFInit ) - return false; - try { if ( mFont == NULL ) return false; diff --git a/src/graphics/cttffont.hpp b/src/graphics/cttffont.hpp index 8b02bc0cb..58806b469 100755 --- a/src/graphics/cttffont.hpp +++ b/src/graphics/cttffont.hpp @@ -87,7 +87,6 @@ class EE_API cTTFFont : public cFont { EE_TTF_FONTSTYLE mStyle; eeFloat mTexWidth, mTexHeight; - bool mTTFInit; bool mLoadedFromMemory; diff --git a/src/helper/SOIL/stb_image.c b/src/helper/SOIL/stb_image.c index 5f9070aac..e56c0522a 100644 --- a/src/helper/SOIL/stb_image.c +++ b/src/helper/SOIL/stb_image.c @@ -1,4 +1,4 @@ -/* stbi-1.29 - public domain JPEG/PNG reader - http://nothings.org/stb_image.c +/* stbi-1.30 - public domain JPEG/PNG reader - http://nothings.org/stb_image.c when you control the images you're loading no warranty implied; use at your own risk diff --git a/src/helper/haikuttf/hkbase.hpp b/src/helper/haikuttf/hkbase.hpp index 5968860e0..746d7031d 100644 --- a/src/helper/haikuttf/hkbase.hpp +++ b/src/helper/haikuttf/hkbase.hpp @@ -14,6 +14,34 @@ typedef SOPHIST_int32 s32; typedef SOPHIST_uint32 u32; } +#define HK_PLATFORM_WIN (1) +#define HK_PLATFORM_LINUX (2) +#define HK_PLATFORM_MACOSX (3) + +#if defined( __WIN32__ ) || defined( _WIN32 ) || defined( _WIN64 ) +# define HK_PLATFORM HK_PLATFORM_WIN +#elif defined( __APPLE_CC__) || defined ( __APPLE__ ) +# define HK_PLATFORM HK_PLATFORM_MACOSX +#elif defined( LINUX ) || defined( __linux__ ) +# define HK_PLATFORM HK_PLATFORM_LINUX +#endif + +#if HK_PLATFORM == HK_PLATFORM_LINUX || HK_PLATFORM == HK_PLATFORM_MACOSX +#define HK_PLATFORM_UNIX +#endif + +#if HK_PLATFORM == HK_PLATFORM_WIN +#ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN +#endif +#include +#elif defined( HK_PLATFORM_UNIX ) +#include +#else +// Fallback to SDL mutex +#include +#endif + #include #include FT_FREETYPE_H #include FT_OUTLINE_H diff --git a/src/helper/haikuttf/hkfont.cpp b/src/helper/haikuttf/hkfont.cpp index 681784028..e6437afff 100644 --- a/src/helper/haikuttf/hkfont.cpp +++ b/src/helper/haikuttf/hkfont.cpp @@ -106,12 +106,15 @@ FT_Error hkFont::GlyphLoad( u16 ch, hkGlyph * cached, int want ) { return FT_Err_Invalid_Handle; face = mFace; - + + mFm->MutexLock(); + if ( !cached->Index() ) cached->Index( FT_Get_Char_Index( face, ch ) ); - + + error = FT_Load_Glyph( face, cached->Index(), FT_LOAD_DEFAULT | mHinting ); - + if( error ) return error; @@ -255,6 +258,8 @@ FT_Error hkFont::GlyphLoad( u16 ch, hkGlyph * cached, int want ) { FT_Done_Glyph( bitmap_glyph ); } } + + mFm->MutexUnlock(); cached->Cached( ch ); diff --git a/src/helper/haikuttf/hkfontmanager.cpp b/src/helper/haikuttf/hkfontmanager.cpp index 29b0551e5..26f868dc4 100644 --- a/src/helper/haikuttf/hkfontmanager.cpp +++ b/src/helper/haikuttf/hkfontmanager.cpp @@ -33,8 +33,9 @@ int hkFontManager::Init() { void hkFontManager::Destroy() { if ( mInitialized ) { - if ( --mInitialized == 0 ) + if ( --mInitialized == 0 ) { FT_Done_FreeType( mLibrary ); + } } } @@ -56,17 +57,21 @@ void hkFontManager::CloseFont( hkFont * Font ) { } hkFont * hkFontManager::OpenFromMemory( const u8* data, unsigned long size, int ptsize, long index, unsigned int glyphCacheSize ) { - if ( Init() != 0) + if ( Init() != 0 ) return NULL; FT_Face face = NULL; - + + MutexLock(); + if ( FT_New_Memory_Face( mLibrary, reinterpret_cast(data), static_cast(size), index, &face ) != 0 ) return NULL; if ( FT_Select_Charmap( face, FT_ENCODING_UNICODE ) != 0 ) return NULL; - + + MutexUnlock(); + hkFont * Font = new hkFont( this, glyphCacheSize ); Font->Face( face ); @@ -79,7 +84,9 @@ hkFont * hkFontManager::OpenFromFile( const char* filename, int ptsize, long ind return NULL; FT_Face face; - + + MutexLock(); + if ( FT_New_Face( mLibrary, filename, index, &face ) != 0 ) return NULL; @@ -87,6 +94,8 @@ hkFont * hkFontManager::OpenFromFile( const char* filename, int ptsize, long ind if ( FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0 ) return NULL; + MutexUnlock(); + hkFont * Font = new hkFont( this, glyphCacheSize ); Font->Face( face ); @@ -102,12 +111,19 @@ hkFont * hkFontManager::FontPrepare( hkFont * font, int ptsize ) { face = font->Face(); if ( FT_IS_SCALABLE( face ) ) { + MutexLock(); + error = FT_Set_Char_Size( font->Face(), 0, ptsize * 64, 0, 0 ); - + if( error ) { CloseFont( font ); + + MutexUnlock(); + return NULL; } + + MutexUnlock(); scale = face->size->metrics.y_scale; font->Ascent( FT_CEIL( FT_MulFix( face->ascender, scale) ) ); @@ -152,4 +168,12 @@ hkFont * hkFontManager::FontPrepare( hkFont * font, int ptsize ) { return font; } +void hkFontManager::MutexLock() { + Lock(); +} + +void hkFontManager::MutexUnlock() { + Unlock(); +} + } diff --git a/src/helper/haikuttf/hkfontmanager.hpp b/src/helper/haikuttf/hkfontmanager.hpp index 3932403fe..d13fde38d 100644 --- a/src/helper/haikuttf/hkfontmanager.hpp +++ b/src/helper/haikuttf/hkfontmanager.hpp @@ -4,10 +4,11 @@ #include "hkbase.hpp" #include "hkglyph.hpp" #include "hkfont.hpp" +#include "hkmutex.hpp" namespace HaikuTTF { -class hkFontManager { +class hkFontManager : private hkMutex { static hkFontManager * mSingleton; public: static hkFontManager * instance() { @@ -42,12 +43,18 @@ class hkFontManager { FT_Library Library() const { return mLibrary; } protected: + friend class hkFont; + FT_Library mLibrary; int mInitialized; hkFont * FontPrepare( hkFont * font, int ptsize ); + + void MutexLock(); + + void MutexUnlock(); private: - + //SDL_mutex * mMutex; }; } diff --git a/src/helper/haikuttf/hkmutex.cpp b/src/helper/haikuttf/hkmutex.cpp new file mode 100644 index 000000000..1f67d146f --- /dev/null +++ b/src/helper/haikuttf/hkmutex.cpp @@ -0,0 +1,48 @@ +#include "hkmutex.hpp" + +namespace HaikuTTF { + +hkMutex::hkMutex() { + #if HK_PLATFORM == HK_PLATFORM_WIN + InitializeCriticalSection(&mMutex); + #elif defined( HK_PLATFORM_UNIX ) + pthread_mutex_init(&mMutex, NULL); + #else + mMutex = SDL_CreateMutex(); + #endif +} + +hkMutex::~hkMutex() { + #if HK_PLATFORM == HK_PLATFORM_WIN + DeleteCriticalSection(&mMutex); + #elif defined( HK_PLATFORM_UNIX ) + pthread_mutex_destroy(&mMutex); + #else + SDL_DestroyMutex(mMutex); + #endif +} + +void hkMutex::Lock() { + #if HK_PLATFORM == HK_PLATFORM_WIN + EnterCriticalSection(&mMutex); + #elif defined( HK_PLATFORM_UNIX ) + pthread_mutex_lock(&mMutex); + #else + SDL_LockMutex(mMutex) + #endif +} + +void hkMutex::Unlock() { + #if HK_PLATFORM == HK_PLATFORM_WIN + LeaveCriticalSection(&mMutex); + #elif defined( HK_PLATFORM_UNIX ) + pthread_mutex_unlock(&mMutex); + #else + SDL_UnlockMutex(mMutex) + #endif +} + +} + + + diff --git a/src/helper/haikuttf/hkmutex.hpp b/src/helper/haikuttf/hkmutex.hpp new file mode 100644 index 000000000..5d61bdea1 --- /dev/null +++ b/src/helper/haikuttf/hkmutex.hpp @@ -0,0 +1,28 @@ +#ifndef HAIKUTTF_HKMUTEX_HPP +#define HAIKUTTF_HKMUTEX_HPP + +#include "hkbase.hpp" + +namespace HaikuTTF { + +class hkMutex { + public: + hkMutex(); + + ~hkMutex(); + + void Lock(); + + void Unlock(); + protected: + #if HK_PLATFORM == HK_PLATFORM_WIN + CRITICAL_SECTION mMutex; + #elif defined( HK_PLATFORM_UNIX ) + pthread_mutex_t mMutex; + #else + SDL_mutex * mMutex; + #endif +}; + +} +#endif diff --git a/src/system/cmutex.cpp b/src/system/cmutex.cpp index 4ad4793d6..89a49cab2 100755 --- a/src/system/cmutex.cpp +++ b/src/system/cmutex.cpp @@ -11,17 +11,11 @@ cMutex::~cMutex() { } bool cMutex::Lock() { - int ret = SDL_LockMutex(mMutex); - if (ret == 0) - return true; - return false; + return 0 == SDL_LockMutex(mMutex); } bool cMutex::Unlock() { - int ret = SDL_UnlockMutex(mMutex); - if (ret == 0) - return true; - return false; + return 0 == SDL_UnlockMutex(mMutex); } }} diff --git a/src/test/ee.cpp b/src/test/ee.cpp index e88af966d..3ac3f0546 100644 --- a/src/test/ee.cpp +++ b/src/test/ee.cpp @@ -100,6 +100,8 @@ class cEETest : private cThread { cTextureFont * FF; cTextureFont * FF2; cTTFFont * TTF; + cTTFFont * TTFB; + cPrimitives PR; bool iL1, iL2; eeFloat HWidth, HHeight; @@ -166,7 +168,7 @@ class cEETest : private cThread { eeInt mHeight; std::wstring mBuda; - cTextCache * mBudaTC; + cTextCache mBudaTC; bool mTextureLoaded; cResourceLoader mResLoad; @@ -185,8 +187,6 @@ class cEETest : private cThread { eeFloat mAxisX; eeFloat mAxisY; - Uint32 mFace; - cTextureGroupLoader * mTGL; cSprite mBlindy; @@ -203,6 +203,8 @@ class cEETest : private cThread { cUIProgressBar * mProgressBar; cTextCache mEEText; + cTextCache mFBOText; + cTextCache mInfoText; }; void cEETest::CreateAquaTextureAtlas() { @@ -245,8 +247,6 @@ void cEETest::Init() { MyPath = AppPath(); - CreateAquaTextureAtlas(); - cIniFile Ini( MyPath + "data/ee.ini" ); Ini.ReadFile(); @@ -284,10 +284,10 @@ void cEETest::Init() { SetRandomSeed(); - LoadFonts(); - LoadTextures(); + LoadFonts(); + CreateShaders(); if ( Mus.OpenFromPack( &PAK, "music.ogg" ) ) { @@ -317,7 +317,7 @@ void cEETest::Init() { mFB->ClearColor( eeColorAf( 0, 0, 0, 0.5f ) ); - eePolygon2f Poly = CreateRoundedPolygon( 0.f, 0.f, 250.f, 50.f ); + eePolygon2f Poly = CreateRoundedPolygon( 0.f, 0.f, 256.f, 50.f ); mVBO = cVertexBuffer::Create( VERTEX_FLAG_GET( VERTEX_FLAG_POSITION ) | VERTEX_FLAG_GET( VERTEX_FLAG_COLOR ), DM_POLYGON ); @@ -337,16 +337,21 @@ void cEETest::Init() { } void cEETest::LoadFonts() { + mFontLoader.Add( eeNew( cTTFFontLoader, ( "arialb", &PAK, "arial.ttf", 12, EE_TTF_STYLE_NORMAL, false, 256, eeColor(255,255,255), 1, eeColor(0,0,0), true ) ) ); + mFontLoader.Add( eeNew( cTTFFontLoader, ( "arial", &PAK, "arial.ttf", 12, EE_TTF_STYLE_NORMAL, false, 256, eeColor(255,255,255) ) ) ); mFontLoader.Add( eeNew( cTextureFontLoader, ( "conchars", eeNew( cTextureLoader, ( &PAK, "conchars.png", false, eeRGB(0,0,0) ) ), (eeUint)32 ) ) ); mFontLoader.Add( eeNew( cTextureFontLoader, ( "ProggySquareSZ", eeNew( cTextureLoader, ( &PAK, "ProggySquareSZ.png" ) ), &PAK, "ProggySquareSZ.dat" ) ) ); - mFontLoader.Add( eeNew( cTTFFontLoader, ( "arial", &PAK, "arial.ttf", 12, EE_TTF_STYLE_NORMAL, false, 256, eeColor(255,255,255), 1, eeColor(0,0,0), true ) ) ); + mFontLoader.Load( cb::Make1( this, &cEETest::OnFontLoaded ) ); } void cEETest::OnFontLoaded( cResourceLoader * ObjLoaded ) { - FF = reinterpret_cast ( cFontManager::instance()->GetByName( "conchars" ) ); - FF2 = reinterpret_cast ( cFontManager::instance()->GetByName( "ProggySquareSZ" ) ); - TTF = reinterpret_cast ( cFontManager::instance()->GetByName( "arial" ) ); + FF = reinterpret_cast ( cFontManager::instance()->GetByName( "conchars" ) ); + FF2 = reinterpret_cast ( cFontManager::instance()->GetByName( "ProggySquareSZ" ) ); + TTF = reinterpret_cast ( cFontManager::instance()->GetByName( "arial" ) ); + TTFB = reinterpret_cast ( cFontManager::instance()->GetByName( "arialb" ) ); + + eeASSERT( TTFB != NULL ); Con.Create( FF, true ); Con.IgnoreCharOnPrompt( 186 ); // L'º' @@ -369,6 +374,7 @@ void cEETest::CreateShaders() { void cEETest::CreateUI() { cUIManager::instance()->Init(); + cUIThemeManager::instance()->DefaultFont( TTF ); cUIControl::CreateParams Params( cUIManager::instance()->MainControl(), eeVector2i(0,0), eeSize( 320, 240 ), UI_FILL_BACKGROUND | UI_CLIP_ENABLE | UI_BORDER ); @@ -422,7 +428,6 @@ void cEETest::CreateUI() { TextParams.PosSet( 0, 0 ); TextParams.Size = eeSize( 320, 240 ); TextParams.Flags = UI_VALIGN_TOP | UI_HALIGN_RIGHT; - TextParams.Font = TTF; cUITextBox * Text = eeNew( cUITextBox, ( TextParams ) ); Text->Visible( true ); Text->Enabled( false ); @@ -436,16 +441,18 @@ void cEETest::CreateUI() { InputParams.PosSet( 20, 216 ); InputParams.Size = eeSize( 200, 22 ); InputParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_LEFT | UI_CLIP_ENABLE; // | UI_BORDER | UI_FILL_BACKGROUND - InputParams.Font = TTF; cUITextInput * Input = eeNew( cUITextInput, ( InputParams ) ); - Input->Padding( eeRectf( 4, -2, -8, 0 ) ); + Input->Padding( eeRectf( 4, -2, 8, 0 ) ); Input->Visible( true ); Input->Enabled( true ); - TextParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_CENTER; - TextParams.PosSet( 230, 216 ); - TextParams.Size = eeSize( 80, 22 ); - cUIPushButton * Button = eeNew( cUIPushButton, ( TextParams ) ); + cUIPushButton::CreateParams ButtonParams; + ButtonParams.Parent( C ); + ButtonParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_CENTER; + ButtonParams.PosSet( 225, 216 ); + ButtonParams.Size = eeSize( 90, 22 ); + ButtonParams.SetIcon( cGlobalShapeGroup::instance()->GetByName( "aqua_button_ok" ) ); + cUIPushButton * Button = eeNew( cUIPushButton, ( ButtonParams ) ); Button->Visible( true ); Button->Enabled( true ); Button->Text( L"Click Me" ); @@ -453,6 +460,7 @@ void cEETest::CreateUI() { Button->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cEETest::ButtonClick ) ); TextParams.PosSet( 120, 20 ); + TextParams.Size = eeSize( 80, 22 ); TextParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_LEFT; cUICheckBox * Checkbox = eeNew( cUICheckBox, ( TextParams ) ); Checkbox->Visible( true ); @@ -496,7 +504,6 @@ void cEETest::CreateUI() { SpinBoxParams.PosSet( 80, 150 ); SpinBoxParams.Size = eeSize( 80, 24 ); SpinBoxParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_LEFT | UI_CLIP_ENABLE; - SpinBoxParams.Font = TTF; SpinBoxParams.AllowDotsInNumbers = true; cUISpinBox * mSpinBox = eeNew( cUISpinBox, ( SpinBoxParams ) ); mSpinBox->Visible( true ); @@ -517,9 +524,8 @@ void cEETest::CreateUI() { cUIProgressBar::CreateParams PBParams; PBParams.Parent( C ); PBParams.PosSet( 20, 197 ); - PBParams.Size = eeSize( 150, 16 ); + PBParams.Size = eeSize( 200, 16 ); PBParams.DisplayPercent = true; - PBParams.Font = TTF; mProgressBar = eeNew( cUIProgressBar, ( PBParams ) ); mProgressBar->Visible( true ); mProgressBar->Enabled( true ); @@ -530,21 +536,24 @@ void cEETest::CreateUI() { mTextBoxValue->Visible( true ); mBuda = L"El mono ve el pez en el agua y sufre. Piensa que su mundo es el único que existe, el mejor, el real. Sufre porque es bueno y tiene compasión, lo ve y piensa: \"Pobre se está ahogando no puede respirar\". Y lo saca, lo saca y se queda tranquilo, por fin lo salvé. Pero el pez se retuerce de dolor y muere. Por eso te mostré el sueño, es imposible meter el mar en tu cabeza, que es un balde."; - TTF->ShrinkText( mBuda, 400 ); + TTFB->ShrinkText( mBuda, 400 ); - //cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_normal.png" ), "aqua_textinput_normal" ) ) ); - //cUIThemeManager::instance()->Add( cUITheme::LoadFromPath( MyPath + "data/aqua/", "aqua", "aqua" ) ); + cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_normal.png" ), "aqua_textinput_normal" ) ) ); + cUIThemeManager::instance()->Add( cUITheme::LoadFromPath( MyPath + "data/aqua/", "aqua", "aqua" ) ); +/* + CreateAquaTextureAtlas(); cTextureGroupLoader tgl( MyPath + "data/aqua.etg" ); - TF->GetByName( "data/aqua.png" )->ClampMode( EE_CLAMP_REPEAT ); TF->GetByName( "data/aqua.png" )->TextureFilter( TEX_FILTER_NEAREST ); cUIThemeManager::instance()->Add( cUITheme::LoadFromShapeGroup( cShapeGroupManager::instance()->GetByName( "aqua" ), "aqua", "aqua" ) ); +*/ cUIManager::instance()->SetTheme( "aqua" ); - mBudaTC = eeNew( cTextCache, ( TTF, mBuda, eeColorA(255,255,255,255) ) ); - - mEEText.Create( TTF, L"Entropia Engine++\nCTRL + 1 = Screen 1 - CTRL + 2 = Screen 2\nCTRL + 3 = Screen 3" ); + mBudaTC.Create( TTFB, mBuda, eeColorA(255,255,255,255) ); + mEEText.Create( TTFB, L"Entropia Engine++\nCTRL + 1 = Screen 1 - CTRL + 2 = Screen 2\nCTRL + 3 = Screen 3" ); + mFBOText.Create( TTFB, L"This is a VBO\nInside of a FBO" ); + mInfoText.Create( FF, L"", eeColorA(255,255,255,150) ); } void cEETest::OnValueChange( const cUIEvent * Event ) { @@ -632,32 +641,6 @@ void cEETest::LoadTextures() { eeInt w, h; - mFace = TF->LoadFromPack( &PakTest, "adjutantportrait_l_static.dds" ); - /** // DDS Lock/Unlock Test - cTexture * mFacePtr = TF->GetTexture( mFace ); - - if ( NULL != mFacePtr ) { - w = (eeInt)mFacePtr->Width(); - h = (eeInt)mFacePtr->Height(); - - mFacePtr->Lock(); - - for ( y = 0; y < h; y++ ) { - for ( x = 0; x < w; x++ ) { - eeColorA tempC = mFacePtr->GetPixel( x, y ); - - tempC.Red = std::min( tempC.Red + 50, 255 ); - tempC.Green = std::min( tempC.Green + 50, 255 ); - tempC.Blue = std::min( tempC.Blue + 50, 255 ); - - eeColorA newC( tempC.R(), tempC.G(), tempC.B(), 255 ); - mFacePtr->SetPixel( x, y, newC ); - } - } - - mFacePtr->Unlock(false,true); - }*/ - for ( Int32 my = 0; my < 4; my++ ) for( Int32 mx = 0; mx < 8; mx++ ) SP.AddFrame( TN[4], 0, 0, 0, 0, eeRecti( mx * 64, my * 64, mx * 64 + 64, my * 64 + 64 ) ); @@ -717,6 +700,8 @@ void cEETest::LoadTextures() { TreeTilingCreated = false; CreateTiling(Wireframe); + + cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_button_ok.png" ), "aqua_button_ok" ) ) ); } void cEETest::RandomizeHeights() { @@ -981,6 +966,8 @@ void cEETest::Render() { SizeToString( TF->MemorySize() ).c_str() ); #endif + + mInfoText.Text( mInfo ); } if ( !MultiViewportMode ) { @@ -1019,14 +1006,10 @@ void cEETest::Render() { mEEText.GetTextHeight(), ColRR1, ColRR2, ColRR3, ColRR4 ); - + mEEText.Draw( 0.f, (eeFloat)EE->GetHeight() - mEEText.GetTextHeight(), FONT_DRAW_CENTER, 1.f, Ang ); - - FF->Color( eeColorA(255,255,255,200) ); - FF->Draw( mInfo, 6, 6 ); - - FF2->SetText( InBuf.Buffer() ); - FF2->Draw( 6, 180, FONT_DRAW_SHADOW ); + mInfoText.Draw( 6.f, 6.f ); + mBudaTC.Draw( 5.f, 60.f ); Uint32 NLPos = 0; Uint32 LineNum = InBuf.GetCurPosLinePos( NLPos ); @@ -1037,14 +1020,11 @@ void cEETest::Render() { FF2->Draw( L"_", 6.f + FF2->GetTextWidth(), 180.f + (eeFloat)LineNum * (eeFloat)FF2->GetFontSize() ); } - mBudaTC->Draw( 5.f, 50.f ); -/* - cTexture * TexFace = TF->GetTexture( mFace ); - if ( TexFace ) - TexFace->Draw( (eeFloat)EE->GetWidth() - (eeFloat)TexFace->Width() , (eeFloat)EE->GetHeight() - (eeFloat)TexFace->Height(), 0.f, 1.f, eeColorA(), ALPHA_DESTALPHA, RN_MIRROR ); -*/ FF2->SetText( L"FPS: " + toWStr( EE->FPS() ) ); FF2->Draw( EE->GetWidth() - FF2->GetTextWidth() - 15, 0 ); + + FF2->SetText( InBuf.Buffer() ); + FF2->Draw( 6, 180, FONT_DRAW_SHADOW ); if ( NULL != mFB ) { mFB->Bind(); @@ -1055,6 +1035,8 @@ void cEETest::Render() { mVBO->Bind(); mVBO->Draw(); mVBO->Unbind(); + + mFBOText.Draw( 128.f - (eeFloat)(Int32)( mFBOText.GetTextWidth() * 0.5f ), 25.f - (eeFloat)(Int32)( mFBOText.GetTextHeight() * 0.5f ), FONT_DRAW_CENTER ); mFB->Unbind(); @@ -1316,7 +1298,6 @@ void cEETest::End() { eeSAFE_DELETE( mTGL ); eeSAFE_DELETE( mFB ); eeSAFE_DELETE( mVBO ); - eeSAFE_DELETE( mBudaTC ); cLog::instance()->Save(); diff --git a/src/ui/cuicontrol.cpp b/src/ui/cuicontrol.cpp index 6c31e5551..377ed7483 100644 --- a/src/ui/cuicontrol.cpp +++ b/src/ui/cuicontrol.cpp @@ -306,9 +306,7 @@ Uint32 cUIControl::OnFocus() { Uint32 cUIControl::OnFocusLoss() { SendCommonEvent( cUIEvent::EventOnFocusLoss ); - - SetSkinState( cUISkinState::StateLostFocus ); - + return 1; } diff --git a/src/ui/cuigfx.cpp b/src/ui/cuigfx.cpp index 20a5c9f14..df6b33518 100644 --- a/src/ui/cuigfx.cpp +++ b/src/ui/cuigfx.cpp @@ -8,9 +8,6 @@ cUIGfx::cUIGfx( const cUIGfx::CreateParams& Params ) : mColor( Params.ShapeColor ), mRender( Params.ShapeRender ) { - if ( NULL == mShape) - Close(); - mType |= UI_TYPE_GET(UI_TYPE_GFX); if ( NULL != mShape && ( ( Flags() & UI_AUTO_SIZE ) || ( Params.Size.x == -1 && Params.Size.y == -1 ) ) ) @@ -25,6 +22,13 @@ cUIGfx::cUIGfx( const cUIGfx::CreateParams& Params ) : cUIGfx::~cUIGfx() { } +void cUIGfx::Shape( cShape * shape ) { + mShape = shape; + + if ( NULL != mShape && ( ( Flags() & UI_AUTO_SIZE ) ) ) + Size( mShape->Size() ); +} + void cUIGfx::Draw() { cUIControlAnim::Draw(); diff --git a/src/ui/cuigfx.hpp b/src/ui/cuigfx.hpp index 0ba99d964..fce684c95 100644 --- a/src/ui/cuigfx.hpp +++ b/src/ui/cuigfx.hpp @@ -32,6 +32,8 @@ class EE_API cUIGfx : public cUIControlAnim { cShape * Shape() const; + void Shape( cShape * shape ); + const eeRGBA& Color() const; void Color( const eeRGBA& color ); diff --git a/src/ui/cuiprogressbar.cpp b/src/ui/cuiprogressbar.cpp index e1d2649fb..531c03940 100644 --- a/src/ui/cuiprogressbar.cpp +++ b/src/ui/cuiprogressbar.cpp @@ -12,6 +12,8 @@ cUIProgressBar::cUIProgressBar( const cUIProgressBar::CreateParams& Params ) : mTotalSteps( 100.f ), mParallax( NULL ) { + mType |= UI_TYPE_GET(UI_TYPE_PROGRESSBAR); + cUITextBox::CreateParams TxtBoxParams = Params; TxtBoxParams.Parent( this ); diff --git a/src/ui/cuipushbutton.cpp b/src/ui/cuipushbutton.cpp index d892c2ea1..0af7d7904 100644 --- a/src/ui/cuipushbutton.cpp +++ b/src/ui/cuipushbutton.cpp @@ -2,10 +2,39 @@ namespace EE { namespace UI { -cUIPushButton::cUIPushButton( const cUITextBox::CreateParams& Params ) : - cUITextBox( Params ) +cUIPushButton::cUIPushButton( const cUIPushButton::CreateParams& Params ) : + cUIControlAnim( Params ), + mIcon( NULL ), + mTextBox( NULL ), + mIconSpace( Params.IconHorizontalMargin ) { mType |= UI_TYPE_GET(UI_TYPE_PUSHBUTTON); + + cUIGfx::CreateParams GfxParams; + GfxParams.Parent( this ); + GfxParams.Shape = Params.Icon; + GfxParams.Flags = UI_AUTO_SIZE; + mIcon = eeNew( cUIGfx, ( GfxParams ) ); + mIcon->Visible( true ); + mIcon->Enabled( false ); + + Icon( Params.Icon ); + + cUITextBox::CreateParams TxtParams = Params; + TxtParams.Parent( this ); + TxtParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_CENTER; + mTextBox = eeNew( cUITextBox, ( TxtParams ) ); + mTextBox->Visible( true ); + mTextBox->Enabled( false ); + + OnSizeChange(); +} + +void cUIPushButton::OnSizeChange() { + mTextBox->Size( mSize.Width(), mSize.Height() ); + mTextBox->Pos( 0, 0 ); + mIcon->Pos( mIconSpace, 0 ); + mIcon->CenterVertical(); } cUIPushButton::~cUIPushButton() { @@ -15,4 +44,45 @@ void cUIPushButton::SetTheme( cUITheme * Theme ) { cUIControl::SetTheme( Theme, "button" ); } +void cUIPushButton::Icon( cShape * Icon ) { + mIcon->Shape( Icon ); + mIcon->Pos( mIconSpace, 0 ); + mIcon->CenterVertical(); +} + +cUIGfx * cUIPushButton::Icon() const { + return mIcon; +} + +void cUIPushButton::Text( const std::wstring& text ) { + mTextBox->Text( text ); + OnSizeChange(); +} + +void cUIPushButton::Text( const std::string& text ) { + mTextBox->Text( text ); + OnSizeChange(); +} + +void cUIPushButton::Padding( const eeRectf& padding ) { + mTextBox->Padding( padding ); +} + +const eeRectf& cUIPushButton::Padding() const { + return mTextBox->Padding(); +} + +void cUIPushButton::IconHorizontalMargin( Int32 margin ) { + mIconSpace = margin; + OnSizeChange(); +} + +const Int32& cUIPushButton::IconHorizontalMargin() const { + return mIconSpace; +} + +cUITextBox * cUIPushButton::TextBox() const { + return mTextBox; +} + }} diff --git a/src/ui/cuipushbutton.hpp b/src/ui/cuipushbutton.hpp index feeeab7af..2e1a69134 100644 --- a/src/ui/cuipushbutton.hpp +++ b/src/ui/cuipushbutton.hpp @@ -2,18 +2,63 @@ #define EE_UICUIPUSHBUTTON_HPP #include "cuitextbox.hpp" +#include "cuigfx.hpp" namespace EE { namespace UI { -class EE_API cUIPushButton : public cUITextBox { +class EE_API cUIPushButton : public cUIControlAnim { public: - cUIPushButton( const cUITextBox::CreateParams& Params ); + class CreateParams : public cUITextBox::CreateParams { + public: + inline CreateParams() : + cUITextBox::CreateParams(), + Icon( NULL ), + IconHorizontalMargin( 0 ) + { + } + + inline ~CreateParams() {} + + cShape * Icon; + + inline void SetIcon( cShape * icon ) { + Icon = icon; + + if ( !IconHorizontalMargin ) + IconHorizontalMargin = 4; + } + + Int32 IconHorizontalMargin; + }; + cUIPushButton( const cUIPushButton::CreateParams& Params ); ~cUIPushButton(); virtual void SetTheme( cUITheme * Theme ); - protected: + + void Icon( cShape * Icon ); + + cUIGfx * Icon() const; + + void Text( const std::wstring& text ); + void Text( const std::string& text ); + + void Padding( const eeRectf& padding ); + + const eeRectf& Padding() const; + + void IconHorizontalMargin( Int32 margin ); + + const Int32& IconHorizontalMargin() const; + + cUITextBox * TextBox() const; + protected: + cUIGfx * mIcon; + cUITextBox * mTextBox; + Int32 mIconSpace; + + virtual void OnSizeChange(); }; }} diff --git a/src/ui/cuiskin.cpp b/src/ui/cuiskin.cpp index 3917918ce..a9e3bfcc3 100644 --- a/src/ui/cuiskin.cpp +++ b/src/ui/cuiskin.cpp @@ -5,7 +5,7 @@ namespace EE { namespace UI { const char * UISkinStatesNames[] = { "normal", "focus", - "unfocus", + "selected", "menter", "mexit", "mdown" diff --git a/src/ui/cuiskinstate.hpp b/src/ui/cuiskinstate.hpp index ccfb89780..5bbeffc3b 100644 --- a/src/ui/cuiskinstate.hpp +++ b/src/ui/cuiskinstate.hpp @@ -12,7 +12,7 @@ class cUISkinState { enum UISkinStates { StateNormal = 0, StateFocus, - StateLostFocus, + StateSelected, StateMouseEnter, StateMouseExit, StateMouseDown, diff --git a/src/ui/cuispinbox.cpp b/src/ui/cuispinbox.cpp index 943d2a499..9fbfc407e 100644 --- a/src/ui/cuispinbox.cpp +++ b/src/ui/cuispinbox.cpp @@ -141,6 +141,8 @@ void cUISpinBox::InternalValue( const eeFloat& Val, const bool& Force ) { } mValue = Val; + + mInput->GetInputTextBuffer()->ChangedSinceLastUpdate( false ); OnValueChange(); } diff --git a/src/ui/cuitextbox.cpp b/src/ui/cuitextbox.cpp index b77ae2f6e..1d4207839 100644 --- a/src/ui/cuitextbox.cpp +++ b/src/ui/cuitextbox.cpp @@ -1,5 +1,6 @@ #include "cuitextbox.hpp" #include "cuimanager.hpp" +#include "cuithememanager.hpp" namespace EE { namespace UI { @@ -9,11 +10,17 @@ cUITextBox::cUITextBox( const cUITextBox::CreateParams& Params ) : mFontShadowColor( Params.FontShadowColor ), mAlignOffset( 0.f, 0.f ) { + mType |= UI_TYPE_GET(UI_TYPE_TEXTBOX); + mTextCache.Font( Params.Font ); mTextCache.Color( mFontColor ); mTextCache.ShadowColor( mFontShadowColor ); - - mType |= UI_TYPE_GET(UI_TYPE_TEXTBOX); + + if ( NULL == Params.Font && NULL != cUIThemeManager::instance()->DefaultFont() ) { + mTextCache.Font( cUIThemeManager::instance()->DefaultFont() ); + } else { + eePRINT( "cUITextBox::cUITextBox : Created a UI TextBox without a defined font." ); + } AutoAlign(); } @@ -27,7 +34,7 @@ void cUITextBox::Draw() { if ( mTextCache.GetTextWidth() ) { if ( IsClipped() ) - cUIManager::instance()->ClipEnable( mScreenPos.x + (Int32)mPadding.Left, mScreenPos.y + (Int32)mPadding.Top, mSize.Width() + (Int32)mPadding.Right, mSize.Height() + (Int32)mPadding.Bottom ); + cUIManager::instance()->ClipEnable( mScreenPos.x + (Int32)mPadding.Left, mScreenPos.y + (Int32)mPadding.Top, mSize.Width() - (Int32)mPadding.Right, mSize.Height() - (Int32)mPadding.Bottom ); mTextCache.Draw( (eeFloat)mScreenPos.x + mAlignOffset.x + mPadding.Left + 1.f, (eeFloat)mScreenPos.y + mAlignOffset.y + mPadding.Top, Flags(), 1.f, 0.f, mBlend ); @@ -154,4 +161,12 @@ const eeRectf& cUITextBox::Padding() const { return mPadding; } +void cUITextBox::SetTheme( cUITheme * Theme ) { + cUIControlAnim::SetTheme( Theme ); + + if ( NULL == mTextCache.Font() && NULL != Theme->DefaultFont() ) { + mTextCache.Font( Theme->DefaultFont() ); + } +} + }} diff --git a/src/ui/cuitextbox.hpp b/src/ui/cuitextbox.hpp index 764efca16..af903a8ff 100644 --- a/src/ui/cuitextbox.hpp +++ b/src/ui/cuitextbox.hpp @@ -11,7 +11,9 @@ class EE_API cUITextBox : public cUIControlAnim { public: inline CreateParams() : cUIControl::CreateParams(), - Font( NULL ) + Font( NULL ), + FontColor( 0, 0, 0, 255 ), + FontShadowColor( 255, 255, 255, 150 ) { } @@ -55,6 +57,8 @@ class EE_API cUITextBox : public cUIControlAnim { virtual void Padding( const eeRectf& padding ); const eeRectf& Padding() const; + + virtual void SetTheme( cUITheme * Theme ); protected: cTextCache mTextCache; eeColorA mFontColor; diff --git a/src/ui/cuitextinput.cpp b/src/ui/cuitextinput.cpp index 9825b5f61..7abb41cdf 100644 --- a/src/ui/cuitextinput.cpp +++ b/src/ui/cuitextinput.cpp @@ -128,8 +128,8 @@ void cUITextInput::AlignFix() { if ( tX < 0.f ) mAlignOffset.x = -( mAlignOffset.x + ( tW - mAlignOffset.x ) ); - else if ( tX > mSize.Width() + mPadding.Right ) - mAlignOffset.x = mSize.Width() + mPadding.Right - ( mAlignOffset.x + ( tW - mAlignOffset.x ) ); + else if ( tX > mSize.Width() - mPadding.Right ) + mAlignOffset.x = mSize.Width() - mPadding.Right - ( mAlignOffset.x + ( tW - mAlignOffset.x ) ); } diff --git a/src/ui/cuitheme.cpp b/src/ui/cuitheme.cpp index ab5113d81..79432cf67 100644 --- a/src/ui/cuitheme.cpp +++ b/src/ui/cuitheme.cpp @@ -203,11 +203,12 @@ bool cUITheme::SearchFilesOfElement( cShapeGroup * SG, const std::string& Path, return Found; } -cUITheme::cUITheme( const std::string& Name, const std::string& Abbr ) : +cUITheme::cUITheme( const std::string& Name, const std::string& Abbr, cFont * DefaultFont ) : tResourceManager ( false ), mName( Name ), mNameHash( MakeHash( mName ) ), - mAbbr( Abbr ) + mAbbr( Abbr ), + mFont( DefaultFont ) { } @@ -238,4 +239,12 @@ cUISkin * cUITheme::Add( cUISkin * Resource ) { return tResourceManager::Add( Resource ); } +void cUITheme::DefaultFont( cFont * Font ) { + mFont = Font; +} + +cFont * cUITheme::DefaultFont() const { + return mFont; +} + }} diff --git a/src/ui/cuitheme.hpp b/src/ui/cuitheme.hpp index 0d489d450..f22ba17d0 100644 --- a/src/ui/cuitheme.hpp +++ b/src/ui/cuitheme.hpp @@ -3,6 +3,7 @@ #include "base.hpp" #include "../graphics/cshapegroup.hpp" +#include "../graphics/cfont.hpp" #include "cuiskin.hpp" namespace EE { namespace UI { @@ -13,7 +14,7 @@ class EE_API cUITheme : public tResourceManager { static cUITheme * LoadFromShapeGroup( cShapeGroup * ShapeGroup, const std::string& Name, const std::string NameAbbr ); - cUITheme( const std::string& Name, const std::string& Abbr ); + cUITheme( const std::string& Name, const std::string& Abbr, cFont * DefaultFont = NULL ); virtual ~cUITheme(); @@ -26,11 +27,15 @@ class EE_API cUITheme : public tResourceManager { const std::string& Abbr() const; virtual cUISkin * Add( cUISkin * Resource ); + + void DefaultFont( cFont * Font ); + + cFont * DefaultFont() const; protected: std::string mName; Uint32 mNameHash; - std::string mAbbr; + cFont * mFont; private: static bool SearchFilesOfElement( cShapeGroup * SG, const std::string& Path, std::string Element, Uint32& IsComplex, const std::string ImgExt ); diff --git a/src/ui/cuithememanager.cpp b/src/ui/cuithememanager.cpp index fc020a4d2..9a32aad12 100644 --- a/src/ui/cuithememanager.cpp +++ b/src/ui/cuithememanager.cpp @@ -3,7 +3,8 @@ namespace EE { namespace UI { cUIThemeManager::cUIThemeManager() : - tResourceManager( true ) + tResourceManager( true ), + mFont( NULL ) { } @@ -11,4 +12,12 @@ cUIThemeManager::~cUIThemeManager() { } +void cUIThemeManager::DefaultFont( cFont * Font ) { + mFont = Font; +} + +cFont * cUIThemeManager::DefaultFont() const { + return mFont; +} + }} diff --git a/src/ui/cuithememanager.hpp b/src/ui/cuithememanager.hpp index b9b955324..e7478a801 100644 --- a/src/ui/cuithememanager.hpp +++ b/src/ui/cuithememanager.hpp @@ -12,6 +12,12 @@ class EE_API cUIThemeManager : public tResourceManager, public tSingle cUIThemeManager(); virtual ~cUIThemeManager(); + + void DefaultFont( cFont * Font ); + + cFont * DefaultFont() const; + protected: + cFont * mFont; }; }} diff --git a/src/ui/uihelper.hpp b/src/ui/uihelper.hpp index 99672d821..7dda5e037 100644 --- a/src/ui/uihelper.hpp +++ b/src/ui/uihelper.hpp @@ -52,6 +52,7 @@ Uint32 EE_API VAlignGet( Uint32 Flags ); #define UI_TYPE_SLIDER (8) #define UI_TYPE_SPINBOX (9) #define UI_TYPE_SCROLLBAR (10) +#define UI_TYPE_PROGRESSBAR (11) #define UI_TYPE_GET(X) ( 1 << (X) ) diff --git a/src/window/cengine.cpp b/src/window/cengine.cpp index 6d5018150..7294132d0 100755 --- a/src/window/cengine.cpp +++ b/src/window/cengine.cpp @@ -11,6 +11,7 @@ #include "../ui/cuimanager.hpp" #include "../audio/caudiolistener.hpp" #include "../graphics/glhelper.hpp" +#include "../helper/haikuttf/hkfontmanager.hpp" using namespace EE::Graphics; using namespace EE::Graphics::Private; @@ -117,6 +118,8 @@ cEngine::~cEngine() { cLog::DestroySingleton(); + HaikuTTF::hkFontManager::DestroySingleton(); + SDL_Quit(); } diff --git a/src/window/cinputtextbuffer.cpp b/src/window/cinputtextbuffer.cpp index 3712e24b3..9ad3a0e08 100755 --- a/src/window/cinputtextbuffer.cpp +++ b/src/window/cinputtextbuffer.cpp @@ -160,6 +160,10 @@ bool cInputTextBuffer::ChangedSinceLastUpdate() { return mChangeSinceLastUpdate; } +void cInputTextBuffer::ChangedSinceLastUpdate( const bool& Changed ) { + mChangeSinceLastUpdate = Changed; +} + void cInputTextBuffer::SetAutoPromp( const bool& set ) { if ( set ) { mPromptAutoPos = true; diff --git a/src/window/cinputtextbuffer.hpp b/src/window/cinputtextbuffer.hpp index de6880bdb..64f527bd6 100755 --- a/src/window/cinputtextbuffer.hpp +++ b/src/window/cinputtextbuffer.hpp @@ -66,6 +66,9 @@ class EE_API cInputTextBuffer { /** @return If something changed since last update */ bool ChangedSinceLastUpdate(); + /** Set if changed since last update */ + void ChangedSinceLastUpdate( const bool& Changed ); + /** @return The Cursor Position (where is the cursor editing) */ eeInt CurPos() const;