limit points to the limits of the monitor
parent
c4ec01c0d2
commit
3db38eb474
|
@ -1755,6 +1755,25 @@ function coordsToPoints( $coords ) {
|
|||
return( $points );
|
||||
}
|
||||
|
||||
function limitPoints( &$points, $min_x, $min_y, $max_x, $max_y ) {
|
||||
foreach ( $points as &$point ) {
|
||||
if ( $point['x'] < $min_x ) {
|
||||
Debug('Limiting point x'.$point['x'].' to min_x ' . $min_x );
|
||||
$point['x'] = $min_x;
|
||||
} else if ( $point['x'] > $max_x ) {
|
||||
Debug('Limiting point x'.$point['x'].' to max_x ' . $max_x );
|
||||
$point['x'] = $max_x;
|
||||
}
|
||||
if ( $point['y'] < $min_y ) {
|
||||
Debug('Limiting point y'.$point['y'].' to min_y ' . $min_y );
|
||||
$point['y'] = $min_y;
|
||||
} else if ( $point['y'] > $max_y ) {
|
||||
Debug('Limiting point y'.$point['y'].' to max_y ' . $max_y );
|
||||
$point['y'] = $max_y;
|
||||
}
|
||||
} // end foreach point
|
||||
} // end function limitPoints( $points, $min_x, $min_y, $max_x, $max_y )
|
||||
|
||||
function getLanguages() {
|
||||
$langs = array();
|
||||
foreach ( glob("lang/*_*.php") as $file ) {
|
||||
|
|
|
@ -18,9 +18,8 @@
|
|||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
|
||||
if ( !canView( 'Monitors' ) )
|
||||
{
|
||||
$view = "error";
|
||||
if ( !canView( 'Monitors' ) ) {
|
||||
$view = 'error';
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -34,29 +33,25 @@ $hicolor = '0x00ff00'; // Green
|
|||
$presets = array();
|
||||
$presetNames = array();
|
||||
$presetNames[0] = translate('ChoosePreset');
|
||||
$sql = "select *, Units-1 as UnitsIndex, CheckMethod-1 as CheckMethodIndex from ZonePresets order by Id asc";
|
||||
foreach( dbFetchAll( $sql ) as $preset )
|
||||
{
|
||||
$presetNames[$preset['Id']] = $preset['Name'];
|
||||
$presets[] = $preset;
|
||||
$sql = 'SELECT *, Units-1 AS UnitsIndex, CheckMethod-1 AS CheckMethodIndex FROM ZonePresets ORDER BY Id ASC';
|
||||
foreach( dbFetchAll( $sql ) as $preset ) {
|
||||
$presetNames[$preset['Id']] = $preset['Name'];
|
||||
$presets[] = $preset;
|
||||
}
|
||||
|
||||
$optTypes = array();
|
||||
foreach ( getEnumValues( 'Zones', 'Type' ) as $optType )
|
||||
{
|
||||
$optTypes[$optType] = $optType;
|
||||
foreach ( getEnumValues( 'Zones', 'Type' ) as $optType ) {
|
||||
$optTypes[$optType] = $optType;
|
||||
}
|
||||
|
||||
$optUnits = array();
|
||||
foreach ( getEnumValues( 'Zones', 'Units' ) as $optUnit )
|
||||
{
|
||||
$optUnits[$optUnit] = $optUnit;
|
||||
foreach ( getEnumValues( 'Zones', 'Units' ) as $optUnit ) {
|
||||
$optUnits[$optUnit] = $optUnit;
|
||||
}
|
||||
|
||||
$optCheckMethods = array();
|
||||
foreach ( getEnumValues( 'Zones', 'CheckMethod' ) as $optCheckMethod )
|
||||
{
|
||||
$optCheckMethods[$optCheckMethod] = $optCheckMethod;
|
||||
foreach ( getEnumValues( 'Zones', 'CheckMethod' ) as $optCheckMethod ) {
|
||||
$optCheckMethods[$optCheckMethod] = $optCheckMethod;
|
||||
}
|
||||
|
||||
$monitor = new Monitor( $mid );
|
||||
|
@ -66,14 +61,10 @@ $maxX = $monitor->Width()-1;
|
|||
$minY = 0;
|
||||
$maxY = $monitor->Height()-1;
|
||||
|
||||
if ( !isset($newZone) )
|
||||
{
|
||||
if ( $zid > 0 )
|
||||
{
|
||||
if ( !isset($newZone) ) {
|
||||
if ( $zid > 0 ) {
|
||||
$zone = dbFetchOne( 'SELECT * FROM Zones WHERE MonitorId = ? AND Id=?', NULL, array( $monitor->Id(), $zid ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$zone = array(
|
||||
'Id' => 0,
|
||||
'Name' => translate('New'),
|
||||
|
@ -104,17 +95,16 @@ if ( !isset($newZone) )
|
|||
$zone['AreaCoords'] = preg_replace( '/\s+/', ',', $zone['Coords'] );
|
||||
|
||||
$newZone = $zone;
|
||||
}
|
||||
} # end if new Zone
|
||||
|
||||
//if ( !$points )
|
||||
//{
|
||||
//$points = $zone['Points'];
|
||||
//}
|
||||
# Ensure Zone fits within the limits of the Monitor
|
||||
limitPoints( $newZone['Points'], $minX, $minY, $maxX, $maxY );
|
||||
|
||||
ksort( $newZone['Points'], SORT_NUMERIC );
|
||||
|
||||
$newZone['Coords'] = pointsToCoords( $newZone['Points'] );
|
||||
$newZone['Area'] = getPolyArea( $newZone['Points'] );
|
||||
$newZone['AreaCoords'] = preg_replace( '/\s+/', ',', $newZone['Coords'] );
|
||||
$selfIntersecting = isSelfIntersecting( $newZone['Points'] );
|
||||
|
||||
$focusWindow = true;
|
||||
|
|
|
@ -18,23 +18,27 @@
|
|||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
|
||||
if ( !canView( 'Monitors' ) )
|
||||
{
|
||||
$view = "error";
|
||||
return;
|
||||
if ( !canView( 'Monitors' ) ) {
|
||||
$view = 'error';
|
||||
return;
|
||||
}
|
||||
|
||||
$mid = validInt($_REQUEST['mid']);
|
||||
$monitor = new Monitor( $mid );
|
||||
# Width() and Height() are already rotated
|
||||
$minX = 0;
|
||||
$maxX = $monitor->Width()-1;
|
||||
$minY = 0;
|
||||
$maxY = $monitor->Height()-1;
|
||||
|
||||
$zones = array();
|
||||
foreach( dbFetchAll( 'select * from Zones where MonitorId = ? order by Area desc', NULL, array($mid) ) as $row )
|
||||
{
|
||||
if ( $row['Points'] = coordsToPoints( $row['Coords'] ) )
|
||||
{
|
||||
$row['AreaCoords'] = preg_replace( '/\s+/', ',', $row['Coords'] );
|
||||
$zones[] = $row;
|
||||
}
|
||||
foreach( dbFetchAll( 'SELECT * FROM Zones WHERE MonitorId=? ORDER BY Area DESC', NULL, array($mid) ) as $row ) {
|
||||
$row['Points'] = coordsToPoints( $row['Coords'] );
|
||||
|
||||
limitPoints( $row['Points'], $minX, $minY, $maxX, $maxY );
|
||||
$row['Coords'] = pointsToCoords( $row['Points'] );
|
||||
$row['AreaCoords'] = preg_replace( '/\s+/', ',', $row['Coords'] );
|
||||
$zones[] = $row;
|
||||
}
|
||||
|
||||
$connkey = generateConnKey();
|
||||
|
|
Loading…
Reference in New Issue