Air_Hockey_Simulator.AirHockeySimCtrl.OnPaint C# (CSharp) Method

OnPaint() protected method

protected OnPaint ( PaintEventArgs e ) : void
e PaintEventArgs
return void
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            double delta_time = (DateTime.Now - lastGUIUpdate).TotalMilliseconds;
            SetupGraphics(g, delta_time.ToString());

            if (!debug_break) {
                //DateTime tm_start = DateTime.Now;
                InformationPacket ip = Physics.Physics.Update(Puck, Puck, Table, delta_time);
                //times.Add((DateTime.Now - tm_start).TotalMilliseconds);
                //if (times.Count == 1000)
                //{
                //    tm.Stop();
                //    MessageBox.Show(times.Average().ToString());
                //}
                debugging_packets.Add(ip);
                if (debugging_packets.Count > 2)
                    debugging_packets.RemoveAt(0);
            }

            if (Puck.Location.X < 0 || Puck.Location.X > Table.Width || Puck.Location.Y < 0 || Puck.Location.Y > Table.Height) {
                tm.Stop();
                debug_break = true;
            }

            g.FillRectangle(Brushes.White, 0, 0, si(Table.Width), si(Table.Height));
            g.DrawRectangle(Pens.Black, 0, 0, si(Table.Width), si(Table.Height));

            foreach (Line w in Table.Walls) {
                DrawLine(g, w, Pens.Black);
            }

            foreach (Arc a in Table.Arcs) {
                DrawArc(g, a, Pens.Black);
            }

            g.FillEllipse(Brushes.Blue, getPuckRectangle(Puck));
            DrawLine(g, Puck.Path, Pens.Red);

            if (debug_break) {
                for (int j = 0; j < debugging_packets.Count; ++j) {
                    for (int i = 0; i < debugging_packets[j].Points.Count; ++i) {
                        g.DrawRectangle(getFromInt(i), s(debugging_packets[j].Points[i].X), s(debugging_packets[j].Points[i].Y), 10, 10);
                    }
                    for (int i = 0; i < debugging_packets[j].Lines.Count; ++i) {
                        DrawLine(g, debugging_packets[j].Lines[i], getFromInt(j));
                    }
                }
            }

            lastGUIUpdate = DateTime.Now;
            base.OnPaint(e);
        }