示例#1
0
void QDeclarativeGrid::doPositioning()
{
    int c=_columns,r=_rows;//Actual number of rows/columns
    int numVisible = positionedItems.count();
    if (_columns==-1 && _rows==-1){
        c = 4;
        r = (numVisible+3)/4;
    }else if (_rows==-1){
        r = (numVisible+(_columns-1))/_columns;
    }else if (_columns==-1){
        c = (numVisible+(_rows-1))/_rows;
    }

    QList<int> maxColWidth;
    QList<int> maxRowHeight;
    int childIndex =0;
    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++){
            if (j==0)
                maxRowHeight << 0;
            if (i==0)
                maxColWidth << 0;

            if (childIndex == positionedItems.count())
                continue;
            const PositionedItem &child = positionedItems.at(childIndex++);
            if (!child.item || isInvisible(child.item))
                continue;
            if (child.item->width() > maxColWidth[j])
                maxColWidth[j] = child.item->width();
            if (child.item->height() > maxRowHeight[i])
                maxRowHeight[i] = child.item->height();
        }
    }

    int xoffset=0;
    int yoffset=0;
    int curRow =0;
    int curCol =0;
    for (int i = 0; i < positionedItems.count(); ++i) {
        const PositionedItem &child = positionedItems.at(i);
        if (!child.item || isInvisible(child.item))
            continue;
        if((child.item->x()!=xoffset)||(child.item->y()!=yoffset)){
            positionX(xoffset, child);
            positionY(yoffset, child);
        }
        xoffset+=maxColWidth[curCol]+spacing();
        curCol++;
        curCol%=c;
        if (!curCol){
            yoffset+=maxRowHeight[curRow]+spacing();
            xoffset=0;
            curRow++;
            if (curRow>=r)
                break;
        }
    }
}
示例#2
0
bool QueenPiece::isMovePossible(int newCell) const
{
    const int newX = ChessPiece::positionX(newCell);
    const int newY = ChessPiece::positionY(newCell);
    const int deltaX = Utils::abs(newX - positionX());
    const int deltaY = Utils::abs(newY - positionY());

    return (deltaX == deltaY) || deltaX == 0 || deltaY == 0;
}
示例#3
0
void QDeclarativeColumn::doPositioning()
{
    int voffset = 0;

    for (int ii = 0; ii < positionedItems.count(); ++ii) {
        const PositionedItem &child = positionedItems.at(ii);
        if (!child.item || isInvisible(child.item))
            continue;

        if(child.item->y() != voffset)
            positionY(voffset, child);

        voffset += child.item->height();
        voffset += spacing();
    }
}
示例#4
0
void QDeclarativeFlow::doPositioning(QSizeF *contentSize)
{
    Q_D(QDeclarativeFlow);

    int hoffset = 0;
    int voffset = 0;
    int linemax = 0;

    for (int i = 0; i < positionedItems.count(); ++i) {
        const PositionedItem &child = positionedItems.at(i);
        if (!child.item || isInvisible(child.item))
            continue;

        if (d->flow == LeftToRight)  {
            if (hoffset && hoffset + child.item->width() > width()) {
                hoffset = 0;
                voffset += linemax + spacing();
                linemax = 0;
            }
        } else {
            if (voffset && voffset + child.item->height() > height()) {
                voffset = 0;
                hoffset += linemax + spacing();
                linemax = 0;
            }
        }

        if(child.item->x() != hoffset || child.item->y() != voffset){
            positionX(hoffset, child);
            positionY(voffset, child);
        }

        contentSize->setWidth(qMax(contentSize->width(), hoffset + child.item->width()));
        contentSize->setHeight(qMax(contentSize->height(), voffset + child.item->height()));

        if (d->flow == LeftToRight)  {
            hoffset += child.item->width();
            hoffset += spacing();
            linemax = qMax(linemax, qCeil(child.item->height()));
        } else {
            voffset += child.item->height();
            voffset += spacing();
            linemax = qMax(linemax, qCeil(child.item->width()));
        }
    }
}
示例#5
0
文件: MapDraw.cpp 项目: winder/DSAnts
// Shift the center if the player is too far to the side of the map.
void MapDraw::shiftCenter(Creature *p)
{
  float pos = positionY(p->getY());
  int DISTANCE = GRID_SIZE / 3;

  // if the ant is GRID_SIZE/3 boxes away from the center, start trying to follow it.
  if (pos < (-1* DISTANCE))
    decY();
  else if (pos > DISTANCE) 
    incY();

  pos = positionX(p->getX());
  if (pos < (-1 * DISTANCE))
    decX();
  else if (pos > DISTANCE) 
    incX();
}
示例#6
0
/**
    \fn configure
*/
bool addLogopFilter::configure( void)
{
#define PX(x) &(configuration.x)
	   diaElemFile       file(0,(char **)PX(logo),QT_TRANSLATE_NOOP("logo","_Logo (jpg file):"), NULL, QT_TRANSLATE_NOOP("logo","Select JPEG file"));
	   diaElemUInteger   positionX(PX(x),QT_TRANSLATE_NOOP("logo","_X Position:"),0,info.width);
	   diaElemUInteger   positionY(PX(y),QT_TRANSLATE_NOOP("logo","_Y Position:"),0,info.height);
	   diaElemUInteger   alpha(PX(alpha),QT_TRANSLATE_NOOP("logo","_Alpha:"),0,255);

	   diaElem *elems[4]={&file,&positionX,&positionY,&alpha};

	   if( diaFactoryRun(QT_TRANSLATE_NOOP("logo","Logo"),4,elems))
	   {
		   if(false==reloadImage())
            GUI_Error_HIG("Oops","Cannot load the logo");
		   return true;
	   }
	   return false;
}
示例#7
0
void QDeclarativeColumn::doPositioning(QSizeF *contentSize)
{
    int voffset = 0;

    for (int ii = 0; ii < positionedItems.count(); ++ii) {
        const PositionedItem &child = positionedItems.at(ii);
        if (!child.item || isInvisible(child.item))
            continue;

        if(child.item->y() != voffset)
            positionY(voffset, child);

        contentSize->setWidth(qMax(contentSize->width(), child.item->width()));

        voffset += child.item->height();
        voffset += spacing();
    }

    contentSize->setHeight(voffset - spacing());
}
示例#8
0
void QDeclarativeGrid::doPositioning(QSizeF *contentSize)
{
    int c = m_columns;
    int r = m_rows;
    int numVisible = positionedItems.count();
    if (m_columns <= 0 && m_rows <= 0){
        c = 4;
        r = (numVisible+3)/4;
    } else if (m_rows <= 0){
        r = (numVisible+(m_columns-1))/m_columns;
    } else if (m_columns <= 0){
        c = (numVisible+(m_rows-1))/m_rows;
    }

    QList<int> maxColWidth;
    QList<int> maxRowHeight;
    int childIndex =0;
    if (m_flow == LeftToRight) {
        for (int i=0; i < r; i++){
            for (int j=0; j < c; j++){
                if (j==0)
                    maxRowHeight << 0;
                if (i==0)
                    maxColWidth << 0;

                if (childIndex == positionedItems.count())
                    continue;
                const PositionedItem &child = positionedItems.at(childIndex++);
                if (!child.item || isInvisible(child.item))
                    continue;
                if (child.item->width() > maxColWidth[j])
                    maxColWidth[j] = child.item->width();
                if (child.item->height() > maxRowHeight[i])
                    maxRowHeight[i] = child.item->height();
            }
        }
    } else {
        for (int j=0; j < c; j++){
            for (int i=0; i < r; i++){
                if (j==0)
                    maxRowHeight << 0;
                if (i==0)
                    maxColWidth << 0;

                if (childIndex == positionedItems.count())
                    continue;
                const PositionedItem &child = positionedItems.at(childIndex++);
                if (!child.item || isInvisible(child.item))
                    continue;
                if (child.item->width() > maxColWidth[j])
                    maxColWidth[j] = child.item->width();
                if (child.item->height() > maxRowHeight[i])
                    maxRowHeight[i] = child.item->height();
            }
        }
    }

    int xoffset=0;
    int yoffset=0;
    int curRow =0;
    int curCol =0;
    for (int i = 0; i < positionedItems.count(); ++i) {
        const PositionedItem &child = positionedItems.at(i);
        if (!child.item || isInvisible(child.item))
            continue;
        if((child.item->x()!=xoffset)||(child.item->y()!=yoffset)){
            positionX(xoffset, child);
            positionY(yoffset, child);
        }

        if (m_flow == LeftToRight) {
            contentSize->setWidth(qMax(contentSize->width(), xoffset + child.item->width()));
            contentSize->setHeight(yoffset + maxRowHeight[curRow]);

            xoffset+=maxColWidth[curCol]+spacing();
            curCol++;
            curCol%=c;
            if (!curCol){
                yoffset+=maxRowHeight[curRow]+spacing();
                xoffset=0;
                curRow++;
                if (curRow>=r)
                    break;
            }
        } else {
            contentSize->setHeight(qMax(contentSize->height(), yoffset + child.item->height()));
            contentSize->setWidth(xoffset + maxColWidth[curCol]);

            yoffset+=maxRowHeight[curRow]+spacing();
            curRow++;
            curRow%=r;
            if (!curRow){
                xoffset+=maxColWidth[curCol]+spacing();
                yoffset=0;
                curCol++;
                if (curCol>=c)
                    break;
            }
        }
    }
}
示例#9
0
void QDeclarativeGrid::doPositioning(QSizeF *contentSize)
{
    QDeclarativeBasePositionerPrivate *d = static_cast<QDeclarativeBasePositionerPrivate*>(QDeclarativeBasePositionerPrivate::get(this));
    int c = m_columns;
    int r = m_rows;
    //Is allocating the extra QPODVector too much overhead?
    QPODVector<PositionedItem, 8> visibleItems;//we aren't concerned with invisible items
    visibleItems.reserve(positionedItems.count());
    for(int i=0; i<positionedItems.count(); i++)
        if(positionedItems[i].item && positionedItems[i].isVisible)
            visibleItems.append(positionedItems[i]);

    int numVisible = visibleItems.count();
    if (m_columns <= 0 && m_rows <= 0) {
        c = 4;
        r = (numVisible+3)/4;
    } else if (m_rows <= 0) {
        r = (numVisible+(m_columns-1))/m_columns;
    } else if (m_columns <= 0) {
        c = (numVisible+(m_rows-1))/m_rows;
    }

    if(r==0 || c==0)
        return; //Nothing to do

    QList<int> maxColWidth;
    QList<int> maxRowHeight;
    int childIndex =0;
    if (m_flow == LeftToRight) {
        for (int i=0; i < r; i++) {
            for (int j=0; j < c; j++) {
                if (j==0)
                    maxRowHeight << 0;
                if (i==0)
                    maxColWidth << 0;

                if (childIndex == visibleItems.count())
                    break;

                const PositionedItem &child = visibleItems.at(childIndex++);
                QGraphicsItemPrivate *childPrivate = QGraphicsItemPrivate::get(child.item);
                if (childPrivate->width() > maxColWidth[j])
                    maxColWidth[j] = childPrivate->width();
                if (childPrivate->height() > maxRowHeight[i])
                    maxRowHeight[i] = childPrivate->height();
            }
        }
    } else {
        for (int j=0; j < c; j++) {
            for (int i=0; i < r; i++) {
                if (j==0)
                    maxRowHeight << 0;
                if (i==0)
                    maxColWidth << 0;

                if (childIndex == visibleItems.count())
                    break;

                const PositionedItem &child = visibleItems.at(childIndex++);
                QGraphicsItemPrivate *childPrivate = QGraphicsItemPrivate::get(child.item);
                if (childPrivate->width() > maxColWidth[j])
                    maxColWidth[j] = childPrivate->width();
                if (childPrivate->height() > maxRowHeight[i])
                    maxRowHeight[i] = childPrivate->height();
            }
        }
    }

    int widthSum = 0;
    for(int j=0; j < maxColWidth.size(); j++) {
        if(j)
            widthSum += spacing();
        widthSum += maxColWidth[j];
    }

    int heightSum = 0;
    for(int i=0; i < maxRowHeight.size(); i++) {
        if(i)
            heightSum += spacing();
        heightSum += maxRowHeight[i];
    }

    contentSize->setHeight(heightSum);
    contentSize->setWidth(widthSum);

    int end = 0;
    if(widthValid())
        end = width();
    else
        end = widthSum;

    int xoffset=0;
    if(!d->isLeftToRight())
        xoffset=end;
    int yoffset=0;
    int curRow =0;
    int curCol =0;
    for (int i = 0; i < visibleItems.count(); ++i) {
        const PositionedItem &child = visibleItems.at(i);
        int childXOffset = xoffset;
        if(!d->isLeftToRight())
            childXOffset -= QGraphicsItemPrivate::get(child.item)->width();
        if((child.item->x()!=childXOffset)||(child.item->y()!=yoffset)) {
            positionX(childXOffset, child);
            positionY(yoffset, child);
        }

        if (m_flow == LeftToRight) {
            if(d->isLeftToRight())
                xoffset+=maxColWidth[curCol]+spacing();
            else
                xoffset-=maxColWidth[curCol]+spacing();
            curCol++;
            curCol%=c;
            if (!curCol) {
                yoffset+=maxRowHeight[curRow]+spacing();
                if(d->isLeftToRight())
                    xoffset=0;
                else
                    xoffset=end;
                curRow++;
                if (curRow>=r)
                    break;
            }
        } else {
            yoffset+=maxRowHeight[curRow]+spacing();
            curRow++;
            curRow%=r;
            if (!curRow) {
                if(d->isLeftToRight())
                    xoffset+=maxColWidth[curCol]+spacing();
                else
                    xoffset-=maxColWidth[curCol]+spacing();
                yoffset=0;
                curCol++;
                if (curCol>=c)
                    break;
            }
        }
    }
}
示例#10
0
void QDeclarativeFlow::doPositioning(QSizeF *contentSize)
{
    Q_D(QDeclarativeFlow);

    int hoffset = 0;
    int voffset = 0;
    int linemax = 0;
    QList<int> hoffsets;

    for (int i = 0; i < positionedItems.count(); ++i) {
        const PositionedItem &child = positionedItems.at(i);
        if (!child.item || !child.isVisible)
            continue;

        QGraphicsItemPrivate *childPrivate = QGraphicsItemPrivate::get(child.item);
        if (d->flow == LeftToRight)  {
            if (widthValid() && hoffset && hoffset + childPrivate->width() > width()) {
                hoffset = 0;
                voffset += linemax + spacing();
                linemax = 0;
            }
        } else {
            if (heightValid() && voffset && voffset + childPrivate->height() > height()) {
                voffset = 0;
                hoffset += linemax + spacing();
                linemax = 0;
            }
        }

        if(d->isLeftToRight()) {
            if(child.item->x() != hoffset)
                positionX(hoffset, child);
        } else {
            hoffsets << hoffset;
        }
        if(child.item->y() != voffset)
            positionY(voffset, child);

        contentSize->setWidth(qMax(contentSize->width(), hoffset + childPrivate->width()));
        contentSize->setHeight(qMax(contentSize->height(), voffset + childPrivate->height()));

        if (d->flow == LeftToRight)  {
            hoffset += childPrivate->width();
            hoffset += spacing();
            linemax = qMax(linemax, qCeil(childPrivate->height()));
        } else {
            voffset += childPrivate->height();
            voffset += spacing();
            linemax = qMax(linemax, qCeil(childPrivate->width()));
        }
    }

    if(d->isLeftToRight())
        return;

    int end;
    if(widthValid())
        end = width();
    else
        end = contentSize->width();
    int acc = 0;
    for (int i = 0; i < positionedItems.count(); ++i) {
        const PositionedItem &child = positionedItems.at(i);
        if (!child.item || !child.isVisible)
            continue;
        hoffset = end - hoffsets[acc++] - QGraphicsItemPrivate::get(child.item)->width();
        if(child.item->x() != hoffset)
            positionX(hoffset, child);
    }
}
示例#11
0
void UpdateLocalPlayer(int gameTime) {
	float deltaTimeS = (float)(gameTime) / 1000;
	Vector2 originalPosition = localPlayer.position;

	for (auto &tile : pushTileMap) {
		if (CheckCollision(tile.tile) == true) {
			//0=up 1=down 2=right 3=left
			if (tile.GetDirection(pushTileMap) == 0) localPlayer.velocityY = tile.force * deltaTimeS;
			if (tile.GetDirection(pushTileMap) == 1) localPlayer.velocityY = -tile.force * deltaTimeS;
			if (tile.GetDirection(pushTileMap) == 2) localPlayer.velocityX = tile.force * deltaTimeS;
			if (tile.GetDirection(pushTileMap) == 3) localPlayer.velocityX = -tile.force * deltaTimeS;
		}
	}

	if (floatingMovement) FloatingMovement(deltaTimeS);

	localPlayer.position.x += localPlayer.velocityX;
	localPlayer.position.y += localPlayer.velocityY;
	localPlayer.velocityX = 0;

	if (std::find(keyList.begin(), keyList.end(), SDLK_f) != keyList.end()) floatingMovement = !floatingMovement;

	if (std::find(keyList.begin(), keyList.end(), SDLK_LCTRL) != keyList.end()) { localPlayer.speed = 150; }
	else { localPlayer.speed = 100; }
	if (std::find(keyList.begin(), keyList.end(), SDLK_LEFT) != keyList.end() && std::find(keyList.begin(), keyList.end(), SDLK_RIGHT) == keyList.end()) localPlayer.velocityX =  -localPlayer.speed * deltaTimeS;
	if (std::find(keyList.begin(), keyList.end(), SDLK_RIGHT) != keyList.end() && std::find(keyList.begin(), keyList.end(), SDLK_LEFT) == keyList.end()) localPlayer.velocityX = localPlayer.speed * deltaTimeS;

	if (localPlayer.onGround == true) { 
		if (jumpPress == false) {
			if (std::find(keyList.begin(), keyList.end(), SDLK_SPACE) != keyList.end()) {
				localPlayer.velocityY = -3.5; localPlayer.onGround = false; jumpPress = true;
			}
		}
	}
	else {
		localPlayer.velocityY += 9.8 * deltaTimeS;
	}

	if (std::find(keyList.begin(), keyList.end(), SDLK_SPACE) == keyList.end()) {
		if (localPlayer.velocityY < 0 && localPlayer.onGround == false) localPlayer.velocityY += 9.8 * deltaTimeS;
		if (localPlayer.onGround == true) jumpPress = false;
	}

	for (auto &tile : tileMap) {
		if (tile.tileID == 1) {
			if (CheckCollision(tile) == true) HandleCollision(tile);
		}
	}

	std::vector<Tile> tempGroundTileList;
	for (auto &tile : groundTileList) {
		if (CheckCollision(tile) == false) {
			tempGroundTileList.push_back(tile);
		}
	}

	for (auto &tile : tempGroundTileList) {
		groundTileList.erase(std::remove(groundTileList.begin(), groundTileList.end(), tile), groundTileList.end());
	}
	tempGroundTileList.clear();

	if (groundTileList.size() == 0) localPlayer.onGround = false;

	if (originalPosition != localPlayer.position) {
		char positionChar[BUFLEN];
		std::string positionX(std::to_string(localPlayer.position.x)), positionY(std::to_string(localPlayer.position.y).c_str());
		strcpy(positionChar, ("position>" + positionX.substr(0, positionX.find('.') + 3) + "," + positionY.substr(0, positionY.find('.') + 3)).c_str());
		SendMessageWithTimer(positionChar);
	}
}
示例#12
0
文件: MapDraw.cpp 项目: winder/DSAnts
bool MapDraw::drawAnt(Creature* a, bool animate)
{
  // top-right - white
  tm->nextTexture(1);

  // ant dead?
  if (a->getHP() <= 0)
    material( 15,10,10 );
  else
    material(3,3,3);

  // exit early if not visible.
  if (! isVisible(a->getX(), a->getY()))
    return false;

  // find X/Y location by finding offset from center.
  // Then add the offset for smoothly moving between 2 squares.
//TODO: Why do I need to add 1 to a->getX() ?!?
  float x = (positionX(a->getX()+1)*MODEL_SCALE) + (a->getOffsetX()*MODEL_SCALE_INCREMENT);
  float y = (positionY(a->getY())*MODEL_SCALE) + (a->getOffsetY()*MODEL_SCALE_INCREMENT);

  if (!animate)
  {
    StaticDraw::drawRect(x, y, MODEL_SCALE*0.2, MODEL_SCALE*.4, MODEL_SCALE*0.9, tm);
    return true;
  }
  // draw at x, y.

  // slightly off the background to get rid of overlaping.
  glPushMatrix();
  // if X has no influence, facing right or left.
  // convert facing direction to measurement of 90 degrees ((-20:20) * 2.25).
  // (angle is -32768 to 32767) 
  float xInfluence = ((a->getFacingX() * 2.25f));
  // default facing up.
  float yInfluence = ((a->getFacingY() * 2.25f));

  float rotation = 0;

  // this nonsense sets the ants rotation to face the direction its walking.
  // TODO: figure out how to convert this to glRotatef32i.
  // pointing top-left
  if (( a->getFacingX() <= 0 ) && (a->getFacingY() >= 0))
    rotation = (-315) - (yInfluence+xInfluence);
  // pointing down-left
  else if (( a->getFacingX() <= 0 ) && (a->getFacingY() <= 0))
    rotation = (-225) - (yInfluence-xInfluence);
  // pointing top-right
  else if (( a->getFacingX() > 0 ) && (a->getFacingY() >= 0))
    rotation = (-45) + (yInfluence-xInfluence);
  // pointing down-right
  else if (( a->getFacingX() > 0 ) && (a->getFacingY() <= 0))
    rotation = (-135) + (yInfluence+xInfluence);

  // translate to the center point.
  glTranslatef(x, y, 0.01);
  // rotate so the ant faces in the correct direction.
  glRotatef( rotation      , 0, 0, 1);

  if (a->getType() == ANT_WORKER)
    drawWorker( a->getCarrying() );
  else if (a->getType() == ANT_QUEEN)
    drawQueen( a->getCarrying() ); // queens don't carry anything, but whatev.

  glPopMatrix(1);
  return true;
}