private void Mstep() { double mu = param.Mu; double theta = param.Theta; param.Mu = -theta *NMath.Log(en2 / en1); param.Theta = theta * (en3 / en1); param.Omega = en1; }
void OnTreeViewResized(object sender, EventArgs e) { var height = (treeView.RowHeight + treeView.IntercellSpacing.Height) * treeView.RowCount; var maxHeight = GetMaxHeight(treeView.Window); height = NMath.Min(height, maxHeight); widthConstraint.Constant = treeView.OptimalTooltipWidth; heightConstraint.Constant = height; }
public ExpectedValue(Stat.SDist dist, int divide, double eps) { this.dist = dist; // inte_divide = divide; inte_eps = eps; gx = new double[divide]; gw = new double[divide]; NMath.GaussWeights(gx, gw, inte_eps); }
private static NGraphicsPath CreateCircleSegment(double w, double h) { double radius = 0.4 * NMath.Min(w, h); NPoint center = new NPoint(0.5 * w, 0.5 * h); NGraphicsPath path = new NGraphicsPath(); path.AddCircleSegment(center, radius, 0.25 * NMath.PI, 1.5 * NMath.PI); return(path); }
void UpdateButtomLayoutConstraint(UIKeyboardEventArgs e) { UIViewAnimationCurve curve = e.AnimationCurve; UIView.Animate(e.AnimationDuration, 0, ConvertToAnimationOptions(e.AnimationCurve), () => { nfloat offsetFromBottom = tableView.Frame.GetMaxY() - e.FrameEnd.GetMinY(); offsetFromBottom = NMath.Max(0, offsetFromBottom); SetToolbarContstraint(offsetFromBottom); }, null); }
private void EventSinkService_TransformationsChanged(object sender, EventArgs e) { float zoomFactor = (view.ScaleX + view.ScaleY) / 2; int value = (int)NMath.Round(zoomFactor * 100); if (value != zoomScrollbar.Value) { zoomScrollbar.Value = value; } }
private void Mstep() { double mu = param.Mu; double theta = param.Theta; param.Mu = -theta *NMath.Log(en2 / en1); param.Theta = theta * (en3 / en1); param.Omega = -en1 *NMath.Expm1(-NMath.Exp(param.Mu / param.Theta)); }
private void DrawFourWinged(CGRect rect) { //// Rectangle 2 Drawing UIBezierPath rectangle2Path = new UIBezierPath(); rectangle2Path.MoveTo(new CGPoint(rect.GetMinX() + 36.0f, rect.GetMinY() + 35.0f)); rectangle2Path.AddCurveToPoint(new CGPoint(rect.GetMinX() + 51.0f, rect.GetMinY() + 22.0f), new CGPoint(rect.GetMinX() + 35.55f, rect.GetMinY() + 30.32f), new CGPoint(rect.GetMinX() + 38.68f, rect.GetMinY() + 22.0f)); rectangle2Path.AddCurveToPoint(new CGPoint(rect.GetMinX() + 65.0f, rect.GetMinY() + 33.0f), new CGPoint(rect.GetMinX() + 62.87f, rect.GetMinY() + 22.0f), new CGPoint(rect.GetMinX() + 64.9f, rect.GetMinY() + 28.88f)); rectangle2Path.AddCurveToPoint(new CGPoint(rect.GetMinX() + 0.60000f * rect.Width, rect.GetMinY() + 0.44000f * rect.Height), new CGPoint(rect.GetMinX() + 65.14f, rect.GetMinY() + 38.95f), new CGPoint(rect.GetMinX() + 0.59613f * rect.Width, rect.GetMinY() + 0.42938f * rect.Height)); rectangle2Path.AddCurveToPoint(new CGPoint(rect.GetMinX() + 0.60000f * rect.Width, rect.GetMinY() + 0.48344f * rect.Height), new CGPoint(rect.GetMinX() + 0.60712f * rect.Width, rect.GetMinY() + 0.46251f * rect.Height), new CGPoint(rect.GetMinX() + 0.60000f * rect.Width, rect.GetMinY() + 0.44163f * rect.Height)); rectangle2Path.AddLineTo(new CGPoint(rect.GetMinX() + 0.60000f * rect.Width, rect.GetMinY() + 0.69242f * rect.Height)); rectangle2Path.AddCurveToPoint(new CGPoint(rect.GetMinX() + 0.59378f * rect.Width, rect.GetMinY() + 0.76814f * rect.Height), new CGPoint(rect.GetMinX() + 0.60000f * rect.Width, rect.GetMinY() + 0.72837f * rect.Height), new CGPoint(rect.GetMinX() + 0.60000f * rect.Width, rect.GetMinY() + 0.74928f * rect.Height)); rectangle2Path.AddLineTo(new CGPoint(rect.GetMinX() + 0.59288f * rect.Width, rect.GetMinY() + 0.77179f * rect.Height)); rectangle2Path.AddCurveToPoint(new CGPoint(rect.GetMinX() + 0.50975f * rect.Width, rect.GetMinY() + 0.83000f * rect.Height), new CGPoint(rect.GetMinX() + 0.58016f * rect.Width, rect.GetMinY() + 0.80674f * rect.Height), new CGPoint(rect.GetMinX() + 0.54694f * rect.Width, rect.GetMinY() + 0.83000f * rect.Height)); rectangle2Path.AddCurveToPoint(new CGPoint(rect.GetMinX() + 0.50500f * rect.Width, rect.GetMinY() + 0.83000f * rect.Height), new CGPoint(rect.GetMinX() + 0.50500f * rect.Width, rect.GetMinY() + 0.83000f * rect.Height), new CGPoint(rect.GetMinX() + 0.50500f * rect.Width, rect.GetMinY() + 0.83000f * rect.Height)); rectangle2Path.AddLineTo(new CGPoint(rect.GetMinX() + 0.50500f * rect.Width, rect.GetMinY() + 0.83000f * rect.Height)); rectangle2Path.AddLineTo(new CGPoint(rect.GetMinX() + 0.50500f * rect.Width, rect.GetMinY() + 0.83000f * rect.Height)); rectangle2Path.AddLineTo(new CGPoint(rect.GetMinX() + 0.50025f * rect.Width, rect.GetMinY() + 0.83000f * rect.Height)); rectangle2Path.AddCurveToPoint(new CGPoint(rect.GetMinX() + 0.41712f * rect.Width, rect.GetMinY() + 0.77179f * rect.Height), new CGPoint(rect.GetMinX() + 0.46306f * rect.Width, rect.GetMinY() + 0.83000f * rect.Height), new CGPoint(rect.GetMinX() + 0.42984f * rect.Width, rect.GetMinY() + 0.80674f * rect.Height)); rectangle2Path.AddCurveToPoint(new CGPoint(rect.GetMinX() + 0.41000f * rect.Width, rect.GetMinY() + 0.68656f * rect.Height), new CGPoint(rect.GetMinX() + 0.41000f * rect.Width, rect.GetMinY() + 0.74928f * rect.Height), new CGPoint(rect.GetMinX() + 0.41000f * rect.Width, rect.GetMinY() + 0.72837f * rect.Height)); rectangle2Path.AddLineTo(new CGPoint(rect.GetMinX() + 0.41000f * rect.Width, rect.GetMinY() + 0.69242f * rect.Height)); rectangle2Path.AddCurveToPoint(new CGPoint(rect.GetMinX() + 0.42000f * rect.Width, rect.GetMinY() + 0.44000f * rect.Height), new CGPoint(rect.GetMinX() + 0.41000f * rect.Width, rect.GetMinY() + 0.44163f * rect.Height), new CGPoint(rect.GetMinX() + 0.42000f * rect.Width, rect.GetMinY() + 0.44000f * rect.Height)); rectangle2Path.AddCurveToPoint(new CGPoint(rect.GetMinX() + 36.0f, rect.GetMinY() + 35.0f), new CGPoint(rect.GetMinX() + 0.42340f * rect.Width, rect.GetMinY() + 0.43067f * rect.Height), new CGPoint(rect.GetMinX() + 36.55f, rect.GetMinY() + 40.72f)); rectangle2Path.ClosePath(); UIColor.Gray.SetFill(); rectangle2Path.Fill(); //// Oval 2 Drawing var oval2Path = UIBezierPath.FromOval(new CGRect(rect.GetMinX() + NMath.Floor(rect.Width * 0.12000f + 0.5f), rect.GetMinY() + NMath.Floor(rect.Height * 0.40000f + 0.5f), NMath.Floor(rect.Width * 0.45000f + 0.5f) - NMath.Floor(rect.Width * 0.12000f + 0.5f), NMath.Floor(rect.Height * 0.61000f + 0.5f) - NMath.Floor(rect.Height * 0.40000f + 0.5f))); UIColor.Gray.SetFill(); oval2Path.Fill(); //// Oval 3 Drawing var oval3Path = UIBezierPath.FromOval(new CGRect(rect.GetMinX() + NMath.Floor(rect.Width * 0.21000f + 0.5f), rect.GetMinY() + NMath.Floor(rect.Height * 0.55000f + 0.5f), NMath.Floor(rect.Width * 0.45000f + 0.5f) - NMath.Floor(rect.Width * 0.21000f + 0.5f), NMath.Floor(rect.Height * 0.73000f + 0.5f) - NMath.Floor(rect.Height * 0.55000f + 0.5f))); UIColor.Gray.SetFill(); oval3Path.Fill(); //// Oval 4 Drawing var oval4Path = UIBezierPath.FromOval(new CGRect(rect.GetMinX() + NMath.Floor(rect.Width * 0.55000f + 0.5f), rect.GetMinY() + NMath.Floor(rect.Height * 0.40000f + 0.5f), NMath.Floor(rect.Width * 0.88000f + 0.5f) - NMath.Floor(rect.Width * 0.55000f + 0.5f), NMath.Floor(rect.Height * 0.61000f + 0.5f) - NMath.Floor(rect.Height * 0.40000f + 0.5f))); UIColor.Gray.SetFill(); oval4Path.Fill(); //// Oval 5 Drawing var oval5Path = UIBezierPath.FromOval(new CGRect(rect.GetMinX() + NMath.Floor(rect.Width * 0.55000f + 0.5f), rect.GetMinY() + NMath.Floor(rect.Height * 0.55000f + 0.5f), NMath.Floor(rect.Width * 0.79000f + 0.5f) - NMath.Floor(rect.Width * 0.55000f + 0.5f), NMath.Floor(rect.Height * 0.73000f + 0.5f) - NMath.Floor(rect.Height * 0.55000f + 0.5f))); UIColor.Gray.SetFill(); oval5Path.Fill(); }
public Stream GetFilledCircleWithCenteredText(int imgSize, string rgbCircleColor, string txt, string rgbTextColor, string fontFamilyName, int fontSize) { Stream result = null; using (UIImage image = new UIImage()) { UIGraphics.BeginImageContext(new SizeF(imgSize, imgSize)); CGRect rect = new CGRect(0, 0, imgSize, imgSize); image.Draw(rect); using (CGContext g = UIGraphics.GetCurrentContext()) { float x = (float)(rect.X + (rect.Width / 2)); float y = (float)(rect.Y + (rect.Height / 2)); // Draws the circle UIColor background = FromHexString(rgbCircleColor); g.SetLineWidth(1); g.SetFillColor(background.CGColor); g.SetStrokeColor(background.CGColor); CGPath path = new CGPath(); path.AddArc(x, y, NMath.Min(rect.Width, rect.Height) / 2 - 1f, 0, 2.0f * (float)Math.PI, true); g.AddPath(path); g.DrawPath((CGPathDrawingMode.FillStroke)); // Draws the text g.SetFillColor(FromHexString(rgbTextColor).CGColor); var attributedString = new NSAttributedString(txt, new CoreText.CTStringAttributes { ForegroundColorFromContext = true, Font = new CoreText.CTFont(fontFamilyName, fontSize * 2) }); using (var textLine = new CoreText.CTLine(attributedString)) { g.TranslateCTM(x - (textLine.GetBounds(CoreText.CTLineBoundsOptions.UseGlyphPathBounds).Width / 2), y + (textLine.GetBounds(CoreText.CTLineBoundsOptions.UseGlyphPathBounds).Height / 2)); g.ScaleCTM(1, -1); textLine.Draw(g); } } var resultImage = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); NSData data = resultImage.AsPNG(); result = data.AsStream(); } return(result); }
public override void LayoutSubviews() { var width = this.Bounds.Width / (Sliders.Count + 1); var padding = width / 2; var right = Bounds.Width - sidePadding; var leftPadding = this.GetSafeArea().Left; var frame = onSwitch.Frame; frame.X = right - frame.Width; frame.Y = this.Parent.NavigationController.NavigationBar.Frame.Bottom + topItemsPadding; onSwitch.Frame = frame; active.Center = new CGPoint(active.Frame.Width / 2 + sidePadding / 2 + leftPadding, onSwitch.Center.Y); var fullwidth = Bounds.Width; line1.Frame = new CGRect(0, frame.Bottom + topItemsPadding / 2, fullwidth, 1); frame = combobox.Frame; frame.X = right - frame.Width; frame.Y = onSwitch.Frame.Bottom + topItemsPadding; combobox.Frame = frame; preset.Center = new CGPoint(preset.Frame.Width / 2 + sidePadding / 2 + leftPadding, combobox.Center.Y); line2.Frame = new CGRect(0, frame.Bottom + topItemsPadding / 2, fullwidth, 1); const float BottomBarHeight = 34; toolbar.Frame = new CGRect(0, Bounds.Height - NowPlayingViewController.Current.GetCurrentTopHeight() - BottomBarHeight, Bounds.Width, BottomBarHeight); var sliderTop = line2.Frame.Bottom; var available = toolbar.Frame.Top - sliderTop - (topItemsPadding * 2) - 25; nfloat height = 0; //if (Util.IsIphone) height = NMath.Min(available, EqSliderMaxHeight); //else // height = this.Bounds.Height - 65; sliderH = sliderTop + ((available - height) / 2) + topItemsPadding; for (int i = 0; i < Sliders.Count; i++) { var x = width * i + padding; var slider = Sliders[i]; var label = labels[i]; slider.Frame = new CGRect(x, sliderH, width, height); label.Frame = new CGRect(x, slider.Frame.Bottom, width, 25); } //combobox.Frame = combobox.Frame.SetLocation (xOffset + padding, height + 75); //SetNeedsDisplay(); }
protected override void OnElementChanged(ElementChangedEventArgs <CircleView> e) { base.OnElementChanged(e); if (e.NewElement != null) { Layer.MasksToBounds = true; Layer.CornerRadius = NMath.Min((float)e.NewElement.WidthRequest, (float)e.NewElement.HeightRequest) / 2.0f; } }
public virtual nint ClampedPageValue(nint page) { if (IsWrappedEnabled) { return(_numberOfPages != 0 ? (page + _numberOfPages) % _numberOfPages : 0); } else { return(NMath.Min(NMath.Max(0, page), _numberOfPages - 1)); } }
public void TestCorrelation() { var factory = new NArrayFactory(StorageLocation.Host); var a = factory.CreateNArray(new double[] { 0.32, 0.91, -0.32, -0.25 }); var b = factory.CreateNArray(new double[] { 0.49, 0.75, -0.39, -0.20 }); var correlation = NMath.Correlation(a, b); Assert.AreEqual(Math.Round(correlation, 12), Math.Round(0.96831734966276, 12)); }
nfloat CalcContentOverlap() { var onScreenHeight = CalcOnScreenContentHeight(); // >= 0 // chat's input view with or without keyboard var obstacleHeight = tableView.ContentInset.Bottom; // >= 0 var overlap = NMath.Max(onScreenHeight + obstacleHeight - tableView.Frame.Height, 0); return(overlap); }
private static NArray <T> Slice <T>(NArray <T> array, int chunkIndex, int startIndex, int length) { if (array is ILocalNArray) { return(NMath.CreateNArray <T>((array.Storage as ChunkyStorage <T>).Slice(chunkIndex))); } else { return(array.Slice(startIndex, length)); } }
void Pan(UIPanGestureRecognizer pan) { var location = pan.LocationInView(View); switch (pan.State) { case UIGestureRecognizerState.Began: // Capture the initial touch offset from the itemView's center. var center = itemView.Center; offset.X = location.X - center.X; offset.Y = location.Y - center.Y; // Disable the behavior while the item is manipulated by the pan recognizer. stickyBehavior.Enabled = false; break; case UIGestureRecognizerState.Changed: // Get reference bounds. var referenceBounds = View.Bounds; var referenceWidth = referenceBounds.Width; var referenceHeight = referenceBounds.Height; // Get item bounds. var itemBounds = itemView.Bounds; var itemHalfWidth = itemBounds.Width / 2f; var itemHalfHeight = itemBounds.Height / 2f; // Apply the initial offset. location.X -= offset.X; location.Y -= offset.Y; // Bound the item position inside the reference view. location.X = NMath.Max(itemHalfWidth, location.X); location.X = NMath.Min(referenceWidth - itemHalfWidth, location.X); location.Y = NMath.Max(itemHalfHeight, location.Y); location.Y = NMath.Min(referenceHeight - itemHalfHeight, location.Y); // Apply the resulting item center. itemView.Center = location; break; case UIGestureRecognizerState.Ended: case UIGestureRecognizerState.Cancelled: // Get the current velocity of the item from the pan gesture recognizer. var velocity = pan.VelocityInView(View); // Re-enable the stickyCornersBehavior. stickyBehavior.Enabled = true; // Add the current velocity to the sticky corners behavior. stickyBehavior.AddLinearVelocity(velocity); break; } }
private static void SoftmaxExample() { var matA = new NMatrix(1, 3, new double[] { 0.3, 2.9, 4.0 }); Console.WriteLine($"A: {matA.ToString()}"); var matResult = NMath.Softmax(matA); Console.WriteLine($"Softmax(A): {matResult.ToString()}"); }
void UpdateCachedAssets() { bool isViewVisible = IsViewLoaded && View.Window != null; if (!isViewVisible) { return; } // The preheat window is twice the height of the visible rect. CGRect preheatRect = CollectionView.Bounds; preheatRect = preheatRect.Inset(0f, -.5f * preheatRect.Height); nfloat delta = NMath.Abs(preheatRect.GetMidY() - previousPreheatRect.GetMidY()); if (delta > CollectionView.Bounds.Height / 3.0f) { // Compute the assets to start caching and to stop caching. var addedIndexPaths = new List <NSIndexPath> (); var removedIndexPaths = new List <NSIndexPath> (); ComputeDifferenceBetweenRect(previousPreheatRect, preheatRect, removedRect => { var indexPaths = CollectionView.GetIndexPaths(removedRect); if (indexPaths != null) { removedIndexPaths.AddRange(indexPaths); } }, addedRect => { var indexPaths = CollectionView.GetIndexPaths(addedRect); if (indexPaths != null) { addedIndexPaths.AddRange(indexPaths); } }); var assetsToStartCaching = AssetsAtIndexPaths(addedIndexPaths.ToArray()); var assetsToStopCaching = AssetsAtIndexPaths(removedIndexPaths.ToArray()); // Update the assets the PHCachingImageManager is caching. if (assetsToStartCaching != null) { imageManager.StartCaching(assetsToStartCaching, assetGridThumbnailSize, PHImageContentMode.AspectFill, null); } if (assetsToStopCaching != null) { imageManager.StopCaching(assetsToStopCaching, assetGridThumbnailSize, PHImageContentMode.AspectFill, null); } // Store the preheat rect to compare against in the future. previousPreheatRect = preheatRect; } }
CGPoint ProcessTouch(CGPoint touchPoint) { nfloat x = NMath.Max(0, touchPoint.X); x = NMath.Min(x, graphLayer.Frame.Width + leftMargin); nfloat y = NMath.Max(0, touchPoint.Y); y = NMath.Min(y, graphLayer.Frame.Height + bottomMargin); return(new CGPoint(x, y)); }
public override void LayoutSubviews() { var bounds = ContentView.Bounds; var padding = bounds.Height * .11f; var frameHeight = bounds.Height * .8f; CellView.Frame = Bounds; if (AccessoryView != null) { AccessoryView.Frame = new CGRect(0, 0, frameHeight, frameHeight); } base.LayoutSubviews(); nfloat aLeft = 0; //Fix the accessoryview so its covers the whole right of the cell if (AccessoryView != null) { DisclosureButton.Image = Images.GetDisclosureImage(frameHeight / 2, frameHeight / 2); var aFrame = AccessoryView.Frame; var extraWidth = Bounds.Right - aFrame.Right; aFrame.Width += extraWidth; AccessoryView.Frame = aFrame; aLeft = aFrame.Left; bounds.Width = aLeft; } var leftPadding = this.GetSafeArea().Left; var frame = bounds; frame.Width = frame.Height = frameHeight; frame.Y = (bounds.Height - frame.Height) / 2; frame.X = padding + leftPadding; ImageView.Frame = frame; var x = frame.Right + padding + TextOffset; var offIconW = NMath.Min(offlineIconWidth, OfflineImageView.Frame.Width); var right = bounds.Right; var width = right - x - offIconW; frame.Width = width; frame.X = x; TextView.Frame = frame; x = frame.Right; frame.Width = bounds.Width - frame.Right; frame.X = x; OfflineImageView.Center = frame.GetCenter(); MediaTypeImage.Frame = new CGRect(aLeft + Padding, bounds.Height - offlineIconWidth - Padding, offlineIconWidth, offlineIconWidth); }
public void CUDA() { var location = StorageLocation.Host; var normal = new Normal(new RandomNumberStream(location), 0, 1); var input = NArray.CreateRandom(1000, normal); var result = NArray.CreateLike(input); NArray.Evaluate(() => { return(NMath.Exp(input * 0.2 + 6)); }); }
public static void DrawArrow(Vector3 origin, Vector3 direction, float arrowAngle = 25.0f) { float arrowLength = NMath.Gap(origin, origin + direction) / 7; Gizmos.color = Color; Gizmos.DrawRay(origin, direction); Vector3 right = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 90, arrowAngle) * new Vector3(1, 0, 0); Vector3 left = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 90, -arrowAngle) * new Vector3(1, 0, 0); Gizmos.DrawRay(origin + direction, right * arrowLength); Gizmos.DrawRay(origin + direction, left * arrowLength); }
private double Q_normal(double x) { if (x >= 0.0) { return(0.5 * NMath.Q_gamma(0.5, 0.5 * x * x, LOG_PI / 2)); } else { return(0.5 * (1 + NMath.P_gamma(0.5, 0.5 * x * x, LOG_PI / 2))); } // return 0.5 * (1.0 + erf(-x/sqrt(2.0))); }
/// <summary> /// Updates the progress bar to the given value with the optional properties /// </summary> /// <param name="progress">The progress to update to, pinned between <c>0</c> and <c>1</c>.</param> /// <param name="animated">Whether or not the update should be animated (defaults to <c>true</c>).</param> /// <param name="initialDelay">Sets an initial delay before the animation begins.</param> /// <param name="duration">Sets the overal duration that the animation should complete within.</param> public void UpdateProgress(nfloat progress, bool animated = true, double initialDelay = 0, double?duration = null) { var pinnedProgress = pin(progress, 0.0f, 1.0f); var indeterminate = progressLayer.AnimationForKey(CircularProgressAnimationKeys.indeterminate); if (indeterminate != null && pinnedProgress > 0) { progressLayer.RemoveAnimation(CircularProgressAnimationKeys.indeterminate); } if (animated) { // Get duration double animationDuration = 0; if (duration.HasValue && Math.Abs(duration.Value) > double.Epsilon) { animationDuration = duration.Value; } else { // Same duration as UIProgressView animation animationDuration = NMath.Abs(Progress - pinnedProgress); } // Get current progress (to avoid jumpy behavior) // Basic animations have their value reset to the original once the animation is finished // since only the presentation layer is animating nfloat currentProgress = 0; var presentationLayer = progressLayer.PresentationLayer as CircularProgressLayer; if (presentationLayer != null) { currentProgress = presentationLayer.Progress; } progressLayer.Progress = currentProgress; progressLayer.RemoveAnimation(CircularProgressAnimationKeys.progress); animate(progress, currentProgress, initialDelay, animationDuration); } else { progressLayer.RemoveAnimation(CircularProgressAnimationKeys.progress); progressLayer.Progress = pinnedProgress; progressLayer.SetNeedsDisplay(); } }
// Compute projection from object interface to virtual screen on the range [-1, 1]. CGPoint ScreenProjection(CGPoint location, CGRect bounds) { var w = bounds.Width; var h = bounds.Height; var aspectRatioCorrection = (h - w) / 2; var screenCoord = new CGPoint(location.X / w * 2 - 1, (h - location.Y - aspectRatioCorrection) / w * 2 - 1); screenCoord.X = NMath.Min(1, NMath.Max(-1, screenCoord.X)); screenCoord.Y = NMath.Min(1, NMath.Max(-1, screenCoord.Y)); return(screenCoord); }
public override void ResizeSubviewsWithOldSize(CoreGraphics.CGSize oldSize) { base.ResizeSubviewsWithOldSize(oldSize); var bounds = Bounds; blur.Frame = bounds; var sliderCount = sliders.Count; var width = this.Bounds.Width / (sliderCount + 1); var padding = width / 2; var right = Bounds.Width - sidePadding; var sliderTop = 100; var available = bounds.Bottom - sliderTop - (topItemsPadding * 2) - 25; nfloat height = 0; //if (Util.IsIphone) height = NMath.Min(available, EqSliderMaxHeight); //else // height = this.Bounds.Height - 65; var sliderH = sliderTop + ((available - height) / 2) + topItemsPadding; nfloat x; // var offset = width * 2; // preAmp.Frame = new CGRect (padding, sliderH, width, height); // preampLabel.Frame = new CGRect(padding, preAmp.Frame.Bottom, width, 25); for (int i = 0; i < sliders.Count; i++) { x = width * i + padding; var slider = sliders[i]; var label = sliderLabels[i]; slider.Frame = new CGRect(x, sliderH, width, height); label.Frame = new CGRect(x, slider.Frame.Bottom, width, 25); } var frame = enabledSwitch.Frame; frame.X = padding + (frame.Width - width) / 2; frame.Y = sliderH - topItemsPadding - frame.Height; enabledSwitch.Frame = frame; x = frame.Right + padding; comboBox.SizeToFit(); frame = comboBox.Frame; frame.Width = 300; frame.X = x; frame.Y = sliderH - topItemsPadding - frame.Height; comboBox.Frame = frame; }
public override void DrawInContext(CGContext context) { base.DrawInContext(context); nfloat size = NMath.Min(Bounds.Size.Width, Bounds.Size.Height); CGAffineTransform transform = AffineTransform; nfloat xTranslate = 0; nfloat yTranslate = 0; if (Bounds.Size.Width < Bounds.Size.Height) { yTranslate = (Bounds.Size.Height - size) / 2f; } else { xTranslate = (Bounds.Size.Width - size) / 2f; } transform.Translate(xTranslate, yTranslate); nfloat strokeWidth = StrokeFactor * size; nfloat checkBoxInset = InsetFactor * size; // Create the outer border for the check box. nfloat outerDimension = size - 2 * checkBoxInset; var checkBoxRect = new CGRect(checkBoxInset, checkBoxInset, outerDimension, outerDimension); checkBoxRect = transform.TransformRect(checkBoxRect); // Make the desired width of the outer box. context.SetLineWidth(strokeWidth); // Set the tint color of the outer box. context.SetStrokeColor(TintColor); // Draw the outer box. context.StrokeRect(checkBoxRect); // Draw the inner box if it's checked. if (Checked) { nfloat markInset = MarkInsetFactor * size; nfloat markDimension = size - 2 * markInset; var markRect = new CGRect(markInset, markInset, markDimension, markDimension); markRect = transform.TransformRect(markRect); context.SetFillColor(TintColor); context.FillRect(markRect); } }
public static float GetLineHeight(this CTFont font) { // https://stackoverflow.com/questions/5511830/how-does-line-spacing-work-in-core-text-and-why-is-it-different-from-nslayoutm //var ascent = (double)font.AscentMetric; //var descent = (double)font.DescentMetric; //var leading = (double)font.LeadingMetric; //leading = leading < 0 ? 0.0 : Math.Floor(leading + 0.5); //var lineHeight = Math.Floor(ascent + 0.5) + Math.Floor(descent + 0.5) + leading; //var ascenderDelta = leading > 0 ? 0.0 : Math.Floor(0.2 * lineHeight + 0.5); //return (float)(lineHeight + ascenderDelta); return((float)NMath.Ceiling(font.AscentMetric + font.DescentMetric + font.LeadingMetric + 1)); }
private void DrawStopRecordButton(CGRect frame) { var color = UIColor.Red; var RectPath = UIBezierPath.FromRect(new CGRect(NMath.Floor((frame.Width * 0.5f) - 24), NMath.Floor((frame.Height * 0.5f) - 24), 48, 48)); color.SetFill(); RectPath.Fill(); UIColor.White.SetStroke(); RectPath.LineWidth = 1.0f; RectPath.Stroke(); }
public override void TouchesMoved(NSSet touches, UIEvent @event) { this.SetBackgroundColor(UIColor.Gray); var first = touches.ToArray <UITouch>()[0]; var x = first.LocationInNode(this).X - this.background.Position.X; var position = Math.Max(NMath.Min(x, this.Width), 0f); this.slider.Position = new CGPoint(this.background.Position.X + position, 0f); this.Value = (float)(position / this.Width); this.actionClicked.Invoke(this); }