Esempio n. 1
0
void EaseSpriteDemo::onEnter()
{
	CCLayer::onEnter();

	// Example:
	// You can create a sprite using a Texture2D
	CCTexture2D* tex = new CCTexture2D();
	UIImage* pImage = new UIImage();
	
	if(pImage->initWithContentsOfFile(CCFileUtils::fullPathFromRelativePath(s_pPathGrossini)))
	{
		tex->initWithImage(pImage);
		m_grossini = CCSprite::spriteWithTexture(tex); 
		m_grossini->retain();

	}

	tex->release();
	delete pImage;
	
	// Example:
	// Or you can create an sprite using a filename. PNG and BMP files are supported. Probably TIFF too
	m_tamara = CCSprite::spriteWithFile(s_pPathSister1); m_tamara->retain();
	m_kathia = CCSprite::spriteWithFile(s_pPathSister2); m_kathia->retain();
	
	addChild( m_grossini, 3);
	addChild( m_kathia, 2);
	addChild( m_tamara, 1);

	CGSize s = CCDirector::sharedDirector()->getWinSize();

	m_grossini->setPosition( CGPointMake(60, 50) );
	m_kathia->setPosition( CGPointMake(60, 150) );
	m_tamara->setPosition( CGPointMake(60, 250) );

	CCLabelTTF* label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 32);
	addChild(label);
	label->setPosition( CGPointMake(s.width/2, s.height-50) );

	CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(EaseSpriteDemo::backCallback) );
	CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(EaseSpriteDemo::restartCallback) );
	CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(EaseSpriteDemo::nextCallback) );

	CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);

	menu->setPosition( CGPointZero );
	item1->setPosition( CGPointMake( s.width/2 - 100,30) );
	item2->setPosition( CGPointMake( s.width/2, 30) );
	item3->setPosition( CGPointMake( s.width/2 + 100,30) );
	
	addChild(menu, 1);	
}
Esempio n. 2
0
	virtual void callback(UIBase *base)
	{
		if (dialog && window)
		{
			// 创建图片
			UIPanel *panel = window->getNowTouchPanel();
			if (panel)
			{
				UIImage *image = (UIImage*) panel->createImage(ccp(0,300),CCSizeMake(0,0),"defaultimg.png",panel);
				if (image)
				{
					image->setEditable(true);
					image->bind(UIBase::EVENT_EDIT_DOWN,new stShowProp());
				}
			}
		}
	}
Esempio n. 3
0
void UIDirect3D9Window::DrawShape(UIEffect *Effect, QRectF *Dest, bool &PositionChanged, UIShapePath *Path)
{
    if (!Dest || !Path)
        return;

    UIImage* image = GetShapeImage(Path, Dest);

    if (!image)
        return;

    if (image->GetState() == UIImage::ImageLoading)
        return;

    PositionChanged |= Path->IsShared();

    DrawImage(Effect, Dest, PositionChanged, image);
}
FindBar::FindBar() : UIElement() {
	barBg = new UIRect(30,30);
	barBg->setAnchorPoint(-1.0, -1.0, 0.0);
	barBg->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiHeaderBgColor"));
	addChild(barBg);
	setHeight(30);
	
	UILabel *findLabel = new UILabel("FIND", 18, "section");
	addChild(findLabel);
	findLabel->setColor(1.0, 1.0, 1.0, 0.6);
	findLabel->setPosition(10,3);

	UILabel *replaceLabel = new UILabel("REPLACE", 18, "section");
	addChild(replaceLabel);
	replaceLabel->setColor(1.0, 1.0, 1.0, 0.6);
	replaceLabel->setPosition(200,3);
	
	processInputEvents = true;
	
	findInput = new UITextInput(false, 120, 12);
	addFocusChild(findInput);
	findInput->setPosition(60, 4);

	replaceInput = new UITextInput(false, 120, 12);
	addFocusChild(replaceInput);
	replaceInput->setPosition(280, 4);
	
	replaceAllButton = new UIButton("Replace All", 100);
	addFocusChild(replaceAllButton);
	replaceAllButton->setPosition(420, 3);

	UIImage *functionIcon = new UIImage("main/function_icon.png", 11, 17);
	addChild(functionIcon);
	functionIcon->setPosition(540, 6);
	
	functionList = new UIComboBox(globalMenu, 200);
	addChild(functionList);
	functionList->setPosition(560, 4);	
		
	closeButton = new UIImageButton("main/barClose.png", 1.0, 17, 17);
	addChild(closeButton);
}
Esempio n. 5
0
bool CCParticleSystem::initWithDictionary(NSDictionary<std::string, NSObject*> *dictionary)
{
	bool bRet = false;
	unsigned char *buffer = NULL;
	unsigned char *deflated = NULL;
	UIImage *image = NULL;
	do 
	{
		int maxParticles = atoi(valueForKey("maxParticles", dictionary));
		// self, not super
		if(this->initWithTotalParticles(maxParticles))
		{
			// angle
			m_fAngle = (float)atof(valueForKey("angle", dictionary));
			m_fAngleVar = (float)atof(valueForKey("angleVariance", dictionary));

			// duration
			m_fDuration = (float)atof(valueForKey("duration", dictionary));

			// blend function 
			m_tBlendFunc.src = atoi(valueForKey("blendFuncSource", dictionary));
			m_tBlendFunc.dst = atoi(valueForKey("blendFuncDestination", dictionary));

			// color
			m_tStartColor.r = (float)atof(valueForKey("startColorRed", dictionary));
			m_tStartColor.g = (float)atof(valueForKey("startColorGreen", dictionary));
			m_tStartColor.b = (float)atof(valueForKey("startColorBlue", dictionary));
			m_tStartColor.a = (float)atof(valueForKey("startColorAlpha", dictionary));

			m_tStartColorVar.r = (float)atof(valueForKey("startColorVarianceRed", dictionary));
			m_tStartColorVar.g = (float)atof(valueForKey("startColorVarianceGreen", dictionary));
			m_tStartColorVar.b = (float)atof(valueForKey("startColorVarianceBlue", dictionary));
			m_tStartColorVar.a = (float)atof(valueForKey("startColorVarianceAlpha", dictionary));

			m_tEndColor.r = (float)atof(valueForKey("finishColorRed", dictionary));
			m_tEndColor.g = (float)atof(valueForKey("finishColorGreen", dictionary));
			m_tEndColor.b = (float)atof(valueForKey("finishColorBlue", dictionary));
			m_tEndColor.a = (float)atof(valueForKey("finishColorAlpha", dictionary));

			m_tEndColorVar.r = (float)atof(valueForKey("finishColorVarianceRed", dictionary));
			m_tEndColorVar.g = (float)atof(valueForKey("finishColorVarianceGreen", dictionary));
			m_tEndColorVar.b = (float)atof(valueForKey("finishColorVarianceBlue", dictionary));
			m_tEndColorVar.a = (float)atof(valueForKey("finishColorVarianceAlpha", dictionary));

			// particle size
			m_fStartSize = (float)atof(valueForKey("startParticleSize", dictionary));
			m_fStartSizeVar = (float)atof(valueForKey("startParticleSizeVariance", dictionary));
			m_fEndSize = (float)atof(valueForKey("finishParticleSize", dictionary));
			m_fEndSizeVar = (float)atof(valueForKey("finishParticleSizeVariance", dictionary));

			// position
			m_tPosition.x = (float)atof(valueForKey("sourcePositionx", dictionary));
			m_tPosition.y = (float)atof(valueForKey("sourcePositiony", dictionary));
			m_tPosVar.x = (float)atof(valueForKey("sourcePositionVariancex", dictionary));
			m_tPosVar.y = (float)atof(valueForKey("sourcePositionVariancey", dictionary));

			m_nEmitterMode = atoi(valueForKey("emitterType", dictionary));

			// Mode A: Gravity + tangential accel + radial accel
			if( m_nEmitterMode == kCCParticleModeGravity ) 
			{
				// gravity
				modeA.gravity.x = (float)atof(valueForKey("gravityx", dictionary));
				modeA.gravity.y = (float)atof(valueForKey("gravityy", dictionary));

				// speed
				modeA.speed = (float)atof(valueForKey("speed", dictionary));
				modeA.speedVar = (float)atof(valueForKey("speedVariance", dictionary));

                const char * pszTmp = NULL;
				// radial acceleration
                pszTmp = valueForKey("radialAcceleration", dictionary);
                modeA.radialAccel = (pszTmp) ? (float)atof(pszTmp) : 0;

                pszTmp = valueForKey("radialAccelVariance", dictionary);
				modeA.radialAccelVar = (pszTmp) ? (float)atof(pszTmp) : 0;

				// tangential acceleration
                pszTmp = valueForKey("tangentialAcceleration", dictionary);
				modeA.tangentialAccel = (pszTmp) ? (float)atof(pszTmp) : 0;

                pszTmp = valueForKey("tangentialAccelVariance", dictionary);
				modeA.tangentialAccelVar = (pszTmp) ? (float)atof(pszTmp) : 0;
			}

			// or Mode B: radius movement
			else if( m_nEmitterMode == kCCParticleModeRadius ) 
			{
				modeB.startRadius = (float)atof(valueForKey("maxRadius", dictionary));
				modeB.startRadiusVar = (float)atof(valueForKey("maxRadiusVariance", dictionary));
				modeB.endRadius = (float)atof(valueForKey("minRadius", dictionary));
				modeB.endRadiusVar = 0;
				modeB.rotatePerSecond = (float)atof(valueForKey("rotatePerSecond", dictionary));
				modeB.rotatePerSecondVar = (float)atof(valueForKey("rotatePerSecondVariance", dictionary));

			} else {
				NSAssert( false, "Invalid emitterType in config file");
				CCX_BREAK_IF(true);
			}

			// life span
			m_fLife = (float)atof(valueForKey("particleLifespan", dictionary));
			m_fLifeVar = (float)atof(valueForKey("particleLifespanVariance", dictionary));

			// emission Rate
			m_fEmissionRate = m_nTotalParticles / m_fLife;

			// texture		
			// Try to get the texture from the cache
			char *textureName = (char *)valueForKey("textureFileName", dictionary);
            std::string fullpath = CCFileUtils::fullPathFromRelativeFile(textureName, m_sPlistFile.c_str());

            if (strlen(textureName) > 0)
            {
                // set not pop-up message box when load image failed
                bool bNotify = UIImage::getIsPopupNotify();
                UIImage::setIsPopupNotify(false);
                this->m_pTexture = CCTextureCache::sharedTextureCache()->addImage(fullpath.c_str());

                // reset the value of UIImage notify
                UIImage::setIsPopupNotify(bNotify);
            }

			// if it fails, try to get it from the base64-gzipped data			
            char *textureData = NULL;
			if ( ! m_pTexture && 
                (textureData = (char *)valueForKey("textureImageData", dictionary)))
			{
				int dataLen = strlen(textureData);
				if(dataLen != 0)
				{
					int decodeLen = base64Decode((unsigned char*)textureData, dataLen, &buffer);
					NSAssert( buffer != NULL, "CCParticleSystem: error decoding textureImageData");
					CCX_BREAK_IF(!buffer);

						int deflatedLen = ZipUtils::ccInflateMemory(buffer, decodeLen, &deflated);
						NSAssert( deflated != NULL, "CCParticleSystem: error ungzipping textureImageData");
						CCX_BREAK_IF(!deflated);
						
						image = new UIImage();
						bool isOK = image->initWithData(deflated, deflatedLen);
						NSAssert(isOK, "CCParticleSystem: error init image with Data");
						CCX_BREAK_IF(!isOK);
						
						m_pTexture = CCTextureCache::sharedTextureCache()->addUIImage(image, fullpath.c_str());
				}
			}
			NSAssert( this->m_pTexture != NULL, "CCParticleSystem: error loading the texture");
			
			CCX_BREAK_IF(!m_pTexture);
			this->m_pTexture->retain();
			bRet = true;
		}
	} while (0);
	CCX_SAFE_DELETE_ARRAY(buffer);
    CCX_SAFE_DELETE_ARRAY(deflated);
	CCX_SAFE_DELETE(image);
	return bRet;
}
Esempio n. 6
0
void Game::startIntroCutscene() {
	gfx->recomputeBackground();
	gfx->getUI()->darkenScreen(1.f);
	if(introCutscene) gfx->deleteSceneNode(introCutscene);
	introCutscene = new UICutscene(gfx);

	vector2 wparams = gfx->getRenderer()->getWindowParams();
	vector2 center = wparams*0.5f;

	/*** FRAME 0 ***/
	introCutscene->startFrame(3.f);

	UILabel* text = new UILabel(gfx);
	text->setColor(color(0.7f, 0.7f, 0.7f, 0.f));
	text->setText("powered by", 0, 32.f);
	text->setPosition(center+vector2(-150.f, 100.f));
//	text->fadeOut();

	UIImage* gllogo = new UIImage(gfx);
	gllogo->setImage("LOGOS");
	gllogo->setPosition(vector2(center[0]-100.f, center[1]-gllogo->getSize()[1]+100.f));
//	gllogo->fadeOut();
	introCutscene->addWidgetToFrame(text);
	introCutscene->addWidgetToFrame(gllogo);

	introCutscene->endFrame();

	/*** FRAME 1 ***/

	introCutscene->startFrame(6.f);

	text = new UILabel(gfx);
	text->setColor(color(0.7f, 0.7f, 0.7f, 0.f));
//	text->setText("Copyright 2010 Alexander Dzhoganov", 0, 32.f);
	text->setText(GNU_COPYRIGHT_NOTICE, 0, 20.f);
	text->setPosition(vector2(center[0]-400.f, center[1]));
	text->fadeOut();
	introCutscene->addWidgetToFrame(text);

	UILabel* skiplabel = new UILabel(gfx);
	skiplabel->setColor(color(0.4f, 0.4f, 0.4f, 0.f));
	skiplabel->setText("press  [space ] to skip intro", 0, 16.f);
	skiplabel->setPosition(vector2(wparams[0]-320.f, 50.f));

	introCutscene->addWidgetToFrame(skiplabel);

	introCutscene->endFrame();

	/*** FRAME 2 ***/

	introCutscene->startFrame(3.f);

	text = new UILabel(gfx);
	text->setColor(color(0.7f, 0.7f, 0.7f, 0.f));
	text->setText("a game by Alexander Dzhoganov", 0, 32.f);
	text->setPosition(center);
	text->fadeOut();
	introCutscene->addWidgetToFrame(text);

	introCutscene->endFrame();

	/*** FRAME 3 ***/

	introCutscene->startFrame(3.f);

	text = new UILabel(gfx);
	text->setColor(color(0.7f, 0.7f, 0.7f, 0.f));
	text->setText("programming by:\nAlexander Dzhoganov\n\nart by:\nViktor Popov", 0, 32.f);
	text->setPosition(center);
	text->fadeOut();
	introCutscene->addWidgetToFrame(text);

	introCutscene->endFrame();


	gfx->getUI()->addWidget(introCutscene);
}
Esempio n. 7
0
UIImage* UIDirect3D9Window::DrawText(UIEffect *Effect, QRectF *Dest, bool &PositionChanged, const QString &Text, UIFont *Font, int Flags, int Blur, UIImage *Fallback)
{
    if (!Font->GetImageReady())
    {
        // font is image backed
        QString file = Font->GetImageFileName();
        UIImage *image = Font->GetImage();

        // allocate an image
        if (!image)
        {
            QString name = Font->GetHash() + file;
            QSize size(Dest->size().width(), Dest->size().height());
            image = AllocateImage(name, size, file);
            Font->SetImage(image);
        }

        if (!image)
        {
            LOG(VB_GENERAL, LOG_ERR, QString("Failed to load '%1' text image.")
                    .arg(file));
            // don't try again
            Font->SetImageReady(true);
            return NULL;
        }

        UIImage::ImageState state = image->GetState();

        if (state == UIImage::ImageUploadedToGPU ||
            state == UIImage::ImageReleasedFromGPU)
        {
            LOG(VB_GENERAL, LOG_ERR, "Font image cannot be unloaded from memory");
            Font->SetImageReady(true);
            return NULL;
        }

        if (state == UIImage::ImageLoading)
            return NULL;

        // trigger loading
        if (state == UIImage::ImageNull)
        {
            LoadImageFromFile(image);
            return NULL;
        }

        // update the font's brush
        Font->UpdateTexture();
    }

    UIImage* image = GetSimpleTextImage(Text, Dest, Font, Flags, Blur);

    if (!image)
        return NULL;

    if ((image->GetState() == UIImage::ImageLoading) && Fallback)
        image = Fallback;

    DrawImage(Effect, Dest, PositionChanged, image);

    return image;
}
Esempio n. 8
0
void ActionsDemo::onEnter()
{
    CCLayer::onEnter();

    // Example:
    // You can create a sprite using a Texture2D
    CCTexture2D *tex = new CCTexture2D();
    UIImage* pImage = new UIImage();
    std::string fullpath( CCFileUtils::fullPathFromRelativePath(s_pPathGrossini));
    pImage->initWithContentsOfFile(fullpath);
    tex->initWithImage( pImage );
    m_grossini = CCSprite::spriteWithTexture(tex);
    m_grossini->retain();
    delete pImage;
    tex->release();

    // Example:
    // Or you can create an sprite using a filename. only PNG is supported now. Probably TIFF too
    m_tamara = CCSprite::spriteWithFile(s_pPathSister1);
    m_tamara->retain();

    m_kathia = CCSprite::spriteWithFile(s_pPathSister2);
    m_kathia->retain();

    addChild(m_grossini, 1);
    addChild(m_tamara, 2);
    addChild(m_kathia, 3);

    CGSize s = CCDirector::sharedDirector()->getWinSize();

    m_grossini->setPosition( CGPointMake(s.width/2, s.height/3));
    m_tamara->setPosition( CGPointMake(s.width/2, 2*s.height/3));
    m_kathia->setPosition( CGPointMake(s.width/2, s.height/2));

    // add title and subtitle
    std::string str = title();
    const char * pTitle = str.c_str();
    CCLabelTTF* label = CCLabelTTF::labelWithString(pTitle, "Arial", 18);
    addChild(label, 1);
    label->setPosition( CGPointMake(s.width/2, s.height - 30) );

    std::string strSubtitle = subtitle();
    if( ! strSubtitle.empty() )
    {
        CCLabelTTF* l = CCLabelTTF::labelWithString(strSubtitle.c_str(), "Thonburi", 22);
        addChild(l, 1);
        l->setPosition( CGPointMake(s.width/2, s.height - 60) );
    }

    // add menu
    CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(ActionsDemo::backCallback) );
    CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(ActionsDemo::restartCallback) );
    CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(ActionsDemo::nextCallback) );

    CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);

    menu->setPosition( CGPointZero );
    item1->setPosition( CGPointMake( s.width/2 - 100,30) );
    item2->setPosition( CGPointMake( s.width/2, 30) );
    item3->setPosition( CGPointMake( s.width/2 + 100,30) );

    addChild(menu, 1);
}