Esempio n. 1
0
float EmberEntity::getHeight(const WFMath::Point<2>& localPosition) const
{

	if (mHeightProvider) {
		float height = 0;
		if (mHeightProvider->getHeight(WFMath::Point<2>(localPosition.x(), localPosition.y()), height)) {
			return height;
		}
	}

	//A normal EmberEntity shouldn't know anything about the terrain, so we can't handle the area here.
	//Instead we just pass it on to the parent until we get to someone who knows how to handle this (preferably the terrain).
	if (getEmberLocation()) {

		WFMath::Point<2> adjustedLocalPosition(getPredictedPos().x(), getPredictedPos().y());

		WFMath::Vector<3> xVec = WFMath::Vector<3>(1.0, 0.0, 0.0).rotate(getOrientation());
		double theta = atan2(xVec.y(), xVec.x()); // rotation about Z
		WFMath::RotMatrix<2> rm;
		WFMath::Vector<2> adjustment(localPosition.x(), localPosition.y());
		adjustment.rotate(rm.rotation(theta));
		adjustedLocalPosition += adjustment;

		return getEmberLocation()->getHeight(adjustedLocalPosition) - getPredictedPos().z();
	}

	WFMath::Point<3> predictedPos = getPredictedPos();
	if (predictedPos.isValid()) {
		return predictedPos.z();
	} else {
		return 0.0f;
	}
}
Esempio n. 2
0
void RegionChooser::show_region_properties()
{
    if (!region) return;
    Gtk::Dialog dialog(_("Region Properties"), true /*modal*/);
    // add "Keygroup" checkbox
    Gtk::CheckButton checkBoxKeygroup(_("Member of a Keygroup (Exclusive Group)"));
    checkBoxKeygroup.set_active(region->KeyGroup);
    dialog.get_vbox()->pack_start(checkBoxKeygroup);
    checkBoxKeygroup.show();
    // add "Keygroup" spinbox
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
    Gtk::Adjustment adjustment(1, 1, 999);
    Gtk::SpinButton spinBox(adjustment);
#else
    Gtk::SpinButton spinBox(Gtk::Adjustment::create(1, 1, 999));
#endif
    if (region->KeyGroup) spinBox.set_value(region->KeyGroup);
    dialog.get_vbox()->pack_start(spinBox);
    spinBox.show();
    // add OK and CANCEL buttons to the dialog
    dialog.add_button(_("_OK"), 0);
    dialog.add_button(_("_Cancel"), 1);
    dialog.show_all_children();
    if (!dialog.run()) { // OK selected ...
        region->KeyGroup =
            (checkBoxKeygroup.get_active()) ? spinBox.get_value_as_int() : 0;
    }
}
Esempio n. 3
0
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 )
		) );
	}
}
Esempio n. 4
0
int soso()
{
   static int	 separate_static_item = 0xa5a5a5a5;
   static long long clearly_so;

   int		 x = startfromhere++;

   x *= factor;
   x += adjustment(cu);
   x -= yasimi;
   return x;
}
Esempio n. 5
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;
		}
	}
}
Esempio n. 6
0
const sf::FloatRect Scrollbar::GetSliderRect() const {
	float mimimum_slider_length( Context::Get().GetEngine().GetProperty<float>( "SliderMinimumLength", shared_from_this() ) );

	Adjustment::Ptr adjustment( GetAdjustment() );

	auto current_value = adjustment->GetValue();
	auto value_range = std::max( adjustment->GetUpper() - adjustment->GetLower() - adjustment->GetPageSize(), .0f );
	auto pages = value_range / adjustment->GetPageSize() + 1.f;

	if( GetOrientation() == Orientation::HORIZONTAL ) {
		auto stepper_length = GetAllocation().height;
		auto trough_length = GetAllocation().width - 2.f * stepper_length;
		auto slider_length = std::max( mimimum_slider_length, trough_length / pages );
		if( adjustment->GetPageSize() == .0f ) {
			slider_length = mimimum_slider_length;
		}

		auto slider_x = stepper_length + ( trough_length - slider_length ) * ( current_value - adjustment->GetLower() ) / value_range;
		auto slider_y = 0.f;

		if( value_range == .0f ) {
			slider_x = stepper_length;
		}

		return sf::FloatRect( slider_x, slider_y, slider_length, GetAllocation().height );
	}

	auto stepper_length = GetAllocation().width;
	auto trough_length = GetAllocation().height - 2.f * stepper_length;
	auto slider_length = std::max( mimimum_slider_length, trough_length / pages );
	if( adjustment->GetPageSize() == .0f ) {
		slider_length = mimimum_slider_length;
	}

	auto slider_x = 0.f;
	auto slider_y = stepper_length + ( trough_length - slider_length ) * ( current_value - adjustment->GetLower() ) / value_range;

	if( value_range == .0f ) {
		slider_y = stepper_length;
	}

	return sf::FloatRect( slider_x, slider_y, GetAllocation().width, slider_length );
}
Esempio n. 7
0
void RegionChooser::show_region_properties()
{
    if (!region) return;
    Gtk::Dialog dialog(_("Region Properties"), true /*modal*/);
    // add "Keygroup" checkbox
    Gtk::CheckButton checkBoxKeygroup(_("Member of a Keygroup (Exclusive Group)"));
    checkBoxKeygroup.set_active(region->KeyGroup);
    dialog.get_vbox()->pack_start(checkBoxKeygroup);
    checkBoxKeygroup.show();
    // add "Keygroup" spinbox
    Gtk::Adjustment adjustment(1, 1, pow(2,32));
    Gtk::SpinButton spinBox(adjustment);
    if (region->KeyGroup) spinBox.set_value(region->KeyGroup);
    dialog.get_vbox()->pack_start(spinBox);
    spinBox.show();
    // add OK and CANCEL buttons to the dialog
    dialog.add_button(Gtk::Stock::OK, 0);
    dialog.add_button(Gtk::Stock::CANCEL, 1);
    dialog.show_all_children();
    if (!dialog.run()) { // OK selected ...
        region->KeyGroup =
            (checkBoxKeygroup.get_active()) ? spinBox.get_value_as_int() : 0;
    }
}
Esempio n. 8
0
    //____________________________________________________
    SliderDemoWidget::SliderDemoWidget( void )
    {

        // main widget
        GtkWidget* mainWidget( gtk_hbox_new( false, 0 ) );
        gtk_box_set_spacing( GTK_BOX( mainWidget ), 5 );
        setWidget( mainWidget );

        // setup
        setName( "Sliders" );
        setComments( "Shows the appearance of sliders, progress bars and scrollbars" );
        setIconName( "measure" );
        realize();

        // horizontal sliders
        {

            // frame
            GtkWidget* frame( gtk_frame_new( "Horizontal" ) );
            gtk_box_pack_start( GTK_BOX( mainWidget ), frame, true, true, 0 );
            gtk_widget_show( frame );

            // container
            GtkWidget* box( gtk_vbox_new( false, 0 ) );
            gtk_container_set_border_width( GTK_CONTAINER( box ), 5 );
            gtk_box_set_spacing( GTK_BOX( box ), 2 );
            gtk_widget_show( box );
            gtk_container_add( GTK_CONTAINER( frame ), box );

            // scale
            _horizontalSliders._scale = gtk_hscale_new_with_range( 0, 100, 1 );
            gtk_scale_set_draw_value( GTK_SCALE( _horizontalSliders._scale ), false );
            gtk_box_pack_start( GTK_BOX( box ), _horizontalSliders._scale, false, true, 0 );
            gtk_widget_show( _horizontalSliders._scale );


            // progress entry
            _horizontalSliders._progressEntry = gtk_entry_new();
            gtk_entry_set_text( GTK_ENTRY( _horizontalSliders._progressEntry ), "Progress Bar Entry" );
            gtk_entry_set_progress_fraction( GTK_ENTRY( _horizontalSliders._progressEntry ), 0.25 );
            gtk_box_pack_start( GTK_BOX( box ), _horizontalSliders._progressEntry, false, true, 0 );
            gtk_widget_show( _horizontalSliders._progressEntry );

            // progress bar
            _horizontalSliders._progressBar = gtk_progress_bar_new();
            #if GTK_CHECK_VERSION(3, 0, 0)
            gtk_orientable_set_orientation( GTK_ORIENTABLE( _horizontalSliders._progressBar ), GTK_ORIENTATION_HORIZONTAL );
            #else
            gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR( _horizontalSliders._progressBar ), GTK_PROGRESS_LEFT_TO_RIGHT );
            #endif

            gtk_progress_set_show_text( GTK_PROGRESS( _horizontalSliders._progressBar ), true );
            gtk_box_pack_start( GTK_BOX( box ), _horizontalSliders._progressBar, false, true, 0 );
            gtk_widget_show( _horizontalSliders._progressBar );

            // pulse progressBar
            _pulseProgressBar = gtk_progress_bar_new();
            #if GTK_CHECK_VERSION(3, 0, 0)
            gtk_orientable_set_orientation( GTK_ORIENTABLE( _pulseProgressBar ), GTK_ORIENTATION_HORIZONTAL );
            #else
            gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR( _pulseProgressBar ), GTK_PROGRESS_LEFT_TO_RIGHT );
            #endif

            gtk_progress_bar_set_pulse_step( GTK_PROGRESS_BAR( _pulseProgressBar ), 0.01 );
            gtk_box_pack_start( GTK_BOX( box ), _pulseProgressBar, false, true, 0 );
            gtk_widget_show( _pulseProgressBar );

            // scrollbar
            GtkAdjustment* adjustment( GTK_ADJUSTMENT( gtk_adjustment_new( 25, 0, 110, 1, 1, 10 ) ) );
            _horizontalSliders._scrollBar = gtk_hscrollbar_new( adjustment );
            gtk_box_pack_start( GTK_BOX( box ), _horizontalSliders._scrollBar, false, true, 0 );
            gtk_widget_show( _horizontalSliders._scrollBar );

        }

        // vertical sliders
        {

            // frame
            GtkWidget* frame( gtk_frame_new( "Vertical" ) );
            gtk_box_pack_start( GTK_BOX( mainWidget ), frame, false, true, 0 );
            gtk_widget_show( frame );

            // container
            GtkWidget* box( gtk_hbox_new( false, 0 ) );
            gtk_container_set_border_width( GTK_CONTAINER( box ), 5 );
            gtk_box_set_spacing( GTK_BOX( box ), 5 );
            gtk_widget_show( box );
            gtk_container_add( GTK_CONTAINER( frame ), box );

            // scale
            _verticalSliders._scale = gtk_vscale_new_with_range( 0, 100, 1 );
            gtk_scale_set_draw_value( GTK_SCALE( _verticalSliders._scale ), false );
            gtk_box_pack_start( GTK_BOX( box ), _verticalSliders._scale, false, true, 0 );
            gtk_widget_show( _verticalSliders._scale );

            // progress bar
            _verticalSliders._progressBar = gtk_progress_bar_new();
            #if GTK_CHECK_VERSION(3, 0, 0)
            gtk_orientable_set_orientation( GTK_ORIENTABLE( _verticalSliders._progressBar ), GTK_ORIENTATION_VERTICAL );
            #else
            gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR( _verticalSliders._progressBar ), GTK_PROGRESS_BOTTOM_TO_TOP );
            #endif

            gtk_progress_set_show_text( GTK_PROGRESS( _verticalSliders._progressBar ), true );
            gtk_box_pack_start( GTK_BOX( box ), _verticalSliders._progressBar, false, true, 0 );
            gtk_widget_show( _verticalSliders._progressBar );

            // scrollbar
            GtkAdjustment* adjustment( GTK_ADJUSTMENT( gtk_adjustment_new( 25, 0, 110, 1, 1, 10 ) ) );
            _verticalSliders._scrollBar = gtk_vscrollbar_new( adjustment );
            gtk_box_pack_start( GTK_BOX( box ), _verticalSliders._scrollBar, false, true, 0 );
            gtk_widget_show( _verticalSliders._scrollBar );

        }

        // connections
        connect( G_OBJECT( _horizontalSliders._scale ), "value-changed", GCallback( valueChanged ), this );
        connect( G_OBJECT( _horizontalSliders._scrollBar ), "value-changed", GCallback( valueChanged ), this );

        connect( G_OBJECT( _verticalSliders._scale ), "value-changed", GCallback( valueChanged ), this );
        connect( G_OBJECT( _verticalSliders._scrollBar ), "value-changed", GCallback( valueChanged ), this );

        // Initialize all
        gtk_range_set_value( GTK_RANGE( _verticalSliders._scale ), 25 );
    }
void
sstSequence::ClampBeats()
{
	float margin = 100.f;

	vsScreen *screen = vsSystem::GetScreen();

	float fov = screen->GetScene(0)->GetFOV();
	float screenHeight = fov;
	float screenWidth = screenHeight * screen->GetAspectRatio();

	float topEdge = (screenHeight * -.5f) + 100.0f + margin;
	float botEdge = 0.f;	// never go below the halfway point, because that's just not nice.  :)
	float leftEdge = (screenWidth * -0.5f) + margin;
	float rightEdge = (screenWidth * 0.5f) - margin;
//	bool clampedSuccessfully = false;

	// if we're supposed to be on the right, clamp us onto the right side.

	if ( m_onRight )
		leftEdge = 0.f;
	else
		rightEdge = 0.f;

	vsVector2D worldBeatPos[MAX_BEATS];
	vsVector2D topLeft(10000.0f,10000.0f);		// arbitrary large values
	vsVector2D botRight(-1000.0f,-10000.0f);	// arbitrary small values

	for ( int i = 0; i < m_beatCount; i++ )
	{
		vsTransform2D t = GetTransformAtTime( m_segment[i].m_time );
		worldBeatPos[i] = t.ApplyTo( m_segment[i].m_position );

		if ( worldBeatPos[i].x < topLeft.x )
			topLeft.x = worldBeatPos[i].x;
		if ( worldBeatPos[i].x > botRight.x )
			botRight.x = worldBeatPos[i].x;
		if ( worldBeatPos[i].y < topLeft.y )
			topLeft.y = worldBeatPos[i].y;
		if ( worldBeatPos[i].y > botRight.y )
			botRight.y = worldBeatPos[i].y;
	}

	float width = botRight.x - topLeft.x;
	float height = botRight.y - topLeft.y;

	float usableScreenWidth = rightEdge - leftEdge;
	float usableScreenHeight = botEdge - topEdge;

	if ( width > usableScreenWidth || height > usableScreenHeight )
	{
		// we're never going to make this fit;  make our translation smaller!
		//printf("Too big!  Try again!\n");
		return DoneAddingBeats();
	}

//	float widthRange = usableScreenWidth - width;
//	float heightRange = usableScreenHeight - height;

	vsVector2D minAdjustment = vsVector2D::Zero;
	vsVector2D maxAdjustment = vsVector2D::Zero;
	if ( topLeft.x < leftEdge )
	{
		minAdjustment.x = leftEdge - topLeft.x;
		maxAdjustment.x = rightEdge - botRight.x;
	}
	else if ( botRight.x > rightEdge )
	{
		minAdjustment.x = rightEdge - botRight.x;
		maxAdjustment.x = leftEdge - topLeft.x;
	}

	if ( topLeft.y < topEdge )
	{
		minAdjustment.y = topEdge - topLeft.y;
		maxAdjustment.y = botEdge - botRight.y;
	}
	else if ( botRight.y > botEdge )
	{
		minAdjustment.y = botEdge - botRight.y;
		maxAdjustment.y = topEdge - topLeft.y;
	}

	vsVector2D adjustment( vsRandom::GetFloat(minAdjustment.x, maxAdjustment.x),
						  vsRandom::GetFloat(minAdjustment.y, maxAdjustment.y) );

	m_transformA.SetTranslation( m_transformA.GetTranslation() + adjustment );
	m_transformB.SetTranslation( m_transformB.GetTranslation() + adjustment );
}