// Sets the height of the steps based on mouse positions.
// If the mouse skipped over some steps between last mouseDrag event, we'll interpolate
// and set all the steps inbetween to appropriate values.
void GraphicalStepSequencer::changeStep(const MouseEvent& e) {
  Point<int> mouse_position = e.getPosition();
  int from_step = getHoveredStep(last_edit_position_);
  int selected_step = getHoveredStep(mouse_position);

  float x = mouse_position.x;
  float y = mouse_position.y;
  float x_delta = last_edit_position_.x - x;
  float y_delta = last_edit_position_.y - y;
  float slope = y_delta == 0 ? 0 : y_delta / x_delta;
  float next_x = getWidth() * (1.0f * selected_step) / num_steps_;
  int direction = -1;

  if (selected_step < from_step) {
    direction = 1;
    next_x += getWidth() * 1.0f / num_steps_;
  }
  float inc_x = next_x - x;

  for (int step = selected_step; step != from_step + direction; step += direction) {
    if (step >= 0 && step < num_steps_) {
      float new_value = -2.0f * y / getHeight() + 1.0f;
      sequence_[step]->setValue(std::max(std::min(new_value, 1.0f), -1.0f));
    }
    y += inc_x * slope;
    inc_x = direction * getWidth() * 1.0f / num_steps_;
  }
  resetBackground();
}
void CSharedPainterScene::mouseReleaseEvent( QGraphicsSceneMouseEvent *evt )
{
	if( !freePenMode_)
	{
		doLowQualityMoveItems();

		QGraphicsScene::mouseReleaseEvent( evt );
		return;
	}

	if( drawFlag_ )
	{
		drawFlag_ = false;

		fireEvent_DrawItem( currLineItem_ );

		currLineItem_ = boost::shared_ptr<CLineItem>();

		for( size_t i = 0; i < tempLineItemList_.size(); i++ )
		{
			QGraphicsScene::removeItem( tempLineItemList_[i] );
		}
		tempLineItemList_.clear();

		resetBackground( sceneRect () );
	}
}
void CSharedPainterScene::drawBackgroundImage( boost::shared_ptr<CBackgroundImageItem> image )
{
	backgroundImageItem_ = image;

	if( image )
	{
		backgroundPixmap_ = image->createPixmap();

		int newSceneW = sceneRect().width();
		int newSceneH = sceneRect().height();

		QSize size = backgroundPixmap_.size();
		if( newSceneW < size.width() )
			newSceneW = size.width();
		if( newSceneH < size.height() )
			newSceneH = size.height();
		setSceneRect( 0, 0, newSceneW, newSceneH );
	}
	else
	{
		clearBackgroundImage();
		return;
	}

	resetBackground( sceneRect () );
}
void GraphicalStepSequencer::resized() {
  ensureMinSize();

  const Desktop::Displays::Display& display = Desktop::getInstance().getDisplays().getMainDisplay();
  float scale = display.scale;
  background_ = Image(Image::ARGB, scale * getWidth(), scale * getHeight(), true);
  resetBackground();
}
void CSharedPainterScene::clearBackgroundImage( void )
{
	backgroundImageItem_ = boost::shared_ptr<CBackgroundImageItem>();

	backgroundPixmap_ = QPixmap();

	resetBackground( sceneRect() );
}
void GraphicalStepSequencer::setNumStepsSlider(Slider* num_steps_slider) {
  if (num_steps_slider_)
    num_steps_slider_->removeListener(this);
  num_steps_slider_ = num_steps_slider;
  num_steps_slider_->addListener(this);

  ensureMinSize();
  resetBackground();
}
Пример #7
0
NodeItem::NodeItem(QGraphicsItem* parent /* = nullptr */)
    : QGraphicsObject(parent)
    , m_emphasised(false)
{
    resetBackground();
    resetEmphasisBrush();
    resetBorderPen();
    resetSelectionPen();
    resetTextPen();
    resetFont();

    setFlag(QGraphicsItem::ItemIsMovable);
    setFlag(QGraphicsItem::ItemSendsScenePositionChanges);
    setFlag(QGraphicsItem::ItemIsSelectable);
    setPos(0, 0);
    setZValue(200.0f);
}
Пример #8
0
void
moveSprites(SDL_Surface** screen, struct sprite** letters, int letterSpeed)
{
    struct sprite* current;

	current= *letters;
	while(current!=NULL){
		moveSprite(&(*screen), &current, letterSpeed);
		current = current->next;
	}
	current = *letters;
	while(current!=NULL){
		showSprite(&(*screen), &current);
		current=current->next;
	}
	SDL_Flip(*screen);
	current = *letters;
	while(current!=NULL){
		resetBackground(&(*screen), &current);
		current= current->next;
	}
}
void GraphicalStepSequencer::sliderValueChanged(Slider* moved_slider) {
  ensureMinSize();
  resetBackground();
}
void GraphicalStepSequencer::setStepSliders(std::vector<Slider*> sliders) {
  sequence_ = sliders;
  for (int i = 0; i < sliders.size(); ++i)
    sequence_[i]->addListener(this);
  resetBackground();
}
void CSharedPainterScene::setBackgroundColor( int r, int g, int b, int a )
{
	backgroundColor_ = QColor(r, g, b, a);
	resetBackground( sceneRect () );	
}
void CSharedPainterScene::drawBackgroundGridLine( int size )
{
	gridLineSize_ = size;

	resetBackground( sceneRect() );
}
void CSharedPainterScene::sceneRectChanged(const QRectF &rect)
{
	//qDebug() << "sceneRectChanged" << rect;
	resetBackground( rect );
}