Esempio n. 1
0
        public override NSTouchBarItem MakeItem(NSTouchBar touchBar, string identifier)
        {
            NSCustomTouchBarItem item = new NSCustomTouchBarItem(identifier);

            switch (int.Parse(identifier))
            {
            case 0:
            {
                var img1 = Bitmap.FromResource(imgprefix + "icons8-save.png").ToNS(20);
                //var img2 = Bitmap.FromResource(imgprefix + "icons8-save_as.png").ToNS(20);
                seg1 = NSSegmentedControl.FromImages(new NSImage[] { img1 }, NSSegmentSwitchTracking.Momentary, () => { SegmentAction1(); });
                seg1.SegmentDistribution = NSSegmentDistribution.Fill;
                seg1.SetWidth(26, 0);
                //seg1.SetWidth(26, 1);
                seg1.SetTag(0, 0);
                //seg1.SetTag(1, 1);
                item.View = seg1;
                return(item);
            }

            case 1:
            {
                var img1 = Bitmap.FromResource(imgprefix + "icons8-thin_test_tube.png").ToNS(20);
                var img2 = Bitmap.FromResource(imgprefix + "icons8-math.png").ToNS(20);
                var img3 = Bitmap.FromResource(imgprefix + "icons8-sorting_options.png").ToNS(20);
                seg2 = NSSegmentedControl.FromImages(new NSImage[] { img1, img2, img3 }, NSSegmentSwitchTracking.Momentary, () => { SegmentAction2(); });
                seg2.SegmentDistribution = NSSegmentDistribution.Fill;
                seg2.SetWidth(26, 0);
                seg2.SetWidth(26, 1);
                seg2.SetWidth(26, 2);
                seg2.SetTag(2, 0);
                seg2.SetTag(3, 1);
                seg2.SetTag(4, 2);
                item.View = seg2;
                return(item);
            }

            case 2:
            {
                var img1 = Bitmap.FromResource(imgprefix + "icons8-play.png").ToNS(20);
                var img2 = Bitmap.FromResource(imgprefix + "Checked_96px.png").ToNS(20);
                seg3 = NSSegmentedControl.FromImages(new NSImage[] { img1, img2 }, NSSegmentSwitchTracking.Momentary, () => { SegmentAction3(); });
                seg3.SegmentDistribution = NSSegmentDistribution.Fill;
                seg3.SetWidth(26, 0);
                seg3.SetWidth(26, 1);
                seg3.SetTag(5, 0);
                seg3.SetTag(6, 1);
                item.View = seg3;
                return(item);
            }

            case 3:
            {
                var img1 = Bitmap.FromResource(imgprefix + "icons8-zoom_out_filled.png").ToNS(20);
                var img2 = Bitmap.FromResource(imgprefix + "icons8-zoom_in_filled.png").ToNS(20);
                var img3 = Bitmap.FromResource(imgprefix + "icons8-zoom_to_extents.png").ToNS(20);
                var img4 = Bitmap.FromResource(imgprefix + "icons8-zoom_to_actual_size_filled.png").ToNS(20);
                seg4 = NSSegmentedControl.FromImages(new NSImage[] { img1, img2, img3, img4 }, NSSegmentSwitchTracking.Momentary, () => { SegmentAction4(); });
                seg4.SegmentDistribution = NSSegmentDistribution.Fill;
                seg4.SetWidth(26, 0);
                seg4.SetWidth(26, 1);
                seg4.SetWidth(26, 2);
                seg4.SetWidth(26, 3);
                seg4.SetTag(7, 0);
                seg4.SetTag(8, 1);
                seg4.SetTag(9, 2);
                seg4.SetTag(10, 3);
                item.View = seg4;
                return(item);
            }

            case 4:
            {
                var img1 = Bitmap.FromResource(imgprefix + "icons8-grid.png").ToNS(20);
                var img2 = Bitmap.FromResource(imgprefix + "icons8-grid_filled.png").ToNS(20);
                seg5 = NSSegmentedControl.FromImages(new NSImage[] { img1, img2 }, NSSegmentSwitchTracking.Momentary, () => { SegmentAction5(); });
                seg5.SegmentDistribution = NSSegmentDistribution.Fill;
                seg5.SetWidth(26, 0);
                seg5.SetWidth(26, 1);
                seg5.SetTag(11, 0);
                seg5.SetTag(12, 1);
                item.View = seg5;
                return(item);
            }

            case 5:
            {
                var img1 = Bitmap.FromResource(imgprefix + "shape_group.png").ToNS(20);
                var img2 = Bitmap.FromResource(imgprefix + "shape_align_left.png").ToNS(20);
                var img3 = Bitmap.FromResource(imgprefix + "shape_align_center.png").ToNS(20);
                var img4 = Bitmap.FromResource(imgprefix + "shape_align_right.png").ToNS(20);
                var img5 = Bitmap.FromResource(imgprefix + "shape_align_top.png").ToNS(20);
                var img6 = Bitmap.FromResource(imgprefix + "shape_align_middle.png").ToNS(20);
                var img7 = Bitmap.FromResource(imgprefix + "shape_align_bottom.png").ToNS(20);
                var img8 = Bitmap.FromResource(imgprefix + "shape_align_center1.png").ToNS(20);
                var img9 = Bitmap.FromResource(imgprefix + "shape_align_middle1.png").ToNS(20);
                seg6 = NSSegmentedControl.FromImages(new NSImage[] { img1, img2, img3, img4, img5, img6, img7, img8, img9 }, NSSegmentSwitchTracking.Momentary, () => { SegmentAction6(); });
                seg6.SegmentDistribution = NSSegmentDistribution.Fill;
                seg6.SetWidth(26, 0);
                seg6.SetWidth(26, 1);
                seg6.SetWidth(26, 2);
                seg6.SetWidth(26, 3);
                seg6.SetWidth(26, 4);
                seg6.SetWidth(26, 5);
                seg6.SetWidth(26, 6);
                seg6.SetWidth(26, 7);
                seg6.SetWidth(26, 8);
                seg6.SetTag(13, 0);
                seg6.SetTag(14, 1);
                seg6.SetTag(15, 2);
                seg6.SetTag(16, 3);
                seg6.SetTag(17, 4);
                seg6.SetTag(18, 5);
                seg6.SetTag(19, 6);
                seg6.SetTag(20, 7);
                seg6.SetTag(21, 8);
                item.View = seg6;
                return(item);
            }
            }
            return(null);
        }
Esempio n. 2
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            #region first two buttons

            // add the image menu item back to the first menu item
            NSMenuItem menuItem = new NSMenuItem("", new Selector(""), "");

            menuItem.Image = NSImage.ImageNamed("moof.png");
            buttonMenu.InsertItem(menuItem, 0);

            nibBasedPopUpDown.Menu  = buttonMenu;
            nibBasedPopUpRight.Menu = buttonMenu;

            // create the pull down button pointing DOWN
            CGRect buttonFrame = placeHolder1.Frame;
            codeBasedPopUpDown = new NSPopUpButton(buttonFrame, true);

            ((NSPopUpButtonCell)codeBasedPopUpDown.Cell).ArrowPosition = NSPopUpArrowPosition.Bottom;
            ((NSPopUpButtonCell)codeBasedPopUpDown.Cell).BezelStyle    = NSBezelStyle.ThickSquare;
            codeBasedPopUpDown.Menu = buttonMenu;
            popupBox.AddSubview(codeBasedPopUpDown);
            placeHolder1.RemoveFromSuperview();

            // create the pull down button pointing RIGHT
            buttonFrame         = placeHolder2.Frame;
            codeBasedPopUpRight = new NSPopUpButton(buttonFrame, true);

            ((NSPopUpButtonCell)codeBasedPopUpRight.Cell).ArrowPosition = NSPopUpArrowPosition.Bottom;
            ((NSPopUpButtonCell)codeBasedPopUpRight.Cell).PreferredEdge = NSRectEdge.MaxXEdge;
            ((NSPopUpButtonCell)codeBasedPopUpRight.Cell).BezelStyle    = NSBezelStyle.Circular;
            codeBasedPopUpRight.Menu = buttonMenu;
            ((NSPopUpButtonCell)codeBasedPopUpRight.Cell).HighlightsBy = (nint)(int)NSCellStyleMask.ChangeGrayCell;
            popupBox.AddSubview(codeBasedPopUpRight);
            placeHolder2.RemoveFromSuperview();

            #endregion

            #region second two buttons

            // create the rounded button
            buttonFrame = placeHolder3.Frame;
            // note: this button we want alternate title and image, so we need to call this:
            codeBasedButtonRound = new NSButton(buttonFrame)
            {
                Title          = "NSButton",
                AlternateTitle = "(pressed)",
                Image          = NSImage.ImageNamed("moof.png"),
                AlternateImage = NSImage.ImageNamed("moof2.png"),
                BezelStyle     = NSBezelStyle.RegularSquare,
                ImagePosition  = NSCellImagePosition.ImageLeft,
                Font           = NSFont.SystemFontOfSize(NSFont.SmallSystemFontSize),
                Sound          = NSSound.FromName("Pop"),
            };
            // Two choices, either use the .NET event system:
            //    foo.Activated += delegate {..} or += SomeMethod
            //
            // Or you can use the Target = this Action = new Selector ("buttonAction:")
            // pattern
            codeBasedButtonRound.Activated += delegate {
                buttonAction(null);
            };
            codeBasedButtonRound.SetButtonType(NSButtonType.MomentaryChange);
            codeBasedButtonRound.Cell.Alignment = NSTextAlignment.Left;
            buttonBox.AddSubview(codeBasedButtonRound);
            placeHolder3.RemoveFromSuperview();                                 // we are done with the place holder, remove it from the window

            // create the square button
            buttonFrame           = placeHolder4.Frame;
            codeBasedButtonSquare = new NSButton(buttonFrame)
            {
                Title         = "NSButton",
                BezelStyle    = NSBezelStyle.ShadowlessSquare,
                ImagePosition = NSCellImagePosition.ImageLeft,
                Image         = NSImage.ImageNamed("moof.png"),
                Font          = NSFont.SystemFontOfSize(NSFont.SmallSystemFontSize),
                Sound         = NSSound.FromName("Pop"),
            };
            codeBasedButtonSquare.Activated     += delegate { buttonAction(null); };
            codeBasedButtonSquare.Cell.Alignment = NSTextAlignment.Left;
            buttonBox.AddSubview(codeBasedButtonSquare);
            placeHolder4.RemoveFromSuperview();                                 // we are done with the place holder, remove it from the window

            #endregion

            #region segmented control

            buttonFrame             = placeHolder5.Frame;
            codeBasedSegmentControl = new NSSegmentedControl(buttonFrame)
            {
                SegmentCount = 3,
                Target       = this,
                Action       = new Selector("segmentAction:")
            };

            codeBasedSegmentControl.SetWidth(nibBasedSegControl.GetWidth(0), 0);
            codeBasedSegmentControl.SetWidth(nibBasedSegControl.GetWidth(1), 1);
            codeBasedSegmentControl.SetWidth(nibBasedSegControl.GetWidth(2), 2);
            codeBasedSegmentControl.SetLabel("One", 0);
            codeBasedSegmentControl.SetLabel("Two", 1);
            codeBasedSegmentControl.SetLabel("Three", 2);
            segmentBox.AddSubview(codeBasedSegmentControl);
            placeHolder5.RemoveFromSuperview();

            // use a menu to the first segment (applied to both nib-based and code-based)
            codeBasedSegmentControl.SetMenu(buttonMenu, 0);
            nibBasedSegControl.SetMenu(buttonMenu, 0);

            // add icons to each segment (applied to both nib-based and code-based)
            NSImage segmentIcon1 = NSWorkspace.SharedWorkspace.IconForFileType(HFSTypeCode.ComputerIcon);
            segmentIcon1.Size = new CGSize(16, 16);
            nibBasedSegControl.SetImage(segmentIcon1, 0);
            codeBasedSegmentControl.SetImage(segmentIcon1, 0);

            NSImage segmentIcon2 = NSWorkspace.SharedWorkspace.IconForFileType(HFSTypeCode.DesktopIcon);
            segmentIcon2.Size = new CGSize(16, 16);
            nibBasedSegControl.SetImage(segmentIcon2, 1);
            codeBasedSegmentControl.SetImage(segmentIcon2, 1);

            NSImage segmentIcon3 = NSWorkspace.SharedWorkspace.IconForFileType(HFSTypeCode.FinderIcon);
            segmentIcon3.Size = new CGSize(16, 16);
            nibBasedSegControl.SetImage(segmentIcon3, 2);
            codeBasedSegmentControl.SetImage(segmentIcon3, 2);

            #endregion

            #region level indicator

            buttonFrame        = placeHolder8.Frame;
            codeBasedIndicator = new NSLevelIndicator(buttonFrame)
            {
                MaxValue           = 10,
                MajorTickMarkCount = 4,
                TickMarkCount      = 7,
                WarningValue       = 5,
                CriticalValue      = 8,
                Action             = new Selector("levelAction:")
            };
            codeBasedIndicator.Cell.LevelIndicatorStyle = NSLevelIndicatorStyle.DiscreteCapacity;
            indicatorBox.AddSubview(codeBasedIndicator);
            placeHolder8.RemoveFromSuperview();


            #endregion
        }
		public override void AwakeFromNib ()
		{
			base.AwakeFromNib ();
			
			#region first two buttons 
			
			// add the image menu item back to the first menu item
			NSMenuItem menuItem = new NSMenuItem ("", new Selector (""), "");
			
			menuItem.Image = NSImage.ImageNamed ("moof.png");
			buttonMenu.InsertItem (menuItem, 0);
			
			nibBasedPopUpDown.Menu = buttonMenu;
			nibBasedPopUpRight.Menu = buttonMenu;
		
			// create the pull down button pointing DOWN
			CGRect buttonFrame = placeHolder1.Frame;
			codeBasedPopUpDown = new NSPopUpButton (buttonFrame, true);
			
			((NSPopUpButtonCell)codeBasedPopUpDown.Cell).ArrowPosition = NSPopUpArrowPosition.Bottom;
			((NSPopUpButtonCell)codeBasedPopUpDown.Cell).BezelStyle = NSBezelStyle.ThickSquare;
			codeBasedPopUpDown.Menu = buttonMenu;
			popupBox.AddSubview (codeBasedPopUpDown);
			placeHolder1.RemoveFromSuperview ();
		
			// create the pull down button pointing RIGHT
			buttonFrame = placeHolder2.Frame;
			codeBasedPopUpRight = new NSPopUpButton (buttonFrame, true);
			
			((NSPopUpButtonCell)codeBasedPopUpRight.Cell).ArrowPosition = NSPopUpArrowPosition.Bottom;
			((NSPopUpButtonCell)codeBasedPopUpRight.Cell).PreferredEdge = NSRectEdge.MaxXEdge;
			((NSPopUpButtonCell)codeBasedPopUpRight.Cell).BezelStyle = NSBezelStyle.Circular;
			codeBasedPopUpRight.Menu = buttonMenu;
			((NSPopUpButtonCell)codeBasedPopUpRight.Cell).HighlightsBy = (nint)(int)NSCellStyleMask.ChangeGrayCell;
			popupBox.AddSubview (codeBasedPopUpRight);
			placeHolder2.RemoveFromSuperview ();

			#endregion
			
			#region second two buttons
			
			// create the rounded button
			buttonFrame = placeHolder3.Frame;
			// note: this button we want alternate title and image, so we need to call this:
			codeBasedButtonRound = new NSButton (buttonFrame) {
				Title = "NSButton",
				AlternateTitle = "(pressed)",
				Image = NSImage.ImageNamed ("moof.png"),
				AlternateImage = NSImage.ImageNamed ("moof2.png"),
				BezelStyle = NSBezelStyle.RegularSquare,
				ImagePosition = NSCellImagePosition.ImageLeft,
				Font = NSFont.SystemFontOfSize (NSFont.SmallSystemFontSize),
				Sound = NSSound.FromName ("Pop"),
			};
			// Two choices, either use the .NET event system:
			//    foo.Activated += delegate {..} or += SomeMethod
			//
			// Or you can use the Target = this Action = new Selector ("buttonAction:")
			// pattern
			codeBasedButtonRound.Activated += delegate {
				buttonAction (null);
			};
			codeBasedButtonRound.SetButtonType (NSButtonType.MomentaryChange);
			codeBasedButtonRound.Cell.Alignment = NSTextAlignment.Left;
			buttonBox.AddSubview (codeBasedButtonRound);
			placeHolder3.RemoveFromSuperview (); 			// we are done with the place holder, remove it from the window
			
			// create the square button
			buttonFrame = placeHolder4.Frame;
			codeBasedButtonSquare = new NSButton (buttonFrame){
				Title = "NSButton",
				BezelStyle = NSBezelStyle.ShadowlessSquare,
				ImagePosition = NSCellImagePosition.ImageLeft,
				Image = NSImage.ImageNamed ("moof.png"),
				Font = NSFont.SystemFontOfSize (NSFont.SmallSystemFontSize),
				Sound = NSSound.FromName ("Pop"),
			};
			codeBasedButtonSquare.Activated += delegate { buttonAction (null); };
			codeBasedButtonSquare.Cell.Alignment = NSTextAlignment.Left;
			buttonBox.AddSubview (codeBasedButtonSquare);
			placeHolder4.RemoveFromSuperview (); 			// we are done with the place holder, remove it from the window
			
			#endregion
			
			#region segmented control
			
			buttonFrame = placeHolder5.Frame;
			codeBasedSegmentControl = new NSSegmentedControl(buttonFrame) {
				SegmentCount = 3,
				Target = this,
				Action = new Selector("segmentAction:")
			};
					
			codeBasedSegmentControl.SetWidth (nibBasedSegControl.GetWidth(0), 0);
			codeBasedSegmentControl.SetWidth (nibBasedSegControl.GetWidth (1), 1);
			codeBasedSegmentControl.SetWidth (nibBasedSegControl.GetWidth (2), 2);
			codeBasedSegmentControl.SetLabel ("One", 0);
			codeBasedSegmentControl.SetLabel ("Two", 1);
			codeBasedSegmentControl.SetLabel ("Three", 2);
			segmentBox.AddSubview (codeBasedSegmentControl);
			placeHolder5.RemoveFromSuperview ();
	
			// use a menu to the first segment (applied to both nib-based and code-based)
			codeBasedSegmentControl.SetMenu (buttonMenu, 0);
			nibBasedSegControl.SetMenu (buttonMenu, 0);
			
			// add icons to each segment (applied to both nib-based and code-based)
			NSImage segmentIcon1 = NSWorkspace.SharedWorkspace.IconForFileType(NSFileTypeForHFSTypeCode.ComputerIcon);
			segmentIcon1.Size = new CGSize(16, 16);
			nibBasedSegControl.SetImage (segmentIcon1, 0);
			codeBasedSegmentControl.SetImage (segmentIcon1, 0);
			
			NSImage segmentIcon2 = NSWorkspace.SharedWorkspace.IconForFileType (NSFileTypeForHFSTypeCode.DesktopIcon);
			segmentIcon2.Size = new CGSize (16, 16);
			nibBasedSegControl.SetImage (segmentIcon2, 1);
			codeBasedSegmentControl.SetImage (segmentIcon2, 1);
			
			NSImage segmentIcon3 = NSWorkspace.SharedWorkspace.IconForFileType (NSFileTypeForHFSTypeCode.FinderIcon);
			segmentIcon3.Size = new CGSize (16, 16);
			nibBasedSegControl.SetImage (segmentIcon3, 2);
			codeBasedSegmentControl.SetImage (segmentIcon3, 2);
		
			#endregion
			
			#region level indicator
			
			buttonFrame = placeHolder8.Frame;
			codeBasedIndicator = new NSLevelIndicator(buttonFrame) {
				MaxValue = 10,
				MajorTickMarkCount = 4,
				TickMarkCount = 7,
				WarningValue = 5,
				CriticalValue = 8,
				Action = new Selector("levelAction:")
			};
			codeBasedIndicator.Cell.LevelIndicatorStyle = NSLevelIndicatorStyle.DiscreteCapacity;
			indicatorBox.AddSubview(codeBasedIndicator);
			placeHolder8.RemoveFromSuperview();
			
			
			#endregion
		}