Beispiel #1
0
 private void UpdateGraphicsBuffer()
 {
     if (this.Width > 0 && this.Height > 0)
     {
         _bufContext.MaximumBuffer = new Size(this.Width + 1, this.Height + 1);
         _bufGraphics = _bufContext.Allocate(this.CreateGraphics(), this.ClientRectangle);
         _bufGraphics.Graphics.SmoothingMode   = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
         _bufGraphics.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
     }
 }
Beispiel #2
0
 public MapDrawer(Map map, ImageList tiles)
 {
     InitializeComponent();
     this.map   = map;
     this.tiles = tiles;
     context    = BufferedGraphicsManager.Current;
     buffer     = context.Allocate(CreateGraphics(), new Rectangle(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height));
     mouse      = new Point(0, 0);
     relative   = new Point(0, 0);
 }
Beispiel #3
0
 private void UpdateGraphicsBuffer()
 {
     if (this.Width > 0 && this.Height > 0)
     {
         BufferedGraphicsContext context = BufferedGraphicsManager.Current;
         context.MaximumBuffer = new Size(this.Width + 1, this.Height + 1);
         _bufGraphics          = context.Allocate(this.CreateGraphics(), this.ClientRectangle);
         IncreaseGraphicsQuality(_bufGraphics.Graphics);
     }
 }
Beispiel #4
0
        private void timerRender_Tick(object sender, EventArgs e)
        {
            BufferedGraphicsContext context  = BufferedGraphicsManager.Current;
            BufferedGraphics        graphics = context.Allocate(this.CreateGraphics(), new Rectangle(0, 0, ScreenWidth, ScreenHeight));

            GameOfLife.Render(graphics.Graphics);

            graphics.Render(this.CreateGraphics());
            graphics.Dispose();
        }
Beispiel #5
0
        /// <summary>
        /// Function to create the double buffer surface resources.
        /// </summary>
        /// <param name="displayControl">The control that will be used as the display.</param>
        private void CreateDoubleBufferSurface(Control displayControl)
        {
            _graphics = Graphics.FromHwnd(displayControl.Handle);

            _mouseImage    = new Bitmap(displayControl.ClientSize.Width, displayControl.ClientSize.Height, PixelFormat.Format32bppArgb);
            _imageGraphics = Graphics.FromImage(_mouseImage);

            _graphicsContext = BufferedGraphicsManager.Current;
            _buffer          = _graphicsContext.Allocate(_imageGraphics, new Rectangle(0, 0, _mouseImage.Width, _mouseImage.Height));
        }
Beispiel #6
0
 public void Render_NullGraphics_Nop()
 {
     using (var context = new BufferedGraphicsContext())
         using (var image = new Bitmap(3, 3))
             using (Graphics graphics = Graphics.FromImage(image))
                 using (BufferedGraphics bufferedGraphics = context.Allocate(graphics, new Rectangle(0, 0, 1, 1)))
                 {
                     bufferedGraphics.Render(null);
                 }
 }
 private void UpdateGraphicsBuffer()
 {
     if (this.Width > 0 && this.Height > 0)
     {
         BufferedGraphicsContext bufContext = BufferedGraphicsManager.Current;
         bufContext.MaximumBuffer = new Size(this.Width + 1, this.Height + 1);
         BackBuffer = bufContext.Allocate(this.CreateGraphics(), this.ClientRectangle);
         OnBackBufferUpdated();
     }
 }
Beispiel #8
0
 void CustomUserControl_SizeChanged(object sender, EventArgs e)
 {
     if (this.Width > 0 && this.Height > 0)
     {
         context = BufferedGraphicsManager.Current;
         context.MaximumBuffer = new Size(this.Width + 1, this.Height + 1);
         grafx = context.Allocate(this.CreateGraphics(), new Rectangle(0, 0, this.Width, this.Height));
         DrawAndRefresh();
     }
 }
Beispiel #9
0
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);

            graphicsContext = BufferedGraphicsManager.Current;
            graphicsContext.MaximumBuffer = new System.Drawing.Size(Width + 1, Height + 1);

            bufferedGraphics?.Dispose();
            bufferedGraphics = graphicsContext.Allocate(CreateGraphics(), new Rectangle(0, 0, Width, Height));
        }
Beispiel #10
0
 public void InitializeBuffer()
 {
     this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
     context = BufferedGraphicsManager.Current;
     context.MaximumBuffer = new Size(this.Width + 1, this.Height + 1);
     this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
     grafx             = context.Allocate(this.CreateGraphics(), new Rectangle(0, 0, this.Width, this.Height));
     this.SizeChanged += CustomUserControl_SizeChanged;
     this.Paint       += CustomUserControl_Paint;
 }
Beispiel #11
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

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

            // Creates a BufferedGraphics instance associated with this form, and with dimensions the same size as the drawing surface of Form1.
            gfxBuffer = gfxBufferedContext.Allocate(this.CreateGraphics(), this.DisplayRectangle);
        }
Beispiel #12
0
 private void DoubleBufferControl_Resize(object sender, EventArgs e)
 {
     mGraphicManager.MaximumBuffer = new Size(this.Width, this.Height);
     if (!object.ReferenceEquals(mManagedBackBuffer, NO_MANAGED_BACK_BUFFER))
     {
         mManagedBackBuffer.Dispose();
     }
     mManagedBackBuffer = mGraphicManager.Allocate(this.CreateGraphics(), ClientRectangle);
     this.Refresh();
 }
Beispiel #13
0
 /// <summary>
 /// Обновить поверхность отображения
 /// </summary>
 protected override void UpdateGraphics()
 {
     if (_buf != null)
     {
         _buf.Dispose();
     }
     _buf = _ctx.Allocate(_g, ClientRectangle);
     _buf.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
     _buf.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
 }
Beispiel #14
0
        public static void Init(Form form)
        {
            Graphics g;

            _context = BufferedGraphicsManager.Current;
            g        = form.CreateGraphics();
            Width    = form.Width;
            Height   = form.Height;
            Buffer   = _context.Allocate(g, new Rectangle(0, 0, Width, Height));
        }
Beispiel #15
0
 public Form1()
 {
     InitializeComponent();
     this.SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
     currentContext = BufferedGraphicsManager.Current;
     myBuffer       = currentContext.Allocate(this.CreateGraphics(), this.DisplayRectangle);
     g  = myBuffer.Graphics;
     gb = new Function();
     gb.Rotate(Math.PI / -12, 2);
     gb.Rotate(Math.PI / -3, 0);
 }
        public void RenderBackground(Graphics g, RectangleF bounds)
        {
            BufferedGraphicsContext bufferedGraphicsContext = BufferedGraphicsManager.Current;

            using (BufferedGraphics bufferedGraphics = bufferedGraphicsContext.Allocate(g, Rectangle.Round(bounds)))
            {
                _renderer.RenderBackground(bufferedGraphics.Graphics, bounds);

                bufferedGraphics.Render(g);
            }
        }
Beispiel #17
0
        private void InitGraphics()
        {
            mFormsTimer          = new System.Windows.Forms.Timer();
            mFormsTimer.Interval = 50;
            mFormsTimer.Tick    += new System.EventHandler(this.TimerEventProcessor);
            mFormsTimer.Start();

            context_ = BufferedGraphicsManager.Current;
            context_.MaximumBuffer = new Size((int)map_width_, (int)map_height_);
            graphics_ = context_.Allocate(this.CreateGraphics(), new Rectangle(0, 0, (int)map_width_, (int)map_height_));
        }
Beispiel #18
0
        public void Allocate_BusyGraphics_ThrowsInvalidOperationException()
        {
            using (var context = new BufferedGraphicsContext())
                using (var image = new Bitmap(10, 10))
                    using (Graphics graphics = Graphics.FromImage(image))
                    {
                        try
                        {
                            graphics.GetHdc();

                            Rectangle largeRectangle = new Rectangle(0, 0, context.MaximumBuffer.Width + 1, context.MaximumBuffer.Height + 1);
                            Assert.Throws <InvalidOperationException>(() => context.Allocate(graphics, largeRectangle));
                            Assert.Throws <InvalidOperationException>(() => context.Allocate(graphics, Rectangle.Empty));
                        }
                        finally
                        {
                            graphics.ReleaseHdc();
                        }
                    }
        }
Beispiel #19
0
        public static void Init(Form form)
        {
            Graphics g;

            galaxy   = new Galaxy(form.ClientSize.Width, form.ClientSize.Height);
            _context = BufferedGraphicsManager.Current;
            g        = form.CreateGraphics();
            Buffer   = _context.Allocate(g, new Rectangle(0, 0, galaxy.galaxyWidth, galaxy.galaxyHeight));
            timer.Start();
            timer.Tick += Timer_Tick;
        }
Beispiel #20
0
        public Form1()
        {
            InitializeComponent();

            graphics = pictureBox1.CreateGraphics();
            bufferedGraphicsContext = new BufferedGraphicsContext();
            bufferedGraphics        = bufferedGraphicsContext.Allocate(graphics,
                                                                       new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));

            bufferedGraphics.Graphics.Clear(pictureBox1.BackColor);
        }
Beispiel #21
0
        public ScreenDrawer(Graphics renderTo, Rectangle screenArea)
        {
            _renderTo     = renderTo;
            _screenWidth  = screenArea.Width / _cellWidth;
            _screenHeight = screenArea.Height / _cellWidth;

            _bufferContext = BufferedGraphicsManager.Current;
            _buffer        = _bufferContext.Allocate(renderTo, screenArea);

            _drawingGraphics = _buffer.Graphics;
        }
Beispiel #22
0
        private void pnlDrawingBoard_Paint(object sender, PaintEventArgs e)
        {
            int Count = 0;

            if (xDraw == true)
            {
                CurrentContext = BufferedGraphicsManager.Current;
                MyBuffer       = CurrentContext.Allocate(e.Graphics, pnlDrawingBoard.DisplayRectangle);

                SystemSettings.Alaising(Aliasing);

                int  BenLength;
                bool Safe = true;
                BenLength = DataPool.Length - 1;

                foreach (Object Obj in DataPool)
                {
                    int xConvert;

                    if (Count == xBitCount || xAxis > pnlDrawingBoard.Width - 10)
                    {
                        txtBitCount.Value = txtBitCount.Value;
                        if (yAxis != this.Height - 10)
                        {
                            xAxis  = 0;
                            yAxis += 10;

                            xBitCount += Convert.ToInt32(txtBitCount.Text);
                        }
                    }

                    if (Safe == true)
                    {
                        xConvert = Convert.ToInt32(DataPool.Substring(Count, 1));
                        if (xConvert == 0)
                        {
                            MyBuffer.Graphics.FillRectangle(new SolidBrush(SystemSettings.ZeroColor), xAxis, yAxis, 10, 10);
                        }
                        else
                        {
                            MyBuffer.Graphics.FillRectangle(new SolidBrush(SystemSettings.OneColor), xAxis, yAxis, 10, 10);
                        }
                    }
                    else
                    {
                        txtBitCount.Maximum = txtBitCount.Value;
                    }

                    xAxis += 10;
                    Count += 1;
                }
                MyBuffer.Render();
            }
        }
Beispiel #23
0
 private void Window_Resize(object sender, EventArgs e)
 {
     context = BufferedGraphicsManager.Current;
     context.MaximumBuffer = new Size(this.Width + 1, this.Height + 1);
     if (bufferedGraphics != null)
     {
         bufferedGraphics.Dispose();
     }
     bufferedGraphics = context.Allocate(this.CreateGraphics(), new Rectangle(0, 0, this.Width, this.Height));
     this.Refresh();
 }
Beispiel #24
0
        private int[,] Init()
        {
            currentContext = BufferedGraphicsManager.Current;
            myBuffer       = currentContext.Allocate(panel1.CreateGraphics(), panel1.DisplayRectangle);

            BrushBlack = new SolidBrush(Color.DarkGreen);
            BrushWhite = new SolidBrush(Color.WhiteSmoke);

            int[,] board = new int[mX, mY];
            return(board);
        }
 private void UpdateGraphicsBuffer()
 {
     if (this.Width > 0 && this.Height > 0)
     {
         BufferedGraphicsContext bufContext = BufferedGraphicsManager.Current;
         bufContext.MaximumBuffer = new Size(this.Width + 1, this.Height + 1);
         _bufGraphics             = bufContext.Allocate(this.CreateGraphics(), this.ClientRectangle);
         _bufGraphics.Graphics.CompositingQuality = CompositingQuality.HighQuality;
         AdjustGraphics(_bufGraphics.Graphics);
     }
 }
        //Оброботчик события загрузки формы
        private void Form1_Load(object sender, EventArgs e)
        {
            //Объект для рисования на панели
            graphics = panel1.CreateGraphics();
            context  = BufferedGraphicsManager.Current;
            canvas   = context.Allocate(graphics, panel1.DisplayRectangle);

            //Точка (0, 0) на графике
            xcenter = 30;
            ycenter = panel1.Height;
        }
Beispiel #27
0
        /// <summary>
        /// Изменение размеров компонента, изменяем размеры панелей
        /// </summary>
        private void OnResize(object sender, EventArgs e)
        {
            try
            {
                // Re-create the graphics buffer for a new window size.
                context.MaximumBuffer = new Size(this.Width + 1, this.Height + 1);
                if (grafx != null)
                {
                    grafx.Dispose();
                    grafx = null;
                }

                grafx = context.Allocate(this.CreateGraphics(), new Rectangle(0, 0, this.Width, this.Height));

                // определяем размеры экрана и координаты трех ключевых точек
                // координаты точки pointLeftUp заданы константами вверху и не переопределяются
                // размеры области должны быть четными, т.е. влево и вправо от центра должно быть одинаковое растояние
                pointRightDown.X = (this.Width - pointLeftUp.X - mpWidthY) / 2;
                pointRightDown.X = pointLeftUp.X + pointRightDown.X * 2;
                pointRightDown.Y = (this.Height - apHeightX) / 2;
                pointRightDown.Y = pointLeftUp.Y + pointRightDown.Y * 2;
                pointOrigin.X    = pointLeftUp.X + (pointRightDown.X - pointLeftUp.X) / 2;
                pointOrigin.Y    = pointLeftUp.Y + (pointRightDown.Y - pointLeftUp.Y) / 2;

                // все переменные линиий (шагов сетки) отсчитываются относительно 0 координат (центра)
                // т.е. реально на эране линий будет в два раза больше, в право и влево от центра
                // определяем, сколько шагов сетки (линий) помещается по вертикали
                gridCountY = (pointOrigin.Y - pointLeftUp.Y) / gridStepY;
                // определяем, сколько шагов сетки (линий) помещается по горизонтали
                gridCountX = (pointOrigin.X - pointLeftUp.X) / gridStepX;

                // панели масштаба
                scPosX   = new Point(pointLeftUp.X - 30, pointRightDown.Y + 30);
                scPosY.Y = pointRightDown.Y + 45 - scaleCountY * scWidth;

                // панель информации
                ipPos = new Point(pointRightDown.X - ipWidth, pointLeftUp.Y);
                // определяем позицию кнопок прокрутки
                XScrollRightButton.Left = this.Width - 10 - XScrollRightButton.Width;
                XScrollRightButton.Top  = scPosX.Y;
                XScrollLeftButton.Left  = XScrollRightButton.Left - 10 - XScrollRightButton.Width;
                XScrollLeftButton.Top   = XScrollRightButton.Top;

                YScrollUpButton.Left   = 10;
                YScrollUpButton.Top    = 10;
                YScrollDownButton.Left = YScrollUpButton.Left;
                YScrollDownButton.Top  = YScrollUpButton.Top + 10 + YScrollUpButton.Height;

                RecalcVariables();
                RedrawScreen(grafx.Graphics);
            }
            catch { }
            this.Refresh();
        }
Beispiel #28
0
 public Form1()
 {
     InitializeComponent();
     cbbDashStyle.Text  = "Solid";
     cbbBrushStyle.Text = "Solid";
     btnGroup.Enabled   = false;
     btnUngroup.Enabled = false;
     pnlPaint.Focus();
     currentContext = BufferedGraphicsManager.Current;
     myBuffer       = currentContext.Allocate(pnlPaint.CreateGraphics(), pnlPaint.DisplayRectangle);
 }
 private void UpdateGraphicsBuffer()
 {
     if (this.Width > 0 && this.Height > 0)
     {
         BufferedGraphicsContext bufContext = BufferedGraphicsManager.Current;
         bufContext.MaximumBuffer = new Size(this.Width + 1, this.Height + 1);
         _bufGraphics             = bufContext.Allocate(this.CreateGraphics(), this.ClientRectangle);
         UpdateDrawingBoundaries();
         _bufGraphics.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
     }
 }
        protected override void OnResize(EventArgs e)
        {
            if (ManagedBackBuffer != null)
            {
                ManagedBackBuffer.Dispose();
            }

            GraphicManager.MaximumBuffer = new Size(this.Width + 1, this.Height + 1);
            ManagedBackBuffer            = GraphicManager.Allocate(this.CreateGraphics(), ClientRectangle);
            this.Refresh();
        }
Beispiel #31
0
            public DrawManager(Game game_m)
            {
                game = game_m;
                formGraphics = game.gameForm.CreateGraphics();
                game.gameForm.Resize += gameForm_Resize;

                Console.WriteLine(formGraphics.DpiX+"   "+formGraphics.DpiY);

                view = new View(20, 20, 1920, 1080);
                context = BufferedGraphicsManager.Current;

                context.MaximumBuffer = new Size((int)view.width + 1, (int)view.height + 1);

                grafx = context.Allocate(formGraphics, new Rectangle(0, 0, game.gameForm.Width, game.gameForm.Height));
                drawBrush = new SolidBrush(Color.Black);
                font = new System.Drawing.Font("Arial", 16);
                watch = new Stopwatch();
                watch.Start();
                fps = 0.0;
                last = 0;
            }
            private void VerifyGraphicsContext()
            {
                if (SourceControlObject != null)
                {
                    int ClientWidth = (SourceControlObject.ClientSize.Width + 1);
                    int ClientHeight = (SourceControlObject.ClientSize.Height + 1);
                    bool RebuildObjectsFlag = true;

                    if ((GraphicsContextObject != null) && (GraphicsObject != null))
                    {
                        if ((GraphicsContextObject.MaximumBuffer.Width == ClientWidth)
                        && (GraphicsContextObject.MaximumBuffer.Height == ClientHeight))
                        {
                            RebuildObjectsFlag = false;
                        }
                    }

                    if (RebuildObjectsFlag == true)
                    {
                        if (GraphicsObject != null)
                        {
                            GraphicsObject.Dispose();
                            GraphicsObject = null;
                        }

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

                        if ((ClientWidth > 1) && (ClientHeight > 1))
                        {
                            GraphicsContextObject = new BufferedGraphicsContext();
                            GraphicsContextObject.MaximumBuffer = new Size(ClientWidth, ClientHeight);

                            Graphics ControlGraphicsObject = SourceControlObject.CreateGraphics();

                            GraphicsObject = GraphicsContextObject.Allocate(ControlGraphicsObject, SourceControlObject.ClientRectangle);
                            GraphicsObject.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                            GraphicsObject.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        }
                    }
                }
            }