Example #1
0
void setPosition(double _lon, double _lat, float _duration, EaseType _e) {

    double lon_start, lat_start;
    getPosition(lon_start, lat_start);
    auto cb = [=](float t) { setPositionNow(ease(lon_start, _lon, t, _e), ease(lat_start, _lat, t, _e)); };
    setEase(EaseField::position, { _duration, cb });

}
Example #2
0
	tween<T>& tween<T>::ease(const char* type)
	{
		auto it = impl::stringToEasingMap.find(type);
		if(it != impl::stringToEasingMap.end()) {
			return ease(it->second);
		} else {
			return ease(easing::quadout);	// Invalid input string - return default?
		}
	}
Example #3
0
Vector3 BezierSpline::get_tangent(scalar_t t)
{	
	if (!get_segment_count()) return Vector3(0, 0, 0);

	if (arc_parametrize)
	{
		t = ease(parametrize(t));
	}
 
	t = (t * get_segment_count());
	int seg = (int) t;
	t -= (scalar_t) floor(t);
	if (seg >= get_segment_count())
	{
		seg = get_segment_count() - 1;
		t = 1.0f;
	}

	seg *= 4;
	ListNode<Vector3> *iter = const_cast<BezierSpline*>(this)->control_points.begin();
	for (int i = 0; i < seg; i++) iter = iter->next;
	
	Vector3 Cp[4];
	for (int i = 0; i < 4; i++)
	{
		Cp[i] = iter->data;
		iter = iter->next;
	}
	
	// interpolate
	return bezier_tangent(Cp[0], Cp[1], Cp[2], Cp[3], t);
}
Example #4
0
Vector3 PolyLine::interpolate(scalar_t t) const {
	if(t > 1.0) t = 1.0;
	if(t < 0.0) t = 0.0;

	if(control_points.size() < 2) return Vector3(0, 0, 0);

	// TODO: check if this is reasonable for polylines.
	if(arc_parametrize) {
		t = ease(parametrize(t));
	}

	// find the appropriate segment of the spline that t lies and calculate the piecewise parameter
	t = (scalar_t)(control_points.size() - 1) * t;
	int seg = (int)t;
	t -= (scalar_t)floor(t);
	if(seg >= get_segment_count()) {
		seg = get_segment_count() - 1;
		t = 1.0f;
	}

	Vector3 cp[2];
	ListNode<Vector3> *iter = const_cast<PolyLine*>(this)->control_points.begin();
	for(int i=0; i<seg; i++) {
		iter = iter->next;
	}

	cp[0] = iter->data;
	cp[1] = iter->next->data;

	return cp[0] + (cp[1] - cp[0]) * t;
}
Example #5
0
void setZoom(float _z, float _duration, EaseType _e) {

    float z_start = getZoom();
    auto cb = [=](float t) { setZoomNow(ease(z_start, _z, t, _e)); };
    setEase(EaseField::zoom, { _duration, cb });

}
Example #6
0
void setTilt(float _radians, float _duration, EaseType _e) {

    float tilt_start = getTilt();
    auto cb = [=](float t) { setTiltNow(ease(tilt_start, _radians, t, _e)); };
    setEase(EaseField::tilt, { _duration, cb });

}
Example #7
0
void CreditsScreen::render() {
	// TODO: This is kinda ugly, done on every frame...
	char temp[256];
	sprintf(temp, "PPSSPP %s", PPSSPP_GIT_VERSION);
	credits[0] = (const char *)temp;

	UIShader_Prepare();
	UIBegin(UIShader_Get());
	DrawBackground(1.0f);

	const int numItems = ARRAY_SIZE(credits);
	int itemHeight = 36;
	int totalHeight = numItems * itemHeight + dp_yres + 200;
	int y = dp_yres - (frames_ % totalHeight);
	for (int i = 0; i < numItems; i++) {
		float alpha = linearInOut(y+32, 64, dp_yres - 192, 64);
		if (alpha > 0.0f) {
			UIText(dp_xres/2, y, credits[i], whiteAlpha(alpha), ease(alpha), ALIGN_HCENTER);
		}
		y += itemHeight;
	}
	I18NCategory *g = GetI18NCategory("General");

	if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), 200, 0, g->T("Back"), ALIGN_BOTTOMRIGHT)) {
		screenManager()->switchScreen(new MenuScreen());
	}

	UIEnd();
}
Example #8
0
Vector3 BSpline::interpolate(scalar_t t) const {
	if(t > 1.0) t = 1.0;
	if(t < 0.0) t = 0.0;

	if(control_points.size() < 4) return Vector3(0, 0, 0);

	if(arc_parametrize) {
		t = ease(parametrize(t));
	}

	// find the appropriate segment of the spline that t lies and calculate the piecewise parameter
	t = (scalar_t)(control_points.size() - 3) * t;
	int seg = (int)t;
	t -= (scalar_t)floor(t);
	if(seg >= get_segment_count()) {
		seg = get_segment_count() - 1;
		t = 1.0f;
	}
	
	ListNode<Vector3> *iter = const_cast<BSpline*>(this)->control_points.begin();
	for(int i=0; i<seg; i++) iter = iter->next;

	Vector3 Cp[4];
	for(int i=0; i<4; i++) {
        Cp[i] = iter->data;
		iter = iter->next;
	}

	Vector3 res;
	res.x = bspline(Cp[0].x, Cp[1].x, Cp[2].x, Cp[3].x, t);
	res.y = bspline(Cp[0].y, Cp[1].y, Cp[2].y, Cp[3].y, t);
	res.z = bspline(Cp[0].z, Cp[1].z, Cp[2].z, Cp[3].z, t);

	return res;
}
Example #9
0
void CreditsScreen::render() {
    UIShader_Prepare();
    UIBegin();
    DrawBackground(1.0f);

    const int numItems = ARRAY_SIZE(credits);
    int itemHeight = 36;
    int totalHeight = numItems * itemHeight + dp_yres + 200;
    int y = dp_yres - (frames_ % totalHeight);
    for (int i = 0; i < numItems; i++) {
        float alpha = linearInOut(y+32, 64, dp_yres - 192, 64);
        if (alpha > 0.0f) {
            UIText(dp_xres/2, y, credits[i], whiteAlpha(alpha), ease(alpha), ALIGN_HCENTER);
        }
        y += itemHeight;
    }

    if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), 200, "Back", ALIGN_BOTTOMRIGHT)) {
        screenManager()->switchScreen(new MenuScreen());
    }

    UIEnd();

    glsl_bind(UIShader_Get());
    ui_draw2d.Flush(UIShader_Get());
}
Example #10
0
void test_ease(double (*ease)(double, double, double,  double, double)) {
    FILE * data = fopen("in.dat", "w");
    double start = 2, end = 5;
    double from = 2, to = 4;
    for (double x = start; x <= end; x += 0.01)
        fprintf(data, "%.10lf\t%.10lf\n", x, ease(start, end, from, to, x));
    fclose(data);
}
void TimedScaleCallback::performTime(TimeEventData& data) {
	if (getPercentageDone() == 0.0) {
		mStartScale = mEntity->getScale();
	}
	mTimePassed += data.mTimePassed;
	mEntity->scaleTo(
			mStartScale + ease(getPercentageDone()) * (mEndScale - mStartScale));
}
float genNoise(sf::Vector2f loc, sf::Vector2f** gradients, size_t size){
	sf::Vector2f a,b,c,d;
	a = gradients[(int)(loc.x/640*size)][(int)(loc.y/640*size)];        //x0y0
	b = gradients[(int)(loc.x/640*size) + 1][(int)(loc.y/640*size)];    //x1y0
	c = gradients[(int)(loc.x/640*size)][(int)(loc.y/640*size) + 1];            //x0y1
	d = gradients[(int)(loc.x/640*size) + 1][(int)(loc.y/640*size) + 1];        //x1y1
	//std::cout << (int)loc.x/10 << std::endl;
	
	//std::cin.get();
	//float alen,blen,clen,dlen;

	float ax, ay, bx, by, cx, cy, dx, dy;
	ax = (int)(loc.x/640*size);
	ay = (int)(loc.y/640*size);
	bx = (int)(loc.x/640*size) + 1;
	by = (int)(loc.y/640*size);
	cx = (int)(loc.x/640*size);
	cy = (int)(loc.y/640*size) + 1;
	dx = (int)(loc.x/640*size) + 1;
	dy = (int)(loc.y/640*size) + 1;
	//std::cout << "a " << ax << " " << ay << " " << "b " << bx << " " << by << " " << "c " << cx << " " << cy << " " << "d " << dx << " " << dy << std::endl; 
	//std::cout << ay << "\n";
	//std::cout << "loc " << loc.x<< " " << loc.y << std::endl;
	//std::cout << "loc " << loc.x/640*SIZE<< " " << loc.y/640*SIZE << std::endl;
	//std::cout << loc.x/640*SIZE - dx;
	//std::cout << loc.y/640*SIZE - dy;
	//std::cin.get();
	float s,t,u,v;

	/*s = a.x * ((ax - loc.x/10.0)) + a.y * ((ay - loc.y/10.0)); 
	t = b.x * ((bx - loc.x/10.0)) + b.y * ((by - loc.y/10.0));
	u = c.x * ((cx - loc.x/10.0)) + c.y * ((cy - loc.y/10.0));
	v = d.x * ((dx - loc.x/10.0)) + d.y * ((dy - loc.y/10.0));*/
	s = a.x * ((loc.x/640.0*size - ax)) + a.y * ((loc.y/640.0*size - ay)); 
	t = b.x * ((loc.x/640.0*size - bx)) + b.y * ((loc.y/640.0*size - by));
	u = c.x * ((loc.x/640.0*size - cx)) + c.y * ((loc.y/640.0*size - cy));
	v = d.x * ((loc.x/640.0*size - dx)) + d.y * ((loc.y/640.0*size - dy));
//	float Sx =  6*pow(s,5) - 15 * pow(s,4) + 10 * pow(s,3);//(s5 - 15x4 + 10x3 
//	float Sx =  6*pow(s,5) - 15 * pow(s,4) + 10 * pow(s,3);
	float lerpX = loc.x/640*size - ax;
	float lerpY = loc.y/640*size - ay;
	float st = ease(s , t , lerpX);
	float uv = ease(u , v , lerpX);
	return ease(st, uv, lerpY);
}
Example #13
0
static void transform_squish(float s, float x, float y, float *ox, float *oy)
{
    const float nx = (x + 1)/2;
    
    const float off_s = 1.0f+s*0.2f;
    
    *ox = ease(lerp(-1.0f+s*0.2f, 1.0f, nx), s);
    *oy = y;
}
Example #14
0
double  ofApp::perlin_noise(vector<double> coordinate,vector<double> gradient1,vector<double> gradient2,vector<double> gradient3,vector<double> gradient4)
{
    vector<double> l1;
    vector<double> l2;
    vector<double> l3;
    vector<double> l4;
    l1.push_back(coordinate[0]); l1.push_back(coordinate[1]);
    l2.push_back(1-coordinate[0]); l2.push_back(coordinate[1]);
    l3.push_back(1-coordinate[0]); l3.push_back(1-coordinate[1]);
    l4.push_back(coordinate[0]); l4.push_back(1-coordinate[1]);

    double a=dot_product(l1,gradient1);
    double b=dot_product(l2,gradient2);
    double c=dot_product(l3,gradient3);
    double d=dot_product(l4,gradient4);
    double S1=ease(coordinate[0]);
    double S2=ease(coordinate[1]);
    return a*(1-S1)*(1-S2)+b*S1*(1-S2)+c*S1*S2+d*(1-S1)*S2;
}
Example #15
0
 const Tween & make_tween(VariableType * variable, VariableType targetValue, float seconds, EasingFunc ease)
 {
     VariableType initialValue = *variable;
     auto updateFunction = [variable, initialValue, targetValue, ease](float t)
     {
         *variable = static_cast<VariableType>(initialValue * (1 - ease(t)) + targetValue * ease(t));
     };
     
     tweens.push_back({variable, now, now + seconds, updateFunction});
     return tweens.back();
 }
void TimedColorCallback::perform(EventType* event) {
	TimeEventData myData = TimeEvent::getData(event);
	if (getPercentageDone() == 0.0) {
		mPainter->setColor(mStartColor);
	}
	mTimePassed += myData.mTimePassed;
	mPainter->setColor(mStartColor + ease(getPercentageDone()) * mEndColor);
	checkTime(myData.mTimePassed);
	if (mFinished) {
		mModel->removeEffect(mPainter);
	}
}
Example #17
0
void setRotation(float _radians, float _duration, EaseType _e) {

    float radians_start = getRotation();

    // Ease over the smallest angular distance needed
    float radians_delta = glm::mod(_radians - radians_start, (float)TWO_PI);
    if (radians_delta > PI) { radians_delta -= TWO_PI; }
    _radians = radians_start + radians_delta;

    auto cb = [=](float t) { setRotationNow(ease(radians_start, _radians, t, _e)); };
    setEase(EaseField::rotation, { _duration, cb });

}
Example #18
0
void MakeStackIcon::onRender(uint flags)
{
	if (!enabled)
		return;
#ifdef DXRENDER
	D3DMATERIAL9 stackIconMaterial = dxr->textureMaterial;
	stackIconMaterial.Diffuse = D3DXCOLOR(1, 1, 1, ease(alpha));
	dxr->device->SetMaterial(&stackIconMaterial);
	Mat33 orientation(NxQuat(90, Vec3(1,0,0)));
	dxr->renderSideLessBox(Vec3(position.x, 10, position.z), orientation, Vec3(size / 2.0f, -size / 2.0f, 1), texMgr->getGLTextureId("widget.vertStack"));
	dxr->device->SetMaterial(&dxr->textureMaterial);
#else
	glPushAttribToken token(GL_ENABLE_BIT);

	//glColor4f(72.0f/255., 149.0f/255., 234.0f/255., 1.0);
	if (alpha == 1.0)
		glColor4d(1, 1, 1, 1);
	else glColor4d(1, 1, 1, ease(alpha));

	glDisable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, texMgr->getGLTextureId("widget.vertStack"));
	glEnable(GL_BLEND);

	glPushMatrix();
	glTranslated(position.x, 0, position.z);
	glScalef(size / 2.0f, 0.2f, size / 2.0f);
	glBegin(GL_TRIANGLE_FAN);
	{
		glNormal3f(0,1,0);
		glTexCoord2f(1,1); 	glVertex3f(-1,1,1);
		glTexCoord2f(0,1); 	glVertex3f(1,1,1);
		glTexCoord2f(0,0); 	glVertex3f(1,1,-1);
		glTexCoord2f(1,0); 	glVertex3f(-1,1,-1);
	}
	glEnd();
	glPopMatrix();
#endif
}
Example #19
0
float Easing::ease(float p_from, float p_to, float p_progress) const
{
	if (p_progress <= 0.0f) {
		return p_from;
	}

	if (p_progress >= 1.0f) {
		return p_to;
	}

	float easedT;

	switch (m_type) {
		case T_IN:
			easedT = ease(p_progress);
			break;

		case T_OUT:
			easedT = 1.0f - ease(1.0f - p_progress);
			break;

		case T_IN_OUT:
			if (p_progress < 0.5f) {
				easedT = ease(2 * p_progress) / 2.0f;
			} else {
				easedT = 1.0f - ease(2.0f - 2.0f * p_progress) / 2.0f;
			}

			break;

		default:
			G_ASSERT(0 && "unknown Type");
	}

	return p_from + ((p_to - p_from) * easedT);
}
Example #20
0
File: warp.cpp Project: i80and/warp
float Warp::noise(float x, float y) const {
    float x0 = floorf(x);
    float x1 = ceilf(x);
    float y0 = floorf(y);
    float y1 = ceilf(y);

    Vec2 g_rand_x0_y1 = getGradient(x0, y1);
    Vec2 g_rand_x1_y1 = getGradient(x1, y1);
    Vec2 g_rand_x1_y0 = getGradient(x1, y0);
    Vec2 g_rand_x0_y0 = getGradient(x0, y0);

    float s = (g_rand_x0_y0.x() * (x-x0)) + (g_rand_x0_y0.y() * (y-y0));
    float t = (g_rand_x1_y0.x() * (x-x1)) + (g_rand_x1_y0.y() * (y-y0));
    float u = (g_rand_x0_y1.x() * (x-x0)) + (g_rand_x0_y1.y() * (y-y1));
    float v = (g_rand_x1_y1.x() * (x-x1)) + (g_rand_x1_y1.y() * (y-y1));

    float weight_x = ease(x-x0);
    float a = s + (weight_x * (t - s));
    float b = u + (weight_x * (v - u));

    float weight_y = ease(y-y0);

    return a + weight_y * (b - a);
};
Example #21
0
Vector3 CatmullRomSpline::interpolate(scalar_t t) const {
	if(t > 1.0) t = 1.0;
	if(t < 0.0) t = 0.0;

	if(control_points.size() < 2) return Vector3(0, 0, 0);

	if(arc_parametrize) {
		t = ease(parametrize(t));
	}

	// find the appropriate segment of the spline that t lies and calculate the piecewise parameter
	t = (scalar_t)(control_points.size() - 1) * t;
	int seg = (int)t;
	t -= (scalar_t)floor(t);
	if(seg >= get_segment_count()) {
		seg = get_segment_count() - 1;
		t = 1.0f;
	}

	Vector3 cp[4];
	ListNode<Vector3> *iter = const_cast<CatmullRomSpline*>(this)->control_points.begin();
	for(int i=0; i<seg; i++) {
		iter = iter->next;
	}

	cp[1] = iter->data;
	cp[2] = iter->next->data;
	
	if(!seg) {
		cp[0] = cp[1];
	} else {
		cp[0] = iter->prev->data;
	}
	
	if(seg == control_points.size() - 2) {
		cp[3] = cp[2];
	} else {
		cp[3] = iter->next->next->data;
	}

	Vector3 res;
	res.x = catmull_rom_spline(cp[0].x, cp[1].x, cp[2].x, cp[3].x, t);
	res.y = catmull_rom_spline(cp[0].y, cp[1].y, cp[2].y, cp[3].y, t);
	res.z = catmull_rom_spline(cp[0].z, cp[1].z, cp[2].z, cp[3].z, t);

	return res;
}
Example #22
0
void display_credits(Raster *double_buffer)
{
	static const uint32_t max_ticks = 640;

	static const char *pressf1 = _("Press F1 for help");
	if (ticks > max_ticks)
	{
		clear_bitmap(wk);
		Draw.print_font(wk, (wk->width - 8 * strlen(*cc)) / 2, 42, *cc, FNORMAL);

		/* After each 'max_ticks' number of ticks, increment the current line of
		 * credits displayed, looping back to the beginning as needed.
		 */
		if (*(++cc) == NULL)
		{
			cc = credits;
		}
		Draw.print_font(wk, (wk->width - 8 * strlen(*cc)) / 2, 10, *cc, FNORMAL);
		ticks = 0;
	}
	else
	{
		++ticks;
	}

	int ease_amount = (max_ticks / 2) - ticks;
	int x0 = (320 - wk->width) / 2;
	for (int i = 0; i < wk->width; ++i)
	{
		blit(wk, double_buffer, i, ease(i + ease_amount), i + x0, KQ_SCREEN_H - 55,
			1, 32);
	}
	Draw.print_font(double_buffer, (KQ_SCREEN_W - 8 * strlen(pressf1)) / 2,
		KQ_SCREEN_H - 30, pressf1, FNORMAL);
#ifdef KQ_CHEATS
	/* Put an un-ignorable cheat message; this should stop
	 * PH releasing versions with cheat mode compiled in ;)
	 */
	extern int cheat;
	Draw.print_font(double_buffer, 80, 40,
		cheat ? _("*CHEAT MODE ON*") : _("*CHEAT MODE OFF*"), FGOLD);
#endif
#ifdef DEBUGMODE
	/* TT: Similarly, if we are in debug mode, we should be warned. */
	Draw.print_font(double_buffer, 80, 48, _("*DEBUG MODE ON*"), FGOLD);
#endif
}
void GLWidget::updateAnimation() {
    if (controlPoints.size() < 4) {
        return;
    }

    currentAnimationTime += DELTA_TIME;
    int numSegments = (float)(controlPoints.size() - 3);
    float animTime = animationTimePerSegment*numSegments;
    if (currentAnimationTime > animTime) {
        currentAnimationTime = 0.0f;
    }

    float t = currentAnimationTime / animTime;
    float t1 = 0.0f + accelerationTime;
    float t2 = 1.0f - accelerationTime;
    animationProgress = ease(t, t1, t2);
}
Example #24
0
void display_credits(void)
{
    static const char *pressf1;
    int i, x0, e;
    static int last_e = 999;

    pressf1 = _("Press F1 for help");
    if (wk == NULL)
    {
        allocate_credits();
    }
    if (ticks > 640)
    {
        clear_bitmap(wk);
        print_font(wk, (wk->w - 8 * strlen(*cc)) / 2, 42, *cc, FNORMAL);
        if (*(++cc) == NULL)
        {
            cc = credits;
        }
        print_font(wk, (wk->w - 8 * strlen(*cc)) / 2, 10, *cc, FNORMAL);
        ticks = 0;
    }
    e = 320 - ticks;
    if (e != last_e)
    {
        x0 = (320 - wk->w) / 2;
        for (i = 0; i < wk->w; ++i)
        {
            blit(wk, double_buffer, i, ease(i + e), i + x0, 185, 1, 32);
        }
        print_font(double_buffer, (320 - 8 * strlen(pressf1)) / 2, 210,
                   pressf1, FNORMAL);
#ifdef KQ_CHEATS
        /* Put an un-ignorable cheat message; this should stop
         * PH releasing versions with cheat mode compiled in ;)
         */
        print_font(double_buffer, 80, 40,
                   cheat ? _("*CHEAT MODE ON*") : _("*CHEAT MODE OFF*"), FGOLD);
#endif
#ifdef DEBUGMODE
        /* TT: Similarly, if we are in debug mode, we should be warned. */
        print_font(double_buffer, 80, 48, _("*DEBUG MODE ON*"), FGOLD);
#endif
        last_e = e;
    }
}
Example #25
0
void FileListAdapter::drawItem(int item, int x, int y, int w, int h, bool selected) const
{
	int icon = -1;
	if ((*items_)[item].isDirectory) {
		icon = options_.folderIcon;
	} else {
		std::string extension = getFileExtension((*items_)[item].name);
		auto iter = options_.iconMapping.find(extension);
		if (iter != options_.iconMapping.end())
			icon = iter->second;
	}

	float scaled_h = ui_atlas.images[I_BUTTON].h;
	float scaled_w = scaled_h * (144.f / 80.f);

	int iconSpace = scaled_w + 10;
	ui_draw2d.DrawImage2GridH(selected ? I_BUTTON_SELECTED: I_BUTTON, x, y, x + w);
	ui_draw2d.DrawTextShadow(UBUNTU24, (*items_)[item].name.c_str(), x + UI_SPACE + iconSpace, y + 25, 0xFFFFFFFF, ALIGN_LEFT | ALIGN_VCENTER);

	// This might create a texture so we must flush first.
	UIFlush();
	GameInfo *ginfo = 0;
	if (!(*items_)[item].isDirectory) {
		ginfo = g_gameInfoCache.GetInfo((*items_)[item].fullName, false);
		if (!ginfo) {
			ELOG("No ginfo :( %s", (*items_)[item].fullName.c_str());
		}
	}
	if (ginfo) {
		if (ginfo->iconTexture) {
			uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timeIconWasLoaded) * 2));
			UIFlush();
			ginfo->iconTexture->Bind(0);
			ui_draw2d.DrawTexRect(x + 10, y, x + 10 + scaled_w, y + scaled_h, 0, 0, 1, 1, color);
			ui_draw2d.Flush();
			ctx_->RebindTexture();
		}
	} else {
		if (icon != -1)
			ui_draw2d.DrawImage(icon, x + UI_SPACE, y + 25, 1.0f, 0xFFFFFFFF, ALIGN_VCENTER | ALIGN_LEFT);
	}
}
/* ----------------------------------------------------------------------------
 * Draws a text widget.
 */
void menu_text::draw(const float time_spent) {
    if(!font || !enabled) return;
    
    int text_x = center.x;
    if(text_align == ALLEGRO_ALIGN_LEFT) {
        text_x = center.x - size.x * 0.5;
    } else if(text_align == ALLEGRO_ALIGN_RIGHT) {
        text_x = center.x + size.x * 0.5;
    }
    
    float juicy_grow_amount =
        ease(
            EASE_UP_AND_DOWN,
            juicy_grow_time_left / JUICY_GROW_DURATION
        ) * JUICY_GROW_DELTA;
        
    draw_scaled_text(
        font, text_color,
        point(text_x, center.y),
        point(1.0 + juicy_grow_amount, 1.0 + juicy_grow_amount),
        text_align, 1, text
    );
}
/* ----------------------------------------------------------------------------
 * Retrieves the data necessary for the drawing routine.
 * Returns false if this element shouldn't be drawn.
 * id:     ID of the HUD item.
 * center: Pointer to place the final center coordinates in, if any.
 * size:   Pointer to place the final dimensions in, if any.
 */
bool hud_item_manager::get_draw_data(
    const size_t id, point* center, point* size
) {
    hud_item* h = &items[id];
    if(offscreen) return false;
    if(h->size.x <= 0 || h->size.y <= 0) return false;
    if(h->center.x + h->size.x / 2.0f < 0)    return false;
    if(h->center.x - h->size.x / 2.0f > 1.0f) return false;
    if(h->center.y + h->size.y / 2.0f < 0)    return false;
    if(h->center.y - h->size.y / 2.0f > 1.0f) return false;
    
    point normal_coords, final_coords;
    normal_coords.x = h->center.x * scr_w;
    normal_coords.y = h->center.y * scr_h;
    
    if(move_timer.time_left == 0.0f) {
        final_coords = normal_coords;
        
    } else {
        point start_coords, end_coords;
        unsigned char ease_method;
        point offscreen_coords;
        
        float angle = get_angle(point(0.5, 0.5), h->center);
        offscreen_coords.x = h->center.x + cos(angle);
        offscreen_coords.y = h->center.y + sin(angle);
        offscreen_coords.x *= scr_w;
        offscreen_coords.y *= scr_h;
        
        if(move_in) {
            start_coords = offscreen_coords;
            end_coords = normal_coords;
            ease_method = EASE_OUT;
        } else {
            start_coords = normal_coords;
            end_coords = offscreen_coords;
            ease_method = EASE_IN;
        }
        
        final_coords.x =
            interpolate_number(
                ease(ease_method, 1 - move_timer.get_ratio_left()),
                0, 1, start_coords.x, end_coords.x
            );
        final_coords.y =
            interpolate_number(
                ease(ease_method, 1 - move_timer.get_ratio_left()),
                0, 1, start_coords.y, end_coords.y
            );
    }
    
    if(center) {
        *center = final_coords;
    }
    if(size) {
        size->x = h->size.x * scr_w;
        size->y = h->size.y * scr_h;
    }
    
    return true;
}
Example #28
0
void PauseScreen::render() {
	UIShader_Prepare();
	UIBegin(UIShader_Get());
	DrawBackground(1.0f);

	std::string title = game_title.c_str();
	// Try to ignore (tm) etc.
	//if (UTF8StringNonASCIICount(game_title.c_str()) > 2) {
	//	title = "(can't display japanese title)";
	//} else {
	//}


	UIContext *ctx = screenManager()->getUIContext();
	// This might create a texture so we must flush first.
	UIFlush();
	GameInfo *ginfo = g_gameInfoCache.GetInfo(PSP_CoreParameter().fileToStart, true);

	if (ginfo) {
		title = ginfo->title;
	}

	if (ginfo && ginfo->pic1Texture) {
		ginfo->pic1Texture->Bind(0);
		uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 3)) & 0xFFc0c0c0;
		ui_draw2d.DrawTexRect(0,0,dp_xres, dp_yres, 0,0,1,1,color);
		ui_draw2d.Flush();
		ctx->RebindTexture();
	}

	if (ginfo && ginfo->pic0Texture) {
		ginfo->pic0Texture->Bind(0);
		// Pic0 is drawn in the bottom right corner, overlaying pic1.
		float sizeX = dp_xres / 480 * ginfo->pic0Texture->Width();
		float sizeY = dp_yres / 272 * ginfo->pic0Texture->Height();
		uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 2)) & 0xFFc0c0c0;
		ui_draw2d.DrawTexRect(dp_xres - sizeX, dp_yres - sizeY, dp_xres, dp_yres, 0,0,1,1,color);
		ui_draw2d.Flush();
		ctx->RebindTexture();
	}

	if (ginfo && ginfo->iconTexture) {
		uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timeIconWasLoaded) * 1.5));
		ginfo->iconTexture->Bind(0);

		// Maintain the icon's aspect ratio.  Minis are square, for example.
		float iconAspect = (float)ginfo->iconTexture->Width() / (float)ginfo->iconTexture->Height();
		float h = 80.0f;
		float w = 144.0f;
		float x = 10.0f + (w - h * iconAspect) / 2.0f;
		w = h * iconAspect;

		ui_draw2d.DrawTexRect(x, 10, x + w, 10 + h, 0, 0, 1, 1, 0xFFFFFFFF);
		ui_draw2d.Flush();
		ctx->RebindTexture();
	}

	ui_draw2d.DrawText(UBUNTU24, title.c_str(), 10+144+10, 30, 0xFFFFFFFF, ALIGN_LEFT);

	int x = 30;
	int y = 50;
	int stride = 40;
	int columnw = 400;

	// Shared with settings
	I18NCategory *ss = GetI18NCategory("System");
	I18NCategory *gs = GetI18NCategory("Graphics");
	I18NCategory *a = GetI18NCategory("Audio");
	
	UICheckBox(GEN_ID, x, y += stride, ss->T("Show FPS"), ALIGN_TOPLEFT, &g_Config.bShowFPSCounter);
	UICheckBox(GEN_ID, x, y += stride, a->T("Enable Sound"), ALIGN_TOPLEFT, &g_Config.bEnableSound);
	// TODO: Maybe shouldn't show this if the screen ratios are very close...
#ifdef BLACKBERRY10
	if (pixel_xres == pixel_yres)
		UICheckBox(GEN_ID, x, y += stride, gs->T("Partial Vertical Stretch"), ALIGN_TOPLEFT, &g_Config.bPartialStretch);
#endif
	UICheckBox(GEN_ID, x, y += stride, gs->T("Stretch to Display"), ALIGN_TOPLEFT, &g_Config.bStretchToDisplay);

	UICheckBox(GEN_ID, x, y += stride, gs->T("Hardware Transform"), ALIGN_TOPLEFT, &g_Config.bHardwareTransform);
	if (UICheckBox(GEN_ID, x, y += stride, gs->T("Buffered Rendering"), ALIGN_TOPLEFT, &g_Config.bBufferedRendering)) {
		if (gpu)
			gpu->Resized();
	}
	UICheckBox(GEN_ID, x, y += stride, gs->T("Media Engine"), ALIGN_TOPLEFT, &g_Config.bUseMediaEngine);
	bool enableFrameSkip = g_Config.iFrameSkip != 0;
	UICheckBox(GEN_ID, x, y += stride, gs->T("Frame Skipping"), ALIGN_TOPLEFT, &enableFrameSkip);
	if (enableFrameSkip) {
		if (g_Config.iFrameSkip == 0)
			g_Config.iFrameSkip = 3;

		float getfskip= g_Config.iFrameSkip;
		char showfskip[256];
		sprintf(showfskip, "Skip Frames: %0.0f", getfskip);
		ui_draw2d.DrawText(UBUNTU24, showfskip, dp_xres - 8, 12, 0xc0000000, ALIGN_TOPRIGHT);
		ui_draw2d.DrawText(UBUNTU24, showfskip, dp_xres - 10, 10, 0xFF3fFF3f, ALIGN_TOPRIGHT);
		ui_draw2d.DrawText(UBUNTU24, gs->T("Frames :"), x + 60, y += stride + 10, 0xFFFFFFFF, ALIGN_LEFT);
		HLinear hlinear1(x + 200 , y + 5, 20);
		if (UIButton(GEN_ID, hlinear1, 80, 0, "Auto", ALIGN_LEFT))
			g_Config.iFrameSkip = 3;
		if (UIButton(GEN_ID, hlinear1, 40, 0, "-1", ALIGN_LEFT))
			if(g_Config.iFrameSkip>0){
			g_Config.iFrameSkip -= 1;}
		if (UIButton(GEN_ID, hlinear1, 40, 0, "+1", ALIGN_LEFT))
			if(g_Config.iFrameSkip!=9){
			g_Config.iFrameSkip += 1;}
	}
	else {
		g_Config.iFrameSkip = 0;
	}

	I18NCategory *i = GetI18NCategory("Pause");

	// TODO: Add UI for more than one slot.
	HLinear hlinear1(x, y + 80, 20);
	if (UIButton(GEN_ID, hlinear1, LARGE_BUTTON_WIDTH, 0, i->T("Save State"), ALIGN_LEFT)) {
		SaveState::SaveSlot(0, 0, 0);
		screenManager()->finishDialog(this, DR_CANCEL);
	}
	if (UIButton(GEN_ID, hlinear1, LARGE_BUTTON_WIDTH, 0, i->T("Load State"), ALIGN_LEFT)) {
		SaveState::LoadSlot(0, 0, 0);
		screenManager()->finishDialog(this, DR_CANCEL);
	}

	VLinear vlinear(dp_xres - 10, 160, 20);
	if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH + 20, 0, i->T("Continue"), ALIGN_RIGHT)) {
		screenManager()->finishDialog(this, DR_CANCEL);
	}

	if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH + 20, 0, i->T("Settings"), ALIGN_RIGHT)) {
		screenManager()->push(new SettingsScreen(), 0);
	}

	if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH + 20, 0, i->T("Back to Menu"), ALIGN_RIGHT)) {
		screenManager()->finishDialog(this, DR_OK);
	}

	/*
	if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), LARGE_BUTTON_WIDTH*2, 0, "Debug: Dump Next Frame", ALIGN_BOTTOMRIGHT)) {
		gpu->DumpNextFrame();
	}
	*/

	DrawWatermark();
	UIEnd();
}
Example #29
0
void MenuScreen::render() {
	UIShader_Prepare();
	UIBegin(UIShader_Get());
	DrawBackground(1.0f);

	double xoff = 150 - frames_ * frames_ * 0.4f;
	if (xoff < -20)
		xoff = -20;
	if (frames_ > 200)  // seems the above goes nuts after a while...
		xoff = -20;

	int w = LARGE_BUTTON_WIDTH + 60;

	ui_draw2d.DrawTextShadow(UBUNTU48, "PPSSPP", dp_xres + xoff - w/2, 75, 0xFFFFFFFF, ALIGN_HCENTER | ALIGN_BOTTOM);
	ui_draw2d.SetFontScale(0.7f, 0.7f);
	ui_draw2d.DrawTextShadow(UBUNTU24, PPSSPP_GIT_VERSION, dp_xres + xoff, 85, 0xFFFFFFFF, ALIGN_RIGHT | ALIGN_BOTTOM);
	ui_draw2d.SetFontScale(1.0f, 1.0f);
	VLinear vlinear(dp_xres + xoff, 100, 20);

	I18NCategory *m = GetI18NCategory("MainMenu");

	if (UIButton(GEN_ID, vlinear, w, 0, m->T("Load", "Load..."), ALIGN_RIGHT)) {
#if defined(USING_QT_UI) && !defined(MEEGO_EDITION_HARMATTAN)
		QString fileName = QFileDialog::getOpenFileName(NULL, "Load ROM", g_Config.currentDirectory.c_str(), "PSP ROMs (*.iso *.cso *.pbp *.elf)");
		if (QFile::exists(fileName)) {
			QDir newPath;
			g_Config.currentDirectory = newPath.filePath(fileName).toStdString();
			g_Config.Save();
			screenManager()->switchScreen(new EmuScreen(fileName.toStdString()));
		}
#elif _WIN32
		MainWindow::BrowseAndBoot("");
#else
		FileSelectScreenOptions options;
		options.allowChooseDirectory = true;
		options.filter = "iso:cso:pbp:elf:prx:";
		options.folderIcon = I_ICON_FOLDER;
		options.iconMapping["iso"] = I_ICON_UMD;
		options.iconMapping["cso"] = I_ICON_UMD;
		options.iconMapping["pbp"] = I_ICON_EXE;
		options.iconMapping["elf"] = I_ICON_EXE;
		screenManager()->switchScreen(new FileSelectScreen(options));
#endif
		UIReset();
	}

	if (UIButton(GEN_ID, vlinear, w, 0, m->T("Settings"), ALIGN_RIGHT)) {
		screenManager()->push(new SettingsScreen(), 0);
		UIReset();
	}

	if (UIButton(GEN_ID, vlinear, w, 0, m->T("Credits"), ALIGN_RIGHT)) {
		screenManager()->switchScreen(new CreditsScreen());
		UIReset();
	}

	if (UIButton(GEN_ID, vlinear, w, 0, m->T("Exit"), ALIGN_RIGHT)) {
		// TODO: Save when setting changes, rather than when we quit
		NativeShutdown();
		// TODO: Need a more elegant way to quit
#ifdef _WIN32
		ExitProcess(0);
#else
		exit(0);
#endif
	}

	if (UIButton(GEN_ID, vlinear, w, 0, "www.ppsspp.org", ALIGN_RIGHT)) {
		LaunchBrowser("http://www.ppsspp.org/");
	}

	int recentW = 350;
	if (g_Config.recentIsos.size()) {
		ui_draw2d.DrawText(UBUNTU24, m->T("Recent"), -xoff, 80, 0xFFFFFFFF, ALIGN_BOTTOMLEFT);
	}

	int spacing = 15;

	float textureButtonWidth = 144;
	float textureButtonHeight = 80;

	if (dp_yres < 480)
		spacing = 8;
	// On small screens, we can't fit four vertically.
	if (100 + spacing * 6 + textureButtonHeight * 4 > dp_yres) {
		textureButtonHeight = (dp_yres - 100 - spacing * 6) / 4;
		textureButtonWidth = (textureButtonHeight / 80) * 144;
	}

	VGrid vgrid_recent(-xoff, 100, std::min(dp_yres-spacing*2, 480), spacing, spacing);

	for (size_t i = 0; i < g_Config.recentIsos.size(); i++) {
		std::string filename;
		std::string rec = g_Config.recentIsos[i];
		for (size_t j = 0; j < rec.size(); j++)
			if (rec[j] == '\\') rec[j] = '/';
		SplitPath(rec, nullptr, &filename, nullptr);

		UIContext *ctx = screenManager()->getUIContext();
		// This might create a texture so we must flush first.
		UIFlush();
		GameInfo *ginfo = g_gameInfoCache.GetInfo(g_Config.recentIsos[i], false);
		if (ginfo && ginfo->fileType != FILETYPE_PSP_ELF) {
			u32 color;
			if (ginfo->iconTexture == 0) {
				color = 0;
			} else {
				color = whiteAlpha(ease((time_now_d() - ginfo->timeIconWasLoaded) * 2));
			}
			if (UITextureButton(ctx, (int)GEN_ID_LOOP(i), vgrid_recent, textureButtonWidth, textureButtonHeight, ginfo->iconTexture, ALIGN_LEFT, color, I_DROP_SHADOW)) {
				UIEnd();
				screenManager()->switchScreen(new EmuScreen(g_Config.recentIsos[i]));
				return;
			}
		} else {
			if (UIButton((int)GEN_ID_LOOP(i), vgrid_recent, textureButtonWidth, textureButtonHeight, filename.c_str(), ALIGN_LEFT)) {
				UIEnd();
				screenManager()->switchScreen(new EmuScreen(g_Config.recentIsos[i]));
				return;
			}
		}
	}

#if defined(_DEBUG) & defined(_WIN32)
	// Print the current dp_xres/yres in the corner. For UI scaling testing - just
	// resize to 800x480 to get an idea of what it will look like on a Nexus S.
	ui_draw2d.SetFontScale(0.4, 0.4);
	char temptext[64];
	sprintf(temptext, "%ix%i", dp_xres, dp_yres);
	ui_draw2d.DrawTextShadow(UBUNTU24, temptext, 5, dp_yres-5, 0xFFFFFFFF, ALIGN_BOTTOMLEFT);
	ui_draw2d.SetFontScale(1.0, 1.0);
#endif

	DrawWatermark();

	UIEnd();
}
Example #30
0
void PauseScreen::render() {
	UIShader_Prepare();
	UIBegin(UIShader_Get());
	DrawBackground(1.0f);

	std::string title = game_title.c_str();
	// Try to ignore (tm) etc.
	//if (UTF8StringNonASCIICount(game_title.c_str()) > 2) {
	//	title = "(can't display japanese title)";
	//} else {
	//}


	UIContext *ctx = screenManager()->getUIContext();
	// This might create a texture so we must flush first.
	UIFlush();
	GameInfo *ginfo = g_gameInfoCache.GetInfo(PSP_CoreParameter().fileToStart, true);

	if (ginfo) {
		title = ginfo->title;
	}

	if (ginfo && ginfo->pic1Texture) {
		ginfo->pic1Texture->Bind(0);
		uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 3)) & 0xFFc0c0c0;
		ui_draw2d.DrawTexRect(0,0,dp_xres, dp_yres, 0,0,1,1,color);
		ui_draw2d.Flush();
		ctx->RebindTexture();
	}

	if (ginfo && ginfo->pic0Texture) {
		ginfo->pic0Texture->Bind(0);
		// Pic0 is drawn in the bottom right corner, overlaying pic1.
		float sizeX = dp_xres / 480 * ginfo->pic0Texture->Width();
		float sizeY = dp_yres / 272 * ginfo->pic0Texture->Height();
		uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 2)) & 0xFFc0c0c0;
		ui_draw2d.DrawTexRect(dp_xres - sizeX, dp_yres - sizeY, dp_xres, dp_yres, 0,0,1,1,color);
		ui_draw2d.Flush();
		ctx->RebindTexture();
	}

	if (ginfo && ginfo->iconTexture) {
		uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timeIconWasLoaded) * 1.5));
		ginfo->iconTexture->Bind(0);
		ui_draw2d.DrawTexRect(10,10,10+144, 10+80, 0,0,1,1,0xFFFFFFFF);
		ui_draw2d.Flush();
		ctx->RebindTexture();
	}

	ui_draw2d.DrawText(UBUNTU24, title.c_str(), 10+144+10, 30, 0xFFFFFFFF, ALIGN_LEFT);

	int x = 30;
	int y = 50;
	int stride = 40;
	int columnw = 400;

	// Shared with settings
	I18NCategory *ss = GetI18NCategory("System");
	I18NCategory *gs = GetI18NCategory("Graphics");

	UICheckBox(GEN_ID, x, y += stride, ss->T("Show Debug Statistics"), ALIGN_TOPLEFT, &g_Config.bShowDebugStats);
	UICheckBox(GEN_ID, x, y += stride, ss->T("Show FPS"), ALIGN_TOPLEFT, &g_Config.bShowFPSCounter);

	// TODO: Maybe shouldn't show this if the screen ratios are very close...
	UICheckBox(GEN_ID, x, y += stride, gs->T("Stretch to Display"), ALIGN_TOPLEFT, &g_Config.bStretchToDisplay);

	UICheckBox(GEN_ID, x, y += stride, gs->T("Hardware Transform"), ALIGN_TOPLEFT, &g_Config.bHardwareTransform);
	if (UICheckBox(GEN_ID, x, y += stride, gs->T("Buffered Rendering"), ALIGN_TOPLEFT, &g_Config.bBufferedRendering)) {
		if (gpu)
			gpu->Resized();
	}
	bool fs = g_Config.iFrameSkip == 1;
	UICheckBox(GEN_ID, x, y += stride, gs->T("Frame Skipping"), ALIGN_TOPLEFT, &fs);
	UICheckBox(GEN_ID, x, y += stride, gs->T("Media Engine"), ALIGN_TOPLEFT, &g_Config.bUseMediaEngine);
	g_Config.iFrameSkip = fs ? 1 : 0;

	I18NCategory *i = GetI18NCategory("Pause");

	// TODO: Add UI for more than one slot.
	HLinear hlinear1(x, y + 80, 20);
	if (UIButton(GEN_ID, hlinear1, LARGE_BUTTON_WIDTH, 0, i->T("Save State"), ALIGN_LEFT)) {
		SaveState::SaveSlot(0, 0, 0);
		screenManager()->finishDialog(this, DR_CANCEL);
	}
	if (UIButton(GEN_ID, hlinear1, LARGE_BUTTON_WIDTH, 0, i->T("Load State"), ALIGN_LEFT)) {
		SaveState::LoadSlot(0, 0, 0);
		screenManager()->finishDialog(this, DR_CANCEL);
	}

	VLinear vlinear(dp_xres - 10, 160, 20);
	if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH + 20, 0, i->T("Continue"), ALIGN_RIGHT)) {
		screenManager()->finishDialog(this, DR_CANCEL);
	}

	if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH + 20, 0, i->T("Settings"), ALIGN_RIGHT)) {
		screenManager()->push(new SettingsScreen(), 0);
	}

	if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH + 20, 0, i->T("Back to Menu"), ALIGN_RIGHT)) {
		screenManager()->finishDialog(this, DR_OK);
	}

	/*
	if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), LARGE_BUTTON_WIDTH*2, 0, "Debug: Dump Next Frame", ALIGN_BOTTOMRIGHT)) {
		gpu->DumpNextFrame();
	}
	*/

	DrawWatermark();
	UIEnd();
}