diff --git a/src/test/ee.cpp b/src/test/ee.cpp index 06019bb59..d0e30eaca 100644 --- a/src/test/ee.cpp +++ b/src/test/ee.cpp @@ -608,7 +608,7 @@ void cEETest::CreateUI() { MenuParams.MinWidth = 100; MenuParams.MinSpaceForIcons = 16; MenuParams.PosSet( 0, 0 ); - MenuParams.FontOverColor = eeColorA( 255, 255, 255, 255 ); + MenuParams.FontSelectedColor = eeColorA( 255, 255, 255, 255 ); Menu = eeNew( cUIPopUpMenu, ( MenuParams ) ); Menu->Add( L"New", cGlobalShapeGroup::instance()->GetByName( "aqua_button_ok" ) ); Menu->Add( L"Open..." ); diff --git a/src/ui/cuicontrol.cpp b/src/ui/cuicontrol.cpp index f0fa7b8e8..ab23a62e1 100644 --- a/src/ui/cuicontrol.cpp +++ b/src/ui/cuicontrol.cpp @@ -257,12 +257,12 @@ void cUIControl::SendCommonEvent( const Uint32& Event ) { Uint32 cUIControl::OnKeyDown( const cUIEventKey& Event ) { SendEvent( &Event ); - return 1; + return 0; } Uint32 cUIControl::OnKeyUp( const cUIEventKey& Event ) { SendEvent( &Event ); - return 1; + return 0; } Uint32 cUIControl::OnMouseMove( const eeVector2i& Pos, const Uint32 Flags ) { @@ -981,4 +981,8 @@ void cUIControl::DisableChildCloseCheck() { mControlFlags |= UI_CTRL_FLAG_DISABLE_CHECK_CLOSE_CHILDS; } +void cUIControl::SetFocus() { + cUIManager::instance()->FocusControl( this ); +} + }} diff --git a/src/ui/cuicontrol.hpp b/src/ui/cuicontrol.hpp index 01e7a481b..d4c9bc239 100644 --- a/src/ui/cuicontrol.hpp +++ b/src/ui/cuicontrol.hpp @@ -211,7 +211,15 @@ class EE_API cUIControl { bool HasFocus() const; + void SetFocus(); + bool IsParentOf( cUIControl * Ctrl ); + + void SendEvent( const cUIEvent * Event ); + + void SendMouseEvent( const Uint32& Event, const eeVector2i& Pos, const Uint32& Flags ); + + void SendCommonEvent( const Uint32& Event ); protected: friend class cUIManager; friend class cUIControlAnim; @@ -327,12 +335,6 @@ class EE_API cUIControl { void ClipTo(); - void SendEvent( const cUIEvent * Event ); - - void SendMouseEvent( const Uint32& Event, const eeVector2i& Pos, const Uint32& Flags ); - - void SendCommonEvent( const Uint32& Event ); - void SetPrevSkinState(); void UpdateScreenPos(); diff --git a/src/ui/cuidragable.hpp b/src/ui/cuidragable.hpp index f5543ae3f..02ae02322 100644 --- a/src/ui/cuidragable.hpp +++ b/src/ui/cuidragable.hpp @@ -20,7 +20,7 @@ class EE_API cUIDragable : public cUIControl { virtual void Update(); - const bool& DragEnable() const; + const bool& DragEnable() const; void DragEnable( const bool& enable ); void DragButton( const Uint32& Button ); @@ -34,7 +34,7 @@ class EE_API cUIDragable : public cUIControl { eeVector2i mDraggingPoint; Uint32 mDragButton; - virtual Uint32 OnMouseDown( const eeVector2i& Pos, const Uint32 Flags ); + virtual Uint32 OnMouseDown( const eeVector2i& Pos, const Uint32 Flags ); virtual Uint32 OnMouseUp( const eeVector2i& Pos, const Uint32 Flags ); }; diff --git a/src/ui/cuidropdownlist.cpp b/src/ui/cuidropdownlist.cpp index a1f299f61..8b1fb3863 100644 --- a/src/ui/cuidropdownlist.cpp +++ b/src/ui/cuidropdownlist.cpp @@ -28,6 +28,9 @@ cUIDropDownList::cUIDropDownList( cUIDropDownList::CreateParams& Params ) : mListBox->AddEventListener( cUIEvent::EventOnComplexControlFocusLoss, cb::Make1( this, &cUIDropDownList::OnListBoxFocusLoss ) ); mListBox->AddEventListener( cUIEvent::EventOnSelected, cb::Make1( this, &cUIDropDownList::OnItemSelected ) ); + mListBox->AddEventListener( cUIEvent::EventOnItemClicked, cb::Make1( this, &cUIDropDownList::OnItemClicked ) ); + mListBox->AddEventListener( cUIEvent::EventOnItemKeyDown, cb::Make1( this, &cUIDropDownList::OnItemKeyDown ) ); + mListBox->AddEventListener( cUIEvent::EventKeyDown, cb::Make1( this, &cUIDropDownList::OnItemKeyDown ) ); } cUIDropDownList::~cUIDropDownList() { @@ -76,21 +79,31 @@ void cUIDropDownList::ShowListBox() { Show(); - cUIManager::instance()->FocusControl( mListBox ); + mListBox->SetFocus(); } else { Hide(); } } +void cUIDropDownList::OnItemKeyDown( const cUIEvent * Event ) { + const cUIEventKey * KEvent = reinterpret_cast ( Event ); + + if ( KEvent->KeyCode() == KEY_RETURN ) + OnItemClicked( Event ); +} + void cUIDropDownList::OnListBoxFocusLoss( const cUIEvent * Event ) { if ( cUIManager::instance()->FocusControl() != this ) { Hide(); } } -void cUIDropDownList::OnItemSelected( const cUIEvent * Event ) { +void cUIDropDownList::OnItemClicked( const cUIEvent * Event ) { Hide(); + SetFocus(); +} +void cUIDropDownList::OnItemSelected( const cUIEvent * Event ) { Text( mListBox->GetItemSelectedText() ); } diff --git a/src/ui/cuidropdownlist.hpp b/src/ui/cuidropdownlist.hpp index 33eb34210..ef90e4515 100644 --- a/src/ui/cuidropdownlist.hpp +++ b/src/ui/cuidropdownlist.hpp @@ -50,6 +50,10 @@ class EE_API cUIDropDownList : public cUITextInput { virtual void Hide(); Uint32 OnMouseClick( const eeVector2i& Pos, const Uint32 Flags ); + + virtual void OnItemClicked( const cUIEvent * Event ); + + virtual void OnItemKeyDown( const cUIEvent * Event ); }; }} diff --git a/src/ui/cuievent.hpp b/src/ui/cuievent.hpp index 74f073e6a..0f0dd2c14 100644 --- a/src/ui/cuievent.hpp +++ b/src/ui/cuievent.hpp @@ -36,6 +36,8 @@ class EE_API cUIEvent { EventOnComplexControlFocusLoss, EventOnItemClicked, EventOnHideByClick, + EventOnItemKeyDown, + EventOnItemKeyUp, EventUser, EventForceDWord = 0xFFFFFFFF }; diff --git a/src/ui/cuilistbox.cpp b/src/ui/cuilistbox.cpp index f702867ce..10aa0bf6e 100644 --- a/src/ui/cuilistbox.cpp +++ b/src/ui/cuilistbox.cpp @@ -518,7 +518,15 @@ void cUIListBox::UpdateScroll( bool FromScrollChange ) { } } +void cUIListBox::ItemKeyEvent( const cUIEventKey &Event ) { + cUIEventKey ItemEvent( Event.Ctrl(), cUIEvent::EventOnItemKeyDown, Event.KeyCode(), Event.Char() ); + SendEvent( &ItemEvent ); +} + void cUIListBox::ItemClicked( cUIListBoxItem * Item ) { + cUIEvent ItemEvent( Item, cUIEvent::EventOnItemClicked ); + SendEvent( &ItemEvent ); + if ( !( IsMultiSelect() && cUIManager::instance()->GetInput()->IsKeyDown( KEY_LCTRL ) ) ) ResetItemsStates(); } @@ -748,7 +756,7 @@ void cUIListBox::SelectPrev() { if ( mItems[ SelIndex ]->Pos().y < 0 ) { ScrollBar()->Value( (eeFloat)( SelIndex * mRowHeight ) / (eeFloat)( ( mItems.size() - 1 ) * mRowHeight ) ); - cUIManager::instance()->FocusControl( mItems[ SelIndex ] ); + mItems[ SelIndex ]->SetFocus(); } } @@ -774,7 +782,7 @@ void cUIListBox::SelectNext() { if ( mItems[ SelIndex ]->Pos().y + (Int32)RowHeight() > mContainer->Size().Height() ) { ScrollBar()->Value( (eeFloat)( SelIndex * mRowHeight ) / (eeFloat)( ( mItems.size() - 1 ) * mRowHeight ) ); - cUIManager::instance()->FocusControl( mItems[ SelIndex ] ); + mItems[ SelIndex ]->SetFocus(); } } @@ -783,6 +791,14 @@ void cUIListBox::SelectNext() { } } +Uint32 cUIListBox::OnKeyDown( const cUIEventKey &Event ) { + cUIControlAnim::OnKeyDown( Event ); + + ManageKeyboard(); + + return 1; +} + void cUIListBox::ManageKeyboard() { if ( !mSelected.size() || mFlags & UI_MULTI_SELECT ) return; @@ -806,7 +822,7 @@ void cUIListBox::ManageKeyboard() { ScrollBar()->Value( 0 ); - cUIManager::instance()->FocusControl( mItems[ 0 ] ); + mItems[ 0 ]->SetFocus(); mItems[ 0 ]->Select(); } @@ -818,7 +834,7 @@ void cUIListBox::ManageKeyboard() { ScrollBar()->Value( 1 ); - cUIManager::instance()->FocusControl( mItems[ Count() - 1 ] ); + mItems[ Count() - 1 ]->SetFocus(); mItems[ Count() - 1 ]->Select(); } diff --git a/src/ui/cuilistbox.hpp b/src/ui/cuilistbox.hpp index d867b27a5..b41875afa 100644 --- a/src/ui/cuilistbox.hpp +++ b/src/ui/cuilistbox.hpp @@ -205,6 +205,10 @@ class EE_API cUIListBox : public cUIControlAnim { virtual void OnAlphaChange(); virtual Uint32 OnMessage( const cUIMessage * Msg ); + + virtual Uint32 OnKeyDown( const cUIEventKey &Event ); + + void ItemKeyEvent( const cUIEventKey &Event ); }; }} diff --git a/src/ui/cuilistboxitem.cpp b/src/ui/cuilistboxitem.cpp index d7ff86f4f..90f1e4c37 100644 --- a/src/ui/cuilistboxitem.cpp +++ b/src/ui/cuilistboxitem.cpp @@ -14,7 +14,7 @@ cUIListBoxItem::cUIListBoxItem( cUITextBox::CreateParams& Params ) : cUIListBoxItem::~cUIListBoxItem() { if ( cUIManager::instance()->FocusControl() == this ) - cUIManager::instance()->FocusControl( mParentCtrl ); + mParentCtrl->SetFocus(); if ( cUIManager::instance()->OverControl() == this ) cUIManager::instance()->OverControl( mParentCtrl ); @@ -26,19 +26,25 @@ void cUIListBoxItem::SetTheme( cUITheme * Theme ) { Uint32 cUIListBoxItem::OnMouseClick( const eeVector2i& Pos, const Uint32 Flags ) { if ( Flags & EE_BUTTONS_LRM ) { + reinterpret_cast ( Parent()->Parent() )->ItemClicked( this ); + Select(); } return 1; } +Uint32 cUIListBoxItem::OnKeyDown( const cUIEventKey &Event ) { + reinterpret_cast ( Parent()->Parent() )->ItemKeyEvent( Event ); + + return 1; +} + void cUIListBoxItem::Select() { cUIListBox * LBParent = reinterpret_cast ( Parent()->Parent() ); bool wasSelected = 0 != ( mControlFlags & UI_CTRL_FLAG_SELECTED ); - LBParent->ItemClicked( this ); - if ( LBParent->IsMultiSelect() ) { if ( !wasSelected ) { SetSkinState( cUISkinState::StateSelected ); @@ -76,7 +82,7 @@ void cUIListBoxItem::Update() { Alpha( LBParent->Alpha() ); if ( IsMouseOver() ) { - if ( Flags & EE_BUTTONS_WUWD ) + if ( Flags & EE_BUTTONS_WUWD && LBParent->ScrollBar()->Visible() ) LBParent->ScrollBar()->Slider()->ManageClick( Flags ); } diff --git a/src/ui/cuilistboxitem.hpp b/src/ui/cuilistboxitem.hpp index 22500e5bd..d86671526 100644 --- a/src/ui/cuilistboxitem.hpp +++ b/src/ui/cuilistboxitem.hpp @@ -26,6 +26,8 @@ class EE_API cUIListBoxItem : public cUITextBox { virtual Uint32 OnMouseClick( const eeVector2i& Pos, const Uint32 Flags ); virtual Uint32 OnMouseExit( const eeVector2i& Pos, const Uint32 Flags ); + + virtual Uint32 OnKeyDown( const cUIEventKey &Event ); }; }} diff --git a/src/ui/cuimenu.cpp b/src/ui/cuimenu.cpp index e65c6904e..b9fe9b9a8 100644 --- a/src/ui/cuimenu.cpp +++ b/src/ui/cuimenu.cpp @@ -10,6 +10,7 @@ cUIMenu::cUIMenu( cUIMenu::CreateParams& Params ) : mFontColor( Params.FontColor ), mFontShadowColor( Params.FontShadowColor ), mFontOverColor( Params.FontOverColor ), + mFontSelectedColor( Params.FontSelectedColor ), mMinWidth( Params.MinWidth ), mMinSpaceForIcons( Params.MinSpaceForIcons ), mMaxWidth( 0 ), @@ -17,7 +18,9 @@ cUIMenu::cUIMenu( cUIMenu::CreateParams& Params ) : mNextPosY( 0 ), mBiggestIcon( mMinSpaceForIcons ), mItemSelected( NULL ), - mClickHide( false ) + mItemSelectedIndex( 0xFFFFFFFF ), + mClickHide( false ), + mLastTickMove( 0 ) { mType |= UI_TYPE_GET( UI_TYPE_MENU ); @@ -228,6 +231,15 @@ cUIControl * cUIMenu::GetItem( const std::wstring& Text ) { return NULL; } +Uint32 cUIMenu::GetItemIndex( cUIControl * Item ) { + for ( Uint32 i = 0; i < mItems.size(); i++ ) { + if ( mItems[i] == Item ) + return i; + } + + return 0xFFFFFFFF; +} + Uint32 cUIMenu::Count() const { return mItems.size(); } @@ -378,10 +390,17 @@ bool cUIMenu::Show() { bool cUIMenu::Hide() { Enabled( false ); Visible( false ); + + if ( NULL != mItemSelected ) + mItemSelected->SetSkinState( cUISkinState::StateNormal ); + + mItemSelected = NULL; + mItemSelectedIndex = 0xFFFFFFFF; + return true; } -void cUIMenu::SetItemSelected( cUIMenuItem * Item ) { +void cUIMenu::SetItemSelected( cUIControl * Item ) { if ( NULL != mItemSelected ) { if ( mItemSelected->IsType( UI_TYPE_MENUSUBMENU ) ) { cUIMenuSubMenu * tMenu = reinterpret_cast ( mItemSelected ); @@ -389,9 +408,123 @@ void cUIMenu::SetItemSelected( cUIMenuItem * Item ) { if ( NULL != tMenu->SubMenu() ) tMenu->SubMenu()->Hide(); } + + mItemSelected->SetSkinState( cUISkinState::StateNormal ); } - mItemSelected = Item; + if ( NULL != Item ) + Item->SetSkinState( cUISkinState::StateSelected ); + + if ( mItemSelected != Item ) { + mItemSelected = Item; + mItemSelectedIndex = GetItemIndex( mItemSelected ); + } +} + +void cUIMenu::TrySelect( cUIControl * Ctrl, bool Up ) { + if ( mItems.size() ) { + if ( !Ctrl->IsType( UI_TYPE_SEPARATOR ) ) { + SetItemSelected( Ctrl ); + } else { + Uint32 Index = GetItemIndex( Ctrl ); + + if ( Index != 0xFFFFFFFF ) { + if ( Up ) { + if ( Index > 0 ) { + for ( Uint32 i = Index - 1; i >= 0; i-- ) { + if ( !mItems[i]->IsType( UI_TYPE_SEPARATOR ) ) { + SetItemSelected( mItems[i] ); + return; + } + } + } + + SetItemSelected( mItems[ mItems.size() ] ); + } else { + for ( Uint32 i = Index + 1; i < mItems.size(); i++ ) { + if ( !mItems[i]->IsType( UI_TYPE_SEPARATOR ) ) { + SetItemSelected( mItems[i] ); + return; + } + } + + SetItemSelected( mItems[0] ); + } + } + } + } +} + +void cUIMenu::NextSel() { + if ( mItems.size() ) { + if ( mItemSelectedIndex != 0xFFFFFFFF ) { + if ( mItemSelectedIndex + 1 < mItems.size() ) { + TrySelect( mItems[ mItemSelectedIndex + 1 ], false ); + } else { + TrySelect( mItems[0], false ); + } + } else { + TrySelect( mItems[0], false ); + } + } +} + +void cUIMenu::PrevSel() { + if ( mItems.size() ) { + if ( mItemSelectedIndex != 0xFFFFFFFF ) { + if ( mItemSelectedIndex >= 1 ) { + TrySelect( mItems[ mItemSelectedIndex - 1 ], true ); + } else { + TrySelect( mItems[ mItems.size() - 1 ], true ); + } + } else { + TrySelect( mItems[0], true ); + } + } +} + +Uint32 cUIMenu::OnKeyDown( const cUIEventKey& Event ) { + if ( eeGetTicks() - mLastTickMove > 50 ) { + switch ( Event.KeyCode() ) { + case KEY_DOWN: + mLastTickMove = eeGetTicks(); + NextSel(); + + break; + case KEY_UP: + mLastTickMove = eeGetTicks(); + PrevSel(); + + break; + case KEY_RIGHT: + if ( NULL != mItemSelected && mItemSelected->IsType( UI_TYPE_MENUSUBMENU ) ) { + cUIMenuSubMenu * tMenu = reinterpret_cast ( mItemSelected ); + + tMenu->ShowSubMenu(); + } + + break; + case KEY_LEFT: + Hide(); + + break; + case KEY_ESCAPE: + Hide(); + + break; + case KEY_RETURN: + if ( NULL != mItemSelected ) { + mItemSelected->SendMouseEvent(cUIEvent::EventMouseClick, cUIManager::instance()->GetMousePos(), 0xFFFFFFFF ); + + cUIMessage Msg( mItemSelected, cUIMessage::MsgClick, 0xFFFFFFFF ); + mItemSelected->MessagePost( &Msg ); + } + + break; + } + } + + return 1; } }} diff --git a/src/ui/cuimenu.hpp b/src/ui/cuimenu.hpp index 30936c083..f289d34b8 100644 --- a/src/ui/cuimenu.hpp +++ b/src/ui/cuimenu.hpp @@ -20,6 +20,7 @@ class EE_API cUIMenu : public cUIControlAnim { Font( NULL ), FontColor( 0, 0, 0, 255 ), FontOverColor( 0, 0, 0, 255 ), + FontSelectedColor( 0, 0, 0, 255 ), MinWidth( 0 ), MinSpaceForIcons( 0 ) { @@ -31,9 +32,10 @@ class EE_API cUIMenu : public cUIControlAnim { if ( NULL == Font ) Font = cUIThemeManager::instance()->DefaultFont(); - FontColor = Theme->FontColor(); - FontShadowColor = Theme->FontShadowColor(); - FontOverColor = Theme->FontOverColor(); + FontColor = Theme->FontColor(); + FontShadowColor = Theme->FontShadowColor(); + FontOverColor = Theme->FontOverColor(); + FontSelectedColor = Theme->FontSelectedColor(); } } @@ -45,6 +47,7 @@ class EE_API cUIMenu : public cUIControlAnim { eeColorA FontColor; eeColorA FontShadowColor; eeColorA FontOverColor; + eeColorA FontSelectedColor; Uint32 MinWidth; Uint32 MinSpaceForIcons; @@ -68,6 +71,8 @@ class EE_API cUIMenu : public cUIControlAnim { cUIControl * GetItem( const std::wstring& Text ); + Uint32 GetItemIndex( cUIControl * Item ); + Uint32 Count() const; void Remove( const Uint32& Index ); @@ -96,14 +101,17 @@ class EE_API cUIMenu : public cUIControlAnim { eeColorA mFontColor; eeColorA mFontShadowColor; eeColorA mFontOverColor; + eeColorA mFontSelectedColor; Uint32 mMinWidth; Uint32 mMinSpaceForIcons; Uint32 mMaxWidth; Uint32 mRowHeight; Uint32 mNextPosY; Uint32 mBiggestIcon; - cUIMenuItem * mItemSelected; + cUIControl * mItemSelected; + Uint32 mItemSelectedIndex; bool mClickHide; + Uint32 mLastTickMove; virtual void OnSizeChange(); @@ -131,7 +139,15 @@ class EE_API cUIMenu : public cUIControlAnim { bool IsSubMenu( cUIControl * Ctrl ); - void SetItemSelected( cUIMenuItem * Item ); + void SetItemSelected( cUIControl * Item ); + + virtual Uint32 OnKeyDown( const cUIEventKey& Event ); + + void PrevSel(); + + void NextSel(); + + void TrySelect( cUIControl * Ctrl, bool Up ); }; }} diff --git a/src/ui/cuimenuitem.cpp b/src/ui/cuimenuitem.cpp index 8179ab569..3bfbacc51 100644 --- a/src/ui/cuimenuitem.cpp +++ b/src/ui/cuimenuitem.cpp @@ -27,4 +27,16 @@ Uint32 cUIMenuItem::OnMouseEnter( const eeVector2i &Pos, Uint32 Flags ) { return 1; } +void cUIMenuItem::OnStateChange() { + cUIMenu * tMenu = reinterpret_cast ( Parent() ); + + if ( mSkinState->GetState() == cUISkinState::StateSelected ) { + mTextBox->Color( tMenu->mFontSelectedColor ); + } else if ( mSkinState->GetState() == cUISkinState::StateMouseEnter ) { + mTextBox->Color( tMenu->mFontOverColor ); + } else { + mTextBox->Color( tMenu->mFontColor ); + } +} + }} diff --git a/src/ui/cuimenuitem.hpp b/src/ui/cuimenuitem.hpp index e33aa92ae..ff894c007 100644 --- a/src/ui/cuimenuitem.hpp +++ b/src/ui/cuimenuitem.hpp @@ -7,13 +7,15 @@ namespace EE { namespace UI { class EE_API cUIMenuItem : public cUIPushButton { public: - cUIMenuItem( cUIPushButton::CreateParams& Params ); + cUIMenuItem( cUIMenuItem::CreateParams& Params ); ~cUIMenuItem(); virtual void SetTheme( cUITheme * Theme ); protected: virtual Uint32 OnMouseEnter( const eeVector2i &Pos, Uint32 Flags ); + + virtual void OnStateChange(); }; }} diff --git a/src/ui/cuimenusubmenu.cpp b/src/ui/cuimenusubmenu.cpp index 9d3876659..b9df0de4a 100644 --- a/src/ui/cuimenusubmenu.cpp +++ b/src/ui/cuimenusubmenu.cpp @@ -124,7 +124,7 @@ void cUIMenuSubMenu::OnSubMenuFocusLoss( const cUIEvent * Event ) { cUIControl * FocusCtrl = cUIManager::instance()->FocusControl(); if ( Parent() != FocusCtrl && !Parent()->IsParentOf( FocusCtrl ) ) { - cUIManager::instance()->FocusControl( Parent() ); + Parent()->SetFocus(); } if ( mSubMenu->mClickHide ) { diff --git a/src/ui/cuimenusubmenu.hpp b/src/ui/cuimenusubmenu.hpp index 8d28c6b3c..87b5783a7 100644 --- a/src/ui/cuimenusubmenu.hpp +++ b/src/ui/cuimenusubmenu.hpp @@ -35,6 +35,8 @@ class cUIMenuSubMenu : public cUIMenuItem { cUIMenu * SubMenu() const; cUIGfx * Arrow() const; + + void ShowSubMenu(); protected: cUIMenu * mSubMenu; cUISkin * mSkinArrow; @@ -55,8 +57,6 @@ class cUIMenuSubMenu : public cUIMenuItem { void OnSubMenuFocusLoss( const cUIEvent * Event ); void OnHideByClick( const cUIEvent * Event ); - - void ShowSubMenu(); }; }} diff --git a/src/ui/cuipopupmenu.cpp b/src/ui/cuipopupmenu.cpp index c6546e2b0..de463514c 100644 --- a/src/ui/cuipopupmenu.cpp +++ b/src/ui/cuipopupmenu.cpp @@ -27,7 +27,7 @@ bool cUIPopUpMenu::Show() { else CreateFadeIn( cUIThemeManager::instance()->ControlsFadeInTime() ); - cUIManager::instance()->FocusControl( this ); + SetFocus(); return true; } @@ -44,6 +44,12 @@ bool cUIPopUpMenu::Hide() { Visible( false ); } + if ( NULL != mItemSelected ) + mItemSelected->SetSkinState( cUISkinState::StateNormal ); + + mItemSelected = NULL; + mItemSelectedIndex = 0xFFFFFFFF; + return true; } diff --git a/src/ui/cuislider.cpp b/src/ui/cuislider.cpp index 6ca9848df..74d584ab8 100644 --- a/src/ui/cuislider.cpp +++ b/src/ui/cuislider.cpp @@ -257,33 +257,30 @@ void cUISlider::Update() { if ( IsMouseOver() || mBackSlider->IsMouseOver() || mSlider->IsMouseOver() ) { ManageClick( cUIManager::instance()->GetInput()->ClickTrigger() ); } - - if ( mSlider->HasFocus() ) - ManageKeyboard(); } -void cUISlider::ManageKeyboard() { +Uint32 cUISlider::OnKeyDown( const cUIEventKey &Event ) { if ( eeGetTicks() - mLastTickMove > 100 ) { - cInput * KM = cUIManager::instance()->GetInput(); - - if ( KM->IsKeyDown( KEY_DOWN ) ) { + if ( Event.KeyCode() == KEY_DOWN ) { mLastTickMove = eeGetTicks(); Value( mValue + mClickStep ); - } else if ( KM->IsKeyDown( KEY_UP ) ) { + } else if ( Event.KeyCode() == KEY_UP ) { mLastTickMove = eeGetTicks(); Value( mValue - mClickStep ); - } else if ( KM->IsKeyDown( KEY_PAGEUP ) ) { + } else if ( Event.KeyCode() == KEY_PAGEUP ) { mLastTickMove = eeGetTicks(); Value( mMinValue ); - } else if ( KM->IsKeyDown( KEY_PAGEDOWN ) ) { + } else if ( Event.KeyCode() == KEY_PAGEDOWN ) { mLastTickMove = eeGetTicks(); Value( mMaxValue ); } } + + return 1; } void cUISlider::ManageClick( const Uint32& Flags ) { diff --git a/src/ui/cuislider.hpp b/src/ui/cuislider.hpp index 6b1b17212..80ceba82c 100644 --- a/src/ui/cuislider.hpp +++ b/src/ui/cuislider.hpp @@ -82,7 +82,7 @@ class EE_API cUISlider : public cUIControlAnim { void ManageClick( const Uint32& Flags ); - void ManageKeyboard(); + virtual Uint32 OnKeyDown( const cUIEventKey &Event ); virtual void OnAlphaChange(); };