CGContextShowTextAtPoint() help
hi,
I am a new user to Mac OS.I need to port a C project from Mac os 9 to Mac os 10.4.So while porting it to xcode I found that few API's which we used in our project has been deprecated.One such API is DrawString() to print text on the screen.In the Apple developer reference document they have asked to use ATSU or Quartz as an alternative.I used CGContextShowatPoint() API but it is not printing the text.Please help me with this.
Code I used is:
-------------
#include <ApplicationServices/ApplicationServices.h>
char str[100];
sprintf(str,"Press any key to exit");
CGContextRef context;
CGContextShowTextAtPoint(context,400,300,str,strle n(str)-1);
Please tell me what is wrong in the above code.
It is a carbon application.Please help me out.
I am a new user to Mac OS.I need to port a C project from Mac os 9 to Mac os 10.4.So while porting it to xcode I found that few API's which we used in our project has been deprecated.One such API is DrawString() to print text on the screen.In the Apple developer reference document they have asked to use ATSU or Quartz as an alternative.I used CGContextShowatPoint() API but it is not printing the text.Please help me with this.
Code I used is:
-------------
#include <ApplicationServices/ApplicationServices.h>
char str[100];
sprintf(str,"Press any key to exit");
CGContextRef context;
CGContextShowTextAtPoint(context,400,300,str,strle n(str)-1);
Please tell me what is wrong in the above code.
It is a carbon application.Please help me out.
Maybe you can use this instead?
http://developer.apple.com/documentation...rence.html
in particular, http://developer.apple.com/documentation...awAtPoint:
http://developer.apple.com/documentation...rence.html
in particular, http://developer.apple.com/documentation...awAtPoint:
Sir, e^iπ + 1 = 0, hence God exists; reply!
If you have a valid context (you don't in the pasted code, but I'm not sure if that's just short for brevity's sake), then you're on the right track.
http://developer.apple.com/documentation...ion_4.html
Where are you getting the context from?
http://developer.apple.com/documentation...ion_4.html
Where are you getting the context from?
void MakeTargets()
{
.....
//The following code is for Drawing Text
CGContextRef context;
CGContextSelectFont(context, "Helvetica", 16, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (context, kCGTextFillStroke); CGContextSetRGBFillColor (context, 0, 5, 0, .5);
CGContextSetRGBStrokeColor (context, 0, 1, 1, 1);
CGContextShowTextAtPoint(context,20,440,stringTemp,strlen(stringTemp)-1);
........
}
How to create a valid graphics context?And what else should I add to this code to make it work?The text should be printed in a screen where I have loaded a few pictures(targets).
{
.....
//The following code is for Drawing Text
CGContextRef context;
CGContextSelectFont(context, "Helvetica", 16, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (context, kCGTextFillStroke); CGContextSetRGBFillColor (context, 0, 5, 0, .5);
CGContextSetRGBStrokeColor (context, 0, 1, 1, 1);
CGContextShowTextAtPoint(context,20,440,stringTemp,strlen(stringTemp)-1);
........
}
How to create a valid graphics context?And what else should I add to this code to make it work?The text should be printed in a screen where I have loaded a few pictures(targets).
You need to read these docs from the beginning:
http://developer.apple.com/documentation...-TPXREF101
http://developer.apple.com/documentation...-TPXREF101