コード例 #1
0
        public void Render(IStateOwner pOwner, SKCanvas pRenderTarget, MenuStateMultiOption Source, MenuStateMenuItemSkiaDrawData Element)
        {
            SKFontInfo useFont       = MenuStateTextMenuItemSkiaRenderer.GetScaledFont(pOwner, Source.FontSize);
            var        OptionManager = Source.OptionManagerBase;
            var        Bounds        = Element.Bounds;
            String     sLeftCover    = "< ";
            String     sRightCover   = ">";

            var PrevItem = OptionManager.GetTextBase(OptionManager.PeekPreviousBase());
            var NextItem = OptionManager.GetTextBase(OptionManager.PeekNextBase());

            sLeftCover  = PrevItem + sLeftCover;
            sRightCover = sRightCover + NextItem;

            SKPaint Foreground = new SKPaint()
            {
                Color = SkiaSharp.Views.Desktop.Extensions.ToSKColor(Source.ForeColor)
            };
            SKPaint Background = new SKPaint()
            {
                Color = SkiaSharp.Views.Desktop.Extensions.ToSKColor(Source.BackColor)
            };
            SKPaint Shadow = new SKPaint()
            {
                Color = SkiaSharp.Views.Desktop.Extensions.ToSKColor(Source.ShadowColor)
            };
            DrawTextInformationSkia dtis = new DrawTextInformationSkia()
            {
                ForegroundPaint = Foreground, BackgroundPaint = Background, ShadowPaint = Shadow
            };

            dtis.DrawFont = new SKFontInfo(TetrisGame.RetroFontSK, Source.FontSize);
            //TODO: need to get this implemented via a SKPaint, but the TextMenu item should probably have draw data in an "abstracted" form...
            SKRect MeasureLeft  = new SKRect();
            SKRect MeasureRight = new SKRect();

            Foreground.MeasureText(sLeftCover, ref MeasureLeft);

            Foreground.MeasureText(sRightCover, ref MeasureRight);
            //var MeasureLeft = pRenderTarget.MeasureString(sLeftCover, useFont);
            //var MeasureRight = pRenderTarget.MeasureString(sRightCover, useFont);
            SKPoint LeftPos  = new SKPoint(Bounds.Left - MeasureLeft.Width, Bounds.Top + (Bounds.Height / 2) - MeasureLeft.Height / 2);
            SKPoint RightPos = new SKPoint(Bounds.Right, Bounds.Top + (Bounds.Height / 2) - MeasureRight.Height / 2);


            if (Source.Activated)
            {
                dtis.Text = sLeftCover;
                pRenderTarget.DrawTextSK(dtis);
                dtis.Text = sRightCover;
                pRenderTarget.DrawTextSK(dtis);
            }
            base.Render(pOwner, pRenderTarget, Source, Element);
        }
コード例 #2
0
        public override void DrawCharacter(SKCanvas g, char character, DrawTextInformationSkia DrawData, SKPoint Position, SKPoint CharacterSize, int CharacterNumber, int TotalCharacters, int Pass)
        {
            if (DrawData.PreDrawData != null)
            {
                DrawCharacter(g, character, DrawData.PreDrawData, Position, CharacterSize, CharacterNumber, TotalCharacters, Pass);
            }
            //adjust positioning by calling each extension.
            foreach (var iterate in _Extensions)
            {
                iterate.AdjustPositioning(ref Position, CharacterSize, DrawData, CharacterNumber, TotalCharacters, Pass);
            }
            SKPoint AddedOffset = Pass == 1 ? SKPoint.Empty : DrawData.ShadowOffset;
            SKPaint DrawBrush   = Pass == 1 ? DrawData.ShadowPaint: DrawData.ForegroundPaint;

            //call beforedraw...
            foreach (var iterate in _Extensions)
            {
                iterate.BeforeDraw(g, character, DrawData, Position, CharacterSize, CharacterNumber, TotalCharacters, Pass);
            }
            SKFontInfo UseFont = new SKFontInfo(DrawData.DrawFont);

            SKPoint DrawPosition = new SKPoint(Position.X + AddedOffset.X, Position.Y + AddedOffset.Y);

            if (DrawData.ScalePercentage != 1)
            {
                UseFont.FontSize = UseFont.FontSize * DrawData.ScalePercentage;
                float NewWidth  = CharacterSize.X * DrawData.ScalePercentage;
                float NewHeight = CharacterSize.Y * DrawData.ScalePercentage;
                AddedOffset.X -= ((NewWidth - CharacterSize.X)) / 2;
                AddedOffset.Y -= ((NewHeight - CharacterSize.Y)) / 2;
            }

            g.DrawText(character.ToString(), DrawPosition, DrawBrush);

            foreach (var iterate in _Extensions.Reverse())
            {
                iterate.AfterDraw(g, character, DrawData, Position, CharacterSize, CharacterNumber, TotalCharacters, Pass);
            }
            if (DrawData.PostDrawData != null)
            {
                DrawCharacter(g, character, DrawData.PostDrawData, Position, CharacterSize, CharacterNumber, TotalCharacters, Pass);
            }
        }
コード例 #3
0
        public virtual float DrawHeader(IStateOwner pOwner, MenuState Source, SKCanvas Target, SKRect Bounds)
        {
            if (Source.StateHeader == "Options")
            {
                Source.StateHeader = "Menu";
            }
            if (String.IsNullOrEmpty(Source.StateHeader))
            {
                return(0);
            }
            SKFontInfo useHeaderFont = GetScaledHeaderFont(pOwner, Source);

            Painter = new SKPaint()
            {
                Color = SKColors.Black
            };
            BackPainter = new SKPaint()
            {
                Color = SKColors.White
            };
            BackPainter.Typeface = Painter.Typeface = useHeaderFont.TypeFace;
            BackPainter.TextSize = Painter.TextSize = (float)(useHeaderFont.FontSize * pOwner.ScaleFactor);


            SKRect HeaderSize = new SKRect();

            Painter.MeasureText(Source.StateHeader ?? "", ref HeaderSize);
            while (HeaderSize.Width > Bounds.Width)
            {
                BackPainter.TextSize = Painter.TextSize = BackPainter.TextSize * .9f;
                Painter.MeasureText(Source.StateHeader ?? "", ref HeaderSize);
            }
            float UseX = (Bounds.Width / 2) - (HeaderSize.Width / 2) + Source.MainXOffset;
            float UseY = HeaderSize.Height * 3f;
            DrawTextInformationSkia sktext = new DrawTextInformationSkia();

            sktext.CharacterHandler = new DrawCharacterHandlerSkia(new VerticalWavePositionCharacterPositionCalculatorSkia()
            {
                Height = HeaderSize.Height / 2
            });
            sktext.ShadowPaint     = BackPainter;
            sktext.ForegroundPaint = Painter;
            sktext.BackgroundPaint = new SKPaint()
            {
                Color = SKColors.Transparent
            };
            sktext.Text            = Source.StateHeader ?? "";
            sktext.ScalePercentage = 1;
            sktext.DrawFont        = useHeaderFont;
            sktext.Position        = new SKPoint(UseX, UseY);

            try
            {
                Target.DrawTextSK(sktext);
            }
            catch (Exception exr)
            {
                ;
            }
            //paint foreground.
            //Target.DrawText(Source.StateHeader ?? "", new SKPoint(UseX + 5, UseY + 5), BackPainter);
            //Target.DrawText(Source.StateHeader ?? "", new SKPoint(UseX, UseY), Painter);


            //TetrisGame.DrawTextSK(Target, Source.StateHeader,new SKPoint(UseX, UseY), useHeaderFont, SKColors.Black, SKColors.White);

            return(UseY + HeaderSize.Height);
        }
コード例 #4
0
 public SKFontInfo(SKFontInfo Source)
 {
     TypeFace = Source.TypeFace;
     FontSize = Source.FontSize;
 }