public void Draw(NSRect aCellFrame, NSView aControlView) { BookmarkData item = ObjectValue.CastAs <BookmarkData>(); // create attributes for the title and subtitle text NSMutableParagraphStyle style = new NSMutableParagraphStyle(); style.SetParagraphStyle(NSParagraphStyle.DefaultParagraphStyle); style.SetLineBreakMode(NSLineBreakMode.NSLineBreakByTruncatingTail); NSDictionary titleAttr = NSDictionary.DictionaryWithObjectsAndKeys(FontManager.FontMedium, NSAttributedString.NSFontAttributeName, NSColor.WhiteColor, NSAttributedString.NSForegroundColorAttributeName, style, NSAttributedString.NSParagraphStyleAttributeName, null); NSDictionary subtitleAttr = NSDictionary.DictionaryWithObjectsAndKeys(FontManager.FontSmall, NSAttributedString.NSFontAttributeName, NSColor.WhiteColor, NSAttributedString.NSForegroundColorAttributeName, style, NSAttributedString.NSParagraphStyleAttributeName, null); style.Release(); NSPoint pt = aCellFrame.origin; // draw title NSString title = NSString.StringWithUTF8String(item.Bookmark.Title); title.DrawAtPointWithAttributes(pt, titleAttr); NSSize size = title.SizeWithAttributes(titleAttr); pt.y += size.height; // draw breadcrumb List <string> titleTrail = new List <string>(); foreach (Breadcrumb bc in item.Bookmark.BreadcrumbTrail) { titleTrail.Add(bc.Title); } string breadcrumb = string.Join("/", titleTrail.ToArray()); NSString breadcrumb2 = NSString.StringWithUTF8String(breadcrumb); breadcrumb2.DrawAtPointWithAttributes(pt, subtitleAttr); }
private void Draw(NSRect aRect, NSImage aLeft, NSImage aRight, NSImage aFiller) { // draw the background NSRect leftRect = new NSRect(aRect.MinX, aRect.MinY, aLeft.Size.width, aRect.Height); aLeft.DrawInRectFromRectOperationFraction(leftRect, NSRect.NSZeroRect, NSCompositingOperation.NSCompositeSourceOver, 1.0f); NSRect rightRect = new NSRect(aRect.MaxX - aRight.Size.width, aRect.MinY, aRight.Size.width, aRect.Height); aRight.DrawInRectFromRectOperationFraction(rightRect, NSRect.NSZeroRect, NSCompositingOperation.NSCompositeSourceOver, 1.0f); NSRect fillerRect = new NSRect(aRect.MinX + aLeft.Size.width, aRect.MinY, aRect.Width - aLeft.Size.width - aRight.Size.width, aRect.Height); aFiller.DrawInRectFromRectOperationFraction(fillerRect, NSRect.NSZeroRect, NSCompositingOperation.NSCompositeSourceOver, 1.0f); // draw image if (iText != null && iImage != null) { // button has text and an image NSSize imgSz = ImageSize; NSRect imgRect = new NSRect(iTextLeft ? fillerRect.MaxX - imgSz.width : fillerRect.MinX, aRect.MidY - imgSz.height * 0.5f, imgSz.width, imgSz.height); // fit the image to the available rect imgRect = NSImageHelper.CentreImageInRect(iImage, imgRect); iImage.DrawInRectFromRectOperationFraction(imgRect.IntegralRect(), NSRect.NSZeroRect, NSCompositingOperation.NSCompositeSourceOver, 1.0f); } else if (iImage != null) { // image only - draw centred NSSize imgSz = ImageSize; NSRect dstRect = new NSRect(aRect.MidX - imgSz.width * 0.5f, aRect.MidY - imgSz.height * 0.5f, imgSz.width, imgSz.height); // fit the image to the available rect dstRect = NSImageHelper.CentreImageInRect(iImage, dstRect); iImage.DrawInRectFromRectOperationFraction(dstRect.IntegralRect(), NSRect.NSZeroRect, NSCompositingOperation.NSCompositeSourceOver, 1.0f); } }
public override void DrawRect(NSRect aRect) { // draw bars if (iMaxValue > 0) { // draw the current value bar NSColor colour = NSColor.ColorWithCalibratedRedGreenBlueAlpha(71.0f / 255.0f, 172.0f / 255.0f, 220.0f / 255.0f, 1.0f); colour.SetStroke(); DrawArc(0, iValue, true); // draw the preview bar if (iPreviewEnabled) { colour = NSColor.ColorWithCalibratedRedGreenBlueAlpha(187.0f / 255.0f, 187.0f / 255.0f, 0.0f / 255.0f, 1.0f); colour.SetStroke(); DrawArc(iValue, iPreviewValue, (iPreviewValue > iValue)); } } // draw text if (iText != null) { NSMutableParagraphStyle style = new NSMutableParagraphStyle(); style.SetParagraphStyle(NSParagraphStyle.DefaultParagraphStyle); style.SetAlignment(NSTextAlignment.NSCenterTextAlignment); NSDictionary dict = NSDictionary.DictionaryWithObjectsAndKeys(FontManager.FontMedium, NSAttributedString.NSFontAttributeName, style, NSAttributedString.NSParagraphStyleAttributeName, NSColor.WhiteColor, NSAttributedString.NSForegroundColorAttributeName, null); style.Release(); NSSize size = iText.SizeWithAttributes(dict); NSRect rect = new NSRect((Bounds.Width - size.width) * 0.5f, (Bounds.Height - size.height) * 0.5f, size.width, size.height); iText.DrawInRectWithAttributes(rect, dict); } }
public void DrawText(NSRect aRect) { if (iText == null) { return; } // assume images for the background are the same for the no-hover, hover and down states NSImage left = iLeft; NSImage right = iRight; NSRect fillerRect = new NSRect(aRect.MinX + left.Size.width, aRect.MinY, aRect.Width - left.Size.width - right.Size.width, aRect.Height); // calculate the text rect NSSize textSz = TextSize; NSSize imgSz = ImageSize; NSRect textRect = new NSRect(iTextLeft ? fillerRect.MinX + iTextPadding: fillerRect.MinX + imgSz.width + iTextPadding, aRect.MidY - textSz.height * 0.5f, fillerRect.Width - imgSz.width - 2.0f * iTextPadding, textSz.height); // draw iText.DrawInRectWithAttributes(textRect.IntegralRect(), TextAttributes); }
private NSImage GetImage(Uri aUri) { ArtworkCache.Item item = ArtworkCacheInstance.Instance.Artwork(aUri); NSImage img = null; if (item != null) { if (!item.Failed) { img = item.Image; } else { img = Properties.Resources.IconLoading; } } if (img != null) { NSSize size = img.Size; size = new NSSize(kMaxImageSize, (size.height / size.width) * kMaxImageSize); img.Size = size; } return(img); }
// Changing frame (which is what happens when the window is resized) should cause relayout. public void setFrameSize(NSSize size) { SuperCall(NSView.Class, "setFrameSize:", size); DoLayout(); }
public NSRect(float x, float y, float width, float height) { origin = new NSPoint(x, y); size = new NSSize(width, height); }
private void splitView(NSSplitView splitView) resizeSubviewsWithOldSize(NSSize oldSize) { NSArray subviews = splitView.subviews(); bool isVertical = splitView.isVertical(); if (this.bottomRightHidden()) { CGSize size0 = this.frame().size; CGSize size1 = this.frame().size; if (isVertical) { size0.width--; size1.width = 1; } else { size0.height--; size1.height = 1; } subviews.objectAtIndex(0).setFrameSize(size0); subviews.objectAtIndex(1).setFrameSize(size1); return; } if (this.topLeftHidden()) { subviews.objectAtIndex(1).setFrameSize(this.frame().size); subviews.objectAtIndex(0).setFrameSize(NSZeroSize); return; } CGFloat delta = isVertical ? splitView.bounds.size.width - oldSize.width : splitView.bounds.size.height - oldSize.height; int start = _priorityViewIndex == 1 ? 1 : 0; int end = _priorityViewIndex == 1 ? -1 : 2; int direction = _priorityViewIndex == 1 ? -1 : 1; for (int i = start; i != end; i += direction) { NSView view = subviews.objectAtIndex(i); NSSize frameSize = view.frame().size; CGFloat size; if (isVertical) { frameSize.height = splitView.bounds.size.height; size = frameSize.width; } else { frameSize.width = splitView.bounds.size.width; size = frameSize.height; } CGFloat minLengthValue = i == 0 ? _minTopLeft : _minBottomRight; if ((delta > 0) || ((size + delta) >= minLengthValue)) { size += delta; delta = 0; } else if (delta < 0) { delta += (size - minLengthValue); size = minLengthValue; } if (isVertical) frameSize.width = size; else frameSize.height = size; view.setFrameSize(frameSize); } CGFloat offset = 0; CGFloat dividerThickness = this.dividerThickness(); for (int i = 0; i < subviews.count(); i++) { NSView view = subviews.objectAtIndex(i); NSRect viewFrame = view.frame; NSPoint viewOrigin = viewFrame.origin; if (isVertical) { viewOrigin.x = offset; view.setFrameOrigin(viewOrigin); offset += (viewFrame.size.width + dividerThickness); } else { viewOrigin.y = offset; view.setFrameOrigin(viewOrigin); offset += (viewFrame.size.height + dividerThickness); } } }
/// <summary> /// Initializes a new instance of the <c>NSRect</c> struct using the supplied coordinates, width, and height. /// </summary> /// <param name="x">The x coordinate of the top left corner of the rectangle.</param> /// <param name="y">The y coordinate of the top left corner of the rectangle.</param> /// <param name="width">The width of the rectangle.</param> /// <param name="height">The height of the rectangle.</param> public NSRect(double x, double y, double width, double height) { location = new NSPoint(x, y); size = new NSSize(width, height); }
private void DoAdjustFrame(NSSize size) { NSRect frame = DoGetFrame(size); frame.origin += m_offset; // We'll allow the annotation to extend to the left or the right, but if it // scrolls too far up or down we'll hide it. NSRect content = m_parent.contentRectForFrameRect(m_parent.frame()); if (frame.Bottom >= content.Bottom && frame.Top < content.Top) { setFrame_display(frame, false); // this is in screen coordinates even though we are a child window } else { frame.origin.x -= 8000; setFrame_display(frame, false); } }
public static extern void NSShowAnimationEffect(int animationEffect, NSPoint centerLocation, NSSize size, IntPtr animationDelegate, IntPtr didEndSelector, IntPtr contextInfo);
public static void NSShowAnimationEffect(int animationEffect, NSPoint centerLocation, NSSize size, NSObject animationDelegate, Selector didEndSelector, IntPtr contextInfo) { NativeMethods.NSShowAnimationEffect(animationEffect, centerLocation, size, animationDelegate, didEndSelector, contextInfo); }
internal extern static void Void_objc_msgSend(IntPtr receiver, IntPtr selector, NSSize arg0);
private void DoFindLargestFont(ITextOverlay overlay, NSRect rect) { float[] candidates = new float[]{12.0f, 14.0f, 18.0f, 24.0f, 36.0f, 48.0f, 64.0f, 72.0f, 06.0f, 144.0f, 288.0f, 0.0f}; int i = 0; while (candidates[i + 1] != 0.0f) { var attrs = NSMutableDictionary.Create(); NSFont font = NSFont.fontWithName_size(NSString.Create("Verdana"), candidates[i + 1]); attrs.setObject_forKey(font, Externs.NSFontAttributeName); attrs.setObject_forKey(overlay.Color, Externs.NSForegroundColorAttributeName); NSMutableParagraphStyle style = NSMutableParagraphStyle.Create(); style.setAlignment(Enums.NSCenterTextAlignment); attrs.setObject_forKey(style, Externs.NSParagraphStyleAttributeName); var candidate = NSAttributedString.Create(overlay.Text, attrs); NSSize size = candidate.size(); if (size.width <= rect.size.width && size.height <= rect.size.height) { m_overlay = candidate.Retain(); m_overlaySize = size; ++i; } else { break; } } }
public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, NSSize size);
public void Show(NSPoint aAnchor, bool aAnchorOnLeft, NSSize aSize) { // calculate the rect for the window - the passed in arguments are "preferred" values // and will only be honoured if possible float x, y, w, h, anchorPos; bool anchorOnTop = false; if (NSScreen.MainScreen == null) { Linn.UserLog.WriteLine(DateTime.Now + ": Logging for #822 MainScreen null"); } if (ViewBkgd == null) { Linn.UserLog.WriteLine(DateTime.Now + ": Logging for #822 ViewBkgd null"); } if (Window == null) { Linn.UserLog.WriteLine(DateTime.Now + ": Logging for #822 Window null"); } if (ViewContent == null) { Linn.UserLog.WriteLine(DateTime.Now + ": Logging for #822 ViewContent null"); } if (iView == null) { Linn.UserLog.WriteLine(DateTime.Now + ": Logging for #822 iView null"); } if (iView.View == null) { Linn.UserLog.WriteLine(DateTime.Now + ": Logging for #822 iView.View null"); } if (iAnimation == null) { Linn.UserLog.WriteLine(DateTime.Now + ": Logging for #822 iAnimation null"); } NSRect screenFrame = NSScreen.MainScreen.VisibleFrame; // determine the y-pos, height and anchor position if (aAnchor.y - aSize.height > screenFrame.MinY) { // window can fit in available screen with given coords and anchor at the top h = aSize.height; y = aAnchor.y - aSize.height; anchorOnTop = true; } else if (aAnchor.y + aSize.height < screenFrame.MaxY) { // window can fit in available screen with given coords and anchor at the bottom h = aSize.height; y = aAnchor.y; anchorOnTop = false; } else if (aAnchor.y > screenFrame.MidY) { // window height is truncated with anchor at top h = aAnchor.y - screenFrame.MinY; y = screenFrame.MinY; anchorOnTop = true; } else { // window height is truncated with anchor at bottom h = screenFrame.MaxY - aAnchor.y; y = aAnchor.y; anchorOnTop = false; } // determine x-pos and width const float anchorIndent = 50.0f; if (aAnchorOnLeft) { float left = aAnchor.x - anchorIndent; float right = left + aSize.width; if (right < screenFrame.MaxX) { // anchor ok on the left x = left; w = aSize.width; anchorPos = anchorIndent; } else { // move anchor to the right x = aAnchor.x + anchorIndent - aSize.width; w = aSize.width; anchorPos = aSize.width - anchorIndent; } } else { float left = aAnchor.x + anchorIndent - aSize.width; if (left > screenFrame.MinX) { // anchor ok on right x = left; w = aSize.width; anchorPos = aSize.width - anchorIndent; } else { // move anchor to the left x = aAnchor.x - anchorIndent; w = aSize.width; anchorPos = anchorIndent; } } // set the target rect for the window ViewBkgd.AnchorOnTop = anchorOnTop; ViewBkgd.AnchorPos = anchorPos; NSRect targetFrame = new NSRect(x, y, w, h); NSRect initialFrame = GetMinimalRect(targetFrame); // initialise the content view to be the target size - this avoids adverse animation // effects where the view could potentially have a 0 or -ve height Window.SetFrameDisplay(targetFrame, false); iView.View.Frame = ViewContent.Bounds; // initialise and show the window Window.SetFrameDisplay(initialFrame, false); Window.MakeKeyAndOrderFront(this); // the popover closes when it resigns key window status. Normally, this would mean // it can no longer be seen (the main window is on top). Given that this window should // animate when closing, setting the window level will ensure that the popover is always // on top of the main window, so the closing animation can be seen Window.Level = NSWindowLevel.NSFloatingWindowLevel; // animate NSViewAnimationHelper.SetFrames(iAnimation, Window, initialFrame, targetFrame); iAnimation.Duration = 0.2; iAnimation.StartAnimation(); }
private NSRect DoGetFrame(NSSize size) { NSRect bbox = m_editor.GetBoundingBox(new NSRange(m_range.Index, m_range.Length)); NSPoint origin = m_parent.convertBaseToScreen(bbox.origin); if (m_alignment == AnnotationAlignment.Bottom) origin.y -= size.height; else if (m_alignment == AnnotationAlignment.Top) origin.y += size.height; NSRect frame = new NSRect(origin, size); return frame; }
/// <summary> /// Initializes a new instance of the <c>NSRect</c> struct using the supplied location and size. /// </summary> /// <param name="location">The location of the top left corner of the rectangle.</param> /// <param name="size">The size of the rectangle.</param> public NSRect(NSPoint location, NSSize size) { this.location = location; this.size = size; }