Exemplo n.º 1
0
        public override void Render(IStateOwner pOwner, Graphics pRenderTarget, MenuState Source, BaseDrawParameters Element)
        {
            //draw the header text,
            //then draw each menu item.
            //throw new NotImplementedException();
            Graphics g      = pRenderTarget;
            var      Bounds = Element.Bounds;

            if (Source.BG != null)
            {
                RenderingProvider.Static.DrawElement(pOwner, pRenderTarget, Source.BG, new GDIBackgroundDrawData(Bounds));
            }
            int   CurrentIndex = Source.StartItemOffset;
            float CurrentY = DrawHeader(pOwner, Source, g, Bounds);
            float MaxHeight = 0, MaxWidth = 0;

            //we want to find the widest item.
            foreach (var searchitem in Source.MenuElements)
            {
                if (searchitem is MenuStateSizedMenuItem mss)
                {
                    var sizehandler = RenderingProvider.Static.GetHandler(typeof(Graphics), searchitem.GetType(), typeof(MenuStateMenuItemGDIPlusDrawData));
                    if (sizehandler is ISizableMenuItemGDIPlusRenderingHandler isizer)

                    {
                        var grabsize = isizer.GetSize(pOwner, mss);
                        if (grabsize.Height > MaxHeight)
                        {
                            MaxHeight = grabsize.Height;
                        }
                        if (grabsize.Width > MaxWidth)
                        {
                            MaxWidth = grabsize.Width;
                        }
                    }
                }
            }
            //we draw each item at the maximum size.
            SizeF ItemSize = new SizeF(MaxWidth, MaxHeight);

            CurrentY += (float)(pOwner.ScaleFactor * 5);
            for (int menuitemindex = 0; menuitemindex < Source.MenuElements.Count; menuitemindex++)
            {
                var       drawitem     = Source.MenuElements[menuitemindex];
                Rectangle TargetBounds = new Rectangle((int)(Bounds.Width / 2 - ItemSize.Width / 2) + Source.MainXOffset, (int)CurrentY, (int)(ItemSize.Width), (int)(ItemSize.Height));
                MenuStateMenuItem.StateMenuItemState useState = menuitemindex == Source.SelectedIndex ? MenuStateMenuItem.StateMenuItemState.State_Selected : MenuStateMenuItem.StateMenuItemState.State_Normal;
                RenderingProvider.Static.DrawElement(pOwner, g, drawitem, new MenuStateMenuItemGDIPlusDrawData(TargetBounds, useState));
                //drawitem.Draw(pOwner, g, TargetBounds, useState);
                CurrentY += ItemSize.Height + 5;
            }
        }
Exemplo n.º 2
0
 public MenuStateMenuItemSkiaDrawData(SkiaSharp.SKRect pBounds, MenuStateMenuItem.StateMenuItemState pDrawState)
 {
     Bounds    = pBounds;
     DrawState = pDrawState;
 }
Exemplo n.º 3
0
 public MenuStateMenuItemGDIPlusDrawData(RectangleF pBounds, MenuStateMenuItem.StateMenuItemState pDrawState)
 {
     Bounds    = pBounds;
     DrawState = pDrawState;
 }
        public override void Render(IStateOwner pOwner, SKCanvas pRenderTarget, MenuState Source, GameStateSkiaDrawParameters Element)
        {
            //draw the header text,
            //then draw each menu item.
            //throw new NotImplementedException();
            SKCanvas g      = pRenderTarget;
            var      Bounds = Element.Bounds;

            if (Source.BG != null)
            {
                RenderingProvider.Static.DrawElement(pOwner, pRenderTarget, Source.BG, new SkiaBackgroundDrawData(Bounds));
            }
            int   CurrentIndex = Source.StartItemOffset;
            float CurrentY = DrawHeader(pOwner, Source, g, Bounds);
            float MaxHeight = 0, MaxWidth = 0;

            //we want to find the widest item.
            foreach (var searchitem in Source.MenuElements)
            {
                if (searchitem is MenuStateSizedMenuItem mss)
                {
                    var sizehandler = RenderingProvider.Static.GetHandler(typeof(SKCanvas), searchitem.GetType(), typeof(MenuStateMenuItemSkiaDrawData));
                    if (sizehandler is ISizableMenuItemSkiaRenderingHandler isizer)

                    {
                        var grabsize = isizer.GetSize(pOwner, mss);
                        grabsize = new SKPoint((float)(grabsize.X * pOwner.ScaleFactor * 2), (float)(grabsize.Y * pOwner.ScaleFactor * 2));
                        if (grabsize.Y > MaxHeight)
                        {
                            MaxHeight = grabsize.Y;
                        }
                        if (grabsize.X > MaxWidth)
                        {
                            MaxWidth = grabsize.X;
                        }
                    }
                }
            }
            //we draw each item at the maximum size.
            SKPoint ItemSize = new SKPoint(MaxWidth, MaxHeight);

            CurrentY += (float)(pOwner.ScaleFactor * 5);
            for (int menuitemindex = 0; menuitemindex < Source.MenuElements.Count; menuitemindex++)
            {
                var    drawitem     = Source.MenuElements[menuitemindex];
                var    XPos         = (int)(Bounds.Width / 2 - ItemSize.X / 2) + Source.MainXOffset;
                SKRect TargetBounds = new SKRect(XPos, (int)CurrentY, XPos + (int)(ItemSize.X), CurrentY + (int)(ItemSize.Y));
                MenuStateMenuItem.StateMenuItemState useState = menuitemindex == Source.SelectedIndex ? MenuStateMenuItem.StateMenuItemState.State_Selected : MenuStateMenuItem.StateMenuItemState.State_Normal;
                RenderingProvider.Static.DrawElement(pOwner, g, drawitem, new MenuStateMenuItemSkiaDrawData(TargetBounds, useState));
                //drawitem.Draw(pOwner, g, TargetBounds, useState);
                CurrentY += ItemSize.Y + 5;
            }
            if (CursorBitmap == null)
            {
                CursorBitmap = TetrisGame.Imageman.GetSKBitmap("cursor");

                /*var CursorImage = SkiaSharp.Views.Desktop.Extensions.ToSKImage(new System.Drawing.Bitmap(TetrisGame.Imageman["cursor"]));
                 *
                 * SKImageInfo CursorInfo = new SKImageInfo(CursorImage.Width, CursorImage.Height, SKColorType.Bgra8888, SKAlphaType.Premul);
                 * var skversion = new SKBitmap(CursorInfo);
                 * using (SKCanvas canvo = new SKCanvas(skversion))
                 * {
                 *  canvo.Clear(SKColors.Transparent);
                 *  canvo.DrawImage(CursorImage, new SKPoint(0, 0));
                 * }
                 * CursorBitmap = skversion;*/
            }


            g.DrawBitmap(CursorBitmap, Source.LastMouseMovement, null);
        }