static void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { if (Overlayer == null) { return; } ProgressEntry entry = (ProgressEntry)Overlayer.GetMessageQueue()[e.UserState]; entry.Downloaded = e.BytesReceived; }
void Refresher_Tick(object sender, EventArgs e) { var queue = Overlayer.GetMessageQueue(); if (queue.Count == 0) { Refresher.Stop(); Refresher = null; Hide(); } // Remove timeout items from queue foreach (var item in queue.ToArray()) { if (item.Value is NoticeEntry) { var entry = (NoticeEntry)item.Value; if (entry.Begin + entry.Duration < DateTime.Now) { queue.Remove(item.Key); } } } // Remove removed visual fro window foreach (var pair in Messages.ToArray()) { if (queue.ContainsKey(pair.Key) == false) { MainPanel.Children.Remove(Messages[pair.Key]); Messages.Remove(pair.Key); Progresses.Remove(pair.Key); } } // TODO: caching state. foreach (var pair in queue) { var entry = pair.Value; // TextBlock preparation. TextBlock tb; if (Messages.ContainsKey(pair.Key)) { tb = Messages[pair.Key]; } else { tb = new TextBlock(); tb.Style = TextBlockStyle; tb.FontSize = FontSize; Messages[pair.Key] = tb; MainPanel.Children.Add(tb); } tb.Text = entry.Message; // Background progressbar preparation. if (entry is ProgressEntry) { ProgressEntry item = (ProgressEntry)entry; ProgressBar pg; if (Progresses.ContainsKey(pair.Key)) { pg = Progresses[pair.Key]; } else { pg = new ProgressBar(); pg.Minimum = 0; pg.Maximum = item.Total; pg.Margin = new Thickness(0, 2, 0, 2); } pg.Value = item.Downloaded; tb.Background = new VisualBrush(pg); } else if (entry is NoticeEntry) { var item = (NoticeEntry)entry; if (Progresses.ContainsKey(pair.Key)) { MainPanel.Children.Remove(Progresses[pair.Key]); Progresses.Remove(pair.Key); } tb.Background = NoticeBackground; var remaining = (item.Begin + item.Duration) - DateTime.Now; tb.Opacity = Math.Min(Math.Max(remaining.TotalMilliseconds * 0.002D, 0), 1); } } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Implementation of capturing from the render target of the Direct3D9 Device (or DeviceEx) /// </summary> /// /// <param name="device"> . </param> /// <param name="hook"> The hook. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// void DoCaptureRenderTarget(Device device, string hook) { // Auto hook disable. if (MessageQueue.Count == 0) { SetHookState(false); return; } try { if (MainFont != null && MainFont.Device.NativePointer != device.NativePointer) { MainFont.Dispose(); MainFont = null; } if (MainFont == null) { // Measure screen size after device creation. using (var renderTarget = device.GetRenderTarget(0)) { ScreenWidth = renderTarget.Description.Width; ScreenHeight = renderTarget.Description.Height; } MainFont = new Font(device, new FontDescription() { Height = (int)(Math.Min(ScreenWidth, ScreenHeight) * 0.03), FaceName = "맑은 고딕", CharacterSet = FontCharacterSet.Default, OutputPrecision = FontPrecision.ScreenOutline, Quality = FontQuality.ClearTypeNatural, PitchAndFamily = FontPitchAndFamily.Default, Weight = FontWeight.Regular }); } if (BackLine != null && BackLine.Device.NativePointer != device.NativePointer) { BackLine.Dispose(); BackLine = null; } if (BackLine == null) { BackLine = new Line(device) { Width = MainFont.Description.Height + 2 }; } var fontColor = new ColorBGRA(0, 0, 0, 255); int i = 0; var items = from pair in MessageQueue where pair.Value.Begin < DateTime.Now orderby pair.Value.Begin select pair; float screenCenter = ScreenWidth * 0.5F; float topMargin = ScreenHeight * 0.725F; float spaceBetweenLines = MainFont.Description.Height * 1.4F; int fontMarginX = (int)(MainFont.Description.Height * 0.2F); int fontCorrectionY = (int)(MainFont.Description.Height * 0.5F); BackLine.Begin(); foreach (var pair in items.ToArray()) { var entry = pair.Value; if (entry is ProgressEntry) { ProgressEntry item = (ProgressEntry)entry; Rectangle rect = MainFont.MeasureText(null, item.Message, FontDrawFlags.SingleLine); float lineLength = rect.Right + fontMarginX * 2; Vector2 lineStart = new Vector2() { X = screenCenter - lineLength * 0.5F, Y = i * spaceBetweenLines + topMargin }; float midPoint = lineStart.X + lineLength * item.Downloaded / item.Total; Vector2[] line = new Vector2[] { lineStart, new Vector2(midPoint, lineStart.Y) }; new Vector2(lineStart.X + lineLength, lineStart.Y); BackLine.Draw(line, foreground); // Reduce length by multiplying download rate. line[0] = line[1]; line[1] = new Vector2(lineStart.X + lineLength, lineStart.Y); BackLine.Draw(line, background); MainFont.DrawText(null, item.Message, (int)lineStart.X + fontMarginX, (int)lineStart.Y - fontCorrectionY, fontColor); i++; } else if (entry is NoticeEntry) { NoticeEntry item = (NoticeEntry)entry; Rectangle rect = MainFont.MeasureText(null, item.Message, FontDrawFlags.SingleLine); var endTime = item.Begin + item.Duration; var remainingTime = endTime - DateTime.Now; byte alpha; if (remainingTime.TotalMilliseconds < 0) { MessageQueue.Remove(pair.Key); alpha = 0; } else { alpha = (byte)Math.Min(remainingTime.TotalMilliseconds * 0.5, 255); } var noticeColor = new ColorBGRA(255, 255, 32, alpha); var noticeFontColor = new ColorBGRA(0, 0, 0, alpha); float lineLength = rect.Right + 2 * fontMarginX; Vector2 lineStart = new Vector2() { X = screenCenter - lineLength * 0.5F, Y = i * spaceBetweenLines + topMargin }; BackLine.Draw(new Vector2[] { lineStart, new Vector2(lineStart.X + lineLength, lineStart.Y) }, noticeColor); MainFont.DrawText(null, item.Message, (int)lineStart.X + fontMarginX, (int)lineStart.Y - fontCorrectionY, noticeFontColor); i++; } } BackLine.End(); } catch (Exception e) { MainWindowViewModel.LogException(e); } }