Page 1 of 1
How to change IGraphics->Text font?
Posted: Thu Dec 26, 2013 11:29 am
by AmiHyperion
Hello,
I'm using IGraphics->Text to write text on a window.
I have a few questions for this:
There are special new methods/classes, without macro, to operate with this^
Should i clear the rport each time i write new text?
There's a way for the IGraphics->Text to accept the newline charcode \n?
Ho can i change the font of the text?
Thank you very much
Re: How to change IGraphics->Text font?
Posted: Thu Dec 26, 2013 2:43 pm
by salass00
AmiHyperion wrote:
Should i clear the rport each time i write new text?
Depends on your requirements. Note that while JAM1 draws only the text itself using APen/-Color JAM2 draw mode draws also a box around the text using BPen/-Color which can be useful if you want overwrite previously written text and are using a fixed width font.
IGraphics->TextLength() can be used to find out how wide the text will be when written using IGraphics->Text() (useful if you're using a proportional font).
There's a way for the IGraphics->Text to accept the newline charcode \n?
You can do this yourself easily enough by writing a function that uses IGraphics->Text() to write each line (note that text written with IGraphics->Text() doesn't need to be null-terminated because of the length argument) and then use IGraphics->Move() to move to a new line position.
Ho can i change the font of the text?
Just use IGraphics->SetFont() or RPTAG_Font with IGraphics->SetRPAttrs().
Re: How to change IGraphics->Text font?
Posted: Thu Dec 26, 2013 8:43 pm
by AmiHyperion
Thank you.
It's just so easy as write IGraphics->SetFont()? Maybe IGraphics->SetFont("Topaz",8), or there are other things that i should do?
Re: How to change IGraphics->Text font?
Posted: Thu Dec 26, 2013 8:48 pm
by thomasrapp
Please RTFM before you ask!
struct TextAttr attr = {"topaz.font",8}; /* it's case sensitive! */
struct TextFont *font = IDiskfont->OpenDiskFont(&attr);
IGraphics->SetFont (rp,font);
...
IGraphics->CloseFont (font);
Re: How to change IGraphics->Text font?
Posted: Fri Dec 27, 2013 10:52 am
by AmiHyperion
I really hope that the F statement mean Fine, or Faboulous or friendly manual
Re: How to change IGraphics->Text font?
Posted: Fri Dec 27, 2013 6:10 pm
by LyleHaze
Giving a complete answer with all the necessary supporting code would not be practical. Most OS functions require some initialization of the structures used in the call. As a result, most answers are not intended as "complete code ready to use". In other words, they show the goal you are seeking to reach, but it's still up to the asker to provide supporting code to get there.
"RTFM" was the classic answer, but we are forging ahead in to the new age,
perhaps the best replacement might be "RTWM", meaning "Read the Wiki Manual".
I went to
http://wiki.amigaos.net/index.php/Main_Page and I typed in "SetFont".
The results showed lots of places that SetFont might be used, and in this case "Graphics Library and Text" looked promising.
I followed that link and found
http://wiki.amigaos.net/index.php/Graph ... y_and_Text
looking through that page, I even found a block of highlighted code showing JUST what was asked for:
Code: Select all
/* pseudotext.c */
int main()
{
struct TextAttr myta = {
"topaz.font"
11,
FSF_ITALIC | FSF_BOLD,
NULL
};
struct TextFont *myfont, *oldfont;
struct RastPort *myrp;
struct Window *mywin;
. . .
/* open the graphics and diskfont libraries and whatever else you may need */
. . .
if (myfont = IDiskFont->OpenDiskFont(&myta))
{
/* you would probably set the font of the rastport you are going to use */
myrp = mywin->RPort
oldfont = myrp->Font;
IGraphics->SetFont(myrp, myfont);
. . .
/* perform whatever drawing you need to do */
. . .
/* time to clean up. If the rastport is not exclusively yours,
you may need to restore the original font or other Rasport values */
IGraphics->SetFont(myrp, oldfont);
IGraphics->CloseFont(myfont);
}
/* close whatever libraries and other resources you allocated */
return 0;
}
Now to be honest it's still not "complete".
You will need to open and close the libraries used, as well as add whatever functions you want to actually write the text, but
beyond that it's pretty close to a complete code example.
For help with what is still missing, go back to
http://wiki.amigaos.net/index.php/Main_Page and do a search on "OpenLibrary".
Finally, the AmigaOS documentation WIKI is an ongoing project. It is not complete, but as a Wiki it can be edited by approved users. If you find it useful please consider "paying it forward" by making improvements and corrections as you see opportunities.
Re: How to change IGraphics->Text font?
Posted: Sat Dec 28, 2013 12:50 pm
by AmiHyperion
@LyleHaze
thank you for your reply
"Giving a complete answer with all the necessary supporting code would not be practical."
for someone only two words are necessary: "do this"
For other people a complete step by step guide is necessary.
I understand that sometimes i can be boring... sorry for this.
Yes, i read the "RTWM" before ask, especially the page you have linked. I read some days ago but was not so clear for me, consider that i come from IDE or programming environment where wirting... text1.text="bla bla bla" or label1.caption="change me when you want", may suffice.
Consider that at the top of the pages i read before ask (the same you linked) you can read:
"This page is currently being updated to AmigaOS 4.x some of the information contained here may not yet be applicable in part or totally."
This is the reason i asked:
"There are special new methods/classes, without macro, to operate with this?"
Just because i tried several times with code from the wiki, only to restart again from the beginning after understanding that some way to operate are old methods or now considered obsolete. (see macro, not macro.... etc)
Re: How to change IGraphics->Text font?
Posted: Wed Jan 01, 2014 4:33 pm
by chris
AmiHyperion wrote:This is the reason i asked:
"There are special new methods/classes, without macro, to operate with this?"
Just because i tried several times with code from the wiki, only to restart again from the beginning after understanding that some way to operate are old methods or now considered obsolete. (see macro, not macro.... etc)
Text() is fine, if you're writing direct to a RastPort, nothing has changed (except the way to change the text colour, but you didn't ask about that

)
However, it may be better to
indirectly write to the RastPort, by attaching a read-only string/texteditor.gadget or a label.image. Especially as you mentioned clearing the text, and as all the positioning is sorted out for you, that is the better method.
But it really depends exactly what you are trying to achieve.