This repository has been archived by the owner on Jan 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BeatmapTimeline.xaml.cs
93 lines (80 loc) · 2.65 KB
/
BeatmapTimeline.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Media;
namespace ShadowBBR_Editor
{
/// <summary>
/// Interaction logic for BeatmapTimeline.xaml
/// </summary>
public partial class BeatmapTimeline : UserControl
{
List<BeatmapBeat> beats = new List<BeatmapBeat>();
List<BeatmapLabel> labels = new List<BeatmapLabel>();
int width, height, innerHeight, beatAmount;
internal int canvasPixelDistance, elementTop, labelSpacing, labelFrequency;
public double BeatPixelDistance => (double)labelSpacing / labelFrequency;
public BeatmapTimeline(int width, int height)
{
InitializeComponent();
this.width = width;
this.height = height;
border.Width = width;
border.Height = height;
}
/// <summary>
/// Add a beat to the timeline.
/// </summary>
/// <param name="beatNum">The beat number to place it at.</param>
public void AddBeat(int beatNum)
{
BeatmapBeat beat = new BeatmapBeat(this, innerHeight, beatNum);
beats.Add(beat);
canvas.Children.Add(beat);
beat.RefreshPosition();
}
public void Setup(int beatAmount, int labelSpacing, int labelFrequency = 4)
{
//Creates labels for the timeline
BeatmapLabel start = new BeatmapLabel(0);
labels.Add(start);
canvas.Children.Add(start);
int intervalCount = (beatAmount / labelFrequency);
for (int i = 1; i <= intervalCount - 1; i++)
{
BeatmapLabel label = new BeatmapLabel(labelFrequency * i);
labels.Add(label);
canvas.Children.Add(label);
}
BeatmapLabel end = new BeatmapLabel(beatAmount);
labels.Add(end);
canvas.Children.Add(end);
for (int i = 0; i < labels.Count; i++)
{
Canvas.SetLeft(labels[i], labelSpacing * i);
Canvas.SetTop(labels[i], 1);
}
// -- END OF TIMELINE LABELING
Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
Arrange(new System.Windows.Rect(0, 0, width, height));
Border border = new Border
{
BorderThickness = new System.Windows.Thickness(1),
BorderBrush = new SolidColorBrush(Color.FromRgb(20, 22, 24)),
Background = new SolidColorBrush(Color.FromRgb(30, 32, 34))
};
canvas.Children.Add(border);
Canvas.SetTop(border, 1 + start.ActualHeight);
elementTop = 1 + (int)start.ActualHeight + 1;
border.Width = 1 + Canvas.GetLeft(end);
border.Height = height - 46;
innerHeight = height - 46 - 2;
canvasPixelDistance = (int)border.Width - 1;
canvas.Width = (labelSpacing * (labels.Count - 1)) + (int)end.ActualWidth;
//Store values for later reference
this.beatAmount = beatAmount;
this.labelSpacing = labelSpacing;
this.labelFrequency = labelFrequency;
}
}
}