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);
        }
Esempio n. 2
0
        public void Render(IStateOwner pOwner, SKCanvas pRenderTarget, CharParticle Source, GameStateSkiaDrawParameters Element)
        {
            var Alphause           = TranslateAlpha(Source);
            var CharPoint          = TranslatePosition(pOwner, pRenderTarget, Source.Position, Element);
            var FontSizeTranslate  = new BCPoint(1, Source.FontInfo.FontSize);
            var TranslatedFontSize = TranslatePosition(pOwner, pRenderTarget, FontSizeTranslate, Element);
            var useColor           = new SKColor(Source.Color.R, Source.Color.G, Source.Color.B, Alphause);

            SKRect Bound = new SKRect();

            skp.MeasureText(Source.Text, ref Bound);
            skp.TextSize = TranslatedFontSize.Y;
            SKPaint Foreground = new SKPaint()
            {
                Color = useColor, TextSize = TranslatedFontSize.Y, Typeface = TetrisGame.RetroFontSK
            };
            SKPaint Background = new SKPaint()
            {
                Color = new SKColor(0, 0, 0, Alphause), TextSize = TranslatedFontSize.Y, Typeface = TetrisGame.RetroFontSK
            };
            DrawTextInformationSkia skinfo = new DrawTextInformationSkia()
            {
                Text             = Source.Text,
                Position         = CharPoint,
                CharacterHandler = new DrawCharacterHandlerSkia(new VerticalWavePositionCharacterPositionCalculatorSkia()
                {
                    Height = (float)(pOwner.ScaleFactor * 6)
                }),
                ForegroundPaint = Foreground,
                ShadowPaint     = Background
            };

            skinfo.DrawFont = new SKFontInfo(TetrisGame.RetroFontSK, TranslatedFontSize.Y);
            //pRenderTarget.DrawText(Source.Text, CharPoint.X,CharPoint.Y,TetrisGame.RetroFontSK,  skp);
            //pRenderTarget.DrawTextSK(Source.Text, CharPoint, TetrisGame.RetroFontSK, useColor, skp.TextSize,1);
            SKMatrix cloned = SKMatrix.Identity;

            if (Source.Angle != 0)
            {
                cloned = pRenderTarget.TotalMatrix;
                pRenderTarget.RotateDegrees((float)Source.Angle);
            }

            pRenderTarget.DrawTextSK(skinfo);

            if (Source.Angle != 0)
            {
                pRenderTarget.SetMatrix(cloned);
            }
            //CharPoint -= new BCPoint(skp)
            //    skp.MeasureText(Source.Character);
        }
Esempio n. 3
0
        public static void DrawTextSK(this SKCanvas g, DrawTextInformationSkia DrawData)
        {
            var characterpositions = MeasureCharacterSizes(DrawData.ForegroundPaint, DrawData.Text);

            char[] drawcharacters = DrawData.Text.ToCharArray();
            foreach (int pass in new[] { 1, 2 })
            {
                for (int i = 0; i < drawcharacters.Length; i++)
                {
                    char    drawcharacter = drawcharacters[i];
                    SKPoint DrawPosition  = new SKPoint(characterpositions[i].Left + DrawData.Position.X, characterpositions[i].Top + DrawData.Position.Y);
                    DrawData.CharacterHandler.DrawCharacter(g, drawcharacter, DrawData, DrawPosition, new SKPoint(characterpositions[i].Size.Width, characterpositions[i].Size.Height), i, drawcharacters.Length, pass);
                }
            }
        }
Esempio n. 4
0
        public override void Render(IStateOwner pOwner, SKCanvas pRenderTarget, ViewScoreDetailsState Source, GameStateSkiaDrawParameters Element)
        {
            //TODO: finish this!
            var g      = pRenderTarget;
            var Bounds = Element.Bounds;

            //Draw the background first.
            RenderingProvider.Static.DrawElement(pOwner, pRenderTarget, Source.BG, new SkiaBackgroundDrawData(Bounds));

            DrawTextInformationSkia skdraw = new DrawTextInformationSkia()
            {
                ForegroundPaint = new SKPaint()
            };

            float StartY   = (Bounds.Height * 0.175f);
            var   CurrentY = StartY;
            float MiddleX  = Bounds.Width / 2;

            float   TextSize      = Bounds.Height / 30f;
            var     ScoreFont     = TetrisGame.RetroFontSK; //point size 24.
            SKPaint MainScoreFont = new SKPaint()
            {
                Typeface = ScoreFont, TextSize = (float)(24 * pOwner.ScaleFactor), Color = SKColors.Black
            };
            SKPaint ShadowScoreFont = new SKPaint()
            {
                Typeface = ScoreFont, TextSize = (float)(24 * pOwner.ScaleFactor), Color = SKColors.White
            };
            SKPaint ListingFont = new SKPaint()
            {
                Typeface = ScoreFont, TextSize = (float)(18 * pOwner.ScaleFactor), Color = SKColors.Black
            };
            float   PercentThroughSecond = (float)DateTime.Now.Millisecond / 1000f;
            SKPaint ListingFontRainbow   = new SKPaint()
            {
                Typeface = ScoreFont, TextSize = (float)(18 * pOwner.ScaleFactor), Color = SKColor.FromHsl(PercentThroughSecond * 240, 240, 120)
            };
            SKPaint ListingFontShadow = new SKPaint()
            {
                Typeface = ScoreFont, TextSize = (float)(18 * pOwner.ScaleFactor), Color = SKColors.White
            };
            SKPaint ListingFontArrow = new SKPaint()
            {
                Typeface = TetrisGame.ArialFontSK, TextSize = (float)(18 * pOwner.ScaleFactor), Color = SKColor.FromHsl(PercentThroughSecond * 240, 240, 120)
            };
            SKPaint ListingFontArrowShadow = new SKPaint()
            {
                Typeface = TetrisGame.ArialFontSK, TextSize = (float)(18 * pOwner.ScaleFactor), Color = SKColors.White
            };
            SKRect resultitem = new SKRect();
            float  LineHeight = MainScoreFont.MeasureText("#", ref resultitem);
            var    useShader  = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(0, Bounds.Height), new SKColor[] { SKColors.Red, SKColors.Orange, SKColors.Yellow, SKColors.Green, SKColors.Blue, SKColors.Indigo, SKColors.Violet }, null, SKShaderTileMode.Mirror);

            SKPaint LinePaint = new SKPaint()
            {
                BlendMode = SKBlendMode.ColorBurn, StrokeWidth = 24, Shader = useShader
            };

            g.DrawRect(new SKRect(0, 0, Bounds.Width, Bounds.Height), LinePaint);
            //g.DrawRect(new SKRect((int)(Bounds.Width * (1 / 7)), CurrentY, (float)(Bounds.Width - (Bounds.Width * (1 / 7))), (float)(CurrentY + (LineHeight * 2.5) + (LineHeight * 3) * 12)),LinePaint);



            if (Source.IncrementedDrawState >= 0)
            {
                //draw "SCORE DETAILS"
                String sHeaderText  = "SCORE DETAILS";
                SKRect MeasuredRect = new SKRect();
                MainScoreFont.MeasureText(sHeaderText, ref MeasuredRect);
                SKPoint DrawPosition = new SKPoint(MiddleX - (MeasuredRect.Width / 2), StartY);
                g.DrawText(sHeaderText, new SKPoint(DrawPosition.X + 2, DrawPosition.Y + 2), ShadowScoreFont);
                g.DrawText(sHeaderText, DrawPosition, MainScoreFont);
                CurrentY = StartY + MeasuredRect.Height + 10;
            }

            if (Source.IncrementedDrawState >= 1)
            {
                //maybe a line under the header.
            }

            if (Source.IncrementedDrawState >= 2)
            {
                switch (Source.CurrentView)
                {
                case ViewScoreDetailsState.ViewScoreDetailsType.Details_Tetrominoes:
                    DrawTetronimoDetails(Source, g, Bounds, CurrentY);
                    break;

                case ViewScoreDetailsState.ViewScoreDetailsType.Details_LevelTimes:
                    DrawLevelTimesDetails(Source, g, Bounds, CurrentY);
                    break;
                }
                //draw the high score listing entries.
                //iterate from 2 to drawstate and draw the high score at position drawstate-2.

                /*for (int scoreiterate = 2; scoreiterate < Source.IncrementedDrawState; scoreiterate++)
                 * {
                 *  int CurrentScoreIndex = scoreiterate - 2;
                 *  int CurrentScorePosition = CurrentScoreIndex + 1;
                 *  double useYPosition = StartY + (LineHeight * 2.5) + (LineHeight * 3) * CurrentScoreIndex;
                 *  double useXPosition = Bounds.Width * 0.19d;
                 *  String sUseName = "N/A";
                 *  int sUseScore = 0;
                 *  IHighScoreEntry currentScore = Source.hs.Count > CurrentScoreIndex ? Source.hs[CurrentScoreIndex] : null;
                 *  if (currentScore != null)
                 *  {
                 *      sUseName = currentScore.Name;
                 *      sUseScore = currentScore.Score;
                 *  }
                 *  SKRect MeasureName = new SKRect(), MeasureScore = new SKRect();
                 *  ListingFont.MeasureText(sUseName, ref MeasureName);
                 *  ListingFont.MeasureText(sUseScore.ToString(), ref MeasureScore);
                 *  float PosXPosition = Bounds.Width * 0.1f;
                 *  float NameXPosition = Bounds.Width * 0.20f;
                 *  float ScoreXPositionRight = Bounds.Width * (1 - 0.10f);
                 *  var useForegroundPaint = Source.HighlightedScorePositions.Contains(CurrentScorePosition) ? ListingFontRainbow : ListingFont;
                 *
                 *  //draw position
                 *  g.DrawText(CurrentScorePosition.ToString() + ".", new SKPoint(PosXPosition + 2, (float)useYPosition + 2), ListingFontShadow);
                 *  g.DrawText(CurrentScorePosition.ToString() + ".", new SKPoint(PosXPosition, (float)useYPosition), useForegroundPaint);
                 *  //draw high score name
                 *  g.DrawText(sUseName, new SKPoint(PosXPosition + 2 + Math.Abs(resultitem.Height) * 2.25f, (float)useYPosition + 2), ListingFontShadow);
                 *  g.DrawText(sUseName, new SKPoint(PosXPosition + Math.Abs(resultitem.Height) * 2.25f, (float)useYPosition), useForegroundPaint);
                 *
                 *  //draw the high score
                 *  float ScoreXPosition = ScoreXPositionRight - MeasureScore.Width;
                 *
                 *  g.DrawText(sUseScore.ToString(), new SKPoint(ScoreXPosition + 2, (float)useYPosition + 2), ListingFontShadow);
                 *  g.DrawText(sUseScore.ToString(), new SKPoint(ScoreXPosition, (float)useYPosition), useForegroundPaint);
                 *  useForegroundPaint.StrokeWidth = 6;
                 *
                 *  g.DrawLine(new SKPoint(NameXPosition + MeasureName.Width + 15, (float)useYPosition + LineHeight / 2), new SKPoint(ScoreXPosition - 15, (float)useYPosition + LineHeight / 2), useForegroundPaint);
                 *
                 *  if (Source.SelectedScorePosition == CurrentScoreIndex)
                 *  {
                 *      //draw selection indicator if needed
                 *      SKRect MeasureArrow = new SKRect();
                 *      useForegroundPaint.MeasureText(PointerText, ref MeasureArrow);
                 *      float ArrowX = PosXPosition - MeasureArrow.Width - 5;
                 *      float ArrowY = (float)useYPosition;
                 *      g.DrawText(PointerText, new SKPoint(ArrowX + 2, ArrowY + 2), ListingFontArrowShadow);
                 *      g.DrawText(PointerText, new SKPoint(ArrowX, ArrowY), ListingFontArrow);
                 *  }
                 * }*/
            }

            /*
             *
             * Font HeaderFont = TetrisGame.GetRetroFont(24, pOwner.ScaleFactor);
             * Font PlacementFont = TetrisGame.GetRetroFont(10, pOwner.ScaleFactor);
             * Font DetailFont = TetrisGame.GetRetroFont(8, pOwner.ScaleFactor);
             *
             *
             * //One thing we draw in every case is the "--SCORE DETAILS--" header text. this is positioned at 5% from the top, centered in the middle of our bounds.
             * float Millipercent = (float)DateTime.Now.Ticks / 5000f; //(float)DateTime.Now.Millisecond / 1000;
             *
             * var MeasuredHeader = g.MeasureString(Source._DetailHeader, HeaderFont);
             * int RotateAmount = (int)(Millipercent * 240);
             * Color UseColor1 = HSLColor.RotateHue(Color.Red, RotateAmount);
             * Color UseColor2 = HSLColor.RotateHue(Color.LightPink, RotateAmount);
             * PointF ScorePosition = new PointF((Bounds.Width / 2) - (MeasuredHeader.Width / 2), Bounds.Height * 0.05f);
             * using (LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(0, 0, (int)MeasuredHeader.Width, (int)MeasuredHeader.Height), UseColor1, UseColor2, LinearGradientMode.Vertical))
             * {
             *  using (GraphicsPath gp = new GraphicsPath())
             *  {
             *      gp.AddString(Source._DetailHeader, HeaderFont, new Point((int)ScorePosition.X, (int)ScorePosition.Y), StringFormat.GenericDefault);
             *      g.FillPath(lgb, gp);
             *      g.DrawPath(Pens.White, gp);
             *  }
             * }
             *
             * //we also show Xth Place - <NAME> centered below the header using the placementfont.
             * String sPlacement = TetrisGame.FancyNumber(Source._Position) + " - " + Source.ShowEntry.Name + " - " + Source.ShowEntry.Score.ToString();
             *
             * var measureit = g.MeasureString(sPlacement, PlacementFont);
             *
             * PointF DrawPlacement = new PointF(Bounds.Width / 2 - measureit.Width / 2, (float)(ScorePosition.Y + MeasuredHeader.Height * 1.1f));
             *
             * g.DrawString(sPlacement, PlacementFont, Brushes.Black, DrawPlacement.X + 3, DrawPlacement.Y + 3);
             * g.DrawString(sPlacement, PlacementFont, Brushes.White, DrawPlacement.X, DrawPlacement.Y);
             *
             * g.DrawLine(Separator, (float)(Bounds.Width * 0.05f), (float)(DrawPlacement.Y + measureit.Height + 5), (float)(Bounds.Width * 0.95), (float)(DrawPlacement.Y + measureit.Height + 5));
             *
             *
             * switch (Source.CurrentView)
             * {
             *  case ViewScoreDetailsState.ViewScoreDetailsType.Details_Tetrominoes:
             *      DrawTetronimoDetails(Source, g, Bounds);
             *      break;
             *  case ViewScoreDetailsState.ViewScoreDetailsType.Details_LevelTimes:
             *      DrawLevelTimesDetails(Source, g, Bounds);
             *      break;
             * }
             */
        }
        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);
        }
        public void Render(IStateOwner pOwner, SKCanvas pRenderTarget, MenuStateTextMenuItem Source, MenuStateMenuItemSkiaDrawData Element)
        {
            var useFont     = GetScaledFont(pOwner, Source.FontSize);
            var MeasureText = TetrisGame.MeasureSKText(useFont.TypeFace, useFont.FontSize, Source.Text);


            SKPoint DrawPosition = GetDrawPosition(Element.Bounds, MeasureText, Source.TextAlignment);
            SKPaint BackPaint    = null;


            if (Element.DrawState == MenuStateMenuItem.StateMenuItemState.State_Selected)
            {
                BackPaint = new SKPaint()
                {
                    Color = SKColors.DarkBlue
                }
            }
            ;
            else
            {
                BackPaint = new SKPaint()
                {
                    Color = SkiaSharp.Views.Desktop.Extensions.ToSKColor(Source.BackColor)
                }
            };
            pRenderTarget.DrawRect(Element.Bounds, BackPaint);


            SKPaint ForePaint  = null;
            SKPaint ShadePaint = null;

            if (Element.DrawState == MenuStateMenuItem.StateMenuItemState.State_Selected)
            {
                ForePaint = new SKPaint()
                {
                    Color = SKColors.Aqua
                }
            }
            ;
            else
            {
                ForePaint = new SKPaint()
                {
                    Color = SkiaSharp.Views.Desktop.Extensions.ToSKColor(Source.ForeColor), TextAlign = SKTextAlign.Center
                }
            };

            ShadePaint = new SKPaint()
            {
                Color = SkiaSharp.Views.Desktop.Extensions.ToSKColor(Source.ShadowColor), TextAlign = SKTextAlign.Center
            };


            ForePaint.Typeface  = useFont.TypeFace;
            ForePaint.TextSize  = (int)(Source.FontSize * pOwner.ScaleFactor);
            ShadePaint.Typeface = useFont.TypeFace;
            ShadePaint.TextSize = (int)(Source.FontSize * pOwner.ScaleFactor);

            var useStyle = new DrawTextInformationSkia()
            {
                Text            = Source.Text,
                BackgroundPaint = new SKPaint()
                {
                    Color = SKColors.Transparent
                },
                DrawFont        = useFont,
                ForegroundPaint = ForePaint,
                ShadowPaint     = ShadePaint,
                Position        = new SKPoint(DrawPosition.X, DrawPosition.Y + MeasureText.Height / 2),
                ShadowOffset    = new SKPoint(5f, 5f),
            };

            if (Element.DrawState == MenuStateMenuItem.StateMenuItemState.State_Selected)
            {
                useStyle.CharacterHandler.SetPositionCalculator(new RotatingPositionCharacterPositionCalculatorSkia());
            }

            pRenderTarget.DrawTextSK(useStyle);


            //            TetrisGame.DrawText(Target, useFont, Text, ForeBrush, ShadowBrush, DrawPosition.X, DrawPosition.Y, 5f, 5f, central);

            //Cheating...
            // Source.Draw(pOwner,pRenderTarget,Element.Bounds,Element.DrawState);
        }