Exemplo n.º 1
0
nuiSize nuiPopupMenu::AdjustRectsPos(nuiSize& rX, nuiSize& rY, uint depth, nuiRect CurRect)
{
  nuiTopLevel* pRoot = GetTopLevel();
  NGL_ASSERT(pRoot);
  NGL_ASSERT(depth+1 < mRects.size());
  nuiRect MainRect = pRoot->GetRect();
  nuiRect& prevRect(mRects[depth]->mRect); // prevRect is the previous rect in the hierarchy (NOT the previous rect of this sub menu)
  depth++;

  nuiMenuRect* pMenuRect = mRects[depth];
  nuiRect& rRect(pMenuRect->mRect);

  nuiSize x, y;
  x = rX + (mXdir * rRect.GetWidth()) - (mXdir < 0 ? prevRect.GetWidth() : 0); // Compute X so that the rect doesn't get out of the main container
  y = rY + (mYdir * rRect.GetHeight()) + (mYdir < 0 ? CurRect.GetHeight() : 0); // Compute Y so that the rect doesn't get out of the main container
  if (x > MainRect.GetWidth() || x < 0) // Should we change the current x direction?
    mXdir *= -1;
  if (y > MainRect.GetHeight() || y < 0)  // Should we change the current y direction?
    mYdir *= -1;

  rX = rX - ((mXdir < 0) ? rRect.GetWidth()  + prevRect.GetWidth() : 0);
  rY = rY - ((mYdir < 0) ? rRect.GetHeight() - CurRect.GetHeight() : 0);

  if (rY < 0)
    rY = 0;
  if ( 
    ( (mYdir > 0) && (MainRect.GetHeight() < (rY + rRect.GetHeight()) ) ) ||
    ( (mYdir < 0) && (0 > (rY - rRect.GetHeight()) ) )
    )
  {
    nuiSize heightDiff = MainRect.GetHeight() - rRect.GetHeight();
    if (heightDiff > 0)
    {
      rY = heightDiff;
    }
    else
    {
      nuiRect r( ToNearest(rX + rRect.GetWidth() - SB_WIDTH), 0, ToNearest(SB_WIDTH), ToNearest(MainRect.GetHeight()));
      pMenuRect->mpSBar->GetRange().SetRange(0.f, rRect.GetHeight());
      pMenuRect->mpSBar->GetRange().SetPageSize(MainRect.GetHeight());
      pMenuRect->mpSBar->GetRange().SetIncrement(10.f);

      pMenuRect->mpSBar->SetLayout(r);
      pMenuRect->mpSBar->SetVisible(true);
      pMenuRect->mpSBar->SetSelected(false);
      pMenuRect->mpSBar->SetEnabled(true);
      rY = -pMenuRect->mpSBar->GetRange().GetValue();
      return (SB_WIDTH);
    }
  }
  if (pMenuRect->mpSBar)
  {
    pMenuRect->mpSBar->SetVisible(false);
    pMenuRect->mpSBar->SetEnabled(false);
  }
  return (0.f);
}
void QSpreadsheetHeaderView::drawPrevButton(QPainter *painter, int logicalIndex) const
{
    QRect rect = prevRect(logicalIndex);

    painter->setPen(QColor(71,71,71));
    painter->drawLine(rect.left()+1, rect.center().y() - 3, rect.left()+1, rect.center().y() + 3);
    painter->drawLine(rect.left()+2, rect.center().y() - 2, rect.left()+2, rect.center().y() + 2);
    painter->drawLine(rect.left()+3, rect.center().y() - 1, rect.left()+3, rect.center().y() + 1);
    painter->drawPoint(rect.left()+4, rect.center().y());
}
void QSpreadsheetHeaderView::mousePressEvent ( QMouseEvent * event )
{
    QHeaderView::mousePressEvent(event);

    int logicalIndex = logicalIndexAt(event->pos());

    if (buttonMenuRect(logicalIndex).contains(event->pos())) {
        QMenu menu(this);
        QAction *hideCol = menu.addAction("Hide column");
        QAction *sortAZ = menu.addAction("Sort sheet A->Z");
        QAction *sortZA = menu.addAction("Sort sheet Z->A");

        // Disable hide column if only one column remains. Otherwise
        // the gui is no more available to show them back.
        hideCol->setEnabled(hiddenSectionCount() < count() - 1);

        QAction *res = menu.exec(mapToGlobal(event->pos()));

        if (res == hideCol) {
            hideSection(logicalIndex);
            updateSection(logicalIndex-1);
        }
        if (res == sortAZ)
            model()->sort(logicalIndex, Qt::AscendingOrder);
        if (res == sortZA)
            model()->sort(logicalIndex, Qt::DescendingOrder);
    }

    // Catch previous arrow mouse click.
    if (prevRect(logicalIndex).contains(event->pos())) {
        showSection(logicalIndex - 1);
        updateSection(logicalIndex - 2);
    }

    // Catch next arrow mouse click.
    if (nextRect(logicalIndex).contains(event->pos())) {
        showSection(logicalIndex + 1);
        updateSection(logicalIndex + 2);
    }
}
Exemplo n.º 4
0
void Tile::Update(ALLEGRO_EVENT ev, Entity &e)
{
	if(motion == Motion::HORIZONTAL)
	{
		velocity[0] += moveSpeed * direction;
		velocity[1] = 0;
	}
	else if(motion == Motion::VERTICAL)
	{
		velocity[0] = 0;
		velocity[1] = moveSpeed * direction;
	}

	rangeCounter += velocity[0] + velocity[1];

	if(labs(rangeCounter) >= range)
	{
		rangeCounter = 0;
		direction *= -1;
	}

	position[0] += velocity[0];
	position[1] += velocity[1];

	tileAnimation.Position(position[0], position[1]);

	//타일에 collision박스를 씌워 준다
	FloatRect tileRect(position[0], position[1], 32, 32);
	FloatRect prevRect(e.prevPosition[0], e.prevPosition[1], 32, 32);

	//충돌 시험
	if(e.rect->IsIntersect(tileRect) && state == State::SOLID)
	{
		if(e.rect->Bottom >= tileRect.Top && prevRect.Bottom <= tileRect.Top)
		{
			/*타일 위에 있을때는 containsEntity를 키고 그래비티는 끄면서 점프를 할수 있게 해준다*/
			e.position[1] = tileRect.Top - 32;
			e.activateGravity = false;
			e.isJumping = false;
			containsEntity = true;
			e.tileID = id;
		}
		else if(e.rect->Top <= tileRect.Bottom && prevRect.Top >= tileRect.Bottom)
		{
			e.position[1] = tileRect.Bottom;
		}
		else if(e.rect->Right >= tileRect.Left && prevRect.Right <= tileRect.Left)
		{
			e.position[0] = tileRect.Left - 32;
		}
		else if(e.rect->Left <= tileRect.Right && prevRect.Left >= tileRect.Right)
		{
			e.position[0] = tileRect.Right;
		}
		/*2015.04.13 이 줄을 추가 함으로써 바로바로 에니메이션에 포지션 주는걸 막는다
		따라서 타일 안으로 안들어감*/
		//e.animation.Position(e.position[0], e.position[1]);
	}

	if(containsEntity && e.tileID == id)
	{
		/*containsEntity가 트루인데 entity가 벗어나면 다시 그래비티 활성화 containsEntity 는 false*/
		if(e.position[0] + 32 < tileRect.Left || e.position[0] > tileRect.Right)
		{
			containsEntity = false;
			e.activateGravity = true;
		}
		else if(!e.animation.IsActive())
		{
			e.position[0] += velocity[0];
			e.position[1] += velocity[1];

			e.animation.Position(e.position[0], e.position[1]);
		}
		if(e.isJumping == false)
		{
			e.position[1] = position[1] - 32;
		}
	}
	/*else
	{
		if(motion == Motion::HORIZONTAL)
		{
			velocity[0] += moveSpeed * direction;
			velocity[1] = 0;
		}
		else if(motion == Motion::VERTICAL)
		{
			velocity[0] = 0;
			velocity[1] = moveSpeed * direction;
		}

		rangeCounter += velocity[0] + velocity[1];

		if(labs(rangeCounter) >= range)
		{
			range = 0;
			direction *= -1;
		}

		position[0] += velocity[0];
		position[1] += velocity[1];

		tileAnimation.Position(position[0], position[1]);

		//타일에 collision박스를 씌워 준다
		rect = new FloatRect(position[0], position[1], 32, 32);
		prevRect = new FloatRect(prevPosition[0], prevPosition[1], 32, 32);

		//충돌 시험
		if(e.rect->IsIntersect(*rect) && state == State::SOLID)
		{
			if(e.rect->Bottom >= rect->Top && e.prevRect->Bottom <= rect->Top)
			{
				/*타일 위에 있을때는 containsEntity를 키고 그래비티는 끄면서 점프를 할수 있게 해준다
				e.position[1] = rect->Top - 32;
				e.activateGravity = false;
				containsEntity = true;
				e.tileID = id;
			}
			else if(e.rect->Top <= rect->Bottom && e.prevRect->Top >= rect->Bottom)
			{
				e.position[1] = rect->Bottom;
			}
			else if(e.rect->Right >= rect->Left && e.prevRect->Right <= rect->Left)
			{
				e.position[0] = rect->Left - 32;
			}
			else if(e.rect->Left <= rect->Right && e.prevRect->Left >= rect->Right)
			{
				e.position[0] = rect->Right;
			}
			/*2015.04.13 이 줄을 추가 함으로써 바로바로 에니메이션에 포지션 주는걸 막는다
			따라서 타일 안으로 안들어감
			e.animation.Position(e.position[0], e.position[1]);
		}

		if(containsEntity && e.tileID == id)
		{
			/*containsEntity가 트루인데 entity가 벗어나면 다시 그래비티 활성화 containsEntity 는 false
			if(e.position[0] + 32 < rect->Left || e.position[0] > rect->Right)
			{
				containsEntity = false;
				e.activateGravity = true;
			}
		}
	}*/
}