From 8cde6427f48a46e0daaa317a1e28c8c1d4edff2a Mon Sep 17 00:00:00 2001 From: spartanj Date: Mon, 27 Dec 2010 00:21:48 -0300 Subject: [PATCH] Added cUIComplexControl and cUITooltip. The complex controls allow to create tooltips to display when the mouse is over. Now the controls that represent a real control ( a normal GUI control ) inherits from cUIComplexControl. Fixed some minor bugs on the UI. --- src/test/ee.cpp | 1 + src/ui/cuicomplexcontrol.cpp | 102 ++++++++++++++ src/ui/cuicomplexcontrol.hpp | 44 ++++++ src/ui/cuicontrol.cpp | 11 +- src/ui/cuicontrol.hpp | 18 +-- src/ui/cuidragable.cpp | 1 + src/ui/cuidropdownlist.cpp | 10 +- src/ui/cuigfx.cpp | 2 +- src/ui/cuigfx.hpp | 16 ++- src/ui/cuilistbox.cpp | 2 +- src/ui/cuilistbox.hpp | 6 +- src/ui/cuilistboxcontainer.cpp | 2 + src/ui/cuimenu.cpp | 2 +- src/ui/cuimenu.hpp | 6 +- src/ui/cuiprogressbar.cpp | 2 +- src/ui/cuiprogressbar.hpp | 2 +- src/ui/cuipushbutton.cpp | 2 +- src/ui/cuipushbutton.hpp | 3 +- src/ui/cuiscrollbar.cpp | 2 +- src/ui/cuiscrollbar.hpp | 12 +- src/ui/cuislider.cpp | 2 +- src/ui/cuislider.hpp | 16 ++- src/ui/cuispinbox.cpp | 2 +- src/ui/cuispinbox.hpp | 2 +- src/ui/cuisprite.cpp | 2 +- src/ui/cuisprite.hpp | 14 +- src/ui/cuitextbox.cpp | 2 +- src/ui/cuitextbox.hpp | 8 +- src/ui/cuitheme.cpp | 1 + src/ui/cuithememanager.cpp | 29 +++- src/ui/cuithememanager.hpp | 17 +++ src/ui/cuitooltip.cpp | 241 +++++++++++++++++++++++++++++++++ src/ui/cuitooltip.hpp | 111 +++++++++++++++ src/ui/uihelper.hpp | 48 ++++--- 34 files changed, 656 insertions(+), 85 deletions(-) create mode 100644 src/ui/cuicomplexcontrol.cpp create mode 100644 src/ui/cuicomplexcontrol.hpp create mode 100644 src/ui/cuitooltip.cpp create mode 100644 src/ui/cuitooltip.hpp diff --git a/src/test/ee.cpp b/src/test/ee.cpp index 4b213355e..048393f2d 100644 --- a/src/test/ee.cpp +++ b/src/test/ee.cpp @@ -477,6 +477,7 @@ void cEETest::CreateUI() { Button->Enabled( true ); Button->Text( L"Click Me" ); Button->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cEETest::ButtonClick ) ); + Button->TooltipText( L"Click and see what happens..." ); TextParams.PosSet( 130, 20 ); TextParams.Size = eeSize( 80, 22 ); diff --git a/src/ui/cuicomplexcontrol.cpp b/src/ui/cuicomplexcontrol.cpp new file mode 100644 index 000000000..89726a1b0 --- /dev/null +++ b/src/ui/cuicomplexcontrol.cpp @@ -0,0 +1,102 @@ +#include "cuicomplexcontrol.hpp" +#include "cuimanager.hpp" + +namespace EE { namespace UI { + +cUIComplexControl::cUIComplexControl( const cUIComplexControl::CreateParams& Params ) : + cUIControlAnim( Params ), + mTooltip( NULL ) +{ + mType |= UI_TYPE_CONTROL_COMPLEX; + + TooltipText( Params.TooltipText ); +} + +cUIComplexControl::~cUIComplexControl() { + eeSAFE_DELETE( mTooltip ); +} + +void cUIComplexControl::Update() { + if ( NULL != mTooltip && mTooltip->Text().size() ) { + if ( IsMouseOverMeOrChilds() ) { + eeVector2i Pos = cUIManager::instance()->GetMousePos(); + Pos.x += cUIThemeManager::instance()->CursorSize().x; + Pos.y += cUIThemeManager::instance()->CursorSize().y; + + if ( Pos.x + mTooltip->Size().Width() > cUIManager::instance()->MainControl()->Size().Width() ) { + Pos.x = cUIManager::instance()->GetMousePos().x - mTooltip->Size().Width(); + } + + if ( Pos.y + mTooltip->Size().Height() > cUIManager::instance()->MainControl()->Size().Height() ) { + Pos.y = cUIManager::instance()->GetMousePos().y - mTooltip->Size().Height(); + } + + if ( 0 == cUIThemeManager::instance()->TooltipTimeToShow() ) { + if ( !mTooltip->Visible() || cUIThemeManager::instance()->TooltipFollowMouse() ) + mTooltip->Pos( Pos ); + + mTooltip->Show(); + } else { + if ( -1.f != mTooltip->TooltipTime() ) { + mTooltip->TooltipTimeAdd( cUIManager::instance()->Elapsed() ); + } + + if ( mTooltip->TooltipTime() >= cUIThemeManager::instance()->TooltipTimeToShow() ) { + if ( mTooltip->TooltipTime() != -1.f ) { + mTooltip->Pos( Pos ); + + mTooltip->Show(); + + mTooltip->TooltipTime( -1.f ); + } + } + } + + if ( cUIThemeManager::instance()->TooltipFollowMouse() ) { + mTooltip->Pos( Pos ); + } + } else { + mTooltip->TooltipTime( 0.f ); + + if ( mTooltip->Visible() ) + mTooltip->Hide(); + } + } + + cUIControlAnim::Update(); +} + +void cUIComplexControl::CreateTooltip() { + if ( NULL != mTooltip ) + return; + + cUITooltip::CreateParams Params; + Params.Parent( cUIManager::instance()->MainControl() ); + Params.Flags = UI_VALIGN_CENTER | UI_HALIGN_CENTER | UI_AUTO_PADDING | UI_AUTO_SIZE; + mTooltip = eeNew( cUITooltip, ( Params ) ); +} + +void cUIComplexControl::TooltipText( const std::wstring& Text ) { + if ( NULL == mTooltip ) { // If the tooltip wasn't created it will avoid to create a new one if the string is "" + if ( Text.size() ) { + CreateTooltip(); + + mTooltip->Text( Text ); + } + } else { // but if it's created, i will allow it + mTooltip->Text( Text ); + } +} + +void cUIComplexControl::TooltipText( const std::string& Text ) { + TooltipText( stringTowstring( Text ) ); +} + +std::wstring cUIComplexControl::TooltipText() { + if ( NULL != mTooltip ) + return mTooltip->Text(); + + return std::wstring(); +} + +}} diff --git a/src/ui/cuicomplexcontrol.hpp b/src/ui/cuicomplexcontrol.hpp new file mode 100644 index 000000000..e0028c09c --- /dev/null +++ b/src/ui/cuicomplexcontrol.hpp @@ -0,0 +1,44 @@ +#ifndef EE_UICUICOMPLEXCONTROL_HPP +#define EE_UICUICOMPLEXCONTROL_HPP + +#include "cuicontrolanim.hpp" +#include "cuitooltip.hpp" + +namespace EE { namespace UI { + +class EE_API cUIComplexControl : public cUIControlAnim { + public: + class CreateParams : public cUIControlAnim::CreateParams { + public: + inline CreateParams() : + cUIControlAnim::CreateParams() + { + } + + inline ~CreateParams() {} + + std::wstring TooltipText; + }; + + cUIComplexControl( const cUIComplexControl::CreateParams& Params ); + + ~cUIComplexControl(); + + virtual void Update(); + + cUITooltip * Tooltip(); + + void TooltipText( const std::wstring& Text ); + + void TooltipText( const std::string& Text ); + + std::wstring TooltipText(); + protected: + cUITooltip * mTooltip; + + void CreateTooltip(); +}; + +}} + +#endif diff --git a/src/ui/cuicontrol.cpp b/src/ui/cuicontrol.cpp index 3da381841..a7be9ffd8 100644 --- a/src/ui/cuicontrol.cpp +++ b/src/ui/cuicontrol.cpp @@ -23,8 +23,6 @@ cUIControl::cUIControl( const CreateParams& Params ) : mNumCallBacks(0), mSkinState(NULL) { - mType |= UI_TYPE_GET(UI_TYPE_CONTROL); - if ( NULL == mParentCtrl && NULL != cUIManager::instance()->MainControl() ) { mParentCtrl = cUIManager::instance()->MainControl(); } @@ -245,6 +243,9 @@ void cUIControl::Update() { ChildLoop->Update(); ChildLoop = ChildLoop->mNext; } + + if ( mControlFlags & UI_CTRL_FLAG_MOUSEOVER_ME_OR_CHILD ) + WriteCtrlFlag( UI_CTRL_FLAG_MOUSEOVER_ME_OR_CHILD_POS, 0 ); } void cUIControl::SendMouseEvent( const Uint32& Event, const eeVector2i& Pos, const Uint32& Flags ) { @@ -297,6 +298,10 @@ bool cUIControl::IsMouseOver() { return 0 != Read32BitKey( &mControlFlags, UI_CTRL_FLAG_MOUSEOVER_POS ); } +bool cUIControl::IsMouseOverMeOrChilds() { + return 0 != Read32BitKey( &mControlFlags, UI_CTRL_FLAG_MOUSEOVER_ME_OR_CHILD_POS ); +} + Uint32 cUIControl::OnMouseDoubleClick( const eeVector2i& Pos, const Uint32 Flags ) { SendMouseEvent( cUIEvent::EventMouseDoubleClick, Pos, Flags ); return 1; @@ -715,6 +720,8 @@ cUIControl * cUIControl::OverFind( const eeVector2f& Point ) { UpdateQuad(); if ( PointInsidePolygon2( mPoly, Point ) ) { + WriteCtrlFlag( UI_CTRL_FLAG_MOUSEOVER_ME_OR_CHILD_POS, 1 ); + cUIControl * ChildLoop = mChildLast; while ( NULL != ChildLoop ) { diff --git a/src/ui/cuicontrol.hpp b/src/ui/cuicontrol.hpp index 6a8995199..a292af840 100644 --- a/src/ui/cuicontrol.hpp +++ b/src/ui/cuicontrol.hpp @@ -58,15 +58,15 @@ class EE_API cUIControl { void PosSet( const eeVector2i& pos ) { Pos.x = pos.x; Pos.y = pos.y; } void PosSet( const Int32& X, const Int32& Y ) { Pos.x = X; Pos.y = Y; } void Parent( cUIControl * Ctrl ) { ParentCtrl = Ctrl; } - void SizeGet( const eeSize& size ) { Size.x = size.x; Size.y = size.y; } - void SizeGet( const Int32& Width, const Int32& Height ) { Size.x = Width; Size.y = Height; } + void SizeSet( const eeSize& size ) { Size.x = size.x; Size.y = size.y; } + void SizeSet( const Int32& Width, const Int32& Height ) { Size.x = Width; Size.y = Height; } - cUIControl * ParentCtrl; - eeVector2i Pos; - eeSize Size; - Uint32 Flags; - cUIBackground Background; - cUIBorder Border; + cUIControl * ParentCtrl; + eeVector2i Pos; + eeSize Size; + Uint32 Flags; + cUIBackground Background; + cUIBorder Border; EE_PRE_BLEND_FUNC Blend; }; @@ -201,6 +201,8 @@ class EE_API cUIControl { bool IsMouseOver(); + bool IsMouseOverMeOrChilds(); + const eePolygon2f& GetPolygon() const; const eeVector2f& GetPolygonCenter() const; diff --git a/src/ui/cuidragable.cpp b/src/ui/cuidragable.cpp index a56a672d0..a17038157 100644 --- a/src/ui/cuidragable.cpp +++ b/src/ui/cuidragable.cpp @@ -8,6 +8,7 @@ cUIDragable::cUIDragable( const cUIControl::CreateParams& Params ) : mDragging( false ), mDragButton( EE_BUTTON_LMASK ) { + mType |= UI_TYPE_CONTROL_DRAGABLE; } cUIDragable::~cUIDragable() { diff --git a/src/ui/cuidropdownlist.cpp b/src/ui/cuidropdownlist.cpp index bde57e88e..f775880c1 100644 --- a/src/ui/cuidropdownlist.cpp +++ b/src/ui/cuidropdownlist.cpp @@ -111,10 +111,12 @@ void cUIDropDownList::Show() { mListBox->Enabled( true ); mListBox->Visible( true ); - if ( 255.f == mListBox->Alpha() ) - mListBox->StartAlphaAnim( 0.f, 255.f, cUIThemeManager::instance()->ControlsFadeInTime() ); - else - mListBox->CreateFadeIn( cUIThemeManager::instance()->ControlsFadeInTime() ); + if ( cUIThemeManager::instance()->DefaultEffectsEnabled() ) { + if ( 255.f == mListBox->Alpha() ) + mListBox->StartAlphaAnim( 0.f, 255.f, cUIThemeManager::instance()->ControlsFadeInTime() ); + else + mListBox->CreateFadeIn( cUIThemeManager::instance()->ControlsFadeInTime() ); + } } void cUIDropDownList::Hide() { diff --git a/src/ui/cuigfx.cpp b/src/ui/cuigfx.cpp index d2a3c838e..7fb1fe46a 100644 --- a/src/ui/cuigfx.cpp +++ b/src/ui/cuigfx.cpp @@ -3,7 +3,7 @@ namespace EE { namespace UI { cUIGfx::cUIGfx( const cUIGfx::CreateParams& Params ) : - cUIControlAnim( Params ), + cUIComplexControl( Params ), mShape( Params.Shape ), mColor( Params.ShapeColor ), mRender( Params.ShapeRender ) diff --git a/src/ui/cuigfx.hpp b/src/ui/cuigfx.hpp index 987dd30f8..720bbde3a 100644 --- a/src/ui/cuigfx.hpp +++ b/src/ui/cuigfx.hpp @@ -1,18 +1,20 @@ #ifndef EE_UICUIGFX_H #define EE_UICUIGFX_H -#include "cuicontrolanim.hpp" +#include "cuicomplexcontrol.hpp" namespace EE { namespace UI { -class EE_API cUIGfx : public cUIControlAnim { +class EE_API cUIGfx : public cUIComplexControl { public: - class CreateParams : public cUIControl::CreateParams { + class CreateParams : public cUIComplexControl::CreateParams { public: - inline CreateParams() : cUIControl::CreateParams() { - Shape = NULL; - ShapeColor = eeColorA(); - ShapeRender = RN_NORMAL; + inline CreateParams() : + cUIComplexControl::CreateParams(), + Shape( NULL ), + ShapeColor(), + ShapeRender( RN_NORMAL ) + { } inline ~CreateParams() {} diff --git a/src/ui/cuilistbox.cpp b/src/ui/cuilistbox.cpp index e01446b98..d5cc5db06 100644 --- a/src/ui/cuilistbox.cpp +++ b/src/ui/cuilistbox.cpp @@ -4,7 +4,7 @@ namespace EE { namespace UI { cUIListBox::cUIListBox( cUIListBox::CreateParams& Params ) : - cUIControlAnim( Params ), + cUIComplexControl( Params ), mRowHeight( Params.RowHeight ), mVScrollMode( Params.VScrollMode ), mHScrollMode( Params.HScrollMode ), diff --git a/src/ui/cuilistbox.hpp b/src/ui/cuilistbox.hpp index 864bbd833..e918a2389 100644 --- a/src/ui/cuilistbox.hpp +++ b/src/ui/cuilistbox.hpp @@ -8,12 +8,12 @@ namespace EE { namespace UI { -class EE_API cUIListBox : public cUIControlAnim { +class EE_API cUIListBox : public cUIComplexControl { public: - class CreateParams : public cUIControlAnim::CreateParams { + class CreateParams : public cUIComplexControl::CreateParams { public: inline CreateParams() : - cUIControl::CreateParams(), + cUIComplexControl::CreateParams(), RowHeight( 0 ), SmoothScroll( true ), VScrollMode( UI_SCROLLBAR_AUTO ), diff --git a/src/ui/cuilistboxcontainer.cpp b/src/ui/cuilistboxcontainer.cpp index 59df9b4ef..51244c7e5 100644 --- a/src/ui/cuilistboxcontainer.cpp +++ b/src/ui/cuilistboxcontainer.cpp @@ -44,6 +44,8 @@ cUIControl * cUIListBoxContainer::OverFind( const eeVector2f& Point ) { UpdateQuad(); if ( PointInsidePolygon2( mPoly, Point ) ) { + WriteCtrlFlag( UI_CTRL_FLAG_MOUSEOVER_ME_OR_CHILD_POS, 1 ); + for ( Uint32 i = LBParent->mVisibleFirst; i <= LBParent->mVisibleLast; i++ ) { if ( NULL != LBParent->mItems[i] ) { cUIControl * ChildOver = LBParent->mItems[i]->OverFind( Point ); diff --git a/src/ui/cuimenu.cpp b/src/ui/cuimenu.cpp index 7692a603e..bbf7828fe 100644 --- a/src/ui/cuimenu.cpp +++ b/src/ui/cuimenu.cpp @@ -4,7 +4,7 @@ namespace EE { namespace UI { cUIMenu::cUIMenu( cUIMenu::CreateParams& Params ) : - cUIControlAnim( Params ), + cUIComplexControl( Params ), mPadding( Params.PaddingContainer ), mFont( Params.Font ), mFontColor( Params.FontColor ), diff --git a/src/ui/cuimenu.hpp b/src/ui/cuimenu.hpp index 927deb12a..90c0ad71e 100644 --- a/src/ui/cuimenu.hpp +++ b/src/ui/cuimenu.hpp @@ -9,12 +9,12 @@ namespace EE { namespace UI { -class EE_API cUIMenu : public cUIControlAnim { +class EE_API cUIMenu : public cUIComplexControl { public: - class CreateParams : public cUIControlAnim::CreateParams { + class CreateParams : public cUIComplexControl::CreateParams { public: inline CreateParams() : - cUIControl::CreateParams(), + cUIComplexControl::CreateParams(), RowHeight( 0 ), PaddingContainer(), Font( NULL ), diff --git a/src/ui/cuiprogressbar.cpp b/src/ui/cuiprogressbar.cpp index b590c61a8..c454493d6 100644 --- a/src/ui/cuiprogressbar.cpp +++ b/src/ui/cuiprogressbar.cpp @@ -3,7 +3,7 @@ namespace EE { namespace UI { cUIProgressBar::cUIProgressBar( const cUIProgressBar::CreateParams& Params ) : - cUIControlAnim( Params ), + cUIComplexControl( Params ), mVerticalExpand( Params.VerticalExpand ), mSpeed( Params.MovementSpeed ), mFillerMargin( Params.FillerMargin ), diff --git a/src/ui/cuiprogressbar.hpp b/src/ui/cuiprogressbar.hpp index 4b562f5ee..256739370 100644 --- a/src/ui/cuiprogressbar.hpp +++ b/src/ui/cuiprogressbar.hpp @@ -7,7 +7,7 @@ namespace EE { namespace UI { -class cUIProgressBar : public cUIControlAnim { +class cUIProgressBar : public cUIComplexControl { public: class CreateParams : public cUITextBox::CreateParams { public: diff --git a/src/ui/cuipushbutton.cpp b/src/ui/cuipushbutton.cpp index 0e738bca0..3484ccf00 100644 --- a/src/ui/cuipushbutton.cpp +++ b/src/ui/cuipushbutton.cpp @@ -3,7 +3,7 @@ namespace EE { namespace UI { cUIPushButton::cUIPushButton( const cUIPushButton::CreateParams& Params ) : - cUIControlAnim( Params ), + cUIComplexControl( Params ), mFontColor( Params.FontColor ), mFontOverColor( Params.FontOverColor ), mIcon( NULL ), diff --git a/src/ui/cuipushbutton.hpp b/src/ui/cuipushbutton.hpp index 995223c46..cae710970 100644 --- a/src/ui/cuipushbutton.hpp +++ b/src/ui/cuipushbutton.hpp @@ -1,12 +1,13 @@ #ifndef EE_UICUIPUSHBUTTON_HPP #define EE_UICUIPUSHBUTTON_HPP +#include "cuicomplexcontrol.hpp" #include "cuitextbox.hpp" #include "cuigfx.hpp" namespace EE { namespace UI { -class EE_API cUIPushButton : public cUIControlAnim { +class EE_API cUIPushButton : public cUIComplexControl { public: class CreateParams : public cUITextBox::CreateParams { public: diff --git a/src/ui/cuiscrollbar.cpp b/src/ui/cuiscrollbar.cpp index d52776046..8fa9a8a66 100644 --- a/src/ui/cuiscrollbar.cpp +++ b/src/ui/cuiscrollbar.cpp @@ -4,7 +4,7 @@ namespace EE { namespace UI { cUIScrollBar::cUIScrollBar( const cUIScrollBar::CreateParams& Params ) : - cUIControlAnim( Params ) + cUIComplexControl( Params ) { mType |= UI_TYPE_GET( UI_TYPE_SCROLLBAR ); diff --git a/src/ui/cuiscrollbar.hpp b/src/ui/cuiscrollbar.hpp index 3e688f4a8..537ca1294 100644 --- a/src/ui/cuiscrollbar.hpp +++ b/src/ui/cuiscrollbar.hpp @@ -1,17 +1,19 @@ #ifndef EE_UICUISCROLLBAR_HPP #define EE_UICUISCROLLBAR_HPP -#include "cuicontrolanim.hpp" +#include "cuicomplexcontrol.hpp" #include "cuislider.hpp" namespace EE { namespace UI { -class cUIScrollBar : public cUIControlAnim { +class cUIScrollBar : public cUIComplexControl { public: - class CreateParams : public cUIControl::CreateParams { + class CreateParams : public cUIComplexControl::CreateParams { public: - inline CreateParams() : cUIControl::CreateParams() { - VerticalScrollBar = false; + inline CreateParams() : + cUIComplexControl::CreateParams(), + VerticalScrollBar( false ) + { } inline ~CreateParams() {} diff --git a/src/ui/cuislider.cpp b/src/ui/cuislider.cpp index 74d584ab8..b3c3c0b15 100644 --- a/src/ui/cuislider.cpp +++ b/src/ui/cuislider.cpp @@ -4,7 +4,7 @@ namespace EE { namespace UI { cUISlider::cUISlider( const cUISlider::CreateParams& Params ) : - cUIControlAnim( Params ), + cUIComplexControl( Params ), mVertical( Params.VerticalSlider ), mAllowHalfSliderOut( Params.AllowHalfSliderOut ), mExpandBackground( Params.ExpandBackground ), diff --git a/src/ui/cuislider.hpp b/src/ui/cuislider.hpp index 92b5e96e0..218a672cf 100644 --- a/src/ui/cuislider.hpp +++ b/src/ui/cuislider.hpp @@ -1,19 +1,21 @@ #ifndef EE_UIcUISlider_HPP #define EE_UIcUISlider_HPP -#include "cuicontrolanim.hpp" +#include "cuicomplexcontrol.hpp" #include "cuisliderbutton.hpp" namespace EE { namespace UI { -class EE_API cUISlider : public cUIControlAnim { +class EE_API cUISlider : public cUIComplexControl { public: - class CreateParams : public cUIControl::CreateParams { + class CreateParams : public cUIComplexControl::CreateParams { public: - inline CreateParams() : cUIControl::CreateParams() { - VerticalSlider = false; - AllowHalfSliderOut = true; - ExpandBackground = false; + inline CreateParams() : + cUIComplexControl::CreateParams(), + VerticalSlider( false ), + AllowHalfSliderOut( true ), + ExpandBackground( false ) + { } inline ~CreateParams() {} diff --git a/src/ui/cuispinbox.cpp b/src/ui/cuispinbox.cpp index abe5f951e..9c58f5e28 100644 --- a/src/ui/cuispinbox.cpp +++ b/src/ui/cuispinbox.cpp @@ -3,7 +3,7 @@ namespace EE { namespace UI { cUISpinBox::cUISpinBox( const cUISpinBox::CreateParams& Params ) : - cUIControlAnim( Params ), + cUIComplexControl( Params ), mMinValue( 0.f ), mMaxValue( 1024.f ), mValue( Params.DefaultValue ), diff --git a/src/ui/cuispinbox.hpp b/src/ui/cuispinbox.hpp index 47eab4e8c..b25850000 100644 --- a/src/ui/cuispinbox.hpp +++ b/src/ui/cuispinbox.hpp @@ -6,7 +6,7 @@ namespace EE { namespace UI { -class EE_API cUISpinBox : public cUIControlAnim { +class EE_API cUISpinBox : public cUIComplexControl { public: class CreateParams : public cUITextInput::CreateParams { public: diff --git a/src/ui/cuisprite.cpp b/src/ui/cuisprite.cpp index 967cc1bf6..3665c158d 100644 --- a/src/ui/cuisprite.cpp +++ b/src/ui/cuisprite.cpp @@ -3,7 +3,7 @@ namespace EE { namespace UI { cUISprite::cUISprite( const cUISprite::CreateParams& Params ) : - cUIControlAnim( Params ), + cUIComplexControl( Params ), mSprite( Params.Sprite ), mRender( Params.SpriteRender ) { diff --git a/src/ui/cuisprite.hpp b/src/ui/cuisprite.hpp index 70c40dab8..8d606d205 100644 --- a/src/ui/cuisprite.hpp +++ b/src/ui/cuisprite.hpp @@ -1,17 +1,19 @@ #ifndef EE_UICUISPRITE_HPP #define EE_UICUISPRITE_HPP -#include "cuicontrolanim.hpp" +#include "cuicomplexcontrol.hpp" namespace EE { namespace UI { -class EE_API cUISprite : public cUIControlAnim { +class EE_API cUISprite : public cUIComplexControl { public: - class CreateParams : public cUIControlAnim::CreateParams { + class CreateParams : public cUIComplexControl::CreateParams { public: - inline CreateParams() : cUIControlAnim::CreateParams() { - Sprite = NULL; - SpriteRender = RN_NORMAL; + inline CreateParams() : + cUIComplexControl::CreateParams(), + Sprite( NULL ), + SpriteRender( RN_NORMAL ) + { } inline ~CreateParams() {} diff --git a/src/ui/cuitextbox.cpp b/src/ui/cuitextbox.cpp index a91bfe7f9..c36845c10 100644 --- a/src/ui/cuitextbox.cpp +++ b/src/ui/cuitextbox.cpp @@ -5,7 +5,7 @@ namespace EE { namespace UI { cUITextBox::cUITextBox( const cUITextBox::CreateParams& Params ) : - cUIControlAnim( Params ), + cUIComplexControl( Params ), mFontColor( Params.FontColor ), mFontShadowColor( Params.FontShadowColor ), mAlignOffset( 0.f, 0.f ) diff --git a/src/ui/cuitextbox.hpp b/src/ui/cuitextbox.hpp index 3dba3907e..f396c7200 100644 --- a/src/ui/cuitextbox.hpp +++ b/src/ui/cuitextbox.hpp @@ -1,16 +1,16 @@ #ifndef EE_UICUITEXTBOX_H #define EE_UICUITEXTBOX_H -#include "cuicontrolanim.hpp" +#include "cuicomplexcontrol.hpp" namespace EE { namespace UI { -class EE_API cUITextBox : public cUIControlAnim { +class EE_API cUITextBox : public cUIComplexControl { public: - class CreateParams : public cUIControl::CreateParams { + class CreateParams : public cUIComplexControl::CreateParams { public: inline CreateParams() : - cUIControl::CreateParams(), + cUIComplexControl::CreateParams(), Font( NULL ), FontColor( 0, 0, 0, 255 ), FontShadowColor( 255, 255, 255, 150 ) diff --git a/src/ui/cuitheme.cpp b/src/ui/cuitheme.cpp index 14bc125aa..d5be1f588 100644 --- a/src/ui/cuitheme.cpp +++ b/src/ui/cuitheme.cpp @@ -57,6 +57,7 @@ static void LoadThemeElements() { UI_THEME_ELEMENTS.push_back( "menuarrow" ); UI_THEME_ELEMENTS.push_back( "textedit" ); UI_THEME_ELEMENTS.push_back( "textedit_box" ); + UI_THEME_ELEMENTS.push_back( "tooltip" ); } } diff --git a/src/ui/cuithememanager.cpp b/src/ui/cuithememanager.cpp index 79dfde4c1..b303dc8a8 100644 --- a/src/ui/cuithememanager.cpp +++ b/src/ui/cuithememanager.cpp @@ -11,7 +11,10 @@ cUIThemeManager::cUIThemeManager() : mAutoApplyDefaultTheme( true ), mEnableDefaultEffects( false ), mFadeInTime( 100.f ), - mFadeOutTime( 100.f ) + mFadeOutTime( 100.f ), + mTooltipTimeToShow( 200 ), + mTooltipFollowMouse( true ), + mCursorSize( 16, 16 ) { } @@ -88,4 +91,28 @@ void cUIThemeManager::ControlsFadeOutTime( const eeFloat& Time ) { mFadeOutTime = Time; } +void cUIThemeManager::TooltipTimeToShow( const Uint32& Time ) { + mTooltipTimeToShow = Time; +} + +const Uint32& cUIThemeManager::TooltipTimeToShow() const { + return mTooltipTimeToShow; +} + +void cUIThemeManager::TooltipFollowMouse( const bool& Follow ) { + mTooltipFollowMouse = Follow; +} + +const bool& cUIThemeManager::TooltipFollowMouse() const { + return mTooltipFollowMouse; +} + +void cUIThemeManager::CursorSize( const eeSize& Size ) { + mCursorSize = Size; +} + +const eeSize& cUIThemeManager::CursorSize() const { + return mCursorSize; +} + }} diff --git a/src/ui/cuithememanager.hpp b/src/ui/cuithememanager.hpp index c02e9fc50..e8a8937a0 100644 --- a/src/ui/cuithememanager.hpp +++ b/src/ui/cuithememanager.hpp @@ -46,6 +46,18 @@ class EE_API cUIThemeManager : public tResourceManager, public tSingle const eeFloat& ControlsFadeOutTime() const; void ControlsFadeOutTime( const eeFloat& Time ); + + void TooltipTimeToShow( const Uint32& Time ); + + const Uint32& TooltipTimeToShow() const; + + void TooltipFollowMouse( const bool& Follow ); + + const bool& TooltipFollowMouse() const; + + void CursorSize( const eeSize& Size ); + + const eeSize& CursorSize() const; protected: cFont * mFont; cUITheme * mThemeDefault; @@ -54,6 +66,11 @@ class EE_API cUIThemeManager : public tResourceManager, public tSingle bool mEnableDefaultEffects; eeFloat mFadeInTime; eeFloat mFadeOutTime; + + Uint32 mTooltipTimeToShow; + bool mTooltipFollowMouse; + + eeSize mCursorSize; }; }} diff --git a/src/ui/cuitooltip.cpp b/src/ui/cuitooltip.cpp new file mode 100644 index 000000000..84f874622 --- /dev/null +++ b/src/ui/cuitooltip.cpp @@ -0,0 +1,241 @@ +#include "cuitooltip.hpp" +#include "cuimanager.hpp" + +namespace EE { namespace UI { + +cUITooltip::cUITooltip( cUITooltip::CreateParams& Params ) : + cUIControlAnim( Params ), + mFontColor( Params.FontColor ), + mFontShadowColor( Params.FontShadowColor ), + mAlignOffset( 0.f, 0.f ), + mTooltipTime( 0.f ) +{ + mType |= UI_TYPE_TOOLTIP; + + mTextCache = eeNew( cTextCache, () ); + mTextCache->Font( Params.Font ); + mTextCache->Color( mFontColor ); + mTextCache->ShadowColor( mFontShadowColor ); + + if ( NULL == Params.Font ) { + if ( NULL != cUIThemeManager::instance()->DefaultFont() ) + mTextCache->Font( cUIThemeManager::instance()->DefaultFont() ); + else + eePRINT( "cUITooltip::cUITextBox : Created a UI TextBox without a defined font.\n" ); + } + + AutoAlign(); + + if ( Params.ParentCtrl != cUIManager::instance()->MainControl() ) + Parent( cUIManager::instance()->MainControl() ); + + ApplyDefaultTheme(); +} + +cUITooltip::~cUITooltip() { + eeSAFE_DELETE( mTextCache ); +} + +void cUITooltip::SetTheme( cUITheme * Theme ) { + cUIControl::SetTheme( Theme, "tooltip" ); + + AutoPadding(); + + if ( NULL == mTextCache->Font() && NULL != Theme->Font() ) { + mTextCache->Font( Theme->Font() ); + } +} + +void cUITooltip::AutoPadding() { + if ( mFlags & UI_AUTO_PADDING ) { + mPadding = MakePadding( true, true, true, true ); + } +} + +void cUITooltip::Show() { + if ( !Visible() ) { + ToFront(); + + Visible( true ); + + if ( cUIThemeManager::instance()->DefaultEffectsEnabled() ) { + if ( 255.f == mAlpha ) + StartAlphaAnim( 0.f, 255.f, cUIThemeManager::instance()->ControlsFadeInTime() ); + else + CreateFadeIn( cUIThemeManager::instance()->ControlsFadeInTime() ); + } + } +} + +void cUITooltip::Hide() { + if ( Visible() ) { + if ( cUIThemeManager::instance()->DefaultEffectsEnabled() ) { + DisableFadeOut( cUIThemeManager::instance()->ControlsFadeOutTime() ); + } else { + Visible( false ); + } + } +} + +void cUITooltip::Draw() { + if ( mVisible && 0.f != mAlpha ) { + cUIControlAnim::Draw(); + + if ( mTextCache->GetTextWidth() ) { + mTextCache->Draw( (eeFloat)mScreenPos.x + mAlignOffset.x, (eeFloat)mScreenPos.y + mAlignOffset.y, Flags(), 1.f, 0.f, mBlend ); + } + } +} + +cFont * cUITooltip::Font() const { + return mTextCache->Font(); +} + +void cUITooltip::Font( cFont * font ) { + if ( mTextCache->Font() != font ) { + mTextCache->Font( font ); + AutoPadding(); + AutoSize(); + AutoAlign(); + OnFontChanged(); + } +} + +const std::wstring& cUITooltip::Text() { + return mTextCache->Text(); +} + +void cUITooltip::Text( const std::string& text ) { + Text( stringTowstring( text ) ); +} + +void cUITooltip::Text( const std::wstring& text ) { + mTextCache->Text( text ); + AutoPadding(); + AutoSize(); + AutoAlign(); + OnTextChanged(); +} + +const eeColorA& cUITooltip::Color() const { + return mFontColor; +} + +void cUITooltip::Color( const eeColorA& color ) { + mFontColor = color; + Alpha( color.A() ); +} + +const eeColorA& cUITooltip::ShadowColor() const { + return mFontShadowColor; +} + +void cUITooltip::ShadowColor( const eeColorA& color ) { + mFontShadowColor = color; + Alpha( color.A() ); + mTextCache->ShadowColor( mFontColor ); +} + +void cUITooltip::Alpha( const eeFloat& alpha ) { + cUIControlAnim::Alpha( alpha ); + mFontColor.Alpha = (Uint8)alpha; + mFontShadowColor.Alpha = (Uint8)alpha; + + mTextCache->Color( mFontColor ); +} + +void cUITooltip::AutoSize() { + if ( mFlags & UI_AUTO_SIZE ) { + mSize.Width( (eeInt)mTextCache->GetTextWidth() + mPadding.Left + mPadding.Right ); + mSize.Height( (eeInt)mTextCache->GetTextHeight() + mPadding.Top + mPadding.Bottom ); + } +} + +void cUITooltip::AutoAlign() { + Uint32 Width = mSize.Width() - mPadding.Left - mPadding.Right; + Uint32 Height = mSize.Height() - mPadding.Top - mPadding.Right; + + switch ( FontHAlignGet( Flags() ) ) { + case UI_HALIGN_CENTER: + mAlignOffset.x = mPadding.Left + (eeFloat)( (Int32)( Width - mTextCache->GetTextWidth() ) / 2 ); + break; + case UI_HALIGN_RIGHT: + mAlignOffset.x = ( (eeFloat)Width - (eeFloat)mTextCache->GetTextWidth() ) - mPadding.Right; + break; + case UI_HALIGN_LEFT: + mAlignOffset.x = mPadding.Left; + break; + } + + switch ( FontVAlignGet( Flags() ) ) { + case UI_VALIGN_CENTER: + mAlignOffset.y = mPadding.Top + (eeFloat)( ( (Int32)( Height - mTextCache->GetTextHeight() ) ) / 2 ); + break; + case UI_VALIGN_BOTTOM: + mAlignOffset.y = ( (eeFloat)Height - (eeFloat)mTextCache->GetTextHeight() ) - mPadding.Bottom; + break; + case UI_VALIGN_TOP: + mAlignOffset.y = mPadding.Top; + break; + } +} + +void cUITooltip::OnSizeChange() { + AutoPadding(); + AutoSize(); + AutoAlign(); + + cUIControlAnim::OnSizeChange(); + + mTextCache->Cache(); +} + +void cUITooltip::OnTextChanged() { + SendCommonEvent( cUIEvent::EventOnTextChanged ); +} + +void cUITooltip::OnFontChanged() { + SendCommonEvent( cUIEvent::EventOnFontChanged ); +} + +void cUITooltip::Padding( const eeRecti& padding ) { + mPadding = padding; +} + +const eeRecti& cUITooltip::Padding() const { + return mPadding; +} + +cTextCache * cUITooltip::GetTextCache() { + return mTextCache; +} + +eeFloat cUITooltip::GetTextWidth() { + return mTextCache->GetTextWidth(); +} + +eeFloat cUITooltip::GetTextHeight() { + return mTextCache->GetTextHeight(); +} + +const eeInt& cUITooltip::GetNumLines() const { + return mTextCache->GetNumLines(); +} + +const eeVector2f& cUITooltip::AlignOffset() const { + return mAlignOffset; +} + +void cUITooltip::TooltipTime( const eeFloat& Time ) { + mTooltipTime = Time; +} + +void cUITooltip::TooltipTimeAdd( const eeFloat& Time ) { + mTooltipTime += Time; +} + +const eeFloat& cUITooltip::TooltipTime() const { + return mTooltipTime; +} + +}} diff --git a/src/ui/cuitooltip.hpp b/src/ui/cuitooltip.hpp new file mode 100644 index 000000000..0eaf53283 --- /dev/null +++ b/src/ui/cuitooltip.hpp @@ -0,0 +1,111 @@ +#ifndef EE_UICUITOOLTIP_HPP +#define EE_UICUITOOLTIP_HPP + +#include "cuicontrolanim.hpp" + +namespace EE { namespace UI { + +class EE_API cUITooltip : public cUIControlAnim { + public: + class CreateParams : public cUIControlAnim::CreateParams { + public: + inline CreateParams() : + cUIControlAnim::CreateParams(), + Font( NULL ), + FontColor( 0, 0, 0, 255 ), + FontShadowColor( 255, 255, 255, 150 ) + { + cUITheme * Theme = cUIThemeManager::instance()->DefaultTheme(); + + if ( NULL != Theme ) { + Font = Theme->Font(); + FontColor = Theme->FontColor(); + FontShadowColor = Theme->FontShadowColor(); + } + + if ( NULL == Font ) + Font = cUIThemeManager::instance()->DefaultFont(); + } + + inline ~CreateParams() {} + + cFont * Font; + eeColorA FontColor; + eeColorA FontShadowColor; + }; + + cUITooltip( cUITooltip::CreateParams& Params ); + + ~cUITooltip(); + + virtual void SetTheme( cUITheme * Theme ); + + void Show(); + + void Hide(); + + virtual void Draw(); + + virtual void Alpha( const eeFloat& alpha ); + + cFont * Font() const; + + void Font( cFont * font ); + + virtual const std::wstring& Text(); + + virtual void Text( const std::wstring& text ); + + virtual void Text( const std::string& text ); + + const eeColorA& Color() const; + + void Color( const eeColorA& color ); + + const eeColorA& ShadowColor() const; + + void ShadowColor( const eeColorA& color ); + + virtual void OnTextChanged(); + + virtual void OnFontChanged(); + + virtual void Padding( const eeRecti& padding ); + + const eeRecti& Padding() const; + + cTextCache * GetTextCache(); + + eeFloat GetTextWidth(); + + eeFloat GetTextHeight(); + + const eeInt& GetNumLines() const; + + const eeVector2f& AlignOffset() const; + + void TooltipTime( const eeFloat& Time ); + + void TooltipTimeAdd( const eeFloat& Time ); + + const eeFloat& TooltipTime() const; + protected: + cTextCache * mTextCache; + eeColorA mFontColor; + eeColorA mFontShadowColor; + eeVector2f mAlignOffset; + eeRecti mPadding; + eeFloat mTooltipTime; + + virtual void OnSizeChange(); + + virtual void AutoSize(); + + virtual void AutoAlign(); + + virtual void AutoPadding(); +}; + +}} + +#endif diff --git a/src/ui/uihelper.hpp b/src/ui/uihelper.hpp index 674e39dc8..dacdfb95b 100644 --- a/src/ui/uihelper.hpp +++ b/src/ui/uihelper.hpp @@ -18,6 +18,7 @@ enum UI_CONTROL_FLAGS_POS { UI_CTRL_FLAG_SELECTED_POS = 5, UI_CTRL_FLAG_DISABLE_CHECK_CLOSE_CHILDS_POS = 6, UI_CTRL_FLAG_DISABLE_FADE_OUT_POS = 7, + UI_CTRL_FLAG_MOUSEOVER_ME_OR_CHILD_POS = 8, UI_CTRL_FLAG_FREE_USE_POS = 31 }; @@ -30,6 +31,7 @@ enum UI_CONTROL_FLAGS_VALUES { UI_CTRL_FLAG_SELECTED = (1<