private void canvasptc_Paint(object sender, PaintEventArgs e)
 {
     if (gfx != null)
     {
         gfx.Render(e.Graphics);
     }
 }
Beispiel #2
0
        private void stopWatch_Load(object sender, EventArgs e)
        {
            CurrentContext = BufferedGraphicsManager.Current;
            System.Drawing.BufferedGraphics bg = CurrentContext.Allocate(CreateGraphics(), ClientRectangle);
            bg.Graphics.Clear(SystemColors.Window);


            DrawLines(bg.Graphics);
            DrawNumbers(bg.Graphics);
            DrawHands(bg.Graphics);
            bg.Render();
        }
Beispiel #3
0
		protected override void OnPaint(PaintEventArgs e)
		{
			BufferedGraphicsContext currentContext;
			currentContext = BufferedGraphicsManager.Current;
			myBuffer = currentContext.Allocate(this.CreateGraphics(), this.DisplayRectangle);

			PaintEventArgs args = new PaintEventArgs(myBuffer.Graphics, e.ClipRectangle);

			base.OnPaint(args);

			myBuffer.Render(e.Graphics);
			myBuffer.Dispose();
		}
Beispiel #4
0
        private void stopWatch_Paint(object sender, PaintEventArgs e)
        {
            CurrentContext = BufferedGraphicsManager.Current;
            System.Drawing.BufferedGraphics bg = CurrentContext.Allocate(CreateGraphics(), ClientRectangle);
            bg.Graphics.Clear(Color.White);

            // DateTime now = DateTime.Now
            DrawLines(bg.Graphics);
            DrawNumbers(bg.Graphics);
            DrawHands(bg.Graphics);
            drawCircle(bg.Graphics);
            bg.Render();
        }
Beispiel #5
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            CurrentContext = BufferedGraphicsManager.Current;
            System.Drawing.BufferedGraphics bg = CurrentContext.Allocate(CreateGraphics(), ClientRectangle);
            bg.Graphics.Clear(Color.White);

            currentTimePassed = DateTime.Now - startTime + pauseTime;

            DrawLines(bg.Graphics);
            DrawNumbers(bg.Graphics);
            DrawHands(bg.Graphics);
            drawCircle(bg.Graphics);
            bg.Render();
        }
Beispiel #6
0
        public void Reset()
        {
            if (!running)
            {
                pauseTime         = TimeSpan.Zero;
                currentTimePassed = TimeSpan.Zero;

                CurrentContext = BufferedGraphicsManager.Current;
                System.Drawing.BufferedGraphics bg = CurrentContext.Allocate(CreateGraphics(), ClientRectangle);
                bg.Graphics.Clear(SystemColors.Window);


                DrawLines(bg.Graphics);
                DrawNumbers(bg.Graphics);
                DrawHands(bg.Graphics);
                bg.Render();
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            
            using (currentContext = BufferedGraphicsManager.Current)
            using (myBuffer = currentContext.Allocate(this.CreateGraphics(), this.DisplayRectangle))
            {
                game.draw(myBuffer);
                game.update(myBuffer);
                myBuffer.Render(this.CreateGraphics());
            }
            cont++;

            if(cont == 50) 
            {
                cont = 0;
                game.reset(myBuffer);
            }
        }
Beispiel #8
0
        private void clock_Tick(object sender, EventArgs e)
        {
            // Make the draw buffer and set background color
            myBuffer = currentContext.Allocate(canvas.CreateGraphics(), canvas.DisplayRectangle);
            myBuffer.Graphics.FillRectangle(Brushes.WhiteSmoke, canvas.DisplayRectangle);

            // Move Update Draw Simulation Objects
            foreach (SimulationObject so in objects)
            {
                so.UpdateState();
                so.PerformAction();
                so.Draw(myBuffer.Graphics);
            }

            // Main draw
            myBuffer.Render();
            myBuffer.Dispose();
        }
Beispiel #9
0
        public void DrawPoints(Pen pen, params Point[] points)
        {
            Graphics gr = Graphics.FromImage(_pictureBox.Image);

            foreach (var point in points)
            {
                //Ekaterina
                _imageBuffer.Graphics.DrawEllipse(pen, point.X - 1, _pictureBox.Height - point.Y + 1, 3, 3);
                //end Ekaterina
                int xOffset = getXOffset(point);
                if (point.Index > 0)
                {
                    //Ekaterina
                    _imageBuffer.Graphics.DrawString(point.Index.ToString(), SystemFonts.CaptionFont, Brushes.Black, point.X + xOffset, _pictureBox.Height - point.Y);
                    //end Ekaterina
                }
            }
            _imageBuffer.Render();
        }
Beispiel #10
0
        private void stopWatch_Resize(object sender, EventArgs e)
        {
            if (Width < Height)
            {
                radius = Width / 2;
            }
            else
            {
                radius = Height / 2;
            }
            center  = new Point(Width / 2, Height / 2);
            center2 = new Point(Width / 2, Height / 3);


            CurrentContext = BufferedGraphicsManager.Current;
            System.Drawing.BufferedGraphics bg = CurrentContext.Allocate(CreateGraphics(), ClientRectangle);
            bg.Graphics.Clear(Color.White);

            DrawLines(bg.Graphics);
            DrawNumbers(bg.Graphics);
            DrawHands(bg.Graphics);
            drawCircle(bg.Graphics);
            bg.Render();
        }
Beispiel #11
0
        /// <summary>
        /// This function should be used whenever the underlying krystal data or the field panel has changed.
        /// If the krystal data has changed, the panel obviously needs to be updated.
        /// If the field panel has been resized, the diagram is re-centred.
        /// </summary>
        private void RedrawFieldPanel()
        {
            if (_fieldPanelGraphicsBuffer != null)
                _fieldPanelGraphicsBuffer.Dispose();
            _fieldPanelGraphicsBuffer = _bufferedGraphicsContext.Allocate(FieldPanel.CreateGraphics(), FieldPanel.DisplayRectangle);

            float scalePercent = float.Parse(this.ZoomComboBox.Text);
            try
            {
                _painter.Draw(_fieldPanelGraphicsBuffer.Graphics, _outputKrystal, scalePercent);
                _fieldPanelGraphicsBuffer.Render();
            }
            catch (ApplicationException ae)
            {
                MessageBox.Show(ae.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Beispiel #12
0
 //draw
 public void drawForm()
 {
     //Render to the GCI+ surface
     backBuffer.Render();
 }
 public override void EndRenderAction()
 {
     _bufferedGraphics.Render();
 }
        void accel_AccelerationChange(object sender, AccelerationChangeEventArgs e)
        {
            formGraphicsContext = new BufferedGraphicsContext();

            formGraphicsBuffer = formGraphicsContext.Allocate(Graphics.FromImage(formDrawingSurface), rectBounds);

            formGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            formGraphicsBuffer.Graphics.Clear(SystemColors.Control);

            int i = 0;
            //low pass filtering
            switch (e.Index)
            {
                case 0:
                    xOut = 0;
                    xFilt[6] = e.Acceleration;
                    for (i = 0; i < 6; i++)
                    {
                        xFilt[i] = xFilt[i + 1];
                        xOut = xOut + xFilt[i];
                    }
                    xOut = xOut / 6;
                    label6.Text = e.Acceleration.ToString();
                    break;
                case 1:
                    yOut = 0;
                    yFilt[6] = e.Acceleration;
                    for (i = 0; i < 6; i++)
                    {
                        yFilt[i] = yFilt[i + 1];
                        yOut = yOut + yFilt[i];
                    }
                    yOut = yOut / 6;
                    label7.Text = e.Acceleration.ToString();
                    break;
                case 2:
                    zOut = 0;
                    zFilt[6] = e.Acceleration;
                    for (i = 0; i < 6; i++)
                    {
                        zFilt[i] = zFilt[i + 1];
                        zOut = zOut + zFilt[i];
                    }
                    zOut = zOut / 6;
                    label8.Text = e.Acceleration.ToString();
                    break;
            }

            x1Old = xCenter - (float)xOut * circleRadius;
            y1Old = yCenter + (float)yOut * circleRadius;

            formGraphicsBuffer.Graphics.DrawLine(xyAxisPen, xCenter, yCenter, x1Old, y1Old);
            formGraphicsBuffer.Graphics.DrawEllipse(circlePen, circleRectangle);

            if (accel.axes.Count == 3)
            {
                if (zOut > 0)
                {
                    formGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Red, 2),
                        new Rectangle((int)xCenter - (int)(circleRadius * zOut), (int)yCenter - (int)(circleRadius * zOut),
                        (int)(circleDiameter * zOut), (int)(circleDiameter * zOut)));
                }
                else
                {
                    formGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Green, 2),
                        new Rectangle((int)xCenter - (int)(circleRadius * -zOut), (int)yCenter - (int)(circleRadius * -zOut),
                        (int)(circleDiameter * -zOut), (int)(circleDiameter * -zOut)));
                }
            }

            formGraphicsBuffer.Render(panel1.CreateGraphics());

            formGraphicsBuffer.Dispose();

            formGraphicsContext.Dispose();
        }
Beispiel #15
0
        /// <summary>
        /// 双缓冲画图,用于画map底图
        /// </summary>
        /// <param name="g">目标设备的Graphics</param>
        /// <param name="PicImg">底图的Image实例</param>
        /// <param name="left">底图左边线X坐标</param>
        /// <param name="top">底图上边线Y坐标</param>
        /// <param name="width">底图宽</param>
        /// <param name="height">底图的高</param>
        private void BufferedDrawImg(Graphics g, Image PicImg, int left, int top, float width, float height)
        {
            if (PicImg != null)
            {
                context = BufferedGraphicsManager.Current;
                context.MaximumBuffer = new Size(this.Width + 1, this.Height + 1);
                bgraph = context.Allocate(g, new Rectangle(0, 0, this.Width + 1, this.Height + 1));
                bgraph.Graphics.Clear(this.BackColor);
                bgraph.Graphics.DrawImage(PicImg, left, top, width, height);
                bgraph.Graphics.DrawRectangle(Pens.Black, rect);
                PaintStation(bgraph.Graphics);
                PaintMover(bgraph.Graphics);
                PaintRoute(bgraph.Graphics);
                if (IsPaintRoute)
                {
                    PaintStation(bgraph.Graphics);
                    PaintMover(bgraph.Graphics);
                }
                PaintMoverRoute(bgraph.Graphics);

                //bgraph.Graphics.DrawImage(myimage, 200, 200, 50, 50);
                bgraph.Render();
                bgraph.Dispose();
            }
        }
Beispiel #16
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();
        }
Beispiel #17
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();
        }
Beispiel #18
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            myContext = new BufferedGraphicsContext();
            myBuffer = myContext.Allocate(this.CreateGraphics(), this.DisplayRectangle);
            myBuffer.Graphics.Clear(SystemColors.Control);

            myBuffer.Graphics.DrawLine(Pens.Black, 820, 120, 820, 169);
            myBuffer.Graphics.DrawLine(Pens.Black, 821, 120, 821, 169);
            lblYScale.Text = YScaleText[yScaleIndex];
            lblXScale.Text = XScaleText[xScaleIndex];
            myBuffer.Render();

            int firmwareID1 = 0;
            int firmwareID2 = 0;
            int firmwareID3 = 0;

            //char[] buff = new char[1];
            //buff[0] = 's';
            //serialPort1.Write(buff, 0, 1);
            //serialPort1.WriteLine("s");

            try
            {
                // Try to open Intan RHA2000-EVAL board on USB port
                myUSBSource.Open(ref firmwareID1, ref firmwareID2, ref firmwareID3);
            }
            catch
            {
                // If no board is found (or drivers are not installed), run application with synthetic neural data for demonstration purposes

                if (MessageBox.Show("Intan Technologies USB device not found.  Click OK to run application with synthesized neural data for demonstration purposes.\n\nTo use the RHA2000-EVAL board click Cancel, load correct drivers and/or connect device to USB port, then restart application.\n\nVisit http://www.intantech.com for drivers and more information.",
                    "Intan USB Device Not Found", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.Cancel)
                    this.Close();

                this.Text = "Intan Technologies Amplifier Demo (SIMULATED DATA: Connect board and restart program to record live data)";
                myUSBSource.SynthDataMode = true;
                tmrSynthData.Enabled = true;
                yScaleIndex = 5;
                lblYScale.Text = YScaleText[yScaleIndex];

                // Disable hardware options if no board is connected
                chkSettle.Enabled = false;
                btnZCheck.Enabled = false;

            }

            if (myUSBSource.SynthDataMode)
                lblStatus.Text = "No USB board connected.  Ready to run with synthesized neural data.";

            else
            {
                lblStatus.Text = String.Concat("Connected to Intan Interface Board with firmware type ",
                    firmwareID1.ToString(), ", version ",
                    firmwareID2.ToString(), ".",
                    firmwareID3.ToString());
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            int i;

            try
            {
                float height = (float)(this.Height - scrollHeight);

                long position = startPosition;
                long beginPosition = position;
                long endPosition = position + (Width * bytesPerSample * samplesPerPixel);

                int startSelectionX = (int)(startSelectionPosition - startPosition) / (samplesPerPixel * bytesPerSample);
                int endSelectionX = (int)(endSelectionPosition - startPosition) / (samplesPerPixel * bytesPerSample);

                myBuffer = currentContext.Allocate(e.Graphics, this.ClientRectangle);

                Brush brush = new LinearGradientBrush(this.ClientRectangle, Color.FromArgb(250, 250, 255), Color.FromArgb(180, 180, 255), 90);
                myBuffer.Graphics.FillRectangle(brush, this.ClientRectangle);

                // draw timing lines
                int startPixels;
                // calculate start time
                long startTimeMillis = (position * 1000) / (bytesPerSample * waveStream.WaveFormat.SampleRate);
                // calculate end time
                long endTimeMillis = ((position * 1000) + ((long)Width * (long)samplesPerPixel * (long)bytesPerSample * 1000)) / ((long)bytesPerSample * (long)waveStream.WaveFormat.SampleRate);
                // determine skip frequency for ticks
                long diff = endTimeMillis - startTimeMillis;
                // we want about 20 ticks
                int factor = (int)(Math.Pow(10.0f, (double)((int)Math.Log10(diff / 10))));
                long skipMS = ((int)((diff / 10.0) / factor)) * factor * 2;

                int skipPixels = (int)(((skipMS * waveStream.WaveFormat.AverageBytesPerSecond) / 1000.0f) / (samplesPerPixel * bytesPerSample));

                long offsetMS = (startTimeMillis % skipMS);
                if (offsetMS > 0)
                {
                    startTimeMillis += (skipMS - offsetMS);
                    int offsetPixels = (int)(((skipMS - offsetMS) * waveStream.WaveFormat.AverageBytesPerSecond) / 1000.0f) / (samplesPerPixel * bytesPerSample);
                    startPixels = offsetPixels;
                }
                else
                    startPixels = 0;

                long t;
                int x;
                for (x = startPixels, t = startTimeMillis; x < this.Width; x += skipPixels, t += skipMS)
                {
                    if (skipPixels < 30)
                    {
                        if (skipMS > 3600000)
                            myBuffer.Graphics.DrawString(String.Format("{0:0}h", t / 3600000.0f), timingFont, blackBrush, new PointF(x, 0));
                        else
                            if (skipMS > 60000)
                                myBuffer.Graphics.DrawString(String.Format("{0:0}m", t / 60000.0f), timingFont, blackBrush, new PointF(x, 0));
                            else
                                if (skipMS > 100)
                                    myBuffer.Graphics.DrawString(String.Format("{0:0}s", t / 1000.0f), timingFont, blackBrush, new PointF(x, 0));
                                else
                                    myBuffer.Graphics.DrawString(String.Format("{0:0}", t), timingFont, blackBrush, new PointF(x, 0));
                    }
                    else
                    {
                        if (skipMS > 3600000)
                            myBuffer.Graphics.DrawString(String.Format("{0:n}h", t / 3600000.0f), timingFont, blackBrush, new PointF(x, 0));
                        else
                            if (skipMS > 60000)
                                myBuffer.Graphics.DrawString(String.Format("{0:n}m", t / 60000.0f), timingFont, blackBrush, new PointF(x, 0));
                            else
                                if (skipMS > 100)
                                    myBuffer.Graphics.DrawString(String.Format("{0:n}s", t / 1000.0f), timingFont, blackBrush, new PointF(x, 0));
                                else
                                    myBuffer.Graphics.DrawString(String.Format("{0:n}", t), timingFont, blackBrush, new PointF(x, 0));
                    }

                    myBuffer.Graphics.DrawLine(tickPen, x, 0, x, height - 1);
                }

                byte[] waveData = memoryStream.GetBuffer();
                int bytesToProcess = samplesPerPixel * bytesPerSample;

                if (minValues.Length < (e.ClipRectangle.Width + e.ClipRectangle.X))
                {
                    minValues = new float[e.ClipRectangle.Width + e.ClipRectangle.X];
                    maxValues = new float[e.ClipRectangle.Width + e.ClipRectangle.X];
                }

                bool skipTaken = false;

                for (x = 0; (x < e.ClipRectangle.Right) && (position < waveData.Length); x++)
                {
                    if ((x >= skipAudioX)&&(!skipTaken))
                    {
                        x += skipAudioAmount;
                        skipTaken = true;
                    }
                    short low = BitConverter.ToInt16(waveData, (int)position);
                    short high = low;
                    long n;
                    for (n = position + bytesPerSample; (n < (position + bytesToProcess)) && (n < waveData.Length); n += bytesPerSample)
                    {
                        short sample = BitConverter.ToInt16(waveData, (int)n);
                        if (sample < low) low = sample;
                        if (sample > high) high = sample;
                    }

                    position = n;
                    float lowPercent = ((((float)low) - short.MinValue) / ushort.MaxValue);
                    float highPercent = ((((float)high) - short.MinValue) / ushort.MaxValue);

                    minValues[x] = height * lowPercent;
                    maxValues[x] = height * highPercent;

                    int l = (int)minValues[x];
                    int h = (int)maxValues[x] + 1;
                    myBuffer.Graphics.DrawLine(linePen, x, l, x, h);
                }

                for (i = 0; i < editPoints.Count; i++)
                {
                    if ((editPoints[i].position > beginPosition) && (editPoints[i].position < endPosition))
                    {
                        if (i == editPointSelected)
                            DrawSelectedEditPoint(myBuffer.Graphics, i, editSelectedBrush, editSelectedPen, (int)height);
                        else
                            DrawEditPoint(editPoints[i], myBuffer.Graphics, (int)height);

                    }
                }

                if (!mouseDrag)
                {
                    int hover = editPointHover;
                    if (hover >= 0)
                    {
                        x = (int)((long)editPoints[hover].position - startPosition) / (samplesPerPixel * bytesPerSample);
                        if ((x>0)&&(x<e.ClipRectangle.Right))
                            ControlPaint.DrawReversibleFrame(RectangleToScreen(new Rectangle((int)x - 8, 0, 16, Height - scrollHeight)), Color.Black, FrameStyle.Dashed);
                    }
                }

                myBuffer.Render(e.Graphics);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            //base.OnPaint(e);
        }
Beispiel #20
0
        public void Draw(Graphics g, ref int x, ref int y, Rectangle target, bool final)
        {
            if (!this.Visible)
                return;
            this.BackColor = Block.BackColor;
            try
            {
                bgc = BGC.Allocate(g, target);
                bgc.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
                bgc.Graphics.FillRegion(new SolidBrush(this.Block.BackColor), new System.Drawing.Region(new Rectangle(0, 0, this.Width, this.Height)));
                foreach (Element elm in Children)
                {

                    x += elm.X;
                    y += elm.Y;
                    if(elm.Visible &&
                        elm.X  - this.SpiderView.HorizontalScroll.Value < this.Width + 3 && elm.Y + elm.Height > this.SpiderView.VerticalScroll.Value &&
                    elm.Y  - this.SpiderView.VerticalScroll.Value < this.Height + 3 && elm.X + elm.Width > this.SpiderView.HorizontalScroll.Value)
                        elm.Draw(bgc.Graphics, ref x, ref y, final);
                    elm.AbsoluteTop = y;
                    elm.AbsoluteLeft = x;
                    if (elm.GetType() == typeof(columnheader))
                    {
                        overflows.Add(new DrawBuffer() { x = x, y = y, elm = elm });
                    }
                    x -= elm.X;
                    y -= elm.Y;

                }
                foreach (DrawBuffer db in overflows)
                {
                    db.elm.Draw(bgc.Graphics, ref db.x, ref db.y, final);
                }
                overflows.Clear();

                bgc.Render();
            }
            catch (System.ComponentModel.Win32Exception e)
            {

            }
        }
Beispiel #21
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();
        }
Beispiel #22
0
 private void Draw(BufferedGraphics buffer, float delta)
 {
     UpdateFPS();
     this.world.Draw(buffer.Graphics, this.view, delta);
     this.ui.Draw(buffer.Graphics, this.world);
     buffer.Render();
 }
Beispiel #23
0
 private void displayImage()
 {
     Graphics g = CreateGraphics();
     using (frame = bufferContext.Allocate(g, tabControl.ClientRectangle))
     {
         //frame = bufferContext.Allocate(g, tabControl.ClientRectangle);
         System.Drawing.Rectangle destRect = this.panningPanel.ClientRectangle;
         destRect.Location = this.panningPanel.Location;
         System.Drawing.Rectangle srcRect = new System.Drawing.Rectangle(offsetWidth, offsetHeight, 1000, 1000);
         frame.Graphics.DrawImage(Properties.Resources.GameOfThrones, destRect, srcRect, g.PageUnit);
         frame.Render();
     }
 }
Beispiel #24
0
        public void Meshis(Graphics Graphic,int manhue,int sat, int bright)
        {
            if (Bg!=null)
            {
                F = new Bitmap(Bg, Bg.Width, Bg.Height);
                BE = X.Allocate(Graphic, new Rectangle(0, 0, this.Width, this.Height));

                for (int i = 0; i < F.Width; i++)
                {
                    for (int j = 0; j < F.Height; j++)
                    {
                        Color s = F.GetPixel(i, j);
                        float f = (s.R + s.G + s.B) / 3;

                        float x = (f / 255) * 100;
             //           double rr = Math.Sin(127+manhue/(Math.PI/(255*2))) * f;
                        int sp = bright >= 100 ? sp = bright - 100 : sp = 100;
                       // Color y = XColors.HSBToRGB((manhue) - (int)((int)f), sat, (int)bright);
                        Color y = XColors.Transgen( firstColor, lastColor, manhue + (int)((float)f*2.5f), saturation, brightness);

                        /*
                        if ( f>=127)
                        {
                            int sr = sat ;

                            float frr = XColors.Diff(y.R, 255) ;
                            float frg = XColors.Diff(y.G, 255) ;
                            float frb = XColors.Diff(y.B, 255) ;
                            float ar=frr*(sat/100);
                            float ag = frg * (sat / 100);
                            float ab = frb * (sat / 100);
                            Color r = Color.FromArgb(y.R + (int)ar, y.G + (int)ag, y.B + (int)ab);
                            y = r;
                        }
                         */
                        F.SetPixel(i, j, y);
                    }
                }
                int r = this.Width / Bg.Width;
                for (int i = 0; i < this.Width; i++)
                {
                    BE.Graphics.DrawImage(F, new Point(i*Bg.Width, 0));
                }
                BE.Render();
            }
        }
        //acceleration change event handler
        void accel_AccelerationChange(object sender, AccelerationChangeEventArgs e)
        {
            //get our graphics buffer going so we can draw to our panel
            accelGraphicsContext = new BufferedGraphicsContext();
            accelGraphicsBuffer = accelGraphicsContext.Allocate(Graphics.FromImage(accelDrawingSurface), boundsRectangle);
            accelGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            accelGraphicsBuffer.Graphics.Clear(SystemColors.Control);

            Accelerometer attached = (Accelerometer)sender;

            //in this switch statement we will do a bit of simple low pass filtering to smooth out the motion of the graphical representation of the
            //acceleration data.  We will also write the raw data to the textbox for the appropriate axis.
            int i = 0;
            try
            {
                switch (e.Index)
                {
                    case 0:
                        xOut = 0;
                        xFilt[6] = e.Acceleration;
                        for (i = 0; i < 6; i++)
                        {
                            xFilt[i] = xFilt[i + 1];
                            xOut = xOut + xFilt[i];
                        }
                        xOut = xOut / 6;
                        axis1AccelTxt.Text = e.Acceleration.ToString();
                        break;
                    case 1:
                        yOut = 0;
                        yFilt[6] = e.Acceleration;
                        for (i = 0; i < 6; i++)
                        {
                            yFilt[i] = yFilt[i + 1];
                            yOut = yOut + yFilt[i];
                        }
                        yOut = yOut / 6;
                        axis2AccelTxt.Text = e.Acceleration.ToString();
                        break;
                    case 2:
                        zOut = 0;
                        zFilt[6] = e.Acceleration;
                        for (i = 0; i < 6; i++)
                        {
                            zFilt[i] = zFilt[i + 1];
                            zOut = zOut + zFilt[i];
                        }
                        zOut = zOut / 6;
                        axis3AccelTxt.Text = e.Acceleration.ToString();
                        break;
                }
            }
            catch (PhidgetException ex)
            {
                MessageBox.Show(ex.Description);
            }

            xOld = xCenter - (float)xOut * circleRadius;
            yOld = yCenter + (float)yOut * circleRadius;

            accelGraphicsBuffer.Graphics.DrawLine(xyAxisPen, xCenter, yCenter, xOld, yOld);
            accelGraphicsBuffer.Graphics.DrawEllipse(circlePen, circleRectangle);

            if (attached.axes.Count == 3)
            {
                if (zOut > 0)
                {
                    accelGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Red, 2),
                        new Rectangle((int)xCenter - (int)(circleRadius * zOut), (int)yCenter - (int)(circleRadius * zOut),
                        (int)(circleDiameter * zOut), (int)(circleDiameter * zOut)));
                }
                else
                {
                    accelGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Green, 2),
                        new Rectangle((int)xCenter - (int)(circleRadius * -zOut), (int)yCenter - (int)(circleRadius * -zOut),
                        (int)(circleDiameter * -zOut), (int)(circleDiameter * -zOut)));
                }
            }

            accelGraphicsBuffer.Render(panel1.CreateGraphics());

            accelGraphicsBuffer.Dispose();

            accelGraphicsContext.Dispose();
        }
Beispiel #26
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();
        }