Skip to content

Commit

Permalink
rewrite the position remembering
Browse files Browse the repository at this point in the history
  • Loading branch information
cqjjjzr committed Dec 24, 2021
1 parent c5e4f8d commit 6d8edd1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
9 changes: 5 additions & 4 deletions DesktopLyrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public bool Configure(IntPtr panelHandle)
{
var settingsForm = new FrmSettings(_settings);
settingsForm.ShowDialog();
_settings = settingsForm.Settings;
SaveSettings(_settings);
_frmLyrics?.UpdateFromSettings(_settings);
LyricParser.PreserveSlash = _settings.PreserveSlash;
Expand All @@ -93,11 +92,13 @@ public void SaveSettings()
public void Close(PluginCloseReason reason)
{
_timer.Stop();
Control.FromHandle(_mbApiInterface.MB_GetWindowHandle()).Invoke(new Action(() =>
var ctrl = Control.FromHandle(_mbApiInterface.MB_GetWindowHandle());
_frmLyrics?.Invoke(new Action(() =>
{
_frmLyrics?.Dispose();
_frmLyrics = null;
}));
SaveSettings(_settings);
}

public void Uninstall()
Expand All @@ -113,7 +114,7 @@ public void ReceiveNotification(string sourceFileUrl, NotificationType type)
switch (type)
{
case NotificationType.PluginStartup:
// while (!Debugger.IsAttached) Thread.Sleep(1);
while (!Debugger.IsAttached) System.Threading.Thread.Sleep(1);
try
{
try
Expand Down Expand Up @@ -195,7 +196,7 @@ private void StartupForm()
var f = (Form)Control.FromHandle(_mbApiInterface.MB_GetWindowHandle());
f.Invoke(new Action(() =>
{
_frmLyrics = new FrmLyrics(_settings, SettingsPath2);
_frmLyrics = new FrmLyrics(_settings);
_frmLyrics.Show();
}));
}
Expand Down
1 change: 0 additions & 1 deletion FrmLyrics.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 17 additions & 20 deletions FrmLyrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ namespace MusicBeePlugin
{
public partial class FrmLyrics : Form
{
private readonly SettingsObj _startupSettings;
private readonly string _path;
public FrmLyrics(SettingsObj settings, string path)
private SettingsObj _settings;
public FrmLyrics(SettingsObj settings)
{
_path = path;
_startupSettings = settings;
_settings = settings;

InitializeComponent();
}
Expand All @@ -22,26 +20,32 @@ private void FrmLyrics_Load(object sender, EventArgs e)
var scrBounds = Screen.PrimaryScreen.Bounds;
Width = scrBounds.Width;
Height = 150;
try
{
var coord = File.ReadAllText(_path).Split(' ');
Left = int.Parse(coord[0]);
Top = int.Parse(coord[1]);
}
catch (Exception)
if (_settings.PosY < 0)
{
Top = scrBounds.Height - Height - 150;
Left = 0;
}
else
{
Top = _settings.PosY;
Left = _settings.PosX;
}

TopMost = true;

UnmanagedHelper.SetTopMost(this);
UpdateFromSettings(_startupSettings);
UpdateFromSettings(_settings);

Move += (o, args) =>
{
_settings.PosX = Left;
_settings.PosY = Top;
};
}

public void UpdateFromSettings(SettingsObj settings)
{
_settings = settings;
LyricsRenderer.UpdateFromSettings(settings, Width);

Redraw();
Expand Down Expand Up @@ -109,20 +113,13 @@ private void FrmLyrics_MouseDown(object sender, MouseEventArgs e)
}
}

private void FrmLyrics_Move(object sender, EventArgs e)
{
File.WriteAllText(_path, $@"{Left} {Top}");
}

private void FrmLyrics_MouseUp(object sender, MouseEventArgs e)
{
// This event is never fired...?
//if (e.Button != MouseButtons.Left) return;
//global::Unmanaged.Unmanaged.SendMessage(Handle, 0x00A2, new IntPtr(0x0002), null);
}



protected override CreateParams CreateParams
{
get
Expand Down
4 changes: 3 additions & 1 deletion FrmSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ public class SettingsObj
public bool PreserveSlash = false;
public bool AutoHide = false;
public bool HideOnStartup = false;

public int PosY = -1;
public int PosX = -1;

[JsonIgnore]
public Font FontActual
{
Expand Down
2 changes: 1 addition & 1 deletion TestMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void Main2(string[] args)
Color2 = Color.LightGray,
FontActual = new Font(new FontFamily("Microsoft Yahei"), 34.0f, FontStyle.Regular, GraphicsUnit.Point),
GradientType = 1
}, "x.set"));
}));
}
}
}

0 comments on commit 6d8edd1

Please sign in to comment.