using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace mpeg_tst
{
public class diagram : System.Windows.Forms.Form
{
private d_about my_about=new d_about();
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;
private int[][] mes;
private int[][] poz;
private int[] pzH;
private int nr_mes;
private bool hgrid=true;
private bool vgrid=true;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private int nr_H;
public diagram()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing ) this.Hide();
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(diagram));
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(224)), ((System.Byte)(224)), ((System.Byte)(224)));
this.button1.ForeColor = System.Drawing.Color.Black;
this.button1.Location = new System.Drawing.Point(632, 8);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 24);
this.button1.TabIndex = 0;
this.button1.Text = "CLOSE";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(224)), ((System.Byte)(224)), ((System.Byte)(224)));
this.button2.ForeColor = System.Drawing.Color.Black;
this.button2.Location = new System.Drawing.Point(552, 8);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(72, 24);
this.button2.TabIndex = 1;
this.button2.Text = "About";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(224)), ((System.Byte)(224)), ((System.Byte)(224)));
this.button3.ForeColor = System.Drawing.Color.Black;
this.button3.Location = new System.Drawing.Point(472, 8);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(72, 24);
this.button3.TabIndex = 2;
this.button3.Text = "H-Grid";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(224)), ((System.Byte)(224)), ((System.Byte)(224)));
this.button4.ForeColor = System.Drawing.Color.Black;
this.button4.Location = new System.Drawing.Point(392, 8);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(72, 24);
this.button4.TabIndex = 3;
this.button4.Text = "V-Grid";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// diagram
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(255)));
this.ClientSize = new System.Drawing.Size(712, 366);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button4,
this.button3,
this.button2,
this.button1});
this.ForeColor = System.Drawing.Color.Red;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "diagram";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Diagram";
this.Resize += new System.EventHandler(this.refr);
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{this.Hide();}
public int get_max(int row)
{int i,m=mes[row][0];
for(i=1;i<nr_mes;i++)
if (m<mes[row][i]) m=mes[row][i];
return m;
}
public int get_min(int row)
{
int i,m=mes[row][0];
for(i=1;i<nr_mes;i++)
if (m>mes[row][i]) m=mes[row][i];
return m;
}
protected override void OnPaint(PaintEventArgs pea)
{int H,W,dH,dW,vH,vW,maxH,maxW,minH,minW,i,j,sp;
Graphics G=pea.Graphics;
Pen pen=new Pen(Color.Black);
StringFormat str=new StringFormat();
str.Alignment=str.LineAlignment=StringAlignment.Center;
Font guru=new Font("TimesNewRoman",6);
//Presetari
H=ClientSize.Height;
W=ClientSize.Width;
dH=30;
dW=30;
vH=H-2*dH;
vW=W-2*dW;
//===================================
button1.Location=new System.Drawing.Point(W-80,5);
button2.Location=new System.Drawing.Point(W-160,5);
button3.Location=new System.Drawing.Point(W-240,5);
button4.Location=new System.Drawing.Point(W-320,5);
//Axele de coordonate
G.DrawLine(pen,30,H-30,30,30);
G.DrawLine(pen,30,H-30,W-30,H-30);
G.DrawLine(pen,30,30,25,35);
G.DrawLine(pen,30,30,35,35);
G.DrawLine(pen,W-30,H-30,W-35,H-25);
G.DrawLine(pen,W-30,H-30,W-35,H-35);
G.DrawString("Milisec.",guru,new SolidBrush(Color.Black),W-dW+15,H-dH,str);
G.DrawString("TS packets",guru,new SolidBrush(Color.Black),dW,dH-10,str);
//===================================
if(nr_mes==0) {return;}
// minime si maxime in structura mes
maxH=get_max(1);
maxW=get_max(0);
minH=get_min(1);
minW=get_min(0);
//===================================
//Setarea raportului si a pozitiilor pe axe
poz=new int[2][];
poz[0]=new int[nr_mes];
poz[1]=new int[nr_mes];
sp=vW/20;
for(i=0;i<nr_mes;i++)
{
poz[0][i]=dW+i*vW/nr_mes;
if(i%(nr_mes/sp+1)==0)
{
G.DrawLine(pen,poz[0][i],H-dH+5,poz[0][i],H-dH-5);
G.DrawString(mes[0][i].ToString(),guru,new SolidBrush(Color.Black),poz[0][i],H-dH+15,str);
}
}
nr_H=maxH-minH+2;
pzH=new int[nr_H];
for(i=0;i<nr_H;i++)
{
pzH[i]=dH+(nr_H-i)*(vH-10)/nr_H;
G.DrawLine(pen,dW-5,pzH[i],dW+5,pzH[i]);
G.DrawString(((minH+i)*100).ToString(),guru,new SolidBrush(Color.Black),dW-15,pzH[i],str);
}
for(i=0;i<nr_mes;i++) for(j=minH;j<=maxH;j++) if(mes[1][i]==j) poz[1][i]=pzH[j-minH];
//===================================
pen.Color=Color.BlueViolet;
//V-grid
if(vgrid)
for(i=0;i<nr_mes;i++)
if((i%(nr_mes/sp+1)==0)&&(i>0))
G.DrawLine(pen,poz[0][i],H-dH-5,poz[0][i],poz[1][i]+1);
//H-grid
if(hgrid)
for(i=0;i<nr_mes;i++)
if((i%(nr_mes/sp+1)==0)&&(i>0))
G.DrawLine(pen,poz[0][i],poz[1][i],dW+5,poz[1][i]);
//ActualDraw
pen.Color=Color.Red;
for(i=0;i<nr_mes-1;i++)
G.DrawLine(pen,poz[0][i],poz[1][i],poz[0][i+1],poz[1][i+1]);
//===================================
}
public void set_draw(long[] data,int cnt)
{int i,j,x=0,pos;
nr_mes=0;
mes=new int[2][];
mes[0]=new int[cnt];
mes[1]=new int[cnt];
if(cnt==0) {nr_mes=0;return;}
for(i=0;i<cnt;i++)
{
pos=-1;
j=0;
while((pos<0)&&(j<x))
if (data[i]==mes[0][j]) pos=j;
else j++;
if (pos<0)
{
mes[0][x]=Convert.ToInt32(data[i]);
mes[1][x]=0;
x++;
}
else mes[1][pos]++;
}
nr_mes=x;
}
private void refr(object sender, System.EventArgs e)
{
this.Refresh();
}
private void button2_Click(object sender, System.EventArgs e)
{
my_about.Show();
}
private void button3_Click(object sender, System.EventArgs e)
{
hgrid=!hgrid;
this.Refresh();
}
private void button4_Click(object sender, System.EventArgs e)
{
vgrid=!vgrid;
this.Refresh();
}
}
}