Skip to content

genre_bg

Anthony Samms edited this page Jun 2, 2026 · 1 revision

The GenreBG class renders the coloured horizontal bar that fills the song-select background when a folder is open. It displays the folder's genre name in a title tab at the centre of the screen and handles three distinct visual phases: an entry animation, a steady-state fill that tracks the visible box range, and an exit animation that sweeps the bar toward the centre before fading out. Used by navigator.

Construction

GenreBG(string& text_name, optional<ray::Color> color, TextureIndex texture_index, float distance);
Parameter Description
text_name The folder/genre name displayed in the title tab. Font size is reduced automatically for long strings.
color Optional tint colour. When present, a colour-transform shader is loaded to recolour the bar texture.
texture_index Selects the genre-specific frame from the background texture atlas.
distance How far the bar slides in from the edge during the entry animation (clamped to screen width).

On construction all entry animations are started immediately.

Members

Member Type Description
shader ray::Shader Colour-transform shader; only loaded when color is provided
shader_loaded bool Whether the shader is active
name unique_ptr<OutlinedText> Outlined text for the genre/folder name shown in the title tab
texture_index TextureIndex Frame index into the background texture atlas
stretch MoveAnimation* Controls the vertical stretch of the bar during entry (cubic ease)
scale TextureResizeAnimation* Scales the bar from 0.9× to 1.0× during entry
move MoveAnimation* Slides the bar's right edge inward from distance to its resting position
fade FadeAnimation* Controls overall opacity; reused for entry fade-in and exit fade-out
move_left MoveAnimation* Created during exit: slides the bar's left edge toward centre
move_right MoveAnimation* Created during exit: slides the bar's right edge toward centre

Methods

void update(double current_ms, FolderBox* box);

Advances all active animations. Also calls box->update() if box is not null, keeping the centre folder box in sync during transitions.

void draw(float start_position, float end_position, FolderBox* folder);

Selects the correct draw path based on the current animation phase:

  • Entry (!is_finished()): calls draw_anim() — the bar scales and slides in around the folder box.
  • Exit (!is_complete()): calls draw_exit_anim() — the two bar halves sweep toward the centre.
  • Steady state: draws the bar spanning [start_position, end_position], handling the wrap-around case where start_position > end_position. Draws the title tab at screen centre only when centre is covered by the bar.

The colour-transform shader is applied (BeginShaderMode/EndShaderMode) around all background texture draws when shader_loaded is true.

void exit(float left_position, float right_position, FolderBox* center_box);

Begins the exit animation. Creates move_left and move_right to sweep the bar's edges toward the centre (x≈442 and x≈835 in unscaled coordinates). Replaces fade with a new fade-out that starts after the sweep completes. Also calls center_box->exit_box() and schedules a fade_in on it so the folder box becomes visible as the bar closes.

void fade_out();
void fade_in();

Replace fade with a 300 ms fade-out or fade-in animation and start it immediately. Used when the navigator switches between genres without a full exit/entry cycle.

bool is_finished();

Returns true when the entry move animation has completed — i.e. the bar has fully expanded and is now in steady state.

bool is_complete();

Returns true when both move_left and move_right have finished — i.e. the exit animation is done. Returns true immediately if no exit has been started.

Private methods

void draw_anim(FolderBox* box);

Draws the bar in its animated entry form centred on the box, applying the current scale and stretch values. Draws left edge, centre fill, and right edge textures, plus the title tab.

void draw_exit_anim(float start_position, float end_position, FolderBox* folder);

Draws the bar using the positions from move_left->attribute and move_right->attribute, then calls folder->draw(false) to render the folder box at its current state during the sweep.

Clone this wiki locally