コード例 #1
0
 private static void RenderSolutionNameIcon(string name)
 {
     if (!string.IsNullOrWhiteSpace(name))
     {
         const float margin         = 4;
         NSString    text           = (NSString)name;
         var         paragraphStyle = (NSParagraphStyle)NSParagraphStyle.DefaultParagraphStyle.MutableCopy();
         paragraphStyle.Alignment = NSTextAlignment.Center;
         var attributes = new NSStringAttributes()
         {
             Font            = NSFont.SystemFontOfSize(19, NSFontWeight.Regular),
             ForegroundColor = NSColor.White,
             ParagraphStyle  = paragraphStyle
         };
         var textRect         = new CGSize(_defaultImage.Size.Width - margin * 2, _defaultImage.Size.Height - 2 * margin);
         var rect             = text.BoundingRectWithSize(textRect, NSStringDrawingOptions.UsesLineFragmentOrigin, attributes.Dictionary);
         var centerAdjustment = _defaultImage.Size.Width - rect.Width - 2 * margin;
         rect.Offset(margin + centerAdjustment / 2, margin);
         var brandedImage = NSImage.ImageWithSize(_defaultImage.Size, false, (dstRect) =>
         {
             _defaultImage.Draw(dstRect);
             DrawBackgroundInRect(rect);
             text.DrawInRect(rect, attributes);
             return(true);
         });
         NSApplication.SharedApplication.ApplicationIconImage = brandedImage;
     }
     else
     {
         NSApplication.SharedApplication.ApplicationIconImage = _defaultImage;
     }
 }
コード例 #2
0
        internal static async Task <StorageItemThumbnail> CreatePhotoThumbnailAsync(StorageFile file)
        {
#if __MAC__
            NSImage image = NSImage.FromStream(await file.OpenStreamForReadAsync());
            double  ratio = image.Size.Width / image.Size.Height;

            NSImage newImage = new NSImage(new CGSize(240, 240 * ratio));
            newImage.LockFocus();
            image.Size = newImage.Size;

            image.Draw(new CGPoint(0, 0), new CGRect(0, 0, newImage.Size.Width, newImage.Size.Height), NSCompositingOperation.Copy, 1.0f);
            newImage.UnlockFocus();

            NSMutableData      buffer = new NSMutableData();
            CGImageDestination dest   = CGImageDestination.Create(buffer, UTType.JPEG, 1);
            dest.AddImage(newImage.CGImage);

            return(new StorageItemThumbnail(buffer.AsStream()));
#else
            UIImage image = UIImage.FromFile(file.Path);

            UIImage image2 = image.Scale(new CGSize(240, 240));
            image.Dispose();

            return(new StorageItemThumbnail(image2.AsJPEG().AsStream()));
#endif
        }
コード例 #3
0
        public static NSImage ResizeNSImage(this NSImage image, double desiredWidth, double desiredHeight, InterpolationMode interpolationMode)
        {
            double widthRatio  = desiredWidth / image.Size.Width;
            double heightRatio = desiredHeight / image.Size.Height;

            double scaleRatio = Math.Min(widthRatio, heightRatio);

            if (desiredWidth == 0)
            {
                scaleRatio = heightRatio;
            }

            if (desiredHeight == 0)
            {
                scaleRatio = widthRatio;
            }

            double aspectWidth  = image.Size.Width * scaleRatio;
            double aspectHeight = image.Size.Height * scaleRatio;

            var newSize = new CGSize(aspectWidth, aspectHeight);

            var resizedImage = new NSImage(newSize);

            resizedImage.LockFocus();
            image.Draw(new CGRect(CGPoint.Empty, newSize), CGRect.Empty, NSCompositingOperation.SourceOver, 1.0f);
            resizedImage.UnlockFocus();
            return(resizedImage);
        }
コード例 #4
0
//    public override void DrawWithFrame(RectangleF cellFrame, NSView inView) {
//       float iconX = 0f;
//       float iconY = 0f;
//       float iconWidth = 0f;
//       float iconHeight = 0f;
//
//       cellFrame.X = cellFrame.X - 10;
//       cellFrame.Height = cellFrame.Height - 1;
//       RectangleF newRect = cellFrame;
//
//       if (image != null) {
//          iconX = cellFrame.X + 1;
//          iconY = cellFrame.Y + 2;
//          iconWidth = image.Size.Width;
//          iconHeight = image.Size.Height;
//
//          image.Draw(new RectangleF(iconX, iconY, iconWidth, iconHeight), image.AlignmentRect, NSCompositingOperation.SourceOver, 1.0f, true, null);
//
//          newRect = new RectangleF(iconX + iconWidth, cellFrame.Y, cellFrame.Width - iconX - iconWidth, cellFrame.Height - 1);
//       }
//
//       base.DrawWithFrame(newRect, inView);
//    }

        public override void DrawInteriorWithFrame(RectangleF cellFrame, NSView inView)
        {
            float iconX      = 0f;
            float iconY      = 0f;
            float iconWidth  = 0f;
            float iconHeight = 0f;

            cellFrame.X      = cellFrame.X - 10;
            cellFrame.Height = cellFrame.Height - 1;
            RectangleF newRect = cellFrame;

            if (image != null)
            {
                iconX      = cellFrame.X + 1;
                iconY      = cellFrame.Y + 2;
                iconWidth  = image.Size.Width;
                iconHeight = image.Size.Height;

                image.Draw(new RectangleF(iconX, iconY, iconWidth, iconHeight), image.AlignmentRect, NSCompositingOperation.SourceOver, 1.0f, true, null);

                newRect = new RectangleF(iconX + iconWidth, cellFrame.Y, cellFrame.Width - iconX - iconWidth, cellFrame.Height - 1);
            }

            base.DrawInteriorWithFrame(newRect, inView);
        }
コード例 #5
0
        public override void DrawWithFrame(RectangleF cellFrame, NSView inView)
        {
            //Assert (!_deallocCalled, "DrawWithFrame: Dealloc was called on object");
            //Assert (!_disposeCalled, "DrawWithFrame: Dispose was called on object");

            if (_image != null)
            {
                RectangleF imageFrame;
                cellFrame.Divide(3 + _image.Size.Width, CGRectEdge.MinXEdge, out imageFrame, out cellFrame);

                if (DrawsBackground)
                {
                    BackgroundColor.Set();
                    NSGraphics.RectFill(imageFrame);
                }

                imageFrame.X   += 3;
                imageFrame.Size = _image.Size;

                //if (inView.IsFlipped) {
                //	imageFrame.Y += (float)Math.Ceiling((cellFrame.Height + imageFrame.Height) / 2);
                //}
                //else {
                imageFrame.Y += (float)Math.Ceiling((cellFrame.Height - imageFrame.Height) / 2);
                //}

                _image.Draw(imageFrame, new RectangleF(PointF.Empty, _image.Size), NSCompositingOperation.SourceOver, 1f, true, null);
            }

            base.DrawWithFrame(cellFrame, inView);
        }
コード例 #6
0
ファイル: StatusBar.cs プロジェクト: srsmithdata/monodevelop
        public override void DrawRect(CGRect dirtyRect)
        {
            if (iconImage == null || resultString == null)
            {
                return;
            }

            iconImage.Draw(new CGRect(0, (Frame.Size.Height - iconImage.Size.Height) / 2, iconImage.Size.Width, iconImage.Size.Height));
            resultString.DrawAtPoint(new CGPoint(iconImage.Size.Width, (Frame.Size.Height - resultString.Size.Height) / 2));
        }
コード例 #7
0
        private bool DrawingHandler(CGRect dstRect)
        {
            BaseImage.Draw(dstRect);
            NSAffineTransform transform = new NSAffineTransform();

            transform.Scale(DrawingScale);
            transform.Concat();
            foreach (TextField.DrawingItem item in DrawingItems)
            {
                item.Draw();
            }
            return(true);
        }
コード例 #8
0
        public static void Colourize(NSView control, Color color, Action drawAction)
        {
            var size  = control.Frame.Size;
            var image = new NSImage(size);

            image.LockFocusFlipped(control.IsFlipped);
            drawAction();
            image.UnlockFocus();

            var ciImage = CIImage.FromData(image.AsTiff());

            if (control.IsFlipped)
            {
                var realSize        = control.ConvertSizeToBase(size);
                var affineTransform = new NSAffineTransform();
                affineTransform.Translate(0, realSize.Height);
                affineTransform.Scale(1, -1);
                var filter1 = CIFilter.FromName("CIAffineTransform");
                filter1.SetValueForKey(ciImage, CIInputImage);
                filter1.SetValueForKey(affineTransform, CIInputTransform);
                ciImage = filter1.ValueForKey(CIOutputImage) as CIImage;
            }

            var filter2 = CIFilter.FromName("CIColorControls");

            filter2.SetDefaults();
            filter2.SetValueForKey(ciImage, CIInputImage);
            filter2.SetValueForKey(new NSNumber(0.0f), CIInputSaturation);
            ciImage = filter2.ValueForKey(CIOutputImage) as CIImage;

            var filter3 = CIFilter.FromName("CIColorMatrix");

            filter3.SetDefaults();
            filter3.SetValueForKey(ciImage, CIInputImage);
            filter3.SetValueForKey(new CIVector(0, color.R, 0), CIInputRVector);
            filter3.SetValueForKey(new CIVector(color.G, 0, 0), CIInputGVector);
            filter3.SetValueForKey(new CIVector(0, 0, color.B), CIInputBVector);
            ciImage = filter3.ValueForKey(CIOutputImage) as CIImage;

            image = new NSImage(size);
            var rep = NSCIImageRep.FromCIImage(ciImage);

            image.AddRepresentation(rep);
            image.Draw(SD.PointF.Empty, new SD.RectangleF(SD.PointF.Empty, size), NSCompositingOperation.SourceOver, 1);

            /* Use this when implemented in maccore:
             * ciImage.Draw (SD.PointF.Empty, new SD.RectangleF (SD.PointF.Empty, size), NSCompositingOperation.SourceOver, 1);
             */
        }
コード例 #9
0
        NSImage MakeRotatedCopy(NSImage original, float degrees)
        {
            var copy = new NSImage(original.Size);

            copy.LockFocus();
            try {
                var rot = new NSAffineTransform();
                rot.Translate(original.Size.Width / 2, original.Size.Height / 2);
                rot.RotateByDegrees(degrees);
                rot.Translate(-original.Size.Width / 2, -original.Size.Height / 2);
                rot.Concat();
                original.Draw(PointF.Empty, RectangleF.Empty, NSCompositingOperation.Copy, 1);
            } finally {
                copy.UnlockFocus();
            }
            return(copy);
        }
コード例 #10
0
ファイル: NSImageExtensions.cs プロジェクト: MIliev11/Samples
        public static NSImage ResizeTo(this NSImage self, CoreGraphics.CGSize newSize)
        {
            if (self == null)
            {
                return(null);
            }
            self.ResizingMode = NSImageResizingMode.Stretch;
            var resizedImage = new NSImage(newSize);

            resizedImage.LockFocus();
            self.Size = newSize;
            NSGraphicsContext.CurrentContext.ImageInterpolation = NSImageInterpolation.High;
            self.Draw(CoreGraphics.CGPoint.Empty, new CoreGraphics.CGRect(0, 0, newSize.Width, newSize.Height),
                      NSCompositingOperation.Copy, 1.0f);
            resizedImage.UnlockFocus();
            return(resizedImage);
        }
コード例 #11
0
        public override void DrawRect(RectangleF dirtyRect)
        {
            Console.WriteLine("DrawRect(dirtyRect={0})", dirtyRect);
            // http://undefinedvalue.com/2009/07/07/adding-custom-view-nsstatusitem
            parentStatusItem.DrawStatusBarBackground(this.Bounds, IsMenuVisible);

            NSImage drawnImage = IsMenuVisible ? highlightedIcon : icon;

            RectangleF centeredRect = RectangleF.Empty;

            if (drawnImage != null)
            {
                // NSStatusBar.SystemStatusBar.Thickness == Bounds.Bottom? dunno
                centeredRect = new RectangleF((Bounds.Right - drawnImage.Size.Width) / 2, (Bounds.Bottom - drawnImage.Size.Height) / 2, drawnImage.Size.Width, drawnImage.Size.Height);
                drawnImage.Draw(centeredRect, RectangleF.Empty, NSCompositingOperation.SourceOver, 1f); // 1f is for full opacity
            }
        }
コード例 #12
0
        public void Badge()
        {
            using (NSAutoreleasePool a = new NSAutoreleasePool()) {
                foreach (string path in this.paths)
                {
                    string  extension = Path.GetExtension(path.ToLower());
                    NSImage new_icon  = new NSImage();

                    if (!this.icons.ContainsKey(extension))
                    {
                        foreach (int size in this.sizes)
                        {
                            NSImage file_icon = NSWorkspace.SharedWorkspace.IconForFileType(extension);
                            file_icon.Size = new SizeF(size, size);

                            // TODO: replace this with the sync icon
                            NSImage overlay_icon = NSWorkspace.SharedWorkspace.IconForFileType("sln");
                            overlay_icon.Size = new SizeF(size / 2, size / 2);

                            file_icon.LockFocus();
                            NSGraphicsContext.CurrentContext.ImageInterpolation = NSImageInterpolation.High;
                            overlay_icon.Draw(
                                new RectangleF(0, 0, file_icon.Size.Width / 3, file_icon.Size.Width / 3),
                                new RectangleF(), NSCompositingOperation.SourceOver, 1.0f);
                            file_icon.UnlockFocus();

                            new_icon.AddRepresentation(file_icon.Representations() [0]);
                        }


                        this.icons.Add(extension, new_icon);
                    }
                    else
                    {
                        new_icon = this.icons [extension];
                    }

                    NSWorkspace.SharedWorkspace.SetIconforFile(new_icon, path, 0);
                }
            }
        }
コード例 #13
0
        public static NSImage CreateIconWithSolutionName(string name, NSImage baseImage)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(baseImage);
            }

            const float margin = 4;
            var         text   = (NSString)name;

            // setup text styles
            var paragraphStyle = (NSParagraphStyle)NSParagraphStyle.DefaultParagraphStyle.MutableCopy();

            paragraphStyle.Alignment = NSTextAlignment.Center;
            var attributes = new NSStringAttributes
            {
                Font            = NSFont.SystemFontOfSize(19, NSFontWeight.Regular),
                ForegroundColor = NSColor.White,
                ParagraphStyle  = paragraphStyle
            };

            // setup rect
            var textRect         = new CGSize(baseImage.Size.Width - margin * 2, baseImage.Size.Height - 2 * margin);
            var rect             = text.BoundingRectWithSize(textRect, NSStringDrawingOptions.UsesLineFragmentOrigin, attributes.Dictionary);
            var centerAdjustment = baseImage.Size.Width - rect.Width - 2 * margin;

            rect.Offset(margin + centerAdjustment / 2, margin);

            // create image
            var brandedImage = NSImage.ImageWithSize(baseImage.Size, false, dstRect =>
            {
                baseImage.Draw(dstRect);
                DrawBackgroundInRect(rect);
                text.DrawInRect(rect, attributes);
                return(true);
            });

            return(brandedImage);
        }
コード例 #14
0
		NSImage MakeRotatedCopy (NSImage original, float degrees)
		{
			var copy = new NSImage (original.Size);
			copy.LockFocus ();
			try {
				var rot = new NSAffineTransform ();
				rot.Translate (original.Size.Width / 2, original.Size.Height / 2);
				rot.RotateByDegrees (degrees);
				rot.Translate (-original.Size.Width / 2, -original.Size.Height / 2);
				rot.Concat ();
				original.Draw (CGPoint.Empty, CGRect.Empty, NSCompositingOperation.Copy, 1);
			} finally {
				copy.UnlockFocus ();
			}
			return copy;
		}