private void Select(WindowsRect selectionRect, bool isSingleSelection) { var editableCurve = SelectedCurve as IEditableCurveViewModel; if (editableCurve == null) { return; } // TODO: move this to the curve (especially hit testing) IList <ControlPointViewModelBase> selectedPoints = editableCurve.ControlPoints.Where(c => selectionRect.Contains(c.ActualPoint)).ToList(); if (selectedPoints.Count > 1 && isSingleSelection) { var rectCenter = new WindowsPoint(selectionRect.Left + selectionRect.Width * 0.5, selectionRect.Top + selectionRect.Height * 0.5); var closest = CurveHelper.GetClosestPoint(selectedPoints, rectCenter); selectedPoints = new[] { closest }; } switch (Keyboard.Modifiers) { case ModifierKeys.None: ClearPointSelection(); goto case ModifierKeys.Shift; case ModifierKeys.Shift: // FIXME: do this atomically in the curve foreach (var p in selectedPoints.Where(p => !p.IsSelected)) { SelectedControlPoints.Add(p); p.IsSelected = true; } break; case ModifierKeys.Control: // FIXME: do this atomically in the curve foreach (var p in selectedPoints.Where(p => p.IsSelected)) { SelectedControlPoints.Remove(p); p.IsSelected = false; } break; } }
public void AddPresetExternal(int dbUserId, string presetName) { List <KeyValuePair <int, WindowsRect> > appList = new List <KeyValuePair <int, WindowsRect> >(); List <KeyValuePair <int, WindowsRect> > vncList = new List <KeyValuePair <int, WindowsRect> >(); List <KeyValuePair <int, WindowsRect> > visionList = new List <KeyValuePair <int, WindowsRect> >(); // Get the current latest position of all running apps IList <WindowsHelper.ApplicationInfo> appInfoList = Utils.Windows.WindowsHelper.GetRunningApplicationInfo(); // key - window unique identifier // value - application DB id Dictionary <int, List <int> > launcedAppDic = Server.LaunchedWndHelper.GetInstance().GetLaunchedApps(dbUserId); for (int i = 0; i < launcedAppDic.Count(); i++) { int wndIdentifier = launcedAppDic.ElementAt(i).Key; List <int> appDBIndexes = launcedAppDic.ElementAt(i).Value; WindowsRect rect = new WindowsRect(); try { var latestInfo = appInfoList.Single(t => t.id == wndIdentifier); if (latestInfo.posX != -32000) { rect.Left = latestInfo.posX; rect.Top = latestInfo.posY; rect.Right = latestInfo.posX + latestInfo.width; rect.Bottom = latestInfo.posY + latestInfo.height; } } catch (Exception e) { Trace.WriteLine(e.Message); } foreach (int appDBIndex in appDBIndexes) { appList.Add(new KeyValuePair <int, WindowsRect>(appDBIndex, rect)); } } // key - window unique identifier // value - application DB id Dictionary <int, int> launcedVncDic = Server.LaunchedVncHelper.GetInstance().GetLaunchedApps(dbUserId); for (int i = 0; i < launcedVncDic.Count(); i++) { int wndIdentifier = launcedVncDic.ElementAt(i).Key; int vncDBIndex = launcedVncDic.ElementAt(i).Value; WindowsRect rect = new WindowsRect(); try { var latestInfo = appInfoList.Single(t => t.id == wndIdentifier); if (latestInfo.posX != -32000) { rect.Left = latestInfo.posX; rect.Top = latestInfo.posY; rect.Right = latestInfo.posX + latestInfo.width; rect.Bottom = latestInfo.posY + latestInfo.height; } } catch (Exception e) { Trace.WriteLine(e.Message); } vncList.Add(new KeyValuePair <int, WindowsRect>(vncDBIndex, rect)); } // key - window unique identifier // value - application DB id Dictionary <int, int> launcedSourcesDic = Server.LaunchedSourcesHelper.GetInstance().GetLaunchedApps(dbUserId); for (int i = 0; i < launcedSourcesDic.Count(); i++) { int wndIdentifier = launcedSourcesDic.ElementAt(i).Key; int sourceDBIndex = launcedSourcesDic.ElementAt(i).Value; WindowsRect rect = new WindowsRect(); try { var latestInfo = appInfoList.Single(t => t.id == wndIdentifier); if (latestInfo.posX != -32000) { rect.Left = latestInfo.posX; rect.Top = latestInfo.posY; rect.Right = latestInfo.posX + latestInfo.width; rect.Bottom = latestInfo.posY + latestInfo.height; } } catch (Exception e) { Trace.WriteLine(e.Message); } visionList.Add(new KeyValuePair <int, WindowsRect>(sourceDBIndex, rect)); } Server.ServerDbHelper.GetInstance().AddPreset( presetName, dbUserId, appList, vncList, visionList); }
/// <summary> /// Returns a rectangle that is expanded by the specified thickness, in all directions. /// </summary> /// <param name="r"></param> /// <param name="t">The thickness to apply to the rectangle.</param> /// <returns>The inflated rectangle.</returns> public static WindowsRect Inflate(this WindowsRect r, WindowsThickness t) { return(new WindowsRect(r.Left - t.Left, r.Top - t.Top, r.Width + t.Left + t.Right, r.Height + t.Top + t.Bottom)); }
/// <summary> /// Returns the location of the center of the rectangle. /// </summary> /// <param name="r"></param> /// <returns></returns> public static WindowsPoint GetCenterLocation(this WindowsRect r) { return(new WindowsPoint(r.X + r.Width * 0.5f, r.Y + r.Height * 0.5f)); }
/// <summary> /// Actually renders the points of the curve. /// </summary> /// <param name="drawingContext"></param> /// <param name="clippingRect"></param> /// <param name="isCurrentCurve"></param> protected virtual void RenderPoints(IDrawingContext drawingContext, ref WindowsRect clippingRect, bool isCurrentCurve) { // Default implementation does nothing }
protected static void RenderLine([NotNull] IDrawingContext drawingContext, ref WindowsRect clippingRect, IList <WindowsPoint> points, Color color) { // FIXME: calculate (optimistic) clipped line beforehand so that points that are eventually outside of the clipped area are not given to the rendering context. // FIXME: note that in the end the curve is still clipped by the canvas Clip property. drawingContext.DrawPolyline(points, color); }
private void Select(WindowsRect selectionRect) { Select(selectionRect, false); }