Exemplo n.º 1
0
        public void DoRenderUI()
        {
            GuiRenderer renderer = EngineApp.Instance.ScreenGuiRenderer;

            if (transparency == 0.0f)
            {
                return;
            }

            //load backgrouund texture and font
            if (texture != null && texture.IsDisposed())
            {
                needLoadTextureAndFont = true;
            }
            if (needLoadTextureAndFont)
            {
                texture = TextureManager.Instance.Load("GUI\\Textures\\Console.png", Texture.Type.Type2D, 0);
                font    = FontManager.Instance.LoadFont("Default", .025f);
                needLoadTextureAndFont = false;
            }

            if (font == null)
            {
                return;
            }

            Vec2 viewportSize = renderer.ViewportForScreenGuiRenderer.DimensionsInPixels.Size.ToVec2();
            Vec2 shadowOffset = new Vec2(1, 1) / viewportSize;

            //draw background
            Rect textureRect = new Rect(0, 0, 10 * renderer.AspectRatio, 10 / 2);

            textureRect -= textureOffset;
            renderer.AddQuad(new Rect(0, 0, 1, .5f), textureRect, texture, new ColorValue(1, 1, 1, transparency), false);

            //draw border line
            renderer.AddQuad(new Rect(0, .5f, 1, .508f), new ColorValue(0.29f, 0.6f, 0.86f, 0.9f * transparency));

            //draw background info
            string staticText = string.Format(
                "NeoAxis 3D Engine {0}\r\nPress \"~\" to hide console\r\nPress \"Ctrl + ~\" to hide and disable auto opening",
                EngineVersionInformation.Version);

            renderer.AddTextWordWrap(staticText, new Rect(0, 0, .995f, .495f), HorizontalAlign.Right, false, VerticalAlign.Bottom, 0,
                                     new ColorValue(.5f, .5f, .6f, transparency));

            float fontheight = font.Height;

            float x = .01f;

            float y = .5f - fontheight;

            string str;

            if (stringDownPosition != strings.Count - 1)
            {
                str = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -";
            }
            else
            {
                str = currentString + "_";
            }

            renderer.PushClipRectangle(new Rect(0, 0, .975f, 1));
            renderer.AddText(font, str, new Vec2(x, y) + shadowOffset, HorizontalAlign.Left,
                             VerticalAlign.Center, new ColorValue(0, 0, 0, transparency / 2));
            renderer.AddText(font, str, new Vec2(x, y), HorizontalAlign.Left,
                             VerticalAlign.Center, new ColorValue(1, 1, 1, transparency));
            renderer.PopClipRectangle();

            y -= fontheight + fontheight * .5f;

            int startpos = stringDownPosition;

            if (startpos > strings.Count - 1)
            {
                startpos = strings.Count - 1;
            }
            for (int n = startpos; n >= 0 && y - fontheight > 0; n--)
            {
                renderer.AddText(font, strings[n].text, new Vec2(x, y) + shadowOffset, HorizontalAlign.Left,
                                 VerticalAlign.Center, strings[n].color * new ColorValue(0, 0, 0, transparency / 2));
                renderer.AddText(font, strings[n].text, new Vec2(x, y), HorizontalAlign.Left,
                                 VerticalAlign.Center, strings[n].color * new ColorValue(1, 1, 1, transparency));
                y -= fontheight;
            }
        }
Exemplo n.º 2
0
        void DrawArea_RenderUI( Control sender, GuiRenderer renderer )
        {
            Rect rectangle = sender.GetScreenRectangle();
            bool clipRectangle = true;
            ColorValue[] colors = new ColorValue[]{
                new ColorValue( 1 ,0, 0 ),
                new ColorValue( 0, 1, 0 ),
                new ColorValue( 0, 0, 1 ),
                new ColorValue( 1, 1, 0 ),
                new ColorValue( 1, 1, 1 )};

            if( clipRectangle )
                renderer.PushClipRectangle( rectangle );

            //draw triangles
            if( GetDrawAreaMode() == DrawAreaModes.Triangles )
            {
                float distance = rectangle.GetSize().X / 2;

                List<GuiRenderer.TriangleVertex> triangles = new List<GuiRenderer.TriangleVertex>( 256 );

                Radian angle = -EngineApp.Instance.Time;

                const int steps = 30;
                Vec2 lastPosition = Vec2.Zero;
                for( int step = 0; step < steps + 1; step++ )
                {
                    Vec2 localPos = new Vec2( MathFunctions.Cos( angle ), MathFunctions.Sin( angle ) ) * distance;
                    Vec2 pos = rectangle.GetCenter() + new Vec2( localPos.X, localPos.Y * renderer.AspectRatio );

                    if( step != 0 )
                    {
                        ColorValue color = colors[ step % colors.Length ];
                        ColorValue color2 = color;
                        color2.Alpha = 0;
                        triangles.Add( new GuiRenderer.TriangleVertex( rectangle.GetCenter(), color ) );
                        triangles.Add( new GuiRenderer.TriangleVertex( lastPosition, color2 ) );
                        triangles.Add( new GuiRenderer.TriangleVertex( pos, color2 ) );
                    }

                    angle += ( MathFunctions.PI * 2 ) / steps;
                    lastPosition = pos;
                }

                renderer.AddTriangles( triangles );
            }

            //draw quads
            if( GetDrawAreaMode() == DrawAreaModes.Quads )
            {
                //draw background
                {
                    Texture texture = TextureManager.Instance.Load( "Gui\\Various\\Logo.png" );
                    renderer.AddQuad( rectangle, new Rect( 0, -.3f, 1, 1.4f ), texture,
                        new ColorValue( 1, 1, 1 ), true );
                }

                //draw bars
                {
                    float time = EngineApp.Instance.Time;

                    EngineRandom random = new EngineRandom( 0 );

                    int count = 15;
                    float stepOffset = rectangle.GetSize().X / count;
                    float size = stepOffset * .9f;
                    for( int n = 0; n < count; n++ )
                    {
                        float v = MathFunctions.Cos( time * random.NextFloat() );
                        float v2 = ( v + 1 ) / 2;

                        ColorValue color = colors[ n % colors.Length ];
                        Rect rect = new Rect(
                            rectangle.Left + stepOffset * n, rectangle.Bottom - rectangle.GetSize().Y * v2,
                            rectangle.Left + stepOffset * n + size, rectangle.Bottom );
                        renderer.AddQuad( rect, color );
                    }
                }
            }

            //draw lines
            if( GetDrawAreaMode() == DrawAreaModes.Lines )
            {
                float maxDistance;
                {
                    Vec2 s = rectangle.GetSize() / 2;
                    maxDistance = MathFunctions.Sqrt( s.X * s.X + s.Y * s.Y );
                }

                int step = 0;
                float distance = 0;
                Radian angle = -EngineApp.Instance.Time;
                Vec2 lastPosition = Vec2.Zero;

                while( distance < maxDistance )
                {
                    Vec2 localPos = new Vec2( MathFunctions.Cos( angle ), MathFunctions.Sin( angle ) ) * distance;
                    Vec2 pos = rectangle.GetCenter() + new Vec2( localPos.X, localPos.Y * renderer.AspectRatio );

                    if( step != 0 )
                    {
                        ColorValue color = colors[ step % colors.Length ];
                        renderer.AddLine( lastPosition, pos, color );
                    }

                    step++;
                    angle += MathFunctions.PI / 10;
                    distance += .001f;
                    lastPosition = pos;
                }
            }

            //draw text
            if( GetDrawAreaMode() == DrawAreaModes.Text )
            {
                //draw text with specified font.
                renderer.AddText( drawAreaBigFont, "Big Font Sample", rectangle.LeftTop, HorizontalAlign.Left,
                    VerticalAlign.Top, new ColorValue( 1, 1, 1 ) );

                //draw text with word wrap.
                string text = "Test Test Test.\n\nThe expandable user interface system is a unified system " +
                    "for the creation of end-user controls, menus, dialogues, windows and HUD screens. " +
                    "With the help of this system the end-user exercises control over the application.";
                renderer.AddTextWordWrap( text, rectangle, HorizontalAlign.Right, false, VerticalAlign.Bottom, 0,
                    new ColorValue( 1, 1, 0 ) );
            }

            if( clipRectangle )
                renderer.PopClipRectangle();
        }
Exemplo n.º 3
0
        protected override void OnRenderUI(GuiRenderer renderer)
        {
            base.OnRenderUI(renderer);

            Vec2I 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;

                    string textureName = TextureManager.Instance.GetUniqueName("WebBrowserControl");

                    bool mipmaps = false;
                    if (GetControlManager() != null && GetControlManager() is In3dControlManager)
                    {
                        mipmaps = inGame3DGuiMipmaps;
                    }

                    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(CefPaintElementType.View);
                    //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
            if (browser != null)
            {
                bool backColorZero = BackColor == new ColorValue(0, 0, 0, 0);

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

                color.Clamp(new ColorValue(0, 0, 0, 0), new ColorValue(1, 1, 1, 1));

                Rect rect;
                GetScreenRectangle(out rect);

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

                    Vec2 viewportSize = renderer.ViewportForScreenGuiRenderer.DimensionsInPixels.Size.ToVec2();

                    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.AddQuad(fixedRect, new Rect(0, 0, 1, 1), texture, color, true);
                }
                else
                {
                    renderer.AddQuad(rect, new Rect(0, 0, 1, 1), texture, color, true);
                }
            }

            if (cefRuntimeUnableToLoad)
            {
                renderer.AddTextWordWrap(
                    string.Format("WebBrowserControl: Unable to initialize web browser control. Error: {0}", cefRuntimeUnableToLoadError),
                    GetScreenRectangle(), Renderer.HorizontalAlign.Center, false, Renderer.VerticalAlign.Center, 0, new ColorValue(1, 0, 0));
            }
            else if (!IsSupportedByThisPlatform())
            {
                renderer.AddText(string.Format("WebBrowserControl: {0} is not supported.", PlatformInfo.Platform),
                                 new Vec2(.5f, .5f), Renderer.HorizontalAlign.Center, Renderer.VerticalAlign.Center, new ColorValue(1, 0, 0));
            }
        }
Exemplo n.º 4
0
        private void DrawArea_RenderUI(Control sender, GuiRenderer renderer)
        {
            Rect rectangle     = sender.GetScreenRectangle();
            bool clipRectangle = true;

            ColorValue[] colors = new ColorValue[] {
                new ColorValue(1, 0, 0),
                new ColorValue(0, 1, 0),
                new ColorValue(0, 0, 1),
                new ColorValue(1, 1, 0),
                new ColorValue(1, 1, 1)
            };

            if (clipRectangle)
            {
                renderer.PushClipRectangle(rectangle);
            }

            //draw triangles
            if (GetDrawAreaMode() == DrawAreaModes.Triangles)
            {
                float distance = rectangle.GetSize().X / 2;

                List <GuiRenderer.TriangleVertex> triangles = new List <GuiRenderer.TriangleVertex>(256);

                Radian angle = -EngineApp.Instance.Time;

                const int steps        = 30;
                Vec2      lastPosition = Vec2.Zero;
                for (int step = 0; step < steps + 1; step++)
                {
                    Vec2 localPos = new Vec2(MathFunctions.Cos(angle), MathFunctions.Sin(angle)) * distance;
                    Vec2 pos      = rectangle.GetCenter() + new Vec2(localPos.X, localPos.Y * renderer.AspectRatio);

                    if (step != 0)
                    {
                        ColorValue color  = colors[step % colors.Length];
                        ColorValue color2 = color;
                        color2.Alpha = 0;
                        triangles.Add(new GuiRenderer.TriangleVertex(rectangle.GetCenter(), color));
                        triangles.Add(new GuiRenderer.TriangleVertex(lastPosition, color2));
                        triangles.Add(new GuiRenderer.TriangleVertex(pos, color2));
                    }

                    angle       += (MathFunctions.PI * 2) / steps;
                    lastPosition = pos;
                }

                renderer.AddTriangles(triangles);
            }

            //draw quads
            if (GetDrawAreaMode() == DrawAreaModes.Quads)
            {
                //draw background
                {
                    Texture texture = TextureManager.Instance.Load("GUI\\Textures\\NeoAxisLogo.png");
                    renderer.AddQuad(rectangle, new Rect(0, -.3f, 1, 1.4f), texture,
                                     new ColorValue(1, 1, 1), true);
                }

                //draw bars
                {
                    float time = EngineApp.Instance.Time;

                    EngineRandom random = new EngineRandom(0);

                    int   count      = 15;
                    float stepOffset = rectangle.GetSize().X / count;
                    float size       = stepOffset * .9f;
                    for (int n = 0; n < count; n++)
                    {
                        float v  = MathFunctions.Cos(time * random.NextFloat());
                        float v2 = (v + 1) / 2;

                        ColorValue color = colors[n % colors.Length];
                        Rect       rect  = new Rect(
                            rectangle.Left + stepOffset * n, rectangle.Bottom - rectangle.GetSize().Y *v2,
                            rectangle.Left + stepOffset * n + size, rectangle.Bottom);
                        renderer.AddQuad(rect, color);
                    }
                }
            }

            //draw lines
            if (GetDrawAreaMode() == DrawAreaModes.Lines)
            {
                float maxDistance;
                {
                    Vec2 s = rectangle.GetSize() / 2;
                    maxDistance = MathFunctions.Sqrt(s.X * s.X + s.Y * s.Y);
                }

                int    step         = 0;
                float  distance     = 0;
                Radian angle        = -EngineApp.Instance.Time;
                Vec2   lastPosition = Vec2.Zero;

                while (distance < maxDistance)
                {
                    Vec2 localPos = new Vec2(MathFunctions.Cos(angle), MathFunctions.Sin(angle)) * distance;
                    Vec2 pos      = rectangle.GetCenter() + new Vec2(localPos.X, localPos.Y * renderer.AspectRatio);

                    if (step != 0)
                    {
                        ColorValue color = colors[step % colors.Length];
                        renderer.AddLine(lastPosition, pos, color);
                    }

                    step++;
                    angle       += MathFunctions.PI / 10;
                    distance    += .001f;
                    lastPosition = pos;
                }
            }

            //draw text
            if (GetDrawAreaMode() == DrawAreaModes.Text)
            {
                string text;

                //draw text with specified font.
                text = "Map Editor is a tool to create worlds for your project. The tool is a complex editor to manage " +
                       "objects on the map.";
                renderer.AddTextWordWrap(drawAreaBigFont, text, rectangle, HorizontalAlign.Left, false, VerticalAlign.Top, 0,
                                         new ColorValue(1, 1, 1));

                //draw text with word wrap.
                text = "Deployment Tool is a tool to deploy the final version of your application to specified platforms. " +
                       "This utility is useful to automate the final product's creation.";
                renderer.AddTextWordWrap(drawAreaSmallFont, text, rectangle, HorizontalAlign.Right, false, VerticalAlign.Bottom, 0,
                                         new ColorValue(1, 1, 0));
            }

            if (clipRectangle)
            {
                renderer.PopClipRectangle();
            }
        }
        private void DrawArea_RenderUI(Control sender, GuiRenderer renderer)
        {
            Rect rectangle = sender.GetScreenRectangle();
            bool clipRectangle = true;
            ColorValue[] colors = new ColorValue[]{
				new ColorValue( 1 ,0, 0 ),
				new ColorValue( 0, 1, 0 ),
				new ColorValue( 0, 0, 1 ),
				new ColorValue( 1, 1, 0 ),
				new ColorValue( 1, 1, 1 )};

            if (clipRectangle)
                renderer.PushClipRectangle(rectangle);

            //draw triangles
            if (GetDrawAreaMode() == DrawAreaModes.Triangles)
            {
                float distance = rectangle.GetSize().X / 2;

                List<GuiRenderer.TriangleVertex> triangles = new List<GuiRenderer.TriangleVertex>(256);

                Radian angle = -EngineApp.Instance.Time;

                const int steps = 30;
                Vec2 lastPosition = Vec2.Zero;
                for (int step = 0; step < steps + 1; step++)
                {
                    Vec2 localPos = new Vec2(MathFunctions.Cos(angle), MathFunctions.Sin(angle)) * distance;
                    Vec2 pos = rectangle.GetCenter() + new Vec2(localPos.X, localPos.Y * renderer.AspectRatio);

                    if (step != 0)
                    {
                        ColorValue color = colors[step % colors.Length];
                        ColorValue color2 = color;
                        color2.Alpha = 0;
                        triangles.Add(new GuiRenderer.TriangleVertex(rectangle.GetCenter(), color));
                        triangles.Add(new GuiRenderer.TriangleVertex(lastPosition, color2));
                        triangles.Add(new GuiRenderer.TriangleVertex(pos, color2));
                    }

                    angle += (MathFunctions.PI * 2) / steps;
                    lastPosition = pos;
                }

                renderer.AddTriangles(triangles);
            }

            //draw quads
            if (GetDrawAreaMode() == DrawAreaModes.Quads)
            {
                //draw background
                {
                    Texture texture = TextureManager.Instance.Load("GUI\\Textures\\NeoAxisLogo.png");
                    renderer.AddQuad(rectangle, new Rect(0, -.3f, 1, 1.4f), texture,
                        new ColorValue(1, 1, 1), true);
                }

                //draw bars
                {
                    float time = EngineApp.Instance.Time;

                    EngineRandom random = new EngineRandom(0);

                    int count = 15;
                    float stepOffset = rectangle.GetSize().X / count;
                    float size = stepOffset * .9f;
                    for (int n = 0; n < count; n++)
                    {
                        float v = MathFunctions.Cos(time * random.NextFloat());
                        float v2 = (v + 1) / 2;

                        ColorValue color = colors[n % colors.Length];
                        Rect rect = new Rect(
                            rectangle.Left + stepOffset * n, rectangle.Bottom - rectangle.GetSize().Y * v2,
                            rectangle.Left + stepOffset * n + size, rectangle.Bottom);
                        renderer.AddQuad(rect, color);
                    }
                }
            }

            //draw lines
            if (GetDrawAreaMode() == DrawAreaModes.Lines)
            {
                float maxDistance;
                {
                    Vec2 s = rectangle.GetSize() / 2;
                    maxDistance = MathFunctions.Sqrt(s.X * s.X + s.Y * s.Y);
                }

                int step = 0;
                float distance = 0;
                Radian angle = -EngineApp.Instance.Time;
                Vec2 lastPosition = Vec2.Zero;

                while (distance < maxDistance)
                {
                    Vec2 localPos = new Vec2(MathFunctions.Cos(angle), MathFunctions.Sin(angle)) * distance;
                    Vec2 pos = rectangle.GetCenter() + new Vec2(localPos.X, localPos.Y * renderer.AspectRatio);

                    if (step != 0)
                    {
                        ColorValue color = colors[step % colors.Length];
                        renderer.AddLine(lastPosition, pos, color);
                    }

                    step++;
                    angle += MathFunctions.PI / 10;
                    distance += .001f;
                    lastPosition = pos;
                }
            }

            //draw text
            if (GetDrawAreaMode() == DrawAreaModes.Text)
            {
                string text;

                //draw text with specified font.
                text = "Map Editor is a tool to create worlds for your project. The tool is a complex editor to manage " +
                    "objects on the map.";
                renderer.AddTextWordWrap(drawAreaBigFont, text, rectangle, HorizontalAlign.Left, false, VerticalAlign.Top, 0,
                    new ColorValue(1, 1, 1));

                //draw text with word wrap.
                text = "Deployment Tool is a tool to deploy the final version of your application to specified platforms. " +
                    "This utility is useful to automate the final product's creation.";
                renderer.AddTextWordWrap(drawAreaSmallFont, text, rectangle, HorizontalAlign.Right, false, VerticalAlign.Bottom, 0,
                    new ColorValue(1, 1, 0));
            }

            if (clipRectangle)
                renderer.PopClipRectangle();
        }