Пример #1
0
        public CarouselExample2Canvas()
        {
            Width  = DefaultWidth;
            Height = DefaultHeight;


            Colors.Black.ToGradient(Colors.Red, DefaultHeight / 4).Select(
                (c, i) =>
                new Rectangle
            {
                Fill   = new SolidColorBrush(c),
                Width  = DefaultWidth,
                Height = 4,
            }.MoveTo(0, i * 4).AttachTo(this)
                ).ToArray();


            var cc = new SimpleCarouselControl(DefaultWidth, DefaultHeight);


            new AvalonCarouselControlExample.Avalon.Images.Preview().AttachTo(this).Orphanize();

            new Image[]
            {
                new AvalonCarouselControlExample.Avalon.Images.item1(),
                new AvalonCarouselControlExample.Avalon.Images.item2(),
                new AvalonCarouselControlExample.Avalon.Images.item3(),
                new AvalonCarouselControlExample.Avalon.Images.Preview(),
            }.WithEachIndex(
                (Image k, int index) =>
            {
                cc.AddEntry(
                    new SimpleCarouselControl.EntryInfo
                {
                    Click      = cc.Timer.Toggle,
                    Source     = k.Source,
                    Position   = Math.PI / 2 * index,
                    MouseEnter =
                        delegate
                    {
                        cc.Caption.Text = k.GetType().Name;
                    },
                    MouseLeave =
                        delegate
                    {
                        cc.Caption.Clear();
                    }
                }
                    );
            }
                );



            cc.AttachContainerTo(this);


            cc.Overlay.AttachTo(this);
        }
Пример #2
0
        public GameMenu(int Width, int Height, int ShadowHeight)
        {
            this.ContentHeight = Height * 3 / 4;

            this.Container = new Canvas
            {
                Width  = Width,
                Height = ContentHeight + ShadowHeight,
                Name   = "GameMenu_Container",
            };

            var ShadowContainer = new Canvas
            {
                Width   = Width,
                Height  = ContentHeight + ShadowHeight,
                Opacity = 0.5,
                Name    = "GameMenu_ShadowContainer",
            }.AttachTo(this.Container);

            new Rectangle
            {
                Fill   = Brushes.Black,
                Width  = Width,
                Height = ContentHeight,
            }.MoveTo(0, 0).AttachTo(ShadowContainer);



            Colors.Black.ToTransparentGradient(ShadowHeight).Select(
                (c, i) =>
            {
                return(new Rectangle
                {
                    Fill = new SolidColorBrush(c),
                    Width = Width,
                    Height = 1,
                    Opacity = c.A / 255.0
                }.MoveTo(0, ContentHeight + i).AttachTo(ShadowContainer));
            }
                ).ToArray();



            this.Carousel = new SimpleCarouselControl(Width, ContentHeight).MoveContainerTo(0, 0);



            Carousel.Caption.FontSize = 36;
            Carousel.Caption.Height   = 60;
            Carousel.Caption.Text     = IdleText;

            Action <int, int> AnimatedShadowOpacity = NumericEmitter.Of(
                (x, y) => ShadowContainer.Opacity = x * 0.01
                );

            var ShadowOpacity = 50;

            AnimatedShadowOpacity(ShadowOpacity, 0);


            Carousel.Hover +=
                delegate
            {
                ShadowOpacity = 70;
                AnimatedShadowOpacity(ShadowOpacity, 0);
            };

            Carousel.Idle +=
                delegate
            {
                Carousel.Caption.Text = IdleText;
                ShadowOpacity         = 50;
                AnimatedShadowOpacity(ShadowOpacity, 0);
            };

            this.Options.ForEachNewItem(
                e =>
            {
                double p = 0;

                this.Where(k => k != e).LastOrDefault().Apply(k => p = k.CarouselEntry.Position + k.MarginAfter);

                e.CarouselEntry = new SimpleCarouselControl.EntryInfo
                {
                    Source   = e.Source,
                    Text     = e.Text,
                    Position = p + e.MarginBefore,
                    Click    =
                        delegate
                    {
                        if (e.Click != null)
                        {
                            e.Click();
                        }

                        if (e.Hyperlink != null)
                        {
                            e.Hyperlink.NavigateTo();
                        }
                    }
                };

                Carousel.AddEntry(e.CarouselEntry);
            }
                );



            Carousel.AttachContainerTo(this);

            Carousel.Overlay.AttachTo(this);



            Action <int, int> AnimatedTop = NumericEmitter.Of(
                (x, y) =>
            {
                this.Container.MoveTo(0, y);

                if (AfterMove != null)
                {
                    AfterMove(x, y);
                }
            }
                );

            this.MoveContainerTo(0, -ContentHeight);
            AnimatedTop(0, -ContentHeight);

            this.Show = delegate
            {
                this.Carousel.Timer.Start();
                this.Carousel.Show();
                AnimatedTop(0, 0);

                AnimatedShadowOpacity(ShadowOpacity, 0);
            };

            this.Hide = delegate
            {
                this.Carousel.Hide();
                this.Carousel.Timer.Stop();

                AnimatedTop(0, -ContentHeight);
                AnimatedShadowOpacity(50, 0);
            };

            var Delayed = this.Container.ToDelayedMouseEvents();

            Delayed.ValidateMouseEnter = () => ValidateShow();
            Delayed.ValidateMouseLeave = () => ValidateHide();
            Delayed.MouseEnter        += Show;
            Delayed.MouseLeave        += Hide;



            ShadowContainer.Opacity = 0;
        }
        public AvalonExampleGalleryCanvas(bool EnableBackground, Func <string, OptionPosition> GetOptionPosition)
        {
            Width  = DefaultWidth;
            Height = DefaultHeight;



            var navbar = new AeroNavigationBar();

            var Container = new Canvas
            {
                Width  = DefaultWidth,
                Height = DefaultHeight,
                Name   = "AvalonExampleGalleryCanvas_Container"
            }.AttachTo(this);

            Container.ClipTo(0, 0, DefaultWidth, DefaultHeight);

            var Pages = new Canvas
            {
                Width  = DefaultWidth,
                Height = DefaultHeight,
                Name   = "AvalonExampleGalleryCanvas_Pages"
            }.AttachTo(this);


            var CarouselPages = new Canvas
            {
                Width  = DefaultWidth,
                Height = DefaultHeight,
                Name   = "AvalonExampleGalleryCanvas_CarouselPages"
            }.AttachTo(this);

            var Overlay = new Canvas
            {
                Width  = DefaultWidth,
                Height = DefaultHeight,
                Name   = "AvalonExampleGalleryCanvas_Overlay"
            }.AttachTo(this);


            if (EnableBackground)
            {
                #region background
                var bg = new TiledBackgroundImage(
                    "assets/AvalonExampleGallery/bg.png".ToSource(),
                    96,
                    96,
                    9,
                    8
                    ).AttachContainerTo(Container);


                #endregion
            }


            var Toolbar = new Canvas
            {
                Width   = DefaultWidth,
                Height  = navbar.Height,
                Opacity = 0,
                Name    = "Toolbar"
            }.AttachTo(this);

            1000.AtDelay(
                Toolbar.FadeIn
                );

            #region shadow
            Colors.Black.ToTransparentGradient(40).Select(
                (c, i) =>
            {
                return(new Rectangle
                {
                    Fill = new SolidColorBrush(c),
                    Width = DefaultWidth,
                    Height = 1,
                    Opacity = c.A / 255.0
                }.MoveTo(0, i).AttachTo(Toolbar));
            }
                ).ToArray();
            #endregion

            var          cc         = new SimpleCarouselControl(DefaultWidth, DefaultHeight);
            const string cc_Caption = "Click on a thumbnail!";

            cc.Caption.Text = cc_Caption;
            cc.Timer.Stop();

            var btnCarouselCanvas = new Canvas
            {
                Width  = 128,
                Height = 32,
            }.AttachTo(this).MoveTo(DefaultWidth - 128, 4);


            #region Options
            var AllPages = KnownPages.Value;

            AllPages.ForEach(
                (k, i) =>
            {
                var o = new OptionWithShadowAndType(k.Key, k.Value);


                var ce = new SimpleCarouselControl.EntryInfo
                {
                    Source     = (k.Key + "/Preview.png").ToSource(),
                    Position   = i * Math.PI * 2 / AllPages.Count,
                    MouseEnter =
                        delegate
                    {
                        cc.Caption.Text = o.Caption.Text;
                    },
                    MouseLeave =
                        delegate
                    {
                        cc.Caption.Text = cc_Caption;
                    },
                    Click =
                        delegate
                    {
                        o.InitializeHint();


                        navbar.History.Add(
                            delegate
                        {
                            cc.Timer.Start();
                            o.Target.Orphanize();
                            CarouselPages.Show();
                            Overlay.Show();
                            btnCarouselCanvas.Show();
                        },
                            delegate
                        {
                            if (AtViewSelected != null)
                            {
                                AtViewSelected(o.Caption.Text);
                            }


                            btnCarouselCanvas.Hide();
                            cc.Timer.Stop();
                            CarouselPages.Hide();
                            Overlay.Hide();
                            o.Target.AttachTo(Container);
                        }
                            );
                    }
                };

                cc.AddEntry(ce);


                OptionPosition p = null;

                if (GetOptionPosition != null)
                {
                    p = GetOptionPosition(o.Caption.Text);
                }

                if (p == null)
                {
                    o.MoveTo(
                        48 + (180) * (i % 4),
                        36 + Convert.ToInt32(i / 4) * 128
                        );
                }
                else
                {
                    p.Clear();

                    o.MoveTo(
                        p.X,
                        p.Y
                        );
                }

                o.AttachContainerTo(Pages);
                o.Overlay.AttachTo(Overlay);

                o.TargetInitialized +=
                    delegate
                {
                    o.Target.MoveTo(
                        (DefaultWidth - o.Target.Width) / 2,
                        (DefaultHeight - o.Target.Height) / 2
                        );

                    //o.Target.ClipTo(0, 0, Convert.ToInt32( o.Target.Width), Convert.ToInt32(o.Target.Height));
                };

                o.Click +=
                    delegate
                {
                    navbar.History.Add(
                        delegate
                    {
                        o.Target.Orphanize();
                        Pages.Show();
                        Overlay.Show();
                        btnCarouselCanvas.Show();
                    },
                        delegate
                    {
                        if (AtViewSelected != null)
                        {
                            AtViewSelected(o.Caption.Text);
                        }

                        btnCarouselCanvas.Hide();
                        Pages.Hide();
                        Overlay.Hide();
                        o.Target.AttachTo(Container);
                    }
                        );
                };
            }
                );
            #endregion

            #region btnCarousel


            var btnCarousel = new TextButtonControl
            {
                Width      = btnCarouselCanvas.Width,
                Height     = btnCarouselCanvas.Height,
                Text       = "View as carousel...",
                Foreground = Brushes.White
            }.AttachContainerTo(btnCarouselCanvas);

            btnCarousel.MouseEnter +=
                delegate
            {
                btnCarousel.Foreground = Brushes.Blue;
            };

            btnCarousel.MouseLeave +=
                delegate
            {
                btnCarousel.Foreground = Brushes.White;
            };

            btnCarousel.Click +=
                delegate
            {
                navbar.History.Add(
                    delegate
                {
                    Pages.Show();
                    btnCarousel.Container.Show();
                    CarouselPages.Hide();

                    cc.Hide();
                    cc.Timer.Stop();
                },
                    delegate
                {
                    Pages.Hide();
                    CarouselPages.Show();
                    btnCarousel.Container.Hide();
                    cc.Show();
                    cc.Timer.Start();
                }
                    );
            };
            #endregion


            cc.Hide();

            CarouselPages.Hide();
            cc.AttachContainerTo(CarouselPages);

            cc.Overlay.Name = "cc_Overlay";
            cc.Overlay.AttachTo(Overlay);



            #region logo
            var logo = new Image
            {
                Source = "assets/AvalonExampleGallery/jsc.png".ToSource(),
                Width  = 96,
                Height = 96
            }.MoveTo(DefaultWidth - 96, DefaultHeight - 96).AttachTo(Container);

            var logo_Overlay = new Rectangle
            {
                Width   = 96,
                Height  = 96,
                Fill    = Brushes.Blue,
                Opacity = 0,
                Cursor  = Cursors.Hand
            }.MoveTo(DefaultWidth - 96, DefaultHeight - 96).AttachTo(Overlay);

            logo_Overlay.MouseEnter +=
                delegate
            {
                Pages.Opacity         = 0.5;
                CarouselPages.Opacity = 0.5;
            };

            logo_Overlay.MouseLeave +=
                delegate
            {
                Pages.Opacity         = 1;
                CarouselPages.Opacity = 1;
            };

            logo_Overlay.MouseLeftButtonUp +=
                delegate
            {
                new Uri("http://jsc.sourceforge.net").NavigateTo();
            };
            #endregion


            navbar.MoveContainerTo(4, 4).AttachContainerTo(Toolbar);
        }