AVForm.cs
上传用户:lqb116
上传日期:2014-04-04
资源大小:2712k
文件大小:17k
- using System;
- using System.IO;
- using System.Xml;
- using System.Threading;
- using System.Drawing;
- using System.Collections;
- using System.Windows.Forms;
- using gowk.core.managers;
- using gowk.core.packets;
- using gowk.core.packets.querys;
- using gowk.net.Sockets;
- using gowk.core;
- using gowk.net;
- using gowk.controls;
- using gowk.multimedia;
- namespace gowk.forms
- {
- /// <summary>
- /// AVForm 的摘要说明。
- /// </summary>
- public class AVForm :gowk.controls.GForm
- {
- gowk.multimedia.AV av;
- Form master;
- private gowk.controls.GButton remote;
- private gowk.controls.GButton local;
- private Image upImage,downImage;
- private gowk.controls.GPanel gPanel1;
- private gowk.controls.GPanel gPanel2;
- private gowk.controls.GButton gButton3;
-
- gowk.multimedia.Mixer mixer;
- gowk.multimedia.Mixer.MixerControlDetail indtl,outdtl;
- private System.Windows.Forms.ProgressBar involume;
- private System.Windows.Forms.ProgressBar outvolume;
- gowk.common.SkinConfig skf;
- private gowk.controls.GButton btnoutvalume;
- private gowk.controls.GButton btninvolume;
- private System.Windows.Forms.PictureBox r;
- private System.Windows.Forms.PictureBox l;
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- public AVForm()
- {
- InitializeComponent();
- this.InitializeMixing();
- gowk.common.SkinConfig.Instance.SkinChanged+=new EventHandler(Instance_SkinChanged);
- this.LoadSkin();
- this.l.Visible=false;
- this.r.Visible=true;
- int h=this.remote.Height+this.local.Height+40+r.Height;
- if(this.ImageTopLeft!=null)h+=this.ImageTopLeft.Height;
- if(this.ImageBottomLeft!=null)h+=this.ImageBottomLeft.Height;
- this.Height=h;
- }
- public AVForm(Form master):this()
- {
- this.master=master;
- this.master.Move+=new EventHandler(master_Move);
- this.master.VisibleChanged+=new EventHandler(master_VisibleChanged);
- this.master.SizeChanged+=new EventHandler(master_SizeChanged);
- }
- private void InitializeMixing()
- {
- mixer=new Mixer(this);
- mixer.MixerControlChange+=new EventHandler(mixer_MixerControlChange);
-
- this.outdtl=new gowk.multimedia.Mixer.MixerControlDetail(mixer,gowk.multimedia.Mixer.MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);
- this.outvolume.Minimum=this.outdtl.Min;
- this.outvolume.Maximum=this.outdtl.Max;
- this.outvolume.Value=this.outdtl.Volume;
-
- this.indtl=new gowk.multimedia.Mixer.MixerControlDetail(mixer,gowk.multimedia.Mixer.MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE);
- this.involume.Minimum=indtl.Min;
- this.involume.Maximum=indtl.Max;
- this.involume.Value=this.indtl.Volume;
- }
- private void SyncVolumn()
- {
- this.involume.Value=this.indtl.Volume;
- this.outvolume.Value=this.outdtl.Volume;
-
- // this.btnoutvalume.BackgroundImage=this.indtl.Mute?skf.GetImage("/gowk_skin/images/avform/speakerdisabled"):skf.GetImage("/gowk_skin/images/avform/speaker");
- // this.btninvolume.BackgroundImage=this.outdtl.Mute?skf.GetImage("/gowk_skin/images/avform/microphonedisabled"):skf.GetImage("/gowk_skin/images/avform/microphone");
- }
- private void mixer_MixerControlChange(object sender, EventArgs e)
- {
- this.SyncVolumn();
- }
- private void Instance_SkinChanged(object sender, EventArgs e)
- {
- this.LoadSkin();
- }
- public void Initialize()
- {
- if(av!=null)this.av.Dispose();
- this.av=new AV(this.l,this.r);
- this.av.IniChanel();
- }
- public AV AV
- {
- get{return this.av;}
- }
- public void Connect(string ip,int port)
- {
- this.av.IniAudio();
- this.av.IniVideo();
- this.av.Start(ip,port);
- }
- public void Stop()
- {
- if(this.av!=null)this.av.Dispose();
- }
- private void LoadSkin()
- {
- skf=gowk.common.SkinConfig.Instance;
- this.upImage=skf.GetImage("/gowk_skin/images/avform/up");
- this.downImage=skf.GetImage("/gowk_skin/images/avform/down");
- this.local.GImage.ActiveImage=this.local.GImage.PressedImage=this.local.GImage.NormalImage=null;
- this.remote.GImage.ActiveImage=this.remote.GImage.PressedImage=this.remote.GImage.NormalImage=null;
- this.remote.GImage.Image=this.r.Visible?this.upImage:this.downImage;
- this.local.GImage.Image=this.l.Visible?this.upImage:this.downImage;
-
-
- this.ImageTopLeft=skf.GetImage("/gowk_skin/images/form/t1");
- this.ImageTopCenter=skf.GetImage("/gowk_skin/images/form/t2");
- this.ImageTopRight=skf.GetImage("/gowk_skin/images/form/t3");
- this.ImageMiddleLeft=skf.GetImage("/gowk_skin/images/form/m1");
- this.ImageMiddleCenter=skf.GetImage("/gowk_skin/images/form/m2");
- this.ImageMiddleRight=skf.GetImage("/gowk_skin/images/form/m3");
- this.ImageBottomLeft=skf.GetImage("/gowk_skin/images/form/b1");
- this.ImageBottomCenter=skf.GetImage("/gowk_skin/images/form/b2");
- this.ImageBottomRight=skf.GetImage("/gowk_skin/images/form/b3");
-
- this.btnoutvalume.BackgroundImage=skf.GetImage("/gowk_skin/images/avform/speaker");
- this.btninvolume.BackgroundImage=skf.GetImage("/gowk_skin/images/avform/microphone");
-
- // this.btnoutvalume.BackgroundImage=this.indtl.Mute?skf.GetImage("/gowk_skin/images/avform/speakerdisabled"):skf.GetImage("/gowk_skin/images/avform/speaker");
- // this.btninvolume.BackgroundImage=this.outdtl.Mute?skf.GetImage("/gowk_skin/images/avform/microphonedisabled"):skf.GetImage("/gowk_skin/images/avform/microphone");
- }
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- mixer.MixerControlChange-=new EventHandler(mixer_MixerControlChange);
- gowk.common.SkinConfig.Instance.SkinChanged-=new EventHandler(Instance_SkinChanged);
- try
- {
- this.av.Dispose();
- }
- catch(System.Exception ex)
- {
- gowk.utility.Diagnostics.Debug.Write(ex);
- }
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows 窗体设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(AVForm));
- this.remote = new gowk.controls.GButton();
- this.local = new gowk.controls.GButton();
- this.gPanel1 = new gowk.controls.GPanel();
- this.gPanel2 = new gowk.controls.GPanel();
- this.gButton3 = new gowk.controls.GButton();
- this.outvolume = new System.Windows.Forms.ProgressBar();
- this.btnoutvalume = new gowk.controls.GButton();
- this.btninvolume = new gowk.controls.GButton();
- this.involume = new System.Windows.Forms.ProgressBar();
- this.r = new System.Windows.Forms.PictureBox();
- this.l = new System.Windows.Forms.PictureBox();
- this.gPanel1.SuspendLayout();
- this.gPanel2.SuspendLayout();
- this.SuspendLayout();
- //
- // remote
- //
- this.remote.BackColor = System.Drawing.Color.Transparent;
- this.remote.Dock = System.Windows.Forms.DockStyle.Top;
- this.remote.GBorderStyle = gowk.controls.GBorderStyle.Solid;
- this.remote.IsRound = true;
- this.remote.Location = new System.Drawing.Point(0, 22);
- this.remote.Name = "remote";
- this.remote.Size = new System.Drawing.Size(168, 20);
- this.remote.TabIndex = 1;
- this.remote.Click += new System.EventHandler(this.remote_Click);
- //
- // local
- //
- this.local.BackColor = System.Drawing.Color.Transparent;
- this.local.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.local.GBorderStyle = gowk.controls.GBorderStyle.Solid;
- this.local.IsRound = true;
- this.local.Location = new System.Drawing.Point(0, 332);
- this.local.Name = "local";
- this.local.Size = new System.Drawing.Size(168, 20);
- this.local.TabIndex = 3;
- this.local.Click += new System.EventHandler(this.local_Click);
- //
- // gPanel1
- //
- this.gPanel1.BackColor = System.Drawing.Color.Transparent;
- this.gPanel1.Controls.Add(this.gPanel2);
- this.gPanel1.Controls.Add(this.l);
- this.gPanel1.Controls.Add(this.r);
- this.gPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.gPanel1.GBorderStyle = gowk.controls.GBorderStyle.Solid;
- this.gPanel1.IsRound = true;
- this.gPanel1.Location = new System.Drawing.Point(0, 42);
- this.gPanel1.Name = "gPanel1";
- this.gPanel1.Size = new System.Drawing.Size(168, 290);
- this.gPanel1.TabIndex = 5;
- //
- // gPanel2
- //
- this.gPanel2.Controls.Add(this.gButton3);
- this.gPanel2.Controls.Add(this.outvolume);
- this.gPanel2.Controls.Add(this.btnoutvalume);
- this.gPanel2.Controls.Add(this.btninvolume);
- this.gPanel2.Controls.Add(this.involume);
- this.gPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
- this.gPanel2.GBorderStyle = gowk.controls.GBorderStyle.Solid;
- this.gPanel2.IsRound = true;
- this.gPanel2.Location = new System.Drawing.Point(0, 124);
- this.gPanel2.Name = "gPanel2";
- this.gPanel2.Size = new System.Drawing.Size(168, 38);
- this.gPanel2.TabIndex = 6;
- //
- // gButton3
- //
- this.gButton3.Anchor = System.Windows.Forms.AnchorStyles.None;
- this.gButton3.GBorderStyle = gowk.controls.GBorderStyle.Solid;
- this.gButton3.IsRound = true;
- this.gButton3.Location = new System.Drawing.Point(142, 10);
- this.gButton3.Name = "gButton3";
- this.gButton3.Size = new System.Drawing.Size(16, 16);
- this.gButton3.TabIndex = 12;
- //
- // outvolume
- //
- this.outvolume.Anchor = System.Windows.Forms.AnchorStyles.None;
- this.outvolume.Location = new System.Drawing.Point(38, 24);
- this.outvolume.Name = "outvolume";
- this.outvolume.Size = new System.Drawing.Size(100, 8);
- this.outvolume.TabIndex = 11;
- this.outvolume.MouseUp += new System.Windows.Forms.MouseEventHandler(this.outvolume_MouseUp);
- this.outvolume.MouseMove += new System.Windows.Forms.MouseEventHandler(this.outvolume_MouseMove);
- //
- // btnoutvalume
- //
- this.btnoutvalume.Anchor = System.Windows.Forms.AnchorStyles.None;
- this.btnoutvalume.GBorderStyle = gowk.controls.GBorderStyle.Solid;
- this.btnoutvalume.IsRound = true;
- this.btnoutvalume.Location = new System.Drawing.Point(14, 20);
- this.btnoutvalume.Name = "btnoutvalume";
- this.btnoutvalume.Size = new System.Drawing.Size(16, 16);
- this.btnoutvalume.TabIndex = 10;
- this.btnoutvalume.Click += new System.EventHandler(this.btnoutvalume_Click);
- //
- // btninvolume
- //
- this.btninvolume.Anchor = System.Windows.Forms.AnchorStyles.None;
- this.btninvolume.GBorderStyle = gowk.controls.GBorderStyle.Solid;
- this.btninvolume.IsRound = true;
- this.btninvolume.Location = new System.Drawing.Point(14, 1);
- this.btninvolume.Name = "btninvolume";
- this.btninvolume.Size = new System.Drawing.Size(16, 16);
- this.btninvolume.TabIndex = 9;
- this.btninvolume.Click += new System.EventHandler(this.btninvolume_Click);
- //
- // involume
- //
- this.involume.Anchor = System.Windows.Forms.AnchorStyles.None;
- this.involume.Location = new System.Drawing.Point(38, 5);
- this.involume.Name = "involume";
- this.involume.Size = new System.Drawing.Size(100, 8);
- this.involume.TabIndex = 8;
- this.involume.MouseUp += new System.Windows.Forms.MouseEventHandler(this.involume_MouseUp);
- this.involume.MouseMove += new System.Windows.Forms.MouseEventHandler(this.involume_MouseMove);
- //
- // r
- //
- this.r.Dock = System.Windows.Forms.DockStyle.Top;
- this.r.Image = ((System.Drawing.Image)(resources.GetObject("r.Image")));
- this.r.Location = new System.Drawing.Point(0, 0);
- this.r.Name = "r";
- this.r.Size = new System.Drawing.Size(168, 124);
- this.r.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
- this.r.TabIndex = 7;
- this.r.TabStop = false;
- //
- // l
- //
- this.l.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.l.Image = ((System.Drawing.Image)(resources.GetObject("l.Image")));
- this.l.Location = new System.Drawing.Point(0, 162);
- this.l.Name = "l";
- this.l.Size = new System.Drawing.Size(168, 128);
- this.l.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
- this.l.TabIndex = 8;
- this.l.TabStop = false;
- //
- // AVForm
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.BackColor = System.Drawing.Color.Gray;
- this.ClientSize = new System.Drawing.Size(168, 352);
- this.Controls.Add(this.gPanel1);
- this.Controls.Add(this.local);
- this.Controls.Add(this.remote);
- this.DockPadding.Top = 22;
- this.Name = "AVForm";
- this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
- this.Text = "AVForm";
- this.TransparencyKey = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(128)));
- this.gPanel1.ResumeLayout(false);
- this.gPanel2.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- #endregion
- private void SetHeight()
- {
- int h=this.remote.Height+this.local.Height+40;
- if(this.ImageTopLeft!=null)h+=this.ImageTopLeft.Height;
- if(this.ImageBottomLeft!=null)h+=this.ImageBottomLeft.Height;
- if(this.l.Visible)h+=l.Height;
- if(this.r.Visible)h+=r.Height;
- this.Height=h;
- }
- private void remote_Click(object sender, System.EventArgs e)
- {
- this.remote.GImage.ActiveImage=this.remote.GImage.PressedImage=this.remote.GImage.NormalImage=null;
- if(this.r.Visible)
- {
- this.r.Hide();
- this.remote.GImage.Image=this.downImage;
- }
- else
- {
- this.r.Show();
- this.remote.GImage.Image=this.upImage;
- }
- SetHeight();
- }
- private void local_Click(object sender, System.EventArgs e)
- {
- this.local.GImage.ActiveImage=this.local.GImage.PressedImage=this.local.GImage.NormalImage=null;
- if(this.l.Visible)
- {
- this.l.Hide();
- this.local.GImage.Image=this.downImage;
- }
- else
- {
- this.l.Show();
- this.local.GImage.Image=this.upImage;
- }
- SetHeight();
- }
- private void master_Move(object sender, EventArgs e)
- {
- this.XX();
- }
- private void master_VisibleChanged(object sender, EventArgs e)
- {
- this.Visible=this.master.Visible;
- }
- private void master_SizeChanged(object sender, EventArgs e)
- {
- this.XX();
- }
- protected override void OnLocationChanged(EventArgs e)
- {
- base.OnLocationChanged (e);
- this.XX();
- }
- private bool contains(int value,int min,int max)
- {
- return value<max && value>min;
- }
- private void XX()
- {
- if(!this.Visible && !this.master.Visible)return;
- if(this.WindowState==FormWindowState.Minimized ||this.master.WindowState==FormWindowState.Minimized)return;
- Rectangle mb=this.master.Bounds;
- Rectangle lb=this.Bounds;
- int x=lb.X;
- int y=lb.Y;
- if(lb.Bottom<mb.Top)
- {
- y=mb.Top-lb.Height;
- }
- else if(lb.Top>mb.Bottom)
- {
- y=mb.Bottom;
- }
- if(lb.Right<mb.Left)
- {
- x=mb.Left-lb.Width;
- }
- else if(lb.Left>mb.Right)
- {
- x=mb.Right;
- }
- this.Location=new Point(x,y);
- /* Rectangle track=this.master.Bounds;
- Rectangle lb=this.Bounds;
- track.Inflate(lb.Width,lb.Height);
- track.Width-=lb.Width;
- track.Height-=lb.Height;
- // track.Offset(-5,-5);
- int x=lb.X;
- int y=lb.Y;
- bool xc=this.contains(x,track.Left,track.Right);
- bool yc=this.contains(y,track.Top,track.Bottom);
- if(xc && !yc)
- {
- y=track.Top-x>x-track.Bottom?track.Bottom:track.Top;
- }
- else if(yc && !yc)
- {
- x=x-track.Left>track.Right-x?track.Right:track.Left;
- }
- else
- {
- x=x<track.Left?track.Left:track.Right;
- y=y<track.Top?track.Top:track.Bottom;
- }
- this.Location=new Point(x,y);*/
- }
- private void outvolume_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- if(e.X<0||e.X>this.outvolume.Width)return;
- int v=(int)(e.X*this.outvolume.Maximum/this.outvolume.Width);
- this.outdtl.Volume=v;
- this.outvolume.Value=this.outdtl.Volume;
- }
- private void involume_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- if(e.X<0||e.X>this.involume.Width)return;
- int v=(int)(e.X*this.involume.Maximum/this.involume.Width);
- this.indtl.Volume=v;
- this.involume.Value=this.indtl.Volume;
- }
- private void involume_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- if(this.involume.Capture)involume_MouseUp(sender,e);
- }
- private void outvolume_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- if(this.outvolume.Capture)outvolume_MouseUp(sender,e);
- }
- private void btnoutvalume_Click(object sender, System.EventArgs e)
- {
- // this.outdtl.Mute=!this.outdtl.Mute;
- }
- private void btninvolume_Click(object sender, System.EventArgs e)
- {
- // this.indtl.Mute=!this.indtl.Mute;
- }
- }
- }