void BootupAnimation::renderInStateLogo()
{
	if (!m_logoSurf || !m_logoBrightSurf)
		return;

	const int kLowAlpha  = 0x00 - 0x80;
	const int kHighAlpha = 0xFF;

	static int sCurrAlpha = kLowAlpha;
	static int sDelta = 0x08;

	HostBase* host = HostBase::instance();
	const HostInfo& info = host->getInfo();

	int w = (int) (m_logoSurf->width());
	int h = (int) (m_logoSurf->height());

	int dx = (info.displayWidth  - w) / 2;
	int dy = (info.displayHeight - h) / 2;
	int dr = dx + w;
	int db = dy + h;

	m_ctxt->push();

	m_ctxt->setStrokeColor(PColor32(0x00, 0x00, 0x00, 0x00));
	m_ctxt->setFillColor(PColor32(0x00, 0x00, 0x00, 0xFF));
	m_ctxt->drawRect(0, 0, (int) info.displayWidth, (int) info.displayHeight);

	if (m_rotation != 0) {
		m_ctxt->translate((int)info.displayWidth/2, (int) info.displayHeight/2);
		m_ctxt->rotate(m_rotation);
		m_ctxt->translate((int) -info.displayWidth/2, (int) -info.displayHeight/2);
	}

	if (m_logoSurf) {
		m_ctxt->bitblt(m_logoSurf, dx, dy, dr, db);
	}

	if (m_logoBrightSurf) {
		m_ctxt->setFillOpacity(MAX(MIN(sCurrAlpha, 0xFF), 0x00));
		m_ctxt->bitblt(m_logoBrightSurf, dx, dy, dr, db);
	}

	m_ctxt->pop();

	m_ctxt->flip();

	sCurrAlpha += sDelta;
	if (sCurrAlpha <= kLowAlpha) {
		sDelta = 0x0F;
		sCurrAlpha = kLowAlpha;
	}
	else if (sCurrAlpha >= kHighAlpha) {
		sDelta = -0x0F;
		sCurrAlpha = kHighAlpha;
	}
}
void BootupAnimationTransition::init()
{
	HostBase* host = HostBase::instance();
	const HostInfo& info = host->getInfo();
	
	m_bounds = QRect(-info.displayWidth/2, -info.displayHeight/2, info.displayWidth, info.displayHeight);

	std::string imageRootPath = Settings::LunaSettings()->lunaSystemResourcesPath + "/";
	std::string imagePath;

	imagePath = imageRootPath + "hp-logo.png";
	QPixmap logoPixmap(imagePath.c_str());
	if (logoPixmap.isNull())
		g_warning("Failed to load image: %s", imagePath.c_str());
	
	m_screenPixmap = new QPixmap(info.displayWidth, info.displayHeight);

	m_rotation = Settings::LunaSettings()->homeButtonOrientationAngle;
	
	// prepare the full screen pixmap for the animation
	QPainter painter(m_screenPixmap);
	painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
	painter.fillRect(QRect(0, 0, info.displayWidth, info.displayHeight), QColor(0x00, 0x00, 0x00, 0xFF));
	if (m_rotation != 0) {
		painter.translate(info.displayWidth/2, info.displayHeight/2);
		painter.rotate(m_rotation);
		painter.translate(-info.displayWidth/2, -info.displayHeight/2);
	}

	painter.drawPixmap(info.displayWidth/2 - logoPixmap.width()/ 2, info.displayHeight/2 - logoPixmap.height()/ 2, logoPixmap);
	painter.setRenderHint(QPainter::SmoothPixmapTransform, false);
	painter.end();

	m_opacityAnimationPtr = new QPropertyAnimation();
	m_opacityAnimationPtr->setPropertyName("opacity");
	m_opacityAnimationPtr->setEasingCurve(QEasingCurve::Linear);
	m_opacityAnimationPtr->setTargetObject(this);
	m_opacityAnimationPtr->setDuration(kFadeAnimDuration); 
	m_opacityAnimationPtr->setStartValue(1.0);
	m_opacityAnimationPtr->setEndValue(0.0);
	
	m_scaleAnimationPtr   = new QPropertyAnimation();
	m_scaleAnimationPtr->setPropertyName("scale");
	m_scaleAnimationPtr->setEasingCurve(QEasingCurve::Linear);
	m_scaleAnimationPtr->setTargetObject(this);
	m_scaleAnimationPtr->setDuration(kFadeAnimDuration); 
	m_scaleAnimationPtr->setStartValue(1.0);
	m_scaleAnimationPtr->setEndValue(2.0);

	m_fadeAnimationGroupPtr = new QParallelAnimationGroup();
	m_fadeAnimationGroupPtr->addAnimation(m_opacityAnimationPtr);	
	m_fadeAnimationGroupPtr->addAnimation(m_scaleAnimationPtr);
	connect(m_fadeAnimationGroupPtr, SIGNAL(finished()), SLOT(fadeAnimationFinished()));
}
void BootupAnimation::init()
{
	s_frameTime = s_frameTimeSlow;

	HostBase* host = HostBase::instance();
	const HostInfo& info = host->getInfo();

	m_ctxt = PGContext::create();
	m_ctxt->setDisplay(PPrimary, 0, PFORMAT_8888, 3);
	
	// Fill with black
	m_ctxt->push();
	m_ctxt->setStrokeColor(PColor32(0x00, 0x00, 0x00, 0x00));
	m_ctxt->setFillColor(PColor32(0x00, 0x00, 0x00, 0xFF));
	m_ctxt->drawRect(0, 0, (int) info.displayWidth, (int) info.displayHeight);
	m_ctxt->pop();

	std::string imageRootPath = Settings::LunaSettings()->lunaSystemResourcesPath + "/";
	std::string imagePath;

	imagePath = imageRootPath + "hp-logo.png";
	m_logoSurf = PGSurface::createFromPNGFile(imagePath.c_str());
	if (!m_logoSurf)
		g_warning("Failed to load image: %s", imagePath.c_str());

	imagePath = imageRootPath + "hp-logo-bright.png";
	m_logoBrightSurf = PGSurface::createFromPNGFile(imagePath.c_str());
	if (!m_logoBrightSurf)
		g_warning("Failed to load image: %s", imagePath.c_str());

	imagePath = imageRootPath + "activity-static.png";
	m_activityStaticSurf = PGSurface::createFromPNGFile(imagePath.c_str());
	if (!m_activityStaticSurf)
		g_warning("Failed to load image: %s", imagePath.c_str());
	
	imagePath = imageRootPath + "activity-spinner.png";
	m_activitySpinnerSurf = PGSurface::createFromPNGFile(imagePath.c_str());
	if (!m_activitySpinnerSurf)
		g_warning("Failed to load image: %s", imagePath.c_str());

	imagePath = imageRootPath + "activity-progress.png";
	m_activityProgressSurf = PGSurface::createFromPNGFile(imagePath.c_str());
	if (!m_activityProgressSurf)
		g_warning("Failed to load image: %s", imagePath.c_str());

	const char* fontName = Settings::LunaSettings()->fontBootupAnimation.c_str();
	m_font = PGFont::createFromFile(fontName, s_fontHeight1);
	if (!m_font) {
		g_critical("%s: Failed to load font: %s", __PRETTY_FUNCTION__, fontName);
	}

	m_fallbackFonts = new PGFallbackFonts();

	generateUtf16AndGlyphOffsets();

	m_logoScale = 1.0f;
	m_logoAlpha = 0xFF;

	m_activityProgress = 0;
	m_activitySpinner = 0;

	switch (Settings::LunaSettings()->homeButtonOrientationAngle) {
	case 90:
		m_rotation = -90;
		break;
	case -90:
	case 270:
		m_rotation = 90;
		break;
	case 180:
		m_rotation = 180;
		break;
	default:
		m_rotation = 0;
	}
}