Files
api/services/nginx/app/modules/dynamicimages/images/machine_1.php
T
Jeppe Bundgaard a2dc4da2bf Refactor machine_1 rendering logic and add new assets
- Replace `IMAGE_WASH_PROGRAMS` with `IMAGE_PROGRAMS_WHEEL` and add `IMAGE_BUTTON_HIGHLIGHTED`.
- Introduce `drawProgramWheel` and `drawThumb` methods for improved modularity.
- Adjust thumb properties (`$thumb_position`, `$thumb_size`) and refine positioning logic.
- Update asset loading to include the new `machine_1_button_highlighted_transparent` asset.
2026-01-28 14:27:06 +01:00

106 lines
4.2 KiB
PHP

<?php
namespace dynamicimages\images;
use dynamicimages\classes\dynamicimages_asset;
use dynamicimages\classes\dynamicimages_image;
class machine_1 extends dynamicimages_image
{
const IMAGE_POWER_BUTTON = 'machine_1_button_start_stop.png';
const IMAGE_PANEL_BACKGROUND = 'machine_1_panel_background.png';
const IMAGE_WASH_PROGRAMS_THUMB = 'machine_1_wash_programs_thumb_standalone_transparent.png';
const IMAGE_WASH_PROGRAMS = 'machine_1_programs_wheel_transparent.png';
const IMAGE_BUTTON_HIGHLIGHTED = 'machine_1_button_highlighted_transparent.png';
public int $thumb_position = 9; // 0-11 (default: 0 = up = 270 degrees)
public int $thumb_size = 1550; // height and width of the thumb
/**
* @throws \Exception
*/
public function __construct()
{
$this->setAssetPath(self::asset_path . str_replace(__NAMESPACE__ . '\\', '', __CLASS__) . '/');
parent::__construct([
new dynamicimages_asset(self::getAssetPath(self::IMAGE_POWER_BUTTON)),
new dynamicimages_asset(self::getAssetPath(self::IMAGE_PANEL_BACKGROUND)),
new dynamicimages_asset(self::getAssetPath(self::IMAGE_WASH_PROGRAMS_THUMB)),
new dynamicimages_asset(self::getAssetPath(self::IMAGE_WASH_PROGRAMS)),
new dynamicimages_asset(self::getAssetPath(self::IMAGE_BUTTON_HIGHLIGHTED)),
]);
}
/**
* @throws \Exception
*/
public function setup(): void
{
$this->initImageCanvas(6000, 4500);
// By default, the background should be shown with the programs on top and then on top of that the thumb
$this->drawAsset($this->getAsset(self::IMAGE_PANEL_BACKGROUND), 0, 0);
$this->drawProgramWheel();
$this->drawThumb();
//$this->drawAsset($this->getAsset(self::IMAGE_POWER_BUTTON), 0, 0);
}
/**
* @throws \Exception
*/
public function drawProgramWheel(): void
{
// Match the wheel center to the thumb's visual center
$thumbX = 650;
$thumbY = 1290;
$buffer = 600; // Pixels to increase the wheel size beyond the thumb edges
$thumbX -= $buffer / 2;
$thumbY -= $buffer / 2;
$thumbWidth = $this->calculateThumbWidth($this->thumb_size) + $buffer;
$thumbHeight = $this->thumb_size + $buffer;
$tmp = new dynamicimages_asset($this->getAssetPath(self::IMAGE_WASH_PROGRAMS));
$tmp->resize($thumbWidth, $thumbHeight);
$this->drawAsset($tmp, $thumbX, $thumbY);
// Free memory used by temporary asset image, if any
if (method_exists($tmp, 'clearMemoryImage')) {
$tmp->clearMemoryImage();
}
}
public function getRotationThumbPosition(): float
{
// Each position represents a 30 degree increment (12 positions in total for 360 degrees)
$degrees = -90;
return ($this->thumb_position) * 30 + $degrees;
}
public function calculateThumbWidth(int $height): int
{
$originalWidth = $this->getAsset(self::IMAGE_WASH_PROGRAMS_THUMB)->getWidth();
$originalHeight = $this->getAsset(self::IMAGE_WASH_PROGRAMS_THUMB)->getHeight();
return (int)round(($originalWidth / $originalHeight) * $height);
}
/**
* @return void
* @throws \Exception
*/
public function drawThumb(): void
{
// Thumb parameters
$thumbX = 650;
$thumbY = 1290;
// Base resized thumb to compute the visual pivot (center coordinates)
$baseThumb = $this->getAsset(self::IMAGE_WASH_PROGRAMS_THUMB)->resize($this->calculateThumbWidth($this->thumb_size), $this->thumb_size);
$centerX = $thumbX + (int)floor($baseThumb->getWidth() / 2);
$centerY = $thumbY + (int)floor($baseThumb->getHeight() / 2);
$tmp = new dynamicimages_asset($this->getAssetPath(self::IMAGE_WASH_PROGRAMS_THUMB));
$tmp->resize($this->calculateThumbWidth($this->thumb_size), $this->thumb_size)
->rotate($this->getRotationThumbPosition());
$this->drawAssetCentered($tmp, $centerX, $centerY);
// Free memory used by temporary asset image, if any
if (method_exists($tmp, 'clearMemoryImage')) {
$tmp->clearMemoryImage();
}
}
}