コード例 #1
0
ファイル: SparkleSetup.cs プロジェクト: iurims/SparkleShare
        public SparkleDataSource(List<SparklePlugin> plugins)
        {
            Items = new List <object> ();
            Cells = new NSAttributedString [plugins.Count];

            int i = 0;
            foreach (SparklePlugin plugin in plugins) {
                Items.Add (plugin);

                NSTextFieldCell cell = new NSTextFieldCell ();
                NSData data          = NSData.FromString (
                    "<font face='Lucida Grande'><b>" + plugin.Name + "</b></font>");

                NSDictionary dictionary       = new NSDictionary();
                NSAttributedString attributes = new NSAttributedString (
                    data, new NSUrl ("file://"), out dictionary);

                NSMutableAttributedString mutable_attributes = new NSMutableAttributedString (attributes);
                mutable_attributes.Append (new NSAttributedString ("\n" + plugin.Description));

                cell.SetAttributedStringValue (mutable_attributes);

                Cells [i] = (NSAttributedString) cell.ObjectValue;
                i++;
            }
        }
コード例 #2
0
ファイル: HyperLink.cs プロジェクト: greenqloud/qloudsync
        public HyperLink(string pretext, string text, string postext, string address, string style)
            : base()
        {
            this.url = new NSUrl (address);

            AllowsEditingTextAttributes = true;
            Bordered        = false;
            DrawsBackground = false;
            Editable        = false;
            Selectable      = false;
            base.Font = NSFontManager.SharedFontManager.FontWithFamily (
                "Lucida Grande", NSFontTraitMask.Condensed, 0, 13);

            NSData name_data = NSData.FromString (pretext+"<a href='" + this.url +
                                                  "' "+style+" >" + text + "</a>"+postext);

            NSDictionary name_dictionary       = new NSDictionary();
            NSAttributedString name_attributes = new NSAttributedString (name_data, new NSUrl ("file://"), out name_dictionary);

            NSMutableAttributedString s = new NSMutableAttributedString ();
            s.Append (name_attributes);

            Cell.AttributedStringValue = s;

            SizeToFit ();
        }
コード例 #3
0
		public CTFramesetter (NSAttributedString value)
		{
			if (value == null)
				throw ConstructorError.ArgumentNull (this, "value");
			handle = CTFramesetterCreateWithAttributedString (value.Handle);
			if (handle == IntPtr.Zero)
				throw ConstructorError.Unknown (this);
		}
コード例 #4
0
 public static string GetTextRange(this NSTextView textView, NSRange range)
 {
     var data = textView.RtfFromRange(range);
     NSError error;
     NSDictionary dictionary;
     var attributedString = new NSAttributedString(data, new NSDictionary(), out dictionary, out error);
     return attributedString.Value;
 }
コード例 #5
0
ファイル: CTTypesetter.cs プロジェクト: jorik041/maccore
        public CTTypesetter(NSAttributedString value, CTTypesetterOptions options)
        {
            if (value == null)
                throw ConstructorError.ArgumentNull (this, "value");

            handle = CTTypesetterCreateWithAttributedStringAndOptions (value.Handle,
                    options == null ? IntPtr.Zero : options.Dictionary.Handle);

            if (handle == IntPtr.Zero)
                throw ConstructorError.Unknown (this);
        }
コード例 #6
0
		public void Append (NSAttributedString first, params object [] rest)
		{
			Append (first);
			foreach (var obj in rest){
				if (obj is NSAttributedString)
					Append ((NSAttributedString) obj);
				else if (obj is string)
					Append (new NSAttributedString ((string) obj));
				else
					Append (new NSAttributedString (obj.ToString ()));

			}
		}
コード例 #7
0
		public override NSCollectionViewItem NewItemForRepresentedObject (NSObject obj) {
			var item = base.NewItemForRepresentedObject (obj) as NoteCollectionViewItemController;
			item.RepresentedObject = obj;

			var dummyNote = obj as CocoaNoteAdapter;
			//item.ImageView.Image = dummyNote.Snapshot;
			item.TextField.StringValue = dummyNote.Title;
			NSDictionary attrDict;
			var attrString = new NSAttributedString (NSData.FromString (dummyNote.HtmlContent),
			                                         new NSUrl ("http://foo.com"),
			                                         out attrDict);
			item.ContentTextView.TextStorage.SetString (attrString);
			return item;
		}
コード例 #8
0
 public void Append(NSAttributedString first, params object [] rest)
 {
     Append(first);
     foreach (var obj in rest)
     {
         if (obj is NSAttributedString)
         {
             Append((NSAttributedString)obj);
         }
         else if (obj is string)
         {
             Append(new NSAttributedString((string)obj));
         }
         else
         {
             Append(new NSAttributedString(obj.ToString()));
         }
     }
 }
コード例 #9
0
ファイル: About.cs プロジェクト: Rud5G/SparkleShare
            public SparkleLink(string text, string address)
                : base()
            {
                this.url = new NSUrl (address);

                AllowsEditingTextAttributes = true;
                BackgroundColor = NSColor.White;
                Bordered        = false;
                DrawsBackground = false;
                Editable        = false;
                Selectable      = false;

                NSData name_data = NSData.FromString ("<a href='" + this.url +
                    "' style='font-size: 9pt; font-family: \"Helvetica Neue\"; color: #739ECF'>" + text + "</a></font>");

                NSDictionary name_dictionary       = new NSDictionary();
                NSAttributedString name_attributes = new NSAttributedString (name_data, new NSUrl ("file://"), out name_dictionary);

                NSMutableAttributedString s = new NSMutableAttributedString ();
                s.Append (name_attributes);

                Cell.AttributedStringValue = s;
                SizeToFit ();
            }
コード例 #10
0
        /// <summary>
        /// Measures the text.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <returns>
        /// The size of the text.
        /// </returns>
        public override OxySize MeasureText(string text, string fontFamily, double fontSize, double fontWeight)
        {
            if (string.IsNullOrEmpty (text) || fontFamily == null) {
                return OxySize.Empty;
            }

            var fontName = GetActualFontName (fontFamily, fontWeight);
            var font = this.GetCachedFont (fontName, (float)fontSize);
            using (var attributedString = new NSAttributedString (text, new CTStringAttributes {
                ForegroundColorFromContext = true,
                Font = font
            })) {
                using (var textLine = new CTLine (attributedString)) {
                    float lineHeight, delta;
                    this.GetFontMetrics (font, out lineHeight, out delta);

                    // the text position must be set to get the correct bounds
                    this.gctx.TextPosition = new PointF (0, 0);

                    var bounds = textLine.GetImageBounds (this.gctx);
                    var width = bounds.Left + bounds.Width;

                    return new OxySize (width, lineHeight);
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="p">The position of the text.</param>
        /// <param name="text">The text.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <param name="rotate">The rotation angle.</param>
        /// <param name="halign">The horizontal alignment.</param>
        /// <param name="valign">The vertical alignment.</param>
        /// <param name="maxSize">The maximum size of the text.</param>
        public override void DrawText(ScreenPoint p, string text, OxyColor fill, string fontFamily, double fontSize, double fontWeight, double rotate, HorizontalAlignment halign, VerticalAlignment valign, OxySize? maxSize)
        {
            if (string.IsNullOrEmpty (text)) {
                return;
            }

            var fontName = GetActualFontName (fontFamily, fontWeight);

            var font = this.GetCachedFont (fontName, fontSize);
            using (var attributedString = new NSAttributedString (text, new CTStringAttributes {
                ForegroundColorFromContext = true,
                Font = font
            })) {
                using (var textLine = new CTLine (attributedString)) {
                    float width;
                    float height;

                    this.gctx.TextPosition = new PointF (0, 0);

                    float lineHeight, delta;
                    this.GetFontMetrics (font, out lineHeight, out delta);

                    var bounds = textLine.GetImageBounds (this.gctx);

                    var x0 = 0;
                    var y0 = delta;

                    if (maxSize.HasValue || halign != HorizontalAlignment.Left || valign != VerticalAlignment.Bottom) {
                        width = bounds.Left + bounds.Width;
                        height = lineHeight;
                    } else {
                        width = height = 0f;
                    }

                    if (maxSize.HasValue) {
                        if (width > maxSize.Value.Width) {
                            width = (float)maxSize.Value.Width;
                        }

                        if (height > maxSize.Value.Height) {
                            height = (float)maxSize.Value.Height;
                        }
                    }

                    var dx = halign == HorizontalAlignment.Left ? 0d : (halign == HorizontalAlignment.Center ? -width * 0.5 : -width);
                    var dy = valign == VerticalAlignment.Bottom ? 0d : (valign == VerticalAlignment.Middle ? height * 0.5 : height);

                    this.SetFill (fill);
                    this.SetAlias (false);

                    this.gctx.SaveState ();
                    this.gctx.TranslateCTM ((float)p.X, (float)p.Y);
                    if (!rotate.Equals (0)) {
                        this.gctx.RotateCTM ((float)(rotate / 180 * Math.PI));
                    }

                    this.gctx.TranslateCTM ((float)dx + x0, (float)dy + y0);
                    this.gctx.ScaleCTM (1f, -1f);

                    if (maxSize.HasValue) {
                        var clipRect = new RectangleF (-x0, y0, (float)Math.Ceiling (width), (float)Math.Ceiling (height));
                        this.gctx.ClipToRect (clipRect);
                    }

                    textLine.Draw (this.gctx);

                    this.gctx.RestoreState ();
                }
            }
        }
コード例 #12
0
        public override void DrawRect(RectangleF dirtyRect)
        {
            var window = ((AppStoreWindow)Window);
            var drawsAsMainWindow = window.DrawsAsMainWindow();
            // Start by filling the title bar area with black in fullscreen mode to match native apps
            // Custom title bar drawing blocks can simply override this by not applying the clipping path
            if (window.IsFullScreen())
            {
                NSColor.Black.SetFill();
                NSBezierPath.FromRect(Bounds).Fill();
            }

            CGPath clippingPath;
            var drawingRect = Bounds;

            if (window.TitleBarDrawingCallbackAction != null)
            {
                clippingPath = DrawingHelper.CreateClippingPath(drawingRect, CORNER_CLIP_RADIUS);
                window.TitleBarDrawingCallbackAction(drawsAsMainWindow, drawingRect, clippingPath);
            }
            else
            {
                // There's a thin whitish line between the darker gray window border line
                // and the gray noise textured gradient; preserve that when drawing a native title bar
                var clippingRect = drawingRect;
                clippingRect.Height -= 1;
                clippingPath = DrawingHelper.CreateClippingPath(clippingRect, CORNER_CLIP_RADIUS);

                DrawWindowBackgroundGradient(drawingRect, clippingPath);
            }

            if (window.ShowsTitle && ((window.StyleMask & NSWindowStyle.FullScreenWindow) == 0 || window.ShowsTitleInFullscreen))
            {
                NSDictionary dictionary;
                var titleTextRect = GetTitleFrame(out dictionary, window);

                if (window.VerticallyCenterTitle)
                {
                    titleTextRect.Y = (float)Math.Floor(drawingRect.GetMidY() - titleTextRect.Height / 2f + 1);
                }

                var title = new NSAttributedString(window.Title, dictionary);
                title.DrawString(titleTextRect);
            }
        }
コード例 #13
0
        private void LoadFontsAndImages()
        {
            trackBufferSize.Theme.BackgroundColor = GlobalTheme.SettingsGenericBackgroundColor;
            trackMaximumPeakFolderSize.Theme.BackgroundColor = GlobalTheme.SettingsGenericBackgroundColor;
            trackOutputMeter.Theme.BackgroundColor = GlobalTheme.SettingsGenericBackgroundColor;
            trackSongPosition.Theme.BackgroundColor = GlobalTheme.SettingsGenericBackgroundColor;
            trackUpdatePeriod.Theme.BackgroundColor = GlobalTheme.SettingsGenericBackgroundColor;

            viewGeneralPreferencesHeader.BackgroundColor1 = GlobalTheme.SettingsHeaderColor;
            viewGeneralPreferencesHeader.BackgroundColor2 = GlobalTheme.SettingsHeaderColor;
            viewAudioPreferencesHeader.BackgroundColor1 = GlobalTheme.SettingsHeaderColor;
            viewAudioPreferencesHeader.BackgroundColor2 = GlobalTheme.SettingsHeaderColor;
            viewLibraryPreferencesHeader.BackgroundColor1 = GlobalTheme.SettingsHeaderColor;
            viewLibraryPreferencesHeader.BackgroundColor2 = GlobalTheme.SettingsHeaderColor;
            viewCloudPreferencesHeader.BackgroundColor1 = GlobalTheme.SettingsHeaderColor;
            viewCloudPreferencesHeader.BackgroundColor2 = GlobalTheme.SettingsHeaderColor;

            viewGeneralPreferences.BackgroundColor1 = GlobalTheme.SettingsBackgroundColor;
            viewGeneralPreferences.BackgroundColor2 = GlobalTheme.SettingsBackgroundColor;
            viewAudioPreferences.BackgroundColor1 = GlobalTheme.SettingsBackgroundColor;
            viewAudioPreferences.BackgroundColor2 = GlobalTheme.SettingsBackgroundColor;
            viewLibraryPreferences.BackgroundColor1 = GlobalTheme.SettingsBackgroundColor;
            viewLibraryPreferences.BackgroundColor2 = GlobalTheme.SettingsBackgroundColor;
            viewCloudPreferences.BackgroundColor1 = GlobalTheme.SettingsBackgroundColor;
            viewCloudPreferences.BackgroundColor2 = GlobalTheme.SettingsBackgroundColor;

            viewOutputHeader.BackgroundColor1 = GlobalTheme.SettingsHeader2Color;
            viewOutputHeader.BackgroundColor2 = GlobalTheme.SettingsHeader2Color;
            viewMixerHeader.BackgroundColor1 = GlobalTheme.SettingsHeader2Color;
            viewMixerHeader.BackgroundColor2 = GlobalTheme.SettingsHeader2Color;
            viewStatusHeader.BackgroundColor1 = GlobalTheme.SettingsHeader2Color;
            viewStatusHeader.BackgroundColor2 = GlobalTheme.SettingsHeader2Color;
            viewDropboxHeader.BackgroundColor1 = GlobalTheme.SettingsHeader2Color;
            viewDropboxHeader.BackgroundColor2 = GlobalTheme.SettingsHeader2Color;
            viewUpdateFrequencyHeader.BackgroundColor1 = GlobalTheme.SettingsHeader2Color;
            viewUpdateFrequencyHeader.BackgroundColor2 = GlobalTheme.SettingsHeader2Color;
            viewFoldersHeader.BackgroundColor1 = GlobalTheme.SettingsHeader2Color;
            viewFoldersHeader.BackgroundColor2 = GlobalTheme.SettingsHeader2Color;
            viewPeakFilesHeader.BackgroundColor1 = GlobalTheme.SettingsHeader2Color;
            viewPeakFilesHeader.BackgroundColor2 = GlobalTheme.SettingsHeader2Color;
            viewPeakFileDeletionHeader.BackgroundColor1 = GlobalTheme.SettingsHeader2Color;
            viewPeakFileDeletionHeader.BackgroundColor2 = GlobalTheme.SettingsHeader2Color;
            viewLibraryServiceHeader.BackgroundColor1 = GlobalTheme.SettingsHeader2Color;
            viewLibraryServiceHeader.BackgroundColor2 = GlobalTheme.SettingsHeader2Color;

            var headerFont = NSFont.FromFontName("Roboto Light", 16f);
            lblGeneralPreferences.Font = headerFont;
            lblAudioPreferences.Font = headerFont;
            lblLibraryPreferences.Font = headerFont;
            lblCloudPreferences.Font = headerFont;

            var subtitleFont = NSFont.FromFontName("Roboto Light", 13f);
            var subtitleColor = NSColor.FromDeviceRgba(0, 0, 0, 1);
            lblGeneralUpdateFrequency.Font = subtitleFont;
            lblGeneralPeakFiles.Font = subtitleFont;
            lblGeneralPeakFileDeletion.Font = subtitleFont;
            lblAudioOutput.Font = subtitleFont;
            lblAudioMixer.Font = subtitleFont;
            lblAudioStatus.Font = subtitleFont;
            lblLibraryFolders.Font = subtitleFont;
            lblCloudDropbox.Font = subtitleFont;
            lblLibraryService.Font = subtitleFont;
            lblEnableLibraryService.Font = subtitleFont;
            lblEnableLibraryService.TextColor = subtitleColor;
            lblEnableResumePlayback.Font = subtitleFont;
            lblEnableResumePlayback.TextColor = subtitleColor;

            var textFont = NSFont.FromFontName("Roboto", 12f);
            var textColor = NSColor.FromDeviceRgba(0, 0, 0, 1);
            lblOutputDevice.Font = textFont;
            lblOutputDevice.TextColor = textColor;
            lblSampleRate.Font = textFont;
            lblSampleRate.TextColor = textColor;
            lblUpdatePeriod.Font = textFont;
            lblUpdatePeriod.TextColor = textColor;
            lblSongPosition.Font = textFont;
            lblSongPosition.TextColor = textColor;
            lblOutputMeter.Font = textFont;
            lblOutputMeter.TextColor = textColor;
            lblBufferSize.Font = textFont;
            lblBufferSize.TextColor = textColor;
            lblMaximumPeakFolderSize.Font = textFont;
            lblMaximumPeakFolderSize.TextColor = textColor;
            lblEvery.Font = textFont;
            lblEvery.TextColor = textColor;
            lblEvery2.Font = textFont;
            lblEvery2.TextColor = textColor;
            lblEvery3.Font = textFont;
            lblEvery3.TextColor = textColor;
            lblEvery4.Font = textFont;
            lblEvery4.TextColor = textColor;
            lblMB.Font = textFont;
            lblMB.TextColor = textColor;
            lblMS.Font = textFont;
            lblMS.TextColor = textColor;
            lblMS2.Font = textFont;
            lblMS2.TextColor = textColor;
            lblMS3.Font = textFont;
            lblMS3.TextColor = textColor;
            lblMS4.Font = textFont;
            lblMS4.TextColor = textColor;
            lblMS.Font = textFont;
            lblMS.TextColor = textColor;
            lblHttpPort.Font = textFont;
            lblHttpPort.TextColor = textColor;

            var noteFont = NSFont.FromFontName("Roboto", 11f);
            var noteColor = NSColor.FromDeviceRgba(0.7f, 0.7f, 0.7f, 1);
            lblResumePlaybackNote.Font = noteFont;
            lblResumePlaybackNote.TextColor = noteColor;           
            lblPeakFileFolderSize.Font = noteFont;
            lblPeakFileFolderSize.TextColor = noteColor;           
            lblLibrarySize.Font = noteFont;
            lblLibrarySize.TextColor = noteColor;           
            lblLibraryServiceNote.Font = noteFont;
            lblLibraryServiceNote.TextColor = noteColor;   
            lblUpdateFrequencyWarning.Font = noteFont;
            lblUpdateFrequencyWarning.TextColor = noteColor;
            lblMixerNote.Font = noteFont;
            lblMixerNote.TextColor = noteColor;

            var valueFont = NSFont.FromFontName("Roboto", 12f);
            var valueColor = NSColor.FromDeviceRgba(0.05f, 0.05f, 0.05f, 1);
            lblBufferSizeValue.Font = valueFont;
            lblBufferSizeValue.TextColor = valueColor;
            lblUpdatePeriodValue.Font = valueFont;
            lblUpdatePeriodValue.TextColor = valueColor;
            lblSongPositionValue.Font = valueFont;
            lblSongPositionValue.TextColor = valueColor;
            lblOutputMeterValue.Font = valueFont;
            lblOutputMeterValue.TextColor = valueColor;
            lblMaximumPeakFolderSizeValue.Font = valueFont;
            lblMaximumPeakFolderSizeValue.TextColor = valueColor;
//            lblMaximumPeakFolderSize.Font = valueFont;
//            lblOutputMeterValue.TextColor = valueColor;

            txtCustomDirectory.Font = NSFont.FromFontName("Roboto", 11f);
            txtHttpPort.Font = NSFont.FromFontName("Roboto", 12f);

            // The NSButton checkbox type doesn't let you change the color, so use an attributed string instead
//            var dictAttrStr1 = new NSMutableDictionary();
//            dictAttrStr1.Add(NSAttributedString.ForegroundColorAttributeName, NSColor.White);
//            dictAttrStr1.Add(NSAttributedString.FontAttributeName, NSFont.FromFontName("Roboto", 12));
//            var attrStrEnableResumePlayback = new NSAttributedString("Enable Resume Playback with Dropbox", dictAttrStr1);
//            checkEnableResumePlayback.AttributedTitle = attrStrEnableResumePlayback;

            // The NSButton checkbox type doesn't let you change the color, so use an attributed string instead
            //var attrStrEnableLibraryService = new NSAttributedString("Enable Library Service", dictAttrStr1);
            //checkEnableLibraryService.AttributedTitle = attrStrEnableLibraryService;

            // NSMatrix doesn't allow changing text color, so use an attributed string instead
            var dictAttrStr2 = new NSMutableDictionary();
            dictAttrStr2.Add(NSAttributedString.ForegroundColorAttributeName, NSColor.FromDeviceRgba(0f, 0f, 0f, 1));
            dictAttrStr2.Add(NSAttributedString.FontAttributeName, NSFont.FromFontName("Roboto", 12));
            var radioStr1 = new NSAttributedString(string.Format("Use default directory ({0})", PathHelper.PeakFileDirectory), dictAttrStr2);
            var radioStr2 = new NSAttributedString("Use custom directory:", dictAttrStr2);
            var firstCell = matrixPeakFiles.Cells[0] as NSButtonCell;
            var secondCell = matrixPeakFiles.Cells[1] as NSButtonCell;
            firstCell.AttributedTitle = radioStr1;
            secondCell.AttributedTitle = radioStr2;

            btnTabGeneral.LineLocation = SessionsTabButton.LineLocationEnum.Top;
            btnTabGeneral.ShowSelectedBackgroundColor = true;
            btnTabGeneral.BackgroundColor = GlobalTheme.SettingsTabColor;
            btnTabGeneral.BackgroundMouseDownColor = GlobalTheme.SettingsTabOverColor;
            btnTabGeneral.BackgroundMouseOverColor = GlobalTheme.SettingsTabOverColor;
            btnTabGeneral.BackgroundSelectedColor = GlobalTheme.SettingsTabSelectedColor;
            btnTabAudio.LineLocation = SessionsTabButton.LineLocationEnum.Top;
            btnTabAudio.ShowSelectedBackgroundColor = true;
            btnTabAudio.BackgroundColor = GlobalTheme.SettingsTabColor;
            btnTabAudio.BackgroundMouseDownColor = GlobalTheme.SettingsTabOverColor;
            btnTabAudio.BackgroundMouseOverColor = GlobalTheme.SettingsTabOverColor;
            btnTabAudio.BackgroundSelectedColor = GlobalTheme.SettingsTabSelectedColor;
            btnTabLibrary.LineLocation = SessionsTabButton.LineLocationEnum.Top;
            btnTabLibrary.ShowSelectedBackgroundColor = true;
            btnTabLibrary.BackgroundColor = GlobalTheme.SettingsTabColor;
            btnTabLibrary.BackgroundMouseDownColor = GlobalTheme.SettingsTabOverColor;
            btnTabLibrary.BackgroundMouseOverColor = GlobalTheme.SettingsTabOverColor;
            btnTabLibrary.BackgroundSelectedColor = GlobalTheme.SettingsTabSelectedColor;
            btnTabCloud.LineLocation = SessionsTabButton.LineLocationEnum.Top;
            btnTabCloud.ShowSelectedBackgroundColor = true;
            btnTabCloud.BackgroundColor = GlobalTheme.SettingsTabColor;
            btnTabCloud.BackgroundMouseDownColor = GlobalTheme.SettingsTabOverColor;
            btnTabCloud.BackgroundMouseOverColor = GlobalTheme.SettingsTabOverColor;
            btnTabCloud.BackgroundSelectedColor = GlobalTheme.SettingsTabSelectedColor;

            btnTabGeneral.Image = ImageResources.Images.FirstOrDefault(x => x.Name == "icon_button_general");
            btnTabAudio.Image = ImageResources.Images.FirstOrDefault(x => x.Name == "icon_button_speaker");
            btnTabLibrary.Image = ImageResources.Images.FirstOrDefault(x => x.Name == "icon_button_library");
            btnTabCloud.Image = ImageResources.Images.FirstOrDefault(x => x.Name == "icon_button_cloud");

            btnAddFolder.Image = ImageResources.Images.FirstOrDefault(x => x.Name == "icon_button_add");
            btnRemoveFolder.Image = ImageResources.Images.FirstOrDefault(x => x.Name == "icon_button_delete");
            btnResetLibrary.Image = ImageResources.Images.FirstOrDefault(x => x.Name == "icon_button_reset");
            btnUpdateLibrary.Image = ImageResources.Images.FirstOrDefault(x => x.Name == "icon_button_refresh");
            btnResetAudioSettings.Image = ImageResources.Images.FirstOrDefault(x => x.Name == "icon_button_reset");
            btnLoginDropbox.Image = ImageResources.Images.FirstOrDefault(x => x.Name == "icon_button_dropbox");
            btnBrowseCustomDirectory.Image = ImageResources.Images.FirstOrDefault(x => x.Name == "icon_button_open");
            btnDeletePeakFiles.Image = ImageResources.Images.FirstOrDefault(x => x.Name == "icon_button_delete");
        }   
コード例 #14
0
        public void CreateMenu ()
        {
            lock (menuLock) {
                this.recentChanges.Clear ();

                using (NSAutoreleasePool a = new NSAutoreleasePool ()) {
                    this.menu = new NSMenu ();
                    this.menu.AutoEnablesItems = false;

                    this.state_item = new NSMenuItem () {
                        Title = StateText,
                        Enabled = true
                    };

                    this.folder_item = new NSMenuItem () {
                        Title = GlobalSettings.HomeFolderName+" Folder"
                    };

                    this.folder_item.Activated += delegate {
                        StorageFolderClicked ();
                    };

                    this.folder_item.Image = this.sparkleshare_image;
                    this.folder_item.Image.Size = new SizeF (16, 16);
                    this.folder_item.Enabled = true;

                    this.preferences_item = new NSMenuItem () {
                        Title   = "Preferences",
                        Enabled = true
                    };

                    this.preferences_item.Activated += delegate {
                        if (PreferenceController == null) {
                            PreferenceController = new PreferenceWindowController ();
                            PreferenceController.Window.WillClose += delegate {
                                PreferenceController = null;
                            };
                        } else {
                            PreferenceController.Window.OrderFrontRegardless ();
                        }
                    };

                    this.recent_events_title = new NSMenuItem () {
                        Title   = "Recently Changed",
                        Enabled =  false
                    };       

                    this.about_item = new NSMenuItem () {
                        Title   = string.Format("About {0}", GlobalSettings.ApplicationName),
                        Enabled = true
                    };

                    this.openweb_item = new NSMenuItem () {
                        Title = "Share/View Online",
                        Enabled = true
                    };

                    this.openweb_item.Image = this.share_image;
                    this.openweb_item.Image.Size = new SizeF (16, 16);
                    this.openweb_item.Enabled = true;

                    this.openweb_item.Activated += delegate {                    
                        Program.Controller.OpenStorageQloudWebSite ();
                    };

                    this.about_item.Activated += delegate {
                        AboutClicked ();
                    };

                    this.pause_sync = new NSMenuItem () {
                        Title = PauseText(),
                        Enabled = true
                    };

                    this.pause_sync.Activated += delegate {
                        PauseSync ();
                    };

                    this.quit_item = new NSMenuItem () {
                        Title   = "Quit",
                        Enabled = QuitItemEnabled
                    };

                    this.quit_item.Activated += delegate {
                        QuitClicked ();
                    };



                    co2_savings_item = new NSMenuItem () {
                        Title = "",
                        Enabled = true,
                        Hidden = true
                    };

                    if (co2Update == null) {
                        co2Update = new Thread (delegate() {
                            while (true) {
                                try {
                                    string spent = Statistics.TotalUsedSpace.Spent;
                                    string saved = Statistics.EarlyCO2Savings.Saved;
                                    string subscript = "2";
                                    subscript.ToLowerInvariant ();

                                    using (var ns = new NSAutoreleasePool ()) {
                                        NSRunLoop.Main.BeginInvokeOnMainThread (() => { 
                                            if (spent != null && saved != null) {
                                                co2_savings_item.Title = spent + " used | " + saved + " CO₂ saved";
                                                co2_savings_item.Hidden = false;
                                            }
                                        });
                                    }
                                } catch (Exception e) {
                                    Logger.LogInfo("ERROR ON LOAD CO₂ SAVINGS", e);
                                }
                                Thread.Sleep (600000);
                            }
                        });
                        co2Update.Start ();
                    }

                    help_item = new NSMenuItem () {
                        Title = "Help Center"
                    };

                    help_item.Activated += delegate {
                        Program.Controller.OpenWebsite ("http://support.greenqloud.com");
                    };

               
                    bool renderLoggedIn = Credential.Username != "";
                    if (renderLoggedIn) {
                        this.menu.AddItem (this.state_item);
                        this.menu.AddItem (NSMenuItem.SeparatorItem);
                        this.menu.AddItem (co2_savings_item);
                        this.menu.AddItem (this.folder_item);
                        this.menu.AddItem (this.openweb_item);  
                        this.menu.AddItem (NSMenuItem.SeparatorItem);
                        this.menu.AddItem (this.recent_events_title);
                        this.menu.AddItem (NSMenuItem.SeparatorItem);
                

                        if (Program.Controller.DatabaseLoaded ()) {
                            SQLiteEventDAO eventDao = new SQLiteEventDAO ();
                            List<Event> events = eventDao.LastEvents;
                            string text = "";

                            foreach (Event e in events) {

                                NSMenuItem current = new NSMenuItem () {
                                    Title = e.ItemName,
                                    Enabled = true
                                };


                                current.Image = this.default_image;
                                if (e.ItemType == ItemType.IMAGE)
                                    current.Image = this.pics_image;
                                if (e.ItemType == ItemType.TEXT)
                                    current.Image = this.docs_image;
                                if (e.ItemType == ItemType.VIDEO)
                                    current.Image = this.movies_image;
                                if (e.ItemType == ItemType.AUDIO)
                                    current.Image = this.music_image;

                                current.ToolTip = e.ToString ();

                                EventHandler evt = new EventHandler (
                                    delegate {
                                    NSRunLoop.Main.BeginInvokeOnMainThread (() => RecentChangeItemClicked (e, null));
                                }
                                );
                                current.Activated += evt;

                                string title = "   " + e.ItemUpdatedAt;
                                NSAttributedString att = new NSAttributedString (title, NSFontManager.SharedFontManager.FontWithFamily ("Helvetica", NSFontTraitMask.Narrow, 5, 11));
                                NSMenuItem subtitle = new NSMenuItem () {
                                    Enabled = false
                                };
                                subtitle.IndentationLevel = 1;
                                subtitle.AttributedTitle = att;

                                this.recentChanges.Add (current);
                                this.menu.AddItem (current);
                                this.menu.AddItem (subtitle);
                                text += e.ToString () + "\n\n";

                            }
                            this.recent_events_title.ToolTip = text;

                    

                        }
                        this.menu.AddItem (NSMenuItem.SeparatorItem);
                        this.menu.AddItem (this.preferences_item);
                        this.menu.AddItem (this.pause_sync);
                        this.menu.AddItem (NSMenuItem.SeparatorItem);
                    }
                    //this.menu.AddItem (help_item);

               
                    //this.menu.Delegate    = new SparkleStatusIconMenuDelegate ();
                    this.status_item.Menu = this.menu;
                    this.menu.AddItem (help_item);
                    this.menu.AddItem (this.about_item);
                    this.menu.AddItem (quit_item);
                }
            }
        }
コード例 #15
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 *= contentScaleFactorWidth;
            textDef.Dimensions.Width *= contentScaleFactorWidth;
            textDef.Dimensions.Height *= contentScaleFactorHeight;

            bool hasPremultipliedAlpha;

            // font
            UIFont font = null;

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

            if (font == null) 
            {
                font = UIFont.FromName ("Arial", textDef.FontSize);
                CCLog.Log("{0} not found.  Defaulting to Arial.", textDef.FontName);
            }

            // color
            var foregroundColor = UIColor.White;

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

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

            // LineBreak
            var lineBreak = (CCLabelLineBreak.Character == textDef.LineBreak) ? UILineBreakMode.CharacterWrap
                : (CCLabelLineBreak.Word == textDef.LineBreak) ? UILineBreakMode.WordWrap
                : UILineBreakMode.Clip;

            var nsparagraphStyle = (NSMutableParagraphStyle)NSParagraphStyle.Default.MutableCopy();
            nsparagraphStyle.LineBreakMode = lineBreak;
            nsparagraphStyle.Alignment = textAlign;

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

            // 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 CGSize(textDef.Dimensions.Width, textDef.Dimensions.Height);

            var layoutAvailable = true;
            if (dimensions.Width <= 0)
            {
                dimensions.Width = 8388608;
                layoutAvailable = false;
            }

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


            var boundingRect = stringWithAttributes.GetBoundingRect(new CGSize((int)dimensions.Width, (int)dimensions.Height), 
                NSStringDrawingOptions.UsesLineFragmentOrigin, null);
            
            if (!layoutAvailable)
            {
                if (dimensions.Width == 8388608)
                {
                    dimensions.Width = boundingRect.Width;
                }
                if (dimensions.Height == 8388608)
                {
                    dimensions.Height = boundingRect.Height;
                }
            }

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

            // Alignment
            var xOffset = (nfloat)0.0f;
            switch (textAlign) {
                case UITextAlignment.Left:
                    xOffset = 0; 
                    break;
                case UITextAlignment.Center: 
                    xOffset = (dimensions.Width-boundingRect.Width)/2.0f; 
                    break;
                case UITextAlignment.Right: xOffset = dimensions.Width-boundingRect.Width; break;
                default: break;
            }

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

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


            UIImage image = null;
            CGContext context = null;
            try 
            {
                UIGraphics.BeginImageContext (new CGSize(imageWidth,imageHeight));
                context = UIGraphics.GetCurrentContext ();

                //Set antialias or not
                context.SetShouldAntialias(textDef.isShouldAntialias);

                stringWithAttributes.DrawString(drawRect);

                image = UIGraphics.GetImageFromCurrentImageContext ();

                UIGraphics.EndImageContext();

                // 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;
            }
            catch (Exception exc)
            {
                CCLog.Log ("CCLabel: Error creating native label:{0}\n{1}", exc.Message, exc.StackTrace);
            }
            finally
            {
                // clean up the resources
                if (image != null) 
                {
                    image.Dispose ();
                    image = null;
                }
                if (context != null) 
                {
                    context.Dispose ();
                    context = null;
                }
                if (stringWithAttributes != null) 
                {
                    stringWithAttributes.Dispose ();
                    stringWithAttributes = null;
                }
            }
            return new CCTexture2D ();
        }
コード例 #16
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 *= 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
                {
                    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 foregroundColor = NSColor.White;

            // 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)
            {
                CCLog.Log("Native string:", "Dimensions of native NSAttributedString can not be 0,0");
                return new CCTexture2D();
            }

            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;
                stringWithAttributes.Dispose();
                stringWithAttributes = null;
                stringWithAttributes = new NSAttributedString(text, nsAttributes);
            }

            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;
                    stringWithAttributes.Dispose();
                    stringWithAttributes = null;
                    stringWithAttributes = new NSAttributedString(text, nsAttributes);
                }
                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);


            NSImage image = null;
            try
            {
                //Set antialias or not
                NSGraphicsContext.CurrentContext.ShouldAntialias = textDef.isShouldAntialias;

                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;
            }
            catch (Exception exc)
            {
                CCLog.Log ("CCLabel: Error creating native label:{0}\n{1}", exc.Message, exc.StackTrace);
            }
            finally
            {
                // clean up the resources
                if (image != null) 
                {
                    image.Dispose ();
                    image = null;
                }
                if (stringWithAttributes != null) 
                {
                    stringWithAttributes.Dispose ();
                    stringWithAttributes = null;
                }
            }
            return new CCTexture2D ();


        }
コード例 #17
0
ファイル: Setup.cs プロジェクト: Rud5G/SparkleShare
        public SparkleDataSource (float backing_scale_factor, List<Preset> presets)
        {
            Items         = new List <object> ();
            Cells         = new NSAttributedString [presets.Count];
            SelectedCells = new NSAttributedString [presets.Count];

            this.backing_scale_factor = (int) backing_scale_factor;

            int i = 0;
            foreach (Preset preset in presets) {
                Items.Add (preset);

                NSTextFieldCell cell = new NSTextFieldCell ();

                NSData name_data = NSData.FromString ("<font face='" + UserInterface.FontName + "'><b>" + preset.Name + "</b></font>");

                NSDictionary name_dictionary       = new NSDictionary();
                NSAttributedString name_attributes = new NSAttributedString (
                    name_data, new NSUrl ("file://"), out name_dictionary);

                NSData description_data = NSData.FromString (
                    "<small><font style='line-height: 150%' color='#aaa' face='" + UserInterface.FontName + "'>" + preset.Description + "</font></small>");

                NSDictionary description_dictionary       = new NSDictionary();
                NSAttributedString description_attributes = new NSAttributedString (
                    description_data, new NSUrl ("file://"), out description_dictionary);

                NSMutableAttributedString mutable_attributes = new NSMutableAttributedString (name_attributes);
                mutable_attributes.Append (new NSAttributedString ("\n"));
                mutable_attributes.Append (description_attributes);

                cell.AttributedStringValue = mutable_attributes;
                Cells [i] = (NSAttributedString) cell.ObjectValue;

                NSTextFieldCell selected_cell = new NSTextFieldCell ();

                NSData selected_name_data = NSData.FromString (
                    "<font color='white' face='" + UserInterface.FontName +"'><b>" + preset.Name + "</b></font>");

                NSDictionary selected_name_dictionary = new NSDictionary ();
                NSAttributedString selected_name_attributes = new NSAttributedString (
                    selected_name_data, new NSUrl ("file://"), out selected_name_dictionary);

                NSData selected_description_data = NSData.FromString (
                    "<small><font style='line-height: 150%' color='#9bbaeb' face='" + UserInterface.FontName + "'>" +
                    preset.Description + "</font></small>");

                NSDictionary selected_description_dictionary       = new NSDictionary ();
                NSAttributedString selected_description_attributes = new NSAttributedString (
                    selected_description_data, new NSUrl ("file://"), out selected_description_dictionary);

                NSMutableAttributedString selected_mutable_attributes =
                    new NSMutableAttributedString (selected_name_attributes);

                selected_mutable_attributes.Append (new NSAttributedString ("\n"));
                selected_mutable_attributes.Append (selected_description_attributes);

                selected_cell.AttributedStringValue = selected_mutable_attributes;
                SelectedCells [i] = (NSAttributedString) selected_cell.ObjectValue;

                i++;
            }
        }
コード例 #18
0
        public void DrawText(string text)
        {
            Ensure ();

            var gc = NSGraphicsContext.FromGraphicsPort (context, false);
            gc.SaveGraphicsState ();
            NSGraphicsContext.CurrentContext = gc;

            var str = new NSAttributedString (text, foregroundColor: Color, font: Font);
            var size = str.Size;

            var box = Bounds;

            switch (HAlign) {
            case NSTextAlignment.Right:
                box.X += box.Width - size.Width;
                break;
            case NSTextAlignment.Center:
                box.X += (box.Width - size.Width) / 2;
                break;
            }

            switch (VAlign) {
            case NSTextAlignment.Left:
                box.Y += box.Height - size.Height;
                break;
            case NSTextAlignment.Center:
                box.Y += (box.Height - size.Height) / 2;
                break;
            }

            str.DrawString (box.Location);

            NSGraphicsContext.GlobalRestoreGraphicsState ();
        }
コード例 #19
0
ファイル: SparkleSetup.cs プロジェクト: mvaello/SparkleShare
        public SparkleDataSource(List<SparklePlugin> plugins)
        {
            Items         = new List <object> ();
            Cells         = new NSAttributedString [plugins.Count];
            SelectedCells = new NSAttributedString [plugins.Count];

            int i = 0;
            foreach (SparklePlugin plugin in plugins) {
                Items.Add (plugin);

                NSTextFieldCell cell = new NSTextFieldCell ();

                NSData name_data = NSData.FromString ("<font face='Lucida Grande'><b>" + plugin.Name + "</b></font>");

                NSDictionary name_dictionary       = new NSDictionary();
                NSAttributedString name_attributes = new NSAttributedString (
                    name_data, new NSUrl ("file://"), out name_dictionary);

                NSData description_data = NSData.FromString (
                    "<small><font style='line-height: 150%' color='#aaa' face='Lucida Grande'>" + plugin.Description + "</font></small>");

                NSDictionary description_dictionary       = new NSDictionary();
                NSAttributedString description_attributes = new NSAttributedString (
                    description_data, new NSUrl ("file://"), out description_dictionary);

                NSMutableAttributedString mutable_attributes = new NSMutableAttributedString (name_attributes);
                mutable_attributes.Append (new NSAttributedString ("\n"));
                mutable_attributes.Append (description_attributes);

                cell.AttributedStringValue = mutable_attributes;
                Cells [i] = (NSAttributedString) cell.ObjectValue;

                NSTextFieldCell selected_cell = new NSTextFieldCell ();

                NSData selected_name_data = NSData.FromString (
                    "<font color='white' face='Lucida Grande'><b>" + plugin.Name + "</b></font>");

                NSDictionary selected_name_dictionary = new NSDictionary ();
                NSAttributedString selected_name_attributes = new NSAttributedString (
                    selected_name_data, new NSUrl ("file://"), out selected_name_dictionary);

                NSData selected_description_data = NSData.FromString (
                    "<small><font style='line-height: 150%' color='#9bbaeb' face='Lucida Grande'>" +
                    plugin.Description + "</font></small>");

                NSDictionary selected_description_dictionary       = new NSDictionary ();
                NSAttributedString selected_description_attributes = new NSAttributedString (
                    selected_description_data, new NSUrl ("file://"), out selected_description_dictionary);

                NSMutableAttributedString selected_mutable_attributes =
                    new NSMutableAttributedString (selected_name_attributes);

                selected_mutable_attributes.Append (new NSAttributedString ("\n"));
                selected_mutable_attributes.Append (selected_description_attributes);

                selected_cell.AttributedStringValue = selected_mutable_attributes;
                SelectedCells [i] = (NSAttributedString) selected_cell.ObjectValue;

                i++;
            }
        }
コード例 #20
0
        private RectangleF GetTitleFrame(out NSDictionary titleTextStyles, AppStoreWindow window)
        {
            var drawsAsMainWindow = window.DrawsAsMainWindow();
            var titleTextShadow = drawsAsMainWindow ? window.TitleTextShadow : window.InactiveTitleTextShadow;
            if (titleTextShadow == null)
            {
                titleTextShadow = new NSShadow
                {
                    ShadowBlurRadius = 0f,
                    ShadowOffset = new SizeF(0f, -1.0f),
                    ShadowColor = NSColor.FromDeviceWhite(1.0f, 0.5f),
                };
            }

            var titleTextColor = drawsAsMainWindow ? window.TitleTextColor : window.InactiveTitleTextColor;
            if (titleTextColor == default(NSColor))
            {
                titleTextColor = AppStoreWindow.DefaultTitleTextColor(drawsAsMainWindow);
            }
            var titleFont = window.TitleFont ??
                            NSFont.TitleBarFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Regular));

            var titleParagraphStyle = (NSParagraphStyle)NSParagraphStyle.DefaultParagraphStyle.MutableCopy();//new NSParagraphStyle { LineBreakMode = NSLineBreakMode.TruncatingTail };
            titleParagraphStyle.LineBreakMode = NSLineBreakMode.TruncatingTail;

            titleTextStyles = NSDictionary.FromObjectsAndKeys(
                new object[]
                {
                    titleFont, titleTextColor,
                    titleTextShadow, titleParagraphStyle
                },
                new object[]
                {
                    NSAttributedString.FontAttributeName, NSAttributedString.ForegroundColorAttributeName,
                    NSAttributedString.ShadowAttributeName, NSAttributedString.ParagraphStyleAttributeName
                });

            var titleSize = new NSAttributedString(window.Title, titleTextStyles).Size;
            var titleTextRect = new RectangleF(0, 0, titleSize.Width, titleSize.Height);

            var docIconButton = window.StandardWindowButton(NSWindowButton.DocumentIconButton);
            var versionButton = window.StandardWindowButton(NSWindowButton.DocumentVersionsButton);
            var closeButton = window.ButtonToLayout(NSWindowButton.CloseButton);
            var minimizeButton = window.ButtonToLayout(NSWindowButton.MiniaturizeButton);
            var zoomButton = window.ButtonToLayout(NSWindowButton.ZoomButton);

            if (docIconButton != null)
            {
                var docIconButtonFrame = ConvertRectFromView(docIconButton.Frame, docIconButton.Superview);
                titleTextRect.X = docIconButtonFrame.GetMaxX() + TITLE_DOCUMENT_BUTTON_OFFSET.Width;
                titleTextRect.Y = docIconButtonFrame.GetMidY() - titleSize.Height / 2f +
                TITLE_DOCUMENT_BUTTON_OFFSET.Height;
            }
            else if (versionButton != null)
            {
                var versionsButtonFrame = ConvertRectFromView(versionButton.Frame, versionButton.Superview);
                titleTextRect.X = versionsButtonFrame.GetMinX() - titleSize.Width + TITLE_VERSIONS_BUTTON_OFFSET;

                var document = ((NSWindowController)window.WindowController).Document;
                if (document.HasUnautosavedChanges || document.IsDocumentEdited)
                {
                    titleTextRect.X += TITLE_DOCUMENT_STATUS_X_OFFSET;
                }
            }
            else if (closeButton != null || minimizeButton != null || zoomButton != null)
            {
                var closeMaxX = closeButton == null ? 0f : closeButton.Frame.GetMaxX();
                var minimizeMaxX = minimizeButton == null ? 0f : minimizeButton.Frame.GetMaxX();
                var zoomMaxX = zoomButton == null ? 0f : zoomButton.Frame.GetMaxX();

                var adjustedX = Math.Max(Math.Max(closeMaxX, minimizeMaxX), zoomMaxX) + TITLE_MARGINS.Width;
                var proposedX = Bounds.GetMidX() - titleSize.Width / 2f;
                titleTextRect.X = Math.Max(proposedX, adjustedX);
            }
            else
            {
                titleTextRect.X = Bounds.GetMidX() - titleSize.Width / 2f;
            }

            var fullScreenButton = window.ButtonToLayout(NSWindowButton.FullScreenButton);
            if (fullScreenButton != null)
            {
                var fullScreenX = fullScreenButton.Frame.X;
                var maxTitleX = titleTextRect.GetMaxX();
                if ((fullScreenX - TITLE_MARGINS.Width) < titleTextRect.GetMaxX())
                {
                    titleTextRect.Width = titleTextRect.Size.Width - (maxTitleX - fullScreenX) - TITLE_MARGINS.Width;
                }
            }

            titleTextRect.Y = Bounds.GetMaxY() - titleSize.Height - TITLE_MARGINS.Height;

            return titleTextRect;
        }