예제 #1
0
        public override void Draw(GameTime gameTime, Frame frame)
        {
            var ir = new ImperativeRenderer(frame, Materials, samplerState: SamplerState.LinearClamp);

            ir.AutoIncrementLayer = true;

            ir.Clear(color: ClearColor);

            Text.Position        = TopLeft;
            Text2.LineBreakAtX   = Text.LineBreakAtX = BottomRight.X - TopLeft.X;
            Text.WrapIndentation = Text2.WrapIndentation = Indent.Value ? 64 : 0;

            ir.OutlineRectangle(new Bounds(TopLeft, BottomRight), Color.Red);

            var layout = Text.Get();

            if (ShowOutlines.Value)
            {
                foreach (var dc in layout.DrawCalls)
                {
                    ir.OutlineRectangle(dc.EstimateDrawBounds(), Color.Blue);
                }
            }

            var m = Materials.Get(Materials.ScreenSpaceShadowedBitmap, blendState: BlendState.AlphaBlend);

            m.Parameters.ShadowColor.SetValue(new Vector4(0, 0, 0, 0.66f));
            m.Parameters.ShadowOffset.SetValue(new Vector2(3.5f, 3.5f));

            ir.OutlineRectangle(Bounds.FromPositionAndSize(Text.Position, layout.Size), Color.Yellow * 0.75f);
            ir.DrawMultiple(layout, material: m);

            if (Which.Value)
            {
                Text2.Position = TopLeft + new Vector2(0, layout.Size.Y + 20);
                layout         = Text2.Get();

                if (ShowOutlines.Value)
                {
                    foreach (var dc in layout.DrawCalls)
                    {
                        ir.OutlineRectangle(dc.EstimateDrawBounds(), Color.Blue);
                    }
                }

                ir.OutlineRectangle(Bounds.FromPositionAndSize(Text2.Position, layout.Size), Color.Yellow * 0.75f);
                ir.DrawMultiple(layout, material: m);
            }
        }
예제 #2
0
        private void DrawPerformanceStats(ref ImperativeRenderer ir)
        {
            const float scale = 1f;
            var         text  = PerformanceStats.GetText(this);

            using (var buffer = BufferPool <BitmapDrawCall> .Allocate(text.Length)) {
                var layout     = Font.LayoutString(text, buffer, scale: scale);
                var layoutSize = layout.Size;
                var position   = new Vector2(30f, 30f);
                var dc         = layout.DrawCalls;

                ir.FillRectangle(
                    Bounds.FromPositionAndSize(position, layoutSize),
                    Color.Black
                    );
                ir.Layer += 1;
                ir.DrawMultiple(dc, position);
            }
        }
예제 #3
0
        private void RasterizeAcceleratorOverlay(
            UIOperationContext context, ref ImperativeRenderer labelRenderer, ref ImperativeRenderer targetRenderer,
            Control control, AbstractString label, bool showFocused = false, Control forControl = null
            )
        {
            if (control == null)
            {
                return;
            }
            if (!showFocused && (control == Focused) && !label.IsNull && (label.Length > 0))
            {
                return;
            }
            if (label.Length <= 0)
            {
                return;
            }

            var box = control.GetRect();

            if ((box.Width <= 1) || (box.Height <= 1))
            {
                return;
            }

            var decorator = Decorations.AcceleratorTarget;
            var settings  = new Decorations.DecorationSettings {
                Box        = box,
                ContentBox = box
            };

            decorator.Rasterize(ref context, ref targetRenderer, settings);

            var outlinePadding = 1f;

            decorator = Decorations.AcceleratorLabel;
            Color?textColor = null;

            decorator.GetTextSettings(ref context, default(ControlStates), out Material material, ref textColor, out _);
            var layout    = decorator.GlyphSource.LayoutString(label, buffer: AcceleratorOverlayBuffer);
            var textScale = 1f;

            if (layout.Size.X > (box.Width - decorator.Padding.X))
            {
                textScale = Math.Max(0.25f, (box.Width - decorator.Padding.X) / layout.Size.X);
            }
            var scaledSize = layout.Size * textScale;

            var labelTraits = new DenseList <string> {
                "above"
            };
            var labelPosition = box.Position - new Vector2(0, scaledSize.Y + decorator.Padding.Y + outlinePadding);

            if (labelPosition.Y <= 0)
            {
                labelTraits[0] = "inside";
                labelPosition  = box.Position;
            }
            labelPosition.X = Arithmetic.Clamp(labelPosition.X, 0, CanvasSize.X - scaledSize.X);
            labelPosition.Y = Math.Max(0, labelPosition.Y);

            var labelBox = new RectF(
                labelPosition,
                scaledSize + decorator.Padding.Size
                );

            if (IsObstructedByAnyPreviousBox(ref labelBox, forControl))
            {
                labelBox.Left = box.Extent.X - labelBox.Width;
            }
            if (IsObstructedByAnyPreviousBox(ref labelBox, forControl))
            {
                labelTraits[0] = "below";
                labelBox.Left  = labelPosition.X;
                labelBox.Top   = box.Extent.Y + 1; // FIXME: Why the +1?
            }

            while (IsObstructedByAnyPreviousBox(ref labelBox, forControl))
            {
                labelTraits[0] = "stacked";
                labelBox.Left  = box.Left;
                labelBox.Width = box.Width;
                labelBox.Top   = labelBox.Extent.Y + 0.5f;
            }
            // HACK

            var labelContentBox = new RectF(
                labelBox.Position + new Vector2(decorator.Padding.Left, decorator.Padding.Top),
                scaledSize
                );

            settings = new Decorations.DecorationSettings {
                Box        = labelBox,
                ContentBox = box,
                Traits     = labelTraits
            };
            decorator.Rasterize(ref context, ref labelRenderer, settings);
            labelRenderer.DrawMultiple(layout.DrawCalls, offset: labelContentBox.Position.Floor(), scale: new Vector2(textScale), layer: 1);

            RasterizedOverlayBoxes.Add(new RasterizedOverlayBox {
                Control    = forControl,
                ControlBox = box,
                LabelBox   = labelBox
            });
        }