public StateImage(OSAEObject sObject, string appName)
{
InitializeComponent();
OSAEImageManager imgMgr = new OSAEImageManager();
gAppName = appName;
screenObject = sObject;
ObjectName = screenObject.Property("Object Name").Value;
LinkedObject = OSAEObjectManager.GetObjectByName(ObjectName);
SliderMethod = screenObject.Property("Slider Method").Value;
CurState = OSAEObjectStateManager.GetObjectStateValue(ObjectName).Value;
CurStateLabel = OSAEObjectStateManager.GetObjectStateValue(ObjectName).StateLabel;
try
{
string propertyCheck = OSAEObjectPropertyManager.GetObjectPropertyValue(ObjectName, "Light Level").Value;
if (propertyCheck != "") LightLevel = Convert.ToUInt16(propertyCheck);
else LightLevel = 100;
}
catch
{ }
LastStateChange = OSAEObjectStateManager.GetObjectStateValue(ObjectName).LastStateChange;
Image.ToolTip = ObjectName + " " + CurStateLabel + "\n" + "since: " + LastStateChange;
Image.Tag = ObjectName;
Image.MouseLeftButtonUp += new MouseButtonEventHandler(State_Image_MouseLeftButtonUp);
foreach (OSAEObjectProperty p in screenObject.Properties)
{
if (p.Value.ToLower() == CurState.ToLower())
StateMatch = p.Name.Substring(0, p.Name.LastIndexOf(' '));
}
try
{
string imgName = screenObject.Property(StateMatch + " Image").Value;
string imgName2 = screenObject.Property(StateMatch + " Image 2").Value;
string imgName3 = screenObject.Property(StateMatch + " Image 3").Value;
string imgName4 = screenObject.Property(StateMatch + " Image 4").Value;
try
{ repeatAnimation = Convert.ToBoolean(screenObject.Property("Repeat Animation").Value); }
catch
{
OSAEObjectPropertyManager.ObjectPropertySet(screenObject.Name, "Repeat Animation", "TRUE", gAppName);
repeatAnimation = true;
}
try
{ frameDelay = Convert.ToInt16(screenObject.Property("Frame Delay").Value); }
catch
{
frameDelay = 100;
OSAEObjectPropertyManager.ObjectPropertySet(screenObject.Name, "Frame Delay", "100", gAppName);
}
OSAEImage img1 = imgMgr.GetImage(imgName);
if (img1.Type == "gif")
{
ms1 = new MemoryStream(img1.Data);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = ms1;
bitmapImage.EndInit();
//Image.Source = bitmapImage;
ImageWidth = bitmapImage.Width;
ImageHeight = bitmapImage.Height;
ImageBehavior.SetAnimatedSource(Image, bitmapImage);
Image.Visibility = System.Windows.Visibility.Visible;
}
else if (img1 != null)
{
ms1 = new MemoryStream(img1.Data);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = ms1;
bitmapImage.EndInit();
Image.Source = bitmapImage;
ImageWidth = bitmapImage.Width;
ImageHeight = bitmapImage.Height;
Image.Visibility = System.Windows.Visibility.Visible;
imageFrames = 1;
currentFrame = 1;
OSAEImage img2 = imgMgr.GetImage(imgName2);
if (img2 != null)
{
ms2 = new MemoryStream(img2.Data);
imageFrames = 2;
OSAEImage img3 = imgMgr.GetImage(imgName3);
if (img3 != null)
{
ms3 = new MemoryStream(img3.Data);
imageFrames = 3;
OSAEImage img4 = imgMgr.GetImage(imgName4);
if (img4 != null)
{
ms4 = new MemoryStream(img4.Data);
imageFrames = 4;
}
}
}
}
else
{
Image.Source = null;
Image.Visibility = System.Windows.Visibility.Hidden;
}
}
catch { }
sliderVisible = Convert.ToBoolean(screenObject.Property("Show Slider").Value);
if (sliderVisible)
{
sldSlider.Visibility = System.Windows.Visibility.Visible;
try
{
CurLevel = OSAEObjectPropertyManager.GetObjectPropertyValue(ObjectName, "Level").Value;
sldSlider.Value = Convert.ToUInt16(CurLevel);
}
catch { }
}
else
sldSlider.Visibility = System.Windows.Visibility.Hidden;
timer.Interval = TimeSpan.FromMilliseconds(frameDelay);
timer.Tick += this.timer_Tick;
if (imageFrames > 1) timer.Start();
}