Example #1
0
        public virtual void Render(RenderContext context)
        {
            if (!Visible)
            {
                return;
            }

            UpdateLayout();

            var view = Rectangle.Intersect(context.View, Bounds);

            if (view.Width == 0 || view.Height == 0)
            {
                return;
            }

            var batch = context.Batch;
            var oldScissorRectangle = CrossEngineStuff.GetScissor();

            if (ClipToBounds && !MyraEnvironment.DisableClipping)
            {
                var newScissorRectangle = Rectangle.Intersect(oldScissorRectangle, view);

                if (newScissorRectangle.IsEmpty)
                {
                    return;
                }

                context.Flush();

                CrossEngineStuff.SetScissor(newScissorRectangle);
            }

            var oldOpacity = context.Opacity;

            context.Opacity *= Opacity;

            // Background
            var background = GetCurrentBackground();

            if (background != null)
            {
                context.Draw(background, Bounds);
            }

            var oldView = context.View;

            context.View = view;
            InternalRender(context);
            context.View = oldView;

            // Border
            var border = GetCurrentBorder();

            if (border != null)
            {
                context.Draw(border, Bounds);
            }

            if (MyraEnvironment.DrawWidgetsFrames)
            {
                batch.DrawRectangle(Bounds, Color.LightGreen);
            }

            if (MyraEnvironment.DrawFocusedWidgetFrame && IsFocused)
            {
                batch.DrawRectangle(Bounds, Color.Red);
            }

            if (ClipToBounds && !MyraEnvironment.DisableClipping)
            {
                context.Flush();
                CrossEngineStuff.SetScissor(oldScissorRectangle);
            }

            context.Opacity = oldOpacity;
        }
Example #2
0
        public void Render(RenderContext context)
        {
            if (!Visible)
            {
                return;
            }

            UpdateLayout();

            var view = Rectangle.Intersect(context.View, Bounds);

            if (view.Width == 0 || view.Height == 0)
            {
                return;
            }

            var batch = context.Batch;
            var oldScissorRectangle = CrossEngineStuff.GetScissor();

            if (ClipToBounds && !MyraEnvironment.DisableClipping)
            {
                var newScissorRectangle = Rectangle.Intersect(oldScissorRectangle, view);

                if (newScissorRectangle.IsEmpty)
                {
                    return;
                }

                context.Flush();

                CrossEngineStuff.SetScissor(newScissorRectangle);
            }

            var oldOpacity = context.Opacity;
            var oldView    = context.View;

            context.Opacity *= Opacity;
            context.View     = view;

            BeforeRender?.Invoke(context);

            // Background
            var background = GetCurrentBackground();

            if (background != null)
            {
                context.Draw(background, BackgroundBounds);
            }

            // Borders
            var border = GetCurrentBorder();

            if (border != null)
            {
                var borderBounds = BorderBounds;
                if (BorderThickness.Left > 0)
                {
                    context.Draw(border, new Rectangle(borderBounds.X, borderBounds.Y, BorderThickness.Left, borderBounds.Height));
                }

                if (BorderThickness.Top > 0)
                {
                    context.Draw(border, new Rectangle(borderBounds.X, borderBounds.Y, borderBounds.Width, BorderThickness.Top));
                }

                if (BorderThickness.Right > 0)
                {
                    context.Draw(border, new Rectangle(borderBounds.Right - BorderThickness.Right, borderBounds.Y, BorderThickness.Right, borderBounds.Height));
                }

                if (BorderThickness.Bottom > 0)
                {
                    context.Draw(border, new Rectangle(borderBounds.X, borderBounds.Bottom - BorderThickness.Bottom, borderBounds.Width, BorderThickness.Bottom));
                }
            }

            InternalRender(context);

            AfterRender?.Invoke(context);

            // Restore context settings
            context.View    = oldView;
            context.Opacity = oldOpacity;

            // Optional debug rendering
            if (MyraEnvironment.DrawWidgetsFrames)
            {
                batch.DrawRectangle(Bounds, Color.LightGreen);
            }

            if (MyraEnvironment.DrawKeyboardFocusedWidgetFrame && IsKeyboardFocused)
            {
                batch.DrawRectangle(Bounds, Color.Red);
            }

            if (MyraEnvironment.DrawMouseWheelFocusedWidgetFrame && IsMouseWheelFocused)
            {
                batch.DrawRectangle(Bounds, Color.Yellow);
            }

            if (ClipToBounds && !MyraEnvironment.DisableClipping)
            {
                // Restore scissor
                context.Flush();
                CrossEngineStuff.SetScissor(oldScissorRectangle);
            }
        }