Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Inventory"/> class.
 /// </summary>
 /// <param name="game">Reference to the Game.</param>
 public Inventory(Game game)
 {
     this.game = game;
     graphics = game.graphics;
     _open = false;
     x = y = 0;
     updateUICloseInventory();
 }
Exemplo n.º 2
0
        public Task <IScreenshotResult> CaptureAsync(UIWindow window)
        {
            _ = window ?? throw new ArgumentNullException(nameof(window));

            // NOTE: We rely on the window frame having been set to the correct size when this method is invoked.
            UIGraphics.BeginImageContextWithOptions(window.Bounds.Size, false, window.Screen.Scale);
            var ctx = UIGraphics.GetCurrentContext();

            if (!TryRender(window, out var error))
            {
                // FIXME: test/handle this case
            }

            // Render the status bar with the correct frame size
            try
            {
                TryHideStatusClockView(UIApplication.SharedApplication);
                var statusbarWindow = GetStatusBarWindow(UIApplication.SharedApplication);
                if (statusbarWindow != null /* && metrics.StatusBar != null*/)
                {
                    statusbarWindow.Frame = window.Frame;
                    statusbarWindow.Layer.RenderInContext(ctx);
                }
            }
            catch
            {
                // FIXME: test/handle this case
            }

            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            var result = new ScreenshotResult(image);

            return(Task.FromResult <IScreenshotResult>(result));
        }
Exemplo n.º 3
0
        public static void DrawUIControlWell(CGRect frame, bool inFocus, string title)
        {
            //// General Declarations
            var context = UIGraphics.GetCurrentContext();

            //// Color Declarations
            var wellColor = UIColor.FromRGBA(0.029f, 0.029f, 0.029f, 0.189f);

            //// Variable Declarations
            var textColor = inFocus ? CustomControlsStyleKit.InFocusTextColor : CustomControlsStyleKit.UnFocusedTextColor;

            //// Background Drawing
            var backgroundPath = UIBezierPath.FromRoundedRect(new CGRect(frame.GetMinX() + 1.0f, frame.GetMinY() + 1.0f, NMath.Floor((frame.Width - 1.0f) * 0.99749f + 0.5f), NMath.Floor((frame.Height - 1.0f) * 0.98990f + 0.5f)), 4.0f);

            wellColor.SetFill();
            backgroundPath.Fill();


            //// Text Drawing
            CGRect textRect = new CGRect(frame.GetMinX() + NMath.Floor(frame.Width * 0.03250f + 0.5f), frame.GetMinY() + NMath.Floor(frame.Height * 0.19000f + 0.5f), NMath.Floor(frame.Width * 0.97250f + 0.5f) - NMath.Floor(frame.Width * 0.03250f + 0.5f), NMath.Floor(frame.Height * 0.80000f + 0.5f) - NMath.Floor(frame.Height * 0.19000f + 0.5f));

            textColor.SetFill();
            var textStyle = new NSMutableParagraphStyle();

            textStyle.Alignment = UITextAlignment.Center;

            var textFontAttributes = new UIStringAttributes()
            {
                Font = UIFont.BoldSystemFontOfSize(27.0f), ForegroundColor = textColor, ParagraphStyle = textStyle
            };
            var textTextHeight = new NSString(title).GetBoundingRect(new CGSize(textRect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, textFontAttributes, null).Height;

            context.SaveState();
            context.ClipToRect(textRect);
            new NSString(title).DrawString(new CGRect(textRect.GetMinX(), textRect.GetMinY() + (textRect.Height - textTextHeight) / 2.0f, textRect.Width, textTextHeight), UIFont.BoldSystemFontOfSize(27.0f), UILineBreakMode.WordWrap, UITextAlignment.Center);
            context.RestoreState();
        }
Exemplo n.º 4
0
        public void SimpleValuesSet()
        {
            var sa = new CTStringAttributes();

            sa.ForegroundColor         = UIColor.Blue.CGColor;
            sa.Font                    = new CTFont("Georgia-BoldItalic", 24);
            sa.UnderlineStyle          = CTUnderlineStyle.Double;    // It does not seem to do anything
            sa.UnderlineColor          = UIColor.Blue.CGColor;
            sa.UnderlineStyleModifiers = CTUnderlineStyleModifiers.PatternDashDotDot;

            // CTBaseline and CTWritingDirection support is new in iOS 6.0 and cause NRE before it
            if (TestRuntime.CheckSystemAndSDKVersion(6, 0))
            {
                Assert.IsNull(sa.BaselineClass, "#0");
                sa.BaselineClass = CTBaselineClass.IdeographicHigh;
                Assert.AreEqual(CTBaselineClass.IdeographicHigh, sa.BaselineClass, "#1");

                sa.SetBaselineInfo(CTBaselineClass.Roman, 13);
                sa.SetBaselineInfo(CTBaselineClass.IdeographicHigh, 3);
                sa.SetWritingDirection(CTWritingDirection.LeftToRight);
            }

            var size = new SizeF(300, 300);

            UIGraphics.BeginImageContext(size);
            var gctx = UIGraphics.GetCurrentContext();

            gctx.SetFillColor(UIColor.Green.CGColor);

            var attributedString = new NSAttributedString("Test_ME~`", sa);

            using (var textLine = new CTLine(attributedString)) {
                textLine.Draw(gctx);
            }

            UIGraphics.EndImageContext();
        }
        UIImage DrawHamburger()
        {
            const string hamburgerKey = "Hamburger";
            UIImage      img          = (UIImage)_nSCache.ObjectForKey((NSString)hamburgerKey);

            if (img != null)
            {
                return(img);
            }

            var rect = new CGRect(0, 0, 23f, 23f);

            UIGraphics.BeginImageContextWithOptions(rect.Size, false, 0);
            var ctx = UIGraphics.GetCurrentContext();

            ctx.SaveState();
            ctx.SetStrokeColor(UIColor.Blue.CGColor);

            float size  = 3f;
            float start = 4f;

            ctx.SetLineWidth(size);

            for (int i = 0; i < 3; i++)
            {
                ctx.MoveTo(1f, start + i * (size * 2));
                ctx.AddLineToPoint(22f, start + i * (size * 2));
                ctx.StrokePath();
            }

            ctx.RestoreState();
            img = UIGraphics.GetImageFromCurrentImageContext();
            UIGraphics.EndImageContext();

            _nSCache.SetObjectforKey(img, (NSString)hamburgerKey);
            return(img);
        }
Exemplo n.º 6
0
        void DrawEmotionsOnImage(UIImage theImage, List <Emotion> allEmotions)
        {
            if (allEmotions == null)
            {
                return;
            }

            UIGraphics.BeginImageContext(theImage.Size);

            theImage.Draw(new CGPoint(0, 0));

            var ctx = UIGraphics.GetCurrentContext();

            ctx.SetLineWidth(10);

            foreach (var emotion in allEmotions)
            {
                var emotionColor = GetColorBasedOnEmotion(emotion.GetMainEmotion());
                ctx.SetStrokeColor(emotionColor);

                var right  = (nfloat)(emotion.FaceRectangle.Left + emotion.FaceRectangle.Width);
                var bottom = (nfloat)(emotion.FaceRectangle.Top + emotion.FaceRectangle.Height);

                var left = (nfloat)emotion.FaceRectangle.Left;
                var top  = (nfloat)emotion.FaceRectangle.Top;

                var factRect = CGRect.FromLTRB(left, top, right, bottom);

                ctx.StrokeRect(factRect);
            }

            var newImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            personPhoto.Image = newImage;
        }
        public async Task <byte[]> ResizeImage(byte[] imageData, float width, float height)
        {
            UIImage originalImage = ImageFromByteArray(imageData);

            var originalHeight = originalImage.Size.Height;
            var originalWidth  = originalImage.Size.Width;

            nfloat newHeight = 0;
            nfloat newWidth  = 0;

            if (originalHeight > originalWidth)
            {
                newHeight = height;
                nfloat ratio = originalHeight / height;
                newWidth = originalWidth / ratio;
            }
            else
            {
                newWidth = width;
                nfloat ratio = originalWidth / width;
                newHeight = originalHeight / ratio;
            }

            width  = (float)newWidth;
            height = (float)newHeight;

            UIGraphics.BeginImageContext(new SizeF(width, height));
            originalImage.Draw(new RectangleF(0, 0, width, height));
            var resizedImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            var bytesImagen = resizedImage.AsJPEG().ToArray();

            resizedImage.Dispose();
            return(bytesImagen);
        }
Exemplo n.º 8
0
        public override void Draw(RectangleF rect)
        {
            base.Draw(rect);

            CGContext gctx = UIGraphics.GetCurrentContext();

            gctx.TranslateCTM(0, Bounds.Height);
            gctx.ScaleCTM(1, -1);

            using (CGPDFPage pdfPg = _pdf.GetPage(PageNumber)) {
                gctx.SaveState();

                RectangleF        r  = new RectangleF(Bounds.Left, Bounds.Top, Bounds.Width, Bounds.Height + 44);
                CGAffineTransform tf = pdfPg.GetDrawingTransform(CGPDFBox.Crop, r, 0, true);
                gctx.ConcatCTM(tf);
                gctx.DrawPDFPage(pdfPg);

                gctx.RestoreState();
                gctx.TranslateCTM(5, Bounds.Height - 30);
                gctx.SelectFont("Helvetica", 25f, CGTextEncoding.MacRoman);
                gctx.SetFillColor(UIColor.Red.CGColor);
                gctx.ShowText(AnnotatedText);
            }
        }
Exemplo n.º 9
0
        public static UIImage?ConvertToImage(this UIView view)
        {
            if (!NativeVersion.IsAtLeast(10))
            {
                UIGraphics.BeginImageContext(view.Frame.Size);
                view.Layer.RenderInContext(UIGraphics.GetCurrentContext());
                var image = UIGraphics.GetImageFromCurrentImageContext();
                UIGraphics.EndImageContext();

                if (image.CGImage == null)
                {
                    return(null);
                }

                return(new UIImage(image.CGImage));
            }

            var imageRenderer = new UIGraphicsImageRenderer(view.Bounds.Size);

            return(imageRenderer.CreateImage((a) =>
            {
                view.Layer.RenderInContext(a.CGContext);
            }));
        }
Exemplo n.º 10
0
        public UIImage TouchImage()
        {
            if (touchImage == null)
            {
                UIBezierPath clipPath = UIBezierPath.FromRect(new CGRect(0, 0, 50, 50));

                UIGraphics.BeginImageContextWithOptions(clipPath.Bounds.Size, false, 0);
                UIBezierPath drawPath = UIBezierPath.FromArc(new CGPoint(25, 25), 22, 0, 2 * (nfloat)Math.PI, true);

                drawPath.LineWidth = 2;
                strokeColor.SetStroke();
                fillColor.SetFill();

                drawPath.Stroke();
                drawPath.Fill();

                clipPath.AddClip();

                touchImage = UIGraphics.GetImageFromCurrentImageContext();
                UIGraphics.EndImageContext();
            }

            return(touchImage);
        }
        public override void LoadView()
        {
            base.LoadView();

            /*
             * UIGraphicsBeginImageContext(objAppDelegate.window.frame.size);
             * [objAppDelegate.window.layer renderInContext:UIGraphicsGetCurrentContext()];
             * UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
             * UIGraphicsEndImageContext();
             *
             * UIViewController *controllerForBlackTransparentView=[[[UIViewController alloc] init] autorelease];
             * [controllerForBlackTransparentView setView:viewForProfanity];
             *
             * UIImageView *imageForBackgroundView=[[UIImageView alloc] initWithFrame:CGRectMake(0, -20, 320, 480)];
             * [imageForBackgroundView setImage:viewImage];
             *
             * [viewForProfanity insertSubview:imageForBackgroundView atIndex:0];
             *
             * [self.navigationController presentModalViewController:controllerForBlackTransparentView animated:YES];
             */

            UIGraphics.BeginImageContext(UIApplication.SharedApplication.Delegate.Window.Frame.Size);
            UIApplication.SharedApplication.Delegate.Window.Layer.RenderInContext(UIGraphics.GetCurrentContext());
            UIImage image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            //backgroundImageView = new UIImageView(new RectangleF(0,-20,320,480));
            //backgroundImageView = new UIImageView(new RectangleF(0,-20,this.View.Frame.Width,this.View.Frame.Height));
            //backgroundImageView = new UIImageView(new RectangleF(0,0,this.View.Frame.Width,this.View.Frame.Height));
            var width  = UIApplication.SharedApplication.Delegate.Window.Frame.Width;
            var height = UIApplication.SharedApplication.Delegate.Window.Frame.Height;

            backgroundImageView       = new UIImageView(new RectangleF(0, -20, width, height));
            backgroundImageView.Image = image;
        }
Exemplo n.º 12
0
        public override void Draw(RectangleF rect)
        {
            base.Draw(rect);
            float midY   = this.Bounds.Height / 2f;
            float right  = this.Bounds.Width;
            float bottom = this.Bounds.Height;

            var ctx = UIGraphics.GetCurrentContext();

            ctx.SaveState();
            CGPath path = new CGPath();

            path.MoveToPoint(new PointF(right, 0f));
            path.AddLineToPoint(2f, midY);
            path.AddLineToPoint(right, bottom);
            ctx.AddPath(path);
            ctx.SetStrokeColor(UIColor.Black.CGColor);
            ctx.SetLineWidth(2f);
            ctx.SetLineCap(CGLineCap.Round);
            ctx.StrokePath();
            ctx.RestoreState();
            ctx.Dispose();
            path.Dispose();
        }
Exemplo n.º 13
0
        private void SetupIcon()
        {
            if (_withIcon)
            {
                UIImage image = null;

                try
                {
                    image = UIImage.FromFile(_materialButton.Image.File) ?? UIImage.FromBundle(_materialButton.Image.File);

                    UIGraphics.BeginImageContextWithOptions(new CGSize(18, 18), false, 0f);
                    image?.Draw(new CGRect(0, 0, 18, 18));

                    using (var newImage = UIGraphics.GetImageFromCurrentImageContext())
                    {
                        UIGraphics.EndImageContext();

                        this.Control.SetImage(newImage, UIControlState.Normal);
                        this.Control.SetImage(newImage, UIControlState.Disabled);

                        this.Control.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
                        this.Control.ImageEdgeInsets     = new UIEdgeInsets(0f, 0f, 0f, 0f);
                        this.Control.TintColor           = _materialButton.TextColor.ToUIColor();
                    }
                }
                finally
                {
                    image?.Dispose();
                }
            }
            else
            {
                this.Control.TitleEdgeInsets     = new UIEdgeInsets(0, 0, 0, 0);
                this.Control.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
            }
        }
        private UIImage GetIconForText(string text, UIImage baseImage)
        {
            var nsText = new NSString(text);
            var icon   = iconCache.ObjectForKey(nsText);

            if (icon != null)
            {
                return((UIImage)icon);
            }

            var font = UIFont.BoldSystemFontOfSize(12);
            var size = baseImage.Size;

            UIGraphics.BeginImageContextWithOptions(size, false, 0.0f);
            baseImage.Draw(new CGRect(0, 0, size.Width, size.Height));
            var rect = new CGRect(0, 0, baseImage.Size.Width, baseImage.Size.Height);

            var paragraphStyle = NSParagraphStyle.Default;
            var attributes     = new UIStringAttributes(NSDictionary.FromObjectsAndKeys(
                                                            objects: new NSObject[] { font, paragraphStyle, options.RendererTextColor.ToUIColor() },
                                                            keys: new NSObject[] { UIStringAttributeKey.Font, UIStringAttributeKey.ParagraphStyle, UIStringAttributeKey.ForegroundColor }
                                                            ));

            var textSize = nsText.GetSizeUsingAttributes(attributes);
            var textRect = RectangleFExtensions.Inset(rect, (rect.Size.Width - textSize.Width) / 3,
                                                      (rect.Size.Height - textSize.Height) / 1);

            nsText.DrawString(RectangleFExtensions.Integral(textRect), attributes);

            var newImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            iconCache.SetObjectforKey(newImage, nsText);
            return(newImage);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Scales the icon to the requestes size and centers it
        /// </summary>
        /// <param name="icon">Icon which shall be customized</param>
        /// <returns>The customized icon</returns>
        private static UIImage ResizeFilerIcon(UIImage icon)
        {
            if (icon == null)
            {
                return(null);
            }

            const float desiredSize = 40;

            var imageSize = icon.Size;

            var scale           = Math.Min(desiredSize / imageSize.Width, desiredSize / imageSize.Height);
            var imageScaledSize = new CGSize(imageSize.Width * scale, imageSize.Height * scale);
            var imageLocation   = new CGPoint((desiredSize - imageScaledSize.Width) / 2, (desiredSize - imageScaledSize.Height) / 2);

            UIGraphics.BeginImageContextWithOptions(new CGSize(desiredSize, desiredSize), false, UIScreen.MainScreen.Scale);

            icon.Draw(new CGRect(imageLocation, imageScaledSize));

            icon = UIGraphics.GetImageFromCurrentImageContext();
            UIGraphics.EndImageContext();

            return(icon);
        }
Exemplo n.º 16
0
        private void UpdateImageViewColorFilter(UIColor color)
        {
            var image = Control.Image;

            if (image == null)
            {
                return;
            }
            UIGraphics.BeginImageContextWithOptions(image.Size, false, image.CurrentScale);
            var context = UIGraphics.GetCurrentContext(); //获得Context的引用

            context.TranslateCTM(0, image.Size.Height);
            context.ScaleCTM(1.0f, -1.0f);
            context.SetBlendMode(CGBlendMode.Normal);
            var rect = new CGRect(0, 0, image.Size.Width, image.Size.Height);

            context.ClipToMask(rect, image.CGImage);
            context.SetFillColor(color.CGColor);
            context.FillRect(rect);
            var newImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            Control.Image = newImage;
        }
Exemplo n.º 17
0
        private UIImage ScaleImageDown(UIImage sourceImage)
        {
            // Scale image to fit max size preserving aspect ratio

            var sourceSize      = sourceImage.Size;
            var maxResizeFactor = Math.Min(MAX_IMAGE_SIZE / sourceSize.Width, MAX_IMAGE_SIZE / sourceSize.Height);

            if (maxResizeFactor > 1)
            {
                return(sourceImage);
            }

            var width  = maxResizeFactor * sourceSize.Width;
            var height = maxResizeFactor * sourceSize.Height;

            UIGraphics.BeginImageContext(new CGSize(width, height));
            sourceImage.Draw(new CGRect(0, 0, width, height));

            var resultImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(resultImage);
        }
        /// <summary>
        /// Generates the image for button.
        /// </summary>
        /// <param name="rect">The rect.</param>
        /// <returns>UIImage.</returns>
        private UIImage GenerateImageForButton(CGRect rect)
        {
            UIGraphics.BeginImageContextWithOptions(rect.Size, false, 0);
            UIImage image;

            using (var context = UIGraphics.GetCurrentContext())
            {
                CGPoint p1, p2, p3;
                if (_arrowDirection == ArrowDirection.Left)
                {
                    p1    = new CGPoint(0, (rect.Height) / 2);
                    p2    = new CGPoint(rect.Width, 0);
                    p3    = new CGPoint(rect.Width, rect.Height);
                    image = new UIImage("icLeft");
                }
                else
                {
                    p1    = new CGPoint(rect.Width, rect.Height / 2);
                    p2    = new CGPoint(0, 0);
                    p3    = new CGPoint(0, rect.Height);
                    image = new UIImage("icRight");
                }

                context.SetFillColor(UIColor.Clear.CGColor);
                context.FillRect(rect);
                context.SetFillColor(_color.CGColor);
                context.MoveTo(p1.X, p1.Y);
                context.AddLineToPoint(p2.X, p2.Y);
                context.AddLineToPoint(p3.X, p3.Y);
                context.FillPath();
                // image = UIGraphics.GetImageFromCurrentImageContext();
            }

            UIGraphics.EndImageContext();
            return(image);
        }
Exemplo n.º 19
0
        CGBitmapContext CreateTextBitmapContext(string str, out byte[] bitmapData)
        {
            NSString text   = new NSString(str);
            UIFont   font   = UIFont.FromName("HelveticaNeue-Light", 128);
            SizeF    size   = text.StringSize(font);
            int      width  = (int)size.Width;
            int      height = (int)size.Height;

            bitmapData = new byte[256 * 256 * 4];
            CGBitmapContext bitmapContext = new CGBitmapContext(bitmapData, 256, 256, 8, 256 * 4, CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedLast);

            //Console.WriteLine ("bitmap context size: {0} x {1}", bitmapContext.Width, bitmapContext.Height);
            UIGraphics.PushContext(bitmapContext);
            float grayLevel = str == " " ? .8f : 1;

            bitmapContext.SetRGBFillColor(grayLevel, grayLevel, grayLevel, 1);
            bitmapContext.FillRect(new RectangleF(0, 0, 256.0f, 256.0f));
            bitmapContext.SetRGBFillColor(0, 0, 0, 1);

            text.DrawString(new PointF((256.0f - width) / 2.0f, (256.0f - height) / 2.0f + font.Descender), font);
            UIGraphics.PopContext();

            return(bitmapContext);
        }
        public UIImage Render(BitMatrix matrix, BarcodeFormat format, string content, EncodingOptions options)
        {
            UIGraphics.BeginImageContext(new CGSize(matrix.Width, matrix.Height));
            var context = UIGraphics.GetCurrentContext();

            var black = new CGColor(0f, 0f, 0f);
            var white = new CGColor(1.0f, 1.0f, 1.0f);

            for (int x = 0; x < matrix.Width; x++)
            {
                for (int y = 0; y < matrix.Height; y++)
                {
                    context.SetFillColor(matrix[x, y] ? black : white);
                    context.FillRect(new CGRect(x, y, 1, 1));
                }
            }


            var img = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(img);
        }
Exemplo n.º 21
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            window = new UIWindow(UIScreen.MainScreen.Bounds);

            viewController = new MergeImagesViewController();

            image1 = UIImage.FromFile("monkey1.png");
            image2 = UIImage.FromFile("monkey2.png");

            UIGraphics.BeginImageContext(UIScreen.MainScreen.Bounds.Size);

            image1.Draw(new CGRect(
                            0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height));

            image2.Draw(new CGRect(
                            UIScreen.MainScreen.Bounds.Width / 4,
                            UIScreen.MainScreen.Bounds.Height / 4,
                            UIScreen.MainScreen.Bounds.Width / 2,
                            UIScreen.MainScreen.Bounds.Height / 2));

            combinedImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            combinedImageView = new UIImageView(
                new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height));

            combinedImageView.Image = combinedImage;

            viewController.View.AddSubview(combinedImageView);

            window.RootViewController = viewController;
            window.MakeKeyAndVisible();

            return(true);
        }
Exemplo n.º 22
0
        public static CALayer MakeBackgroundLayer(UIImage image, RectangleF frame)
        {
            var textureColor = UIColor.FromPatternImage(image);

            UIGraphics.BeginImageContext(frame.Size);

            var c = UIGraphics.GetCurrentContext();

            image.DrawAsPatternInRect(frame);

            //Images.MenuShadow.Draw (frame);
            var result = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            var back = new CALayer {
                Frame = frame
            };

            //TODO:
            //Graphics.ConfigLayerHighRes (back);
            back.Contents = result.CGImage;
            return(back);
        }
        /// <summary>
        /// Draws the other.
        /// </summary>
        /// <exception cref="System.NotImplementedException"></exception>
        private void DrawOther()
        {
            int height;
            int width;

            switch (Element.Aspect)
            {
            case Aspect.AspectFill:
                height = (int)Control.Image.Size.Height;
                width  = (int)Control.Image.Size.Width;
                height = MakeSquare(height, ref width);
                break;

            case Aspect.AspectFit:
                height = (int)Control.Image.Size.Height;
                width  = (int)Control.Image.Size.Width;
                height = MakeSquare(height, ref width);
                break;

            default:
                throw new NotImplementedException();
            }

            UIImage image    = Control.Image;
            var     clipRect = new CGRect(0, 0, width, height);
            var     scaled   = image.Scale(new CGSize(width, height));

            UIGraphics.BeginImageContextWithOptions(new CGSize(width, height), false, 0f);
            UIBezierPath.FromRoundedRect(clipRect, Math.Max(width, height) / 2).AddClip();

            scaled.Draw(new CGRect(0, 0, scaled.Size.Width, scaled.Size.Height));
            UIImage final = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            Control.Image = final;
        }
Exemplo n.º 24
0
        public override void DrawRect(CGRect area, UIViewPrintFormatter formatter)
        {
            base.DrawRect(area, formatter);
            nfloat cellSize = area.Width / cellCount;
            var    context  = UIGraphics.GetCurrentContext();

            context.SetLineWidth(1);
            context.SetStrokeColor(UIColor.Gray.CGColor);

            for (int row = 0; row < cellSize; row++)
            {
                nfloat    top     = row * cellSize;
                CGPoint[] pointsH = { new CGPoint(0, top), new CGPoint(area.Width, top) };
                context.AddLines(pointsH);
                for (int column = 0; column < cellSize; column++)
                {
                    nfloat    left    = column * cellSize;
                    CGPoint[] pointsV = { new CGPoint(left, 0), new CGPoint(left, area.Height) };
                    context.AddLines(pointsV);
                }
            }

            context.DrawPath(CGPathDrawingMode.FillStroke);
        }
Exemplo n.º 25
0
        public override void Draw(CGRect dirtyRect)
        {
            base.Draw(dirtyRect);

            if (designMode || !isVisible || drawable == null)
            {
                return;
            }

            // create the skia context
            using var surface = drawable.CreateSurface(Bounds, IgnorePixelScaling ? 1 : ContentScaleFactor, out var info);
            if (info.Width == 0 || info.Height == 0)
            {
                return;
            }

            using var ctx = UIGraphics.GetCurrentContext();

            // draw on the image using SKiaSharp
            OnPaintSurface(new SKPaintSurfaceEventArgs(surface, info));

            // draw the surface to the context
            drawable.DrawSurface(ctx, Bounds, info, surface);
        }
Exemplo n.º 26
0
        public Task <UIImage> LoadImageAsync(
            ImageSource imagesource,
            CancellationToken cancelationToken = default(CancellationToken),
            float scale = 1f)
        {
            UIImage image      = null;
            var     fontsource = imagesource as FontImageSource;

            if (fontsource != null)
            {
                //This will allow lookup from the Embedded Fonts
                var cleansedname = FontExtensions.CleanseFontName(fontsource.FontFamily);
                var font         = UIFont.FromName(cleansedname ?? string.Empty, (float)fontsource.Size) ??
                                   UIFont.SystemFontOfSize((float)fontsource.Size);
                var iconcolor = fontsource.Color.IsDefault ? _defaultColor : fontsource.Color;
                var attString = new NSAttributedString(fontsource.Glyph, font: font, foregroundColor: iconcolor.ToUIColor());
                var imagesize = ((NSString)fontsource.Glyph).GetSizeUsingAttributes(attString.GetUIKitAttributes(0, out _));

                UIGraphics.BeginImageContextWithOptions(imagesize, false, 0f);
                var ctx          = new NSStringDrawingContext();
                var boundingRect = attString.GetBoundingRect(imagesize, (NSStringDrawingOptions)0, ctx);
                attString.DrawString(new RectangleF(
                                         imagesize.Width / 2 - boundingRect.Size.Width / 2,
                                         imagesize.Height / 2 - boundingRect.Size.Height / 2,
                                         imagesize.Width,
                                         imagesize.Height));
                image = UIGraphics.GetImageFromCurrentImageContext();
                UIGraphics.EndImageContext();

                if (image != null && iconcolor != _defaultColor)
                {
                    image = image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
                }
            }
            return(Task.FromResult(image));
        }
Exemplo n.º 27
0
 public override void Draw(CGRect rect)
 {
     base.Draw(rect);
     using (CGContext g = UIGraphics.GetCurrentContext())
     {
         var sample = new CGPath();
         sample.AddLines(new CGPoint[] {
             new CGPoint(Frame.Width / 2, 0), new CGPoint(Frame.Width / 2.8, Frame.Height / 2.5),
             new CGPoint(0, Frame.Height / 2.5),
             new CGPoint(Frame.Width / 3.5, Frame.Height / 1.75),
             new CGPoint(Frame.Width / 7, Frame.Height),
             new CGPoint(Frame.Width / 2, Frame.Height / 1.4),
             new CGPoint(Frame.Width / 1.2, Frame.Height),
             new CGPoint(Frame.Width / 1.4, Frame.Height / 1.75),
             new CGPoint(Frame.Width, Frame.Height / 2.5),
             new CGPoint(Frame.Width / 1.6, Frame.Height / 2.5),
             new CGPoint(Frame.Width / 2, 0)
         });
         g.AddPath(sample);
         UIColor.White.SetStroke();
         UIColor.White.SetFill();
         g.DrawPath(CGPathDrawingMode.FillStroke);
     }
 }
Exemplo n.º 28
0
        public Task <UIImage> LoadImageAsync(
            ImageSource imagesource,
            CancellationToken cancelationToken = default(CancellationToken),
            float scale = 1f)
        {
            UIImage image      = null;
            var     fontsource = imagesource as FontImageSource;

            if (fontsource != null)
            {
                var iconcolor     = fontsource.Color != Color.Default ? fontsource.Color : Color.White;
                var imagesize     = new SizeF((float)fontsource.Size, (float)fontsource.Size);
                var hasFontFamily = fontsource.FontFamily != null && UIFont.FamilyNames.Contains(fontsource.FontFamily);
                var font          = hasFontFamily ?
                                    UIFont.FromName(fontsource.FontFamily, (float)fontsource.Size) :
                                    UIFont.SystemFontOfSize((float)fontsource.Size);

                UIGraphics.BeginImageContextWithOptions(imagesize, false, 0f);
                var attString    = new NSAttributedString(fontsource.Glyph, font: font, foregroundColor: iconcolor.ToUIColor());
                var ctx          = new NSStringDrawingContext();
                var boundingRect = attString.GetBoundingRect(imagesize, (NSStringDrawingOptions)0, ctx);
                attString.DrawString(new RectangleF(
                                         imagesize.Width / 2 - boundingRect.Size.Width / 2,
                                         imagesize.Height / 2 - boundingRect.Size.Height / 2,
                                         imagesize.Width,
                                         imagesize.Height));
                image = UIGraphics.GetImageFromCurrentImageContext();
                UIGraphics.EndImageContext();

                if (iconcolor != Color.Default)
                {
                    image = image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
                }
            }
            return(Task.FromResult(image));
        }
Exemplo n.º 29
0
        private UIImage Scale(UIImage source)
        {
            UIGraphics.BeginImageContext(new SizeF(dimx, dimy));
            var ctx = UIGraphics.GetCurrentContext();

            var img = source.CGImage;

            ctx.TranslateCTM(0, dimy);
            if (img.Width > img.Height)
            {
                ctx.ScaleCTM(1, -img.Width / dimy);
            }
            else
            {
                ctx.ScaleCTM(img.Height / dimx, -1);
            }

            ctx.DrawImage(rect, source.CGImage);

            var ret = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(ret);
        }
Exemplo n.º 30
0
        public sealed override void Draw(CGRect rect)
        {
            base.Draw(rect);

            if (!CanDraw(rect))
            {
                return;
            }

            Stopwatch sw = null;

            if (ShowDebugMessages)
            {
                sw = Stopwatch.StartNew();
            }

            if (rect.Size != ViewPort.ViewPortSize)
            {
                ViewSizeChanged(rect.Size);
            }

            PrepareToDraw(rect);

            using (CGContext context = UIGraphics.GetCurrentContext())
            {
                context.SetShouldAntialias(true);
                DrawContent(context);
            }

            if (ShowDebugMessages)
            {
                sw?.Stop();

                Trace($"[{ViewPort}]: Perfomance is {(sw?.ElapsedMilliseconds < 1000f / 60 ? "Ok" : "Poor")}");
            }
        }
Exemplo n.º 31
0
        private async static void SetImageAsync(ImageSource source, MNFloatingActionButton targetButton)
        {
            var widthRequest  = targetButton.Frame.Width;
            var heightRequest = targetButton.Frame.Height;

            var handler = GetHandler(source);

            using (UIImage image = await handler.LoadImageAsync(source))
            {
                UIGraphics.BeginImageContext(new CoreGraphics.CGSize(widthRequest, heightRequest));
                image.Draw(new CoreGraphics.CGRect(0, 0, widthRequest, heightRequest));
                using (var resultImage = UIGraphics.GetImageFromCurrentImageContext())
                {
                    if (resultImage != null)
                    {
                        UIGraphics.EndImageContext();
                        using (var resizableImage = resultImage.CreateResizableImage(new UIEdgeInsets(0f, 0f, widthRequest, heightRequest)))
                        {
                            targetButton.CenterImageView.Image = resizableImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
                        }
                    }
                }
            }
        }
Exemplo n.º 32
0
    /// <summary>
    /// Start the game, this is used for initialization.
    /// </summary>
    void Start()
    {
        world = new World();
        camera2D = new Camera2D(world, world.spawnX, world.spawnY);
        smallWorldDrawOffsetX = (Camera2D.VIEW_TILES_WIDE - world.tilesWide) / 2;
        smallWorldDrawOffsetY = (Camera2D.VIEW_TILES_HIGH - world.tilesHigh) / 2;
        if (smallWorldDrawOffsetX < 0)
        {
            smallWorldDrawOffsetX = 0;
        }
        if (smallWorldDrawOffsetY < 0)
        {
            smallWorldDrawOffsetY = 0;
        }
        turnsTaken = 0;

        characters = new List<Character>();

        hero = new Character(world, world.spawnX, world.spawnY, BehaviorType.None);
        characters.Add(hero);
        hero.maxHealth = hero.health = 100;
        hero.baseType = Random.Range(0, Character.charBase.Length);
        hero.hairType = Random.Range(0, Character.charHair.Length);
        hero.legsType = Random.Range(0, Character.charLegs.Length);
        hero.torsoType = Random.Range(0, Character.charTorso.Length);
        hero.headType = Random.Range(0, Character.charHead.Length);
        hero.shieldType = Random.Range(0, Character.charShield.Length);
        hero.weaponType = Random.Range(0, Character.charWeapon.Length);

        for (int i = 0; i < 100; i++)
        {
            Character dummy = new Character(world, world.spawnX + (i % 10), world.spawnY + (i / 10), BehaviorType.Villager);
            characters.Add(dummy);
            dummy.baseType = Random.Range(0, Character.charBase.Length);
            dummy.hairType = Random.Range(0, Character.charHair.Length);
        }

        layers = new string[]{
            "Ground",
            "OverGround",
            "Wall",
            "DecorationBase",
            "WallTableDecoration",
            "Roof",
            "DecorationOverhead"
        };

        // Setup the board
        board = new GameObject();
        board.name = "Board";
        tiles = new GameObject[layers.Length, Camera2D.VIEW_TILES_WIDE + 2, Camera2D.VIEW_TILES_HIGH + 2];

        // Add tiles for each layer on the main screen and just off screen for transitions
        for (int layerIndex = 0; layerIndex < layers.Length; layerIndex++)
        {
            string layer = layers[layerIndex];
            for (int x = -1; x <= Camera2D.VIEW_TILES_WIDE; x++)
            {
                for (int y = -1; y <= Camera2D.VIEW_TILES_HIGH; y++)
                {
                    // Don't tile the corners off screen
                    if ((x == -1 || x == Camera2D.VIEW_TILES_WIDE) && (y == -1 || y == Camera2D.VIEW_TILES_HIGH))
                    {
                        continue;
                    }
                    GameObject tile = new GameObject(layer + "X-" + (x + 1) + "Y-" + (y + 1));
                    tile.AddComponent<SpriteRenderer>();
                    tile.GetComponent<SpriteRenderer>().sortingLayerName = layer;
                    tile.transform.position = new Vector3(x * 16, (y + 1) * 16, 0);
                    tile.transform.parent = board.transform;
                    tiles[layerIndex, x + 1, y + 1] = tile;
                }
            }
        }

        graphics = new UIGraphics(this);
        inventory = new Inventory(this);
        updateCharactersVisibility();
        updateCamera();
    }