Abstract definition of a 2D element to be displayed in an Overlay.
This class abstracts all the details of a 2D element which will appear in an overlay. In fact, not all OverlayElement instances can be directly added to an Overlay, only those which are OverlayElementContainer instances (derived from this class) are able to be added, however they can contain any OverlayElement however. This is done to enforce some level of grouping of widgets.
OverlayElements should be managed using OverlayElementManager. This class is responsible for instantiating / deleting elements, and also for accepting new types of element from plugins etc.
Note that positions / dimensions of 2D screen elements are expressed as parametric values (0.0 - 1.0) because this makes them resolution-independent. However, most screen resolutions have an aspect ratio of 1.3333:1 (width : height) so note that in physical pixels 0.5 is wider than it is tall, so a 0.5x0.5 panel will not be square on the screen (but it will take up exactly half the screen in both dimensions).
Inheritance: IRenderable
示例#1
0
        /// <summary>
        /// </summary>
        public OverlayElement CreateElementFromTemplate(string templateName, string typeName, string instanceName,
                                                        bool isTemplate)
        {
            OverlayElement element = null;

            if (String.IsNullOrEmpty(templateName))
            {
                element = CreateElement(typeName, instanceName, isTemplate);
            }
            else
            {
                var template = GetElement(templateName, true);

                var typeToCreate = "";
                if (String.IsNullOrEmpty(typeName))
                {
                    typeToCreate = template.GetType().Name;
                }
                else
                {
                    typeToCreate = typeName;
                }

                element = CreateElement(typeToCreate, instanceName, isTemplate);

                // Copy settings from template
                element.CopyFromTemplate(template);
            }

            return(element);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="templateName"></param>
        /// <param name="typeName"></param>
        /// <param name="instanceName"></param>
        /// <param name="isTemplate"></param>
        /// <returns></returns>
        public OverlayElement CreateElementFromTemplate(string templateName, string typeName, string instanceName, bool isTemplate)
        {
            OverlayElement element = null;

            if (templateName.Length == 0)
            {
                element = CreateElement(typeName, instanceName, isTemplate);
            }
            else
            {
                OverlayElement template = GetElement(templateName, true);

                string typeToCreate = "";
                if (typeName.Length == 0)
                {
                    typeToCreate = template.Type;
                }
                else
                {
                    typeToCreate = typeName;
                }

                element = CreateElement(typeToCreate, instanceName, isTemplate);

                // Copy settings from template
                ((OverlayElementContainer)element).CopyFromTemplate(template);
            }

            return(element);
        }
示例#3
0
        public override OverlayElement FindElementAt(float x, float y)
        {
            OverlayElement ret = null;

            var currZ = -1;

            if (isVisible)
            {
                ret = base.FindElementAt(x, y); //default to the current container if no others are found
                if (ret != null && this.childrenProcessEvents)
                {
                    foreach (var currentOverlayElement in this.children.Values)
                    {
                        if (currentOverlayElement.IsVisible && currentOverlayElement.Enabled)
                        {
                            var z = currentOverlayElement.ZOrder;
                            if (z > currZ)
                            {
                                var elementFound = currentOverlayElement.FindElementAt(x, y);
                                if (elementFound != null)
                                {
                                    currZ = z;
                                    ret   = elementFound;
                                }
                            }
                        }
                    }
                }
            }
            return(ret);
        }
示例#4
0
		public virtual void Start( RenderWindow window, ushort numGroupsInit, ushort numGroupsLoad, Real initProportion )
		{
			mWindow = window;
			mNumGroupsInit = numGroupsInit;
			mNumGroupsLoad = numGroupsLoad;
			mInitProportion = initProportion;
			// We need to pre-initialise the 'Bootstrap' group so we can use
			// the basic contents in the loading screen
			ResourceGroupManager.Instance.InitializeResourceGroup( "Bootstrap" );

			OverlayManager omgr = OverlayManager.Instance;
			mLoadOverlay = omgr.GetByName( "Core/LoadOverlay" );
			if ( mLoadOverlay == null )
			{
				throw new KeyNotFoundException( "Cannot find loading overlay" );
			}
			mLoadOverlay.Show();

			// Save links to the bar and to the loading text, for updates as we go
			mLoadingBarElement = omgr.Elements.GetElement( "Core/LoadPanel/Bar/Progress" );
			mLoadingCommentElement = omgr.Elements.GetElement( "Core/LoadPanel/Comment" );
			mLoadingDescriptionElement = omgr.Elements.GetElement( "Core/LoadPanel/Description" );

			OverlayElement barContainer = omgr.Elements.GetElement( "Core/LoadPanel/Bar" );
			mProgressBarMaxSize = barContainer.Width;
			mLoadingBarElement.Width = 0;

			// self is listener
			ResourceGroupManager.Instance.AddResourceGroupListener( this );
		}
 /// <summary>
 ///    Adds another OverlayElement to this container.
 /// </summary>
 /// <param name="element"></param>
 public virtual void AddChild(OverlayElement element)
 {
     if(element.IsContainer) {
         AddChildImpl((OverlayElementContainer)element);
     }
     else {
         AddChildImpl(element);
     }
 }
示例#6
0
        /// <summary>
        ///    Add a nested container to this container.
        /// </summary>
        /// <param name="container"></param>
        public virtual void AddChildContainer(OverlayElementContainer container)
        {
            // add this container to the main child list first
            OverlayElement element = container;

            AddChildElement(element);

            // now add the container to the container collection
            this.childContainers.Add(container.Name, container);
        }
示例#7
0
        /// <summary>
        /// Destroys the supplied OvelayElement
        /// </summary>
        /// <param name="element"></param>
        /// <param name="isTemplate"></param>
        public void DestroyElement(OverlayElement element, bool isTemplate)
        {
            var elements = isTemplate ? this._elementTemplates : this._elementInstances;

            if (!elements.ContainsValue(element))
            {
                throw new Exception("OverlayElement with the name '" + element.Name + "' not found to destroy.");
            }

            elements.Remove(element.Name);
        }
 /// <summary>
 ///    Adds another OverlayElement to this container.
 /// </summary>
 /// <param name="element"></param>
 public virtual void AddChild(OverlayElement element)
 {
     if (element.IsContainer)
     {
         AddChildImpl((OverlayElementContainer)element);
     }
     else
     {
         AddChildImpl(element);
     }
 }
        /// <summary>
        ///    Adds another OverlayElement to this container.
        /// </summary>
        /// <param name="element"></param>
        public virtual void AddChildImpl(OverlayElement element)
        {
            Debug.Assert(!children.ContainsKey(element.Name), string.Format("Child with name '{0}' already defined.", element.Name));

            // add to lookup table and list
            children.Add(element.Name, element);
            childList.Add(element);

            // inform this child about his/her parent and zorder
            element.NotifyParent(this, overlay);
            element.NotifyZOrder(zOrder + 1);
        }
        /// <summary>
        ///    Adds another OverlayElement to this container.
        /// </summary>
        /// <param name="element"></param>
        public virtual void AddChildImpl(OverlayElement element)
        {
            Debug.Assert(!children.ContainsKey(element.Name), string.Format("Child with name '{0}' already defined.", element.Name));

            // add to lookup table and list
            children.Add(element.Name, element);
            childList.Add(element);

            // inform this child about his/her parent and zorder
            element.NotifyParent(this, overlay);
            element.NotifyZOrder(zOrder + 1);
        }
示例#11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="line"></param>
        /// <param name="overlay"></param>
        /// <param name="element"></param>
        private void ParseElementAttrib(string line, Overlay overlay, OverlayElement element)
        {
            string[] parms = line.Split(' ');

            // get a string containing only the params
            string paramLine = line.Substring(line.IndexOf(' ', 0) + 1);

            // set the param, and hopefully it exists
            if (!element.SetParam(parms[0].ToLower(), paramLine))
            {
                log.WarnFormat("Bad element attribute line: {0} for element '{1}'", line, element.Name);
            }
        }
示例#12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="line"></param>
        /// <param name="overlay"></param>
        /// <param name="element"></param>
        private void ParseElementAttrib(string line, Overlay overlay, OverlayElement element)
        {
            var parms = line.Split(' ');

            // get a string containing only the params
            var paramLine = line.Substring(line.IndexOf(' ', 0) + 1);

            // set the param, and hopefully it exists
            if (!element.SetParam(parms[0].ToLower(), paramLine))
            {
                LogManager.Instance.Write("Bad element attribute line: {0} for element '{1}'", line, element.Name);
            }
        }
示例#13
0
		/// <summary>
		/// Do not instantiate any widgets directly. Use SdkTrayManager.
		/// </summary>
		/// <param name="name"></param>
		/// <param name="caption"></param>
		/// <param name="width"></param>
		public CheckBox( String name, String caption, Real width )
		{
			IsCursorOver = false;
			isFitToContents = width <= 0;
			element = OverlayManager.Instance.Elements.CreateElementFromTemplate
				( "SdkTrays/CheckBox", "BorderPanel", name );
			OverlayElementContainer c = (OverlayElementContainer)element;
			this.textArea = (TextArea)c.Children[ Name + "/CheckBoxCaption" ];
			this.square = (BorderPanel)c.Children[ Name + "/CheckBoxSquare" ];
			this.x = this.square.Children[ this.square.Name + "/CheckBoxX" ];
			this.x.Hide();
			element.Width = width;
			this.Caption = caption;
		}
示例#14
0
文件: Label.cs 项目: WolfgangSt/axiom
		/// <summary>
		/// Do not instantiate any widgets directly. Use SdkTrayManager.
		/// </summary>
		/// <param name="name"></param>
		/// <param name="caption"></param>
		/// <param name="width"></param>
		public Label( String name, String caption, Real width )
		{
			element = OverlayManager.Instance.Elements.CreateElementFromTemplate( "SdkTrays/Label", "BorderPanel", name );
			this.textArea = (TextArea)( (OverlayElementContainer)element ).Children[ Name + "/LabelCaption" ];
			this.textArea.Text = caption;
			this.Caption = caption;
			if ( width <= 0 )
				this.isFitToTray = true;
			else
			{
				this.isFitToTray = false;
				element.Width = width;
			}
		}
        public static void ParseCaption(string[] parms, params object[] objects)
        {
            OverlayElement element = (OverlayElement)objects[0];

            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            // reconstruct the single string since the caption could have spaces
            for (int i = 0; i < parms.Length; i++)
            {
                sb.Append(parms[i]);
                sb.Append(" ");
            }

            element.Text = sb.ToString();
        }
示例#16
0
        public override void CopyFromTemplate(OverlayElement templateOverlay)
        {
            base.CopyFromTemplate(templateOverlay);

            if (templateOverlay.IsContainer && IsContainer)
            {
                foreach (var oldChildElement in ((OverlayElementContainer)templateOverlay).Children.Values)
                {
                    if (oldChildElement.IsCloneable)
                    {
                        var newChildElement = OverlayManager.Instance.Elements.CreateElement(oldChildElement.GetType().Name,
                                                                                             Name + "/" + oldChildElement.Name);
                        newChildElement.CopyFromTemplate(oldChildElement);
                        AddChild((OverlayElement)newChildElement);
                    }
                }
            }
        }
        /// <summary>
        ///    Creates a new OverlayElement of the type requested.
        /// </summary>
        /// <param name="typeName">The type of element to create is passed in as a string because this
        ///    allows plugins to register new types of component.</param>
        /// <param name="instanceName">The type of element to create.</param>
        /// <param name="isTemplate"></param>
        /// <returns></returns>
        public OverlayElement CreateElement(string typeName, string instanceName, bool isTemplate)
        {
            Hashtable elements = GetElementTable(isTemplate);

            if (elements.ContainsKey(instanceName))
            {
                throw new AxiomException("OverlayElement with the name '{0}' already exists.", instanceName);
            }

            OverlayElement element = CreateElementFromFactory(typeName, instanceName);

            element.Initialize();

            // register
            elements.Add(instanceName, element);

            return(element);
        }
        /// <summary>
        ///    Copys data from the template element to this element to clone it.
        /// </summary>
        /// <param name="template"></param>
        /// <returns></returns>
        public virtual void CopyFromTemplate(OverlayElement template)
        {
            PropertyInfo[] props = template.GetType().GetProperties();

            for (int i = 0; i < props.Length; i++)
            {
                PropertyInfo prop = props[i];

                // if the prop is not settable, then skip
                if (!prop.CanWrite || !prop.CanRead)
                {
                    log.Warn(prop.Name);
                    continue;
                }

                object srcVal = prop.GetValue(template, null);
                prop.SetValue(this, srcVal, null);
            }
        }
        /// <summary>
        ///    Add a nested container to this container.
        /// </summary>
        /// <param name="container"></param>
        public virtual void AddChildImpl(OverlayElementContainer container)
        {
            // add this container to the main child list first
            OverlayElement element = container;

            AddChildImpl(element);
            element.NotifyParent(this, overlay);
            element.NotifyZOrder(zOrder + 1);

            // inform container children of the current overlay
            // *gasp* it's a foreach!  this isn't a time critical method anyway
            foreach (OverlayElement child in container.children)
            {
                child.NotifyParent(container, overlay);
                child.NotifyZOrder(container.ZOrder + 1);
            }

            // now add the container to the container collection
            childContainers.Add(container.Name, container);
        }
示例#20
0
        /// <summary>
        ///    Parses a new element
        /// </summary>
        /// <param name="script"></param>
        /// <param name="type"></param>
        /// <param name="name"></param>
        /// <param name="isContainer"></param>
        /// <param name="overlay"></param>
        /// <param name="isTemplate"></param>
        /// <param name="templateName"></param>
        /// <param name="parent"></param>
        private void ParseNewElement(TextReader script, string type, string name, bool isContainer, Overlay overlay, bool isTemplate,
                                     string templateName, OverlayElementContainer parent)
        {
            string         line;
            OverlayElement element = OverlayElementManager.Instance.CreateElementFromTemplate(templateName, type, name, isTemplate);

            if (parent != null)
            {
                // add this element to the parent container
                parent.AddChild(element);
            }
            else if (overlay != null)
            {
                overlay.AddElement((OverlayElementContainer)element);
            }

            while ((line = ParseHelper.ReadLine(script)) != null)
            {
                // inore blank lines and comments
                if (line.Length > 0 && !line.StartsWith("//"))
                {
                    if (line == "}")
                    {
                        // finished element
                        break;
                    }
                    else
                    {
                        if (isContainer && ParseChildren(script, line, overlay, isTemplate, (OverlayElementContainer)element))
                        {
                            // nested children, so don't reparse it
                        }
                        else
                        {
                            // element attribute
                            ParseElementAttrib(line, overlay, element);
                        }
                    }
                }
            }
        }
示例#21
0
        /// <summary>
        /// This returns a OverlayElement at position x,y.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public virtual OverlayElement FindElementAt(float x, float y)
        {
            OverlayElement ret   = null;
            var            currZ = -1;

            for (var i = 0; i < this.elementList.Count; i++)
            {
                var container = (OverlayElementContainer)this.elementList[i];
                var z         = container.ZOrder;
                if (z > currZ)
                {
                    var elementFound = container.FindElementAt(x, y);
                    if (elementFound != null)
                    {
                        currZ = elementFound.ZOrder;
                        ret   = elementFound;
                    }
                }
            }
            return(ret);
        }
        public static void ParseHeight(string[] parms, params object[] objects)
        {
            OverlayElement element = (OverlayElement)objects[0];

            element.Height = StringConverter.ParseFloat(parms[0]);
        }
示例#23
0
 private static bool Contains(OverlayElement e, float x, float y)
 {
     var actualLeftPx = Globals.Scene.CurrentViewport.ActualWidth * e.DerivedLeft;
     var actualTopPx = Globals.Scene.CurrentViewport.ActualHeight * e.DerivedTop;
     return
         actualLeftPx <= x &&
         actualLeftPx + e.Width > x &&
         actualTopPx <= y &&
         actualTopPx + e.Height > y;
 }
示例#24
0
		/// <summary>
		///    Copys data from the template element to this element to clone it.
		/// </summary>
		/// <param name="template"></param>
		/// <returns></returns>
		public virtual void CopyFromTemplate( OverlayElement template )
		{
			template.CopyParametersTo( this );
			sourceTemplate = template;
		}
		public override void CopyFromTemplate( OverlayElement templateOverlay )
		{
			base.CopyFromTemplate( templateOverlay );

			if ( templateOverlay.IsContainer && IsContainer )
			{
				foreach ( var oldChildElement in ( (OverlayElementContainer)templateOverlay ).Children.Values )
				{
					if ( oldChildElement.IsCloneable )
					{
						var newChildElement = OverlayManager.Instance.Elements.CreateElement( oldChildElement.GetType().Name,
						                                                                      Name + "/" + oldChildElement.Name );
						newChildElement.CopyFromTemplate( oldChildElement );
						AddChild( (OverlayElement)newChildElement );
					}
				}
			}
		}
示例#26
0
		/// <summary>
		/// Do not instantiate any widgets directly. Use SdkTrayManager.
		/// </summary>
		/// <param name="name"></param>
		/// <param name="caption"></param>
		/// <param name="width"></param>
		/// <param name="commentBoxWidth"></param>
		public ProgressBar( String name, String caption, Real width, Real commentBoxWidth )
		{
			element = OverlayManager.Instance.Elements.CreateElementFromTemplate( "SdkTrays/ProgressBar", "BorderPanel", name );
			element.Width = ( width );
			var c = (OverlayElementContainer)element;
			this.textArea = (TextArea)c.Children[ Name + "/ProgressCaption" ];
			var commentBox = (OverlayElementContainer)c.Children[ Name + "/ProgressCommentBox" ];
			commentBox.Width = ( commentBoxWidth );
			commentBox.Left = ( -( commentBoxWidth + 5 ) );
			this.commentTextArea = (TextArea)commentBox.Children[ commentBox.Name + "/ProgressCommentText" ];
			this.meter = c.Children[ Name + "/ProgressMeter" ];
			this.meter.Width = ( width - 10 );
			this.fill = ( (OverlayElementContainer)this.meter ).Children[ this.meter.Name + "/ProgressFill" ];
			Caption = caption;
		}
示例#27
0
		/// <summary>
		/// 
		/// </summary>
		public Widget()
		{
			this.trayLoc = TrayLocation.None;
			this.element = null;
			this.listener = null;
		}
		/// <summary>
		/// Destroys the supplied OvelayElement
		/// </summary>
		/// <param name="element"></param>
		public void DestroyElement( OverlayElement element )
		{
			DestroyElement( element, false );
		}
示例#29
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="element"></param>
		/// <param name="cursorPos"></param>
		/// <param name="voidBorder"></param>
		/// <returns></returns>
		public static bool IsCursorOver( OverlayElement element, Vector2 cursorPos, Real voidBorder )
		{
			OverlayManager om = OverlayManager.Instance;
			var l = (int)( element.DerivedLeft*om.ViewportWidth );
			var t = (int)( element.DerivedTop*om.ViewportHeight );
			int r = l + (int)element.Width;
			int b = t + (int)element.Height;

			return ( cursorPos.x >= l + voidBorder && cursorPos.x <= r - voidBorder && cursorPos.y >= t + voidBorder &&
			         cursorPos.y <= b - voidBorder );
		}
示例#30
0
 /// <summary>
 /// Destroys the supplied OvelayElement
 /// </summary>
 /// <param name="element"></param>
 public void DestroyElement(OverlayElement element)
 {
     DestroyElement(element, false);
 }
示例#31
0
		/// <summary>
		/// Static utility method used to get the cursor's offset from the center<para></para>
		/// of an overlay element in pixels.
		/// </summary>
		/// <param name="element"></param>
		/// <param name="cursorPos"></param>
		/// <returns></returns>
		public static Vector2 CursorOffset( OverlayElement element, Vector2 cursorPos )
		{
			OverlayManager om = OverlayManager.Instance;
			return new Vector2( cursorPos.x - ( element.DerivedLeft*om.ViewportWidth + element.Width/2 ),
			                    cursorPos.y - ( element.DerivedTop*om.ViewportHeight + element.Height/2 ) );
		}
示例#32
0
		/// <summary>
		/// 
		/// </summary>
		public void Cleanup()
		{
			if ( this.element != null )
			{
				NukeOverlayElement( this.element );
			}
			this.element = null;
		}
示例#33
0
		public override void CreateScene()
		{
			// Check prerequisites first
			RenderSystemCapabilities caps = Root.Instance.RenderSystem.Capabilities;
			if ( !caps.HasCapability( Capabilities.VertexPrograms ) || !caps.HasCapability( Capabilities.FragmentPrograms ) )
			{
				throw new AxiomException( "Your card does not support vertex and fragment programs, so cannot run this demo. Sorry!" );
			}
			else
			{
				if ( !GpuProgramManager.Instance.IsSyntaxSupported( "arbfp1" ) &&
					!GpuProgramManager.Instance.IsSyntaxSupported( "ps_2_0" ) )
				{
					throw new AxiomException( "Your card does not support shader model 2, so cannot run this demo. Sorry!" );
				}
			}

			scene.AmbientLight = ColorEx.Black;

			// create scene node
			mainNode = scene.RootSceneNode.CreateChildSceneNode();

			// Load the meshes with non-default HBU options
			for ( int mn = 0; mn < NUM_ENTITIES; mn++ )
			{
				Mesh mesh = MeshManager.Instance.Load( entityMeshes[ mn ], ResourceGroupManager.DefaultResourceGroupName,
					BufferUsage.DynamicWriteOnly,
					BufferUsage.StaticWriteOnly,
					true, true, 1 ); //so we can still read it

				// Build tangent vectors, all our meshes use only 1 texture coordset
				short srcIdx, destIdx;

				if ( !mesh.SuggestTangentVectorBuildParams( out srcIdx, out destIdx ) )
				{
					mesh.BuildTangentVectors( srcIdx, destIdx );
				}

				// Create entity
				entities[ mn ] = scene.CreateEntity( "Ent" + mn.ToString(), entityMeshes[ mn ] );

				// Attach to child of root node
				mainNode.AttachObject( entities[ mn ] );

				// Make invisible, except for index 0
				if ( mn == 0 )
				{
					entities[ mn ].MaterialName = materialNames[ currentEntity, currentMaterial ];
				}
				else
				{
					entities[ mn ].IsVisible = false;
				}
			}

			for ( int i = 0; i < NUM_LIGHTS; i++ )
			{
				lightPivots[ i ] = scene.RootSceneNode.CreateChildSceneNode();
				lightPivots[ i ].Rotate( lightRotationAxes[ i ], lightRotationAngles[ i ] );

				// Create a light, use default parameters
				lights[ i ] = scene.CreateLight( "Light" + i.ToString() );
				lights[ i ].Position = lightPositions[ i ];
				lights[ i ].Diffuse = diffuseLightColors[ i ];
				lights[ i ].Specular = specularLightColors[ i ];
				lights[ i ].IsVisible = lightState[ i ];

				// Attach light
				lightPivots[ i ].AttachObject( lights[ i ] );

				// Create billboard for light
				lightFlareSets[ i ] = scene.CreateBillboardSet( "Flare" + i.ToString() );
				lightFlareSets[ i ].MaterialName = "Particles/Flare";
				lightPivots[ i ].AttachObject( lightFlareSets[ i ] );
				lightFlares[ i ] = lightFlareSets[ i ].CreateBillboard( lightPositions[ i ] );
				lightFlares[ i ].Color = diffuseLightColors[ i ];
				lightFlareSets[ i ].IsVisible = lightState[ i ];
			}
			// move the camera a bit right and make it look at the knot
			camera.MoveRelative( new Vector3( 50, 0, 20 ) );
			camera.LookAt( new Vector3( 0, 0, 0 ) );

			// show overlay
			Overlay pOver = OverlayManager.Instance.GetByName( "Example/DP3Overlay" );
			objectInfo = OverlayManager.Instance.Elements.GetElement( "Example/DP3/ObjectInfo" );
			materialInfo = OverlayManager.Instance.Elements.GetElement( "Example/DP3/MaterialInfo" );
			info = OverlayManager.Instance.Elements.GetElement( "Example/DP3/Info" );

			objectInfo.Text = "Current: " + entityMeshes[ currentEntity ];
			materialInfo.Text = "Current: " + materialNames[ currentEntity, currentMaterial ];
			if ( !caps.HasCapability( Capabilities.FragmentPrograms ) )
			{
				info.Text = "NOTE: Light colours and specular highlights are not supported by your card.";
			}
			pOver.Show();
		}
示例#34
0
 public void AddButton(OverlayElement button)
 {
     if (!(button.UserData is Action)) throw new ArgumentException("Button UserData must be an Action");
     Debug.Assert(!_buttons.Contains(button));
     _buttons.Add(button);
 }
示例#35
0
		/// <summary>
		/// Static utility method to recursively delete an overlay element plus<para></para>
		/// all of its children from the system.
		/// </summary>
		/// <param name="element"></param>
		public static void NukeOverlayElement( OverlayElement element )
		{
			var container = element as OverlayElementContainer;
			if ( container != null )
			{
				var toDelete = new List<OverlayElement>();
				foreach ( OverlayElement child in container.Children.Values )
				{
					toDelete.Add( child );
				}

				for ( int i = 0; i < toDelete.Count; i++ )
				{
					NukeOverlayElement( toDelete[ i ] );
				}
			}
			if ( element != null )
			{
				OverlayElementContainer parent = element.Parent;
				if ( parent != null )
				{
					parent.RemoveChild( element.Name );
				}
				OverlayManager.Instance.Elements.DestroyElement( element.Name );
			}
		}
        public static void ParseMaterial(string[] parms, params object[] objects)
        {
            OverlayElement element = (OverlayElement)objects[0];

            element.MaterialName = parms[0];
        }
		/// <summary>
		/// Destroys the supplied OvelayElement
		/// </summary>
		/// <param name="element"></param>
		/// <param name="isTemplate"></param>
		public void DestroyElement( OverlayElement element, bool isTemplate )
		{
			var elements = isTemplate ? this._elementTemplates : this._elementInstances;
			if ( !elements.ContainsValue( element ) )
			{
				throw new Exception( "OverlayElement with the name '" + element.Name + "' not found to destroy." );
			}

			elements.Remove( element.Name );
		}
示例#38
0
		public void CopyParametersTo( OverlayElement instance )
		{
			foreach ( var command in Commands )
			{
				var srcValue = command.Get( this );
				command.Set( instance, srcValue );
			}
		}
        /// <summary>
        ///    Copys data from the template element to this element to clone it.
        /// </summary>
        /// <param name="template"></param>
        /// <returns></returns>
        public virtual void CopyFromTemplate(OverlayElement template)
        {
            PropertyInfo[] props = template.GetType().GetProperties();

            for(int i = 0; i < props.Length; i++) {
                PropertyInfo prop = props[i];

                // if the prop is not settable, then skip
                if(!prop.CanWrite || !prop.CanRead) {
                    log.Warn(prop.Name);
                    continue;
                }

                object srcVal = prop.GetValue(template, null);
                prop.SetValue(this, srcVal, null);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="line"></param>
        /// <param name="overlay"></param>
        /// <param name="element"></param>
        private void ParseElementAttrib(string line, Overlay overlay, OverlayElement element)
        {
            string[] parms = line.Split(' ');

            // get a string containing only the params
            string paramLine = line.Substring(line.IndexOf(' ', 0) + 1);

            // set the param, and hopefully it exists
            if(!element.SetParam(parms[0].ToLower(), paramLine)) {
                log.WarnFormat("Bad element attribute line: {0} for element '{1}'", line, element.Name);
            }
        }
示例#41
0
		/// <summary>
		/// Static utility method to check if the cursor is over an overlay element.
		/// </summary>
		/// <param name="element"></param>
		/// <param name="cursorPos"></param>
		/// <returns></returns>
		public static bool IsCursorOver( OverlayElement element, Vector2 cursorPos )
		{
			return IsCursorOver( element, cursorPos, 0 );
		}
示例#42
0
		public ObjectTextDisplay( MovableObject p, Camera c, string shapeName )
		{
			this.parent = p;
			this.camera = c;
			this.enabled = false;
			this.text = "";

			// create an overlay that we can use for later

			// = Ogre.OverlayManager.getSingleton().create("shapeName");
			this.parentOverlay = (Overlay)OverlayManager.Instance.Create( "shapeName" );

			// (Ogre.OverlayContainer)(Ogre.OverlayManager.getSingleton().createOverlayElement("Panel", "container1"));
			this.parentContainer =
				(OverlayElementContainer)( OverlayElementManager.Instance.CreateElement( "Panel", "container1", false ) );

			//parentOverlay.add2D(parentContainer);
			this.parentOverlay.AddElement( this.parentContainer );

			//parentText = Ogre.OverlayManager.getSingleton().createOverlayElement("TextArea", "shapeNameText");
			this.parentText = OverlayElementManager.Instance.CreateElement( "TextArea", shapeName, false );

			this.parentText.SetDimensions( 1.0f, 1.0f );

			//parentText.setMetricsMode(Ogre.GMM_PIXELS);
			this.parentText.MetricsMode = MetricsMode.Pixels;


			this.parentText.SetPosition( 1.0f, 1.0f );


			this.parentText.SetParam( "font_name", "Arial" );
			this.parentText.SetParam( "char_height", "25" );
			this.parentText.SetParam( "horz_align", "center" );
			this.parentText.Color = new ColorEx( 1.0f, 1.0f, 1.0f );
			//parentText.setColour(Ogre.ColourValue(1.0, 1.0, 1.0));


			this.parentContainer.AddChild( this.parentText );

			this.parentOverlay.Show();
		}
        public static void ParseMetricsMode(string[] parms, params object[] objects)
        {
            OverlayElement element = (OverlayElement)objects[0];

            element.MetricsMode = (MetricsMode)ScriptEnumAttribute.Lookup(parms[0], typeof(MetricsMode));
        }
示例#44
0
		/// <summary>
		///
		/// </summary>
		/// <param name="name"></param>
		protected internal OverlayElement( string name )
            : base()
		{
			this.name = name;
			isVisible = true;
			isCloneable = true;
			left = 0.0f;
			top = 0.0f;
			width = 1.0f;
			height = 1.0f;
			metricsMode = MetricsMode.Relative;
			horzAlign = HorizontalAlignment.Left;
			vertAlign = VerticalAlignment.Top;
			pixelTop = 0.0f;
			pixelLeft = 0.0f;
			pixelWidth = 1.0f;
			pixelHeight = 1.0f;
			pixelScaleX = 1.0f;
			pixelScaleY = 1.0f;
			parent = null;
			overlay = null;
			isDerivedOutOfDate = true;
			isGeomPositionsOutOfDate = true;
			isGeomUVsOutOfDate = true;
			zOrder = 0;
			isEnabled = true;
			isInitialized = false;
			sourceTemplate = null;
		}
        public static void ParseVertAlign(string[] parms, params object[] objects)
        {
            OverlayElement element = (OverlayElement)objects[0];

            element.VerticalAlignment = (VerticalAlignment)ScriptEnumAttribute.Lookup(parms[0], typeof(VerticalAlignment));
        }
示例#46
0
		public void CopyParametersTo( OverlayElement instance )
		{
			foreach ( IPropertyCommand command in Commands )
			{
				string srcValue = command.Get( this );
				command.Set( instance, srcValue );
			}
		}
示例#47
0
 public void RemoveButton(OverlayElement button)
 {
     var success = _buttons.Remove(button);
     Debug.Assert(success, "Button wasn't registered");
 }