public int SelectPartAt(PointF location) { int found = 0; foreach (SymbolPart part in m_Symbol) { if (part.IsNear(location)) { found++; m_GrabHandle = part.GetGrabHandle(location); if (part.Equals(m_SelectedPart) == false) { if (m_SelectedPart != null) { m_SelectedPart.IsSelected = false; } part.IsSelected = true; m_SelectedPart = part; UpdateBackground(); Invalidate(); } } } if (found == 0 && m_SelectedPart != null) { m_SelectedPart.IsSelected = false; m_SelectedPart = null; m_GrabHandle = null; UpdateBackground(); Invalidate(); } return(found); }
private void BuildPrimaryLayout() { primary_vbox = new VBox(); BuildHeader(); BuildViews(); BuildFooter(); search_entry_align = new Alignment(1.0f, 0.5f, 0f, 0f); var box = new HBox() { Spacing = 2 }; var grabber = new GrabHandle(); grabber.ControlWidthOf(view_container.SearchEntry, 150, 350, false); box.PackStart(grabber, false, false, 0); box.PackStart(view_container.SearchEntry, false, false, 0); search_entry_align.Child = box; ActionService.PopulateToolbarPlaceholder(header_toolbar, "/HeaderToolbar/SearchEntry", search_entry_align); search_entry_align.Visible = view_container.SearchSensitive = true; search_entry_align.ShowAll(); primary_vbox.Show(); Add(primary_vbox); }
public LiteralBox() : base() { handle = new GrabHandle (24, 8); PackEnd (handle, false, false, 0); Show (); }
/// <summary> /// Controls mouse up event handler after /// Selection rectangle has been drawn /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Canvas_MouseUp(object sender, MouseEventArgs e) { mouseDown = false; if (currDrawingTool == DrawingTool.Rectangle) { assets.Add(currAsset); path.AddRectangle(currAsset.Rectangle); } else if (currDrawingTool == DrawingTool.Circle) { assets.Add(currAsset); path.AddRectangle(currAsset.Rectangle); } else if (currDrawingTool == DrawingTool.Pen) { if (currAsset.Points.Count == 1) { currAsset.Points.Add(e.Location); } if (currAsset.Points.Count > 1) { assets.Add(currAsset); } path.AddCurve(currAsset.Points.ToArray()); } else if (currDrawingTool == DrawingTool.Line || currDrawingTool == DrawingTool.ArrowLine) { assets.Add(currAsset); path.AddLine(currAsset.LineStart, currAsset.LineEnd); } if (selectionRect.Height > 0 || selectionRect.Width > 0) { path.AddRectangle(selectionRect); toolbox.TopLevel = false; Controls.Add(toolbox); toolbox.Location = GetToolBoxLocation(); toolbox.Show(); toolbox.BringToFront(); manipToolbox.TopLevel = false; Controls.Add(manipToolbox); manipToolbox.Location = GetManipToolboxLoc(); manipToolbox.Show(); manipToolbox.BringToFront(); Focus(); } rectState = RectangleState.None; focusedHandle = GrabHandle.None; }
public bool SetCursor(int x, int y) { bool modified = false; if (!_resizing) { GrabHandle handle = PointToGrabHandle(this.PointToClient(Control.MousePosition)); if (handle != GrabHandle.None) { modified = true; } if (handle == GrabHandle.TopLeft) { Cursor.Current = Cursors.SizeNWSE; } else if (handle == GrabHandle.TopMiddle) { Cursor.Current = Cursors.SizeNS; } else if (handle == GrabHandle.TopRight) { Cursor.Current = Cursors.SizeNESW; } else if (handle == GrabHandle.Right) { Cursor.Current = Cursors.SizeWE; } else if (handle == GrabHandle.BottomRight) { Cursor.Current = Cursors.SizeNWSE; } else if (handle == GrabHandle.BottomMiddle) { Cursor.Current = Cursors.SizeNS; } else if (handle == GrabHandle.BottomLeft) { Cursor.Current = Cursors.SizeNESW; } else if (handle == GrabHandle.Left) { Cursor.Current = Cursors.SizeWE; } else { Cursor.Current = Cursors.Default; } } return(modified); }
/// <summary> /// Constructor /// </summary> public CanvasForm() { SetProcessDpiAwareness(_Process_DPI_Awareness.Process_Per_Monitor_DPI_Aware); path = new GraphicsPath(); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.SupportsTransparentBackColor, true); UpdateStyles(); InitializeComponent(); typeof(Panel).InvokeMember("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, pnlDraw, new object[] { true }); typeof(Panel).InvokeMember("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, pnlOpacity, new object[] { true }); typeof(Panel).InvokeMember("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, pnlPicture, new object[] { true }); toolbox = new DrawingToolBox(); manipToolbox = new ManipulateToolBox(); assets = new List <Asset>(); opacityRect = new Rectangle(0, 0, SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height); brush = new SolidBrush(Color.FromArgb(150, 80, 80, 80)); focusedHandle = GrabHandle.None; rectangles = new Dictionary <GrabHandle, RectangleF>(); foreach (GrabHandle handle in Enum.GetValues(typeof(GrabHandle))) { rectangles[handle] = new RectangleF(-5, -5, 7, 7); path.AddRectangle(rectangles[handle]); } dimensions = new Font(Font.FontFamily, 9, FontStyle.Regular | FontStyle.Bold); screenshots = new Dictionary <Screen, Image>(); _regisKey = new RegisterHotKeyClass(); RegisterEvents(); }
private GrabHandle PointToGrabHandle(Point pointerLocation) { GrabHandle result = GrabHandle.None; if (IsCursorOnGrabHandle(pointerLocation, _handles[0])) { result = GrabHandle.TopLeft; } else if (IsCursorOnGrabHandle(pointerLocation, _handles[1])) { result = GrabHandle.TopMiddle; } else if (IsCursorOnGrabHandle(pointerLocation, _handles[2])) { result = GrabHandle.TopRight; } else if (IsCursorOnGrabHandle(pointerLocation, _handles[3])) { result = GrabHandle.Right; } else if (IsCursorOnGrabHandle(pointerLocation, _handles[4])) { result = GrabHandle.BottomRight; } else if (IsCursorOnGrabHandle(pointerLocation, _handles[5])) { result = GrabHandle.BottomMiddle; } else if (IsCursorOnGrabHandle(pointerLocation, _handles[6])) { result = GrabHandle.BottomLeft; } else if (IsCursorOnGrabHandle(pointerLocation, _handles[7])) { result = GrabHandle.Left; } else { result = GrabHandle.None; } return(result); }
private void BuildPrimaryLayout() { primary_vbox = new VBox(); BuildHeader(); BuildViews(); BuildFooter(); search_entry_align = new Alignment(1.0f, 0.5f, 0f, 0f); var box = new HBox() { Spacing = 2 }; var grabber = new GrabHandle(); var search_entry = view_container.SearchEntry; grabber.ControlWidthOf(search_entry, 150, 350, false); int search_entry_width = SearchEntryWidth.Get(); // -1 indicates that height should be preserved search_entry.SetSizeRequest(search_entry_width, -1); search_entry.SizeAllocated += (o, a) => { SearchEntryWidth.Set(search_entry.Allocation.Width); }; box.PackStart(grabber, false, false, 0); box.PackStart(view_container.SearchEntry, false, false, 0); search_entry_align.Child = box; ActionService.PopulateToolbarPlaceholder(header_toolbar, "/HeaderToolbar/SearchEntry", search_entry_align); search_entry_align.Visible = view_container.SearchSensitive = true; search_entry_align.ShowAll(); primary_vbox.Show(); Add(primary_vbox); }
protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (e.Button != MouseButtons.Left) { return; } if (m_CurrentTool != null && m_CurrentTool is PartSelectionTool && m_SelectedPart != null) { if (m_GrabHandle == null) { m_SelectedPart.Location = AlignToGrid(new PointF(e.X - m_SelectionOffset.X, e.Y - m_SelectionOffset.Y)); } else { m_GrabHandle.Location = AlignToGrid(new PointF(e.X - m_SelectionOffset.X, e.Y - m_SelectionOffset.Y)); } m_GrabHandle = null; UpdateBackground(); UpdateDrawing(); Invalidate(); } }
/// <summary> /// Reset all rectangles in canvas /// </summary> private void RefreshCanvas() { path = new GraphicsPath(); toolbox.ResetDrawingTool(); Controls.Remove(toolbox); toolbox.Visible = false; Controls.Remove(manipToolbox); manipToolbox.Visible = false; foreach (GrabHandle handle in Enum.GetValues(typeof(GrabHandle))) { rectangles[handle] = new RectangleF(-5, -5, 7, 7); } selectionRect = new Rectangle(); focusedHandle = GrabHandle.None; foreach (Image img in screenshots.Values) { img.Dispose(); } screenshots.Clear(); if (screenshot != null) { screenshot.Dispose(); screenshot = null; } assets.Clear(); GC.Collect(); }
/// <summary> /// Gets small rectanlges from large /// </summary> /// <param name="rect"></param> /// <param name="node"></param> /// <param name="handleSize"></param> /// <returns></returns> public static PointF GetRectangleBounds(RectangleF rect, GrabHandle node, float handleSize) { float rectWidth = (float)rect.Width - 1; float rectHeight = (float)rect.Height - 1; float rectX = (float)rect.X; float rectY = (float)rect.Y; switch (node) { case GrabHandle.TopLeft: return(new PointF((rectX - handleSize / 2), (rectY - handleSize / 2))); case GrabHandle.TopRight: return(new PointF(rectX + rectWidth - handleSize / 2, rectY - handleSize / 2)); case GrabHandle.TopMid: return(new Point((int)(rectWidth - handleSize / 2) / 2 + (int)rectX, (int)(rectY - handleSize / 2))); case GrabHandle.MidLeft: return(new PointF((int)(rectX - handleSize / 2), (int)(rectHeight / 2f + rectY - handleSize / 2f))); case GrabHandle.MidRight: return(new Point((int)(rectX + rectWidth - handleSize / 2), (int)((rectHeight) / 2f + rectY - handleSize / 2f))); case GrabHandle.BottomLeft: return(new PointF(rectX - handleSize / 2, rectY + rectHeight - handleSize / 2)); case GrabHandle.BottomMid: return(new Point((int)((rectWidth - handleSize / 2) / 2 + rectX), (int)(rectY + rectHeight - handleSize / 2))); case GrabHandle.BottomRight: return(new PointF(rectX + rectWidth - handleSize / 2, rectY + rectHeight - handleSize / 2)); } return(new PointF(0, 0)); }
/// <summary> /// Logic when selection draw starts /// drawing /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Canvas_MouseDown(object sender, MouseEventArgs e) { drawBorders = true; drawHandles = true; mouseDown = true; switch (currDrawingTool) { case DrawingTool.Arrow: bool inPos = false; foreach (GrabHandle handle in Enum.GetValues(typeof(GrabHandle))) { if (rectangles[handle].Contains(e.Location)) { inPos = true; focusedHandle = handle; break; } } if (inPos) { rectState = RectangleState.Resize; } else if (selectionRect.Contains(e.Location) && !inPos) { rectState = RectangleState.Move; } else { rectState = RectangleState.Draw; toolbox.Visible = false; manipToolbox.Visible = false; path = new GraphicsPath(); } break; case DrawingTool.Circle: var circle = new Asset() { BorderWidth = currBorderWidth, Color = toolbox.SelectedColor, Shape = Shape.Circle, Rectangle = new Rectangle(Cursor.Position.X, Cursor.Position.Y, 0, 0) }; currAsset = circle; break; case DrawingTool.ArrowLine: case DrawingTool.Line: var line = new Asset() { BorderWidth = currBorderWidth, Color = toolbox.SelectedColor, Shape = currDrawingTool == DrawingTool.Line ? Shape.Line : Shape.ArrowLine, LineStart = new Point(e.X, e.Y), LineEnd = new Point(e.X, e.Y) }; currAsset = line; break; case DrawingTool.Pen: var pen = new Asset() { BorderWidth = currBorderWidth, Color = toolbox.SelectedColor, Shape = Shape.Pen, Points = new List <PointF>() }; pen.Points.Add(e.Location); currAsset = pen; break; case DrawingTool.Rectangle: var rectangle = new Asset() { BorderWidth = currBorderWidth, Color = toolbox.SelectedColor, Shape = Shape.Rectangle, Rectangle = new RectangleF(Cursor.Position.X, Cursor.Position.Y, 0, 0) }; currAsset = rectangle; break; case DrawingTool.Text: break; } pX = e.X; pY = e.Y; pnlDraw.Invalidate(Rectangle.Round(path.GetBounds())); }