Beispiel #1
0
        public override void DrawRect(CoreGraphics.CGRect dirtyRect)
        {
            NSColor.Brown.Set();
            NSGraphics.FrameRect(Bounds);

            string s = value.ToString();
            NSMutableAttributedString attributes = new NSMutableAttributedString(value.ToString());

            attributes.AddAttribute(NSStringAttributeKey.Font, NSFont.FromFontName("Helvetica", 96), new NSRange(0, s.Length));
            attributes.AddAttribute(NSStringAttributeKey.ForegroundColor, NSColor.Brown, new NSRange(0, s.Length));
            attributes.DrawAtPoint(new CoreGraphics.CGPoint(10, 10));
        }
Beispiel #2
0
        private void Initialize()
        {
            BackgroundColor = UIColor.Clear;

            Console.WriteLine("UIKnobControl.Bounds.Width = " + Bounds.Width);
            Console.WriteLine("UIKnobControl.Bounds.Height = " + Bounds.Height);

            _bgImage = new UIImageView(UIImage.FromFile("knob_bg.png"))
            {
                Frame       = Bounds,
                ContentMode = UIViewContentMode.ScaleAspectFill
            };

            AddSubview(_bgImage);

            _handleImage = new UIImageView(UIImage.FromFile("knob_handle.png"))
            {
                Frame       = Bounds,
                ContentMode = UIViewContentMode.ScaleAspectFit,
            };

            AddSubview(_handleImage);

            _valueLabel = new UILabel()
            {
                Frame         = Bounds,
                Font          = UIFont.SystemFontOfSize(22.0F),
                TextColor     = UIColor.Gray,
                Text          = _currentValue.ToString(),
                TextAlignment = UITextAlignment.Center
            };

            AddSubview(_valueLabel);
        }
        //Using to test labels right now.
        public void UpdateValues(UILabel label, UIImage image)
        {
            nfloat totP = 0.0f;
            nfloat avgP = 0.0f;

            string[] fromCalc = new string[2];
            fromCalc   = ImageProcessing.CalculatePValue(image, ref totP, ref avgP);
            label.Text = fromCalc [0];
            if (DataTaken && P0Taken)
            {
                string[] valuesFromCalc = new string[2];
                valuesFromCalc = ImageProcessing.CalculatePValue(dataImage, ref totP, ref avgP);
                nfloat avgPData = avgP;
                lastAvgData   = avgP;
                lastTotalData = totP;
                string[] valuesFromCalcP0 = new string[2];
                valuesFromCalcP0 = ImageProcessing.CalculatePValue(P0Image, ref totP, ref avgP);
                nfloat avgP0 = avgP;
                nfloat A     = ImageProcessing.ComputerA(avgPData, avgP0);
                lastAvgP0        = avgP0;
                lastTotalP0      = totP;
                lastA            = A;
                txtAveValue.Text = A.ToString();
            }
        }
        //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        public void UpdateView()
        {
            if (image != null)
            {
                if (UIScreen.MainScreen.Bounds.Width < UIScreen.MainScreen.Bounds.Height)
                {
                    TimeLabel.Frame   = new CoreGraphics.CGRect(TimeLabel.Frame.X, 62, TimeLabel.Frame.Width, TimeLabel.Frame.Height);
                    ImageButton.Frame = new CoreGraphics.CGRect(ImageButton.Frame.X, 77, ImageButton.Frame.Width, ImageButton.Frame.Height);
                }
                else
                {
                    TimeLabel.Frame   = new CoreGraphics.CGRect(TimeLabel.Frame.X, 62 - 33, TimeLabel.Frame.Width, TimeLabel.Frame.Height);
                    ImageButton.Frame = new CoreGraphics.CGRect(ImageButton.Frame.X, 77 - 35, ImageButton.Frame.Width, ImageButton.Frame.Height);
                }

                nfloat scaleKoeff = (nfloat)Math.Min(UIScreen.MainScreen.Bounds.Width / image.Size.Width, (UIScreen.MainScreen.Bounds.Height - ImageButton.Frame.Y) / image.Size.Height);
                Console.WriteLine("W: " + image.Size.Width.ToString() + "H: " + image.Size.Height.ToString());

                Console.WriteLine("scaleKoeff: " + scaleKoeff.ToString() + "H: " + (image.Size.Height * scaleKoeff).ToString());

                ImageButton.SetBackgroundImage(image.Scale(new CoreGraphics.CGSize(image.Size.Width * scaleKoeff, image.Size.Height * scaleKoeff)), UIControlState.Normal);
                ImageButton.SizeToFit();

                TimeLabel.Text = lastTime.ToString();
            }
        }
Beispiel #5
0
        public DeviceDetailController()
        {
            CGRect bounds = WKInterfaceDevice.CurrentDevice.ScreenBounds;
            nfloat scale  = WKInterfaceDevice.CurrentDevice.ScreenScale;

            boundsLabel.SetText(bounds.ToString());
            scaleLabel.SetText(scale.ToString());
            preferredContentSizeLabel.SetText(WKInterfaceDevice.CurrentDevice.PreferredContentSizeCategory);
        }
Beispiel #6
0
        public override string ToString()
        {
            using (var ns = new NSString(NSStringFromCGVector(this)))
                return(ns.ToString());

#if false
            return(String.Format("{{dx={0}, dy={1}}}", dx.ToString(CultureInfo.CurrentCulture),
                                 dy.ToString(CultureInfo.CurrentCulture)));
#endif
        }
Beispiel #7
0
            public UIImage CropImage(UIImage imageIn, nfloat crop_x, nfloat crop_y, nfloat width, nfloat height)
            {
                var imgSize = imageIn.Size;

                UIGraphics.BeginImageContext(new SizeF(float.Parse(width.ToString()), float.Parse(height.ToString())));
                var context     = UIGraphics.GetCurrentContext();
                var clippedRect = new RectangleF(0, 0, float.Parse(width.ToString()), float.Parse(height.ToString()));

                context.ClipToRect(clippedRect);
                var drawRect = new CGRect(-crop_x, -crop_y, imgSize.Width, imgSize.Height);

                imageIn.Draw(drawRect);
                var modifiedImage = UIGraphics.GetImageFromCurrentImageContext();

                UIGraphics.EndImageContext();


                return(modifiedImage);
            }
        private void Initialize()
        {
            _valueLabel = new UILabel()
            {
                Frame         = Bounds,
                Font          = UIFont.SystemFontOfSize(22.0F),
                TextColor     = UIColor.Gray,
                Text          = _currentValue.ToString(),
                TextAlignment = UITextAlignment.Center
            };

            AddSubview(_valueLabel);
            _artboardKnobDrawing = new ArtboardKnobDrawing();
        }
Beispiel #9
0
 public string FormatNFloat(nfloat number, int decimalPlaces = 2)
 {
     return(number.ToString($"F{decimalPlaces}", this.formatInfo));
 }
Beispiel #10
0
        public static String[] CalculatePValue(UIImage image, ref nfloat totP, ref nfloat avgP)
        {
            UIImage uiImagePic = image;


            CIContext ctx     = CIContext.FromOptions(null);
            CGImage   cgimage = uiImagePic.CGImage;

            nfloat powerValueAvg = 0.0f;
            nfloat powerValueTot = 0.0f;
            nint   numPixels     = 0;
            //compute values
            nint width  = cgimage.Width;
            nint height = cgimage.Height;

            nint bpr             = cgimage.BytesPerRow;
            nint bpp             = cgimage.BitsPerPixel;
            nint bpc             = cgimage.BitsPerComponent;
            nint bytes_per_pixel = bpp / bpc;

            CGBitmapFlags  info      = cgimage.BitmapInfo;
            CGDataProvider provider  = cgimage.DataProvider;
            NSData         data      = provider.CopyData();
            IntPtr         bytesintp = data.Bytes;

            byte[] bytes = new byte[data.Length];
            Marshal.Copy(bytesintp, bytes, 0, (int)data.Length);
            Console.WriteLine("Pixel Data:");
            for (nint row = 0; row < height; row++)
            {
                for (nint col = 0; col < width; col++)
                {
                    byte[] pixel = new byte[bytes_per_pixel];
                    for (int i = 0; i < bytes_per_pixel; i++)
                    {
                        pixel [i] = bytes [row * bpr + col * bytes_per_pixel + i];
                    }

                    //Console.Write("(");
                    for (nint x = 0; x < bytes_per_pixel; x++)
                    {
                        //pixel[0] is r
                        //pixel[1] is g
                        //pixel[2] is b
                        //pixel[3] is alpha
                        numPixels++;
                        nfloat curPower = pixel [0] * 0.299f + pixel [1] * 0.587f + pixel [2] * 0.0722f;
                        powerValueTot += curPower;
                        powerValueAvg  = powerValueTot / numPixels;

                        //	Console.Write(pixel[x]);
                        //	if( x < bytes_per_pixel - 1 )
                        //		Console.Write(",");
                    }

                    //Console.Write(")");
                    //if( col < width - 1 )
                    //	Console.Write(", ");
                }

                //Console.Write("\n");
            }
            totP = powerValueTot;
            avgP = powerValueAvg;
            string outputToName;

            outputToName = powerValueAvg.ToString("0.0000");
            string outputToName2 = powerValueTot.ToString("0.0000");

            string[] strToRet = new string[2];
            strToRet [0] = outputToName;
            strToRet [1] = outputToName2;
            return(strToRet);
        }
Beispiel #11
0
        private async void AlertGetName()
        {
            int buttonClicked = -1;

            //Create Our Alert
            var alert = new UIAlertView("Filename", "Please Input The Filename", null, "Cancel", "Submit");

            //Set The Alert Style
            alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput;

            //Create Our Async Task
            var tcs = new TaskCompletionSource <int>();

            //Check What Button Was Pressed
            alert.Clicked += (sender, buttonArgs) =>
            {
                buttonClicked = (int)buttonArgs.ButtonIndex;
                tcs.TrySetResult((int)buttonArgs.ButtonIndex);
            };
            alert.Show();

            //Wait For Us To Get A Button Press
            await tcs.Task;

            //After Press Get Our Text From TextBox
            string text = alert.GetTextField(0).Text;

            if (buttonClicked == 0)             //Cancel Button Clicked
            {
                //Do Nothing
            }
            else if (buttonClicked == 1)             //Submit Button Clicked
            {
                DataSet dataSet = new DataSet()
                {
                    dataSetName    = text,
                    dataSetAvgP0   = lastAvgP0.ToString("0.0000"),
                    dataSetTotP0   = lastTotalP0.ToString("0.0000"),
                    dataSetAvgData = lastAvgData.ToString("0.0000"),
                    dataSetTotData = lastTotalData.ToString("0.0000"),
                    dataSetA       = lastA.ToString("0.0000000")
                };

                try                 //This Has A Possibility To Crash The Program
                {
                    //Try Saving Our Data Set To JSON
                    dataService.SaveDataSet(dataSet);

                    //Has to be called after dataService because Id needs to be assigned by JSON
                    SaveImageToFile(dataSet.dataSetName + "P0" + dataSet.Id, P0Image);
                    SaveImageToFile(dataSet.dataSetName + "Data" + dataSet.Id, dataImage);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception Caught : Cant Write Data To File (Please Fix This)");
                    Console.WriteLine(e);
                }
            }
            else
            {
                Console.WriteLine("Alert : View Was Closed Unnaturally, What Happened?");
            }

            dataService.RefreshCache();
        }