public ApplicationCanvas()
        {
            // X:\jsc.svn\examples\javascript\Test\TestShadowIFrame\TestShadowIFrame\Application.cs

            // could we use Foo.xaml?
            // see also http://caniuse.com/shadowdom
            // http://jonrimmer.github.io/are-we-componentized-yet/
            // https://bugzilla.mozilla.org/show_bug.cgi?id=811542

            // would we be able to use shadow dom to be able to activate file:// code?


            var t = new TextBox { Width = 200, Text = "hello" };
            Canvas.SetTop(t, 30);

            t.AttachTo(this);


            var bu = new Button { Content = "multiline" }.AttachTo(this);

            bu.Click +=
                delegate
            {
                t.AcceptsReturn = true;
                t.Height = 200;

            };
        }
        public ApplicationCanvas()
        {
            //var logo = new JSCSolutionsNETImage();
            //logo.AttachTo(this);
            var text = new TextBox
            {
                AcceptsReturn = true,
                BorderThickness = new Thickness(0),
                Background = Brushes.Transparent,
                Foreground = Brushes.Blue,
            };
            text.AttachTo(this);


            r.Fill = Brushes.Yellow;
            r.Opacity = 0.3;
            r.AttachTo(this);
            r.MoveTo(8, 8);

            this.SizeChanged += (s, e) =>
            {
                r.SizeTo(this.Width - 16, this.Height - 16);

                //logo.MoveTo(
                //    this.Width - logo.Width,
                //    this.Height - logo.Height
                //);
            };

            r.MouseEnter +=
                (s, e) =>
                {
                    text.Show();
                };

            r.MouseLeave +=
                (s, e) =>
                {
                    text.Hide();
                };


            r.MouseMove +=
                (s, e) =>
                {
                    var p = e.GetPosition(this);

                    text.Text = "jsc-solutions.net\n" + new { p.X, p.Y };

                    text.MoveTo(p.X + 32, p.Y);
                };
        }
        public ApplicationCanvas()
        {
            {
                var r = new Rectangle();
                r.Fill = Brushes.Black;
                r.AttachTo(this);
                r.MoveTo(0, 0);
                r.Opacity = 0.9;
                this.SizeChanged += (s, e) => r.SizeTo(this.Width, this.Height / 2);
            }

            {
                var r = new Rectangle();
                r.Fill = Brushes.Black;
                r.AttachTo(this);

                this.SizeChanged += (s, e) => r.MoveTo(0, this.Height / 2).SizeTo(this.Width, this.Height / 2);
            }

            var VocabularyLines = Vocabulary.Trim().Split('\n');

            var v = VocabularyLines.Select(
                k =>
                {
                    var verbs = k.Split(':');

                    return new { A = verbs[0].Trim(), B = verbs[1].Trim() };
                }
            ).Randomize().AsCyclicEnumerator();


            var az = 0.5;
            var ax = 0.0;

            var ABCanvas = new Canvas().AttachTo(this);

            var A = new TextBox
            {
                BorderThickness = new Thickness(0),
                Background = Brushes.Transparent,
                TextAlignment = System.Windows.TextAlignment.Center,
                Foreground = Brushes.White,
                Text = "suur ettevõte",
                IsReadOnly = true,
                FontSize = 70
            };

            A.AttachTo(ABCanvas);

            var B = new TextBox
            {
                BorderThickness = new Thickness(0),
                Background = Brushes.Transparent,
                TextAlignment = System.Windows.TextAlignment.Center,
                Foreground = Brushes.White,
                Text = "large-scale enterprise",
                IsReadOnly = true,
                FontSize = 70
            };

            var MoveNextDisabled = false;
            Action MoveNext = delegate
            {
                if (MoveNextDisabled)
                    return;

                MoveNextDisabled = true;
                v.MoveNext();
                A.Text = v.Current.A;
                B.Text = v.Current.B;

                600.AtDelay(() => MoveNextDisabled = false);
            };

            MoveNext();

            B.AttachTo(ABCanvas);
            B.MoveTo(0, 64);

            Action Update =
                delegate
                {
          

                    if (Math.Abs(ax) > 0.4)
                        MoveNext();

                    az = Math.Min(1, az);
                    az = Math.Max(0, az);

                    var max = this.Height / 6;
                    var min = this.Height / 3;

                    // az = 1 is 0 degrees
                    // az = 0 is 90 degrees

                    az = 1 - az;

                    az -= 0.05;
                    az *= 10;

                    az = 1 - az;

                    az = Math.Min(1, az);
                    az = Math.Max(0, az);

                    //Console.WriteLine(new { az });

                    A.Opacity = Math.Pow(az, 10);
                    var bz = 1 - az;

                    B.Opacity = Math.Pow(bz, 10);

                    A.MoveTo(0, min + az * max - 16).SizeTo(this.Width, 100);
                    B.MoveTo(0, min + (1 - az) * max - 16).SizeTo(this.Width, 100);

                    ABCanvas.MoveTo(this.Width * ax * 0.1, 0);

                };

            this.SizeChanged +=
                delegate
                {
                    Update();
                };

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

                az = (p.Y / this.Height);
                ax = -1 * ((p.X / this.Width) - 0.5);

                Update();
            };

            this.TouchMove += (sender, args) =>
            {
                var p = args.GetTouchPoint(this).Position;
                az = (p.Y / this.Height);
                ax = -1 * ((p.X / this.Width) - 0.5);

                Update();
            };


            this.Accelerate = (x, y, z) =>
            {
                az = z;
                ax = x;
                Update();
            };
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var c = new JSCSolutionsNETCarouselCanvas
            {
                CloseOnClick = false
            };

            c.HideSattelites();


            //c.Container.Effect = new DropShadowEffect();
            //c.Container.BitmapEffect = new DropShadowBitmapEffect();

            //.MoveTo(0, ImageCarouselCanvas.DefaultHeight - 96).SizeTo(ImageCarouselCanvas.DefaultWidth, 96);

            var cc = new Canvas();


            // http://cloudstore.blogspot.com/2008/05/creating-custom-window-style.html
            var wcam = new Window();

            wcam.Background  = Brushes.Transparent;
            wcam.WindowStyle = WindowStyle.None;
            wcam.ResizeMode  = ResizeMode.NoResize;
            wcam.SizeTo(200, 200);
            wcam.AllowsTransparency = true;
            //wcam.Opacity = 0.5;
            wcam.ShowInTaskbar = false;
            wcam.Cursor        = Cursors.Hand;
            wcam.Focusable     = false;
            wcam.Topmost       = true;

            var w = cc.ToWindow();


            w.SizeToContent = SizeToContent.Manual;
            //w.SizeTo(400, 400);
            //w.ToTransparentWindow();


            // http://blog.joachim.at/?p=39
            // http://blogs.msdn.com/changov/archive/2009/01/19/webbrowser-control-on-transparent-wpf-window.aspx
            // http://blogs.interknowlogy.com/johnbowen/archive/2007/06/20/20458.aspx
            w.AllowsTransparency = true;
            w.WindowStyle        = System.Windows.WindowStyle.None;
            w.Focusable          = false;

            //w.Background = new SolidColorBrush(Color.FromArgb(0x20, 0, 0, 0));
            w.Background            = Brushes.Transparent;
            w.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            w.Topmost = true;
            //w.ShowInTaskbar = false;

            var winfoc = new Canvas();



            var winfo = winfoc.ToWindow();

            winfo.AllowsTransparency = true;
            winfo.ShowInTaskbar      = false;
            winfo.WindowStyle        = WindowStyle.None;
            //winfo.Background = Brushes.Transparent;
            winfo.Background = Brushes.Red;
            winfo.Opacity    = 0.3;

            winfo.ResizeMode = ResizeMode.NoResize;

            winfo.SizeToContent = SizeToContent.Manual;
            winfo.Topmost       = true;
            // http://www.squidoo.com/youtubehd



            var NextInputModeEnabled        = false;
            var NextInputModeKeyDownEnabled = false;

            Action <Key> NextInputModeKeyDown = delegate { };

            var CommandKeysEnabled = false;

            #region TopicText
            var TopicText = new System.Windows.Controls.TextBox
            {
                //IsReadOnly = true,
                Background      = Brushes.Transparent,
                BorderThickness = new System.Windows.Thickness(0),
                Foreground      = Brushes.White,
                Effect          = new DropShadowEffect(),
                Text            = "JSC C# Foo Bar",
                //TextDecorations = TextDecorations.Underline,
                FontFamily    = new FontFamily("Verdana"),
                FontSize      = 24,
                TextAlignment = System.Windows.TextAlignment.Right
            };
            #endregion


            #region KeyDown
            InterceptKeys.KeyDown +=
                key =>
            {
                if (key == Key.LeftShift)
                {
                    //w.Background = new SolidColorBrush(Color.FromArgb(2, 0, 0, 0));
                    //w.MakeInteractive(true);
                    NextInputModeEnabled = true;
                }
                else
                {
                    if (NextInputModeEnabled || NextInputModeKeyDownEnabled)
                    {
                        NextInputModeKeyDownEnabled = false;
                        NextInputModeKeyDown(key);
                    }

                    NextInputModeEnabled = false;
                }
            };
            #endregion

            #region KeyUp
            InterceptKeys.KeyUp +=
                key =>
            {
                if (key == Key.CapsLock)
                {
                    CommandKeysEnabled   = !CommandKeysEnabled;
                    TopicText.IsReadOnly = CommandKeysEnabled;
                    TopicText.Select(0, 0);
                }

                if (key == Key.LeftShift)
                {
                    NextInputModeKeyDownEnabled = false;
                }
                else
                {
                }

                NextInputModeEnabled = false;
            };
            #endregion


            var s = 7;

            var ThumbnailSize           = 0.4;
            var CaptionBackgroundHeight = 24;

            #region UpdateChildren
            Action UpdateChildren =
                delegate
            {
                if (w.ActualWidth == 0)
                {
                    return;
                }

                var ss  = s;
                var ss2 = 0;


                Console.WriteLine(
                    new { w.Left, w.Top });

                winfo.MoveTo(w.Left, w.Top).SizeTo(w.ActualWidth, w.ActualHeight);

                if (ThumbnailSize == 1)
                {
                    wcam.Background = Brushes.Black;
                    ss = 0;

                    var qw = w.ActualWidth - ss * 2;
                    var qh = w.ActualHeight - ss * 2;

                    // no status bars or menues please :)

                    wcam.MoveTo(
                        w.Left + ss + ss2,
                        w.Top + (w.ActualHeight - qh * ThumbnailSize - ss) - ss2
                        ).SizeTo(
                        qw * ThumbnailSize,
                        qh * ThumbnailSize
                        );
                }
                else
                {
                    wcam.Background = Brushes.Transparent;

                    //if (w.WindowState == WindowState.Maximized)
                    //{
                    //    ss2 = s;
                    //}

                    var qw = w.ActualWidth - ss * 2;
                    var qh = w.ActualHeight - ss * 2;



                    wcam.MoveTo(w.Left + ss + ss2, w.Top + (w.ActualHeight - qh * ThumbnailSize - ss) - ss2).SizeTo(qw * ThumbnailSize, qh * ThumbnailSize);
                }
            };
            #endregion


            w.LocationChanged +=
                delegate
            {
                UpdateChildren();
            };



            var Borders = Enumerable.Range(1, s * 2).Reverse().Select(
                Width =>
                new
            {
                Width = Width * 2,
                Left  = new Rectangle {
                    Fill = Brushes.Black, Opacity = 0.06
                }.MoveTo(0, 0).AttachTo(winfoc),
                Right = new Rectangle {
                    Fill = Brushes.Black, Opacity = 0.06
                }.MoveTo(0, 0).AttachTo(winfoc),
                Bottom = new Rectangle {
                    Fill = Brushes.Black, Opacity = 0.03
                }.MoveTo(0, 0).AttachTo(winfoc),
                Top = new Rectangle {
                    Fill = Brushes.Black, Opacity = 0.11
                }.MoveTo(0, 0).AttachTo(winfoc)
            }
                ).ToArray();

            var CaptionBackgroundOverlay = new Rectangle
            {
                Fill    = Brushes.Black,
                Opacity = 0.02,
            }.AttachTo(cc);

            var CaptionSysMenuOverlay = new Rectangle
            {
                Fill    = Brushes.Black,
                Opacity = 0.02,
            }.AttachTo(cc).SizeTo(CaptionBackgroundHeight * 4, CaptionBackgroundHeight);

            var ExtraBorderTop = new Rectangle
            {
                Fill    = Brushes.Black,
                Opacity = 0.0,
            }.AttachTo(winfoc);

            var ExtraBorderBottom = new Rectangle
            {
                Fill    = Brushes.Black,
                Opacity = 0.0,
            }.AttachTo(winfoc);

            var CaptionClose = new TextBox
            {
                Foreground      = Brushes.Red,
                FontFamily      = new FontFamily("Webdings"),
                Text            = "r",
                Background      = Brushes.Transparent,
                BorderThickness = new Thickness(0),
                TextAlignment   = System.Windows.TextAlignment.Center,
                Opacity         = 0.5
            }.AttachTo(winfoc);


            var CaptionText = new System.Windows.Controls.TextBox
            {
                IsReadOnly      = true,
                Background      = Brushes.Transparent,
                BorderThickness = new System.Windows.Thickness(0),
                Foreground      = Brushes.White,
                Effect          = new System.Windows.Media.Effects.DropShadowEffect(),
                Text            = "jsc-solutions.net",
                //TextDecorations = TextDecorations.Underline,
                FontFamily    = new FontFamily("Verdana"),
                FontSize      = 16,
                TextAlignment = System.Windows.TextAlignment.Right
            }
            .AttachTo(winfoc);

            TopicText.AttachTo(winfoc);

            #region SetCaption
            Action <string> SetCaption =
                text =>
            {
                if (string.IsNullOrEmpty(text))
                {
                    CaptionText.Text = "jsc-solutions.net";
                }
                else
                {
                    CaptionText.Text = text + " | jsc-solutions.net";
                }
            };
            #endregion



            c.AttachContainerTo(winfoc);

            var ExtraBorderSize = 0.10;


            var Intro = new PromotionBrandIntro.ApplicationCanvas().AttachTo(winfoc);
            Intro.Opacity = 0;

            #region SizeChanged
            Action SizeChanged =
                delegate
            {
                Intro.SizeTo(w.ActualWidth, w.ActualHeight);
                //ink.SizeTo(w.ActualWidth, w.ActualHeight - CaptionBackgroundHeight);

                var CaptionWidth = 200;

                CaptionBackgroundOverlay.MoveTo(w.ActualWidth - CaptionWidth, 0).SizeTo(CaptionWidth, CaptionBackgroundHeight);


                ExtraBorderTop.MoveTo(0, 0).SizeTo(w.ActualWidth, w.ActualHeight * ExtraBorderSize);
                ExtraBorderBottom.MoveTo(0, w.ActualHeight * (1 - ExtraBorderSize)).SizeTo(w.ActualWidth, w.ActualHeight * ExtraBorderSize);

                TopicText.MoveTo(
                    0,
                    w.ActualHeight - 48
                    ).SizeTo(w.ActualWidth - 48, 48);


                if (c != null)
                {
                    c.MoveContainerTo(-200 + 42, -200 + 38);
                }
                Borders.WithEach(k => k.Left.MoveTo(0, 0).SizeTo(k.Width, w.ActualHeight));
                Borders.WithEach(k => k.Right.MoveTo(w.ActualWidth - k.Width, 0).SizeTo(k.Width, w.ActualHeight));
                Borders.WithEach(k => k.Bottom.MoveTo(0, w.ActualHeight - k.Width).SizeTo(w.ActualWidth, k.Width));
                Borders.WithEach(k => k.Top.MoveTo(0, 0).SizeTo(w.ActualWidth, k.Width));
                CaptionText.MoveTo(0, 2).SizeTo(w.ActualWidth - CaptionBackgroundHeight, 32);
                CaptionClose.MoveTo(w.ActualWidth - CaptionBackgroundHeight, s).SizeTo(CaptionBackgroundHeight - s, CaptionBackgroundHeight - s);

                UpdateChildren();
            };
            #endregion

            w.SizeChanged +=
                delegate
            {
                SizeChanged();
            };

            w.StateChanged +=
                delegate
            {
                if (w.WindowState == WindowState.Maximized)
                {
                    w.WindowState = WindowState.Normal;
                }

                SizeChanged();
            };



            #region GetWindows
            Func <IEnumerable <Internal.Window> > GetWindows =
                delegate
            {
                var windows = new List <Internal.Window>();
                Internal.EnumWindows(
                    (IntPtr hwnd, int lParam) =>
                {
                    if (new WindowInteropHelper(wcam).Handle != hwnd &&
                        (Internal.GetWindowLongA(hwnd, Internal.GWL_STYLE) & Internal.TARGETWINDOW) == Internal.TARGETWINDOW
                        )
                    {
                        StringBuilder sb = new StringBuilder(100);
                        Internal.GetWindowText(hwnd, sb, sb.Capacity);

                        windows.Add(
                            new Internal.Window
                        {
                            Handle = hwnd,
                            Title  = sb.ToString()
                        }
                            );
                    }

                    return(true);        //continue enumeration
                }
                    , 0);

                return(windows.OrderBy(k => k.Title));
            };
            #endregion

            var ResetThumbnailSkip = 0;

            Func <Internal.Window> GetCurrentThumbnail = () => GetWindows().AsCyclicEnumerable().Skip(ResetThumbnailSkip).First();

            #region AnimationCompleted
            Intro.AnimationCompleted +=
                delegate
            {
                if (c == null)
                {
                    c = new JSCSolutionsNETCarouselCanvas
                    {
                        CloseOnClick = false
                    }.AttachContainerTo(winfoc);
                    c.HideSattelites();

                    CaptionClose.Show();
                    SizeChanged();
                }
            };
            #endregion


            wcam.SourceInitialized +=
                delegate
            {
                {
                    wcam.MakeInteractive(false);

                    UpdateChildren();
                }



                var thumb = IntPtr.Zero;
                ResetThumbnailSkip = GetWindows().Where(
                    k =>
                    k.Title.Contains("Chrome") ||
                    k.Title.Contains("Studio") ||
                    k.Title.Contains("Minefield")

                    ).TakeWhile(k => k.Handle != Internal.GetForegroundWindow()).Count();


                #region ResetThumbnail
                Action ResetThumbnail =
                    delegate
                {
                    GetCurrentThumbnail().With(
                        shadow =>
                    {
                        //t.Text = shadow.Title;

                        if (thumb != IntPtr.Zero)
                        {
                            Internal.DwmUnregisterThumbnail(thumb);
                        }

                        int i = Internal.DwmRegisterThumbnail(
                            new WindowInteropHelper(wcam).Handle, shadow.Handle, out thumb);

                        #region UpdateThumbnail
                        Action UpdateThumbnail =
                            delegate
                        {
                            if (thumb != IntPtr.Zero)
                            {
                                Internal.PSIZE size;
                                Internal.DwmQueryThumbnailSourceSize(thumb, out size);

                                Internal.DWM_THUMBNAIL_PROPERTIES props = new Internal.DWM_THUMBNAIL_PROPERTIES();

                                props.fVisible              = true;
                                props.dwFlags               = Internal.DWM_TNP_VISIBLE | Internal.DWM_TNP_RECTDESTINATION | Internal.DWM_TNP_OPACITY | Internal.DWM_TNP_SOURCECLIENTAREAONLY;
                                props.opacity               = (byte)((byte)(0x7F) + (byte)((0x80) * (ThumbnailSize)));
                                props.rcDestination         = new Internal.Rect(0, 0, (int)wcam.ActualWidth, (int)wcam.ActualHeight);
                                props.fSourceClientAreaOnly = true;

                                if (size.x < wcam.ActualWidth)
                                {
                                    props.rcDestination.Right = props.rcDestination.Left + size.x;

                                    props.rcDestination.Left  += ((int)wcam.ActualWidth - size.x) / 2;
                                    props.rcDestination.Right += ((int)wcam.ActualWidth - size.x) / 2;
                                }

                                if (size.y < wcam.ActualHeight)
                                {
                                    props.rcDestination.Bottom = props.rcDestination.Top + size.y;

                                    props.rcDestination.Top    += ((int)wcam.ActualHeight - size.y) / 2;
                                    props.rcDestination.Bottom += ((int)wcam.ActualHeight - size.y) / 2;
                                }



                                Internal.DwmUpdateThumbnailProperties(thumb, ref props);
                            }
                        };
                        #endregion


                        (1000 / 15).AtInterval(UpdateThumbnail);

                        wcam.SizeChanged += delegate { UpdateThumbnail(); };
                    }
                        );
                };
                #endregion



                ResetThumbnail();

                NextInputModeKeyDown +=
                    key =>
                {
                    if (key == Key.RightShift)
                    {
                        NextInputModeKeyDownEnabled = true;

                        if (c != null)
                        {
                            CaptionClose.Hide();
                            c.AtClose +=
                                delegate
                            {
                                c.OrphanizeContainer();
                            };
                            c.Close();
                            c = null;
                        }

                        Intro.Background      = Brushes.Transparent;
                        Intro.Overlay.Opacity = 1;
                        Intro.FadeIn(
                            delegate
                        {
                            2000.AtDelay(Intro.PrepareAnimation());
                        }
                            );
                    }

                    if (!CommandKeysEnabled)
                    {
                        if (key == Key.F2)
                        {
                            w.Activate();

                            TopicText.Focusable = true;
                            TopicText.Focus();
                            TopicText.SelectAll();
                        }
                        return;
                    }

                    if (key == Key.Right)
                    {
                        if (w.IsActive)
                        {
                            GetCurrentThumbnail().Activate();
                        }
                        else
                        {
                            NextInputModeKeyDownEnabled = true;
                            ResetThumbnailSkip          = GetWindows().TakeWhile(k => k.Handle != Internal.GetForegroundWindow()).Count();
                            ResetThumbnail();
                        }
                    }

                    if (key == Key.Up)
                    {
                        NextInputModeKeyDownEnabled = true;

                        if (ThumbnailSize < 0.3)
                        {
                            ThumbnailSize = 0.3;
                        }
                        else if (ThumbnailSize < 0.5)
                        {
                            ThumbnailSize = 0.5;
                        }
                        else if (ThumbnailSize < 1)
                        {
                            ThumbnailSize = 1;
                        }
                        else
                        {
                            if (c != null)
                            {
                                CaptionClose.Hide();
                                c.AtClose +=
                                    delegate
                                {
                                    c.OrphanizeContainer();
                                };
                                c.Close();
                                c = null;
                            }
                        }


                        UpdateChildren();
                    }
                    if (key == Key.Down)
                    {
                        NextInputModeKeyDownEnabled = true;
                        if (c == null)
                        {
                            c = new JSCSolutionsNETCarouselCanvas
                            {
                                CloseOnClick = false
                            }.AttachContainerTo(winfoc);
                            CaptionClose.Show();
                        }
                        else if (ThumbnailSize > 0.5)
                        {
                            ThumbnailSize = 0.5;
                        }
                        else if (ThumbnailSize > 0.3)
                        {
                            ThumbnailSize = 0.3;
                        }
                        else if (ThumbnailSize == 0.3)
                        {
                            ThumbnailSize = 0;
                        }

                        SizeChanged();
                    }



                    if (key == Key.Left)
                    {
                        if (w.IsActive)
                        {
                            NextInputModeKeyDownEnabled = true;
                            if (ExtraBorderTop.Opacity == 1)
                            {
                                ExtraBorderTop.Opacity    = 0;
                                ExtraBorderBottom.Opacity = 0;
                            }
                            else
                            {
                                ExtraBorderTop.Opacity    = 1;
                                ExtraBorderBottom.Opacity = 1;
                            }
                        }
                    }
                };
            };

            winfo.SourceInitialized +=
                delegate
            {
                winfo.MakeInteractive(false);
            };

            w.SourceInitialized +=
                delegate
            {
                // http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/61e93dca-e24c-4953-9719-22ce3f705353
                Matrix m  = PresentationSource.FromVisual(w).CompositionTarget.TransformToDevice;
                double dx = m.M11;
                double dy = m.M22;


                w.SizeTo(1280 / dx, 768 / dy);
                w.MoveTo(8, 0);
                SizeChanged();

                wcam.Owner  = w;
                winfo.Owner = w;
                wcam.Show();
                winfo.Show();

                HwndSource hwndSource = (HwndSource)HwndSource.FromVisual(w);
                hwndSource.AddHook(
                    (IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handeled) =>
                {
                    if (msg == 0x0084)         // WM_NCHITTEST
                    {
                        //http://agsmith.wordpress.com/2008/09/16/hit-testing-in-wpf/

                        var p = new
                        {
                            cx = w.ActualWidth - (Internal.LOWORD(lParam) - w.Left),
                            cy = w.ActualHeight - (Internal.HIWORD(lParam) - w.Top),
                            x  = Internal.LOWORD(lParam) - w.Left,
                            y  = Internal.HIWORD(lParam) - w.Top
                        };


                        CaptionText.Text = p.ToString();

                        handeled = true;

                        return((IntPtr)HitTestValues.HTCAPTION);        // HTCAPTION


                        if (false)
                        {
                            if (p.x < s)
                            {
                                if (p.y < s)
                                {
                                    return((IntPtr)HitTestValues.HTTOPLEFT);        // HTCAPTION
                                }
                            }
                            if (p.x < CaptionBackgroundHeight)
                            {
                                if (p.y < CaptionBackgroundHeight)
                                {
                                    return((IntPtr)HitTestValues.HTSYSMENU);        // HTCAPTION
                                }
                            }
                            if (p.cx < CaptionBackgroundHeight)
                            {
                                if (p.y < CaptionBackgroundHeight)
                                {
                                    return((IntPtr)HitTestValues.HTCLOSE);        // HTCAPTION
                                }
                            }
                            if (p.cx < s)
                            {
                                if (p.cy < s)
                                {
                                    return((IntPtr)HitTestValues.HTBOTTOMRIGHT);        // HTCAPTION
                                }
                            }
                            if (p.cx < s)
                            {
                                if (p.y < s)
                                {
                                    return((IntPtr)HitTestValues.HTTOPRIGHT);        // HTCAPTION
                                }
                            }
                            if (p.x < s)
                            {
                                if (p.cy < s)
                                {
                                    return((IntPtr)HitTestValues.HTBOTTOMLEFT);        // HTCAPTION
                                }
                            }
                            if (p.x < s)
                            {
                                return((IntPtr)HitTestValues.HTLEFT);        // HTCAPTION
                            }
                            if (p.y < s)
                            {
                                return((IntPtr)HitTestValues.HTTOP);        // HTCAPTION
                            }
                            if (p.cx < s)
                            {
                                return((IntPtr)HitTestValues.HTRIGHT);        // HTCAPTION
                            }
                            if (p.cy < s)
                            {
                                return((IntPtr)HitTestValues.HTBOTTOM);        // HTCAPTION
                            }
                            if (p.y < CaptionBackgroundHeight)
                            {
                                return((IntPtr)HitTestValues.HTCAPTION);        // HTCAPTION
                            }
                            return((IntPtr)HitTestValues.HTTRANSPARENT);        // HTCAPTION
                        }
                    }
                    return(IntPtr.Zero);
                }

                    );
            };



            InterceptKeys.InternalMain(
                Rehook =>
            {
                w.Deactivated +=
                    delegate
                {
                    TopicText.Focusable = false;
                };
                w.Activated +=
                    delegate
                {
                    //TopicText.Focus();
                    Rehook();
                };

                w.ShowDialog();
            }
                );
        }
        public ApplicationCanvas()
        {
            this.Background = Brushes.Red;

            r.Fill = Brushes.White;
            r.AttachTo(this);
            r.MoveTo(4, 4);

            this.SizeChanged += (s, e) => r.SizeTo(this.Width - 8.0, this.Height - 8.0);

            {
                var ego = new ski1();

                ego.AttachTo(this).MoveTo(164, 96);

                (1000 / 60).AtIntervalWithCounter(
                    c =>
                    {
                        ego.MoveTo(164, c % this.Height);
                    }
                );
            }

            {
                var ego = new ski1();

                var dc = -64;

                ego.AttachTo(this).MoveTo(320, dc);

                (1000 / 60).AtIntervalWithCounter(
                    c =>
                    {
                        ego.MoveTo(320, (c + dc) % this.Height);
                    }
                );
            }

            Action<double, double> tree = (x, y) => new ski51().AttachTo(this).MoveTo(x, y);
            Action<double, double> deadtree = (x, y) => new ski50().AttachTo(this).MoveTo(x, y);
            Action<double, double> stone = (x, y) => new ski45().AttachTo(this).MoveTo(x, y);
            Action<double, double> stonefield = (x, y) => new ski27().AttachTo(this).MoveTo(x, y);

            tree(64, 32);

            var logo = new Avalon.Images.jsc().AttachTo(this);

            this.SizeChanged += (s, e) => logo.MoveTo(this.Width - logo.Width, this.Height - logo.Height);

            this.MouseLeftButtonUp +=
                (s, a) =>
                {
                    var pos = a.GetPosition(this);

                    var f = new[] {
                        tree,
                        tree,
                        tree,
                        tree,
                        deadtree,
                        deadtree,
                        stone,
                        stone,
                        stone,
                        stonefield };

                    f.Random()(pos.X, pos.Y);
                };

            var t = new TextBox
            {
                Text = "ski",
                Background = Brushes.Transparent,
                BorderThickness = new Thickness(0)
            };

            t.AttachTo(this).MoveTo(96, 8);

            var ax = 0.0;
            var ay = 0.0;
            var az = 0.0;

            Action SizeChangedOrAccelerated =
                delegate
                {
                    t.Text = "ski: " + new { this.Width, this.Height, ax, ay, az };
                };

            this.SizeChanged += (s, e) => { SizeChangedOrAccelerated(); };

            t2.AttachTo(this).MoveTo(96, 24);

            Accelerate =
                (_ax, _ay, _az) =>
                {
                    ax = _ax;
                    ay = _ay;
                    az = _az;

                    SizeChangedOrAccelerated();
                };
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            var c = new JSCSolutionsNETCarouselCanvas
                {
                    CloseOnClick = false
                };

            c.HideSattelites();


            //c.Container.Effect = new DropShadowEffect();
            //c.Container.BitmapEffect = new DropShadowBitmapEffect();

            //.MoveTo(0, ImageCarouselCanvas.DefaultHeight - 96).SizeTo(ImageCarouselCanvas.DefaultWidth, 96);

            var cc = new Canvas();


            // http://cloudstore.blogspot.com/2008/05/creating-custom-window-style.html
            var wcam = new Window();
            wcam.Background = Brushes.Transparent;
            wcam.WindowStyle = WindowStyle.None;
            wcam.ResizeMode = ResizeMode.NoResize;
            wcam.SizeTo(200, 200);
            wcam.AllowsTransparency = true;
            //wcam.Opacity = 0.5;
            wcam.ShowInTaskbar = false;
            wcam.Cursor = Cursors.Hand;
            wcam.Focusable = false;
            wcam.Topmost = true;

            var w = cc.ToWindow();


            w.SizeToContent = SizeToContent.Manual;
            //w.SizeTo(400, 400);
            //w.ToTransparentWindow();


            // http://blog.joachim.at/?p=39
            // http://blogs.msdn.com/changov/archive/2009/01/19/webbrowser-control-on-transparent-wpf-window.aspx
            // http://blogs.interknowlogy.com/johnbowen/archive/2007/06/20/20458.aspx
            w.AllowsTransparency = true;
            w.WindowStyle = System.Windows.WindowStyle.None;
            w.Focusable = false;

            //w.Background = new SolidColorBrush(Color.FromArgb(0x20, 0, 0, 0));
            w.Background = Brushes.Transparent;
            w.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            w.Topmost = true;
            //w.ShowInTaskbar = false;

            var winfoc = new Canvas();



            var winfo = winfoc.ToWindow();

            winfo.AllowsTransparency = true;
            winfo.ShowInTaskbar = false;
            winfo.WindowStyle = WindowStyle.None;
            //winfo.Background = Brushes.Transparent;
            winfo.Background = Brushes.Red;
            winfo.Opacity = 0.3;

            winfo.ResizeMode = ResizeMode.NoResize;

            winfo.SizeToContent = SizeToContent.Manual;
            winfo.Topmost = true;
            // http://www.squidoo.com/youtubehd









            var NextInputModeEnabled = false;
            var NextInputModeKeyDownEnabled = false;

            Action<Key> NextInputModeKeyDown = delegate { };

            var CommandKeysEnabled = false;

            #region TopicText
            var TopicText = new System.Windows.Controls.TextBox
            {
                //IsReadOnly = true,
                Background = Brushes.Transparent,
                BorderThickness = new System.Windows.Thickness(0),
                Foreground = Brushes.White,
                Effect = new DropShadowEffect(),
                Text = "JSC C# Foo Bar",
                //TextDecorations = TextDecorations.Underline,
                FontFamily = new FontFamily("Verdana"),
                FontSize = 24,
                TextAlignment = System.Windows.TextAlignment.Right
            };
            #endregion


            #region KeyDown
            InterceptKeys.KeyDown +=
                key =>
                {
                    if (key == Key.LeftShift)
                    {
                        //w.Background = new SolidColorBrush(Color.FromArgb(2, 0, 0, 0));
                        //w.MakeInteractive(true);
                        NextInputModeEnabled = true;
                    }
                    else
                    {

                        if (NextInputModeEnabled || NextInputModeKeyDownEnabled)
                        {

                            NextInputModeKeyDownEnabled = false;
                            NextInputModeKeyDown(key);

                        }

                        NextInputModeEnabled = false;
                    }
                };
            #endregion

            #region KeyUp
            InterceptKeys.KeyUp +=
                key =>
                {
                    if (key == Key.CapsLock)
                    {
                        CommandKeysEnabled = !CommandKeysEnabled;
                        TopicText.IsReadOnly = CommandKeysEnabled;
                        TopicText.Select(0, 0);
                    }

                    if (key == Key.LeftShift)
                    {
                        NextInputModeKeyDownEnabled = false;
                    }
                    else
                    {

                    }

                    NextInputModeEnabled = false;
                };
            #endregion


            var s = 7;

            var ThumbnailSize = 0.4;
            var CaptionBackgroundHeight = 24;

            #region UpdateChildren
            Action UpdateChildren =
                delegate
                {
                    if (w.ActualWidth == 0)
                        return;

                    var ss = s;
                    var ss2 = 0;


                    Console.WriteLine(
                        new { w.Left, w.Top });

                    winfo.MoveTo(w.Left, w.Top).SizeTo(w.ActualWidth, w.ActualHeight);

                    if (ThumbnailSize == 1)
                    {
                        wcam.Background = Brushes.Black;
                        ss = 0;

                        var qw = w.ActualWidth - ss * 2;
                        var qh = w.ActualHeight - ss * 2;

                        // no status bars or menues please :)

                        wcam.MoveTo(
                            w.Left + ss + ss2,
                            w.Top + (w.ActualHeight - qh * ThumbnailSize - ss) - ss2
                        ).SizeTo(
                            qw * ThumbnailSize,
                            qh * ThumbnailSize
                        );

                    }
                    else
                    {
                        wcam.Background = Brushes.Transparent;

                        //if (w.WindowState == WindowState.Maximized)
                        //{
                        //    ss2 = s;
                        //}

                        var qw = w.ActualWidth - ss * 2;
                        var qh = w.ActualHeight - ss * 2;



                        wcam.MoveTo(w.Left + ss + ss2, w.Top + (w.ActualHeight - qh * ThumbnailSize - ss) - ss2).SizeTo(qw * ThumbnailSize, qh * ThumbnailSize);

                    }


                };
            #endregion


            w.LocationChanged +=
                delegate
                {
                    UpdateChildren();
                };



            var Borders = Enumerable.Range(1, s * 2).Reverse().Select(
                Width =>
                new
                {
                    Width = Width * 2,
                    Left = new Rectangle { Fill = Brushes.Black, Opacity = 0.06 }.MoveTo(0, 0).AttachTo(winfoc),
                    Right = new Rectangle { Fill = Brushes.Black, Opacity = 0.06 }.MoveTo(0, 0).AttachTo(winfoc),
                    Bottom = new Rectangle { Fill = Brushes.Black, Opacity = 0.03 }.MoveTo(0, 0).AttachTo(winfoc),
                    Top = new Rectangle { Fill = Brushes.Black, Opacity = 0.11 }.MoveTo(0, 0).AttachTo(winfoc)
                }
            ).ToArray();

            var CaptionBackgroundOverlay = new Rectangle
            {
                Fill = Brushes.Black,
                Opacity = 0.02,
            }.AttachTo(cc);

            var CaptionSysMenuOverlay = new Rectangle
            {
                Fill = Brushes.Black,
                Opacity = 0.02,
            }.AttachTo(cc).SizeTo(CaptionBackgroundHeight * 4, CaptionBackgroundHeight);

            var ExtraBorderTop = new Rectangle
            {
                Fill = Brushes.Black,
                Opacity = 0.0,
            }.AttachTo(winfoc);

            var ExtraBorderBottom = new Rectangle
            {
                Fill = Brushes.Black,
                Opacity = 0.0,
            }.AttachTo(winfoc);

            var CaptionClose = new TextBox
            {
                Foreground = Brushes.Red,
                FontFamily = new FontFamily("Webdings"),
                Text = "r",
                Background = Brushes.Transparent,
                BorderThickness = new Thickness(0),
                TextAlignment = System.Windows.TextAlignment.Center,
                Opacity = 0.5
            }.AttachTo(winfoc);


            var CaptionText = new System.Windows.Controls.TextBox
            {
                IsReadOnly = true,
                Background = Brushes.Transparent,
                BorderThickness = new System.Windows.Thickness(0),
                Foreground = Brushes.White,
                Effect = new System.Windows.Media.Effects.DropShadowEffect(),
                Text = "jsc-solutions.net",
                //TextDecorations = TextDecorations.Underline,
                FontFamily = new FontFamily("Verdana"),
                FontSize = 16,
                TextAlignment = System.Windows.TextAlignment.Right
            }
            .AttachTo(winfoc);

            TopicText.AttachTo(winfoc);

            #region SetCaption
            Action<string> SetCaption =
                text =>
                {
                    if (string.IsNullOrEmpty(text))
                        CaptionText.Text = "jsc-solutions.net";
                    else
                        CaptionText.Text = text + " | jsc-solutions.net";

                };
            #endregion




            c.AttachContainerTo(winfoc);

            var ExtraBorderSize = 0.10;


            var Intro = new PromotionBrandIntro.ApplicationCanvas().AttachTo(winfoc);
            Intro.Opacity = 0;

            #region SizeChanged
            Action SizeChanged =
                delegate
                {
                    Intro.SizeTo(w.ActualWidth, w.ActualHeight);
                    //ink.SizeTo(w.ActualWidth, w.ActualHeight - CaptionBackgroundHeight);

                    var CaptionWidth = 200;

                    CaptionBackgroundOverlay.MoveTo(w.ActualWidth - CaptionWidth, 0).SizeTo(CaptionWidth, CaptionBackgroundHeight);


                    ExtraBorderTop.MoveTo(0, 0).SizeTo(w.ActualWidth, w.ActualHeight * ExtraBorderSize);
                    ExtraBorderBottom.MoveTo(0, w.ActualHeight * (1 - ExtraBorderSize)).SizeTo(w.ActualWidth, w.ActualHeight * ExtraBorderSize);

                    TopicText.MoveTo(
                        0,
                        w.ActualHeight - 48
                    ).SizeTo(w.ActualWidth - 48, 48);

                   
                    if (c != null)
                        c.MoveContainerTo(-200 + 42, -200 + 38);
                    Borders.WithEach(k => k.Left.MoveTo(0, 0).SizeTo(k.Width, w.ActualHeight));
                    Borders.WithEach(k => k.Right.MoveTo(w.ActualWidth - k.Width, 0).SizeTo(k.Width, w.ActualHeight));
                    Borders.WithEach(k => k.Bottom.MoveTo(0, w.ActualHeight - k.Width).SizeTo(w.ActualWidth, k.Width));
                    Borders.WithEach(k => k.Top.MoveTo(0, 0).SizeTo(w.ActualWidth, k.Width));
                    CaptionText.MoveTo(0, 2).SizeTo(w.ActualWidth - CaptionBackgroundHeight, 32);
                    CaptionClose.MoveTo(w.ActualWidth - CaptionBackgroundHeight, s).SizeTo(CaptionBackgroundHeight - s, CaptionBackgroundHeight - s);

                    UpdateChildren();
                };
            #endregion

            w.SizeChanged +=
                delegate
                {
                    SizeChanged();
                };

            w.StateChanged +=
                delegate
                {
                    if (w.WindowState == WindowState.Maximized)
                        w.WindowState = WindowState.Normal;

                    SizeChanged();
                };



            #region GetWindows
            Func<IEnumerable<Internal.Window>> GetWindows =
                delegate
                {
                    var windows = new List<Internal.Window>();
                    Internal.EnumWindows(
                        (IntPtr hwnd, int lParam) =>
                        {
                            if (new WindowInteropHelper(wcam).Handle != hwnd
                                && (Internal.GetWindowLongA(hwnd, Internal.GWL_STYLE) & Internal.TARGETWINDOW) == Internal.TARGETWINDOW
                                )
                            {
                                StringBuilder sb = new StringBuilder(100);
                                Internal.GetWindowText(hwnd, sb, sb.Capacity);

                                windows.Add(
                                    new Internal.Window
                                    {
                                        Handle = hwnd,
                                        Title = sb.ToString()
                                    }
                                );
                            }

                            return true; //continue enumeration
                        }
                        , 0);

                    return windows.OrderBy(k => k.Title);
                };
            #endregion

            var ResetThumbnailSkip = 0;

            Func<Internal.Window> GetCurrentThumbnail = () => GetWindows().AsCyclicEnumerable().Skip(ResetThumbnailSkip).First();

            #region AnimationCompleted
            Intro.AnimationCompleted +=
                delegate
                {
                    if (c == null)
                    {
                        c = new JSCSolutionsNETCarouselCanvas
                        {
                            CloseOnClick = false
                        }.AttachContainerTo(winfoc);
                        c.HideSattelites();

                        CaptionClose.Show();
                        SizeChanged();
                    }
                };
            #endregion


            wcam.SourceInitialized +=
                delegate
                {
                    {
                        wcam.MakeInteractive(false);

                        UpdateChildren();
                    }



                    var thumb = IntPtr.Zero;
                    ResetThumbnailSkip = GetWindows().Where(
                        k =>
                            k.Title.Contains("Chrome")
                            || k.Title.Contains("Studio")
                            || k.Title.Contains("Minefield")

                            ).TakeWhile(k => k.Handle != Internal.GetForegroundWindow()).Count();


                    #region ResetThumbnail
                    Action ResetThumbnail =
                        delegate
                        {
                            GetCurrentThumbnail().With(
                                shadow =>
                                {
                                    //t.Text = shadow.Title;

                                    if (thumb != IntPtr.Zero)
                                        Internal.DwmUnregisterThumbnail(thumb);

                                    int i = Internal.DwmRegisterThumbnail(
                                        new WindowInteropHelper(wcam).Handle, shadow.Handle, out thumb);

                                    #region UpdateThumbnail
                                    Action UpdateThumbnail =
                                        delegate
                                        {
                                            if (thumb != IntPtr.Zero)
                                            {
                                                Internal.PSIZE size;
                                                Internal.DwmQueryThumbnailSourceSize(thumb, out size);

                                                Internal.DWM_THUMBNAIL_PROPERTIES props = new Internal.DWM_THUMBNAIL_PROPERTIES();

                                                props.fVisible = true;
                                                props.dwFlags = Internal.DWM_TNP_VISIBLE | Internal.DWM_TNP_RECTDESTINATION | Internal.DWM_TNP_OPACITY | Internal.DWM_TNP_SOURCECLIENTAREAONLY;
                                                props.opacity = (byte)((byte)(0x7F) + (byte)((0x80) * (ThumbnailSize)));
                                                props.rcDestination = new Internal.Rect(0, 0, (int)wcam.ActualWidth, (int)wcam.ActualHeight);
                                                props.fSourceClientAreaOnly = true;

                                                if (size.x < wcam.ActualWidth)
                                                {
                                                    props.rcDestination.Right = props.rcDestination.Left + size.x;

                                                    props.rcDestination.Left += ((int)wcam.ActualWidth - size.x) / 2;
                                                    props.rcDestination.Right += ((int)wcam.ActualWidth - size.x) / 2;
                                                }

                                                if (size.y < wcam.ActualHeight)
                                                {

                                                    props.rcDestination.Bottom = props.rcDestination.Top + size.y;

                                                    props.rcDestination.Top += ((int)wcam.ActualHeight - size.y) / 2;
                                                    props.rcDestination.Bottom += ((int)wcam.ActualHeight - size.y) / 2;

                                                }



                                                Internal.DwmUpdateThumbnailProperties(thumb, ref props);
                                            }
                                        };
                                    #endregion


                                    (1000 / 15).AtInterval(UpdateThumbnail);

                                    wcam.SizeChanged += delegate { UpdateThumbnail(); };
                                }
                            );
                        };
                    #endregion



                    ResetThumbnail();

                    NextInputModeKeyDown +=
                        key =>
                        {
                            if (key == Key.RightShift)
                            {
                                NextInputModeKeyDownEnabled = true;

                                if (c != null)
                                {
                                    CaptionClose.Hide();
                                    c.AtClose +=
                                        delegate
                                        {
                                            c.OrphanizeContainer();
                                        };
                                    c.Close();
                                    c = null;
                                }

                                Intro.Background = Brushes.Transparent;
                                Intro.Overlay.Opacity = 1;
                                Intro.FadeIn(
                                    delegate
                                    {


                                        2000.AtDelay(Intro.PrepareAnimation());
                                    }
                                );
                            }

                            if (!CommandKeysEnabled)
                            {
                                if (key == Key.F2)
                                {
                                    w.Activate();

                                    TopicText.Focusable = true;
                                    TopicText.Focus();
                                    TopicText.SelectAll();
                                }
                                return;
                            }

                            if (key == Key.Right)
                            {
                                if (w.IsActive)
                                {
                                    GetCurrentThumbnail().Activate();
                                }
                                else
                                {
                                    NextInputModeKeyDownEnabled = true;
                                    ResetThumbnailSkip = GetWindows().TakeWhile(k => k.Handle != Internal.GetForegroundWindow()).Count();
                                    ResetThumbnail();
                                }
                            }

                            if (key == Key.Up)
                            {
                                NextInputModeKeyDownEnabled = true;

                                if (ThumbnailSize < 0.3)
                                    ThumbnailSize = 0.3;
                                else if (ThumbnailSize < 0.5)
                                    ThumbnailSize = 0.5;
                                else if (ThumbnailSize < 1)
                                    ThumbnailSize = 1;
                                else
                                {
                                    if (c != null)
                                    {
                                        CaptionClose.Hide();
                                        c.AtClose +=
                                            delegate
                                            {
                                                c.OrphanizeContainer();
                                            };
                                        c.Close();
                                        c = null;
                                    }

                                }


                                UpdateChildren();

                            }
                            if (key == Key.Down)
                            {
                                NextInputModeKeyDownEnabled = true;
                                if (c == null)
                                {
                                    c = new JSCSolutionsNETCarouselCanvas
                                    {
                                        CloseOnClick = false
                                    }.AttachContainerTo(winfoc);
                                    CaptionClose.Show();
                                }
                                else if (ThumbnailSize > 0.5)
                                    ThumbnailSize = 0.5;
                                else if (ThumbnailSize > 0.3)
                                    ThumbnailSize = 0.3;
                                else if (ThumbnailSize == 0.3)
                                    ThumbnailSize = 0;

                                SizeChanged();
                            }



                            if (key == Key.Left)
                            {
                                if (w.IsActive)
                                {
                                    NextInputModeKeyDownEnabled = true;
                                    if (ExtraBorderTop.Opacity == 1)
                                    {
                                        ExtraBorderTop.Opacity = 0;
                                        ExtraBorderBottom.Opacity = 0;
                                    }
                                    else
                                    {
                                        ExtraBorderTop.Opacity = 1;
                                        ExtraBorderBottom.Opacity = 1;
                                    }
                                }
                            }

                        };


                };

            winfo.SourceInitialized +=
                delegate
                {
                    winfo.MakeInteractive(false);
                };

            w.SourceInitialized +=
                delegate
                {

                    // http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/61e93dca-e24c-4953-9719-22ce3f705353
                    Matrix m = PresentationSource.FromVisual(w).CompositionTarget.TransformToDevice;
                    double dx = m.M11;
                    double dy = m.M22;


                    w.SizeTo(1280 / dx, 768 /dy);
                    w.MoveTo(8, 0);
                    SizeChanged();

                    wcam.Owner = w;
                    winfo.Owner = w;
                    wcam.Show();
                    winfo.Show();

                    HwndSource hwndSource = (HwndSource)HwndSource.FromVisual(w);
                    hwndSource.AddHook(
                        (IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handeled) =>
                        {
                            if (msg == 0x0084) // WM_NCHITTEST
                            {
                                //http://agsmith.wordpress.com/2008/09/16/hit-testing-in-wpf/

                                var p = new
                                {
                                    cx = w.ActualWidth - (Internal.LOWORD(lParam) - w.Left),
                                    cy = w.ActualHeight - (Internal.HIWORD(lParam) - w.Top),
                                    x = Internal.LOWORD(lParam) - w.Left,
                                    y = Internal.HIWORD(lParam) - w.Top
                                };


                                CaptionText.Text = p.ToString();

                                handeled = true;

                                return (IntPtr)HitTestValues.HTCAPTION; // HTCAPTION


                                if (false)
                                {
                                    if (p.x < s)
                                        if (p.y < s)
                                            return (IntPtr)HitTestValues.HTTOPLEFT; // HTCAPTION

                                    if (p.x < CaptionBackgroundHeight)
                                        if (p.y < CaptionBackgroundHeight)
                                            return (IntPtr)HitTestValues.HTSYSMENU; // HTCAPTION


                                    if (p.cx < CaptionBackgroundHeight)
                                        if (p.y < CaptionBackgroundHeight)
                                            return (IntPtr)HitTestValues.HTCLOSE; // HTCAPTION


                                    if (p.cx < s)
                                        if (p.cy < s)
                                            return (IntPtr)HitTestValues.HTBOTTOMRIGHT; // HTCAPTION

                                    if (p.cx < s)
                                        if (p.y < s)
                                            return (IntPtr)HitTestValues.HTTOPRIGHT; // HTCAPTION

                                    if (p.x < s)
                                        if (p.cy < s)
                                            return (IntPtr)HitTestValues.HTBOTTOMLEFT; // HTCAPTION

                                    if (p.x < s)
                                        return (IntPtr)HitTestValues.HTLEFT; // HTCAPTION

                                    if (p.y < s)
                                        return (IntPtr)HitTestValues.HTTOP; // HTCAPTION


                                    if (p.cx < s)
                                        return (IntPtr)HitTestValues.HTRIGHT; // HTCAPTION

                                    if (p.cy < s)
                                        return (IntPtr)HitTestValues.HTBOTTOM; // HTCAPTION

                                    if (p.y < CaptionBackgroundHeight)
                                        return (IntPtr)HitTestValues.HTCAPTION; // HTCAPTION

                                    return (IntPtr)HitTestValues.HTTRANSPARENT; // HTCAPTION
                                }

                            }
                            return IntPtr.Zero;
                        }

                   );
                };



            InterceptKeys.InternalMain(
                Rehook =>
                {
                    w.Deactivated +=
                        delegate
                        {
                            TopicText.Focusable = false;
                        };
                    w.Activated +=
                        delegate
                        {


                            //TopicText.Focus();
                            Rehook();
                        };

                    w.ShowDialog();
                }
            );

        }
		public AvalonQueryExampleCanvas()
		{
			CheckIsPanel();

			Width = DefaultWidth;
			Height = DefaultHeight;

			#region Gradient
			for (int i = 0; i < DefaultHeight; i += 4)
			{
				new Rectangle
				{
					Fill = ((uint)(0xff00007F + Convert.ToInt32(128 * i / DefaultHeight))).ToSolidColorBrush(),
					Width = DefaultWidth,
					Height = 5,
				}.MoveTo(0, i).AttachTo(this);
			}
			#endregion

			new Image
			{
				Source = "assets/FlashAvalonQueryExample/labels.png".ToSource()
			}.MoveTo(0, 0).AttachTo(this);

			//var FaciconService = "http://www.google.com/s2/favicons?domain=";

			// http://www.google.com/s2/favicons?domain=wordpress.com
			var KnownDomains = "63/155262375_104aee1bb0, 3183/2825405970_a1469cd673, 2336/2454679206_de5176b827, 3178/2825551196_6548ff54b9";
			var KnownFilter = "31";

			Func<Brush> Color_Inactive = () => 0xffc0c0c0.ToSolidColorBrush();
			Func<Brush> Color_Active = () => 0xffffffff.ToSolidColorBrush();
			Func<Brush> Color_Error = () => 0xffffff80.ToSolidColorBrush();

			var KnownDomainsInputHeight = 100;

			var KnownDomainsInput = new TextBox
			{
				AcceptsReturn = true,
				FontSize = 15,
				Text = KnownDomains,
				BorderThickness = new Thickness(0),
				//Foreground = 0xffffffff.ToSolidColorBrush(),
				Background = Color_Inactive(),
				Width = 400,
				Height = KnownDomainsInputHeight,
				TextWrapping = TextWrapping.Wrap
			}.MoveTo(32, 32).AttachTo(this);

			KnownDomainsInput.Orphanize();
			KnownDomainsInput.AttachTo(this);

			Action<TextBox> ApplyActiveColor =
				e =>
				{
					e.GotFocus +=
						delegate
						{
							e.Background = Color_Active();
						};


					e.LostFocus +=
						delegate
						{
							e.Background = Color_Inactive();
						};
				};

			ApplyActiveColor(KnownDomainsInput);

			var FilterInputHeight = 22;

			var FilterInput = new TextBox
			{
				FontSize = 15,
				Text = KnownFilter,
				BorderThickness = new Thickness(0),
				//Foreground = 0xffffffff.ToSolidColorBrush(),
				Background = Color_Inactive(),
				Width = 400,
				Height = FilterInputHeight,
			}.MoveTo(32, 32 + KnownDomainsInputHeight + 4).AttachTo(this);

			ApplyActiveColor(FilterInput);


			var AnyInputChangedBefore = new List<Action>();

			Action AnyInputChanged =
				delegate
				{
					AnyInputChangedBefore.Do();
					AnyInputChangedBefore.Clear();

					var query = from k in KnownDomainsInput.Text.Split(',')
								let t = k.Trim()
								where t.Contains(FilterInput.Text)
								orderby t
								select t;


					query.ForEach(
						(k, i) =>
						{
							// http://static.flickr.com/63/155262375_104aee1bb0.jpg
							var src = "http://static.flickr.com/" + k + "_s.jpg";

							var y = 32 + KnownDomainsInputHeight + 4 + FilterInputHeight + 4 + i * 80;

							var bg = new Rectangle
							{
								Fill = Color_Inactive(),
								Width = 400,
								Height = 26

							}
							.MoveTo(32, y + 20).AttachTo(this);

							var img_shadow = new Rectangle
							{
								Fill = 0xff000000.ToSolidColorBrush(),
								Opacity = 0.3,
								Width = 75,
								Height = 75
							}
							.MoveTo(32 + 2 + 3, y + 2 + 3).AttachTo(this);

							var img = new Image
							{
								Width = 75,
								Height = 75
							}
							.MoveTo(32 + 2, y + 2).AttachTo(this);


							var text = new TextBox
							{
								IsReadOnly = true,
								Text = (i + 1) + ". " + src,
								Width = 400 - 88,
								Height = 20,
								BorderThickness = new Thickness(0),
								Foreground = 0xff0000ff.ToSolidColorBrush(),
								Background = 0xffffffff.ToSolidColorBrush()
							}.MoveTo(32 + 84, y + 22).AttachTo(this);




							var src_uri = new BitmapImage();

							src_uri.DownloadCompleted +=
								delegate
								{
									text.Foreground = 0xff000000.ToSolidColorBrush();
									//bg.Fill = Color_Active();
								};

							src_uri.DownloadFailed +=
								delegate
								{
									text.Text += " failed...";
									text.Foreground = 0xffff0000.ToSolidColorBrush();
									//bg.Fill = Color_Error();
								};

							src_uri.BeginInit();
                            Console.WriteLine(src);
							src_uri.UriSource = new Uri(src);
							src_uri.EndInit();


							img.Source = src_uri;

							text.Background = Color_Inactive();
							bg.Opacity = 0.3;

							text.GotFocus +=
								delegate
								{
									text.Background = Color_Active();
									bg.Opacity = 1;
								};

							text.LostFocus +=
								delegate
								{
									text.Background = Color_Inactive();
									bg.Opacity = 0.3;
								};

							AnyInputChangedBefore.Add(
								delegate
								{
									bg.Orphanize();
									img.Orphanize();
									text.Orphanize();
									img_shadow.Orphanize();
								}
							);

							//ResultOutput.AppendTextLine((i + 1) + ". " + k + " " + src);
						}
					);
					// we need to validate CNAMEs



				};

			#region attach AnyInputChanged
			KnownDomainsInput.TextChanged +=
				delegate
				{
					AnyInputChanged();
				};

			FilterInput.TextChanged +=
				delegate
				{
					AnyInputChanged();
				};

			AnyInputChanged();

			#endregion

		}
        public ApplicationCanvas()
        {
            var r0shadow = new Rectangle();
            r0shadow.Opacity = 0.5;
            r0shadow.Fill = Brushes.Black;
            r0shadow.AttachTo(this);

            var r1shadow = new Rectangle();
            r1shadow.Opacity = 0.5;
            r1shadow.Fill = Brushes.Black;
            r1shadow.AttachTo(this);


            var rcontent = new Canvas().AttachTo(this);


            var r0 = new Rectangle();


            r0.Opacity = 0.8;
            r0.Fill = Brushes.DarkGreen;
            r0.AttachTo(rcontent);

            var r1 = new Rectangle();


            r1.Opacity = 0.8;
            r1.Fill = Brushes.DarkGreen;
            r1.AttachTo(rcontent);
            r1.MoveTo(0, 96);



            r0.SizeTo(500, 96 - 16);
            r1.SizeTo(500, 230);
            r0shadow.SizeTo(500, 96 - 16);
            r1shadow.SizeTo(500, 230);

            var t = new TextBox();

            t.IsReadOnly = true;

            //            type: System.Windows.Controls.TextBlock
            //method: Void set_Foreground(System.Windows.Media.Brush)

            t.Foreground = Brushes.Yellow;
            t.AttachTo(rcontent);
            t.AcceptsReturn = true;
            t.Text = "You have found a shop.\nSee something you like?";
            t.Background = Brushes.Transparent;
            t.BorderThickness = new Thickness(0);
            t.FontSize = 24;
            t.MoveTo(8, 8);


            t2 = new TextBox();

            t2.IsReadOnly = true;

            //            type: System.Windows.Controls.TextBlock
            //method: Void set_Foreground(System.Windows.Media.Brush)

            t2.Foreground = Brushes.Yellow;
            t2.AttachTo(rcontent);
            t2.AcceptsReturn = true;
            t2.Text = "! First we will log you in to FACEBOOK and then to PAYPAL, takes a few...";
            t2.Background = Brushes.Transparent;
            t2.BorderThickness = new Thickness(0);
            t2.MoveTo(8, 290);

            t2o = t2.ToAnimatedOpacity();

            t2o.Opacity = 0.2;

            bg_ammo = new Rectangle();


            bg_ammo.Fill = Brushes.Yellow;
            bg_ammo.AttachTo(rcontent);
            bg_ammo.SizeTo(400, 48);
            bg_ammo.MoveTo(50, 128 + 32 - 8);

            var ammo = new Avalon.Images.avatars_ammo();

            ammo.AttachTo(rcontent);
            ammo.MoveTo(32 + 32, 128 + 32);



            overlay_ammo.Fill = Brushes.Yellow;
            overlay_ammo.Opacity = 0;
            overlay_ammo.AttachTo(rcontent);
            overlay_ammo.SizeTo(400, 48);
            overlay_ammo.MoveTo(50, 128 + 32 - 8);

            var bg_ammo_opacity = bg_ammo.ToAnimatedOpacity();

            overlay_ammo.Cursor = Cursors.Hand;
            bg_ammo_opacity.Opacity = 0.5;
            overlay_ammo.MouseEnter +=
                delegate
                {
                    bg_ammo_opacity.Opacity = 1.0;
                };

            overlay_ammo.MouseLeave +=
                delegate
                {
                    bg_ammo_opacity.Opacity = 0.5;
                };
            overlay_ammo.MouseLeftButtonUp +=
             delegate
             {
                 t2o.Opacity = 1;

                 if (BuyAmmo != null)
                     BuyAmmo();
             };














            bg_shotgun.Opacity = 0.5;
            bg_shotgun.Fill = Brushes.Yellow;
            bg_shotgun.AttachTo(rcontent);
            bg_shotgun.SizeTo(400, 48);
            bg_shotgun.MoveTo(50, 128 + 64 + 32);

            var shotgun = new Avalon.Images.avatars_shotgun();

            shotgun.AttachTo(rcontent);
            shotgun.MoveTo(32 + 32, 128 + 64 + 32 + 8);



            var overlay_shotgun = new Rectangle();


            overlay_shotgun.Opacity = 0;
            overlay_shotgun.Fill = Brushes.Yellow;
            overlay_shotgun.AttachTo(rcontent);
            overlay_shotgun.SizeTo(400, 48);
            overlay_shotgun.MoveTo(50, 128 + 64 + 32);

            var bg_shotgun_opacity = bg_shotgun.ToAnimatedOpacity();

            overlay_shotgun.Cursor = Cursors.Hand;
            bg_shotgun_opacity.Opacity = 0.5;
            overlay_shotgun.MouseEnter +=
                delegate
                {
                    bg_shotgun_opacity.Opacity = 1.0;
                };

            overlay_shotgun.MouseLeave +=
                delegate
                {
                    bg_shotgun_opacity.Opacity = 0.5;
                };

            overlay_shotgun.MouseLeftButtonUp +=
                delegate
                {
                    t2o.Opacity = 1;

                    if (BuyShotgun != null)
                        BuyShotgun();
                };

            this.SizeChanged += (s, e) =>
            {



                r0shadow.MoveTo((this.Width - 500) / 2 + 4, (this.Height - 400) / 2 + 4);
                r1shadow.MoveTo((this.Width - 500) / 2 + 4, (this.Height - 400) / 2 + 4 + 96);
                rcontent.MoveTo((this.Width - 500) / 2, (this.Height - 400) / 2);

            };

            var rclose_shadow = new Rectangle();


            //rclose.Opacity = 0.8;
            rclose_shadow.Fill = Brushes.Black;
            rclose_shadow.AttachTo(rcontent);
            rclose_shadow.Opacity = 0.3;

            rclose_shadow.SizeTo(32, 32);

            var rclose = new Rectangle();


            rclose.Fill = Brushes.Red;
            rclose.AttachTo(rcontent);
            rclose.Cursor = Cursors.Hand;

            rclose.SizeTo(32, 32);

            var rclosemagin = -8;
            rclose.MoveTo(500 - 32 - rclosemagin, rclosemagin);
            rclose_shadow.MoveTo(500 - 32 - rclosemagin + 4, rclosemagin + 4);


            rclose.MouseLeftButtonUp +=
                delegate
                {
                    if (Close != null)
                        Close();
                };
        }