-
Notifications
You must be signed in to change notification settings - Fork 1
/
VideoPanel.cs
122 lines (106 loc) · 4.06 KB
/
VideoPanel.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Drawing;
using System.Windows.Forms;
namespace VideoEditor
{
class VideoPanel
{
public bool enabled = true;
public Button button;
public Label pathLabel = new Label();
public Label timeLabel = new Label();
public VideoFile video;
public string Filename
{
get
{
return video.filename;
}
}
public int Frames
{
get
{
return video.frames;
}
}
private const int BUTTON_SX = 30;
private const int BUTTON_SY = 30;
private const int THUMBNAIL_SX = (int)(MergeWindow.SCREEN_X * 0.26);
private const int THUMBNAIL_SY = (int)(MergeWindow.SCREEN_Y * 0.28);
private const int PATH_LABEL_SX = (int)(THUMBNAIL_SX * 0.68);
private const int PATH_LABEL_SY = THUMBNAIL_SX / 4;
private const int TIME_LABEL_SX = (int)(THUMBNAIL_SX * 0.3);
private const int TIME_LABEL_SY = THUMBNAIL_SX / 4;
private const int PATH_MAXLEN = 18;
public VideoPanel(Form owner, string filename_)
{
video = new VideoFile(filename_);
// ボタン
button = new Button()
{
Text = "X",
Location = new System.Drawing.Point(-100, -100),
Size = new System.Drawing.Size(BUTTON_SX, BUTTON_SY),
};
button.Click += delegate (object sender, EventArgs e)
{
enabled = false;
button.Enabled = false;
button.Visible = false;
pathLabel.Enabled = false;
pathLabel.Visible = false;
timeLabel.Enabled = false;
timeLabel.Visible = false;
};
owner.Controls.Add(button);
// ラベル
pathLabel.Text = (video.filename.Length > PATH_MAXLEN) ?
"..." + video.filename.Substring(video.filename.Length + 3 - PATH_MAXLEN, PATH_MAXLEN - 3) :
video.filename;
pathLabel.Font = new Font(pathLabel.Font.OriginalFontName, 10);
pathLabel.Size = new System.Drawing.Size(PATH_LABEL_SX, PATH_LABEL_SY);
timeLabel.Text = toTimeString();
timeLabel.Font = new Font(timeLabel.Font.OriginalFontName, 12);
timeLabel.Size = new System.Drawing.Size(TIME_LABEL_SX, TIME_LABEL_SY);
owner.Controls.Add(pathLabel);
owner.Controls.Add(timeLabel);
}
public void drawThumbnail(Graphics g, int index, double scrolled)
{
const int scrx = MergeWindow.SCREEN_X;
const int scry = MergeWindow.SCREEN_Y;
double i = index - scrolled;
int imlx = (int)((0.06 + 0.295 * i) * scrx);
const int imly = (int)(0.09 * scry);
const int imsx = THUMBNAIL_SX;
const int imsy = THUMBNAIL_SY;
const int bsx = BUTTON_SX;
const int bsy = BUTTON_SY;
int pllx = imlx;
const int plly = imly + imsy;
int tllx = imlx + imsx - TIME_LABEL_SX;
const int tlly = imly + imsy;
button.Location = new System.Drawing.Point(imlx - bsx / 2, imly - bsy / 2);
g.DrawImage(video.thumbnail, imlx, imly, imsx, imsy);
pathLabel.Location = new System.Drawing.Point(pllx, plly);
timeLabel.Location = new System.Drawing.Point(tllx, tlly);
}
private string toTimeString() // 初期化時に一度だけ呼び出す
{
int iSeconds = (int)video.seconds;
int min = iSeconds / 60;
int sec = iSeconds % 60;
if (min >= 60)
{
int h = min / 60;
min = min % 60;
return string.Format("{0:0}:{1:00}:{2:00}", h, min, sec); // length is 7
}
else
{
return string.Format(" {0:00}:{1:00}", min, sec); // length is 7
}
}
}
}