示例#1
0
void Container::HandleEvent( const sf::Event& event ) {
	// Ignore event when widget is not visible.
	if( !IsGloballyVisible() ) {
		return;
	}

	// Create a copy of the event and transform mouse coordinates to local
	// coordinates if event is a mouse event.
	sf::Event local_event( event );

	if( local_event.type == sf::Event::MouseMoved ) {
		local_event.mouseMove.x -= static_cast<int>( GetAllocation().left );
		local_event.mouseMove.y -= static_cast<int>( GetAllocation().top );
	}

	if(
		local_event.type == sf::Event::MouseButtonPressed ||
		local_event.type == sf::Event::MouseButtonReleased
	) {
		local_event.mouseButton.x -= static_cast<int>( GetAllocation().left );
		local_event.mouseButton.y -= static_cast<int>( GetAllocation().top );
	}

	std::size_t children_size = m_children.size();

	// Pass event to children.
	for( std::size_t index = 0; index < children_size; ++index ) {
		m_children[index]->HandleEvent( local_event );
	}

	// Process event for own widget.
	Widget::HandleEvent( event );
}
示例#2
0
文件: Widget.cpp 项目: Cruel/SFGUI
void Widget::RequestResize() {
	m_requisition = CalculateRequisition();

	if( m_custom_requisition ) {
		if( m_custom_requisition->x > 0.f ) {
			m_requisition.x = std::max( m_custom_requisition->x, m_requisition.x );
		}

		if( m_custom_requisition->y > 0.f ) {
			m_requisition.y = std::max( m_custom_requisition->y, m_requisition.y );
		}
	}

	HandleRequisitionChange();

	auto parent = m_parent.lock();

	// Notify observers.
	GetSignals().Emit( OnSizeRequest );

	if( parent ) {
		parent->RequestResize();
	}
	else {
		sf::FloatRect allocation(
			GetAllocation().left,
			GetAllocation().top,
			std::max( GetAllocation().width, m_requisition.x ),
			std::max( GetAllocation().height, m_requisition.y )
		);

		SetAllocation( allocation );
	}
}
示例#3
0
void ComboBox::HandleMouseMoveEvent( int x, int y ) {
	if( m_active ) {
		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().GetLineHeight( font, font_size ) + 2 * padding );

			if( line_y < GetItemCount() ) {
				if( line_y != m_highlighted_item ) {
					Invalidate();
					m_highlighted_item = line_y;
				}
			}
			else {
				if( m_highlighted_item != NONE ) {
					m_highlighted_item = NONE;
					Invalidate();
				}
			}
		}
		else {
			if( m_highlighted_item != NONE ) {
				m_highlighted_item = NONE;
				Invalidate();
			}
		}
	}
}
示例#4
0
void Box::AllocateChildren() const {
    ChildrenCont::const_iterator iter( m_children.begin() );
    ChildrenCont::const_iterator iterend( m_children.end() );
    unsigned int num_expand( 0 );
    unsigned int num_visible( 0 );

    // Count number of visible and expanded children.
    for( ; iter != iterend; ++iter ) {
        if( !IsChildInteresting( iter->widget ) ) {
            continue;
        }

        ++num_visible;

        if( iter->expand ) {
            ++num_expand;
        }
    }

    // Calculate extra width pre expanded widget.
    float extra( 0.f );

    if( num_expand > 0 ) {
        if( m_orientation == HORIZONTAL ) {
            extra = std::max( 0.f, GetAllocation().width - GetRequisition().x ) / static_cast<float>( num_expand );
        }
        else {
            extra = std::max( 0.f, GetAllocation().height - GetRequisition().y ) / static_cast<float>( num_expand );
        }
    }

    // Allocate children.
    float gap( Context::Get().GetEngine().GetProperty<float>( "Gap", shared_from_this() ) );
    sf::Vector2f allocation( 0.f, 0.f );
    sf::Vector2f position( gap, gap );

    for( iter = m_children.begin(); iter != iterend; ++iter ) {
        if( !IsChildInteresting( iter->widget ) ) {
            continue;
        }

        if( m_orientation == HORIZONTAL ) {
            allocation.x = iter->widget->GetRequisition().x + (iter->expand ? extra : 0.f);
            allocation.y = GetAllocation().height - 2 * gap;

            iter->widget->SetAllocation( sf::FloatRect( position.x, position.y, allocation.x - (iter->expand && !iter->fill ? extra : 0.f), allocation.y ) );
            position.x += allocation.x + GetSpacing();
        }
        else {
            allocation.x = GetAllocation().width - 2 * gap;
            allocation.y = iter->widget->GetRequisition().y + (iter->expand ? extra : 0.f);

            iter->widget->SetAllocation( sf::FloatRect( position.x, position.y, allocation.x, allocation.y - (iter->expand && !iter->fill ? extra : 0.f) ) );
            position.y += allocation.y + GetSpacing();
        }

        --num_visible;
    }
}
示例#5
0
void Window::HandleAdd( Widget::Ptr child ) {
	Bin::HandleAdd( child );

	if( GetChild() ) {
		// Reset allocation so the window will be as large as required.
		SetAllocation( sf::FloatRect( GetAllocation().left, GetAllocation().top, 1.f, 1.f ) );
		RequestResize();
	}
}
示例#6
0
void ComboBox::HandleStateChange( State old_state ) {
	Bin::HandleStateChange( old_state );

	if( GetState() == ACTIVE ) {
		SetZOrder( 1 );

		GrabModal();

		m_start_entry = 0;

		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 ) );
		const float line_height( Context::Get().GetEngine().GetFontLineHeight( font, font_size ) );

		if( ( GetDisplayedItems() > 2 ) && ( GetDisplayedItems() < GetItemCount() ) ) {
			float border_width( Context::Get().GetEngine().GetProperty<float>( "BorderWidth", shared_from_this() ) );


			const sf::Vector2f item_size(
				GetAllocation().width - 2 * border_width,
				line_height + 2 * padding
			);

			m_scrollbar = Scrollbar::Create( Scrollbar::VERTICAL );

			float offset = ( GetState() == ACTIVE ? border_width : 0.f ) + GetAllocation().width - padding - line_height;

			m_scrollbar->SetPosition( sf::Vector2f( offset, GetAllocation().height + border_width ) );
			m_scrollbar->SetRequisition( sf::Vector2f( GetAllocation().width - offset, static_cast<float>( GetDisplayedItems() ) * item_size.y - 2.f * border_width ) );

			m_scrollbar->GetAdjustment()->SetPageSize( static_cast<float>( GetDisplayedItems() ) );
			m_scrollbar->GetAdjustment()->SetLower( 0.f );
			m_scrollbar->GetAdjustment()->SetUpper( static_cast<float>( GetItemCount() ) );
			m_scrollbar->GetAdjustment()->SetMinorStep( 1.f );
			m_scrollbar->GetAdjustment()->SetMajorStep( 1.f );

			m_scrollbar->GetAdjustment()->GetSignal( Adjustment::OnChange ).Connect( &ComboBox::ChangeStartEntry, this );

			m_scrollbar->SetZOrder( 2 );

			Add( m_scrollbar );
		}
	}
	else {
		SetZOrder( 0 );

		if( m_scrollbar ) {
			Remove( m_scrollbar );

			m_scrollbar.reset();
		}
	}
}
示例#7
0
文件: Window.cpp 项目: soarqin/SFGUI
bool Window::HandleAdd( Widget::Ptr child ) {
	if( !Bin::HandleAdd( child ) ) {
		return false;
	}

	// Reset allocation so the window will be as large as required.
	SetAllocation( sf::FloatRect( GetAllocation().left, GetAllocation().top, 1.f, 1.f ) );
	RequestResize();

	return true;
}
示例#8
0
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();
			}
		}
	}
}
示例#9
0
文件: Window.cpp 项目: Zykr/SFGUI
sf::FloatRect Window::GetClientRect() const {
	sf::FloatRect  clientrect( 0, 0, GetAllocation().Width, GetAllocation().Height );
	float  title_height( HasStyle( Titlebar ) ? Context::Get().GetEngine().GetProperty<float>( "TitleHeight", shared_from_this() ) : 0.f );
	float  border_width( Context::Get().GetEngine().GetProperty<float>( "BorderWidth", shared_from_this() ) );

	clientrect.Left += border_width + GetBorderWidth();
	clientrect.Top += title_height + border_width + GetBorderWidth();
	clientrect.Width -= 2 * border_width + 2 * GetBorderWidth();
	clientrect.Height -= title_height + 2 * border_width + 2 * GetBorderWidth();

	return clientrect;
}
示例#10
0
void Scrollbar::HandleMouseMoveEvent( int x, int y ) {
	if( !m_dragging || ( x == std::numeric_limits<int>::min() ) || ( y == std::numeric_limits<int>::min() ) ) {
		return;
	}

	Adjustment::Ptr adjustment( GetAdjustment() );
	auto slider_rect = GetSliderRect();

	auto value_range = std::max( adjustment->GetUpper() - adjustment->GetLower() - adjustment->GetPageSize(), adjustment->GetMinorStep() / 2.f );
	auto steps = value_range / adjustment->GetMinorStep();

	if( GetOrientation() == Orientation::HORIZONTAL ) {
		auto stepper_length = GetAllocation().height;

		auto slider_center_x = slider_rect.left + slider_rect.width / 2.0f;
		auto step_distance = ( GetAllocation().width - 2.f * stepper_length ) / steps;

		auto delta = (
			static_cast<float>( x ) - (slider_center_x + m_slider_click_offset)
		);

		while( delta < (-step_distance / 2) ) {
			adjustment->Decrement();
			delta += step_distance;
		}

		while( delta > (step_distance / 2) ) {
			adjustment->Increment();
			delta -= step_distance;
		}
	}
	else {
		auto stepper_length = GetAllocation().width;

		auto slider_center_y = slider_rect.top + slider_rect.height / 2.0f;
		auto step_distance = (GetAllocation().height - 2.f * stepper_length) / steps;

		auto delta = static_cast<float>( y ) - (slider_center_y + m_slider_click_offset);

		while( delta < (-step_distance / 2) ) {
			adjustment->Decrement();
			delta += step_distance;
		}

		while( delta > (step_distance / 2) ) {
			adjustment->Increment();
			delta -= step_distance;
		}
	}
}
示例#11
0
文件: Viewport.cpp 项目: Zykr/SFGUI
void Viewport::Expose( CullingTarget& target ) const {
	if( IsVisible() ) {
		if( GetChild() ) {
			unsigned int target_width = target.GetWidth();
			unsigned int target_height = target.GetHeight();

			sf::View view(
				sf::FloatRect(
					std::floor( m_horizontal_adjustment->GetValue() + .5f ),
					std::floor( m_vertical_adjustment->GetValue() + .5f ),
					GetAllocation().Width,
					GetAllocation().Height
				)
			);

			float viewport_left = std::floor( Widget::GetAbsolutePosition().x + .5f ) / static_cast<float>( target_width );
			float viewport_top = std::floor( Widget::GetAbsolutePosition().y + .5f ) / static_cast<float>( target_height );
			float viewport_width = GetAllocation().Width / static_cast<float>( target_width );
			float viewport_height = GetAllocation().Height / static_cast<float>( target_height );

			// Make sure float to int rounding errors can't lead to streching effects.
			if( static_cast<int>( viewport_width * static_cast<float>( target_width ) ) < static_cast<int>( GetAllocation().Width ) ) {
				viewport_width += 1.f / static_cast<float>( target_width );
			}

			if( static_cast<int>( viewport_height * static_cast<float>( target_height ) ) < static_cast<int>( GetAllocation().Height ) ) {
				viewport_height += 1.f / static_cast<float>( target_height );
			}

			view.SetViewport(
				sf::FloatRect(
					viewport_left,
					viewport_top,
					viewport_width,
					viewport_height
				)
			);

			sf::View original_view = target.GetView();

			target.SetView( view );

			GetChild()->Expose( target );

			target.SetView( original_view );
		}

		OnExpose();
	}
}
示例#12
0
文件: Scale.cpp 项目: soarqin/SFGUI
void Scale::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) {
	if( button != sf::Mouse::Left ) {
		return;
	}

	if( m_drag_offset ) {
		m_drag_offset.reset();
		m_dragging = false;
	}

	if( !GetAllocation().contains( static_cast<float>( x ), static_cast<float>( y ) ) ) {
		return;
	}

	if( press ) {
		if( !GetSliderRect().contains( static_cast<float>( x ) - GetAllocation().left, static_cast<float>( y ) - GetAllocation().top ) ) {
			Adjustment::Ptr adjustment( GetAdjustment() );

			auto minor_step = adjustment->GetMinorStep();
			auto range = adjustment->GetUpper() - adjustment->GetLower();
			auto steps = range / minor_step;
			auto needed_steps = 0.f;

			auto trough_position = 0.f;
			auto trough_length = 0.f;

			if( GetOrientation() == Orientation::HORIZONTAL ) {
				trough_position = static_cast<float>( x ) - ( GetAllocation().left + GetSliderRect().width / 2.f );
				trough_length = GetAllocation().width - GetSliderRect().width;
			}

			if( GetOrientation() == Orientation::VERTICAL ) {
				trough_position = static_cast<float>( y ) - ( GetAllocation().top + GetSliderRect().height / 2.f );
				trough_length = GetAllocation().height - GetSliderRect().height;
			}

			trough_position = std::min( trough_position, trough_length );

			auto trough_ratio = trough_position / trough_length;

			for( ; needed_steps < steps; needed_steps += 1.f ) {
				if( ( 1.f / steps ) * needed_steps > trough_ratio ) {
					break;
				}
			}

			needed_steps = std::max( needed_steps - 1.f, 0.f );

			adjustment->SetValue( needed_steps * minor_step );
		}

		m_dragging = true;
		m_drag_offset.reset( new sf::Vector2f(
				static_cast<float>( x ) - ( GetAllocation().left + GetSliderRect().left + GetSliderRect().width / 2.f ),
				static_cast<float>( y ) - ( GetAllocation().top + GetSliderRect().top + GetSliderRect().height / 2.f )
		) );
	}
}
示例#13
0
void Alignment::UpdateChild() {
	Widget::Ptr child = GetChild();

	if( !child ) {
		return;
	}

	sf::FloatRect allocation( GetAllocation() );

	sf::Vector2f spare_space( allocation.width, allocation.height );
	spare_space -= child->GetRequisition();
	spare_space.x *= 1.f - GetScale().x;
	spare_space.y *= 1.f - GetScale().y;

	if( ( spare_space.x < 0 ) || ( spare_space.y < 0 ) ) {
#ifdef SFGUI_DEBUG
		std::cerr << "SFGUI warning: Alignment got a smaller allocation than it requested." << std::endl;
		return;
#endif
	}

	allocation.left = spare_space.x * GetAlignment().x;
	allocation.top = spare_space.y * GetAlignment().y;
	allocation.width -= spare_space.x;
	allocation.height -= spare_space.y;

	child->SetAllocation( allocation );
}
示例#14
0
文件: Widget.cpp 项目: Zykr/SFGUI
sf::Vector2f Widget::GetAbsolutePosition() const {
	// If no parent, allocation's position is absolute position.
	PtrConst parent( m_parent.lock() );

	if( !parent ) {
		return sf::Vector2f( GetAllocation().Left, GetAllocation().Top );
	}

	// Get parent's absolute position and add own rel. position to it.
	sf::Vector2f parent_position( parent->GetAbsolutePosition() );

	return sf::Vector2f(
		parent_position.x + GetAllocation().Left,
		parent_position.y + GetAllocation().Top
	);
}
示例#15
0
文件: Widget.cpp 项目: Zykr/SFGUI
void Widget::Refresh() const {
	sf::FloatRect old_allocation( GetAllocation() );

	RequestSize();

	if(
		old_allocation.Left == GetAllocation().Left &&
		old_allocation.Top == GetAllocation().Top &&
		old_allocation.Width == GetAllocation().Width &&
		old_allocation.Height == GetAllocation().Height
	) {
		HandleAbsolutePositionChange();
		HandleSizeAllocate( old_allocation );
	}

	Invalidate();
}
示例#16
0
文件: Scale.cpp 项目: soarqin/SFGUI
const sf::FloatRect Scale::GetSliderRect() const {
	auto slider_length = Context::Get().GetEngine().GetProperty<float>( "SliderLength", shared_from_this() );
	auto slider_width = (GetOrientation() == Orientation::HORIZONTAL) ? GetAllocation().height : GetAllocation().width;
	auto adjustment = GetAdjustment();
	auto current_value = adjustment->GetValue();
	auto value_range = adjustment->GetUpper() - adjustment->GetLower() - adjustment->GetPageSize();

	if( GetOrientation() == Orientation::HORIZONTAL ) {
		auto slider_x = (GetAllocation().width - slider_length) * (current_value - adjustment->GetLower()) / value_range;
		auto slider_y = (GetAllocation().height - slider_width) / 2.f;

		return sf::FloatRect( slider_x, slider_y, slider_length, slider_width );
	}

	auto slider_x = (GetAllocation().width - slider_width) / 2.f;
	auto slider_y = (GetAllocation().height - slider_length) * (1 - ((current_value - adjustment->GetLower()) / value_range));

	return sf::FloatRect( slider_x, slider_y, slider_width, slider_length );
}
示例#17
0
文件: Canvas.cpp 项目: Cruel/SFGUI
void Canvas::HandleAbsolutePositionChange() {
	auto position = Widget::GetAbsolutePosition();

	auto parent = GetParent();

	sf::Vector2f parent_position( 0.f, 0.f );

	while( parent ) {
		if( parent->GetName() == "Viewport" ) {
			// Try to get the first ancestor of the viewport that is not a viewport itself.
			// Add up all allocations while searching.
			Container::PtrConst viewport_parent = parent->GetParent();

			while( viewport_parent && viewport_parent->GetName() == "Viewport" ) {
				parent_position += sf::Vector2f( viewport_parent->GetAllocation().left, viewport_parent->GetAllocation().top );

				viewport_parent = viewport_parent->GetParent();
			}

			if( !viewport_parent || ( viewport_parent->GetName() == "Viewport" ) ) {
				parent_position = sf::Vector2f( 0.f, 0.f );
				break;
			}

			parent_position += viewport_parent->GetAbsolutePosition();
			parent_position += sf::Vector2f( parent->GetAllocation().left, parent->GetAllocation().top );

			break;
		}

		parent = parent->GetParent();
	}

	m_custom_viewport->SetDestinationOrigin(
		sf::Vector2f(
			std::floor( parent_position.x + position.x + .5f ),
			std::floor( parent_position.y + position.y + .5f )
		)
	);

	Invalidate();
}
示例#18
0
文件: Window.cpp 项目: Zykr/SFGUI
void Window::HandleMouseMoveEvent( int x, int y ) {
	if( m_dragging ) {
		SetPosition(
			sf::Vector2f(
				static_cast<float>( x ) - m_drag_offset.x,
				static_cast<float>( y ) - m_drag_offset.y
			)
		);
	}
	else if( m_resizing ) {
		AllocateSize(
			sf::FloatRect(
				GetAllocation().Left,
				GetAllocation().Top,
				std::max( GetRequisition().x, static_cast<float>( x ) + m_drag_offset.x - GetAllocation().Left ),
				std::max( GetRequisition().y, static_cast<float>( y ) + m_drag_offset.y - GetAllocation().Top )
			)
		);
	}
}
示例#19
0
文件: Widget.cpp 项目: Cruel/SFGUI
void Widget::SetPosition( const sf::Vector2f& position ) {
	sf::FloatRect allocation( GetAllocation() );

	// Make sure allocation is pixel-aligned.
	m_allocation.left = std::floor( position.x + .5f );
	m_allocation.top = std::floor( position.y + .5f );

	if( ( allocation.top != m_allocation.top ) || ( allocation.left != m_allocation.left ) ) {
	  HandlePositionChange();
	  HandleAbsolutePositionChange();
	}
}
示例#20
0
void GLCanvas::HandleSizeChange() {
	sf::FloatRect allocation = GetAllocation();

	m_custom_viewport->SetSize(
		sf::Vector2f(
			std::floor( allocation.width + .5f ),
			std::floor( allocation.height + .5f )
		)
	);

	Invalidate();
}
示例#21
0
文件: Widget.cpp 项目: Zykr/SFGUI
void Widget::RequestSize() const {
	m_recalc_requisition = true;
	Container::Ptr parent = m_parent.lock();

	// Notify observers.
	OnSizeRequest();

	if( parent ) {
		parent->RequestSize();
	}
	else {
		sf::Vector2f  requisition( GetRequisition() );

		sf::FloatRect  allocation(
			GetAllocation().Left,
			GetAllocation().Top,
			std::max( GetAllocation().Width, requisition.x ),
			std::max( GetAllocation().Height, requisition.y )
		);

		AllocateSize( allocation );
	}
}
示例#22
0
sf::FloatRect Window::GetClientRect() const {
	sf::FloatRect clientrect( 0, 0, GetAllocation().width, GetAllocation().height );
	float border_width( Context::Get().GetEngine().GetProperty<float>( "BorderWidth", shared_from_this() ) );
	float gap( Context::Get().GetEngine().GetProperty<float>( "Gap", shared_from_this() ) );

	clientrect.left += border_width + gap;
	clientrect.top += border_width + gap;
	clientrect.width -= 2 * border_width + 2 * gap;
	clientrect.height -= 2 * border_width + 2 * gap;

	if( HasStyle( TITLEBAR ) ) {
		unsigned int title_font_size( Context::Get().GetEngine().GetProperty<unsigned int>( "FontSize", shared_from_this() ) );
		const sf::Font& title_font( *Context::Get().GetEngine().GetResourceManager().GetFont( Context::Get().GetEngine().GetProperty<std::string>( "FontName", shared_from_this() ) ) );
		float title_height(
			Context::Get().GetEngine().GetFontLineHeight( title_font, title_font_size ) +
			2 * Context::Get().GetEngine().GetProperty<float>( "TitlePadding", shared_from_this() )
		);

		clientrect.top += title_height;
		clientrect.height -= title_height;
	}

	return clientrect;
}
示例#23
0
void Window::HandleMouseMoveEvent( int x, int y ) {
	if( ( x == std::numeric_limits<int>::min() ) || ( y == std::numeric_limits<int>::min() ) ) {
		return;
	}

	if( m_dragging ) {
		SetPosition(
			sf::Vector2f(
				static_cast<float>( x ) - m_drag_offset.x,
				static_cast<float>( y ) - m_drag_offset.y
			)
		);
	}
	else if( m_resizing && (GetStyle() & RESIZE) == RESIZE ) {
		SetAllocation(
			sf::FloatRect(
				GetAllocation().left,
				GetAllocation().top,
				std::max( GetRequisition().x, static_cast<float>( x ) + m_drag_offset.x - GetAllocation().left ),
				std::max( GetRequisition().y, static_cast<float>( y ) + m_drag_offset.y - GetAllocation().top )
			)
		);
	}
}
示例#24
0
文件: Canvas.cpp 项目: Cruel/SFGUI
void Canvas::HandleSizeChange() {
	auto allocation = GetAllocation();

	m_custom_viewport->SetSize(
		sf::Vector2f(
			std::floor( allocation.width + .5f ),
			std::floor( allocation.height + .5f )
		)
	);

	if( m_render_texture ) {
		m_resize = true;
	}

	Invalidate();
}
示例#25
0
void Label::HandleSizeChange() {
	if( !m_wrap || ( GetAllocation().width <= 0 ) ) {
		return;
	}

	WrapText();

	static auto calculate_y_requisition = false;

	if( !calculate_y_requisition ) {
		calculate_y_requisition = true;
		RequestResize();
	}
	else {
		calculate_y_requisition = false;
	}
}
示例#26
0
void
JITOutput::FinalizeNativeCode()
{
    CustomHeap::Allocation * allocation = GetAllocation();
#if ENABLE_OOP_NATIVE_CODEGEN
    if (JITManager::GetJITManager()->IsJITServer())
    {
        m_func->GetOOPCodeGenAllocators()->emitBufferManager.CompletePreviousAllocation(m_oopAlloc);

#if defined(_CONTROL_FLOW_GUARD) && !defined(_M_ARM)
        if (!m_func->IsLoopBody() && CONFIG_FLAG(UseJITTrampoline))
        {
            allocation->thunkAddress = m_func->GetOOPThreadContext()->GetJITThunkEmitter()->CreateThunk(m_outputData->codeAddress);
        }
#endif
    }
    else
#endif
    {
        m_func->GetInProcCodeGenAllocators()->emitBufferManager.CompletePreviousAllocation(m_inProcAlloc);
        m_func->GetInProcJITEntryPointInfo()->SetInProcJITNativeCodeData(m_func->GetNativeCodeDataAllocator()->Finalize());
        m_func->GetInProcJITEntryPointInfo()->GetJitTransferData()->SetRawData(m_func->GetTransferDataAllocator()->Finalize());
#if !FLOATVAR
        CodeGenNumberChunk * numberChunks = m_func->GetNumberAllocator()->Finalize();
        m_func->GetInProcJITEntryPointInfo()->SetNumberChunks(numberChunks);
#endif

#if defined(_CONTROL_FLOW_GUARD) && !defined(_M_ARM)
        if (!m_func->IsLoopBody() && CONFIG_FLAG(UseJITTrampoline))
        {
            allocation->thunkAddress = m_func->GetInProcThreadContext()->GetJITThunkEmitter()->CreateThunk(m_outputData->codeAddress);
        }
#endif
    }
    m_outputData->thunkAddress = allocation->thunkAddress;
    if (!allocation->thunkAddress && CONFIG_FLAG(OOPCFGRegistration))
    {
        PVOID callTarget = (PVOID)m_outputData->codeAddress;
#ifdef _M_ARM
        callTarget = (PVOID)((uintptr_t)callTarget | 0x1);
#endif
        m_func->GetThreadContextInfo()->SetValidCallTargetForCFG(callTarget);
    }
}
示例#27
0
文件: Canvas.cpp 项目: Cruel/SFGUI
void Canvas::Clear( const sf::Color& color, bool depth ) {
	auto allocation = GetAllocation();

	if( !m_render_texture ) {
		// Make sure there is a non-internal/shared context active.
		// After 8 hours of debugging, I found out that if you deactivate the
		// currently active context and construct a sf::RenderTexture, it leads
		// to the sf::RenderTexture's internal OpenGL texture being created
		// in a "corrupted" context leading to OpenGL possibly generating the
		// same texture IDs that it already previously generated and are still in
		// use. Since 2 textures share the same ID, when you draw to the
		// sf::RenderTexture it actually overwrites whatever was in the other
		// normally created texture. This leads to very exotic looking sf::Sprites,
		// not for the end-user. SFML context management strikes again.
		sf::Context context;

		m_render_texture = std::make_shared<sf::RenderTexture>();

		if( !m_render_texture->create( static_cast<unsigned int>( std::floor( allocation.width + .5f ) ), static_cast<unsigned int>( std::floor( allocation.height + .5f ) ), m_depth ) ) {
#if defined( SFGUI_DEBUG )
			std::cerr << "SFGUI warning: Canvas failed to create internal SFML RenderTexture.\n";
#endif
		}
	}
	else if( m_resize ) {
		if( !m_render_texture->create( static_cast<unsigned int>( std::floor( allocation.width + .5f ) ), static_cast<unsigned int>( std::floor( allocation.height + .5f ) ), m_depth ) ) {
#if defined( SFGUI_DEBUG )
			std::cerr << "SFGUI warning: Canvas failed to create internal SFML RenderTexture.\n";
#endif
		}
	}

	m_resize = false;

	m_render_texture->setActive( true );

	WipeStateCache( *m_render_texture );

	CheckGLError( glClearColor( color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f ) );
	CheckGLError( glClear( GL_COLOR_BUFFER_BIT | ( depth ? GL_DEPTH_BUFFER_BIT : 0 ) ) );
}
示例#28
0
文件: ComboBox.cpp 项目: Cruel/SFGUI
ComboBox::IndexType ComboBox::GetDisplayedItemCount() const {
	float border_width( Context::Get().GetEngine().GetProperty<float>( "BorderWidth", shared_from_this() ) );
	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 ) );
	const float line_height( Context::Get().GetEngine().GetFontLineHeight( font, font_size ) );

	const sf::Vector2f item_size(
		GetAllocation().width - 2 * border_width,
		line_height + 2 * padding
	);

	auto available_space = static_cast<float>( Renderer::Get().GetWindowSize().y ) - ( GetAbsolutePosition().y + item_size.y );

	auto num_displayed_entries = static_cast<IndexType>( available_space / item_size.y );

	num_displayed_entries = ( GetItemCount() < num_displayed_entries ? GetItemCount() : num_displayed_entries );

	return num_displayed_entries;
}
示例#29
0
文件: Widget.cpp 项目: Zykr/SFGUI
void Widget::SetPosition( const sf::Vector2f& position ) const {
	sf::FloatRect  oldallocation( GetAllocation() );

	// Make sure allocation is pixel-aligned.
	m_allocation.Left = std::floor( position.x + .5f );
	m_allocation.Top = std::floor( position.y + .5f );

	if( oldallocation.Top == m_allocation.Top &&
	    oldallocation.Left == m_allocation.Left ) {
		// Nothing even changed. Save the hierarchy the trouble.
		return;
	}

	HandleAbsolutePositionChange();
	HandleSizeAllocate( oldallocation );

	if( m_drawable ) {
		m_drawable->SetPosition( GetAbsolutePosition() );
	}

	OnSizeAllocate();
}
示例#30
0
void Button::AllocateChild() {
	auto child = GetChild();

	if( !child ) {
		return;
	}

	float padding( Context::Get().GetEngine().GetProperty<float>( "Padding", shared_from_this() ) );
	float border_width( Context::Get().GetEngine().GetProperty<float>( "BorderWidth", shared_from_this() ) );

	sf::FloatRect allocation( GetAllocation() );

	allocation.left = padding + border_width;
	allocation.top = padding + border_width;
	allocation.width = child->GetRequisition().x;
	allocation.height -= border_width * 2.f + padding * 2.f;

	if( GetState() == State::ACTIVE ) {
		allocation.left += border_width;
		allocation.top += border_width;
	}

	child->SetAllocation( allocation );
}