void ApplyCurrentTheme() { // Set gradient color for the navigation bar's background CGSize gradientImageSize = new CGSize(NavigationBar.Frame.Size.Width, NavigationBar.Frame.Size.Height + 20.0f); UIImage gradientImage = ImageUtils.GetGradientImage( Theme.Current.MainGradientStartColor.CGColor, Theme.Current.MainGradientEndColor.CGColor, gradientImageSize); NavigationBar.BarTintColor = UIColor.FromPatternImage(gradientImage); }
public ResultsScreen (CGSize size) : base (size) { var timeLabel = new SKLabelNode ("GillSans-Bold") { Text = "Time: " + GameInfo.GameTimeInSeconds, FontSize = 24, Position = new CGPoint (FrameMidX, FrameMidY + 120) }; var modeLabel = new SKLabelNode ("GillSans-Bold") { Text = "Mode: " + GameInfo.GameMode, FontSize = 24, Position = new CGPoint (FrameMidX, FrameMidY + 60) }; var scoreLabel = new SKLabelNode ("GillSans-Bold") { Text = "Score: " + GameInfo.CurrentTaps, FontSize = 30, Position = new CGPoint (FrameMidX, FrameMidY) }; doneButton = new SKLabelNode ("GillSans-Bold") { Text = "Done", FontSize = 24, FontColor = ButtonColor, Position = new CGPoint (FrameMidX, FrameMidY - 90) }; AddChild (timeLabel); AddChild (modeLabel); AddChild (scoreLabel); AddChild (doneButton); }
public override void ViewDidLoad () { base.ViewDidLoad (); // no data IntPtr data = IntPtr.Zero; // size CGSize bitmapSize = new CGSize (200, 300); //View.Frame.Size; // 32bit RGB (8bits * 4components (aRGB) = 32bit) int bitsPerComponent = 8; // 4bytes for each pixel (32 bits = 4bytes) int bytesPerRow = (int)(4 * bitmapSize.Width); // no special color space CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB (); // aRGB CGImageAlphaInfo alphaType = CGImageAlphaInfo.PremultipliedFirst; using (CGBitmapContext context = new CGBitmapContext (data , (int)bitmapSize.Width, (int)bitmapSize.Height, bitsPerComponent , bytesPerRow, colorSpace, alphaType)) { // draw whatever here. } }
public override void Draw(CGRect rect) { base.Draw(rect); var inset = this.TextContainerInset; var leftInset = inset.Left + this.TextContainer.LineFragmentPadding; var rightInset = inset.Left + this.TextContainer.LineFragmentPadding; var maxSize = new CGSize() { Width = this.Frame.Width - (leftInset + rightInset), Height = this.Frame.Height - (inset.Top + inset.Bottom) }; var size = new NSString(this.Placeholder).StringSize(this.PlaceholderFont, maxSize, UILineBreakMode.WordWrap); var frame = new CGRect(new CGPoint(leftInset, inset.Top), size); this.placeholderLabel = new UILabel(frame) { BackgroundColor = UIColor.Clear, Font = this.PlaceholderFont, LineBreakMode = UILineBreakMode.WordWrap, Lines = 0, Text = this.Placeholder, TextColor = this.PlaceholderColor }; this.Add(this.placeholderLabel); }
protected override CGSize NativeMeasureOverride(CGSize availableSize) { var size = base.NativeMeasureOverride(availableSize); size.Height = MathF.Max(size.Height, DefaultSize + this.Margin.VerticalThicknessF()); size.Width = MathF.Max(size.Width, DefaultSize + this.Margin.HorizontalThicknessF()); return size; }
protected void DrawScreen () { // create our offscreen bitmap context // size CGSize bitmapSize = new CGSize (imageView.Frame.Size); using (CGBitmapContext context = new CGBitmapContext (IntPtr.Zero, (int)bitmapSize.Width, (int)bitmapSize.Height, 8, (int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB (), CGImageAlphaInfo.PremultipliedFirst)) { // save the state of the context while we change the CTM context.SaveState (); // draw our circle context.SetFillColor (1, 0, 0, 1); context.TranslateCTM (currentLocation.X, currentLocation.Y); context.RotateCTM (currentRotation); context.ScaleCTM (currentScale, currentScale); context.FillRect (new CGRect (-10, -10, 20, 20)); // restore our transformations context.RestoreState (); // draw our coordinates for reference DrawCoordinateSpace (context); // output the drawing to the view imageView.Image = UIImage.FromImage (context.ToImage ()); } }
public LineLayout () { ItemSize = new CGSize (ITEM_SIZE, ITEM_SIZE); ScrollDirection = UICollectionViewScrollDirection.Horizontal; SectionInset = new UIEdgeInsets (200, 0.0f, 200, 0.0f); MinimumLineSpacing = 50.0f; }
public override void DidFinishLaunching(NSNotification notification) { // Start the progress indicator animation. loadingProgressIndicator.StartAnimation (this); gameLogo.Image = new NSImage (NSBundle.MainBundle.PathForResource ("logo", "png")); archerButton.Image = new NSImage (NSBundle.MainBundle.PathForResource ("button_archer", "png")); warriorButton.Image = new NSImage (NSBundle.MainBundle.PathForResource ("button_warrior", "png")); // The size for the primary scene - 1024x768 is good for OS X and iOS. var size = new CGSize (1024, 768); // Load the shared assets of the scene before we initialize and load it. scene = new AdventureScene (size); scene.LoadSceneAssetsWithCompletionHandler (() => { scene.Initialize (); scene.ScaleMode = SKSceneScaleMode.AspectFill; SKView.PresentScene (scene); loadingProgressIndicator.StopAnimation (this); loadingProgressIndicator.Hidden = true; NSAnimationContext.CurrentContext.Duration = 2.0f; ((NSButton)archerButton.Animator).AlphaValue = 1.0f; ((NSButton)warriorButton.Animator).AlphaValue = 1.0f; scene.ConfigureGameControllers(); }); SKView.ShowsFPS = true; SKView.ShowsDrawCount = true; SKView.ShowsNodeCount = true; }
public static UIImage ImageFromFont(string text, UIColor iconColor, CGSize iconSize, string fontName) { UIGraphics.BeginImageContextWithOptions(iconSize, false, 0); var textRect = new CGRect(CGPoint.Empty, iconSize); var path = UIBezierPath.FromRect(textRect); UIColor.Clear.SetFill(); path.Fill(); var font = UIFont.FromName(fontName, iconSize.Width); using (var label = new UILabel() { Text = text, Font = font }) { GetFontSize(label, iconSize, 500, 5); font = label.Font; } iconColor.SetFill(); using (var nativeString = new NSString(text)) { nativeString.DrawString(textRect, new UIStringAttributes { Font = font, ForegroundColor = iconColor, BackgroundColor = UIColor.Clear, ParagraphStyle = new NSMutableParagraphStyle { Alignment = UITextAlignment.Center } }); } var image = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); image = image.ImageWithRenderingMode (UIImageRenderingMode.AlwaysOriginal); return image; }
public TilingView(string name, CGSize size) : base(new CGRect (CGPoint.Empty, size)) { ImageName = name; var tiledLayer = (CATiledLayer)this.Layer; tiledLayer.LevelsOfDetail = 4; }
private static UIImage CreateImage(string color) { try { var red = color.Substring(0, 2); var green = color.Substring(2, 2); var blue = color.Substring(4, 2); var redB = System.Convert.ToByte(red, 16); var greenB = System.Convert.ToByte(green, 16); var blueB = System.Convert.ToByte(blue, 16); var size = new CGSize(28f, 28f); var cgColor = UIColor.FromRGB(redB, greenB, blueB).CGColor; UIGraphics.BeginImageContextWithOptions(size, false, 0); var ctx = UIGraphics.GetCurrentContext(); ctx.SetLineWidth(1.0f); ctx.SetStrokeColor(cgColor); ctx.AddEllipseInRect(new CGRect(0, 0, size.Width, size.Height)); ctx.SetFillColor(cgColor); ctx.FillPath(); var image = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); return image; } catch { return null; } }
private static void GetFontSize(UILabel label, CGSize size, int maxFontSize, int minFontSize) { label.Frame = new CGRect(CGPoint.Empty, size); var fontSize = maxFontSize; var constraintSize = new CGSize(label.Frame.Width, nfloat.MaxValue); while (fontSize > minFontSize) { label.Font = UIFont.FromName(label.Font.Name, fontSize); using (var nativeString = new NSString(label.Text)) { var textRect = nativeString.GetBoundingRect( constraintSize, NSStringDrawingOptions.UsesFontLeading, new UIStringAttributes { Font = label.Font}, null ); if (textRect.Size.Height <= label.Frame.Height) { break; } } fontSize -= 2; } }
public override CGSize GetSizeForChildContentContainer (IUIContentContainer contentContainer, CGSize parentContainerSize) { if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) return parentContainerSize; else return new CGSize(parentContainerSize.Width / 3, parentContainerSize.Height); }
private UIImage CreatePieSegment(CGSize size, nfloat endAngle) { // Add the arc var arc = new CGPath(); arc.MoveToPoint(size.Width / 2.0f, size.Height / 2.0f); arc.AddLineToPoint(size.Width / 2.0f, 0); arc.AddArc(size.Width / 2.0f, size.Height / 2.0f, size.Width / 2.0f, _startAngle, endAngle, false); arc.AddLineToPoint(size.Width / 2.0f, size.Height / 2.0f); // Stroke the arc UIGraphics.BeginImageContextWithOptions(size, false, 0); var context = UIGraphics.GetCurrentContext(); context.AddPath(arc); context.SetFillColor(UIColor.FromRGBA(0f, 0f, 0f, 1f).CGColor); context.FillPath(); // Get the mask image var image = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); return image; }
internal NSTextContainer(CGSize size, bool isContainer) { if (isContainer) Handle = InitWithContainerSize (size); else Handle = InitWithSize (size); }
public PrimaryCell( CGSize parentSize, UITableViewCellStyle style, string cellIdentifier ) : base( style, cellIdentifier ) { BackgroundColor = Rock.Mobile.UI.Util.GetUIColor( ControlStylingConfig.BG_Layer_Color ); SelectionStyle = UITableViewCellSelectionStyle.None; Image = new UIImageView( ); Image.BackgroundColor = UIColor.Yellow; Image.ContentMode = UIViewContentMode.ScaleAspectFill; Image.Layer.AnchorPoint = CGPoint.Empty; AddSubview( Image ); // Banner Image Image.Image = new UIImage( NSBundle.MainBundle.BundlePath + "/" + PrivateConnectConfig.MainPageHeaderImage ); Image.SizeToFit( ); // resize the image to fit the width of the device nfloat imageAspect = Image.Bounds.Height / Image.Bounds.Width; Image.Frame = new CGRect( 0, 0, parentSize.Width, parentSize.Width * imageAspect ); Title = new UILabel( ); Title.Text = ConnectStrings.Main_Connect_Header; Title.Font = Rock.Mobile.PlatformSpecific.iOS.Graphics.FontManager.GetFont( ControlStylingConfig.Font_Bold, ControlStylingConfig.Large_FontSize ); Title.Layer.AnchorPoint = CGPoint.Empty; Title.TextColor = Rock.Mobile.UI.Util.GetUIColor( ControlStylingConfig.TextField_ActiveTextColor ); Title.LineBreakMode = UILineBreakMode.TailTruncation; Title.TextAlignment = UITextAlignment.Center; Title.Frame = new CGRect( 5, Image.Frame.Bottom, parentSize.Width - 10, 0 ); Title.SizeToFit( ); AddSubview( Title ); }
// Draws our animation path on the background image, just to show it void DrawPathAsBackground () { // create our offscreen bitmap context var bitmapSize = new CGSize (View.Frame.Size); using (var context = new CGBitmapContext ( IntPtr.Zero, (int)bitmapSize.Width, (int)bitmapSize.Height, 8, (int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB (), CGImageAlphaInfo.PremultipliedFirst)) { // convert to View space var affineTransform = CGAffineTransform.MakeIdentity (); // invert the y axis affineTransform.Scale (1f, -1f); // move the y axis up affineTransform.Translate (0, View.Frame.Height); context.ConcatCTM (affineTransform); // actually draw the path context.AddPath (animationPath); context.SetStrokeColor (UIColor.LightGray.CGColor); context.SetLineWidth (3f); context.StrokePath (); // set what we've drawn as the backgound image backgroundImage.Image = UIImage.FromImage (context.ToImage ()); } }
public void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTransitionCoordinator coordinator) { // This API sometime cannot return the correct value. // Maybe this is the Xamarin or iOS bug // https://bugzilla.xamarin.com/show_bug.cgi?id=37064 var menu = _basePage.SlideMenu; double NavigationBarHeight = 0; // this is used for rotation double bigValue = UIScreen.MainScreen.Bounds.Height > UIScreen.MainScreen.Bounds.Width ? UIScreen.MainScreen.Bounds.Height : UIScreen.MainScreen.Bounds.Width; double smallValue = UIScreen.MainScreen.Bounds.Height < UIScreen.MainScreen.Bounds.Width ? UIScreen.MainScreen.Bounds.Height : UIScreen.MainScreen.Bounds.Width; if (toSize.Width < toSize.Height) { ScreenSizeHelper.ScreenHeight = bigValue; // this is used for mutiltasking ScreenSizeHelper.ScreenWidth = toSize.Width < smallValue ? toSize.Width : smallValue; NavigationBarHeight = bigValue - toSize.Height; } else { ScreenSizeHelper.ScreenHeight = smallValue; ScreenSizeHelper.ScreenWidth = toSize.Width < bigValue ? toSize.Width : bigValue; NavigationBarHeight = smallValue - toSize.Height; } if (_dragGesture == null) return; menu.PageBottomOffset = NavigationBarHeight; _dragGesture.UpdateLayoutSize (menu); var rect = _dragGesture.GetHidePosition (); menu.Layout (new Xamarin.Forms.Rectangle ( rect.left, rect.top, (rect.right - rect.left), (rect.bottom - rect.top))); _dragGesture.LayoutHideStatus (); }
public SignatureController () : base(new UINavigationController()) { var navController = ContentViewController as UINavigationController; navController.ViewControllers = new UIViewController[] { new ContentController(this) }; PopoverContentSize = new CGSize(665, 400); }
public AchievementsScreen (CGSize size) : base (size) { var title = new SKLabelNode ("GillSans-Bold") { Text = "Achievements", FontSize = 30, Position = new CGPoint (FrameMidX, FrameMidY + 190) }; backButton = new SKLabelNode ("GillSans-Bold") { Text = "Back", FontSize = 18, FontColor = ButtonColor, Position = new CGPoint (FrameMidX, FrameMidY - 200) }; var incompleteLabel = new SKLabelNode ("GillSans-Bold") { Text = "Incomplete", FontSize = 18, Position = new CGPoint (FrameMidX + 75, FrameMidY + 150) }; var completeLabel = new SKLabelNode ("GillSans-Bold") { Text = "Complete", FontSize = 18, Position = new CGPoint (FrameMidX - 75, FrameMidY + 150) }; if (GKLocalPlayer.LocalPlayer.Authenticated) GKAchievementDescription.LoadAchievementDescriptions (LoadAchievementInfo); AddChild (title); AddChild (incompleteLabel); AddChild (completeLabel); AddChild (backButton); }
public override CGSize SizeThatFits(CGSize size) { var result = new CGSize(this.size, size.Height); if (size.Height == float.MaxValue) size.Height = 0; return result; }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); CGSize sz = Image.Size; if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) { if (UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.Portrait || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.PortraitUpsideDown) { sz = new CGSize(UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Width * (sz.Height/sz.Width)); } else { sz = new CGSize((UIScreen.MainScreen.Bounds.Height-NavigationController.NavigationBar.Bounds.Height) * (sz.Width/sz.Height), UIScreen.MainScreen.Bounds.Height-NavigationController.NavigationBar.Bounds.Height); } } else { if (sz.Width > sz.Height) { sz = new CGSize(PopoverSize.Height * (sz.Width/sz.Height), PopoverSize.Height); } else { sz = new CGSize(PopoverSize.Width, PopoverSize.Width * (sz.Height/sz.Width)); } } imageView.Frame = new CGRect(0, 0, sz.Width, sz.Height); imageView.Image = Image; scrollView.ContentSize = sz; scrollView.MinimumZoomScale = 0.25f; scrollView.MaximumZoomScale = 5f; scrollView.ViewForZoomingInScrollView += (UIScrollView sv) => {return imageView;}; if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { scrollView.ScrollRectToVisible(new CGRect(Image.Size.Width/2 - 300, Image.Size.Height/2 - 300, 600, 600), true); } }
protected override void CreateFrameBuffer () { nfloat screenScale = UIScreen.MainScreen.Scale; CAEAGLLayer eaglLayer = (CAEAGLLayer) Layer; CGSize size = new CGSize ( (int) Math.Round (screenScale * eaglLayer.Bounds.Size.Width), (int) Math.Round (screenScale * eaglLayer.Bounds.Size.Height)); try { ContextRenderingApi = EAGLRenderingAPI.OpenGLES3; base.CreateFrameBuffer (); int depthRenderbuffer; GL.GenRenderbuffers (1, out depthRenderbuffer); GL.BindRenderbuffer (RenderbufferTarget.Renderbuffer, depthRenderbuffer); GL.RenderbufferStorage (RenderbufferTarget.Renderbuffer, RenderbufferInternalFormat.DepthComponent16, (int)size.Width, (int)size.Height); GL.FramebufferRenderbuffer (FramebufferTarget.Framebuffer, FramebufferSlot.DepthAttachment, RenderbufferTarget.Renderbuffer, depthRenderbuffer); Console.WriteLine ("using ES 3.0"); Console.WriteLine ("version: {0} glsl version: {1}", GL.GetString (StringName.Version), GL.GetString (StringName.ShadingLanguageVersion)); } catch (Exception e) { throw new Exception ("Looks like OpenGL ES 3.0 not available", e); } cube.Initialize (); cube.LoadTexture (LoadBitmapData); SetupProjection (); }
private static CGSize RCTTargetSize(CGSize sourceSize, nfloat sourceScale, CGSize destSize, nfloat destScale, RCTResizeMode resizeMode, bool allowUpscaling) { switch (resizeMode) { case RCTResizeMode.ScaleToFill: if (!allowUpscaling) { nfloat scale = sourceScale / destScale; destSize.Width = (nfloat)Math.Min(sourceSize.Width * scale, destSize.Width); destSize.Height = (nfloat)Math.Min(sourceSize.Height * scale, destSize.Height); } return RCTCeilSize(destSize, destScale); default: { // Get target size CGSize size = RCTTargetRect(sourceSize, destSize, destScale, resizeMode).Size; if (!allowUpscaling) { // return sourceSize if target size is larger if (sourceSize.Width * sourceScale < size.Width * destScale) { return sourceSize; } } return size; } } }
public HIPImageCropperView(CGRect frame, CGSize cropSize, CropperViewPosition position, CropHoleType cropHoleType = CropHoleType.Square) : base(frame) { _maskPosition = position; _cropHoleType = cropHoleType; _cropSize = cropSize; this.BackgroundColor = UIColor.Black; this.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; this.ClipsToBounds = true; ScrollView = new UIScrollView(); ImageView = new UIImageView(); OverlayView = new UIView() { UserInteractionEnabled = false, BackgroundColor = UIColor.Black.ColorWithAlpha(0.6f), AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight }; LoadIndicator = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.White) { HidesWhenStopped = true, AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleTopMargin }; }
public InGameScene (CGSize size) : base (size) { BackgroundColor = AppKit.NSColor.FromCalibratedRgba (0.15f, 0.15f, 0.3f, 1f); timeLabel = LabelWithText ("Time", 24); AddChild (timeLabel); CGRect af = timeLabel.CalculateAccumulatedFrame (); timeLabel.Position = new CGPoint (Frame.Size.Width - af.Size.Width, Frame.Size.Height - (af.Size.Height)); timeLabelValue = LabelWithText ("102:00", 20); AddChild (timeLabelValue); CGRect timeLabelValueSize = timeLabelValue.CalculateAccumulatedFrame (); timeLabelValue.Position = new CGPoint (Frame.Size.Width - af.Size.Width - timeLabelValueSize.Size.Width - 10, Frame.Size.Height - af.Size.Height); scoreLabel = LabelWithText ("Score", 24); AddChild (scoreLabel); af = scoreLabel.CalculateAccumulatedFrame (); scoreLabel.Position = new CGPoint (af.Size.Width * 0.5f, Frame.Size.Height - af.Size.Height); scoreLabelValue = LabelWithText ("0", 24); AddChild (scoreLabelValue); scoreLabelValue.Position = new CGPoint (af.Size.Width * 0.75f + (timeLabelValueSize.Size.Width), Frame.Size.Height - af.Size.Height); // Add drop shadows to each label above. timeLabelValueShadow = DropShadowOnLabel (timeLabelValue); timeLabelShadow = DropShadowOnLabel (timeLabel); scoreLabelShadow = DropShadowOnLabel (scoreLabel); scoreLabelValueShadow = DropShadowOnLabel (scoreLabelValue); }
public override void ViewDidLoad () { base.ViewDidLoad (); // set the background color of the view to white View.BackgroundColor = UIColor.White; // instantiate a new image view that takes up the whole screen and add it to // the view hierarchy CGRect imageViewFrame = new CGRect (0, -NavigationController.NavigationBar.Frame.Height, View.Frame.Width, View.Frame.Height); imageView = new UIImageView (imageViewFrame); View.AddSubview (imageView); // create our offscreen bitmap context // size CGSize bitmapSize = new CGSize (View.Frame.Size); using (CGBitmapContext context = new CGBitmapContext (IntPtr.Zero, (int)bitmapSize.Width, (int)bitmapSize.Height, 8, (int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB (), CGImageAlphaInfo.PremultipliedFirst)) { // declare vars UIImage apressImage = UIImage.FromFile ("icon-114.png"); CGPoint imageOrigin = new CGPoint ((imageView.Frame.Width / 2) - (apressImage.CGImage.Width / 2), (imageView.Frame.Height / 2) - (apressImage.CGImage.Height / 2)); CGRect imageRect = new CGRect (imageOrigin.X, imageOrigin.Y, apressImage.CGImage.Width, apressImage.CGImage.Height); // draw the image context.DrawImage (imageRect, apressImage.CGImage); // output the drawing to the view imageView.Image = UIImage.FromImage (context.ToImage ()); } }
public override void ViewDidLoad () { base.ViewDidLoad (); ClearsSelectionOnViewWillAppear = false; ContentSizeForViewInPopover = new CGSize (320, 600); TableView.Source = new TableSource (); }
public override void ViewDidLoad () { base.ViewDidLoad (); // set the background color of the view to white View.BackgroundColor = UIColor.White; // instantiate a new image view that takes up the whole screen and add it to // the view hierarchy CGRect imageViewFrame = new CGRect (0, -NavigationController.NavigationBar.Frame.Height, View.Frame.Width, View.Frame.Height); imageView = new UIImageView (imageViewFrame); View.AddSubview (imageView); // create our offscreen bitmap context // size CGSize bitmapSize = new CGSize (imageView.Frame.Size); using (CGBitmapContext context = new CGBitmapContext (IntPtr.Zero, (int)bitmapSize.Width, (int)bitmapSize.Height, 8, (int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB (), CGImageAlphaInfo.PremultipliedFirst)) { // draw our coordinates for reference DrawCoordinateSpace (context); // draw our flag DrawFlag (context); // add a label DrawCenteredTextAtPoint (context, 384, 700, "Stars and Stripes", 60); // output the drawing to the view imageView.Image = UIImage.FromImage (context.ToImage ()); } }
public static UIImage MakeThumb(this UIImage image, CGSize size) { UIGraphics.BeginImageContextWithOptions(size, false, UIScreen.MainScreen.Scale); image.Draw(new CGRect(0, 0, size.Width, size.Height)); var thumb = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); return thumb; }
protected void ClearConstraints() { ConstrainedSize = default; ConstrainedDimension = default; }
public virtual CGRect BoundingRectWithSize(CGSize size, NSStringDrawingOptions options, [Optional] NSStringDrawingContext context) { return(default(CGRect)); }
public static Size GetSize(this CGSize size) { return(new Size(size.Width, size.Height)); }
public static SKPhysicsBody BodyWithRectangleOfSize(CGSize size, CGPoint center) { return(CreateRectangularBody(size, center)); }
public static SKPhysicsBody BodyWithRectangleOfSize(CGSize size) { return(CreateRectangularBody(size)); }
/* * MPMoviePlayerController _player; * private List<NSObject> _observers = new List<NSObject>(); * protected override void OnElementChanged(ElementChangedEventArgs<CustomVideoSlider> e) * { * base.OnElementChanged(e); * if (e.NewElement != null) * { * if (base.Control == null) * { * _player = new MPMoviePlayerController(); * _player.ScalingMode = MPMovieScalingMode.AspectFit; * * _player.ShouldAutoplay = true; * _player.ControlStyle = MPMovieControlStyle.None; * _player.MovieControlMode=MPMovieControlMode.Hidden; * _player.View.Frame = this.Bounds; * _player.BackgroundColor = UIColor.Clear; * base.SetNativeControl(_player.View); * var center = NSNotificationCenter.DefaultCenter; * // _observers.Add(center.AddObserver((NSString)"UIDeviceOrientationDidChangeNotification", DeviceRotated)); * _observers.Add(center.AddObserver(MPMoviePlayerController.PlaybackStateDidChangeNotification, OnLoadStateChanged)); * _observers.Add(center.AddObserver(MPMoviePlayerController.PlaybackDidFinishNotification, OnPlaybackComplete)); * _observers.Add(center.AddObserver(MPMoviePlayerController.WillExitFullscreenNotification, OnExitFullscreen)); * _observers.Add(center.AddObserver(MPMoviePlayerController.WillEnterFullscreenNotification, OnEnterFullscreen)); * * * * bootomToolbarView = new UIView() * { * TranslatesAutoresizingMaskIntoConstraints = false, * }; * * bootomToolbarView.AddObserver(this, (NSString)"bounds", NSKeyValueObservingOptions.New, IntPtr.Zero); * * gradientLayer = new CAGradientLayer(); * //gradientLayer.Frame = Bounds; * gradientLayer.Colors = new CGColor[] { UIColor.Clear.CGColor, UIColor.Orange.CGColor }; * gradientLayer.Locations= new NSNumber[2] {new NSNumber(0.7),new NSNumber(1.2)}; * bootomToolbarView.Layer.AddSublayer(gradientLayer); * this.InsertSubviewAbove(bootomToolbarView, _player.View); * * labelTimeLeft = new UILabel() * { * TranslatesAutoresizingMaskIntoConstraints = false, * Text = string.Format("{0:mm\\:ss}", TimeSpan.FromMilliseconds(slider.FileDuration ?? 0)), * TextColor = UIColor.White * }; * bootomToolbarView.AddSubview(labelTimeLeft); * * labelTimePlayed = new UILabel() * { * TranslatesAutoresizingMaskIntoConstraints = false, * Text = "00:00", * TextColor = UIColor.White * }; * * bootomToolbarView.AddSubview(labelTimePlayed); * * seekBar = new UISlider() * { * TranslatesAutoresizingMaskIntoConstraints = false, * MaximumTrackTintColor = Color.LightGray.ToUIColor(), * MinimumTrackTintColor = Color.White.ToUIColor(), * ThumbTintColor = Color.FromHex("#827DCE").ToUIColor() * * }; * * seekBar.TouchDown += Control_TouchDown; * seekBar.TouchUpInside += Control_TouchUpInside; * * bootomToolbarView.AddSubview(seekBar); * * bootomToolbarView.RightAnchor.ConstraintEqualTo(RightAnchor).Active = true; * bootomToolbarView.LeftAnchor.ConstraintEqualTo(LeftAnchor).Active = true; * bootomToolbarView.BottomAnchor.ConstraintEqualTo(BottomAnchor).Active = true; * bootomToolbarView.HeightAnchor.ConstraintEqualTo(40).Active = true; * * * labelTimeLeft.RightAnchor.ConstraintEqualTo(bootomToolbarView.RightAnchor, -10).Active = true; * labelTimeLeft.BottomAnchor.ConstraintEqualTo(bootomToolbarView.BottomAnchor, -10).Active = true; * labelTimeLeft.WidthAnchor.ConstraintEqualTo(50).Active = true; * labelTimeLeft.HeightAnchor.ConstraintEqualTo(20).Active = true; * * labelTimePlayed.LeftAnchor.ConstraintEqualTo(bootomToolbarView.LeftAnchor, 10).Active = true; * labelTimePlayed.BottomAnchor.ConstraintEqualTo(bootomToolbarView.BottomAnchor, -10).Active = true; * labelTimePlayed.WidthAnchor.ConstraintEqualTo(50).Active = true; * labelTimePlayed.HeightAnchor.ConstraintEqualTo(20).Active = true; * * seekBar.LeftAnchor.ConstraintEqualTo(labelTimePlayed.RightAnchor, 10).Active = true; * seekBar.RightAnchor.ConstraintEqualTo(labelTimeLeft.LeftAnchor, -10).Active = true; * seekBar.BottomAnchor.ConstraintEqualTo(bootomToolbarView.BottomAnchor, -10).Active = true; * seekBar.HeightAnchor.ConstraintEqualTo(20).Active = true; * * ToggleFullscreen(); * } * } * updateVideoPath(); * updateFullscreen(); * } * private void DeviceRotated(NSNotification notification) * { * ToggleFullscreen(); * } * * private void OnLoadStateChanged(NSNotification notification) * { * * } * * private void OnPlaybackComplete(NSNotification notification) { } * * private void OnExitFullscreen(NSNotification notification) { } * * private void OnEnterFullscreen(NSNotification notification) { } * * private void ToggleFullscreen() * { * _player.ScalingMode = MPMovieScalingMode.None; * switch (UIDevice.CurrentDevice.Orientation) * { * case UIDeviceOrientation.Portrait: * _player?.SetFullscreen(false, true); * break; * case UIDeviceOrientation.PortraitUpsideDown: * _player?.SetFullscreen(false, true); * break; * case UIDeviceOrientation.LandscapeLeft: * _player?.SetFullscreen(true, true); * break; * case UIDeviceOrientation.LandscapeRight: * _player?.SetFullscreen(true, true); * break; * } * _player.View.SetNeedsLayout(); * _player.View.SetNeedsDisplay(); * } * * protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) * { * base.OnElementPropertyChanged(sender, e); * if (e.PropertyName == CustomVideoSlider.FileUrlProperty.PropertyName) updateVideoPath(); * // if (e.PropertyName == CustomVideoSlider.FullscreenProperty.PropertyName) updateFullscreen(); * } * * public override void MovedToSuperview() * { * base.MovedToSuperview(); * } * * private void updateVideoPath() * { * if (_player == null) return; * // _player.ControlStyle = MPMovieControlStyle.Embedded; * _player.ShouldAutoplay = true; * _player.ContentUrl = !string.IsNullOrWhiteSpace(this.Element.FileUrl) ? NSUrl.FromString(this.Element.FileUrl) : null; * _player.PrepareToPlay(); * } * * private void updateFullscreen() * { * if (_player == null) return; * _player.SetFullscreen(true, true); * _player.View.SetNeedsLayout(); * _player.View.SetNeedsDisplay(); * } * * protected override void Dispose(bool disposing) * { * if (this._player != null) * { * this._player.Dispose(); * this._player = null; * } * base.Dispose(disposing); * } * */ protected override void OnElementChanged(ElementChangedEventArgs <CustomVideoPlayer> e) { base.OnElementChanged(e); if (Control == null) { //seekBar = new UISlider(); //SetNativeControl(seekBar); mainView = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false, }; SetNativeControl(mainView); } if (e.OldElement != null) { videoPlayerAV.RemoveObserver(this, (NSString)"videoBounds"); bootomToolbarView.RemoveObserver(this, (NSString)"bounds"); UIApplication.SharedApplication.SetStatusBarHidden(false, true); StopPlayingAction(false); playerItem.RemoveObserver(this, (NSString)"loadedTimeRanges"); playerItem.Dispose(); player.Dispose(); Console.WriteLine("Video Finished 1"); //playerItem = null; //player = null; } if (e.NewElement != null) { slider = e.NewElement; _fitSize = Control.Bounds.Size; // except if your not running iOS 7... then it fails... if (_fitSize.Width <= 0 || _fitSize.Height <= 0) { _fitSize = new SizeF(22, 22); // Per the glorious documentation known as the SDK docs } slider.CommandImageFileName = "audioPlay.png"; slider.CommandText = "Play"; slider.StopPlayingAction = StopPlayingAction; //seekBar = new UISlider(); //seekBar.MaximumTrackTintColor = Color.LightGray.ToUIColor(); //seekBar.MinimumTrackTintColor = Color.White.ToUIColor(); //seekBar.ThumbTintColor = Color.FromHex("#827DCE").ToUIColor(); //seekBar.Continuous = false; // Control.ScaleY = 5; if (slider.FileUrl != null) { // playerItem = AVPlayerItem.FromUrl(NSUrl.FromString("https://s3.amazonaws.com/kargopolov/kukushka.mp3"));// (asset); playerItem = AVPlayerItem.FromUrl(NSUrl.FromString(slider.FileUrl));// (asset); //playerItem = AVPlayerItem.FromUrl(NSUrl.FromString("https://mindcorners.blob.core.windows.net/post-attachment-videos/6412cb27-414a-435b-a480-66af5e935cb8.mov?sv=2017-04-17&sr=b&sig=gd3mn1Gai7QZHoSpx%2Fi8x%2FHfnOutACOV7WvsVblywk0%3D&se=2017-10-11T15%3A05%3A15Z&sp=r")); playerItem.AddObserver(this, (NSString)"loadedTimeRanges", NSKeyValueObservingOptions.New, IntPtr.Zero); player = new AVPlayer(playerItem); //player.AddObserver(this, "loadedTimeRanges", NSKeyValueObservingOptions.New, null); //playerLayer = AVPlayerLayer.FromPlayer(player); videoPlayerAV = new AVPlayerViewController(); videoPlayerAV.View.BackgroundColor = UIColor.Clear; videoPlayerAV.ShowsPlaybackControls = false; videoPlayerAV.AddObserver(this, (NSString)"videoBounds", NSKeyValueObservingOptions.New, IntPtr.Zero); videoPlayerAV.View.Frame = Control.Frame; videoPlayerAV.Player = player; UITapGestureRecognizer tapGesture = new UITapGestureRecognizer(OnVideoTap); videoView = new UIView() { BackgroundColor = UIColor.Clear }; // videoView.Bounds = new CGRect(0,0,100,100); videoView.AddGestureRecognizer(tapGesture); //videoPlayerAV.View.AddSubview(videoView); //button.CenterYAnchor.ConstraintEqualTo(videoPlayerAV.ContentOverlayView.CenterYAnchor).Active = true; //button.WidthAnchor.ConstraintEqualTo(50).Active = true; //button.HeightAnchor.ConstraintEqualTo(50).Active = true; //videoPlayerAV.VideoGravity = AVLayerVideoGravity.ResizeAspect; mainView.AddSubview(videoPlayerAV.View); mainView.AddSubview(videoView); videoView.TopAnchor.ConstraintEqualTo(mainView.TopAnchor).Active = true; videoView.BottomAnchor.ConstraintEqualTo(mainView.BottomAnchor).Active = true; videoView.LeftAnchor.ConstraintEqualTo(mainView.LeftAnchor).Active = true; videoView.RightAnchor.ConstraintEqualTo(mainView.RightAnchor).Active = true; videoView.WidthAnchor.ConstraintEqualTo(mainView.WidthAnchor).Active = true; videoView.HeightAnchor.ConstraintEqualTo(mainView.HeightAnchor).Active = true; button = new UIButton() { BackgroundColor = UIColor.Clear, TitleLabel = { Text = slider.CommandText }, TranslatesAutoresizingMaskIntoConstraints = false, }; button.TouchUpInside += Button_TouchUpInside; videoView.AddSubview(button); button.CenterXAnchor.ConstraintEqualTo(videoView.CenterXAnchor).Active = true; button.CenterYAnchor.ConstraintEqualTo(videoView.CenterYAnchor).Active = true; //button.CenterXAnchor.ConstraintEqualTo(videoPlayerAV.View.CenterXAnchor).Active = true; //button.CenterYAnchor.ConstraintEqualTo(videoPlayerAV.View.CenterYAnchor).Active = true; button.WidthAnchor.ConstraintEqualTo(50).Active = true; button.HeightAnchor.ConstraintEqualTo(50).Active = true; var center = NSNotificationCenter.DefaultCenter; NSNotificationCenter.DefaultCenter.AddObserver((NSString)"UIDeviceOrientationDidChangeNotification", DeviceRotated); //mainView.Layer.AddSublayer(playerLayer); if (slider.AutoPlay) { UpdatePlaying(); } else { { slider.CommandImageFileName = "audioPlay.png"; slider.CommandText = "Play"; button.Hidden = false; //button.SetTitle("paused", UIControlState.Normal); player.Pause(); isPlaying = false; } button.SetImage(UIImage.FromFile(slider.CommandImageFileName), UIControlState.Normal); } } bootomToolbarView = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false, }; bootomToolbarView.AddObserver(this, (NSString)"bounds", NSKeyValueObservingOptions.New, IntPtr.Zero); gradientLayer = new CAGradientLayer(); //gradientLayer.Frame = Bounds; gradientLayer.Colors = new CGColor[] { UIColor.Clear.CGColor, UIColor.Black.CGColor }; gradientLayer.Locations = new NSNumber[2] { new NSNumber(0.7), new NSNumber(1.2) }; bootomToolbarView.Layer.AddSublayer(gradientLayer); mainView.InsertSubviewAbove(bootomToolbarView, videoPlayerAV.View); labelTimeLeft = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Text = string.Format("{0:mm\\:ss}", TimeSpan.FromMilliseconds(slider.FileDuration ?? 0)), TextColor = UIColor.White }; bootomToolbarView.AddSubview(labelTimeLeft); labelTimePlayed = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Text = "00:00", TextColor = UIColor.White }; bootomToolbarView.AddSubview(labelTimePlayed); seekBar = new UISlider() { TranslatesAutoresizingMaskIntoConstraints = false, MaximumTrackTintColor = Color.LightGray.ToUIColor(), MinimumTrackTintColor = Color.White.ToUIColor(), ThumbTintColor = Color.FromHex("#827DCE").ToUIColor() }; seekBar.SetThumbImage(UIImage.FromFile("audioTint.png"), UIControlState.Normal); seekBar.TouchDown += Control_TouchDown; seekBar.TouchUpInside += Control_TouchUpInside; bootomToolbarView.AddSubview(seekBar); //videoPlayerAV.View.RightAnchor.ConstraintEqualTo(RightAnchor).Active = true; //videoPlayerAV.View.LeftAnchor.ConstraintEqualTo(LeftAnchor).Active = true; //videoPlayerAV.View.BottomAnchor.ConstraintEqualTo(BottomAnchor).Active = true; //videoPlayerAV.View.TopAnchor.ConstraintEqualTo(TopAnchor).Active = true; bootomToolbarView.RightAnchor.ConstraintEqualTo(RightAnchor).Active = true; bootomToolbarView.LeftAnchor.ConstraintEqualTo(LeftAnchor).Active = true; bootomToolbarView.BottomAnchor.ConstraintEqualTo(BottomAnchor).Active = true; bootomToolbarView.HeightAnchor.ConstraintEqualTo(40).Active = true; labelTimeLeft.RightAnchor.ConstraintEqualTo(bootomToolbarView.RightAnchor, -10).Active = true; labelTimeLeft.BottomAnchor.ConstraintEqualTo(bootomToolbarView.BottomAnchor, -10).Active = true; labelTimeLeft.WidthAnchor.ConstraintEqualTo(50).Active = true; labelTimeLeft.HeightAnchor.ConstraintEqualTo(20).Active = true; labelTimePlayed.LeftAnchor.ConstraintEqualTo(bootomToolbarView.LeftAnchor, 10).Active = true; labelTimePlayed.BottomAnchor.ConstraintEqualTo(bootomToolbarView.BottomAnchor, -10).Active = true; labelTimePlayed.WidthAnchor.ConstraintEqualTo(50).Active = true; labelTimePlayed.HeightAnchor.ConstraintEqualTo(20).Active = true; seekBar.LeftAnchor.ConstraintEqualTo(labelTimePlayed.RightAnchor, 10).Active = true; seekBar.RightAnchor.ConstraintEqualTo(labelTimeLeft.LeftAnchor, -10).Active = true; seekBar.BottomAnchor.ConstraintEqualTo(bootomToolbarView.BottomAnchor, -10).Active = true; seekBar.HeightAnchor.ConstraintEqualTo(20).Active = true; mainView.RightAnchor.ConstraintEqualTo(RightAnchor).Active = true; mainView.LeftAnchor.ConstraintEqualTo(LeftAnchor).Active = true; // mainView.BottomAnchor.ConstraintEqualTo(BottomAnchor).Active = true; mainView.TopAnchor.ConstraintEqualTo(TopAnchor).Active = true; // bootomToolbarView = new UIView(); // //bootomToolbarView.BackgroundColor = UIColor.Orange; // CAGradientLayer gradientLayer = new CAGradientLayer(); // gradientLayer.Frame = bootomToolbarView.Frame; // gradientLayer.Colors = new CGColor[] {UIColor.Clear.CGColor, UIColor.Orange.CGColor}; // bootomToolbarView.Layer.AddSublayer(gradientLayer); // //bootomToolbarView.BackgroundColor = new CGGradient(CGColorSpace.CreateAcesCGLinear(), new CGColor[] {UIColor.Clear.CGColor, UIColor.Black.CGColor }); // labelTimePlayed = new UILabel(); //// labelTimePlayed.Frame = new CGRect(0,10,50,20); // labelTimePlayed.Text = "00:00"; // labelTimePlayed.TextColor = UIColor.White; // //seekBar.Frame = new CGRect(50, 10, 100, 20); // labelTimeLeft = new UILabel(); // //labelTimeLeft.Frame = new CGRect(150, 10, 50, 20); // labelTimeLeft.Text = "00:00"; // labelTimeLeft.Text = string.Format("{0:mm\\:ss}", TimeSpan.FromMilliseconds(slider.FileDuration ?? 0)); // labelTimeLeft.TextColor = UIColor.White; // //bootomToolbarView.Frame = new CGRect(0, 10, 200, 20); // bootomToolbarView.AddSubview(labelTimePlayed); // bootomToolbarView.InsertSubviewAbove(labelTimeLeft, labelTimePlayed); // bootomToolbarView.InsertSubviewAbove(seekBar, labelTimeLeft); // mainView.InsertSubviewAbove(bootomToolbarView, videoPlayerAV.View); //playerLayer = AVPlayerLayer.FromPlayer(player); UIApplication.SharedApplication.SetStatusBarHidden(true, true); } //seekBar.TouchDown += Control_TouchDown; //seekBar.TouchUpInside += Control_TouchUpInside; }
public override void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTransitionCoordinator coordinator) { base.ViewWillTransitionToSize(toSize, coordinator); var videoPreviewLayerConnection = PreviewView.VideoPreviewLayer.Connection; if (videoPreviewLayerConnection != null) { var deviceOrientation = UIDevice.CurrentDevice.Orientation; if (!deviceOrientation.IsPortrait() && !deviceOrientation.IsLandscape()) { return; } var newVideoOrientation = VideoOrientationFor(deviceOrientation); var oldSize = View.Frame.Size; var oldVideoOrientation = videoPreviewLayerConnection.VideoOrientation; videoPreviewLayerConnection.VideoOrientation = newVideoOrientation; // When we transition to the new size, we need to adjust the region // of interest's origin and size so that it stays anchored relative // to the camera. coordinator.AnimateAlongsideTransition(context => { var oldRegion = PreviewView.RegionOfInterest; var newRegion = new CGRect(); if (oldVideoOrientation == LandscapeRight && newVideoOrientation == LandscapeLeft) { newRegion = oldRegion.WithX(oldSize.Width - oldRegion.X - oldRegion.Width); } else if (oldVideoOrientation == LandscapeRight && newVideoOrientation == Portrait) { newRegion.X = toSize.Width - oldRegion.Y - oldRegion.Height; newRegion.Y = oldRegion.X; newRegion.Width = oldRegion.Height; newRegion.Height = oldRegion.Width; } else if (oldVideoOrientation == LandscapeLeft && newVideoOrientation == LandscapeRight) { newRegion = oldRegion.WithX(oldSize.Width - oldRegion.X - oldRegion.Width); } else if (oldVideoOrientation == LandscapeLeft && newVideoOrientation == Portrait) { newRegion.X = oldRegion.Y; newRegion.Y = oldSize.Width - oldRegion.X - oldRegion.Width; newRegion.Width = oldRegion.Height; newRegion.Height = oldRegion.Width; } else if (oldVideoOrientation == Portrait && newVideoOrientation == LandscapeRight) { newRegion.X = oldRegion.Y; newRegion.Y = toSize.Height - oldRegion.X - oldRegion.Width; newRegion.Width = oldRegion.Height; newRegion.Height = oldRegion.Width; } else if (oldVideoOrientation == Portrait && newVideoOrientation == LandscapeLeft) { newRegion.X = oldSize.Height - oldRegion.Y - oldRegion.Height; newRegion.Y = oldRegion.X; newRegion.Width = oldRegion.Height; newRegion.Height = oldRegion.Width; } PreviewView.SetRegionOfInterestWithProposedRegionOfInterest(newRegion); }, context => { sessionQueue.DispatchAsync(() => { metadataOutput.RectOfInterest = PreviewView.VideoPreviewLayer.MapToLayerCoordinates(PreviewView.RegionOfInterest); }); // Remove the old metadata object overlays. RemoveMetadataObjectOverlayLayers(); }); } }
public static void ShowAnimationEffect(NSAnimationEffect animationEffect, CGPoint centerLocation, CGSize size, Action endedCallback) { var d = new NSAsyncActionDispatcher(endedCallback); ShowAnimationEffect(animationEffect, centerLocation, size, d, NSActionDispatcher.Selector, IntPtr.Zero); GC.KeepAlive(d); }
public static void ShowAnimationEffect(NSAnimationEffect animationEffect, CGPoint centerLocation, CGSize size, NSObject animationDelegate, Selector didEndSelector, IntPtr contextInfo) { NSShowAnimationEffect((nuint)(ulong)animationEffect, centerLocation, size, animationDelegate, didEndSelector, contextInfo); }
public static NSTextContainer FromContainerSize(CGSize containerSize) { return(new NSTextContainer(containerSize, true)); }
public static NSTextContainer FromSize(CGSize size) { return(new NSTextContainer(size, false)); }
public NSTextContainer(CGSize size) { Handle = InitWithContainerSize(size); }
public override void ViewDidLoad() { base.ViewDidLoad(); int width = 245; if (!UserInterfaceIdiomIsPhone) { width = 700; } session = BL.Managers.SessionManager.GetSession(sessionId); Title = "Session Detail"; TitleLabel.Text = session.Title; SpeakerLabel.Text = session.SpeakerNames; TimeLabel.Text = session.Start.ToString("dddd") + " " + session.Start.ToString("H:mm") + " - " + session.End.ToString("H:mm"); LocationLabel.Text = session.Room; OverviewLabel.Text = session.Overview; CGSize titleSize = UIStringDrawing.StringSize(session.Title , UIFont.FromName("Helvetica-Light", AppDelegate.Font16pt) , new SizeF(245, 400), UILineBreakMode.WordWrap); TitleLabel.Font = UIFont.FromName("Helvetica-Light", AppDelegate.Font16pt); TitleLabel.TextColor = UIColor.Black; TitleLabel.Frame = new CGRect(13, 15, width, titleSize.Height); TitleLabel.Lines = 0; TitleLabel.Font = UIFont.FromName("Helvetica-Light", AppDelegate.Font16pt); CGSize speakerSize = UIStringDrawing.StringSize(session.SpeakerNames , UIFont.FromName("Helvetica-LightOblique", AppDelegate.Font10pt) , new SizeF(245, 400), UILineBreakMode.WordWrap); SpeakerLabel.Font = UIFont.FromName("Helvetica-LightOblique", AppDelegate.Font10pt); SpeakerLabel.Frame = new CGRect(13 , 15 + 13 + titleSize.Height , width, speakerSize.Height); TimeLabel.Font = UIFont.FromName("Helvetica-Light", AppDelegate.Font7_5pt); TimeLabel.Frame = new CGRect(13 , 15 + titleSize.Height + 13 + speakerSize.Height + 5 , width, 10); LocationLabel.Font = UIFont.FromName("Helvetica-Light", AppDelegate.Font7_5pt); LocationLabel.Frame = new CGRect(13 , 15 + titleSize.Height + 13 + speakerSize.Height + 7 + 12 , width, 10); float overviewLabelWidth = 310; var overviewLabelY = 15 + titleSize.Height + 13 + speakerSize.Height + TimeLabel.Frame.Height + LocationLabel.Frame.Height + 20; nfloat overviewLabelHeight = (UserInterfaceIdiomIsPhone?360:854) - overviewLabelY; OverviewLabel.Editable = false; OverviewLabel.Font = UIFont.FromName("Helvetica-Light", AppDelegate.Font10_5pt); if (AppDelegate.IsPhone) { // going to scroll the whole thing! OverviewLabel.ScrollEnabled = false; CGSize overviewSize = UIStringDrawing.StringSize( session.Overview , UIFont.FromName("Helvetica-Light", AppDelegate.Font10_5pt) , new CGSize(overviewLabelWidth, 2500) // just width wasn't working... , UILineBreakMode.WordWrap); overviewLabelHeight = overviewSize.Height + 30; ScrollView.ContentSize = new CGSize(320, overviewLabelY + overviewLabelHeight + 10); } OverviewLabel.Frame = new CGRect(5 , overviewLabelY , UserInterfaceIdiomIsPhone?overviewLabelWidth:700 , overviewLabelHeight); FavoriteButton.TouchUpInside += (sender, e) => { ToggleFavorite(); }; if (FavoritesManager.IsFavorite(session.Key)) { FavoriteButton.SetImage(new UIImage(AppDelegate.ImageIsFavorite), UIControlState.Normal); } else { FavoriteButton.SetImage(new UIImage(AppDelegate.ImageNotFavorite), UIControlState.Normal); } }
private BarLayer CreateBarLayer(nfloat barHeight) { var barLayer = new BarLayer() { ZPosition = 0, BorderColor = UIColor.White.CGColor, AnchorPoint = new CGPoint(0.0f, 0.5f), Frame = new CGRect(0, 0, Bounds.Width, barHeight) }; var mainBar = new CALayer(); mainBar.AnchorPoint = new CGPoint(0.0f, 0.0f); mainBar.Bounds = new CGRect(0, 0, Bounds.Width - xAxisMargin - xTextMargin, barHeight); mainBar.Position = new CGPoint(xAxisMargin, 0); mainBar.BackgroundColor = MainBarColor.CGColor; mainBar.SetValueForKeyPath(new NSNumber(minBarScale), new NSString("transform.scale.x")); barLayer.AddSublayer(mainBar); var secondaryBar = new CALayer(); secondaryBar.AnchorPoint = new CGPoint(0.0f, 0.0f); secondaryBar.Bounds = new CGRect(0, 0, Bounds.Width - xAxisMargin - xTextMargin, barHeight); secondaryBar.Position = new CGPoint(xAxisMargin, 0); secondaryBar.BackgroundColor = SecondaryBarColor.CGColor; secondaryBar.SetValueForKeyPath(new NSNumber(minBarScale), new NSString("transform.scale.x")); barLayer.AddSublayer(secondaryBar); var emptyBar = new CALayer(); emptyBar.AnchorPoint = new CGPoint(0.0f, 0.0f); emptyBar.Bounds = new CGRect(0, 0, 2.0f, barHeight); emptyBar.Position = new CGPoint(xAxisMargin, 0); emptyBar.BackgroundColor = UIColor.Gray.CGColor; barLayer.AddSublayer(emptyBar); CGFont font = CGFont.CreateWithFontName(LabelFont.Name); CGSize size = ((NSString)"00.00:00").StringSize(LabelFont); var textLayer = new CATextLayer() { ContentsScale = UIScreen.MainScreen.Scale, FontSize = 10.0f, AnchorPoint = new CGPoint(0.0f, 0.5f), AlignmentMode = CATextLayer.AlignmentLeft, BackgroundColor = UIColor.Clear.CGColor, ForegroundColor = LabelColor.CGColor }; barLayer.AddSublayer(textLayer); var timeTextLayer = new CATextLayer() { ContentsScale = UIScreen.MainScreen.Scale, FontSize = 10.0f, AnchorPoint = new CGPoint(0.0f, 0.5f), AlignmentMode = CATextLayer.AlignmentLeft, BackgroundColor = UIColor.Clear.CGColor, ForegroundColor = SecondaryBarColor.CGColor }; barLayer.AddSublayer(timeTextLayer); if (font != null) { textLayer.SetFont(font); timeTextLayer.SetFont(font); font.Dispose(); } CATransaction.DisableActions = true; textLayer.Bounds = new CGRect(new CGPoint(0, 0), size); textLayer.Position = mainBar.Position; timeTextLayer.Bounds = new CGRect(new CGPoint(0, 0), size); timeTextLayer.Position = new CGPoint(mainBar.Position.X + 5.0f, mainBar.Position.Y); CATransaction.DisableActions = false; return(barLayer); }
public override void ConstrainTo(CGSize constraint) { ClearConstraints(); ConstrainedSize = constraint; }
extern static void NSShowAnimationEffect(nuint animationEffect, CGPoint centerLocation, CGSize size, NSObject animationDelegate, Selector didEndSelector, IntPtr contextInfo);
public override CGSize SizeThatFits(CGSize size) { return(_fitSize); }
UIImage DrawShape(ShapeType shapeType, CGSize size, UIColor strokeColor, UIColor fillColor) { float width = (float)size.Width; float height = (float)size.Height; var stroke = 1; var scale = (width / 2) - (stroke * 2); var center = new Vector2(width / 2, height / 2); UIImage starImage; UIGraphics.BeginImageContext(new CGSize(width, height)); using (CGContext g = UIGraphics.GetCurrentContext()) { g.SetLineWidth(stroke); FillColor.ToUIColor().SetFill(); StrokeColor.ToUIColor().SetStroke(); var shapePoints = new Vector2[0]; switch (shapeType) { case ShapeType.Oval: var radiusX = (width / 3) - stroke; var radiusY = (height / 2) - stroke; g.AddEllipseInRect(new CGRect(0, 0, radiusX * 2, radiusY * 2)); break; case ShapeType.Circle: var radius = Math.Min(width, height) / 2 - stroke; g.AddEllipseInRect(new CGRect(0, 0, radius * 2, radius * 2)); break; case ShapeType.Line: shapePoints = CreateLineGeometry(scale, center); break; case ShapeType.Hexagon: shapePoints = CreateHexagonGeometry(scale, center); break; case ShapeType.Rectangle: shapePoints = CreateRectangleGeometry(scale, center); break; case ShapeType.Square: shapePoints = CreateSquareGeometry(scale, center); break; case ShapeType.Trapezoid: shapePoints = CreateTrapezoidGeometry(scale, center); break; case ShapeType.Triangle: shapePoints = CreateTriangleGeometry(scale, center); break; case ShapeType.Star: shapePoints = CreateStarGeometry(scale, center); break; default: break; } if (shapePoints.Count() > 0) { var points = new List <CGPoint>(); foreach (var item in shapePoints) { points.Add(new CGPoint(item.X, item.Y)); } var path = new CGPath(); path.AddLines(points.ToArray()); path.CloseSubpath(); g.AddPath(path); } g.DrawPath(CGPathDrawingMode.FillStroke); starImage = UIGraphics.GetImageFromCurrentImageContext(); } return(starImage); }
public AlignScene(CGSize size) : base(size) { }
public override CGSize GetSizeForChildContentContainer(IUIContentContainer contentContainer, CGSize parentContainerSize) { var preferredHeight = Min(maximumHeight, PresentedViewController.PreferredContentSize.Height); return(new CGSize(parentContainerSize.Width, preferredHeight == 0 ? maximumHeight : preferredHeight)); }
public MainToolbar(Gtk.Window window) { gtkWindow = window; widget = new NSToolbar(MainToolbarId) { DisplayMode = NSToolbarDisplayMode.Icon, }; awesomeBar = new AwesomeBar(); awesomeBar.RunButton.Activated += (o, e) => { RunButtonClicked?.Invoke(o, e); }; awesomeBar.RunButton.UnfocusToolbar += (o, e) => { awesomeBar.Window.MakeFirstResponder(null); exitAction(Gtk.DirectionType.TabBackward); }; // Remove the focus from the Gtk system when Cocoa has focus // Fixes BXC #29601 awesomeBar.SearchBar.GainedFocus += (o, e) => IdeApp.Workbench.RootWindow.Focus = null; AttachToolbarEvents(awesomeBar.SearchBar); selectorView.ConfigurationChanged += (sender, e) => { if (ConfigurationChanged != null) { ConfigurationChanged(sender, e); } }; selectorView.RunConfigurationChanged += (sender, e) => { if (RunConfigurationChanged != null) { RunConfigurationChanged(sender, e); } }; selectorView.RuntimeChanged += (sender, ea) => { if (RuntimeChanged != null) { RuntimeChanged(sender, ea); } }; widget.WillInsertItem = (tool, id, send) => { switch (id) { case AwesomeBarId: return(new NSToolbarItem(AwesomeBarId) { View = awesomeBar, MinSize = new CGSize(MacSystemInformation.OsVersion < MacSystemInformation.Mojave ? 1024: 600, AwesomeBar.ToolbarWidgetHeight), MaxSize = new CGSize(float.PositiveInfinity, AwesomeBar.ToolbarWidgetHeight) }); default: throw new NotImplementedException(); } }; // We can't use the events that Xamarin.Mac adds for delegate methods as they will overwrite // the delegate that Gtk has added NSWindow nswin = GtkMacInterop.GetNSWindow(window); // The way how sizing of the NSToolbar is implemented seems to have changen in Mojave. // Previously we had to track the window size and update our MinSize to prevent NSToolbar // from removing the item automatically. Now the same logic has the opposite effect on Mojave. // Additionally AwesomeBar has no active window, after being removed from the NSToolbar, making // the required size calculation much more complex. However letting NSToolbar do the magic // internally works on Mojave correctly. if (MacSystemInformation.OsVersion < MacSystemInformation.Mojave) { Action <NSNotification> resizeAction = notif => Runtime.RunInMainThread(() => { var win = awesomeBar.Window; if (win == null) { return; } var item = widget.Items [0]; var abFrameInWindow = awesomeBar.ConvertRectToView(awesomeBar.Frame, null); var awesomebarHeight = AwesomeBar.ToolbarWidgetHeight; var size = new CGSize(win.Frame.Width - abFrameInWindow.X - 4, awesomebarHeight); if (item.MinSize != size) { item.MinSize = size; } }); NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.DidResizeNotification, resizeAction, nswin); NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.DidEndLiveResizeNotification, resizeAction, nswin); } NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.WillEnterFullScreenNotification, (note) => IsFullscreen = true, nswin); NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.WillExitFullScreenNotification, (note) => IsFullscreen = false, nswin); }
UIEdgeInsets CenterPointEdgeInsetsForImageSize(CGSize size) { CGPoint p = new CGPoint(size.Width / 2f, size.Height / 2f); return(new UIEdgeInsets(p.Y, p.X, p.Y, p.X)); }
public override Bitmap OnDrawPopup(PopupDrawInfo popupDrawInfo) { string text = "Custom Popup"; PopupStyle style = popupDrawInfo.Popup.Style; // Calculate scaled dimensions float DPToPX = popupDrawInfo.DPToPX; float PXTODP = 1 / DPToPX; if (style.ScaleWithDPI) { DPToPX = 1; } else { PXTODP = 1; } float screenWidth = popupDrawInfo.ScreenBounds.GetWidth() * PXTODP; float screenHeight = popupDrawInfo.ScreenBounds.GetHeight() * PXTODP; // Update sizes based on scale (uses extension method, cf. Shared/Extensions int fontSize = FontSize.Update(DPToPX); int triangleWidth = TriangleSize.Update(DPToPX); int triangleHeight = TriangleSize.Update(DPToPX); int strokeWidth = StrokeWidth.Update(DPToPX); int screenPadding = ScreenPadding.Update(DPToPX); UIFont font = UIFont.FromName("HelveticaNeue-Light", fontSize); // Calculate the maximum popup size, adjust with dpi float maxPopupWidth = Math.Min(screenWidth, screenHeight); // Calculate maximum text and description width float halfStrokeWidth = strokeWidth * 0.5f; float maxTextWidth = maxPopupWidth - (2 * screenPadding + strokeWidth); CGSize textSize = text.StringSize(font, new CGSize(maxTextWidth, nfloat.MaxValue)); // Calculate bitmap size nfloat popupWidth = textSize.Width + 2 * PopupPadding + strokeWidth + triangleWidth; nfloat popupHeight = textSize.Height + 2 * PopupPadding + strokeWidth; CGSize popupSize = new CGSize(popupWidth, popupHeight); // Create graphics context; UIGraphics.BeginImageContext(popupSize); CGContext context = UIGraphics.GetCurrentContext(); CGRect backgroundStrokeRect = new CGRect( triangleWidth, halfStrokeWidth, popupWidth - (strokeWidth + triangleWidth), popupHeight - strokeWidth ); UIBezierPath backgroundPath = UIBezierPath.FromRoundedRect(backgroundStrokeRect, 1); backgroundPath.LineWidth = strokeWidth; // Prepare triangle path CGPath trianglePath = new CGPath(); trianglePath.MoveToPoint(triangleWidth, 0); trianglePath.AddLineToPoint(halfStrokeWidth, triangleHeight * 0.5f); trianglePath.AddLineToPoint(triangleWidth, triangleHeight); trianglePath.CloseSubpath(); // Calculate anchor point and triangle position nfloat triangleOffsetX = 0; nfloat triangleOffsetY = (popupHeight - triangleHeight) / 2; // Stroke background StrokeColor.SetStroke(); backgroundPath.Stroke(); // Stroke triangle context.SaveState(); context.TranslateCTM(triangleOffsetX, triangleOffsetY); context.SetLineWidth(strokeWidth); context.AddPath(trianglePath); context.SetStrokeColor(StrokeColor.CGColor); context.StrokePath(); context.RestoreState(); // Fill background BackgroundColor.SetFill(); backgroundPath.Fill(); // Fill triangle context.SaveState(); context.TranslateCTM(triangleOffsetX, triangleOffsetY); context.AddPath(trianglePath); context.SetFillColor(BackgroundColor.CGColor); context.FillPath(); context.RestoreState(); // Draw text context.SetFillColor(TextColor.CGColor); CGRect textRect = new CGRect( halfStrokeWidth + PopupPadding + triangleWidth, PopupPadding, textSize.Width, textSize.Height ); text.DrawString(textRect, font, UILineBreakMode.WordWrap); // Extract image UIImage image = UIGraphics.GetImageFromCurrentImageContext(); // Clean up UIGraphics.EndImageContext(); return(BitmapUtils.CreateBitmapFromUIImage(image)); }
public static SizeF ToSizeF(this CGSize size) { return(new SizeF((float)size.Width, (float)size.Height)); }
public override CGSize SizeThatFits(CGSize size) { return(new CGSize(size.Width, 1.0 / UIScreen.MainScreen.Scale)); }
public TOCroppedImageAttributes(CGRect croppedFrame, global::System.nint angle, CGSize originalSize) : base(NSObjectFlag.Empty) { IsDirectBinding = GetType().Assembly == global::ApiDefinition.Messaging.this_assembly; if (IsDirectBinding) { InitializeHandle(global::ApiDefinition.Messaging.IntPtr_objc_msgSend_CGRect_nint_CGSize(this.Handle, Selector.GetHandle("initWithCroppedFrame:angle:originalImageSize:"), croppedFrame, angle, originalSize), "initWithCroppedFrame:angle:originalImageSize:"); } else { InitializeHandle(global::ApiDefinition.Messaging.IntPtr_objc_msgSendSuper_CGRect_nint_CGSize(this.SuperHandle, Selector.GetHandle("initWithCroppedFrame:angle:originalImageSize:"), croppedFrame, angle, originalSize), "initWithCroppedFrame:angle:originalImageSize:"); } }
public static UIImage ApplyThemeColorToImage(string imagePath, bool skipApplyIfCustomImage = false, CGSize originalImageSize = new CGSize(), UIColor expectedColor = null, CGPoint?expectedColorCoordinate = null) { if (skipApplyIfCustomImage) { var image = GetImage(imagePath); if (ImageWasOverridden(image, originalImageSize, expectedColor, expectedColorCoordinate)) { return(image); } } return(ApplyColorToImage(imagePath, Theme.CompanyColor)); }
extern static /* CGImageRef */ IntPtr QLThumbnailImageCreate(/* CFAllocatorRef */ IntPtr allocator, /* CFUrlRef */ IntPtr url, CGSize maxThumbnailSize, /* CFDictionaryRef */ IntPtr options);
public override void SetFrameSize(CGSize newSize) { base.SetFrameSize(newSize); SendWindowPosChanged(newSize); }
public MapViewMarkerAdapter(CGSize size) : base(size) { }