Esempio n. 1
0
        public override void DrawScreenOn(Gdi mem, Rectangle rect)
        {
            var fromDC = _fromGraphics.GetHdc();
            var toDC   = _ToGraphics.GetHdc();

            var toWidth = (int)(ViewTransitionManager.TransitionCanvas.Width * _transitionPct);

            if (SlideDirection == TransitionType.SlideLeft)
            {
                toWidth = ViewTransitionManager.TransitionCanvas.Width - toWidth;
            }

            int fromWidth = ViewTransitionManager.TransitionCanvas.Width - toWidth;

            if (SlideDirection == TransitionType.SlideLeft)
            {
                mem.BitBlt(0, 0, toWidth, _FromBitmap.Height,
                           fromDC, fromWidth, 0, TernaryRasterOperations.SRCCOPY);

                mem.BitBlt(toWidth, 0, fromWidth, _ToBitmap.Height,
                           toDC, 0, 0, TernaryRasterOperations.SRCCOPY);
            }
            else
            {
                mem.BitBlt(0, 0, toWidth, _FromBitmap.Height,
                           toDC, fromWidth, 0, TernaryRasterOperations.SRCCOPY);

                mem.BitBlt(toWidth, 0, fromWidth, _ToBitmap.Height,
                           fromDC, 0, 0, TernaryRasterOperations.SRCCOPY);
            }

            _fromGraphics.ReleaseHdc(fromDC);
            _ToGraphics.ReleaseHdc(toDC);
        }
Esempio n. 2
0
        public void DrawRender(Gdi g)
        {
            Rectangle rect   = new Rectangle(0, 0, Width, Height);
            IntPtr    hdcMem = OffScreenGraphics.GetHdc();

            using (Gdi gMem = Gdi.FromHdc(hdcMem, Rectangle.Empty))
            {
                DrawScreenOn(gMem, rect, _currentScrollPosition);

                g.BitBlt(Location.X, Location.Y, rect.Width, rect.Height, gMem, 0, 0, TernaryRasterOperations.SRCCOPY);
            }

            OffScreenGraphics.ReleaseHdc(hdcMem);
        }
Esempio n. 3
0
        protected bool OnPaint(IntPtr hWnd)
        {
            var ps = new Win32.PAINTSTRUCT();

            if (OffScreenGraphics == null)
            {
                return(false);
            }

            var hdc    = Win32.BeginPaint(hWnd, ref ps);
            var hdcMem = OffScreenGraphics.GetHdc();

            try
            {
                using (Gdi g = Gdi.FromHdc(hdc, ps.rcPaint))
                {
                    using (Gdi gMem = Gdi.FromHdc(hdcMem, Rectangle.Empty))
                    {
                        Rectangle rect = ps.rcPaint;

                        try
                        {
                            DrawScreenOn(gMem, rect, _currentScrollPosition);
                        }
                        catch (COMException ex)
                        {
                            throw;
                        }
                        catch (Exception)
                        {
                            throw;
                        }

                        g.BitBlt(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top, gMem, rect.Left, rect.Top,
                                 TernaryRasterOperations.SRCCOPY);
                    }
                }
            }
            finally
            {
                OffScreenGraphics.ReleaseHdc(hdcMem);
                Win32.EndPaint(hWnd, ref ps);
            }

            return(true);
        }
Esempio n. 4
0
        public static Bitmap CaptureDesktop()
        {
            Bitmap bmp = null;

            {
                var hDc = IntPtr.Zero;
                try
                {
                    SIZE size;
                    hDc = Win32.GetDC(Win32.GetDesktopWindow());
                    var hMemDc = Gdi.CreateCompatibleDC(hDc);

                    size.Cx = Win32.GetSystemMetrics
                                  (Win32.SmCxscreen);

                    size.Cy = Win32.GetSystemMetrics
                                  (Win32.SmCyscreen);

                    var hBitmap = Gdi.CreateCompatibleBitmap(hDc, size.Cx, size.Cy);

                    if (hBitmap != IntPtr.Zero)
                    {
                        var hOld = Gdi.SelectObject
                                       (hMemDc, hBitmap);

                        Gdi.BitBlt(hMemDc, 0, 0, size.Cx, size.Cy, hDc,
                                   0, 0, Gdi.Srccopy);

                        Gdi.SelectObject(hMemDc, hOld);
                        Gdi.DeleteDC(hMemDc);
                        bmp = Image.FromHbitmap(hBitmap);
                        Gdi.DeleteObject(hBitmap);
                        // GC.Collect();
                    }
                }
                finally
                {
                    if (hDc != IntPtr.Zero)
                    {
                        Win32.ReleaseDC(Win32.GetDesktopWindow(), hDc);
                    }
                }
            }
            return(bmp);
        }
Esempio n. 5
0
        protected virtual void OnRender(Gdi graphics, Rectangle clipRect)
        {
            IntPtr ptrSrc = OffscreenBuffer.OffScreenGraphics.GetHdc();

            using (Gdi gr = Gdi.FromHdc(ptrSrc, Rectangle.Empty))
            {
                DrawBackground(gr, clipRect);

                // Pass the graphics to the canvas to render
                if (Canvas != null)
                {
                    Canvas.Render(gr, clipRect);
                }
            }

            graphics.BitBlt(clipRect.Left, clipRect.Top, Width, Height, ptrSrc, clipRect.Left, clipRect.Top, TernaryRasterOperations.SRCCOPY);

            OffscreenBuffer.OffScreenGraphics.ReleaseHdc(ptrSrc);

            InvokeFirstRender();
        }
Esempio n. 6
0
        public void PerformCapture()
        {
            lock (this)
            {
                _hasFrame = true;
                RECT rc;
                User.GetWindowRect(_windowHandle, out rc);

                if (rc != _rc)
                {
                    Dispose(false);
                    _rc = rc;
                    Init();
                }

                User.GetCursorPos(out _cursor);

                Gdi.SelectObject(_compatDC, _bitmap);
                Gdi.BitBlt(_compatDC, 0, 0, _rc.Width, _rc.Height, _windowDC, 0, 0, System.Drawing.CopyPixelOperation.SourceCopy);
            }
        }
Esempio n. 7
0
        protected override void OnRender(Gdi graphics, Rectangle clipRect)
        {
            IntPtr ptrSrc = OffscreenBuffer.OffScreenGraphics.GetHdc();

            using (Gdi gr = Gdi.FromHdc(ptrSrc, Rectangle.Empty))
            {
                DrawBackground(gr, clipRect);

                // fill background with double gradient
                var y = (int)(_backgroundRectangle.Height * _gradientCenter);

                gr.GradientFill(new Rectangle(_backgroundRectangle.Left, _backgroundRectangle.Top,
                                              _backgroundRectangle.Width, y),
                                _gradientColor1, _gradientColor2, FillDirection.TopToBottom);

                gr.GradientFill(new Rectangle(_backgroundRectangle.Left, _backgroundRectangle.Top + y,
                                              _backgroundRectangle.Width, _backgroundRectangle.Height - y),
                                _gradientColor2, _gradientColor3, FillDirection.TopToBottom);

                // Pass the graphics to the canvas to render
                if (Canvas != null)
                {
                    Canvas.Render(gr, clipRect);
                }

                //Draw Text
                SetFont(gr);

                gr.DrawText(_message,
                            new Win32.RECT(_textRectangle.X,
                                           _textRectangle.Y,
                                           _textRectangle.Width,
                                           _textRectangle.Height),
                            Win32.DT.LEFT | Win32.DT.TOP | Win32.DT.WORDBREAK | Win32.DT.NOCLIP);
            }

            graphics.BitBlt(clipRect.Left, clipRect.Top, Width, Height, ptrSrc, clipRect.Left, clipRect.Top, TernaryRasterOperations.SRCCOPY);

            OffscreenBuffer.OffScreenGraphics.ReleaseHdc(ptrSrc);
        }
Esempio n. 8
0
        bool OnPaint(IntPtr hWnd)
        {
            if (CurrentTransition == null)
            {
                return(false);
            }

            var ps = new Win32.PAINTSTRUCT();

            IntPtr hdc = Win32.BeginPaint(hWnd, ref ps);

            IntPtr hdcMem = _offScreenGraphics.GetHdc();

            using (Gdi g = Gdi.FromHdc(hdc, ps.rcPaint))
            {
                using (Gdi gMem = Gdi.FromHdc(hdcMem, Rectangle.Empty))
                {
                    Rectangle rect = ps.rcPaint;

                    try
                    {
                        CurrentTransition.DrawScreenOn(gMem, ps.rcPaint);
                    }
                    catch (Exception)
                    {
                        throw;
                    }

                    g.BitBlt(rect.Left, rect.Top, rect.Width, rect.Height, hdcMem, rect.Left, rect.Top,
                             TernaryRasterOperations.SRCCOPY);
                }
            }

            _offScreenGraphics.ReleaseHdc(hdcMem);
            Win32.EndPaint(hWnd, ref ps);
            return(true);
        }
Esempio n. 9
0
 public BOOL BitBlt(int x, int y, int width, int height, HDc source, int srcX, int srcY)
 {
     return(Gdi.BitBlt(this, x, y, width, height, source, srcX, srcY, RasterOperation.SourceCopy));
 }
Esempio n. 10
0
        /// <summary>
        /// Перерисовать главное окно.
        /// </summary>
        public void Redraw()
        {
            // Если заблокирована перерисовка главного окна, выходим.
            if (!NeedRedraw)
            {
                return;
            }

            // Главное окно.
            MainForm wndMain = MainWindow;

            // Если размеры клиентской области равны нулю,
            // то нечего перерисовывать - выходим.
            if (wndMain.ClientSize.Width <= 0 || wndMain.ClientSize.Height <= 0)
            {
                return;
            }

            // Смещение листа, вызванное скроллбарами.
            Point scrollbarsOffset = UpdateScrollbars(wndMain);

            // Начинаем отрисовку.
            using (var tmp = new Bitmap(wndMain.ClientSize.Width, wndMain.ClientSize.Height))
            {
                using (Graphics gtmp = Graphics.FromImage(tmp))
                {
                    // Событие: начало перерисовки главного окна.
                    if (BeginRedraw != null)
                    {
                        BeginRedraw(gtmp, tmp.Width, tmp.Height);
                    }

                    // Очищаем область для рисования.
                    gtmp.Clear(Settings.Colors.WorkArea);

                    Rectangle clientRect = wndMain.InnerRectangle;

                    int leftOffset = 0;
                    int topOffset  = 0;

                    // Рисуем лист.
                    if (IsDocumentsExists)
                    {
                        using (Bitmap sheet = CurrentDocument.DocumentSheet.Draw())
                        {
                            leftOffset = clientRect.Left + ((clientRect.Width - sheet.Width) >> 1) - scrollbarsOffset.X;
                            topOffset  = clientRect.Top + ((clientRect.Height - sheet.Height) >> 1) - scrollbarsOffset.Y;

                            const int shadowSize = 3;
                            gtmp.FillRectangle(Brushes.Black, leftOffset + sheet.Width, topOffset + shadowSize,
                                               shadowSize, sheet.Height);
                            gtmp.FillRectangle(Brushes.Black, leftOffset + shadowSize, topOffset + sheet.Height,
                                               sheet.Width - shadowSize, shadowSize);

                            if (Settings.Environment.CanUseNative)
                            {
                                using (Graphics sourceGfx = Graphics.FromImage(sheet))
                                {
                                    Gdi.BitBlt(
                                        sheet, sourceGfx,
                                        0, 0,
                                        gtmp,
                                        leftOffset, topOffset,
                                        sheet.Width, sheet.Height);
                                }
                            }
                            else
                            {
                                gtmp.DrawImageUnscaled(sheet, leftOffset, topOffset);
                            }

                            gtmp.DrawRectangle(
                                Settings.Pens.SheetBorder,
                                leftOffset - 1,
                                topOffset - 1,
                                sheet.Width + 1,
                                sheet.Height + 1);
                        }
                    }

                    // Рисуем линейки.
                    DrawRulers(gtmp, clientRect, leftOffset, topOffset);

                    // Событие: конец перерисовки главного окна.
                    // TODO: как-то по-другому обозвать событие что-ли? Ведь окно ещё не отрисовано.
                    if (EndRedraw != null)
                    {
                        EndRedraw(gtmp, tmp.Width, tmp.Height);
                    }

                    gtmp.Flush();

                    // Отрисовываем получившееся изображение в окно.
                    using (Graphics gfx = wndMain.CreateGraphics())
                        if (Settings.Environment.CanUseNative)
                        {
                            Gdi.BitBlt(tmp, gtmp, 0, 0, gfx, 0, 0, tmp.Width, tmp.Height);
                        }
                        else
                        {
                            gfx.DrawImageUnscaled(tmp, 0, 0);
                        }
                }
            }
        }