-
Notifications
You must be signed in to change notification settings - Fork 5
/
FrmLyrics.cs
148 lines (126 loc) · 3.95 KB
/
FrmLyrics.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
using System;
using System.Windows.Forms;
using Unmanaged;
namespace MusicBeePlugin
{
public partial class FrmLyrics : Form
{
private SettingsObj _settings;
public FrmLyrics(SettingsObj settings)
{
_settings = settings;
InitializeComponent();
}
private void FrmLyrics_Load(object sender, EventArgs e)
{
// TODO: multi-screen support
var scrBounds = Screen.PrimaryScreen.Bounds;
LyricsRenderer.SetDpi(DeviceDpi);
Width = scrBounds.Width;
Height = 150;
if (_settings.PosY < 0)
{
Top = scrBounds.Height - Height - 150;
Left = 0;
}
else
{
Top = _settings.PosY;
Left = _settings.PosX;
}
TopMost = true;
UnmanagedHelper.SetTopMost(this);
UpdateFromSettings(_settings);
Move += (o, args) =>
{
_settings.PosX = Left;
_settings.PosY = Top;
};
FormClosing += (o, args) =>
{
if (args.CloseReason == CloseReason.UserClosing)
args.Cancel = true;
};
}
public void UpdateFromSettings(SettingsObj settings)
{
_settings = settings;
LyricsRenderer.UpdateFromSettings(settings, Width);
Redraw();
}
private void Redraw()
{
if (_line1 == null)
{
Clear();
return;
}
if (_line2 == null)
{
DrawLyrics1Line(_line1);
return;
}
DrawLyrics2Line(_line1, _line2);
}
public void Clear()
{
if (_line1 != "")
DrawLyrics1Line("");
_line1 = "";
}
private string _line1, _line2;
public void UpdateLyrics(string line1, string line2)
{
_line1 = line1;
_line2 = line2;
Redraw();
}
private void DrawLyrics1Line(string lyrics)
{
using (var g = CreateGraphics())
{
var bitmap = LyricsRenderer.Render1LineLyrics(lyrics, g);
if (bitmap == null)
return;
using (bitmap)
{
if (Width != bitmap.Width) Width = bitmap.Width;
if (Height != bitmap.Height) Height = bitmap.Height;
GdiplusHelper.SetBitmap(bitmap, 255, Handle, Left, Top, Width, Height);
}
}
}
private void DrawLyrics2Line(string line1, string line2)
{
using (var g = CreateGraphics())
{
var bitmap = LyricsRenderer.Render2LineLyrics(line1, line2, g);
if (bitmap == null)
return;
using (bitmap)
{
if (Width != bitmap.Width) Width = bitmap.Width;
if (Height != bitmap.Height) Height = bitmap.Height;
GdiplusHelper.SetBitmap(bitmap, 255, Handle, Left, Top, Width, Height);
}
}
}
private void FrmLyrics_MouseDown(object sender, MouseEventArgs e)
{
if (!Visible) return;
Unmanaged.Unmanaged.ReleaseCapture();
if (e.Button != MouseButtons.Left) return;
Unmanaged.Unmanaged.SendMessage(Handle, 0x00A1, new IntPtr(0x0002), null);
}
protected override CreateParams CreateParams
{
get
{
var cp = base.CreateParams;
cp.ExStyle |= 0x00080000; // WS_EX_LAYERED
cp.ExStyle |= 0x00000080; // WS_EX_TOOLWINDOW
return cp;
}
}
}
}