Click here to Skip to main content
13,736,246 members
Click here to Skip to main content

Stats

705.1K views
29.7K downloads
281 bookmarked
Posted 14 Sep 2010
Licenced CPOL

PVS.AVPlayer - MCI Audio and Video Library

, 7 Aug 2018
Windows Media Control Interface (MCI) library with many added features
PVS.AVPlayer
PVS.AVPlayer .NET 2.0
PVS.AVPlayer.XML
PVS.AVPlayer .NET 3.0
PVS.AVPlayer.XML
PVS.AVPlayer .NET 3.5
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.0
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.5
PVS.AVPlayer .NET 4.5.1
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.5.2
PVS.AVPlayer.XML
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.6
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.6.1
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.6.2
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.7
PVS.AVPlayer .NET 4.7.1
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.7.2
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer All Source Code
AVPlayerExample
AVPlayerExample
AVPlayerExample.csproj.user
bin
Debug
PVS.AVPlayer.XML
Release
Dialogs
Display Overlays
obj
Debug
Release
x86
Debug
Release
Properties
Resources
Crystal Italic1.ttf
WingDings3a.ttf
Voice Recorder
FolderView
FolderView
bin
Debug
PVS.AVPlayer.XML
Release
FolderView.csproj.user
obj
Release
x86
Debug
Release
Properties
Resources
Crystal Italic1.ttf
PVS.AVPlayer
AVPlayerExample.csproj.user
PVS.AVPlayer.dll
PVS.AVPlayer.XML
Custom Items
Native Methods
Bob.png
Crystal Italic1.ttf
Dial Green 2.png
Dial Green 4.png
Dial Green.png
Dial Red 2.png
Dial Red.png
media7.ico
media7a.ico
Media8.ico
Media8a.ico
VU Meter.png
WingDings3a.ttf
Sound Recorder
Various
About Dialog
PVS.AVPlayer.dll
PVS.AVPlayer.XML
Custom Items
FolderView.csproj.user
Debug
Bob.png
Crystal Italic1.ttf
media7a.ico
media7b.ico
Media8a.ico
Media8b.ico
Subtitles Overlay
Various
How To (C#)
PVSAVPlayerHowTo
bin
Debug
PVS.AVPlayer.dll
PVS.AVPlayer.XML
Release
obj
Debug
Release
Properties
How To (VB.NET)
PVSAVPlayerHowToVB
bin
Debug
PVS.AVPlayer.dll
PVS.AVPlayer.XML
Release
My Project
Application.myapp
obj
Debug
Release
PVSAVPlayerHowTo.vbproj.user
PVS.AVPlayer Examples
AVPlayerExample.ex_
FolderView.ex_
AVPlayerExample.exe
FolderView.exe
PVS.AVPlayer.dll
#region Usings

using PVS.AVPlayer;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

#endregion

namespace AVPlayerExample
{
    public sealed partial class ScribbleOverlay : Form, IOverlay
    {
        /*
        
        PVS.AVPlayer Display Overlay - Example 'Scribble'
        Simple basic drawing with the mouse on a transparent surface.
        
        */

        // ******************************** Fields

        #region Fields

        private MainWindow  _baseForm;
        private Player      _basePlayer;

        private Graphics    _formGraphics;
        private Graphics    _bufferGraphics;
        private Pen         _pen1;
        private bool        _isDrawing;
        private Point       _lastLocation;
        private Panel       _selectedColor;
        private ColorDialog _colorDialog1;

        // preserve and scale drawing
        private bool        _autoScale = true;  // scribble scaling
        private bool        _scaling;           // in progress
        private Bitmap      _buffer;

        // Mouse Events
        private bool        _hasMouseEvents;
        private bool        _menuActive;

        private bool        _disposed;

        #endregion

        // ******************************** Initialize & Form event handling

        #region Initialize & Form event handling

        // Main
        public ScribbleOverlay(MainWindow baseForm, Player thePlayer)
        {
            InitializeComponent();
            _baseForm = baseForm;
            _basePlayer = thePlayer;

            // Pass on drag and drop to main form (handled in source file: DragDrop.cs):
            AllowDrop = true;
            DragDrop += _baseForm.Form1_DragDrop;

            _buffer = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
            _selectedColor = panel1;
            _pen1 = new Pen(_selectedColor.BackColor, 2);
            _colorDialog1 = new ColorDialog();
        }

        protected override bool ShowWithoutActivation
        {
            get { return true; }
        }

        private void SetMouseEvents()
        {
            if (!_hasMouseEvents)
            {
                _basePlayer.Events.MediaMouseDown += ScribbleOverlay_MouseDown;
                _basePlayer.Events.MediaMouseMove += ScribbleOverlay_MouseMove;
                _basePlayer.Events.MediaMouseUp += ScribbleOverlay_MouseUp;

                _hasMouseEvents = true;
            }
        }

        private void RemoveMouseEvents()
        {
            if (_hasMouseEvents)
            {
                _basePlayer.Events.MediaMouseDown -= ScribbleOverlay_MouseDown;
                _basePlayer.Events.MediaMouseMove -= ScribbleOverlay_MouseMove;
                _basePlayer.Events.MediaMouseUp -= ScribbleOverlay_MouseUp;

                _hasMouseEvents = false;
            }
        }

        // Called when the form is shown or hidden
        private void ScribbleOverlay_VisibleChanged(object sender, EventArgs e)
        {
            // Turn on/off mouse events with Form visibility (Show/Hide)
            if (Visible) SetMouseEvents();
            else RemoveMouseEvents();
        }

        protected override void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    if (_hasMouseEvents) RemoveMouseEvents();
                    _pen1.Dispose(); _pen1 = null;
                    _colorDialog1.Dispose(); _colorDialog1 = null;
                    _buffer.Dispose(); _buffer = null;

                    DragDrop += _baseForm.Form1_DragDrop;
                    _baseForm = null;
                    _basePlayer = null;

                    if (components != null) components.Dispose();
                }
                _disposed = true;
            }
            base.Dispose(disposing);
        }

        #endregion

        // ******************************** IOverlay Control

        #region IOverlay Control

        // The visibility of the menu is controlled by the user from the main application (in this example application)
        public bool MenuEnabled
        {
            get { return scribblePanel.Visible; }
            set { scribblePanel.Visible = value; }
        }

        public bool HasMenu
        {
            get { return true; }
        }

        public void MediaStopped()
        {
            // not used with this overlay
        }

        #endregion

        // ******************************** Do the drawing

        #region Drawing

        private void ScribbleOverlay_MouseDown(object sender, MediaMouseEventArgs e)
        {
            if (!_menuActive)
            {
                _lastLocation = PointToClient(e.Location);
                _formGraphics = CreateGraphics();
                _bufferGraphics = Graphics.FromImage(_buffer);
                _isDrawing = true;
            }
        }

        private void ScribbleOverlay_MouseMove(object sender, MediaMouseEventArgs e)
        {
            if (_isDrawing)
            {
                Point p = PointToClient(e.Location);
                _formGraphics.DrawLine(_pen1, _lastLocation, p);
                _bufferGraphics.DrawLine(_pen1, _lastLocation, p);
                _lastLocation = p;
            }
        }

        private void ScribbleOverlay_MouseUp(object sender, MediaMouseEventArgs e)
        {
            if (_isDrawing)
            {
                _isDrawing = false;
                _formGraphics.Dispose();
                _formGraphics = null;
                _bufferGraphics.Dispose();
                _bufferGraphics = null;
            }
        }

        private void ScribbleOverlay_Paint(object sender, PaintEventArgs e)
        {
            if (!_scaling) e.Graphics.DrawImage(_buffer, 0, 0);
        }

        private void ScribbleOverlay_SizeChanged(object sender, EventArgs e)
        {
            if (_autoScale)
            {
                _scaling = true;
                Bitmap b = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
                Graphics g = Graphics.FromImage(b);
                g.CompositingQuality = CompositingQuality.HighQuality;
                g.InterpolationMode = InterpolationMode.NearestNeighbor;
                g.SmoothingMode = SmoothingMode.None;
                g.DrawImage(_buffer, 0, 0, b.Width, b.Height);
                _buffer.Dispose();
                g.Dispose();
                _buffer = b;
                _scaling = false;
                Refresh();
            }
        }

        #endregion

        // ******************************** Clear Button and Color Panels

        #region Clear Button and Color Panels

        // Clear
        private void ClearButton_Click(object sender, EventArgs e)
        {
            Bitmap b = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
            _buffer.Dispose();
            _buffer = b;

            Refresh();
        }

        // ******************************** Set drawing line color

        // Handles mousedown event for all color panels
        // panel7 is an 'eraser' (same color as Form backcolor)
        private void Panel_MouseDown(object sender, MouseEventArgs e)
        {
            _selectedColor.BorderStyle = BorderStyle.FixedSingle;
            _selectedColor = (Panel)sender;
            _selectedColor.BorderStyle = BorderStyle.Fixed3D;

            if (_selectedColor != panel7 && e.Button == MouseButtons.Right)
            {
                _colorDialog1.Color = _selectedColor.BackColor;
                if (_colorDialog1.ShowDialog(this) == DialogResult.OK)
                {
                    _selectedColor.BackColor = _colorDialog1.Color;
                }
            }

            _pen1.Color = _selectedColor.BackColor;
        }

        #endregion

        // ******************************** Options Menu

        #region Options Menu Opening / Closing

        // When menu openend - can't change color of 'eraser'
        private void OptionsMenu_Opening(object sender, CancelEventArgs e)
        {
            _menuActive = true;
            RemoveMouseEvents();
            lineColorMenuItem.Enabled = _selectedColor != panel7;
        }

        private void OptionsMenu_Closing(object sender, ToolStripDropDownClosingEventArgs e)
        {
            _menuActive = false;
            SetMouseEvents();
        }

        #endregion

        // **************** Options Menu - Line Thickness

        #region Line Thickness

        // Check/Uncheck items in the Line Thickness menu
        private void SetLineThicknessMenu(ToolStripMenuItem theItem)
        {
            foreach (ToolStripMenuItem item in ((ToolStripMenuItem)optionsMenu.Items[1]).DropDown.Items)
            {
                item.Checked = item == theItem;
            }
        }

        // Line Thickness 1 pixel
        private void Pixel1_MenuItem_Click(object sender, EventArgs e)
        {
            _pen1.Width = 1;
            SetLineThicknessMenu(pixel1_MenuItem);
        }

        // Line Thickness 2 pixels
        private void Pixels2_MenuItem_Click(object sender, EventArgs e)
        {
            _pen1.Width = 2;
            SetLineThicknessMenu(pixels2_MenuItem);
        }

        // Line Thickness 4 pixels
        private void Pixels4_MenuItem_Click(object sender, EventArgs e)
        {
            _pen1.Width = 4;
            SetLineThicknessMenu(pixels4_MenuItem);
        }

        // Line Thickness 8 pixels
        private void Pixels8_MenuItem_Click(object sender, EventArgs e)
        {
            _pen1.Width = 8;
            SetLineThicknessMenu(pixels8_MenuItem);
        }

        // Line Thickness 16 pixels
        private void Pixels16_MenuItem_Click(object sender, EventArgs e)
        {
            _pen1.Width = 16;
            SetLineThicknessMenu(pixels16_MenuItem);
        }

        #endregion

        // **************** Options Menu - Line Color

        #region Line Color

        // Line Color
        private void LineColorMenuItem_Click(object sender, EventArgs e)
        {
            if (_selectedColor != panel7)
            {
                _colorDialog1.Color = _selectedColor.BackColor;
                if (_colorDialog1.ShowDialog(this) == DialogResult.OK)
                {
                    _selectedColor.BackColor = _colorDialog1.Color;
                    _pen1.Color = _selectedColor.BackColor;
                }
            }
        }

        #endregion

        // **************** Options Menu - Opacity

        #region Opacity

        // Check/Uncheck items in the Opacity menu
        private void SetOpacityMenu(ToolStripMenuItem theItem)
        {
            foreach (ToolStripMenuItem item in ((ToolStripMenuItem)optionsMenu.Items[3]).DropDown.Items)
            {
                item.Checked = item == theItem;
            }
            opacityMenuItem.Checked = (Opacity != 1);
        }

        // Opacity 25%
        private void Opacity25_MenuItem_Click(object sender, EventArgs e)
        {
            Opacity = 0.25;
            SetOpacityMenu(opacity25_MenuItem);
        }

        // Opacity 50%
        private void Opacity50_MenuItem_Click(object sender, EventArgs e)
        {
            Opacity = 0.5;
            SetOpacityMenu(opacity50_MenuItem);
        }

        // Opacity 75%
        private void Opacity75_MenuItem_Click(object sender, EventArgs e)
        {
            Opacity = 0.75;
            SetOpacityMenu(opacity75_MenuItem);
        }

        // Opacity 100%
        private void Opacity100_MenuItem_Click(object sender, EventArgs e)
        {
            Opacity = 1;
            SetOpacityMenu(opacity100_MenuItem);
        }

        #endregion

        // **************** Options Menu - AutoScale

        #region AutoScale

        private void AutoScaleMenuItem_Click(object sender, EventArgs e)
        {
            autoScaleMenuItem.Checked = _autoScale = !_autoScale;
        }

        #endregion

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Peter Vegter
United States United States
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180920.1 | Last Updated 7 Aug 2018
Article Copyright 2010 by Peter Vegter
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid