using System;
using System.Drawing;
using System.Windows.Forms;
using JD.Collections;
using PleoNET;
namespace JD.VideoPlayer.Project
{
///
/// A control which holds a PleoControl and a PleoVideoClip
///
public class VideoControl : PleoControl
{
private IVideoConductor _videoConductor;
private bool _hightlighed;
public VideoControl()
{
_videoConductor = null;
Highlighted = false;
}
public IVideoConductor VideoConductor
{
get
{
return _videoConductor;
}
set
{
if (_videoConductor != value)
{
if (null != _videoConductor)
{
_videoConductor.BeforeClipDispose -= VideoControl_BeforeClipDispose;
_videoConductor.ClipChanged -= VideoControl_ClipChanged;
}
_videoConductor = value;
if (null != _videoConductor)
{
_videoConductor.BeforeClipDispose += VideoControl_BeforeClipDispose;
_videoConductor.ClipChanged += VideoControl_ClipChanged;
}
}
}
}
protected override void Dispose(bool disposing)
{
// Detach events
if (disposing)
{
VideoConductor = null;
}
base.Dispose(disposing);
}
protected void VideoControl_BeforeClipDispose(object sender, VideoConductorEventArgs args)
{
var clip = args.Clip;
if (null != clip)
{
UnbindVideoClip();
}
}
protected void VideoControl_ClipChanged(object sender, VideoConductorEventArgs args)
{
var clip = args.Clip;
if (null != clip)
{
BindVideoClip(clip);
}
}
///
/// Useful for community mashups where the video is filmed flipped.
///
public bool FlipVideo { get; set; }
public bool Highlighted
{
get { return _hightlighed; }
set
{
_hightlighed = value;
BackColor = Highlighted ? Color.FromArgb(255, 50, 50, 50) : Color.DimGray;
Invalidate();
}
}
protected bool HasNoClip
{
get
{
return (null == _videoConductor || null == _videoConductor.Clip);
}
}
public new Bitmap Snapshot()
{
if (HasNoClip)
{
return null;
}
Update();
return base.Snapshot();
}
protected override void OnPaint(PaintEventArgs e)
{
var container = e.Graphics.BeginContainer();
if (FlipVideo)
{
e.Graphics.TranslateTransform(Width, 0);
e.Graphics.ScaleTransform(-1, 1);
}
base.OnPaint(e);
e.Graphics.EndContainer(container);
PaintText(e);
}
public void PaintText(PaintEventArgs e)
{
if (!string.IsNullOrEmpty(Text))
{
using (var brush = new SolidBrush(ForeColor))
{
e.Graphics.DrawString(Text, DefaultFont, brush, Bounds);
}
}
}
public override bool PreProcessMessage(ref System.Windows.Forms.Message msg)
{
if (msg.Msg == TeaBox.Actions.ActionManager.WM_KEYDOWN)
{
long param = (long)msg.WParam;
Keys keys = (Keys)param | Control.ModifierKeys;
// Let the action manager handle the arrow keys.
if (keys.IsIn(Keys.Left, Keys.Right, Keys.Up, Keys.Down, Keys.Tab | Keys.Shift))
{
return false;
}
}
return base.PreProcessMessage(ref msg);
}
}
}