Beispiel #1
0
        /// <summary>Constructor; initializes the window and constructs the tab thumbnail image to use when dragging.</summary>
        /// <param name="tab">Tab that was torn out of its parent window.</param>
        /// <param name="tabRenderer">Renderer instance to use when drawing the actual tab.</param>
        public TornTabForm(TitleBarTab tab, BaseTabRenderer tabRenderer)
        {
            _layeredWindow = new LayeredWindow();
            _initialized   = false;

            // Set drawing styles
            SetStyle(ControlStyles.DoubleBuffer, true);

            // This should show up as a semi-transparent borderless window
            Opacity         = 0.70;
            ShowInTaskbar   = false;
            FormBorderStyle = FormBorderStyle.None;
// ReSharper disable DoNotCallOverridableMethodsInConstructor
            BackColor = Color.Fuchsia;
// ReSharper restore DoNotCallOverridableMethodsInConstructor
            TransparencyKey   = Color.Fuchsia;
            AllowTransparency = true;

            Disposed += TornTabForm_Disposed;

            // Get the tab thumbnail (full size) and then draw the actual representation of the tab onto it as well
            Bitmap   tabContents    = tab.GetImage();
            Bitmap   contentsAndTab = new Bitmap(tabContents.Width, tabContents.Height + tabRenderer.TabHeight, tabContents.PixelFormat);
            Graphics tabGraphics    = Graphics.FromImage(contentsAndTab);

            tabGraphics.DrawImage(tabContents, 0, tabRenderer.TabHeight);

            bool oldShowAddButton = tabRenderer.ShowAddButton;

            tabRenderer.ShowAddButton = false;
            tabRenderer.Render(
                new List <TitleBarTab>
            {
                tab
            }, tabGraphics, new Point(0, 0), new Point(0, 0), true);
            tabRenderer.ShowAddButton = oldShowAddButton;

            // Scale the thumbnail down to half size
            _tabThumbnail = new Bitmap(contentsAndTab.Width / 2, contentsAndTab.Height / 2, contentsAndTab.PixelFormat);
            Graphics thumbnailGraphics = Graphics.FromImage(_tabThumbnail);

            thumbnailGraphics.InterpolationMode  = InterpolationMode.High;
            thumbnailGraphics.CompositingQuality = CompositingQuality.HighQuality;
            thumbnailGraphics.SmoothingMode      = SmoothingMode.AntiAlias;
            thumbnailGraphics.DrawImage(contentsAndTab, 0, 0, _tabThumbnail.Width, _tabThumbnail.Height);

            Width  = _tabThumbnail.Width - 1;
            Height = _tabThumbnail.Height - 1;

            _cursorOffset = new Point(tabRenderer.TabContentWidth / 4, tabRenderer.TabHeight / 4);

            SetWindowPosition(Cursor.Position);
        }
Beispiel #2
0
        /// <summary>
        /// Calls <see cref="EasyTabs.LayeredWindow.UpdateWindow" /> to update the position of the thumbnail and blend it properly with the underlying desktop elements
        /// </summary>
        private void UpdateLayeredBackground()
        {
            if (TabThumbnail == null || !Initialized)
            {
                return;
            }
            byte opacity = (byte)(Opacity * 255);

            LayeredWindow.UpdateWindow(TabThumbnail, opacity, Width, Height,
                                       new POINT {
                x = Location.X, y = Location.Y
            });
        }
Beispiel #3
0
        public TornTabForm(TitleBarTab tab, BaseTabRenderer tabRenderer)
        {
            LayeredWindow = new LayeredWindow();
            Initialized   = false;
            SetStyle(ControlStyles.DoubleBuffer, true);
            Opacity           = 0.70;
            ShowInTaskbar     = false;
            FormBorderStyle   = FormBorderStyle.None;
            BackColor         = Color.Fuchsia;
            TransparencyKey   = Color.Fuchsia;
            AllowTransparency = true;

            Disposed += OnDisposed;

            Bitmap tabContents    = tab.GetThumbnail();
            Bitmap contentsAndTab = new Bitmap(tabContents.Width, tabContents.Height + tabRenderer.TabHeight,
                                               tabContents.PixelFormat);
            Graphics tabGraphics = Graphics.FromImage(contentsAndTab);

            tabGraphics.DrawImage(tabContents, 0, tabRenderer.TabHeight);

            bool oldShowAddButton = tabRenderer.ShowAddButton;

            tabRenderer.ShowAddButton = false;
            tabRenderer.Render(new List <TitleBarTab> {
                tab
            }, tabGraphics, new Point(0, 0), new Point(0, 0), true);
            tabRenderer.ShowAddButton = oldShowAddButton;

            TabThumbnail = new Bitmap(contentsAndTab.Width / 2, contentsAndTab.Height / 2, contentsAndTab.PixelFormat);
            Graphics thumbnailGraphics = Graphics.FromImage(TabThumbnail);

            thumbnailGraphics.InterpolationMode  = InterpolationMode.High;
            thumbnailGraphics.CompositingQuality = CompositingQuality.HighQuality;
            thumbnailGraphics.SmoothingMode      = SmoothingMode.AntiAlias;
            thumbnailGraphics.DrawImage(contentsAndTab, 0, 0, TabThumbnail.Width, TabThumbnail.Height);

            Width        = TabThumbnail.Width - 1;
            Height       = TabThumbnail.Height - 1;
            CursorOffset = new Point(tabRenderer.TabContentWidth / 4, tabRenderer.TabHeight / 4);
            SetWindowPosition(Cursor.Position);
        }
Beispiel #4
0
        /// <summary>
        /// Event handler that's called when the window is loaded; shows <see cref="_layeredWindow" /> and installs the mouse hook via <see cref="Win32Interop.Methods.User32.SetWindowsHookEx" />
        /// </summary>
        /// <param name="e">Arguments associated with this event</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Initialized = true;
            UpdateLayeredBackground();
            LayeredWindow.Show();
            LayeredWindow.Enabled = false;
            if (!HookInstalled)
            {
                using (Process curProcess = Process.GetCurrentProcess())
                {
                    using (ProcessModule curModule = curProcess.MainModule)
                    {
                        HookProc = MouseHookCallBack;
                        HookID   = User32.SetWindowsHookEx(WH.WH_MOUSE_LL, HookProc,
                                                           Kernel32.GetModuleHandle(curModule.ModuleName), 0);
                    }
                }

                HookInstalled = true;
            }
        }
Beispiel #5
0
 /// <summary>
 /// Event handler that is called when the window is closing; closes <see cref="LayeredWindow" /> as well
 /// </summary>
 /// <param name="e">Arguments associated with this event</param>
 protected override void OnClosing(CancelEventArgs e)
 {
     base.OnClosing(e);
     LayeredWindow.Close();
 }
Beispiel #6
-1
        /// <summary>Constructor; initializes the window and constructs the tab thumbnail image to use when dragging.</summary>
        /// <param name="tab">Tab that was torn out of its parent window.</param>
        /// <param name="tabRenderer">Renderer instance to use when drawing the actual tab.</param>
        public TornTabForm(TitleBarTab tab, BaseTabRenderer tabRenderer)
        {
            _layeredWindow = new LayeredWindow();
            _initialized = false;

            // Set drawing styles
            SetStyle(ControlStyles.DoubleBuffer, true);

            // This should show up as a semi-transparent borderless window
            Opacity = 0.70;
            ShowInTaskbar = false;
            FormBorderStyle = FormBorderStyle.None;
            // ReSharper disable DoNotCallOverridableMethodsInConstructor
            BackColor = Color.Fuchsia;
            // ReSharper restore DoNotCallOverridableMethodsInConstructor
            TransparencyKey = Color.Fuchsia;
            AllowTransparency = true;

            Disposed += TornTabForm_Disposed;

            // Get the tab thumbnail (full size) and then draw the actual representation of the tab onto it as well
            Bitmap tabContents = tab.GetImage();
            Bitmap contentsAndTab = new Bitmap(tabContents.Width, tabContents.Height + tabRenderer.TabHeight, tabContents.PixelFormat);
            Graphics tabGraphics = Graphics.FromImage(contentsAndTab);

            tabGraphics.DrawImage(tabContents, 0, tabRenderer.TabHeight);

            bool oldShowAddButton = tabRenderer.ShowAddButton;

            tabRenderer.ShowAddButton = false;
            tabRenderer.Render(
                new List<TitleBarTab>
                {
                    tab
                }, tabGraphics, new Point(0, 0), new Point(0, 0), true);
            tabRenderer.ShowAddButton = oldShowAddButton;

            // Scale the thumbnail down to half size
            _tabThumbnail = new Bitmap(contentsAndTab.Width / 2, contentsAndTab.Height / 2, contentsAndTab.PixelFormat);
            Graphics thumbnailGraphics = Graphics.FromImage(_tabThumbnail);

            thumbnailGraphics.InterpolationMode = InterpolationMode.High;
            thumbnailGraphics.CompositingQuality = CompositingQuality.HighQuality;
            thumbnailGraphics.SmoothingMode = SmoothingMode.AntiAlias;
            thumbnailGraphics.DrawImage(contentsAndTab, 0, 0, _tabThumbnail.Width, _tabThumbnail.Height);

            Width = _tabThumbnail.Width - 1;
            Height = _tabThumbnail.Height - 1;

            _cursorOffset = new Point(tabRenderer.TabContentWidth / 4, tabRenderer.TabHeight / 4);

            SetWindowPosition(Cursor.Position);
        }