Beispiel #1
0
Animation::Animation(const std::string& filename, int timePerFrame, int numFrames):m_timePerFrame(timePerFrame), m_numFrames(numFrames), m_currentFrame(0){
	m_texture.loadFromFile(filename);
	m_sprite.setTexture(m_texture);

	sf::IntRect textureRect(0, 0, m_texture.getSize().x/m_numFrames, m_texture.getSize().y);
	m_sprite.setTextureRect(textureRect);
}
    void copyTexture(const ThreadDispatcher::message& msg)
    {
        const CreateTextureTask* task = (const CreateTextureTask*)msg.cbData;


        MemoryTexture* src = task->src.get();
        NativeTexture* dest = task->dest.get();

        bool done = false;

        if (isCompressedFormat(src->getFormat()))
        {
            dest->init(src->lock(), false);
            done = true;
        }
        else
        {

            Rect textureRect(0, 0, src->getWidth(), src->getHeight());

            if (dest->getHandle() == 0)
                dest->init(textureRect.getWidth(), textureRect.getHeight(), src->getFormat());

            dest->updateRegion(0, 0, src->lock());
        }

        task->ready();
    }
Beispiel #3
0
// Private Method(s)
	// Setup Tiles
void Puzzle::setupTiles()
{
	int tilesSquared = static_cast<int>(sqrt(mTiles.size()));
	int curCol = 0, curRow = 0;

	sf::FloatRect outlineRect = mGrid.getOutlineRect();
	sf::Vector2f tileRect(outlineRect.width / tilesSquared, outlineRect.height / tilesSquared);

	sf::Vector2f textureSize(mTexture.getSize());
	sf::Vector2f textureRect(textureSize.x / tilesSquared, textureSize.y / tilesSquared);

	sf::Vector2f scalingFactor(tileRect.x / textureRect.x,
		tileRect.y / textureRect.y);

	for (unsigned i = 0; i < mTiles.size(); i++)
	{
		mTiles[i].first->setTextureRect(static_cast<sf::IntRect>
			(sf::FloatRect(curCol * textureRect.x, curRow * textureRect.y,
						   textureRect.x, textureRect.y)));
		mTiles[i].first->setTexture(mTexture);
		mTiles[i].first->scale(scalingFactor);
		mTiles[i].first->setPosition(mGrid.getTilePos(i));

		curCol++;
		if (curCol % tilesSquared == 0) {
			curRow++;
			curCol = 0;
		}
	}
}
Beispiel #4
0
void World::buildScene()
{
    for (std::size_t i = 0; i < LayerCount; ++i)
    {
        SceneNode::Ptr layer(new SceneNode());
        mSceneLayers[i] = layer.get();

        mSceneGraph.attachChild(std::move(layer));
    }

    sf::Texture& texture = mTextures.get(Textures::ID::Desert);
    sf::IntRect textureRect(mWorldBounds);
    texture.setRepeated(true);

    std::unique_ptr<SpriteNode> backgroundSprite(new SpriteNode(texture, textureRect));
    backgroundSprite->setPosition(mWorldBounds.left, mWorldBounds.top);
    mSceneLayers[Layer::Background]->attachChild(std::move(backgroundSprite));

    std::unique_ptr<Aircraft> leader(new Aircraft(Aircraft::Type::Eagle, mTextures));
    mPlayerAircraft = leader.get();
    mPlayerAircraft->setPosition(mSpawnPosition);
    mPlayerAircraft->setVelocity(0.f, mScrollSpeed);
    mSceneLayers[Layer::Air]->attachChild(std::move(leader));

    std::unique_ptr<Aircraft> leftEscort(new Aircraft(Aircraft::Type::Raptor, mTextures));
    leftEscort->setPosition(-80.f, 50.f);
    mPlayerAircraft->attachChild(std::move(leftEscort));
    
    std::unique_ptr<Aircraft> rightEscort(new Aircraft(Aircraft::Type::Raptor, mTextures));
    rightEscort->setPosition(80.f, 50.f);
    mPlayerAircraft->attachChild(std::move(rightEscort));
}
void World::buildScene() {
    // Initialize the different layers
    for (std::size_t i = 0; i < Layer::count; i++) {
        SceneNode::Ptr layer(new SceneNode());
        sceneLayers[i] = layer.get();
        sceneGraph.attachChild(std::move(layer));
    }

    // Prepare the title background
    sf::Texture &texture = textures.get(Textures::Desert);
    sf::IntRect textureRect(worldBounds);
    texture.setRepeated(true);

    // Add the background sprite to the scene
    std::unique_ptr<SpriteNode> backgroundSprite(new SpriteNode(texture, textureRect));
    backgroundSprite->setPosition(worldBounds.left, worldBounds.top);
    sceneLayers[Background]->attachChild(std::move(backgroundSprite));

    // Add player's aircraft
    std::unique_ptr<Aircraft> leader(new Aircraft(Aircraft::Eagle, textures));
    playerAircraft = leader.get();
    playerAircraft->setPosition(spawnPosition);
    playerAircraft->setVelocity(40.f, scrollSpeed);
    sceneLayers[Air]->attachChild(std::move(leader));

    // Add two escorting aircrafts, placed relatively to the main plane
    std::unique_ptr<Aircraft> leftEscort(new Aircraft(Aircraft::Raptor, textures));
    leftEscort->setPosition(-80.f, 50.f);
    playerAircraft->attachChild(std::move(leftEscort));
    std::unique_ptr<Aircraft> rightEscort(new Aircraft(Aircraft::Raptor, textures));
    rightEscort->setPosition(80.f, 50.f);
    playerAircraft->attachChild(std::move(rightEscort));
}
Beispiel #6
0
void TestMap::buildScene()
{
	for (std::size_t i = 0; i < LayerCount; ++i)
	{
		SceneNode::Ptr layer(new SceneNode());
		mSceneLayers[i] = layer.get();

		mSceneGraph.attachChild(std::move(layer));
	}

	// Prepare the tiled background
	sf::Texture& texture = mTextures.get(Textures::Desert);
	sf::IntRect textureRect(mWorldBounds);
	texture.setRepeated(false);

	// Add the background sprite to the scene
	std::unique_ptr<SpriteNode> backgroundSprite(new SpriteNode(texture, textureRect));
	backgroundSprite->setPosition(mWorldBounds.left, mWorldBounds.top);
	mSceneLayers[Background]->attachChild(std::move(backgroundSprite));

	/*std::unique_ptr<Character> player(new Character(mTextures));
	mCharacter = player.get();
	mCharacter->setPosition(mWorldBounds.height / 2.f, 50.f);
	mSceneLayers[NPC]->attachChild(std::move(player));*/
}
void World::buildScene()
{
	// Initialize the different layers
	for (std::size_t i = 0; i < LayerCount; ++i)
	{
		Category::Type category = (i == Air) ? Category::SceneAirLayer : Category::None;

		SceneNode::Ptr layer(new SceneNode(category));
		mSceneLayers[i] = layer.get();

		mSceneGraph.attachChild(std::move(layer));
	}

	// Prepare the tiled background
	sf::Texture& texture = mTextures.get(Textures::Desert);
	sf::IntRect textureRect(mWorldBounds);
	texture.setRepeated(true);

	// Add the background sprite to the scene
	std::unique_ptr<SpriteNode> backgroundSprite(new SpriteNode(texture, textureRect));
	backgroundSprite->setPosition(mWorldBounds.left, mWorldBounds.top);
	mSceneLayers[Background]->attachChild(std::move(backgroundSprite));

	// Add player's aircraft
	std::unique_ptr<Aircraft> player(new Aircraft(Aircraft::Eagle, mTextures, mFonts));
	mPlayerAircraft = player.get();
	mPlayerAircraft->setPosition(mSpawnPosition);
	mSceneLayers[Air]->attachChild(std::move(player));

	// Add enemy aircraft
	addEnemies();
}
Beispiel #8
0
void
World::buildScene() {
    for ( std::size_t i=0; i<LayerCount; i++ ) {
        // TODO: replace it with more readable construct
        Category::Type category = (i == LowerAir) ? Category::SceneAirLayer : Category::None;

        SceneNode::Ptr layer( new SceneNode( category ) );
        mSceneLayers[i] = layer.get();

        mSceneGraph.AttachChild( std::move( layer ) );
    }

    // Prepare the tiled background
    // Wrap up it into a private method later
    sf::Texture& jungleTexture = mTextures.get( Textures::Jungle );
    jungleTexture.setRepeated( true );

    float viewHeight = mWorldView.getSize().y;
    sf::IntRect textureRect( mWorldBounds );
    textureRect.height += static_cast<int>( viewHeight );

    // Add the background sprite to the scene
    std::unique_ptr<SpriteNode> jungleSprite(
        new SpriteNode( jungleTexture, textureRect )
    );
    jungleSprite->setPosition( mWorldBounds.left, mWorldBounds.top );
    mSceneLayers[Background]->AttachChild( std::move( jungleSprite ) );

    // Add the finsh line to the scene
    sf::Texture& finishTexture = mTextures.get( Textures::FinishLine );
    std::unique_ptr<SpriteNode> finishSprite( new SpriteNode( finishTexture ) );
    finishSprite->setPosition( 0.0f, -76.0f );
    mFinishSprite = finishSprite.get();
    mSceneLayers[Background]->AttachChild( std::move( finishSprite ) );

    // Add particle node to the scene
    std::unique_ptr<ParticleNode> smokeNode(
        new ParticleNode( Particle::Smoke, mTextures )
    );
    mSceneLayers[LowerAir]->AttachChild( std::move( smokeNode ) );

    // Add propellant particle node to scene
    std::unique_ptr<ParticleNode> propellantNode(
        new ParticleNode( Particle::Propellant, mTextures )
    );
    mSceneLayers[LowerAir]->AttachChild( std::move( propellantNode ) );

    // Add sound effect node
    std::unique_ptr<SoundNode> soundNode( new SoundNode( mSounds ) );
    mSceneGraph.AttachChild( std::move( soundNode ) );

    // Add network node, if necessary
    if ( mNetworkedWorld ) {
        std::unique_ptr<NetworkNode> networkNode( new NetworkNode() );
        mNetworkNode = networkNode.get();
        mSceneGraph.AttachChild( std::move( networkNode ) );
    }
    addEnemies();
}
Beispiel #9
0
void World::Impl::BuildScene()
{
	for ( std::size_t i = 0; i < LayerCount; ++i )
	{
		Category::Type category = ( i == LowerAir ) ? Category::SceneAirLayer : Category::None;

		SceneNode::SceneNodePtr layer( new SceneNode( category ) );
		mSceneLayers[ i ] = layer.get();
		mSceneGraph.AttachChild( std::move( layer ) );
	}

	sf::Texture & texture = mTextures.Get( Texture::Jungle );
	texture.setRepeated( true );

	float viewHeight = mWorldView.getSize().y;
	sf::IntRect textureRect( mWorldBounds );
	textureRect.height += static_cast<int>( viewHeight );

	std::unique_ptr< SpriteNode > backgroundSprite( new SpriteNode( texture, textureRect ) );
	backgroundSprite->setPosition( mWorldBounds.left, mWorldBounds.top - viewHeight );
	mSceneLayers[ Background ]->AttachChild( std::move( backgroundSprite ) );

	// Add particle node to the scene
	std::unique_ptr<ParticleNode> smokeNode( new ParticleNode( Particle::Type::Smoke, mTextures ) );
	mSceneLayers[ LowerAir ]->AttachChild( std::move( smokeNode ) );

	// Add propellant particle node to the scene
	std::unique_ptr<ParticleNode> propellantNode( new ParticleNode( Particle::Type::Propellant, mTextures ) );
	mSceneLayers[ LowerAir ]->AttachChild( std::move( propellantNode ) );

	// Add sound effect node
	std::unique_ptr< SoundNode > soundNode( new SoundNode( mSounds ) );
	mSceneGraph.AttachChild( std::move( soundNode ) );

	// Add network node, if necessary
	if ( mNetworkedWorld )
	{
		std::unique_ptr<NetworkNode> networkNode( new NetworkNode() );
		mNetworkNode = networkNode.get();
		mSceneGraph.AttachChild( std::move( networkNode ) );
	}

	b2BodyDef BodyDef;
	BodyDef.position = b2Vec2( 100.f / 2 / PhysicsNode::Scale, 16.f / 2 / PhysicsNode::Scale );
	BodyDef.type = b2_staticBody;
	b2Body* Body = mPhysics.CreateBody( &BodyDef );

	b2PolygonShape Shape;
	Shape.SetAsBox( ( 100.f / 2 ) / PhysicsNode::Scale, ( 16.f / 2 ) / PhysicsNode::Scale );
	b2FixtureDef FixtureDef;
	FixtureDef.density = 0.f;
	FixtureDef.shape = &Shape;
	Body->CreateFixture( &FixtureDef );
}
Beispiel #10
0
Animation::Animation(const std::string& filename, int timePerFrame, int numFrames) :
mTimePerFrame(timePerFrame),
mNumFrames(numFrames),
mCurrentFrame(0){
	/* Använder texturen som en sprite */
	mSprite.setTexture(ResourceManager::getTexture(filename));

	/* Visar den första framen av spritesheetet */
	sf::IntRect textureRect(0, 0, ResourceManager::getTexture(filename).getSize().x / mNumFrames, ResourceManager::getTexture(filename).getSize().y);
	mSprite.setTextureRect(textureRect);
};
Beispiel #11
0
//När objektet skapas måste filnamnet på vilket spritesheet som
//skall användas, hur lång tid varje frame ska synas, anges i millisekunder,
//samt hur många frames per animation.
Animation::Animation(const std::string& filename, int timePerFrame, int numFrames):
	mTimePerFrame(timePerFrame),
	mNumFrames(numFrames),
	mCurrentFrame(0),
	mAnimate(true)
{
	mTexture = TextureManager::getTexture(filename);
	mSprite = TextureManager::getSprite(filename);
	sf::IntRect textureRect(0,0, mTexture.getSize().x/mNumFrames, mTexture.getSize().y);
	mSprite.setTextureRect(textureRect);
}
Beispiel #12
0
// Add new world Texture bounds.
void World::addNewWorldArea()
{
	sf::Texture& texture = mTextures.get(Textures::Background);
	mWorldBounds.top -= WorldLeght;

	sf::IntRect textureRect(mWorldBounds.left, mWorldBounds.top, mWorldBounds.width, mWorldBounds.height);
	texture.setRepeated(true);

	std::unique_ptr<SpriteNode> backgroundSprite(new SpriteNode(texture, textureRect));
	backgroundSprite->setPosition(mWorldBounds.left, mWorldBounds.top);
	mSceneLayers[Background]->attachChild(std::move(backgroundSprite));
}
void World::buildScene()
{
	// Initialize the different layers
	for (std::size_t i = 0; i < LayerCount; ++i)
	{
		Category::Type category = (i == LowerAir) ? Category::SceneAirLayer : Category::None;

		SceneNode::Ptr layer(new SceneNode(category));
		mSceneLayers[i] = layer.get();

		mSceneGraph.attachChild(std::move(layer));
	}

	// Prepare the tiled background
	sf::Texture& jungleTexture = mTextures.get(Textures::Jungle);
	jungleTexture.setRepeated(true);

	float viewHeight = mWorldView.getSize().y;
	sf::IntRect textureRect(mWorldBounds);
	textureRect.height += static_cast<int>(viewHeight);

	// Add the background sprite to the scene
	std::unique_ptr<SpriteNode> jungleSprite(new SpriteNode(jungleTexture, textureRect));
	jungleSprite->setPosition(mWorldBounds.left, mWorldBounds.top - viewHeight);
	mSceneLayers[Background]->attachChild(std::move(jungleSprite));

	// Add the finish line to the scene
	sf::Texture& finishTexture = mTextures.get(Textures::FinishLine);
	std::unique_ptr<SpriteNode> finishSprite(new SpriteNode(finishTexture));
	finishSprite->setPosition(0.f, -76.f);
	mSceneLayers[Background]->attachChild(std::move(finishSprite));

	// Add particle node to the scene
	std::unique_ptr<ParticleNode> smokeNode(new ParticleNode(Particle::Smoke, mTextures));
	mSceneLayers[LowerAir]->attachChild(std::move(smokeNode));

	// Add propellant particle node to the scene
	std::unique_ptr<ParticleNode> propellantNode(new ParticleNode(Particle::Propellant, mTextures));
	mSceneLayers[LowerAir]->attachChild(std::move(propellantNode));

	// Add sound effect node
	std::unique_ptr<SoundNode> soundNode(new SoundNode(mSounds));
	mSceneGraph.attachChild(std::move(soundNode));

	// Add player's aircraft
	std::unique_ptr<Aircraft> player(new Aircraft(Aircraft::Eagle, mTextures, mFonts));
	mPlayerAircraft = player.get();
	mPlayerAircraft->setPosition(mSpawnPosition);
	mSceneLayers[UpperAir]->attachChild(std::move(player));

	// Add enemy aircraft
	addEnemies();
}
Beispiel #14
0
Animation::Animation(const std::string& p_filename, int p_timePerFrame, int p_numFrames) :
    m_timePerFrame(p_timePerFrame),
    m_numFrames(p_numFrames),
    m_currentFrame(0)
{
    m_pSprite = new sf::Sprite;
    m_pTexture = Resources::GetTexture(p_filename);
    m_pSprite->setTexture(*m_pTexture);

    // The rectangle below is used as an "view" for viewing only part of the sprites texture. Parameters are x position, y position, width and height. The width is divided by m_numFrames, this is the number of pixels per frame.
    sf::IntRect textureRect(0, 0, m_pTexture->getSize().x/m_numFrames, m_pTexture->getSize().y);
    m_pSprite->setTextureRect(textureRect);
}
Beispiel #15
0
void World::buildScene()
{
   
    for (std::size_t i = 0; i < LayerCount; i++) {
        SceneNode::Ptr layer(new SceneNode());
        mSceneLayers[i] = layer.get();
        mSceneGraph.attachChild(std::move(layer));
    }
    
    // map
    sf::Texture& texture = mTextures.get(Textures::Map);
    sf::IntRect textureRect(mWorldBounds);
    texture.setRepeated(true);
    
    std::unique_ptr<SpriteNode> backgroundSprite(new SpriteNode(texture, textureRect));
    
    backgroundSprite->setPosition(mWorldBounds.left, mWorldBounds.top);
    
    mSceneLayers[Background]->attachChild(std::move(backgroundSprite));
    
    // end line
    sf::Texture& end = mTextures.get(Textures::End);
    std::unique_ptr<SpriteNode> endSprite(new SpriteNode(end));
    
    endSprite->setPosition(0.f, -76.f);
    
    mSceneLayers[Background]->attachChild(std::move(endSprite));
    
    
    // player aircraft
    std::unique_ptr<Aircraft>   Leader(new Aircraft(Aircraft::Player1, mTextures, mFonts));
    mPlayerAircraft = Leader.get();
    mPlayerAircraft->setPosition(mSpawnPosition);
    mPlayerAircraft->setVelocity(0.f, mScrollSpeed);
    mSceneLayers[Air]->attachChild(std::move(Leader));
    
    // score display
    std::unique_ptr<TextNode>   score(new TextNode(mFonts, ""));
    mScoreDisplay = score.get();
    score->setSize(40);
    score->setColor(sf::Color::Yellow);
    score->setFont(mFonts, Fonts::Blade2);
    score->setString("Score: " + std::to_string(mScore));
    score->setPosition(mWorldView.getSize().x - 100.f, mWorldBounds.height - 750.f);
    mSceneLayers[Air]->attachChild(std::move(score));

}
void
TiledContentHost::RenderTile(const TiledTexture& aTile,
                             EffectChain& aEffectChain,
                             float aOpacity,
                             const gfx::Matrix4x4& aTransform,
                             const gfx::Filter& aFilter,
                             const gfx::Rect& aClipRect,
                             const nsIntRegion& aScreenRegion,
                             const nsIntPoint& aTextureOffset,
                             const nsIntSize& aTextureBounds)
{
  MOZ_ASSERT(aTile.mDeprecatedTextureHost, "Trying to render a placeholder tile?");

  RefPtr<TexturedEffect> effect =
    CreateTexturedEffect(aTile.mDeprecatedTextureHost, aFilter);
  if (!effect) {
    return;
  }

  if (aTile.mDeprecatedTextureHost->Lock()) {
    aEffectChain.mPrimaryEffect = effect;
  } else {
    return;
  }

  nsIntRegionRectIterator it(aScreenRegion);
  for (const nsIntRect* rect = it.Next(); rect != nullptr; rect = it.Next()) {
    Rect graphicsRect(rect->x, rect->y, rect->width, rect->height);
    Rect textureRect(rect->x - aTextureOffset.x, rect->y - aTextureOffset.y,
                     rect->width, rect->height);

    effect->mTextureCoords = Rect(textureRect.x / aTextureBounds.width,
                                  textureRect.y / aTextureBounds.height,
                                  textureRect.width / aTextureBounds.width,
                                  textureRect.height / aTextureBounds.height);
    mCompositor->DrawQuad(graphicsRect, aClipRect, aEffectChain, aOpacity, aTransform);
  }
  mCompositor->DrawDiagnostics(DIAGNOSTIC_CONTENT|DIAGNOSTIC_TILE,
                               aScreenRegion, aClipRect, aTransform);

  aTile.mDeprecatedTextureHost->Unlock();
}
/// @todo: compatibility with multiple lines spritesheet
void Animation::update(sf::Time elapsedTime)
{
    sf::Time timePerFrame = _duration / static_cast<float>(_numberFrames);
    _elapsedTime += elapsedTime;

    while(_isLoaded && _elapsedTime >= timePerFrame && (_currentFrame <= _numberFrames || _repeat))
    {
        _currentFrame++;
        if(_currentFrame >= _numberFrames && _repeat)
            _currentFrame = 0;

        _elapsedTime -= timePerFrame;
    }

    sf::IntRect textureRect(_frameRect.left + _currentFrame * _frameRect.width,
                            _frameRect.top, ///@todo: here
                            _frameRect.width,
                            _frameRect.height);

    _sprite.setTextureRect(textureRect);
}
void World::buildScene()
{
	for (int i = 0; i < LayerCount; i++)
	{
		SceneNode::Ptr layer(new SceneNode());
		sceneLayers[i] = layer.get();
		sceneGraph.attachChild(std::move(layer));
	}
	
	sf::Texture& texture = data->rscStorage.getTextureRef("land");
	sf::IntRect textureRect(worldBounds);
	texture.setRepeated(true);
	
	unique_ptr<SpriteNode> backgroundSprite(new SpriteNode(texture, textureRect));
	backgroundSprite->setPosition(worldBounds.left, worldBounds.top);
	sceneLayers[Background]->attachChild(std::move(backgroundSprite));
	
	unique_ptr<Character> leader(new Character("greenalien", &data->animStorage));
	playerCharacter = leader.get();
	playerCharacter->setPosition(spawnPosition);
	playerCharacter->setVelocity(100.f, 0.f);
	sceneLayers[Surface]->attachChild(std::move(leader));
}
Beispiel #19
0
void World::buildScene()
{
	// Initialize the different layers
	for (std::size_t i = 0; i < LayerCount; ++i)
	{
		SceneNode::Ptr layer(new SceneNode());
		mSceneLayers[i] = layer.get();

		mSceneGraph.attachChild(std::move(layer));
	}

	// Prepare the tiled background
	sf::Texture& texture = mTextures.get(Textures::Background);
	sf::IntRect textureRect(mWorldBounds);
	texture.setRepeated(true);

	// Add the background sprite to the scene
	std::unique_ptr<SpriteNode> backgroundSprite(new SpriteNode(texture, textureRect));
	backgroundSprite->setPosition(mWorldBounds.left, mWorldBounds.top);
	mBackgroundSprite = backgroundSprite.get();
	mSceneLayers[Background]->attachChild(std::move(backgroundSprite));


	// Add player's spaceship
	std::unique_ptr<Spaceship> leader(new Spaceship(Spaceship::Rocket, mTextures));
	mPlayerSpaceship = leader.get();
	mPlayerSpaceship->setPosition(mSpawnPosition);
	mSceneLayers[Space]->attachChild(std::move(leader));

	mBattlifieldBounds.setSize(sf::Vector2f(getBattlefieldBounds().width, getBattlefieldBounds().height));
	mBattlifieldBounds.setPosition(getBattlefieldBounds().left, getBattlefieldBounds().top);
	mBattlifieldBounds.setFillColor(sf::Color::Transparent);
	mBattlifieldBounds.setOutlineThickness(2.f);
	mBattlifieldBounds.setOutlineColor(sf::Color::Green);

	initialText();
}
Beispiel #20
0
void Button::changeTexture(Type type)
{
    sf::IntRect textureRect(190 * type, 0, 190, 49);
    sprite.setTextureRect(textureRect);
}
Beispiel #21
0
NS_DOROTHY_BEGIN

oParticleDef* oParticleCache::load( const char* filename )
{
    auto it = _parDict.find(filename);
    if (it != _parDict.end())
    {
        return it->second;
    }
    else
    {
        unsigned long size;
        auto data = oSharedContent.loadFile(filename, size);
        auto dict = CCDictionary::createWithContents(data, (unsigned int)size);

        oParticleDef* type = new oParticleDef();
        type->autorelease();

        type->maxParticles = (int)dict->numberForKey("maxParticles");
        type->angle = (float)dict->numberForKey("angle");
        type->angleVariance = (float)dict->numberForKey("angleVariance");
        type->duration = (float)dict->numberForKey("duration");
        type->blendFuncSource = (float)dict->numberForKey("blendFuncSource");
        type->blendFuncDestination = (float)dict->numberForKey("blendFuncDestination");
        type->startColorRed = (float)dict->numberForKey("startColorRed");
        type->startColorGreen = (float)dict->numberForKey("startColorGreen");
        type->startColorBlue = (float)dict->numberForKey("startColorBlue");
        type->startColorAlpha = (float)dict->numberForKey("startColorAlpha");
        type->startColorVarianceRed = (float)dict->numberForKey("startColorVarianceRed");
        type->startColorVarianceGreen = (float)dict->numberForKey("startColorVarianceGreen");
        type->startColorVarianceBlue = (float)dict->numberForKey("startColorVarianceBlue");
        type->startColorVarianceAlpha = (float)dict->numberForKey("startColorVarianceAlpha");
        type->finishColorRed = (float)dict->numberForKey("finishColorRed");
        type->finishColorGreen = (float)dict->numberForKey("finishColorGreen");
        type->finishColorBlue = (float)dict->numberForKey("finishColorBlue");
        type->finishColorAlpha = (float)dict->numberForKey("finishColorAlpha");
        type->finishColorVarianceRed = (float)dict->numberForKey("finishColorVarianceRed");
        type->finishColorVarianceGreen = (float)dict->numberForKey("finishColorVarianceGreen");
        type->finishColorVarianceBlue = (float)dict->numberForKey("finishColorVarianceBlue");
        type->finishColorVarianceAlpha = (float)dict->numberForKey("finishColorVarianceAlpha");
        type->startParticleSize = (float)dict->numberForKey("startParticleSize");
        type->startParticleSizeVariance = (float)dict->numberForKey("startParticleSizeVariance");
        type->finishParticleSize = (float)dict->numberForKey("finishParticleSize");
        type->finishParticleSizeVariance = (float)dict->numberForKey("finishParticleSizeVariance");
        type->sourcePositionx = (float)dict->numberForKey("sourcePositionx");
        type->sourcePositiony = (float)dict->numberForKey("sourcePositiony");
        type->sourcePositionVariancex = (float)dict->numberForKey("sourcePositionVariancex");
        type->sourcePositionVariancey = (float)dict->numberForKey("sourcePositionVariancey");
        type->rotationStart = (float)dict->numberForKey("rotationStart");
        type->rotationStartVariance = (float)dict->numberForKey("rotationStartVariance");
        type->rotationEnd = (float)dict->numberForKey("rotationEnd");
        type->rotationEndVariance = (float)dict->numberForKey("rotationEndVariance");
        type->emissionRate = (float)dict->numberForKey("emissionRate");
        type->emitterType = (int)dict->numberForKey("emitterType");
        type->gravityx = (float)dict->numberForKey("gravityx");
        type->gravityy = (float)dict->numberForKey("gravityy");
        type->speed = (float)dict->numberForKey("speed");
        type->speedVariance = (float)dict->numberForKey("speedVariance");
        type->radialAcceleration = (float)dict->numberForKey("radialAcceleration");
        type->radialAccelVariance = (float)dict->numberForKey("radialAccelVariance");
        type->tangentialAcceleration = (float)dict->numberForKey("tangentialAcceleration");
        type->tangentialAccelVariance = (float)dict->numberForKey("tangentialAccelVariance");
        type->rotationIsDir = dict->numberForKey("rotationIsDir") != 0;
        type->maxRadius = (float)dict->numberForKey("maxRadius");
        type->maxRadiusVariance = (float)dict->numberForKey("maxRadiusVariance");
        type->minRadius = (float)dict->numberForKey("minRadius");
        type->minRadiusVariance = (float)dict->numberForKey("minRadiusVariance");
        type->rotatePerSecond = (float)dict->numberForKey("rotatePerSecond");
        type->rotatePerSecondVariance = (float)dict->numberForKey("rotatePerSecondVariance");
        type->particleLifespan = (float)dict->numberForKey("particleLifespan");
        type->particleLifespanVariance = (float)dict->numberForKey("particleLifespanVariance");
        type->emissionRate = (float)(type->maxParticles) / type->particleLifespan;
        type->textureFileName = dict->stringForKey("textureFileName");
        const char* textureData = dict->stringForKey("textureImageData");
        if (textureData[0])
        {
            CCParticleSystem::dataToTexture(type->textureFileName.c_str(), textureData);
        }
        float textureRectx = (float)dict->numberForKey("textureRectx");
        float textureRecty = (float)dict->numberForKey("textureRecty");
        float textureRectw = (float)dict->numberForKey("textureRectw");
        float textureRecth = (float)dict->numberForKey("textureRecth");
        CCRect textureRect(textureRectx, textureRecty, textureRectw, textureRecth);
        type->textureRect = textureRect;
        _parDict[filename] = type;
        return type;
    }
}
Beispiel #22
0
void
TiledContentHost::RenderTile(TileHost& aTile,
                             EffectChain& aEffectChain,
                             float aOpacity,
                             const gfx::Matrix4x4& aTransform,
                             const gfx::Filter& aFilter,
                             const gfx::Rect& aClipRect,
                             const nsIntRegion& aScreenRegion,
                             const IntPoint& aTextureOffset,
                             const IntSize& aTextureBounds,
                             const gfx::Rect& aVisibleRect)
{
  MOZ_ASSERT(!aTile.IsPlaceholderTile());

  AutoLockTextureHost autoLock(aTile.mTextureHost);
  AutoLockTextureHost autoLockOnWhite(aTile.mTextureHostOnWhite);
  if (autoLock.Failed() ||
      autoLockOnWhite.Failed()) {
    NS_WARNING("Failed to lock tile");
    return;
  }

  if (!aTile.mTextureHost->BindTextureSource(aTile.mTextureSource)) {
    return;
  }

  if (aTile.mTextureHostOnWhite && !aTile.mTextureHostOnWhite->BindTextureSource(aTile.mTextureSourceOnWhite)) {
    return;
  }

  RefPtr<TexturedEffect> effect =
    CreateTexturedEffect(aTile.mTextureSource,
                         aTile.mTextureSourceOnWhite,
                         aFilter,
                         true,
                         aTile.mTextureHost->GetRenderState());
  if (!effect) {
    return;
  }

  aEffectChain.mPrimaryEffect = effect;

  nsIntRegionRectIterator it(aScreenRegion);
  for (const IntRect* rect = it.Next(); rect != nullptr; rect = it.Next()) {
    Rect graphicsRect(rect->x, rect->y, rect->width, rect->height);
    Rect textureRect(rect->x - aTextureOffset.x, rect->y - aTextureOffset.y,
                     rect->width, rect->height);

    effect->mTextureCoords = Rect(textureRect.x / aTextureBounds.width,
                                  textureRect.y / aTextureBounds.height,
                                  textureRect.width / aTextureBounds.width,
                                  textureRect.height / aTextureBounds.height);
    mCompositor->DrawQuad(graphicsRect, aClipRect, aEffectChain, aOpacity, aTransform, aVisibleRect);
  }
  DiagnosticFlags flags = DiagnosticFlags::CONTENT | DiagnosticFlags::TILE;
  if (aTile.mTextureHostOnWhite) {
    flags |= DiagnosticFlags::COMPONENT_ALPHA;
  }
  mCompositor->DrawDiagnostics(flags,
                               aScreenRegion, aClipRect, aTransform, mFlashCounter);
}
Beispiel #23
0
void AFP::MapParser::addBackgroundLayers(std::vector <SceneNode*>& sceneLayers,
        SceneNode& spriteGraph, const sf::FloatRect worldBounds)
{
    /// Initialize the different tiling backround layers
    for (int i = 0; i < mMap.GetNumImageLayers(); ++i)
    {
        SceneNode::Ptr layer(new SceneNode(Category::None));
        sceneLayers.push_back(layer.get());

        /// Add background layers to spritegraph
        spriteGraph.attachChild(std::move(layer));

        const Tmx::ImageLayer* imageLayer = mMap.GetImageLayer(i);
        const Tmx::PropertySet layerProperties = imageLayer->GetProperties();

        if (layerProperties.HasProperty("repeat") &&
            layerProperties.GetLiteralProperty("repeat") == "true")
        {
            /// Set backround texture to be tiled
            sf::Texture& texture = mTextures.get(imageLayer->GetName());
            sf::IntRect textureRect(worldBounds);
            texture.setRepeated(true);

            /// Make the texture as big as the world bounds
            std::unique_ptr<SpriteNode> backgroundSprite(
                    new SpriteNode(texture, textureRect));

            backgroundSprite->setPosition(
                    worldBounds.left,
                    worldBounds.top);
            sceneLayers.back()->attachChild(std::move(backgroundSprite));

        }
        else if (layerProperties.HasProperty("repeatVertical") &&
                layerProperties.GetLiteralProperty("repeatVertical") == "true")
        {
            /// Tile texture vertically
            sf::Texture& texture = mTextures.get(imageLayer->GetName());
            sf::IntRect textureRect(0.f, 0.f, worldBounds.width,
                    texture.getSize().y);
            texture.setRepeated(true);

            std::unique_ptr<SpriteNode> backgroundSprite(
                    new SpriteNode(texture, textureRect));

            if (!layerProperties.HasProperty("height"))
            {
                throw std::runtime_error("World::buildScene(): Missing property"
                        " height from vertical image layer!");

            }

            /// Set tiled image to the correct height. In tiled the height is
            /// set as the number of pixels from the bottom
            int height = layerProperties.GetNumericProperty("height");

            backgroundSprite->setPosition(
                    worldBounds.left,
                    mMap.GetHeight() * mMap.GetTileHeight() - height -
                    texture.getSize().y);
            sceneLayers.back()->attachChild(std::move(backgroundSprite));

        }

    }

}
void
TiledContentHost::RenderTile(const TileHost& aTile,
                             const gfxRGBA* aBackgroundColor,
                             EffectChain& aEffectChain,
                             float aOpacity,
                             const gfx::Matrix4x4& aTransform,
                             const gfx::Filter& aFilter,
                             const gfx::Rect& aClipRect,
                             const nsIntRegion& aScreenRegion,
                             const nsIntPoint& aTextureOffset,
                             const nsIntSize& aTextureBounds)
{
  if (aTile.IsPlaceholderTile()) {
    // This shouldn't ever happen, but let's fail semi-gracefully. No need
    // to warn, the texture update would have already caught this.
    return;
  }

  if (aBackgroundColor) {
    aEffectChain.mPrimaryEffect = new EffectSolidColor(ToColor(*aBackgroundColor));
    nsIntRegionRectIterator it(aScreenRegion);
    for (const nsIntRect* rect = it.Next(); rect != nullptr; rect = it.Next()) {
      Rect graphicsRect(rect->x, rect->y, rect->width, rect->height);
      mCompositor->DrawQuad(graphicsRect, aClipRect, aEffectChain, 1.0, aTransform);
    }
  }

  AutoLockTextureHost autoLock(aTile.mTextureHost);
  AutoLockTextureHost autoLockOnWhite(aTile.mTextureHostOnWhite);
  if (autoLock.Failed() ||
      autoLockOnWhite.Failed()) {
    NS_WARNING("Failed to lock tile");
    return;
  }
  RefPtr<TextureSource> source = aTile.mTextureHost->GetTextureSources();
  RefPtr<TextureSource> sourceOnWhite =
    aTile.mTextureHostOnWhite ? aTile.mTextureHostOnWhite->GetTextureSources() : nullptr;
  if (!source || (aTile.mTextureHostOnWhite && !sourceOnWhite)) {
    return;
  }

  RefPtr<TexturedEffect> effect = CreateTexturedEffect(source, sourceOnWhite, aFilter, true);
  if (!effect) {
    return;
  }

  aEffectChain.mPrimaryEffect = effect;

  nsIntRegionRectIterator it(aScreenRegion);
  for (const nsIntRect* rect = it.Next(); rect != nullptr; rect = it.Next()) {
    Rect graphicsRect(rect->x, rect->y, rect->width, rect->height);
    Rect textureRect(rect->x - aTextureOffset.x, rect->y - aTextureOffset.y,
                     rect->width, rect->height);

    effect->mTextureCoords = Rect(textureRect.x / aTextureBounds.width,
                                  textureRect.y / aTextureBounds.height,
                                  textureRect.width / aTextureBounds.width,
                                  textureRect.height / aTextureBounds.height);
    mCompositor->DrawQuad(graphicsRect, aClipRect, aEffectChain, aOpacity, aTransform);
  }
  mCompositor->DrawDiagnostics(DiagnosticFlags::CONTENT | DiagnosticFlags::TILE,
                               aScreenRegion, aClipRect, aTransform, mFlashCounter);
}
void Button::changeTexture(Type buttonType)
{
	sf::IntRect textureRect(0, 50*buttonType, 200, 50);
	mSprite.setTextureRect(textureRect);
}
    void Mem2Native::updateTexture()
    {
        int SIZE = _size;
        if (!SIZE)
            SIZE = RECT_SIZE;

        MemoryTexture* src = _opt->src.get();
        NativeTexture* dest = _opt->dest.get();
        Point& prev = _prev;

        bool done = false;

        if (isCompressedFormat(src->getFormat()))
        {
            dest->init(src->lock(), false);
            done = true;
        }
        else
        {

            Rect textureRect(0, 0, src->getWidth(), src->getHeight());

            if (dest->getHandle() == 0)
                dest->init(textureRect.getWidth(), textureRect.getHeight(), src->getFormat());


            Rect srcRect(prev.x, prev.y,
                         std::min(SIZE, textureRect.getWidth()), std::min(SIZE, textureRect.getHeight()));
            srcRect.clip(textureRect);


            ImageData srcim = src->lock(&srcRect);


            ImageData destim;
            if (srcRect != textureRect)
            {
                int pitch = srcRect.getWidth() * getBytesPerPixel(dest->getFormat());
                _buffer.resize(srcRect.getHeight() * pitch);
                destim = ImageData(
                             srcRect.getWidth(), srcRect.getHeight(),
                             pitch,
                             dest->getFormat(),
                             &_buffer[0]
                         );

                operations::copy(srcim, destim);
            }
            else
            {
                destim = srcim;
            }

            dest->updateRegion(srcRect.pos.x, srcRect.pos.y, destim);

            prev.x += SIZE;
            if (prev.x >= textureRect.getWidth())
            {
                prev.x = 0;
                prev.y += SIZE;
            }

            if (prev.y >= textureRect.getBottom())
            {
                _buffer.clear();
                prev = Point(0, 0);
                done = true;
            }
        }

        if (done)
        {
            textureDone();
        }
    }
Beispiel #27
0
void Button::ChangeTexture(Button::Type_t type)
{
	sf::IntRect textureRect(0, 50 * type, 200, 50);
	m_sprite.setTextureRect(textureRect);
}
Beispiel #28
0
	void Button::changeTexture(Type buttonType)
	{
		sf::IntRect textureRect(0, 50 * buttonType, 150, 50);
		sprite_.setTextureRect(textureRect);
	}
Beispiel #29
0
void KisOpenGLCanvas2::drawImage()
{
    if (!d->displayShader) {
        return;
    }

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    KisCoordinatesConverter *converter = coordinatesConverter();

    d->displayShader->bind();

    QMatrix4x4 projectionMatrix;
    projectionMatrix.setToIdentity();
    projectionMatrix.ortho(0, width(), height(), 0, NEAR_VAL, FAR_VAL);

    // Set view/projection matrices
    QMatrix4x4 modelMatrix(coordinatesConverter()->imageToWidgetTransform());
    modelMatrix.optimize();
    modelMatrix = projectionMatrix * modelMatrix;
    d->displayShader->setUniformValue(d->displayShader->location(Uniform::ModelViewProjection), modelMatrix);

    QMatrix4x4 textureMatrix;
    textureMatrix.setToIdentity();
    d->displayShader->setUniformValue(d->displayShader->location(Uniform::TextureMatrix), textureMatrix);

    QRectF widgetRect(0,0, width(), height());
    QRectF widgetRectInImagePixels = converter->documentToImage(converter->widgetToDocument(widgetRect));

    qreal scaleX, scaleY;
    converter->imageScale(&scaleX, &scaleY);
    d->displayShader->setUniformValue(d->displayShader->location(Uniform::ViewportScale), (GLfloat) scaleX);
    d->displayShader->setUniformValue(d->displayShader->location(Uniform::TexelSize), (GLfloat) d->openGLImageTextures->texelSize());

    QRect ir = d->openGLImageTextures->storedImageBounds();
    QRect wr = widgetRectInImagePixels.toAlignedRect();

    if (!d->wrapAroundMode) {
        // if we don't want to paint wrapping images, just limit the
        // processing area, and the code will handle all the rest
        wr &= ir;
    }

    int firstColumn = d->xToColWithWrapCompensation(wr.left(), ir);
    int lastColumn = d->xToColWithWrapCompensation(wr.right(), ir);
    int firstRow = d->yToRowWithWrapCompensation(wr.top(), ir);
    int lastRow = d->yToRowWithWrapCompensation(wr.bottom(), ir);

    int minColumn = d->openGLImageTextures->xToCol(ir.left());
    int maxColumn = d->openGLImageTextures->xToCol(ir.right());
    int minRow = d->openGLImageTextures->yToRow(ir.top());
    int maxRow = d->openGLImageTextures->yToRow(ir.bottom());

    int imageColumns = maxColumn - minColumn + 1;
    int imageRows = maxRow - minRow + 1;

    for (int col = firstColumn; col <= lastColumn; col++) {
        for (int row = firstRow; row <= lastRow; row++) {

            int effectiveCol = col;
            int effectiveRow = row;
            QPointF tileWrappingTranslation;

            if (effectiveCol > maxColumn || effectiveCol < minColumn) {
                int translationStep = floor(qreal(col) / imageColumns);
                int originCol = translationStep * imageColumns;
                effectiveCol = col - originCol;
                tileWrappingTranslation.rx() = translationStep * ir.width();
            }

            if (effectiveRow > maxRow || effectiveRow < minRow) {
                int translationStep = floor(qreal(row) / imageRows);
                int originRow = translationStep * imageRows;
                effectiveRow = row - originRow;
                tileWrappingTranslation.ry() = translationStep * ir.height();
            }

            KisTextureTile *tile =
                    d->openGLImageTextures->getTextureTileCR(effectiveCol, effectiveRow);

            if (!tile) {
                warnUI << "OpenGL: Trying to paint texture tile but it has not been created yet.";
                continue;
            }

            /*
             * We create a float rect here to workaround Qt's
             * "history reasons" in calculation of right()
             * and bottom() coordinates of integer rects.
             */
            QRectF textureRect(tile->tileRectInTexturePixels());
            QRectF modelRect(tile->tileRectInImagePixels().translated(tileWrappingTranslation.x(), tileWrappingTranslation.y()));

            //Setup the geometry for rendering
            if (KisOpenGL::hasOpenGL3()) {
                rectToVertices(d->vertices, modelRect);

                d->quadBuffers[0].bind();
                d->quadBuffers[0].write(0, d->vertices, 3 * 6 * sizeof(float));

                rectToTexCoords(d->texCoords, textureRect);
                d->quadBuffers[1].bind();
                d->quadBuffers[1].write(0, d->texCoords, 2 * 6 * sizeof(float));
            }
            else {
                rectToVertices(d->vertices, modelRect);
                d->displayShader->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE);
                d->displayShader->setAttributeArray(PROGRAM_VERTEX_ATTRIBUTE, d->vertices);

                rectToTexCoords(d->texCoords, textureRect);
                d->displayShader->enableAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE);
                d->displayShader->setAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE, d->texCoords);
            }

            if (d->displayFilter) {
                glActiveTexture(GL_TEXTURE0 + 1);
                glBindTexture(GL_TEXTURE_3D, d->displayFilter->lutTexture());
                d->displayShader->setUniformValue(d->displayShader->location(Uniform::Texture1), 1);
            }

            int currentLodPlane = tile->currentLodPlane();
            if (d->displayShader->location(Uniform::FixedLodLevel) >= 0) {
                d->displayShader->setUniformValue(d->displayShader->location(Uniform::FixedLodLevel),
                                                  (GLfloat) currentLodPlane);
            }

            glActiveTexture(GL_TEXTURE0);
            tile->bindToActiveTexture();

            if (currentLodPlane > 0) {
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
            } else if (SCALE_MORE_OR_EQUAL_TO(scaleX, scaleY, 2.0)) {
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            } else {
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

                switch(d->filterMode) {
                case KisOpenGL::NearestFilterMode:
                    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
                    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
                    break;
                case KisOpenGL::BilinearFilterMode:
                    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                    break;
                case KisOpenGL::TrilinearFilterMode:
                    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
                    break;
                case KisOpenGL::HighQualityFiltering:
                    if (SCALE_LESS_THAN(scaleX, scaleY, 0.5)) {
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
                    } else {
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                    }
                    break;
                }
            }

            glDrawArrays(GL_TRIANGLES, 0, 6);
        }
    }

    glBindTexture(GL_TEXTURE_2D, 0);
    d->displayShader->release();
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}
Beispiel #30
0
 void Button::changeTexture(Type buttonType)
 {
     sf::IntRect textureRect(0, mButtonHeight*buttonType, mButtonWidth, mButtonHeight);
     mSprite.setTextureRect(textureRect);
 }