Ejemplo n.º 1
0
        public static void SwitchFullScreen(Window win, ref Rect lastRect, bool?fullScreen = null, Rect monitorInfo = default)
        {
            if (monitorInfo == default)
            {
                monitorInfo = NativeHelpers.GetMonitorFromWindow(win);
            }

            if (fullScreen == null)
            {
                fullScreen = !IsFullScreen(win, monitorInfo);
            }

            win.WindowState = WindowState.Normal;//need WindowState.Normal to hide taskbar under fullscreen
            if (fullScreen.Value)
            {
                //go fullscreen
                lastRect   = new Rect(win.Left, win.Top, win.Width, win.Height);
                win.Top    = monitorInfo.Top;
                win.Left   = monitorInfo.Left;
                win.Width  = monitorInfo.Width;
                win.Height = monitorInfo.Height;
            }
            else
            {
                //restore last
                win.Top    = lastRect.Top;
                win.Left   = lastRect.Left;
                win.Width  = lastRect.Width;
                win.Height = lastRect.Height;
            }
        }
Ejemplo n.º 2
0
 protected override void OnStateChanged(EventArgs e)
 {
     //override state behavior to enable fullscreen in immersion mode
     if (WindowState == WindowState.Maximized && Setting.ImmersionMode)
     {
         WindowState = WindowState.Normal;
         var info = NativeHelpers.GetMonitorFromWindow(this);
         if (Top == info.Top && Left == info.Left && Width == info.Width && Height == info.Height)
         {
             //restore
             Top    = lastWindowRect.Top;
             Left   = lastWindowRect.Left;
             Width  = lastWindowRect.Width;
             Height = lastWindowRect.Height;
         }
         else
         {
             //fullscreen
             lastWindowRect = new Rect(Left, Top, Width, Height);
             Top            = info.Top;
             Left           = info.Left;
             Width          = info.Width;
             Height         = info.Height;
         }
     }
 }
Ejemplo n.º 3
0
        public static bool IsFullScreen(Window win, Rect monitorInfo = default)
        {
            if (monitorInfo == default)
            {
                monitorInfo = NativeHelpers.GetMonitorFromWindow(win);
            }

            return(win.Top == monitorInfo.Top && win.Left == monitorInfo.Left && win.Width == monitorInfo.Width && win.Height == monitorInfo.Height);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Fade in the window at mouse position. Or the specified Left and Top position.
        /// If the window is already faded in, move the window to the new position. In this case the FadingInEvent will not be raised.
        /// </summary>
        public void FadeIn(double left = double.NaN, double top = double.NaN)
        {
            if (!IsLoaded)
            {
                Opacity = 0d;
                Show();//how to call something similar to initializecomponent?
            }

            //reset nextCloseBehavior
            nextCloseBehavior = CloseBehavior;

            //compute mouse position or set to existing values
            Point  newpos, realpos = default;
            var    mon       = NativeHelpers.GetMonitorFromWindow(this);
            double currscrnW = mon.Right;
            double currscrnH = mon.Bottom;

            if (WindowStartupLocation == WindowStartupLocation.Manual)
            {
                if (left.Equals(double.NaN) || top.Equals(double.NaN))
                {
                    //get the physical pixel-based position.
                    newpos = PointToScreen(Mouse.GetPosition(this));
                    //convert to the actual position considering the DPI settings etc.
                    realpos = PresentationSource.FromVisual(this).CompositionTarget.TransformFromDevice.Transform(newpos);

                    //make sure the window is displayed inside the screens.
                    double originX, originY;
                    if (currscrnW - realpos.X > ActualWidth)
                    {
                        originX = 0d;
                    }
                    else
                    {
                        originX    = 1d;
                        realpos.X -= ActualWidth;
                    }
                    if (currscrnH - realpos.Y > ActualHeight)
                    {
                        originY = 0d;
                    }
                    else
                    {
                        originY    = 1d;
                        realpos.Y -= ActualHeight;
                    }
                    RenderTransformOrigin_BG = new Point(originX, originY);
                }
                else
                {
                    //make sure the window is displayed inside the screens.
                    if (left < 0d)
                    {
                        left = 0d;
                    }
                    if (top < 0d)
                    {
                        top = 0d;
                    }
                    if (left + ActualWidth > currscrnW)
                    {
                        left = currscrnW - ActualWidth;
                    }
                    if (top + ActualHeight > currscrnH)
                    {
                        top = currscrnH - ActualHeight;
                    }
                    realpos = new Point(left, top);
                }
            }

            if (Opacity == 0d)
            {
                if (realpos != default)
                {
                    Left = realpos.X;
                    Top  = realpos.Y;
                }
                Show();
                RaiseEvent(new RoutedEventArgs(FadingInEvent));
            }
            else
            {
                //move window to the new cursor location
                var easefunc = new CubicEase()
                {
                    EasingMode = EasingMode.EaseInOut
                };
                var anim_move_x = new DoubleAnimation(realpos.X, new Duration(new TimeSpan(0, 0, 0, 0, 300)), FillBehavior.Stop)
                {
                    EasingFunction = easefunc
                };
                var anim_move_y = new DoubleAnimation(realpos.Y, new Duration(new TimeSpan(0, 0, 0, 0, 300)), FillBehavior.Stop)
                {
                    EasingFunction = easefunc
                };
                BeginAnimation(LeftProperty, anim_move_x);
                BeginAnimation(TopProperty, anim_move_y);
            }
        }
Ejemplo n.º 5
0
        private void Sidebar_Click(object sender, MouseButtonEventArgs e)
        {
            switch (((FrameworkElement)sender).Name)
            {
            case nameof(HY_Open):
                openFolderPrompt();
                break;

            case nameof(HY_CacheFirst):
                CacheHelper.CachePath(CurrentPath, true, this, this);
                break;

            case nameof(HY_CacheAll):
                CacheHelper.CachePath(CurrentPath, false, this, this);
                break;

            case nameof(HY_Options):
                var win = new SettingsWindow(this);
                win.ShowDialog();
                win.Close();
                break;

            case nameof(HY_Slideshow):
                new SlideshowWindow(CurrentPath).Show();
                break;

            case nameof(HY_ImmersionMode):
                Setting.ImmersionMode = !Setting.ImmersionMode;
                if (Setting.ImmersionMode)
                {
                    virWrapPanel.ScrollOwner.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
                    if (WindowState == WindowState.Maximized)
                    {
                        //go fullscreen if alreayd maximized
                        WindowState    = WindowState.Normal;
                        lastWindowRect = new Rect(Left, Top, Width, Height);
                        var info = NativeHelpers.GetMonitorFromWindow(this);
                        Top    = info.Top;
                        Left   = info.Left;
                        Width  = info.Width;
                        Height = info.Height;
                    }
                }
                else
                {
                    virWrapPanel.ScrollOwner.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
                    if (lastWindowRect.Size.Width + lastWindowRect.Size.Height > 0)
                    {
                        Top    = lastWindowRect.Top;
                        Left   = lastWindowRect.Left;
                        Width  = lastWindowRect.Width;
                        Height = lastWindowRect.Height;
                    }
                }
                break;

            case nameof(HY_Close):
                Close();
                break;
            }
        }