EN
apps/winzik / src / Gui / CompactWindow.php · commit 6576d6f
<?phpnamespace App\Gui;/** * The compact mode (Form4 of 2001): mainp.bmp, 112 x 12, seven small buttons (previous, pause, play, next, back to the * player, open, lyrics). The "?" button opens it 20 pixels lower to show the scrolling title (Command7_Click). * In 2001 it sat on the title bar of the window in front; here it stays at the top right of the desktop. */final class CompactWindow extends SkinWindow{    public const WIDTH = 112;    /** its height folded (the buttons) and unfolded (the title under them) */    public const FOLDED = 13;    public const UNFOLDED = 33;    private const BUTTONS = ['prev' => 'arrp', 'pause' => 'pausep', 'play' => 'playp', 'next' => 'avp', 'back' => 'petitp', 'open' => 'helpp', 'lyrics' => 'lyrp'];    private float $shown = self::FOLDED;    private bool $started = false;    public function id(): string    {        return 'compact';    }    public function width(): float    {        return self::WIDTH;    }    public function height(): float    {        return round($this->shown);    }    public function visible(): bool    {        return $this->wz->ui['compact']['active'] && !$this->wz->ui['tray'];    }    public function controls(): array    {        $controls = [];        $i = 0;        foreach (array_keys(self::BUTTONS) as $id) {            $controls[$id] = [$i * 16, 0, 16, 13];            $i++;        }        return $controls;    }    public function update(float $dt): void    {        $target = $this->wz->ui['compact']['expanded'] ? self::UNFOLDED : self::FOLDED;        if (!$this->started) {            // at the start it is as it was left (unfolded: its saved place is the one of the bar unfolded)            $this->started = true;            $this->shown = $target;        }        if ($this->shown != $target) {            $before = $this->height();            [, $my, , $mh] = $this->desk->monitorAt($this->x + self::WIDTH / 2, $this->y + $before / 2);            // against the bottom of the screen: it unfolds upward, its bottom edge stays; anywhere else its top stays            $docked = $this->y + $before >= $my + $mh - $this->desk->bottomMargin() - 0.5;            $step = $dt * 60;            $this->shown = $this->shown < $target ? min($target, $this->shown + $step) : max($target, $this->shown - $step);            if ($docked && $this->visible()) {                $this->y = max($my, $this->y - ($this->height() - $before));                $this->remember();            }        }        if (!$this->visible()) {            // hidden: it waits where the player is, so it shows there (on a web page the corners belong to the page)            $this->x = (float)$this->wz->ui['main']['x'];            $this->y = (float)$this->wz->ui['main']['y'];        }    }    public function render(Canvas $c): void    {        $h = $this->height();        $c->fill(0, 0, self::WIDTH, $h, '#404040');        if (!$c->image('mainp', 0, 0)) {            $c->fill(0, 0, self::WIDTH, 12, '#606060');        }        $i = 0;        foreach (self::BUTTONS as $id => $picture) {            $c->image($picture, $i * 16, 0);            $this->pushed($c, $id);            $i++;        }        if ($h > 16) {            // Text4: the title in a black box, pink text            $c->fill(3, 16, 107, 15, '#000000');            if ($h >= 31) {                $c->text($c->fit($this->wz->scrolledTitle(), 104, 8), 5, 18, 8, '#ff8080');            }        }    }    protected function clicked(string $id, bool $double): void    {        $wz = $this->wz;        match ($id) {            'prev' => $wz->previous(),            'pause' => $wz->togglePause(),            'play' => $wz->play(),            'next' => $wz->next(),            'back' => $wz->toggleCompact(),                        // Command5_Click: the player comes back            'open' => $wz->ui['compact']['expanded'] = !$wz->ui['compact']['expanded'],            'lyrics' => $wz->toggleLyrics(),                       // Command8_Click            default => null,        };    }}