Example #1
0
 public static void DrawText(RectangleF rect, float x, float y, string text, string fontName, float fontSize, NSColor fontColor)
 {
     NSMutableDictionary dict = new NSMutableDictionary();
     dict.Add(NSAttributedString.FontAttributeName, NSFont.FromFontName(fontName, fontSize));
     dict.Add(NSAttributedString.ForegroundColorAttributeName, fontColor);
     NSString nsstr = new NSString(text);
     RectangleF rectBounds = nsstr.BoundingRectWithSize(new SizeF(rect.Width, rect.Height), NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin, dict);
     rectBounds.X = rect.X + x;
     rectBounds.Y = rect.Y + y;
     nsstr.DrawString(rectBounds, NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin, dict);
 }
Example #2
0
		// Create the set of display lists for the bitmaps
		bool MakeGLDisplayListFirst (char first, int count, int baseDL)
		{

			int curListIndex;
			NSColor blackColor;
			NSMutableDictionary attribDict;
			int dListNum;
			NSString currentChar;
			char currentUnichar;
			SizeF charSize;
			RectangleF charRect;
			NSImage theImage;
			bool retval;

			// Make sure the list isn't already under construction
			GL.GetInteger (GetPName.ListIndex, out curListIndex);
			if (curListIndex != 0) {
				Console.WriteLine ("Display list already under construction");
				return false;
			}

			// Save pixel unpacking state
			GL.PushClientAttrib (ClientAttribMask.ClientPixelStoreBit);

			GL.PixelStore (PixelStoreParameter.UnpackSwapBytes, 0);
			GL.PixelStore (PixelStoreParameter.UnpackLsbFirst, 0);
			GL.PixelStore (PixelStoreParameter.UnpackSkipPixels, 0);
			GL.PixelStore (PixelStoreParameter.UnpackSkipRows, 0);
			GL.PixelStore (PixelStoreParameter.UnpackRowLength, 0);
			GL.PixelStore (PixelStoreParameter.UnpackAlignment, 0);

			blackColor = NSColor.Black;

			attribDict = new NSMutableDictionary ();
			attribDict.SetValueForKey (font, NSAttributedString.FontAttributeName);
			attribDict.SetValueForKey (NSColor.White, NSAttributedString.ForegroundColorAttributeName);
			attribDict.SetValueForKey (blackColor, NSAttributedString.BackgroundColorAttributeName);

			charRect.Location.X = charRect.Location.Y = 0;

			theImage = new NSImage (new SizeF (0,0));
			retval = true;

			for (dListNum = baseDL, currentUnichar = first; currentUnichar < first + count; 
				dListNum++, currentUnichar++) {

				currentChar = new NSString (Char.ToString (currentUnichar));
				charSize = currentChar.StringSize (attribDict);
				charRect.Size = charSize;
				charRect = charRect.Integral ();
				if (charRect.Size.Width > 0 && charRect.Size.Height > 0) {

					theImage.Size = charRect.Size;
					theImage.LockFocus ();
					NSGraphicsContext.CurrentContext.ShouldAntialias = false;
					blackColor.Set ();
					NSBezierPath.FillRect (charRect);
					currentChar.DrawString (charRect, attribDict);
					theImage.UnlockFocus ();

					if (!MakeDisplayList(dListNum, theImage)) {
						retval = false;
						break;
					}
				}
			}
			return retval;
		}
Example #3
0
 public static void DrawTextInRect(CGContext context, RectangleF rect, string text, string fontName, float fontSize, NSColor fontColor)
 {
     context.SaveState();
     NSString str = new NSString(text);
     var dict = new NSMutableDictionary();
     dict.Add(NSAttributedString.ForegroundColorAttributeName, fontColor);
     dict.Add(NSAttributedString.FontAttributeName, NSFont.FromFontName(fontName, fontSize));
     str.DrawString(rect, dict);
     context.RestoreState();
 }
Example #4
0
		private void DrawStringOutline(string text, NSColor color, RectangleF rect, int align)
		{
			NSString nsString = new NSString (text);

			int halign = align % 3;
			int valign = align / 3;


			var objectsText = new object[] { m_font, color };
			var keysText = new object[] { NSAttributedString.FontAttributeName, NSAttributedString.ForegroundColorAttributeName };
			var attributesText = NSDictionary.FromObjectsAndKeys(objectsText, keysText);

			var objectsOutline = new object[] { m_font, NSColor.White };
			var keysOutline = new object[] { NSAttributedString.FontAttributeName, NSAttributedString.ForegroundColorAttributeName };
			var attributesOutline = NSDictionary.FromObjectsAndKeys(objectsOutline, keysOutline);


			SizeF size = nsString.StringSize (attributesText);

			if (halign == 0) {
			} else if (halign == 1) {
				rect.X = (rect.Left + rect.Right) / 2 - size.Width / 2;
			} else if (halign == 2) {
				rect.X = rect.Right - size.Width;
			}
			rect.Width = size.Width;

			if (valign == 0) {
			} else if (valign == 1) {
				rect.Y = (rect.Top + rect.Bottom) / 2 - size.Height / 2;
			} else if (valign == 2) {
				rect.Y = rect.Bottom - size.Height;
			}
			rect.Height = size.Height;

			NSColor.Black.Set ();
			for (int ox = -1; ox <= 1; ox++) {
				for (int oy = -1; oy <= 1; oy++) {
					RectangleF rectString = rect;
					rectString.Offset (new PointF (ox, oy));
					nsString.DrawString (Invert (rectString), attributesOutline);
				}
			}
			nsString.DrawString(Invert(rect), attributesText);
		}