コード例 #1
0
void QGeoTiledMapNokia::evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTiles)
{
    const int spaceToLogo = 4;
    const int blurRate = 1;
    const int fontSize = 10;

    if (m_engine.isNull())
        return;

    const QString copyrightsString = m_engine->evaluateCopyrightsText(activeMapType(), mapController()->zoom(), visibleTiles);

    if (width() > 0 && height() > 0 && ((copyrightsString.isNull() && m_copyrightsSlab.isNull()) || copyrightsString != m_lastCopyrightsString)) {
        QFont font("Sans Serif");
        font.setPixelSize(fontSize);
        font.setStyleHint(QFont::SansSerif);
        font.setWeight(QFont::Bold);

        QRect textBounds = QFontMetrics(font).boundingRect(0, 0, width(), height(), Qt::AlignBottom | Qt::AlignLeft | Qt::TextWordWrap, copyrightsString);

        m_copyrightsSlab = QImage(m_logo.width() + textBounds.width() + spaceToLogo + blurRate * 2,
                                qMax(m_logo.height(), textBounds.height() + blurRate * 2),
                                QImage::Format_ARGB32_Premultiplied);
        m_copyrightsSlab.fill(Qt::transparent);

        QPainter painter(&m_copyrightsSlab);
        painter.drawImage(QPoint(0, m_copyrightsSlab.height() - m_logo.height()), m_logo);
        painter.setFont(font);
        painter.setPen(QColor(0, 0, 0, 64));
        painter.translate(spaceToLogo + m_logo.width(), -blurRate);
        for (int x=-blurRate; x<=blurRate; ++x) {
            for (int y=-blurRate; y<=blurRate; ++y) {
                painter.drawText(x, y, textBounds.width(), m_copyrightsSlab.height(),
                                 Qt::AlignBottom | Qt::AlignLeft | Qt::TextWordWrap,
                                 copyrightsString);
            }
        }
        painter.setPen(Qt::white);
        painter.drawText(0, 0, textBounds.width(), m_copyrightsSlab.height(),
                         Qt::AlignBottom | Qt::AlignLeft | Qt::TextWordWrap,
                         copyrightsString);
        painter.end();

        m_lastCopyrightsString = copyrightsString;
    }

    emit copyrightsChanged(m_copyrightsSlab);
}
コード例 #2
0
int SessionController::launch(Character &character, Interface &interface) {
	//Initialization
	Map map = SaveUtils::loadMap(character.getName(), character.getMap());
	SessionScreen sessionScreen;
	character.checkView(map);
	sessionScreen.display(character, interface, map);
	GameInput input;
	//Game Loop
	while (input.getValue() != CLOSE_INPUT) {
		//To know if we have to count the current turn.
		bool played = false;
		//To know if we have to refresh the screen.
		bool toRefresh = true;
		//To know if the player have changed his position.
		bool moved = false;
		input = sessionScreen.recupInput();
		switch (input.getValue()) {
			moved = false;
			//Quit Game
			case ESCAPE_INPUT : {
				interface.write("Return to the menu (y or n)?");
				sessionScreen.display(character, interface, map);
				GameInput tmpInput;
				int tmpValue;
				do {
					tmpInput = sessionScreen.recupInput();
					tmpValue = tmpInput.getValue();
				} while ((tmpValue != N_INPUT) && (tmpValue != Y_INPUT));
				if (tmpValue == N_INPUT)
					interface.write("Okay then.");
				else {
					SaveUtils::save(character, interface);
					SaveUtils::saveMap(character.getName(), character.getMap(), map);
					return TO_MAIN_MENU;
				}
				break;
			}
			//Display Map
			case M_INPUT : {
				MapController mapController(map, character);
				input.setValue(mapController.launch(map, character));
				break;
			}
			//Display Inventory
			case I_INPUT : {
				InventoryController inventoryController;
				input.setValue(inventoryController.launch(character));
				break;
			}
			//Pick Item
			case P_INPUT : {
				/*if (map.cell[character.getX()][character.getY()].drops.empty())
					interface.write("There's nothing here.");
				else {
					//character.equipement.legs = &map.cell[character.getX()][character.getY()].drops.front();
				}*/
				break;
			}
			//Change map
			case Q_INPUT : {
				if (changeMap(character, map, interface)) {
					SaveUtils::save(character, interface);
					return REDO;
				}
				else
					interface.write("You cannot exit from here !");
				break;
			}
			//Moving inputs
			case UP_INPUT : {
				moved = character.move(0,-1,map);
				played = true;
				break;
			}
			case DOWN_INPUT : {
				moved = character.move(0,1,map);
				played = true;
				break;
			}
			case RIGHT_INPUT : {
				moved = character.move(1,0,map);
				played = true;
				break;
			}
			case LEFT_INPUT : {
				moved = character.move(-1,0,map);
				played = true;
				break;
			}
			default:
				toRefresh = false;
		}
		if (moved) {
			interface.showItems(map.cell[character.getX()][character.getY()]);
			interface.showDestination(map.cell[character.getX()][character.getY()]);
		}
		if (played) {
			map.refreshCells(character.getX(), character.getY());
			character.checkView(map);
		}
		if (toRefresh)
			sessionScreen.display(character, interface, map);
	}
	SaveUtils::save(character, interface);
	SaveUtils::saveMap(character.getName(), character.getMap(), map);
	return CLOSE_INPUT;
}