index >= 0 && isset($this->wz->playlist->items[$this->index]); } /** Shows the card of a line near a point (desktop pixels), on the screen. */ public function showAt(int $index, float $dx, float $dy): void { $this->index = $index; [$mx, $my, $mw, $mh] = $this->desk->monitorAt($dx, $dy); $this->x = min($dx + 14, $mx + $mw - self::WIDTH - 2); $this->y = $dy + 16 + self::HEIGHT > $my + $mh ? $dy - self::HEIGHT - 8 : $dy + 16; } public function hide(): void { $this->index = -1; } public function render(Canvas $c): void { $file = $this->wz->playlist->items[$this->index] ?? null; if ($file === null) { return; } $skin = $this->wz->skin; $pal = $skin->palette(); $colors = $skin->colors; $c->fill(0, 0, self::WIDTH, self::HEIGHT, $pal['list']); $c->frame(0, 0, self::WIDTH, self::HEIGHT, $colors['barGreenLeft']); [$tag, $info] = $this->wz->describeLater($file); $path = $this->wz->path($file); $cover = $this->wz->covers()->picture($path, $tag); if ($cover === null || !$c->file($cover, 6, 6, 92, 92)) { // no picture (yet): a note on the skin's face $c->fill(6, 6, 92, 92, $pal['face']); // a note, drawn (the fonts have no ♪) $c->fill(58, 28, 3, 38, $pal['ink']); $c->fill(58, 28, 14, 4, $pal['ink']); $c->fill(68, 28, 4, 12, $pal['ink']); $c->fill(46, 60, 14, 10, $pal['ink']); } $more = $this->wz->covers()->info($path); $name = Text::baseName(Text::withoutExtension($file)); $title = $tag->title !== '' ? $tag->title : $name; $artist = $tag->artist !== '' ? $tag->artist : (string)($more['artist'] ?? ''); $album = $tag->album !== '' ? $tag->album : (string)($more['album'] ?? ''); $date = (string)($more['date'] ?? '') ?: $tag->year; $s = (int)round($info->duration); $stats = $this->wz->stats(); $rating = $stats->rating($path); $plays = $stats->plays($path); $mark = ($rating > 0 ? 'Note : ' . $rating . '/5 - ' : '') . ($plays > 0 ? 'écouté ' . $plays . ' fois - note d\'écoute ' . $stats->score($path) : 'jamais écouté en entier'); $lines = [ [$title, 9, $colors['active']], [$artist, 8, $colors['title']], [$album !== '' ? 'Album : ' . $album : '', 7.5, $colors['volume']], [$date !== '' ? 'Sortie : ' . $date : '', 7.5, $colors['volume']], [$tag->present && $tag->genre !== \App\Model\Id3Tag::OTHER ? 'Genre : ' . $tag->genreName() : '', 7.5, $colors['volume']], [$mark, 7, '#ffd040'], [trim(($s > 0 ? sprintf('%d:%02d', intdiv($s, 60), $s % 60) : '') . ($info->kbps > 0 ? ' - ' . $info->kbps . ' kbps' : '') . ' - ' . strtoupper(Text::extension($file)), ' -'), 7, '#a0a0b0'], ]; $y = 6; foreach ($lines as [$text, $size, $color]) { if ($text === '') { continue; } $c->text($c->fit($text, self::WIDTH - 112, $size), 106, $y, $size, $color); $y += $size + 5; } } }