Example #1
0
        /// <summary>
        /// Function to clean up any objects that are allocating memory.
        /// </summary>
        private void CleanUp()
        {
            if (_buffer != null)
            {
                _buffer.Dispose();
                _buffer = null;
            }

            if (_graphicsContext != null)
            {
                _graphicsContext.Dispose();
                _graphicsContext = null;
            }

            if (_graphics != null)
            {
                _graphics.Dispose();
                _graphics = null;
            }

            if (_imageGraphics != null)
            {
                _imageGraphics.Dispose();
                _imageGraphics = null;
            }

            if (_mouseImage == null)
            {
                return;
            }

            _mouseImage.Dispose();
            _mouseImage = null;
        }
Example #2
0
 /// <summary>
 /// Stops splash screen and frees graphic resources.
 /// Останавливает отрисовку заставки и освобождает ресурсы.
 /// </summary>
 public static void SplashScreenStop()
 {
     timer.Dispose();
     _objs = null;
     _context.Dispose();
     Buffer.Dispose();
 }
Example #3
0
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                if (components != null)
                {
                    components.Dispose();
                }
                if (Layers != null)
                {
                    foreach (Layer l in Layers)
                    {
                        l.Dispose();
                    }
                }
                if (backbufferGraphics != null)
                {
                    backbufferGraphics.Dispose();
                }
                if (backbufferContext != null)
                {
                    backbufferContext.Dispose();
                }

                if (customBrush != null)
                {
                    customBrush.Dispose();
                }
            }
            base.Dispose(disposing);
        }
Example #4
0
        public void ResizeBuffer()
        {
            //assert that buffer was created after resize
            if (Buffer != null)
            {
                Buffer.Dispose();
                BufferContext.Dispose();
                Buffer        = null;
                BufferContext = null;
            }


            //don't resize if less than 1x1
            if (refRenderTarget.Width > 0 && refRenderTarget.Height > 0)
            {
                //make it larger than control in order to create temp buffer
                BufferContext = BufferedGraphicsManager.Current;
                BufferContext.MaximumBuffer = new Size(refRenderTarget.Width + 1, refRenderTarget.Height + 1);
                Buffer = BufferContext.Allocate(refRenderTarget.CreateGraphics(), new Rectangle(0, 0, refRenderTarget.Width, refRenderTarget.Height));
            }
            else
            {
                Buffer = null;
                //throw new RenderDeviceException("Buffer could not be resized!");
            }
        }
Example #5
0
 void MainFormFormClosed(object sender, FormClosedEventArgs e)
 {
     bg.Dispose();
     bgc.Dispose();
     //mg.ReleaseHdc();
     mg.Dispose();
 }
Example #6
0
        private void drawGyroGraph()
        {
            //get our graphics buffer going so we can draw to our panel
            gyroGraphicsContext = new BufferedGraphicsContext();
            gyroGraphicsBuffer  = gyroGraphicsContext.Allocate(Graphics.FromImage(gyroDrawingSurface), gyroboundsRectangle);
            gyroGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            gyroGraphicsBuffer.Graphics.Clear(SystemColors.Control);


            float xCenter = (float)(gyroboundsRectangle.Width / 2.0);
            float yCenter = (float)(gyroboundsRectangle.Height / 2.0);

            //heading circles
            for (int i = 0; i < spatial.gyroAxes.Count; i++)
            {
                gyroGraphicsBuffer.Graphics.DrawEllipse(gyrocirclePen, gyrocircleRectangle[i]);
                gyroGraphicsBuffer.Graphics.DrawEllipse(
                    gyroxyAxisPen[i],
                    (float)(gyrocircleRadius[i] * Math.Cos(gyroHeading[i] * (Math.PI / 180.0)) + xCenter) - 2,
                    (float)(-gyrocircleRadius[i] * Math.Sin(gyroHeading[i] * (Math.PI / 180.0)) + yCenter) - 2,
                    4,
                    4
                    );
            }

            gyroGraphicsBuffer.Render(gyroView.CreateGraphics());

            gyroGraphicsBuffer.Dispose();

            gyroGraphicsContext.Dispose();
        }
Example #7
0
        public void Draw()
        {
            var tmpG = Graphics.FromImage(bitmap);

            tmpG.Clear(ForeColor);
            MoveTmpToNormal();
            tmpG.SmoothingMode = SmoothingMode.AntiAlias;
            foreach (GraphItem obj in root.Children)
            {
                var state = tmpG.Save();
                obj.OnPaint(tmpG, new Rectangle(0, 0, Width, Height), matrix);
                tmpG.Restore(state);
            }
            if (matrix != null)
            {
                matrix.Reset();
            }
            BufferedGraphicsContext ctx         = new BufferedGraphicsContext();
            BufferedGraphics        graphBuffer = ctx.Allocate(g, new Rectangle(0, 0, Width, Height));
            Graphics diaplayGraphic             = graphBuffer.Graphics;

            diaplayGraphic.Clear(ForeColor);
            diaplayGraphic.DrawImage(bitmap, 0, 0);


            graphBuffer.Render();
            graphBuffer.Dispose();
            ctx.Invalidate();
            ctx.Dispose();
        }
Example #8
0
 private void DisposeManagedResources()
 {
     m_bufferedGraphicsContext.Dispose();
     if (m_bufferedGraphics != null)
     {
         m_bufferedGraphics.Dispose();
     }
 }
Example #9
0
 public void Dispose()
 {
     _currentContext?.Dispose();
     _screenBuffer?.Dispose();
     _screenGraphics?.Dispose();
     _gameBuffer?.Dispose();
     _gameGraphics?.Dispose();
 }
Example #10
0
        public void Dispose()
        {
            DisposeBuffer();

            if (_graphicsContext != null)
            {
                _graphicsContext.Dispose();
                _graphicsContext = null;
            }
        }
Example #11
0
 /// <summary>
 /// Frees game's resources.
 /// </summary>
 public static void GameStop()
 {
     Program.form.KeyDown -= Form_KeyDown;
     timer.Dispose();
     objs   = null;
     ship   = null;
     bullet = null;
     asteroids.Clear();
     context.Dispose();
     Buffer.Dispose();
 }
Example #12
0
        private void drawCompassBearingGraph()
        {
            compassGraphicsContext = new BufferedGraphicsContext();
            compassGraphicsBuffer  = compassGraphicsContext.Allocate(Graphics.FromImage(compassDrawingSurface), compassboundsRectangle);
            compassGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            compassGraphicsBuffer.Graphics.Clear(SystemColors.Control);

            float xCenter = (float)(compassboundsRectangle.Width / 2.0);
            float yCenter = (float)(compassboundsRectangle.Height / 2.0);

            compassGraphicsBuffer.Graphics.DrawEllipse(compassCirclePen, compasscircleRectangle);

            Point pt = new Point((int)(xCenter - spatialImage.Width / 2), (int)(yCenter - spatialImage.Height / 2));

            compassGraphicsBuffer.Graphics.DrawImageUnscaled(rotateImage(spatialImage, (float)compassBearing), pt);

            compassGraphicsBuffer.Graphics.DrawString("N", new Font("Arial", 16), new SolidBrush(Color.Black), xCenter - 10, 0);
            compassGraphicsBuffer.Graphics.DrawString("E", new Font("Arial", 16), new SolidBrush(Color.Black), xCenter * 2 - 20, yCenter - 12);
            compassGraphicsBuffer.Graphics.DrawString("S", new Font("Arial", 16), new SolidBrush(Color.Black), xCenter - 10, yCenter * 2 - 20);
            compassGraphicsBuffer.Graphics.DrawString("W", new Font("Arial", 16), new SolidBrush(Color.Black), 0, yCenter - 12);

            //Ticks around the compass circle
            for (int i = 0; i < 360; i += 10)
            {
                Pen p        = compassTickPen;
                int tickSize = 4;
                if (i == 0 || i == 90 || i == 180 || i == 270)
                {
                    p        = compassTickPenBig;
                    tickSize = 6;
                }
                compassGraphicsBuffer.Graphics.DrawLine(p,
                                                        (float)((compassCircleRadius + tickSize) * Math.Cos(i * (Math.PI / 180.0)) + xCenter),
                                                        (float)(-(compassCircleRadius + tickSize) * Math.Sin(i * (Math.PI / 180.0)) + yCenter),
                                                        (float)((compassCircleRadius - tickSize) * Math.Cos(i * (Math.PI / 180.0)) + xCenter),
                                                        (float)(-(compassCircleRadius - tickSize) * Math.Sin(i * (Math.PI / 180.0)) + yCenter));
            }

            //Marker on the compass circle
            compassGraphicsBuffer.Graphics.DrawEllipse(
                compassDotPen,
                (float)(compassCircleRadius * Math.Cos((-compassBearing + 90) * (Math.PI / 180.0)) + xCenter) - 2,
                (float)(-compassCircleRadius * Math.Sin((-compassBearing + 90) * (Math.PI / 180.0)) + yCenter) - 2,
                4,
                4
                );

            compassGraphicsBuffer.Render(compassView.CreateGraphics());

            compassGraphicsBuffer.Dispose();

            compassGraphicsContext.Dispose();
        }
Example #13
0
 public void Dispose_BusyAndValidated_ThrowsInvalidOperationException()
 {
     using (var context = new BufferedGraphicsContext())
         using (var image = new Bitmap(10, 10))
             using (Graphics graphics = Graphics.FromImage(image))
             {
                 using (context.Allocate(graphics, Rectangle.Empty))
                 {
                     Assert.Throws <InvalidOperationException>(() => context.Dispose());
                 }
             }
 }
Example #14
0
        public void Resize()
        {
            _bufferedGraphics?.Dispose();
            _bufferedGraphicsContext?.Dispose();

            _bufferedGraphicsContext = BufferedGraphicsManager.Current;
            _bufferedGraphics        = _bufferedGraphicsContext.Allocate(_form.CreateGraphics(), _form.DisplayRectangle);
            _screenGraphics          = _bufferedGraphics.Graphics;

            _screenGraphics.SmoothingMode     = SmoothingMode.None;
            _screenGraphics.InterpolationMode = InterpolationMode.NearestNeighbor;
        }
Example #15
0
        private void DoRedraw(Rectangle rect)
        {
            BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
            BufferedGraphics        myBuffer       = currentContext.Allocate(control.CreateGraphics(), rect);
            Graphics g = myBuffer.Graphics;

            provider.DoRedraw(g, rect);

            myBuffer.Render();
            myBuffer.Dispose();
            currentContext.Dispose();
        }
Example #16
0
    public void Method12()
    {
        // <snippet12>
        BufferedGraphicsContext myContext;

        myContext = new BufferedGraphicsContext();
        // Insert code to create graphics here.
        // On a non-default BufferedGraphicsContext instance, you should always
        // call Dispose when finished.
        myContext.Dispose();
        // </snippet12>
    }
Example #17
0
        /// <summary>
        /// Выход из игры.
        /// </summary>

        private static void ExitGame()
        {
            Buffer.Dispose();
            _context.Dispose();
            gameTimer.Stop();
            GameForm.Dispose();
            GameForm.Close();
            GC.Collect();
            SplashScreen.MainForm.Show();
            SplashScreen.Init(SplashScreen.MainForm);
            SplashScreen.Draw();
            Program.CloseGame = false;
        }
Example #18
0
        /// <summary>
        /// Function to perform clean up on the objects within this object.
        /// </summary>
        /// <param name="clearDrawing">TRUE to destroy the drawing image, FALSE to leave alone.</param>
        private void CleanUp(bool clearDrawing)
        {
            if (_buffer != null)
            {
                _buffer.Dispose();
                _buffer = null;
            }

            if (_context != null)
            {
                _context.Dispose();
                _context = null;
            }

            if (_surfaceGraphics != null)
            {
                _surfaceGraphics.Dispose();
                _surfaceGraphics = null;
            }

            if (_controlGraphics != null)
            {
                _controlGraphics.Dispose();
                _controlGraphics = null;
            }

            if (_sufaceBuffer != null)
            {
                _sufaceBuffer.Dispose();
                _sufaceBuffer = null;
            }

            if (!clearDrawing)
            {
                return;
            }

            if (_imageGraphics != null)
            {
                _imageGraphics.Dispose();
                _imageGraphics = null;
            }

            if (_drawing == null)
            {
                return;
            }

            _drawing.Dispose();
            _drawing = null;
        }
        /// <summary>
        /// Action call for the Mouse-Move event. For the x-coordinate
        /// supplied by the MouseEvent, the unscaled x and y coordinates
        /// of the plotted function are determined and displayed
        /// on the control.
        /// </summary>
        private void panel_MouseMove(object sender, MouseEventArgs e)
        {
            int    Xh, Xc;
            HTuple Ytup;
            float  Yh, Yc;

            Xh = e.X;

            if (PreX == Xh || Xh < originX || Xh > BorderRight || func == null)
            {
                return;
            }

            PreX = Xh;

            Xc   = (int)Math.Round((Xh - originX) / scaleX);
            Ytup = func.GetYValueFunct1d(new HTuple(Xc), "zero");

            Yc = (float)Ytup[0].D;
            Yh = panelHeight - (Yc * scaleY);

            BufferedGraphicsContext ctx = BufferedGraphicsManager.Current;
            BufferedGraphics        bg  = ctx.Allocate(gPanel, new Rectangle(new Point(0, 0), panel.Size));
            Graphics gOfbuff            = bg.Graphics;
            Bitmap   toDrawBeffor       = new Bitmap(panel.Width, panel.Height);
            Graphics gOfToDrawBeffor    = Graphics.FromImage(toDrawBeffor);

            // 自定义绘图
            gOfToDrawBeffor.DrawLine(Pens.Blue, 0, 0, 1000, 1000);

            gOfToDrawBeffor.DrawImageUnscaled(functionMap, 0, 0);
            gOfToDrawBeffor.DrawLine(penCursor, Xh, 0, Xh, BorderTop);
            gOfToDrawBeffor.DrawLine(penCursor, originX, Yh, BorderRight + margin, Yh);
            string xStr = string.Format("{0}={1}", XName, Xc);
            string yStr = string.Format("{0}={1}", YName, (int)Yc);

            gOfToDrawBeffor.DrawString(xStr, drawFont, brushCS, panelWidth - margin * 4, 10);
            gOfToDrawBeffor.DrawString(yStr, drawFont, brushCS, panelWidth - margin * 4, 20);

            //双缓存到panel上
            gOfbuff.Clear(panel.BackColor);
            gOfbuff.DrawImage(toDrawBeffor, 0, 0);
            bg.Render();
            toDrawBeffor.Dispose();
            gOfToDrawBeffor.Dispose();
            gOfbuff.Dispose();
            ctx.Dispose();
            bg.Dispose();
        }
Example #20
0
        private void RemoveVerticalLine(Graphics g, Point point)
        {
            Rectangle rect     = provider.DrawRect;
            Rectangle drawRect = new Rectangle(point.X - 2, rect.Y, 4, rect.Height);

            BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
            BufferedGraphics        myBuffer       = currentContext.Allocate(g, drawRect);
            Graphics graphic = myBuffer.Graphics;

            provider.DoRedraw(graphic, drawRect);

            myBuffer.Render();
            myBuffer.Dispose();
            currentContext.Dispose();
        }
Example #21
0
 protected override void Dispose(bool disposing)
 {
     isDisposing = true;
     if (disposing)
     {
         // We must dispose of backbufferGraphics before we dispose of backbufferContext or we will get an exception.
         if (backbufferGraphics != null)
         {
             backbufferGraphics.Dispose();
         }
         if (backbufferContext != null)
         {
             backbufferContext.Dispose();
         }
     }
     base.Dispose(disposing);
 }
Example #22
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     if (disposing)
     {
         __graphics.Dispose();
         if (DOUBLE_BUFFERED)
         {
             __bufferedGraphics.Dispose();
             if (__disposeContext)
             {
                 __context.Dispose();
             }
         }
     }
     __graphics = null;
     __handle   = IntPtr.Zero;
 }
Example #23
0
 internal void Release()
 {
     if (Graphics != null)
     {
         Graphics.Dispose();
     }
     if (Surface != null)
     {
         Surface.Dispose();
     }
     if (Context != null)
     {
         Context.Dispose();
     }
     Graphics = null;
     Surface  = null;
     Context  = null;
 }
Example #24
0
        /// <summary>
        /// The main loop to render
        /// </summary>
        private void Render()
        {
            int  framesRendered = 0;
            long startTime      = Environment.TickCount;

            Bitmap   frame          = new Bitmap(CANVAS_WIDTH, CANVAS_HEIGHT); //This bitmap is used to draw upon on the loop, doing this allows us to only draw 1 image on the panel
            Bitmap   movingFrame    = new Bitmap(CANVAS_WIDTH, CANVAS_HEIGHT);
            Graphics frameGraphics  = Graphics.FromImage(frame);               //Extract the graphics object from the Bitmap
            Graphics movingGraphics = Graphics.FromImage(movingFrame);

            frameGraphics.Clear(Color.Red);
            IterateGridObjects(frameGraphics);
            BufferedGraphicsContext buffer           = new BufferedGraphicsContext();
            BufferedGraphics        bufferedGraphics = buffer.Allocate(drawHandle, new Rectangle(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT));

            while (render)
            {
                UpdateGrids(frameGraphics);
                DrawGhostObject(frameGraphics);
                movingGraphics.Clear(Color.Transparent);
                DrawMovingObjects(movingGraphics);
                bufferedGraphics.Graphics.DrawImageUnscaled(frame, 0, 0);
                bufferedGraphics.Graphics.DrawImageUnscaled(movingFrame, 0, 0);
                bufferedGraphics.Render();
                framesRendered++;
                if (Environment.TickCount >= startTime + 1000) //Each second we update our frames
                {
                    TMConsole.FPS  = framesRendered;
                    startTime      = Environment.TickCount;
                    framesRendered = 0; //reset to 0 for the next second
                }
            }
            //Dispose used frames and bitmaps and assets
            frame.Dispose();
            frameGraphics.Dispose();
            movingFrame.Dispose();
            movingGraphics.Dispose();
            buffer.Dispose();
            UnloadAssets();
            //Sets the renderthread to null, we're done with it
            renderThread = null;
        }
Example #25
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            System.Drawing.Graphics gr            = panel2.CreateGraphics();
            BufferedGraphicsContext espaciobuffer = BufferedGraphicsManager.Current;
            BufferedGraphics        buffer        = espaciobuffer.Allocate(gr, new Rectangle(0, 0, Wreal, Hreal));

            buffer.Graphics.Clear(Color.White);
            buffer.Graphics.DrawImage(pictureBox1.Image, XReal, YReal, Wreal, Hreal);

            //controlador.DibujarMatriz(buffer.Graphics,XReal,YReal);
            //controlador.DibujarPath(buffer.Graphics);
            //controlador.DibujarParaderos(buffer.Graphics);

            controlador.dibujaLinea(buffer.Graphics);

            buffer.Render(gr);
            gr.Dispose();
            espaciobuffer.Dispose();
            buffer.Dispose();
        }
Example #26
0
        private void drawAccelGraph()
        {
            accelGraphicsContext = new BufferedGraphicsContext();
            accelGraphicsBuffer  = accelGraphicsContext.Allocate(Graphics.FromImage(accelDrawingSurface), accelboundsRectangle);
            accelGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            accelGraphicsBuffer.Graphics.Clear(SystemColors.Control);

            float xCenter = (float)(accelboundsRectangle.Width / 2.0);
            float yCenter = (float)(accelboundsRectangle.Height / 2.0);

            float xOld = xCenter - (float)spatial.accelerometerAxes[0].Acceleration * accelcircleRadius * (float)(1 / ambientGravity);
            float yOld = yCenter - (float)spatial.accelerometerAxes[1].Acceleration * accelcircleRadius * (float)(1 / ambientGravity);

            accelGraphicsBuffer.Graphics.DrawLine(accelxyAxisPen, xCenter, yCenter, xOld, yOld);
            accelGraphicsBuffer.Graphics.DrawEllipse(accelcirclePen, new Rectangle((int)(xCenter - accelcircleRadius), (int)(yCenter - accelcircleRadius),
                                                                                   (int)accelcircleDiameter, (int)accelcircleDiameter));

            if (spatial.accelerometerAxes.Count == 3)
            {
                double zOut = spatial.accelerometerAxes[2].Acceleration * (float)(1 / ambientGravity);
                if (zOut > 0)
                {
                    accelGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Red, 2),
                                                             new Rectangle((int)xCenter - (int)(accelcircleRadius * zOut), (int)yCenter - (int)(accelcircleRadius * zOut),
                                                                           (int)(accelcircleDiameter * zOut), (int)(accelcircleDiameter * zOut)));
                }
                else
                {
                    accelGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Green, 2),
                                                             new Rectangle((int)xCenter - (int)(accelcircleRadius * -zOut), (int)yCenter - (int)(accelcircleRadius * -zOut),
                                                                           (int)(accelcircleDiameter * -zOut), (int)(accelcircleDiameter * -zOut)));
                }
            }

            accelGraphicsBuffer.Render(panel1.CreateGraphics());

            accelGraphicsBuffer.Dispose();

            accelGraphicsContext.Dispose();
        }
        // Draws the motor visualisation circle to the interface
        private void drawCirclePlot()
        {
            circlePlotContext = new BufferedGraphicsContext();
            circlePlotBuffer  = circlePlotContext.Allocate(Graphics.FromImage(circlePlotSurface), circleBounds);
            circlePlotBuffer.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            circlePlotBuffer.Graphics.Clear(SystemColors.Control);

            float xCenter = (float)(circleBounds.Width / 2.0);
            float yCenter = (float)(circleBounds.Height / 2.0);

            circlePlotBuffer.Graphics.DrawEllipse(outerCirclePlotPen, circleRectangles[0]);
            circlePlotBuffer.Graphics.DrawEllipse(circlePlotPens[0], (float)(circleRadii[0] * Math.Cos(currentPos * 2 * Math.PI / 2000.0) + xCenter) - 2,
                                                  (float)(-circleRadii[0] * Math.Sin(currentPos * 2 * Math.PI / 2000.0) + yCenter) - 2, 4, 4);

            circlePlotBuffer.Graphics.DrawEllipse(outerCirclePlotPen, circleRectangles[1]);
            circlePlotBuffer.Graphics.DrawEllipse(circlePlotPens[1], (float)(circleRadii[1] * Math.Cos(desiredPos * 2 * Math.PI / 2000.0) + xCenter) - 2,
                                                  (float)(-circleRadii[1] * Math.Sin(desiredPos * 2 * Math.PI / 2000.0) + yCenter) - 2, 4, 4);

            circlePlotBuffer.Render(circlePlotPanel.CreateGraphics());
            circlePlotBuffer.Dispose();
            circlePlotContext.Dispose();
        }
Example #28
0
        private void drawMagFieldGraph()
        {
            magFieldGraphicsContext = new BufferedGraphicsContext();
            magFieldGraphicsBuffer  = magFieldGraphicsContext.Allocate(Graphics.FromImage(magFieldDrawingSurface), magFieldBoundsRectangle);
            magFieldGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            magFieldGraphicsBuffer.Graphics.Clear(SystemColors.Control);

            float xCenter = (float)(magFieldBoundsRectangle.Width / 2.0);
            float yCenter = (float)(magFieldBoundsRectangle.Height / 2.0);

            float xOld = xCenter + (float)(spatial.compassAxes[0].MagneticField) * magFieldCircleRadius * (float)(1 / ambientMagneticField);
            float yOld = yCenter + (float)(spatial.compassAxes[1].MagneticField) * magFieldCircleRadius * (float)(1 / ambientMagneticField);

            magFieldGraphicsBuffer.Graphics.DrawLine(magFieldXYAxisPen, xCenter, yCenter, xOld, yOld);
            magFieldGraphicsBuffer.Graphics.DrawEllipse(magFieldCirclePen, magFieldCircleRectangle);

            if (spatial.compassAxes.Count == 3)
            {
                double zOut = (spatial.compassAxes[2].MagneticField) * (float)(1 / ambientMagneticField);
                if (zOut > 0)
                {
                    magFieldGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Red, 2),
                                                                new Rectangle((int)xCenter - (int)(magFieldCircleRadius * zOut), (int)yCenter - (int)(magFieldCircleRadius * zOut),
                                                                              (int)(magFieldCircleDiameter * zOut), (int)(magFieldCircleDiameter * zOut)));
                }
                else
                {
                    magFieldGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Green, 2),
                                                                new Rectangle((int)xCenter - (int)(magFieldCircleRadius * -zOut), (int)yCenter - (int)(magFieldCircleRadius * -zOut),
                                                                              (int)(magFieldCircleDiameter * -zOut), (int)(magFieldCircleDiameter * -zOut)));
                }
            }

            magFieldGraphicsBuffer.Render(magFieldView.CreateGraphics());

            magFieldGraphicsBuffer.Dispose();

            magFieldGraphicsContext.Dispose();
        }
        public GunFire()
        {
            InitializeComponent();

            _ship = new Classes.Ship();

            _spaceShip = new Classes.BaseImage(Properties.Resources.SpaceShipSm, new Rectangle(100, 100, 104, 80)); // X, Y, Width, Height
            _laserBolt = new Classes.BaseImage(Properties.Resources.LaserboltSm, new Rectangle(200, 132, 25, 15));

            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

            // Gets a reference to the current BufferedGraphicsContext
            currentContext = BufferedGraphicsManager.Current;

            // Creates a BufferedGraphics instance associated with Form1, and with
            // dimensions the same size as the drawing surface of Form1.
            myBuffer = currentContext.Allocate(this.CreateGraphics(), this.DisplayRectangle);

            DrawToBuffer(myBuffer.Graphics);
            timer1.Start();
            currentContext.Dispose();
        }
Example #30
0
 /// <summary>
 /// 销毁对象
 /// </summary>
 public void Dispose()
 {
     if (m_currentContext != null)
     {
         m_currentContext.Dispose();
         m_currentContext = null;
     }
     if (m_emptyStringFormat != null)
     {
         m_emptyStringFormat.Dispose();
         m_emptyStringFormat = null;
     }
     if (m_buffer != null)
     {
         m_buffer.Dispose();
         m_buffer = null;
     }
     if (m_graphics != null)
     {
         m_graphics.Dispose();
         m_graphics = null;
     }
 }