<?phpnamespace App\Gui;use App\Core\WinZik;use JumPHP\Gui\Overlay;use JumPHP\Gui\Pointer;use JumPHP\Gui\Theme;use JumPHP\Gui\Widget;use JumPHP\Kernel\Platform;use JumPHP\Renderer\Renderer;/** * The screen of 1999 where the windows of WinZik live: the player, its play list under it, the compact bar, the lyrics * across the bottom, the icon near the clock. Windows are dragged by their background and stick to the edges of the * screen (nbcot: 200 twips); the play list sticks under the player and follows it (attachehaut). A right click * anywhere opens the menu of WinZik. Everything is zoomed (the pictures are 258 pixels wide). * * A widget of the form (forms/MainForm.form.yaml: `class: App\Gui\Desktop`); the state is App\Core\WinZik. */final class Desktop extends Widget implements Overlay{ public const DEFAULTS = ['width' => 'fill', 'height' => 'fill', 'background' => '#008080']; /** the distance at which a window sticks to an edge (200 twips = 13 pixels) */ public const SNAP = 13; /** how near two windows stick together (desktop pixels) */ public const MAGNET = 16; public float $scale = 1.0; /** seconds, for the blinking things */ public float $clock = 0.0; public ?MainWindow $main = null; public ?PlaylistWindow $playlist = null; public ?LyricsBar $lyrics = null; public ?CompactWindow $compact = null; public ?EqWindow $eq = null; public ?VideoWindow $video = null; public ?CardWindow $card = null; public ?NoteWindow $note = null; /** the desktop version: each window is a window of the computer (App\Native\NativeShell drives them) */ public ?\App\Native\NativeShell $native = null; /** native: the window the pointer is in (it gets the press, whatever is under it) */ private ?SkinWindow $forced = null; /** native: the events the engine's window gives the form are not WinZik's (its window is hidden) */ private bool $fromNative = false; /** @var list<SkinWindow> back to front */ private array $windows = []; private ?PopupMenu $menu = null; /** the window pressed: [window, dragged?, grab x, grab y] */ private ?SkinWindow $grabbed = null; private bool $dragging = false; /** the list was docked when it was taken: dragging it carries the player (decided at the press, not at each step) */ private bool $carry = false; private float $grabX = 0; private float $grabY = 0; /** where the press started (desktop pixels): a control pressed then moved away from moves its window */ private float $pressX = 0; private float $pressY = 0; /** the windows unroll at the start and roll up at the end (Form15 / Picture17: SetWindowRgn) */ private float $reveal = 1.0; private float $closing = -1.0; /** the tooltip: control under the pointer and since when */ private string $tipKey = ''; private float $tipTime = 0; /** the window and the control of the tooltip */ private ?SkinWindow $tipWindow = null; private string $tipControl = ''; private float $mouseX = -1; private float $mouseY = -1; /** joystick: what was held at the last frame, when it repeats */ private array $padHeld = []; private array $padRepeat = []; private bool $built = false; private ?int $lastActive = null; /** * The phone app (Android, iPhone): one screen, the windows one under the other as wide as it (the player, the * equalizer, the list down to the bottom), nothing to drag, a long press for the menu, the buttons easier to touch. */ public bool $phone = false; /** tests (MainForm param phone): a phone's screen simulated, a column of the view this wide for its height (9 / 19.5) */ public float $phoneAspect = 0.0; /** a long press opens the menu (no right click on a phone): how long since the press, whether it moved */ private float $pressHeld = 0.0; private bool $pressMoved = false; /** the long press opened the menu: its release is not a click in it */ private bool $swallowUp = false; /** seconds held still for the menu */ public const LONG_PRESS = 0.5; /** a touch this near a control (skin pixels) is on it */ public const TOUCH_SLOP = 8.0; /** the phone: the bar at the bottom of the screen (its "≡ Menu" button, WinZik's button, the clock), skin pixels */ public const PHONE_BAR = 28; /** the long press under way: 0..1 of LONG_PRESS (a ring fills around the finger), 0 = none */ public float $ring = 0.0; /** where the finger went down (view pixels: the menu opens there, the ring is drawn there) */ private float $pressViewX = 0.0; private float $pressViewY = 0.0; /** a finger on the menu: where it went down, where it is, whether it slid (then it scrolls, nothing runs) */ private ?array $menuPress = null; /** the size of the texture the turned window is drawn in (view pixels) */ private array $turnedSize = [0, 0]; /** the film shown turned is wider than tall: its picture size, per film */ private array $filmShape = ['', true]; public static function events(): array { return ['click']; } public function focusable(): bool { return true; } public function host(): Host { $form = $this->form; if (!$form instanceof Host) { throw new \LogicException('The desktop lives in a form that implements App\Gui\Host'); } return $form; } public function wz(): WinZik { return $this->host()->winzik(); } private function build(): void { if ($this->built) { return; } $this->built = true; $wz = $this->wz(); $this->main = new MainWindow($wz, $this); $this->playlist = new PlaylistWindow($wz, $this); $this->compact = new CompactWindow($wz, $this); $this->lyrics = new LyricsBar($wz, $this); $this->eq = new EqWindow($wz, $this); $this->video = new VideoWindow($wz, $this); $this->card = new CardWindow($wz, $this); $this->note = new NoteWindow($wz, $this); $this->windows = [$this->note, $this->playlist, $this->eq, $this->video, $this->main, $this->compact, $this->lyrics, $this->card]; foreach ($this->windows as $window) { $window->restore(); } $this->reveal = ($wz->options['unroll'] ?? true) ? 0.0 : 1.0; $this->followMain(); } // size ------------------------------------------------------------------------------------------------------- protected function content(Theme $t, float $maxWidth, string $breakpoint): array { return [$maxWidth, 400]; } public function layout(Theme $t, float $x, float $y, float $w, float $h, string $breakpoint): void { $this->phone = $this->native === null && ($this->phoneAspect > 0 || Platform::isPhoneApp()); if ($this->phoneAspect > 0) { // the simulated screen: as big as the view lets it be, its proportions kept [$w, $h] = $w > $h * $this->phoneAspect ? [round($h * $this->phoneAspect), $h] : [$w, round($w / $this->phoneAspect)]; } parent::layout($t, $x, $y, $w, $h, $breakpoint); if ($this->native !== null) { return; // the zoom of the windows of the computer: NativeShell } if ($this->phone) { // the zoom follows the screen (a rotation, a resize): the windows fill its width, the menu's zoom is not used $this->baseScale = $this->scale = self::phoneScale($w, $h); if ($this->built) { $this->phoneLayout(); } return; } $zoom = $this->form !== null ? (string)($this->wz()->options['zoom'] ?? 'auto') : 'auto'; if (is_numeric($zoom) && (float)$zoom > 0) { $this->baseScale = (float)$zoom; } else { // the player and its list under it fit in the height, and the player in the width $this->baseScale = max(1.0, min(4.0, floor(min($w / 275, $h / 510) * 2) / 2)); } $this->scale = self::effectiveScale($this->baseScale, $this->zoomPct()); if ($this->built) { $this->keepInside(); } } /** * The zoom of the phone: upright, the player (258 pixels) as wide as the screen; on its side (landscape) the * player and the equalizer at the left, the list at the right, as tall as the screen. */ public static function phoneScale(float $w, float $h): float { if ($w > $h * 1.2) { return max(1.0, min($w / (2 * MainWindow::WIDTH), $h / (MainWindow::TALL + EqWindow::HEIGHT))); } // upright: the player across the screen; on a whole or half pixel of the screen when that loses little (sharp pixels) $fit = min($w / MainWindow::WIDTH, $h / (MainWindow::TALL + 150)); $crisp = floor($fit * 2) / 2; return max(1.0, $crisp >= $fit * 0.94 ? $crisp : $fit); } /** whether the phone shows two columns (on its side) */ public function phoneColumns(): bool { return $this->deskWidth() >= 2 * MainWindow::WIDTH - 0.5; } /** * The phone: the player at the top, the film and the equalizer under it (when shown), the list under them down to * the bottom of the screen (or the lyrics bar). Every frame: a window shown or hidden, the player unrolled... */ private function phoneLayout(): void { if ($this->main === null || $this->playlist === null) { return; } $wz = $this->wz(); $dw = $this->deskWidth(); $two = $this->phoneColumns(); $left = $two ? 0.0 : max(0.0, floor(($dw - MainWindow::WIDTH) / 2)); $y = 0.0; foreach ([$this->main, $this->video, $this->eq] as $window) { if ($window !== null && $window->visible() && !($window === $this->video && $this->video->full())) { [$window->x, $window->y] = [$left, $y]; $y += $window->height(); } } if ($this->compact !== null) { [$this->compact->x, $this->compact->y] = [$left, 0.0]; } $bottom = $this->deskHeight() - $this->bottomMargin() - ($this->lyrics !== null && $this->lyrics->visible() && !$this->lyrics->full() ? $this->lyrics->barHeight() : 0); // the list as wide as the screen (the player, 258 pixels, in its middle when the zoom left a little room) [$px, $py] = $two ? [(float)MainWindow::WIDTH, 0.0] : [0.0, $y]; $width = (int)max(PlaylistWindow::MIN_WIDTH, min(PlaylistWindow::MAX_WIDTH, floor($two ? $dw - MainWindow::WIDTH : $dw))); $fixed = PlaylistWindow::HEIGHT - PlaylistWindow::ROWS * PlaylistWindow::ROW_HEIGHT; $rows = (int)max(PlaylistWindow::MIN_ROWS, min(PlaylistWindow::MAX_ROWS, floor(($bottom - $py - $fixed) / PlaylistWindow::ROW_HEIGHT))); if (($wz->ui['playlist']['rows'] ?? null) !== $rows || ($wz->ui['playlist']['width'] ?? null) !== $width) { $wz->ui['playlist']['rows'] = $rows; $wz->ui['playlist']['width'] = $width; $wz->touch(); } [$this->playlist->x, $this->playlist->y] = [$px, $py]; } /** * The phone: a touch just beside a control (a finger is wider than a pixel of 2001) is on it: the point moved * onto the nearest control, when one is that near. @return array{0: float, 1: float} (window pixels) */ private function touchPoint(SkinWindow $window, float $x, float $y): array { if (!$this->phone || $window->controlAt($x, $y) !== '') { return [$x, $y]; } $best = null; $bestD = self::TOUCH_SLOP; foreach ($window->controls() as [$cx, $cy, $cw, $ch]) { if ($cw <= 0 || $ch <= 0) { continue; } $nx = max($cx, min($x, $cx + $cw - 0.01)); $ny = max($cy, min($y, $cy + $ch - 0.01)); $d = hypot($nx - $x, $ny - $y); if ($d < $bestD) { [$bestD, $best] = [$d, [$nx, $ny]]; } } return $best ?? [$x, $y]; } public function deskWidth(): float { return ($this->native !== null ? $this->native->screenWidth() : $this->w) / max(0.01, $this->scale); } public function deskHeight(): float { return ($this->native !== null ? $this->native->screenHeight() : $this->h) / max(0.01, $this->scale); } /** @return list<SkinWindow> back to front */ public function windows(): array { $this->build(); return $this->windows; } public function menu(): ?PopupMenu { return $this->menu; } /** room left at the bottom for the icon of the tray */ public function bottomMargin(): float { if ($this->native !== null) { return 0; // the lyrics go over the task bar of the computer } if ($this->phone) { return self::PHONE_BAR; } return ($this->form !== null && ($this->wz()->options['taskbar'] ?? false)) || ($this->form !== null && $this->wz()->ui['tray']) ? 28 : 0; } /** Desktop pixels of a view point. @return array{0: float, 1: float} */ private function toDesk(float $px, float $py): array { return [($px - $this->x) / $this->scale, ($py - $this->y) / $this->scale]; } // the windows ------------------------------------------------------------------------------------------------ private function windowAt(float $dx, float $dy): ?SkinWindow { if ($this->forced !== null) { return $this->forced; } for ($i = count($this->windows) - 1; $i >= 0; $i--) { if ($this->windows[$i]->contains($dx, $dy)) { return $this->windows[$i]; } } return null; } /** The play list stuck under the player follows it (Form1.Form_MouseMove: Form2.Top = Form1.Top + Form1.Height). */ public function followMain(): void { if ($this->main === null || $this->playlist === null) { return; } if ($this->phone) { $this->phoneLayout(); return; } if ($this->wz()->ui['playlist']['attached']) { // docked: right under the player, lined up on its left edge, always (whatever moved the player) $x = $this->main->x; $y = $this->main->y + $this->main->height(); if ($this->playlist->x !== $x || $this->playlist->y !== $y) { $this->playlist->x = $x; $this->playlist->y = $y; $this->playlist->remember(); } } } public function togglePlaylist(): void { $wz = $this->wz(); $wz->ui['playlist']['visible'] = !$wz->ui['playlist']['visible']; $this->followMain(); $wz->touch(); } /** picture20: everything goes away, an icon stays near the clock (Shell_NotifyIcon). */ public function toTray(): void { $this->native?->minimize(); $this->wz()->ui['tray'] = true; $this->menu = null; $this->wz()->touch(); } public function fromTray(): void { $this->wz()->ui['tray'] = false; $this->wz()->touch(); } /** picture18 (Command9_Click): the player and its list hide, the lyrics bar stays; its Q brings them back. */ public function lyricsOnly(): void { $this->wz()->ui['lyricsOnly'] = true; $this->wz()->touch(); } /** * How much of a window is there while the windows unroll (at the start) or roll up (at the end): its left part, * as wide as this (desktop pixels, 0 = none of it). 2001: SetWindowRgn(0, 0, x1r1, height) on each form, x1r1 * growing with a timer across the screen. The desktop version makes each window of the computer that wide. */ /** the windows unrolling or rolling up (drawn at every frame then) */ public function revealing(): bool { return $this->reveal < 1 || $this->closing >= 0; } public function revealed(SkinWindow $window): float { $cover = $this->closing >= 0 ? $this->closing : $this->reveal; if ($cover >= 1) { return $window->width(); } // the edge crosses the desktop; the desktop version's desktop is the whole screen: there it crosses the // windows of WinZik only (the player would be there at once), the lyrics bar (as wide as the screen) the screen $span = $this->deskWidth(); if ($this->native !== null && $window !== $this->lyrics) { $span = 0.0; foreach ($this->windows as $w) { if ($w !== $this->lyrics && $w->visible()) { $span = max($span, $w->x + $w->width()); } } $span = max(300.0, $span); } return max(0.0, min($window->width(), $span * $cover - $window->x)); } /** The close button: the windows roll up (when the option is on), then WinZik quits. */ public function quitWithEffect(): void { $this->menu = null; if (($this->wz()->options['unrollQuit'] ?? true) && $this->closing < 0) { $this->closing = 1.0; return; } $this->host()->quit(); } /** * The screen under a point (desktop pixels): in the desktop version each screen of the computer, else the window. * @return array{0: float, 1: float, 2: float, 3: float} */ public function monitorAt(float $dx, float $dy): array { return $this->native !== null ? $this->native->monitorAt($dx, $dy) : [0.0, 0.0, $this->deskWidth(), $this->deskHeight()]; } /** how many screens the computer has (1 outside the desktop version) */ public function screens(): int { return $this->native !== null ? $this->native->screenCount() : 1; } /** @return array{0: float, 1: float, 2: float, 3: float} the screen of the player (the lyrics, a film on the whole screen go there) */ public function playerMonitor(): array { if ($this->turned() !== null) { return [0.0, 0.0, $this->deskHeight(), $this->deskWidth()]; // the phone turned: its screen on its side } return $this->native !== null ? $this->native->playerMonitor() : [0.0, 0.0, $this->deskWidth(), $this->deskHeight()]; } /** * The phone held upright shows the karaoke on the whole screen, and a wide film on the whole screen, turned a quarter * (the user turns the phone, the app stays upright): that window, or null. */ public function turned(): ?SkinWindow { if (!$this->phone || $this->native !== null || $this->deskWidth() > $this->deskHeight()) { return null; } if ($this->video !== null && $this->video->full() && $this->video->visible() && $this->filmWide()) { return $this->video; } if ($this->lyrics !== null && $this->lyrics->full() && $this->lyrics->visible()) { return $this->lyrics; } return null; } /** the film playing is wider than tall (its pictures; true before the first one) */ private function filmWide(): bool { $film = (string)$this->wz()->player->file; if ($this->filmShape[0] !== $film) { $frame = $this->wz()->videoFrame(); if ($frame === null) { return true; } $size = @getimagesize($frame); $this->filmShape = [$film, !is_array($size) || $size[0] >= $size[1]]; } return (bool)$this->filmShape[1]; } /** A point of the phone's screen (desktop pixels) in the turned window (its own pixels, landscape). @return array{0: float, 1: float} */ private function turnedPoint(float $dx, float $dy): array { return [$dy, $this->deskWidth() - $dx]; } /** Windows stay on the screen when it gets smaller (or after a zoom). */ private function keepInside(): void { if ($this->phone) { $this->phoneLayout(); return; } $dw = $this->deskWidth(); $dh = $this->deskHeight(); foreach ([$this->main, $this->playlist, $this->compact, $this->eq, $this->video] as $window) { if ($window === null) { continue; } $window->x = max(0, min($window->x, $dw - $window->width())); $window->y = max(0, min($window->y, $dh - min($window->height(), 40))); } $this->followMain(); } /** Moves a window, stuck to the edges of the screen when it comes near them. */ private function moveWindow(SkinWindow $window, float $x, float $y): void { if ($this->phone) { return; // the phone: each window has its place } $wz = $this->wz(); if ($window === $this->playlist && $this->carry && $this->main !== null && $this->main->visible()) { // docked: the list moves the player with it (the whole stays together; the menu undocks it) $this->moveWindow($this->main, $this->main->x + ($x - $window->x), $this->main->y + ($y - $window->y)); return; } $w = $window->width(); $h = $window->height(); // the edges of the screen the window is on (several screens: each its own) [$mx, $my, $mw, $mh] = $this->monitorAt($x + $w / 2, $y + min($h, 40) / 2); if ($wz->options['snap'] ?? true) { if (abs($x - $mx) < self::SNAP) { $x = $mx; } elseif (abs($x + $w - ($mx + $mw)) < self::SNAP) { $x = $mx + $mw - $w; } if (abs($y - $my) < self::SNAP) { $y = $my; } elseif (abs($y + $h - ($my + $mh)) < self::SNAP) { $y = $my + $mh - $h; } } $x = max(-$w + 20, min($this->deskWidth() - 20, $x)); $y = max(0, min($this->deskHeight() - 12, $y)); if ($wz->options['snap'] ?? true) { [$x, $y] = $this->snapToWindows($window, $x, $y); } if ($window === $this->playlist && $this->main !== null) { // right under the player (Form2.Form_MouseMove, attachehaut = 1): docked, it follows it $wz->ui['playlist']['attached'] = $this->main->visible() && abs($y - ($this->main->y + $this->main->height())) < 0.5 && $x < $this->main->x + $this->main->width() && $x + $w > $this->main->x; } elseif ($window === $this->main && $this->playlist !== null && $this->playlist->visible() && !$wz->ui['playlist']['attached']) { // the player brought onto the top of the list: docked too if (abs($y + $h - $this->playlist->y) < 0.5 && $x < $this->playlist->x + $this->playlist->width() && $x + $w > $this->playlist->x) { $wz->ui['playlist']['attached'] = true; } } $dx = $x - $window->x; $window->x = $x; $window->y = $y; if ($window === $this->main && $wz->ui['playlist']['attached'] && $this->playlist !== null) { $this->playlist->x += $dx; $this->followMain(); $this->playlist->remember(); } $window->remember(); } /** * The magnet between the windows (2001 had it between the player and its list): an edge near another window's * edge goes against it, and then their sides line up when they are near. @return array{0: float, 1: float} */ private function snapToWindows(SkinWindow $window, float $x, float $y): array { $w = $window->width(); $h = $window->height(); $near = self::MAGNET; $attached = $this->wz()->ui['playlist']['attached']; foreach ([$this->main, $this->playlist, $this->eq, $this->video] as $o) { if ($o === null || $o === $window || !$o->visible()) { continue; } if ($window === $this->main && $o === $this->playlist && $attached) { continue; // it moves with the player } $ox = $o->x; $oy = $o->y; $ow = $o->width(); $oh = $o->height(); $overlapX = $x < $ox + $ow + $near && $x + $w > $ox - $near; $overlapY = $y < $oy + $oh + $near && $y + $h > $oy - $near; $snappedY = false; if ($overlapX) { if (abs($y - ($oy + $oh)) < $near) { $y = $oy + $oh; // under it $snappedY = true; } elseif (abs($y + $h - $oy) < $near) { $y = $oy - $h; // above it $snappedY = true; } if ($snappedY && abs($x - $ox) < $near) { $x = $ox; // and lined up } elseif ($snappedY && abs($x + $w - ($ox + $ow)) < $near) { $x = $ox + $ow - $w; } } if ($overlapY && !$snappedY) { $snappedX = false; if (abs($x - ($ox + $ow)) < $near) { $x = $ox + $ow; // at its right $snappedX = true; } elseif (abs($x + $w - $ox) < $near) { $x = $ox - $w; // at its left $snappedX = true; } if ($snappedX && abs($y - $oy) < $near) { $y = $oy; } } } return [$x, $y]; } /** * A vertical edge being dragged (the left / right side of a window being resized): it sticks to the left / right * sides of the other windows and of its screen when it comes near them. */ public function magnetEdge(SkinWindow $self, float $edge, float $y): float { $best = $edge; $near = self::MAGNET; [$mx, , $mw] = $this->monitorAt($edge, $y); $candidates = [$mx, $mx + $mw]; foreach ([$this->main, $this->playlist, $this->eq, $this->video] as $o) { if ($o !== null && $o !== $self && $o->visible()) { $candidates[] = $o->x; $candidates[] = $o->x + $o->width(); } } foreach ($candidates as $c) { if (abs($edge - $c) < $near) { $near = abs($edge - $c); $best = $c; } } return $best; } // the pointer's shape ------------------------------------------------------------------------------------------- /** @var array<int, mixed> SDL cursors made once */ private static array $cursors = []; private int $cursorNow = -1; /** The four arrows where a press moves a window (its background, a window being dragged), up-down on the dots of the list. */ private function pointerShape(?SkinWindow $under): void { if (Platform::isHeadless() || Platform::isWasm() || !function_exists('SDL_CreateSystemCursor')) { return; } $shape = \SDL_SYSTEM_CURSOR_ARROW; if ($this->dragging && $this->grabbed !== null) { $shape = \SDL_SYSTEM_CURSOR_SIZEALL; } elseif ($this->grabbed !== null && in_array($this->grabbed->pressedControl(), ['gripL', 'gripR'], true)) { $shape = $this->grabbed->pressedControl() === 'gripR' ? \SDL_SYSTEM_CURSOR_SIZENWSE : \SDL_SYSTEM_CURSOR_SIZENESW; } elseif ($under !== null && $this->menu === null) { $control = $under->controlAt($this->mouseX - $under->x, $this->mouseY - $under->y); $shape = match (true) { // the dots of the list: longer / wider; its background: the window moves; a button: the little hand $control === 'gripR' => \SDL_SYSTEM_CURSOR_SIZENWSE, $control === 'gripL' => \SDL_SYSTEM_CURSOR_SIZENESW, $control === '' && $under !== $this->lyrics => \SDL_SYSTEM_CURSOR_SIZEALL, $control === '' || $control === 'list' || $control === 'picture' => \SDL_SYSTEM_CURSOR_ARROW, default => \SDL_SYSTEM_CURSOR_HAND, }; } elseif ($this->menu !== null && $this->menu->contains($this->mouseX, $this->mouseY)) { $shape = \SDL_SYSTEM_CURSOR_HAND; } if ($shape === $this->cursorNow) { return; } $this->cursorNow = $shape; self::$cursors[$shape] ??= \SDL_CreateSystemCursor($shape); if (self::$cursors[$shape]) { \SDL_SetCursor(self::$cursors[$shape]); } } /** Escape: the menu closes, else the lyrics on the whole screen roll back. */ private function escape(): void { if ($this->menu !== null) { if (!$this->menu->back()) { $this->menu = null; // a submenu opened in its place (the phone) goes back first } } elseif ($this->video !== null && $this->video->full()) { $this->video->toggleFull(); } elseif ($this->lyrics !== null && $this->lyrics->full()) { $this->lyrics->toggleFull(); } } // the zoom --------------------------------------------------------------------------------------------------- /** the zoom of the menu: with the screen's scale (x1 .. x4 by halves) it falls on halves too (crisp pixels) */ public const ZOOMS = [200, 150, 125, 100, 75, 50]; /** * The scale WinZik is drawn at: the screen's times the zoom, on a half (x1, x1.5, x2, x2.5...), never under x1. A * pixel of the skins is then 1, 1.5, 2... pixels of the screen: x1.2 made every line of one pixel blurred. */ public static function effectiveScale(float $base, int $pct): float { return max(1.0, round($base * $pct / 100 * 2) / 2); } /** the scale before the zoom of the menu (the window's, or the screen's in the desktop version) */ public float $baseScale = 2.0; public function zoomPct(): int { $pct = (int)($this->wz()->options['zoomPct'] ?? 100); if (in_array($pct, self::ZOOMS, true)) { return $pct; } // a zoom of before (120, 80, 60, 40 %): the nearest one $best = 100; foreach (self::ZOOMS as $z) { if (abs($z - $pct) < abs($best - $pct)) { $best = $z; } } return $best; } /** The whole of WinZik smaller or bigger (the texts are drawn at their new size: they stay sharp). */ public function setZoom(int $pct): void { $this->wz()->options['zoomPct'] = in_array($pct, self::ZOOMS, true) ? $pct : 100; $this->wz()->touch(); $this->applyZoom(); } /** Ctrl + wheel: one step of the zoom. */ public function zoomStep(float $notches): void { $zooms = array_reverse(self::ZOOMS); $i = (int)array_search($this->zoomPct(), $zooms, true); $this->setZoom($zooms[max(0, min(count($zooms) - 1, $i + ($notches > 0 ? 1 : -1)))]); } public function applyZoom(): void { $this->scale = self::effectiveScale($this->baseScale, $this->zoomPct()); if ($this->built && $this->native === null) { $this->keepInside(); } } private function ctrlHeld(): bool { $keyboard = $this->form?->engineOrNull()?->input->getKeyboard(); return $keyboard !== null && ($keyboard->isKeyHeld(\SDLK_LCTRL) || $keyboard->isKeyHeld(\SDLK_RCTRL)); } // loading songs ---------------------------------------------------------------------------------------------- /** The system's own file chooser (the installed WinZik, zenity / Windows), else WinZik's window of 2001. */ public function systemPicker(): bool { return Platform::isDesktop() && !Platform::isWasm() && !Platform::isHeadless() && \JumPHP\Native\Native::supports('open'); } /** A menu at a point (desktop pixels): made for a finger on the phone. */ private function popup(array $items, float $dx, float $dy): PopupMenu { // the phone: above its bar (the menu never covers the Menu button, nor goes under it) $bounds = $this->phone ? [0.0, 0.0, $this->deskWidth(), $this->deskHeight() - self::PHONE_BAR] : $this->monitorAt($dx, $dy); return new PopupMenu($items, $dx, $dy, $this->deskWidth(), $this->deskHeight(), $bounds, null, $this->phone); } /** L, or + of the play list: files, a whole folder, or several folders, with the system's window. */ public function openLoad(float $dx, float $dy): void { if (!$this->systemPicker()) { $this->host()->openFiles(); return; } $this->menu = $this->popup([ ['label' => 'Des fichiers (MP3, MP4...)', 'run' => fn () => $this->pick('files')], ['label' => 'Un dossier entier', 'run' => fn () => $this->pick('folder')], ['label' => 'Plusieurs dossiers', 'run' => fn () => $this->pick('folders')], ['separator' => true, 'label' => ''], ['label' => "La fenêtre d'ajout de WinZik", 'run' => fn () => $this->host()->openFiles()], ], $dx, $dy); } private function pick(string $kind): void { $wz = $this->wz(); $media = array_merge(\App\Model\Playlist::AUDIO, \App\Model\Playlist::VIDEO); $options = ['title' => match ($kind) { 'files' => 'Ajouter des morceaux à la playlist', 'folder' => 'Ajouter un dossier entier (et ses sous-dossiers)', default => 'Ajouter des dossiers (Ctrl + clic pour en choisir plusieurs)', }, 'directory' => (string)($wz->options['lastDir'] ?? '') ?: \App\Media\MediaDirs::user('MUSIC')]; $options += match ($kind) { 'files' => ['multiple' => true, 'filters' => ['Musique et vidéos' => $media, 'Tous les fichiers' => ['*']]], 'folder' => ['folder' => true], default => ['folder' => true, 'multiple' => true], }; \JumPHP\Native\FilePicker::open($options)->then(function (mixed $chosen) use ($wz): void { $paths = array_values(array_filter(is_array($chosen) ? $chosen : [$chosen], 'is_string')); if ($paths === []) { return; } $wz->options['lastDir'] = is_dir($paths[0]) ? dirname(rtrim($paths[0], '/\\')) : dirname($paths[0]); $added = $wz->addPaths($paths); if ($added > 0) { $wz->notice($added . ' fichier(s) ajouté(s) à la playlist', 5); } }, fn (\Throwable $e) => $wz->notice('Fenêtre de fichiers impossible : ' . $e->getMessage(), 6)); } // the menu --------------------------------------------------------------------------------------------------- /** @return list<array> the menu of 2001 (Form7), adapted: no plugins, no priority, no Internet Explorer */ public function menuItems(): array { $wz = $this->wz(); $host = $this->host(); $menu = [ ['label' => 'Play', 'run' => fn () => $wz->play()], ['label' => 'Pause', 'run' => fn () => $wz->pause()], ['label' => 'Stop', 'run' => fn () => $wz->stop()], ['label' => 'Hasard', 'checked' => $wz->playlist->shuffle, 'run' => fn () => $wz->toggleShuffle()], ['label' => 'Précédent', 'run' => fn () => $wz->previous()], ['label' => 'Suivant', 'run' => fn () => $wz->next()], ['separator' => true, 'label' => ''], ['label' => 'Mode Lock', 'run' => fn () => $host->openLock()], ['label' => 'Afficher paroles', 'checked' => (bool)$wz->ui['lyrics']['visible'], 'run' => fn () => $wz->toggleLyrics()], ['label' => 'Aller chercher les paroles sur le net', 'run' => fn () => $host->downloadLyrics()], // --- lyrics: the search on the Internet (the dialog), the translation ['label' => 'Chercher les paroles (Internet, Claude)…', 'run' => fn () => $this->lyricsSearch()], ['label' => 'Afficher la traduction (T)', 'checked' => $wz->showsTranslation(), 'run' => fn () => $wz->toggleTranslation()], $this->translateItem(), // --- end lyrics ['label' => 'Paroles en plein écran', 'checked' => $this->lyrics?->full() ?? false, 'run' => function () use ($wz): void { $wz->ui['lyrics']['visible'] = true; $this->lyrics?->toggleFull(); }], ['label' => 'Paroles synchronisées (LRCLIB)', 'run' => fn () => $wz->fetchSyncedLyrics(true)], ['label' => 'Editeur de paroles', 'run' => fn () => $host->openLyricsEditor()], ...($wz->transcriber !== null ? [['label' => \App\Media\Transcriber::claude() !== null && ($wz->options['whisperClaude'] ?? true) ? 'Créer les paroles (Whisper + Claude)' : 'Créer les paroles (Whisper)', 'run' => fn () => $wz->transcribe()]] : []), ...($wz->transcriber !== null && \App\Media\Transcriber::claude() !== null ? [['label' => 'Chercher les paroles sur Internet (Claude)', 'run' => fn () => $wz->transcribe('internet')]] : []), ['label' => 'Marketplace des paroles', 'run' => fn () => $host->openMarket('lyrics')], ['label' => 'Informations du morceau (tag)', 'run' => fn () => $host->openTags()], ]; $options = [ ['label' => 'Choisir un plugins', 'run' => fn () => $host->openPlugins()], ['label' => 'Choisir un Skin', 'run' => fn () => $host->openSkins()], ['label' => 'Editeur de skins (EDT)', 'run' => fn () => $host->openSkinEditor()], ['label' => 'Marketplace des skins', 'run' => fn () => $host->openMarket('skin')], ['label' => 'Répertoire secondaire des paroles', 'run' => fn () => $host->openOptions()], ...($this->phone ? [] : [['label' => 'Configurer le Joystick', 'run' => fn () => $host->openControls()]]), ['label' => 'Configurer WinZiK', 'run' => fn () => $host->openOptions()], ]; $items = [ ['label' => 'Menu', 'sub' => $menu], ['label' => 'Options', 'sub' => $options], ['label' => 'Playlist', 'checked' => (bool)$wz->ui['playlist']['visible'], 'run' => fn () => $this->togglePlaylist()], // --- lyrics: the play mode "only the songs with lyrics" ['label' => 'Seulement les morceaux avec paroles', 'checked' => $wz->playsLyricsOnly(), 'run' => fn () => $wz->setLyricsOnly(!$wz->playsLyricsOnly())], // --- end lyrics ...$this->cloudItems(), ...$this->castItems(), // cast: Caster sur la TV… // the phone: no mini bar over the other windows, nothing to shrink into a task bar, nothing to quit (the system does) ...($this->phone ? [] : [['label' => 'Mode compact', 'checked' => (bool)$wz->ui['compact']['active'], 'run' => fn () => $wz->toggleCompact()]]), ['label' => 'Egaliseur', 'checked' => (bool)$wz->ui['eq']['visible'], 'run' => fn () => $wz->toggleEq()], ...($this->phone ? [] : [['label' => 'Playlist attachée au lecteur', 'checked' => (bool)$wz->ui['playlist']['attached'], 'run' => function () use ($wz): void { $wz->ui['playlist']['attached'] = !$wz->ui['playlist']['attached']; if ($wz->ui['playlist']['attached'] && $this->main !== null && $this->playlist !== null) { $this->playlist->x = $this->main->x; // under the player, lined up $this->followMain(); $this->playlist->remember(); } $wz->touch(); }]]), ...($this->native !== null && $wz->ui['compact']['active'] ? [['label' => 'Mini barre sur la fenêtre active', 'checked' => (bool)($wz->options['compactFollow'] ?? true), 'run' => function () use ($wz): void { $wz->options['compactFollow'] = !($wz->options['compactFollow'] ?? true); $wz->touch(); }]] : []), ['label' => 'Sauter les blancs et les intros', 'checked' => $wz->skipBlanks(), 'run' => function () use ($wz): void { $wz->options['skipBlanks'] = !$wz->skipBlanks(); $wz->touch(); }], ...($this->native !== null ? [['label' => 'Toujours au-dessus', 'checked' => (bool)($wz->options['onTop'] ?? true), 'run' => function () use ($wz): void { $wz->options['onTop'] = !($wz->options['onTop'] ?? true); $wz->touch(); }]] : []), ...($this->phone ? [] : [['label' => 'Zoom', 'sub' => array_map(fn (int $pct) => ['label' => $pct . ' %', 'checked' => $this->zoomPct() === $pct, 'run' => fn () => $this->setZoom($pct)], self::ZOOMS)]]), ...($wz->youtube !== null ? [['label' => 'YouTube (chercher, MP3 / MP4)', 'run' => fn () => $host->openYoutube()], // Spotify's search (the user's own identifiers, Options): its songs, each taken from YouTube ['label' => 'Chercher sur Spotify…', 'run' => function () use ($wz, $host): void { $wz->youtube->source = 'spotify'; $host->openYoutube(); }], ['label' => 'Importer mes playlists Spotify…', 'run' => fn () => $host->openSpotify()]] : []), ...($wz->playingVideo() ? [['label' => 'Vidéo', 'checked' => (bool)($wz->ui['video']['visible'] ?? true), 'run' => function () use ($wz): void { $wz->ui['video']['visible'] = !($wz->ui['video']['visible'] ?? true); $wz->touch(); }]] : []), ...($this->phone ? [] : [['label' => 'Réduire dans la barre', 'run' => fn () => $this->toTray()]]), ...($this->phone && $this->native === null ? [ // the phone: the karaoke on the whole screen (turned: the phone held on its side), the other interface ['label' => 'Karaoké plein écran (téléphone en paysage)', 'checked' => $this->lyrics?->full() ?? false, 'run' => function () use ($wz): void { $wz->ui['lyrics']['visible'] = true; $this->lyrics?->toggleFull(); }], ['label' => 'Interface mobile', 'run' => fn () => $host->openMobileUi()], ] : []), ['separator' => true, 'label' => ''], ['label' => 'Le site WinZik (archive)', 'run' => fn () => $host->openWebsite()], ['label' => 'A propos', 'run' => fn () => $host->openAbout()], ]; $updater = $wz->updater; if ($updater !== null && $updater->enabled()) { $items[] = $updater->state === 'installed' ? ['label' => 'Redémarrer (WinZik ' . $updater->version . ')', 'run' => fn () => $updater->relaunch() && $host->quit()] : ['label' => 'Rechercher une mise à jour', 'enabled' => $updater->state !== 'checking' && $updater->state !== 'installing', 'run' => fn () => $updater->check()]; } if (Platform::isDesktop() && !$this->phone) { $items[] = ['label' => 'Quitter', 'run' => fn () => $this->quitWithEffect()]; } if ($wz->ui['tray']) { array_unshift($items, ['label' => 'Ouvrir WinZik', 'run' => fn () => $this->fromTray()], ['separator' => true, 'label' => '']); } return $items; } /** The "+" of the lyrics: the ways to get the lyrics of the song playing. */ /** * The menu of the lyrics bar's "+": above the bar when it is at the bottom of its screen, under it when it is at * the top (it went up, away from the pointer): always whole on that screen. */ public function openLyricsMenuAt(float $dx, float $barTop, float $barBottom): void { $this->openLyricsMenu($dx, $barBottom); $menu = $this->menu; if ($menu === null) { return; } [$mx, $my, $mw, $mh] = $this->monitorAt($dx, $barTop); $below = $barTop - $my < $my + $mh - $barBottom; // the bar is in the upper half: the menu opens downwards $menu->y = $below ? $barBottom : $barTop - $menu->height(); $menu->y = max($my, min($menu->y, $my + $mh - $menu->height())); $menu->x = max($mx, min($menu->x, $mx + $mw - $menu->width - 2)); } /** The lyrics asked from the icon: the bar (or the whole screen); WinZik hidden in the tray: the lyrics alone. */ private function lyricsFromTray(bool $full): void { $wz = $this->wz(); if ($wz->ui['tray']) { $wz->ui['tray'] = false; $wz->ui['lyricsOnly'] = true; } $wz->ui['lyrics']['visible'] = true; $wz->ui['lyrics']['full'] = $full; $wz->touch(); } /** The menu of the icon in the notification area, at the point clicked on it (desktop pixels). */ public function openTrayMenu(float $dx, float $dy): void { $wz = $this->wz(); $this->menu = $this->popup([ ['label' => 'Afficher WinZik', 'run' => fn () => $this->native?->wakeUp()], ['label' => 'Play / Pause', 'run' => fn () => $wz->togglePause()], ['label' => 'Suivant', 'run' => fn () => $wz->next()], ['label' => 'Mode compact', 'run' => fn () => $wz->toggleCompact()], ['separator' => true, 'label' => ''], ['label' => 'Afficher les paroles (barre en bas)', 'run' => fn () => $this->lyricsFromTray(false)], ['label' => 'Paroles en plein écran', 'run' => fn () => $this->lyricsFromTray(true)], ['separator' => true, 'label' => ''], ['label' => 'Quitter', 'run' => fn () => $wz->quit()], ], $dx, $dy); } public function openLyricsMenu(float $dx, float $dy): void { $wz = $this->wz(); $host = $this->host(); $claude = \App\Media\Transcriber::claude() !== null; // --- lyrics: the search dialog first, the translation $items = [['label' => 'Chercher les paroles (Internet, Claude)…', 'run' => fn () => $this->lyricsSearch()]]; if ($wz->lyrics !== null) { $items[] = $this->translateItem(); $items[] = ['label' => 'Afficher la traduction (T)', 'checked' => $wz->showsTranslation(), 'run' => fn () => $wz->toggleTranslation()]; } $items[] = ['separator' => true, 'label' => '']; // --- end lyrics if ($wz->transcriber !== null) { $items[] = ['label' => $claude ? 'Créer les paroles (Whisper + Claude)' : 'Créer les paroles (Whisper)', 'run' => fn () => $wz->transcribe()]; if ($claude) { $items[] = ['label' => 'Chercher les paroles sur Internet (Claude)', 'run' => fn () => $wz->transcribe('internet')]; } } $items[] = ['label' => 'Paroles synchronisées (LRCLIB)', 'run' => fn () => $wz->fetchSyncedLyrics(true)]; $items[] = ['label' => 'Marketplace des paroles', 'run' => fn () => $host->openMarket('lyrics')]; $items[] = ['separator' => true, 'label' => '']; $items[] = ['label' => 'Editeur de paroles', 'run' => fn () => $host->openLyricsEditor()]; $this->menu = $this->popup($items, $dx, $dy); } // --- lyrics: the search dialog, the translation now --- /** * The search of lyrics on the Internet (App\Form\LyricsSearchForm) for a song: the one given (the dot of a line of the * play list), else the line the menu was opened on, else the song playing. */ public function lyricsSearch(?string $file = null): void { $wz = $this->wz(); $file ??= isset($this->menuLines[0]) && count($this->menuLines) === 1 ? ($wz->playlist->items[$this->menuLines[0]] ?? null) : null; $file ??= $wz->playlist->current(); if ($file === null) { $wz->notice('Choisissez d\'abord un morceau dans la playlist', 3); return; } $this->menu = null; $this->host()->openLyricsSearch($file); } /** "Traduire les paroles maintenant", or where the translation is while it runs. @return array<string, mixed> */ private function translateItem(): array { $wz = $this->wz(); $state = $wz->translationState(); if ($state['state'] === 'translating') { return ['label' => sprintf('Traduction en cours… %d %%', (int)round($state['progress'] * 100)), 'enabled' => false]; } return ['label' => 'Traduire les paroles maintenant (' . \App\Model\Language::name($wz->translationLang()) . ')', 'enabled' => $wz->lyrics !== null, 'run' => function () use ($wz): void { $wz->notice('Traduction des paroles…', 3); $wz->translate()->then(fn () => null, fn (\Throwable $e) => $wz->notice('Traduction impossible : ' . $e->getMessage(), 6)); }]; } // --- end lyrics /** The presets of the equalizer, as a menu under its button. */ public function openPresets(float $dx, float $dy): void { $wz = $this->wz(); $items = []; foreach (array_keys(\App\Model\Equalizer::PRESETS) as $name) { $items[] = ['label' => $name, 'run' => function () use ($wz, $name): void { $wz->eq->preset($name); $wz->eqChanged(); }]; } $this->menu = $this->popup($items, $dx, $dy); } /** Overlay: the form calls it on a right click (PopupMenu Form7.abc). */ public function openMenu(float $px, float $py): void { if ($this->native !== null && !$this->fromNative) { return; } $this->build(); [$dx, $dy] = $this->toDesk($px, $py); $this->menuLines = $this->linesAt($dx, $dy); $this->menu = $this->popup($this->menuItems(), $dx, $dy); } // --- cloud: the menu of the cloud playlist (App\Cloud\Cloud) --- /** @var list<int> the lines of the play list the menu is about (the ones chosen, else the one under the pointer) */ public array $menuLines = []; /** @return list<int> */ private function linesAt(float $dx, float $dy): array { $pl = $this->playlist; if ($pl === null || !$pl->visible()) { return []; } if ($pl->selection !== []) { return array_map('intval', array_keys(array_filter($pl->selection))); } if ($dx < $pl->x || $dx >= $pl->x + $pl->width() || $dy < $pl->y || $dy >= $pl->y + $pl->height()) { return []; } $row = $pl->rowAt($dy - $pl->y); $index = $row < 0 || $pl->grouped() ? -1 : $pl->indexAt($pl->top() + $row); return $index >= 0 ? [$index] : []; } /** * Playlist : Ma playlist / Playlist cloud (mon compte); on lines: Mettre dans le cloud (the PC sends the MP3, or the * phone gets it from YouTube), Copier sur cet appareil, Retirer du cloud; Mon compte cloud. Nothing without a cloud here. * @return list<array<string, mixed>> */ private function cloudItems(): array { $wz = $this->wz(); $cloud = $wz->cloud(); if ($cloud === null || $cloud->state() === 'off') { return []; } $host = $this->host(); $signed = $cloud->signedIn(); $files = []; foreach ($this->menuLines as $i) { if (isset($wz->playlist->items[$i])) { $files[] = $wz->playlist->items[$i]; } } $outside = array_values(array_filter($files, fn (string $f) => $cloud->entryOfItem($f) === null && !\App\Cloud\Cloud::isPseudo($f))); $inside = array_values(array_filter(array_map(fn (string $f) => $cloud->entryOfItem($f)['id'] ?? null, $files))); $absent = array_values(array_filter($inside, fn (string $id) => $cloud->playlist->fileOf($id) === null)); $put = function (string $how) use ($cloud, $outside, $wz): void { $n = $how === 'pc' ? $cloud->putFromPc($outside) : $cloud->putFromYoutube($outside); $wz->notice($n > 0 ? $n . ' morceau(x) mis dans le cloud' : ($cloud->message ?: 'Rien à mettre dans le cloud'), 5); if ($this->playlist !== null) { $this->playlist->selection = []; } }; $items = [ ['label' => 'Playlist : Ma playlist', 'checked' => $cloud->view() === 'local', 'run' => fn () => $cloud->useView('local')], ['label' => 'Playlist : Playlist cloud (mon compte)', 'checked' => $cloud->view() === 'cloud', 'run' => fn () => $signed ? $cloud->useView('cloud') : $host->openCloud()], ]; if ($outside !== []) { $items[] = ['label' => 'Mettre dans le cloud', 'enabled' => $signed, 'sub' => [ ['label' => 'Le PC envoie le MP3', 'run' => fn () => $put('pc')], ['label' => 'Le mobile la récupère sur YouTube', 'run' => fn () => $put('youtube')], ]]; } if ($absent !== []) { $items[] = ['label' => 'Copier sur cet appareil', 'run' => function () use ($cloud, $absent): void { foreach ($absent as $id) { $cloud->fetch($id); } }]; } if ($inside !== []) { $items[] = ['label' => 'Retirer du cloud', 'run' => fn () => $cloud->remove($inside)]; } if ($signed && $cloud->playSync !== null) { // « Lecture synchronisée »: the same song, pause, position and volume on every device of the account (or this one alone) $items[] = ['label' => 'Lecture synchronisée avec mes appareils', 'checked' => $cloud->playSynced(), 'run' => function () use ($cloud, $wz): void { $cloud->setPlaySync(!$cloud->playSynced()); $wz->notice($cloud->playSynced() ? 'Lecture synchronisée avec vos appareils' : 'Lecture indépendante : cet appareil joue seul', 4); }]; if ($cloud->syncLabel() !== '') { $items[] = ['label' => $cloud->syncLabel(), 'enabled' => false]; } } $items[] = ['label' => $signed ? 'Mon compte cloud (' . $cloud->login() . ')…' : 'Mon compte cloud…', 'run' => fn () => $host->openCloud()]; return $items; } // --- end cloud --- // --- cast: the music and the lyrics on the TV (App\Cast\Cast, App\Form\CastForm; AGENTS.md "Cast") --- /** @return list<array<string, mixed>> Caster sur la TV… (and Arrêter la diffusion while it casts); nothing in the browser */ private function castItems(): array { $cast = $this->wz()->cast(); $engine = $this->form?->engineOrNull(); if ($cast === null || $engine === null) { return []; } $open = fn () => $engine->scenes->push(\App\Form\CastForm::class); if (!$cast->active()) { return [['label' => 'Caster sur la TV…', 'run' => $open]]; } return [ ['label' => 'Caster sur la TV… (' . ($cast->device()->name ?? 'navigateur') . ')', 'checked' => true, 'run' => $open], ['label' => 'Arrêter la diffusion sur la TV', 'run' => fn () => $cast->disconnect()], ]; } // --- end cast --- public function hasMenu(): bool { return $this->menu !== null; } /** Tests: the labels of the menu open (and of its submenu). @return list<string> */ public function menuLabels(): array { $labels = []; foreach ([$this->menu, $this->menu?->child] as $menu) { foreach ($menu === null ? [] : $menu->items as $item) { if (empty($item['separator'])) { $labels[] = (string)$item['label']; } } } return $labels; } public function hoverAt(float $py): void { } /** Overlay: the menu closes. */ public function close(): void { $this->menu = null; } // input ------------------------------------------------------------------------------------------------------ /** NativeShell: the pointer in a window of the computer (desktop pixels). $what: down | drag | up | right | wheel */ public function nativePointer(string $what, float $dx, float $dy, ?SkinWindow $in, bool $double = false, float $wheel = 0): void { $p = new Pointer(); [$p->x, $p->y, $p->double, $p->wheel] = [$this->x + $dx * $this->scale, $this->y + $dy * $this->scale, $double, $wheel]; $this->forced = $in; $this->fromNative = true; try { match ($what) { 'down' => $this->pointerDown($p), 'drag' => $this->pointerDrag($p), 'up' => $this->pointerUp($p, true), 'right' => $this->openMenu($p->x, $p->y), 'wheel' => $this->ctrlHeld() ? $this->zoomStep($wheel) : $in?->wheel($wheel), default => null, }; } finally { $this->forced = null; $this->fromNative = false; } } public function pointerDown(Pointer $p): void { if ($this->native !== null && !$this->fromNative) { return; } $this->build(); [$dx, $dy] = $this->toDesk($p->x, $p->y); [$this->pressViewX, $this->pressViewY] = [$p->x, $p->y]; $this->menuPress = null; $this->swallowUp = false; if ($this->menu !== null) { if ($this->menu->contains($dx, $dy)) { $this->grabbed = null; if ($this->menu->touch) { // a finger: the row lights; slid, the rows scroll; lifted where it went down, the row runs $this->menuPress = [$dy, $dy, false]; $this->menu->pressAt($dx, $dy); } return; // the click is done when it is let go } $this->menu = null; if ($this->phone) { // a tap beside the menu closes it, and only that [$this->grabbed, $this->swallowUp] = [null, true]; return; } } if ($this->phone && $this->turned() === null && $this->phoneBar($dx, $dy)) { [$this->grabbed, $this->swallowUp] = [null, true]; return; } if (!$this->phone && (($this->wz()->options['taskbar'] ?? false) || $this->wz()->ui['tray'])) { [$bx, $by, $bw, $bh] = $this->taskButton(); if ($dx >= $bx && $dx < $bx + $bw && $dy >= $by && $dy < $by + $bh) { $this->wz()->ui['tray'] ? $this->fromTray() : $this->toTray(); return; } } if (!$this->phone && $this->wz()->ui['tray'] && $this->trayContains($dx, $dy)) { $this->fromTray(); // a click on the icon (2001: DOUBLE_CLICK_GAUCHE; one click on a page) return; } $turned = $this->turned(); if ($turned !== null) { // the phone turned: the whole screen is that window, on its side [$dx, $dy] = $this->turnedPoint($dx, $dy); $window = $turned; } else { $window = $this->windowAt($dx, $dy); } $this->grabbed = $window; $this->dragging = false; [$this->pressHeld, $this->pressMoved, $this->swallowUp] = [0.0, false, false]; if ($window === null) { return; } // the window comes to the front (the lyrics bar stays above everything) if ($window !== $this->lyrics) { $this->windows = array_values(array_filter($this->windows, fn (SkinWindow $w) => $w !== $window && $w !== $this->lyrics)); $this->windows[] = $window; if ($window === $this->main && $this->wz()->ui['playlist']['attached'] && $this->playlist !== null) { // the player and its list move together: the list just behind the player $this->windows = array_values(array_filter($this->windows, fn (SkinWindow $w) => $w !== $this->playlist)); array_splice($this->windows, count($this->windows) - 1, 0, [$this->playlist]); } $this->windows[] = $this->lyrics; } [$this->pressX, $this->pressY] = [$dx, $dy]; $this->grabX = $dx - $window->x; $this->grabY = $dy - $window->y; $this->carry = $window === $this->playlist && $this->wz()->ui['playlist']['attached']; [$lx, $ly] = $this->touchPoint($window, $dx - $window->x, $dy - $window->y); if (!$window->press($lx, $ly, $p)) { $this->dragging = true; } } public function pointerDrag(Pointer $p): void { if ($this->native !== null && !$this->fromNative) { return; } if ($this->menuPress !== null && $this->menu !== null) { // a finger on the menu: slid, its rows follow it [, $dy] = $this->toDesk($p->x, $p->y); [$from, $last, $moved] = $this->menuPress; $moved = $moved || abs($dy - $from) > 4; if ($moved) { $active = $this->menu->active(); $active->scrollBy($last - $dy); $active->hover = -1; } $this->menuPress = [$from, $dy, $moved]; return; } if ($this->grabbed === null) { return; } [$dx, $dy] = $this->toDesk($p->x, $p->y); $turned = $this->turned(); if ($turned !== null && $this->grabbed === $turned) { [$dx, $dy] = $this->turnedPoint($dx, $dy); } if (abs($dx - $this->pressX) + abs($dy - $this->pressY) > 4) { $this->pressMoved = true; } $control = $this->grabbed->pressedControl(); if (!$this->dragging && $control !== '' && !$this->grabbed->dragsItself($control) && abs($dx - $this->pressX) + abs($dy - $this->pressY) > 4 && $this->grabbed !== $this->lyrics) { // a button (or the title, a line of the list) pressed then dragged: the window moves, the click is cancelled $this->grabbed->cancelPress(); $this->dragging = true; } if ($this->dragging) { $this->moveWindow($this->grabbed, $dx - $this->grabX, $dy - $this->grabY); } else { $this->grabbed->drag($dx - $this->grabbed->x, $dy - $this->grabbed->y); } } public function pointerUp(Pointer $p, bool $inside): void { if ($this->native !== null && !$this->fromNative) { return; } [$dx, $dy] = $this->toDesk($p->x, $p->y); if ($this->swallowUp) { $this->swallowUp = false; // the end of the long press that opened the menu return; } if ($this->menu !== null && $this->grabbed === null) { $press = $this->menuPress; $this->menuPress = null; if ($press !== null && $press[2]) { return; // the finger slid the rows: nothing runs } if ($this->menu->click($dx, $dy, $this->deskWidth(), $this->deskHeight())) { $this->menu = null; } return; } $window = $this->grabbed; $this->grabbed = null; $turned = $this->turned(); if ($turned !== null && $window === $turned) { [$dx, $dy] = $this->turnedPoint($dx, $dy); } if ($window !== null && !$this->dragging) { [$lx, $ly] = $this->touchPoint($window, $dx - $window->x, $dy - $window->y); $window->release($lx, $ly, $p->double); } $this->dragging = false; } public function wheel(float $notches): bool { if ($this->native !== null) { return false; // NativeShell gives the wheel to the window under the pointer } if ($this->ctrlHeld()) { $this->zoomStep($notches); return true; } if ($this->mouseX < 0) { return false; } $window = $this->windowAt($this->mouseX, $this->mouseY); return $window !== null && $window->wheel($notches); } /** SDL 2 key codes of the keys the binding may not define: F11 and the media keys of a keyboard */ public const KEY_F11 = 1073741892; public const KEY_AUDIONEXT = 1073742082; public const KEY_AUDIOPREV = 1073742083; public const KEY_AUDIOSTOP = 1073742084; public const KEY_AUDIOPLAY = 1073742085; public const KEY_AUDIOMUTE = 1073742086; /** the volume before the mute key (-1: not muted) */ private int $mutedFrom = -1; /** * The keyboard (WinZik had none: the joystick did it; these are the keys of the players of that time). Always: * Space play / pause, the media keys of the keyboard (lecture, suivant, précédent, stop, muet), Escape. With the * "Plugins Clavier": X play, C pause, V stop, B / N next, Z / W previous, + / - and arrows up / down volume (the * computer's when the slider is on it), arrows left / right 5 s (with Shift 30 s), 0..9 to 0..90 % of the song, * Enter play, H hasard, L / Ctrl+O load, K lyrics, F lyrics on the whole screen, P play list, M compact, E equalizer, * Y YouTube, Suppr the lines chosen, F11 the film on the whole screen, Ctrl+Q quit. Over the play list its own keys * first (PlaylistWindow::keys()). */ public function keys(Pointer $p): bool { $wz = $this->wz(); $list = $this->playlist; // --- lyrics: Escape closes the lyrics on the whole screen first (before the search or the lines of the play list) if ($this->menu === null && $p->pressed(Pointer::ESCAPE) && ($this->lyrics?->full() ?? false) && !($this->video?->full() ?? false)) { $this->lyrics->toggleFull(); return true; } // --- end lyrics // the search of the play list open: the letters typed go to it (before any key of WinZik), the arrows move in it if ($list !== null && $list->searching) { $used = false; foreach ($p->keys as $key) { $used = $list->searchKey($key, '') || $list->key($key, $p->shift, $p->ctrl) || $used; } foreach ($p->text as $char) { $used = $list->searchKey(null, $char) || $used; } if ($used) { return true; } } // the pointer over the play list: its keys first (arrows, Entrée, Suppr, Ctrl+A, a letter searches...) if ($list !== null && $list->visible() && $this->mouseX >= 0 && $this->underPointer() === $list && $list->keys($p)) { return true; } $clavier = $wz->plugin() === 'clavier'; $used = false; foreach ($p->keys as $key) { if ($this->basicKey($key)) { $used = true; } elseif ($clavier) { $used = $this->pluginKey($key, $p) || $used; } } if ($p->ctrl) { return $used; // Ctrl + a letter came as a key (above), not as a character } foreach ($p->text as $char) { if ($char === ' ') { $wz->togglePause(); $used = true; } elseif (!$clavier && strtolower($char) === 't' && ($this->lyrics?->full() ?? false)) { $wz->toggleTranslation(); // lyrics: T on the whole screen, with or without the plug-in $used = true; } elseif ($clavier) { $used = $this->pluginChar($char) || $used; } } return $used; } /** The keys that work with or without the plug-in: Escape and the media keys. @return bool it was one */ private function basicKey(int $key): bool { $wz = $this->wz(); switch ($key) { case Pointer::ESCAPE: $this->escape(); return true; case self::KEY_AUDIOPLAY: $wz->togglePause(); return true; case self::KEY_AUDIONEXT: $wz->next(); return true; case self::KEY_AUDIOPREV: $wz->previous(); return true; case self::KEY_AUDIOSTOP: $wz->stop(); return true; case self::KEY_AUDIOMUTE: $this->toggleMute(); return true; } return false; } /** A key of the "Plugins Clavier" that types no character (arrows, Entrée, Suppr, F11, Ctrl + a letter). */ private function pluginKey(int $key, Pointer $p): bool { $wz = $this->wz(); if ($p->ctrl && ($key === ord('o') || $key === ord('O'))) { $this->load(); return true; } if ($p->ctrl && ($key === ord('q') || $key === ord('Q'))) { $this->quitWithEffect(); return true; } $jump = $p->shift ? 30.0 : 5.0; switch ($key) { case Pointer::LEFT: $wz->seek(max(0.0, $wz->player->position - $jump)); return true; case Pointer::RIGHT: $wz->seek($wz->player->position + $jump); return true; case Pointer::UP: $this->volumeBy(5); return true; case Pointer::DOWN: $this->volumeBy(-5); return true; case Pointer::RETURN: case Pointer::KP_ENTER: $wz->play(); return true; case Pointer::DELETE: // the lines chosen in the play list (else its line of the keyboard): the list's own Suppr return $this->playlist !== null && $this->playlist->visible() && $this->playlist->key(Pointer::DELETE); case self::KEY_F11: if ($wz->playingVideo() && $this->video !== null) { $this->video->toggleFull(); return true; } return false; } return false; } /** A character of the "Plugins Clavier". */ private function pluginChar(string $char): bool { $wz = $this->wz(); if (strlen($char) === 1 && $char >= '0' && $char <= '9') { // 0..9: to 0..90 % of the song $length = $wz->player->duration(); if ($length > 0) { $wz->seek($length * (int)$char / 10); } return true; } $used = true; match (strtolower($char)) { 'x' => $wz->play(), 'c' => $wz->pause(), 'v' => $wz->stop(), 'b', 'n' => $wz->next(), 'z', 'w' => $wz->previous(), '+', '=' => $this->volumeBy(5), '-' => $this->volumeBy(-5), 'h' => $wz->toggleShuffle(), 'l' => $this->load(), 'k' => $wz->toggleLyrics(), 't' => $wz->toggleTranslation(), // lyrics: the translation under the lines 'f' => $this->lyrics?->toggleFull(), 'p' => $this->togglePlaylist(), 'm' => $wz->toggleCompact(), 'e' => $wz->toggleEq(), 'y' => $wz->youtube !== null ? $this->host()->openYoutube() : null, default => $used = false, }; return $used; } /** L, Ctrl+O: the files to add (the system's window, or WinZik's). */ private function load(): void { if ($this->main !== null) { $this->openLoad($this->main->x + 20, $this->main->y + 20); } else { $this->host()->openFiles(); } } /** The volume the slider sets (WinZik's or the computer's) up or down. */ private function volumeBy(int $step): void { $wz = $this->wz(); $this->mutedFrom = -1; $wz->setVolumeValue(max(0, min(100, $wz->volumeValue() + $step))); } /** The mute key: silence, then the volume of before. */ private function toggleMute(): void { $wz = $this->wz(); if ($this->mutedFrom >= 0 && $wz->volumeValue() === 0) { $wz->setVolumeValue($this->mutedFrom); $this->mutedFrom = -1; $wz->notice('Son remis', 2); } else { $this->mutedFrom = $wz->volumeValue(); $wz->setVolumeValue(0); $wz->notice('Son coupé', 2); } } /** The window under the pointer (desktop pixels; the desktop version: the window of the computer it is in). */ private function underPointer(): ?SkinWindow { if ($this->mouseX < 0) { return null; } return $this->native !== null ? $this->native->windowUnderPointer() : $this->windowAt($this->mouseX, $this->mouseY); } // each frame ------------------------------------------------------------------------------------------------- public function update(float $dt): void { if ($this->form?->engineOrNull() === null || $this->native !== null) { return; // native: NativeShell calls step() every frame, whatever scene is on top } $mouse = $this->form->engineOrNull()->input->getMouse(); $this->step($dt, $this->contains($mouse->x, $mouse->y) ? $this->toDesk($mouse->x, $mouse->y) : null); } /** @param array{0: float, 1: float}|null $pointer where the pointer is (desktop pixels), null = away */ public function step(float $dt, ?array $pointer): void { $this->build(); $this->clock += $dt; $wz = $this->wz(); $this->followMain(); // docked: never apart, whatever moved one of them if ($this->reveal < 1) { $this->reveal = min(1.0, $this->reveal + $dt * 1.6); } if ($this->closing >= 0) { $this->closing -= $dt * 1.6; if ($this->closing <= 0) { $this->closing = -1; $this->reveal = 0.0; // rolled up: they stay so until the end (and unroll again if they come back) $this->host()->quit(); } } foreach ($this->windows as $window) { $window->update($dt); } if ($wz->ui['playlist']['attached'] || $this->phone) { $this->followMain(); } if ($this->phone && $wz->ui['compact']['active']) { // the mini bar sits on the title of the other windows of a computer: a phone has none (its button, a key, a // setting of the computer): the player stays $wz->ui['compact']['active'] = false; $wz->touch(); $wz->notice('Pas de mode compact sur le téléphone', 3); } if ($this->phone) { $pointer = null; // a finger does not hover: no tooltip, no bar that runs away, nothing shown only under the pointer $this->longPress($dt); } // the pointer: hover, the lyrics bar that runs away, the menu, the tooltips [$this->mouseX, $this->mouseY] = $pointer ?? [-1.0, -1.0]; $this->lyrics?->pointerAt($this->mouseY); $this->menu?->hoverAt($this->mouseX, $this->mouseY, $this->deskWidth(), $this->deskHeight()); $under = $this->mouseX >= 0 && $this->menu === null ? ($this->native !== null ? $this->native->windowUnderPointer() : $this->windowAt($this->mouseX, $this->mouseY)) : null; foreach ($this->windows as $window) { if ($window === $under) { $window->hover($this->mouseX - $window->x, $this->mouseY - $window->y); } else { $window->hover(-1, -1); } } $this->pointerShape($under); $control = $under !== null && $this->grabbed === null ? $under->controlAt($this->mouseX - $under->x, $this->mouseY - $under->y) : ''; $key = $under !== null && $this->grabbed === null ? $under->id() . '.' . $control : ''; if ($key !== $this->tipKey) { $this->tipKey = $key; $this->tipWindow = $key !== '' ? $under : null; $this->tipControl = $control; $this->tipTime = 0; } else { $this->tipTime += $dt; } // a song changed while the list is scrolled away: it shows (List1.ListIndex = actif) if ($this->lastActive !== $wz->playlist->active) { $this->lastActive = $wz->playlist->active; $this->playlist?->reveal($wz->playlist->active); } $this->joystick($dt); } /** * The phone: held still on a window (its background, a button, a line of the list; not a slider) the menu opens, * as the right click of the computer. */ private function longPress(float $dt): void { $this->ring = 0.0; $window = $this->grabbed; if ($window === null || $this->menu !== null || $this->pressMoved) { return; } $control = $window->pressedControl(); if ($control !== '' && $control !== 'list' && $window->dragsItself($control)) { return; } $this->pressHeld += $dt; if ($this->pressHeld < self::LONG_PRESS) { $this->ring = $this->pressHeld / self::LONG_PRESS; // the ring around the finger fills return; } $window->cancelPress(); $this->grabbed = null; $this->dragging = false; $this->swallowUp = true; $this->openMenu($this->pressViewX, $this->pressViewY); } /** Form1.Timer3: the joystick does what Form11 says, every 250 ms while held. */ private function joystick(float $dt): void { $wz = $this->wz(); if (!($wz->options['joystick'] ?? false)) { return; } foreach ($this->padState() as $input => $held) { if (!$held) { unset($this->padHeld[$input], $this->padRepeat[$input]); continue; } $action = (int)($wz->controls[$input] ?? -1); if (!isset($this->padHeld[$input])) { $this->padHeld[$input] = true; $this->padRepeat[$input] = 0.4; $wz->action($action); } elseif (in_array($action, [0, 1, 8, 9], true)) { $this->padRepeat[$input] -= $dt; if ($this->padRepeat[$input] <= 0) { $this->padRepeat[$input] = 0.25; $wz->action($action); } } } } /** @return array<string, bool> the 8 inputs of Form11 (axes X+ X- Y+ Y-, buttons 1..4) held now */ public function padState(): array { $engine = $this->form?->engineOrNull(); if ($engine === null) { return []; } $pad = (int)($this->wz()->options['pad'] ?? 0); $g = $engine->input->getGamepad(); $lx = $g->axis($pad, 'lx'); $ly = $g->axis($pad, 'ly'); return [ 'xp' => $lx > 0.5 || $g->isButtonHeld($pad, 'right'), 'xm' => $lx < -0.5 || $g->isButtonHeld($pad, 'left'), 'yp' => $ly < -0.5 || $g->isButtonHeld($pad, 'up'), 'ym' => $ly > 0.5 || $g->isButtonHeld($pad, 'down'), 'b1' => $g->isButtonHeld($pad, 'a'), 'b2' => $g->isButtonHeld($pad, 'b'), 'b3' => $g->isButtonHeld($pad, 'x'), 'b4' => $g->isButtonHeld($pad, 'y'), ]; } // drawing ---------------------------------------------------------------------------------------------------- public function render(Renderer $r, Theme $t): void { $this->build(); if ($this->native !== null) { $r->fillRect($this->x, $this->y, $this->w, $this->h, '#202030'); return; // the windows are windows of the computer } $wz = $this->wz(); $c = new Canvas($r, $this->form?->sdlOrNull()); $c->scale = $this->scale; $c->skin = $wz->skin; $turned = $this->turned(); if ($turned !== null) { $this->renderTurned($r, $c, $turned); $this->renderOver($c); return; } $r->fillRect($this->x, $this->y, $this->w, $this->h, (string)$this->props['background']); $c->at($this->x / $this->scale, $this->y / $this->scale); if (!$this->phone) { $c->text('WinZik ' . $this->wz()->version() . ' - 1999-2002, recréé avec JumPHP en 2026', 6, $this->deskHeight() - 14, 7, [255, 255, 255, 110]); } foreach ($this->windows as $window) { if (!$window->visible()) { continue; } $c->at($this->x / $this->scale + $window->x, $this->y / $this->scale + $window->y); $window->render($c); $shown = $this->revealed($window); if ($shown < $window->width()) { $c->fill($shown, 0, $window->width() - $shown, $window->height(), (string)$this->props['background']); } } if ($this->phone) { $this->renderPhoneBar($c); } elseif ($wz->ui['tray'] || ($wz->options['taskbar'] ?? false)) { $this->renderTray($c); } $this->renderLeds($c); $this->renderTip($c); $this->renderOver($c); } /** Over everything: the ring of a long press, the menu. */ private function renderOver(Canvas $c): void { if ($this->ring > 0.15 && $this->menu === null) { $this->renderRing($c); } if ($this->menu !== null) { $c->at($this->x / $this->scale, $this->y / $this->scale); $this->menu->render($c); } } /** The long press under way: a ring around the finger fills (full: the menu opens). */ private function renderRing(Canvas $c): void { [$cx, $cy] = $this->toDesk($this->pressViewX, $this->pressViewY); $c->at($this->x / $this->scale, $this->y / $this->scale); $radius = 18.0; $dots = 24; for ($k = 0; $k < $dots; $k++) { $a = -M_PI / 2 + 2 * M_PI * $k / $dots; [$px, $py] = [$cx + cos($a) * $radius, $cy + sin($a) * $radius]; $c->disc($px, $py, 3.0, [0, 0, 0, 90]); $c->disc($px, $py, 2.2, $k / $dots < $this->ring ? '#ffffff' : [255, 255, 255, 80]); } } /** * The karaoke (or a film) on the whole screen of a phone held upright: drawn in a texture as wide as the screen is * tall, then copied turned a quarter (the top of the picture on the right edge: the phone turned to the left). */ private function renderTurned(Renderer $r, Canvas $c, SkinWindow $window): void { $r->fillRect($this->x, $this->y, $this->w, $this->h, '#000000'); $sdl = $this->form?->sdlOrNull(); if ($sdl === null) { return; } [$tw, $th] = [(int)round($this->h), (int)round($this->w)]; if ($this->turnedSize !== [$tw, $th] || !$sdl->hasTexture('winzik-turned')) { $sdl->createTexture('winzik-turned', $tw, $th); $this->turnedSize = [$tw, $th]; } $texture = $sdl->getTexture('winzik-turned')['texture']; [$ox, $oy] = $r->translation(); $before = $r->setTarget($texture); $r->translate(-$ox, -$oy); $r->clear('#000000'); $c->at(0, 0); $window->render($c); $r->translate($ox, $oy); $r->setTarget($before); $r->copy($texture, null, $this->x + ($this->w - $tw) / 2, $this->y + ($this->h - $th) / 2, $tw, $th, false, false, 90.0); } /** the phone's bar: its "≡ Menu" button (the menu of the right click) @return array{0: float, 1: float, 2: float, 3: float} */ public function menuButton(): array { return [3.0, $this->deskHeight() - self::PHONE_BAR + 4, 58.0, 20.0]; } /** A touch on the bar of the phone (desktop pixels): its buttons. @return bool it was on the bar */ private function phoneBar(float $dx, float $dy): bool { if ($dy < $this->deskHeight() - self::PHONE_BAR) { return false; } $in = fn (array $box) => $dx >= $box[0] - 2 && $dx < $box[0] + $box[2] + 2 && $dy >= $box[1] - 4 && $dy < $box[1] + $box[3] + 4; if ($in($this->menuButton())) { $this->openBarMenu(); } elseif ($in($this->taskButton())) { $this->wz()->ui['tray'] ? $this->fromTray() : $this->toTray(); } elseif ($this->wz()->ui['tray'] && $in($this->trayRect())) { $this->fromTray(); } return true; } /** The "≡ Menu" button of the phone: the menu of the right click, over the bar. */ public function openBarMenu(): void { $this->build(); $this->menuLines = $this->linesAt(-1, -1); // cloud: the lines chosen $this->menu = $this->popup($this->menuItems(), 0, $this->deskHeight() - self::PHONE_BAR); } /** The bar of the phone, as the task bar of Windows 98: "≡ Menu" (as Démarrer), WinZik's button, the clock. */ private function renderPhoneBar(Canvas $c): void { $c->at($this->x / $this->scale, $this->y / $this->scale); $dw = $this->deskWidth(); $y = $this->deskHeight() - self::PHONE_BAR; $c->fill(0, $y, $dw, self::PHONE_BAR, '#c0c0c0'); $c->fill(0, $y, $dw, 1, '#dfdfdf'); $c->fill(0, $y + 1, $dw, 1, '#ffffff'); [$bx, $by, $bw, $bh] = $this->menuButton(); $open = $this->menu !== null; $c->bevel($bx, $by, $bw, $bh, !$open); $d = $open ? 1 : 0; for ($i = 0; $i < 3; $i++) { $c->fill($bx + 6 + $d, $by + 5 + $i * 4 + $d, 12, 2, '#000000'); } $c->text('Menu', $bx + 23 + $d, $by + 4 + $d, 10, '#000000'); [$tx, $ty, $tw, $th] = $this->taskButton(); $tray = (bool)$this->wz()->ui['tray']; $c->bevel($tx, $ty, $tw, $th, $tray); $c->image('ico', $tx + 3, $ty + 2, 16, 16); $c->text('WinZik', $tx + 23, $ty + 4, 9, '#000000'); [$kx, $ky, $kw, $kh] = $this->trayRect(); $c->bevel($kx, $ky, $kw, $kh, false); $c->text(date('H:i'), $kx + $kw / 2, $ky + 4, 9, '#000000', 'center'); } /** The LED plug-in: the three lights of a keyboard of 1999, above the lyrics bar at the right. */ private function renderLeds(Canvas $c): void { $leds = $this->wz()->leds(); if ($leds === null) { return; } [$scroll, $caps, $num] = $leds; $w = 132; $x = $this->deskWidth() - $w - 4; $y = $this->deskHeight() - ($this->lyrics?->barHeight() ?? LyricsBar::HEIGHT) - 26 - $this->bottomMargin(); $c->at($this->x / $this->scale, $this->y / $this->scale); $c->bevel($x, $y, $w, 22, true, '#d8d4c8'); foreach ([['Verr Num', $num], ['Verr Maj', $caps], ['Arrêt défil', $scroll]] as $i => [$label, $on]) { $lx = $x + 8 + $i * 42; $c->fill($lx + 12, $y + 4, 10, 5, $on ? '#30ff30' : '#204020'); if ($on) { $c->fill($lx + 10, $y + 3, 14, 7, [80, 255, 80, 60]); } $c->text($label, $lx + 17, $y + 11, 6, '#303030', 'center'); } } private function trayRect(): array { if ($this->phone) { return [$this->deskWidth() - 48, $this->deskHeight() - 24, 44, 20]; } return [$this->deskWidth() - 70, $this->deskHeight() - 24, 66, 20]; } /** @return array{0: float, 1: float, 2: float, 3: float} the WinZik button of the task bar */ private function taskButton(): array { [, $y] = $this->trayRect(); return $this->phone ? [65.0, $y, 84.0, 20.0] : [4, $y, 110, 20]; } private function trayContains(float $dx, float $dy): bool { [$x, $y, $w, $h] = $this->trayRect(); return $dx >= $x && $dx < $x + $w && $dy >= $y && $dy < $y + $h; } /** The icon near the clock (Shell_NotifyIcon, szTip "WinZik"). */ private function renderTray(Canvas $c): void { [$x, $y, $w, $h] = $this->trayRect(); $c->at($this->x / $this->scale, $this->y / $this->scale); $c->fill(0, $y - 4, $this->deskWidth(), $h + 8, '#c0c0c0'); $c->fill(0, $y - 4, $this->deskWidth(), 1, '#ffffff'); $c->bevel($x, $y, $w, $h, false); $c->image('ico', $x + 3, $y + 2, 16, 16); $c->text(date('H:i'), $x + $w - 5, $y + 4, 8, '#000000', 'right'); if (($this->wz()->options['taskbar'] ?? false) || $this->wz()->ui['tray']) { // App.TaskVisible: the button of WinZik in the task bar (pressed while its windows are shown) [$bx, $by, $bw, $bh] = $this->taskButton(); $c->bevel($bx, $by, $bw, $bh, $this->wz()->ui['tray']); $c->image('ico', $bx + 3, $by + 2, 16, 16); $c->text('WinZik', $bx + 23, $by + 4, 9, '#000000'); } if ($this->wz()->ui['tray']) { $c->text('WinZik est réduit : cliquer sur « WinZik » ou sur son icône pour le rouvrir.', 120, $y + 4, 8, '#000000'); } } private const TIPS = [ 'main.shuffle' => 'Hasard', 'main.info' => 'Informations (tag ID3)', 'main.compact' => 'Mode compact', 'main.close' => 'Quitter', 'main.tray' => 'Réduire dans la barre', 'main.lyrics' => 'Paroles seules', 'main.vu' => 'Bargraph (cliquer pour le cacher)', 'main.prev' => 'Précédent', 'main.pause' => 'Pause', 'main.play' => 'Play', 'main.stop' => 'Stop', 'main.next' => 'Suivant', 'main.playlist' => 'Playlist', 'main.expand' => 'Agrandir', 'main.title' => 'Glisser pour faire défiler le titre', 'playlist.add' => 'Ajouter des fichiers', 'playlist.remove' => 'Retirer le morceau (ou les lignes choisies)', 'playlist.edit' => 'Mode édition', 'playlist.load' => 'Charger une liste (.FLS)', 'playlist.save' => 'Sauver la liste (.FLS)', 'playlist.delete' => 'Supprimer les lignes choisies', 'compact.prev' => 'Précédent', 'compact.pause' => 'Pause', 'compact.play' => 'Play', 'compact.next' => 'Suivant', 'compact.back' => 'Retour au lecteur', 'compact.open' => 'Afficher le titre', 'compact.lyrics' => 'Paroles', ]; /** * The windows that show the hint of their controls themselves (SkinWindow::hint(): the player in its title, the * equalizer in its stripe, the lyrics bar): no tooltip of the desktop for them (not shown twice). */ private static function drawsOwnHints(SkinWindow $window): bool { return $window instanceof MainWindow || $window instanceof EqWindow || $window instanceof LyricsBar; } private function renderTip(Canvas $c): void { $tip = self::TIPS[$this->tipKey] ?? ''; $win = $this->tipWindow; if ($tip === '' && $win !== null && $this->tipControl !== '' && !self::drawsOwnHints($win)) { $tip = $win->tip($this->tipControl); // the window's own words for it } if ($tip === '' || $this->tipTime < 0.7 || $this->mouseX < 0) { return; } $c->at($this->x / $this->scale, $this->y / $this->scale); $w = $c->textWidth($tip, 8) + 8; $x = min($this->mouseX + 6, $this->deskWidth() - $w - 2); $y = min($this->mouseY + 16, $this->deskHeight() - 16); $c->fill($x, $y, $w, 14, '#ffffe1'); $c->frame($x, $y, $w, 14, '#000000'); $c->text($tip, $x + 4, $y + 2, 8, '#000000'); }}