private void DisplayScroll_MouseMove(object sender, MouseEventArgs e) { if (lastDragPoint.HasValue) { Point posNow = e.GetPosition(DisplayScroll); double dX = posNow.X - lastDragPoint.Value.X; double dY = posNow.Y - lastDragPoint.Value.Y; lastDragPoint = posNow; DisplayScroll.ScrollToHorizontalOffset(DisplayScroll.HorizontalOffset - dX); DisplayScroll.ScrollToVerticalOffset(DisplayScroll.VerticalOffset - dY); } }
/// <summary> /// Loads a chapter from the date provided /// </summary> /// <param name="data">The images</param> /// <param name="m">The manga it came from</param> /// <param name="chIndex">The chapter it came from</param> public void LoadChapterFromData(BitmapImage[] data, Manga m, int chIndex) { prefetchedData = null; loadPrefetchOnComplete = false; if (!m.isLocal) { if (bookmarks.ContainsKey(m.id)) //Update bookmark buttons { if (curManga != m && ChGrid.Children.Count > bookmarks[m.id].lastChapter) { (ChGrid.Children[bookmarks[m.id].lastChapter] as Button).Background = null; } bookmarks[m.id].lastChapter = chIndex; bookmarks[m.id].lastRead = DateTime.UtcNow; } else { bookmarks.Add(m.id, new MangaBookmark() { id = m.id, lastChapter = chIndex, lastRead = DateTime.UtcNow }); } } Binding binding = new Binding(); binding.Path = new PropertyPath("ViewportWidth"); binding.Source = DisplayScroll; ImagePane.Children.Clear(); for (int i = 0; i < data.Length; i++) { Image img = new Image(); img.MouseDown += ZoomStart; img.MouseRightButtonUp += ZoomEnd; img.MouseEnter += ZoomEnter; img.MouseMove += ZoomMove; img.Source = data[i]; BindingOperations.SetBinding(img, Image.MaxWidthProperty, binding); ImagePane.Children.Add(img); } //Update bookmark buttons if (ChGrid.Children.Count > chIndex) { if (curManga == null) { (ChGrid.Children[chIndex] as Button).Background = Brushes.DarkGoldenrod; } else if (curManga == m) { (ChGrid.Children[curChIndex] as Button).Background = null; (ChGrid.Children[chIndex] as Button).Background = Brushes.DarkGoldenrod; } } curManga = m; curChIndex = chIndex; //Update top bar BarChName.Text = m.title + ", " + api.GetChapterName(m, chIndex); hasPrev = chIndex > 0; hasNext = chIndex < m.chapters.Length - 1; if (LeftToRight) //Makes sure the left and right butts are properly switched when using different read directions { LeftButt.Visibility = hasPrev ? Visibility.Visible : Visibility.Hidden; RightButt.Visibility = hasNext ? Visibility.Visible : Visibility.Hidden; DisplayScroll.ScrollToLeftEnd(); LeftButt.ToolTip = "Prev"; RightButt.ToolTip = "Next (Fetching...)"; } else { LeftButt.Visibility = hasNext ? Visibility.Visible : Visibility.Hidden; RightButt.Visibility = hasPrev ? Visibility.Visible : Visibility.Hidden; DisplayScroll.ScrollToRightEnd(); RightButt.ToolTip = "Prev"; LeftButt.ToolTip = "Next (Fetching...)"; } if (hasNext)//Prefetch next chapter if applicable { AsyncPrefetchChapter(m, chIndex + 1); } GC.Collect(); }
public void ProcessIndicatorInput(double x) { x -= ScrollIndicator.Margin.Left; x = x / ((ScrollIndicator.Parent as FrameworkElement).ActualWidth - ScrollIndicator.Margin.Left - ScrollIndicator.Margin.Right); DisplayScroll.ScrollToHorizontalOffset(x * DisplayScroll.ScrollableWidth); }
public void ScrollBypass(object sender, MouseWheelEventArgs args) { DisplayScroll.RaiseEvent(args); args.Handled = true; }
private void UpdateUI(string data) { DisplayBox.AppendText(data); DisplayScroll.ScrollToEnd(); }
private void DisplayScroll_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { DisplayScroll.Cursor = Cursors.Arrow; DisplayScroll.ReleaseMouseCapture(); lastDragPoint = null; }
private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e) { #if DEBUG if (DisplayScroll.CanContentScroll) { Console.WriteLine("ScrollChangedEvent just Occurred"); Console.WriteLine("ExtentHeight is now " + e.ExtentHeight); Console.WriteLine("ExtentWidth is now " + e.ExtentWidth); Console.WriteLine("ExtentHeightChange was " + e.ExtentHeightChange); Console.WriteLine("ExtentWidthChange was " + e.ExtentWidthChange); Console.WriteLine("HorizontalOffset is now " + e.HorizontalOffset); Console.WriteLine("VerticalOffset is now " + e.VerticalOffset); Console.WriteLine("HorizontalChange was " + e.HorizontalChange); Console.WriteLine("VerticalChange was " + e.VerticalChange); Console.WriteLine("ViewportHeight is now " + e.ViewportHeight); Console.WriteLine("ViewportWidth is now " + e.ViewportWidth); Console.WriteLine("ViewportHeightChange was " + e.ViewportHeightChange); Console.WriteLine("ViewportWidthChange was " + e.ViewportWidthChange); Console.WriteLine("ActualHeight is now " + DisplayScroll.ActualHeight); Console.WriteLine("ActualWidth is now " + DisplayScroll.ActualWidth); Console.WriteLine("--------------------------------------------------------------"); //ActualHeight = ViewportHeight + HorizontalScrollbarHeight } #endif DisplayScroll.UpdateLayout(); if (e.ViewportHeightChange != 0 || e.ViewportWidthChange != 0) { _zoomValue = ZoomToFit(); var scale = new ScaleTransform(_zoomValue, _zoomValue); DisplayImage.LayoutTransform = scale; DisplayScroll.UpdateLayout(); } if (e.ExtentHeightChange != 0 || e.ExtentWidthChange != 0) { Point?targetBefore = null; Point?targetNow = null; if (lastMousePositionOnTarget.HasValue) { targetBefore = lastMousePositionOnTarget; targetNow = Mouse.GetPosition(DisplayImage); lastMousePositionOnTarget = null; } if (targetBefore.HasValue) { double dXInTargetPixels = targetNow.Value.X - targetBefore.Value.X; double dYInTargetPixels = targetNow.Value.Y - targetBefore.Value.Y; double multiplicatorX = e.ExtentWidth / DisplayImage.ActualWidth; double multiplicatorY = e.ExtentHeight / DisplayImage.ActualHeight; double newOffsetX = DisplayScroll.HorizontalOffset - dXInTargetPixels * multiplicatorX; double newOffsetY = DisplayScroll.VerticalOffset - dYInTargetPixels * multiplicatorY; if (double.IsNaN(newOffsetX) || double.IsNaN(newOffsetY)) { return; } DisplayScroll.ScrollToHorizontalOffset(newOffsetX); DisplayScroll.ScrollToVerticalOffset(newOffsetY); } } }