public static NSImage createGradientImageWidth(CGFloat pixelsWide) height(CGFloat pixelsHigh) fromColor(NSColor fromColor) toColor(NSColor toColor)
		{
			CGImageRef theCGImage = null;
			CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
			//  create the bitmap context
			CGContextRef gradientBitmapContext = CGBitmapContextCreate(null, (size_t)pixelsWide, (size_t)pixelsHigh, 8, 0, colorSpace, CGImageAlphaInfo.kCGImageAlphaNoneSkipFirst as CGBitmapInfo);
			//  define the start and end grayscale values (with the alpha, even though
			//  our bitmap context doesn't support alpha the gradient requires it)
			CGColorRef start = fromColor.CGColor();
			CGColorRef end = toColor.CGColor();
			CGColorRef[] colors = new [] {start, end};
			//  CGFloat locations[2] = { 0.0, 1.0 };
			CFArrayRef colorArray = CFArrayCreate(null, &colors, 2, null);
			//  create the CGGradient and then release the gray color space
			CGGradientRef grayScaleGradient = CGGradientCreateWithColors(null, colorArray, null);
			CGColorSpaceRelease(colorSpace);
			CFRelease(colorArray);
			//  create the start and end points for the gradient vector (straight down)
			CGPoint gradientStartPoint = CGPointZero;
			CGPoint gradientEndPoint = CGPointMake(pixelsWide / 2, pixelsHigh);
			//  draw the gradient into the gray bitmap context
			CGContextDrawLinearGradient(gradientBitmapContext, grayScaleGradient, gradientStartPoint, gradientEndPoint, kCGGradientDrawsAfterEndLocation);
			CGGradientRelease(grayScaleGradient);
			//  convert the context into a CGImageRef and release the context
			theCGImage = CGBitmapContextCreateImage(gradientBitmapContext);
			CGContextRelease(gradientBitmapContext);
			//  return the imageref containing the gradient
			NSImage theImage = this.imageFromCGImageRef(theCGImage);
			//  [NSImage imageWithCGImage:theCGImage];
			CGImageRelease(theCGImage);
			return theImage;
		}
Пример #2
0
		public MyView (CGRect frame) : base (frame)
		{
			lineColor = NSColor.Blue;
			path = new NSBezierPath ();
			path.MoveTo (Bounds.Location);
			path.LineTo (new CGPoint (Bounds.GetMaxX (),Bounds.GetMaxY ()));
		}
Пример #3
0
		private void AddBox (string title, CGRect frame, int level, NSColor color)
		{
			var node = Utils.SCBoxNode (title, frame, color, 2.0f, true);
			node.Scale = new SCNVector3 (0.02f, 0.02f, 0.02f);
			node.Position = new SCNVector3 (-5, 1.5f * level, 10);
			ContentNode.AddChildNode (node);
		}
Пример #4
0
		/// <summary>
		/// Initializes a new instance of the <see cref="AppKit.TextKit.Formatter.KeywordDescriptor"/> class.
		/// </summary>
		/// <param name="type">Specifies the <c>KeywordType</c>.</param>
		/// <param name="color">Specifies the <c>NSColor</c> that this keyword will be set to.</param>
		/// <param name="toolTip">Defines the tool tip for this keyword.</param>
		public KeywordDescriptor (KeywordType type, NSColor color, string toolTip)
		{
			// Initialize
			this.Type = type;
			this.Color = color;
			this.Tooltip = toolTip;
		}
Пример #5
0
        public WarningWindow()
        {
            // Interface Builder won't allow us to create a window with no title bar
            // so we have to create it manually. But we could use IB if we display
            // the window with a sheet...
            NSRect rect = new NSRect(0, 0, 460, 105);
            m_window = NSWindow.Alloc().initWithContentRect_styleMask_backing_defer(rect, 0, Enums.NSBackingStoreBuffered, false);

            m_window.setHasShadow(false);

            // Initialize the text attributes.
            var dict = NSMutableDictionary.Create();

            NSFont font = NSFont.fontWithName_size(NSString.Create("Georgia"), 64.0f);
            dict.setObject_forKey(font, Externs.NSFontAttributeName);

            NSMutableParagraphStyle style = NSMutableParagraphStyle.Create();
            style.setAlignment(Enums.NSCenterTextAlignment);
            dict.setObject_forKey(style, Externs.NSParagraphStyleAttributeName);

            m_attrs = dict.Retain();

            // Initialize the background bezier.
            m_background = NSBezierPath.Create().Retain();
            m_background.appendBezierPathWithRoundedRect_xRadius_yRadius(m_window.contentView().bounds(), 20.0f, 20.0f);

            m_color = NSColor.colorWithDeviceRed_green_blue_alpha(250/255.0f, 128/255.0f, 114/255.0f, 1.0f).Retain();

            ActiveObjects.Add(this);
        }
Пример #6
0
		public override void SetupSlide (PresentationViewController presentationViewController)
		{
			RedColor = NSColor.FromDeviceRgba (168.0f / 255.0f, 21.0f / 255.0f, 0.0f / 255.0f, 1);
			GreenColor = NSColor.FromDeviceRgba (154.0f / 255.0f, 197.0f / 255.0f, 58.0f / 255.0f, 1);
			BlueColor = NSColor.FromDeviceRgba (49.0f / 255.0f, 80.0f / 255.0f, 201.0f / 255.0f, 1);
			PurpleColor = NSColor.FromDeviceRgba (190.0f / 255.0f, 56.0f / 255.0f, 243.0f / 255.0f, 1);

			// Create the diagram but hide it
			DiagramNode = CloningDiagramNode ();
			DiagramNode.Opacity = 0.0f;
			ContentNode.AddChildNode (DiagramNode);
		}
Пример #7
0
		public override void DrawRect (CGRect dirtyRect)
		{
			CGRect bounds = Bounds;
			CGSize stripeSize = bounds.Size;
			stripeSize.Width = bounds.Width / 10.0f;
			CGRect stripe = bounds;
			stripe.Size = stripeSize;
			NSColor[] colors = new NSColor[2] { NSColor.White, NSColor.Blue };
			for (int i = 0; i < 10; i++){
				colors [i % 2].Set ();
				NSGraphics.RectFill (stripe);
				CGPoint origin = stripe.Location;
				origin.X += stripe.Size.Width;
				stripe.Location = origin;
			}
		}
Пример #8
0
		public void ShowMessage (IconId image, string message, bool isMarkup, NSColor color)
		{
			DispatchService.AssertGuiThread ();

			LoadText (message, isMarkup, color);
			LoadPixbuf (image);
			ReconstructString ();
		}
Пример #9
0
		bool LoadText (string message, bool isMarkup, NSColor color)
		{
			message = message ?? "";
			message = message.Replace (Environment.NewLine, " ").Replace ("\n", " ").Trim ();

			if (message == text)
				return false;

			text = message;
			currentTextIsMarkup = isMarkup;
			textColor = color;

			return true;
		}
Пример #10
0
            public PathSelectorView(CGRect frameRect) : base(frameRect)
            {
                PathComponentCells = new [] {
                    new NSPathComponentCell {
                        Image     = ImageService.GetIcon("project").ToNSImage(),
                        Title     = ConfigurationPlaceholder,
                        Enabled   = false,
                        TextColor = NSColor.FromRgba(0.34f, 0.34f, 0.34f, 1),
                    },
                    new NSPathComponentCell {
                        Image     = ImageService.GetIcon("device").ToNSImage(),
                        Title     = RuntimePlaceholder,
                        Enabled   = false,
                        TextColor = NSColor.FromRgba(0.34f, 0.34f, 0.34f, 1),
                    }
                };

                BackgroundColor = NSColor.Clear;
                FocusRingType   = NSFocusRingType.None;
                Activated      += (sender, e) => {
                    var item = ClickedPathComponentCell;
                    if (item == null)
                    {
                        return;
                    }

                    var componentRect = ((NSPathCell)Cell).GetRect(item, Frame, this);
                    int idx           = -1;
                    int i             = 0;

                    var menu = new NSMenu {
                        AutoEnablesItems = false,
                        ShowsStateColumn = false,
                        Font             = NSFont.MenuFontOfSize(12),
                    };
                    if (object.ReferenceEquals(ClickedPathComponentCell, PathComponentCells [ConfigurationIdx]))
                    {
                        if (ActiveConfiguration == null)
                        {
                            return;
                        }

                        foreach (var configuration in ConfigurationModel)
                        {
                            if (idx == -1 && configuration.OriginalId == ActiveConfiguration.OriginalId)
                            {
                                idx = i;
                            }

                            var _configuration = configuration;
                            menu.AddItem(new NSMenuItem(configuration.DisplayString, (o2, e2) => {
                                ActiveConfiguration = configurationModel.First(c => c.OriginalId == _configuration.OriginalId);
                                if (ConfigurationChanged != null)
                                {
                                    ConfigurationChanged(o2, e2);
                                }
                                UpdatePathText(ConfigurationIdx, _configuration.DisplayString);
                            })
                            {
                                Enabled          = true,
                                IndentationLevel = 1,
                            });
                            ++i;
                        }
                    }
                    else if (object.ReferenceEquals(ClickedPathComponentCell, PathComponentCells [RuntimeIdx]))
                    {
                        if (ActiveRuntime == null)
                        {
                            return;
                        }

                        using (var activeMutableModel = ActiveRuntime.GetMutableModel()) {
                            foreach (var runtime in RuntimeModel)
                            {
                                using (var mutableModel = runtime.GetMutableModel()) {
                                    if (idx == -1 && mutableModel.DisplayString == activeMutableModel.DisplayString)
                                    {
                                        idx = i;
                                    }
                                }

                                if (runtime.HasParent)
                                {
                                    continue;
                                }

                                if (runtime.IsSeparator)
                                {
                                    menu.AddItem(NSMenuItem.SeparatorItem);
                                }
                                else
                                {
                                    CreateMenuItem(menu, runtime);
                                }
                                ++i;
                            }
                        }
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }

                    if (menu.Count > 1)
                    {
                        var offs = new CGPoint(componentRect.Left + 3, componentRect.Top + 3);

                        if (Window.Screen.BackingScaleFactor == 2)
                        {
                            offs.Y += 0.5f;                             // fine tune menu position on retinas
                        }
                        menu.PopUpMenu(null, offs, this);
                    }
                };
            }
Пример #11
0
 static NSDictionary FontColorAttrs(string name, float size, NSColor color)
 {
     return NSDictionary.FromObjectsAndKeys (
         new NSObject[] { NSFont.FromFontName (name, size), color },
         new NSObject[] { NSAttributedString.FontAttributeName, NSAttributedString.ForegroundColorAttributeName });
 }
Пример #12
0
 private AnnotateView(IntPtr obj)
     : base(obj)
 {
     m_color = NSColor.whiteColor().Retain();
     ActiveObjects.Add(this);
 }
Пример #13
0
 public void ShowError(string error)
 {
     ShowMessage(Stock.StatusError, error, false, NSColor.FromDeviceRgba(228f / 255, 84f / 255, 55f / 255, 1));
 }
Пример #14
0
        internal static NSColor GetFileColor(string fileName, string[][] fileGlobs, NSColor[] fileColors)
        {
            for (int i = 0; i < FilesCount; ++i)
            {
                if (fileGlobs[i] != null)
                {
                    foreach (string glob in fileGlobs[i])
                    {
                        if (Glob.Match(glob, fileName))
                        {
                            return fileColors[i] ?? NSColor.blackColor();
                        }
                    }
                }
            }

            return NSColor.blackColor();
        }
Пример #15
0
        public About() : base()
        {
            using (var a = new NSAutoreleasePool())
            {
                SetFrame(new RectangleF(0, 0, 640, 281), true);
                Center();

                Delegate    = new AboutDelegate();
                StyleMask   = (NSWindowStyle.Closable | NSWindowStyle.Titled);
                Title       = Properties_Resources.About;
                MaxSize     = new SizeF(640, 281);
                MinSize     = new SizeF(640, 281);
                HasShadow   = true;
                BackingType = NSBackingStore.Buffered;

                this.website_link       = new CmisSyncLink(Properties_Resources.Website, Controller.WebsiteLinkAddress);
                this.website_link.Frame = new RectangleF(new PointF(295, 25), this.website_link.Frame.Size);

                this.credits_link       = new CmisSyncLink(Properties_Resources.Credits, Controller.CreditsLinkAddress);
                this.credits_link.Frame = new RectangleF(
                    new PointF(this.website_link.Frame.X + this.website_link.Frame.Width + 10, 25),
                    this.credits_link.Frame.Size);

                this.report_problem_link       = new CmisSyncLink(Properties_Resources.ReportProblem, Controller.ReportProblemLinkAddress);
                this.report_problem_link.Frame = new RectangleF(
                    new PointF(this.credits_link.Frame.X + this.credits_link.Frame.Width + 10, 25),
                    this.report_problem_link.Frame.Size);

                this.hidden_close_button = new NSButton()
                {
                    Frame = new RectangleF(0, 0, 0, 0),
                    KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask,
                    KeyEquivalent             = "w"
                };

                this.hidden_close_button.Activated += delegate {
                    Controller.WindowClosed();
                };


                ContentView.AddSubview(this.hidden_close_button);

                CreateAbout();

                ContentView.AddSubview(this.website_link);
                ContentView.AddSubview(this.credits_link);
                ContentView.AddSubview(this.report_problem_link);
            }

            Controller.HideWindowEvent += delegate {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        PerformClose(this);
                    });
                }
            };

            Controller.ShowWindowEvent += delegate {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        OrderFrontRegardless();
                    });
                }
            };

            Controller.NewVersionEvent += delegate(string new_version) {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        this.updates_text_field.StringValue = "A newer version (" + new_version + ") is available!";
                        this.updates_text_field.TextColor   = NSColor.FromCalibratedRgba(0.45f, 0.62f, 0.81f, 1.0f);
                    });
                }
            };

            Controller.VersionUpToDateEvent += delegate {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        this.updates_text_field.StringValue = "You are running the latest version.";
                        this.updates_text_field.TextColor   = NSColor.FromCalibratedRgba(0.45f, 0.62f, 0.81f, 1.0f);
                    });
                }
            };

            Controller.CheckingForNewVersionEvent += delegate {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        this.updates_text_field.StringValue = "Checking for updates...";
                        this.updates_text_field.TextColor   = NSColor.FromCalibratedRgba(0.45f, 0.62f, 0.81f, 1.0f);
                    });
                }
            };
        }
Пример #16
0
 public void ShowMessage(string message, bool isMarkup)
 {
     ShowMessage(null, message, true, NSColor.FromRgba(0.34f, 0.34f, 0.34f, 1));
 }
Пример #17
0
        private void CreateAbout()
        {
            this.about_image      = NSImage.ImageNamed("about");
            this.about_image.Size = new SizeF(720, 260);

            this.about_image_view = new NSImageView()
            {
                Image = this.about_image,
                Frame = new RectangleF(0, 0, 720, 260)
            };

            this.version_text_field = new SparkleLabel("version " + Controller.RunningVersion, NSTextAlignment.Left)
            {
                DrawsBackground = false,
                Frame           = new RectangleF(295, 140, 318, 22),
                TextColor       = NSColor.White,
                Font            = NSFontManager.SharedFontManager.FontWithFamily(
                    "Lucida Grande", NSFontTraitMask.Unbold, 0, 11)
            };

            this.updates_text_field = new SparkleLabel("Checking for updates...", NSTextAlignment.Left)
            {
                DrawsBackground = false,
                Frame           = new RectangleF(295, Frame.Height - 232, 318, 98),
                TextColor       = NSColor.FromCalibratedRgba(1.0f, 1.0f, 1.0f, 0.5f),
                Font            = NSFontManager.SharedFontManager.FontWithFamily(
                    "Lucida Grande", NSFontTraitMask.Unbold, 0, 11)
            };

            this.credits_text_field = new SparkleLabel(
                @"Copyright © 2010–" + DateTime.Now.Year + " Hylke Bons and others." +
                "\n" +
                "\n" +
                "SparkleShare is Open Source software. You are free to use, modify, and redistribute it " +
                "under the GNU General Public License version 3 or later.", NSTextAlignment.Left)
            {
                DrawsBackground = false,
                Frame           = new RectangleF(295, Frame.Height - 260, 318, 98),
                TextColor       = NSColor.White,
                Font            = NSFontManager.SharedFontManager.FontWithFamily(
                    "Lucida Grande", NSFontTraitMask.Unbold, 0, 11),
            };

            this.website_link       = new SparkleLink("Website", Controller.WebsiteLinkAddress);
            this.website_link.Frame = new RectangleF(new PointF(295, 25), this.website_link.Frame.Size);

            this.credits_link       = new SparkleLink("Credits", Controller.CreditsLinkAddress);
            this.credits_link.Frame = new RectangleF(
                new PointF(this.website_link.Frame.X + this.website_link.Frame.Width + 10, 25),
                this.credits_link.Frame.Size);

            this.report_problem_link       = new SparkleLink("Report a problem", Controller.ReportProblemLinkAddress);
            this.report_problem_link.Frame = new RectangleF(
                new PointF(this.credits_link.Frame.X + this.credits_link.Frame.Width + 10, 25),
                this.report_problem_link.Frame.Size);

            this.debug_log_link       = new SparkleLink("Debug log", Controller.DebugLogLinkAddress);
            this.debug_log_link.Frame = new RectangleF(
                new PointF(this.report_problem_link.Frame.X + this.report_problem_link.Frame.Width + 10, 25),
                this.debug_log_link.Frame.Size);

            ContentView.AddSubview(this.about_image_view);
            ContentView.AddSubview(this.version_text_field);
            ContentView.AddSubview(this.updates_text_field);
            ContentView.AddSubview(this.credits_text_field);
            ContentView.AddSubview(this.website_link);
            ContentView.AddSubview(this.credits_link);
            ContentView.AddSubview(this.report_problem_link);
            ContentView.AddSubview(this.debug_log_link);
        }
Пример #18
0
        private void CreateAbout()
        {
            using (var a = new NSAutoreleasePool())
            {
                string about_image_path = Path.Combine(NSBundle.MainBundle.ResourcePath,
                                                       "Pixmaps", "about.png");

                this.about_image = new NSImage(about_image_path)
                {
                    Size = new SizeF(640, 260)
                };

                this.about_image_view = new NSImageView()
                {
                    Image = this.about_image,
                    Frame = new RectangleF(0, 0, 640, 260)
                };


                this.version_text_field = new NSTextField()
                {
                    StringValue     = "version " + Controller.RunningVersion,
                    Frame           = new RectangleF(295, 140, 318, 22),
                    BackgroundColor = NSColor.White,
                    Bordered        = false,
                    Editable        = false,
                    DrawsBackground = false,
                    TextColor       = NSColor.FromCalibratedRgba(0.45f, 0.62f, 0.81f, 1.0f),
                    Font            = NSFontManager.SharedFontManager.FontWithFamily
                                          ("Lucida Grande", NSFontTraitMask.Unbold, 0, 11)
                };

                this.updates_text_field = new NSTextField()
                {
                    StringValue     = "Checking for updates...",
                    Frame           = new RectangleF(295, Frame.Height - 232, 318, 98),
                    Bordered        = false,
                    Editable        = false,
                    DrawsBackground = false,
                    Font            = NSFontManager.SharedFontManager.FontWithFamily
                                          ("Lucida Grande", NSFontTraitMask.Unbold, 0, 11),
                    TextColor = NSColor.FromCalibratedRgba(0.45f, 0.62f, 0.81f, 1.0f)        // Tango Sky Blue #1
                };

                this.credits_text_field = new NSTextField()
                {
                    StringValue = @"Copyright © 2013-" + DateTime.Now.Year + "  Aegif and others." +
                                  "\n" +
                                  "\n" +
                                  "CmisSync is Open Source software. You are free to use, modify, and redistribute it " +
                                  "under the GNU General Public License version 3 or later.",
                    Frame           = new RectangleF(295, Frame.Height - 260, 318, 98),
                    TextColor       = NSColor.FromCalibratedRgba(0.45f, 0.62f, 0.81f, 1.0f),
                    DrawsBackground = false,
                    Bordered        = false,
                    Editable        = false,
                    Font            = NSFontManager.SharedFontManager.FontWithFamily(
                        "Lucida Grande", NSFontTraitMask.Unbold, 0, 11),
                };

                ContentView.AddSubview(this.about_image_view);
                ContentView.AddSubview(this.version_text_field);
                //ContentView.AddSubview (this.updates_text_field);
                ContentView.AddSubview(this.credits_text_field);
            }
        }
Пример #19
0
 public static NSColor ToNSColor(this Color col)
 {
     return(NSColor.FromDeviceRgba((float)col.Red, (float)col.Green, (float)col.Blue, (float)col.Alpha));
 }
        protected override void UpdateContents()
        {
            if (Node == null)
            {
                return;
            }

            foreach (var constraint in constraints)
            {
                constraint.Active = false;
                constraint.Dispose();
            }
            constraints.Clear();

            bool   selected           = Superview is NSTableRowView rowView && rowView.Selected;
            var    editable           = TreeView.GetCanEditNode(Node);
            var    textColor          = NSColor.ControlText;
            string evaluateStatusIcon = null;
            string valueButtonText    = null;
            var    showViewerButton   = false;
            Color? previewColor       = null;
            bool   showSpinner        = false;
            string strval;

            if (Node.IsUnknown)
            {
                if (TreeView.DebuggerService.Frame != null)
                {
                    strval = GettextCatalog.GetString("The name '{0}' does not exist in the current context.", Node.Name);
                }
                else
                {
                    strval = string.Empty;
                }
                evaluateStatusIcon = Ide.Gui.Stock.Warning;
            }
            else if (Node.IsError || Node.IsNotSupported)
            {
                evaluateStatusIcon = Ide.Gui.Stock.Warning;
                strval             = Node.Value ?? string.Empty;
                int i = strval.IndexOf('\n');
                if (i != -1)
                {
                    strval = strval.Substring(0, i);
                }
                textColor = NSColor.FromCGColor(GetCGColor(Styles.ObjectValueTreeValueErrorText));
            }
            else if (Node.IsImplicitNotSupported)
            {
                strval    = string.Empty;             //val.Value; with new "Show Value" button we don't want to display message "Implicit evaluation is disabled"
                textColor = NSColor.FromCGColor(GetCGColor(Styles.ObjectValueTreeValueDisabledText));
                if (Node.CanRefresh)
                {
                    valueButtonText = GettextCatalog.GetString("Show Value");
                }
            }
            else if (Node.IsEvaluating)
            {
                strval      = GettextCatalog.GetString("Evaluating\u2026");
                showSpinner = true;

                textColor = NSColor.FromCGColor(GetCGColor(Styles.ObjectValueTreeValueDisabledText));
            }
            else if (Node.IsEnumerable)
            {
                if (Node is ShowMoreValuesObjectValueNode)
                {
                    valueButtonText = GettextCatalog.GetString("Show More");
                }
                else
                {
                    valueButtonText = GettextCatalog.GetString("Show Values");
                }
                strval = string.Empty;
            }
            else if (Node is AddNewExpressionObjectValueNode)
            {
                strval   = string.Empty;
                editable = false;
            }
            else
            {
                strval = TreeView.Controller.GetDisplayValueWithVisualisers(Node, out showViewerButton);

                if (TreeView.Controller.GetNodeHasChangedSinceLastCheckpoint(Node))
                {
                    textColor = NSColor.FromCGColor(GetCGColor(Styles.ObjectValueTreeValueModifiedText));
                }

                var val = Node.GetDebuggerObjectValue();
                if (val != null && !val.IsNull && DebuggingService.HasGetConverter <Color> (val))
                {
                    try {
                        previewColor = DebuggingService.GetGetConverter <Color> (val).GetValue(val);
                    } catch {
                        previewColor = null;
                    }
                }
            }

            strval = strval.Replace("\r\n", " ").Replace("\n", " ");

            var views = new List <NSView> ();

            OptimalWidth = MarginSize;

            // First item: Status Icon -or- Spinner
            if (evaluateStatusIcon != null)
            {
                statusIcon.Image = GetImage(evaluateStatusIcon, Gtk.IconSize.Menu, selected);

                if (!statusIconVisible)
                {
                    AddSubview(statusIcon);
                    statusIconVisible = true;
                }

                constraints.Add(statusIcon.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor));
                constraints.Add(statusIcon.WidthAnchor.ConstraintEqualToConstant(ImageSize));
                constraints.Add(statusIcon.HeightAnchor.ConstraintEqualToConstant(ImageSize));
                views.Add(statusIcon);

                OptimalWidth += ImageSize;
                OptimalWidth += RowCellSpacing;
            }
            else if (statusIconVisible)
            {
                statusIcon.RemoveFromSuperview();
                statusIconVisible = false;
            }

            if (showSpinner)
            {
                if (!spinnerVisible)
                {
                    AddSubview(spinner);
                    spinner.StartAnimation(this);
                    spinnerVisible = true;
                }

                constraints.Add(spinner.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor));
                constraints.Add(spinner.WidthAnchor.ConstraintEqualToConstant(ImageSize));
                constraints.Add(spinner.HeightAnchor.ConstraintEqualToConstant(ImageSize));
                views.Add(spinner);

                OptimalWidth += ImageSize;
                OptimalWidth += RowCellSpacing;
            }
            else if (spinnerVisible)
            {
                spinner.RemoveFromSuperview();
                spinner.StopAnimation(this);
                spinnerVisible = false;
            }

            // Second Item: Color Preview
            if (previewColor.HasValue)
            {
                colorPreview.Layer.BackgroundColor = GetCGColor(previewColor.Value);

                if (!colorPreviewVisible)
                {
                    AddSubview(colorPreview);
                    colorPreviewVisible = true;
                }

                constraints.Add(colorPreview.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor));
                constraints.Add(colorPreview.WidthAnchor.ConstraintEqualToConstant(ImageSize));
                constraints.Add(colorPreview.HeightAnchor.ConstraintEqualToConstant(ImageSize));
                views.Add(colorPreview);

                OptimalWidth += colorPreview.Frame.Width;
                OptimalWidth += RowCellSpacing;
            }
            else if (colorPreviewVisible)
            {
                colorPreview.RemoveFromSuperview();
                colorPreviewVisible = false;
            }

            // Third Item: Value Button
            if (valueButtonText != null && !((MacObjectValueNode)ObjectValue).HideValueButton)
            {
                valueButton.Title = valueButtonText;
                UpdateFont(valueButton, -3);
                valueButton.SizeToFit();

                if (!valueButtonVisible)
                {
                    AddSubview(valueButton);
                    valueButtonVisible = true;
                }

                constraints.Add(valueButton.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor));
                views.Add(valueButton);

                OptimalWidth += valueButton.Frame.Width;
                OptimalWidth += RowCellSpacing;
            }
            else if (valueButtonVisible)
            {
                valueButton.RemoveFromSuperview();
                valueButtonVisible = false;
            }

            // Fourth Item: Viewer Button
            if (showViewerButton)
            {
                if (!viewerButtonVisible)
                {
                    AddSubview(viewerButton);
                    viewerButtonVisible = true;
                }

                constraints.Add(viewerButton.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor));
                constraints.Add(viewerButton.WidthAnchor.ConstraintEqualToConstant(viewerButton.Image.Size.Width));
                constraints.Add(viewerButton.HeightAnchor.ConstraintEqualToConstant(viewerButton.Image.Size.Height));
                views.Add(viewerButton);

                OptimalWidth += viewerButton.Frame.Width;
                OptimalWidth += RowCellSpacing;
            }
            else if (viewerButtonVisible)
            {
                viewerButton.RemoveFromSuperview();
                viewerButtonVisible = false;
            }

            // Fifth Item: Text Value
            TextField.StringValue = strval;
            TextField.TextColor   = textColor;
            TextField.Editable    = editable;
            UpdateFont(TextField);
            TextField.SizeToFit();

            constraints.Add(TextField.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor));
            views.Add(TextField);

            // lay out our views...
            var leadingAnchor = LeadingAnchor;

            for (int i = 0; i < views.Count; i++)
            {
                var view = views[i];

                constraints.Add(view.LeadingAnchor.ConstraintEqualToAnchor(leadingAnchor, i == 0 ? MarginSize : RowCellSpacing));
                leadingAnchor = view.TrailingAnchor;
            }

            constraints.Add(TextField.TrailingAnchor.ConstraintEqualToAnchor(TrailingAnchor, -MarginSize));

            foreach (var constraint in constraints)
            {
                constraint.Active = true;
            }

            OptimalWidth += TextField.Frame.Width;
            OptimalWidth += MarginSize;
        }
Пример #21
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 1.0f;

            switch (index)
            {
            case 0:
                // Set the slide's title and add some code
                TextManager.SetTitle("Materials");

                TextManager.AddBulletAtLevel("Diffuse", 0);
                TextManager.AddBulletAtLevel("Ambient", 0);
                TextManager.AddBulletAtLevel("Specular and shininess", 0);
                TextManager.AddBulletAtLevel("Normal", 0);
                TextManager.AddBulletAtLevel("Reflective", 0);
                TextManager.AddBulletAtLevel("Emission", 0);
                TextManager.AddBulletAtLevel("Transparent", 0);
                TextManager.AddBulletAtLevel("Multiply", 0);

                break;

            case 1:
                EarthNode.Opacity = 1.0f;

                presentationViewController.UpdateLightingWithIntensities(new float[] { 1 });
                break;

            case 2:
                EarthNode.Geometry.FirstMaterial.Diffuse.Contents = NSColor.Blue;

                TextManager.HighlightBullet(0);
                ShowCodeExample("#material.#diffuse.contents# = [NSColor blueColor];#", null, null);
                break;

            case 3:
                EarthNode.Geometry.FirstMaterial.Diffuse.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes/earth/earth-diffuse", "jpg"));

                ShowCodeExample("#material.#diffuse.contents# =#", "earth-diffuse-mini", "jpg");
                break;

            case 4:
                EarthNode.Geometry.FirstMaterial.Ambient.Contents  = new NSImage(NSBundle.MainBundle.PathForResource("Scenes/earth/earth-diffuse", "jpg"));
                EarthNode.Geometry.FirstMaterial.Ambient.Intensity = 1;

                TextManager.HighlightBullet(1);
                ShowCodeExample("#material.#ambient#.contents =#", "earth-diffuse-mini", "jpg");
                presentationViewController.UpdateLightingWithIntensities(LightIntensities);
                break;

            case 5:
                EarthNode.Geometry.FirstMaterial.Shininess         = 0.1f;
                EarthNode.Geometry.FirstMaterial.Specular.Contents = NSColor.White;

                TextManager.HighlightBullet(2);
                ShowCodeExample("#material.#specular#.contents = [NSColor whiteColor];#", null, null);
                break;

            case 6:
                EarthNode.Geometry.FirstMaterial.Specular.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes/earth/earth-specular", "jpg"));

                ShowCodeExample("#material.#specular#.contents =#", "earth-specular-mini", "jpg");
                break;

            case 7:
                EarthNode.Geometry.FirstMaterial.Normal.Contents  = new NSImage(NSBundle.MainBundle.PathForResource("Scenes/earth/earth-bump", "png"));
                EarthNode.Geometry.FirstMaterial.Normal.Intensity = 1.3f;

                TextManager.HighlightBullet(3);
                ShowCodeExample("#material.#normal#.contents =#", "earth-bump", "png");
                break;

            case 8:
                EarthNode.Geometry.FirstMaterial.Reflective.Contents  = new NSImage(NSBundle.MainBundle.PathForResource("Scenes/earth/earth-reflective", "jpg"));
                EarthNode.Geometry.FirstMaterial.Reflective.Intensity = 0.7f;
                EarthNode.Geometry.FirstMaterial.Specular.Intensity   = 0.0f;

                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration       = 2.0f;
                SCNTransaction.AnimationTimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
                CameraOriginalPosition = presentationViewController.CameraHandle.Position;
                presentationViewController.CameraHandle.Position = presentationViewController.CameraHandle.ConvertPositionToNode(new SCNVector3(6, 0, -10.11f), presentationViewController.CameraHandle.ParentNode);
                SCNTransaction.Commit();

                TextManager.HighlightBullet(4);
                ShowCodeExample("material.#reflective#.contents =", "earth-reflective", "jpg");
                break;

            case 9:
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration                 = 1.0f;
                SCNTransaction.AnimationTimingFunction           = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
                presentationViewController.CameraHandle.Position = CameraOriginalPosition;
                SCNTransaction.Commit();
                break;

            case 10:
                EarthNode.Geometry.FirstMaterial.Emission.Contents    = new NSImage(NSBundle.MainBundle.PathForResource("Scenes/earth/earth-emissive", "jpg"));
                EarthNode.Geometry.FirstMaterial.Reflective.Intensity = 0.3f;
                EarthNode.Geometry.FirstMaterial.Emission.Intensity   = 0.5f;

                TextManager.HighlightBullet(5);
                ShowCodeExample("material.#emission#.contents =", "earth-emissive-mini2", "jpg");
                break;

            case 11:
                EarthNode.Geometry.FirstMaterial.Emission.Intensity   = 1.0f;
                EarthNode.Geometry.FirstMaterial.Reflective.Intensity = 0.1f;

                ShowCodeExample(null, null, null);
                presentationViewController.UpdateLightingWithIntensities(new float[] { 0.01f });                  // keeping the intensity non null avoids an unnecessary shader recompilation
                break;

            case 12:
                EarthNode.Geometry.FirstMaterial.Reflective.Intensity = 0.3f;

                presentationViewController.UpdateLightingWithIntensities(LightIntensities);
                break;

            case 13:
                EarthNode.Geometry.FirstMaterial.Emission.Intensity = 0.0f;
                CloudsNode.Opacity = 0.9f;

                TextManager.HighlightBullet(6);
                break;

            case 14:
                // This effect can also be achieved with an image with some transparency set as the contents of the 'diffuse' property
                CloudsNode.Geometry.FirstMaterial.Transparent.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes/earth/cloudsTransparency", "png"));
                CloudsNode.Geometry.FirstMaterial.TransparencyMode     = SCNTransparencyMode.RgbZero;

                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 0;
                CloudsNode.Geometry.FirstMaterial.Transparency = 0;
                SCNTransaction.Commit();

                CloudsNode.Geometry.FirstMaterial.Transparency = 1;

                ShowCodeExample("material.#transparent#.contents =", "cloudsTransparency-mini", "png");
                break;

            case 15:
                EarthNode.Geometry.FirstMaterial.Multiply.Contents = NSColor.FromDeviceRgba(1.0f, (float)(204 / 255.0), (float)(102 / 255.0), 1);

                TextManager.HighlightBullet(7);
                ShowCodeExample("material.#mutliply#.contents = [NSColor yellowColor];", null, null);
                break;

            case 16:
                EarthNode.Geometry.FirstMaterial.Emission.Intensity   = 1.0f;
                EarthNode.Geometry.FirstMaterial.Reflective.Intensity = 0.1f;

                ShowCodeExample(null, null, null);
                presentationViewController.UpdateLightingWithIntensities(new float[] { 0.01f });
                break;

            case 17:
                EarthNode.Geometry.FirstMaterial.Emission.Intensity   = 0.0f;
                EarthNode.Geometry.FirstMaterial.Reflective.Intensity = 0.3f;

                presentationViewController.UpdateLightingWithIntensities(LightIntensities);
                break;
            }

            SCNTransaction.Commit();
        }
Пример #22
0
 public void ShowMessage(IconId image, string message, bool isMarkup)
 {
     ShowMessage(image, message, isMarkup, NSColor.FromRgba(0.34f, 0.34f, 0.34f, 1));
 }
Пример #23
0
        internal CCTexture2D CreateTextSprite(string text, CCFontDefinition textDefinition)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(new CCTexture2D());
            }

            int imageWidth;
            int imageHeight;
            var textDef = textDefinition;
            var contentScaleFactorWidth  = CCLabel.DefaultTexelToContentSizeRatios.Width;
            var contentScaleFactorHeight = CCLabel.DefaultTexelToContentSizeRatios.Height;

            textDef.FontSize          *= (int)contentScaleFactorWidth;
            textDef.Dimensions.Width  *= contentScaleFactorWidth;
            textDef.Dimensions.Height *= contentScaleFactorHeight;

            bool hasPremultipliedAlpha;

            // font
            NSFont font = null;

            var ext = System.IO.Path.GetExtension(textDef.FontName);

            if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
            {
                try
                {
                    textDef.FontName = LoadFontFile(textDef.FontName);
                    font             = NSFont.FromFontName(textDef.FontName, textDef.FontSize);
                }
                catch (Exception exc)
                {
                    CCLog.Log(".ttf {0} file not found or can not be loaded.", textDef.FontName);
                }
            }
            else
            {
                // font
                font = NSFontManager.SharedFontManager.FontWithFamily(textDef.FontName, NSFontTraitMask.Unbold | NSFontTraitMask.Unitalic, 0, textDef.FontSize);
            }

            if (font == null)
            {
                font = NSFontManager.SharedFontManager.FontWithFamily("Arial", NSFontTraitMask.Unbold | NSFontTraitMask.Unitalic, 0, textDef.FontSize);
                CCLog.Log("{0} not found.  Defaulting to Arial.", textDef.FontName);
            }

            // color
            var fontColor       = textDef.FontFillColor;
            var fontAlpha       = textDef.FontAlpha;
            var foregroundColor = NSColor.FromDeviceRgba(fontColor.R / 255.0f,
                                                         fontColor.G / 255.0f,
                                                         fontColor.B / 255.0f,
                                                         fontAlpha / 255.0f);

            // alignment
            var horizontalAlignment = textDef.Alignment;
            var verticleAlignement  = textDef.LineAlignment;

            var textAlign = (CCTextAlignment.Right == horizontalAlignment) ? NSTextAlignment.Right
                : (CCTextAlignment.Center == horizontalAlignment) ? NSTextAlignment.Center
                : NSTextAlignment.Left;

            // LineBreak
            var lineBreak = (CCLabelLineBreak.Character == textDef.LineBreak) ? NSLineBreakMode.CharWrapping
                : (CCLabelLineBreak.Word == textDef.LineBreak) ? NSLineBreakMode.ByWordWrapping
                : NSLineBreakMode.Clipping;

            var nsparagraphStyle = new NSMutableParagraphStyle();

            nsparagraphStyle.SetParagraphStyle(NSMutableParagraphStyle.DefaultParagraphStyle);
            nsparagraphStyle.LineBreakMode = lineBreak;
            nsparagraphStyle.Alignment     = textAlign;

            // Create a new attributed string definition
            var nsAttributes = new NSStringAttributes();

            // Font attribute
            nsAttributes.Font            = font;
            nsAttributes.ForegroundColor = foregroundColor;
            nsAttributes.ParagraphStyle  = nsparagraphStyle;

            var stringWithAttributes = new NSAttributedString(text, nsAttributes);

            var realDimensions = stringWithAttributes.Size;

            // Mac crashes if the width or height is 0
            if (realDimensions == SizeF.Empty)
            {
                throw new ArgumentOutOfRangeException("Native string:", "Dimensions of native NSAttributedString can not be 0,0");
            }

            var dimensions = new SizeF(textDef.Dimensions.Width, textDef.Dimensions.Height);

            var layoutAvailable = true;

            //
            // * Note * This seems to only effect Mac because iOS works fine without this work around.
            // Right Alignment BoundingRectWithSize does not seem to be working correctly when the following conditions are set:
            //      1) Alignment Right
            //      2) No dimensions
            //      3) There are new line characters embedded in the string.
            //
            // So we set alignment to Left, calculate our bounds and then restore alignement afterwards before drawing.
            //
            if (dimensions.Width <= 0)
            {
                dimensions.Width = 8388608;
                layoutAvailable  = false;

                // Set our alignment variables to left - see notes above.
                nsparagraphStyle.Alignment = NSTextAlignment.Left;
            }

            if (dimensions.Height <= 0)
            {
                dimensions.Height = 8388608;
                layoutAvailable   = false;
            }

            // Calculate our bounding rectangle
            var boundingRect = stringWithAttributes.BoundingRectWithSize(new SizeF((int)dimensions.Width, (int)dimensions.Height),
                                                                         NSStringDrawingOptions.UsesLineFragmentOrigin);

            if (!layoutAvailable)
            {
                if (dimensions.Width == 8388608)
                {
                    dimensions.Width = boundingRect.Width;

                    // Restore our alignment before drawing - see notes above.
                    nsparagraphStyle.Alignment = textAlign;
                }
                if (dimensions.Height == 8388608)
                {
                    dimensions.Height = boundingRect.Height;
                }
            }

            imageWidth  = (int)dimensions.Width;
            imageHeight = (int)dimensions.Height;

            // Alignment
            var xOffset = 0.0f;

            switch (textAlign)
            {
            case NSTextAlignment.Left:
                xOffset = 0;
                break;

            case NSTextAlignment.Center:
                xOffset = (dimensions.Width - boundingRect.Width) / 2.0f;
                break;

            case NSTextAlignment.Right: xOffset = dimensions.Width - boundingRect.Width; break;

            default: break;
            }

            // Line alignment
            var yOffset = (CCVerticalTextAlignment.Top == verticleAlignement ||
                           boundingRect.Height >= dimensions.Height) ? (dimensions.Height - boundingRect.Height) // align to top
                : (CCVerticalTextAlignment.Bottom == verticleAlignement) ? 0                                     // align to bottom
                : (imageHeight - boundingRect.Height) / 2.0f;                                                    // align to center

            //Find the rect that the string will draw into inside the dimensions
            var drawRect = new RectangleF(xOffset
                                          , yOffset
                                          , boundingRect.Width
                                          , boundingRect.Height);

            //Disable antialias
            NSGraphicsContext.CurrentContext.ShouldAntialias = false;

            NSImage image = new NSImage(new SizeF(imageWidth, imageHeight));

            image.LockFocus();

            // set a default transform
            var transform = new NSAffineTransform();

            transform.Set();

            stringWithAttributes.DrawInRect(drawRect);

            image.UnlockFocus();

            // We will use Texture2D from stream here instead of CCTexture2D stream.
            var tex = Texture2D.FromStream(CCDrawManager.SharedDrawManager.XnaGraphicsDevice, image);

            // Debugging purposes
//            var path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
//            var fileName = Path.Combine(path, "Label3.png");
//            using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
//            {
//                tex.SaveAsPng(stream, imageWidth, imageHeight);
//            }

            // Create our texture of the label string.
            var texture = new CCTexture2D(tex);

            return(texture);
        }
Пример #24
0
 public void ShowWarning(string warning)
 {
     ShowMessage(Stock.StatusWarning, warning, false, NSColor.FromDeviceRgba(235f / 255, 161f / 255, 7f / 255, 1));
 }
Пример #25
0
 public static global::CoreGraphics.CGColor GetCGColor(NSColor color)
Пример #26
0
        private void DoReadPrefs()
        {
            // Release the old stuff (if any).
            if (m_pathColor != null)
            {
                m_pathColor.release();
                m_pathColor = null;
            }

            for (int i = 0; i < FilesCount; ++i)
            {
                if (m_fileColors[i] != null)
                {
                    m_fileColors[i].release();
                    m_fileColors[i] = null;
                }
            }

            // Load the new stuff.
            NSUserDefaults defaults = NSUserDefaults.standardUserDefaults();

            var data = defaults.objectForKey(NSString.Create(m_path + "-path color")).To<NSData>();
            m_pathColor = NSUnarchiver.unarchiveObjectWithData(data).To<NSColor>().Retain();

            for (int i = 1; i <= FilesCount; ++i)
            {
                data = defaults.objectForKey(NSString.Create(m_path + "-files" + i + " color")).To<NSData>();
                m_fileColors[i - 1] = NSUnarchiver.unarchiveObjectWithData(data).To<NSColor>().Retain();

                string globs = defaults.stringForKey(NSString.Create(m_path + "-files" + i + " globs")).description();
                m_fileGlobs[i - 1] = Glob.Split(globs);
            }
        }
Пример #27
0
 public void ShowMessage(string message)
 {
     ShowMessage(null, message, false, NSColor.FromRgba(0.34f, 0.34f, 0.34f, 1));
 }
Пример #28
0
 static NSDictionary ColorAttrs(NSColor color)
 {
     return NSDictionary.FromObjectsAndKeys (
         new NSObject[] { color },
         new NSObject[] { NSAttributedString.ForegroundColorAttributeName });
 }
Пример #29
0
		NSAttributedString GetStatusString (string text, NSColor color)
		{
			nfloat fontSize = NSFont.SystemFontSize;
			if (Window != null && Window.Screen != null) {
				fontSize -= Window.Screen.BackingScaleFactor == 2 ? 2 : 1;
			} else {
				fontSize -= 1;
			}

			return new NSAttributedString (text, new NSStringAttributes {
				ForegroundColor = color,
				ParagraphStyle = new NSMutableParagraphStyle {
					HeadIndent = imageView.Frame.Width,
					LineBreakMode = NSLineBreakMode.TruncatingMiddle,
				},
				Font = NSFont.SystemFontOfSize (fontSize),
			});
		}
Пример #30
0
        public void OnStartup()
        {
            DoLoadPrefs();

            if (ms_resolvedColor == null)
            {
                ms_resolvedColor = NSColor.colorWithDeviceRed_green_blue_alpha(0.86f, 0.08f, 0.24f, 1.0f).Retain();		// crimson
                ms_unresolvedColor = NSColor.colorWithDeviceRed_green_blue_alpha(1.0f, 0.84f, 0.0f, 1.0f).Retain();		// gold
            //				ms_unresolvedColor = NSColor.colorWithDeviceRed_green_blue_alpha(1.0f, 0.63f, 0.48f, 1.0f).Retain();	// light salmon
            }

            Broadcaster.Register("opening document window", this);
            Broadcaster.Register("swapping code view", this);
            Broadcaster.Register("swapped code view", this);
            Broadcaster.Register("closing document window", this);

            Broadcaster.Register("debugger resumed", this);
            Broadcaster.Register("debugger started", this);
            Broadcaster.Register("debugger stopped", this);
            Broadcaster.Register("debugger resolved breakpoint", this);
            Broadcaster.Register("debugger unresolved breakpoint", this);
        }
Пример #31
0
		bool LoadText (string message, bool isMarkup, MessageType statusType)
		{
			message = message ?? "";
			message = message.Replace (Environment.NewLine, " ").Replace ("\n", " ").Trim ();

			if (message == text)
				return false;

			text = message;
			messageType = statusType;
			textColor = ColorForType (statusType);

			return true;
		}
Пример #32
0
		public void ShowMessage (IconId image, string message, bool isMarkup, NSColor color)
		{
			Runtime.AssertMainThread ();

			bool changed = LoadText (message, isMarkup, color);
			LoadPixbuf (image);
			if (changed)
				ReconstructString ();
		}
Пример #33
0
		static Cairo.Color ConvertColor (NSColor color)
		{
			nfloat r, g, b, a;
			if (color.ColorSpaceName == NSColorSpace.DeviceWhite) {
				a = 1.0f;
				r = g = b = color.WhiteComponent;
			} else {
				color.GetRgba (out r, out g, out b, out a);
			}
			return new Cairo.Color (r, g, b, a);
		}
Пример #34
0
		public static SCNNode SCBoxNode (string title, CGRect frame, NSColor color, float cornerRadius, bool centered)
		{
			NSMutableDictionary titleAttributes = null;
			NSMutableDictionary centeredTitleAttributes = null;

			// create and extrude a bezier path to build the box
			var path = NSBezierPath.FromRoundedRect (frame, cornerRadius, cornerRadius);
			path.Flatness = 0.05f;

			var shape = SCNShape.Create (path, 20);
			shape.ChamferRadius = 0.0f;

			var node = SCNNode.Create ();
			node.Geometry = shape;

			// create an image and fill with the color and text
			var textureSize = new CGSize ();
			textureSize.Width = NMath.Ceiling (frame.Size.Width * 1.5f);
			textureSize.Height = NMath.Ceiling (frame.Size.Height * 1.5f);

			var texture = new NSImage (textureSize);
			texture.LockFocus ();

			var drawFrame = new CGRect (0, 0, textureSize.Width, textureSize.Height);

			nfloat hue, saturation, brightness, alpha;

			(color.UsingColorSpace (NSColorSpace.DeviceRGBColorSpace)).GetHsba (out hue, out saturation, out brightness, out alpha);
			var lightColor = NSColor.FromDeviceHsba (hue, saturation - 0.2f, brightness + 0.3f, alpha);
			lightColor.Set ();

			NSGraphics.RectFill (drawFrame);

			NSBezierPath fillpath = null;

			if (cornerRadius == 0 && centered == false) {
				//special case for the "labs" slide
				drawFrame.Offset (0, -2);
				fillpath = NSBezierPath.FromRoundedRect (drawFrame, cornerRadius, cornerRadius);
			} else {
				drawFrame.Inflate (-3, -3);
				fillpath = NSBezierPath.FromRoundedRect (drawFrame, cornerRadius, cornerRadius);
			}

			color.Set ();
			fillpath.Fill ();

			// draw the title if any
			if (title != null) {
				if (titleAttributes == null) {
					var paraphStyle = new NSMutableParagraphStyle ();
					paraphStyle.LineBreakMode = NSLineBreakMode.ByWordWrapping;
					paraphStyle.Alignment = NSTextAlignment.Center;
					paraphStyle.MinimumLineHeight = 38;
					paraphStyle.MaximumLineHeight = 38;

					var font = NSFont.FromFontName ("Myriad Set Semibold", 34) != null ? NSFont.FromFontName ("Myriad Set Semibold", 34) : NSFont.FromFontName ("Avenir Medium", 34);

					var shadow = new NSShadow ();
					shadow.ShadowOffset = new CGSize (0, -2);
					shadow.ShadowBlurRadius = 4;
					shadow.ShadowColor = NSColor.FromDeviceWhite (0.0f, 0.5f);

					titleAttributes = new NSMutableDictionary ();
					titleAttributes.SetValueForKey (font, NSAttributedString.FontAttributeName);
					titleAttributes.SetValueForKey (NSColor.White, NSAttributedString.ForegroundColorAttributeName);
					titleAttributes.SetValueForKey (shadow, NSAttributedString.ShadowAttributeName);
					titleAttributes.SetValueForKey (paraphStyle, NSAttributedString.ParagraphStyleAttributeName);

					var centeredParaphStyle = (NSMutableParagraphStyle)paraphStyle.MutableCopy ();
					centeredParaphStyle.Alignment = NSTextAlignment.Center;

					centeredTitleAttributes = new NSMutableDictionary ();
					centeredTitleAttributes.SetValueForKey (font, NSAttributedString.FontAttributeName);
					centeredTitleAttributes.SetValueForKey (NSColor.White, NSAttributedString.ForegroundColorAttributeName);
					centeredTitleAttributes.SetValueForKey (shadow, NSAttributedString.ShadowAttributeName);
					centeredTitleAttributes.SetValueForKey (paraphStyle, NSAttributedString.ParagraphStyleAttributeName);
				}

				var attrString = new NSAttributedString (title, centered ? centeredTitleAttributes : titleAttributes);
				var textSize = attrString.Size;

				//check if we need two lines to draw the text
				var twoLines = title.Contains ("\n");
				if (!twoLines)
					twoLines = textSize.Width > frame.Size.Width && title.Contains (" ");

				//if so, we need to adjust the size to center vertically
				if (twoLines)
					textSize.Height += 38;

				if (!centered)
					drawFrame.Inflate (-15, 0);

				//center vertically
				var dy = (drawFrame.Size.Height - textSize.Height) * 0.5f;
				var drawFrameHeight = drawFrame.Size.Height;
				drawFrame.Size = new CGSize (drawFrame.Size.Width, drawFrame.Size.Height - dy);
				attrString.DrawString (drawFrame);
			}

			texture.UnlockFocus ();

			//set the created image as the diffuse texture of our 3D box
			var front = SCNMaterial.Create ();
			front.Diffuse.Contents = texture;
			front.LocksAmbientWithDiffuse = true;

			//use a lighter color for the chamfer and sides
			var sides = SCNMaterial.Create ();
			sides.Diffuse.Contents = lightColor;
			node.Geometry.Materials = new SCNMaterial[] {
				front,
				sides,
				sides,
				sides,
				sides
			};

			return node;
		}
Пример #35
0
		public override void PresentStep (int index, PresentationViewController presentationViewController)
		{
			switch (index) {
			case 0:
				// Hide everything (in case the user went backward)
				for (var i = 1; i < 4; i++) {
					var teapot = GroundNode.FindChildNode ("Teapot" + i, true);
					teapot.Opacity = 0.0f;
				}
				break;
			case 1:
				// Move the camera and adjust the clipping plane
				SCNTransaction.Begin ();
				SCNTransaction.AnimationDuration = 3;
				presentationViewController.CameraNode.Position = new SCNVector3 (0, 0, 200);
				presentationViewController.CameraNode.Camera.ZFar = 500.0f;
				SCNTransaction.Commit ();
				break;
			case 2:
				// Revert to original position
				SCNTransaction.Begin ();
				SCNTransaction.AnimationDuration = 1;
				presentationViewController.CameraNode.Position = new SCNVector3 (0, 0, 0);
				presentationViewController.CameraNode.Camera.ZFar = 100.0f;
				SCNTransaction.Commit ();
				break;
			case 3:
				var numberNodes = new SCNNode[] { AddNumberNode ("64k", -17),
					AddNumberNode ("6k", -9),
					AddNumberNode ("3k", -1),
					AddNumberNode ("1k", 6.5f),
					AddNumberNode ("256", 14)
				};
				SCNTransaction.Begin ();
				SCNTransaction.AnimationDuration = 1;

				// Move the camera and the text
				presentationViewController.CameraHandle.Position = new SCNVector3 (presentationViewController.CameraHandle.Position.X, presentationViewController.CameraHandle.Position.Y + 6, presentationViewController.CameraHandle.Position.Z);
				TextManager.TextNode.Position = new SCNVector3 (TextManager.TextNode.Position.X, TextManager.TextNode.Position.Y + 6, TextManager.TextNode.Position.Z);

				// Show the remaining resolutions
				for (var i = 0; i < 5; i++) {
					var numberNode = numberNodes [i];
					numberNode.Position = new SCNVector3 (numberNode.Position.X, 7, -5);

					var teapot = GroundNode.FindChildNode ("Teapot" + i, true);
					teapot.Opacity = 1.0f;
					teapot.Rotation = new SCNVector4 (0, 0, 1, (float)(Math.PI / 4));
					teapot.Position = new SCNVector3 ((i - 2) * 8, 5, teapot.Position.Z);
				}

				SCNTransaction.Commit ();
				break;
			case 4:
				presentationViewController.ShowsNewInSceneKitBadge (true);

				// Remove the numbers
				RemoveNumberNodes ();

				SCNTransaction.Begin ();
				SCNTransaction.AnimationDuration = 1;
					// Add some text and code
				TextManager.SetSubtitle ("SCNLevelOfDetail");

				TextManager.AddCode ("#var lod1 = SCNLevelOfDetail.#CreateWithWorldSpaceDistance# (aGeometry, aDistance); \n"
				+ "geometry.#LevelsOfDetail# = new SCNLevelOfDetail { lod1, lod2, ..., lodn };#");

				// Animation the merge
				for (int i = 0; i < 5; i++) {
					var teapot = GroundNode.FindChildNode ("Teapot" + i, true);

					teapot.Opacity = i == 0 ? 1.0f : 0.0f;
					teapot.Rotation = new SCNVector4 (0, 0, 1, 0);
					teapot.Position = new SCNVector3 (0, -5, teapot.Position.Z);
				}

				// Move the camera and the text
				presentationViewController.CameraHandle.Position = new SCNVector3 (presentationViewController.CameraHandle.Position.X, presentationViewController.CameraHandle.Position.Y - 3, presentationViewController.CameraHandle.Position.Z);
				TextManager.TextNode.Position = new SCNVector3 (TextManager.TextNode.Position.X, TextManager.TextNode.Position.Y - 3, TextManager.TextNode.Position.Z);

				SCNTransaction.Commit ();
				break;
			case 5:
				presentationViewController.ShowsNewInSceneKitBadge (false);

				SCNTransaction.Begin ();
				SCNTransaction.AnimationDuration = 3;
				// Change the lighting to remove the front light and rise the main light
				presentationViewController.UpdateLightingWithIntensities (new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.3f });
				presentationViewController.RiseMainLight (true);

				// Remove some text
				TextManager.FadeOutText (SlideTextManager.TextType.Title);
				TextManager.FadeOutText (SlideTextManager.TextType.Subtitle);
				TextManager.FadeOutText (SlideTextManager.TextType.Code);
				SCNTransaction.Commit ();

				// Retrieve the main teapot
				var maintTeapot = GroundNode.FindChildNode ("Teapot0", true);

				// The distances to use for each LOD
				var distances = new float [4] { 30, 50, 90, 150 };

				// An array of SCNLevelOfDetail instances that we will build
				var levelsOfDetail = new SCNLevelOfDetail[4];
				for (var i = 1; i < 5; i++) {
					var teapotNode = GroundNode.FindChildNode ("Teapot" + i, true);
					var teapot = teapotNode.Geometry;

					// Unshare the material because we will highlight the different levels of detail with different colors in the next step
					teapot.FirstMaterial = (SCNMaterial)teapot.FirstMaterial.Copy ();

					// Build the SCNLevelOfDetail instance
					var levelOfDetail = SCNLevelOfDetail.CreateWithWorldSpaceDistance (teapot, distances [i - 1]);
					levelsOfDetail [i - 1] = levelOfDetail;
				}

				maintTeapot.Geometry.LevelsOfDetail = levelsOfDetail;

				// Duplicate and move the teapots
				var startTime = CAAnimation.CurrentMediaTime ();
				var delay = 0.2;

				var rowCount = 9;
				var columnCount = 12;

				SCNTransaction.Begin ();
				SCNTransaction.AnimationDuration = 0;
				// Change the far clipping plane to be able to see far away
				presentationViewController.CameraNode.Camera.ZFar = 1000.0;

				for (var j = 0; j < columnCount; j++) {
					for (var i = 0; i < rowCount; i++) {
						// Clone
						var clone = maintTeapot.Clone ();
						maintTeapot.ParentNode.AddChildNode (clone);

						// Animate
						var animation = CABasicAnimation.FromKeyPath ("position");
						animation.Additive = true;
						animation.Duration = 1.0;
						animation.To = NSValue.FromVector (new SCNVector3 ((i - rowCount / 2.0f) * 12.0f, 5 + (columnCount - j) * 15.0f, 0));
						animation.From = NSValue.FromVector (new SCNVector3 (0, 0, 0));
						animation.BeginTime = startTime + delay; // desynchronize

						// Freeze at the end of the animation
						animation.RemovedOnCompletion = false;
						animation.FillMode = CAFillMode.Forwards;

						clone.AddAnimation (animation, new NSString ("cloneAnimation"));

						// Animate the hidden property to automatically show the node when the position animation starts
						animation = CABasicAnimation.FromKeyPath ("hidden");
						animation.Duration = delay + 0.01;
						animation.FillMode = CAFillMode.Both;
						animation.From = new NSNumber (1);
						animation.To = new NSNumber (0);
						clone.AddAnimation (animation, new NSString ("cloneAnimation2"));

						delay += 0.05;
					}
				}
				SCNTransaction.Commit ();

				// Animate the camera while we duplicate the nodes
				SCNTransaction.Begin ();
				SCNTransaction.AnimationDuration = 1.0 + rowCount * columnCount * 0.05;

				var position = presentationViewController.CameraHandle.Position;
				presentationViewController.CameraHandle.Position = new SCNVector3 (position.X, position.Y + 5, position.Z);
				presentationViewController.CameraPitch.Rotation = new SCNVector4 (1, 0, 0, presentationViewController.CameraPitch.Rotation.W - ((float)(Math.PI / 4) * 0.1f));
				SCNTransaction.Commit ();
				break;
			case 6:
				// Highlight the levels of detail with colors
				var teapotChild = GroundNode.FindChildNode ("Teapot0", true);
				var colors = new NSColor[] { NSColor.Red, NSColor.Orange, NSColor.Yellow, NSColor.Green };

				SCNTransaction.Begin ();
				SCNTransaction.AnimationDuration = 1;
				for (var i = 0; i < 4; i++) {
					var levelOfDetail = teapotChild.Geometry.LevelsOfDetail [i];
					levelOfDetail.Geometry.FirstMaterial.Multiply.Contents = colors [i];
				}
				SCNTransaction.Commit ();
				break;
			}
		}
Пример #36
0
		NSAttributedString GetStatusString (string text, NSColor color)
		{
			return new NSAttributedString (text, new NSStringAttributes {
				ForegroundColor = color,
				ParagraphStyle = new NSMutableParagraphStyle {
					HeadIndent = imageView.Frame.Width,
					LineBreakMode = NSLineBreakMode.TruncatingMiddle,
				},
				Font = NSFont.SystemFontOfSize (NSFont.SystemFontSize - 2),
			});
		}
Пример #37
0
        private SCNNode AddLabInfoNode(string title, float yPosition)
        {
            var labInfoNode = Utils.SCBoxNode (title, new CGRect (0, 0, 293.33f, 93.33f), NSColor.FromDeviceRgba (31 / 255, 31 / 255, 31 / 255, 1), 0.0f, false);
            labInfoNode.Scale = new SCNVector3 (0.015f, 0.015f, 0.015f);
            labInfoNode.Pivot = SCNMatrix4.CreateTranslation (new SCNVector3 (145.33f, 46.66f, 5));
            labInfoNode.Position = new SCNVector3 (6.9f, yPosition, 10.0f);
            labInfoNode.Rotation = new SCNVector4 (0, 1, 0, (float)(Math.PI));
            labInfoNode.Opacity = 0.0f;

            var colorBox = Utils.SCBoxNode (null, new CGRect (293.33f, 0, 40, 93.33f), NSColor.FromDeviceRgba (1, 214 / 255, 37 / 255, 1), 0.0f, false);
            colorBox.Geometry.FirstMaterial.LightingModelName = SCNLightingModel.Constant;

            ContentNode.AddChildNode (labInfoNode);
            labInfoNode.AddChildNode (colorBox);

            return labInfoNode;
        }
Пример #38
0
		void LoadText (string message, bool isMarkup, NSColor color)
		{
			message = message ?? "";

			text = message.Replace (Environment.NewLine, " ").Replace ("\n", " ").Trim ();
			currentTextIsMarkup = isMarkup;
			textColor = color;
		}
Пример #39
0
 public void ShowMessage(IconId image, string message)
 {
     ShowMessage(image, message, false, NSColor.FromRgba(0.34f, 0.34f, 0.34f, 1));
 }
Пример #40
0
		void LoadStyles (object sender = null, EventArgs args = null)
		{
			if (IdeApp.Preferences.UserInterfaceTheme == Theme.Dark) {
				Appearance = NSAppearance.GetAppearance (NSAppearance.NameVibrantDark);
			} else {
				Appearance = NSAppearance.GetAppearance (NSAppearance.NameAqua);
			}

			UpdateApplicationNamePlaceholderText ();
			textColor = ColorForType (messageType);
			ReconstructString ();
		}
Пример #41
0
		public void ShowMessage (IconId image, string message, bool isMarkup, NSColor color)
		{
			DispatchService.AssertGuiThread ();

			bool changed = LoadText (message, isMarkup, color);
			LoadPixbuf (image);
			if (changed)
				ReconstructString (updateTrackingAreas: true);
		}
Пример #42
0
        private NSMutableAttributedString DoCreateString(string newValue, NSColor color)
        {
            var attrs = NSMutableDictionary.Create();
            attrs.setObject_forKey(color, Externs.NSForegroundColorAttributeName);
            var result = NSMutableAttributedString.Create(newValue, attrs).Retain();

            return result;
        }
Пример #43
0
        private static void DoSetTempAttrs()
        {
            NSUserDefaults defaults = NSUserDefaults.standardUserDefaults();

            var data = defaults.objectForKey(NSString.Create("selected line color")).To<NSData>();
            if (!NSObject.IsNullOrNil(data))
                ms_selectedLineColor = NSUnarchiver.unarchiveObjectWithData(data).To<NSColor>().Retain();
            else
                ms_selectedLineColor = NSColor.yellowColor().Retain();

            ms_errorColor = NSColor.redColor().Retain();
        }
Пример #44
0
		static string ConvertColorToHex (NSColor color)
		{
			nfloat r, g, b, a;

			if (color.ColorSpaceName == NSColorSpace.DeviceWhite) {
				a = 1.0f;
				r = g = b = color.WhiteComponent;
			} else {
				color.GetRgba (out r, out g, out b, out a);
			}

			return String.Format ("#{0}{1}{2}",
				((int)(r * 255)).ToString ("x2"),
				((int)(g * 255)).ToString ("x2"),
				((int)(b * 255)).ToString ("x2")
			);
		}
 public ThreadedFile(string fullPath, string relativePath, NSColor color)
     : this()
 {
     FullPath = fullPath;
     RelativePath = relativePath;
     FileName = System.IO.Path.GetFileName(relativePath);
     Color = color;
 }
		public CustomCatTextAttachmentCell (NSImage image) : base (image)
		{
			borderColor = NSColor.FromDeviceHsba ((float)random.NextDouble (), 1f, 1f, 1f);
		}
Пример #47
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            // Set the slide's title
            TextManager.SetTitle ("Labs");

            // Add two labs
            var lab1TitleNode = Utils.SCBoxNode ("Scene Kit Lab", new CGRect (-375, -35, 750, 70), NSColor.FromCalibratedWhite (0.15f, 1.0f), 0.0f, false);
            lab1TitleNode.Scale = new SCNVector3 (0.02f, 0.02f, 0.02f);
            lab1TitleNode.Position = new SCNVector3 (-2.8f, 30.7f, 10.0f);
            lab1TitleNode.Rotation = new SCNVector4 (1, 0, 0, (float)(Math.PI));
            lab1TitleNode.Opacity = 0.0f;

            var lab2TitleNode = (SCNNode)lab1TitleNode.Copy ();
            lab2TitleNode.Position = new SCNVector3 (-2.8f, 29.2f, 10.0f);

            ContentNode.AddChildNode (lab1TitleNode);
            ContentNode.AddChildNode (lab2TitleNode);

            var lab1InfoNode = AddLabInfoNode ("\nGraphics and Games Lab A\nTuesday 4:00PM", 30.7f);
            var lab2InfoNode = AddLabInfoNode ("\nGraphics and Games Lab A\nWednesday 9:00AM", 29.2f);

            var delayInSeconds = 0.75;
            var popTime = new DispatchTime (DispatchTime.Now, (long)(delayInSeconds * Utils.NSEC_PER_SEC));
            DispatchQueue.MainQueue.DispatchAfter (popTime, () => {
                SCNTransaction.Begin ();
                SCNTransaction.AnimationDuration = 1;
                lab1TitleNode.Opacity = lab2TitleNode.Opacity = 1.0f;
                lab1TitleNode.Rotation = lab2TitleNode.Rotation = new SCNVector4 (1, 0, 0, 0);
                lab1InfoNode.Opacity = lab2InfoNode.Opacity = 1.0f;
                lab1InfoNode.Rotation = lab2InfoNode.Rotation = new SCNVector4 (0, 1, 0, 0);
                SCNTransaction.Commit ();
            });
        }