From caa2dcc7456dda8d15af4287db35157414f97f0a Mon Sep 17 00:00:00 2001 From: spartanj Date: Wed, 13 Oct 2010 04:26:43 -0300 Subject: [PATCH] Added two theme loading functions to load themes from a folder path or a shape group. Added clamp repeat simulation for shape rendering. Another minor changes on the UI. --- ee.win.cbp | 10 ++ src/graphics/cshapegroup.cpp | 4 + src/graphics/cshapegroup.hpp | 2 + src/graphics/cshapegroupmanager.cpp | 13 +- src/graphics/ctexture.cpp | 46 ++++++- src/graphics/ctexturegrouploader.cpp | 27 +++- src/graphics/ctexturegrouploader.hpp | 5 +- src/system/tresourcemanager.hpp | 4 +- src/test/ee.cpp | 111 ++-------------- src/ui/cuicheckbox.cpp | 14 +- src/ui/cuicheckbox.hpp | 10 +- src/ui/cuiradiobutton.cpp | 14 +- src/ui/cuiradiobutton.hpp | 10 +- src/ui/cuiskincomplex.cpp | 6 + src/ui/cuiskincomplex.hpp | 2 + src/ui/cuislider.cpp | 10 +- src/ui/cuispinbox.cpp | 18 ++- src/ui/cuispinbox.hpp | 10 +- src/ui/cuitheme.cpp | 187 +++++++++++++++++++++++++++ src/ui/cuitheme.hpp | 10 ++ 20 files changed, 377 insertions(+), 136 deletions(-) diff --git a/ee.win.cbp b/ee.win.cbp index 40225013e..0bbafcaa9 100644 --- a/ee.win.cbp +++ b/ee.win.cbp @@ -509,6 +509,8 @@ + + @@ -529,12 +531,20 @@ + + + + + + + + diff --git a/src/graphics/cshapegroup.cpp b/src/graphics/cshapegroup.cpp index 27876f4cc..cb33cacb1 100644 --- a/src/graphics/cshapegroup.cpp +++ b/src/graphics/cshapegroup.cpp @@ -44,4 +44,8 @@ cShape * cShapeGroup::Add( const Uint32& TexId, const eeRecti& SrcRect, const ee return Add( eeNew ( cShape, ( TexId, SrcRect, DestWidth, DestHeight, OffsetX, OffsetY, Name ) ) ); } +Uint32 cShapeGroup::Count() { + return tResourceManager::Count(); +} + }} diff --git a/src/graphics/cshapegroup.hpp b/src/graphics/cshapegroup.hpp index 21601b69a..90945dfd5 100644 --- a/src/graphics/cshapegroup.hpp +++ b/src/graphics/cshapegroup.hpp @@ -29,6 +29,8 @@ class EE_API cShapeGroup : public tResourceManager { void Name( const std::string& name ); const Uint32& Id() const; + + Uint32 Count(); protected: std::string mName; Uint32 mId; diff --git a/src/graphics/cshapegroupmanager.cpp b/src/graphics/cshapegroupmanager.cpp index c38b83cc1..07280e3f3 100644 --- a/src/graphics/cshapegroupmanager.cpp +++ b/src/graphics/cshapegroupmanager.cpp @@ -13,16 +13,23 @@ cShapeGroupManager::~cShapeGroupManager() { } cShape * cShapeGroupManager::GetShapeByName( const std::string& Name ) { - return GetShapeById( MakeHash( Name ) ); + cShape * tShape = GetShapeById( MakeHash( Name ) ); + + eePRINTC( NULL == tShape, "cShapeGroupManager::GetShapeByName shape '%s' not found\n", Name.c_str() ); + + return tShape; } cShape * cShapeGroupManager::GetShapeById( const Uint32& Id ) { std::list::iterator it; - + + cShapeGroup * tSG = NULL; cShape * tShape = NULL; for ( it = mResources.begin(); it != mResources.end(); it++ ) { - tShape = (*it)->GetById( Id ); + tSG = (*it); + + tShape = tSG->GetById( Id ); if ( NULL != tShape ) return tShape; diff --git a/src/graphics/ctexture.cpp b/src/graphics/ctexture.cpp index 49307549b..8a90351a9 100755 --- a/src/graphics/ctexture.cpp +++ b/src/graphics/ctexture.cpp @@ -483,7 +483,51 @@ void cTexture::DrawEx( const eeFloat &x, const eeFloat &y, const eeFloat &width, if ( Effect <= 3 ) { if ( ClampMode() == EE_CLAMP_REPEAT ) { if ( Effect == RN_NORMAL ) - BR->QuadsSetSubsetFree( 0, 0, 0, height / h, width / w, height / h, width / w, 0 ); + if ( renderdiv ) { + BR->QuadsSetSubsetFree( Sector.Left / w, Sector.Top / h, Sector.Left / w, Sector.Bottom / h, Sector.Right / w, Sector.Bottom / h, Sector.Right / w, Sector.Top / h ); + + eeFloat sw = Sector.Right - Sector.Left; + eeFloat sh = Sector.Bottom - Sector.Top; + eeFloat tx = width / sw; + eeFloat ty = height / sh; + Int32 ttx = (Int32)tx; + Int32 tty = (Int32)ty; + Int32 tmpY; + Int32 tmpX; + + for ( tmpY = 0; tmpY < tty; tmpY++ ) { + for ( tmpX = 0; tmpX < ttx; tmpX++ ) { + BR->BatchQuad( mx + tmpX * sw, my + tmpY * sh, sw, sh ); + } + } + + if ( (eeFloat)ttx != tx ) { + eeFloat swn = ( Sector.Right - Sector.Left ) * ( tx - (eeFloat)ttx ); + eeFloat tor = Sector.Left + swn ; + + BR->QuadsSetSubsetFree( Sector.Left / w, Sector.Top / h, Sector.Left / w, Sector.Bottom / h, tor / w, Sector.Bottom / h, tor / w, Sector.Top / h ); + + for ( Int32 tmpY = 0; tmpY < tty; tmpY++ ) { + BR->BatchQuad( mx + ttx * sw, my + tmpY * sh, swn, sh ); + } + } + + if ( (eeFloat)tty != ty ) { + eeFloat shn = ( Sector.Bottom - Sector.Top ) * ( ty - (eeFloat)tty ); + eeFloat tob = Sector.Top + shn; + + BR->QuadsSetSubsetFree( Sector.Left / w, Sector.Top / h, Sector.Left / w, tob / h, Sector.Right / w, tob / h, Sector.Right / w, Sector.Top / h ); + + for ( Int32 tmpX = 0; tmpX < ttx; tmpX++ ) { + BR->BatchQuad( mx + tmpX * sw, my + tty * sh, sw, shn ); + } + } + + BR->DrawOpt(); + + return; + } else + BR->QuadsSetSubsetFree( 0, 0, 0, height / h, width / w, height / h, width / w, 0 ); else if ( Effect == RN_MIRROR ) BR->QuadsSetSubsetFree( width / w, 0, width / w, height / h, 0, height / h, 0, 0 ); else if ( RN_FLIP ) diff --git a/src/graphics/ctexturegrouploader.cpp b/src/graphics/ctexturegrouploader.cpp index eded6d268..301724496 100644 --- a/src/graphics/ctexturegrouploader.cpp +++ b/src/graphics/ctexturegrouploader.cpp @@ -11,7 +11,8 @@ cTextureGroupLoader::cTextureGroupLoader() : mThreaded(false), mLoaded(false), mAppPath( AppPath() ), - mSkipResourceLoad(false) + mSkipResourceLoad(false), + mIsLoading(false) { } @@ -21,7 +22,8 @@ cTextureGroupLoader::cTextureGroupLoader( const std::string& TextureGroupPath, c mLoaded(false), mAppPath( AppPath() ), mPack(NULL), - mSkipResourceLoad(false) + mSkipResourceLoad(false), + mIsLoading(false) { Load(); } @@ -32,7 +34,8 @@ cTextureGroupLoader::cTextureGroupLoader( const Uint8* Data, const Uint32& DataS mLoaded(false), mAppPath( AppPath() ), mPack(NULL), - mSkipResourceLoad(false) + mSkipResourceLoad(false), + mIsLoading(false) { LoadFromMemory( Data, DataSize, TextureGroupName ); } @@ -43,7 +46,8 @@ cTextureGroupLoader::cTextureGroupLoader( cPack * Pack, const std::string& FileP mLoaded(false), mAppPath( AppPath() ), mPack(NULL), - mSkipResourceLoad(false) + mSkipResourceLoad(false), + mIsLoading(false) { LoadFromPack( Pack, FilePackPath ); } @@ -92,9 +96,11 @@ void cTextureGroupLoader::Load( const std::string& TextureGroupPath ) { } } - if ( !mSkipResourceLoad ) + if ( !mSkipResourceLoad ) { + mIsLoading = true; mRL.Load(); - + } + if ( !mThreaded ) CreateShapes(); } @@ -149,7 +155,8 @@ void cTextureGroupLoader::LoadFromMemory( const Uint8* Data, const Uint32& DataS mTempGroups.push_back( tTexGroup ); } } - + + mIsLoading = true; mRL.Load(); if ( !mThreaded ) @@ -158,6 +165,8 @@ void cTextureGroupLoader::LoadFromMemory( const Uint8* Data, const Uint32& DataS } void cTextureGroupLoader::CreateShapes() { + mIsLoading = false; + cShapeGroup * tSG = NULL; for ( Uint32 z = 0; z < mTempGroups.size(); z++ ) { @@ -222,6 +231,10 @@ const bool& cTextureGroupLoader::IsLoaded() const { return mLoaded; } +const bool& cTextureGroupLoader::IsLoading() const { + return mIsLoading; +} + bool cTextureGroupLoader::UpdateTextureAtlas( std::string TextureAtlasPath, std::string ImagesPath ) { if ( !TextureAtlasPath.size() || !ImagesPath.size() || !FileExists( TextureAtlasPath ) || !IsDirectory( ImagesPath ) ) return false; diff --git a/src/graphics/ctexturegrouploader.hpp b/src/graphics/ctexturegrouploader.hpp index 0acbadd2a..dd7d521d8 100644 --- a/src/graphics/ctexturegrouploader.hpp +++ b/src/graphics/ctexturegrouploader.hpp @@ -35,7 +35,9 @@ class EE_API cTextureGroupLoader { void Threaded( const bool& threaded ); - const bool& IsLoaded() const; + const bool& IsLoaded() const; + + const bool& IsLoading() const; /** Will check if the texture atlas is updated ( all the image of the path are inside the texture atlas, and are the same version, otherwise it will recreate or update the texture atlas. */ bool UpdateTextureAtlas( std::string TextureAtlasPath, std::string ImagesPath ); @@ -47,6 +49,7 @@ class EE_API cTextureGroupLoader { std::string mAppPath; cPack * mPack; bool mSkipResourceLoad; + bool mIsLoading; typedef struct sTempTexGroupS { sTextureHdr Texture; diff --git a/src/system/tresourcemanager.hpp b/src/system/tresourcemanager.hpp index c42d07cdf..e8eb0b605 100644 --- a/src/system/tresourcemanager.hpp +++ b/src/system/tresourcemanager.hpp @@ -32,7 +32,7 @@ class tResourceManager { Uint32 Exists( const std::string& Name ); - Uint32 Exists( const Uint32& Id ); + Uint32 ExistsId( const Uint32& Id ); void Destroy(); @@ -121,7 +121,7 @@ Uint32 tResourceManager::Exists( const std::string& Name ) { } template -Uint32 tResourceManager::Exists( const Uint32& Id ) { +Uint32 tResourceManager::ExistsId( const Uint32& Id ) { return Count( Id ); } diff --git a/src/test/ee.cpp b/src/test/ee.cpp index 94ec9869c..a417cdc11 100644 --- a/src/test/ee.cpp +++ b/src/test/ee.cpp @@ -201,7 +201,7 @@ void cEETest::CreateAquaTextureAtlas() { std::string Path( MyPath + "data/aqua" ); if ( !FileExists( Path + ".etg" ) ) { - cTexturePacker tp( 512, 512, true, 2 ); + cTexturePacker tp( 512, 512, true, 0 ); tp.AddTexturesPath( Path ); tp.PackTextures(); tp.Save( Path + ".png", EE_SAVE_TYPE_PNG ); @@ -374,7 +374,7 @@ void cEETest::CreateUI() { C->Pos( 320, 240 ); C->DragEnable( true ); //C->StartRotation( 0.f, 360.f, 2500.f ); - +/* Params.Flags &= ~UI_CLIP_ENABLE; Params.Background.Corners(0); Params.Background.Colors( eeColorA( 0x7700FF00 ), eeColorA( 0x7700CC00 ), eeColorA( 0x7700CC00 ), eeColorA( 0x7700FF00 ) ); @@ -408,7 +408,7 @@ void cEETest::CreateUI() { Gfx->StartAlphaAnim( 100.f, 255.f, 1000.f ); Gfx->AlphaInterpolation()->Loop( true ); Gfx->AlphaInterpolation()->SetTotalTime( 1000.f ); - +*/ cUITextBox::CreateParams TextParams; TextParams.Parent( C ); TextParams.PosSet( 0, 0 ); @@ -493,102 +493,13 @@ void cEETest::CreateUI() { 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.\nPowered by Text Shrinker =)"; TTF->ShrinkText( mBuda, 400 ); - /** Replace this with the texture atlas and an auto theme loader */ - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_button_normal_ml.png" ), "aqua_button_normal_ml" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_button_normal_mr.png" ), "aqua_button_normal_mr" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_button_normal_m.png" ), "aqua_button_normal_m" ) ) ); - - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_button_menter_ml.png" ), "aqua_button_menter_ml" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_button_menter_mr.png" ), "aqua_button_menter_mr" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_button_menter_m.png" ), "aqua_button_menter_m" ) ) ); - - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_button_mdown_ml.png" ), "aqua_button_mdown_ml" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_button_mdown_mr.png" ), "aqua_button_mdown_mr" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_button_mdown_m.png" ), "aqua_button_mdown_m" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_normal.png" ), "aqua_textinput_normal" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_focus.png" ), "aqua_textinput_focus" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_normal_dl.png" ), "aqua_textinput_normal_dl" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_normal_dr.png" ), "aqua_textinput_normal_dr" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_normal_ml.png" ), "aqua_textinput_normal_ml" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_normal_mr.png" ), "aqua_textinput_normal_mr" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_normal_u.png" ), "aqua_textinput_normal_u" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_normal_d.png" ), "aqua_textinput_normal_d" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_normal_ul.png" ), "aqua_textinput_normal_ul" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_normal_ur.png" ), "aqua_textinput_normal_ur" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_normal_m.png" ), "aqua_textinput_normal_m" ) ) ); - - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_checkbox_active_menter.png" ), "aqua_checkbox_active_menter" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_checkbox_active_normal.png" ), "aqua_checkbox_active_normal" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_checkbox_inactive_menter.png" ), "aqua_checkbox_inactive_menter" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_checkbox_inactive_normal.png" ), "aqua_checkbox_inactive_normal" ) ) ); - - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_radiobutton_active_menter.png" ), "aqua_radiobutton_active_menter" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_radiobutton_active_normal.png" ), "aqua_radiobutton_active_normal" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_radiobutton_inactive_menter.png" ), "aqua_radiobutton_inactive_menter" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_radiobutton_inactive_normal.png" ), "aqua_radiobutton_inactive_normal" ) ) ); - - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_hslider_button_normal.png" ), "aqua_hslider_button_normal" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_hslider_button_menter.png" ), "aqua_hslider_button_menter" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_hslider_bg_normal_m.png" ), "aqua_hslider_bg_normal_m" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_hslider_bg_normal_ml.png" ), "aqua_hslider_bg_normal_ml" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_hslider_bg_normal_mr.png" ), "aqua_hslider_bg_normal_mr" ) ) ); - - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_vslider_button_normal.png" ), "aqua_vslider_button_normal" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_vslider_button_menter.png" ), "aqua_vslider_button_menter" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_vslider_bg_normal_m.png" ), "aqua_vslider_bg_normal_m" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_vslider_bg_normal_u.png" ), "aqua_vslider_bg_normal_u" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_vslider_bg_normal_d.png" ), "aqua_vslider_bg_normal_d" ) ) ); - - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_spinbox_input_normal_ml.png" ), "aqua_spinbox_input_normal_ml" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_spinbox_input_normal_m.png" ), "aqua_spinbox_input_normal_m" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_spinbox_input_normal_d.png" ), "aqua_spinbox_input_normal_d" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_spinbox_input_normal_dl.png" ), "aqua_spinbox_input_normal_dl" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_spinbox_input_normal_u.png" ), "aqua_spinbox_input_normal_u" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_spinbox_input_normal_ul.png" ), "aqua_spinbox_input_normal_ul" ) ) ); - - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_spinbox_btnup_normal.png" ), "aqua_spinbox_btnup_normal" ) ) ); - cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_spinbox_btndown_normal.png" ), "aqua_spinbox_btndown_normal" ) ) ); - - cUITheme * AquaTheme = eeNew( cUITheme, ( "aqua", "aqua" ) ); - - cUISkinComplex * AquaTextInput = eeNew( cUISkinComplex, ( "aqua_textinput" ) ); - cUISkinComplex * AquaButton = eeNew( cUISkinComplex, ( "aqua_button" ) ); - cUISkinSimple * AquaCheckboxActive = eeNew( cUISkinSimple, ( "aqua_checkbox_active" ) ); - cUISkinSimple * AquaCheckboxInactive = eeNew( cUISkinSimple, ( "aqua_checkbox_inactive" ) ); - cUISkinSimple * AquaRadioButtonActive = eeNew( cUISkinSimple, ( "aqua_radiobutton_active" ) ); - cUISkinSimple * AquaRadioButtonInactive = eeNew( cUISkinSimple, ( "aqua_radiobutton_inactive" ) ); - cUISkinComplex * AquaSliderBg = eeNew( cUISkinComplex, ( "aqua_hslider_bg" ) ); - cUISkinSimple * AquaSliderButton = eeNew( cUISkinSimple, ( "aqua_hslider_button" ) ); - cUISkinComplex * AquaVSliderBg = eeNew( cUISkinComplex, ( "aqua_vslider_bg" ) ); - cUISkinSimple * AquaVSliderButton = eeNew( cUISkinSimple, ( "aqua_vslider_button" ) ); - cUISkinComplex * AquaSpinBox = eeNew( cUISkinComplex, ( "aqua_spinbox_input" ) ); - cUISkinSimple * AquaSpinBoxBtnUp = eeNew( cUISkinSimple, ( "aqua_spinbox_btnup" ) ); - cUISkinSimple * AquaSpinBoxBtnDown = eeNew( cUISkinSimple, ( "aqua_spinbox_btndown" ) ); - - - AquaTextInput->SetColor ( cUISkin::StateNormal , eeColorA( 240, 240, 255, 255 ) ); - AquaTextInput->SetColor ( cUISkin::StateFocus , eeColorA( 250, 250, 255, 255 ) ); - //AquaButton->SetColor ( cUISkin::StateMouseEnter , eeColorA( 200, 255, 200, 255 ) ); - //AquaButton->SetColor ( cUISkin::StateMouseDown , eeColorA( 150, 255, 150, 255 ) ); - - AquaTheme->Add( AquaTextInput ); - AquaTheme->Add( AquaButton ); - AquaTheme->Add( AquaCheckboxActive ); - AquaTheme->Add( AquaCheckboxInactive ); - AquaTheme->Add( AquaRadioButtonActive ); - AquaTheme->Add( AquaRadioButtonInactive ); - AquaTheme->Add( AquaSliderBg ); - AquaTheme->Add( AquaSliderButton ); - AquaTheme->Add( AquaVSliderBg ); - AquaTheme->Add( AquaVSliderButton ); - AquaTheme->Add( AquaSpinBox ); - AquaTheme->Add( AquaSpinBoxBtnUp ); - AquaTheme->Add( AquaSpinBoxBtnDown ); - /***************/ - - cUIThemeManager::instance()->Add( AquaTheme ); - + cUIThemeManager::instance()->Add( cUITheme::LoadFromPath( MyPath + "data/aqua/", "aqua", "aqua" ) ); +/* + cTextureGroupLoader tgl( MyPath + "data/aqua.etg" ); + TF->GetByName( "data/aqua.png" )->ClampMode( EE_CLAMP_REPEAT ); + 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) ) ); @@ -1081,11 +992,11 @@ void cEETest::Render() { } mBudaTC->Draw( 0.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 ); diff --git a/src/ui/cuicheckbox.cpp b/src/ui/cuicheckbox.cpp index e02287d86..0460ac2a9 100644 --- a/src/ui/cuicheckbox.cpp +++ b/src/ui/cuicheckbox.cpp @@ -8,17 +8,17 @@ cUICheckBox::cUICheckBox( const cUITextBox::CreateParams& Params ) : { mType |= UI_TYPE_GET(UI_TYPE_CHECKBOX); - cUITextBox::CreateParams ButtonParams( Params ); + cUIControlAnim::CreateParams ButtonParams( Params ); ButtonParams.Parent( this ); ButtonParams.PosSet( eeVector2i( 0, 0 ) ); ButtonParams.Size = eeSize( 16, 16 ); - mActiveButton = eeNew( cUIPushButton, ( ButtonParams ) ); + mActiveButton = eeNew( cUIControlAnim, ( ButtonParams ) ); mActiveButton->Visible( false ); mActiveButton->Enabled( true ); - mInactiveButton = eeNew( cUIPushButton, ( ButtonParams ) ); + mInactiveButton = eeNew( cUIControlAnim, ( ButtonParams ) ); mInactiveButton->Visible( true ); mInactiveButton->Enabled( true ); @@ -106,4 +106,12 @@ void cUICheckBox::Padding( const eeRectf& padding ) { mPadding.Left = mPadding.Left + mActiveButton->Size().Width(); } +cUIControlAnim * cUICheckBox::ActiveButton() const { + return mActiveButton; +} + +cUIControlAnim * cUICheckBox::InactiveButton() const { + return mInactiveButton; +} + }} diff --git a/src/ui/cuicheckbox.hpp b/src/ui/cuicheckbox.hpp index 014e27994..e800bd560 100644 --- a/src/ui/cuicheckbox.hpp +++ b/src/ui/cuicheckbox.hpp @@ -23,10 +23,14 @@ class EE_API cUICheckBox : public cUITextBox { const bool& Active() const; virtual void Padding( const eeRectf& padding ); + + cUIControlAnim * ActiveButton() const; + + cUIControlAnim * InactiveButton() const; protected: - cUIPushButton * mActiveButton; - cUIPushButton * mInactiveButton; - bool mActive; + cUIControlAnim * mActiveButton; + cUIControlAnim * mInactiveButton; + bool mActive; void SwitchState(); }; diff --git a/src/ui/cuiradiobutton.cpp b/src/ui/cuiradiobutton.cpp index ee7bf4419..4f78778f8 100644 --- a/src/ui/cuiradiobutton.cpp +++ b/src/ui/cuiradiobutton.cpp @@ -10,17 +10,17 @@ cUIRadioButton::cUIRadioButton( const cUITextBox::CreateParams& Params ) : { mType |= UI_TYPE_GET(UI_TYPE_RADIOBUTTON); - cUITextBox::CreateParams ButtonParams( Params ); + cUIControlAnim::CreateParams ButtonParams( Params ); ButtonParams.Parent( this ); ButtonParams.PosSet( eeVector2i( 0, 0 ) ); ButtonParams.Size = eeSize( 16, 16 ); - mActiveButton = eeNew( cUIPushButton, ( ButtonParams ) ); + mActiveButton = eeNew( cUIControlAnim, ( ButtonParams ) ); mActiveButton->Visible( false ); mActiveButton->Enabled( true ); - mInactiveButton = eeNew( cUIPushButton, ( ButtonParams ) ); + mInactiveButton = eeNew( cUIControlAnim, ( ButtonParams ) ); mInactiveButton->Visible( true ); mInactiveButton->Enabled( true ); @@ -176,4 +176,12 @@ void cUIRadioButton::Padding( const eeRectf& padding ) { mPadding.Left = mPadding.Left + mActiveButton->Size().Width(); } +cUIControlAnim * cUIRadioButton::ActiveButton() const { + return mActiveButton; +} + +cUIControlAnim * cUIRadioButton::InactiveButton() const { + return mInactiveButton; +} + }} diff --git a/src/ui/cuiradiobutton.hpp b/src/ui/cuiradiobutton.hpp index ea2499a03..b01202813 100644 --- a/src/ui/cuiradiobutton.hpp +++ b/src/ui/cuiradiobutton.hpp @@ -23,10 +23,14 @@ class EE_API cUIRadioButton : public cUITextBox { const bool& Active() const; virtual void Padding( const eeRectf& padding ); + + cUIControlAnim * ActiveButton() const; + + cUIControlAnim * InactiveButton() const; protected: - cUIPushButton * mActiveButton; - cUIPushButton * mInactiveButton; - bool mActive; + cUIControlAnim * mActiveButton; + cUIControlAnim * mInactiveButton; + bool mActive; void SwitchState(); diff --git a/src/ui/cuiskincomplex.cpp b/src/ui/cuiskincomplex.cpp index 15eb4a9fa..72d016e84 100644 --- a/src/ui/cuiskincomplex.cpp +++ b/src/ui/cuiskincomplex.cpp @@ -7,6 +7,12 @@ static const char SideSuffix[ cUISkinComplex::SideCount ][4] = { "ml", "mr","d","u","ul","ur","dl","dr","m" }; +std::string cUISkinComplex::GetSideSuffix( const Uint32& Side ) { + eeASSERT( Side < cUISkinComplex::SideCount ); + + return std::string( SideSuffix[ Side ] ); +} + cUISkinComplex::cUISkinComplex( const std::string& Name ) : cUISkin( Name ) { diff --git a/src/ui/cuiskincomplex.hpp b/src/ui/cuiskincomplex.hpp index 0fddfc3be..12382d7c4 100644 --- a/src/ui/cuiskincomplex.hpp +++ b/src/ui/cuiskincomplex.hpp @@ -8,6 +8,8 @@ namespace EE { namespace UI { class EE_API cUISkinComplex : public cUISkin { public: + static std::string GetSideSuffix( const Uint32& Side ); + enum UISkinComplexSides { Left = 0, Right, diff --git a/src/ui/cuislider.cpp b/src/ui/cuislider.cpp index 68787a053..8f73cd1bd 100644 --- a/src/ui/cuislider.cpp +++ b/src/ui/cuislider.cpp @@ -137,11 +137,11 @@ void cUISlider::Value( const eeFloat& Val ) { if ( !mOnPosChange ) { if ( !mVertical ) - mSlider->Pos( mBackSlider->Size().Width() * ( Val - mMinValue ), mSlider->Pos().y ); + mSlider->Pos( mBackSlider->Size().Width() * (Int32)( Val - mMinValue ), mSlider->Pos().y ); else - mSlider->Pos( mSlider->Pos().x, mBackSlider->Size().Height() * ( Val - mMinValue ) ); + mSlider->Pos( mSlider->Pos().x, mBackSlider->Size().Height() * (Int32)( Val - mMinValue ) ); } - + OnValueChange(); } } @@ -190,7 +190,7 @@ const bool& cUISlider::IsVertical() const { void cUISlider::Update() { cUIControlAnim::Update(); - + if ( IsMouseOver() || mBackSlider->IsMouseOver() || mSlider->IsMouseOver() ) { ManageClick( cUIManager::instance()->GetInput()->ClickTrigger() ); } @@ -200,7 +200,7 @@ void cUISlider::ManageClick( const Uint32& Flags ) { if ( Flags ) { eeVector2i ControlPos = cUIManager::instance()->GetMousePos(); mSlider->ScreenToControl( ControlPos ); - + if ( Flags & EE_BUTTON_LMASK && !mSlider->IsMouseOver() ) { if ( !mVertical ) { if ( ControlPos.x < 0 ) diff --git a/src/ui/cuispinbox.cpp b/src/ui/cuispinbox.cpp index 20cdd7213..a44454e44 100644 --- a/src/ui/cuispinbox.cpp +++ b/src/ui/cuispinbox.cpp @@ -17,12 +17,12 @@ cUISpinBox::cUISpinBox( const cUISpinBox::CreateParams& Params ) : mInput = eeNew( cUITextInput, ( InputParams ) ); - cUIPushButton::CreateParams BtnParams( Params ); + cUIControlAnim::CreateParams BtnParams( Params ); BtnParams.Parent( this ); BtnParams.Size = eeSize( 16, 16 ); - mPushUp = eeNew( cUIPushButton, ( BtnParams ) ); - mPushDown = eeNew( cUIPushButton, ( BtnParams ) ); + mPushUp = eeNew( cUIControlAnim, ( BtnParams ) ); + mPushDown = eeNew( cUIControlAnim, ( BtnParams ) ); mInput->Visible ( true ); mInput->Enabled ( true ); @@ -201,4 +201,16 @@ void cUISpinBox::Update() { } } +cUIControlAnim * cUISpinBox::ButtonPushUp() const { + return mPushUp; +} + +cUIControlAnim * cUISpinBox::ButtonPushDown() const { + return mPushDown; +} + +cUITextInput * cUISpinBox::TextInput() const { + return mInput; +} + }} diff --git a/src/ui/cuispinbox.hpp b/src/ui/cuispinbox.hpp index 01f638167..11f7f87b7 100644 --- a/src/ui/cuispinbox.hpp +++ b/src/ui/cuispinbox.hpp @@ -54,10 +54,16 @@ class EE_API cUISpinBox : public cUIControlAnim { const eeFloat& Value() const; virtual void Update(); + + cUIControlAnim * ButtonPushUp() const; + + cUIControlAnim * ButtonPushDown() const; + + cUITextInput * TextInput() const; protected: cUITextInput * mInput; - cUIPushButton * mPushUp; - cUIPushButton * mPushDown; + cUIControlAnim * mPushUp; + cUIControlAnim * mPushDown; eeFloat mMinValue; eeFloat mMaxValue; eeFloat mValue; diff --git a/src/ui/cuitheme.cpp b/src/ui/cuitheme.cpp index 6593606c8..18d9042de 100644 --- a/src/ui/cuitheme.cpp +++ b/src/ui/cuitheme.cpp @@ -1,7 +1,194 @@ #include "cuitheme.hpp" +#include "cuiskinsimple.hpp" +#include "cuiskincomplex.hpp" +#include "../graphics/ctexturefactory.hpp" +#include "../graphics/cshapegroupmanager.hpp" namespace EE { namespace UI { +static const char * UI_THEME_ELEMENTS[] = { + "control", + "button", + "textinput", + "checkbox", + "checkbox_active", + "checkbox_inactive", + "button", + "radiobutton", + "radiobutton_active", + "radiobutton_inactive", + "hslider", + "hslider_bg", + "hslider_button", + "vslider", + "vslider_bg", + "vslider_button", + "spinbox", + "spinbox_input", + "spinbox_btnup", + "spinbox_btndown" +}; + +cUITheme * cUITheme::LoadFromPath( const std::string& Path, const std::string& Name, const std::string& NameAbbr, const std::string ImgExt ) { + Uint32 i; + bool Found; + std::string Element; + std::string RPath( Path ); + + DirPathAddSlashAtEnd( RPath ); + + if ( !IsDirectory( RPath ) ) + return NULL; + + std::vector ElemFound; + std::vector ElemType; + + cShapeGroup * tSG = eeNew( cShapeGroup, ( NameAbbr ) ); + + cUITheme * tTheme = eeNew( cUITheme, ( Name, NameAbbr ) ); + + Uint32 Count = eeARRAY_SIZE( UI_THEME_ELEMENTS ); + + for ( i = 0; i < Count; i++ ) { + Uint32 IsComplex = 0; + + Element = std::string( NameAbbr + "_" + UI_THEME_ELEMENTS[i] ); + + Found = SearchFilesOfElement( tSG, RPath, Element, IsComplex, ImgExt ); + + if ( Found ) { + ElemFound.push_back( Element ); + ElemType.push_back( IsComplex ); + } + } + + if ( tSG->Count() ) + cShapeGroupManager::instance()->Add( tSG ); + else + eeSAFE_DELETE( tSG ); + + for ( i = 0; i < ElemFound.size(); i++ ) { + if ( ElemType[i] ) + tTheme->Add( eeNew( cUISkinComplex, ( ElemFound[i] ) ) ); + else + tTheme->Add( eeNew( cUISkinSimple, ( ElemFound[i] ) ) ); + } + + return tTheme; +} + +cUITheme * cUITheme::LoadFromShapeGroup( cShapeGroup * ShapeGroup, const std::string& Name, const std::string NameAbbr ) { + Uint32 i; + bool Found; + std::string Element; + std::vector ElemFound; + std::vector ElemType; + + cUITheme * tTheme = eeNew( cUITheme, ( Name, NameAbbr ) ); + + Uint32 Count = eeARRAY_SIZE( UI_THEME_ELEMENTS ); + + for ( i = 0; i < Count; i++ ) { + Uint32 IsComplex = 0; + + Element = std::string( NameAbbr + "_" + UI_THEME_ELEMENTS[i] ); + + Found = SearchFilesInGroup( ShapeGroup, Element, IsComplex ); + + if ( Found ) { + ElemFound.push_back( Element ); + ElemType.push_back( IsComplex ); + } + } + + for ( i = 0; i < ElemFound.size(); i++ ) { + if ( ElemType[i] ) + tTheme->Add( eeNew( cUISkinComplex, ( ElemFound[i] ) ) ); + else + tTheme->Add( eeNew( cUISkinSimple, ( ElemFound[i] ) ) ); + } + + return tTheme; +} + +bool cUITheme::SearchFilesInGroup( cShapeGroup * SG, std::string Element, Uint32& IsComplex ) { + bool Found = false; + Uint32 i = 0, s = 0; + std::string ElemPath; + std::string ElemFullPath; + std::string ElemName; + IsComplex = false; + + // Search Complex Skin + for ( i = 0; i < cUISkin::StateCount; i++ ) { + for ( s = 0; s < cUISkinComplex::SideCount; s++ ) { + ElemName = Element + "_" + cUISkin::GetSkinStateName( i ) + "_" + cUISkinComplex::GetSideSuffix( s ); + + if ( SG->GetByName( ElemName ) ) { // only load PNG's FTM + IsComplex = true; + Found = true; + break; + } + } + } + + // Seach Simple Skin + if ( !IsComplex ) { + for ( i = 0; i < cUISkin::StateCount; i++ ) { + ElemName = Element + "_" + cUISkin::GetSkinStateName( i ); + + if ( SG->GetByName( ElemName ) ) { // only load PNG's FTM + Found = true; + break; + } + } + } + + return Found; +} + +bool cUITheme::SearchFilesOfElement( cShapeGroup * SG, const std::string& Path, std::string Element, Uint32& IsComplex, const std::string ImgExt ) { + bool Found = false; + Uint32 i = 0, s = 0; + std::string ElemPath; + std::string ElemFullPath; + std::string ElemName; + IsComplex = false; + + // Search Complex Skin + for ( i = 0; i < cUISkin::StateCount; i++ ) { + for ( s = 0; s < cUISkinComplex::SideCount; s++ ) { + ElemName = Element + "_" + cUISkin::GetSkinStateName( i ) + "_" + cUISkinComplex::GetSideSuffix( s ); + ElemPath = Path + ElemName; + ElemFullPath = ElemPath + "." + ImgExt; + + if ( FileExists( ElemFullPath ) ) { // only load PNG's FTM + SG->Add( eeNew( cShape, ( cTextureFactory::instance()->Load( ElemFullPath ), ElemName ) ) ); + + IsComplex = true; + Found = true; + } + } + } + + // Seach Simple Skin + if ( !IsComplex ) { + for ( i = 0; i < cUISkin::StateCount; i++ ) { + ElemName = Element + "_" + cUISkin::GetSkinStateName( i ); + ElemPath = Path + ElemName; + ElemFullPath = ElemPath + "." + ImgExt; + + if ( FileExists( ElemFullPath ) ) { // only load PNG's FTM + SG->Add( eeNew( cShape, ( cTextureFactory::instance()->Load( ElemFullPath ), ElemName ) ) ); + + Found = true; + } + } + } + + return Found; +} + cUITheme::cUITheme( const std::string& Name, const std::string& Abbr ) : tResourceManager ( false ), mName( Name ), diff --git a/src/ui/cuitheme.hpp b/src/ui/cuitheme.hpp index 1f0c479a8..0d489d450 100644 --- a/src/ui/cuitheme.hpp +++ b/src/ui/cuitheme.hpp @@ -2,12 +2,17 @@ #define EE_UICUITHEME_HPP #include "base.hpp" +#include "../graphics/cshapegroup.hpp" #include "cuiskin.hpp" namespace EE { namespace UI { class EE_API cUITheme : public tResourceManager { public: + static cUITheme * LoadFromPath( const std::string& Path, const std::string& Name, const std::string& NameAbbr, const std::string ImgExt = "png" ); + + static cUITheme * LoadFromShapeGroup( cShapeGroup * ShapeGroup, const std::string& Name, const std::string NameAbbr ); + cUITheme( const std::string& Name, const std::string& Abbr ); virtual ~cUITheme(); @@ -26,6 +31,11 @@ class EE_API cUITheme : public tResourceManager { Uint32 mNameHash; std::string mAbbr; + + private: + static bool SearchFilesOfElement( cShapeGroup * SG, const std::string& Path, std::string Element, Uint32& IsComplex, const std::string ImgExt ); + + static bool SearchFilesInGroup( cShapeGroup * SG, std::string Element, Uint32& IsComplex ); }; }}