コード例 #1
0
        public override void DrawImage(object backend, ImageDescription img, Rectangle srcRect, Rectangle destRect)
        {
            var       cb  = (CGContextBackend)backend;
            CGContext ctx = cb.Context;

            // Add the styles that have been globaly set to the context
            img.Styles = img.Styles.AddRange(cb.Styles);

            NSImage image = img.ToNSImage();

            ctx.SaveState();
            ctx.SetAlpha((float)img.Alpha);

            double rx = destRect.Width / srcRect.Width;
            double ry = destRect.Height / srcRect.Height;

            ctx.AddRect(new CGRect((nfloat)destRect.X, (nfloat)destRect.Y, (nfloat)destRect.Width, (nfloat)destRect.Height));
            ctx.Clip();
            ctx.TranslateCTM((float)(destRect.X - (srcRect.X * rx)), (float)(destRect.Y - (srcRect.Y * ry)));
            ctx.ScaleCTM((float)rx, (float)ry);

            if (image is CustomImage)
            {
                ((CustomImage)image).DrawInContext((CGContextBackend)backend);
            }
            else
            {
                var rr = new CGRect(0, 0, image.Size.Width, image.Size.Height);
                ctx.ScaleCTM(1f, -1f);
                ctx.DrawImage(new CGRect(0, -image.Size.Height, image.Size.Width, image.Size.Height), image.AsCGImage(ref rr, NSGraphicsContext.CurrentContext, null));
            }

            ctx.RestoreState();
        }
コード例 #2
0
ファイル: ContextBackendHandler.cs プロジェクト: wesreid/xwt
        public override void DrawImage(object backend, ImageDescription img, Rectangle srcRect, Rectangle destRect)
        {
            CGContext ctx   = ((CGContextBackend)backend).Context;
            NSImage   image = img.ToNSImage();

            ctx.SaveState();
            ctx.SetAlpha((float)img.Alpha);

            double rx = destRect.Width / srcRect.Width;
            double ry = destRect.Height / srcRect.Height;

            ctx.AddRect(new RectangleF((float)destRect.X, (float)destRect.Y, (float)destRect.Width, (float)destRect.Height));
            ctx.Clip();
            ctx.TranslateCTM((float)(destRect.X - (srcRect.X * rx)), (float)(destRect.Y - (srcRect.Y * ry)));
            ctx.ScaleCTM((float)rx, (float)ry);

            if (image is CustomImage)
            {
                ((CustomImage)image).DrawInContext((CGContextBackend)backend);
            }
            else
            {
                RectangleF rr = new RectangleF(0, 0, (float)image.Size.Width, image.Size.Height);
                ctx.ScaleCTM(1f, -1f);
                ctx.DrawImage(new RectangleF(0, -image.Size.Height, image.Size.Width, image.Size.Height), image.AsCGImage(ref rr, NSGraphicsContext.CurrentContext, null));
            }

            ctx.RestoreState();
        }
コード例 #3
0
ファイル: ButtonBackend.cs プロジェクト: codeyu/xwt
        public void SetContent(string label, ImageDescription image, ContentPosition imagePosition)
        {
            Widget.Title = label ?? "";
            if (string.IsNullOrEmpty(label))
            {
                imagePosition = ContentPosition.Center;
            }
            if (!image.IsNull)
            {
                var img = image.ToNSImage();
                Widget.Image           = (NSImage)img;
                Widget.Cell.ImageScale = NSImageScale.None;
                switch (imagePosition)
                {
                case ContentPosition.Bottom: Widget.ImagePosition = NSCellImagePosition.ImageBelow; break;

                case ContentPosition.Left: Widget.ImagePosition = NSCellImagePosition.ImageLeft; break;

                case ContentPosition.Right: Widget.ImagePosition = NSCellImagePosition.ImageRight; break;

                case ContentPosition.Top: Widget.ImagePosition = NSCellImagePosition.ImageAbove; break;

                case ContentPosition.Center: Widget.ImagePosition = string.IsNullOrEmpty(label) ? NSCellImagePosition.ImageOnly : NSCellImagePosition.ImageOverlaps; break;
                }
            }
            ResetFittingSize();
        }
コード例 #4
0
ファイル: ButtonBackend.cs プロジェクト: Level0r0s/xwt
        public void SetContent(string label, bool useMnemonic, ImageDescription image, ContentPosition imagePosition)
        {
            switch (((Button)Frontend).Type)
            {
            case ButtonType.Help:
            case ButtonType.Disclosure:
                return;
            }
            if (useMnemonic)
            {
                label = label.RemoveMnemonic();
            }
            if (customLabelColor.HasValue)
            {
                Widget.Title = label;
                var ns = new NSMutableAttributedString(Widget.AttributedTitle);
                ns.BeginEditing();
                var r = new NSRange(0, label.Length);
                ns.RemoveAttribute(NSStringAttributeKey.ForegroundColor, r);
                ns.AddAttribute(NSStringAttributeKey.ForegroundColor, customLabelColor.Value.ToNSColor(), r);
                ns.EndEditing();
                Widget.AttributedTitle = ns;
            }
            else
            {
                Widget.Title = label ?? "";
            }
            if (string.IsNullOrEmpty(label))
            {
                imagePosition = ContentPosition.Center;
            }
            if (!image.IsNull)
            {
                var img = image.ToNSImage();
                Widget.Image           = (NSImage)img;
                Widget.Cell.ImageScale = NSImageScale.None;
                switch (imagePosition)
                {
                case ContentPosition.Bottom: Widget.ImagePosition = NSCellImagePosition.ImageBelow; break;

                case ContentPosition.Left: Widget.ImagePosition = NSCellImagePosition.ImageLeft; break;

                case ContentPosition.Right: Widget.ImagePosition = NSCellImagePosition.ImageRight; break;

                case ContentPosition.Top: Widget.ImagePosition = NSCellImagePosition.ImageAbove; break;

                case ContentPosition.Center: Widget.ImagePosition = string.IsNullOrEmpty(label) ? NSCellImagePosition.ImageOnly : NSCellImagePosition.ImageOverlaps; break;
                }
            }
            else
            {
                Widget.ImagePosition = NSCellImagePosition.NoImage;
                Widget.Image         = null;
            }
            SetButtonStyle(currentStyle);
            ResetFittingSize();
        }
コード例 #5
0
        public override object Create(ImageDescription img)
        {
            NSImage nimg = img.ToNSImage();

            return(new ImagePatternInfo()
            {
                Image = nimg
            });
        }
コード例 #6
0
        public void SetImage(ImageDescription image)
        {
            if (image.IsNull)
            {
                Widget.Image = null;
                return;
            }

            Widget.Image = image.ToNSImage();
            Widget.SetFrameSize(Widget.Image.Size);
        }
コード例 #7
0
        public void SetImage(ImageDescription image)
        {
            if (image.IsNull)
            {
                // NSImage.Image incorrectly checks for null
                Messaging.void_objc_msgSend_IntPtr(Widget.Handle, setImage.Handle, IntPtr.Zero);
                return;
            }

            Widget.Image = image.ToNSImage();
            Widget.SetFrameSize(Widget.Image.Size);
        }
コード例 #8
0
        public void SetContent(string label, bool useMnemonic, ImageDescription image, ContentPosition imagePosition)
        {
            switch (((Button)Frontend).Type)
            {
            case ButtonType.Help:
            case ButtonType.Disclosure:
                return;
            }
            if (useMnemonic)
            {
                label = label.RemoveMnemonic();
            }
            Widget.Title = label ?? "";
            if (string.IsNullOrEmpty(label))
            {
                imagePosition = ContentPosition.Center;
            }
            if (!image.IsNull)
            {
                var img = image.ToNSImage();
                Widget.Image           = (NSImage)img;
                Widget.Cell.ImageScale = NSImageScale.None;
                switch (imagePosition)
                {
                case ContentPosition.Bottom: Widget.ImagePosition = NSCellImagePosition.ImageBelow; break;

                case ContentPosition.Left: Widget.ImagePosition = NSCellImagePosition.ImageLeft; break;

                case ContentPosition.Right: Widget.ImagePosition = NSCellImagePosition.ImageRight; break;

                case ContentPosition.Top: Widget.ImagePosition = NSCellImagePosition.ImageAbove; break;

                case ContentPosition.Center: Widget.ImagePosition = string.IsNullOrEmpty(label) ? NSCellImagePosition.ImageOnly : NSCellImagePosition.ImageOverlaps; break;
                }
            }
            SetButtonStyle(currentStyle);
            ResetFittingSize();
        }
コード例 #9
0
ファイル: MenuItemBackend.cs プロジェクト: wwwK/xwt
 public void SetImage(ImageDescription image)
 {
     item.Image = image.ToNSImage();
 }