Beispiel #1
0
 /// <summary>
 /// Adds text lines to rendering queue.
 /// </summary>
 /// <param name="lines">The text lines.</param>
 /// <param name="pos">The text position.</param>
 /// <param name="textVerticalIndention">The vertical intention between lines.</param>
 /// <param name="horizontalAlign">The text horizontal align.</param>
 /// <param name="verticalAlign">The text vertical align.</param>
 /// <param name="color">The text color.</param>
 public void AddTextLines(IList <string> lines, Vector2 pos, EHorizontalAlignment horizontalAlign,
                          EVerticalAlignment verticalAlign, double textVerticalIndention, ColorValue color, AddTextOptions options = AddTextOptions.PixelAlign)
 {
     AddTextLines(null, DefaultFontSize, lines, pos.ToVector2F(), horizontalAlign, verticalAlign, (float)textVerticalIndention, color, options);
 }
        void RenderMultilineDisabled(ViewportRenderingContext context, Vector2 screenPosition)
        {
            var renderer = context.Owner.CanvasRenderer;
            var fontSize = GetFontSizeScreen(context);
            var options  = PixelAlign.Value ? CanvasRenderer.AddTextOptions.PixelAlign : 0;

            var font = Font.Value;

            if (font == null)
            {
                font = renderer.DefaultFont;
            }
            if (font == null || font.Disposed)
            {
                return;
            }

            //Back
            {
                var length = font.GetTextLength(fontSize, renderer, Text);
                var offset = new Vector2(length, fontSize) * 0.5;

                var pos = screenPosition;

                switch (HorizontalAlignment.Value)
                {
                case EHorizontalAlignment.Left:
                case EHorizontalAlignment.Stretch:
                    pos.X += length * 0.5;
                    break;

                case EHorizontalAlignment.Right:
                    pos.X -= length * 0.5;
                    break;
                }

                switch (VerticalAlignment.Value)
                {
                case EVerticalAlignment.Top:
                case EVerticalAlignment.Stretch:
                    pos.Y += fontSize * 0.5;
                    break;

                case EVerticalAlignment.Bottom:
                    pos.Y -= fontSize * 0.5;
                    break;
                }

                var rect = new Rectangle(pos - offset, pos + offset);
                RenderBack2(context, rect);
            }

            if (Shadow)
            {
                ColorValue color = ShadowColor.Value.GetSaturate();
                renderer.AddText(font, fontSize, Text,
                                 screenPosition + ConvertOffsetToScreen(context, ShadowOffset),
                                 HorizontalAlignment, VerticalAlignment, color, options);
            }

            renderer.AddText(font, fontSize, Text, screenPosition, HorizontalAlignment, VerticalAlignment, Color, options);
        }
Beispiel #3
0
        private void ParentMeshInSpace_GetRenderSceneDataAddToFrameData(Component_MeshInSpace sender, ViewportRenderingContext context, GetRenderSceneDataMode mode, ref Component_RenderingPipeline.RenderSceneData.MeshItem item)
        {
            if (!CalculateOnCPU)
            {
                Component_Skeleton skeleton = ReplaceSkeleton;
                if (skeleton == null)
                {
                    skeleton = ParentMeshInSpace?.Mesh.Value?.Skeleton;
                }

                if (skeleton != null)
                {
                    var animation = PlayAnimation.Value;
                    if (animation != null)
                    {
                        UpdateAnimationTime();

                        //settings.animationStates = new AnimationStateItem[ 1 ];
                        //settings.animationStates[ 0 ] = new AnimationStateItem( animation, currentLocalTime, 1 );

                        var skeletonAnimation = animation as Component_SkeletonAnimation;
                        var track             = skeletonAnimation?.Track.Value;

                        if (track != null || CalculateBoneTransforms != null)
                        {
                            Update(skeleton, track, currentAnimationTime);

                            if (transformMatrixRelativeToSkin != null && transformMatrixRelativeToSkin.Length != 0)
                            {
                                item.AnimationData = new Component_RenderingPipeline.RenderSceneData.MeshItem.AnimationDataClass();

                                bool dualQuaternion = false;                                // GetSkinningMode( skeleton ) == Component_Skeleton.SkinningModeEnum.DualQuaternion;
                                if (dualQuaternion)
                                {
                                    item.AnimationData.Mode = 2;
                                }
                                else
                                {
                                    item.AnimationData.Mode = 1;
                                }

                                //create dynamic texture
                                var size         = new Vector2I(4, MathEx.NextPowerOfTwo(transformMatrixRelativeToSkin.Length));
                                var bonesTexture = context.DynamicTexture_Alloc(ViewportRenderingContext.DynamicTextureType.DynamicTexture, Component_Image.TypeEnum._2D, size, PixelFormat.Float32RGBA, 0, false);

                                //try get array from texture to minimize memory allocations
                                var surfaces = bonesTexture.Result.GetData();
                                if (surfaces == null)
                                {
                                    surfaces = new GpuTexture.SurfaceData[] { new GpuTexture.SurfaceData(0, 0, new byte[size.X * size.Y * 16]) }
                                }
                                ;
                                var data = surfaces[0].data;

                                //copy data to the texture
                                unsafe
                                {
                                    fixed(byte *pData2 = data)
                                    {
                                        Matrix4F *pData = (Matrix4F *)pData2;

                                        for (int n = 0; n < transformMatrixRelativeToSkin.Length; n++)
                                        {
                                            pData[n] = transformMatrixRelativeToSkin[n];
                                        }
                                    }
                                }
                                bonesTexture.Result.SetData(new GpuTexture.SurfaceData[] { new GpuTexture.SurfaceData(0, 0, data) });

                                item.AnimationData.BonesTexture = bonesTexture;
                            }
                        }
                    }
                }
            }
        }

        void RenderSkeleton(Viewport viewport)
        {
            // ParentMeshInSpace.Transform is automaticaly applyed to ParentMeshInSpace.Mesh, skeleton must be transformed manually
            var transformMatrix = ParentMeshInSpace?.Transform.Value?.ToMatrix4() ?? Matrix4.Identity;

            var skeletonArrows = GetCurrentAnimatedSkeletonArrows();

            if (skeletonArrows != null)
            {
                var color = new ColorValue(0, 0.5, 1, 0.7);                   //ToDo : Вынести в другое место.
                viewport.Simple3DRenderer.SetColor(color, color * ProjectSettings.Get.HiddenByOtherObjectsColorMultiplier);

                foreach (var arrow in skeletonArrows)
                {
                    viewport.Simple3DRenderer.AddArrow(transformMatrix * arrow.Start, transformMatrix * arrow.End);
                }
            }
        }

        bool CheckNeedModifiableMesh()
        {
            if (CalculateOnCPU)
            {
                if (ReplaceSkeleton.ReferenceSpecified)
                {
                    return(true);
                }
                var mesh = ParentMeshInSpace?.Mesh.Value;
                if (mesh != null && mesh.Skeleton.ReferenceSpecified)
                {
                    return(true);
                }

                if (PlayAnimation.ReferenceSpecified)
                {
                    return(true);
                }
            }

            return(false);
        }

        void UpdateModifiableMesh(ViewportRenderingContext context)
        {
            var originalMesh   = ParentMeshInSpace.Mesh.Value;
            var modifiableMesh = ParentMeshInSpace.ModifiableMesh;

            Component_Skeleton skeleton = ReplaceSkeleton;

            if (skeleton == null)
            {
                skeleton = originalMesh.Skeleton;
            }
            if (skeleton != null)
            {
                //!!!!сериализовывать

                var animation = PlayAnimation.Value;
                if (animation != null)
                {
                    UpdateAnimationTime();

                    //settings.animationStates = new AnimationStateItem[ 1 ];
                    //settings.animationStates[ 0 ] = new AnimationStateItem( animation, currentLocalTime, 1 );

                    var skeletonAnimation = animation as Component_SkeletonAnimation;
                    var track             = skeletonAnimation?.Track.Value;

                    if (track != null || CalculateBoneTransforms != null)
                    {
                        Update(skeleton, track, currentAnimationTime);
                        CalculateCPU(skeleton, originalMesh, modifiableMesh);
                    }
                }

                if (needResetToOriginalMesh)
                {
                    needResetToOriginalMesh = false;
                    if (CalculateOnCPU)
                    {
                        ResetToOriginalMesh(originalMesh, modifiableMesh);
                    }
                }
            }
        }

        /////////////////////////////////////////

        void ResetTime(bool needResetToOriginalMesh)
        {
            if (needResetToOriginalMesh)
            {
                this.needResetToOriginalMesh = true;
            }
            currentEngineTime    = EngineApp.EngineTime;
            currentAnimationTime = (PlayAnimation.Value as Component_SkeletonAnimation)?.TrackStartTime ?? 0;
        }

        void UpdateAnimationTime()
        {
            double t         = EngineApp.EngineTime;
            double increment = t - currentEngineTime;

            currentEngineTime     = t;
            currentAnimationTime += increment * Speed;

            var animation = PlayAnimation.Value as Component_SkeletonAnimation;

            if (animation != null)
            {
                double animationStartTime = animation.TrackStartTime;
                double animationLength    = animation.Length;
                if (animationLength > 0)
                {
                    if (AutoRewind)
                    {
                        while (currentAnimationTime > animationStartTime + animationLength)
                        {
                            currentAnimationTime -= animationLength;
                        }
                        while (currentAnimationTime < animationStartTime)
                        {
                            currentAnimationTime += animationLength;
                        }
                    }
                    else
                    {
                        MathEx.Clamp(ref currentAnimationTime, animationStartTime, animationStartTime + animationLength);
                    }
                }
                else
                {
                    currentAnimationTime = animationStartTime;
                }
            }
            else
            {
                currentAnimationTime = 0;
            }
        }
        public override void NewObjectSetDefaultConfiguration(bool createdFromNewObjectWindow = false)
        {
            if (Components.Count == 0)
            {
                Color = new ColorValue(0.6784314, 0.6784314, 0.6784314);

                //Mesh
                {
                    var mesh = CreateComponent <Component_Mesh>();
                    mesh.Name = "Mesh";
                    Mesh      = ReferenceUtility.MakeThisReference(this, mesh);

                    var geometry = mesh.CreateComponent <Component_MeshGeometry_Box>();
                    geometry.Name       = "Mesh Geometry";
                    geometry.Dimensions = new Vector3(0.05, 0.3, 0.3);
                    geometry.Material   = ReferenceUtility.MakeReference("Base\\Materials\\White.material");
                }

                //Button
                {
                    var meshInSpace = CreateComponent <Component_MeshInSpace>();
                    meshInSpace.Name = "Button";

                    var mesh = meshInSpace.CreateComponent <Component_Mesh>();
                    mesh.Name        = "Mesh";
                    meshInSpace.Mesh = ReferenceUtility.MakeThisReference(this, mesh);

                    var geometry = mesh.CreateComponent <Component_MeshGeometry_Box>();
                    geometry.Name       = "Mesh Geometry";
                    geometry.Dimensions = new Vector3(0.05, 0.15, 0.15);
                    geometry.Material   = ReferenceUtility.MakeReference("Base\\Materials\\White.material");

                    meshInSpace.Mesh = ReferenceUtility.MakeThisReference(meshInSpace, mesh);

                    var transformOffset = meshInSpace.CreateComponent <Component_TransformOffset>();
                    transformOffset.Name           = "Attach Transform Offset";
                    transformOffset.PositionOffset = new Vector3(0.05, 0, 0);
                    transformOffset.Source         = ReferenceUtility.MakeThisReference(transformOffset, this, "Transform");

                    meshInSpace.Transform = ReferenceUtility.MakeThisReference(meshInSpace, transformOffset, "Result");
                }

                //Indicator
                {
                    var meshInSpace = CreateComponent <Component_MeshInSpace>();
                    meshInSpace.Name  = "Indicator";
                    meshInSpace.Color = new ColorValue(0, 1, 0);

                    var mesh = meshInSpace.CreateComponent <Component_Mesh>();
                    mesh.Name        = "Mesh";
                    meshInSpace.Mesh = ReferenceUtility.MakeThisReference(this, mesh);

                    var geometry = mesh.CreateComponent <Component_MeshGeometry_Cylinder>();
                    geometry.Name     = "Mesh Geometry";
                    geometry.Axis     = 0;
                    geometry.Radius   = 0.02;
                    geometry.Height   = 0.02;
                    geometry.Segments = 16;
                    geometry.Material = ReferenceUtility.MakeReference("Base\\Materials\\White.material");

                    meshInSpace.Mesh = ReferenceUtility.MakeThisReference(meshInSpace, mesh);

                    var transformOffset = meshInSpace.CreateComponent <Component_TransformOffset>();
                    transformOffset.Name           = "Attach Transform Offset";
                    transformOffset.PositionOffset = new Vector3(0.03, 0, 0.12);
                    transformOffset.Source         = ReferenceUtility.MakeThisReference(transformOffset, this, "Transform");

                    meshInSpace.Transform = ReferenceUtility.MakeThisReference(meshInSpace, transformOffset, "Result");
                }

                //C# Script
                {
                    var script = CreateComponent <Component_CSharpScript>();
                    script.Name = "C# Script";
                    script.Code = "public void InteractiveObjectButton_UpdateEvent(NeoAxis.Component sender, float delta)\r\n{\r\n\tvar _this = sender as Component_ButtonInSpace;\r\n\tif (_this != null)\r\n\t{\r\n\t\tvar indicator = _this.GetComponent(\"Indicator\") as Component_MeshInSpace;\r\n\t\tif (indicator != null)\r\n\t\t\tindicator.Color = _this.Activated ? new ColorValue(0, 1, 0) : new ColorValue(0.5, 0.5, 0.5);\r\n\r\n\t\tvar buttonOffset = _this.Components.GetByPath(\"Button\\\\Attach Transform Offset\") as Component_TransformOffset;\r\n\t\tif (buttonOffset != null)\r\n\t\t{\r\n\t\t\tvar offsetPushed = 0.01;\r\n\t\t\tvar offsetDefault = 0.05;\r\n\r\n\t\t\tvar coef = 0.0;\r\n\t\t\tif (_this.Clicking && _this.ClickingTotalTime != 0)\r\n\t\t\t{\r\n\t\t\t\tvar timeFactor = MathEx.Saturate(_this.ClickingCurrentTime / _this.ClickingTotalTime);\r\n\r\n\t\t\t\tif(timeFactor < 0.5)\r\n\t\t\t\t\tcoef = timeFactor * 2;\r\n\t\t\t\telse\r\n\t\t\t\t\tcoef = (1.0f - timeFactor) * 2;\r\n\t\t\t}\r\n\r\n\t\t\tvar offset = MathEx.Lerp(offsetDefault, offsetPushed, coef);\r\n\t\t\tbuttonOffset.PositionOffset = new Vector3(offset, 0, 0);\r\n\t\t}\r\n\t}\r\n}";

                    var handler = script.CreateComponent <Component_EventHandler>();
                    handler.Name          = "Event Handler UpdateEvent";
                    handler.WhenEnable    = Component_EventHandler.WhenEnableEnum.Editor | Component_EventHandler.WhenEnableEnum.Simulation | Component_EventHandler.WhenEnableEnum.Instance;
                    handler.Event         = ReferenceUtility.MakeReference("this:..\\..\\event:UpdateEvent");
                    handler.HandlerMethod = ReferenceUtility.MakeReference("this:..\\method:InteractiveObjectButton_UpdateEvent(NeoAxis.Component,System.Single)");
                }
            }
        }
Beispiel #5
0
 public abstract void RenderReference(Component_FlowGraph_DocumentWindow window, Vector2 from, bool fromInput, Vector2 to, ColorValue color, out bool mouseOver);
        public override void Render(ViewportRenderingContext context, out int verticesRendered)
        {
            base.Render(context, out verticesRendered);

            var context2 = context.objectInSpaceRenderingContext;
            var renderer = context.Owner.Simple3DRenderer;

            if (ConstraintRigid != null && renderer != null)
            {
                var tr  = TransformV;
                var pos = tr.Position;

                double low  = -1;
                double high = 1;
                if (LimitEnabled)
                {
                    low  = LimitLow;
                    high = LimitHigh;
                }

                var scale = (Math.Abs(low) + Math.Abs(high)) / 20;

                var posLow  = pos + tr.Rotation * new Vector3(low, 0, 0);
                var posHigh = pos + tr.Rotation * new Vector3(high, 0, 0);

                {
                    var color = new ColorValue(0, 0, 0);
                    renderer.SetColor(color, color * ProjectSettings.Get.HiddenByOtherObjectsColorMultiplier);
                    renderer.AddLine(pos + tr.Rotation * new Vector3(low, 0, 0), pos + tr.Rotation * new Vector3(high, 0, 0));
                    verticesRendered += 2;
                }

                {
                    var color = new ColorValue(0, 0, 0, 0.4);
                    var p1    = pos + tr.Rotation * new Vector3(0, scale, 0);
                    var p2    = pos + tr.Rotation * new Vector3(0, -scale, 0);
                    renderer.SetColor(color, color * ProjectSettings.Get.HiddenByOtherObjectsColorMultiplier);
                    renderer.AddLine(p1, p2);
                    verticesRendered += 2;
                }

                if (LimitEnabled)
                {
                    var color = new ColorValue(1, 0, 0);
                    renderer.SetColor(color, color * ProjectSettings.Get.HiddenByOtherObjectsColorMultiplier);
                    renderer.AddLine(
                        posLow + tr.Rotation * new Vector3(0, scale, 0),
                        posLow + tr.Rotation * new Vector3(0, -scale, 0));
                    renderer.AddLine(
                        posHigh + tr.Rotation * new Vector3(0, scale, 0),
                        posHigh + tr.Rotation * new Vector3(0, -scale, 0));
                    verticesRendered += 4;
                }

                {
                    var color = new ColorValue(0, 0, 0);

                    var posCurrent = pos + tr.Rotation * new Vector3(ConstraintRigid.JointTranslation, 0, 0);

                    var p1 = posCurrent + tr.Rotation * new Vector3(0, scale, 0);
                    var p2 = posCurrent + tr.Rotation * new Vector3(0, -scale, 0);
                    renderer.SetColor(color, color * ProjectSettings.Get.HiddenByOtherObjectsColorMultiplier);
                    renderer.AddLine(p1, p2);
                    verticesRendered += 2;
                }
            }
        }
Beispiel #7
0
        /////////////////////////////////////////

        //!!!!depth write is not supported
        public abstract void SetColor(ColorValue colorVisible, ColorValue colorInvisibleBehindObjects); //, bool depthWrite = false );
Beispiel #8
0
 /// <summary>
 /// Adds rectangle to rendering queue.
 /// </summary>
 /// <param name="rectangle">The rectangle.</param>
 /// <param name="color">The text color.</param>
 public void AddRectangle(Rectangle rectangle, ColorValue color)
 {
     AddRectangle(rectangle.ToRectangleF(), color);
 }
Beispiel #9
0
 public void AddThickRectangle(Rectangle outer, Rectangle inner, ColorValue color)
 {
     AddThickRectangle(outer.ToRectangleF(), inner.ToRectangleF(), color);
 }
Beispiel #10
0
 /// <summary>
 /// Adds line to rendering queue.
 /// </summary>
 /// <param name="start">The line start position.</param>
 /// <param name="end">The line end position.</param>
 /// <param name="color">The text color.</param>
 public void AddLine(Vector2 start, Vector2 end, ColorValue color)
 {
     AddLine(start.ToVector2F(), end.ToVector2F(), color);
 }
Beispiel #11
0
        /////////////////////////////////////////

        /// <summary>
        /// Adds rectangle to rendering queue.
        /// </summary>
        /// <param name="rectangle">The rectangle.</param>
        /// <param name="color">The text color.</param>
        public abstract void AddRectangle(RectangleF rectangle, ColorValue color);
Beispiel #12
0
        /////////////////////////////////////////

        /// <summary>
        /// Adds line to rendering queue.
        /// </summary>
        /// <param name="start">The line start position.</param>
        /// <param name="end">The line end position.</param>
        /// <param name="color">The text color.</param>
        public abstract void AddLine(Vector2F start, Vector2F end, ColorValue color);
Beispiel #13
0
 public int AddTextWordWrap(string text, Rectangle rect, EHorizontalAlignment horizontalAlign,
                            bool alignByWidth, EVerticalAlignment verticalAlign, double textVerticalIndention, ColorValue color, AddTextOptions options = AddTextOptions.PixelAlign)
 {
     return(AddTextWordWrap(null, DefaultFontSize, text, rect.ToRectangleF(), horizontalAlign, alignByWidth, verticalAlign, (float)textVerticalIndention, color, options));
 }
Beispiel #14
0
        /////////////////////////////////////////

        public abstract int AddTextWordWrap(Component_Font font, double fontSize, string text, RectangleF rect, EHorizontalAlignment horizontalAlign,
                                            bool alignByWidth, EVerticalAlignment verticalAlign, float textVerticalIndention, ColorValue color, AddTextOptions options = AddTextOptions.PixelAlign);
Beispiel #15
0
        protected virtual void OnRenderCheck(UICheck control, CanvasRenderer renderer)
        {
            var borderColor = new ColorValue(0.5, 0.5, 0.5);
            var insideColor = new ColorValue(0, 0, 0);
            var checkColor  = new ColorValue(1, 1, 0);
            var textColor   = new ColorValue(1, 1, 1);

            switch (control.State)
            {
            //case UICheck.StateEnum.Hover:
            //	checkColor = new ColorValue( 1, 1, 1 );
            //	break;

            case UICheck.StateEnum.Pushed:
                checkColor = new ColorValue(1, 1, 1);
                break;

            case UICheck.StateEnum.Disabled:
                checkColor = new ColorValue(0.7, 0.7, 0.7);
                textColor  = new ColorValue(0.5, 0.5, 0.5);
                break;
            }

            var colorMultiplier = new ColorValue(1, 1, 1);

            //var colorMultiplier = control.GetTotalColorMultiplier();
            //if( colorMultiplier.Alpha > 0 )
            //{
            control.GetScreenRectangle(out var rect);

            renderer.AddQuad(rect, borderColor * colorMultiplier);
            renderer.AddQuad(Multiply(rect, new Rectangle(0.1, 0.1, 0.9, 0.9)), insideColor * colorMultiplier);

            //Checked image
            if (control.Checked.Value == UICheck.CheckValue.Checked)
            {
                var points = new Vector2[]
                {
                    new Vector2(290.04, 33.286),
                    new Vector2(118.861, 204.427),
                    new Vector2(52.32, 137.907),
                    new Vector2(0, 190.226),
                    new Vector2(118.861, 309.071),
                    new Vector2(342.357, 85.606),
                };
                var points2 = new Vector2[points.Length];
                for (int n = 0; n < points2.Length; n++)
                {
                    points2[n] = points[n] / new Vector2(342.357, 342.357);
                }

                var color2 = checkColor * colorMultiplier;

                var vertices = new CanvasRenderer.TriangleVertex[points2.Length];
                for (int n = 0; n < points2.Length; n++)
                {
                    vertices[n] = new CanvasRenderer.TriangleVertex(Multiply(rect, points2[n]).ToVector2F(), color2);
                }

                var indices = new int[] { 0, 1, 5, 5, 4, 1, 1, 2, 3, 3, 1, 4 };

                renderer.AddTriangles(vertices, indices);
            }

            //Indeterminate image
            if (control.Checked.Value == UICheck.CheckValue.Indeterminate)
            {
                renderer.AddQuad(Multiply(rect, new Rectangle(0.3, 0.3, 0.7, 0.7)), checkColor * colorMultiplier);
            }

            //!!!!странно рисует чуть ниже, чем посередине
            //text
            renderer.AddText(" " + control.Text, new Vector2(rect.Right, rect.GetCenter().Y), EHorizontalAlignment.Left, EVerticalAlignment.Center, textColor * colorMultiplier);
            //renderer.AddText( " " + control.Text, new Vector2( rect.Right, rect.Top ), EHorizontalAlignment.Left, EVerticalAlignment.Top, textColor * colorMultiplier );
            //}
        }
Beispiel #16
0
        /////////////////////////////////////////

        public abstract void AddFillEllipse(RectangleF rectangle, int segments, ColorValue color, Component_Image texture, RectangleF textureCoordRectangle, bool textureClamp);
Beispiel #17
0
        protected virtual void OnRenderList(UIList control, CanvasRenderer renderer)
        {
            var rect = control.GetScreenRectangle();

            renderer.AddQuad(rect, new ColorValue(0, 0, 0));
            //renderer.AddQuad( rect, new ColorValue( 0.2, 0.2, 0.2 ) );

            var rect2 = rect;

            rect2.Expand(-control.GetScreenOffsetByValue(new UIMeasureValueVector2(UIMeasure.Units, 2, 2)));

            //border
            var color = new ColorValue(0.75, 0.75, 0.75);

            renderer.AddQuad(new Rectangle(rect.Left, rect.Top, rect2.Left, rect.Bottom), color);
            renderer.AddQuad(new Rectangle(rect2.Left, rect.Top, rect2.Right, rect2.Top), color);
            renderer.AddQuad(new Rectangle(rect2.Right, rect.Top, rect.Right, rect.Bottom), color);
            renderer.AddQuad(new Rectangle(rect.Left, rect2.Bottom, rect2.Right, rect.Bottom), color);

            var font = control.Font.Value;

            if (font == null)
            {
                font = renderer.DefaultFont;
            }
            var fontSize         = control.GetFontSizeScreen();
            var itemSize         = GetListItemSizeScreen(control, renderer);
            var totalItemsHeight = itemSize * control.Items.Count;
            var scrollBar        = control.GetScrollBar();

            //!!!!тут?
            //update scroll bar properties
            if (scrollBar != null)
            {
                double screenSizeY       = rect2.Size.Y;
                double scrollScreenSizeY = totalItemsHeight - screenSizeY;

                scrollBar.Visible = control.AlwaysShowScrollBar || totalItemsHeight > screenSizeY;
                if (scrollBar.Visible)
                {
                    scrollBar.ValueRange = new Range(0, scrollScreenSizeY);
                }

                //ensure visible
                if (listEnsureVisible != -1)
                {
                    if ((float)listEnsureVisible * itemSize > screenSizeY / 2)
                    {
                        var factor = (float)listEnsureVisible / (float)(control.Items.Count - 1);
                        var v      = scrollScreenSizeY * factor;
                        scrollBar.Value = MathEx.Clamp(v, 0, scrollBar.ValueRange.Value.Maximum);
                    }
                    else
                    {
                        scrollBar.Value = 0;
                    }

                    listEnsureVisible = -1;
                }

                //if( scrollBar.Visible )
                //{
                //	if( scrollScreenSizeY > 0 )
                //	{
                //		double currentScrollScreenPosY = scrollBar.Value * scrollScreenSizeY;

                //		double itemScrollScreenPosY = itemSize * (double)control.SelectedIndex;
                //		Range itemScrollScreenRangeY = new Range( itemScrollScreenPosY, itemScrollScreenPosY + itemSize );

                //		if( itemScrollScreenRangeY.Minimum < currentScrollScreenPosY )
                //		{
                //			currentScrollScreenPosY = itemScrollScreenRangeY.Minimum;
                //		}
                //		else
                //		{
                //			if( itemScrollScreenRangeY.Maximum > currentScrollScreenPosY + screenSizeY )
                //				currentScrollScreenPosY = itemScrollScreenRangeY.Maximum + itemSize - screenSizeY;
                //		}

                //		scrollBar.Value = currentScrollScreenPosY / scrollScreenSizeY;
                //	}
                //	else
                //		scrollBar.Value = 0;
                //}
                //else
                //	scrollBar.Value = 0;
            }

            //items
            if (control.Items.Count != 0)
            {
                renderer.PushClipRectangle(rect2);

                var positionY = rect2.Top;
                if (scrollBar != null && scrollBar.VisibleInHierarchy && scrollBar.EnabledInHierarchy)
                {
                    positionY -= scrollBar.Value;
                }

                for (int n = 0; n < control.Items.Count; n++)
                {
                    var item          = control.Items[n];
                    var itemRectangle = new Rectangle(rect2.Left, positionY, rect2.Right, positionY + itemSize);
                    if (scrollBar != null && scrollBar.EnabledInHierarchy && scrollBar.VisibleInHierarchy)
                    {
                        itemRectangle.Right -= scrollBar.GetScreenSize().X;
                    }

                    if (itemRectangle.Intersects(rect2))
                    {
                        renderer.PushClipRectangle(itemRectangle);

                        if (n == control.SelectedIndex)
                        {
                            var color2 = control.ReadOnlyInHierarchy ? new ColorValue(0.5, 0.5, 0.5) : new ColorValue(0, 0, 0.8);
                            renderer.AddQuad(itemRectangle, color2);
                        }

                        var positionX = rect2.Left + control.GetScreenOffsetByValue(new UIMeasureValueVector2(UIMeasure.Units, 2, 0)).X;
                        renderer.AddText(font, fontSize, item, new Vector2(positionX, itemRectangle.GetCenter().Y), EHorizontalAlignment.Left, EVerticalAlignment.Center, new ColorValue(1, 1, 1));

                        renderer.PopClipRectangle();
                    }

                    positionY += itemSize;
                }

                renderer.PopClipRectangle();
            }
        }
Beispiel #18
0
 public void AddFillEllipse(Rectangle rectangle, int segments, ColorValue color, Component_Image texture, Rectangle textureCoordRectangle, bool textureClamp)
 {
     AddFillEllipse(rectangle.ToRectangleF(), segments, color, texture, textureCoordRectangle.ToRectangleF(), textureClamp);
 }
Beispiel #19
0
        public void SetViewport(Viewport viewport, Matrix4F viewMatrix, Matrix4F projectionMatrix,
                                FrameBufferTypes clearBuffers, ColorValue clearBackgroundColor, float clearDepthValue = 1, byte clearStencilValue = 0)
        {
            currentViewport = viewport;
            currentViewNumber++;

            //init bgfx view

            Bgfx.ResetView(CurrentViewNumber);

            bool skip         = false;
            var  renderWindow = currentViewport.parent as RenderWindow;

            if (renderWindow != null && renderWindow.ThisIsApplicationWindow)
            {
                skip = true;
            }
            if (!skip)
            {
                Bgfx.SetViewFrameBuffer(CurrentViewNumber, currentViewport.parent.FrameBuffer);
            }

            Bgfx.SetViewMode(CurrentViewNumber, ViewMode.Sequential);
            Bgfx.SetViewRect(CurrentViewNumber, 0, 0, CurrentViewport.SizeInPixels.X, CurrentViewport.SizeInPixels.Y);
            unsafe
            {
                Bgfx.SetViewTransform(CurrentViewNumber, (float *)&viewMatrix, (float *)&projectionMatrix);
            }

            ////!!!!
            //if( clearBuffers == 0 )
            //{
            //	var target = viewport.Parent as RenderTexture;
            //	if( target != null )
            //	{
            //		if( !target.Creator._renderTargetCleared )
            //		{
            //			clearBuffers = FrameBufferTypes.Color;
            //			//clearBuffers = FrameBufferTypes.All;
            //		}
            //	}
            //}

            //clear
            if (clearBuffers != 0)
            {
                ClearTargets targets = 0;
                if ((clearBuffers & FrameBufferTypes.Color) != 0)
                {
                    targets |= ClearTargets.Color;
                }
                if ((clearBuffers & FrameBufferTypes.Depth) != 0)
                {
                    targets |= ClearTargets.Depth;
                }
                if ((clearBuffers & FrameBufferTypes.Stencil) != 0)
                {
                    targets |= ClearTargets.Stencil;
                }
                Bgfx.SetViewClear(CurrentViewNumber, targets, ToRGBA(clearBackgroundColor), clearDepthValue, clearStencilValue);

                Bgfx.Touch(CurrentViewNumber);
            }

            ////!!!!
            //if( clearBuffers != 0 )//if( clearBuffers == FrameBufferTypes.All )
            //{
            //	var target = viewport.Parent as RenderTexture;
            //	if( target != null )
            //		target.Creator._renderTargetCleared = true;
            //}

            //u_viewportSettings
            unsafe
            {
                var data = new ViewportSettingsUniform();
                data.size    = viewport.SizeInPixels.ToVector2F();
                data.sizeInv = new Vector2F(1, 1) / data.size;

                int vec4Count = sizeof(ViewportSettingsUniform) / sizeof(Vector4F);
                if (vec4Count != 1)
                {
                    Log.Fatal("Component_RenderingPipeline: Render: vec4Count != 1.");
                }
                SetUniform("u_viewportSettings", ParameterType.Vector4, vec4Count, &data);
            }
        }
Beispiel #20
0
 public void AddFillEllipse(Rectangle rectangle, int segments, ColorValue color)
 {
     AddFillEllipse(rectangle.ToRectangleF(), segments, color, null, RectangleF.Zero, false);
 }
Beispiel #21
0
        public abstract void SetColor(ColorValue colorVisible, ColorValue colorInvisibleBehindObjects); //, bool depthWrite = false );

        public void SetColor(ColorValue color, bool depthTest = true)                                   //, bool depthWrite = false )
        {
            //!!!!можно три режима ввести, чтобы когда не проверять, то за 1 раз рисовать. с другой стороны можно всегда 1 раз рисовать

            SetColor(color, depthTest ? new ColorValue(0, 0, 0, 0) : color);                //, depthWrite );
        }
Beispiel #22
0
            //!!!!можно его сделать развитым. в юнити normal, tangent, uv0, uv1
            //!!!!!еще про смешивание. хотя вероятно это надо обуздать что максимум можно извлечь из шейдеров. + еще всякие размытия

            //

            public TriangleVertex(Vector2F position, ColorValue color, Vector2F texCoord)
            {
                this.position = position;
                this.color    = color;
                this.texCoord = texCoord;
            }
Beispiel #23
0
        //!!!!для не прямоугольных нод видать не такие параметры
        public override void RenderReference(Component_FlowGraph_DocumentWindow window, Vector2 from, bool fromInput, Vector2 to, ColorValue color, out bool mouseOver)
        {
            var viewport = window.ViewportControl.Viewport;

            mouseOver = false;

            //!!!!
            if ((from - to).Length() < 0.5)
            //if( ( from - to ).Length() < 0.5 )
            {
                viewport.CanvasRenderer.AddLine(window.ConvertUnitToScreen(from), window.ConvertUnitToScreen(to), color /* colorMultiplier*/);
                mouseOver = false;
                return;
            }

            //!!!!!!если за пределами экрана, то не проверять. в других местах тоже.
            Vector2 mousePositionInUnits = window.ConvertScreenToUnit(viewport.MousePosition, true);

            double diff = to.X - from.X + 4;

            if (fromInput)
            {
                diff = -diff;
            }

            var sidePointsDistance = Math.Sqrt(Math.Abs(diff) * 2) * 1.3;

            if (sidePointsDistance > 15)
            {
                sidePointsDistance = 15;
            }
            if (sidePointsDistance < 3)
            {
                sidePointsDistance = 3;
            }

            if (fromInput)
            {
                if (from.X - to.X > 0 && from.X - to.X < 4)
                {
                    var d = 4 - (from.X - to.X);
                    if (d < 1)
                    {
                        d = 1;
                    }
                    sidePointsDistance /= d;
                }
            }
            else
            {
                if (to.X - from.X > 0 && to.X - from.X < 4)
                {
                    var d = 4 - (to.X - from.X);
                    if (d < 1)
                    {
                        d = 1;
                    }
                    sidePointsDistance /= d;
                }
            }

            //var realDiffAbs = Math.Abs( to.X - from.X );
            //if( realDiffAbs < 2 )
            //{
            //	sidePointsDistance /=
            //}

            //if( to.X - from.X > 0 && to.X - from.X < 3 )
            //{
            //	sidePointsDistance -= 3 - ( to.X - from.X );
            //	//sidePointsDistance = 4;
            //}

            //double sidePointsDistance;
            //if( diff > 0 )
            //{
            //	sidePointsDistance = Math.Sqrt( diff * 2 ) * 1.3;
            //	if( sidePointsDistance > 15 )
            //		sidePointsDistance = 15;
            //	if( sidePointsDistance < 4 )
            //		sidePointsDistance = 4;

            //	//sidePointsDistance = diff / 2;
            //	//if( diff < 4 )
            //	//	sidePointsDistance = diff;
            //	//sidePointsDistance = diff / 3;
            //	//if( sidePointsDistance < 4 )
            //	//	sidePointsDistance = 4;
            //}
            //else
            //{
            //	sidePointsDistance = Math.Sqrt( -diff * 2 ) * 1.3;
            //	if( sidePointsDistance > 15 )
            //		sidePointsDistance = 15;
            //	if( sidePointsDistance < 4 )
            //		sidePointsDistance = 4;
            //}

            if (fromInput)
            {
                sidePointsDistance = -sidePointsDistance;
            }

            //double sidePointsDistance = 5;
            //if( to.X < from.X )
            //	sidePointsDistance = ( from.X - to.X ) / 3;
            //if( sidePointsDistance < 5 )
            //	sidePointsDistance = 5;
            //if( to.X - from.X < 5 && to.X - from.X > 0 )
            //	sidePointsDistance = to.X - from.X;
            //if( to.X == from.X )
            //	sidePointsDistance = 2;
            //if( from.X - to.X == 1 )
            //	sidePointsDistance = 3;
            //if( from.X - to.X == 2 )
            //	sidePointsDistance = 4;
            //if( fromInput )
            //	sidePointsDistance = -sidePointsDistance;

            Vector2[] inputPoints = new Vector2[4];
            inputPoints[0] = from;
            inputPoints[1] = from + new Vector2(sidePointsDistance, 0);
            inputPoints[2] = to + new Vector2(-sidePointsDistance, 0);
            inputPoints[3] = to;

            double[] inputPointsDoubles = new double[inputPoints.Length * 2];
            for (int n = 0; n < inputPoints.Length; n++)
            {
                inputPointsDoubles[n * 2 + 0] = inputPoints[n].X;
                inputPointsDoubles[n * 2 + 1] = inputPoints[n].Y;
            }

            //!!!!!менять количество в зависимости от масштаба
            //!!!!!нелинейно менять количество. на загруглениях больше точек.
            //!!!!!или от растяжения количество точек
            //!!!!!или найти сплайну, которая сама считает нужное количество точек
            double pointsOnCurveD = 10 + Math.Abs(from.X - to.X) / 1.5 + Math.Abs(from.Y - to.Y) / 1.5;

            //int pointsOnCurve = 25;
            if (window.GetZoom() < .5f)
            {
                pointsOnCurveD /= 2;
            }
            if (window.GetZoom() < .25f)
            {
                pointsOnCurveD /= 2;
            }
            if (window.GetZoom() > 1)
            {
                pointsOnCurveD *= window.GetZoom();
            }
            var pointsOnCurve = (int)pointsOnCurveD;

            double[] outPointsDoubles = new double[pointsOnCurve * 2];
            BezierCurve2D.Bezier2D(inputPointsDoubles, pointsOnCurve, outPointsDoubles);

            Vector2[] outPoints = new Vector2[pointsOnCurve];
            for (int n = 0; n < pointsOnCurve; n++)
            {
                outPoints[n] = new Vector2((float)outPointsDoubles[n * 2 + 0], (float)outPointsDoubles[n * 2 + 1]);
            }

            var lines = new List <CanvasRenderer.LineItem>(outPoints.Length);

            Vector2 previousPos        = Vector2.Zero;
            Vector2 previousPosInUnits = Vector2.Zero;

            for (int n = 0; n < outPoints.Length; n++)
            {
                Vector2 positionInUnits = outPoints[n];

                if (n != 0 && !mouseOver)
                {
                    ////!!!!!или только за Title цеплять
                    //if( rect.IsContainsPoint( renderTargetUserControl1.GetFloatMousePosition() ) )
                    //   mouseOverObjects.Add( node );

                    const float minDistance = 0.3f;                    // 0.25f;
                    if (LineSegmentPointDistance(previousPosInUnits, positionInUnits, mousePositionInUnits) < minDistance)
                    {
                        mouseOver = true;
                    }
                }

                Vector2 pos = window.ConvertUnitToScreen(positionInUnits);
                if (n != 0)
                {
                    lines.Add(new CanvasRenderer.LineItem(previousPos.ToVector2F(), pos.ToVector2F(), color /* colorMultiplier*/));
                    //viewport.CanvasRenderer.AddLine( previousPos, pos, color /* colorMultiplier*/ );
                }
                previousPos        = pos;
                previousPosInUnits = positionInUnits;
            }

            viewport.CanvasRenderer.AddLines(lines);
        }
Beispiel #24
0
        /// <summary>
        /// Generates a packed data version of the passed in <see cref="NeoAxis.ColorValue"/>.
        /// </summary>
        /// <param name="color">The color to convert.</param>
        /// <returns>The uint value.</returns>
        ///// <remarks>
        ///// Since different render systems have different color data formats (eg
        ///// RGBA for GL, ARGB for D3D) this method allows you to use 1 method for all.
        ///// </remarks>
        public static uint ConvertColorValue(ref ColorValue color)
        {
            var packed = new ColorByte(ref color);

            return(packed.PackedValue);
        }
        void RenderBackRectangle(ViewportRenderingContext context, Rectangle rectangle, ColorValue color)
        {
            var renderer = context.Owner.CanvasRenderer;

            switch (BackStyle.Value)
            {
            case BackStyleEnum.Rectangle:
                renderer.AddQuad(rectangle, color);
                break;

            case BackStyleEnum.RoundedRectangle:
            {
                var rect2     = rectangle.ToRectangleF();
                var fontSize  = GetFontSizeScreen(context);
                var roundSize = new Vector2F(renderer.AspectRatioInv, 1) * (float)fontSize * 0.4f;

                int steps = 16;

                var list = new List <Vector2F>(steps * 4);

                for (int n = 0; n < steps; n++)
                {
                    var v     = (float)n / (float)(steps - 1);
                    var angle = v * MathEx.PI / 2;
                    list.Add(rect2.LeftTop + new Vector2F(1.0f - MathEx.Cos(angle), 1.0f - MathEx.Sin(angle)) * roundSize);
                }

                for (int n = steps - 1; n >= 0; n--)
                {
                    var v     = (float)n / (float)(steps - 1);
                    var angle = v * MathEx.PI / 2;
                    list.Add(rect2.RightTop + new Vector2F(MathEx.Cos(angle) - 1.0f, 1.0f - MathEx.Sin(angle)) * roundSize);
                }

                for (int n = 0; n < steps; n++)
                {
                    var v     = (float)n / (float)(steps - 1);
                    var angle = v * MathEx.PI / 2;
                    list.Add(rect2.RightBottom + new Vector2F(MathEx.Cos(angle) - 1.0f, MathEx.Sin(angle) - 1.0f) * roundSize);
                }

                for (int n = steps - 1; n >= 0; n--)
                {
                    var v     = (float)n / (float)(steps - 1);
                    var angle = v * MathEx.PI / 2;
                    list.Add(rect2.LeftBottom + new Vector2F(1.0f - MathEx.Cos(angle), MathEx.Sin(angle) - 1.0f) * roundSize);
                }

                var vertices = new List <CanvasRenderer.TriangleVertex>(1 + list.Count);
                var indices  = new List <int>(list.Count * 3);

                vertices.Add(new CanvasRenderer.TriangleVertex(rect2.GetCenter(), color));
                foreach (var v in list)
                {
                    vertices.Add(new CanvasRenderer.TriangleVertex(v, color));
                }

                for (int n = 0; n < list.Count; n++)
                {
                    indices.Add(0);
                    indices.Add(1 + n);
                    indices.Add(1 + (n + 1) % list.Count);
                }

                renderer.AddTriangles(vertices, indices);
            }
            break;
            }
        }
Beispiel #26
0
 /// <summary>
 /// Generates a packed data version of the passed in <see cref="NeoAxis.ColorValue"/> suitable for use as with this RenderSystem.
 /// </summary>
 /// <param name="color">The color to convert.</param>
 /// <returns>The uint value.</returns>
 ///// <remarks>
 ///// Since different render systems have different color data formats (eg
 ///// RGBA for GL, ARGB for D3D) this method allows you to use 1 method for all.
 ///// </remarks>
 public static uint ConvertColorValue(ColorValue color)
 {
     return(ConvertColorValue(ref color));
 }
Beispiel #27
0
        //

        static SimpleTypes()
        {
            //string
            RegisterType(typeof(string), delegate(string value)
            {
                if (value == null)
                {
                    return("");
                    //throw new Exception( "GetSimpleTypeValue: string type, value = null" );
                }
                return(value);
            }, "");

            //bool
            RegisterType(typeof(bool), delegate(string value)
            {
                string lower = value.ToLower();
                if (value == "1" || lower == "yes" || lower == "true")
                {
                    return(true);
                }
                else if (value == "0" || lower == "no" || lower == "false")
                {
                    return(false);
                }
                else
                {
                    return(bool.Parse(value));
                }
            }, false);

            //sbyte
            RegisterType(typeof(sbyte), delegate(string value) { return(sbyte.Parse(value)); }, 0);

            //byte
            RegisterType(typeof(byte), delegate(string value) { return(byte.Parse(value)); }, 0);

            //char
            RegisterType(typeof(char), delegate(string value) { return(char.Parse(value)); }, 0);

            //short
            RegisterType(typeof(short), delegate(string value) { return(short.Parse(value)); }, 0);

            //ushort
            RegisterType(typeof(ushort), delegate(string value) { return(ushort.Parse(value)); }, 0);

            //int
            RegisterType(typeof(int), delegate(string value) { return(int.Parse(value)); }, 0);

            //uint
            RegisterType(typeof(uint), delegate(string value) { return(uint.Parse(value)); }, (uint)0);

            //long
            RegisterType(typeof(long), delegate(string value) { return(long.Parse(value)); }, (long)0);

            //ulong
            RegisterType(typeof(ulong), delegate(string value) { return(ulong.Parse(value)); }, (ulong)0);

            //float
            RegisterType(typeof(float), delegate(string value) { return(float.Parse(value)); }, 0.0f);

            //double
            RegisterType(typeof(double), delegate(string value) { return(double.Parse(value)); }, 0.0);

            //decimal
            RegisterType(typeof(decimal), delegate(string value) { return(decimal.Parse(value)); }, (decimal)0.0);

            //Vec2
            RegisterType(typeof(Vector2F), delegate(string value) { return(Vector2F.Parse(value)); }, Vector2F.Zero);

            //Range
            RegisterType(typeof(RangeF), delegate(string value) { return(RangeF.Parse(value)); }, RangeF.Zero);

            //Vec3
            RegisterType(typeof(Vector3F), delegate(string value) { return(Vector3F.Parse(value)); }, Vector3F.Zero);

            //Vec4
            RegisterType(typeof(Vector4F), delegate(string value) { return(Vector4F.Parse(value)); }, Vector4F.Zero);

            //Bounds
            RegisterType(typeof(BoundsF), delegate(string value) { return(BoundsF.Parse(value)); }, BoundsF.Zero);

            //Quat
            RegisterType(typeof(QuaternionF), delegate(string value) { return(QuaternionF.Parse(value)); }, QuaternionF.Identity);

            //ColorValue
            RegisterType(typeof(ColorValue), delegate(string value) { return(ColorValue.Parse(value)); }, ColorValue.Zero);

            //ColorValuePowered
            RegisterType(typeof(ColorValuePowered), delegate(string value) { return(ColorValuePowered.Parse(value)); }, ColorValuePowered.Zero);

            //ColorPacked
            RegisterType(typeof(ColorByte), delegate(string value) { return(ColorByte.Parse(value)); }, ColorByte.Zero);

            //SphereDir
            RegisterType(typeof(SphericalDirectionF), delegate(string value) { return(SphericalDirectionF.Parse(value)); }, SphericalDirectionF.Zero);

            //Vec2I
            RegisterType(typeof(Vector2I), delegate(string value) { return(Vector2I.Parse(value)); }, Vector2I.Zero);

            //Vec3I
            RegisterType(typeof(Vector3I), delegate(string value) { return(Vector3I.Parse(value)); }, Vector3I.Zero);

            //Vec4I
            RegisterType(typeof(Vector4I), delegate(string value) { return(Vector4I.Parse(value)); }, Vector4I.Zero);

            //Rect
            RegisterType(typeof(RectangleF), delegate(string value) { return(RectangleF.Parse(value)); }, RectangleF.Zero);

            //RectI
            RegisterType(typeof(RectangleI), delegate(string value) { return(RectangleI.Parse(value)); }, RectangleI.Zero);

            //Degree
            RegisterType(typeof(DegreeF), delegate(string value) { return(DegreeF.Parse(value)); }, DegreeF.Zero);

            //Radian
            RegisterType(typeof(RadianF), delegate(string value) { return(RadianF.Parse(value)); }, RadianF.Zero);

            //Vec2D
            RegisterType(typeof(Vector2), delegate(string value) { return(Vector2.Parse(value)); }, Vector2.Zero);

            //RangeD
            RegisterType(typeof(Range), delegate(string value) { return(Range.Parse(value)); }, Range.Zero);

            //RangeI
            RegisterType(typeof(RangeI), delegate(string value) { return(RangeI.Parse(value)); }, RangeI.Zero);

            //Vec3D
            RegisterType(typeof(Vector3), delegate(string value) { return(Vector3.Parse(value)); }, Vector3.Zero);

            //Vec4D
            RegisterType(typeof(Vector4), delegate(string value) { return(Vector4.Parse(value)); }, Vector4.Zero);

            //BoundsD
            RegisterType(typeof(Bounds), delegate(string value) { return(Bounds.Parse(value)); }, Bounds.Zero);

            //QuatD
            RegisterType(typeof(Quaternion), delegate(string value) { return(Quaternion.Parse(value)); }, Quaternion.Identity);

            //SphereDirD
            RegisterType(typeof(SphericalDirection), delegate(string value) { return(SphericalDirection.Parse(value)); }, SphericalDirection.Zero);

            //RectD
            RegisterType(typeof(Rectangle), delegate(string value) { return(Rectangle.Parse(value)); }, Rectangle.Zero);

            //DegreeD
            RegisterType(typeof(Degree), delegate(string value) { return(Degree.Parse(value)); }, Degree.Zero);

            //RadianD
            RegisterType(typeof(Radian), delegate(string value) { return(Radian.Parse(value)); }, Radian.Zero);

            //Angles
            RegisterType(typeof(AnglesF), delegate(string value) { return(AnglesF.Parse(value)); }, AnglesF.Zero);

            //AnglesD
            RegisterType(typeof(Angles), delegate(string value) { return(Angles.Parse(value)); }, Angles.Zero);

            //Mat2F
            RegisterType(typeof(Matrix2F), delegate(string value) { return(Matrix2F.Parse(value)); }, Matrix2F.Zero);

            //Mat2D
            RegisterType(typeof(Matrix2), delegate(string value) { return(Matrix2.Parse(value)); }, Matrix2.Zero);

            //Mat3F
            RegisterType(typeof(Matrix3F), delegate(string value) { return(Matrix3F.Parse(value)); }, Matrix3F.Zero);

            //Mat3D
            RegisterType(typeof(Matrix3), delegate(string value) { return(Matrix3.Parse(value)); }, Matrix3.Zero);

            //Mat4F
            RegisterType(typeof(Matrix4F), delegate(string value) { return(Matrix4F.Parse(value)); }, Matrix4F.Zero);

            //Mat4D
            RegisterType(typeof(Matrix4), delegate(string value) { return(Matrix4.Parse(value)); }, Matrix4.Zero);

            //PlaneF
            RegisterType(typeof(PlaneF), delegate(string value) { return(PlaneF.Parse(value)); }, PlaneF.Zero);

            //PlaneD
            RegisterType(typeof(Plane), delegate(string value) { return(Plane.Parse(value)); }, Plane.Zero);

            //Transform
            RegisterType(typeof(Transform), delegate(string value) { return(Transform.Parse(value)); }, Transform.Identity);

            //UIMeasureValueDouble
            RegisterType(typeof(UIMeasureValueDouble), delegate(string value) { return(UIMeasureValueDouble.Parse(value)); }, new UIMeasureValueDouble());

            //UIMeasureValueVec2
            RegisterType(typeof(UIMeasureValueVector2), delegate(string value) { return(UIMeasureValueVector2.Parse(value)); }, new UIMeasureValueVector2());

            //UIMeasureValueRect
            RegisterType(typeof(UIMeasureValueRectangle), delegate(string value) { return(UIMeasureValueRectangle.Parse(value)); }, new UIMeasureValueRectangle());

            RegisterType(typeof(RangeVector3F), delegate(string value) { return(RangeVector3F.Parse(value)); }, RangeVector3F.Zero);
            RegisterType(typeof(RangeColorValue), delegate(string value) { return(RangeColorValue.Parse(value)); }, RangeColorValue.Zero);

            //no Parse methods. This is complex structures. This is not simple types? or just can't parse?
            //Box
            //Capsule
            //Cone
            //Line3
            //Line2
            //Ray
            //Frustum?

            RegisterConvertDoubleToFloatTypes();
        }
Beispiel #28
0
        public override void NewObjectSetDefaultConfiguration(bool createdFromNewObjectWindow = false)
        {
            if (Components.Count == 0)
            {
                Color = new ColorValue(0.6784314, 0.6784314, 0.6784314);

                //Mesh
                {
                    var mesh = CreateComponent <Component_Mesh>();
                    mesh.Name = "Mesh";
                    Mesh      = ReferenceUtility.MakeThisReference(this, mesh);

                    var geometry = mesh.CreateComponent <Component_MeshGeometry_Box>();
                    geometry.Name       = "Mesh Geometry";
                    geometry.Dimensions = new Vector3(0.05, 0.3, 0.3);
                    geometry.Material   = ReferenceUtility.MakeReference("Base\\Materials\\White.material");
                }

                //Button
                {
                    var meshInSpace = CreateComponent <Component_MeshInSpace>();
                    meshInSpace.Name = "Button";

                    var mesh = meshInSpace.CreateComponent <Component_Mesh>();
                    mesh.Name        = "Mesh";
                    meshInSpace.Mesh = ReferenceUtility.MakeThisReference(this, mesh);

                    var geometry = mesh.CreateComponent <Component_MeshGeometry_Cylinder>();
                    geometry.Name     = "Mesh Geometry";
                    geometry.Axis     = 0;
                    geometry.Radius   = 0.08;
                    geometry.Height   = 0.08;
                    geometry.Material = ReferenceUtility.MakeReference("Base\\Materials\\White.material");

                    meshInSpace.Mesh = ReferenceUtility.MakeThisReference(meshInSpace, mesh);

                    var transformOffset = meshInSpace.CreateComponent <Component_TransformOffset>();
                    transformOffset.Name           = "Attach Transform Offset";
                    transformOffset.PositionOffset = new Vector3(0.05, 0, 0);
                    transformOffset.Source         = ReferenceUtility.MakeThisReference(transformOffset, this, "Transform");

                    meshInSpace.Transform = ReferenceUtility.MakeThisReference(meshInSpace, transformOffset, "Result");
                }

                //Indicator Min
                {
                    var meshInSpace = CreateComponent <Component_MeshInSpace>();
                    meshInSpace.Name  = "Indicator Min";
                    meshInSpace.Color = new ColorValue(1, 0, 0);

                    var mesh = meshInSpace.CreateComponent <Component_Mesh>();
                    mesh.Name        = "Mesh";
                    meshInSpace.Mesh = ReferenceUtility.MakeThisReference(this, mesh);

                    var geometry = mesh.CreateComponent <Component_MeshGeometry_Cylinder>();
                    geometry.Name     = "Mesh Geometry";
                    geometry.Axis     = 0;
                    geometry.Radius   = 0.02;
                    geometry.Height   = 0.02;
                    geometry.Segments = 16;
                    geometry.Material = ReferenceUtility.MakeReference("Base\\Materials\\White.material");

                    meshInSpace.Mesh = ReferenceUtility.MakeThisReference(meshInSpace, mesh);

                    var transformOffset = meshInSpace.CreateComponent <Component_TransformOffset>();
                    transformOffset.Name           = "Attach Transform Offset";
                    transformOffset.PositionOffset = new Vector3(0.03, -0.11, 0.11);
                    transformOffset.Source         = ReferenceUtility.MakeThisReference(transformOffset, this, "Transform");

                    meshInSpace.Transform = ReferenceUtility.MakeThisReference(meshInSpace, transformOffset, "Result");
                }

                //Indicator Max
                {
                    var meshInSpace = CreateComponent <Component_MeshInSpace>();
                    meshInSpace.Name  = "Indicator Max";
                    meshInSpace.Color = new ColorValue(0, 1, 0);

                    var mesh = meshInSpace.CreateComponent <Component_Mesh>();
                    mesh.Name        = "Mesh";
                    meshInSpace.Mesh = ReferenceUtility.MakeThisReference(this, mesh);

                    var geometry = mesh.CreateComponent <Component_MeshGeometry_Cylinder>();
                    geometry.Name     = "Mesh Geometry";
                    geometry.Axis     = 0;
                    geometry.Radius   = 0.02;
                    geometry.Height   = 0.02;
                    geometry.Segments = 16;
                    geometry.Material = ReferenceUtility.MakeReference("Base\\Materials\\White.material");

                    meshInSpace.Mesh = ReferenceUtility.MakeThisReference(meshInSpace, mesh);

                    var transformOffset = meshInSpace.CreateComponent <Component_TransformOffset>();
                    transformOffset.Name           = "Attach Transform Offset";
                    transformOffset.PositionOffset = new Vector3(0.03, 0.11, 0.11);
                    transformOffset.Source         = ReferenceUtility.MakeThisReference(transformOffset, this, "Transform");

                    meshInSpace.Transform = ReferenceUtility.MakeThisReference(meshInSpace, transformOffset, "Result");
                }

                //Marker Min
                {
                    var meshInSpace = CreateComponent <Component_MeshInSpace>();
                    meshInSpace.Name  = "Marker Min";
                    meshInSpace.Color = new ColorValue(1, 0, 0);

                    var mesh = meshInSpace.CreateComponent <Component_Mesh>();
                    mesh.Name        = "Mesh";
                    meshInSpace.Mesh = ReferenceUtility.MakeThisReference(this, mesh);

                    var geometry = mesh.CreateComponent <Component_MeshGeometry_Box>();
                    geometry.Name       = "Mesh Geometry";
                    geometry.Dimensions = new Vector3(0.05, 0.14, 0.01);
                    geometry.Material   = ReferenceUtility.MakeReference("Base\\Materials\\White.material");

                    meshInSpace.Mesh = ReferenceUtility.MakeThisReference(meshInSpace, mesh);

                    var transformOffset = meshInSpace.CreateComponent <Component_TransformOffset>();
                    transformOffset.Name           = "Attach Transform Offset";
                    transformOffset.PositionOffset = new Vector3(0.01, 0, 0);
                    transformOffset.Source         = ReferenceUtility.MakeThisReference(transformOffset, this, "Transform");

                    meshInSpace.Transform = ReferenceUtility.MakeThisReference(meshInSpace, transformOffset, "Result");
                }

                //Marker Max
                {
                    var meshInSpace = CreateComponent <Component_MeshInSpace>();
                    meshInSpace.Name  = "Marker Max";
                    meshInSpace.Color = new ColorValue(0, 1, 0);

                    var mesh = meshInSpace.CreateComponent <Component_Mesh>();
                    mesh.Name        = "Mesh";
                    meshInSpace.Mesh = ReferenceUtility.MakeThisReference(this, mesh);

                    var geometry = mesh.CreateComponent <Component_MeshGeometry_Box>();
                    geometry.Name       = "Mesh Geometry";
                    geometry.Dimensions = new Vector3(0.05, 0.14, 0.01);
                    geometry.Material   = ReferenceUtility.MakeReference("Base\\Materials\\White.material");

                    meshInSpace.Mesh = ReferenceUtility.MakeThisReference(meshInSpace, mesh);

                    var transformOffset = meshInSpace.CreateComponent <Component_TransformOffset>();
                    transformOffset.Name           = "Attach Transform Offset";
                    transformOffset.PositionOffset = new Vector3(0.01, 0, 0);
                    transformOffset.Source         = ReferenceUtility.MakeThisReference(transformOffset, this, "Transform");

                    meshInSpace.Transform = ReferenceUtility.MakeThisReference(meshInSpace, transformOffset, "Result");
                }

                //Marker Current
                {
                    var meshInSpace = CreateComponent <Component_MeshInSpace>();
                    meshInSpace.Name  = "Marker Current";
                    meshInSpace.Color = new ColorValue(1, 1, 1);

                    var mesh = meshInSpace.CreateComponent <Component_Mesh>();
                    mesh.Name        = "Mesh";
                    meshInSpace.Mesh = ReferenceUtility.MakeThisReference(this, mesh);

                    var geometry = mesh.CreateComponent <Component_MeshGeometry_Box>();
                    geometry.Name       = "Mesh Geometry";
                    geometry.Dimensions = new Vector3(0.05, 0.14, 0.01);
                    geometry.Material   = ReferenceUtility.MakeReference("Base\\Materials\\White.material");

                    meshInSpace.Mesh = ReferenceUtility.MakeThisReference(meshInSpace, mesh);

                    var transformOffset = meshInSpace.CreateComponent <Component_TransformOffset>();
                    transformOffset.Name           = "Attach Transform Offset";
                    transformOffset.PositionOffset = new Vector3(0.06, 0, 0);
                    transformOffset.Source         = ReferenceUtility.MakeThisReference(transformOffset, this, "Transform");

                    meshInSpace.Transform = ReferenceUtility.MakeThisReference(meshInSpace, transformOffset, "Result");
                }

                //C# Script
                {
                    var script = CreateComponent <Component_CSharpScript>();
                    script.Name = "C# Script";
                    script.Code = "public void InteractiveObjectButton_UpdateEvent(NeoAxis.Component sender, float delta)\r\n{\r\n\tvar _this = sender as Component_RegulatorSwitchInSpace;\r\n\tif (_this != null)\r\n\t{\r\n\t\tvar indicatorMin = _this.GetComponent(\"Indicator Min\") as Component_MeshInSpace;\r\n\t\tif (indicatorMin != null)\r\n\t\t\tindicatorMin.Color = _this.Value.Value <= _this.ValueRange.Value.Minimum ? new ColorValue(1, 0, 0) : new ColorValue(0.5, 0.5, 0.5);\r\n\r\n\t\tvar indicatorMax = _this.GetComponent(\"Indicator Max\") as Component_MeshInSpace;\r\n\t\tif (indicatorMax != null)\r\n\t\t\tindicatorMax.Color = _this.Value.Value >= _this.ValueRange.Value.Maximum ? new ColorValue(0, 1, 0) : new ColorValue(0.5, 0.5, 0.5);\r\n\r\n\t\tvar button = _this.GetComponent(\"Button\");\r\n\t\tif (button != null)\r\n\t\t{\r\n\t\t\tvar offset = button.GetComponent<Component_TransformOffset>();\r\n\t\t\tif (offset != null)\r\n\t\t\t{\r\n\t\t\t\tvar angle = _this.GetValueAngle() - 90;\r\n\t\t\t\toffset.RotationOffset = new Angles(angle, 0, 0).ToQuaternion();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvar markerMin = _this.GetComponent(\"Marker Min\");\r\n\t\tif (markerMin != null)\r\n\t\t{\r\n\t\t\tvar offset = markerMin.GetComponent<Component_TransformOffset>();\r\n\t\t\tif (offset != null)\r\n\t\t\t{\r\n\t\t\t\tvar angle = _this.AngleRange.Value.Minimum - 90;\r\n\t\t\t\tvar angleR = MathEx.DegreeToRadian(angle);\r\n\t\t\t\toffset.PositionOffset = new Vector3(0.01, Math.Cos(angleR) * 0.04, Math.Sin(-angleR) * 0.04);\r\n\t\t\t\toffset.RotationOffset = new Angles(angle, 0, 0).ToQuaternion();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvar markerMax = _this.GetComponent(\"Marker Max\");\r\n\t\tif (markerMax != null)\r\n\t\t{\r\n\t\t\tvar offset = markerMax.GetComponent<Component_TransformOffset>();\r\n\t\t\tif (offset != null)\r\n\t\t\t{\r\n\t\t\t\tvar angle = _this.AngleRange.Value.Maximum - 90;\r\n\t\t\t\tvar angleR = MathEx.DegreeToRadian(angle);\r\n\t\t\t\toffset.PositionOffset = new Vector3(0.01, Math.Cos(angleR) * 0.04, Math.Sin(-angleR) * 0.04);\r\n\t\t\t\toffset.RotationOffset = new Angles(angle, 0, 0).ToQuaternion();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvar markerCurrent = _this.GetComponent(\"Marker Current\");\r\n\t\tif (markerCurrent != null)\r\n\t\t{\r\n\t\t\tvar offset = markerCurrent.GetComponent<Component_TransformOffset>();\r\n\t\t\tif (offset != null)\r\n\t\t\t{\r\n\t\t\t\tvar angle = _this.GetValueAngle() - 90;\r\n\t\t\t\tvar angleR = MathEx.DegreeToRadian(angle);\r\n\t\t\t\toffset.PositionOffset = new Vector3(0.06, Math.Cos(angleR) * 0.04, Math.Sin(-angleR) * 0.04);\r\n\t\t\t\toffset.RotationOffset = new Angles(angle, 0, 0).ToQuaternion();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}";

                    var handler = script.CreateComponent <Component_EventHandler>();
                    handler.Name          = "Event Handler UpdateEvent";
                    handler.WhenEnable    = Component_EventHandler.WhenEnableEnum.Editor | Component_EventHandler.WhenEnableEnum.Simulation | Component_EventHandler.WhenEnableEnum.Instance;
                    handler.Event         = ReferenceUtility.MakeReference("this:..\\..\\event:UpdateEvent");
                    handler.HandlerMethod = ReferenceUtility.MakeReference("this:..\\method:InteractiveObjectButton_UpdateEvent(NeoAxis.Component,System.Single)");
                }
            }
        }
Beispiel #29
0
        protected override void OnRenderUI(CanvasRenderer renderer)
        {
            base.OnRenderUI(renderer);

            Vector2I size = GetNeededSize();

            if (browser == null)
            {
                CreateBrowser();
            }

            //update brower engine and texture
            if (browser != null)
            {
                if (viewSize != size /*&& !browser.IsResizing */)
                {
                    var oldSize = viewSize;
                    viewSize = size;
                    OnResized(oldSize, viewSize);
                }

                //create texture
                if (texture == null || textureSize != size || needRecreateTexture)
                {
                    if (texture != null)
                    {
                        texture.Dispose();
                        texture = null;
                    }

                    textureSize = size;

                    bool mipmaps = false;
                    //!!!!
                    //if( ControlManager != null && ControlManager is UI3DControlContainer )
                    //	mipmaps = renderingIn3DMipmaps;

                    var usage = Component_Image.Usages.WriteOnly;
                    if (mipmaps)
                    {
                        usage |= Component_Image.Usages.AutoMipmaps;
                    }

                    texture               = ComponentUtility.CreateComponent <Component_Image>(null, true, false);
                    texture.CreateType    = Component_Image.TypeEnum._2D;
                    texture.CreateSize    = textureSize;
                    texture.CreateMipmaps = mipmaps;                    // ? -1 : 0;
                    texture.CreateFormat  = PixelFormat.A8R8G8B8;
                    texture.CreateUsage   = usage;
                    texture.Enabled       = true;

                    //Log.Info( textureSize.ToString() );

                    //if( mipmaps )
                    //{
                    //	texture = TextureManager.Instance.Create( textureName, Texture.Type.Type2D, textureSize,
                    //		1, -1, PixelFormat.A8R8G8B8, Texture.Usage.DynamicWriteOnlyDiscardable | Texture.Usage.AutoMipmap );
                    //}
                    //else
                    //{
                    //	texture = TextureManager.Instance.Create( textureName, Texture.Type.Type2D, textureSize,
                    //		1, 0, PixelFormat.A8R8G8B8, Texture.Usage.DynamicWriteOnlyDiscardable );
                    //}

                    needUpdateTexture   = true;
                    needRecreateTexture = false;
                }

                if (needInvalidate)
                {
                    browserHost.SetZoomLevel(Zoom);
                    browserHost.Invalidate(new CefRectangle(0, 0, 100000, 100000), CefPaintElementType.View);
                    needInvalidate = false;
                }

                //update texture
                if (/*browser.IsDirty ||*/ needUpdateTexture)
                {
                    if (texture != null)
                    {
                        UpdateTexture();
                    }
                    needUpdateTexture = false;
                }
            }

            //draw texture
            {
                //bool backColorZero = BackColor == new ColorValue( 0, 0, 0, 0 );

                //ColorValue color = new ColorValue( 1, 1, 1 );
                ////ColorValue color = backColorZero ? new ColorValue( 1, 1, 1 ) : BackColor;
                //if( texture == null )
                //	color = new ColorValue( 0, 0, 0, color.Alpha );
                //color *= GetTotalColorMultiplier();

                //var color = GetTotalColorMultiplier();
                //if( color.Alpha > 0 )
                //{
                var color = new ColorValue(1, 1, 1);
                //color.Saturate();

                GetScreenRectangle(out var rect);

                Component_Image tex = null;
                if (renderBuffer != null && renderBufferForSize == ViewSize && renderBuffer.Length == ViewSize.X * ViewSize.Y * 4)
                {
                    tex = texture;
                }
                if (tex == null)
                {
                    tex = ResourceUtility.WhiteTexture2D;
                }

                if (renderer.IsScreen)                 //&& !renderer._OutGeometryTransformEnabled )
                {
                    ////screen per pixel accuracy

                    Vector2   viewportSize = renderer.ViewportForScreenCanvasRenderer.SizeInPixels.ToVector2F();
                    var       v            = size.ToVector2() / viewportSize;
                    Rectangle fixedRect    = new Rectangle(rect.LeftTop, rect.LeftTop + v);

                    //Vec2 leftTop = rect.LeftTop;
                    //leftTop *= viewportSize;
                    //leftTop = new Vec2( (int)( leftTop.X + .9999f ), (int)( leftTop.Y + .9999f ) );
                    ////!!!!!
                    ////if( RenderSystem.Instance.IsDirect3D() )
                    ////	leftTop -= new Vec2( .5f, .5f );
                    //leftTop /= viewportSize;

                    //Vec2 rightBottom = rect.RightBottom;
                    //rightBottom *= viewportSize;
                    //rightBottom = new Vec2( (int)( rightBottom.X + .9999f ), (int)( rightBottom.Y + .9999f ) );
                    ////!!!!!
                    ////if( RenderSystem.Instance.IsDirect3D() )
                    ////	rightBottom -= new Vec2( .5f, .5f );
                    //rightBottom /= viewportSize;

                    //Rect fixedRect = new Rect( leftTop, rightBottom );

                    renderer.PushTextureFilteringMode(CanvasRenderer.TextureFilteringMode.Point);
                    renderer.AddQuad(fixedRect, new Rectangle(0, 0, 1, 1), tex, color, true);
                    renderer.PopTextureFilteringMode();
                }
                else
                {
                    renderer.AddQuad(rect, new Rectangle(0, 0, 1, 1), tex, color, true);
                }
                //}
            }

            if (!IsSupportedByThisPlatform())
            {
                var text   = string.Format("UIWebBrowser: {0} is not supported.", SystemSettings.CurrentPlatform);
                var center = GetScreenRectangle().GetCenter();
                renderer.AddText(text, center, EHorizontalAlignment.Center, EVerticalAlignment.Center, new ColorValue(1, 0, 0));
            }
        }
Beispiel #30
0
        /////////////////////////////////////////

        /// <summary>
        /// Adds text lines to rendering queue.
        /// </summary>
        /// <param name="font">The font.</param>
        /// <param name="lines">The text lines.</param>
        /// <param name="pos">The text position.</param>
        /// <param name="horizontalAlign">The text horizontal align.</param>
        /// <param name="verticalAlign">The text vertical align.</param>
        /// <param name="textVerticalIndention">The vertical intention between lines.</param>
        /// <param name="color">The text color.</param>
        public abstract void AddTextLines(Component_Font font, double fontSize, IList <string> lines, Vector2F pos, EHorizontalAlignment horizontalAlign,
                                          EVerticalAlignment verticalAlign, float textVerticalIndention, ColorValue color, AddTextOptions options = AddTextOptions.PixelAlign);