コード例 #1
0
        public ServerFastestSelectionButton(bool isSelected) : base()
        {
            const int    constButtonHeight = 61;
            const int    constImgHeight    = 24;
            const string title             = "Fastest server";

            Title = "";

            // flag icon
            var flagView = new NSImageView();

            flagView.Frame = new CGRect(20, (constButtonHeight - constImgHeight) / 2, constImgHeight, constImgHeight);
            flagView.Image = NSImage.ImageNamed("iconAutomaticServerSelection");
            AddSubview(flagView);

            // title
            __Title       = UIUtils.NewLabel(title);
            __Title.Frame = new CGRect(49, flagView.Frame.Y + 3, 200, 18);
            __Title.Font  = UIUtils.GetSystemFontOfSize(14.0f, NSFontWeight.Semibold);
            __Title.SizeToFit();
            AddSubview(__Title);

            // image
            __Image        = new NSImageView();
            __Image.Frame  = new CGRect(__Title.Frame.X + __Title.Frame.Width, flagView.Frame.Y, 25, 25);
            __Image.Image  = NSImage.ImageNamed("iconSelected");
            __Image.Hidden = true;
            AddSubview(__Image);

            IsSelected = isSelected;
        }
コード例 #2
0
ファイル: OptionPageMonobjc.cs プロジェクト: daviddw/Kinsky
        public OptionPageMonobjc(IOptionPage aOptionsPage, NSRect aFrameRect)
        {
            iName = aOptionsPage.Name;

            iView = new NSView(aFrameRect);

            iControls = new List <IOptionMonobjc>();

            float y   = iView.Frame.Height - 10;
            float mid = iView.Frame.Width * 0.5f;

            foreach (Option option in aOptionsPage.Options)
            {
                NSTextField label = new NSTextField();
                label.SetTitleWithMnemonic(new NSString(option.Name + ":"));
                label.IsSelectable    = false;
                label.IsEditable      = false;
                label.IsBordered      = false;
                label.DrawsBackground = false;
                label.Alignment       = NSTextAlignment.NSLeftTextAlignment;
                label.SizeToFit();
                label.Frame = new NSRect(10, y - label.Frame.Height, mid - 20, label.Frame.Height);

                iView.AddSubview(label);

                IOptionMonobjc o = null;

                if (option is OptionEnum || option is OptionNetworkInterface)
                {
                    o = new OptionNetworkInterfaceMonobjc(new NSRect(mid, y, mid - 10, 20), option);
                }
                else if (option is OptionFilePath)
                {
                    o = new OptionFilePathMonobjc(new NSRect(mid, y, mid - 10, 20), option);
                }
                else if (option is OptionFolderPath)
                {
                    o = new OptionFolderPathMonobjc(new NSRect(mid, y, mid - 10, 20), option);
                }
                else if (option is OptionBool)
                {
                    o = new OptionBoolMonobjc(new NSRect(mid, y, mid - 10, 20), option);
                }
                else if (option is OptionListFolderPath)
                {
                    o = new OptionListFolderPathMonobjc(new NSRect(mid, y, mid - 10, 20), option);
                }

                if (o != null)
                {
                    iView.AddSubview(o.View);
                    y -= o.Height;
                    iControls.Add(o);
                }
            }
        }
コード例 #3
0
ファイル: NumericUpDownHandler.cs プロジェクト: CheckTech/Eto
 protected override SizeF GetNaturalSize(SizeF availableSize)
 {
     if (naturalSize == null)
     {
         text.SizeToFit();
         stepper.SizeToFit();
         var naturalHeight = Math.Max(text.Frame.Height, stepper.Frame.Height);
         naturalSize = new Size(80, (int)naturalHeight);
     }
     return(naturalSize.Value);
 }
コード例 #4
0
        private void UpdatePingTimeText()
        {
            if (IsConfigMode)
            {
                return;
            }

            __PingView.StringValue = GetPingTimeString(ServerLocation.PingTime);
            __PingView.Hidden      = ServerLocation.PingTime == 0;
            __PingView.SizeToFit();
        }
コード例 #5
0
        public static NSTextField NewLabel(string text)
        {
            NSTextField textField = new NSTextField();

            textField.Editable        = false;
            textField.DrawsBackground = false;
            textField.StringValue     = text;
            textField.Bordered        = false;
            textField.SizeToFit();

            return(textField);
        }
コード例 #6
0
        public static NSTextField CreateLabel(string text)
        {
            var textField = new NSTextField();

            textField.StringValue     = text;
            textField.DrawsBackground = false;
            textField.Editable        = false;
            textField.Bezeled         = false;
            textField.Selectable      = false;
            textField.SizeToFit();
            textField.CenterTextVertically();
            return(textField);
        }
コード例 #7
0
        static NSTextField CreateLabel(string text)
        {
            var label = new NSTextField {
                StringValue     = text,
                DrawsBackground = false,
                Bordered        = false,
                Editable        = false,
                Selectable      = false,
            };

            label.SizeToFit();
            return(label);
        }
コード例 #8
0
ファイル: FileDialogs.cs プロジェクト: yongaru/fuse-studio
        void CreateFilters(FileFilter [] filters)
        {
            if (filters.Any())
            {
                var label     = new NSTextField();
                var fileTypes = new NSPopUpButton();
                fileTypes.AddItems(filters.Select(f => f.Label).ToArray());

                var fileTypeView = new NSView();
                fileTypeView.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable;
                const int padding = 15;

                label.StringValue     = "Show Files";
                label.DrawsBackground = false;
                label.Bordered        = false;
                label.Bezeled         = false;
                label.Editable        = false;
                label.Selectable      = false;
                label.SizeToFit();
                fileTypeView.AddSubview(label);

                fileTypes.SizeToFit();
                fileTypes.Activated += (sender, e) =>
                {
                    var currentFilter = filters.FirstOrDefault(f => f.Label == fileTypes.TitleOfSelectedItem);
                    SetCurrentItem(currentFilter);

                    // THIS DOES NOT WORK ON MAC OS FROM MAVERICS TO YOSEMITE
                    // There exists hacks, however they are dependent on OS X version
                    // I have filed bug as many others, but I guess this will never be fixed
                    _panel.ValidateVisibleColumns();
                    _panel.Update();
                };
                fileTypeView.AddSubview(fileTypes);
                fileTypes.SetFrameOrigin(new CGPoint(label.Frame.Width + 10, padding));

                label.SetFrameOrigin(new CGPoint(0, padding + (fileTypes.Frame.Height - label.Frame.Height) / 2));

                fileTypeView.Frame = new CGRect(0, 0, fileTypes.Frame.Width + label.Frame.Width + 10, fileTypes.Frame.Height + padding * 2);

                _panel.AccessoryView = fileTypeView;
                if (filters.Any())
                {
                    SetCurrentItem(filters.First());
                }
            }
            else
            {
                _panel.AccessoryView = null;
            }
        }
コード例 #9
0
ファイル: MacFileDialog.cs プロジェクト: zzlvff/Eto
        void Create()
        {
            if (Control.AccessoryView != null)
            {
                return;
            }

            var fileTypeView = new NSView();

            fileTypeView.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable;

            const int padding = 15;

            if (Widget.Filters.Count > 0)
            {
                var label = new NSTextField();
                label.StringValue     = "Format";
                label.DrawsBackground = false;
                label.Bordered        = false;
                label.Bezeled         = false;
                label.Editable        = false;
                label.Selectable      = false;
                label.SizeToFit();
                fileTypeView.AddSubview(label);

                fileTypes.SizeToFit();
                fileTypes.Activated += (sender, e) =>
                {
                    SetCurrentItem();
                    Control.ValidateVisibleColumns();
                    Control.Update();
                };
                fileTypeView.AddSubview(fileTypes);
                fileTypes.SetFrameOrigin(new CGPoint((nfloat)label.Frame.Width + 10, padding));

                label.SetFrameOrigin(new CGPoint(0, (nfloat)(padding + (fileTypes.Frame.Height - label.Frame.Height) / 2)));

                fileTypeView.Frame = new CGRect(0, 0, (nfloat)(fileTypes.Frame.Width + label.Frame.Width + 10), (nfloat)(fileTypes.Frame.Height + padding * 2));

                Control.AccessoryView = fileTypeView;
                SetCurrentItem();
            }
            else
            {
                Control.AccessoryView = null;
            }
        }
コード例 #10
0
ファイル: MacFileDialog.cs プロジェクト: pcdummy/Eto
        void Create()
        {
            if (Control.AccessoryView != null)
            {
                return;
            }

            var fileTypeView = new NSView();

            fileTypeView.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable;

            int padding = 15;

            if (macfilters != null && macfilters.Count > 0)
            {
                var label = new NSTextField();
                label.StringValue     = "Format";
                label.DrawsBackground = false;
                label.Bordered        = false;
                label.Bezeled         = false;
                label.Editable        = false;
                label.Selectable      = false;
                label.SizeToFit();
                fileTypeView.AddSubview(label);

                fileTypes.SizeToFit();
                fileTypes.Activated += (sender, e) => {
                    SetFilters();
                    Control.ValidateVisibleColumns();                     // SetFilters ();
                    Control.Update();
                };
                fileTypeView.AddSubview(fileTypes);
                fileTypes.SetFrameOrigin(new System.Drawing.PointF(label.Frame.Width + 10, padding));

                label.SetFrameOrigin(new System.Drawing.PointF(0, padding + (fileTypes.Frame.Height - label.Frame.Height) / 2));

                fileTypeView.Frame = new System.Drawing.RectangleF(0, 0, fileTypes.Frame.Width + label.Frame.Width + 10, fileTypes.Frame.Height + padding * 2);

                Control.AccessoryView = fileTypeView;
            }
            else
            {
                Control.AccessoryView = null;
            }
        }
コード例 #11
0
        public void SizeToFit()
        {
            stepper.SizeToFit();
            input.SizeToFit();

            var minHeight = (nfloat)Math.Max(stepper.Frame.Height, input.Frame.Height);
            var minWidth  = input.Frame.Width + stepper.Frame.Width;

            minWidth = (nfloat)Math.Max(minWidth, 55);
            var stepperX = minWidth - (stepper.Frame.Width);
            var stepperY = (minHeight - stepper.Frame.Height) / 2;
            var inputX   = 0;
            var inputY   = (minHeight - input.Frame.Height) / 2;

            SetFrameSize(new CGSize(minWidth, minHeight));
            stepper.Frame = new CGRect(stepperX, stepperY, stepper.Frame.Width, stepper.Frame.Height);
            input.Frame   = new CGRect(inputX, inputY, minWidth - (stepper.Frame.Width), input.Frame.Height);
        }
コード例 #12
0
ファイル: RadioStationCell.cs プロジェクト: xjpeter/gMusic
            public override void ResizeSubviewsWithOldSize(CoreGraphics.CGSize oldSize)
            {
                base.ResizeSubviewsWithOldSize(oldSize);
                var bounds = Bounds;
                var frame  = new CGRect(0, 0, bounds.Width, bounds.Width);

                ImageView.Frame = frame;
                var y      = frame.Bottom;
                var height = bounds.Height - y;

                Label.SizeToFit();

                frame       = Label.Frame;
                frame.X     = 0;
                frame.Y     = y + (height - frame.Height) / 2;
                frame.Width = bounds.Width;
                Label.Frame = frame;
            }
コード例 #13
0
            public override void ResizeSubviewsWithOldSize(CGSize oldSize)
            {
                base.ResizeSubviewsWithOldSize(oldSize);
                var bounds = Bounds;

                titleField.SizeToFit();
                var frame = titleField.Frame;

                frame.X = (bounds.Width - frame.Width) / 2;
                frame.Y = (bounds.Height - frame.Height) / 2;

                titleField.Frame = frame;

                backButton.SizeToFit();
                frame            = backButton.Frame;
                frame.X          = 10f;
                frame.Y          = (bounds.Height - frame.Height) / 2;
                backButton.Frame = frame;
            }
コード例 #14
0
        public override void ResizeSubviewsWithOldSize(CoreGraphics.CGSize oldSize)
        {
            base.ResizeSubviewsWithOldSize(oldSize);

            var bounds = Bounds;

            backgroudView.Frame = bounds;
            trackField.SizeToFit();
            var frame = trackField.Frame;

            frame.X          = padding;
            frame.Y          = (bounds.Height - frame.Height) / 2;
            trackField.Frame = frame;

            frame           = bounds;
            frame.X         = trackWidth + padding * 2;
            frame.Width    -= frame.X;
            textField.Frame = frame;
        }
コード例 #15
0
        void UpdateTitle()
        {
            if (_toolbar == null || _navigation == null || _titleGroup == null)
            {
                return;
            }

            var title      = GetCurrentPageTitle();
            var item       = new NSToolbarItem(title);
            var view       = new NSView();
            var titleField = new NSTextField
            {
                AllowsEditingTextAttributes = true,
                Bordered        = false,
                DrawsBackground = false,
                Bezeled         = false,
                Editable        = false,
                Selectable      = false,
                Cell            = new VerticallyCenteredTextFieldCell(0f, NSFont.TitleBarFontOfSize(18)),
                StringValue     = title
            };

            titleField.Cell.TextColor = GetTitleColor();
            titleField.SizeToFit();
            _titleGroup.Group.MinSize  = new CGSize(NavigationTitleMinSize, ToolbarHeight);
            _titleGroup.Group.Subitems = new NSToolbarItem[] { item };
            view.AddSubview(titleField);
            _titleGroup.Group.View = view;
            //save a reference so we can paint this for the background
            _nsToolbarItemViewer = _titleGroup.Group.View.Superview;
            if (_nsToolbarItemViewer == null)
            {
                return;
            }
            //position is hard .. we manually set the title to be centered
            var totalWidth = _nsToolbarItemViewer.Superview.Frame.Width;
            var fieldWidth = titleField.Frame.Width;
            var x          = ((totalWidth - fieldWidth) / 2) - _nsToolbarItemViewer.Frame.X;

            titleField.Frame = new CGRect(x, 0, fieldWidth, ToolbarHeight);
        }
コード例 #16
0
        void UpdateTitle()
        {
            if (_toolbar == null || _navigation == null || _titleGroup == null)
            {
                return;
            }

            var title      = GetCurrentPageTitle();
            var item       = new NSToolbarItem(title);
            var view       = new NSView();
            var titleField = new NSTextField
            {
                AllowsEditingTextAttributes = true,
                Bordered        = false,
                DrawsBackground = false,
                Bezeled         = false,
                Editable        = false,
                Selectable      = false,
                Cell            = new VerticallyCenteredTextFieldCell(0f, NSFont.TitleBarFontOfSize(18)),
                StringValue     = title
            };

            titleField.Cell.TextColor = GetTitleColor();
            titleField.SizeToFit();
            _titleGroup.Group.MinSize  = new CGSize(NavigationTitleMinSize, ToolbarHeight);
            _titleGroup.Group.Subitems = new NSToolbarItem[] { item };
            view.AddSubview(titleField);

            titleField.CenterXAnchor.ConstraintEqualToAnchor(view.CenterXAnchor).Active = true;
            titleField.CenterYAnchor.ConstraintEqualToAnchor(view.CenterYAnchor).Active = true;
            titleField.TranslatesAutoresizingMaskIntoConstraints = false;
            view.TranslatesAutoresizingMaskIntoConstraints       = false;

            _titleGroup.Group.View = view;
            //save a reference so we can paint this for the background
            _nsToolbarItemViewer = _titleGroup.Group.View.Superview;
        }
コード例 #17
0
        internal static NSView LabelControl(string label, float controlWidth, NSControl control)
        {
            var view = new NSView(new RectangleF(0, 0, controlWidth, 28))
            {
                AutoresizesSubviews = true,
                AutoresizingMask    = NSViewResizingMask.WidthSizable | NSViewResizingMask.MaxXMargin,
            };

            var text = new NSTextField(new RectangleF(0, 6, 100, 20))
            {
                StringValue     = label,
                DrawsBackground = false,
                Bordered        = false,
                Editable        = false,
                Selectable      = false
            };

            text.SizeToFit();
            float textWidth  = text.Frame.Width;
            float textHeight = text.Frame.Height;

            control.SizeToFit();
            var   rect          = control.Frame;
            float controlHeight = rect.Height;

            control.Frame = new RectangleF(textWidth + 5, 0, controlWidth, rect.Height);

            rect        = view.Frame;
            rect.Width  = control.Frame.Width + textWidth + 5;
            rect.Height = Math.Max(controlHeight, textHeight);
            view.Frame  = rect;

            view.AddSubview(text);
            view.AddSubview(control);

            return(view);
        }
コード例 #18
0
        public ServerSelectionButton(ServerLocation serverLocation) : base()
        {
            ServerLocation = serverLocation;

            const int constButtonHeight = 61;
            const int constFlagHeight   = 24;

            Bordered = false;
            Title    = "";
            Frame    = new CGRect(0, 0, 320, constButtonHeight);

            // flag icon
            var flagView = new NSImageView();

            flagView.Frame = new CGRect(20, (constButtonHeight - constFlagHeight) / 2, constFlagHeight, constFlagHeight);
            flagView.Image = GuiHelpers.CountryCodeToImage.GetCountryFlag(serverLocation.CountryCode);
            AddSubview(flagView);

            // server name
            __ServerName       = UIUtils.NewLabel(serverLocation.Name);
            __ServerName.Frame = new CGRect(49, flagView.Frame.Y + 1, 200, 18);
            __ServerName.Font  = UIUtils.GetSystemFontOfSize(14.0f, NSFontWeight.Semibold);
            __ServerName.SizeToFit();
            AddSubview(__ServerName);

            // check if server name is too long
            const int maxXforSelectedIcon    = 218;
            nfloat    serverNameOverlapWidth = (__ServerName.Frame.X + __ServerName.Frame.Width) - maxXforSelectedIcon;

            if (serverNameOverlapWidth > 0)
            {
                CGRect oldFrame = __ServerName.Frame;
                __ServerName.Frame = new CGRect(oldFrame.X, oldFrame.Y, oldFrame.Width - serverNameOverlapWidth, oldFrame.Height);
            }

            // selected server image
            __selectedServerImage        = new NSImageView();
            __selectedServerImage.Frame  = new CGRect(__ServerName.Frame.X + __ServerName.Frame.Width, flagView.Frame.Y - 2, 25, 25);
            __selectedServerImage.Image  = NSImage.ImageNamed("iconSelected");
            __selectedServerImage.Hidden = !ServerLocation.IsSelected;
            AddSubview(__selectedServerImage);

            // ping status image
            __pingStatusImage        = new NSImageView();
            __pingStatusImage.Frame  = new CGRect(238, flagView.Frame.Y, 24, 24);
            __pingStatusImage.Hidden = true;
            AddSubview(__pingStatusImage);
            UpdatePingStatusImage();

            // ping timeout info
            __PingView           = UIUtils.NewLabel(GetPingTimeString(ServerLocation.PingTime));
            __PingView.Alignment = NSTextAlignment.Left;
            __PingView.Font      = UIUtils.GetSystemFontOfSize(12.0f);
            __PingView.Frame     = new CGRect(260, flagView.Frame.Y + 4, 60, 18);
            __PingView.TextColor = NSColor.FromRgb(180, 193, 204);
            if (ServerLocation.PingTime == 0)
            {
                __PingView.Hidden = true;
            }
            __PingView.SizeToFit();
            AddSubview(__PingView);

            // "disabled layer" visible only if button is disabled
            __DisabledLayer       = new ColorView();
            __DisabledLayer.Frame = new CGRect(Frame.X, Frame.Y, Frame.Width, Frame.Height - 1);
            var bgClr = Colors.WindowBackground;

            __DisabledLayer.BackgroundColor = Colors.IsDarkMode ? new CGColor(bgClr.RedComponent, bgClr.GreenComponent, bgClr.BlueComponent, 0.6f) : new CGColor(1.0f, 0.6f);
            __DisabledLayer.Hidden          = true;
            AddSubview(__DisabledLayer);
        }
コード例 #19
0
		internal static NSView LabelControl (string label, float controlWidth, NSControl control)
		{
			var view = new NSView (new CGRect (0, 0, controlWidth, 28)) {
				AutoresizesSubviews = true,
				AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.MaxXMargin,
			};
			
			var text = new NSTextField (new CGRect (0, 6, 100, 20)) {
				StringValue = label,
				DrawsBackground = false,
				Bordered = false,
				Editable = false,
				Selectable = false
			};
			text.SizeToFit ();
			var textWidth = text.Frame.Width;
			var textHeight = text.Frame.Height;
			
			control.SizeToFit ();
			var rect = control.Frame;
			var controlHeight = rect.Height;
			control.Frame = new CGRect (textWidth + 5, 0, controlWidth, rect.Height);
			
			rect = view.Frame;
			rect.Width = control.Frame.Width + textWidth + 5;
			rect.Height = NMath.Max (controlHeight, textHeight);
			view.Frame = rect;
			
			view.AddSubview (text);
			view.AddSubview (control);
			
			return view;
		}
コード例 #20
0
        void AddNativeControls(NestedNativeControlGalleryPage page)
        {
            if (page.NativeControlsAdded)
            {
                return;
            }

            StackLayout sl = page.Layout;

            // Create and add a native UILabel
            var originalText = "I am a native UILabel";
            var longerText   =
                "I am a native UILabel with considerably more text. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";

            var uilabel = new NSTextField
            {
                StringValue          = originalText,
                MaximumNumberOfLines = 0,
                LineBreakMode        = NSLineBreakMode.ByWordWrapping,
                Font = NSFont.FromFontName("Helvetica", 24f)
            };

            sl?.Children.Add(uilabel);

            // Create and add a native Button
            var uibutton = NSButtonExtensions.CreateButton("Toggle Text Amount", () =>
            {
                uilabel.StringValue = uilabel.StringValue == originalText ? longerText : originalText;
                uilabel.SizeToFit();
            });

            uibutton.Font = NSFont.FromFontName("Helvetica", 14f);


            sl?.Children.Add(uibutton.ToView());

            // Create some control which we know don't behave correctly with regard to measurement
            var difficultControl0 = new BrokenNativeControl
            {
                Font = NSFont.FromFontName("Helvetica", 14f),
                MaximumNumberOfLines = 0,
                LineBreakMode        = NSLineBreakMode.ByWordWrapping,
                StringValue          = "Doesn't play nice with sizing. That's why there's a big gap around it."
            };

            var difficultControl1 = new BrokenNativeControl
            {
                Font = NSFont.FromFontName("Helvetica", 14f),
                MaximumNumberOfLines = 0,
                LineBreakMode        = NSLineBreakMode.ByWordWrapping,
                StringValue          = "Custom size fix specified. No gaps."
            };

            var explanation0 = new NSTextField
            {
                StringValue          = "The next control is a customized label with a bad SizeThatFits implementation.",
                MaximumNumberOfLines = 0,
                LineBreakMode        = NSLineBreakMode.ByWordWrapping,
                Font = NSFont.FromFontName("Helvetica", 14f),
            };

            var explanation1 = new NSTextField
            {
                StringValue          = "The next control is the same broken class as above, but we pass in an override to the GetDesiredSize method.",
                MaximumNumberOfLines = 0,
                LineBreakMode        = NSLineBreakMode.ByWordWrapping,
                Font = NSFont.FromFontName("Helvetica", 14f),
            };

            // Add a misbehaving control
            sl?.Children.Add(explanation0);
            sl?.Children.Add(difficultControl0);

            // Add the misbehaving control with a custom delegate for FixSize
            sl?.Children.Add(explanation1);
            sl?.Children.Add(difficultControl1, FixSize);

            page.NativeControlsAdded = true;
        }
コード例 #21
0
        public PlaybackBar(CGRect rect) : base(rect)
        {
            BackgroundColor     = NSColor.FromRgba(249, 249, 249, 255);
            AutoresizingMask    = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable;
            AddSubview(AlbumArt = new NSImageView(new CGRect(0, 0, 67, 67)));
            videoView           = new VideoView {
                WantsLayer = true, Hidden = true
            };

            videoView.MakeBackingLayer();

            AddSubview(previous = CreateButton("SVG/previous.svg", PlaybackManager.Shared.Previous));
            AddSubview(play     = CreateButton("SVG/playButtonBordered.svg", () => {
                if (playing)
                {
                    PlaybackManager.Shared.Pause();
                }
                else
                {
                    PlaybackManager.Shared.Play();
                }
            }));
            AddSubview(next     = CreateButton("SVG/next.svg", () => PlaybackManager.Shared.NextTrack()));
            AddSubview(textView = new TwoLabelView());

            AddSubview(progress = new ProgressView());

            AddSubview(shuffle = CreateButton("SVG/shuffle.svg", 25, PlaybackManager.Shared.ToggleRandom));
            AddSubview(repeat  = CreateButton("SVG/repeat.svg", 25, PlaybackManager.Shared.ToggleRepeat));

            AddSubview(time = new NSTextField {
                StringValue = "0000:00"
            }.StyleAsSubText());
            time.SizeToFit();

            AddSubview(remaining = new NSTextField {
                StringValue = "0000:00", Alignment = NSTextAlignment.Right
            }.StyleAsSubText());
            remaining.SizeToFit();

            AddSubview(volumeSlider = new NSSlider {
                DoubleValue = Settings.CurrentVolume, MinValue = 0, MaxValue = 1
            });
            volumeSlider.Activated += (object sender, EventArgs e) =>
            {
                Settings.CurrentVolume = (float)volumeSlider.DoubleValue;
            };
            volumeSlider.SizeToFit();

            AddSubview(thumbsDown = CreateButton("SVG/thumbsDown.svg", 30, async() =>
            {
                var song = MusicManager.Shared.GetCurrentSong();
                if (song.Rating != 1)
                {
                    await MusicManager.Shared.ThumbsDown(song);
                }
                else
                {
                    await MusicManager.Shared.Unrate(song);
                }
                SetThumbsState(song);
            }));

            AddSubview(thumbsUp = CreateButton("SVG/thumbsUp.svg", 30, async() =>
            {
                var song = MusicManager.Shared.GetCurrentSong();
                if (song.Rating != 5)
                {
                    await MusicManager.Shared.ThumbsUp(song);
                }
                else
                {
                    await MusicManager.Shared.Unrate(song);
                }
                SetThumbsState(song);
            }));

            Update(PlaybackManager.Shared.NativePlayer.CurrentSong);
            var dropShadow = new NSShadow {
                ShadowColor = NSColor.Black,
            };

            this.WantsLayer = true;
            this.Shadow     = dropShadow;
            NotificationManager.Shared.CurrentSongChanged   += (sender, e) => Update(e.Data);
            NotificationManager.Shared.PlaybackStateChanged += (sender, e) => SetState(e.Data);

            NotificationManager.Shared.CurrentTrackPositionChanged += (object sender, SimpleTables.EventArgs <TrackPosition> e) => {
                var data = e.Data;
                //timeLabel.Text = data.CurrentTimeString;
                //remainingTimeLabel.Text = data.RemainingTimeString;
                progress.Progress     = data.Percent;
                time.StringValue      = data.CurrentTimeString;
                remaining.StringValue = data.RemainingTimeString;
            };

            NotificationManager.Shared.ShuffleChanged     += (sender, args) => SetShuffleState(args.Data);
            NotificationManager.Shared.RepeatChanged      += (sender, args) => SetRepeatState(args.Data);
            NotificationManager.Shared.SongDownloadPulsed += (object sender, NotificationManager.SongDowloadEventArgs e) => {
                if (e.SongId != Settings.CurrentSong)
                {
                    return;
                }
                progress.DownloadProgress = e.Percent;
            };

//			NotificationManager.Shared.ToggleFullScreenVideo += (s, a) => ToggleFullScreenVideo();
            SetState(PlaybackState.Stopped);
            SetShuffleState(Settings.ShuffleSongs);
            SetRepeatState(Settings.RepeatMode);
        }
コード例 #22
0
		static NSTextField CreateLabel (string text)
		{
			var label = new NSTextField {
				StringValue = text,
				DrawsBackground = false,
				Bordered = false,
				Editable = false,
				Selectable = false,
			};
			label.SizeToFit ();
			return label;
		}