Skip to content

Commit 3bda1a4

Browse files
committed
Add STYLE:bounce scroll type
Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 757b5c5 commit 3bda1a4

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

demo.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ typedef enum {
3737
SCROLL_NONE,
3838
SCROLL_SINE_WAVE,
3939
SCROLL_CLASSIC,
40-
SCROLL_ROLLER_3D
40+
SCROLL_ROLLER_3D,
41+
SCROLL_BOUNCE
4142
} ScrollStyle;
4243

4344
typedef struct {
@@ -1054,6 +1055,8 @@ static void apply_scroll_controls(DemoContext *ctx, float scroll_offset, float t
10541055
ctx->scroll_style = SCROLL_ROLLER_3D;
10551056
else if (strcmp(cc->data, "classic") == 0)
10561057
ctx->scroll_style = SCROLL_CLASSIC;
1058+
else if (strcmp(cc->data, "bounce") == 0)
1059+
ctx->scroll_style = SCROLL_BOUNCE;
10571060
break;
10581061

10591062
case 'C': /* COLOR */
@@ -1177,7 +1180,7 @@ void render_scroll_text(DemoContext *ctx)
11771180
ctx->scroll_offset += ctx->scroll_speed * delta_time;
11781181
}
11791182

1180-
if (ctx->scroll_style == SCROLL_SINE_WAVE || ctx->scroll_style == SCROLL_ROLLER_3D) {
1183+
if (ctx->scroll_style == SCROLL_SINE_WAVE || ctx->scroll_style == SCROLL_ROLLER_3D || ctx->scroll_style == SCROLL_BOUNCE) {
11811184
/* Glyph cache with metrics */
11821185
typedef struct {
11831186
SDL_Texture *tex;
@@ -1344,6 +1347,21 @@ void render_scroll_text(DemoContext *ctx)
13441347
SDL_RenderCopy(ctx->renderer, gcache[ch].tex, NULL, &glow);
13451348
SDL_SetTextureAlphaMod(gcache[ch].tex, 255);
13461349
SDL_SetTextureBlendMode(gcache[ch].tex, SDL_BLENDMODE_BLEND);
1350+
} else if (ctx->scroll_style == SCROLL_BOUNCE) {
1351+
/* Bouncing characters - each char bounces independently */
1352+
float bounce_phase = ctx->global_time * 4.0f + i * 0.5f;
1353+
/* Use abs(sin) to create bounce pattern (always positive) */
1354+
float bounce_height = fabsf(sinf(bounce_phase)) * 60.0f;
1355+
/* Add slight squash at bottom */
1356+
float squash = 1.0f - (1.0f - fabsf(sinf(bounce_phase))) * 0.15f;
1357+
1358+
int bounce_y = HEIGHT / 2 - (int)bounce_height;
1359+
int dw = gcache[ch].w;
1360+
int dh = (int)(gcache[ch].h * squash);
1361+
1362+
SDL_SetTextureColorMod(gcache[ch].tex, r, g, b);
1363+
SDL_Rect dest = {(int)char_x, bounce_y - dh / 2, dw, dh};
1364+
SDL_RenderCopy(ctx->renderer, gcache[ch].tex, NULL, &dest);
13471365
} else {
13481366
/* Simple sine wave */
13491367
SDL_SetTextureColorMod(gcache[ch].tex, r, g, b);

0 commit comments

Comments
 (0)