public void Remove(KeyFrame value, bool bSuspendRedraw)
        {
            // Use base class to process actual collection operation
            base.List.Remove(value as object);

            if(value.KeyFrameType == KeyFrame.enumKeyFrameType.Snapshot)
                _arySingleFrames.Remove(value);
            else if(value.KeyFrameType == KeyFrame.enumKeyFrameType.CurrentFrame)
                _CurrentFrame = null;
            else
                _aryMulitFrames.Remove(value);

            if(!bSuspendRedraw) _Ruler.RedrawBitmap();
        }
        public bool Overlaps(long lStart, long lEnd, KeyFrame testFrame)
        {
            KeyFrame.enumFrameTimeType iTimeType = KeyFrame.enumFrameTimeType.StartTime;
            foreach(KeyFrame frame in base.List)
            {
                if(frame != testFrame && frame != _CurrentFrame && frame.Overlaps(lStart, lEnd, ref iTimeType))
                    return true;
            }

            return false;
        }
 public void Remove(KeyFrame value)
 {
     Remove(value, false);
 }
        public KeyFrame FindClosest(KeyFrame.enumKeyFrameType iType, long lMillisecond, bool bInActualZoneOnly)
        {
            if(iType == KeyFrame.enumKeyFrameType.Snapshot)
            {
                KeyFrame minFrame = null;
                long lMinDist = -1, lDist = 0;

                foreach(KeyFrame frame in _arySingleFrames)
                {
                    lDist = Math.Abs(frame.StartMillisecond - lMillisecond);

                    if(!bInActualZoneOnly || (bInActualZoneOnly && (frame.StartMillisecond <= _Ruler.ActualMillisecond)))
                    {
                        if(lDist < lMinDist || lMinDist == -1)
                        {
                            lMinDist = lDist;
                            minFrame = frame;
                        }
                    }
                }

                if(lMinDist < (long) (lMillisecond*0.05))
                    return minFrame;
                else
                    return null;
            }
            else
            {
                foreach(KeyFrame frame in _aryMulitFrames)
                {
                    if( (lMillisecond >= frame.StartMillisecond) && (lMillisecond <= frame.EndMillisecond) )
                        return frame;
                }
            }

            return null;
        }
 public int IndexOf(KeyFrame value)
 {
     // Find the 0 based index of the requested entry
     return base.List.IndexOf(value);
 }
 public KeyFrame Add(KeyFrame keyFrame)
 {
     return Add(keyFrame, false);
 }
		private void DrawControl(Graphics graphics)
		{
			if(this.Width == 0 || this.Height == 0)
				return;

			_bInsideDraw = true;
			Graphics g = null;

			if(_CurrentFrame == null)
			{
				_CurrentFrame = new KeyFrameCurrent(_lCurrentMillisecond);
				_aryKeyFrames.Add(_CurrentFrame, true);
			}

			RecalculateZoom();
			RecalculateTimeScale();

			if (_Bitmap == null)
			{

				//Debug.WriteLine("TimeRuler Size: (" + this.Width.ToString() + ", " + this.Height.ToString() + ")");

				// Create a bitmap
				_Bitmap = new Bitmap(this.Width, this.Height);

				g = Graphics.FromImage(_Bitmap);

				try
				{
					// Wash the background with BackColor
					//Lets wash the whole thing out with the parent back color
					g.FillRectangle(new SolidBrush(this.Parent.BackColor), 0, 0, _Bitmap.Width, _Bitmap.Height);

					//Lets only draw the ruler portion of this in the control back color.
					if (this.Orientation == enumOrientation.orHorizontal)
					{
						int iHeight = _Bitmap.Height - _iHeaderOffset;
						g.FillRectangle(new SolidBrush(this.BackColor), _iSideOffset, _iHeaderOffset, _iDisplaySize, iHeight);
						Line(g, _iSideOffset, _iHeaderOffset, (_iDisplaySize + _iSideOffset), _iHeaderOffset);
					}
					else
					{
						int iWidth = _Bitmap.Width - _iHeaderOffset;
						g.FillRectangle(new SolidBrush(this.BackColor), _iHeaderOffset, _iSideOffset, iWidth, _iDisplaySize);
						Line(g, _iHeaderOffset, _iSideOffset, _iHeaderOffset, (_iDisplaySize + _iSideOffset));
					}

					DrawTimeScale(g);
					DrawProgressBars(g);
					_aryKeyFrames.Draw(g);

					// Paint the lines on the image
					int iScale = (int) _Scale;
					int intScale = (int) _Scale;

					int iStart = Start();
					int iEnd = iStart + _iDisplaySize + 1;
					float fltStart = (float) iStart;
					float fltEnd = (float) iEnd;

					int j;
					for(float fltJ = fltStart; fltJ <= fltEnd; fltJ += _Scale)
					{
						j = (int) fltJ;
						int iLeft = (int) _Scale;  // Make an assumption that we're starting at zero or on a major increment
						int jOffset = j+_ScaleStartValue;

						if (_RulerAlignment != enumRulerAlignment.raMiddle)
						{
							if (this.Orientation == enumOrientation.orHorizontal)
								Line(g, j, _iHeaderOffset, j, Height);
							else
								Line (g, _iHeaderOffset, j, Width, j);
						}

						iLeft = intScale;     // Set the for loop increment

						iScale = iLeft;

						int iValue = (((jOffset-iStart)/intScale)+1) * _iMajorInterval;
						DrawValue(g, iValue, j - iStart, iScale);

						int iUsed = 0;

						//Draw small lines
						for(int i = 0; i < _iNumberOfDivisions; i++)
						{
							int iX = Convert.ToInt32(Math.Round((double)(_Scale-iUsed)/(double)(_iNumberOfDivisions - i),0)); // Use a spreading algorithm rather that using expensive floating point numbers
							iUsed += iX;

							if (iUsed >= (intScale-iLeft))
							{
								iX = iUsed+j-(intScale-iLeft);

								// Is it an even number and, if so, is it the middle value?
								bool bMiddleMark = ((_iNumberOfDivisions & 0x1) == 0) & (i+1==_iNumberOfDivisions/2);
								bool bShowMiddleMark = bMiddleMark;
								bool bLastDivisionMark = (i+1 == _iNumberOfDivisions);
								bool bLastAlignMiddleDivisionMark =  bLastDivisionMark & (_RulerAlignment == enumRulerAlignment.raMiddle);
								bool bShowDivisionMark = !bMiddleMark & !bLastAlignMiddleDivisionMark;

								if( _RulerAlignment == enumRulerAlignment.raMiddle || !bLastDivisionMark )
								{
									if (bShowMiddleMark)
									{
										DivisionMark(g, iX, _MiddleMarkFactor);  // Height or Width will be 1/3
									} 
									else if (bShowDivisionMark)
									{
										DivisionMark(g, iX, _DivisionMarkFactor);  // Height or Width will be 1/5
									}
								}
							}
						}
					}
					
					if (_i3DBorderStyle != Border3DStyle.Flat)
						ControlPaint.DrawBorder3D(g, this.ClientRectangle, this._i3DBorderStyle );

				}
				catch(Exception ex)
				{
					System.Diagnostics.Debug.WriteLine(ex.Message);
				}
				finally 
				{
					g.Dispose();
				}
			}

			g = graphics;

			try
			{

				// Always draw the bitmap
				g.DrawImage(_Bitmap, this.ClientRectangle);

				RenderTrackLine(g);
			}
			catch(Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.Message);
			}
			finally
			{
				_bInsideDraw = false;
				GC.Collect();
			}

		}
		internal void OnKeyFrameMoving(KeyFrame frameSelected)
		{
			KeyFrameEventArgs e = new KeyFrameEventArgs(frameSelected);
			if (KeyFrameMoving != null) KeyFrameMoving(this, e);
		}
		internal void OnCurrentFrameMoved(KeyFrame frameSelected)
		{
			KeyFrameEventArgs e = new KeyFrameEventArgs(frameSelected);
			if (CurrentFrameMoved != null) CurrentFrameMoved(this, e);
		}
		private void RulerControl_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			try
			{
				//Debug.WriteLine("MouseUp: (" + e.X.ToString() + ", " + e.Y.ToString() + ")");
				if(_MovingFrame != null) 
				{
					_MovingFrame.EndMove(e, this);
					OnKeyFrameMoved(_MovingFrame);
					_MovingFrame = null;
				}
			}
			catch {}

			EventArgs eClick = new EventArgs();
			this.OnClick(eClick);
		}
		internal void OnKeyFrameRemoved(KeyFrame frameSelected)
		{
			KeyFrameEventArgs e = new KeyFrameEventArgs(frameSelected);
			if (KeyFrameRemoved != null) KeyFrameRemoved(this, e);
		}
		private void RulerControl_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			try
			{
				//Debug.WriteLine("MouseDown: (" + e.X.ToString() + ", " + e.Y.ToString() + ")");

				if (e.Button.Equals(MouseButtons.Left) && _bAllowKeyFrameSelection) 
				{
					SelectedKeyFrame = _aryKeyFrames.IsHandleClick(e);

					if(_SelectedFrame != null && _SelectedFrame.CanBeMoved(this))
					{
						_MovingFrame = _SelectedFrame;
						_MovingFrame.StartMove(e, this);
					}
				}
			}
			catch {}

		}
		private void AddKeyFrame(Point pMousePos)
		{
			try
			{
				int iMousePosition = ((this.Orientation == enumOrientation.orHorizontal) ? pMousePos.X : pMousePos.Y);
				long lMillisecond = CalculateMillisecondValue(iMousePosition);

				if( (lMillisecond >= _lStartMillisecond) && (lMillisecond <= _lEndMillisecond) )
				{
					if(lMillisecond <= _lCurrentMillisecond)
						throw new System.Exception("You can not add new keyframes that occur before the current simulation time.");

					KeyFrame keyFrame = new KeyFrame(lMillisecond);
					this.KeyFrames.Add(keyFrame);

					OnKeyFrameAdded(keyFrame);

					SelectedKeyFrame = keyFrame;
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
			public KeyFrameEventArgs(KeyFrame Frame) : base()
			{
				this.SelectedKeyFrame = Frame;
			}
        public KeyFrame RemoveClosest(KeyFrame.enumKeyFrameType iType, long lMillisecond)
        {
            KeyFrame keyClosest = FindClosest(iType, lMillisecond);

            if(keyClosest != null)
            {
                Remove(keyClosest);
                return keyClosest;
            }

            return null;
        }
 public bool Contains(KeyFrame value)
 {
     // Use base class to process actual collection operation
     return base.List.Contains(value as object);
 }
        public int SetIndex(int newIndex, KeyFrame value)
        {
            base.List.Remove(value);
            base.List.Insert(newIndex, value);

            return newIndex;
        }
 public KeyFrame FindClosest(KeyFrame.enumKeyFrameType iType, long lMillisecond)
 {
     return FindClosest(iType, lMillisecond, false);
 }
        public KeyFrame Add(KeyFrame keyFrame, bool bSuspendRedraw)
        {
            if( (keyFrame.StartMillisecond > _Ruler.EndMillisecond) || (keyFrame.EndMillisecond > _Ruler.EndMillisecond) )
                throw new System.Exception("You can not add a keyframe with a start/end time greater than the end time of the ruler.");

            if(keyFrame.KeyFrameType == KeyFrame.enumKeyFrameType.Snapshot)
            {
                //First lets verify that there is not already a single frame at this time slice.
                foreach(KeyFrame frame in _arySingleFrames)
                    if(frame.StartMillisecond == keyFrame.StartMillisecond)
                        return null;

                //Now lets make sure that it does not overlap with any of the video frames.
                KeyFrame.enumFrameTimeType iTimeType = KeyFrame.enumFrameTimeType.StartTime;
                foreach(KeyFrame frame in _aryMulitFrames)
                    if(frame.Overlaps(keyFrame, ref iTimeType))
                        return null;

                _arySingleFrames.Add(keyFrame);
            }
            else if(keyFrame.KeyFrameType == KeyFrame.enumKeyFrameType.CurrentFrame)
            {
                if(_CurrentFrame != null)
                    throw new System.Exception("There is alread a current frame defined.");

                _CurrentFrame = keyFrame;
            }
            else
            {
                //First lets verify that there is not already a range frame overlapping this time slice.
                KeyFrame.enumFrameTimeType iTimeType = KeyFrame.enumFrameTimeType.StartTime;
                foreach(KeyFrame frame in _aryMulitFrames)
                    if(frame.Overlaps(keyFrame, ref iTimeType))
                    {
                        //If it overlaps because of the start time then chunk it. If it overlaps because of the end time
                        //then lets see if we can come up with an end time that will work.
                        if(iTimeType == KeyFrame.enumFrameTimeType.StartTime)
                            return null;
                        else
                            keyFrame.EndMillisecond = frame.StartMillisecond - 1;
                    }

                //Now lets verify that there is not a single frame overlapping this video range.
                foreach(KeyFrame frame in _arySingleFrames)
                    if(keyFrame.Overlaps(frame, ref iTimeType))
                    {
                        //Lets find whether the start or end point is closest and then then
                        //add the frame so it does not overlap.
                        if(Math.Abs(frame.StartMillisecond-keyFrame.StartMillisecond) < Math.Abs(frame.StartMillisecond-keyFrame.EndMillisecond) )
                        {
                            //Start millisecond is closer to the single.
                            keyFrame.StartMillisecond = frame.StartMillisecond + 1;
                        }
                        else
                        {
                            //End millisecond is closer to the single.
                            keyFrame.EndMillisecond = frame.StartMillisecond - 1;

                        }
                    }

                _aryMulitFrames.Add(keyFrame);
            }

            base.List.Add(keyFrame as object);

            if(!bSuspendRedraw) _Ruler.RedrawBitmap();

            return keyFrame;
        }
예제 #20
0
        public virtual bool Overlaps(KeyFrame keyTest, ref enumFrameTimeType iTimeType)
        {
            if( (keyTest.StartMillisecond >= this.StartMillisecond) && (keyTest.StartMillisecond <= this.EndMillisecond) ||
                  (this.StartMillisecond >= keyTest.StartMillisecond) && (this.StartMillisecond <= keyTest.EndMillisecond) )
            {
                iTimeType = enumFrameTimeType.StartTime;
                return true;
            }

            if( (keyTest.EndMillisecond >= this.StartMillisecond) && (keyTest.EndMillisecond <= this.EndMillisecond) ||
                  (this.EndMillisecond >= keyTest.StartMillisecond) && (this.EndMillisecond <= keyTest.EndMillisecond) )
            {
                iTimeType = enumFrameTimeType.EndTime;
                return true;
            }

            return false;
        }