diff --git a/Makefile b/Makefile index 2f14e19f7..fff39c52b 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,3 @@ -export CFLAGS = -Wall $(DEBUGFLAGS) $(BUILDFLAGS) -export CFLAGSEXT = $(DEBUGFLAGS) $(BUILDFLAGS) -export LDFLAGS = $(LINKFLAGS) -export LIBPATH = ./ -export VERSION = 0.7 -export CP = cp -export LN = ln -export LNFLAGS = -s -f -export AR = ar -export ARFLAGS = rcs -export DESTDIR = /usr -export DESTLIBDIR = $(DESTDIR)/lib -export DESTINCDIR = $(DESTDIR)/include - ifeq ($(DYNAMIC), yes) LIB = libeepp.so LIBNAME = $(LIBPATH)/$(LIB).$(VERSION) @@ -26,7 +12,7 @@ ifeq ($(DEBUGBUILD), yes) DEBUGFLAGS = -g -DDEBUG -DEE_DEBUG -DEE_MEMORY_MANAGER RELEASETYPE = debug else - DEBUGFLAGS = -O2 -s -DNDEBUG + DEBUGFLAGS = -fno-strict-aliasing -O3 -s -DNDEBUG RELEASETYPE = release endif @@ -46,6 +32,20 @@ export CC = llvm-gcc export CPP = llvm-g++ endif +export CFLAGS = -Wall $(DEBUGFLAGS) $(BUILDFLAGS) +export CFLAGSEXT = $(DEBUGFLAGS) $(BUILDFLAGS) +export LDFLAGS = $(LINKFLAGS) +export LIBPATH = ./ +export VERSION = 0.7 +export CP = cp +export LN = ln +export LNFLAGS = -s -f +export AR = ar +export ARFLAGS = rcs +export DESTDIR = /usr +export DESTLIBDIR = $(DESTDIR)/lib +export DESTINCDIR = $(DESTDIR)/include + STRLOWERCASE = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1)))))))))))))))))))))))))) OS = $(strip $(call STRLOWERCASE, $(shell uname) ) ) diff --git a/src/test/ee.cpp b/src/test/ee.cpp index 60cfa6686..25416aed7 100644 --- a/src/test/ee.cpp +++ b/src/test/ee.cpp @@ -384,15 +384,12 @@ void cEETest::CreateUI() { cUIControl::CreateParams Params( cUIManager::instance()->MainControl(), eeVector2i(0,0), eeSize( 530, 240 ), UI_FILL_BACKGROUND | UI_CLIP_ENABLE | UI_BORDER ); - cUIThemeManager::instance()->Add( cUITheme::LoadFromPath( MyPath + "data/aqua/", "aqua", "aqua" ) ); - + //cUIThemeManager::instance()->Add( cUITheme::LoadFromPath( MyPath + "data/aqua/", "aqua", "aqua" ) ); CreateAquaTextureAtlas(); - /* cTextureGroupLoader tgl( MyPath + "data/aqua.etg" ); TF->GetByName( "data/aqua.png" )->TextureFilter( TEX_FILTER_NEAREST ); cUIThemeManager::instance()->Add( cUITheme::LoadFromShapeGroup( cShapeGroupManager::instance()->GetByName( "aqua" ), "aqua", "aqua" ) ); - */ cUIThemeManager::instance()->DefaultEffectsEnabled( true ); cUIThemeManager::instance()->DefaultFont( TTF ); @@ -400,14 +397,12 @@ void cEETest::CreateUI() { Params.Border.Width( 2 ); Params.Border.Color( 0xFF979797 ); - //Params.Background.Corners(5); Params.Background.Colors( eeColorA( 0x66EDEDED ), eeColorA( 0xCCEDEDED ), eeColorA( 0xCCEDEDED ), eeColorA( 0x66EDEDED ) ); cUIControlAnim * C = eeNew( cUITest, ( Params ) ); C->Visible( true ); C->Enabled( true ); C->Pos( 320, 240 ); C->DragEnable( true ); - //C->StartRotation( 0.f, 360.f, 5000.f ); Params.Flags &= ~UI_CLIP_ENABLE; Params.Background.Corners(0); @@ -459,7 +454,6 @@ void cEETest::CreateUI() { cUITextInput::CreateParams InputParams; InputParams.Parent( C ); - //InputParams.Background.Corners(6); InputParams.Border.Color(0xFF979797); InputParams.Background.Colors( eeColorA(0x99AAAAAA), eeColorA(0x99CCCCCC), eeColorA(0x99CCCCCC), eeColorA(0x99AAAAAA) ); InputParams.PosSet( 20, 216 ); @@ -621,6 +615,7 @@ void cEETest::CreateUI() { Menu->Add( L"Save" ); Menu->Add( L"Save As..." ); Menu->Add( L"Save All" ); + Menu->AddCheckBox( L"Check Me" ); Menu->AddSeparator(); Menu->Add( L"Quit" ); diff --git a/src/ui/cuicheckbox.cpp b/src/ui/cuicheckbox.cpp index 71c23d4ad..607738391 100644 --- a/src/ui/cuicheckbox.cpp +++ b/src/ui/cuicheckbox.cpp @@ -36,6 +36,10 @@ void cUICheckBox::SetTheme( cUITheme * Theme ) { mActiveButton->ForceThemeSkin ( Theme, "checkbox_active" ); mInactiveButton->ForceThemeSkin ( Theme, "checkbox_inactive" ); + DoAfterSetTheme(); +} + +void cUICheckBox::DoAfterSetTheme() { cShape * tShape = NULL; cUISkin * tSkin = mActiveButton->GetSkin(); diff --git a/src/ui/cuicheckbox.hpp b/src/ui/cuicheckbox.hpp index 9565be038..c65a214db 100644 --- a/src/ui/cuicheckbox.hpp +++ b/src/ui/cuicheckbox.hpp @@ -40,6 +40,8 @@ class EE_API cUICheckBox : public cUITextBox { virtual Uint32 OnKeyDown( const cUIEventKey& Event ); virtual Uint32 OnMessage( const cUIMessage * Msg ); + + void DoAfterSetTheme(); }; }} diff --git a/src/ui/cuigfx.cpp b/src/ui/cuigfx.cpp index df6b33518..4346c8ecd 100644 --- a/src/ui/cuigfx.cpp +++ b/src/ui/cuigfx.cpp @@ -25,8 +25,13 @@ cUIGfx::~cUIGfx() { void cUIGfx::Shape( cShape * shape ) { mShape = shape; - if ( NULL != mShape && ( ( Flags() & UI_AUTO_SIZE ) ) ) - Size( mShape->Size() ); + if ( Flags() & UI_AUTO_SIZE ) { + if ( NULL != mShape ) { + Size( mShape->Size() ); + } else { + Size( eeSize( 0, 0 ) ); + } + } } void cUIGfx::Draw() { diff --git a/src/ui/cuimenu.cpp b/src/ui/cuimenu.cpp index 099edb6fe..d33d75d28 100644 --- a/src/ui/cuimenu.cpp +++ b/src/ui/cuimenu.cpp @@ -63,23 +63,58 @@ Uint32 cUIMenu::Add( const std::wstring& Text, cShape * Icon ) { return Add( CreateMenuItem( Text, Icon ) ); } -Uint32 cUIMenu::Add( cUIMenuItem * Control ) { - if ( this != Control->Parent() ) - Control->Parent( this ); +cUIMenuCheckBox * cUIMenu::CreateMenuCheckBox( const std::wstring& Text ) { + cUIMenuCheckBox::CreateParams Params; + Params.Parent( this ); + Params.Font = mFont; + Params.FontColor = mFontColor; + Params.FontShadowColor = mFontShadowColor; + Params.FontOverColor = mFontOverColor; + Params.Flags = UI_CLIP_ENABLE | UI_VALIGN_CENTER | UI_HALIGN_LEFT; + Params.Size = eeSize( 0, mRowHeight ); - if ( mFlags & UI_AUTO_SIZE ) { - if ( Control->TextBox()->GetTextWidth() > (Int32)mMaxWidth - mPadding.Left - mPadding.Right ) { - mMaxWidth = Control->TextBox()->GetTextWidth() + mPadding.Left + mPadding.Right; + cUIMenuCheckBox * tCtrl = eeNew( cUIMenuCheckBox, ( Params ) ); - Size( mMaxWidth, mSize.Height() ); + tCtrl->Text( Text ); + tCtrl->Visible( true ); + tCtrl->Enabled( true ); - ResizeControls(); + return tCtrl; +} + +Uint32 cUIMenu::AddCheckBox( const std::wstring& Text ) { + return Add( CreateMenuCheckBox( Text ) ); +} + +bool cUIMenu::CheckControlSize( cUIControl * Control, const bool& Resize ) { + if ( Control->IsType( UI_TYPE_MENUITEM ) ) { + cUIMenuItem * tItem = reinterpret_cast ( Control ); + + if ( NULL != tItem->Icon() && tItem->IconHorizontalMargin() + tItem->Icon()->Size().Width() > (Int32)mBiggestIcon ) { + mBiggestIcon = tItem->IconHorizontalMargin() + tItem->Icon()->Size().Width(); + } + + if ( mFlags & UI_AUTO_SIZE ) { + if ( tItem->TextBox()->GetTextWidth() + mBiggestIcon > (Int32)mMaxWidth - mPadding.Left - mPadding.Right ) { + mMaxWidth = tItem->TextBox()->GetTextWidth() + mBiggestIcon + mPadding.Left + mPadding.Right; + + if ( Resize ) { + ResizeControls(); + + return true; + } + } } } - if ( NULL != Control->Icon() && Control->IconHorizontalMargin() + Control->Icon()->Size().Width() > (Int32)mBiggestIcon ) { - mBiggestIcon = Control->IconHorizontalMargin() + Control->Icon()->Size().Width(); - } + return false; +} + +Uint32 cUIMenu::Add( cUIControl * Control ) { + if ( this != Control->Parent() ) + Control->Parent( this ); + + CheckControlSize( Control ); SetControlSize( Control, Count() ); @@ -102,6 +137,8 @@ void cUIMenu::SetControlSize( cUIControl * Control, const Uint32& Pos ) { if ( NULL == tItem->Icon()->Shape() ) { tItem->Padding( eeRecti( mBiggestIcon, 0, 0, 0 ) ); + } else { + tItem->Padding( eeRecti( 0, 0, 0, 0 ) ); } } else { Control->Size( mSize.Width() - mPadding.Left - mPadding.Right, Control->Size().Height() ); @@ -226,7 +263,7 @@ void cUIMenu::OnSizeChange() { } if ( 0 != mMinWidth && mSize.Width() < (Int32)mMinWidth ) { - Size( mMinWidth, mItems.size() * mRowHeight + mPadding.Top + mPadding.Bottom ); + Size( mMinWidth, mNextPosY + mPadding.Top + mPadding.Bottom ); } } @@ -251,20 +288,9 @@ void cUIMenu::ReposControls() { if ( mFlags & UI_AUTO_SIZE ) { mMaxWidth = 0; - cUIMenuItem * tMenu; for ( i = 0; i < mItems.size(); i++ ) { - if ( mItems[i]->IsType( UI_TYPE_MENUITEM ) ) { - tMenu = reinterpret_cast ( mItems[i] ); - - if ( tMenu->TextBox()->GetTextWidth() > (Int32)mMaxWidth - mPadding.Left - mPadding.Right ) { - mMaxWidth = tMenu->TextBox()->GetTextWidth() + mPadding.Left + mPadding.Right; - } - - if ( NULL != tMenu->Icon() && tMenu->IconHorizontalMargin() + tMenu->Icon()->Size().Width() > (Int32)mBiggestIcon ) { - mBiggestIcon = tMenu->IconHorizontalMargin() + tMenu->Icon()->Size().Width(); - } - } + CheckControlSize( mItems[i], false ); } } @@ -278,7 +304,11 @@ void cUIMenu::ReposControls() { } void cUIMenu::ResizeMe() { - Size( mSize.Width(), mNextPosY + mPadding.Top + mPadding.Bottom ); + if ( mFlags & UI_AUTO_SIZE ) { + Size( mMaxWidth, mNextPosY + mPadding.Top + mPadding.Bottom ); + } else { + Size( mSize.Width(), mNextPosY + mPadding.Top + mPadding.Bottom ); + } } }} diff --git a/src/ui/cuimenu.hpp b/src/ui/cuimenu.hpp index c0ff0cd28..a60339d19 100644 --- a/src/ui/cuimenu.hpp +++ b/src/ui/cuimenu.hpp @@ -1,8 +1,9 @@ -#ifndef EE_UICUIMENU -#define EE_UICUIMENU +#ifndef EE_UICUIMENU_HPP +#define EE_UICUIMENU_HPP #include "cuicontrolanim.hpp" #include "cuimenuitem.hpp" +#include "cuimenucheckbox.hpp" #include "cuiseparator.hpp" namespace EE { namespace UI { @@ -52,10 +53,12 @@ class EE_API cUIMenu : public cUIControlAnim { Uint32 Add( const std::wstring& Text, cShape * Icon = NULL ); - Uint32 Add( cUIMenuItem * Control ); + Uint32 Add( cUIControl * Control ); Uint32 AddSeparator(); + Uint32 AddCheckBox( const std::wstring& Text ); + cUIControl * GetItem( const Uint32& Index ); cUIControl * GetItem( const std::wstring& Text ); @@ -74,6 +77,8 @@ class EE_API cUIMenu : public cUIControlAnim { virtual void SetTheme( cUITheme * Theme ); protected: + friend class cUIMenuCheckBox; + std::deque mItems; eeRecti mPadding; cFont * mFont; @@ -101,8 +106,12 @@ class EE_API cUIMenu : public cUIControlAnim { void ResizeMe(); cUIMenuItem * CreateMenuItem( const std::wstring& Text, cShape * Icon ); + + cUIMenuCheckBox * CreateMenuCheckBox( const std::wstring& Text ); void DoAfterSetTheme(); + + bool CheckControlSize( cUIControl * Control, const bool& Resize = true ); }; }} diff --git a/src/ui/cuimenucheckbox.cpp b/src/ui/cuimenucheckbox.cpp new file mode 100644 index 000000000..cfc05b80d --- /dev/null +++ b/src/ui/cuimenucheckbox.cpp @@ -0,0 +1,91 @@ +#include "cuimenucheckbox.hpp" +#include "cuimenu.hpp" + +namespace EE { namespace UI { + +cUIMenuCheckBox::cUIMenuCheckBox( cUIMenuCheckBox::CreateParams& Params ) : + cUIMenuItem( Params ), + mActive( false ), + mSkinActive( NULL ), + mSkinInactive( NULL ) +{ + mType |= UI_TYPE_GET( UI_TYPE_MENUCHECKBOX ); + + ApplyDefaultTheme(); +} + +cUIMenuCheckBox::~cUIMenuCheckBox() { +} + +void cUIMenuCheckBox::SetTheme( cUITheme * Theme ) { + cUIControl::SetTheme( Theme, "menuitem" ); + + mSkinActive = Theme->GetByName( Theme->Abbr() + "_" + "menucheckbox_active" ); + mSkinInactive = Theme->GetByName( Theme->Abbr() + "_" + "menucheckbox_inactive" ); + + Active( mActive ); + + DoAfterSetTheme(); +} + +const bool& cUIMenuCheckBox::Active() const { + return mActive; +} + +const bool& cUIMenuCheckBox::IsActive() const { + return Active(); +} + +void cUIMenuCheckBox::Active( const bool& active ) { + bool oActive = mActive; + mActive = active; + + if ( mActive ) { + if ( NULL != mSkinActive ) { + if ( mSkinState->GetState() == cUISkinState::StateMouseEnter ) + Icon( mSkinActive->GetShape( cUISkinState::StateMouseEnter ) ); + else + Icon( mSkinActive->GetShape( cUISkinState::StateNormal ) ); + } else + mIcon->Shape( NULL ); + } else { + if ( NULL != mSkinInactive ) + if ( mSkinState->GetState() == cUISkinState::StateMouseEnter ) + Icon( mSkinInactive->GetShape( cUISkinState::StateMouseEnter ) ); + else + Icon( mSkinInactive->GetShape( cUISkinState::StateNormal ) ); + else + mIcon->Shape( NULL ); + } + + if ( oActive != active ) { + cUIMenu * Menu = reinterpret_cast ( Parent() ); + + if ( !Menu->CheckControlSize( this ) ) { + if ( NULL != Icon()->Shape() ) { + Padding( eeRecti( 0, 0, 0, 0 ) ); + } + } + + OnValueChange(); + } +} + +void cUIMenuCheckBox::SwitchActive() { + Active( !mActive ); +} + +Uint32 cUIMenuCheckBox::OnMouseClick( const eeVector2i &Pos, Uint32 Flags ) { + cUIPushButton::OnMouseClick( Pos, Flags ); + SwitchActive(); + + return 1; +} + +void cUIMenuCheckBox::OnStateChange() { + cUIMenuItem::OnStateChange(); + + Active( mActive ); +} + +}} diff --git a/src/ui/cuimenucheckbox.hpp b/src/ui/cuimenucheckbox.hpp new file mode 100644 index 000000000..aedf5c4bb --- /dev/null +++ b/src/ui/cuimenucheckbox.hpp @@ -0,0 +1,35 @@ +#ifndef EE_UICUIMENUCHECKBOX_HPP +#define EE_UICUIMENUCHECKBOX_HPP + +#include "cuimenuitem.hpp" + +namespace EE { namespace UI { + +class cUIMenuCheckBox : public cUIMenuItem { + public: + cUIMenuCheckBox( cUIMenuCheckBox::CreateParams& Params ); + + ~cUIMenuCheckBox(); + + virtual void SetTheme( cUITheme * Theme ); + + const bool& Active() const; + + const bool& IsActive() const; + + void Active( const bool& active ); + + void SwitchActive(); + protected: + bool mActive; + cUISkin * mSkinActive; + cUISkin * mSkinInactive; + + virtual Uint32 OnMouseClick( const eeVector2i &Pos, Uint32 Flags ); + + virtual void OnStateChange(); +}; + +}} + +#endif diff --git a/src/ui/cuimenuitem.cpp b/src/ui/cuimenuitem.cpp index 24ec709d2..2585a5b69 100644 --- a/src/ui/cuimenuitem.cpp +++ b/src/ui/cuimenuitem.cpp @@ -17,6 +17,5 @@ void cUIMenuItem::SetTheme( cUITheme * Theme ) { cUIControl::SetTheme( Theme, "menuitem" ); DoAfterSetTheme(); } - + }} - diff --git a/src/ui/cuimenuitem.hpp b/src/ui/cuimenuitem.hpp index c3d837756..86bcd5323 100644 --- a/src/ui/cuimenuitem.hpp +++ b/src/ui/cuimenuitem.hpp @@ -1,5 +1,5 @@ -#ifndef EE_UICUIMENUITEM -#define EE_UICUIMENUITEM +#ifndef EE_UICUIMENUITEM_HPP +#define EE_UICUIMENUITEM_HPP #include "cuipushbutton.hpp" diff --git a/src/ui/cuipushbutton.cpp b/src/ui/cuipushbutton.cpp index a41fb2ced..a4f75ba1d 100644 --- a/src/ui/cuipushbutton.cpp +++ b/src/ui/cuipushbutton.cpp @@ -80,7 +80,7 @@ void cUIPushButton::SetTheme( cUITheme * Theme ) { } void cUIPushButton::DoAfterSetTheme() { - if ( NULL == mTextBox->Font() && NULL != mSkinState && NULL != mSkinState->GetSkin() && NULL != mSkinState->GetSkin()->Theme() && NULL != mSkinState->GetSkin()->Theme()->Font() ) + if ( NULL != mTextBox && NULL == mTextBox->Font() && NULL != mSkinState && NULL != mSkinState->GetSkin() && NULL != mSkinState->GetSkin()->Theme() && NULL != mSkinState->GetSkin()->Theme()->Font() ) mTextBox->Font( mSkinState->GetSkin()->Theme()->Font() ); if ( mControlFlags & UI_CTRL_FLAG_FREE_USE ) { diff --git a/src/ui/cuitheme.cpp b/src/ui/cuitheme.cpp index c4533ffab..b3a536409 100644 --- a/src/ui/cuitheme.cpp +++ b/src/ui/cuitheme.cpp @@ -47,7 +47,9 @@ static const char * UI_THEME_ELEMENTS[] = { "combobox", "menu", "menuitem", - "separator" + "separator", + "menucheckbox_active", + "menucheckbox_inactive" }; cUITheme * cUITheme::LoadFromPath( const std::string& Path, const std::string& Name, const std::string& NameAbbr, const std::string ImgExt ) { diff --git a/src/ui/uihelper.hpp b/src/ui/uihelper.hpp index 528437569..3254253b3 100644 --- a/src/ui/uihelper.hpp +++ b/src/ui/uihelper.hpp @@ -73,10 +73,11 @@ Uint32 EE_API VAlignGet( Uint32 Flags ); #define UI_TYPE_LISTBOX (12) #define UI_TYPE_LISTBOXITEM (13) #define UI_TYPE_DROPDOWNLIST (14) -#define UI_TYPE_COMBOBOX (15) -#define UI_TYPE_MENU (16) -#define UI_TYPE_MENUITEM (17) -#define UI_TYPE_SEPARATOR (18) +#define UI_TYPE_SEPARATOR (15) +#define UI_TYPE_COMBOBOX (16) +#define UI_TYPE_MENU (17) +#define UI_TYPE_MENUITEM (18) +#define UI_TYPE_MENUCHECKBOX (19) #define UI_TYPE_GET(X) ( 1 << (X) )