Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Drawing strings

Drawing strings
Thread Tools
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Mar 12, 2001, 11:07 AM
 
What is the simplest way to draw strings into an NSView (or just draw strings anywhere)? I want to display numbers below some axes that my app draws using an NSBezierPath. I would just use NSTextView in IB, but I need to draw different numbers depending on some calculations.
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Mar 12, 2001, 11:16 AM
 
[myNSString drawAtPoint:NSMakePoint(x, y)
withAttributes:dictionary];

You can use an empty dictionary to test it.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Junior Member
Join Date: Mar 2001
Status: Offline
Reply With Quote
Mar 16, 2001, 12:40 AM
 
In case you want to see it, the drawAtPoint function is discussed in the NSStringAdditions file in AppKit.

-Peter
     
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
Mar 16, 2001, 10:40 AM
 
Couldn't that be simplified even more? I seem to recall writing a Tic Tac Toe game that used only strings drawn to a NSView (like you are asking about). I think that you can nil the "withAttributes" parameter:
[myNSString drawAtPoint:NSMakePoint(x,y) withAttributes:nil];

Since I used this, I never even knew that a dictionary was supposed to be used for that parameter. Thanks Parallax, that is good to know!

Jeff.
Spectral Class
"Shedding Light on Innovation"
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Mar 16, 2001, 02:26 PM
 
Yup, there's a bunch of useful properties which you may like to know:

NSFontAttributeName (NSFont) - font and size
NSKernAttributeName (NSNumber) - Kerning (negative numbers make the text condensed)
NSForegroundColorAttributeName (NSColor) - font color

Listed at:

http://devworld.apple.com/techpubs/m...singAttrs.html
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Junior Member
Join Date: Nov 2000
Status: Offline
Reply With Quote
Apr 10, 2001, 01:48 PM
 
NSString drawAtPoint dosen't seem to allow you to draw at a negitive point. It goes back to 0,0. Is this true? Is there a way to draw at a negitive point?

------------------
Timothy Hatcher
Programmer/Designer @ MainNet Incorporated
__________________________________________

http://www.main-net.com
Timothy Hatcher / xenon
.:[ massinova.com ]:.
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Apr 10, 2001, 07:50 PM
 
What about in Java? Does anyone know who to draw strings in Java? It seems like the examples above are for Obj-C.

     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:41 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2