<?phpnamespace App\Gui;use JumPHP\Gui\Radio;use JumPHP\Gui\Theme;use JumPHP\Renderer\Renderer;/** java.awt.Checkbox in a CheckboxGroup: the round button of Windows (grey and black arcs, white inside, a black dot). */final class AwtRadio extends Radio{ public const DEFAULTS = ['text' => 'Choice', 'checked' => false, 'group' => '', 'background' => '']; /** S shadow, D dark, L light, F face, W the white inside: the upper-left arcs dark, the lower-right ones light. */ private const BUTTON = [ '....SSSS....', '..SSDDDDSS..', '.SDDWWWWDDL.', '.SDWWWWWWFL.', 'SDWWWWWWWWFL', 'SDWWWWWWWWFL', 'SDWWWWWWWWFL', 'SDWWWWWWWWFL', '.SDWWWWWWFL.', '.SFFWWWWFFL.', '..LLFFFFLL..', '....LLLL....', ]; /** The same with the black dot of the chosen one (4 x 4, corners cut). */ private const CHECKED = [ '....SSSS....', '..SSDDDDSS..', '.SDDWWWWDDL.', '.SDWWWWWWFL.', 'SDWWW##WWWFL', 'SDWW####WWFL', 'SDWW####WWFL', 'SDWWW##WWWFL', '.SDWWWWWWFL.', '.SFFWWWWFFL.', '..LLFFFFLL..', '....LLLL....', ]; protected function content(Theme $t, float $maxWidth, string $breakpoint): array { return [$t->px(12 + 6) + $t->font(12)->width($this->tr((string)$this->props['text'])) + $t->px(4), $t->px(20)]; } public function render(Renderer $r, Theme $t): void { if ($this->props['background'] !== '') { $r->fillRect($this->x, $this->y, $this->w, $this->h, (string)$this->props['background']); } // the round button of Windows, pixel for pixel (12 x 12), each pixel a square of whole screen pixels $px = Awt::px($t); $ox = (int)round($this->x + $t->px(1)); $oy = (int)round($this->y + ($this->h - 12 * $px) / 2); $inside = $this->isEnabled() ? '#ffffff' : Awt::$face; $colors = ['S' => Awt::SHADOW, 'D' => Awt::DARK, 'L' => Awt::LIGHT, 'F' => Awt::$face, 'W' => $inside, '#' => $this->isEnabled() ? Awt::DARK : Awt::SHADOW]; foreach ($this->props['checked'] ? self::CHECKED : self::BUTTON as $row => $line) { for ($col = 0; $col < 12; $col++) { $c = $line[$col]; if ($c === '.') { continue; } $run = 1; while ($col + $run < 12 && $line[$col + $run] === $c) { $run++; } $r->fillRect($ox + $col * $px, $oy + $row * $px, $run * $px, $px, $colors[$c]); $col += $run - 1; } } $font = $t->font(12); $text = $this->tr((string)$this->props['text']); $tx = $this->x + $t->px(12 + 6); $ty = $this->y + ($this->h - $font->height()) / 2; $this->isEnabled() ? $font->draw($r, $text, $tx, $ty, 1, '#000000') : Awt::disabledText($r, $t, $font, $text, $tx, $ty); }}