/*
* Copyright (c) 2006-2014, openmetaverse.org
* All rights reserved.
*
* - Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Neither the name of the openmetaverse.org nor the names
* of its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using OpenMetaverse.StructuredData;
namespace OpenMetaverse
{
#region enums
///
/// Permissions for control of object media
///
[Flags]
public enum MediaPermission : byte
{
None = 0,
Owner = 1,
Group = 2,
Anyone = 4,
All = None | Owner | Group | Anyone
}
///
/// Style of cotrols that shold be displayed to the user
///
public enum MediaControls
{
Standard = 0,
Mini
}
#endregion enums
///
/// Class representing media data for a single face
///
public class MediaEntry
{
/// Is display of the alternative image enabled
public bool EnableAlterntiveImage;
/// Should media auto loop
public bool AutoLoop;
/// Shoule media be auto played
public bool AutoPlay;
/// Auto scale media to prim face
public bool AutoScale;
/// Should viewer automatically zoom in on the face when clicked
public bool AutoZoom;
/// Should viewer interpret first click as interaction with the media
/// or when false should the first click be treated as zoom in commadn
public bool InteractOnFirstClick;
/// Style of controls viewer should display when
/// viewer media on this face
public MediaControls Controls;
/// Starting URL for the media
public string HomeURL;
/// Currently navigated URL
public string CurrentURL;
/// Media height in pixes
public int Height;
/// Media width in pixels
public int Width;
/// Who can controls the media
public MediaPermission ControlPermissions;
/// Who can interact with the media
public MediaPermission InteractPermissions;
/// Is URL whitelist enabled
public bool EnableWhiteList;
/// Array of URLs that are whitelisted
public string[] WhiteList;
///
/// Serialize to OSD
///
/// OSDMap with the serialized data
public OSDMap GetOSD()
{
OSDMap map = new OSDMap();
map["alt_image_enable"] = OSD.FromBoolean(EnableAlterntiveImage);
map["auto_loop"] = OSD.FromBoolean(AutoLoop);
map["auto_play"] = OSD.FromBoolean(AutoPlay);
map["auto_scale"] = OSD.FromBoolean(AutoScale);
map["auto_zoom"] = OSD.FromBoolean(AutoZoom);
map["controls"] = OSD.FromInteger((int)Controls);
map["current_url"] = OSD.FromString(CurrentURL);
map["first_click_interact"] = OSD.FromBoolean(InteractOnFirstClick);
map["height_pixels"] = OSD.FromInteger(Height);
map["home_url"] = OSD.FromString(HomeURL);
map["perms_control"] = OSD.FromInteger((int)ControlPermissions);
map["perms_interact"] = OSD.FromInteger((int)InteractPermissions);
List wl = new List();
if (WhiteList != null && WhiteList.Length > 0)
{
for (int i = 0; i < WhiteList.Length; i++)
wl.Add(OSD.FromString(WhiteList[i]));
}
map["whitelist"] = new OSDArray(wl);
map["whitelist_enable"] = OSD.FromBoolean(EnableWhiteList);
map["width_pixels"] = OSD.FromInteger(Width);
return map;
}
///
/// Deserialize from OSD data
///
/// Serialized OSD data
/// Deserialized object
public static MediaEntry FromOSD(OSD osd)
{
MediaEntry m = new MediaEntry();
OSDMap map = (OSDMap)osd;
m.EnableAlterntiveImage = map["alt_image_enable"].AsBoolean();
m.AutoLoop = map["auto_loop"].AsBoolean();
m.AutoPlay = map["auto_play"].AsBoolean();
m.AutoScale = map["auto_scale"].AsBoolean();
m.AutoZoom = map["auto_zoom"].AsBoolean();
m.Controls = (MediaControls)map["controls"].AsInteger();
m.CurrentURL = map["current_url"].AsString();
m.InteractOnFirstClick = map["first_click_interact"].AsBoolean();
m.Height = map["height_pixels"].AsInteger();
m.HomeURL = map["home_url"].AsString();
m.ControlPermissions = (MediaPermission)map["perms_control"].AsInteger();
m.InteractPermissions = (MediaPermission)map["perms_interact"].AsInteger();
if (map["whitelist"].Type == OSDType.Array)
{
OSDArray wl = (OSDArray)map["whitelist"];
if (wl.Count > 0)
{
m.WhiteList = new string[wl.Count];
for (int i = 0; i < wl.Count; i++)
{
m.WhiteList[i] = wl[i].AsString();
}
}
}
m.EnableWhiteList = map["whitelist_enable"].AsBoolean();
m.Width = map["width_pixels"].AsInteger();
return m;
}
}
public partial class Primitive
{
///
/// Current version of the media data for the prim
///
public string MediaVersion = string.Empty;
///
/// Array of media entries indexed by face number
///
public MediaEntry[] FaceMedia;
}
}