コード例 #1
0
ファイル: Widget.cpp プロジェクト: Cruel/SFGUI
void Widget::SetState( State state ) {
	// Do nothing if state wouldn't change.
	if( GetState() == state ) {
		return;
	}

	auto old_state = GetState();

	// Store the new state.
	m_state = state;

	auto emit_state_change = false;

	// If HandleStateChange() changed the state, do not call observer, will be
	// done from there too.
	if( GetState() != old_state ) {
		HandleStateChange( static_cast<State>( old_state ) );
		emit_state_change = true;
	}

	if( state == State::ACTIVE ) {
		GrabFocus( shared_from_this() );
		SetActiveWidget( shared_from_this() );
	}
	else if( old_state == State::ACTIVE ) {
		SetActiveWidget( Ptr() );
	}

	if( emit_state_change ) {
		GetSignals().Emit( OnStateChange );
	}
}
コード例 #2
0
ファイル: Widget.cpp プロジェクト: ksandison/sfgui
void Widget::SetState( State state ) {
	// Do nothing if state wouldn't change.
	if( GetState() == state ) {
		return;
	}

	unsigned char old_state( GetState() );

	// Clear the state bits to 0s.
	m_bitfield &= static_cast<unsigned char>( 0xf1 );

	// Store the new state.
	m_bitfield |= static_cast<unsigned char>( state << 1 );

	// If HandleStateChange() changed the state, do not call observer, will be
	// done from there too.
	if( GetState() != old_state ) {
		HandleStateChange( static_cast<State>( old_state ) );
		GetSignals().Emit( OnStateChange );
	}

	if( state == ACTIVE ) {
		GrabFocus( shared_from_this() );
		SetActiveWidget( shared_from_this() );
	}
	else if( old_state == ACTIVE ) {
		SetActiveWidget( Ptr() );
	}
}
コード例 #3
0
ファイル: ComboBox.cpp プロジェクト: Soth1985/Survive
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();
			}
		}
	}
}
コード例 #4
0
ファイル: Widget.cpp プロジェクト: Cruel/SFGUI
void Widget::SetActiveWidget() {
	SetActiveWidget( shared_from_this() );
}
コード例 #5
0
ファイル: ComboBox.cpp プロジェクト: Cruel/SFGUI
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 );
	}
}