Пример #1
0
        public void SaveToXml(System.Xml.XmlTextWriter xmlWriter, Dictionary <string, VisibleKey> selectedKeys, AnimationTarget target, int parameterIndex)
        {
            bool anythingToWrite = false;

            foreach (Key key in Keys.Values)
            {
                if (selectedKeys.ContainsKey(VisibleKey.GetIndexKey(target, parameterIndex, key.Time)))
                {
                    anythingToWrite = true;
                }
            }

            if (anythingToWrite)
            {
                xmlWriter.WriteStartElement("Keys");
                xmlWriter.WriteAttributeString("ParameterName", ParameterName.ToString());
                foreach (Key key in Keys.Values)
                {
                    if (selectedKeys.ContainsKey(VisibleKey.GetIndexKey(target, parameterIndex, key.Time)))
                    {
                        key.SaveToXml(xmlWriter);
                    }
                }
                xmlWriter.WriteEndElement();
            }
        }
Пример #2
0
 private void DeleteKey(VisibleKey vk)
 {
     AnimationTarget target = null;
     target = vk.Target;
     if (target != null)
     {
         var index = vk.ParameterIndex;
         target.DeleteKey(index, vk.Time);
     }
 }
Пример #3
0
        private void TimeLine_Paint(object sender, PaintEventArgs e)
        {
            if (!DesignMode)
            {
                if (Earth3d.MainWindow != null && Earth3d.MainWindow.TourEdit != null && Earth3d.MainWindow.TourEdit.Tour != null)
                {
                    Tour = Earth3d.MainWindow.TourEdit.Tour;
                }
                else
                {
                    Tour = null;
                }
            }

            var g = e.Graphics;
            var p = new Pen(Color.FromArgb(71, 84, 108));

            offset = left - (int)((ScrollPos / (scrollbarWidth / (double)(Width - left))) % pixelsPerSecond);

            if (Tour != null && Tour.CurrentTourStop != null)
            {
                slideTime = Tour.CurrentTourStop.Duration.TotalSeconds;
                currentTween = Tour.CurrentTourStop.TweenPosition;
            }

            totalFrames = (int)(slideTime * 30);
            frameTime = 1.0 / totalFrames;
            lastKeyTime = 1;// -frameTime;

            pixelsPerSecond = 30 * tick;
            totalPixelWith = (int)(pixelsPerSecond * slideTime);
            secondsOnscreen = (Width - left) / (double)pixelsPerSecond;
            ScrollPos = (int)Math.Max(0, Math.Min(ScrollPos, (slideTime * pixelsPerSecond - secondsOnscreen * pixelsPerSecond)));
            scrollbarWidth = (int)((Width - left) * Math.Min(1, (secondsOnscreen / slideTime)));
            scrollbarStart = ScrollPos + left;
            startSecond = (int)((ScrollPos / (scrollbarWidth / (double)(Width - left))) / pixelsPerSecond);

            var background = new SolidBrush(Color.FromArgb(40, 44, 60));
            var darkBackground = new SolidBrush(BackColor);
            var lightBackground = new SolidBrush(Color.FromArgb(30, 33, 46));
            g.FillRectangle(background, new Rectangle(0, 0, Width, bottom));

            var buttons = new Rectangle(-3,-3, left+5,37);

            var buttonsOnly = buttons.Contains(e.ClipRectangle);

            if (!buttonsOnly)
            {

                for (var y = bottom + lineHeight * 3; y < Height; y += lineHeight * 6)
                {
                    g.FillRectangle(lightBackground, new Rectangle(left, y, Width - left, lineHeight * 3));
                }

                step = (tick > 7) ? tick : (tick > 3) ? (tick * 2) : (tick * 5);
                var endPos = Math.Min(Width - offset, totalPixelWith) + step;

                for (var x = 0; x < endPos; x += step)
                {
                    var big = (x % (5 * step)) == 0;

                    //g.DrawLine(Pens.White, x, big ? 15 : 20, x, bottom);

                    if (big)
                    {
                        g.DrawLine(Pens.DarkGray, x + offset, bottom, x + offset, Height);
                        g.DrawLine(Pens.LightGray, x + offset, 15, x + offset, bottom);
                    }
                    else
                    {
                        g.DrawLine(Pens.Gray, x + offset, bottom, x + offset, Height);
                        g.DrawLine(Pens.LightGray, x + offset, 20, x + offset, bottom);
                    }
                }

                var ts = new TimeSpan(0, 0, startSecond);
                var inc = new TimeSpan(0, 0, 1);

                for (var x = 0; x < endPos; x += (30 * tick))
                {
                    g.DrawString(string.Format("{0:0#}:{1:0#}", ts.Minutes, ts.Seconds), UiTools.StandardRegular, UiTools.StadardTextBrush, new PointF((x + offset) + 1, 2));
                    g.DrawLine(Pens.White, x + offset, 0, x + offset, Height);
                    ts = ts.Add(inc);
                }
                if (tick > 3)
                {
                    for (var x = 0; x < endPos; x += (5 * step))
                    {
                        var mark = (x / tick) % 30;

                        if (mark != 0)
                        {

                            g.DrawString(string.Format("{0}", mark), UiTools.StandardSmall, UiTools.StadardTextBrush, new PointF((x + offset) - ((mark < 10) ? 4 : 7), 2));
                        }
                    }
                }

                nextLine = -startLine;

                var indent = 2;

                var displayLine = false;
                totalLines = 0;

                displayLines = (Height - bottom) / lineHeight;

                lineIds = new string[displayLines];

                g.FillRectangle(background, new Rectangle(0, 0, left, bottom));
                g.FillRectangle(darkBackground, new Rectangle(0, bottom, left, (Height - bottom)));

                if (nextLine >= 0)
                {
                    displayLine = true;
                }

                var selected = false;

                var displayedLineIndex = 0;

                VisibleKeys.Clear();

                for (var y = bottom + lineHeight * 3; y < Height; y += lineHeight * 6)
                {
                    g.FillRectangle(lightBackground, new Rectangle(0, y, left, lineHeight * 3));
                }

                // Draw Text
                if (Tour != null && tour.CurrentTourStop != null && tour.CurrentTourStop.KeyFramed)
                {
                    foreach (var target in tour.CurrentTourStop.AnimationTargets)
                    {
                        if (target.Target == null)
                        {
                            continue;
                        }
                        var name = target.Target.GetName();
                        var targetID = target.Target.GetIndentifier();
                        if (displayLine)
                        {
                            selected = Selection.Contains(targetID);
                            g.DrawString((target.Expanded ? "-   " : "+  ") + name, UiTools.StandardRegular, selected ? UiTools.YellowTextBrush : UiTools.StadardTextBrush, new PointF(indent, nextLine * lineHeight + bottom + 2));
                            lineIds[displayedLineIndex] = targetID;
                            displayedLineIndex++;
                        }
                        indent += 20;

                        if (target.Expanded)
                        {
                            nextLine++;
                            totalLines++;

                            if (nextLine * lineHeight + bottom + 2 + 16 > Height)
                            {
                                displayLine = false;
                            }
                            else
                            {
                                if (nextLine >= 0)
                                {
                                    displayLine = true;
                                }
                            }
                        }

                        for (var i = 0; i < target.ParameterNames.Count; i++)
                        {
                            var line = target.ParameterNames[i];
                            if (displayLine)
                            {
                                if (target.Expanded)
                                {
                                    var id = targetID + "\t" + line;
                                    selected = Selection.Contains(id);
                                    g.DrawString(line, UiTools.StandardRegular, selected ? UiTools.YellowTextBrush : UiTools.StadardTextBrush, new PointF(indent, nextLine * lineHeight + bottom + 2));
                                    lineIds[displayedLineIndex] = id;
                                    displayedLineIndex++;
                                }
                                foreach (var key in target.KeyFrames[i].Keys.Values)
                                {
                                    var keySelected = selectedKeys.ContainsKey(VisibleKey.GetIndexKey(target, i, key.Time));
                                    var xx = 0;

                                    if (ghostingSelection && keySelected)
                                    {
                                        xx = TimeToPixel(key.GhostTime);
                                    }
                                    else
                                    {
                                        xx = TimeToPixel(key.Time);
                                    }

                                    if (xx >= left && xx < Width + (step / 2))
                                    {
                                        var yy = nextLine * lineHeight + bottom + 2;
                                        var vk = new VisibleKey(target, i, line, key.Time, new Point(xx, yy));
                                        VisibleKeys.Add(vk);

                                        g.FillRectangle(keySelected ? UiTools.YellowTextBrush : UiTools.StadardTextBrush, new Rectangle(xx - (step / 2), yy, step, 10));
                                    }
                                }
                            }

                            if (target.Expanded)
                            {
                                nextLine++;
                                totalLines++;
                                if (nextLine * lineHeight + bottom + 2 + 16 > Height)
                                {
                                    displayLine = false;
                                }
                                else
                                {
                                    if (nextLine >= 0)
                                    {
                                        displayLine = true;
                                    }
                                }
                            }

                        }

                        if (!target.Expanded)
                        {
                            nextLine++;
                            totalLines++;

                            if (nextLine * lineHeight + bottom + 2 + 16 > Height)
                            {
                                displayLine = false;
                            }
                            else
                            {
                                if (nextLine >= 0)
                                {
                                    displayLine = true;
                                }
                            }
                        }

                        indent -= 20;

                    }

                    vScrollBarShown = false;
                    //Draw vertical scrollbar
                    if (displayLine == false)
                    {
                        Brush scrollBar = new SolidBrush(Color.FromArgb(112, 140, 186));
                        var scrollBarOutline = new Pen(scrollBar);
                        g.FillRectangle(background, new Rectangle(left - 20, bottom, 20, (Height - bottom)));

                        vScrollBarShown = true;

                        vScrollBarHieght = ((Height - bottom) * displayLines) / totalLines;
                        vScrollBarTop = ((Height - bottom) * startLine) / totalLines;
                        g.FillRectangle(scrollBar, new Rectangle(left - 20, vScrollBarTop + bottom, 20, vScrollBarHieght));

                        g.DrawLine(scrollBarOutline, left - 20, bottom, left - 20, Height);

                        scrollBarOutline.Dispose();
                        scrollBar.Dispose();
                    }
                    else
                    {
                        if (startLine != 0)
                        {
                            startLine = 0;
                            Invalidate();
                        }
                    }

                    // Draw time location
                    var tx = TimeToPixel(TweenPosition) - (step / 2);
                    if (tx >= (left - (step / 2)))
                    {
                        g.DrawLine(Pens.Yellow, tx, bottom, tx, Height - 8);
                        g.DrawLine(Pens.Yellow, tx + step, bottom, tx + step, Height - 8);
                        g.FillPolygon(UiTools.YellowTextBrush, new[] { new Point(tx - (step / 2), bottom - 8), new Point((int)(tx + (step * 1.5)), bottom - 8), new Point(tx + (step / 2), bottom) });
                    }

                    //Key Selection Rect
                    if (selectingKeys)
                    {
                        g.DrawRectangle(Pens.Yellow, selectRect);
                    }

                }
                else
                {
                    startLine = 0;
                }

                // Edge effect
                g.DrawRectangle(p, new Rectangle(0, 0, Width - 1, Height - 1));

                // Draw scrollbar
                g.DrawImageUnscaled(bmpScrollBackLeft, left, Height - 7);
                for (var j = left; j < Width - 10; j += 50)
                {
                    g.DrawImageUnscaled(bmpScrollBackMiddle, j, Height - 7);
                }
                g.DrawImageUnscaled(bmpScrollBackRight, Width - 10, Height - 7);

                g.DrawImageUnscaled(bmpScrollBarLeft, scrollbarStart, Height - 6);
                for (var j = scrollbarStart + 10; j < (scrollbarWidth + scrollbarStart) - 10; j += 50)
                {
                    g.DrawImageUnscaledAndClipped(bmpScrollBarMiddle, new Rectangle(j, Height - 6, Math.Min(50, ((scrollbarWidth + scrollbarStart) - j) - 10), 6));
                }
                g.DrawImageUnscaled(bmpScrollBarRight, (scrollbarStart + scrollbarWidth) - 10, Height - 6);

            }
            else
            {
                // Edge effect
                g.DrawRectangle(p, new Rectangle(0, 0, Width - 1, Height - 1));
            }

            AddKey.Enabled = Selection.Count > 0;
            DelKey.Enabled = selectedKeys.Count > 0;

            lightBackground.Dispose();
            darkBackground.Dispose();
            background.Dispose();
            p.Dispose();
        }
Пример #4
0
        private void SelectColumnKeys()
        {
            selectedKeys.Clear();

            if (Tour != null && tour.CurrentTourStop != null)
            {
                foreach (var target in tour.CurrentTourStop.AnimationTargets)
                {
                    for (var i = 0; i < target.ParameterNames.Count; i++)
                    {
                        foreach (var key in target.KeyFrames[i].Keys.Values)
                        {
                            if (KeyGroup.Quant(key.Time) == KeyGroup.Quant(TweenPosition))
                            {
                                var vk = new VisibleKey(target, i, target.ParameterNames[i], key.Time, new Point(0, 0));

                                selectedKeys.Add(vk.IndexKey, vk);
                            }
                        }
                    }
                }
            }
            KeyProperties.ShowProperties(selectedKeys);
            Invalidate();
        }
Пример #5
0
        private void LoadTypeCombo()
        {
            initializing = true;
            keyType.Items.Clear();

            int selectedIndex = 0;

            VisibleKey vKey = null;
            Key        key  = null;

            sameTimes  = IsHomogeneousTime();
            sameValues = IsHomogeneousValue();



            Time.ReadOnly         = !sameTimes;
            CurrentValue.ReadOnly = !sameValues;

            if (this.propTime == 0)
            {
                Time.ReadOnly = true;
            }

            if (keys != null && keys.Values.Count > 0)
            {
                vKey                   = keys.Values.First();
                key                    = vKey.Target.GetKey(vKey.ParameterIndex, vKey.Time);
                curveEditor1.P1        = key.P1;
                curveEditor1.P2        = key.P2;
                curveEditor1.P3        = key.P3;
                curveEditor1.P4        = key.P4;
                curveEditor1.CurveType = key.InFunction;
                curveEditor1.Invalidate();

                if (sameValues)
                {
                    propValue         = key.Value;
                    CurrentValue.Text = key.Value.ToString();
                    ValueLabel.Text   = vKey.PropertyName;
                }
                else
                {
                    CurrentValue.Text = Language.GetLocalizedText(1351, "Multiple");
                    ValueLabel.Text   = Language.GetLocalizedText(668, "Value");
                }

                if (sameTimes)
                {
                    Time.Text = FormatTime(key.Time);
                    propTime  = key.Time;
                }
                else
                {
                    Time.Text = Language.GetLocalizedText(1351, "Multiple");
                }
            }

            string selected = "";


            if (key != null)
            {
                selected = key.InFunction.ToString();
            }

            foreach (string name in Enum.GetNames(typeof(Key.KeyType)))
            {
                int index = keyType.Items.Add(name);
                if (name == selected)
                {
                    selectedIndex = index;
                }
            }

            keyType.SelectedIndex = selectedIndex;
            initializing          = false;
            dirtyEdit             = false;
        }
        private void SelectAllKeys()
        {
            this.selectedKeys.Clear();

            if (Tour != null && tour.CurrentTourStop != null)
            {
                foreach (AnimationTarget target in tour.CurrentTourStop.AnimationTargets)
                {
                    for (int i = 0; i < target.ParameterNames.Count; i++)
                    {
                        foreach (Key key in target.KeyFrames[i].Keys.Values)
                        {
                            VisibleKey vk = new VisibleKey(target, i, target.ParameterNames[i], key.Time, new Point(0, 0));
                            selectedKeys.Add(vk.IndexKey, vk);
                        }
                    }
                }
            }
            KeyProperties.ShowProperties(selectedKeys);
            Invalidate();
        }