Example #1
0
        protected override void OnRenderButton(UIButton control, CanvasRenderer renderer)
        {
            var styleColor = ColorValue.Zero;

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

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

            case UIButton.StateEnum.Pushed: styleColor = new ColorValue(0.25, 0.25, 0.9); 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);

                var center = rect.GetCenter() + new Vector2(0, renderer.DefaultFontSize / 10);
                renderer.AddText(control.Text, center, EHorizontalAlignment.Center, EVerticalAlignment.Center, new ColorValue(1, 1, 1));
            }
        }
Example #2
0
        protected override void OnRenderButton(UIButton control, CanvasRenderer renderer)
        {
            if (control.Parent as UIContextMenu != null)
            {
                //context menu button

                var styleColor = ColorValue.Zero;
                switch (control.State)
                {
                case UIButton.StateEnum.Normal: styleColor = new ColorValue(0.1, 0.1, 0.7); break;

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

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

                case UIButton.StateEnum.Highlighted: styleColor = new ColorValue(0.6, 0.6, 0); break;

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

                control.GetScreenRectangle(out var rect);
                var color = styleColor.GetSaturate();
                if (color.Alpha > 0)
                {
                    //back
                    renderer.AddQuad(rect, color);

                    //!!!!image

                    //text
                    var position  = new Vector2(rect.Left + control.GetScreenOffsetByValueX(new UIMeasureValueDouble(UIMeasure.Units, 10)), rect.GetCenter().Y) + new Vector2(0, renderer.DefaultFontSize / 10);
                    var textColor = control.State == UIButton.StateEnum.Disabled ? new ColorValue(0.7, 0.7, 0.7) : new ColorValue(1, 1, 1);
                    renderer.AddText(control.Text, position, EHorizontalAlignment.Left, EVerticalAlignment.Center, textColor);
                }
            }
            else
            {
                //usual button

                var styleColor = ColorValue.Zero;
                switch (control.State)
                {
                case UIButton.StateEnum.Normal: styleColor = new ColorValue(0.1, 0.1, 0.6); break;

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

                case UIButton.StateEnum.Pushed: styleColor = new ColorValue(0.25, 0.25, 0.9); 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)
                {
                    //back
                    renderer.AddQuad(rect, color);

                    //image
                    if (control.Image.Value != null)
                    {
                        var image = control.Image.Value;
                        if (control.ReadOnly && control.ImageDisabled.Value != null)
                        {
                            image = control.ImageDisabled.Value;
                        }

                        var imageRect = rect;
                        imageRect.Expand(-control.GetScreenOffsetByValue(new UIMeasureValueVector2(UIMeasure.Units, 4, 4)));
                        renderer.AddQuad(imageRect, new Rectangle(0, 0, 1, 1), image, new ColorValue(1, 1, 1), true);
                    }

                    //text
                    var position  = rect.GetCenter() + new Vector2(0, renderer.DefaultFontSize / 10);
                    var textColor = control.State == UIButton.StateEnum.Disabled ? new ColorValue(0.7, 0.7, 0.7) : new ColorValue(1, 1, 1);
                    renderer.AddText(control.Text, position, EHorizontalAlignment.Center, EVerticalAlignment.Center, textColor);
                }
            }
        }