Example #1
0
        private void RenderThreadStart()
        {
            while (_rendererSignal.WaitOne())
            {
                RenderArgs e;
                lock (this)
                {
                    e = _bgRenderArgs;
                    if (e == null)
                        continue;
                }

                var g = Graphics.FromImage(_backBuffer);

                g.Transform = Viewport.GetRotationScaleMatrix(e.Matrix);

                /*var invRotScale = e.Matrix;
                invRotScale.OffsetX = invRotScale.OffsetY = 0;
                invRotScale.Invert();

                var translate = e.Matrix * invRotScale;*/
                var translate = Viewport.GetTranslateMatrix(e.Matrix);

                BeginInvoke(new ThreadStart(RenderingStarted));

                if (_renderer != null)
                {
                    try
                    {
                        _map.Zoom = e.Scale;
                        _map.Angle = viewport1.Angle;
                        //_renderer.Angle = (float);
                        _renderer.Zoom = e.Scale;
                        _renderer.Window = e.ViewBox;
                        _renderer.Matrix = e.Matrix;
                        _renderer.Translate = translate;
                        _renderer.BeginScene(g);
                        _renderer.Render();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                /*}
                else
                {*/
                    //g.Clear(Color.Gray);
                    //draw test rectagle
                    var rectPosition = translate.Transform(new WinPoint(100.0, 200.0));
                    PointF rectPositionF = rectPosition.ToPointF();
                    g.DrawRectangle(Pens.Black, rectPositionF.X, rectPositionF.Y, 100f, 100f);

                    var p = new WinPoint(100, 200);
                    p = translate.Transform(p);
                    g.DrawString("hello world jpgqy", SystemFonts.DefaultFont, Brushes.Black, p.ToPointF(), new System.Drawing.StringFormat { LineAlignment = StringAlignment.Far });

                }

                BeginInvoke(new ThreadStart(RenderingComplete));
                lock (this)
                {
                    var temp = _backBuffer;
                    _backBuffer = _frontBuffer;
                    _frontBuffer = temp;
                    _imageTransform = e.Matrix;
                    _imageTransform.Invert();
                    viewport1.Invalidate();
                }
            }
        }