<?phpnamespace App\Mobile;use App\Audio\Player;use App\Core\WinZik;use App\Model\Equalizer;use App\Model\Id3Tag;use App\Model\Karaoke;use App\Model\Playlist;use App\Model\Text;use App\Scene\AboutScene;use JumPHP\Gui\Pointer;use JumPHP\Gui\Theme;use JumPHP\Gui\Widget;use JumPHP\Native\FilePicker;use JumPHP\Native\Native;use JumPHP\Renderer\Renderer;use JumPHP\Renderer\TextDrawer;/** * WinZik on a phone held upright: a music player of today, used with a finger. Three places (Lecteur, Playlist, Ajouter * de la musique), a bar of tabs at the bottom, a mini player over the list, bottom sheets instead of menus (a long press * or ⋮ on a song: Lire, Lire ensuite, Infos, Noter, Monter, Descendre, Retirer), the back button closes what is open. * Everything is drawn here, in dp (density-independent pixels: Theme::px), at least 48 dp for what a finger touches. * The state is WinZik's (the player, the play list, the stars, the lyrics): no second player. */final class MobileView extends Widget{ use YouTubePages; use LyricsPages; use MediaPages; use CloudPages; use CastPages; // cast: Plus > Caster sur la TV use LyricsWebPages; // lyrics: search on the Internet, unsynced lyrics, translations, the playlist's marks /** * Lecteur and Playlist (the tabs), then the pages over them (full screen, a back button): Ajouter (folders, also to * import lyrics or open a .FLS), YouTube, Spotify, Karaoké, Éditeur de paroles, Vidéo, Tag, Genre, Marketplace, * Options, Skins, Playlists (.FLS). */ public const SCREENS = ['player', 'playlist', 'add', 'youtube', 'spotify', 'karaoke', 'lyricsEdit', 'video', 'tag', 'genre', 'market', 'options', 'skins', 'library', 'cloud', 'cast', 'lyricsFind']; /** the pages of a whole screen (the tabs are hidden, the back button goes to the screen they came from) */ private const PAGES = ['add', 'youtube', 'spotify', 'karaoke', 'lyricsEdit', 'video', 'tag', 'genre', 'market', 'options', 'skins', 'library', 'cloud', 'cast', 'lyricsFind']; private const NAV = 68.0; // the bar of tabs private const ROW = 68.0; // a song of the list private const MINI = 64.0; // the mini player private const LONG_PRESS = 0.45; // seconds held still: the action sheet private const SLOP = 10.0; // dp moved: a drag, not a tap /** seconds without a finger on the karaoke's lyrics scrolled by hand: they follow the line sung again */ public const KARAOKE_FOLLOW = 4.0; public ?WinZik $wz = null; /** the dialogs of the application: fn (string $what): 'tag' (the tag editor), 'about' (the credits of 2001) */ public ?\Closure $open = null; /** tests: a phone of this size (dp) in the middle of the view; null: the whole widget is the screen */ public ?array $phone = null; public string $screen = 'player'; /** @var array<string, string> the screen each page goes back to */ private array $from = []; /** what the add screen picks: music (into the list), lyrics (.lrc / .lyr of the song playing), fls (a play list) */ public string $pickMode = 'music'; /** @var array<string, string> the text fields of the pages (id => text) */ public array $fields = []; /** the field being typed in ('' none: the phone's keyboard is closed) */ public string $field = ''; /** @var array<string, float> where each field of the page is (dp from the top of its content): it scrolls up to it */ private array $fieldY = []; /** the scroll region given to the hits drawn now (the rows of a page) */ private string $hitScroll = ''; /** the rows of a page drawn now: only those between these heights */ private float $clipTop = -INF; private float $clipBottom = INF; /** back() goes to the page before: it keeps where it came from and what it showed */ private bool $returning = false; /** rows drawn on white cards (pages), not on the sheet */ private bool $cards = false; /** the open bottom sheet ('' none): actions, more, info, eq, theme, options, about */ public string $sheet = ''; /** the song of the action / info sheet (a line of the list) */ public int $sheetLine = -1; /** 0..1: how far the sheet is up; it slides */ private float $sheetOpen = 0.0; private bool $sheetClosing = false; public string $search = ''; public bool $searching = false; /** the folder shown in the add screen ('' = the places of the phone) */ public string $folder = ''; /** @var array<string, float> scrolled dp of the list, of the folders, of a sheet */ public array $scroll = ['list' => 0.0, 'add' => 0.0]; /** @var array<string, float> their speed (dp / s) after a flick */ private array $speed = ['list' => 0.0, 'add' => 0.0]; /** @var array<string, float> how far each can scroll (from the last frame) */ private array $scrollMax = ['list' => 0.0, 'add' => 0.0]; /** @var list<array{0: float, 1: float, 2: float, 3: float, 4: string, 5: mixed, 6: string}> x, y, w, h, id, data, scroll region */ private array $hits = []; /** the finger: what it pressed, where, since when */ private ?array $press = null; private float $clock = 0.0; /** while dragging the position / the volume: where it would go (0..1) */ private ?float $seekAt = null; private int $volumeBefore = 0; /** set when the user acts (Répéter: a song changed by the user is not repeated) */ public bool $acted = false; /** the long press opened a sheet (the finger lifting must not tap what is under it) */ private bool $longDone = false; // the frame ----------------------------------------------------------------------------------------------------- private float $s = 1.0; // pixels per dp private float $ox = 0.0; // the screen's top-left (pixels) private float $oy = 0.0; public float $W = 390.0; // the screen (dp) public float $H = 844.0; private ?Theme $t = null; private ?Renderer $r = null; private ?Icons $icons = null; /** @var array<string, mixed> */ private array $c = MobileTheme::THEMES['givre']; /** the screen drawn turned a quarter (the karaoke in landscape: the phone held sideways, the app stays upright) */ private bool $turned = false; /** @var array{0: int, 1: int} the size of the turned texture (pixels) */ private array $turnSize = [0, 0]; public function focusable(): bool { return true; } public function wantsText(): bool { return $this->searching || $this->field !== ''; } protected function content(Theme $t, float $maxWidth, string $breakpoint): array { return [0, 0]; } // what the tests and the form use --------------------------------------------------------------------------- /** The middle of something touchable (view pixels), from the last frame: [x, y], null when not on screen. */ public function at(string $id, mixed $data = null): ?array { foreach (array_reverse($this->hits) as [$x, $y, $w, $h, $hid, $hdata]) { if ($hid === $id && ($data === null || $hdata === $data)) { [$cx, $cy] = [$x + $w / 2, $y + $h / 2]; if ($this->turned) { // a point of the turned screen: back to the upright one [$cx, $cy] = [$this->W - $cy, $cx]; } return [$this->ox + $cx * $this->s, $this->oy + $cy * $this->s]; } } return null; } /** @return list<string> the ids touchable now (tests) */ public function touchable(): array { return array_values(array_unique(array_map(fn (array $h) => $h[4], $this->hits))); } /** @return array{0: float, 1: float, 2: float, 3: float} the phone's screen in view pixels */ public function screenRect(): array { return [$this->ox, $this->oy, $this->W * $this->s, $this->H * $this->s]; } public function repeat(): bool { return (bool)($this->wz?->ui['mobile']['repeat'] ?? false); } public function themeId(): string { $id = (string)($this->wz?->ui['mobile']['theme'] ?? 'givre'); return isset(MobileTheme::THEMES[$id]) ? $id : 'givre'; } public function go(string $screen): void { if (!in_array($screen, self::SCREENS, true)) { return; } if (in_array($screen, self::PAGES, true) && $this->screen !== $screen && !$this->returning) { // a page remembers where it came from (a page opened from a page goes back to it) $this->from[$screen] = $this->screen; $this->scroll[$screen === 'add' ? 'add' : 'page:' . $screen] = 0.0; $this->enterPage($screen); } if ($screen === 'add' && $this->screen !== 'add' && !in_array($this->pickMode, ['lyrics', 'fls'], true)) { $this->pickMode = 'music'; } $leaving = $this->screen; $this->screen = $screen; $this->searching = $this->searching && $screen === 'playlist'; $this->field = ''; $this->press = null; // the screen stays lit while the lyrics or the film are watched $watch = in_array($screen, ['karaoke', 'video', 'lyricsEdit'], true); if ($watch !== in_array($leaving, ['karaoke', 'video', 'lyricsEdit'], true)) { $this->form?->engineOrNull()?->device()->keepAwake($watch); } } /** A page opens: what it shows is made ready (its fields, its list). */ private function enterPage(string $screen): void { match ($screen) { 'youtube' => $this->enterYouTube(), 'spotify' => $this->enterSpotify(), 'karaoke' => $this->enterKaraoke(), 'lyricsEdit' => $this->enterEditor(), 'video' => $this->enterVideo(), 'tag' => $this->enterTag(), 'market' => $this->enterMarket(), 'options' => $this->enterOptions(), 'library' => $this->enterLibrary(), 'cloud' => $this->enterCloud(), 'cast' => $this->enterCast(), 'lyricsFind' => $this->enterLyricsFind(), default => null, }; } public function isPage(): bool { return in_array($this->screen, self::PAGES, true); } public function openSheet(string $sheet, int $line = -1): void { $this->sheet = $sheet; $this->sheetLine = $line; $this->sheetClosing = false; $this->searching = false; $this->press = null; } public function closeSheet(): void { if ($this->sheet !== '') { $this->sheetClosing = true; } } /** Android's back button (Escape): the keyboard, the sheet, the add screen, the list, in that order. */ public function back(): bool { if ($this->searching) { $this->searching = false; return true; } if ($this->field !== '') { $this->field = ''; return true; } if ($this->sheet !== '' && !$this->sheetClosing) { $this->closeSheet(); return true; } if ($this->isPage()) { $to = $this->from[$this->screen] ?? 'player'; unset($this->from[$this->screen]); if ($this->screen === 'add') { $this->pickMode = 'music'; } $this->returning = true; $this->go($to === $this->screen ? 'player' : $to); $this->returning = false; return true; } if ($this->screen !== 'player') { $this->go('player'); return true; } return false; } // a frame ---------------------------------------------------------------------------------------------------- public function update(float $dt): void { $this->clock += $dt; $this->updateKaraoke($dt); $this->updateVideo($dt); $this->cloudSyncing = max(0.0, $this->cloudSyncing - $dt); $this->updateFollow($dt); // the sheet slides up / down if ($this->sheet !== '') { $this->sheetOpen = $this->sheetClosing ? max(0.0, $this->sheetOpen - $dt * 6) : min(1.0, $this->sheetOpen + $dt * 6); if ($this->sheetClosing && $this->sheetOpen <= 0) { $this->sheet = ''; $this->sheetClosing = false; $this->sheetLine = -1; } } // a flick goes on, slower and slower foreach ($this->speed as $key => $v) { if ($v == 0 || ($this->press !== null && $this->press['scroll'] === $key)) { continue; } $this->scroll[$key] = max(0.0, min($this->scrollMax[$key] ?? 0.0, $this->scroll[$key] + $v * $dt)); $v *= exp(-3.2 * $dt); $this->speed[$key] = abs($v) < 8 || $this->scroll[$key] <= 0 || $this->scroll[$key] >= ($this->scrollMax[$key] ?? 0) ? 0.0 : $v; } // held still on a song: its sheet $p = $this->press; if ($p !== null && !$p['moved'] && !$this->longDone && in_array($p['id'], ['row', 'act-row', 'cloudRow'], true) && $this->clock - $p['since'] >= self::LONG_PRESS) { $this->longDone = true; $this->press = null; $this->form?->engineOrNull()?->device()->vibrate(25); $this->acted = true; if ($p['id'] === 'cloudRow') { $this->cloudEntry = (string)$p['data']; $this->openSheet('cloudActions'); } else { $this->openSheet('actions', (int)$p['data']); } } } // the finger -------------------------------------------------------------------------------------------------- /** @return array{0: float, 1: float} a point of the view in dp of the screen (of the turned screen when it is turned) */ private function local(Pointer $p): array { $x = ($p->x - $this->ox) / $this->s; $y = ($p->y - $this->oy) / $this->s; return $this->turned ? [$y, $this->W - $x] : [$x, $y]; } /** whether the screen is drawn turned a quarter now (tests) */ public function turned(): bool { return $this->turned; } /** @return array{0: string, 1: mixed, 2: string, 3: array}|null the thing under a point (the last drawn wins) */ private function hitAt(float $x, float $y): ?array { foreach (array_reverse($this->hits) as $h) { if ($x >= $h[0] && $x < $h[0] + $h[2] && $y >= $h[1] && $y < $h[1] + $h[3]) { return [$h[4], $h[5], $h[6], $h]; } } return null; } public function pointerDown(Pointer $p): void { [$x, $y] = $this->local($p); $hit = $this->hitAt($x, $y); $this->longDone = false; // a touch anywhere but in the field typed in closes the phone's keyboard (what was typed stays), and still does // what it does there (a result tapped plays, a list dragged scrolls) $id = $hit[0] ?? ''; if ($this->searching && $id !== 'search' && $id !== 'searchClear') { $this->searching = false; } if ($this->field !== '' && !($id === 'field' && ($hit[1] ?? null) === $this->field)) { $this->field = ''; } if ($hit === null) { $this->press = null; return; } [$id, $data, $scroll, $rect] = $hit; $this->press = ['id' => $id, 'data' => $data, 'scroll' => $scroll, 'x' => $x, 'y' => $y, 'since' => $this->clock, 'moved' => false, 'from' => $scroll !== '' ? ($this->scroll[$scroll] ?? 0.0) : 0.0, 'rect' => $rect, 'track' => [[$this->clock, $y]]]; if (isset($this->scroll[$scroll])) { $this->speed[$scroll] = 0.0; // a finger stops a flick } if ($scroll === 'kara') { $this->karaokeDown(); } if (in_array($id, self::SLIDERS, true)) { $this->slide($id, $x, $rect, $y, $data); } } /** what follows the finger while it is down */ private const SLIDERS = ['seek', 'volume', 'vseek', 'band', 'preamp']; public function pointerDrag(Pointer $p): void { $press = &$this->press; if ($press === null) { return; } [$x, $y] = $this->local($p); if (in_array($press['id'], self::SLIDERS, true)) { $this->slide($press['id'], $x, $press['rect'], $y, $press['data']); return; } if (!$press['moved'] && (abs($y - $press['y']) > self::SLOP || abs($x - $press['x']) > self::SLOP)) { $press['moved'] = true; } if ($press['moved'] && $this->cloudPulling($press, $y)) { return; // the top of the cloud list pulled down: read again on release } if ($press['moved'] && $press['scroll'] === 'kara') { $this->karaokeDrag($press, $y); return; } if ($press['moved'] && $press['scroll'] !== '' && isset($this->scroll[$press['scroll']])) { $key = $press['scroll']; $this->scroll[$key] = max(0.0, min($this->scrollMax[$key] ?? 0.0, $press['from'] - ($y - $press['y']))); $key === 'list' && $this->listByHand(); $press['track'][] = [$this->clock, $y]; $press['track'] = array_slice($press['track'], -6); } } public function pointerUp(Pointer $p, bool $inside): void { $press = $this->press; $this->press = null; if ($press === null || $this->longDone) { $this->longDone = false; return; } [$x, $y] = $this->local($p); if (($press['id'] === 'seek' || $press['id'] === 'vseek') && $this->seekAt !== null && $this->wz !== null) { $this->wz->seek($this->seekAt * $this->wz->player->duration()); $this->seekAt = null; $this->acted = true; $this->videoUi = 3.0; return; } if (in_array($press['id'], ['volume', 'band', 'preamp'], true)) { if ($press['id'] !== 'volume') { $this->wz?->eqChanged(); } return; } if ($press['moved'] && $this->cloudPull > 0) { $this->cloudPulled(); return; } if ($press['scroll'] === 'kara' && ($press['moved'] || !empty($press['stopper']))) { // the lyrics flicked go on; a touch that only stopped them taps nothing $press['moved'] && $this->karaokeFlick($press, $y); return; } if ($press['moved']) { // a flick: the speed of the last moves goes on $key = $press['scroll']; if ($key !== '' && isset($this->speed[$key])) { $track = $press['track']; $track[] = [$this->clock, $y]; [$t0, $y0] = $track[0]; $span = $this->clock - $t0; $this->speed[$key] = $span > 0.001 ? max(-6000.0, min(6000.0, -($y - $y0) / $span)) : 0.0; } return; } $hit = $this->hitAt($x, $y); if ($hit !== null && $hit[0] === $press['id'] && $hit[1] === $press['data']) { $this->tap($press['id'], $press['data']); } } /** The position, the volume, a band of the equalizer follows the finger. @param array $rect the hit of the bar */ private function slide(string $id, float $x, array $rect, float $y = 0.0, mixed $data = null): void { $wz = $this->wz; if ($id === 'band' && $wz !== null) { // a band: up = louder, its middle 0 dB $pad = 10.0; $v = 1 - max(0.0, min(1.0, ($y - $rect[1] - $pad) / max(1.0, $rect[3] - 2 * $pad))); $wz->eq->bands[(int)$data] = \App\Model\Equalizer::clamp(round((\App\Model\Equalizer::MIN + $v * (\App\Model\Equalizer::MAX - \App\Model\Equalizer::MIN)) * 2) / 2); $wz->eq->on = true; $wz->ui['mobile']['eqPreset'] = 'Manuel'; $wz->eqChanged(); return; } $pad = 14.0; $v = max(0.0, min(1.0, ($x - $rect[0] - $pad) / max(1.0, $rect[2] - 2 * $pad))); if ($id === 'seek' || $id === 'vseek') { $this->seekAt = $v; $this->videoUi = 3.0; } elseif ($id === 'preamp' && $wz !== null) { $wz->eq->preamp = \App\Model\Equalizer::clamp(round((\App\Model\Equalizer::MIN + $v * (\App\Model\Equalizer::MAX - \App\Model\Equalizer::MIN)) * 2) / 2); $wz->eqChanged(); } elseif ($wz !== null) { $wz->setVolume((int)round($v * 100)); } } public function wheel(float $notches): bool { if ($this->screen === 'karaoke') { $this->karaokeWheel($notches); return true; } $key = $this->screen === 'add' ? 'add' : (isset($this->scroll['page:' . $this->screen]) ? 'page:' . $this->screen : 'list'); $this->scroll[$key] = max(0.0, min($this->scrollMax[$key] ?? 0.0, $this->scroll[$key] - $notches * 3 * self::ROW / 2)); $key === 'list' && $this->listByHand(); return true; } public function keys(Pointer $p): bool { if ($this->field !== '') { $id = $this->field; $text = $this->fields[$id] ?? ''; foreach ($p->text as $char) { $text .= $char; } if ($p->pressed(Pointer::BACKSPACE)) { $text = mb_substr($text, 0, max(0, mb_strlen($text) - 1)); } $enter = $p->pressed(Pointer::RETURN) || $p->pressed(Pointer::KP_ENTER); if ($enter && in_array($id, self::MULTILINE, true)) { $text .= "\n"; $enter = false; } $this->fields[$id] = $text; if ($enter) { $this->field = ''; $this->submit($id); } if ($p->pressed(Pointer::ESCAPE)) { $this->back(); } return true; } if ($this->searching) { foreach ($p->text as $char) { $this->search .= $char; $this->scroll['list'] = 0.0; } if ($p->pressed(Pointer::BACKSPACE)) { $this->search = mb_substr($this->search, 0, max(0, mb_strlen($this->search) - 1)); } if ($p->pressed(Pointer::RETURN) || $p->pressed(Pointer::KP_ENTER)) { $this->searching = false; } if ($p->pressed(Pointer::ESCAPE)) { $this->back(); } return true; } if ($p->pressed(Pointer::ESCAPE)) { $this->back(); return true; } if ($p->pressed(Pointer::SPACE) || in_array(' ', $p->text, true)) { $this->tap('play', null); return true; } return false; } /** What a tap does. */ public function tap(string $id, mixed $data): void { $wz = $this->wz; if ($wz === null) { return; } $this->acted = true; switch ($id) { case 'tab': $data === 'more' ? $this->openSheet('more') : $this->go((string)$data); break; case 'play': case 'miniPlay': $wz->togglePause(); break; case 'next': case 'miniNext': $wz->next(); break; case 'prev': // like every player: back to the start of the song, unless it just began $wz->player->position > 3 ? $wz->seek(0) : $wz->previous(); break; case 'shuffle': $wz->toggleShuffle(); $wz->notice($wz->playlist->shuffle ? 'Lecture aléatoire activée' : 'Lecture aléatoire désactivée', 2); break; case 'repeat': $wz->ui['mobile']['repeat'] = !$this->repeat(); $wz->touch(); $wz->notice($this->repeat() ? 'Répéter le morceau : activé' : 'Répéter le morceau : désactivé', 2); break; case 'mute': if ($wz->player->volume > 0) { $this->volumeBefore = $wz->player->volume; $wz->setVolume(0); } else { $wz->setVolume($this->volumeBefore > 0 ? $this->volumeBefore : 60); } break; case 'mini': $this->go('player'); break; case 'row': if ($wz->playlist->active === (int)$data && $wz->player->state === Player::PLAYING) { $this->go('player'); } else { $wz->playIndex((int)$data); } break; case 'rowMore': $this->openSheet('actions', (int)$data); break; case 'locate': $this->locatePlaying(); break; case 'headerMore': if ($this->screen === 'player') { $wz->playlist->current() !== null ? $this->openSheet('actions', $wz->playlist->active) : $this->openSheet('more'); } else { $this->openSheet($this->inCloudView() && ($this->cloud()?->signedIn() ?? false) ? 'cloudMenu' : 'playlistMenu'); } break; case 'add': case 'emptyAdd': $this->closeSheet(); $this->go('add'); break; case 'search': $this->searching = true; $this->form?->setFocus($this); break; case 'searchClear': $this->search = ''; $this->searching = false; break; case 'order': // the order of the list, the most liked first (stars, listens: the list itself), or by artist and album (shown so) if ($wz->byPreference() !== ($data === 'pref')) { $wz->togglePreferenceOrder(); } $wz->ui['mobile']['byArtist'] = $data === 'artist'; $wz->touch(); $this->scroll['list'] = 0.0; break; case 'veil': case 'sheetClose': $this->closeSheet(); break; case 'act': $this->action((string)$data); break; case 'star': $file = $wz->playlist->items[$this->sheetLine] ?? null; if ($file !== null) { $wz->rate($file, (int)$data); } break; case 'more': $this->openSheet((string)$data); break; case 'eqOn': $wz->eq->on = !$wz->eq->on; $wz->eqChanged(); break; case 'eqPreset': $wz->eq->preset((string)$data); $wz->eq->on = true; $wz->ui['mobile']['eqPreset'] = (string)$data; $wz->eqChanged(); break; case 'theme': $wz->ui['mobile']['theme'] = (string)$data; $wz->touch(); break; case 'opt': $key = (string)$data; $wz->options[$key] = !($wz->options[$key] ?? self::OPTIONS[$key][2]); $wz->touch(); break; case 'editTag': $this->closeSheet(); $this->tagLine = $this->sheetLine >= 0 ? $this->sheetLine : $wz->playlist->active; $this->go('tag'); break; case 'page': // a page: where the finger was (nothing under it), the keyboard closes break; case 'field': $this->field = (string)$data; $this->fields[$this->field] ??= ''; $this->form?->setFocus($this); $key = 'page:' . $this->screen; if (isset($this->fieldY[$this->field], $this->scroll[$key])) { // the field goes up, above the phone's keyboard $this->scroll[$key] = max(0.0, min($this->scrollMax[$key] ?? 0.0, $this->fieldY[$this->field] - 12)); } break; case 'goto': // a row of a sheet that opens a page $this->closeSheet(); if ($data === 'add') { $this->pickMode = 'music'; } $this->go((string)$data); break; case 'lyricsMenu': $this->openSheet('lyrics'); break; case 'lyricsBox': case 'karaokeOpen': if ($wz->lyrics !== null && !$wz->lyrics->isEmpty()) { $this->go('karaoke'); } elseif ($id === 'lyricsBox' && $wz->playlist->current() !== null) { $this->openLyricsFind(null); // « Pas de paroles · touchez pour en trouver »: the search } else { $this->openSheet('lyrics'); } break; case 'art': if ($wz->playingVideo()) { $this->go('video'); } break; case 'timeLeft': $wz->options['timeLeft'] = !($wz->options['timeLeft'] ?? false); $wz->notice(!empty($wz->options['timeLeft']) ? 'Compteur : temps restant' : 'Compteur : temps écoulé', 2); $wz->touch(); break; case 'eqAuto': $wz->eq->auto = !$wz->eq->auto; $wz->eqChanged(); break; case 'original': // the interface of 2001: the skinned windows (MainForm stays in it; its menu comes back here) $this->closeSheet(); $wz->options['phoneUi'] = 'original'; $wz->save(); ($this->open)('original'); break; case 'credits': $this->closeSheet(); ($this->open)('about'); break; case 'addBack': $this->back(); break; case 'place': case 'dir': $this->folder = (string)$data; $this->scroll['add'] = 0.0; break; case 'up': $parent = dirname($this->folder); $this->folder = $this->isPlace($this->folder) || $parent === $this->folder ? '' : $parent; $this->scroll['add'] = 0.0; break; case 'file': if ($this->pickMode !== 'music') { $this->pickFile((string)$data); break; } $n = $wz->addFiles([(string)$data]); $wz->notice($n > 0 ? 'Ajouté : ' . Text::baseName((string)$data) : 'Ce fichier ne se lit pas', 3); break; case 'addDir': $before = $wz->playlist->count(); $wz->addPaths([(string)$data]); $added = $wz->playlist->count() - $before; if ($added > 0) { $wz->notice($added . ' morceau(x) ajouté(s) à la playlist', 3); } break; case 'pick': if ($this->pickMode !== 'music') { $mode = $this->pickMode; FilePicker::open(['filters' => $mode === 'fls' ? ['Playlist WinZik' => ['fls']] : ['Paroles' => ['lrc', 'lyr']]])->then(function (mixed $file): void { $file = is_array($file) ? ($file[0] ?? null) : $file; if (is_string($file) && $file !== '') { $this->pickFile($file); } }, fn () => null); break; } FilePicker::open(['multiple' => true, 'filters' => ['Musique' => [...Playlist::AUDIO, ...Playlist::VIDEO]]])->then(function (mixed $files) use ($wz): void { $list = is_array($files) ? $files : ($files === null ? [] : [(string)$files]); $n = $wz->addFiles(array_map('strval', $list)); if ($n > 0) { $wz->notice($n . ' morceau(x) ajouté(s) à la playlist', 3); } }, fn () => null); break; default: $this->tapCloud($id, $data) || $this->tapCast($id, $data) || $this->tapYouTube($id, $data) || $this->tapLyrics($id, $data) || $this->tapMedia($id, $data); } } /** Spotify: where one gets one's own identifiers, the address Spotify sends the browser back to (SpotifyAccount) */ public const SPOTIFY_DASHBOARD = 'https://developer.spotify.com/dashboard'; public const SPOTIFY_REDIRECT = 'http://127.0.0.1:8888/callback'; /** the fields where Entrée goes to the next line */ private const MULTILINE = ['edText']; /** Entrée in a field. */ private function submit(string $id): void { $this->submitCloud($id) || $this->submitCast($id) || $this->submitYouTube($id) || $this->submitLyrics($id) || $this->submitMedia($id); } /** An entry of the action sheet. */ private function action(string $what): void { $wz = $this->wz; $line = $this->sheetLine; if ($wz === null || !isset($wz->playlist->items[$line])) { $this->closeSheet(); return; } $active = $wz->playlist->active; switch ($what) { case 'play': $wz->playIndex($line); $this->closeSheet(); break; case 'next': // right after the song playing if ($line !== $active) { $wz->moveLine($line, $line > $active ? $active + 1 : $active); $wz->notice('Lu juste après le morceau en cours', 2); } $this->closeSheet(); break; case 'info': $this->openSheet('info', $line); break; case 'tag': $this->closeSheet(); $this->tagLine = $line; $this->go('tag'); break; case 'up': case 'down': $to = $what === 'up' ? $line - 1 : $line + 1; if ($to >= 0 && $to < $wz->playlist->count()) { $wz->moveLine($line, $to); $this->sheetLine = $to; } break; case 'cloudPut': $this->cloudPut($line); break; case 'remove': $name = $this->titleOf($line)[0]; $wz->removeLines([$line]); $wz->notice('Retiré de la playlist : ' . $name, 3); $this->closeSheet(); break; } } /** The options that mean something on a phone: key => [label, explanation, default]. */ public const OPTIONS = [ 'lrclib' => ['Paroles synchronisées', 'Cherchées sur LRCLIB pour chaque morceau qui n\'en a pas', true], 'marketLyrics' => ['Paroles de la marketplace', 'Celles partagées par les autres utilisateurs de WinZik', true], 'skipBlanks' => ['Sauter les blancs et les intros', 'Le silence au début et à la fin, les intros repérées', true], 'autoLyrics' => ['Paroles de l\'ancien site', 'Cherchées à chaque nouveau morceau (archive de 2001)', false], 'timeLeft' => ['Temps restant', 'Le compteur du Lecteur décompte la fin du morceau', false], 'splash' => ['Image au démarrage', 'L\'écran de WinZik pendant le chargement', true], ]; // the songs ---------------------------------------------------------------------------------------------------- /** @return array{0: string, 1: string, 2: float} title, artist, length of a line of the list */ public function titleOf(int $line): array { $file = $this->wz?->playlist->items[$line] ?? null; if ($file === null) { return ['', '', 0.0]; } if (\App\Cloud\Cloud::isPseudo($file)) { // a song of the cloud not on the phone yet: what the cloud says of it $e = $this->wz->cloud()?->entryOfItem($file) ?? []; return [(string)($e['title'] ?? 'Morceau du cloud'), (string)($e['artist'] ?? ''), (float)($e['duration'] ?? 0)]; } [$tag, $info] = $this->wz->describeLater($file); $title = trim($tag->title) !== '' ? trim($tag->title) : preg_replace('/\.[a-z0-9]{2,4}$/i', '', Text::baseName($file)); return [(string)$title, trim($tag->artist), $info->duration]; } /** @return list<int> the lines shown in the list (the search applied) */ public function shownLines(): array { $wz = $this->wz; if ($wz === null) { return []; } $lines = array_keys($wz->playlist->items); if ($wz->playsLyricsOnly()) { // lyrics: « Seulement avec paroles »: the songs that will play $lines = array_values(array_filter($lines, fn (int $i): bool => $wz->hasLyrics((string)$wz->playlist->items[$i]))); } if ($this->byArtist()) { // by artist, then album, then title (the artists and albums of the play list of the computer) $keys = []; foreach ($lines as $i) { [$title, $artist] = $this->titleOf($i); [$tag] = $wz->describeLater((string)$wz->playlist->items[$i]); $keys[$i] = [$artist === '' ? "\u{10FFFF}" : self::fold($artist), self::fold(trim($tag->album)), self::fold($title), $i]; } usort($lines, fn (int $a, int $b) => $keys[$a] <=> $keys[$b]); } $q = self::fold($this->search); if ($q === '') { return $lines; } return array_values(array_filter($lines, function (int $i) use ($q): bool { [$title, $artist] = $this->titleOf($i); return str_contains(self::fold($title . ' ' . $artist . ' ' . Text::baseName((string)$this->wz->playlist->items[$i])), $q); })); } public function byArtist(): bool { $wz = $this->wz; return $wz !== null && (bool)($wz->ui['mobile']['byArtist'] ?? false) && !$wz->byPreference(); } /** lower case, without accents: "Éte" finds "été" */ private static function fold(string $text): string { return Text::fold($text); } public static function clock(float $seconds): string { $seconds = max(0, (int)floor($seconds)); return $seconds >= 3600 ? sprintf('%d:%02d:%02d', intdiv($seconds, 3600), intdiv($seconds % 3600, 60), $seconds % 60) : sprintf('%d:%02d', intdiv($seconds, 60), $seconds % 60); } // the places of the phone --------------------------------------------------------------------------------------- /** @return list<array{0: string, 1: string, 2: string}> label, folder, icon */ public function places(): array { $root = rtrim((string)(getenv('EXTERNAL_STORAGE') ?: '/storage/emulated/0'), '/'); $list = []; foreach ([['Musique', "$root/Music"], ['Téléchargements', "$root/Download"], ['Stockage du téléphone', $root], ['Carte SD', '/sdcard']] as [$label, $dir]) { if (@is_dir($dir) && !in_array(realpath($dir), array_map(fn ($p) => realpath($p[1]), $list), true)) { $list[] = [$label, $dir, 'folder']; } } $music = \App\Media\MediaDirs::user('MUSIC'); if (@is_dir($music) && !in_array(realpath($music), array_map(fn ($p) => realpath($p[1]), $list), true)) { $list[] = ['Musique', $music, 'folder']; } if ($this->wz !== null) { $list[] = ['Morceaux de démonstration', $this->wz->path('assets/music'), 'note']; } return $list; } private function isPlace(string $dir): bool { foreach ($this->places() as [, $place]) { if (rtrim($place, '/') === rtrim($dir, '/')) { return true; } } return false; } /** @return array{0: list<string>, 1: list<string>, 2: bool} the sub-folders and the songs of a folder, whether it could be read */ public function listFolder(string $dir): array { $entries = @scandir($dir); if ($entries === false) { return [[], [], false]; } $dirs = $files = []; foreach ($entries as $e) { if ($e === '.' || $e === '..' || $e[0] === '.') { continue; } $path = rtrim($dir, '/') . '/' . $e; if (@is_dir($path)) { $dirs[] = $path; } elseif ($this->pickMode === 'music' ? Playlist::isMedia($e) : in_array(Text::extension($e), $this->pickMode === 'fls' ? ['fls'] : ['lrc', 'lyr'], true)) { $files[] = $path; } } natcasesort($dirs); natcasesort($files); return [array_values($dirs), array_values($files), true]; } // drawing helpers (dp) ------------------------------------------------------------------------------------------ private function hit(float $x, float $y, float $w, float $h, string $id, mixed $data = null, string $scroll = ''): void { $this->hits[] = [$x, $y, $w, $h, $id, $data, $scroll !== '' ? $scroll : $this->hitScroll]; } private function pressed(string $id, mixed $data = null): bool { return $this->press !== null && !$this->press['moved'] && $this->press['id'] === $id && $this->press['data'] === $data; } private function col(string $name): string|array { return $this->c[$name] ?? '#ff00ff'; } /** a colour with alpha: '#rrggbb' + 0..255 */ private static function alpha(string|array $color, int $a): array { $c = \JumPHP\Util\Color::of($color); return [$c->r, $c->g, $c->b, $a]; } private static function mix(string|array $a, string|array $b, float $t): array { $ca = \JumPHP\Util\Color::of($a); $cb = \JumPHP\Util\Color::of($b); return [(int)round($ca->r + ($cb->r - $ca->r) * $t), (int)round($ca->g + ($cb->g - $ca->g) * $t), (int)round($ca->b + ($cb->b - $ca->b) * $t), 255]; } private function rect(float $x, float $y, float $w, float $h, string|array $color): void { $this->r->fillRect($this->ox + $x * $this->s, $this->oy + $y * $this->s, $w * $this->s, $h * $this->s, $color); } private function box(float $x, float $y, float $w, float $h, string|array $color, float $radius): void { $this->t->box($this->r, round($this->ox + $x * $this->s), round($this->oy + $y * $this->s), round($w * $this->s), round($h * $this->s), $color, round($radius * $this->s)); } private function circle(float $cx, float $cy, float $radius, string|array $color): void { $this->box($cx - $radius, $cy - $radius, 2 * $radius, 2 * $radius, $color, $radius); } /** a soft shadow under a box */ private function shadow(float $x, float $y, float $w, float $h, float $radius, int $strength = 18): void { $this->box($x - 1, $y + 3, $w + 2, $h + 2, [10, 40, 80, (int)($strength * 0.6)], $radius + 1); $this->box($x, $y + 1.5, $w, $h, [10, 40, 80, $strength], $radius); } private function icon(string $name, float $x, float $y, float $size, string|array $color): void { if ($name === '') { return; // a button whose picture is drawn by its page (a spinner) } $this->icons?->draw($this->r, $name, $this->ox + $x * $this->s, $this->oy + $y * $this->s, $size * $this->s, \JumPHP\Util\Color::of($color)); } private function font(float $size, bool $bold = false): TextDrawer { // the theme scales by its own factor: the text follows this view's (a phone's density, a test's phone frame) $theme = $this->t->scale > 0 ? $this->t->scale : 1.0; return $this->t->font($size * $this->s / $theme, $bold); } public function textWidth(string $text, float $size, bool $bold = false): float { return $this->t === null ? mb_strlen($text) * $size * 0.5 : $this->font($size, $bold)->width($text) / $this->s; } /** The text cut with … to fit $max dp. */ private function fit(string $text, float $size, bool $bold, float $max): string { if ($max <= 0 || $this->textWidth($text, $size, $bold) <= $max) { return $text; } $chars = mb_str_split($text) ?: []; $lo = 0; $hi = count($chars); while ($lo < $hi) { $mid = intdiv($lo + $hi + 1, 2); if ($this->textWidth(rtrim(implode('', array_slice($chars, 0, $mid))) . '…', $size, $bold) <= $max) { $lo = $mid; } else { $hi = $mid - 1; } } return rtrim(implode('', array_slice($chars, 0, $lo))) . '…'; } /** A text whose middle is at $cy (dp). */ private function text(string $text, float $x, float $cy, float $size, string|array $color, bool $bold = false, string $align = 'left', float $max = 0): void { if ($text === '') { return; } $font = $this->font($size, $bold); $text = $this->fit($text, $size, $bold, $max); $font->draw($this->r, $text, round($this->ox + $x * $this->s), round($this->oy + $cy * $this->s - $font->height() / 2), 1, $color, $align); } /** @return list<string> the text in lines of at most $max dp */ private function wrap(string $text, float $size, bool $bold, float $max): array { $lines = []; $line = ''; foreach (preg_split('/\s+/u', trim($text)) ?: [] as $word) { $try = $line === '' ? $word : "$line $word"; if ($line !== '' && $this->textWidth($try, $size, $bold) > $max) { $lines[] = $line; $line = $word; } else { $line = $try; } } if ($line !== '') { $lines[] = $line; } return $lines; } /** A box whose colour goes from $top to $bottom, its corners round. */ private function gradientBox(float $x, float $y, float $w, float $h, string|array $top, string|array $bottom, float $radius): void { $s = $this->s; $px = $this->ox + $x * $s; $py = $this->oy + $y * $s; $pw = $w * $s; $ph = $h * $s; $rr = $radius * $s; for ($yy = 0.0; $yy < $ph; $yy += $hh) { $hh = min($yy < $rr || $yy > $ph - $rr ? 1.0 : 3.0, $ph - $yy); $mid = $yy + $hh / 2; $inset = 0.0; $d = $mid < $rr ? $rr - $mid : ($mid > $ph - $rr ? $mid - ($ph - $rr) : 0.0); if ($d > 0) { $inset = $rr - sqrt(max(0.0, $rr * $rr - $d * $d)); } $this->r->fillRect($px + $inset, $py + $yy, $pw - 2 * $inset, $hh, self::mix($top, $bottom, $mid / max(1, $ph))); } } /** a loader: 8 dots in a circle, the bright one going round */ private function spinner(float $cx, float $cy, float $radius, string|array|null $color = null): void { $color ??= $this->col('accent'); $lit = (int)floor(fmod($this->clock, 0.8) / 0.1); for ($i = 0; $i < 8; $i++) { $a = $i * M_PI / 4 - M_PI / 2; $k = (8 + $i - $lit) % 8; $this->circle($cx + cos($a) * $radius, $cy + sin($a) * $radius, 2.4, self::alpha($color, max(40, 255 - $k * 30))); } } /** * A text field: its label, its box (the text, a caret while typed in; a secret shown as dots). * @param array $row ['input', label, field id, placeholder, secret] */ private function drawInput(array $row, float $y): void { $W = $this->W; [, $label, $id, $placeholder] = $row; $secret = (bool)($row[4] ?? false); $this->fieldY[$id] = $y - ($this->pageTop - ($this->scroll['page:' . $this->screen] ?? 0.0)); $this->text((string)$label, 24, $y + 11, 13, $this->col('muted'), true, 'left', $W - 48); $bh = $this->inputHeight($row); $by = $y + 22; $editing = $this->field === $id; $this->box(16, $by, $W - 32, $bh, $editing ? $this->col('accent') : $this->col('line'), 16); $this->box(16 + ($editing ? 2 : 1), $by + ($editing ? 2 : 1), $W - 32 - ($editing ? 4 : 2), $bh - ($editing ? 4 : 2), $this->col('surface'), 15); $text = $this->fields[$id] ?? ''; $caret = $editing && fmod($this->clock, 1.0) < 0.55 ? '|' : ''; $max = $W - 64; if (in_array($id, self::MULTILINE, true)) { $lines = explode("\n", $text); $rows = (int)floor(($bh - 24) / 22); $shown = array_slice($lines, max(0, count($lines) - $rows)); if ($text === '' && !$editing) { $this->text((string)$placeholder, 32, $by + 24, 15, $this->col('muted'), false, 'left', $max); } foreach ($shown as $k => $l) { $last = $k === count($shown) - 1; $this->text($l . ($last ? $caret : ''), 32, $by + 24 + $k * 22, 15, $this->col('text'), false, 'left', $max); } } else { $shown = $secret && $text !== '' ? str_repeat('•', min(40, mb_strlen($text))) : $text; // the end of a long text: what is being typed stays in sight while ($shown !== '' && $this->textWidth('…' . $shown . $caret, 15) > $max) { $shown = mb_substr($shown, 1); $cut = true; } $shown = (isset($cut) ? '…' : '') . $shown; if ($text === '' && !$editing) { $this->text((string)$placeholder, 32, $by + $bh / 2, 15, $this->col('muted'), false, 'left', $max); } else { $this->text($shown . $caret, 32, $by + $bh / 2, 15, $this->col('text'), false, 'left'); } } $this->hit(16, $by, $W - 32, $bh, 'field', $id); } /** the top of the page drawn now (its rows scroll under it) */ private float $pageTop = 64.0; /** what is kept at the bottom of the page drawn now (its buttons) */ private float $pageFooter = 0.0; /** * A page: a header with a back button, rows that the finger scrolls (on cards), and room kept at the bottom for its * own buttons (drawn by the page after this). * @param list<array> $rows the rows of the sheets (and input, section, note, chipset, result, job...) * @param list<array{0: string, 1: string}> $buttons icon, id at the right of the header */ private function renderPage(string $title, string $sub, array $rows, array $buttons = [], float $footer = 0.0, bool $dark = false): void { $W = $this->W; $key = 'page:' . $this->screen; $this->scroll[$key] ??= 0.0; $this->speed[$key] ??= 0.0; $top = $this->pageTop = 72.0; $this->pageFooter = $footer; $bottom = $this->H - $footer; $total = 8.0 + 24; foreach ($rows as $row) { $total += $this->rowHeight($row); } $this->scrollMax[$key] = max(0.0, $total - ($bottom - $top)); $this->scroll[$key] = min($this->scroll[$key], $this->scrollMax[$key]); $off = $this->scroll[$key]; $this->hit(0, $top, $W, $bottom - $top, 'page', null, $key); $first = count($this->hits); [$this->clipTop, $this->clipBottom] = [$top - 8, $bottom + 8]; $this->cards = true; $this->hitScroll = $key; $this->drawCards($rows, $top + 8 - $off); $this->drawSheet($rows, $top + 8 - $off); $this->hitScroll = ''; $this->cards = false; [$this->clipTop, $this->clipBottom] = [-INF, INF]; // what scrolled under the header or the buttons can not be touched there $this->hits = [...array_slice($this->hits, 0, $first), ...array_values(array_filter(array_slice($this->hits, $first), fn (array $h) => $h[1] + $h[3] / 2 > $top && $h[1] + $h[3] / 2 < $bottom))]; if ($this->scrollMax[$key] > 0 && ($this->press !== null || ($this->speed[$key] ?? 0) != 0)) { $h = $bottom - $top; $bh = max(40.0, $h * $h / ($h + $this->scrollMax[$key])); $this->box($W - 6, $top + ($h - $bh) * $off / $this->scrollMax[$key], 3, $bh, self::alpha($this->col('muted'), 120), 1.5); } if (!$dark) { $this->paintBackground(0, $top); if ($footer > 0) { $this->paintBackground($bottom, $this->H); } } $this->header($title, $sub, $buttons, true); } // render --------------------------------------------------------------------------------------------------------- public function render(Renderer $r, Theme $t): void { $this->r = $r; $this->t = $t; $this->icons ??= new Icons($this->form?->sdlOrNull()); $this->c = MobileTheme::get($this->themeId()); $this->s = max(0.5, $t->scale); if ($this->phone === null && \JumPHP\Kernel\Platform::isPhoneApp()) { // a phone gives its screen in real pixels (1080 wide for ~400 dp): the dp from its width, as Android does $this->s = max($this->s, min(4.0, $this->w / 392)); } if ($this->phone !== null) { // tests: the phone's screen in the middle of the view, the rest dark [$pw, $ph] = $this->phone; $this->s = min($t->scale, $this->w / $pw, $this->h / $ph); $this->W = $pw; $this->H = $ph; $this->ox = round($this->x + ($this->w - $pw * $this->s) / 2); $this->oy = round($this->y + ($this->h - $ph * $this->s) / 2); $r->fillRect($this->x, $this->y, $this->w, $this->h, '#1b2430'); } else { $this->W = $this->w / $this->s; $this->H = $this->h / $this->s; $this->ox = $this->x; $this->oy = $this->y; } $this->hits = []; $this->turned = false; if ($this->wz === null) { return; } if ($this->screen === 'karaoke' && $this->karaokeLandscape() && ($sdl = $this->form?->sdlOrNull()) !== null) { $this->renderTurned($r, $sdl); return; } // the background: the frost of Givre, light at the top $this->paintBackground(0, $this->H); match ($this->screen) { 'playlist' => $this->renderPlaylist(), 'add' => $this->renderAdd(), 'youtube' => $this->renderYouTube(), 'spotify' => $this->renderSpotify(), 'karaoke' => $this->renderKaraoke(), 'lyricsEdit' => $this->renderEditor(), 'video' => $this->renderVideo(), 'tag' => $this->renderTag(), 'genre' => $this->renderGenre(), 'market' => $this->renderMarket(), 'options' => $this->renderOptions(), 'skins' => $this->renderSkins(), 'library' => $this->renderLibrary(), 'cloud' => $this->renderCloud(), 'cast' => $this->renderCast(), 'lyricsFind' => $this->renderLyricsFind(), default => $this->renderPlayer(), }; if (!$this->isPage()) { $this->renderNav(); } $this->renderToast(); if ($this->sheet !== '') { $this->renderSheet(); } } /** * The karaoke in landscape: drawn in a texture as wide as the screen is tall (the screen's sizes swapped), copied * turned a quarter (like Desktop::renderTurned()); its hits stay in the turned screen's dp, local() / at() turn them. */ private function renderTurned(Renderer $r, \JumPHP\Renderer\Sdl $sdl): void { [$ox, $oy, $W, $H, $s] = [$this->ox, $this->oy, $this->W, $this->H, $this->s]; [$tw, $th] = [max(1, (int)round($H * $s)), max(1, (int)round($W * $s))]; if ($this->turnSize !== [$tw, $th] || !$sdl->hasTexture('mobile-turned')) { $sdl->createTexture('mobile-turned', $tw, $th); $this->turnSize = [$tw, $th]; } $texture = $sdl->getTexture('mobile-turned')['texture']; [$tx, $ty] = $r->translation(); $before = $r->setTarget($texture); $r->translate(-$tx, -$ty); $r->clear('#000000'); [$this->ox, $this->oy, $this->W, $this->H] = [0.0, 0.0, $H, $W]; $this->turned = true; try { $this->renderKaraoke(); $this->renderToast(); if ($this->sheet !== '') { $this->renderSheet(); } } finally { [$this->ox, $this->oy, $this->W, $this->H] = [$ox, $oy, $W, $H]; $r->translate($tx, $ty); $r->setTarget($before); } $r->fillRect($ox, $oy, $W * $s, $H * $s, '#000000'); $r->copy($texture, null, $ox + ($W * $s - $tw) / 2, $oy + ($H * $s - $th) / 2, $tw, $th, false, false, 90.0); } /** The background (the frost of Givre, light at the top) between two heights: it also hides what scrolled there. */ private function paintBackground(float $from, float $to): void { $bands = 48; $band = $this->H / $bands; for ($i = max(0, (int)floor($from / $band)); $i < $bands; $i++) { $y0 = max($from, $band * $i); $y1 = min($to, $band * ($i + 1)); if ($y0 >= $to) { break; } $this->rect(0, $y0, $this->W, $y1 - $y0 + 0.6, self::mix($this->c['top'], $this->c['bottom'], $i / ($bands - 1))); } } /** the top of the screen: a title, buttons at the right */ private function header(string $title, string $sub, array $buttons, bool $back = false): float { $h = 64.0; $x = 20.0; if ($back) { $this->roundButton(8, 8, 48, 'back', 'addBack', null, $this->col('text')); $x = 64.0; } $right = $this->W - 8; foreach (array_reverse($buttons) as [$icon, $id]) { $right -= 48; $this->roundButton($right, 8, 48, $icon, $id, null, $this->col('text')); } if ($sub === '') { $this->text($title, $x, 32, $back ? 20 : 26, $this->col('text'), true, 'left', $right - $x - 8); } else { $this->text($title, $x, 25, 24, $this->col('text'), true, 'left', $right - $x - 8); $this->text($sub, $x, 50, 13, $this->col('muted'), false, 'left', $right - $x - 8); } return $h; } /** a round button with an icon (48 dp: a finger) */ private function roundButton(float $x, float $y, float $size, string $icon, string $id, mixed $data, string|array $color, string|array|null $fill = null, float $iconSize = 24): void { if ($fill !== null) { $this->circle($x + $size / 2, $y + $size / 2, $size / 2, $fill); } if ($this->pressed($id, $data)) { $this->circle($x + $size / 2, $y + $size / 2, $size / 2, self::alpha($this->col('accent'), 40)); } $this->icon($icon, $x + ($size - $iconSize) / 2, $y + ($size - $iconSize) / 2, $iconSize, $color); $this->hit($x, $y, $size, $size, $id, $data); } /** the bar of tabs */ private function renderNav(): void { $y = $this->H - self::NAV; $this->rect(0, $y, $this->W, self::NAV, $this->col('surface')); $this->rect(0, $y, $this->W, 1, $this->col('line')); $tabs = [['player', 'note', 'Lecteur'], ['playlist', 'list', 'Playlist'], ['more', 'more', 'Plus']]; $w = $this->W / count($tabs); foreach ($tabs as $i => [$id, $icon, $label]) { $on = $id === $this->screen || ($id === 'more' && in_array($this->sheet, ['more', 'eq', 'theme', 'about', 'lyrics'], true)); $cx = $w * $i + $w / 2; if ($on) { $this->box($cx - 30, $y + 9, 60, 30, $this->col('soft'), 15); } $color = $on ? $this->col('accent') : $this->col('muted'); $this->icon($icon, $cx - 12, $y + 12, 24, $color); $this->text($label, $cx, $y + 52, 12.5, $on ? $this->col('text') : $this->col('muted'), $on, 'center'); $this->hit($w * $i, $y, $w, self::NAV, 'tab', $id); } } // the player ------------------------------------------------------------------------------------------------------ private function renderPlayer(): void { $wz = $this->wz; $W = $this->W; $this->icon('snow', 20, 20, 24, $this->col('accent')); $this->text('WinZik', 52, 32, 20, $this->col('text'), true); // cloud: « Synchro · 2 appareils » while this phone plays with the others of the account (a tap: the account's page) $sync = $this->cloud()?->syncLabel() ?? ''; $subX = 52 + $this->textWidth('WinZik', 20, true) + 10; if ($sync !== '') { $this->icon('cloud', $subX, 20, 18, $this->col('accent')); $room = $W - 108 - ($subX + 22); // up to the mic: a narrow phone shortens it $this->text($sync, $subX + 22, 33, 14, $this->col('accent'), true, 'left', $room); $this->hit($subX - 6, 8, min($room, $this->textWidth($sync, 14, true)) + 34, 40, 'goto', 'cloud'); } else { $this->text('En lecture', $subX, 33, 14, $this->col('muted')); } $this->roundButton($W - 56, 8, 48, 'more', 'headerMore', null, $this->col('text')); // the karaoke on the whole screen in one tap (no lyrics yet: where to find them) $this->roundButton($W - 104, 8, 48, 'mic', 'karaokeOpen', null, $this->col('text')); $navTop = $this->H - self::NAV; $volumeY = $navTop - 38; $controlsY = $volumeY - 78; $progressY = $controlsY - 74; $lyricsBottom = $progressY - 26; $lyricsTop = $lyricsBottom - 62; $artistY = $lyricsTop - 16; $titleY = $artistY - 28; $artTop = 72.0; $art = max(120.0, min($W - 56, $titleY - 26 - $artTop)); $artX = ($W - $art) / 2; $file = $wz->playlist->current(); $line = $wz->playlist->active; $this->renderArt($artX, $artTop, $art, $file); if ($file === null) { $this->text('Aucun morceau', $W / 2, $titleY, 24, $this->col('text'), true, 'center'); $this->text('Ajoutez de la musique dans la Playlist', $W / 2, $artistY, 16, $this->col('muted'), false, 'center'); } else { [$title, $artist, $length] = $this->titleOf($line); $this->text($title, $W / 2, $titleY, 24, $this->col('text'), true, 'center', $W - 48); $this->text($artist !== '' ? $artist : 'Artiste inconnu', $W / 2, $artistY, 16, $this->col('muted'), false, 'center', $W - 48); } $this->renderLyrics($lyricsTop, $lyricsBottom); $this->renderUpdateBanner($artTop + 8); // the position: a bar the finger drags $duration = $wz->player->duration(); $pos = $this->seekAt !== null ? $this->seekAt * $duration : $wz->player->position; $ratio = $duration > 0 ? max(0.0, min(1.0, $pos / $duration)) : 0.0; $x0 = 28.0; $bw = $W - 56; $this->box($x0, $progressY - 3, $bw, 6, self::alpha($this->col('accent'), 45), 3); if ($ratio > 0) { $this->box($x0, $progressY - 3, max(6, $bw * $ratio), 6, $this->col('accent'), 3); } $knob = $this->seekAt !== null ? 11.0 : 8.0; $this->circle($x0 + $bw * $ratio, $progressY, $knob + 2, $this->col('surface')); $this->circle($x0 + $bw * $ratio, $progressY, $knob, $this->col('accent')); $this->text(self::clock($pos), $x0, $progressY + 22, 13, $this->col('muted')); $left = !empty($wz->options['timeLeft']) && $duration > 0; $this->text($duration > 0 ? ($left ? '-' . self::clock($duration - $pos) : self::clock($duration)) : '--:--', $x0 + $bw, $progressY + 22, 13, $this->col('muted'), false, 'right'); $this->hit($x0 - 14, $progressY - 22, $bw + 28, 44, 'seek'); // the time at the right: elapsed / left (the counter of 2001) $this->hit($x0 + $bw - 70, $progressY + 12, 84, 36, 'timeLeft'); // the buttons $playing = $wz->player->state === Player::PLAYING; $cx = $W / 2; $big = 76.0; $this->shadow($cx - $big / 2, $controlsY - $big / 2, $big, $big, $big / 2, 30); $this->circle($cx, $controlsY, $big / 2, $this->pressed('play') ? self::mix($this->col('accent'), '#000000', 0.15) : $this->col('accent')); $this->icon($playing ? 'pause' : 'play', $cx - 18, $controlsY - 18, 36, $this->col('onAccent')); $this->hit($cx - $big / 2, $controlsY - $big / 2, $big, $big, 'play'); $gap = min(92.0, ($W - 40) / 4.2); $this->roundButton($cx - $gap - 28, $controlsY - 28, 56, 'prev', 'prev', null, $this->col('text'), null, 34); $this->roundButton($cx + $gap - 28, $controlsY - 28, 56, 'next', 'next', null, $this->col('text'), null, 34); $side = min($cx - 24, 2 * $gap); foreach ([['shuffle', -$side, $wz->playlist->shuffle], ['repeat', $side, $this->repeat()]] as [$id, $dx, $on]) { $this->roundButton($cx + $dx - 24, $controlsY - 24, 48, $id, $id, null, $on ? $this->col('accent') : $this->col('muted'), null, 24); if ($on) { $this->circle($cx + $dx, $controlsY + 20, 2.5, $this->col('accent')); } if ($id === 'repeat' && $on) { $this->text('1', $cx + $dx + 1, $controlsY + 0.5, 9, $this->col('accent'), true, 'center'); } } // the volume $vol = $wz->player->volume; $this->roundButton(16, $volumeY - 24, 48, $vol > 0 ? 'volume' : 'mute', 'mute', null, $this->col('muted'), null, 22); $vx = 72.0; $vw = $W - $vx - 32; $this->box($vx, $volumeY - 2, $vw, 4, self::alpha($this->col('muted'), 50), 2); $this->box($vx, $volumeY - 2, max(4, $vw * $vol / 100), 4, $this->col('muted'), 2); $this->circle($vx + $vw * $vol / 100, $volumeY, 9, $this->col('surface')); $this->circle($vx + $vw * $vol / 100, $volumeY, 7, $this->col('muted')); $this->hit($vx - 14, $volumeY - 22, $vw + 28, 44, 'volume'); } /** the picture of the song: its cover, or the frost of Givre with the spectrum of the sound */ private function renderArt(float $x, float $y, float $size, ?string $file): void { $wz = $this->wz; $radius = 28.0; $this->shadow($x, $y, $size, $size, $radius, 26); if ($wz->playingVideo()) { // a film: its picture instead of the cover; a tap shows it on the whole screen $this->renderVideoBox($x, $y, $size, $size, $radius); $this->hit($x, $y, $size, $size, 'art'); return; } $cover = null; if ($file !== null && !\JumPHP\Kernel\Platform::isHeadless()) { [$tag] = $wz->describeLater($file); $cover = $wz->covers()->picture($wz->path($file), $tag); } $sdl = $this->form?->sdlOrNull(); if ($cover !== null && $sdl !== null) { $name = 'mobile-cover-' . md5($cover); try { $sdl->hasTexture($name) || $sdl->loadTexture($name, $cover); $tex = $sdl->getTexture($name); $this->r->copy($tex['texture'], null, $this->ox + $x * $this->s, $this->oy + $y * $this->s, $size * $this->s, $size * $this->s); return; } catch (\Throwable) { // no picture: the frost } } $this->gradientBox($x, $y, $size, $size, $this->col('art1'), $this->col('art2'), $radius); // a big snowflake, and the bars of the sound $flake = $size * 0.34; $this->icon('snow', $x + ($size - $flake) / 2, $y + $size * 0.13, $flake, self::alpha('#ffffff', 235)); $this->text('WINZIK', $x + $size / 2, $y + $size * 0.13 + $flake + 18, max(13, $size * 0.055), self::alpha('#ffffff', 230), true, 'center'); $bars = $wz->spectrum->bars; $n = count($bars); $live = max($bars ?: [0]) > 0.02; $playing = $wz->player->state === Player::PLAYING; $pad = $size * 0.09; $bw = ($size - 2 * $pad) / $n; $maxH = $size * 0.34; $base = $y + $size - $pad; for ($i = 0; $i < $n; $i++) { if ($live) { $v = max(0.0, min(1.0, $bars[$i])); } elseif ($playing) { // no samples to measure (the phone has no ffmpeg): the bars dance with the level of the song $level = 0.35 + 0.65 * max($wz->vuLeft, $wz->vuRight); $v = $level * (0.25 + 0.6 * abs(sin($this->clock * (1.7 + 0.37 * $i) + $i * 1.3)) * (1 - abs($i - $n / 2) / $n * 0.8)); } else { $v = 0.05; } $h = max(4.0, $maxH * $v); $this->box($x + $pad + $i * $bw + $bw * 0.18, $base - $h, $bw * 0.64, $h, self::alpha('#ffffff', 200), min(3.0, $bw * 0.3)); } } // renderLyrics(): the Lecteur's lyrics card, in LyricsWebPages (synchronised, to scroll, translated) // the list --------------------------------------------------------------------------------------------------------- private function renderPlaylist(): void { $wz = $this->wz; $W = $this->W; $navTop = $this->H - self::NAV; if ($this->inCloudView()) { $this->renderCloudList(); return; } // the switch « Ce téléphone | Cloud » when there is a cloud $seg = $this->cloud() !== null ? 52.0 : 0.0; if ($wz->playlist->count() === 0) { $this->header('Playlist', 'Vide', [['plus', 'add'], ['more', 'headerMore']]); if ($seg > 0) { $this->renderSegment(72); } $this->renderEmpty(72 + $seg, $navTop); return; } // the songs first, then the top drawn over the rows that scrolled under it $top = 72.0 + 60 + 46 + $seg + self::lyricsFilterHeight(); // lyrics: + the row « Seulement avec paroles » $miniTop = $navTop - self::MINI - 10; $bottom = $wz->player->file !== null ? $miniTop - 4 : $navTop; $lines = $this->shownLines(); $this->scrollMax['list'] = max(0.0, count($lines) * self::ROW + 12 - ($bottom - $top)); $this->scroll['list'] = min($this->scroll['list'], $this->scrollMax['list']); $off = $this->scroll['list']; $this->listView = $bottom - $top; $this->hit(0, $top, $W, $bottom - $top, 'list', null, 'list'); $first = max(0, (int)floor($off / self::ROW)); $last = min(count($lines) - 1, (int)ceil(($off + $bottom - $top) / self::ROW)); for ($k = $first; $k <= $last; $k++) { $this->renderRow($lines[$k], $top + $k * self::ROW - $off); } if ($lines === [] && $this->search === '' && $wz->playsLyricsOnly()) { $this->renderLyricsOnlyEmpty($top, $bottom); // lyrics: none of the songs has lyrics } elseif ($lines === []) { $this->text('Aucun morceau ne correspond', $W / 2, $top + 40, 16, $this->col('text'), true, 'center'); $this->text('à « ' . $this->search . ' »', $W / 2, $top + 64, 15, $this->col('muted'), false, 'center', $W - 48); } // the scroll bar while it moves if ($this->scrollMax['list'] > 0 && ($this->press !== null || $this->speed['list'] != 0)) { $h = $bottom - $top; $bh = max(40.0, $h * $h / ($h + $this->scrollMax['list'])); $this->box($W - 6, $top + ($h - $bh) * $off / $this->scrollMax['list'], 3, $bh, self::alpha($this->col('muted'), 120), 1.5); } // the rows hidden under the top or the mini player can not be touched there $until = $top - 4; $this->hits = array_values(array_filter($this->hits, fn (array $h) => $h[4] === 'list' || ($h[1] + $h[3] / 2 > $until && $h[1] + $h[3] / 2 < $bottom))); $this->paintBackground(0, $until); $this->paintBackground($bottom, $navTop); $this->renderPlaylistTop(); if ($wz->player->file !== null) { $this->renderMini($miniTop); $this->renderLocate($lines, $off, $miniTop); } } /** The header, the search field and the order chips of the list (drawn twice: before and over the rows). */ private function renderPlaylistTop(): void { $wz = $this->wz; $W = $this->W; $count = $wz->playlist->count(); $total = 0.0; foreach (array_keys($wz->playlist->items) as $i) { if ($i < 400) { $total += $this->titleOf($i)[2]; } } $sub = $count . ($count > 1 ? ' morceaux' : ' morceau') . ($total > 0 ? ' · ' . self::clock($total) : ''); $this->header('Playlist', $sub, [['plus', 'add'], ['more', 'headerMore']]); $sy = 72.0; if ($this->cloud() !== null) { $this->renderSegment($sy); $sy += 52; } $this->box(16, $sy, $W - 32, 48, $this->col('surface'), 24); if ($this->searching) { $this->box(16, $sy, $W - 32, 48, $this->col('accent'), 24); $this->box(18, $sy + 2, $W - 36, 44, $this->col('surface'), 22); } $this->icon('search', 30, $sy + 13, 22, $this->col('muted')); $shown = $this->search === '' ? 'Rechercher un titre, un artiste' : $this->search; $caret = $this->searching && fmod($this->clock, 1.0) < 0.55 ? '|' : ''; $this->text($shown . $caret, 62, $sy + 24, 15, $this->search === '' ? $this->col('muted') : $this->col('text'), false, 'left', $W - 140); $this->hit(16, $sy, $W - 32 - ($this->search !== '' ? 48 : 0), 48, 'search'); if ($this->search !== '') { $this->roundButton($W - 16 - 48, $sy, 48, 'close', 'searchClear', null, $this->col('muted'), null, 20); } $cy = $sy + 60; $x = 16.0; $current = $wz->byPreference() ? 'pref' : ($this->byArtist() ? 'artist' : 'list'); foreach ([['list', 'Dans l\'ordre'], ['pref', 'Préférés'], ['artist', 'Par artiste']] as [$id, $label]) { $on = $id === $current; $w = $this->textWidth($label, 14, $on) + ($id === 'pref' ? 52 : 32); $this->box($x, $cy, $w, 36, $on ? $this->col('soft') : self::alpha($this->col('surface'), 160), 18); if ($id === 'pref') { $this->icon('star', $x + 12, $cy + 9, 18, $on ? $this->col('star') : $this->col('muted')); } $this->text($label, $x + ($id === 'pref' ? 36 : 16), $cy + 18, 14, $on ? $this->col('accent') : $this->col('muted'), $on); $this->hit($x, $cy - 6, $w, 48, 'order', $id); $x += $w + 8; } $this->renderLyricsFilter($cy + 46); // lyrics: « Seulement avec paroles » } /** a song of the list */ private function renderRow(int $line, float $y): void { $wz = $this->wz; $W = $this->W; $active = $line === $wz->playlist->active && $wz->player->file !== null; $playing = $active && $wz->player->state === Player::PLAYING; if ($active) { $this->box(8, $y + 2, $W - 16, self::ROW - 4, self::alpha($this->col('surface'), 235), 16); $this->box(8, $y + 2, 4, self::ROW - 4, $this->col('accent'), 2); } if ($this->flash > 0 && $line === $this->flashLine) { // found again (« où ça joue »): a glow that fades $this->box(8, $y + 2, $W - 16, self::ROW - 4, self::alpha($this->col('accent'), (int)(70 * min(1.0, $this->flash))), 16); } if ($this->pressed('row', $line) || ($this->sheet === 'actions' && $this->sheetLine === $line)) { $this->box(8, $y + 2, $W - 16, self::ROW - 4, self::alpha($this->col('accent'), 30), 16); } // the badge: a note, or bars that move for the song playing $bx = 20.0; $by = $y + 12; $this->box($bx, $by, 44, 44, $active ? $this->col('accent') : $this->col('soft'), 12); if ($playing) { for ($k = 0; $k < 3; $k++) { $h = 8 + 14 * abs(sin($this->clock * (3.1 + $k * 1.3) + $k)); $this->box($bx + 12 + $k * 8, $by + 32 - $h, 5, $h, $this->col('onAccent'), 2); } } else { $this->icon('note', $bx + 11, $by + 11, 22, $active ? $this->col('onAccent') : $this->col('accent')); } [$title, $artist, $length] = $this->titleOf($line); $file = (string)$wz->playlist->items[$line]; $stars = $wz->stats()->rating($wz->path($file)); $textX = 76.0; $right = $W - 56; $this->text($title, $textX, $y + 25, 16, $active ? $this->col('accent') : $this->col('text'), true, 'left', $right - $textX - 4); $sub = ($artist !== '' ? $artist : 'Artiste inconnu') . ($length > 0 ? ' · ' . self::clock($length) : ''); $marks = $this->lyricsMarks($line); // lyrics: synchronised / to scroll / translated $subMax = $right - $textX - 4 - ($stars > 0 ? 16 + 12 * $stars : 0) - ($marks !== [] ? 8 + 17 * count($marks) : 0); $sub = $this->fit($sub, 13, false, $subMax); $this->text($sub, $textX, $y + 47, 13, $this->col('muted')); $mx = $textX + $this->textWidth($sub, 13) + 8; foreach ($marks as $mark) { $this->icon($mark, $mx, $y + 40, 14, $this->col('accent')); $mx += 17; } for ($k = 0; $k < $stars; $k++) { $this->icon('star', $mx + $k * 12, $y + 41, 12, $this->col('star')); } $this->hit(8, $y, $W - 64, self::ROW, 'row', $line, 'list'); $this->roundButton($W - 56, $y + 10, 48, 'more', 'rowMore', $line, $this->col('muted'), null, 22); $this->hits[count($this->hits) - 1][6] = 'list'; } // --- follow: the list follows the song playing (not while the finger scrolled it); « où ça joue » -------------------- /** seconds after the finger scrolled the list before it follows the songs again */ public const FOLLOW_AFTER = 8.0; /** the clock when the finger last scrolled the list */ private float $listHandAt = -100.0; /** the song playing last seen (-2: none seen yet) */ private int $followSeen = -2; /** a song changed while the list was held: shown once the finger has left it long enough */ private bool $followPending = false; /** the list glides there (dp), null: it does not */ public ?float $listGlide = null; /** the height of the list's rows on screen (dp, last frame) */ private float $listView = 0.0; /** the row found again glows this long (s) */ public float $flash = 0.0; public int $flashLine = -1; /** The finger (or the wheel) scrolled the list: it does not follow the songs for FOLLOW_AFTER seconds. */ private function listByHand(): void { $this->listHandAt = $this->clock; $this->listGlide = null; } /** The list was scrolled by hand a moment ago. */ public function listHeld(): bool { return $this->clock - $this->listHandAt < self::FOLLOW_AFTER; } /** Where the list shows the song playing in its middle (dp scrolled), null: not shown (the search, the cloud view). */ public function playingScroll(): ?float { $wz = $this->wz; if ($wz === null || $wz->playlist->active < 0 || $this->inCloudView()) { return null; } $lines = $this->shownLines(); $k = array_search($wz->playlist->active, $lines, true); if (!is_int($k)) { return null; } $view = $this->listView > 0 ? $this->listView : $this->H - 72 - 106 - self::NAV - self::MINI - 14; $max = max(0.0, count($lines) * self::ROW + 12 - $view); return max(0.0, min($max, $k * self::ROW - ($view - self::ROW) / 2)); } /** The song playing is out of the rows on screen (the button « où ça joue » shows). */ private function playingOutOfView(array $lines, float $off): bool { $k = array_search($this->wz->playlist->active, $lines, true); if (!is_int($k)) { return false; } $y = $k * self::ROW - $off; return $y < -self::ROW / 2 || $y > $this->listView - self::ROW / 2; } /** « Où ça joue » tapped: the list glides to the song playing, which glows a moment; the list follows again. */ public function locatePlaying(): void { $to = $this->playingScroll(); if ($to === null) { return; } $this->listHandAt = -100.0; $this->followPending = false; $this->speed['list'] = 0.0; $this->listGlide = $to; $this->flash = 1.6; $this->flashLine = $this->wz->playlist->active; } /** Each frame: a new song shown (unless the finger holds the list), the glide, the glow. */ private function updateFollow(float $dt): void { $this->flash = max(0.0, $this->flash - $dt); if (($this->speed['list'] ?? 0.0) != 0.0) { $this->listByHand(); // a flick still going on } $active = $this->wz?->playlist->active ?? -1; if ($active !== $this->followSeen) { $first = $this->followSeen === -2; $this->followSeen = $active; $this->followPending = !$first; } if ($this->followPending && !$this->listHeld()) { $this->followPending = false; $to = $this->playingScroll(); $k = $to === null ? false : array_search($this->wz->playlist->active, $this->shownLines(), true); $y = is_int($k) ? $k * self::ROW - $this->scroll['list'] : 0.0; if ($this->listView > 0 && $y >= 0 && $y <= $this->listView - self::ROW) { $to = null; // already whole on screen (a row tapped): the list stays still } if ($to !== null && $this->screen === 'playlist') { $this->listGlide = $to; // on screen: it glides there } elseif ($to !== null) { $this->scroll['list'] = $to; } } if ($this->listGlide !== null) { if ($this->press !== null && $this->press['scroll'] === 'list') { $this->listGlide = null; return; } $now = $this->scroll['list']; $next = $now + ($this->listGlide - $now) * min(1.0, $dt * 9); if (abs($this->listGlide - $next) < 0.5) { $next = $this->listGlide; $this->listGlide = null; } $this->scroll['list'] = $next; } } /** The round button « où ça joue » over the list, above the mini player, while the song playing is out of view. */ private function renderLocate(array $lines, float $off, float $miniTop): void { if ($this->sheet !== '' || !$this->playingOutOfView($lines, $off)) { return; } $size = 52.0; $x = $this->W - 64 - $size; // left of the ⋮ of the rows: they stay touchable $y = $miniTop - $size - 12; $this->shadow($x, $y, $size, $size, $size / 2, 26); $this->roundButton($x, $y, $size, 'target', 'locate', null, $this->col('onAccent'), $this->col('accent'), 26); } // --- end follow /** the list is empty: what to do */ private function renderEmpty(float $top, float $bottom): void { $W = $this->W; $cy = $top + ($bottom - $top) * 0.38; $this->circle($W / 2, $cy - 40, 52, $this->col('soft')); $this->icon('note', $W / 2 - 26, $cy - 66, 52, $this->col('accent')); $this->text('Votre playlist est vide', $W / 2, $cy + 42, 21, $this->col('text'), true, 'center'); $y = $cy + 74; foreach ($this->wrap('Ajoutez les morceaux de votre téléphone : touchez le bouton ci-dessous, puis choisissez un dossier (Musique, Téléchargements...) ou un fichier.', 15, false, $W - 64) as $line) { $this->text($line, $W / 2, $y, 15, $this->col('muted'), false, 'center'); $y += 22; } $this->pill($W / 2 - 120, $y + 14, 240, 'plus', 'Ajouter de la musique', 'emptyAdd', null); } /** a big button with an icon and a text */ private function pill(float $x, float $y, float $w, string $icon, string $label, string $id, mixed $data, bool $primary = true): void { $fill = $primary ? $this->col('accent') : $this->col('soft'); if ($this->pressed($id, $data)) { $fill = self::mix($fill, '#000000', 0.12); } $ink = $primary ? $this->col('onAccent') : $this->col('accent'); if ($primary) { $this->shadow($x, $y, $w, 52, 26, 22); } $this->box($x, $y, $w, 52, $fill, 26); $tw = $this->textWidth($label, 16, true) + ($icon !== '' ? 30 : 0); $tx = $x + ($w - $tw) / 2; if ($icon !== '') { $this->icon($icon, $tx, $y + 15, 22, $ink); $tx += 30; } $this->text($label, $tx, $y + 26, 16, $ink, true, 'left', $w - 24); $this->hit($x, $y, $w, 52, $id, $data); } /** the song playing, over the bar of tabs */ private function renderMini(float $y): void { $wz = $this->wz; $W = $this->W; $x = 10.0; $w = $W - 20; $h = self::MINI; $this->shadow($x, $y, $w, $h, 18, 28); $this->box($x, $y, $w, $h, $this->col('surface'), 18); if ($this->pressed('mini')) { $this->box($x, $y, $w, $h, self::alpha($this->col('accent'), 25), 18); } $this->gradientBox($x + 10, $y + 10, 44, 44, $this->col('art1'), $this->col('art2'), 12); $this->icon('snow', $x + 20, $y + 20, 24, '#ffffff'); [$title, $artist] = $this->titleOf($wz->playlist->active); $tx = $x + 66; // the song has lyrics: a button to their karaoke on the whole screen $buttons = $this->songLyrics() !== null ? 154.0 : 104.0; $max = $w - 66 - $buttons; $this->text($title, $tx, $y + 24, 15, $this->col('text'), true, 'left', $max); $this->text($artist !== '' ? $artist : 'Artiste inconnu', $tx, $y + 44, 13, $this->col('muted'), false, 'left', $max); $this->hit($x, $y, $w - $buttons, $h, 'mini'); if ($buttons > 104) { $this->roundButton($x + $w - 154, $y + 8, 48, 'mic', 'karaokeOpen', null, $this->col('accent'), null, 24); } $playing = $wz->player->state === Player::PLAYING; $this->roundButton($x + $w - 104, $y + 8, 48, $playing ? 'pause' : 'play', 'miniPlay', null, $this->col('text'), null, 28); $this->roundButton($x + $w - 54, $y + 8, 48, 'next', 'miniNext', null, $this->col('text'), null, 24); // its position, a thin line at the bottom $d = $wz->player->duration(); $ratio = $d > 0 ? max(0.0, min(1.0, $wz->player->position / $d)) : 0.0; $this->rect($x + 18, $y + $h - 3, $w - 36, 2, self::alpha($this->col('accent'), 40)); $this->rect($x + 18, $y + $h - 3, ($w - 36) * $ratio, 2, $this->col('accent')); } // adding music -------------------------------------------------------------------------------------------------------- private function renderAdd(): void { $wz = $this->wz; $W = $this->W; $top = 64.0; $y = $top + 4; $rows = []; // [icon, label, sub, id, data, action icon] if ($this->folder === '') { if (Native::supports('open')) { $rows[] = ['plus', $this->pickMode === 'music' ? 'Choisir des fichiers…' : 'Choisir un fichier…', 'Le sélecteur de fichiers du téléphone', 'pick', null, '']; } foreach ($this->places() as [$label, $dir, $icon]) { $rows[] = [$icon, $label, $dir, 'place', $dir, 'chevron']; } if ($this->pickMode === 'fls' && $wz !== null) { $rows[] = ['save', 'Playlists enregistrées', $wz->storagePath('playlists'), 'place', $wz->storagePath('playlists'), 'chevron']; } $intro = $this->wrap(match ($this->pickMode) { 'lyrics' => 'Choisissez un fichier de paroles (.lrc ou .lyr) : il devient les paroles du morceau en cours.', 'fls' => 'Choisissez une playlist (.fls) : elle remplace la playlist actuelle.', default => 'Choisissez un dossier : ses morceaux et ceux de ses sous-dossiers s\'ajoutent à la playlist.', }, 14, false, $W - 40); } else { [$dirs, $files, $ok] = $this->listFolder($this->folder); $rows[] = ['up', 'Dossier parent', '', 'up', null, '']; if (!$ok) { $intro = $this->wrap('WinZik ne peut pas lire ce dossier. Autorisez l\'accès à la musique et aux fichiers dans les réglages du téléphone (Applications > WinZik > Autorisations).', 14, false, $W - 40); } else { $intro = []; foreach ($dirs as $d) { $rows[] = ['folder', Text::baseName($d), '', 'dir', $d, 'chevron']; } $known = array_flip(array_map(fn ($f) => $wz->path($f), $wz->playlist->items)); foreach ($files as $f) { if ($this->pickMode !== 'music') { $rows[] = [$this->pickMode === 'fls' ? 'list' : 'lyrics', Text::baseName($f), $this->pickMode === 'fls' ? 'Toucher pour l\'ouvrir' : 'Toucher pour l\'importer', 'file', $f, 'chevron']; continue; } $rows[] = ['note', Text::baseName($f), isset($known[$f]) ? 'Déjà dans la playlist' : 'Toucher pour l\'ajouter', 'file', $f, isset($known[$f]) ? 'check' : 'plus']; } if ($dirs === [] && $files === []) { $intro = [$this->pickMode === 'music' ? 'Aucun morceau ni dossier ici.' : 'Aucun fichier ni dossier ici.']; } } } $allButton = $this->folder !== '' && $this->pickMode === 'music'; $listTop = $y + count($intro) * 20 + 14 + ($allButton ? 66 : 0); $bottom = $this->H; $this->scrollMax['add'] = max(0.0, count($rows) * self::ROW + 24 - ($bottom - $listTop)); $this->scroll['add'] = min($this->scroll['add'], $this->scrollMax['add']); $off = $this->scroll['add']; $this->hit(0, $listTop, $W, $bottom - $listTop, 'addList', null, 'add'); foreach ($rows as $k => [$icon, $label, $sub, $id, $data, $action]) { $ry = $listTop + $k * self::ROW - $off; if ($ry + self::ROW < $listTop - 4 || $ry > $bottom) { continue; } if ($this->pressed($id, $data)) { $this->box(8, $ry + 2, $W - 16, self::ROW - 4, self::alpha($this->col('accent'), 30), 16); } $this->box(20, $ry + 12, 44, 44, $icon === 'note' ? $this->col('soft') : self::alpha($this->col('surface'), 220), 12); $this->icon($icon, 31, $ry + 23, 22, $this->col('accent')); $this->text($label, 76, $sub !== '' ? $ry + 25 : $ry + 34, 16, $this->col('text'), true, 'left', $W - 76 - 52); $this->text($sub, 76, $ry + 47, 13, $this->col('muted'), false, 'left', $W - 76 - 52); if ($action !== '') { $this->icon($action, $W - 44, $ry + 22, 24, $action === 'chevron' ? $this->col('muted') : $this->col('accent')); } $this->hit(8, $ry, $W - 16, self::ROW, $id, $data, 'add'); } // the top over the rows $this->paintBackground(0, $listTop); $this->hits = array_values(array_filter($this->hits, fn (array $h) => $h[1] + $h[3] > $listTop)); $title = $this->folder !== '' ? Text::baseName($this->folder) : ['lyrics' => 'Importer des paroles', 'fls' => 'Ouvrir une playlist'][$this->pickMode] ?? 'Ajouter de la musique'; $this->header($title, '', [], true); foreach ($intro as $k => $line) { $this->text($line, 20, $y + 10 + $k * 20, 14, $this->col('muted')); } if ($allButton) { $this->pill(16, $y + count($intro) * 20 + 4, $W - 32, 'plus', 'Ajouter tout ce dossier', 'addDir', $this->folder); } } // the toast ----------------------------------------------------------------------------------------------------------- private function renderToast(): void { $text = $this->wz === null ? '' : $this->wz->notice; if ($text === '' || $this->sheet !== '') { return; } $W = $this->W; $max = $W - 64; $w = min($max, $this->textWidth($text, 14) + 40); $y = $this->screen === 'playlist' && $this->wz->player->file !== null ? $this->H - self::NAV - self::MINI - 70 : $this->H - self::NAV - 56; if ($this->isPage()) { $y = $this->H - 72 - $this->pageFooter; } $this->box(($W - $w) / 2, $y, $w, 44, self::alpha($this->col('text'), 235), 22); $this->text($text, $W / 2, $y + 22, 14, $this->col('surface'), false, 'center', $w - 32); } // the bottom sheets --------------------------------------------------------------------------------------------------- private function renderSheet(): void { $W = $this->W; $H = $this->H; $ease = 1 - (1 - $this->sheetOpen) ** 3; $veil = $this->c['veil']; $this->rect(0, 0, $W, $H, [$veil[0], $veil[1], $veil[2], (int)($veil[3] * $ease)]); $first = count($this->hits); $this->hit(0, 0, $W, $H, 'veil'); $content = $this->sheetContent(); $h = min($H - 48, $this->sheetHeight($content)); $y = $H - $h * $ease; $this->box(0, $y, $W, $h + 30, $this->col('surface'), 28); $this->box($W / 2 - 18, $y + 10, 36, 5, $this->col('line'), 2.5); $this->hit(0, $y, $W, $h, 'sheet'); $this->drawSheet($content, $y + 22); if ($this->sheetClosing) { // a sheet going down: what is under it can be touched at once $this->hits = array_slice($this->hits, 0, $first); } } /** * What the open sheet shows, as rows: [kind, ...]. Kinds: title (text, sub), row (icon, label, id, data, colour, * right), stars, chips, toggle (label, sub, id, data, on), swatches, text, button (label, id, data, primary), space. * @return list<array> */ private function sheetContent(): array { $wz = $this->wz; $line = $this->sheetLine; switch ($this->sheet) { case 'actions': [$title, $artist, $length] = $this->titleOf($line); $count = $wz->playlist->count(); return [ ['title', $title, ($artist !== '' ? $artist : 'Artiste inconnu') . ($length > 0 ? ' · ' . self::clock($length) : '')], ['stars'], ['row', 'play', $line === $wz->playlist->active && $wz->player->state === Player::PLAYING ? 'Reprendre du début' : 'Lire', 'act', 'play', 'text', ''], ['row', 'queue', 'Lire ensuite', 'act', 'next', 'text', ''], ['row', 'info', 'Infos du morceau', 'act', 'info', 'text', 'chevron'], ['row', 'tag', 'Modifier le tag', 'act', 'tag', 'text', 'chevron'], ['row', 'lyrics', $this->lyricsRowLabel($line), 'lyFind', $line, 'text', 'chevron'], // lyrics ...$this->cloudPutRow($line), ...($line > 0 ? [['row', 'up', 'Monter dans la liste', 'act', 'up', 'text', '']] : []), ...($line < $count - 1 ? [['row', 'down', 'Descendre dans la liste', 'act', 'down', 'text', '']] : []), ['row', 'trash', 'Retirer de la playlist', 'act', 'remove', 'danger', ''], ]; case 'more': return [ ['title', 'Plus', 'WinZik ' . $wz->version()], ['row', 'plus', 'Ajouter de la musique', 'goto', 'add', 'text', 'chevron'], ['row', 'youtube', 'YouTube (MP3, vidéos)', 'goto', 'youtube', 'text', 'chevron'], ['row', 'spotify', 'Mes playlists Spotify', 'goto', 'spotify', 'text', 'chevron'], ...($this->cloud() !== null ? [['row', 'cloud', 'Mon compte (cloud)', 'goto', 'cloud', 'text', 'chevron']] : []), ...($this->castService() !== null ? [['row', 'computer', 'Caster sur la TV', 'goto', 'cast', 'text', 'chevron']] : []), ['row', 'mic', 'Paroles et karaoké', 'more', 'lyrics', 'text', 'chevron'], ['row', 'eq', 'Égaliseur', 'more', 'eq', 'text', 'chevron'], ['row', 'store', 'Marketplace (paroles, skins)', 'goto', 'market', 'text', 'chevron'], ['row', 'palette', 'Thème de couleurs', 'more', 'theme', 'text', 'chevron'], ['row', 'gear', 'Options', 'goto', 'options', 'text', 'chevron'], ['row', 'window', 'Interface : WinZik original (skin)', 'original', null, 'text', ''], ['row', 'info', 'À propos de WinZik', 'more', 'about', 'text', 'chevron'], ]; case 'playlistMenu': return [ ['title', 'Playlist', $wz->playlist->count() . ' morceau(x)'], ['row', 'plus', 'Ajouter de la musique', 'goto', 'add', 'text', 'chevron'], ['row', 'youtube', 'Ajouter depuis YouTube', 'goto', 'youtube', 'text', 'chevron'], ['row', 'save', 'Enregistrer ou ouvrir (.FLS)', 'goto', 'library', 'text', 'chevron'], ['row', 'shuffle', $wz->playlist->shuffle ? 'Lecture aléatoire : activée' : 'Lecture aléatoire : désactivée', 'shuffle', null, 'text', ''], ...($wz->playlist->count() > 0 ? [['row', 'trash', 'Vider la playlist', 'more', 'confirmClear', 'danger', '']] : []), ]; case 'confirmClear': return [ ['title', 'Vider la playlist ?', $wz->playlist->count() . ' morceau(x) retiré(s) de la liste'], ['text', 'Les fichiers restent sur le téléphone : seule la liste est vidée. Enregistrez-la d\'abord (.FLS) pour la retrouver.'], ['button', 'Vider la playlist', 'clearList', null, true], ['button', 'Annuler', 'sheetClose', null, false], ]; case 'info': return $this->infoContent($line); case 'eq': $eq = $wz->eq; return [ ['title', 'Égaliseur', $eq->on ? 'Préréglage : ' . (string)($wz->ui['mobile']['eqPreset'] ?? 'Plat') : 'Désactivé'], ['toggle', 'Égaliseur activé', 'Glissez les bandes du doigt, ou un préréglage', 'eqOn', null, $eq->on], ['toggle', 'AUTO', 'Chaque morceau garde ses propres réglages', 'eqAuto', null, $eq->auto], ['curve'], ['preamp'], ['chips', array_keys(Equalizer::PRESETS)], ]; case 'theme': return [['title', 'Thème de couleurs', 'Les couleurs du lecteur'], ['swatches']]; case 'about': return [ ['logo'], ['text', 'Le lecteur audio skinnable de 2001 (Visual Basic 6, Windows 98), recréé en PHP avec JumPHP. Version téléphone : lecteur, playlist, YouTube, Spotify, paroles karaoké, vidéos.'], ['button', 'Générique de 2001', 'credits', null, false], ['button', 'Le site WinZik (archive)', 'website', null, false], ['button', 'Rechercher une mise à jour', 'updateCheck', null, false], ['button', 'Fermer', 'sheetClose', null, true], ]; } return $this->cloudSheet() ?? $this->youTubeSheet() ?? $this->lyricsSheet() ?? $this->mediaSheet() ?? []; } /** @return list<array> the details of a song */ private function infoContent(int $line): array { $wz = $this->wz; $file = $wz->playlist->items[$line] ?? null; if ($file === null) { return []; } [$tag, $info] = $wz->describeLater($file); $path = $wz->path($file); [$title, $artist] = $this->titleOf($line); $fields = [ ['Album', $tag->album], ['Année', $tag->year], ['Genre', $tag->present ? (Id3Tag::GENRES[$tag->genre] ?? '') : ''], ['Durée', $info->duration > 0 ? self::clock($info->duration) : ''], ['Format', strtoupper(Text::extension($path)) . ($info->kbps > 0 ? ' · ' . $info->kbps . ' kbps' : '') . ($info->sampleRate > 0 ? ' · ' . $info->sampleRate . ' Hz' : '')], ['Écoutes', (string)$wz->stats()->plays($path)], ['Passés', (string)$wz->stats()->skips($path)], ['Score', (string)$wz->stats()->score($path)], ['Fichier', Text::baseName($path)], ]; $rows = [['title', $title, $artist !== '' ? $artist : 'Artiste inconnu']]; foreach ($fields as [$k, $v]) { if ($v !== '') { $rows[] = ['field', $k, $v]; } } $rows[] = ['space', 8]; $rows[] = ['button', 'Modifier le tag et les repères', 'editTag', null, false]; $rows[] = ['button', 'Fermer', 'sheetClose', null, true]; return $rows; } private function rowHeight(array $row): float { return $this->cloudRowHeight($row) ?? $this->lyricsRowHeight($row) ?? match ($row[0]) { 'title' => 64.0, 'row' => 56.0, 'stars' => 60.0, 'toggle' => 68.0, 'field' => 40.0, 'button' => 64.0, 'space' => (float)$row[1], 'curve' => 168.0, 'preamp' => 56.0, 'chips' => 48.0 * (int)ceil(count($row[1]) / 3) + 8, 'swatches' => 2 * 112.0 + 8, 'logo' => 150.0, 'text' => 22.0 * count($this->wrap((string)$row[1], 15, false, $this->W - 48)) + 16, 'note' => 20.0 * count($this->wrap((string)$row[1], 14, false, $this->W - 48)) + 12, 'section' => 44.0, 'input' => 22.0 + $this->inputHeight($row) + 14, 'chipset' => $this->chipsetLayout($row[1])[1] + 8, 'row2' => 66.0, 'result' => 68.0, 'job' => 78.0, 'stepper' => 68.0, 'progress' => 34.0, 'pills' => 60.0, 'busy' => 48.0, 'line' => 54.0, default => 48.0, }; } /** the box of a text field: one line, or several for the lyrics */ private function inputHeight(array $row): float { if (!in_array($row[2], self::MULTILINE, true)) { return 52.0; } $n = count(explode("\n", $this->fields[$row[2]] ?? '')) + 1; return min(22.0 * 14, max(22.0 * 6, 22.0 * $n)) + 24; } /** * Chips laid out in lines of the width of the screen. * @param list<array{0: string, 1: string, 2: mixed, 3: bool}> $chips label, id, data, on * @return array{0: list<array{0: float, 1: float, 2: float}>, 1: float} each chip's x, y, width; the height of all */ private function chipsetLayout(array $chips): array { $x = 24.0; $y = 0.0; $out = []; foreach ($chips as [$label, , , $on]) { $w = $this->textWidth((string)$label, 14, (bool)$on) + 32; if ($x + $w > $this->W - 24 && $x > 24) { $x = 24.0; $y += 48; } $out[] = [$x, $y, $w]; $x += $w + 8; } return [$out, $chips === [] ? 0.0 : $y + 48]; } /** The white cards behind the rows of a page (a group of rows between two titles, fields or buttons). */ private function drawCards(array $content, float $y): void { $in = ['row', 'row2', 'toggle', 'field', 'stars', 'stepper', 'result', 'job', 'line', 'progress', 'cloudDevice', 'lyCand']; $start = null; foreach ([...$content, ['end']] as $row) { $inside = in_array($row[0], $in, true); if ($inside && $start === null) { $start = $y; } elseif (!$inside && $start !== null) { if ($y > $this->clipTop && $start < $this->clipBottom) { $this->box(12, $start, $this->W - 24, $y - $start, self::alpha($this->col('surface'), 235), 18); } $start = null; } if ($row[0] !== 'end') { $y += $this->rowHeight($row); } } } private function sheetHeight(array $content): float { $h = 22.0 + 20; foreach ($content as $row) { $h += $this->rowHeight($row); } return $h; } private function drawSheet(array $content, float $y): void { $wz = $this->wz; $W = $this->W; $ix = $this->cards ? 12.0 : 0.0; // the pressed row: inside its card foreach ($content as $row) { $h = $this->rowHeight($row); if ($y + $h < $this->clipTop || $y > $this->clipBottom) { $y += $h; continue; } switch ($row[0]) { case 'title': $this->text((string)$row[1], 24, $y + 22, 19, $this->col('text'), true, 'left', $W - 48 - 40); $this->text((string)$row[2], 24, $y + 46, 14, $this->col('muted'), false, 'left', $W - 48); $this->roundButton($W - 60, $y + 4, 48, 'close', 'sheetClose', null, $this->col('muted'), null, 20); $this->rect(24, $y + $h - 1, $W - 48, 1, $this->col('line')); break; case 'row': [, $icon, $label, $id, $data, $tone, $right] = $row; if ($this->pressed($id, $data)) { $this->rect($ix, $y, $W - 2 * $ix, $h, self::alpha($this->col('accent'), 25)); } $color = $tone === 'danger' ? $this->col('danger') : $this->col('text'); $this->icon($icon, 24, $y + 16, 24, $tone === 'danger' ? $color : $this->col('accent')); $this->text((string)$label, 68, $y + $h / 2, 16, $color, false, 'left', $W - 120); if ($right !== '') { $this->icon($right, $W - 44, $y + 16, 24, $this->col('muted')); } $this->hit(0, $y, $W, $h, $id, $data); break; case 'stars': $file = $wz->playlist->items[$row[1] ?? $this->sheetLine] ?? null; $rating = $file === null ? 0 : $wz->stats()->rating($wz->path($file)); $this->text('Noter', 24, $y + $h / 2, 15, $this->col('muted')); for ($k = 1; $k <= 5; $k++) { $sx = $W - 24 - (6 - $k) * 48; $this->roundButton($sx, $y + 6, 48, $k <= $rating ? 'star' : 'starOutline', (string)($row[2] ?? 'star'), $k, $k <= $rating ? $this->col('star') : $this->col('muted'), null, 30); } if (!$this->cards) { $this->rect(24, $y + $h - 1, $W - 48, 1, $this->col('line')); } break; case 'toggle': [, $label, $sub, $id, $data, $on] = $row; if ($this->pressed($id, $data)) { $this->rect($ix, $y, $W - 2 * $ix, $h, self::alpha($this->col('accent'), 25)); } $this->text((string)$label, 24, $y + 24, 16, $this->col('text'), false, 'left', $W - 110); $this->text((string)$sub, 24, $y + 46, 13, $this->col('muted'), false, 'left', $W - 110); $sx = $W - 24 - 52; $this->box($sx, $y + 20, 52, 30, $on ? $this->col('accent') : $this->col('line'), 15); $this->circle($on ? $sx + 37 : $sx + 15, $y + 35, 11, '#ffffff'); $this->hit(0, $y, $W, $h, $id, $data); break; case 'field': $this->text((string)$row[1], 24, $y + $h / 2, 14, $this->col('muted')); $this->text((string)$row[2], 110, $y + $h / 2, 15, $this->col('text'), false, 'left', $W - 134); break; case 'button': [, $label, $id, $data, $primary] = $row; $this->pill(24, $y + 6, $W - 48, '', (string)$label, (string)$id, $data, (bool)$primary); break; case 'curve': // the 10 bands: each a slider the finger drags up (louder) or down $bands = $wz->eq->bands; $bw = ($W - 48) / count($bands); $top = $y + 8; $span = 128.0; $mid = $top + $span / 2; $this->rect(24, $mid, $W - 48, 1, $this->col('line')); foreach ($bands as $k => $db) { $cx = 24 + $k * $bw + $bw / 2; $this->box($cx - 2, $top + 10, 4, $span - 20, $this->col('surface2'), 2); $hh = abs($db) / Equalizer::MAX * ($span / 2 - 10); $ink = $wz->eq->on ? $this->col('accent') : $this->col('line'); $this->box($cx - 3, $db >= 0 ? $mid - $hh : $mid, 6, max(2, $hh), $ink, 3); $ky = $mid - $db / Equalizer::MAX * ($span / 2 - 10); $this->circle($cx, $ky, 9, $this->col('surface')); $this->circle($cx, $ky, 7, $ink); $this->text(Equalizer::BANDS[$k], $cx, $top + $span + 14, 10, $this->col('muted'), false, 'center'); $this->hit($cx - $bw / 2, $top, $bw, $span, 'band', $k); } break; case 'preamp': $v = ($wz->eq->preamp - Equalizer::MIN) / (Equalizer::MAX - Equalizer::MIN); $this->text('Préampli', 24, $y + 28, 14, $this->col('muted')); $this->text(sprintf('%+.1f dB', $wz->eq->preamp), $W - 24, $y + 28, 14, $this->col('text'), true, 'right'); $sx = 110.0; $sw = $W - 110 - 96; $this->box($sx, $y + 26, $sw, 4, $this->col('line'), 2); $this->box($sx, $y + 26, max(4, $sw * $v), 4, $this->col('accent'), 2); $this->circle($sx + $sw * $v, $y + 28, 10, $this->col('surface')); $this->circle($sx + $sw * $v, $y + 28, 8, $this->col('accent')); $this->hit($sx - 14, $y + 4, $sw + 28, 48, 'preamp'); break; case 'chips': $current = $wz->eq->on ? (string)($wz->ui['mobile']['eqPreset'] ?? 'Plat') : ''; $cw = ($W - 48 - 16) / 3; foreach ($row[1] as $k => $name) { $cx = 24 + ($k % 3) * ($cw + 8); $cy = $y + intdiv($k, 3) * 48; $on = $name === $current; $fill = $on ? $this->col('accent') : ($this->pressed('eqPreset', $name) ? $this->col('line') : $this->col('surface2')); $this->box($cx, $cy + 4, $cw, 40, $fill, 20); $this->text($name, $cx + $cw / 2, $cy + 24, 14, $on ? $this->col('onAccent') : $this->col('text'), $on, 'center', $cw - 12); $this->hit($cx, $cy, $cw, 48, 'eqPreset', $name); } break; case 'swatches': $cw = ($W - 48 - 12) / 2; $k = 0; foreach (MobileTheme::THEMES as $id => $th) { $cx = 24 + ($k % 2) * ($cw + 12); $cy = $y + intdiv($k, 2) * 112; $on = $id === $this->themeId(); $this->box($cx, $cy, $cw, 100, $on ? $this->col('accent') : $this->col('line'), 18); $this->box($cx + 3, $cy + 3, $cw - 6, 94, $th['top'], 15); $this->gradientBox($cx + 14, $cy + 14, 44, 44, $th['art1'], $th['art2'], 12); $this->circle($cx + 80, $cy + 36, 14, $th['accent']); $this->icon('play', $cx + 72, $cy + 28, 16, $th['onAccent']); $this->text((string)$th['name'], $cx + 14, $cy + 78, 14, $th['text'], true, 'left', $cw - 28); if ($on) { $this->circle($cx + $cw - 22, $cy + 22, 12, $this->col('accent')); $this->icon('check', $cx + $cw - 31, $cy + 13, 18, $this->col('onAccent')); } $this->hit($cx, $cy, $cw, 100, 'theme', $id); $k++; } break; case 'note': $ty = $y + 16; foreach ($this->wrap((string)$row[1], 14, false, $W - 48) as $l) { $this->text($l, 24, $ty, 14, $row[2] ?? $this->col('muted')); $ty += 20; } break; case 'section': $this->text(mb_strtoupper((string)$row[1]), 24, $y + 28, 12.5, $this->col('accent'), true, 'left', $W - 140); if (($row[2] ?? '') !== '') { $this->text((string)$row[2], $W - 24, $y + 28, 13, $this->col('muted'), false, 'right'); } break; case 'input': $this->drawInput($row, $y); break; case 'chipset': [$places] = $this->chipsetLayout($row[1]); foreach ($row[1] as $k => [$label, $id, $data, $on]) { [$cx, $cy, $cw] = $places[$k]; $fill = $on ? $this->col('accent') : ($this->pressed($id, $data) ? $this->col('line') : $this->col('surface')); $this->box($cx, $y + $cy + 4, $cw, 40, $fill, 20); if (!$on) { $this->box($cx, $y + $cy + 4, $cw, 40, self::alpha($this->col('line'), 120), 20); $this->box($cx + 1, $y + $cy + 5, $cw - 2, 38, $fill, 19); } $this->text((string)$label, $cx + $cw / 2, $y + $cy + 24, 14, $on ? $this->col('onAccent') : $this->col('text'), (bool)$on, 'center'); $this->hit($cx, $y + $cy, $cw, 48, (string)$id, $data); } break; case 'row2': [, $icon, $label, $sub, $id, $data, $right] = $row; if ($this->pressed($id, $data)) { $this->rect($ix, $y, $W - 2 * $ix, $h, self::alpha($this->col('accent'), 25)); } $this->box(24, $y + 11, 44, 44, $this->col('soft'), 12); $this->icon($icon, 34, $y + 21, 24, $this->col('accent')); $this->text((string)$label, 80, $y + 23, 16, $this->col('text'), true, 'left', $W - 80 - ($right !== '' ? 60 : 30)); $this->text((string)$sub, 80, $y + 45, 13, $this->col('muted'), false, 'left', $W - 80 - ($right !== '' ? 60 : 30)); if ($right !== '') { $this->icon($right, $W - 52, $y + 21, 24, $right === 'check' ? $this->col('accent') : $this->col('muted')); } $this->hit($ix, $y, $W - 2 * $ix, $h, $id, $data); break; case 'result': [, $title, $sub, $id, $data, $rightIcon, $rightId] = $row; if ($this->pressed($id, $data)) { $this->rect($ix, $y, $W - 2 * $ix, $h, self::alpha($this->col('accent'), 25)); } $this->box(24, $y + 12, 44, 44, $this->col('soft'), 12); $this->icon((string)($row[7] ?? 'youtube'), 34, $y + 22, 24, $this->col('accent')); $this->text((string)$title, 80, $y + 24, 15, $this->col('text'), true, 'left', $W - 80 - 76); $this->text((string)$sub, 80, $y + 46, 13, $this->col('muted'), false, 'left', $W - 80 - 76); $this->hit($ix, $y, $W - 2 * $ix - 64, $h, $id, $data); $this->roundButton($W - 72, $y + 10, 48, (string)$rightIcon, (string)$rightId, $data, $this->col('accent'), $this->col('soft'), 24); break; case 'job': [, $title, $state, $progress, $index, $kind] = $row; $ink = $kind === 'error' ? $this->col('danger') : ($kind === 'done' ? $this->col('accent') : $this->col('muted')); $this->icon($kind === 'done' ? 'check' : ($kind === 'error' ? 'close' : 'download'), 24, $y + 14, 22, $ink); $right = $kind === 'error' ? 112.0 : 64.0; $this->text((string)$title, 56, $y + 24, 15, $this->col('text'), true, 'left', $W - 56 - $right); $this->text((string)$state, 56, $y + 46, 13, $ink, false, 'left', $W - 56 - $right); $bw = $W - 56 - $right; $this->box(56, $y + 60, $bw, 5, $this->col('surface2'), 2.5); if ($progress > 0) { $this->box(56, $y + 60, max(5, $bw * min(1.0, (float)$progress)), 5, $kind === 'error' ? $this->col('danger') : $this->col('accent'), 2.5); } if ($kind === 'error') { $this->roundButton($W - 120, $y + 15, 48, 'retry', 'ytRetry', $index, $this->col('accent'), null, 22); } $this->roundButton($W - 68, $y + 15, 48, 'close', 'ytRemove', $index, $this->col('muted'), null, 20); break; case 'stepper': [, $label, $sub, $minus, $plus, $id] = $row; $this->text((string)$label, 24, $y + 24, 16, $this->col('text'), false, 'left', $W - 200); $this->text((string)$sub, 24, $y + 46, 13, $this->col('muted'), false, 'left', $W - 200); foreach ([[$minus, -1, $W - 24 - 152], [$plus, 1, $W - 24 - 72]] as [$text, $sign, $bx]) { $fill = $this->pressed((string)$id, $sign) ? $this->col('line') : $this->col('surface2'); $this->box($bx, $y + 14, 72, 40, $fill, 20); $this->text((string)$text, $bx + 36, $y + 34, 14, $this->col('accent'), true, 'center'); $this->hit($bx - 4, $y + 8, 80, 52, (string)$id, $sign); } break; case 'progress': $this->text((string)$row[1], 24, $y + 12, 13, $this->col('muted'), false, 'left', $W - 48); $this->box(24, $y + 24, $W - 48, 6, $this->col('surface2'), 3); $this->box(24, $y + 24, max(6, ($W - 48) * min(1.0, (float)$row[2])), 6, $this->col('accent'), 3); break; case 'pills': $n = count($row[1]); $pw = ($W - 48 - 10 * ($n - 1)) / max(1, $n); foreach ($row[1] as $k => [$label, $id, $data, $primary]) { $this->pill(24 + $k * ($pw + 10), $y + 4, $pw, (string)($row[1][$k][4] ?? ''), (string)$label, (string)$id, $data, (bool)$primary); } break; case 'busy': $this->spinner(40, $y + $h / 2, 10); $this->text((string)$row[1], 62, $y + $h / 2, 14, $this->col('muted'), false, 'left', $W - 86); break; case 'line': [, $time, $text, $index, $state] = $row; if ($state === 'next') { $this->box($ix + 4, $y + 4, $W - 2 * $ix - 8, $h - 8, $this->col('soft'), 14); } $this->text((string)$time, 28, $y + $h / 2, 13, $state === 'todo' || $state === 'next' ? $this->col('muted') : $this->col('accent'), true); $this->text((string)$text, 96, $y + $h / 2, 15, $state === 'next' ? $this->col('accent') : $this->col('text'), $state === 'next', 'left', $W - 96 - 28); $this->hit($ix, $y, $W - 2 * $ix, $h, 'edLine', $index); break; case 'logo': $this->gradientBox($W / 2 - 40, $y + 8, 80, 80, $this->col('art1'), $this->col('art2'), 22); $this->icon('snow', $W / 2 - 26, $y + 22, 52, '#ffffff'); $this->text('WinZik', $W / 2, $y + 112, 26, $this->col('text'), true, 'center'); $this->text('Version ' . $wz->version(), $W / 2, $y + 138, 14, $this->col('muted'), false, 'center'); break; case 'text': $ty = $y + 18; foreach ($this->wrap((string)$row[1], 15, false, $W - 48) as $l) { $this->text($l, $W / 2, $ty, 15, $this->col('muted'), false, 'center'); $ty += 22; } break; default: if (!$this->drawLyricsRow($row, $y, $h)) { $this->drawCloudRow($row, $y, $h); } } $y += $h; } } /** the credits of 2001 (À propos), kept for the tests */ public static function credits(): array { return AboutScene::CREDITS; }}