} //bool DragRectEnable() /// <summary> /// 计算指定坐标在对象中的区域 -1:在对象区域中,0-7:在对象的某个拖拉矩形中,-2:不在对象中或不需要进行拖拽操作 /// </summary> /// <param name="x">X坐标</param> /// <param name="y">Y坐标</param> /// <returns>控制号</returns> public DragPointStyle DragHit(int x, int y) { if (bolCanResize == false && myBounds.Contains(x, y)) { return(DragPointStyle.Move); } for (int iCount = 0; iCount < 8; iCount++) { if (myDragRect[iCount].Contains(x, y)) { if (this.DragRectEnable((DragPointStyle)iCount)) { return((DragPointStyle)iCount); } else { return(DragPointStyle.None); } } } if (myBounds.Contains(x, y) && bolCanMove) { return(DragPointStyle.Move); } else { return(DragPointStyle.None); } }
private Form _FormAt(System.Drawing.Point mousePosition) { for (int i = Forms.Count - 1; i >= 0; i--) { if (Forms[i].TopMost && Forms[i].Visible && Forms[i].Enabled) { var formRect = new System.Drawing.Rectangle(Forms[i].Location.X, Forms[i].Location.Y, Forms[i].Width, Forms[i].Height); if (formRect.Contains(mousePosition)) { return(Forms[i]); } } } for (int i = Forms.Count - 1; i >= 0; i--) { if (Forms[i].TopMost == false && Forms[i].Visible && Forms[i].Enabled) { var formRect = new System.Drawing.Rectangle(Forms[i].Location.X, Forms[i].Location.Y, Forms[i].Width, Forms[i].Height); if (formRect.Contains(mousePosition)) { return(Forms[i]); } } } return(null); }
public void Render(Aurigma.GraphicsMill.Bitmap canvas, float zoom, System.Drawing.Rectangle viewport, System.Drawing.Rectangle renderingRegion) { if (viewport.Width < 1 || viewport.Height < 1 || renderingRegion.Width < 1 || renderingRegion.Height < 1) { return; } if (canvas == null) { throw new System.ArgumentNullException("canvas"); } if (canvas.IsEmpty) { throw new System.ArgumentException(StringResources.GetString("ExStrBitmapCannotBeEmpty"), "canvas"); } if (!viewport.Contains(renderingRegion)) { throw new System.ArgumentException(StringResources.GetString("ExStrRenderingRegionShouldBeInsideViewport"), "renderingRegion"); } System.Drawing.Rectangle viewportInvalidatedRect = CoordinateMapper.WorkspaceToControl(this.InvalidatedRegion, zoom, System.Drawing.Point.Empty, Aurigma.GraphicsMill.Unit.Point, _renderingResolution); if (renderingRegion.IntersectsWith(viewportInvalidatedRect) || !_viewportCache.IsEntirelyInCache(zoom, renderingRegion)) { BuildUpViewportImage(canvas, zoom, viewport, viewportInvalidatedRect); this.InvalidatedRegion = System.Drawing.RectangleF.Empty; _viewportCache.UpdateCache(canvas, zoom, viewport); } else { System.Diagnostics.Debug.Assert(_viewportCache.IsEntirelyInCache(zoom, renderingRegion), "At this point we should already have actual image in cache."); _viewportCache.DrawCached(canvas, zoom, viewport, renderingRegion); } }
/// <summary> /// Find laser-plane through RANSAC /// </summary> /// <param name="context">Context</param> /// <param name="plane">Found plane</param> /// <returns>Success</returns> public bool FindLaserPlane(Bundle bundle) { BundleBookmarks b = new BundleBookmarks(bundle); List <System.Drawing.PointF> laser_pixels = b.LaserPixel; List <Ray> eye_rays = b.EyeRays; System.Drawing.Rectangle roi = b.ROI; List <Ray> rays; Console.WriteLine("value {0}", _only_out_of_roi); if (_only_out_of_roi) { rays = new List <Ray>(); for (int i = 0; i < laser_pixels.Count; ++i) { if (!roi.Contains(laser_pixels[i])) { rays.Add(eye_rays[i]); } } } else { rays = eye_rays; } if (rays.Count == 0) { return(false); } Vector[] isect; double[] ts; int[] plane_ids; IList <Plane> reference_planes = b.ReferencePlanes; Core.Intersection.FindEyeRayPlaneIntersections( rays.ToArray(), reference_planes.ToArray(), out ts, out isect, out plane_ids); Ransac <PlaneModel> ransac = new Ransac <PlaneModel>(isect); int min_consensus = (int)Math.Max(rays.Count * _min_consensus_precent, b.Image.Width * 0.05); _constraint.Bundle = bundle; Ransac <PlaneModel> .Hypothesis h = ransac.Run(_max_iterations, _plane_accurracy, min_consensus, _constraint); if (h != null) { b.LaserPlane = h.Model.Plane; return(true); } else { return(false); } }
/// <summary> /// Collect the current data from the device (using WinForms.Cursor) /// </summary> public override void GetCmdData(string cmd, out int data) { System.Drawing.Point cPt = Cursor.Position; // somewhere on all screens if (m_targetRect.Contains(cPt)) { cPt = cPt - new System.Drawing.Size(m_targetRect.X, m_targetRect.Y); // move the point relative to the target rect origin switch (cmd) { case "maxis_x": data = (int)(2000 * cPt.X / m_targetRect.Width) - 1000; break; // data should be -1000..1000 case "maxis_y": data = -1 * ((int)(2000 * cPt.Y / m_targetRect.Height) - 1000); break; // data should be -1000..1000 default: data = 0; break; } } else { data = 0; } System.Diagnostics.Debug.Print(string.Format("C:({0})-T({1})({2}) - data: {3}", Cursor.Position.ToString( ), m_targetRect.Location.ToString( ), m_targetRect.Size.ToString( ), data.ToString( ))); }
private void ListView1_QueryContinueDrag(object sender, QueryContinueDragEventArgs e) { if (e.Action == DragAction.Drop) { System.Drawing.Rectangle rect = form.ClientRectangle; rect.X -= 5; rect.Y -= 35; rect.Width += 10; rect.Height += 40; if (rect.Contains(form.PointToClient(Control.MousePosition))) { return; } System.Diagnostics.Debug.WriteLine("drag continue " + e.Action); if (deleteFiles) { listView1.SuspendLayout(); foreach (var item in listView1.SelectedItems) { listView1.Items.Remove(item); } listView1.ResumeLayout(); } deleteFiles = false; } }
//Handle mouse movement private void onMouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (mouseDown && e.Button == System.Windows.Forms.MouseButtons.Left) { if (stim1.Contains(e.Location)) { offset.X = e.X - prevLoc.X; offset.Y = e.Y - prevLoc.Y; prevLoc = e.Location; stim1.Offset(offset); } else if (stim2.Contains(e.Location)) { offset.X = e.X - prevLoc.X; offset.Y = e.Y - prevLoc.Y; prevLoc = e.Location; stim2.Offset(offset); } else if (stim3.Contains(e.Location)) { offset.X = e.X - prevLoc.X; offset.Y = e.Y - prevLoc.Y; prevLoc = e.Location; stim3.Offset(offset); } else if (stim4.Contains(e.Location)) { offset.X = e.X - prevLoc.X; offset.Y = e.Y - prevLoc.Y; prevLoc = e.Location; stim4.Offset(offset); } } }
/// <summary> /// Count the number of black/white transitions for a single ellipse /// </summary> /// <param name="e">Ellipse</param> /// <param name="matrix">Affine ellipse frame that transforms the ellipse to a circle located at origin</param> /// <param name="gray">Binary image</param> /// <returns>The number of black/white transitions found</returns> private int CountBinaryTransitions(DetectedEllipse e, Matrix matrix, Emgu.CV.Image <Gray, byte> gray) { // Generate points on circle double r = e.Ellipse.MCvBox2D.size.Height * 0.5; double t_step = (2 * Math.PI) / _number_circle_points; System.Drawing.Rectangle rect = new System.Drawing.Rectangle(System.Drawing.Point.Empty, gray.Size); int count_transitions = 0; double last_intensity = 0; for (double t = 0; t <= 2 * Math.PI; t += t_step) { Vector v = new Vector(new double[] { r *Math.Cos(t), r * Math.Sin(t), 1.0 }); Vector x = matrix.Multiply(v.ToColumnMatrix()).GetColumnVector(0); System.Drawing.Point p = new System.Drawing.Point((int)Math.Round(x[0]), (int)Math.Round(x[1])); if (rect.Contains(p)) { if (t == 0) { last_intensity = gray[p].Intensity; } else { double i = gray[p].Intensity; if (i != last_intensity) { count_transitions += 1; last_intensity = i; } } } } return(count_transitions); }
private void srcBox_MouseDown(object sender, MouseEventArgs e) { if (currentImages != null) { if (e.Button == MouseButtons.Left) { System.Drawing.Rectangle dst = new System.Drawing.Rectangle(0, 0, 1, 1); for (int i = 0; i < currentImages.getDstImageCount(); i++) { Image srcImage = currentImages.getDstImage(i); if (srcImage != null && srcImage.killed == false) { dst.X = srcImage.x; dst.Y = srcImage.y; dst.Width = srcImage.getWidth(); dst.Height = srcImage.getHeight(); if (dst.Contains(e.X, e.Y)) { currentImageRect = dst; currentImageIndex = i; pictureBox1.Refresh(); break; } } } } } }
//Finds what window the gaze/fixation was on public static List <string> whichWindowWasInteresting(System.Drawing.Point gazePoint) { List <string> windows = new List <string>(); var windowDict = new List <Tuple <HWND, Tuple <string, OpenWindowGetter.WINDOWPLACEMENT> > >(); //Adapted from same reference in the class "OpenWindowGetter" //Compare gaze data to open window locations foreach (KeyValuePair <HWND, Tuple <string, OpenWindowGetter.WINDOWPLACEMENT> > window in OpenWindowGetter.GetOpenWindows()) { //extract values IntPtr handle = window.Key; string title = window.Value.Item1; System.Drawing.Rectangle location = window.Value.Item2.rcNormalPosition; //see if gaze location overlaps with an open window bool sameLocation = location.Contains(gazePoint); //Add to return list if the gaze/fixation was in the same location as the active window if (sameLocation) { windows.Add(title); windowDict.Add(new Tuple <HWND, Tuple <string, OpenWindowGetter.WINDOWPLACEMENT> >(handle, window.Value)); } } //if there's more than one window, try to narrow down which window is actually visible to the user if (windows.Count > 1) { return(OpenWindowGetter.getWindowOfFixation(windowDict)); } return(windows); }
/* * Event Listeners */ private void value_Resize(object sender, EventArgs e) { System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, _panel._scrolledPanel.Size.Width, _panel._scrolledPanel.Size.Height); if (!rect.Contains(((Control)sender).Bounds)) { _panel.UpdateScroll(); } }
/// <summary> /// Set the magnifier to the given x/y position relative to expanded original backing image (with added border) /// </summary> private void UpdateMagnifierLocation(int x, int y) { try { magnifierPosition.X = x; magnifierPosition.Y = y; // bounds checks if (magnifierPosition.X < MagnifyRadius) { magnifierPosition.X = (int)(MagnifyRadius); } else if (magnifierPosition.X >= this.EC.DataContext.Screenshot.Width + (int)(MagnifyRadius)) { magnifierPosition.X = this.EC.DataContext.Screenshot.Width + (int)(MagnifyRadius); } if (magnifierPosition.Y < MagnifyRadius) { magnifierPosition.Y = (int)(MagnifyRadius); } else if (magnifierPosition.Y >= this.EC.DataContext.Screenshot.Height + (int)(MagnifyRadius)) { magnifierPosition.Y = this.EC.DataContext.Screenshot.Height + (int)(MagnifyRadius); } // update listener with point relative to original image (sanity bounds check) var pointOrigCoords = new System.Drawing.Point((int)(magnifierPosition.X - MagnifyRadius), (int)(magnifierPosition.Y - MagnifyRadius)); if (pointOrigCoords.X >= 0 && pointOrigCoords.X < this.EC.DataContext.Screenshot.Width && pointOrigCoords.Y >= 0 && pointOrigCoords.Y < this.EC.DataContext.Screenshot.Height) { HoverPositionChanged?.Invoke(pointOrigCoords); } var magnifyRect = new System.Drawing.Rectangle(magnifierPosition.X - MagnifyRadius, magnifierPosition.Y - MagnifyRadius, MagnifyRadius * 2, MagnifyRadius * 2); // Update the magnified image and change margin so it is in the right place var backgroundRect = new System.Drawing.Rectangle(new System.Drawing.Point(0, 0), background.Size); if (backgroundRect.Contains(magnifyRect)) { scaledBackground = this.background.Clone(magnifyRect, this.background.PixelFormat); magimage.Source = scaledBackground.ConvertToSource(); var scaledMagWidth = ScaleFactor * MagnifyRadius; var scaledMagHeight = ScaleFactor * MagnifyRadius; magborder.Margin = new Thickness((magnifierPosition.X / backgroundImageScale) - scaledMagWidth - 1, (magnifierPosition.Y / backgroundImageScale) - scaledMagHeight - 1, 0, 0); } } catch (NullReferenceException e) { e.ReportException(); } catch (ArgumentNullException e) { e.ReportException(); } }
/// <summary> /// Returns true if cache is actual for specified zoom and cached region contains entire specified rectangle. /// </summary> public bool IsEntirelyInCache(float zoom, System.Drawing.Rectangle rect) { if (zoom != _zoom || _image == null) { return(false); } return(_viewport.Contains(rect)); }
public void Select(ref Rectangle rect, ref List <InteractiveObject2D> result) { foreach (InteractiveObject2D obj in list) { if (rect.Contains(obj.rect) || rect.IntersectsWith(obj.rect)) { result.Add(obj); } } }
private bool IsInVideoField(double offsetX, double offsetY) { var v = ViewTimeline; var s = CurrentSubtitleWraper; var posWrap = CurrentSubtitleWraper.TranslatePoint(new Point(0, 0), Clips); var posClip = ViewTimeline.TranslatePoint(new Point(0, 0), Clips); var VideoBoundingBox = new System.Drawing.Rectangle((int)posClip.X, (int)posClip.Y, (int)v.ActualWidth, (int)v.ActualHeight); var SubBox = new System.Drawing.Rectangle((int)(posWrap.X + offsetX), (int)(posWrap.Y + offsetY), (int)s.ActualWidth, (int)s.ActualHeight); return(VideoBoundingBox.Contains(SubBox)); }
/* * Overridden Panels */ public override void Add(Control value) { _scrolledPanel.Controls.Add(value); System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, _panel._scrolledPanel.Size.Width, _panel._scrolledPanel.Size.Height); if (!rect.Contains(value.Bounds)) { _panel.UpdateScroll(); } value.Resize += new EventHandler(value_Resize); }
private void dgIcons_MouseMove(object sender, MouseEventArgs e) { if ((e.Button & MouseButtons.Left) == MouseButtons.Left) { // If the mouse moves outside the rectangle, start the drag. if (dragBoxFromMouseDown != System.Drawing.Rectangle.Empty && !dragBoxFromMouseDown.Contains(e.X, e.Y)) { // Proceed with the drag and drop, passing in the list item. DragDropEffects dropEffect = dgIcons.DoDragDrop(valueFromMouseDown, DragDropEffects.Copy); } } }
internal bool isContainedElement(ElementWrapper elementWrapper) { if (elementWrapper == null) { return(false); } // The element in question must be a direct child of the regions owning element if (elementWrapper.wrappedElement.ParentID != redefinedElement.wrappedElement.ElementID) { return(false); } if (partition != null) { // Check if the element in question resides inside the graphical representation of this region //-------------------------------------------------------------------------------------------- if (masterDiagram != null) { // Get the element in question's graphical representation from the master diagram global::EA.DiagramObject elementDiagramObject = getMasterDiagramObject(elementWrapper); if (elementDiagramObject != null) { System.Drawing.Rectangle elementRectangle = new System.Drawing.Rectangle (elementDiagramObject.left , System.Math.Abs(elementDiagramObject.top) , elementDiagramObject.right - elementDiagramObject.left , System.Math.Abs(elementDiagramObject.bottom) - System.Math.Abs(elementDiagramObject.top) ); // Get the owning elements graphical region representation from the master diagram global::EA.DiagramObject owningElementDiagramObject = getMasterDiagramObject(redefinedElement); if (owningElementDiagramObject != null) { int x = owningElementDiagramObject.left; int y = System.Math.Abs(owningElementDiagramObject.top) + getRegionTopOffset(partition); int width = owningElementDiagramObject.right - x; int height = partition.Size; System.Drawing.Rectangle regionRectangle = new System.Drawing.Rectangle(x, y, width, height); if (regionRectangle.Contains(elementRectangle)) { return(true); } } } } } else { return(true); } return(false); }
private void OnMoveDialogAway(object?sender, PointEventArgs e) { if (this.Host == null) { return; } const int triggerMargin = 64; // First, we check if the current position is hiding the selection or not var current = new System.Drawing.Rectangle( (int)this.Host.Left - triggerMargin, (int)this.Host.Top - triggerMargin, (int)this.Host.Width + 2 * triggerMargin, (int)this.Host.Height + 2 * triggerMargin); if (!current.Contains(e.Data)) { return; } // We simply try to put the dialog in one of the four corners of the main window, until we find one // which does not hide the selection const int margin = 32; var owner = this.Host.Owner; for (var i = 0; i < 2; ++i) { for (var j = 0; j < 2; ++j) { var left = j == 0 ? owner.Left + margin : owner.Left + owner.Width - this.Host.Width - margin; var top = i == 0 ? owner.Top + margin : owner.Top + owner.Height - this.Host.Height - margin; var r = new System.Drawing.Rectangle( (int)left, (int)top, (int)this.Host.Width, (int)this.Host.Height); if (r.Contains(e.Data)) { continue; } this.Host.Left = left; this.Host.Top = top; return; } } }
/// <summary> /// Returns the text zones that are contained within the rectangle /// </summary> /// <param name="rectangle"></param> /// <returns></returns> public TextZone[] SearchForText(System.Drawing.Rectangle rectangle) { if (Children.Count() == 0 && ZoneType == ZoneTypes.Word) { if (rectangle.Contains(Rectangle)) { return(new TextZone[] { this }); } } // Search the children for the text return(Children.SelectMany(x => x.SearchForText(rectangle)).ToArray()); }
/// <summary> /// Returns the text zones that are contained within the rectangle /// </summary> /// <param name="rectangle"></param> /// <returns></returns> public TextZone[] OrientedSearchForText(System.Drawing.Rectangle rectangle, int pageHeight) { if (Children.Length == 0 && ZoneType == ZoneTypes.Word) { if (rectangle.Contains(Rectangle.OrientRectangle(pageHeight))) { return(new TextZone[] { this }); } } // Search the children for the text return(Children.SelectMany(x => x.OrientedSearchForText(rectangle, pageHeight)).ToArray()); }
//------------------------------------------------------------------- public static ControlContainerInterface getUnderMouse(ControlContainerInterface _ignore) { clean(); System.Drawing.Point pos = Cursor.Position; List <ControlContainerInterface> solutions = new List <ControlContainerInterface>(); foreach (ControlContainerInterface i in Singleton) { Control ctrl = i.GetControl(); if (ctrl == null) { continue; } if (ctrl == _ignore) { continue; } System.Drawing.Rectangle R = ctrl.Bounds; R = ctrl.RectangleToScreen(R); if (R.Contains(pos)) { solutions.Add(i); } } if (solutions.Count == 0) { return(null); } if (solutions.Count == 1) { return(solutions[0]); } int bestResult = GetZOrder(solutions[0].GetControl()); ControlContainerInterface bestSolution = null; foreach (ControlContainerInterface i in solutions) { int z = GetZOrder(i.GetControl()); if (z < bestResult) { bestResult = z; bestSolution = i; } } return(bestSolution); }
// this is the new wndproc, just show a messagebox on left button down: private IntPtr MyWndProc(IntPtr hWnd, int msg, int wParam, int lParam) { //is this a message for us? if (((msg == (int)WM_LBUTTONDOWN) || (msg == (int)WM_LBUTTONUP)) && (this._mIsStartButtonDisabled || this._mIsCloseButtonDisabled)) { int x = ((int)lParam) & 0xFFFF; int y = ((int)lParam) >> 16; bool isVGA; bool isQVGA; using (System.Windows.Forms.Control detector = new System.Windows.Forms.Control()) { using (System.Drawing.Graphics gr = detector.CreateGraphics()) { isVGA = gr.DpiY == 192; isQVGA = gr.DpiY == 96; } } RECT rect; GetWindowRect(hWnd, out rect); //get the rectangle of the menu_bar int width = Math.Max(rect.Left, rect.Right) - Math.Min(rect.Left, rect.Right); int height = Math.Max(rect.Bottom, rect.Top) - Math.Min(rect.Bottom, rect.Top); //width values are assumed int buttonWidth = (isQVGA | isVGA) ? 92 : 46; int buttonHeight = height; //(isQVGA | isVGA) ? 72 : 36; System.Drawing.Rectangle rectStartButton = new System.Drawing.Rectangle(0, 0, buttonWidth, buttonHeight); System.Drawing.Rectangle rectCloseButton = new System.Drawing.Rectangle(width - buttonWidth, 0, buttonWidth, buttonHeight); //check if enabled and click is inside the start or close button rectangle if (this._mIsStartButtonDisabled && rectStartButton.Contains(x, y)) { return(IntPtr.Zero); } if (this._mIsCloseButtonDisabled && rectCloseButton.Contains(x, y)) { return(IntPtr.Zero); } //if both are false, we have to provide the click to windows return(CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam)); } else { return(CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam)); } }
public HitTestResult HitTest(Point pt) { if (TimeLine.Contains(pt)) { return new HitTestResult() { Area = ViewArea.Timeline } } ; else if (TopDate.Contains(pt)) { return new HitTestResult() { Area = ViewArea.TopDate } } ; else if (BottomDate.Contains(pt)) { return new HitTestResult() { Area = ViewArea.BottomDate } } ; else if (TopDrag.Contains(pt)) { return new HitTestResult() { Area = ViewArea.TopDrag } } ; else if (BottomDrag.Contains(pt)) { return new HitTestResult() { Area = ViewArea.BottomDrag } } ; else { return new HitTestResult() { Area = ViewArea.None } }; }
public virtual bool HitTest(System.Drawing.Rectangle rect) {//is this object contained within the supplied rectangle System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix(); gp.AddRectangle(new System.Drawing.Rectangle(this.m_Position.X, this.m_Position.Y, this.m_Size.Width, this.m_Size.Height)); if (this.m_Rotation != 0) { myMatrix.RotateAt((float)this.m_Rotation, new System.Drawing.PointF((float)this.m_Position.X, (float)this.m_Position.Y), System.Drawing.Drawing2D.MatrixOrder.Append); } gp.Transform(myMatrix); System.Drawing.Rectangle gpRect = System.Drawing.Rectangle.Round(gp.GetBounds()); return(rect.Contains(gpRect)); }
// Technique from https://stackoverflow.com/a/17610347/5583585 protected override void WndProc(ref Message m) { const int WM_LBUTTONDOWN = 0x201; const int WM_LBUTTONUP = 0x202; const int WM_LEFTDBLCLICK = 0x203; const int WM_PARENTNOTIFY = 0x210; var handleClick = false; switch (m.Msg) { case WM_LBUTTONDOWN: break; case WM_LBUTTONUP: handleClick = true; break; case WM_PARENTNOTIFY: if ((int)m.WParam == WM_LBUTTONDOWN) { handleClick = true; } break; case WM_LEFTDBLCLICK: handleClick = true; break; } if (handleClick) { var activationControl = this.clbProjects.Tag as Control; // Fix up to include the scrollbar in the ClientRectangle var fixedClientRectangle = new System.Drawing.Rectangle(this.clbProjects.ClientRectangle.X, this.clbProjects.ClientRectangle.Y, this.clbProjects.Bounds.Width, this.clbProjects.Bounds.Height); if (!fixedClientRectangle.Contains(this.clbProjects.PointToClient(Cursor.Position))) { // If the activating control was clicked then we let it handle showing/hiding the child control if (activationControl == null || !activationControl.ClientRectangle.Contains(activationControl.PointToClient(Cursor.Position))) { this.clbProjects.Visible = false; } } } base.WndProc(ref m); }
public bool IsCursorInside(System.Drawing.Rectangle screenBounds) { if (overlayWindowI != null) { var screenPos = System.Windows.Forms.Cursor.Position; bool isInside = screenBounds.Contains(screenPos.X, screenPos.Y); if (isInside) { return(true); } } return(false); }
private Control _ControlAt(System.Drawing.Point mousePosition) { if (Contexts.Count > 0) { var lastContext = Contexts.Last(); var cRect = new System.Drawing.Rectangle(lastContext.Location.X, lastContext.Location.Y, lastContext.Width, lastContext.Height); if (cRect.Contains(mousePosition)) { return(lastContext); } } if (ModalForms.Count > 0) { var lastModalForm = ModalForms.Last(); var formRect = new System.Drawing.Rectangle(lastModalForm.Location.X, lastModalForm.Location.Y, lastModalForm.Width, lastModalForm.Height); if (formRect.Contains(mousePosition)) { return(lastModalForm); } return(null); } for (int i = Forms.Count - 1; i >= 0; i--) { if (Forms[i].TopMost && Forms[i].Visible && Forms[i].Enabled) { var formRect = new System.Drawing.Rectangle(Forms[i].Location.X, Forms[i].Location.Y, Forms[i].Width, Forms[i].Height); if (formRect.Contains(mousePosition)) { return(Forms[i]); } } } for (int i = Forms.Count - 1; i >= 0; i--) { if (Forms[i].TopMost == false && Forms[i].Visible && Forms[i].Enabled) { var formRect = new System.Drawing.Rectangle(Forms[i].Location.X, Forms[i].Location.Y, Forms[i].Width, Forms[i].Height); if (formRect.Contains(mousePosition)) { return(Forms[i]); } } } return(null); }
private void Window_LocationChanged(object sender, EventArgs e) { var currentScreen = WinForms.Screen.FromHandle(new WindowInteropHelper(this).Handle).Bounds; var window = new System.Drawing.Rectangle((int)Left, (int)Top, (int)Width, (int)Height); var topHalf = new System.Drawing.Rectangle(currentScreen.X, currentScreen.Y, currentScreen.Width, currentScreen.Height / 2); if (topHalf.Contains(window)) { DockPanel.SetDock(ContentGrid, Dock.Top); DockPanel.SetDock(TitlebarDockPanel, Dock.Bottom); } else { DockPanel.SetDock(ContentGrid, Dock.Bottom); DockPanel.SetDock(TitlebarDockPanel, Dock.Top); } }
private bool _IsHovered(Control control, System.Drawing.Point mousePosition) { if (control == null) { return(false); } var mouseToClient = control.PointToClient(mousePosition); var controlForm = GetRootControl(control); if (control.Context || (controlForm != null && controlForm == _ControlAt(mousePosition))) { if (control.Context == false) { for (int i = 0; i < Contexts.Count; i++) { var contextControl = Contexts[i]; if (contextControl == controlForm) { continue; } var contextRect = new System.Drawing.Rectangle(contextControl.Location.X, contextControl.Location.Y, contextControl.Width, contextControl.Height); if (contextRect.Contains(mousePosition)) { return(false); } } } if (control.ClientRectangle.Contains(mouseToClient)) { if (control.mouseEntered == false) { control.mouseEntered = true; control.RaiseOnMouseEnter(new MouseEventArgs(MouseButtons.None, 0, mouseToClient.X, mouseToClient.Y, 0)); HoveredControls.Add(control); } control.hovered = true; control.RaiseOnMouseHover(new MouseEventArgs(MouseButtons.None, 0, mouseToClient.X, mouseToClient.Y, 0)); return(true); } } return(false); }
public FadingTextField(string s, Vector2 position, Vector2 velocity, Rectangle rect, Func<FadingTextField, Task> remove) { Text = new Text(s, position, Color.White); Velocity = new Vector3(velocity, 0); var every = TimeSpan.FromSeconds(1 / 30.0); Unsubscribe = Observable.Timer(TimeSpan.Zero, every) .TimeInterval() .Subscribe(t => { Text.Position += Velocity * (float)t.Interval.TotalSeconds; if (!rect.Contains((int)Text.Position.X, (int)Text.Position.Y)) { remove(this); if (Unsubscribe != null) Unsubscribe.Dispose(); } }); }
/// <summary> /// Count the number of black/white transitions for a single ellipse /// </summary> /// <param name="e">Ellipse</param> /// <param name="matrix">Affine ellipse frame that transforms the ellipse to a circle located at origin</param> /// <param name="gray">Binary image</param> /// <returns>The number of black/white transitions found</returns> private int CountBinaryTransitions(DetectedEllipse e, Matrix matrix, Emgu.CV.Image<Gray, byte> gray) { // Generate points on circle double r = e.Ellipse.MCvBox2D.size.Height * 0.5; double t_step = (2 * Math.PI) / _number_circle_points; System.Drawing.Rectangle rect = new System.Drawing.Rectangle(System.Drawing.Point.Empty, gray.Size); int count_transitions = 0; double last_intensity = 0; for (double t = 0; t <= 2 * Math.PI; t += t_step) { Vector v = new Vector(new double[] { r * Math.Cos(t), r * Math.Sin(t), 1.0 }); Vector x = matrix.Multiply(v.ToColumnMatrix()).GetColumnVector(0); System.Drawing.Point p = new System.Drawing.Point((int)Math.Round(x[0]), (int)Math.Round(x[1])); if (rect.Contains(p)) { if (t == 0) { last_intensity = gray[p].Intensity; } else { double i = gray[p].Intensity; if (i != last_intensity) { count_transitions += 1; last_intensity = i; } } } } return count_transitions; }
private Control _ControlAt(System.Drawing.Point mousePosition) { Control control = null; if (Contexts.Count > 0) { for (int i = 0; i < Contexts.Count; i++) { var contextControl = Contexts[i]; var cRect = new System.Drawing.Rectangle(contextControl.Location.X, contextControl.Location.Y, contextControl.Width, contextControl.Height); if (cRect.Contains(mousePosition)) { control = contextControl; break; } } } if (ModalForms.Count > 0) { if (control == null) { var lastModalForm = ModalForms.Last(); var formRect = new System.Drawing.Rectangle(lastModalForm.Location.X, lastModalForm.Location.Y, lastModalForm.Width, lastModalForm.Height); if (formRect.Contains(mousePosition)) control = lastModalForm; } } else { if (control == null) for (int i = Forms.Count - 1; i >= 0; i--) { var form = Forms[i]; if (form.TopMost && form.Visible && form.Enabled) { var formRect = new System.Drawing.Rectangle(form.Location.X, form.Location.Y, form.Width, form.Height); if (formRect.Contains(mousePosition)) { control = form; break; } } } if (control == null) for (int i = Forms.Count - 1; i >= 0; i--) { var form = Forms[i]; if (form.TopMost == false && form.Visible && form.Enabled) { var formRect = new System.Drawing.Rectangle(form.Location.X, form.Location.Y, form.Width, form.Height); if (formRect.Contains(mousePosition)) { control = form; break; } } } } if (control != null) control = FindControlAt(control, mousePosition); return control; }
private void checkOverflow(Basic ctrlFrame) { CtrlDef_T ctrlDef; System.Drawing.Rectangle rectFrame = new System.Drawing.Rectangle( ctrlFrame.m_selScreenX, ctrlFrame.m_selScreenY, ctrlFrame.m_selW, ctrlFrame.m_selH); if (ctrlFrame != null && ctrlFrame.m_xe != null && ctrlFrame.m_xe.Name != "" && CtrlDef_T.isFrame(ctrlFrame.m_xe.Name) == true) { foreach (object item in ctrlFrame.Items) { if (item is Basic) { Basic ctrlItem = (Basic)item; if (ctrlItem.m_xe.GetAttribute("visible") != "false") { System.Drawing.Rectangle rectItem = new System.Drawing.Rectangle( ctrlItem.m_selScreenX, ctrlItem.m_selScreenY, ctrlItem.m_selW, ctrlItem.m_selH); if (ctrlItem.m_xe.Name != "event" && !rectFrame.Contains(rectItem)) { Public.ResultLink.createResult("\r\n[" + ctrlItem.mx_text.Text + "]", Public.ResultType.RT_INFO, ctrlItem); Public.ResultLink.createResult(" 超出了 ", Public.ResultType.RT_INFO); Public.ResultLink.createResult("[" + ctrlFrame.mx_text.Text + "]", Public.ResultType.RT_INFO, ctrlFrame); Public.ResultLink.createResult(" 的范围。", Public.ResultType.RT_INFO, ctrlItem); } checkOverflow(ctrlItem); } } } } }
internal bool isContainedElement(ElementWrapper elementWrapper) { if(elementWrapper == null) { return false; } // The element in question must be a direct child of the regions owning element if(elementWrapper.wrappedElement.ParentID != redefinedElement.wrappedElement.ElementID) { return false; } if(partition != null) { // Check if the element in question resides inside the graphical representation of this region //-------------------------------------------------------------------------------------------- if(masterDiagram != null) { // Get the element in question's graphical representation from the master diagram global::EA.DiagramObject elementDiagramObject = getMasterDiagramObject(elementWrapper); if(elementDiagramObject != null) { System.Drawing.Rectangle elementRectangle = new System.Drawing.Rectangle ( elementDiagramObject.left , System.Math.Abs(elementDiagramObject.top) , elementDiagramObject.right - elementDiagramObject.left , System.Math.Abs(elementDiagramObject.bottom) - System.Math.Abs(elementDiagramObject.top) ); // Get the owning elements graphical region representation from the master diagram global::EA.DiagramObject owningElementDiagramObject = getMasterDiagramObject(redefinedElement); if(owningElementDiagramObject != null) { int x = owningElementDiagramObject.left; int y = System.Math.Abs(owningElementDiagramObject.top) + getRegionTopOffset(partition); int width = owningElementDiagramObject.right - x; int height = partition.Size; System.Drawing.Rectangle regionRectangle = new System.Drawing.Rectangle(x,y,width,height); if(regionRectangle.Contains(elementRectangle)) { return true; } } } } } else { return true; } return false; }
void DelayTimer_Tick(object sender, EventArgs e) { _DelayTimer.Stop(); var t = new Thread(() => { var clonedCurrentItem = this.CurrentItem.Clone(); var tooltip = clonedCurrentItem.ToolTipText; if (String.IsNullOrEmpty(tooltip) && Type == 1) { Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)(this.Hide)); return; } Contents = Type == 0 ? $"{clonedCurrentItem.DisplayName}\r\n{clonedCurrentItem.ToolTipText}" : clonedCurrentItem.ToolTipText; RaisePropertyChanged("Contents"); // BE-557: clonedCurrentItem.GetPropertyValue returned VT_EMPTY, edge case included to handle this var perceivedTypeProperty = clonedCurrentItem.GetPropertyValue( SystemProperties.PerceivedType, typeof(PerceivedType)); if (perceivedTypeProperty.VarType != VarEnum.VT_EMPTY && ((PerceivedType)perceivedTypeProperty.Value) == PerceivedType.Image && !clonedCurrentItem.IsFolder) { var image = clonedCurrentItem.ThumbnailSource( 350, ShellThumbnailFormatOption.Default, ShellThumbnailRetrievalOption.Default); image.Freeze(); this.Image = image; RaisePropertyChanged("Image"); this.FileNameWidth = this.Image.Width - 110; RaisePropertyChanged("FileNameWidth"); try { var ratingValue = clonedCurrentItem.GetPropertyValue(MediaProperties.Rating, typeof(Double)).Value; var rating = ratingValue == null ? 0 : Convert.ToDouble(ratingValue) / 20D; this.Rating = rating; RaisePropertyChanged("Rating"); this.Dimentions = ((Math.Ceiling( Convert.ToDouble(clonedCurrentItem.GetPropertyValue(SystemProperties.FileSize, typeof(double)).Value)) / 1024).ToString("# ### ### ##0") + " KB (" + clonedCurrentItem.GetPropertyValue(MediaProperties.Dimensions, typeof(String)).Value.ToString() + " px )").Trim(); RaisePropertyChanged("Dimentions"); } catch (NullReferenceException) { } this.FileName = Path.GetFileName(clonedCurrentItem.ParsingName)?.Trim(); RaisePropertyChanged("FileName"); } else { var image = clonedCurrentItem.ThumbnailSource( 64, ShellThumbnailFormatOption.Default, ShellThumbnailRetrievalOption.Default); image.Freeze(); this.Image = image; RaisePropertyChanged("Image"); } Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)(() => { var lvi = new LVITEMINDEX(); lvi.iItem = this.ItemIndex; lvi.iGroup = this._View.GetGroupIndex(this.ItemIndex); var bounds = new User32.RECT(); User32.SendMessage(this._View.LVHandle, MSG.LVM_GETITEMINDEXRECT, ref lvi, ref bounds); var rect = new System.Drawing.Rectangle(bounds.Left, bounds.Top, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top); var posm = User32.GetCursorPosition(); var mousePos = this._View.PointToClient(posm); var isInsideItem = rect.Contains(mousePos); if (isInsideItem) this.Show(); else this.Hide(); })); }); t.SetApartmentState(ApartmentState.STA); t.Start(); }
private void dgvChars_MouseMove(object sender, MouseEventArgs e) { // キャラのドラッグ中の操作 if (dragPrevIndexes != null && dragPrevIndexes.Length > 0 && dragStartIndexes != null && dragStartIndexes.Length == dragPrevIndexes.Length && dragHoldRelIndex >= 0) { // 現在のマウスの位置 DataGridView.HitTestInfo hitc = dgvChars.HitTest(e.X, e.Y); // 現在の位置が、有効なセル上を選択している場合 if (hitc.Type == DataGridViewHitTestType.Cell && (dgvChars.NewRowIndex == -1 || dgvChars.NewRowIndex != hitc.RowIndex)) { if (dragPrevIndexes[dragHoldRelIndex] != hitc.RowIndex) { slideChar(dragPrevIndexes, hitc.RowIndex); // ここで dragPrevIndexes の調整もしてしまう //dragPrevIndex = hitc.RowIndex; this.Cursor = Cursors.NoMoveVert; } } else { if (dragPrevIndexes[dragHoldRelIndex] != dragStartIndexes[dragHoldRelIndex]) { //slideChar(dragPrevIndexes, dragStartIndexes); // ここで dragPrevIndexes の調整もしてしまう。オーバーロードで実装 //dragPrevIndex = dragStartIndex; //this.Cursor = Cursors.No; this.Cursor = Cursors.Default; } } } // else があってもいいけどひとつ目の条件から無くてもいい。 if (mouseDownPoint != System.Drawing.Point.Empty && dgvChars.SelectedRows.Count > 0) { //ドラッグとしないマウスの移動範囲を取得する System.Drawing.Rectangle moveRect = new System.Drawing.Rectangle( mouseDownPoint.X - SystemInformation.DragSize.Width / 2, mouseDownPoint.Y - SystemInformation.DragSize.Height / 2, SystemInformation.DragSize.Width, SystemInformation.DragSize.Height); //ドラッグとする移動範囲を超えたか調べる if (!moveRect.Contains(e.X, e.Y)) { DataGridView.HitTestInfo hit = dgvChars.HitTest(mouseDownPoint.X, mouseDownPoint.Y); // ドラッグ元としての指定位置が、有効なセル上を選択している場合 if (hit.Type == DataGridViewHitTestType.Cell && (dgvChars.NewRowIndex == -1 || dgvChars.NewRowIndex != hit.RowIndex)) { // ドラッグ元の行 int ind = hit.RowIndex; // 編集状態であれば解除 gbChars.Focus(); //dgvChars.Rows[dgvChars.SelectedRows[0].Index].Cells[0].Selected = true; // ドラッグスタート位置を記憶 // は、マウスをクリックしたときにやらないと既に解除されていて意味が無い。 //dragStartIndex = dragPrevIndex = ind; //dragStartIndexes = GetSelectedCharsIndexesArray(); Array.Sort(dragStartIndexes); // でもソートは必要。ここでやるのがいいでしょう。 // 掴んでいるのが選択したファイルのうち上から何番目であるかを // ゼロオリジンで記憶 dragHoldRelIndex = -1; for (int i = 0; i < dragStartIndexes.Length; i++) { if (dragStartIndexes[i] == ind) { dragHoldRelIndex = i; break; } } // これは想定外。でもありそう。 if (dragHoldRelIndex < 0) { return; } // 選択されているものを // 掴んでいる前後に寄せ集める for (int dir = -1; dir <= 1; dir += 2) { for (int i = dragHoldRelIndex + dir; i >= 0 && i < dragStartIndexes.Length; i += dir) { var dstIndex = ind + i - dragHoldRelIndex; if (dir * (dstIndex - dragStartIndexes[i]) < 0) { var temp = dlcData.Chars[dragStartIndexes[i]]; dlcData.Chars[dragStartIndexes[i]] = dlcData.Chars[dstIndex]; dlcData.Chars[dstIndex] = temp; } } } // dlcData の変更を表示に反映 for (int i = dragStartIndexes[0]; i <= dragStartIndexes[dragStartIndexes.Length - 1]; i++) { dgvChars.Rows[i].Cells[0].Value = GetCharNamesJpn(dlcData.Chars[i].ID, false);// Program.CharNamesJpn[dlcData.Chars[i].ID]; dgvChars.Rows[i].Cells[1].Value = dlcData.Chars[i].CostumeSlot.ToString(); dgvChars.Rows[i].Cells[2].Value = dlcData.Chars[i].AddTexsCount.ToString(); //dgvChars.Rows[i].Cells[3].Value = dlcData.Chars[i].Comment; showComment(i); } // 選択は連続するが、今後の仕様変更を想定して選択されたものは全て覚えておく dragPrevIndexes = new int[dragStartIndexes.Length]; for (int i = 0; i < dragPrevIndexes.Length; i++) { dragPrevIndexes[i] = ind + i - dragHoldRelIndex; } // コイツが邪魔をするので黙らせる。 dgvChars_SelectionChanged_RepairingSelection = true; // ドラッグ中、DGV の選択機能は全くあてにならないのでその表示が見えないようにする //dgvChars.RowsDefaultCellStyle.SelectionBackColor = System.Drawing.Color.White; //dgvChars.RowsDefaultCellStyle.SelectionForeColor = System.Drawing.Color.Black; // 色づけて擬似的に選択させる // 手動ソート中ということを表すためにちょっとくらい色が違ってもいいのでは。。 ColoringLikeSelection(); /* // 実際にはここの時点で dragPrevIndexes が選択状態になっていないのでそうする // dragPrevIndexes の算出が複雑になったり不要になったりする仕様変更を考慮して上とは別に書いておく dgvChars.ClearSelection(); for (int i = 0; i < dragPrevIndexes.Length; i++) { dgvChars.Rows[dragPrevIndexes[i]].Selected = true; } */ this.Cursor = Cursors.NoMoveVert; //MessageBox.Show(dragStartIndexes.Length.ToString()); // ちょっとドラッグイベントを使うのをやめてみる //DoDragDrop(ind, DragDropEffects.Move); } // ドラッグ元の指定位置が、有効なセル上を選択していない場合 else { // 指定行は、ドラッグ&ドロップの対象ではないので、処理を終了 return; } mouseDownPoint = System.Drawing.Point.Empty; } } }
public override bool Detect(System.Drawing.Point pTest) { SetHieghtAndWidth(); System.Drawing.Rectangle r = new System.Drawing.Rectangle(StartPt.X, StartPt.Y, width, height); return r.Contains(pTest); }