superstar_v2/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.HandwritingSearch.cs
jasonchenwork 237e9f6c49 2509021737
手寫板清除問題修正
點歌對話框遮罩問題修正
跑馬燈流程,參數調整
2025-09-02 17:38:58 +08:00

247 lines
11 KiB
C#

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();
}
private void InitializeHandWritingPanelForSongs()
{
handWritingPanelForSongs = new Panel
{
BorderStyle = BorderStyle.FixedSingle,
BackColor = Color.WhiteSmoke,
Visible = false
};
ResizeAndPositionControl(handWritingPanelForSongs, 20, 89, 650, 260);
pictureBoxHandWritingSongs.Controls.Add(handWritingPanelForSongs);
}
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)
{
RecognizeInk(inkOverlayForSongs, candidateListBoxForSongs);
}
private void InitializeHandwritingInputBoxForSongs()
{
handwritingInputBoxForSongs = new RichTextBox
{
Font = new Font("微軟正黑體", (float)26 / 900 * Screen.PrimaryScreen.Bounds.Height, FontStyle.Regular),
Visible = false
};
ResizeAndPositionControl(handwritingInputBoxForSongs, 20, 12, 541, 64);
pictureBoxHandWritingSongs.Controls.Add(handwritingInputBoxForSongs);
}
private void InitializeCandidateListBoxForSongs()
{
candidateListBoxForSongs = new ListBox
{
Font = new Font("微軟正黑體", (float)26 / 900 * Screen.PrimaryScreen.Bounds.Height, FontStyle.Regular),
Visible = false
};
ResizeAndPositionControl(candidateListBoxForSongs, 675, 81, 115, 270);
candidateListBoxForSongs.SelectedIndexChanged += CandidateListBoxForSongs_SelectedIndexChanged;
pictureBoxHandWritingSongs.Controls.Add(candidateListBoxForSongs);
}
private void CandidateListBoxForSongs_SelectedIndexChanged(object sender, EventArgs e)
{
if (candidateListBoxForSongs.SelectedIndex != -1)
{
string selectedWord = candidateListBoxForSongs.SelectedItem.ToString();
handwritingInputBoxForSongs.Text += selectedWord;
candidateListBoxForSongs.Visible = false;
if (inkOverlayForSongs != null)
{
inkOverlayForSongs.Ink.DeleteStrokes();
handWritingPanelForSongs.Invalidate();
}
}
}
private void ShowImageOnPictureBoxHandWritingSongs(string imagePath)
{
Bitmap originalImage = new Bitmap(imagePath);
pictureBoxHandWritingSongs.Image = originalImage;
ResizeAndPositionPictureBox(pictureBoxHandWritingSongs, 388, 355, 810, 360);
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);
}
private void InitializeBtnsHandwritingSongs()
{
var data = LoadBtnConfigData();
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);
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)
{
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();
}
private void RefillButtonHandWritingSongs_Click(object sender, EventArgs e)
{
handwritingInputBoxForSongs.Text = "";
}
private void ClearButtonHandWritingSongs_Click(object sender, EventArgs e)
{
if (pictureBoxHandWritingSongs.Controls.Contains(handWritingPanelForSongs) && inkOverlayForSongs != null)
{
inkOverlayForSongs.Ink.DeleteStrokes();
handWritingPanelForSongs.Invalidate();
}
}
private void CloseButtonForSongs_Click(object sender, EventArgs e)
{
pictureBoxHandWritingSongs.SuspendLayout();
handWritingSearchSongButton.BackgroundImage = handWritingSearchSongNormalBackground;
SetHandWritingForSongsAndButtonsVisibility(false);
FindHandwritingSongs();
pictureBoxHandWritingSongs.ResumeLayout();
}
private void FindHandwritingSongs()
{
string searchText = handwritingInputBoxForSongs.Text;
// 在這裡添加搜尋歌曲的邏輯
// 例如:根據輸入框的內容搜尋歌曲
string query = string.IsNullOrWhiteSpace(searchText)
? "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;";
var searchResults = SearchSongs_Mysql(query);
// 重置分頁
currentPage = 0;
totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage);
// 更新多頁面面板的內容
multiPagePanel.currentPageIndex = 0;
multiPagePanel.LoadSongs(searchResults);
}
#endregion
}
}