void ComboBox::HandleMouseMoveEvent( int x, int y ) { if( m_active ) { if( m_scrollbar ) { sf::Event event; event.type = sf::Event::MouseMoved; event.mouseMove.x = x - static_cast<int>( GetAllocation().left ); event.mouseMove.y = y - static_cast<int>( GetAllocation().top ); ReleaseModal(); m_scrollbar->SetActiveWidget(); m_scrollbar->HandleEvent( event ); SetActiveWidget(); GrabModal(); sf::FloatRect scrollbar_allocation = m_scrollbar->GetAllocation(); scrollbar_allocation.left += GetAllocation().left; scrollbar_allocation.top += GetAllocation().top; if( scrollbar_allocation.contains( static_cast<float>( x ), static_cast<float>( y ) ) ) { m_highlighted_item = NONE; Invalidate(); return; } } if( ( x > GetAllocation().left ) && ( x < GetAllocation().left + GetAllocation().width ) ) { float padding( Context::Get().GetEngine().GetProperty<float>( "ItemPadding", shared_from_this() ) ); const std::string& font_name( Context::Get().GetEngine().GetProperty<std::string>( "FontName", shared_from_this() ) ); unsigned int font_size( Context::Get().GetEngine().GetProperty<unsigned int>( "FontSize", shared_from_this() ) ); const sf::Font& font( *Context::Get().GetEngine().GetResourceManager().GetFont( font_name ) ); IndexType line_y = y; line_y -= static_cast<int>( GetAllocation().top + GetAllocation().height + padding ); line_y /= static_cast<int>( Context::Get().GetEngine().GetFontLineHeight( font, font_size ) + 2 * padding ); if( line_y < GetItemCount() ) { if( line_y != m_highlighted_item ) { Invalidate(); m_highlighted_item = line_y + GetStartItemIndex(); } } else { if( m_highlighted_item != NONE ) { m_highlighted_item = NONE; Invalidate(); } } } else { if( m_highlighted_item != NONE ) { m_highlighted_item = NONE; Invalidate(); } } } }
void ComboBox::HandleUpdate( float seconds ) { Bin::HandleUpdate( seconds ); if( GetState() != State::ACTIVE ) { if( IsModal() ) { ReleaseModal(); } } }
void ComboBox::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) { if( ( x == std::numeric_limits<int>::min() ) || ( y == std::numeric_limits<int>::min() ) ) { return; } if( GetState() == State::ACTIVE ) { if( m_scrollbar ) { sf::Event event; event.type = press ? sf::Event::MouseButtonPressed : sf::Event::MouseButtonReleased; event.mouseButton.button = button; event.mouseButton.x = x - static_cast<int>( GetAllocation().left ); event.mouseButton.y = y - static_cast<int>( GetAllocation().top ); ReleaseModal(); m_scrollbar->SetActiveWidget(); m_scrollbar->HandleEvent( event ); SetActiveWidget(); GrabModal(); auto scrollbar_allocation = m_scrollbar->GetAllocation(); scrollbar_allocation.left += GetAllocation().left; scrollbar_allocation.top += GetAllocation().top; if( scrollbar_allocation.contains( static_cast<float>( x ), static_cast<float>( y ) ) ) { return; } } if( !press || ( button != sf::Mouse::Left ) ) { return; } auto emit_select = false; if( m_highlighted_item != NONE ) { m_active_item = m_highlighted_item; emit_select = true; } m_highlighted_item = NONE; if( IsMouseInWidget() ) { SetState( State::PRELIGHT ); } else { SetState( State::NORMAL ); } Invalidate(); if( emit_select ) { GetSignals().Emit( OnSelect ); } return; } if( press && ( button == sf::Mouse::Left ) && IsMouseInWidget() ) { m_highlighted_item = NONE; SetState( State::ACTIVE ); Invalidate(); GetSignals().Emit( OnOpen ); } }