Printing text

6 posts / 0 new
Last post
mritter0
mritter0's picture
Offline
Last seen: 1 year 10 months ago
Joined: 2014-04-21 21:15
Printing text

I am making new gadget class. I have a text related issue:

Imagine a button gadget with a locked width. Then the user changes the text to something longer than the button is wide. How do I clip the text off at the end of the button (inner width)? So it doesn't keep printing past the gadget.

IGraphics->Text() would be great if it printed by PIXEL length instead of CHARACTERS length.

My box is not static,though. The width/height can change with window resizing.

thomas
thomas's picture
Offline
Last seen: 13 hours 16 min ago
Joined: 2011-05-16 14:23
Re: Printing text

Normal clipping routines of layers.library should do. See http://wiki.amigaos.net/wiki/Graphics_Regions

Here is an exampe: http://thomas-rapp.homepage.t-online.de/examples/scalespace.c
It hides the region creation and the necessary handling of Begin/EndRefresh in two support functions set_clip_region resp. remove_clip_region.

hypex
hypex's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-09-09 16:20
Re: Printing text

At first I thought you was printng text from a button until i stopped making sense. ;-)

Graphics is a touch low level. I would have expected there to be Reaction functions for this built in. But you could also try Intution functions since this is in the BOOPSI domain. Such as PrintIText(). But it may have the same problems.

The ­itexticlass also looks interesting for the job.

mritter0
mritter0's picture
Offline
Last seen: 1 year 10 months ago
Joined: 2014-04-21 21:15
Re: Printing text

Thanks, Thomas. I found a different example of yours that I almost got working. I wasn't disposing of the region at the correct place. And I had to adjust the order the gadget was drawn, as well.

xenic
xenic's picture
Offline
Last seen: 1 year 11 months ago
Joined: 2011-05-07 04:52
Re: Printing text

@mritter0
IntuiTextLength() gives you the width in pixels.

X1000 - OS 4.1FE

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
Re: Printing text

IntuiTextLength() gives you the width in pixels.

TextLength()/IntuiTextLength() will only tell you how many horisontal pixels rendering the entire text will use, so you will only be able to tell if the entire text will fit or not.

In order to find out how many characters can be rendered fully into a given area the TextFit() function can be used.

I used this function in the bevel.image implementation for my no longer worked on open source ReAction clone:
https://sourceforge.net/p/openreaction/code/HEAD/tree/src/bevel_ic/dispatch.c#l214

Log in or register to post comments