You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
2.2 KiB
127 lines
2.2 KiB
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App;
|
|
|
|
/**
|
|
* Represents and provides an interface for manipulating screens
|
|
*
|
|
* @author Adam Pippin <hello@adampippin.ca>
|
|
*/
|
|
class Screen
|
|
{
|
|
/**
|
|
* A list of possible hardware outputs that could implement this screen
|
|
* @var string[]
|
|
*/
|
|
protected $_outputs;
|
|
|
|
/**
|
|
* The driver for manipulating the layout
|
|
* @var ILayoutDriver
|
|
*/
|
|
protected $_driver;
|
|
|
|
/**
|
|
* Set up a new screen
|
|
*
|
|
* @param string[] $outputs
|
|
* @param ILayoutDriver $driver
|
|
*/
|
|
public function __construct(array $outputs, ILayoutDriver $driver)
|
|
{
|
|
$this->_outputs = $outputs;
|
|
$this->_driver = $driver;
|
|
}
|
|
|
|
/**
|
|
* Enumerate all possible outputs and return the first that is found to be connected
|
|
*
|
|
* @return string
|
|
*/
|
|
protected function getOutputName(): string
|
|
{
|
|
foreach ($this->_outputs as $output)
|
|
{
|
|
if ($this->_driver->isConnected($output))
|
|
{
|
|
return $output;
|
|
}
|
|
}
|
|
|
|
throw new \Exception("No connected output found!");
|
|
}
|
|
|
|
/**
|
|
* Determine whether this screen is connected
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function isConnected(): bool
|
|
{
|
|
try
|
|
{
|
|
$this->getOutputName();
|
|
return true;
|
|
}
|
|
catch (\Exception $ex)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Determine whether this screen is considered the "primary" screen
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function isPrimary(): bool
|
|
{
|
|
return $this->_driver->isPrimary($this->getOutputName());
|
|
}
|
|
|
|
/**
|
|
* Get the pixel dimensions of the screen
|
|
*
|
|
* @return int[] x, y
|
|
*/
|
|
public function getDimensions(): array
|
|
{
|
|
return $this->_driver->getDimensions($this->getOutputName());
|
|
}
|
|
|
|
/**
|
|
* Get the pixel offset of the screen
|
|
*
|
|
* @return int[] x, y
|
|
*/
|
|
public function getOffset(): array
|
|
{
|
|
return $this->_driver->getOffset($this->getOutputName());
|
|
}
|
|
|
|
/**
|
|
* Set the pixel offset of the screen
|
|
*
|
|
* @param int $x
|
|
* @param int $y
|
|
* @return void
|
|
*/
|
|
public function setOffset(int $x, int $y): void
|
|
{
|
|
$this->_driver->setOffset($this->getOutputName(), $x, $y);
|
|
}
|
|
|
|
/**
|
|
* Set the resolution of the screen
|
|
*
|
|
* @param int $w
|
|
* @param int $h
|
|
* @return void
|
|
*/
|
|
public function setDimensions(int $w, int $h): void
|
|
{
|
|
$this->_driver->setDimensions($this->getOutputName(), $w, $h);
|
|
}
|
|
}
|
|
|