Ejemplo n.º 1
0
        protected override void OnRenderUI(CanvasRenderer renderer)
        {
            base.OnRenderUI(renderer);

            //draw texture
            {
                var color = new ColorValue(1, 1, 1);

                GetScreenRectangle(out var rect);

                var tex = createdImage;
                if (tex == null)
                {
                    tex = ResourceUtility.WhiteTexture2D;
                }

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

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

                    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);
                }
                //}
            }
        }
Ejemplo n.º 2
0
        protected virtual void OnRenderSlider(UISlider control, CanvasRenderer renderer)
        {
            var rect = control.GetScreenRectangle();

            renderer.AddQuad(rect, new ColorValue(0.5, 0.5, 0.5, 0.5));

            var valuesRay = GetSliderValuesRayInScreenCoords(control);

            //visualize ticks
            var tickBarSize = GetSliderElementSizeInScreenCoords(control, SliderElement.Tick);

            foreach (var factor in control.GetTickFactors())
            {
                var position = valuesRay.GetPointOnRay(factor);

                var r = new Rectangle(position);
                r.Expand(tickBarSize / 2);

                ColorValue c;
                if (!control.ReadOnly.Value)
                {
                    c = new ColorValue(1, 1, 1, 0.5);
                }
                else
                {
                    c = new ColorValue(0.5, 0.5, 0.5, 0.5);
                }
                renderer.AddQuad(r, c);
            }

            //visualize current value
            {
                var position = valuesRay.GetPointOnRay(control.GetValueFactor());

                var valueBarSize = GetSliderElementSizeInScreenCoords(control, SliderElement.ValueBar);
                var r            = new Rectangle(position);
                r.Expand(valueBarSize / 2);

                ColorValue c;
                if (!control.ReadOnly.Value)
                {
                    c = new ColorValue(1, 1, 1);
                }
                else
                {
                    c = new ColorValue(0.5, 0.5, 0.5);
                }
                renderer.AddQuad(r, c);
            }
        }
Ejemplo n.º 3
0
        protected virtual void OnRenderButton(UIButton control, CanvasRenderer renderer)
        {
            var styleColor = ColorValue.Zero;

            switch (control.State)
            {
            case UIButton.StateEnum.Normal: styleColor = new ColorValue(0.5, 0.5, 0.5); break;

            case UIButton.StateEnum.Hover: styleColor = new ColorValue(0.65, 0.65, 0.65); break;

            case UIButton.StateEnum.Pushed: styleColor = new ColorValue(0.8, 0.8, 0.8); break;

            //case UIButton.StateEnum.Normal: styleColor = new ColorValue( 0, 0.5, 0 ); break;
            //case UIButton.StateEnum.Hover: styleColor = new ColorValue( 0, 0.7, 0 ); break;
            //case UIButton.StateEnum.Pushed: styleColor = new ColorValue( 0, 0.9, 0 ); break;
            case UIButton.StateEnum.Highlighted: styleColor = new ColorValue(0.6, 0.6, 0); break;

            case UIButton.StateEnum.Disabled: styleColor = new ColorValue(0.5, 0.5, 0.5); break;
            }

            control.GetScreenRectangle(out var rect);
            var color = styleColor.GetSaturate();

            if (color.Alpha > 0)
            {
                renderer.AddQuad(rect, color);
                renderer.AddText(control.Text, rect.GetCenter(), EHorizontalAlignment.Center, EVerticalAlignment.Center, new ColorValue(1, 1, 1));
            }
        }
Ejemplo n.º 4
0
        protected virtual void OnRenderScrollBar(UIScrollBar control, CanvasRenderer renderer)
        {
            var rect = control.GetScreenRectangle();

            GetScrollBarButtonsScreenRectangles(control, out var up, out var down);

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

            double factor = control.GetValueFactor();

            var r = new Rectangle(
                Vector2.Lerp(up.LeftTop, down.LeftTop, factor),
                Vector2.Lerp(up.RightBottom, down.RightBottom, factor));

            ColorValue c;

            if (!control.ReadOnly.Value)
            {
                c = new ColorValue(1, 1, 1);
            }
            else
            {
                c = new ColorValue(0.5, 0.5, 0.5);
            }
            renderer.AddQuad(r, c);

            //renderer.AddQuad( up, new ColorValue( 1, 0, 0 ) );
            //renderer.AddQuad( down, new ColorValue( 0, 0, 1 ) );

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

            //var rect2 = rect;
            //rect2.Expand( -control.GetScreenOffsetByValue( new UIMeasureValueVector2( UIMeasure.Units, 2, 2 ) ) );

            //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 );
        }
Ejemplo n.º 5
0
        /////////////////////////////////////////

        protected virtual void OnRenderProgressBar(UIProgressBar control, CanvasRenderer renderer)
        {
            var rect = control.GetScreenRectangle();

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

            if (control.Maximum.Value != 0)
            {
                double progress = control.Value.Value / control.Maximum.Value;
                if (progress > 0)
                {
                    var rect2 = rect;
                    rect2.Expand(-control.GetScreenOffsetByValue(new UIMeasureValueVector2(UIMeasure.Units, 4, 4)));
                    rect2.Right = MathEx.Lerp(rect2.Left, rect2.Right, progress);

                    renderer.AddQuad(rect2, new ColorValue(1, 1, 1));
                }
            }
        }
Ejemplo n.º 6
0
        /////////////////////////////////////////

        protected virtual void OnRenderWindow(UIWindow control, CanvasRenderer renderer)
        {
            var rect = control.GetScreenRectangle();

            renderer.AddQuad(rect, new ColorValue(0.15, 0.15, 0.15));

            var rect2 = rect;

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

            var color = new ColorValue(0.5, 0.5, 0.5);

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

            if (control.TitleBar.Value)
            {
                double titleBarHeight = 30;
                double screenY        = rect.Top + control.GetScreenOffsetByValue(new UIMeasureValueVector2(UIMeasure.Units, 0, titleBarHeight)).Y;
                double screenY2       = screenY + control.GetScreenOffsetByValue(new UIMeasureValueVector2(UIMeasure.Units, 0, 4)).Y;

                var rect3 = new Rectangle(rect2.Left, rect2.Top, rect2.Right, screenY2);
                renderer.AddQuad(rect3, color);

                if (!string.IsNullOrEmpty(control.Text))
                {
                    var pos = new Vector2(rect.GetCenter().X, (rect2.Top + screenY) / 2);
                    renderer.AddText(control.Text, pos, EHorizontalAlignment.Center, EVerticalAlignment.Center, new ColorValue(1, 1, 1));
                }
            }
        }
Ejemplo n.º 7
0
        /////////////////////////////////////////

        protected override void OnRenderUI(CanvasRenderer renderer)
        {
            base.OnRenderUI(renderer);

            //bool backColorZero = backColor == new ColorValue( 0, 0, 0, 0 );

            //!!!!неправильной текстурой рисовать, чтобы видно было что ошибка? везде так
            //!!!!!заранее при загрузке?

            Component_Image texture = SourceImage;

            ////!!!!?
            //GpuTexture gpuTexture = ResourceUtils.GetTextureCompiledData( texture );
            //if( gpuTexture == null )
            //	gpuTexture = ResourceUtils.GetTextureCompiledData( ResourceUtils.WhiteTexture2D );

            if (texture != null)
            {
                //Rect texCoord = backTextureCoord;

                //if( backTextureTile && texture != null )
                //{
                //	double baseHeight = UIControlsWorld.ScaleByResolutionBaseHeight;
                //	//!!!!!!slow
                //	Vec2 tileCount = new Vec2( baseHeight * renderer.AspectRatio, baseHeight ) / gpuTexture.SourceSize.ToVec2F() * GetScreenSize();
                //	texCoord = new Rect( -tileCount * .5f, tileCount * .5f ) + new Vec2( .5f, .5f );
                //}

                //var color = GetTotalColorMultiplier();
                //if( color.Alpha > 0 )
                //{
                //	color.Saturate();

                GetScreenRectangle(out var rect);

                var filtering = Filtering.Value;
                //!!!!или всегда выставлять. или добавить пункт Default.
                if (filtering == CanvasRenderer.TextureFilteringMode.Point)
                {
                    renderer.PushTextureFilteringMode(CanvasRenderer.TextureFilteringMode.Point);
                }

                renderer.AddQuad(rect, TextureCoordinates.Value, texture, ColorValue.One, Clamp);
                //renderer.AddQuad( rect, texCoord, texture, color, backTextureTile ? false : true );

                if (filtering == CanvasRenderer.TextureFilteringMode.Point)
                {
                    renderer.PopTextureFilteringMode();
                }
                //}
            }
        }
Ejemplo n.º 8
0
        protected override void OnRenderUI(CanvasRenderer renderer)
        {
            //base.OnRenderUI( renderer );

            var videoTexture = videoBuffer.GetUpdatedTexture();
            var texture      = videoTexture?.Result;

            //!!!!
            //bool backColorZero = BackColor == new ColorValue( 0, 0, 0, 0 );

            {
                //!!!!
                Rectangle texCoord = new Rectangle(0, 0, 1, 1);
                //Rect texCoord = BackTextureCoord;

                //correct tex coord round2 texture
                if (texture != null)
                {
                    Vector2 textureSize = texture.ResultSize.ToVector2F();
                    Vector2 videoSize   = oggFile.VideoDriver.GetSize().ToVector2F();
                    Vector2 coef        = videoSize / textureSize;

                    texCoord.Right  *= coef.X;
                    texCoord.Bottom *= coef.Y;
                }

                //!!!!было
                //if( BackTextureTile && texture != null )
                //{
                //	Vec2 tileCount = GetScreenTextureBaseSize() / texture.Size.ToVec2F() * GetScreenSize();
                //	texCoord = new Rect( -tileCount * .5f, tileCount * .5f ) + new Vec2( .5f, .5f );
                //}

                //!!!!
                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();

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

                GetScreenRectangle(out var rect);

                //!!!!
                renderer.AddQuad(rect, texCoord, videoTexture, color, true);
                //renderer.AddQuad( rect, texCoord, videoTexture, color, BackTextureTile ? false : true );
            }
        }
Ejemplo n.º 9
0
        protected virtual void OnRenderEdit(UIEdit control, CanvasRenderer renderer)
        {
            var rect = control.GetScreenRectangle();

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

            var rect2 = rect;

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

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

            //renderer.AddQuad( control.GetScreenRectangle(), new ColorValue( 0.75, 0.75, 0.75 ) );

            //var textControl = control.GetTextControl();
            //if( textControl != null )
            //	renderer.AddQuad( textControl.GetScreenRectangle(), new ColorValue( 0, 0, 0 ) );
        }
Ejemplo n.º 10
0
        protected virtual void OnRenderBackground(UIControl control, CanvasRenderer renderer)
        {
            //BackgroundColor
            var backgroundColor = control.BackgroundColor.Value;

            if (backgroundColor.Alpha > 0)
            {
                control.GetScreenRectangle(out var rect);
                var color = backgroundColor.GetSaturate();
                if (color.Alpha > 0)
                {
                    renderer.AddQuad(rect, color);
                }
            }
        }
Ejemplo n.º 11
0
 protected virtual void RenderTargetImage(CanvasRenderer renderer)
 {
     //visualize target image
     if (DisplayTarget && (UseBuiltInCamera.Value == BuiltInCameraEnum.FirstPerson || UseBuiltInCamera.Value == BuiltInCameraEnum.ThirdPerson || GetCurrentCameraManagement() != null) && !FreeCamera && Scene.Mode.Value == Component_Scene.ModeEnum._3D)
     {
         //!!!!?
         //if( weapon != null || currentAttachedGuiObject != null || currentSwitch != null )
         {
             var size      = DisplayTargetSize.Value / 2;
             var rectangle = new Rectangle(
                 0.5 - size, 0.5 - size * renderer.AspectRatio,
                 0.5 + size, 0.5 + size * renderer.AspectRatio);
             renderer.AddQuad(rectangle, new Rectangle(0, 0, 1, 1), DisplayTargetImage, DisplayTargetColor);
         }
     }
 }
Ejemplo n.º 12
0
        public virtual void RenderUI(CanvasRenderer renderer, Component_RenderingPipeline.RenderSceneData.LightItem lightItem, Viewport viewport, double intensity)
        {
            var lightPosition = lightItem.Position;

            //!!!!override real position
            //{
            //	if( Sun.Instances.Count > 0 )
            //	{
            //		//get first sun entity on the map.
            //		Sun sun = Sun.Instances[ 0 ];

            //		Vec3 direction;
            //		if( sun.BillboardOverridePosition != Vec3.Zero )
            //			direction = sun.BillboardOverridePosition.GetNormalize();
            //		else
            //			direction = -sun.Rotation.GetForward();
            //		position = camera.Position + direction * 100000;

            //		return true;
            //	}

            //	position = Vec3.Zero;
            //	return false;
            //}

            if (viewport.CameraSettings.ProjectToScreenCoordinates(lightPosition, out var screenLightPosition))
            {
                //get enabled flares
                var flares = GetComponents <Component_LensFlare>(onlyEnabledInHierarchy: true);

                //sort by position
                CollectionUtility.SelectionSort(flares, delegate(Component_LensFlare f1, Component_LensFlare f2)
                {
                    if (f1.Position > f2.Position)
                    {
                        return(-1);
                    }
                    if (f1.Position < f2.Position)
                    {
                        return(1);
                    }
                    return(0);
                });

                //for( int n = 0; n < flares.Count; n++ )
                //	sortedFlares[ n ].tempSmoothIntensityFactor = cameraInfo.SmoothIntensityFactors[ n ];

                //render
                foreach (var flare in flares)
                {
                    var image = flare.Image.Value;

                    var flareVector   = screenLightPosition - new Vector2(0.5, 0.5);
                    var flarePosition = new Vector2(0.5, 0.5) + flareVector * flare.Position;
                    var size          = flare.Size.Value;
                    var flareSize     = new Vector2(size.X, size.Y * renderer.AspectRatio);
                    var rectangle     = new Rectangle(flarePosition - flareSize * 0.5, flarePosition + flareSize * 0.5);

                    var flareColor = Color.Value * flare.Color * new ColorValue(1, 1, 1, intensity);
                    // * new ColorValue( 1, 1, 1, item.tempSmoothIntensityFactor );

                    if (flareColor.Alpha > 0)
                    {
                        renderer.PushBlendingType(flare.Blending.Value);
                        renderer.AddQuad(rectangle, new RectangleF(0, 0, 1, 1), image, flareColor, true);
                        renderer.PopBlendingType();
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public static void PerformRenderUI()
        {
            CanvasRenderer renderer = MainViewport.CanvasRenderer;

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

            //load backgrouund texture and font
            if (texture != null && texture.Disposed)
            {
                needLoadTextureAndFont = true;
            }
            if (needLoadTextureAndFont)
            {
                texture = ResourceManager.LoadResource <Component_Image>("Base\\UI\\Images\\Console.png");
                //texture = ResourceManager.LoadResource<Component_Image>( "Base\\UI\\Images\\Console.jpg" );

                font = renderer.DefaultFont;
                //font = EngineFontManager.Instance.LoadFont( "Default", .025f );
                needLoadTextureAndFont = false;
            }

            if (font == null)
            {
                return;
            }

            Vector2F viewportSize = renderer.ViewportForScreenCanvasRenderer.SizeInPixels.ToVector2F();
            Vector2F shadowOffset = new Vector2F(1, 1) / viewportSize;

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

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

            //var textureRect = new Rectangle( 0, 1.0 - renderer.AspectRatioInv, 1, 1 );
            //renderer.AddQuad( new Rectangle( 0, 0, 1, .5f ), textureRect, texture, new ColorValue( 0.7, 0.7, 0.7, transparency ), false );

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

            //draw background info
            string staticText = "Press \"~\" or \"F12\" to hide console\r\nPress \"Ctrl + ~\" to hide and disable auto opening";

            renderer.AddTextWordWrap(staticText, new RectangleF(0, 0, .995f, .495f), EHorizontalAlignment.Right, false, EVerticalAlignment.Bottom, 0,
                                     new ColorValue(0.8, 0.8, 0.8, transparency));

            float fontheight = (float)fontSize;            // font.Height;

            float x = .01f;

            float y = .5f - fontheight;

            string str;

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

            renderer.PushClipRectangle(new RectangleF(0, 0, .975f, 1));
            renderer.AddText(font, fontSize, str, new Vector2F(x, y) + shadowOffset, EHorizontalAlignment.Left,
                             EVerticalAlignment.Center, new ColorValue(0, 0, 0, transparency / 2));
            renderer.AddText(font, fontSize, str, new Vector2F(x, y), EHorizontalAlignment.Left,
                             EVerticalAlignment.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--)
            {
                var text      = strings[n].text;
                int lineCount = text.Count(f => f == '\n') + 1;

                float y2 = y - fontheight * (lineCount - 1) / 2;

                renderer.AddText(font, fontSize, text, new Vector2F(x, y2) + shadowOffset, EHorizontalAlignment.Left,
                                 EVerticalAlignment.Center, strings[n].color * new ColorValue(0, 0, 0, transparency / 2));
                renderer.AddText(font, fontSize, text, new Vector2F(x, y2), EHorizontalAlignment.Left,
                                 EVerticalAlignment.Center, strings[n].color * new ColorValue(1, 1, 1, transparency));
                y -= fontheight * lineCount;
            }
        }
Ejemplo n.º 14
0
        ////Tick

        //public void PerformUITick( double delta )
        //{
        //	CheckCachedParameters();
        //	UpdateTopMouseCoversControl();

        //	if( capturedControl != null && capturedControl.ParentContainer == null )
        //		capturedControl = null;
        //	if( focusedControl != null && focusedControl.ParentContainer == null )
        //		focusedControl = null;

        //	OnUITick( delta );

        //	//!!!!где еще вызывать это? и для каких типов объектов
        //}

        //Render

        //public void DoRender()
        //{
        //CheckCachedParameters();
        //UpdateTopMouseCoversControl();

        //CurrentCursor = defaultCursor;

        //было, не нужно
        //OnRenderWithChildren();
        //}

        void DrawCursor(CanvasRenderer renderer)
        {
            lastCursorRectangle = Rectangle.Zero;

            //hide cursor for mouse relative mode
            if (MouseRelativeMode)
            {
                currentCursor = null;
            }

            //!!!!!!focused иначе проверять
            //!!!!!!EngineApp.Instance.ApplicationWindow.Focused?
            if (!string.IsNullOrEmpty(currentCursor))               //!!!!!EngineApp.Instance.ApplicationWindow.Focused/*IsWindowFocused()*/ && EngineApp.Instance.IsCreated && !LongOperationCallbackManager.DuringCallingCallback )
            {
                //!!!!Wait
                var        textureIns = ResourceManager.LoadResource <Component_Image>(currentCursor);
                GpuTexture texture    = textureIns?.Result;
                if (texture != null)
                {
                    //!!!!было
                    //texture._ThisIsGuiTexture = true;

                    if (drawCursorWithPerPixelAccuracy)
                    {
                        Vector2 screenPixelSize = viewport.SizeInPixels.ToVector2();

                        Vector2 m           = MousePosition * screenPixelSize;
                        Vector2 leftTop     = m - texture.SourceSize.ToVector2F() * .5f;
                        Vector2 rightBottom = m + texture.SourceSize.ToVector2F() * .5f;

                        //!!!!!
                        //per pixel alignment
                        //if( this is UIContainerScreen )
                        {
                            leftTop = new Vector2((int)(leftTop.X + .9999f), (int)(leftTop.Y + .9999f));

                            //!!!!
                            //if( RenderSystem.Instance.IsDirect3D() )
                            //	leftTop -= new Vec2( .5f, .5f );

                            rightBottom = new Vector2((int)(rightBottom.X + .9999f), (int)(rightBottom.Y + .9999f));
                            //!!!!
                            //if( RenderSystem.Instance.IsDirect3D() )
                            //	rightBottom -= new Vec2( .5f, .5f );
                        }

                        leftTop     /= screenPixelSize;
                        rightBottom /= screenPixelSize;

                        Rectangle rectangle = new Rectangle(leftTop, rightBottom);
                        renderer.AddQuad(rectangle, new Rectangle(0, 0, 1, 1), textureIns, new ColorValue(1, 1, 1), true);

                        lastCursorRectangle = rectangle;
                    }
                    else
                    {
                        double  baseHeight = UIControlsWorld.ScaleByResolutionBaseHeight;
                        Vector2 size       = texture.SourceSize.ToVector2F() / new Vector2(baseHeight * renderer.AspectRatio, baseHeight);

                        Rectangle rectangle = new Rectangle(-size / 2, size / 2) + MousePosition;

                        renderer.AddQuad(rectangle, new Rectangle(0, 0, 1, 1), textureIns, new ColorValue(1, 1, 1), true);

                        lastCursorRectangle = rectangle;
                    }
                }
            }
        }
Ejemplo n.º 15
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));
            }
        }
Ejemplo n.º 16
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 );
            //}
        }
Ejemplo n.º 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();
            }
        }