public Preview() { var t = PrepareChessTexture(Theme.Colors.ZebraColor1.Transparentify(0.5f), Theme.Colors.ZebraColor2); const float ChessCellSize = 50; //Color4 Color1 = Core.UserPreferences.Instance.Get<UserPreferences>().BackgroundColorA; //Color4 Color2 = Core.UserPreferences.Instance.Get<UserPreferences>().BackgroundColorB; RootWidget = new ThemedScrollView(); RootWidget.Content.Layout = new FlowLayout { Spacing = 5.0f, }; RootWidget.Content.Padding = new Thickness(5.0f); RootWidget.CompoundPresenter.Insert(1, new SyncDelegatePresenter <Widget>((w) => { w.PrepareRendererState(); var ratio = ChessCellSize * 1.0f; Renderer.DrawSprite( t, Color4.White, Vector2.Zero, w.Size, -Vector2.Zero / ratio, (w.Size - Vector2.Zero) / ratio); })); RootWidget.Updated += (dt) => { if (RootWidget.IsMouseOver()) { if (!RootWidget.Input.IsKeyPressed(Key.Control)) { return; } int zoomDelta = 0; if (RootWidget.Input.WasKeyPressed(Key.MouseWheelUp)) { zoomDelta = 1; } if (RootWidget.Input.WasKeyPressed(Key.MouseWheelDown)) { zoomDelta = -1; } if (zoomDelta != 0) { for (int i = 0; i < zoom.Count; i++) { var z = zoom[i]; int newZoom = Mathf.Clamp(z.Item1 + zoomDelta, 0, z.Item2); if (newZoom != z.Item1) { zoom[i] = new Tuple <int, int>(newZoom, z.Item2); } } ApplyZoom(); } } }; }
private void ProcessDragState(float dt) { var input = scrollView.Input; switch (dragState) { case DragState.None: { if (scrollView.IsMouseOver()) { if (input.ConsumeKeyPress(Key.Mouse0)) { dragEndPosition = dragStartPosition = scrollView.Content.LocalMousePosition(); dragState = DragState.WaitingForSelecting; } if (input.ConsumeKeyRelease(Key.Mouse1)) { dragState = DragState.None; selection.Clear(); SystemShellContextMenu.Instance.Show(model.CurrentPath); } } break; } case DragState.Selecting: { if (Window.Current.Input.WasKeyReleased(Key.Mouse0)) { Window.Current.Input.ConsumeKey(Key.Mouse0); scrollView.SetFocus(); dragState = DragState.None; } dragEndPosition = scrollView.Content.LocalMousePosition(); var scrollOffset = 0.0f; if (scrollView.LocalMousePosition().Y < 0) { scrollOffset = scrollView.LocalMousePosition().Y; } else if (scrollView.LocalMousePosition().Y > scrollView.Size.Y) { scrollOffset = scrollView.LocalMousePosition().Y - scrollView.Size.Y; } scrollView.ScrollPosition += Math.Sign(scrollOffset) * Mathf.Sqr(scrollOffset) * 0.1f * dt; scrollView.ScrollPosition = Mathf.Clamp(scrollView.ScrollPosition, scrollView.MinScrollPosition, scrollView.MaxScrollPosition); Window.Current.Invalidate(); } break; case DragState.WaitingForDragging: if ((dragStartPosition - Window.Current.Input.MousePosition).Length > 5.0f) { dragState = DragState.Dragging; CommonWindow.Current.DragFiles(selection.ToArray()); } if ( Window.Current.Input.WasKeyReleased(Key.Mouse0) || Window.Current.Input.WasKeyReleased(Key.Mouse0DoubleClick) ) { dragState = DragState.None; Window.Current.Input.ConsumeKey(Key.Mouse0); } break; case DragState.WaitingForSelecting: if (input.ConsumeKeyRelease(Key.Mouse0)) { dragState = DragState.None; if (!input.IsKeyPressed(Key.Control) && !input.IsKeyPressed(Key.Shift)) { selection.Clear(); } } else if (input.IsKeyPressed(Key.Mouse0)) { if ((scrollView.Content.LocalMousePosition() - dragStartPosition).Length > 6.0f) { dragState = DragState.Selecting; if (input.IsKeyPressed(Key.Control)) { savedSelection = selection.Clone(); } else { savedSelection = null; } } } break; case DragState.Dragging: if (Window.Current.Input.WasKeyReleased(Key.Mouse0)) { Window.Current.Input.ConsumeKey(Key.Mouse0); dragState = DragState.None; } break; } }