More timeline fixes
This commit is contained in:
parent
0c5d53ae61
commit
decd83c487
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -122,7 +122,7 @@
|
||||
//
|
||||
// stPanel1
|
||||
//
|
||||
this.stPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
this.stPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.stPanel1.Location = new System.Drawing.Point(0, 0);
|
||||
this.stPanel1.Name = "stPanel1";
|
||||
@ -131,8 +131,8 @@
|
||||
//
|
||||
// animationTrackBar
|
||||
//
|
||||
this.animationTrackBar.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
this.animationTrackBar.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.animationTrackBar.CurrentFrame = 0;
|
||||
this.animationTrackBar.FrameCount = 1000;
|
@ -108,7 +108,7 @@ namespace Switch_Toolbox.Library
|
||||
|
||||
animationTrackBar.BackColor = FormThemes.BaseTheme.FormBackColor;
|
||||
animationTrackBar.ForeColor = FormThemes.BaseTheme.FormForeColor;
|
||||
// animationTrackBar.FrameChanged += new EventHandler(animationTrackBar_ValueChanged);
|
||||
animationTrackBar.FrameChanged += new EventHandler(animationTrackBar_ValueChanged);
|
||||
|
||||
/* animationTrackBar.ThumbInnerColor = FormThemes.BaseTheme.TimelineThumbColor;
|
||||
animationTrackBar.ThumbOuterColor = FormThemes.BaseTheme.TimelineThumbColor;
|
||||
@ -282,9 +282,8 @@ namespace Switch_Toolbox.Library
|
||||
|
||||
}
|
||||
|
||||
private void animationTrackBar_ValueChanged()
|
||||
{
|
||||
|
||||
private void animationTrackBar_ValueChanged(object sender, EventArgs e) {
|
||||
currentFrameUpDown.Value = animationTrackBar.CurrentFrame;
|
||||
}
|
||||
|
||||
private void OnFrameAdvanced()
|
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Switch_Toolbox.Library.Forms
|
||||
{
|
||||
class BoneAnimTimeline : TimeLine
|
||||
{
|
||||
int[] keyFrames = new int[] { 0, 5, 15, 20, 40, 100 };
|
||||
|
||||
protected static int lineHeight = TextRenderer.MeasureText("§", font).Height;
|
||||
|
||||
protected int scrollY = 0;
|
||||
|
||||
protected int trackCount = 30;
|
||||
|
||||
public BoneAnimTimeline()
|
||||
{
|
||||
margin = 100;
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
e.Graphics.FillRectangle(brush3, new Rectangle(0, 0, margin, Height));
|
||||
|
||||
e.Graphics.SetClip(new Rectangle(0, barHeight, Width, Height - barHeight));
|
||||
|
||||
bool v = false;
|
||||
int y = -scrollY;
|
||||
for (int _i = 0; _i < trackCount; _i++)
|
||||
{
|
||||
e.Graphics.DrawString("bone" + _i, font, brush5, new Point(10, barHeight + y));
|
||||
for (int i = 1; i < keyFrames.Length; i++)
|
||||
{
|
||||
int l = Math.Max(-20, (int)((
|
||||
keyFrames[i - 1]
|
||||
- frameLeft) * (Width - 40 - margin) / (frameRight - frameLeft)));
|
||||
int r = (int)((
|
||||
keyFrames[i]
|
||||
- frameLeft) * (Width - 40 - margin) / (frameRight - frameLeft));
|
||||
|
||||
if (v = !v)
|
||||
e.Graphics.FillRectangle(brush5, new Rectangle(l + margin + 20, barHeight + y, r - l, lineHeight));
|
||||
}
|
||||
y += lineHeight;
|
||||
}
|
||||
base.OnPaint(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseWheel(MouseEventArgs e)
|
||||
{
|
||||
if (e.X < margin)
|
||||
{
|
||||
scrollY = Math.Max(Math.Min(trackCount * lineHeight + barHeight - Height, scrollY - e.Delta / 2), 0);
|
||||
Refresh();
|
||||
}
|
||||
else
|
||||
base.OnMouseWheel(e);
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
scrollY = Math.Max(Math.Min(trackCount * lineHeight + barHeight - Height, scrollY), 0);
|
||||
base.OnResize(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -19,22 +19,17 @@ namespace Switch_Toolbox.Library.Forms
|
||||
timer.Tick += Timer_Tick;
|
||||
}
|
||||
|
||||
public void Play() { }
|
||||
public void Stop() { }
|
||||
|
||||
protected int margin = 0;
|
||||
|
||||
public event EventHandler FrameChanged;
|
||||
|
||||
private Timer timer = new Timer();
|
||||
|
||||
public bool Locked { get; private set; } = false;
|
||||
|
||||
public void Play()
|
||||
{
|
||||
Locked = true;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
Locked = false;
|
||||
}
|
||||
|
||||
private void ResolveCollision()
|
||||
{
|
||||
if (frameLeft < 0)
|
||||
@ -69,7 +64,7 @@ namespace Switch_Toolbox.Library.Forms
|
||||
|
||||
public int CurrentFrame
|
||||
{
|
||||
get { return currentFrame; }
|
||||
get => currentFrame;
|
||||
set
|
||||
{
|
||||
if (FollowCurrentFrame && !(Focused && MouseButtons == MouseButtons.Right))
|
||||
@ -90,7 +85,7 @@ namespace Switch_Toolbox.Library.Forms
|
||||
|
||||
public int FrameCount
|
||||
{
|
||||
get { return lastFrame + 1; }
|
||||
get => lastFrame + 1;
|
||||
set
|
||||
{
|
||||
lastFrame = value - 1;
|
||||
@ -114,31 +109,40 @@ namespace Switch_Toolbox.Library.Forms
|
||||
|
||||
public bool FollowCurrentFrame = true;
|
||||
|
||||
private int currentFrame = 0;
|
||||
private int lastFrame = 1000;
|
||||
protected int currentFrame = 0;
|
||||
protected int lastFrame = 1000;
|
||||
|
||||
private double frameLeft = 0;
|
||||
private double frameRight = 200;
|
||||
protected double frameLeft = 0;
|
||||
protected double frameRight = 200;
|
||||
|
||||
private Point lastMousePos;
|
||||
protected Point lastMousePos;
|
||||
|
||||
|
||||
private static Brush brush1 = new SolidBrush(Color.FromArgb(255, 255, 20));
|
||||
private static Brush brush2 = new SolidBrush(Color.FromArgb(20, 20, 20));
|
||||
private static Brush brush3 = new SolidBrush(Color.FromArgb(50, 50, 50));
|
||||
private static Brush brush4 = new SolidBrush(Color.FromArgb(90, 90, 90));
|
||||
private static Pen pen1 = new Pen(new SolidBrush(Color.FromArgb(30, 30, 30)), 2);
|
||||
private static Pen pen2 = new Pen(new SolidBrush(Color.FromArgb(100, 100, 20)), 2);
|
||||
protected static Brush brush1 = new SolidBrush(Color.FromArgb(255, 255, 20));
|
||||
protected static Brush brush2 = new SolidBrush(Color.FromArgb(20, 20, 20));
|
||||
protected static Brush brush3 = new SolidBrush(Color.FromArgb(50, 50, 50));
|
||||
protected static Brush brush4 = new SolidBrush(Color.FromArgb(90, 90, 90));
|
||||
protected static Brush brush5 = new SolidBrush(Color.FromArgb(150, 150, 150));
|
||||
|
||||
private static Font font = new Font(new FontFamily("arial"), 10);
|
||||
protected static Pen pen1 = new Pen(new SolidBrush(Color.FromArgb(30, 30, 30)), 2);
|
||||
protected static Pen pen2 = new Pen(new SolidBrush(Color.FromArgb(100, 100, 20)), 2);
|
||||
protected static Pen pen3 = new Pen(new SolidBrush(Color.FromArgb(150, 150, 150)), 2);
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
protected static Font font = new Font(new FontFamily("arial"), 10);
|
||||
|
||||
protected static int barHeight = TextRenderer.MeasureText("0", font).Height;
|
||||
|
||||
|
||||
protected override void OnPaintBackground(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
double currentFrameX = 20 + (currentFrame - frameLeft) * (Width - 40.0) / (frameRight - frameLeft);
|
||||
|
||||
e.Graphics.SetClip(new Rectangle(margin, 0, Width - margin, Height));
|
||||
|
||||
double currentFrameX = 20 + margin + (currentFrame - frameLeft) * (Width - 40 - margin) / (frameRight - frameLeft);
|
||||
|
||||
e.Graphics.FillRectangle(brush2, new Rectangle(0, 0, Width, Height));
|
||||
e.Graphics.FillRectangle(brush3, new Rectangle(0, 0, Width, TextRenderer.MeasureText("" + currentFrame, font).Height));
|
||||
e.Graphics.FillRectangle(brush3, new Rectangle(0, 0, Width, barHeight));
|
||||
|
||||
double step = 50 * (frameRight - frameLeft) / Width;
|
||||
if (step > 10)
|
||||
@ -158,36 +162,56 @@ namespace Switch_Toolbox.Library.Forms
|
||||
|
||||
for (double frame = Math.Floor(frameLeft / step) * step; frame <= max; frame += step)
|
||||
{
|
||||
double frameX = 20 + (frame - frameLeft) * (Width - 40.0) / (frameRight - frameLeft);
|
||||
double frameX = 20 + margin + (frame - frameLeft) * (Width - 40 - margin) / (frameRight - frameLeft);
|
||||
|
||||
e.Graphics.DrawLine(pen1, new Point((int)frameX, TextRenderer.MeasureText("" + frame, font).Height), new Point((int)frameX, Height));
|
||||
e.Graphics.DrawLine(pen1, new Point((int)frameX, barHeight), new Point((int)frameX, Height));
|
||||
|
||||
e.Graphics.DrawString("" + frame, font, brush4, new Point((int)frameX - TextRenderer.MeasureText("" + frame, font).Width / 2, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (frameRight == lastFrame)
|
||||
{
|
||||
//draw last frame regardless of the steps
|
||||
double x = Width - 20;
|
||||
|
||||
e.Graphics.DrawLine(pen1, new Point((int)x, TextRenderer.MeasureText("" + lastFrame, font).Height), new Point((int)x, Height));
|
||||
e.Graphics.DrawLine(pen1, new Point((int)x, barHeight), new Point((int)x, Height));
|
||||
|
||||
e.Graphics.DrawString("" + lastFrame, font, brush4, new Point((int)x - TextRenderer.MeasureText("" + lastFrame, font).Width / 2, 0));
|
||||
}
|
||||
/*
|
||||
int lastY = value((int)(Math.Round(- 20+margin * (frameRight - frameLeft) / (Width - 40-margin) + frameLeft) + lastFrame + 1) % (lastFrame + 1));
|
||||
for (int x = 5; x < Width+10; x+=5)
|
||||
{
|
||||
e.Graphics.DrawLine(pen3, x - 5, lastY, x, lastY =
|
||||
value((int)(Math.Round((x - 20+margin) * (frameRight - frameLeft) / (Width - 40-margin) + frameLeft) + lastFrame + 1) % (lastFrame + 1))
|
||||
);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
e.Graphics.DrawLine(pen2, new Point((int)currentFrameX, TextRenderer.MeasureText("" + currentFrame, font).Height), new Point((int)currentFrameX, Height));
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
e.Graphics.SetClip(new Rectangle(margin, 0, Width - margin, Height));
|
||||
|
||||
double currentFrameX = 20 + margin + (currentFrame - frameLeft) * (Width - 40 - margin) / (frameRight - frameLeft);
|
||||
base.OnPaint(e);
|
||||
e.Graphics.DrawLine(pen2, new Point((int)currentFrameX, barHeight), new Point((int)currentFrameX, Height));
|
||||
|
||||
e.Graphics.DrawString("" + currentFrame, font, brush1, new Point((int)currentFrameX - TextRenderer.MeasureText("" + currentFrame, font).Width / 2, 0));
|
||||
}
|
||||
|
||||
private int value(int frame)
|
||||
{
|
||||
return frame + 30;
|
||||
}
|
||||
|
||||
private void Timer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
double step;
|
||||
if (lastMousePos.X < 20)
|
||||
if (lastMousePos.X < 20 + margin)
|
||||
{
|
||||
step = (20 - lastMousePos.X) * (frameRight - frameLeft) / Width;
|
||||
step = (20 + margin - lastMousePos.X) * (frameRight - frameLeft) / Width;
|
||||
frameLeft -= step;
|
||||
frameRight -= step;
|
||||
|
||||
@ -214,7 +238,7 @@ namespace Switch_Toolbox.Library.Forms
|
||||
#endregion
|
||||
}
|
||||
|
||||
currentFrame = Math.Min(Math.Max(0, (int)Math.Round(((lastMousePos.X - 20) * (frameRight - frameLeft) / (Width - 40.0) + frameLeft))), lastFrame);
|
||||
currentFrame = Math.Min(Math.Max(0, (int)Math.Round(((lastMousePos.X - 20 - margin) * (frameRight - frameLeft) / (Width - 40 - margin) + frameLeft))), lastFrame);
|
||||
FrameChanged?.Invoke(this, new EventArgs());
|
||||
Refresh();
|
||||
}
|
||||
@ -228,15 +252,15 @@ namespace Switch_Toolbox.Library.Forms
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
|
||||
timer.Enabled = (e.X < 20 || e.X > Width - 20);
|
||||
timer.Enabled = (e.X < 20 + margin || e.X > Width - 20);
|
||||
Locked = true;
|
||||
currentFrame = Math.Min(Math.Max(0, (int)Math.Round(((e.X - 20) * (frameRight - frameLeft) / (Width - 40.0) + frameLeft))), lastFrame);
|
||||
currentFrame = Math.Min(Math.Max(0, (int)Math.Round(((e.X - 20 - margin) * (frameRight - frameLeft) / (Width - 40 - margin) + frameLeft))), lastFrame);
|
||||
FrameChanged?.Invoke(this, new EventArgs());
|
||||
Refresh();
|
||||
}
|
||||
else if (e.Button == MouseButtons.Right)
|
||||
{
|
||||
double delta = (e.X - lastMousePos.X) * (frameRight - frameLeft) / (Width - 40.0);
|
||||
double delta = (e.X - lastMousePos.X) * (frameRight - frameLeft) / (Width - 40 - margin);
|
||||
frameLeft -= delta;
|
||||
frameRight -= delta;
|
||||
|
||||
@ -266,7 +290,7 @@ namespace Switch_Toolbox.Library.Forms
|
||||
|
||||
double delta = 1 + Math.Min(Math.Max(-0.5, -e.Delta * 0.00390625), 0.5);
|
||||
|
||||
double frameOrigin = Math.Min(Math.Max(0, ((e.X - 20) * (frameRight - frameLeft) / (Width - 40.0) + frameLeft)), lastFrame);
|
||||
double frameOrigin = Math.Min(Math.Max(0, ((e.X - 20 - margin) * (frameRight - frameLeft) / (Width - 40 - margin) + frameLeft)), lastFrame);
|
||||
|
||||
frameLeft = Math.Min(-1, (frameLeft - frameOrigin)) * delta + frameOrigin;
|
||||
frameRight = Math.Max(1, (frameRight - frameOrigin)) * delta + frameOrigin;
|
@ -212,6 +212,9 @@
|
||||
<Compile Include="Forms\BatchFormatExport.Designer.cs">
|
||||
<DependentUpon>BatchFormatExport.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\Editors\Animation\BoneAnimTimeline.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Forms\Custom\DropdownPanel\ExpandCollapseEventArgs.cs" />
|
||||
<Compile Include="Forms\Custom\DropdownPanel\STCollapsePanelButton.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
@ -373,10 +376,10 @@
|
||||
<Compile Include="Forms\Editors\TextEditor\TextEditorForm.Designer.cs">
|
||||
<DependentUpon>TextEditorForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\Editors\TimeLine.cs">
|
||||
<Compile Include="Forms\Editors\Animation\TimeLine.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Forms\Editors\TimeLine.Designer.cs">
|
||||
<Compile Include="Forms\Editors\Animation\TimeLine.Designer.cs">
|
||||
<DependentUpon>TimeLine.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\Extensions\MDICustom.cs" />
|
||||
@ -506,10 +509,10 @@
|
||||
<Compile Include="IO\StringExtension.cs" />
|
||||
<Compile Include="IO\STStream.cs" />
|
||||
<Compile Include="Plugin\GenericPluginLoader.cs" />
|
||||
<Compile Include="Forms\Editors\AnimationPanel.cs">
|
||||
<Compile Include="Forms\Editors\Animation\AnimationPanel.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Forms\Editors\AnimationPanel.Designer.cs">
|
||||
<Compile Include="Forms\Editors\Animation\AnimationPanel.Designer.cs">
|
||||
<DependentUpon>AnimationPanel.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\Editors\AssimpMeshSelector.cs">
|
||||
@ -635,7 +638,7 @@
|
||||
<EmbeddedResource Include="Forms\Dialogs\STErrorDialog.resx">
|
||||
<DependentUpon>STErrorDialog.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\Editors\AnimationPanel.resx">
|
||||
<EmbeddedResource Include="Forms\Editors\Animation\AnimationPanel.resx">
|
||||
<DependentUpon>AnimationPanel.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\Editors\Assimp Settings.resx">
|
||||
@ -701,7 +704,7 @@
|
||||
<EmbeddedResource Include="Forms\Editors\TextEditor\TextEditorForm.resx">
|
||||
<DependentUpon>TextEditorForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\Editors\TimeLine.resx">
|
||||
<EmbeddedResource Include="Forms\Editors\Animation\TimeLine.resx">
|
||||
<DependentUpon>TimeLine.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\Editors\TransformMeshTool.resx">
|
||||
|
Loading…
x
Reference in New Issue
Block a user