private void panTimelineViewer_DragDrop(object sender, DragEventArgs e)
        {
            if (TimelineDragDropInsertIndex >= 0)
            {
                Timeline ItemToMove = GetTimelineEvent(TimelineDragDropSelectedItemIndex, true);
                InsertTimelineEvent(TimelineDragDropInsertIndex, ItemToMove, false);
                FinishTimelineEventRemove();
            }
            else if (TimelineDragDropInsertIndex == -1)
            {
                Point MousePos = PointToClient(new Point(e.X, e.Y));

                int NewDragDropInsertIndex = (MousePos.Y - 20) / 21 + vsbTimeline.Value;
                if (NewDragDropInsertIndex < TimelineActiveItems)
                {
                    if (NewDragDropInsertIndex != TimelineDragDropSelectedItemIndex)
                    {
                        GroupTimeline SelectGroup = GetTimelineEvent(NewDragDropInsertIndex) as GroupTimeline;
                        Timeline      ItemToMove  = GetTimelineEvent(TimelineDragDropSelectedItemIndex, true);

                        if (SelectGroup != null)
                        {
                            InsertTimelineEvent(NewDragDropInsertIndex, ItemToMove, true);
                        }
                    }
                }
                FinishTimelineEventRemove();
            }
            TimelineDragDropInsertIndex = -1;
            DrawTimeline();
        }
        private void InsertTimelineEvent(int TargetIndex, Timeline ActiveEvent, bool InsertInGroup)
        {
            int CurrentIndex = 0;

            for (int i = 0; i < ActiveAnimation.ListTimelineEvent.Count; i++)
            {
                if (ActiveAnimation.ListTimelineEvent[i] == null)
                {
                    if (TargetIndex == i)
                    {
                        break;
                    }
                    else
                    {
                        CurrentIndex++;
                        continue;
                    }
                }

                GroupTimeline ActiveGroup = ActiveAnimation.ListTimelineEvent[i] as GroupTimeline;

                if (CurrentIndex == TargetIndex)
                {
                    if (InsertInGroup && ActiveGroup != null)
                    {
                        ActiveEvent.GroupIndex = (int)ActiveGroup.KeyValue;
                        ActiveGroup.ListEvent.Add(ActiveEvent);
                        return;
                    }
                    else
                    {
                        ActiveEvent.GroupIndex = -1;
                        ActiveAnimation.ListTimelineEvent.Insert(i, ActiveEvent);
                        return;
                    }
                }
                if (ActiveGroup != null)
                {
                    if (InsertTimelineEvent(TargetIndex, ref CurrentIndex, ActiveGroup, ActiveEvent, InsertInGroup))
                    {
                        return;
                    }
                }
                else
                {
                    CurrentIndex++;
                }
            }
            if (CurrentIndex <= TargetIndex)
            {
                ActiveEvent.GroupIndex = -1;
                ActiveAnimation.ListTimelineEvent.Insert(CurrentIndex, ActiveEvent);
                return;
            }
        }
        public override Timeline Copy(AnimationClass.AnimationLayer ActiveLayer)
        {
            GroupTimeline NewGroupEvent = new GroupTimeline(Name);

            NewGroupEvent.UpdateFrom(this, ActiveLayer);

            NewGroupEvent.ListEvent = ListEvent;

            NewGroupEvent.KeyValue = KeyValue;
            NewGroupEvent.IsOpen   = IsOpen;

            return(NewGroupEvent);
        }
        private bool InsertTimelineEvent(int TargetIndex, ref int CurrentIndex, GroupTimeline ActiveGroup, Timeline ActiveEvent, bool InsertInGroup)
        {
            if (CurrentIndex == TargetIndex)
            {
                ActiveEvent.GroupIndex = ActiveGroup.GroupIndex;
                ActiveGroup.ListEvent.Insert(0, ActiveEvent);
                return(true);
            }

            CurrentIndex++;
            if (!ActiveGroup.IsOpen)
            {
                return(false);
            }

            for (int i = 0; i < ActiveGroup.ListEvent.Count; i++)
            {
                if (ActiveGroup.ListEvent[i] == null)
                {
                    CurrentIndex++;
                    continue;
                }

                GroupTimeline ChildGroup = ActiveGroup.ListEvent[i] as GroupTimeline;
                if (ChildGroup != null)
                {
                    if (InsertInGroup && CurrentIndex == TargetIndex)
                    {
                        ActiveEvent.GroupIndex = (int)ChildGroup.KeyValue;
                        ChildGroup.ListEvent.Add(ActiveEvent);
                        return(true);
                    }
                    else if (InsertTimelineEvent(TargetIndex, ref CurrentIndex, ChildGroup, ActiveEvent, InsertInGroup))
                    {
                        return(true);
                    }
                }
                else
                {
                    if (CurrentIndex == TargetIndex)
                    {
                        ActiveGroup.ListEvent.Insert(i, ActiveEvent);
                        return(true);
                    }
                    CurrentIndex++;
                }
            }
            return(false);
        }
            public virtual void LoadLayer(BinaryReader BR, Microsoft.Xna.Framework.Content.ContentManager Content, Dictionary <string, Timeline> DicTimeline)
            {
                Name                = BR.ReadString();
                LayerBlendState     = (LayerBlendStates)BR.ReadByte();
                _LayerSamplerStates = (LayerSamplerStates)BR.ReadByte();
                UpdateSamplerState();

                int DicGroupEventCount = BR.ReadInt32();

                DicGroupEvent = new Dictionary <uint, GroupTimeline>(DicGroupEventCount);
                for (int T = 0; T < DicGroupEventCount; T++)
                {
                    uint          Key        = BR.ReadUInt32();
                    GroupTimeline NewGroup   = new GroupTimeline(BR.ReadString());
                    int           GroupIndex = BR.ReadInt32();
                    NewGroup.GroupIndex = GroupIndex;
                    NewGroup.KeyValue   = Key;
                    DicGroupEvent.Add(Key, NewGroup);
                }

                int DicTimelineEventCount = BR.ReadInt32();

                DicTimelineEvent = new Dictionary <int, List <Timeline> >(DicTimelineEventCount);
                for (int T = 0; T < DicTimelineEventCount; T++)
                {
                    int ListEventCount = BR.ReadInt32();

                    for (int E = 0; E < ListEventCount; E++)
                    {
                        Timeline ActiveEvent = Timeline.Load(BR, Content, this, DicTimeline);

                        if (!DicTimelineEvent.ContainsKey(ActiveEvent.SpawnFrame))
                        {
                            DicTimelineEvent.Add(ActiveEvent.SpawnFrame, new List <Timeline>());
                        }

                        DicTimelineEvent[ActiveEvent.SpawnFrame].Add(ActiveEvent);
                    }
                }
                int ChildrenCount = BR.ReadInt32();

                for (int L = 0; L < ChildrenCount; L++)
                {
                    AnimationLayer NewChildrenLayer = new AnimationLayer(Owner, "");
                    NewChildrenLayer.LoadLayer(BR, Content, DicTimeline);
                    ListChildren.Add(NewChildrenLayer);
                }
            }
        private void DrawGroup(ref int Index, ref int VisibleIndex, int Indent, GroupTimeline ActiveGroup)
        {
            if (Index >= vsbTimeline.Value)
            {
                if (ActiveAnimation.ListSelectedObjects.Contains(ActiveGroup))
                {
                    panTimelineViewerGraphicDevice.Graphics.FillRectangle(Brushes.CornflowerBlue, new Rectangle(10, 20 + VisibleIndex * 21, 100, 20));
                }

                if (ActiveGroup.IsOpen)
                {
                    panTimelineViewerGraphicDevice.Graphics.DrawLine(Pens.Black, 1 + Indent * 5, 30 + VisibleIndex * 21, 6 + Indent * 5, 30 + VisibleIndex * 21);
                    panTimelineViewerGraphicDevice.Graphics.DrawLine(Pens.Black, 1 + Indent * 5, 30 + VisibleIndex * 21, 6 + Indent * 5, 25 + VisibleIndex * 21);
                    panTimelineViewerGraphicDevice.Graphics.DrawLine(Pens.Black, 6 + Indent * 5, 25 + VisibleIndex * 21, 6 + Indent * 5, 30 + VisibleIndex * 21);
                }
                else
                {
                    panTimelineViewerGraphicDevice.Graphics.DrawLine(Pens.Black, 2 + Indent * 5, 22 + VisibleIndex * 21, 6 + Indent * 5, 26 + VisibleIndex * 21);
                    panTimelineViewerGraphicDevice.Graphics.DrawLine(Pens.Black, 2 + Indent * 5, 30 + VisibleIndex * 21, 6 + Indent * 5, 26 + VisibleIndex * 21);
                    panTimelineViewerGraphicDevice.Graphics.DrawLine(Pens.Black, 2 + Indent * 5, 22 + VisibleIndex * 21, 2 + Indent * 5, 30 + VisibleIndex * 21);
                }
                panTimelineViewerGraphicDevice.Graphics.DrawString(ActiveGroup.Name, fntListView, Brushes.Black, 10 + Indent * 5, 20 + VisibleIndex * 21);
                ++VisibleIndex;
            }
            Index++;

            if (ActiveGroup.IsOpen)
            {
                for (int i = 0; i < ActiveGroup.ListEvent.Count; i++)
                {
                    Timeline      ChildEvent = ActiveGroup.ListEvent[i];
                    GroupTimeline ChildGroup = ChildEvent as GroupTimeline;

                    if (ChildGroup != null)
                    {
                        DrawGroup(ref Index, ref VisibleIndex, Indent + 1, ChildGroup);
                    }
                    else
                    {
                        if (Index >= vsbTimeline.Value)
                        {
                            DrawTimelineEvent(Indent + 1, ref VisibleIndex, ChildEvent);
                        }
                        Index++;
                    }
                }
            }
        }
        private void tsmCreateGroup_Click(object sender, EventArgs e)
        {
            GroupTimeline NewGroup = new GroupTimeline();

            ActiveAnimation.ListTimelineEvent.Add(NewGroup);
            uint InsertIndex = 0;

            while (ActiveLayer.DicGroupEvent.ContainsKey(InsertIndex))
            {
                InsertIndex++;
            }

            NewGroup.KeyValue = InsertIndex;
            ActiveLayer.DicGroupEvent.Add(InsertIndex, NewGroup);
            UpdateTimelineVisibleItems();
            DrawTimeline();
        }
        private void FinishTimelineEventRemove(GroupTimeline ActiveGroup)
        {
            for (int i = 0; i < ActiveGroup.ListEvent.Count; i++)
            {
                if (ActiveGroup.ListEvent[i] == null)
                {
                    ActiveGroup.ListEvent.RemoveAt(i--);
                }
                else
                {
                    GroupTimeline ChildGroup = ActiveGroup.ListEvent[i] as GroupTimeline;

                    if (ChildGroup != null)
                    {
                        FinishTimelineEventRemove(ChildGroup);
                    }
                }
            }
        }
        private void UpdateTimelineVisibleItems(GroupTimeline ActiveGroup)
        {
            if (!ActiveGroup.IsOpen)
            {
                return;
            }

            for (int i = 0; i < ActiveGroup.ListEvent.Count; i++)
            {
                TimelineActiveItems++;

                GroupTimeline ChildGroup = ActiveGroup.ListEvent[i] as GroupTimeline;

                if (ChildGroup != null)
                {
                    UpdateTimelineVisibleItems(ChildGroup);
                }
            }
        }
        private Timeline GetTimelineEventFromGroup(int TargetIndex, ref int CurrentIndex, GroupTimeline ActiveGroup, bool Remove, int Indent = 1)
        {
            if (!ActiveGroup.IsOpen)
            {
                return(null);
            }

            Timeline TempEvent;

            for (int i = 0; i < ActiveGroup.ListEvent.Count; i++)
            {
                if (CurrentIndex == TargetIndex)
                {
                    TimelineDragDropSelectedItemIndent = Indent;
                    if (Remove)
                    {
                        TempEvent = ActiveGroup.ListEvent[i];
                        ActiveGroup.ListEvent[i] = null;
                        return(TempEvent);
                    }
                    else
                    {
                        return(ActiveGroup.ListEvent[i]);
                    }
                }
                else
                {
                    CurrentIndex++;
                    GroupTimeline ChildGroup = ActiveGroup.ListEvent[i] as GroupTimeline;
                    if (ChildGroup != null)
                    {
                        TempEvent = GetTimelineEventFromGroup(TargetIndex, ref CurrentIndex, ChildGroup, Remove, Indent + 1);
                        if (TempEvent != null)
                        {
                            return(TempEvent);
                        }
                    }
                }
            }
            return(null);
        }
        public void UpdateTimelineVisibleItems()
        {
            TimelineActiveItems = 0;

            for (int i = 0; i < ActiveAnimation.ListTimelineEvent.Count; i++)
            {
                TimelineActiveItems++;

                GroupTimeline ActiveGroup = ActiveAnimation.ListTimelineEvent[i] as GroupTimeline;

                if (ActiveGroup != null)
                {
                    UpdateTimelineVisibleItems(ActiveGroup);
                }
            }

            if (TimelineActiveItems > TimelineVisibleItemCount)
            {
                vsbTimeline.Maximum = 1 + TimelineActiveItems - TimelineVisibleItemCount;
            }
        }
        private void panTimelineViewer_DragOver(object sender, DragEventArgs e)
        {
            Point MousePos = PointToClient(new Point(e.X, e.Y));

            if (MousePos.X < TimelineStartX)
            {
                int NewDragDropInsertIndex = (MousePos.Y - 20) / 21 + vsbTimeline.Value;
                if (NewDragDropInsertIndex < TimelineActiveItems)
                {
                    if (NewDragDropInsertIndex != TimelineDragDropSelectedItemIndex)
                    {
                        GroupTimeline SelectGroup = GetTimelineEvent(NewDragDropInsertIndex) as GroupTimeline;

                        if (SelectGroup != null)
                        {
                            TimelineDragDropInsertIndex = -1;
                        }
                        else
                        {
                            TimelineDragDropInsertIndex = (MousePos.Y - 10) / 21 + vsbTimeline.Value;
                        }
                    }
                    else
                    {
                        TimelineDragDropInsertIndex = -2;
                    }
                }
                else
                {
                    TimelineDragDropInsertIndex = TimelineActiveItems;
                }

                DrawTimeline();
            }
            else
            {
                TimelineDragDropInsertIndex = -2;
            }
        }
        private void SelectTimelineGroup(GroupTimeline ActiveGroup, bool IsSelected)
        {
            for (int i = 0; i < ActiveGroup.ListEvent.Count; i++)
            {
                if (IsSelected)
                {
                    if (!ActiveAnimation.ListSelectedObjects.Contains(ActiveGroup.ListEvent[i]))
                    {
                        ActiveAnimation.ListSelectedObjects.Add(ActiveGroup.ListEvent[i]);
                    }
                }
                else
                {
                    ActiveAnimation.ListSelectedObjects.Remove(ActiveGroup.ListEvent[i]);
                }

                GroupTimeline ChildGroup = ActiveGroup.ListEvent[i] as GroupTimeline;

                if (ChildGroup != null)
                {
                    SelectTimelineGroup(ChildGroup, IsSelected);
                }
            }
        }
        private Timeline GetTimelineEvent(int TargetIndex, bool Remove = false)
        {
            int      CurrentIndex = 0;
            Timeline TempEvent;

            for (int i = 0; i < ActiveAnimation.ListTimelineEvent.Count; i++)
            {
                if (CurrentIndex == TargetIndex)
                {
                    TimelineDragDropSelectedItemIndent = 0;
                    if (Remove)
                    {
                        TempEvent = ActiveAnimation.ListTimelineEvent[i];
                        ActiveAnimation.ListTimelineEvent[i] = null;
                        return(TempEvent);
                    }
                    else
                    {
                        return(ActiveAnimation.ListTimelineEvent[i]);
                    }
                }

                CurrentIndex++;
                GroupTimeline ActiveGroup = ActiveAnimation.ListTimelineEvent[i] as GroupTimeline;

                if (ActiveGroup != null)
                {
                    TempEvent = GetTimelineEventFromGroup(TargetIndex, ref CurrentIndex, ActiveGroup, Remove);
                    if (TempEvent != null)
                    {
                        return(TempEvent);
                    }
                }
            }
            return(null);
        }
        private void DrawTimeline()
        {
            panTimelineViewerGraphicDevice.Graphics.Clear(Color.White);
            int TimelineWidth = Width - TimelineStartX;

            //Draw Key Frame limit lines.
            for (int X = ScrollbarStartIndex < 8 ? -ScrollbarStartIndex : -ScrollbarStartIndex % 8, i = ScrollbarStartIndex < 8 ? 0 : 5 - (ScrollbarStartIndex / 8) % 5; X < TimelineStartX + TimelineWidth - 1 - TimelineStartX; X += 8)
            {
                if (i == 0)
                {
                    panTimelineViewerGraphicDevice.Graphics.DrawLine(Pens.Black, TimelineStartX + X, 0, TimelineStartX + X, 5);
                    panTimelineViewerGraphicDevice.Graphics.DrawLine(Pens.Black, TimelineStartX + X, 15, TimelineStartX + X, 20);
                    i = 4;
                }
                else
                {
                    panTimelineViewerGraphicDevice.Graphics.DrawLine(Pens.Gray, TimelineStartX + X, 0, TimelineStartX + X, 5);
                    panTimelineViewerGraphicDevice.Graphics.DrawLine(Pens.Gray, TimelineStartX + X, 15, TimelineStartX + X, 20);
                    i--;
                }
            }
            panTimelineViewerGraphicDevice.Graphics.DrawRectangle(Pens.Black, new Rectangle(TimelineStartX, 0, TimelineWidth - 1, TimelineHeight - 1));
            panTimelineViewerGraphicDevice.Graphics.DrawLine(Pens.Black, 0, 20, TimelineStartX + TimelineWidth - 1, 20);

            int VisibleIndex = 0;
            int Index        = 0;

            if (ActiveAnimation != null)
            {
                for (int i = 0; i < ActiveAnimation.ListTimelineEvent.Count && VisibleIndex < TimelineVisibleItemCount; i++)
                {
                    Timeline ActiveEvent = ActiveAnimation.ListTimelineEvent[i];

                    GroupTimeline ActiveGroup = ActiveEvent as GroupTimeline;

                    if (ActiveGroup != null)
                    {
                        DrawGroup(ref Index, ref VisibleIndex, 0, ActiveGroup);
                    }
                    else
                    {
                        if (Index >= vsbTimeline.Value)
                        {
                            DrawTimelineEvent(0, ref VisibleIndex, ActiveEvent);
                        }

                        ++Index;
                    }

                    if (TimelineDragDropInsertIndex >= 0)
                    {
                        panTimelineViewerGraphicDevice.Graphics.DrawLine(Pens.Black, 5, 20 + (TimelineDragDropInsertIndex - vsbTimeline.Value) * 21, TimelineStartX - 5, 20 + (TimelineDragDropInsertIndex - vsbTimeline.Value) * 21);
                    }
                }

                if (PlaybackEndKeyFrame >= 0)
                {
                    panTimelineViewerGraphicDevice.Graphics.FillRectangle(PlaybackBrush, new Rectangle(TimelineStartX + PlaybackStartKeyFrame * 8 - ScrollbarStartIndex, 0, (PlaybackEndKeyFrame - PlaybackStartKeyFrame) * 8 - ScrollbarStartIndex, TimelineHeight - 1));
                }

                //Draw the timeline cursor.
                panTimelineViewerGraphicDevice.Graphics.FillRectangle(Brushes.LightSalmon, new Rectangle(TimelineStartX + ActiveKeyFrame * 8 - ScrollbarStartIndex, 0, 8, 20));
                panTimelineViewerGraphicDevice.Graphics.DrawRectangle(Pens.Red, new Rectangle(TimelineStartX + ActiveKeyFrame * 8 - ScrollbarStartIndex, 0, 8, 20));
                panTimelineViewerGraphicDevice.Graphics.DrawLine(Pens.Red, TimelineStartX + ActiveKeyFrame * 8 - ScrollbarStartIndex, 0, TimelineStartX + ActiveKeyFrame * 8 - ScrollbarStartIndex, TimelineHeight - 1);
            }

            //Draw the Key Frames.
            for (int X = -ScrollbarStartIndex % 40 + 1, i = (ScrollbarStartIndex / 40) * 5; X < TimelineWidth - 1; X += 40, i += 5)
            {
                panTimelineViewerGraphicDevice.Graphics.DrawString(i.ToString(), fntTimeline, Brushes.Black, TimelineStartX + X, 6);
            }

            #region Scrollbar

            panTimelineViewerGraphicDevice.Graphics.FillRectangle(Brushes.DarkGray, new Rectangle(TimelineStartX, TimelineHeight, TimelineWidth, 20));
            panTimelineViewerGraphicDevice.Graphics.FillRectangle(Brushes.LightGray, new Rectangle(TimelineStartX + 1, TimelineHeight + 1, 18, 18));
            panTimelineViewerGraphicDevice.Graphics.FillRectangle(Brushes.LightGray, new Rectangle(TimelineStartX + TimelineWidth - 19, TimelineHeight + 1, 18, 18));

            int   ScrollbarPos         = (int)(ScrollbarWidth / (float)TimelineWidth * ScrollbarStartIndex);
            float ScrollbarActualWidth = Width - TimelineStartX - 40 - ScrollbarWidth;

            ScrollbarPos = (int)(ScrollbarStartIndex * (ScrollbarActualWidth / MaximumKeyFrame));

            panTimelineViewerGraphicDevice.Graphics.FillRectangle(Brushes.LightGray, new Rectangle(TimelineStartX + 20 + ScrollbarPos, TimelineHeight + 1, ScrollbarWidth, 18));

            #endregion

            panTimelineViewerGraphicDevice.Render();
        }
        private void panTimelineViewer_MouseDown(object sender, MouseEventArgs e)
        {
            MouseEventOriginal = e;
            MouseEventOld      = e;

            if (e.X < 0)
            {
                return;
            }

            #region Left Button

            if (e.Button == MouseButtons.Left)
            {
                if (e.X < TimelineStartX)
                {
                    TimelineDragDropSelectedItemIndex = -2;
                    int VisibleIndex = 0;

                    for (int i = 0; i < TimelineActiveItems && VisibleIndex < TimelineVisibleItemCount; i++)
                    {
                        ActiveTimelineEvent = GetTimelineEvent(i);

                        //End of TimelineEvent list.
                        if (ActiveTimelineEvent == null)
                        {
                            break;
                        }

                        if (e.Y >= (VisibleIndex + 1) * 20 && e.Y < (VisibleIndex + 2) * 20 && i >= vsbTimeline.Value)
                        {
                            TimelineDragDropSelectedItemIndex = i;
                        }
                        else
                        {
                            if (Control.ModifierKeys != Keys.Shift)
                            {
                                ActiveAnimation.ListSelectedObjects.Remove(ActiveTimelineEvent);
                                GroupTimeline ActiveGroup = ActiveTimelineEvent as GroupTimeline;

                                if (ActiveGroup != null)
                                {
                                    SelectTimelineGroup(ActiveGroup, false);
                                }
                            }
                        }
                        if (i >= vsbTimeline.Value)
                        {
                            VisibleIndex++;
                        }
                    }

                    if (TimelineDragDropSelectedItemIndex >= 0)
                    {
                        ActiveTimelineEvent = GetTimelineEvent(TimelineDragDropSelectedItemIndex);
                        GroupTimeline ActiveGroup = ActiveTimelineEvent as GroupTimeline;

                        if (ActiveGroup != null)
                        {
                            //Expend/Collapse the group
                            if (e.X >= 1 + TimelineDragDropSelectedItemIndent * 5 && e.X < 9 + TimelineDragDropSelectedItemIndent * 5)
                            {
                                ActiveGroup.IsOpen = !ActiveGroup.IsOpen;
                                TimelineDragDropSelectedItemIndex = -2;
                                UpdateTimelineVisibleItems();
                            }
                            else
                            {
                                SelectTimelineGroup(ActiveGroup, true);
                                OnTimelineSelected(ActiveTimelineEvent);
                            }
                        }
                        else
                        {
                            OnTimelineSelected(ActiveTimelineEvent);
                        }
                    }
                    DrawTimeline();
                }
                else if (e.Y <= 20)
                {
                    OnKeyFrameChange((e.X - TimelineStartX + ScrollbarStartIndex) / 8);
                    PlaybackStartKeyFrame = ActiveKeyFrame;
                    PlaybackEndKeyFrame   = -1;
                    DrawTimeline();
                }
                else if (e.Y >= Height - 20)
                {
                    ScrollbarSelected = true;
                }
                else if (ActiveTimelineEvent == null)
                {
                    int MouseFrameHalf  = (e.X - TimelineStartX + ScrollbarStartIndex + 4) / 8;
                    int MouseEventFrame = (e.X - TimelineStartX + ScrollbarStartIndex) / 8;

                    for (int i = vsbTimeline.Value, VisibleIndex = 0; i < TimelineActiveItems && VisibleIndex < TimelineVisibleItemCount; i++, VisibleIndex++)
                    {
                        if (e.Y < (VisibleIndex + 1) * 20 || e.Y >= (VisibleIndex + 2) * 20)
                        {
                            continue;
                        }

                        Timeline ActiveEvent = GetTimelineEvent(i);
                        ActiveTimelineEvent = ActiveEvent;

                        AnimationObjectKeyFrame ActiveAnimationObjectKeyFrame = null;

                        if (MouseEventFrame == ActiveEvent.SpawnFrame)
                        {
                            TimelineResizeSide = TimelineResizeSides.Left;
                        }
                        else if (MouseFrameHalf == ActiveEvent.DeathFrame)
                        {
                            TimelineResizeSide = TimelineResizeSides.Right;
                        }
                        else if (ActiveEvent.TryGetValue(MouseEventFrame, out ActiveAnimationObjectKeyFrame))
                        {
                            OnKeyFrameSelected(ActiveAnimationObjectKeyFrame);
                            TimelineResizeSide = TimelineResizeSides.MoveKeyFrame;
                        }
                        else if (MouseEventFrame > ActiveEvent.SpawnFrame && MouseEventFrame < ActiveEvent.DeathFrame)
                        {
                            TimelineResizeSide = TimelineResizeSides.All;
                        }
                    }
                }
            }

            #endregion

            #region Right Button

            else if (e.Button == MouseButtons.Right)
            {
                Timeline ActiveEvent;

                if (e.X < TimelineStartX)
                {
                    for (int i = vsbTimeline.Value, VisibleIndex = 0; i < TimelineActiveItems && VisibleIndex < TimelineVisibleItemCount; i++, VisibleIndex++)
                    {
                        ActiveEvent = GetTimelineEvent(i);

                        if (e.Y < (VisibleIndex + 1) * 20 || e.Y >= (VisibleIndex + 2) * 20)
                        {
                            ActiveAnimation.ListSelectedObjects.Remove(ActiveEvent);
                            continue;
                        }

                        ActiveAnimation.ListSelectedObjects.Add(ActiveEvent);
                        ActiveTimelineEvent = ActiveEvent;
                    }
                    DrawTimeline();
                }
                else
                {
                    ActiveKeyFrame = (e.X - TimelineStartX + ScrollbarStartIndex) / 8;

                    for (int i = vsbTimeline.Value, VisibleIndex = 0; i < TimelineActiveItems && VisibleIndex < TimelineVisibleItemCount; i++, VisibleIndex++)
                    {
                        if (e.Y < (VisibleIndex + 1) * 20 || e.Y >= (VisibleIndex + 2) * 20)
                        {
                            continue;
                        }

                        ActiveEvent = GetTimelineEvent(i);

                        ActiveTimelineEvent = ActiveEvent;
                    }
                }
            }

            #endregion
        }