private async void HandleTap(UITapGestureRecognizer sender) { if (isHandlingTap) { return; } try { isHandlingTap = true; SCNView sceneViewTappedOn = sender.View as SCNView; CoreGraphics.CGPoint touchCoordinates = sender.LocationInView(sceneViewTappedOn); SCNHitTestResult[] hitTest = sceneViewTappedOn.HitTest(touchCoordinates, new SCNHitTestOptions()); if (!hitTest.Any()) { return; } SCNNode pressedNode = hitTest.FirstOrDefault().Node; await AnimateNode(pressedNode); RemoveAllNodes(); AddNode(); } finally { isHandlingTap = false; } }
public static void ShowContextMenu(Gtk.Widget parent, int x, int y, NSMenu menu) { if (parent == null) { throw new ArgumentNullException("parent"); } if (menu == null) { throw new ArgumentNullException("menu"); } parent.GrabFocus(); Gtk.Application.Invoke(delegate { // Explicitly release the grab because the menu is shown on the mouse position, and the widget doesn't get the mouse release event Gdk.Pointer.Ungrab(Gtk.Global.CurrentEventTime); var nsview = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView(parent); var toplevel = parent.Toplevel as Gtk.Window; var nswindow = MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow(toplevel); var titleBarHeight = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight(); var pt = new CoreGraphics.CGPoint(x, nswindow.Frame.Height - y - titleBarHeight - 12); var tmp_event = NSEvent.MouseEvent(NSEventType.LeftMouseDown, pt, 0, 0, nswindow.WindowNumber, null, 0, 0, 0); NSMenu.PopUpContextMenu(menu, tmp_event, nsview); }); }
// Create a custom UIButton and add it to the center of our tab bar void AddCenterButton(string buttonImageName) { UIImage buttonImage = UIImage.FromFile(buttonImageName); UIButton button = UIButton.FromType(UIButtonType.Custom); button.AutoresizingMask = UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleTopMargin; UIView item = TabBar.Subviews [TabBar.Subviews.Length / 2]; SizeF itemSize = item.Frame.Size; button.Frame = new RectangleF(0, 0, itemSize.Width, itemSize.Height); button.SetImage(buttonImage, UIControlState.Normal); button.ContentMode = UIViewContentMode.Center; button.TouchUpInside += (sender, e) => ShowModalController(sender as UIButton); float heightDifference = (float)(buttonImage.Size.Height - TabBar.Frame.Height); if (heightDifference < 0) { button.Center = TabBar.Center; } else { PointF center = TabBar.Center; center.Y = center.Y - heightDifference / 2; button.Center = center; } View.AddSubview(button); }
public override UIView HitTest(CoreGraphics.CGPoint point, UIEvent uievent) { UIView hitTestView = base.HitTest(point, uievent); if (LayoutElement.GestureEnabled) { foreach (var child in LayoutElement.Children) { if (child.Bounds.Contains((double)point.X, (double)point.Y)) { var draggable = child as IDrag; if (draggable != null && draggable.DragEnabled) { lastTouchX = point.X; lastTouchY = point.Y; dragMightStart = true; currentDraggable = draggable; return(this); } } } } return(hitTestView); }
protected override void DidScroll(CoreGraphics.CGPoint p) { base.DidScroll(p); _descriptionElement.SetLayout(); _commentsElement.SetLayout(); }
public static void ShowContextMenu (Gtk.Widget parent, int x, int y, NSMenu menu) { if (parent == null) throw new ArgumentNullException ("parent"); if (menu == null) throw new ArgumentNullException ("menu"); parent.GrabFocus (); Gtk.Application.Invoke (delegate { // Explicitly release the grab because the menu is shown on the mouse position, and the widget doesn't get the mouse release event Gdk.Pointer.Ungrab (Gtk.Global.CurrentEventTime); var nsview = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView (parent); var toplevel = parent.Toplevel as Gtk.Window; var nswindow = MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow (toplevel); var titleBarHeight = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight (); var pt = new CoreGraphics.CGPoint (x, nswindow.Frame.Height - y - titleBarHeight - 12); var tmp_event = NSEvent.MouseEvent (NSEventType.LeftMouseDown, pt, 0, 0, nswindow.WindowNumber, null, 0, 0, 0); NSMenu.PopUpContextMenu (menu, tmp_event, nsview); }); }
public static void SetPosition(Control control, Point point, nfloat frameHeight, bool flipped) { var offset = ((IIosView)control.Handler).PositionOffset; var childView = control.GetContainerView(); var preferredSize = control.GetPreferredSize(Size.MaxValue); CoreGraphics.CGPoint origin; if (flipped) { origin = new CoreGraphics.CGPoint( point.X + offset.Width, point.Y + offset.Height ); } else { origin = new CoreGraphics.CGPoint( point.X + offset.Width, frameHeight - (preferredSize.Height + point.Y + offset.Height) ); } var frame = new CoreGraphics.CGRect(origin, preferredSize.ToNS()); childView.Frame = frame; }
public override UIView HitTest(CoreGraphics.CGPoint point, UIEvent uievent) { UIButton but = null; foreach (UIView itemView in Subviews) { foreach (var item in itemView.Subviews) { if (item is UIButton) { if (item.Frame.Contains(point)) { but = item as UIButton; } } } } if (but != null) { but.SendActionForControlEvents(UIControlEvent.TouchUpInside); } else { if (GraphicsViewWorker.StaitcView != null) { GraphicsViewWorker.StaitcView.RemoveFromSuperview(); GraphicsViewWorker.StaitcView = null; } } return(null); }
public static void SetFrameOrigin(this UIView view, CoreGraphics.CGPoint location) { var frame = view.Frame; frame.Location = location; view.Frame = frame; }
public void RefreshChildView() { var pair = this.children.FirstOrDefault(t => t.Key(this.ViewModel)); if (pair.Value == null) { throw new ArgumentNullException("pair.Value", "No ViewController specified."); } var view = this.CreateViewControllerFor(new ProxyViewModelRequest(pair.Value, this.ViewModel)); var controller = (UIViewController)view; var attr = pair.Value.GetCustomAttributes(false).OfType <WrapWithAttribute>().FirstOrDefault(); if (attr != null && attr.With == WrapWithController.NavigationController) { // 64 var point = new CoreGraphics.CGPoint(0, 64); var size = new CoreGraphics.CGSize(controller.View.Frame.Size.Width, controller.View.Frame.Size.Height - point.Y); controller.View.Frame = new CoreGraphics.CGRect(point, size); } this.AddChildViewController(controller); this.View.AddSubview(controller.View); controller.DidMoveToParentViewController(this); }
public MapNode(Map map) { this.map = map; Name = "Map"; UserInteractionEnabled = true; int idx = 0; atlas = SKTextureAtlas.FromName("TileImages"); foreach (var tid in map.TIDs) { Tile t = map.TIDToTile [tid]; CoreGraphics.CGPoint position = map.PositionToPoint(map.IndexToPosition(idx)); SKTexture tex = atlas.TextureNamed(t.ImageName); SKSpriteNode node = SKSpriteNode.FromTexture(tex); node.UserInteractionEnabled = false; node.Position = position; node.ZPosition = idx; node.AnchorPoint = new CoreGraphics.CGPoint(0.5, 0); AddChild(node); idx++; } var nc = NSNotificationCenter.DefaultCenter; nc.AddObserver((NSString)InventoryComponent.ItemCollectedNotification, HandleItemCollected); nc.AddObserver((NSString)InventoryComponent.ItemDroppedNotification, HandleItemDropped); }
public iOSLongPressEventArgs(UILongPressGestureRecognizer gr, long duration, CoreGraphics.CGPoint locationAtStart) { Cancelled = (gr.State == UIGestureRecognizerState.Cancelled || gr.State == UIGestureRecognizerState.Failed); ViewPosition = iOSEventArgsHelper.GetViewPosition(gr.View.Frame); Touches = iOSEventArgsHelper.GetTouches(gr, locationAtStart); Duration = duration; }
/// <summary> /// Indexs the path at point. /// </summary> /// <returns>The path at point.</returns> /// <param name="listView">List view.</param> /// <param name="p">P.</param> public Tuple <int, int> IndexPathAtPoint(Xamarin.Forms.ListView listView, Xamarin.Forms.Point p) { var renderer = Renderer(listView); var point = new CoreGraphics.CGPoint(p.X * Display.Scale, p.Y * Display.Scale); //System.Diagnostics.Debug.WriteLine("size=["+renderer.Control.Frame.Size+"]"); //System.Diagnostics.Debug.WriteLine("point=["+point+"]"); var visibleCells = renderer.Control.VisibleCells; var visibleCellIndexPaths = renderer.Control.IndexPathsForVisibleRows; var scroll = renderer.Control.ContentOffset; //System.Diagnostics.Debug.WriteLine("Scroll=["+scroll+"]"); foreach (var ip in visibleCellIndexPaths) { var cell = renderer.Control.CellAt(ip); var frame = cell.Frame; var frameX = cell.ConvertRectToView(frame, renderer.Control); var frameZ = new CoreGraphics.CGRect(frameX.X - scroll.X * Display.Scale, frameX.Y - scroll.Y * Display.Scale, frameX.Width * Display.Scale, frameX.Height * Display.Scale); //System.Diagnostics.Debug.WriteLine("ip=["+ip+"] frame=[" + frameZ + "]"); if (frameZ.Contains(point)) { return(new Tuple <int, int>(ip.Section, ip.Row)); } } return(null); //System.Diagnostics.Debug.WriteLine(""); //var indexPath = renderer.Control.IndexPathForRowAtPoint(point); //return new Tuple<int, int>(indexPath.Section, indexPath.Row); }
public static Task ScrollToPositionAsync(this NSScrollView scrollView, PointF point, bool animate, double duration = 0.5) { if (!animate) { var nsView = scrollView.DocumentView as NSView; nsView?.ScrollPoint(point); return(Task.FromResult(true)); } TaskCompletionSource <bool> source = new TaskCompletionSource <bool>(); NSAnimationContext.BeginGrouping(); NSAnimationContext.CurrentContext.CompletionHandler += () => { source.TrySetResult(true); }; NSAnimationContext.CurrentContext.Duration = duration; var animator = scrollView.ContentView.Animator as NSView; animator?.SetBoundsOrigin(point); NSAnimationContext.EndGrouping(); return(source.Task); }
public iOSTapEventArgs(UITapGestureRecognizer gr, int numberOfTaps, CoreGraphics.CGPoint locationAtStart) { Cancelled = (gr.State == UIGestureRecognizerState.Cancelled || gr.State == UIGestureRecognizerState.Failed); ViewPosition = iOSEventArgsHelper.GetViewPosition(gr.View.Frame); Touches = iOSEventArgsHelper.GetTouches(gr, locationAtStart); NumberOfTaps = numberOfTaps; }
public iOSPinchEventArgs(UIGestureRecognizer gr, PinchEventArgs previous, CoreGraphics.CGPoint locationAtStart) { Cancelled = (gr.State == UIGestureRecognizerState.Cancelled || gr.State == UIGestureRecognizerState.Failed); ViewPosition = iOSEventArgsHelper.GetViewPosition(gr.View.Frame); Touches = iOSEventArgsHelper.GetTouches(gr, 2, previous, locationAtStart); base.CalculateScales(previous); }
public override void MouseDragged(NSEvent e) { base.MouseDragged(e); CoreGraphics.CGPoint loc = this.Frame.Location; CoreGraphics.CGPoint tl = new CoreGraphics.CGPoint(this.Frame.Top, this.Frame.Left); if (resizeArea.Frame.Contains(e.LocationInWindow)) { Console.WriteLine("Mouse dragged " + e.AbsoluteX.ToString() + " delta " + e.DeltaX.ToString()); tl.X += e.DeltaX; loc.Y -= e.DeltaY; tl.Y += e.DeltaY; this.SetContentSize(new CoreGraphics.CGSize(this.Frame.Width + e.DeltaX, this.Frame.Height + e.DeltaY)); this.SetFrameOrigin(loc); fixResize(); //this.SetFrameTopLeftPoint(tl); } else { loc.X += e.DeltaX; loc.Y -= e.DeltaY; this.SetFrameOrigin(loc); } }
private void HandlerLongPress(UILongPressGestureRecognizer sender) { ARSCNView longPressScene = sender.View as ARSCNView; CoreGraphics.CGPoint longPressLocation = sender.LocationInView(longPressScene); SCNHitTestResult[] hitTest = longPressScene.HitTest(longPressLocation, new SCNHitTestOptions()); if (hitTest?.Any() != true) { return; } SCNNode node = hitTest.First().Node; if (sender.State == UIGestureRecognizerState.Began) { SCNAction rotateAction = SCNAction.RotateBy(0, ConvertDegreesToRadians(360f), 0, 1f); SCNAction rotateForever = SCNAction.RepeatActionForever(rotateAction); node.RunAction(rotateForever); } else if (sender.State == UIGestureRecognizerState.Ended) { node.RemoveAllActions(); } }
private static void PlatformSetPosition(int x, int y) { PrimaryWindow.MouseState.X = x; PrimaryWindow.MouseState.Y = y; var mousePt = NSEvent.CurrentMouseLocation; NSScreen currentScreen = null; foreach (var screen in NSScreen.Screens) { if (screen.Frame.Contains(mousePt)) { currentScreen = screen; break; } } var point = new PointF(x, Window.ClientBounds.Height - y); var windowPt = Window.ConvertPointToView(point, null); var screenPt = Window.Window.ConvertBaseToScreen(windowPt); var flippedPt = new PointF(screenPt.X, currentScreen.Frame.Size.Height - screenPt.Y); flippedPt.Y += currentScreen.Frame.Location.Y; CGSetLocalEventsSuppressionInterval(0.0); CGWarpMouseCursorPosition(flippedPt); CGSetLocalEventsSuppressionInterval(0.25); }
public void MoveEntity(Map.Map.Position destination, Action <bool> completionHandler) { var centity = (Entity)Entity; var comp = (CharacterSpriteComponent)Entity.GetComponent(typeof(CharacterSpriteComponent)); if (comp == null) { return; } GKGraphNode[] path = GameViewController.CurrentScene.CurrentMap.FindPath(centity.Model.StartPosition, destination, false); if (teleportation) { if (path == null) { completionHandler(false); return; } var lastNode = (MapGraphNode)path.Last(); CoreGraphics.CGPoint point = GameViewController.CurrentScene.CurrentMap.PositionToPoint(lastNode.NodePosition, true); comp.Sprite.Position = point; centity.Model.StartPosition = lastNode.NodePosition; comp.Sprite.ZPosition = GameViewController.CurrentScene.CurrentMap.ZLevelForPosition(lastNode.NodePosition); completionHandler(true); } else { FollowPath(path, completionHandler); } }
void UpdatePanGesture() { var model = (MasterDetailPage)Element; if (!model.IsGestureEnabled) { if (_panGesture != null) View.RemoveGestureRecognizer(_panGesture); return; } if (_panGesture != null) { View.AddGestureRecognizer(_panGesture); return; } UITouchEventArgs shouldRecieve = (g, t) => !(t.View is UISlider); var center = new PointF(); _panGesture = new UIPanGestureRecognizer(g => { switch (g.State) { case UIGestureRecognizerState.Began: center = g.LocationInView(g.View); break; case UIGestureRecognizerState.Changed: var currentPosition = g.LocationInView(g.View); var motion = currentPosition.X - center.X; var detailView = _detailController.View; var targetFrame = detailView.Frame; if (Presented) targetFrame.X = (nfloat)Math.Max(0, _masterController.View.Frame.Width + Math.Min(0, motion)); else targetFrame.X = (nfloat)Math.Min(_masterController.View.Frame.Width, Math.Max(0, motion)); detailView.Frame = targetFrame; break; case UIGestureRecognizerState.Ended: var detailFrame = _detailController.View.Frame; var masterFrame = _masterController.View.Frame; if (Presented) { if (detailFrame.X < masterFrame.Width * .75) Presented = false; else LayoutChildren(true); } else { if (detailFrame.X > masterFrame.Width * .25) Presented = true; else LayoutChildren(true); } break; } }); _panGesture.ShouldReceiveTouch = shouldRecieve; _panGesture.MaximumNumberOfTouches = 2; View.AddGestureRecognizer(_panGesture); }
/** Creates new MetaState */ public MetaState() { savedStates = new Stack(); MetaObjects = new ArrayList(); currentPoint = new CoreGraphics.CGPoint(0, 0); currentPen = new MetaPen(); currentBrush = new MetaBrush(); currentFont = new MetaFont(); }
public static void ShowContextMenu(Gtk.Widget parent, int x, int y, NSMenu menu, bool selectFirstItem = false) { if (parent == null) { throw new ArgumentNullException("parent"); } if (menu == null) { throw new ArgumentNullException("menu"); } parent.GrabFocus(); Gtk.Application.Invoke((o, args) => { // Explicitly release the grab because the menu is shown on the mouse position, and the widget doesn't get the mouse release event Gdk.Pointer.Ungrab(Gtk.Global.CurrentEventTime); var nsview = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView(parent); var toplevel = parent.Toplevel as Gtk.Window; var nswindow = MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow(toplevel); int titleBarOffset; if (toplevel.TypeHint == Gdk.WindowTypeHint.Toolbar && toplevel.Type == Gtk.WindowType.Toplevel && toplevel.Decorated == false) { // Undecorated toplevel toolbars are used for auto-hide pad windows. Don't add a titlebar offset for them. titleBarOffset = 0; } else if (MonoDevelop.Ide.DesktopService.GetIsFullscreen(toplevel)) { titleBarOffset = 0; } else { titleBarOffset = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight() + 12; } parent.TranslateCoordinates(parent.Toplevel, x, y, out x, out y); if (selectFirstItem) { var pt = new CoreGraphics.CGPoint(x, y); lastOpenPositon = pt; menu.PopUpMenu(menu.ItemAt(0), pt, nsview); } else { var pt = new CoreGraphics.CGPoint(x, nswindow.Frame.Height - y - titleBarOffset); lastOpenPositon = pt; var tmp_event = NSEvent.MouseEvent(NSEventType.LeftMouseDown, pt, 0, 0, nswindow.WindowNumber, null, 0, 0, 0); NSMenu.PopUpContextMenu(menu, tmp_event, nsview); } }); }
bool ShowFixesMenu(Gtk.Widget parent, Gdk.Rectangle evt, FixMenuDescriptor entrySet) { #if MAC parent.GrabFocus(); int x, y; x = (int)evt.X; y = (int)evt.Y; Gtk.Application.Invoke(delegate { // Explicitly release the grab because the menu is shown on the mouse position, and the widget doesn't get the mouse release event Gdk.Pointer.Ungrab(Gtk.Global.CurrentEventTime); var menu = CreateNSMenu(entrySet); menu.Delegate = new ClosingMenuDelegate(document.Editor); var nsview = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView(parent); var toplevel = parent.Toplevel as Gtk.Window; int trans_x, trans_y; parent.TranslateCoordinates(toplevel, (int)x, (int)y, out trans_x, out trans_y); // Window coordinates in gtk are the same for cocoa, with the exception of the Y coordinate, that has to be flipped. var pt = new CoreGraphics.CGPoint((float)trans_x, (float)trans_y); int w, h; toplevel.GetSize(out w, out h); pt.Y = h - pt.Y; var tmp_event = AppKit.NSEvent.MouseEvent(AppKit.NSEventType.LeftMouseDown, pt, 0, 0, MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow(toplevel).WindowNumber, null, 0, 0, 0); AppKit.NSMenu.PopUpContextMenu(menu, tmp_event, nsview); }); #else var menu = CreateGtkMenu(entrySet); menu.Events |= Gdk.EventMask.AllEventsMask; menu.SelectFirst(true); menu.Hidden += delegate { document.Editor.SuppressTooltips = false; }; menu.ShowAll(); menu.SelectFirst(true); menu.MotionNotifyEvent += (o, args) => { if (args.Event.Window == Editor.Parent.TextArea.GdkWindow) { StartMenuCloseTimer(); } else { CancelMenuCloseTimer(); } }; GtkWorkarounds.ShowContextMenu(menu, parent, null, evt); #endif return(true); }
public override void WillEndDragging(UIScrollView scrollView, CoreGraphics.CGPoint velocity, ref CoreGraphics.CGPoint targetContentOffset) { var hv = appBar.HeaderViewController.HeaderView; if (scrollView == hv.TrackingScrollView) { hv.TrackingScrollViewWillEndDraggingWithVelocity(velocity, targetContentOffset); } }
public override void WillEndDragging(UIScrollView scrollView, PointF velocity, ref PointF targetContentOffset) { if (ShouldIgnoreScrolling(scrollView)) { return; } var width = ButtonsWidth; var x = targetContentOffset.X; var parentThreshold = scrollView.Frame.Width * .4f; var contentThreshold = width * .8f; if (x >= parentThreshold || x >= contentThreshold) { IsOpen = true; targetContentOffset = new PointF(width, 0); RemoveHighlight(scrollView); if (_globalCloser == null) { UIView view = scrollView; while (view.Superview != null) { view = view.Superview; var table = view as UITableView; if (table != null) { ContextActionsCell contentCell = GetContextCell(scrollView); NSAction close = () => { RestoreHighlight(scrollView); IsOpen = false; scrollView.SetContentOffset(new PointF(0, 0), true); ClearCloserRecognizer(contentCell); contentCell = null; }; _table = table; _globalCloser = new GlobalCloseContextGestureRecognizer(scrollView, close); _globalCloser.ShouldRecognizeSimultaneously = (recognizer, r) => r == _table?.PanGestureRecognizer; table.AddGestureRecognizer(_globalCloser); _closer = new UITapGestureRecognizer(close); contentCell.ContentCell.AddGestureRecognizer(_closer); } } } } else { ClearCloserRecognizer(GetContextCell(scrollView)); IsOpen = false; targetContentOffset = new PointF(0, 0); RestoreHighlight(scrollView); } }
private void CustomDelegate_OnRegionChanged(object sender, MKMapViewChangeEventArgs e) { var lat = map.Region.Center.Latitude; var lon = map.Region.Center.Longitude; CoreGraphics.CGPoint location = new CoreGraphics.CGPoint(lat, lon); //var coord = map.ConvertPoint(location, map); map.AddAnnotation(annotation); map.ReloadInputViews(); }
public void PlatformToSystemException(float x, float y) { #if __IOS__ var platform = new CoreGraphics.CGPoint(x, y); Assert.Throws <ArgumentOutOfRangeException>(() => platform.ToSystemPoint()); #elif WINDOWS_UWP var platform = new Windows.Foundation.Point(x, y); Assert.Throws <ArgumentOutOfRangeException>(() => platform.ToSystemPoint()); #endif }
public override void MouseDragged(NSEvent e) { base.MouseDragged(e); //Console.WriteLine("Mouse dragged " + e.AbsoluteX.ToString()+" delta "+e.DeltaX.ToString()); CoreGraphics.CGPoint loc = this.Frame.Location; loc.X += e.DeltaX; loc.Y -= e.DeltaY; this.SetFrameOrigin(loc); //theController.grabScreenAsPNG (); }
public override UIView HitTest(CoreGraphics.CGPoint point, UIEvent uievent) { var hitView = base.HitTest(point, uievent); if (hitView == RootViewController.View) { hitView = null; } return(hitView); }
public void OutValueTypeTest() { var obj = new OutParams(); PointF point = new PointF(3, 14); bool res; res = bool_objc_msgSend_out_PointF(obj.Handle, new Selector("Test_PointF:").Handle, out point); Assert.That(res, "#res"); Assert.That(point.X, Is.EqualTo((nfloat)3.1415f), "#x"); Assert.That(point.Y, Is.EqualTo((nfloat)0), "#y"); }
public static void ShowContextMenu (Gtk.Widget parent, int x, int y, NSMenu menu) { if (parent == null) throw new ArgumentNullException ("parent"); if (menu == null) throw new ArgumentNullException ("menu"); parent.GrabFocus (); Gtk.Application.Invoke (delegate { // Explicitly release the grab because the menu is shown on the mouse position, and the widget doesn't get the mouse release event Gdk.Pointer.Ungrab (Gtk.Global.CurrentEventTime); var nsview = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView (parent); var toplevel = parent.Toplevel as Gtk.Window; var nswindow = MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow (toplevel); int titleBarOffset; if (toplevel.TypeHint == Gdk.WindowTypeHint.Toolbar && toplevel.Type == Gtk.WindowType.Toplevel && toplevel.Decorated == false) { // Undecorated toplevel toolbars are used for auto-hide pad windows. Don't add a titlebar offset for them. titleBarOffset = 0; } else if (MonoDevelop.Ide.DesktopService.GetIsFullscreen (toplevel)) { titleBarOffset = 0; } else { titleBarOffset = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight () + 12; } var pt = new CoreGraphics.CGPoint (x, nswindow.Frame.Height - y - titleBarOffset); var tmp_event = NSEvent.MouseEvent (NSEventType.LeftMouseDown, pt, 0, 0, nswindow.WindowNumber, null, 0, 0, 0); NSMenu.PopUpContextMenu (menu, tmp_event, nsview); }); }
internal static void ShowSigninSheet () { NSApplication NSApp = NSApplication.SharedApplication; NSWindow gameWindow = NSApp.MainWindow; SigninController controller = new SigninController (); NSWindow window = controller.Window; // Something has happened with BeginSheet and needs to be looked into. // Until then just use modal for now. var frame = window.Frame; var location = new PointF (gameWindow.Frame.Bottom, gameWindow.Frame.Left); location = new PointF(gameWindow.Frame.Location.X, gameWindow.Frame.Location.Y); window.SetFrameOrigin(location); NSApp.BeginInvokeOnMainThread(delegate { Guide.isVisible = true; // NSApp.BeginSheet (window, gameWindow); NSApp.RunModalForWindow (window); // // sheet is up here..... // // NSApp.EndSheet (window); window.OrderOut (gameWindow); Guide.isVisible = false; // }); //window.MakeKeyAndOrderFront(gameWindow); // SignedInGamer sig = new SignedInGamer(); // sig.DisplayName = "MonoMac Gamer"; // sig.Gamertag = "MonoMac Gamer"; // sig.InternalIdentifier = Guid.NewGuid(); // // Gamer.SignedInGamers.Add(sig); }
private void UpdateMousePosition (PointF location) { MouseState.X = (int)location.X; MouseState.Y = (int)(ClientBounds.Height - location.Y); }
/// <summary> /// To put a table within the existing table at the given position /// generateTable will of course re-arrange the widths of the columns. /// </summary> /// <param name="aTable">the table you want to insert</param> /// <param name="aLocation">a System.Drawing.Point</param> public void InsertTable(Table aTable, CoreGraphics.CGPoint p) { if (aTable == null) throw new Exception("insertTable - table has null-value"); mTableInserted = true; aTable.Complete(); if (p.Y > columns) throw new ArgumentException("insertTable -- wrong columnposition("+ p.Y + ") of location; max =" + columns); nint rowCount = (nint)p.X + 1 - rows.Count; int i = 0; if ( rowCount > 0 ) { //create new rows ? for (; i < rowCount; i++) { rows.Add(new Row(columns)); } } ((Row) rows[(int)p.X]).SetElement(aTable,(nint)p.Y); CurrentLocationToNextValidPosition = p; }
/// <summary> /// Constructs a Table with a certain number of columns /// and a certain number of Rows. /// </summary> /// <param name="columns">The number of columns in the table</param> /// <param name="rows">The number of rows</param> /// <overloads> /// Has three overloads /// </overloads> public Table(int columns, int rows) : base(0, 0, 0, 0) { Border = BOX; BorderWidth = 1; defaultCell.Border = BOX; // a table should have at least 1 column if (columns <= 0) { throw new BadElementException("A table should have at least 1 column."); } this.columns = columns; // a certain number of rows are created for (int i = 0; i < rows; i++) { this.rows.Add(new Row(columns)); } curPosition = new CoreGraphics.CGPoint(0, 0); // the DEFAULT widths are calculated widths = new float[columns]; float width = 100f / columns; for (int i = 0; i < columns; i++) { widths[i] = width; } }
/// <summary> /// Adds a Cell to the Table at a certain location. /// </summary> /// <param name="aCell">The Cell to add</param> /// <param name="aLocation">The location where the Cell will be added</param> public void AddCell(Cell aCell, object aLocation) { CoreGraphics.CGPoint p; if (aCell == null) throw new Exception("addCell - cell has null-value"); if (aLocation == null) throw new Exception("addCell - point has null-value"); else p = (CoreGraphics.CGPoint)aLocation; if (aCell.IsTable()) { IEnumerator i = aCell.Elements.GetEnumerator(); i.MoveNext(); InsertTable((Table)i.Current, p); } if (p.X < 0) throw new BadElementException("row coordinate of location must be >= 0"); if ((p.Y <= 0) && (p.Y > columns)) throw new BadElementException("column coordinate of location must be >= 0 and < nr of columns"); if (!IsValidLocation(aCell, p)) throw new BadElementException("Adding a cell at the location (" + p.X + "," + p.Y + ") with a colspan of " + aCell.Colspan + " and a rowspan of " + aCell.Rowspan + " is illegal (beyond boundaries/overlapping)."); if (aCell.Border == UNDEFINED) aCell.Border = defaultCell.Border; aCell.Fill(); PlaceCell(rows, aCell, p); CurrentLocationToNextValidPosition = p; }
public void ReadAll() { if (meta.ReadInt() != unchecked((int)0x9AC6CDD7)) { throw new DocumentException("Not a placeable windows metafile"); } meta.ReadWord(); left = meta.ReadShort(); top = meta.ReadShort(); right = meta.ReadShort(); bottom = meta.ReadShort(); inch = meta.ReadWord(); state.ScalingX = (float)(right - left) / (float)inch * 72f; state.ScalingY = (float)(bottom - top) / (float)inch * 72f; state.OffsetWx = left; state.OffsetWy = top; state.ExtentWx = right - left; state.ExtentWy = bottom - top; meta.ReadInt(); meta.ReadWord(); meta.Skip(18); int tsize; int function; cb.SetLineCap(1); cb.SetLineJoin(1); for (;;) { int lenMarker = meta.Length; tsize = meta.ReadInt(); if (tsize < 3) break; function = meta.ReadWord(); switch (function) { case 0: break; case META_CREATEPALETTE: case META_CREATEREGION: case META_DIBCREATEPATTERNBRUSH: state.AddMetaObject(new MetaObject()); break; case META_CREATEPENINDIRECT: { MetaPen pen = new MetaPen(); pen.Init(meta); state.AddMetaObject(pen); break; } case META_CREATEBRUSHINDIRECT: { MetaBrush brush = new MetaBrush(); brush.Init(meta); state.AddMetaObject(brush); break; } case META_CREATEFONTINDIRECT: { MetaFont font = new MetaFont(); font.Init(meta); state.AddMetaObject(font); break; } case META_SELECTOBJECT: { int idx = meta.ReadWord(); state.SelectMetaObject(idx, cb); break; } case META_DELETEOBJECT: { int idx = meta.ReadWord(); state.DeleteMetaObject(idx); break; } case META_SAVEDC: state.SaveState(cb); break; case META_RESTOREDC: { int idx = meta.ReadShort(); state.RestoreState(idx, cb); break; } case META_SETWINDOWORG: state.OffsetWy = meta.ReadShort(); state.OffsetWx = meta.ReadShort(); break; case META_SETWINDOWEXT: state.ExtentWy = meta.ReadShort(); state.ExtentWx = meta.ReadShort(); break; case META_MOVETO: { int y = meta.ReadShort(); CoreGraphics.CGPoint p = new CoreGraphics.CGPoint(meta.ReadShort(), y); state.CurrentPoint = p; break; } case META_LINETO: { int y = meta.ReadShort(); int x = meta.ReadShort(); CoreGraphics.CGPoint p = state.CurrentPoint; cb.MoveTo(state.TransformX(p.X), state.TransformY(p.Y)); cb.LineTo(state.TransformX(x), state.TransformY(y)); cb.Stroke(); state.CurrentPoint = new CoreGraphics.CGPoint(x, y); break; } case META_POLYLINE: { state.LineJoinPolygon = cb; int len = meta.ReadWord(); int x = meta.ReadShort(); int y = meta.ReadShort(); cb.MoveTo(state.TransformX(x), state.TransformY(y)); for (int k = 1; k < len; ++k) { x = meta.ReadShort(); y = meta.ReadShort(); cb.LineTo(state.TransformX(x), state.TransformY(y)); } cb.Stroke(); break; } case META_POLYGON: { if (IsNullStrokeFill(false)) break; int len = meta.ReadWord(); int sx = meta.ReadShort(); int sy = meta.ReadShort(); cb.MoveTo(state.TransformX(sx), state.TransformY(sy)); for (int k = 1; k < len; ++k) { int x = meta.ReadShort(); int y = meta.ReadShort(); cb.LineTo(state.TransformX(x), state.TransformY(y)); } cb.LineTo(state.TransformX(sx), state.TransformY(sy)); StrokeAndFill(); break; } case META_POLYPOLYGON: { if (IsNullStrokeFill(false)) break; int numPoly = meta.ReadWord(); int[] lens = new int[numPoly]; for (int k = 0; k < lens.Length; ++k) lens[k] = meta.ReadWord(); for (int j = 0; j < lens.Length; ++j) { int len = lens[j]; int sx = meta.ReadShort(); int sy = meta.ReadShort(); cb.MoveTo(state.TransformX(sx), state.TransformY(sy)); for (int k = 1; k < len; ++k) { int x = meta.ReadShort(); int y = meta.ReadShort(); cb.LineTo(state.TransformX(x), state.TransformY(y)); } cb.LineTo(state.TransformX(sx), state.TransformY(sy)); } StrokeAndFill(); break; } case META_ELLIPSE: { if (IsNullStrokeFill(state.LineNeutral)) break; int b = meta.ReadShort(); int r = meta.ReadShort(); int t = meta.ReadShort(); int l = meta.ReadShort(); cb.Arc(state.TransformX(l), state.TransformY(b), state.TransformX(r), state.TransformY(t), 0, 360); StrokeAndFill(); break; } case META_ARC: { if (IsNullStrokeFill(state.LineNeutral)) break; float yend = state.TransformY(meta.ReadShort()); float xend = state.TransformX(meta.ReadShort()); float ystart = state.TransformY(meta.ReadShort()); float xstart = state.TransformX(meta.ReadShort()); float b = state.TransformY(meta.ReadShort()); float r = state.TransformX(meta.ReadShort()); float t = state.TransformY(meta.ReadShort()); float l = state.TransformX(meta.ReadShort()); float cx = (r + l) / 2; float cy = (t + b) / 2; float arc1 = GetArc(cx, cy, xstart, ystart); float arc2 = GetArc(cx, cy, xend, yend); arc2 -= arc1; if (arc2 <= 0) arc2 += 360; cb.Arc(l, b, r, t, arc1, arc2); cb.Stroke(); break; } case META_PIE: { if (IsNullStrokeFill(state.LineNeutral)) break; float yend = state.TransformY(meta.ReadShort()); float xend = state.TransformX(meta.ReadShort()); float ystart = state.TransformY(meta.ReadShort()); float xstart = state.TransformX(meta.ReadShort()); float b = state.TransformY(meta.ReadShort()); float r = state.TransformX(meta.ReadShort()); float t = state.TransformY(meta.ReadShort()); float l = state.TransformX(meta.ReadShort()); float cx = (r + l) / 2; float cy = (t + b) / 2; float arc1 = GetArc(cx, cy, xstart, ystart); float arc2 = GetArc(cx, cy, xend, yend); arc2 -= arc1; if (arc2 <= 0) arc2 += 360; ArrayList ar = PdfContentByte.BezierArc(l, b, r, t, arc1, arc2); if (ar.Count == 0) break; float[] pt = (float [])ar[0]; cb.MoveTo(cx, cy); cb.LineTo(pt[0], pt[1]); for (int k = 0; k < ar.Count; ++k) { pt = (float [])ar[k]; cb.CurveTo(pt[2], pt[3], pt[4], pt[5], pt[6], pt[7]); } cb.LineTo(cx, cy); StrokeAndFill(); break; } case META_CHORD: { if (IsNullStrokeFill(state.LineNeutral)) break; float yend = state.TransformY(meta.ReadShort()); float xend = state.TransformX(meta.ReadShort()); float ystart = state.TransformY(meta.ReadShort()); float xstart = state.TransformX(meta.ReadShort()); float b = state.TransformY(meta.ReadShort()); float r = state.TransformX(meta.ReadShort()); float t = state.TransformY(meta.ReadShort()); float l = state.TransformX(meta.ReadShort()); float cx = (r + l) / 2; float cy = (t + b) / 2; float arc1 = GetArc(cx, cy, xstart, ystart); float arc2 = GetArc(cx, cy, xend, yend); arc2 -= arc1; if (arc2 <= 0) arc2 += 360; ArrayList ar = PdfContentByte.BezierArc(l, b, r, t, arc1, arc2); if (ar.Count == 0) break; float[] pt = (float [])ar[0]; cx = pt[0]; cy = pt[1]; cb.MoveTo(cx, cy); for (int k = 0; k < ar.Count; ++k) { pt = (float [])ar[k]; cb.CurveTo(pt[2], pt[3], pt[4], pt[5], pt[6], pt[7]); } cb.LineTo(cx, cy); StrokeAndFill(); break; } case META_RECTANGLE: { if (IsNullStrokeFill(true)) break; float b = state.TransformY(meta.ReadShort()); float r = state.TransformX(meta.ReadShort()); float t = state.TransformY(meta.ReadShort()); float l = state.TransformX(meta.ReadShort()); cb.Rectangle(l, b, r - l, t - b); StrokeAndFill(); break; } case META_ROUNDRECT: { if (IsNullStrokeFill(true)) break; float h = state.TransformY(0) - state.TransformY(meta.ReadShort()); float w = state.TransformX(meta.ReadShort()) - state.TransformX(0); float b = state.TransformY(meta.ReadShort()); float r = state.TransformX(meta.ReadShort()); float t = state.TransformY(meta.ReadShort()); float l = state.TransformX(meta.ReadShort()); cb.RoundRectangle(l, b, r - l, t - b, (h + w) / 4); StrokeAndFill(); break; } case META_INTERSECTCLIPRECT: { float b = state.TransformY(meta.ReadShort()); float r = state.TransformX(meta.ReadShort()); float t = state.TransformY(meta.ReadShort()); float l = state.TransformX(meta.ReadShort()); cb.Rectangle(l, b, r - l, t - b); cb.EoClip(); cb.NewPath(); break; } case META_EXTTEXTOUT: { int y = meta.ReadShort(); int x = meta.ReadShort(); int count = meta.ReadWord(); int flag = meta.ReadWord(); int x1 = 0; int y1 = 0; int x2 = 0; int y2 = 0; if ((flag & (MetaFont.ETO_CLIPPED | MetaFont.ETO_OPAQUE)) != 0) { x1 = meta.ReadShort(); y1 = meta.ReadShort(); x2 = meta.ReadShort(); y2 = meta.ReadShort(); } byte[] text = new byte[count]; int k; for (k = 0; k < count; ++k) { byte c = (byte)meta.ReadByte(); if (c == 0) break; text[k] = c; } string s; try { s = System.Text.Encoding.GetEncoding(1252).GetString(text, 0, k); } catch { s = System.Text.ASCIIEncoding.ASCII.GetString(text, 0, k); } OutputText(x, y, flag, x1, y1, x2, y2, s); break; } case META_TEXTOUT: { int count = meta.ReadWord(); byte[] text = new byte[count]; int k; for (k = 0; k < count; ++k) { byte c = (byte)meta.ReadByte(); if (c == 0) break; text[k] = c; } string s; try { s = System.Text.Encoding.GetEncoding(1252).GetString(text, 0, k); } catch { s = System.Text.ASCIIEncoding.ASCII.GetString(text, 0, k); } count = (count + 1) & 0xfffe; meta.Skip(count - k); int y = meta.ReadShort(); int x = meta.ReadShort(); OutputText(x, y, 0, 0, 0, 0, 0, s); break; } case META_SETBKCOLOR: state.CurrentBackgroundColor = meta.ReadColor(); break; case META_SETTEXTCOLOR: state.CurrentTextColor = meta.ReadColor(); break; case META_SETTEXTALIGN: state.TextAlign = meta.ReadWord(); break; case META_SETBKMODE: state.BackgroundMode = meta.ReadWord(); break; case META_SETPOLYFILLMODE: state.PolyFillMode = meta.ReadWord(); break; case META_SETPIXEL: { Color color = meta.ReadColor(); int y = meta.ReadShort(); int x = meta.ReadShort(); cb.SaveState(); cb.SetColorFill(color); cb.Rectangle(state.TransformX(x), state.TransformY(y), .2f, .2f); cb.Fill(); cb.RestoreState(); break; } case META_DIBSTRETCHBLT: case META_STRETCHDIB: { int rop = meta.ReadInt(); if (function == META_STRETCHDIB) { /*int usage = */ meta.ReadWord(); } int srcHeight = meta.ReadShort(); int srcWidth = meta.ReadShort(); int ySrc = meta.ReadShort(); int xSrc = meta.ReadShort(); float destHeight = state.TransformY(meta.ReadShort()) - state.TransformY(0); float destWidth = state.TransformX(meta.ReadShort()) - state.TransformX(0); float yDest = state.TransformY(meta.ReadShort()); float xDest = state.TransformX(meta.ReadShort()); byte[] b = new byte[(tsize * 2) - (meta.Length - lenMarker)]; for (int k = 0; k < b.Length; ++k) b[k] = (byte)meta.ReadByte(); try { MemoryStream inb = new MemoryStream(b); Image bmp = BmpImage.GetImage(inb, true, b.Length); cb.SaveState(); cb.Rectangle(xDest, yDest, destWidth, destHeight); cb.Clip(); cb.NewPath(); bmp.ScaleAbsolute(destWidth * bmp.Width / srcWidth, -destHeight * bmp.Height / srcHeight); bmp.SetAbsolutePosition(xDest - destWidth * xSrc / srcWidth, yDest + destHeight * ySrc / srcHeight - bmp.ScaledHeight); cb.AddImage(bmp); cb.RestoreState(); } catch { // empty on purpose } break; } } meta.Skip((tsize * 2) - (meta.Length - lenMarker)); } state.Cleanup(cb); }
// Called when the UIKeyboardDidShowNotification is sent void keyboardDidAppear(NSNotification notification) { NSDictionary info = notification.UserInfo; CoreGraphics.CGSize kbSize = NSValue.ValueFromNonretainedObject (info.ObjectForKey (UIKeyboard.FrameBeginUserInfoKey)).CGRectValue.Size; UIEdgeInsets contentInsets = new UIEdgeInsets (new System.nfloat(0.0), new System.nfloat(0.0), kbSize.Height, new System.nfloat(0.0)); ScrollView.ContentInset = contentInsets; // If active text field is hidden by keyboard, scroll it so it's visible CoreGraphics.CGRect aRect = this.View.Frame; var height = aRect.Size.Height; height -= kbSize.Height; var size = aRect.Size; size.Height = height; aRect.Size = size; UIView activeField = (UIView)notification.Object; if (!aRect.Contains (activeField.Frame.Location)) { CoreGraphics.CGPoint scrollPoint = new CoreGraphics.CGPoint (0.0, activeField.Frame.Location.Y - kbSize.Height); ScrollView.SetContentOffset (scrollPoint, true); } }
bool ShowFixesMenu (Gtk.Widget parent, Gdk.Rectangle evt, FixMenuDescriptor entrySet) { if (parent == null || parent.GdkWindow == null) return true; try { #if MAC parent.GrabFocus (); int x, y; x = (int)evt.X; y = (int)evt.Y; // Explicitly release the grab because the menu is shown on the mouse position, and the widget doesn't get the mouse release event Gdk.Pointer.Ungrab (Gtk.Global.CurrentEventTime); var menu = CreateNSMenu (entrySet); menu.Delegate = new ClosingMenuDelegate (document.Editor); var nsview = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView (parent); var toplevel = parent.Toplevel as Gtk.Window; int trans_x, trans_y; parent.TranslateCoordinates (toplevel, (int)x, (int)y, out trans_x, out trans_y); // Window coordinates in gtk are the same for cocoa, with the exception of the Y coordinate, that has to be flipped. var pt = new CoreGraphics.CGPoint ((float)trans_x, (float)trans_y); int w,h; toplevel.GetSize (out w, out h); pt.Y = h - pt.Y; var tmp_event = AppKit.NSEvent.MouseEvent (AppKit.NSEventType.LeftMouseDown, pt, 0, 0, MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow (toplevel).WindowNumber, null, 0, 0, 0); AppKit.NSMenu.PopUpContextMenu (menu, tmp_event, nsview); #else var menu = CreateGtkMenu (entrySet); menu.Events |= Gdk.EventMask.AllEventsMask; menu.SelectFirst (true); menu.Hidden += delegate { document.Editor.SuppressTooltips = false; }; menu.ShowAll (); menu.SelectFirst (true); menu.MotionNotifyEvent += (o, args) => { if (args.Event.Window == Editor.Parent.TextArea.GdkWindow) { StartMenuCloseTimer (); } else { CancelMenuCloseTimer (); } }; GtkWorkarounds.ShowContextMenu (menu, parent, null, evt); #endif } catch (Exception ex) { LoggingService.LogError ("Error while context menu popup.", ex); } return true; }