diff --git a/PrimaryFormParts/PrimaryForm.MultiPagePanel.cs b/PrimaryFormParts/PrimaryForm.MultiPagePanel.cs index 7834615..dc863a1 100644 --- a/PrimaryFormParts/PrimaryForm.MultiPagePanel.cs +++ b/PrimaryFormParts/PrimaryForm.MultiPagePanel.cs @@ -12,7 +12,7 @@ namespace DualScreenDemo { private const int ItemHeight = 70; private const int RowGap = 2; - private int itemsPerPage + public int itemsPerPage { get { @@ -203,12 +203,10 @@ namespace DualScreenDemo currentSongList = songs; currentArtistList.Clear(); currentPageIndex = 0; - totalPages = (int)Math.Ceiling(songs.Count / (double)itemsPerPage); - + totalPages = (int)Math.Ceiling(songs.Count / (double)itemsPerPage); // 直接調用基礎刷新邏輯 RefreshDisplayBase(); } - public void LoadSingers(List artists) { _isShowingSinger = true; @@ -219,18 +217,17 @@ namespace DualScreenDemo RefreshDisplayBase_Singer(); } - public void LoadPlayedSongs(List songs) + public void LoadPlayedSongs(List songs,int page) { _isShowingSinger = false; currentSongList = songs; currentArtistList.Clear(); - currentPageIndex = 0; + currentPageIndex = page; totalPages = (int)Math.Ceiling(songs.Count / (double)itemsPerPage); // 直接調用基礎刷新邏輯 RefreshDisplayBase(); } - public void RefreshDisplay() { this.Controls.Clear(); // 清除所有 UI 元件 @@ -562,8 +559,6 @@ namespace DualScreenDemo songLabel.BringToFront(); artistLabel.BringToFront(); - //songLabel.Controls.Add(artistLabel); - //artistLabel.Anchor = AnchorStyles.Left | AnchorStyles.Bottom; songLabel.TextAlign = ContentAlignment.TopLeft; } diff --git a/PrimaryFormParts/PrimaryForm.QRCode.cs b/PrimaryFormParts/PrimaryForm.QRCode.cs index 2f53fd6..b98e46d 100644 --- a/PrimaryFormParts/PrimaryForm.QRCode.cs +++ b/PrimaryFormParts/PrimaryForm.QRCode.cs @@ -13,7 +13,7 @@ namespace DualScreenDemo try { - + string imagePath = Path.Combine(serverPath, data["QrCode"]["QrCodeBaseUI"]); if (!File.Exists(imagePath)) { @@ -60,7 +60,7 @@ namespace DualScreenDemo using (qrCodeImage) { - + using (Bitmap bitmap = new Bitmap(baseImage.Width, baseImage.Height)) { using (Graphics g = Graphics.FromImage(bitmap)) @@ -70,30 +70,28 @@ namespace DualScreenDemo // cropped qrcode 版型不同設定調整 g.DrawImage(baseImage, new Rectangle(0, 0, bitmap.Width, bitmap.Height)); Rectangle qrCodeRect = new Rectangle(41, 50, 227, 227); - + g.DrawImage(qrCodeImage, qrCodeRect); - } + } pictureBoxQRCode.Image = new Bitmap(bitmap); } } } - + ResizeAndPositionControl(pictureBoxQRCode, 975, 442, 226, 274); - + Bitmap originalImage = new Bitmap(Path.Combine(serverPath, data["QrCode"]["QrCodeBaseUI"])); - + //Rectangle closeQRCodeCropArea = new Rectangle(198, 6, 22, 22); - + closeQRCodeButton = new Button { Text = "" }; closeQRCodeButton.Name = "closeQRCodeButton"; - closeQRCodeButton.Location = new Point(259, 7); - closeQRCodeButton.Size = new Size(30, 30); closeQRCodeButton.BackColor = Color.Transparent; closeQRCodeButton.BackgroundImageLayout = ImageLayout.Stretch; closeQRCodeButton.FlatStyle = FlatStyle.Flat; @@ -102,6 +100,7 @@ namespace DualScreenDemo closeQRCodeButton.FlatAppearance.MouseDownBackColor = Color.Transparent; closeQRCodeButton.Click += CloseQRCodeButton_Click; pictureBoxQRCode.Controls.Add(closeQRCodeButton); + ResizeAndPositionControl(closeQRCodeButton, 193, 4, 25, 25); } catch (Exception ex) { diff --git a/PrimaryFormParts/PrimaryForm.cs b/PrimaryFormParts/PrimaryForm.cs index ddf8e82..a076aa3 100644 --- a/PrimaryFormParts/PrimaryForm.cs +++ b/PrimaryFormParts/PrimaryForm.cs @@ -136,32 +136,32 @@ namespace DualScreenDemo // string serverPath = Utils.Env.GetPath("", ""); string serverPath = Application.StartupPath; -// async Task GetBitmapFromUriAsync(Uri uri) -// { -// using HttpClient client = new HttpClient(); -// byte[] imageBytes = await client.GetByteArrayAsync(uri); + //async Task GetBitmapFromUriAsync(Uri uri) + //{ + // using HttpClient client = new HttpClient(); + // byte[] imageBytes = await client.GetByteArrayAsync(uri); -// MemoryStream ms = new MemoryStream(imageBytes); -// Bitmap bitmap = new Bitmap(ms); -// Bitmap clonedBitmap = new Bitmap(bitmap); -// ms.Dispose(); + // MemoryStream ms = new MemoryStream(imageBytes); + // Bitmap bitmap = new Bitmap(ms); + // Bitmap clonedBitmap = new Bitmap(bitmap); + // ms.Dispose(); -// return clonedBitmap; -// } + // return clonedBitmap; + //} -// private async void LoadBackgroundImage() -// { -// var data = LoadBtnConfigData(); -// var hostdata = LoadBtnConfigData(); -// string test = hostdata["HeartBeatUrl"] + "/" + data["PrimaryFormBtn"]["AlertNormal1"]; -// Console.WriteLine(test); -// Uri remoteUri = new Uri("http://zqd.superstar.dnsnet.cc/themes/superstar/button/1.主類別/主類別上方_新歌快報(未按).png"); + //private async void LoadBackgroundImage() + //{ + // var data = LoadBtnConfigData(); + // var hostdata = LoadBtnConfigData(); + // string test1 = hostdata["HeartBeatUrl"] + "/" + data["PrimaryFormBtn"]["AlertNormal1"]; + // Console.WriteLine(test1); + // Uri remoteUri = new Uri("http://zqd.superstar.dnsnet.cc/themes/superstar/button/1.主類別/主類別上方_新歌快報(未按).png"); -// Bitmap bitmap = await GetBitmapFromUriAsync(remoteUri); -// this.BackgroundImage = bitmap; -// this.BackgroundImageLayout = ImageLayout.Stretch; // Optional -// } + // Bitmap bitmap = await GetBitmapFromUriAsync(remoteUri); + // this.BackgroundImage = bitmap; + // this.BackgroundImageLayout = ImageLayout.Stretch; // Optional + //} public int currentPage { @@ -179,7 +179,7 @@ namespace DualScreenDemo this.Invalidate(); // 重新繪製界面 } - public const int itemsPerPage = 18; + public const int itemsPerPage = 16; private WaveInEvent waveIn; private WaveFileWriter waveWriter; @@ -340,12 +340,12 @@ namespace DualScreenDemo // 設定繪製文字的位置 (X=500, Y=30) PointF point_PCName = new PointF(450 * scaleX, 30 * scaleY); PointF point_PageNumber = new PointF(1390 * scaleX, 30 * scaleY); - PointF point_verSion = new PointF(1800 * scaleX, 30 * scaleY); + PointF point_verSion = new PointF(1800 * scaleX-10, 30 * scaleY); // 繪製文字: // `DrawString(要繪製的文字, 字型, 畫刷, 位置)` e.Graphics.DrawString(displayName, font, brush, point_PCName); e.Graphics.DrawString(pageNumber, font, brush, point_PageNumber); - e.Graphics.DrawString(version.Substring(version.IndexOf("V"), 4), font, brush, point_verSion); + e.Graphics.DrawString(version.Substring(version.IndexOf("V"), 5), font, brush, point_verSion); } private void User_Paint(object sender, PaintEventArgs e) { @@ -2312,14 +2312,16 @@ namespace DualScreenDemo { var data = LoadBtnConfigData(); - UpdateButtonBackgrounds(orderedSongsButton,orderedSongsActiveBackground); + UpdateButtonBackgrounds(orderedSongsButton, orderedSongsActiveBackground); isOnOrderedSongsPage = true; autoRefreshTimer.Start(); // 开始自动刷新 // 已點歌曲錨點 var List = SongList.GetHistory(); totalPages = (int)Math.Ceiling((double)List.Count / itemsPerPage); - multiPagePanel.currentPageIndex = 0; + int index = List.FindIndex(song => song.GetState() == PlayState.Playing); + int page = 0; + if ((index+1) > multiPagePanel.itemsPerPage) page = Math.Abs((index+1) / multiPagePanel.itemsPerPage); SetHotSongButtonsVisibility(false); SetNewSongButtonsVisibility(false); @@ -2343,7 +2345,7 @@ namespace DualScreenDemo closeQRCodeButton.Visible = false; } - multiPagePanel.LoadPlayedSongs(List); + multiPagePanel.LoadPlayedSongs(List,page); } #region 控制項Visible屬性設定 @@ -2419,5 +2421,40 @@ namespace DualScreenDemo activeButton.BackgroundImage = activeBackground; } + private async void HttpDownload(string fileUrl,string LocalLoc) + { + using HttpClient client = new HttpClient(); + try + { + var response= await client.GetAsync(fileUrl, HttpCompletionOption.ResponseHeadersRead); + + var totalBytes = response.Content.Headers.ContentLength ?? -1L; + using var contentStream = await response.Content.ReadAsStreamAsync(); + using var fileStream = new FileStream(LocalLoc, FileMode.Create, FileAccess.Write, FileShare.None); + + var buffer = new byte[8192]; + long totalRead = 0; + int read; + while ((read = await contentStream.ReadAsync(buffer, 0, buffer.Length)) > 0) + { + await fileStream.WriteAsync(buffer, 0, read); + totalRead += read; + + if (totalBytes > 0) + { + int progress = (int)((totalRead * 100) / totalBytes); + progressBar.Value = progress; + } + } + + Console.WriteLine("File Downloaded"); + } + catch (Exception ex) + { + Console.WriteLine("Download Failed:"+ex.Message); + Program.WriteLog("Download Failed:" + ex.Message); + } + } + } } \ No newline at end of file