Example #1
0
//----------------------------------------------------------------
//              image/sprite SFML label with text
//----------------------------------------------------------------
void BaseHud::HintsBox(int xOffset, int yOffset, int fontSize, std::string caption, int alignment, float scaleX, float scaleY)
{
    sf::Vector2u spriteSize(hintsBoxTexture->getSize());                              // Get the image size
    int scaledSpriteWidth = spriteSize.x * scaleX;
    int scaledSpriteHeight = spriteSize.y * scaleY;

    sf::Vector2f alignedPos = fixAlignment(alignment, xOffset, yOffset, scaledSpriteWidth, scaledSpriteHeight);

    //create sprite
    hintsBoxSprite->setTexture(*hintsBoxTexture);
    hintsBoxSprite->setScale(scaleX, scaleY);
    hintsBoxSprite->setTextureRect(sf::IntRect(0, 0, spriteSize.x, spriteSize.y)); //unscaled!
    hintsBoxSprite->setPosition(alignedPos);

    //create text
    sf::FloatRect textRect = hintsBoxText->getLocalBounds();
    hintsBoxText->setOrigin(textRect.left + textRect.width/2.0f, textRect.top  + textRect.height/2.0f);
    hintsBoxText->setPosition(alignedPos.x + scaledSpriteWidth / 2, alignedPos.y + scaledSpriteHeight / 2 + 20);
    hintsBoxText->setString(caption);
    hintsBoxText->setFont(_font);
    hintsBoxText->setCharacterSize(fontSize);
    hintsBoxText->setColor(sf::Color::White);

    _window->draw(*hintsBoxSprite);
    _window->draw(*hintsBoxText);
}
Example #2
0
//----------------------------------------------------------------
// image/sprite SFML button, triggers action upon click
//----------------------------------------------------------------
bool BaseHud::MenuButton (int xOffset, int yOffset, int spriteID, int alignment, float scaleX, float scaleY)
{
    int spriteSheetColumns = 2;
    int spriteSheetRows = 5;

    sf::Vector2u spriteSize(menuButtonTexture->getSize());                              // Get the image size
    int scaledSpriteWidth = spriteSize.x * scaleX / spriteSheetColumns;
    int scaledSpriteHeight = spriteSize.y * scaleY / spriteSheetRows;
    int tileWidth = ( spriteSize.x / spriteSheetColumns );                          //unscaled!
    int tileHeight = spriteSize.y / spriteSheetRows;                                //unscaled!

    sf::Vector2f alignedPos = fixAlignment(alignment, xOffset, yOffset, scaledSpriteWidth, scaledSpriteHeight);

    //create sprite
    menuButtonSprite->setTexture(*menuButtonTexture);
    menuButtonSprite->setScale(scaleX, scaleY);

    if      (spriteID == 0) menuButtonSprite->setTextureRect(sf::IntRect(        0,              0, tileWidth, tileHeight)); //R1 C1    //Play
    else if (spriteID == 1) menuButtonSprite->setTextureRect(sf::IntRect(tileWidth,              0, tileWidth, tileHeight)); //R1 C2    //Play*
    else if (spriteID == 2) menuButtonSprite->setTextureRect(sf::IntRect(        0, tileHeight * 1, tileWidth, tileHeight)); //R2 C1    //Exit
    else if (spriteID == 3) menuButtonSprite->setTextureRect(sf::IntRect(tileWidth, tileHeight * 1, tileWidth, tileHeight)); //R2 C2    //Exit*
    else if (spriteID == 4) menuButtonSprite->setTextureRect(sf::IntRect(        0, tileHeight * 2, tileWidth, tileHeight)); //R3 C1    //Restart
    else if (spriteID == 5) menuButtonSprite->setTextureRect(sf::IntRect(tileWidth, tileHeight * 2, tileWidth, tileHeight)); //R3 C2    //Restart*
    else if (spriteID == 6) menuButtonSprite->setTextureRect(sf::IntRect(        0, tileHeight * 3, tileWidth, tileHeight)); //R4 C1    //Resume
    else if (spriteID == 7) menuButtonSprite->setTextureRect(sf::IntRect(tileWidth, tileHeight * 3, tileWidth, tileHeight)); //R4 C2    //Resume*
    else if (spriteID == 8) menuButtonSprite->setTextureRect(sf::IntRect(        0, tileHeight * 4, tileWidth, tileHeight)); //R5 C1    //Empty
    else if (spriteID == 9) menuButtonSprite->setTextureRect(sf::IntRect(tileWidth, tileHeight * 4, tileWidth, tileHeight)); //R5 C2    //Empty*

    menuButtonSprite->setPosition(alignedPos);

    _window->draw(*menuButtonSprite);

    return CheckMouseOnButton(alignedPos, scaledSpriteWidth, scaledSpriteHeight); //check for mouseclick
}
Example #3
0
//----------------------------------------------------------------
// image/sprite SFML button, triggers action upon click
//----------------------------------------------------------------
bool BaseHud::HintsButton(int xOffset, int yOffset, int spriteID, int alignment, float scaleX, float scaleY) {
    int spriteSheetColumns = 2;
    int spriteSheetRows = 4;

    sf::Vector2u spriteSize(hintsButtonTexture->getSize());                              // Get the image size
    int scaledSpriteWidth = spriteSize.x * scaleX / spriteSheetColumns;
    int scaledSpriteHeight = spriteSize.y * scaleY / spriteSheetRows;
    int tileWidth = ( spriteSize.x / spriteSheetColumns );                          //unscaled!
    int tileHeight = spriteSize.y / spriteSheetRows;                                //unscaled!

    sf::Vector2f alignedPos = fixAlignment(alignment, xOffset, yOffset, scaledSpriteWidth, scaledSpriteHeight);

    //create sprite
    hintsButtonSprite->setTexture(*hintsButtonTexture);
    hintsButtonSprite->setScale(scaleX, scaleY);

    if      (spriteID == 0) hintsButtonSprite->setTextureRect(sf::IntRect(        0,              0, tileWidth, tileHeight)); //R1 C1    //Sphinx
    else if (spriteID == 1) hintsButtonSprite->setTextureRect(sf::IntRect(tileWidth,              0, tileWidth, tileHeight)); //R1 C2    //Sphinx*
    else if (spriteID == 2) hintsButtonSprite->setTextureRect(sf::IntRect(        0, tileHeight * 1, tileWidth, tileHeight)); //R2 C1    //One
    else if (spriteID == 3) hintsButtonSprite->setTextureRect(sf::IntRect(tileWidth, tileHeight * 1, tileWidth, tileHeight)); //R2 C2    //One*
    else if (spriteID == 4) hintsButtonSprite->setTextureRect(sf::IntRect(        0, tileHeight * 2, tileWidth, tileHeight)); //R3 C1    //Two
    else if (spriteID == 5) hintsButtonSprite->setTextureRect(sf::IntRect(tileWidth, tileHeight * 2, tileWidth, tileHeight)); //R3 C2    //Two*
    else if (spriteID == 6) hintsButtonSprite->setTextureRect(sf::IntRect(        0, tileHeight * 3, tileWidth, tileHeight)); //R4 C1    //Three
    else if (spriteID == 7) hintsButtonSprite->setTextureRect(sf::IntRect(tileWidth, tileHeight * 3, tileWidth, tileHeight)); //R5 C2    //Three*

    hintsButtonSprite->setPosition(alignedPos);

    _window->draw(*hintsButtonSprite);

    return CheckMouseOnButton(alignedPos, scaledSpriteWidth, scaledSpriteHeight); //check for mouseclick
}
Example #4
0
//----------------------------------------------------------------
//              image/sprite SFML label with text
//----------------------------------------------------------------
void BaseHud::StoryBook(int xOffset, int yOffset, int alignment, float scaleX, float scaleY)
{
    sf::Vector2u spriteSize(storyBookTexture->getSize());                              // Get the image size
    sf::Vector2f alignedPos = fixAlignment(alignment, xOffset, yOffset, spriteSize.x * scaleX, spriteSize.y * scaleY);

    //create sprite
    storyBookSprite->setTexture(*storyBookTexture);
    storyBookSprite->setScale(scaleX, scaleY);
    storyBookSprite->setTextureRect(sf::IntRect(0,0,spriteSize.x,spriteSize.y)); //unscaled!
    storyBookSprite->setPosition(alignedPos);

    _window->draw(*storyBookSprite);
}
Example #5
0
Tile :: Tile(Params* const pParams, NE::SpriteLoader* pSL, const std::string& folderPath)
    :pParams(pParams)
{
    assert(pParams);
    assert(pSL);

    // Check if the important nodes are present
    for ( unsigned int i = 0 ; i < sizeof(neededParameters) / sizeof(std::string) ; i++ )
    {
        if ( !pParams->exists(neededParameters[i]) )
        {
            throw MissingParameterException(neededParameters[i]);
        }
    }

    try
    {
        this->internalName = pParams->get("internalName");
        this->name = pParams->get("name");
        this->id = pParams->getAs<unsigned int>("tile-id");
        this->menuEntry = pParams->getAs<short int>("tile-menu");

        UVec2 spriteSize(pParams->getAs<unsigned int>("size_x"),
                         pParams->getAs<unsigned int>("size_y"));

		try
		{
			this->pSprite = new CE::AnimatedSprite(pSL, folderPath + pParams->get("filename"),spriteSize,pParams->getAs<unsigned int>("animationTime",200));
		}
		catch ( FileNotFoundException& fnfe) // Should be handle as smart ptr
		{
			delete pParams;
			throw fnfe;
		}

        if ( this->pSprite == NULL )
        {
            NEError << "Fail to allocate memory for AnimatedSprite for Tile\n";
            throw std::bad_alloc();
        }

        this->defence = pParams->getAs<unsigned int>("defence");
    }
    catch ( ParameterNotFoundParamsException& )
    {
        NEError << "The force list is not matching the requested parameters\n";
        throw MissingParameterException("unknown");
    }
}
Example #6
0
//----------------------------------------------------------------
// image/sprite SFML button, triggers action upon click
//----------------------------------------------------------------
bool BaseHud::StoryBookButton (int xOffset, int yOffset, int spriteID, int alignment, float scaleX, float scaleY)
{
    int spriteSheetRows = 2;

    sf::Vector2u spriteSize(storyBookButtonTexture->getSize());                              // Get the image size
    int scaledSpriteWidth = spriteSize.x * scaleX;
    int scaledSpriteHeight = spriteSize.y * scaleY / spriteSheetRows;
    int tileHeight = ( spriteSize.y / spriteSheetRows );                               //unscaled!

    sf::Vector2f alignedPos = fixAlignment(alignment, xOffset, yOffset, scaledSpriteWidth, scaledSpriteHeight);

    //create sprite
    storyBookButtonSprite->setTexture(*storyBookButtonTexture);
    storyBookButtonSprite->setScale(scaleX, scaleY);
    if (spriteID == 0) storyBookButtonSprite->setTextureRect(sf::IntRect(0,0,spriteSize.x,tileHeight));
    else storyBookButtonSprite->setTextureRect(sf::IntRect(0,tileHeight,spriteSize.x,tileHeight));
    storyBookButtonSprite->setPosition(alignedPos);

    _window->draw(*storyBookButtonSprite);

    return CheckMouseOnButton(alignedPos, scaledSpriteWidth, scaledSpriteHeight); //check for mouseclick
}
Example #7
0
/**
 * Prepares the sprite in the set of type aSpriteType to be displayed at
 * aSpritePos with size aSpriteSize.  The sprite will be resized as necessary under the
 * restriction of aSpriteResizeMode.
 */
EXPORT_C void CSpriteSet::PrepareSpriteForDisplayL(TInt aSpriteType, const TPoint& aSpritePos, const TSize& aSpriteSize, TSpriteResizeMode aSpriteResizeMode)
	{
	__ASSERT_DEBUG((aSpriteType >= 0) && (aSpriteType < iSourceMembers.Count()),Panic(EEgulPanicInvalidSpriteIndex));
	__ASSERT_DEBUG((aSpriteSize.iWidth >= 0) && (aSpriteSize.iHeight >= 0),Panic(EEgulPanicNegativeSpriteSize));
	iSpritePosition = aSpritePos;
	iMainFbsBitGc->SetOrigin(TPoint(0,0));
	TSize spriteSize(aSpriteSize);
	const TSize sourceSize(iSourceMembers[aSpriteType]->Bitmap()->SizeInPixels());
	AdjustSpriteSizeAccordingToResizeMode(spriteSize, sourceSize, aSpriteResizeMode);
	User::LeaveIfError(iMainBmpDevice->Resize(spriteSize));
	User::LeaveIfError(iMaskBmpDevice->Resize(spriteSize));
	iMainFbsBitGc->Resized();
	iMaskFbsBitGc->Resized();
	iMaskFbsBitGc->SetBrushColor(KRgbBlack);
	iMaskFbsBitGc->Clear();
	const TRect translatedClipRect(iClippingRect.iTl - aSpritePos, iClippingRect.Size());
	if(!translatedClipRect.IsEmpty())
		iMaskFbsBitGc->SetClippingRect(translatedClipRect);
	TInternalSpriteResizeMode resizeMode = EHSameVSame;
	ComputeInternalResizeMode(resizeMode,aSpriteResizeMode,sourceSize,spriteSize);
	RenderSprite(aSpriteType,resizeMode,sourceSize,spriteSize);
	iMaskFbsBitGc->CancelClippingRect();
	iMainFbsBitGc->SetOrigin(-aSpritePos);
	}