superstar_v2/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.HandwritingSearch.cs

247 lines
10 KiB
C#
Raw Normal View History

2025-04-07 16:54:10 +08:00
using System.IO;
using Microsoft.Ink;
namespace DualScreenDemo
{
public partial class PrimaryForm
{
private PictureBox pictureBoxHandWritingSongs;
private Button refillButtonHandWritingSongs;
private Button clearButtonHandWritingSongs;
private Button closeButtonForSongs;
private Panel handWritingPanelForSongs;
private InkOverlay inkOverlayForSongs;
private RichTextBox handwritingInputBoxForSongs;
private ListBox candidateListBoxForSongs;
private void InitializeHandWritingForSongs()
{
InitializeHandWritingPanelForSongs();
InitializeInkOverlayForSongs();
InitializeHandwritingInputBoxForSongs();
InitializeCandidateListBoxForSongs();
InitializeBtnsHandwritingSongs();
2025-04-07 16:54:10 +08:00
}
2025-04-07 16:54:10 +08:00
private void InitializeHandWritingPanelForSongs()
{
handWritingPanelForSongs = new Panel
{
BorderStyle = BorderStyle.FixedSingle,
BackColor = Color.WhiteSmoke,
Visible = false
2025-04-07 16:54:10 +08:00
};
ResizeAndPositionControl(handWritingPanelForSongs, 20, 89, 650, 260);
2025-04-07 16:54:10 +08:00
pictureBoxHandWritingSongs.Controls.Add(handWritingPanelForSongs);
2025-04-07 16:54:10 +08:00
}
private void InitializeInkOverlayForSongs()
{
try
{
inkOverlayForSongs = new InkOverlay(handWritingPanelForSongs);
inkOverlayForSongs.Enabled = false;
inkOverlayForSongs.Ink = new Ink();
inkOverlayForSongs.DefaultDrawingAttributes.Color = Color.Black;
inkOverlayForSongs.DefaultDrawingAttributes.Width = 100;
inkOverlayForSongs.Stroke += new InkCollectorStrokeEventHandler(InkOverlayForSongs_Stroke);
inkOverlayForSongs.Enabled = true;
}
catch (Exception ex)
{
Console.WriteLine("Failed to initialize ink overlay for singers: " + ex.Message);
}
}
private void InkOverlayForSongs_Stroke(object sender, InkCollectorStrokeEventArgs e)
{
2025-04-07 16:54:10 +08:00
RecognizeInk(inkOverlayForSongs, candidateListBoxForSongs);
}
private void InitializeHandwritingInputBoxForSongs()
{
2025-04-07 16:54:10 +08:00
handwritingInputBoxForSongs = new RichTextBox
{
Font = new Font("微軟正黑體", (float)26 / 900 * Screen.PrimaryScreen.Bounds.Height, FontStyle.Regular),
2025-04-07 16:54:10 +08:00
Visible = false
};
ResizeAndPositionControl(handwritingInputBoxForSongs, 20, 12, 541, 64);
pictureBoxHandWritingSongs.Controls.Add(handwritingInputBoxForSongs);
}
2025-04-07 16:54:10 +08:00
private void InitializeCandidateListBoxForSongs()
{
2025-04-07 16:54:10 +08:00
candidateListBoxForSongs = new ListBox
{
Font = new Font("微軟正黑體", (float)26 / 900 * Screen.PrimaryScreen.Bounds.Height, FontStyle.Regular),
Visible = false
};
ResizeAndPositionControl(candidateListBoxForSongs, 675, 81, 115, 270);
2025-04-07 16:54:10 +08:00
candidateListBoxForSongs.SelectedIndexChanged += CandidateListBoxForSongs_SelectedIndexChanged;
pictureBoxHandWritingSongs.Controls.Add(candidateListBoxForSongs);
2025-04-07 16:54:10 +08:00
}
private void CandidateListBoxForSongs_SelectedIndexChanged(object sender, EventArgs e)
{
if (candidateListBoxForSongs.SelectedIndex != -1)
{
string selectedWord = candidateListBoxForSongs.SelectedItem.ToString();
handwritingInputBoxForSongs.Text += selectedWord;
candidateListBoxForSongs.Visible = false;
2025-04-07 16:54:10 +08:00
if (inkOverlayForSongs != null)
{
inkOverlayForSongs.Ink.DeleteStrokes();
handWritingPanelForSongs.Invalidate();
2025-04-07 16:54:10 +08:00
}
}
}
private void ShowImageOnPictureBoxHandWritingSongs(string imagePath)
{
Bitmap originalImage = new Bitmap(imagePath);
pictureBoxHandWritingSongs.Image = originalImage;
ResizeAndPositionPictureBox(pictureBoxHandWritingSongs, 388, 355, 810, 360);
2025-04-07 16:54:10 +08:00
pictureBoxHandWritingSongs.Visible = true;
}
private void SetHandWritingForSongsAndButtonsVisibility(bool isVisible)
{
EnableDoubleBuffering(handWritingPanelForSongs);
EnableDoubleBuffering(handwritingInputBoxForSongs);
EnableDoubleBuffering(candidateListBoxForSongs);
EnableDoubleBuffering(pictureBoxHandWritingSongs);
EnableDoubleBuffering(refillButtonHandWritingSongs);
EnableDoubleBuffering(clearButtonHandWritingSongs);
EnableDoubleBuffering(closeButtonForSongs);
if (isVisible)SetUIVisible(pictureBoxHandWritingSongs);
else CloseUI(pictureBoxHandWritingSongs);
2025-04-07 16:54:10 +08:00
}
private void InitializeBtnsHandwritingSongs()
2025-04-07 16:54:10 +08:00
{
var data = LoadBtnConfigData();
2025-04-07 16:54:10 +08:00
refillButtonHandWritingSongs = new Button
{
Name = "refillButtonHandWritingSongs",
};
ConfigureButton(refillButtonHandWritingSongs, 565, 12, 72, 66,
new Bitmap(Path.Combine(serverPath, data["RefillButtonImagesHandWriting"]["normal"])),
new Bitmap(Path.Combine(serverPath, data["RefillButtonImagesHandWriting"]["mouseOver"])),
new Bitmap(Path.Combine(serverPath, data["RefillButtonImagesHandWriting"]["mouseDown"])),
RefillButtonHandWritingSongs_Click);
pictureBoxHandWritingSongs.Controls.Add(refillButtonHandWritingSongs);
clearButtonHandWritingSongs = new Button
{
Name = "clearButtonHandWritingSongs",
};
ConfigureButton(clearButtonHandWritingSongs, 642, 11, 72, 66,
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesHandWriting"]["normal"])),
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesHandWriting"]["mouseOver"])),
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesHandWriting"]["mouseDown"])),
ClearButtonHandWritingSongs_Click);
pictureBoxHandWritingSongs.Controls.Add(clearButtonHandWritingSongs);
2025-04-07 16:54:10 +08:00
closeButtonForSongs = new Button
{
Name = "closeButtonForSongs",
};
ConfigureButton(closeButtonForSongs, 719, 11, 72, 66,
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesHandWriting"]["normal"])),
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesHandWriting"]["mouseOver"])),
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesHandWriting"]["mouseDown"])),
CloseButtonForSongs_Click);
pictureBoxHandWritingSongs.Controls.Add(closeButtonForSongs);
}
#region
private void HandWritingSearchButtonForSongs_Click(object sender, EventArgs e)
2025-04-07 16:54:10 +08:00
{
this.SuspendLayout();
zhuyinSearchSongButton.BackgroundImage = zhuyinSearchSongNormalBackground;
englishSearchSongButton.BackgroundImage = englishSearchSongNormalBackground;
pinyinSearchSongButton.BackgroundImage = pinyinSearchSongNormalBackground;
wordCountSearchSongButton.BackgroundImage = wordCountSearchSongNormalBackground;
handWritingSearchSongButton.BackgroundImage = handWritingSearchSongActiveBackground;
numberSearchSongButton.BackgroundImage = numberSearchSongNormalBackground;
EnableDoubleBuffering(handWritingPanelForSongs);
EnableDoubleBuffering(handwritingInputBoxForSongs);
EnableDoubleBuffering(candidateListBoxForSongs);
EnableDoubleBuffering(pictureBoxHandWritingSongs);
EnableDoubleBuffering(refillButtonHandWritingSongs);
EnableDoubleBuffering(closeButtonForSongs);
var configData = LoadBtnConfigData();
string handWritingImagePath = Path.Combine(serverPath, configData["ImagePaths"]["HandWritingSongs"]);
ShowImageOnPictureBoxHandWritingSongs(Path.Combine(serverPath, handWritingImagePath));
// 鍵盤UI介面顯示設定
SetWordCountSongsAndButtonsVisibility(false);
SetEnglishSongsAndButtonsVisibility(false);
SetPinYinSongsAndButtonsVisibility(false);
SetHandWritingForSongsAndButtonsVisibility(true);
SetSongIDSearchAndButtonsVisibility(false);
SetZhuYinSongsAndButtonsVisibility(false);
ResetinputBox();
this.ResumeLayout();
2025-04-07 16:54:10 +08:00
}
private void RefillButtonHandWritingSongs_Click(object sender, EventArgs e)
{
handwritingInputBoxForSongs.Text = "";
}
private void ClearButtonHandWritingSongs_Click(object sender, EventArgs e)
{
if (this.Controls.Contains(handWritingPanelForSongs) && inkOverlayForSongs != null)
{
inkOverlayForSongs.Ink.DeleteStrokes();
handWritingPanelForSongs.Invalidate();
2025-04-07 16:54:10 +08:00
}
}
private void CloseButtonForSongs_Click(object sender, EventArgs e)
{
2025-04-07 16:54:10 +08:00
this.SuspendLayout();
handWritingSearchSongButton.BackgroundImage = handWritingSearchSongNormalBackground;
SetHandWritingForSongsAndButtonsVisibility(false);
2025-04-11 15:12:20 +08:00
FindHandwritingSongs();
2025-04-07 16:54:10 +08:00
this.ResumeLayout();
}
private void FindHandwritingSongs()
{
2025-04-11 15:12:20 +08:00
string searchText = handwritingInputBoxForSongs.Text;
// 在這裡添加搜尋歌曲的邏輯
// 例如:根據輸入框的內容搜尋歌曲
2025-04-15 10:59:03 +08:00
string query = string.IsNullOrWhiteSpace(searchText)
2025-08-06 10:47:43 +08:00
? "SELECT * FROM song_library_cache ORDER BY song_id DESC LIMIT 1000;"
: $"SELECT * FROM song_library_cache WHERE song_name LIKE '{searchText}%' ORDER BY song_name DESC;";
2025-04-15 10:59:03 +08:00
var searchResults = SearchSongs_Mysql(query);
2025-04-11 15:12:20 +08:00
// 重置分頁
currentPage = 0;
totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage);
// 更新多頁面面板的內容
multiPagePanel.currentPageIndex = 0;
multiPagePanel.LoadSongs(searchResults);
2025-04-11 15:12:20 +08:00
}
#endregion
2025-04-07 16:54:10 +08:00
}
}