public void Tick()
{
if (NeedSizeUpdate)
{
UpdatePosition();
}
if (NeedsRefresh)
{
bool alert = false;
lock (this)
{
if (RefreshImage || (_imgplan == null && !string.IsNullOrEmpty(Fpobject.image)))
{
if (_imgplan!=null)
{
try
{
_imgplan.Dispose();
}
catch
{
// ignored
}
_imgplan = null;
}
if (_imgview != null)
{
try
{
_imgview.Dispose();
}
catch
{
// ignored
}
_imgview = null;
}
Bitmap img=null;
try
{
img = (Bitmap) Image.FromFile(Fpobject.image);
}
catch
{
// ignored
}
if (img != null)
{
if (!Fpobject.originalsize)
{
var rf = new ResizeBilinear(533, 400);
_imgplan = rf.Apply(img);
_imgview = (Bitmap) _imgplan.Clone();
}
else
{
_imgplan = img;
_imgview = (Bitmap) _imgplan.Clone();
}
}
RefreshImage = false;
}
if (_imgplan == null)
return;
Graphics gLf = Graphics.FromImage(_imgview);
gLf.DrawImage(_imgplan, 0, 0,_imgplan.Width,_imgplan.Height);
bool itemRemoved = false;
double wrat = Convert.ToDouble(ImageWidth) / 533d;
double hrat = Convert.ToDouble(ImageHeight) / 400d;
foreach (objectsFloorplanObjectsEntry fpoe in Fpobject.objects.@object)
{
var p = new Point(fpoe.x, fpoe.y);
if (Fpobject.originalsize)
{
p.X = Convert.ToInt32(p.X*wrat);
p.Y = Convert.ToInt32(p.Y*hrat);
}
if (fpoe.fov == 0)
fpoe.fov = 135;
if (fpoe.radius == 0)
fpoe.radius = 80;
switch (fpoe.type)
{
case "camera":
{
var cw = MainClass.GetCameraWindow(fpoe.id);
if (cw != null)
{
double drad = (fpoe.angle - 180) * Math.PI / 180;
var points = new[]
{
new Point(p.X + 11+Convert.ToInt32(20*Math.Cos(drad)), p.Y + 11 + Convert.ToInt32((20* Math.Sin(drad)))),
new Point(p.X + 11+Convert.ToInt32(20*Math.Cos(drad+(135*Math.PI/180))), p.Y + 11 + Convert.ToInt32((20* Math.Sin(drad+(135*Math.PI/180))))),
new Point(p.X + 11+Convert.ToInt32(10*Math.Cos(drad+(180*Math.PI/180))), p.Y + 11 + Convert.ToInt32((10* Math.Sin(drad+(180*Math.PI/180))))),
new Point(p.X + 11+Convert.ToInt32(20*Math.Cos(drad-(135*Math.PI/180))), p.Y + 11 + Convert.ToInt32((20* Math.Sin(drad-(135*Math.PI/180)))))
};
if (cw.Camobject.settings.active && !cw.VideoSourceErrorState)
{
int offset = (fpoe.radius / 2) - 11;
if (cw.Alerted)
{
gLf.FillPolygon(_alertBrush, points);
gLf.FillPie(_alertBrushScanner, p.X - offset, p.Y - offset, fpoe.radius, fpoe.radius,
(float)(fpoe.angle - 180 - (fpoe.fov / 2)), fpoe.fov);
alert = true;
}
else
{
gLf.FillPolygon(_noalertBrush, points);
gLf.FillPie(_noalertBrushScanner, p.X - offset, p.Y - offset, fpoe.radius, fpoe.radius,
(float)(fpoe.angle - 180 - (fpoe.fov / 2)), fpoe.fov);
}
}
else
{
gLf.FillPolygon(_offlineBrush, points);
}
}
else
{
fpoe.id = -2;
itemRemoved = true;
}
}
break;
case "microphone":
{
var vw = MainClass.GetVolumeLevel(fpoe.id);
if (vw != null)
{
if (vw.Micobject.settings.active && !vw.AudioSourceErrorState)
{
if (vw.Alerted)
{
gLf.FillEllipse(_alertBrush, p.X - 20, p.Y - 20, 40, 40);
alert = true;
}
else
{
gLf.FillEllipse(_noalertBrush, p.X - 15, p.Y - 15, 30, 30);
}
}
else
{
gLf.FillEllipse(_offlineBrush, p.X - 15, p.Y - 15, 30, 30);
}
}
else
{
fpoe.id = -2;
itemRemoved = true;
}
}
break;
}
}
if (itemRemoved)
Fpobject.objects.@object = [email protected](fpoe => fpoe.id > -2).ToArray();
gLf.Dispose();
}
Invalidate();
LastRefreshTimestamp = Helper.Now.UnixTicks();
NeedsRefresh = false;
IsAlert = alert;
}
}