コード例 #1
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;
        }
コード例 #2
0
        public NumericTransmitterCanvas()
        {
            Width  = DefaultWidth;
            Height = DefaultHeight;

            Colors.Blue.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 c1 = new ArrowCursorControl
            {
            };

            c1.Red.Opacity = 0.8;
            c1.Container.AttachTo(this);


            var c2 = new ArrowCursorControl
            {
            };

            c2.Yellow.Opacity = 0.8;
            c2.Container.AttachTo(this);


            var c3 = new ArrowCursorControl
            {
            };

            c3.Green.Opacity = 0.8;
            c3.Container.AttachTo(this);

            var Overlay = new Rectangle
            {
                Fill    = Brushes.White,
                Width   = DefaultWidth,
                Height  = DefaultHeight,
                Opacity = 0,
                Cursor  = Cursors.None
            }.AttachTo(this);

            Action <int, int> Emitter = NumericEmitter.Of(
                (x, y) => c3.Container.MoveTo(x, y)
                );


            Action <int, int> Omitter = NumericOmitter.Of(
                (x, y) =>
            {
                c2.Container.MoveTo(x, y);
                Emitter(x, y);
            }
                );



            Overlay.MouseMove +=
                (sender, e) =>
            {
                var p = e.GetPosition(this);

                c1.Container.MoveTo(p.X, p.Y);

                //1000.AtDelay(
                //    delegate
                //    {
                //        c2.Container.MoveTo(p.X, p.Y);
                //    }
                //);

                300.AtDelay(
                    () => Omitter(Convert.ToInt32(p.X), Convert.ToInt32(p.Y))
                    );
            };
        }