Exemple #1
0
#pragma warning restore CS0618

        private void MainImage_PointerMoved(object sender, PointerEventArgs e)
        {
            // allow to move cursor out leaving selection/hignlighting unchanged
            if (IgnorePointerMove(e))
            {
                return;
            }

            PointerPoint p = e.GetCurrentPoint(_mainImageControl);

            _pointerPos = p.Position;
            //
            if (p.Properties.IsMiddleButtonPressed)
            {
                TD.Point delta = ToPoint(_pointerPosDrag - _pointerPos);
                _pointerPosDrag = _pointerPos;
                _viewport.MoveOrigin(delta);
                UpdateDrawerBounds();
                MarkPresetChanged();
                InvalidateView(false); // viewport moved only
            }
            else
            {
                TD.Point u = _viewport.ToUser(ToPoint(_pointerPos));
                _gridDrawer.SetCursor(u.X, u.Y);
                var mode = e.KeyModifiers.HasFlag(KeyModifiers.Alt)
                    ? GridDrawer.CursorHighlightMode.Cents
                    : GridDrawer.CursorHighlightMode.NearestRational;
                _gridDrawer.SetCursorHighlightMode(mode);
                InvalidateView();
            }
        }
Exemple #2
0
        private void RenderThread()
        {
            while (true)
            {
                _eventRenderDoWork.WaitOne();

                //Debug.WriteLine("Render DoWork got");

                // get image and bitmap to render
                TD.Image image;            // source vector image
                int      bitmapIndex = -1; // destination raster bitmap index
                lock (_renderLock) {
                    if (_closingWindow)
                    {
                        return;
                    }
                    image = _mainImage;
                    // choose system bitmap to render
                    for (int i = 0; i < 3; ++i)
                    {
                        if (i != _copyingBitmap && i != _lastRenderedBitmap)
                        {
                            bitmapIndex = i;
                            break;
                        }
                    }
                }

                //Debug.WriteLine("Rendering to {0} begin", bitmapIndex);

                // prepare valid size bitmap
                TD.Point imageSize  = image.GetSize();
                SD.Size  bitmapSize = new SD.Size((int)imageSize.X, (int)imageSize.Y);
                BitmapAdapter.EnsureBitmapSize(
                    ref _mainBitmap.SystemBitmaps[bitmapIndex],
                    bitmapSize
                    );

                // render image to bitmap

                /* !!! slow stuff
                 *
                 * Render raster image           :    9071899 ticks / count    29 =     312824                     // smooth
                 *  Render raster image           :   12153400 ticks / count    44 =     276213                 // TextRenderingHint.SingleBitPerPixel
                 *  Render raster image           :    6779342 ticks / count    35 =     193695                 // no text
                 *  Render raster image           :    8301237 ticks / count    42 =     197648                 // no smooth
                 *      Render raster image           :    8025534 ticks / count    48 =     167198             // TextRenderingHint.SingleBitPerPixel
                 *          Render raster image           :    7030453 ticks / count    38 =     185011         // raster font MS serif
                 *      Render raster image           :    5674569 ticks / count    71 =      79923             // no text
                 * Render raster image           :   10144730 ticks / count    30 =     338157                     // always Arial 30
                 * Render raster image           :   12752666 ticks / count    39 =     326991                     // always Arial 30 - created once
                 *
                 * // read this: https://stackoverflow.com/questions/71374/fastest-api-for-rendering-text-in-windows-forms
                 * // GDI vs. GDI+ Text Rendering Performance https://techcommunity.microsoft.com/t5/windows-blog-archive/gdi-vs-gdi-text-rendering-performance/ba-p/228431
                 *
                 */

#if USE_PERF
                _perfRenderImage.Start();
#endif
                using (var graphics = SD.Graphics.FromImage(
                           _mainBitmap.SystemBitmaps[bitmapIndex]
                           )) {
                    if (_systemSettings.drawerDisableAntialiasing)
                    {
                        graphics.SmoothingMode     = SD.Drawing2D.SmoothingMode.None;
                        graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
                    }
                    else
                    {
                        graphics.SmoothingMode = SD.Drawing2D.SmoothingMode.AntiAlias; // rendering time *= 1.5
                    }
                    graphics.Clear(SD.Color.White);                                    // smooting makes ugly edges is no background filled
                    image.Draw(graphics);
                }
#if USE_PERF
                _perfRenderImage.Stop();
#endif

                //Debug.WriteLine("Rendering to {0} end", bitmapIndex);

                // Let UI thread to continue
                lock (_renderLock) {
                    _lastRenderedBitmap = bitmapIndex;
                }
                Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(UpdateMainBitmap);
            }
        }