I am trying to get the longest length of some strings. It is working
int32 SAK_LongestStrLenPixels(int32 From,int32 To) { STRPTR Text; int32 MaxLen=0, Len, i; for (i=From; i<=To; i++) { if ((Text=SAK_LocaleString(i))) { if ((Len=IGraphics->TextLength(MainWindow->RPort,Text,IUtility->Strlen(Text)))>MaxLen) MaxLen=Len; } } return(MaxLen); }
Except it is not using MainWindow's font, which is proportional. It is using the system default font, which is mono spaced. I am not assigning a different font for my window, why isn't it using the correct one to measure the lengths?
You're not using a GimmeZeroZero window by chance?
from intuition.library/OpenWindow:
Nope. Using window.class to create/layout the guts.
And your 'MainWindow' struct what Font (struct TextFont *IFont;) is using?
Maybe you can post your window creation code, in case misssing some tag.
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
DefaultPubScreen is NULL, so Workbench.
Figured it out. I should be looking at the screen's RastPort, not the window. Which makes sense so I can get the max text length to build the gadgets before opening the window.
if ((Len=IGraphics->TextLength(&DefaultPubScreen->RastPort,Text,IUtility->Strlen(Text)))>MaxLen)
That's interesting. When I want to get text length of strings I last used IntuiTextLength().
@mritter0:
Nitpicking, but from the snippet of code you supplied it shows that, per NewObject()-call, you are (still) using the GetClass()-function as supplied by the class itself. As of V50 this is deprecated practice. See the Autodoc below, regarding this topic.
OldFart
Previously I posted a question on Hyperion Forum and Steven Solie said that the Reaction macros are GOING to be deprecated so don't use them. Fine. Go into reaction_macros.h and replace the #define shortcut with the code it represents (in my code). That is the code.
What should I be using then for the window and gadgets?
Edit: I am opening the class before this.
@mritter0:
Here's an idea about how to do:
An excellent tutorial about this subject by Trixie you can find HERE. This is a very good read and is highly endorsed!
About the ReAction macro's: my perception about them is that they are absolute crap and severly contribute to ReAction's infamous image. Avoid them! They should have been deprecated decades ago if ever introduced. Anything you create yourself in that respect will PROBABLY suit you better then those macro's. But, as I said already: this is MY perception.
OldFart
AFAIK the WindowObject, VGroupObject, etc. macros are inspired by MUI which has very similar macros for GUI creation.
@OldFart: Nit picks are fine with me. I want it right. Thanks. Updated it. I kind of had it that way back when I first started my project on OS3.9. OpenClass() isn't there so I was using someone's custom class opener.
I read Trixie's post but it didn't "click" that I still needed to update my code to OS4 since it was working.
Trixie does struct ClassLibrary * and I started with that but get redefined errors because the classes are still struct Library * in the proto header files (proto/chooser.h for example). Instead of casting them, just update them in the SDK. I would rather be "forced" to update my code so I know it will work in the future and be more stable in the present.
People say don't use the ReAction macros anymore. Some say don't use libauto anymore. I was told (suggested) to not use __USE_INLINE__ anymore. Most (if not all) of the SDK examples follow any of these suggestions. Even the new MenuClass example is using old code. If the core developers aren't doing things the way they tell us we should be doing it, how are we supposed to know what to do? If the examples supplied to us are outdated, how are we to know about newer functions?
There is an obsolete file for DOS functions. Make one for every library and get people in the habit of updating their code. Better yet, don't let the obsolete file update their code without their knowledge, just throw an error. But make a large, global, obsolete file in the root of the SDK with the new functions to use instead. It wouldn't bother me at all to update my code, but I have to know there is a file to look at to see what to use now.
Just do it. Force programmers to update their code and "do it the right way." Backwards compatibility can only go so far.
@mritter0
FWIW I'm considering changing the proto header files' extern definitions for class libraries to struct ClassLibrary * but as this change will probably break a lot of existing code I'd like to have some input from other developers first before making such a change. Also it will cause problems for programs that need to be compiled for both older and newer AmigaOS so some kind of define to switch back to the old struct Library * definition might be in order.
As is currently you can either define your library base globals as struct Library * and add casting in your OpenClass()/CloseClass() calls or define __NOLIBBASE__ to disable the proto file extern definition.
@mritter
While everyone else is concerned with the use of macros, I'm wondering if using the screen's font is the right choice. Since you appear to be concerned about gadget text, what happens if the user has set custom fonts & font sizes in the "GUI preferences/Gadgets/General" tab? Will that affect your use of the screen font to calculate text lengths??
X1000 - OS 4.1FE
@xenic: Yes, gadget text is what I want to account for. But since the window is not open yet the default screen font is all I can look at. Unless there is something else.....
@salass00: I hope I didn't sound too rash/harsh. The OS is almost too flexible. Some things just need to forced to be done a certain way, while simple other things (labels, images) can still have some of the nice flexibility.
A gadget class in a ReAction GUI gets its GM_DOMAIN method called with a RastPort set up properly for layout. There is no need to look at other font sources.
There is GUIA_GadgetTextAttr & GUIA_LabelTextAttr in SDK:Include/include_h/intuition/gui.h but I've never attempted to get any of those settings myself.
X1000 - OS 4.1FE
@Thomas: Finding size of system font
In your reply #2 you say to use the screen font. If not, then what are the ReAction classes using to find the correct font and size?
@xenic: GUIA_GadgetTextAttr is probably what I need. I was just reading the gui.h and says to not access them unless have a really good reason. Guess it wouldn't hurt to read them, just not write to them.
@mritter
You really don't want to override user preferences, so those GUI attributes should only be read. I was wrong about never having used them myself. I modified an old 'personal-use' gadtools program to use the same gadget fonts as Reaction so it would be more readable. Here is a snippet of code I used:
X1000 - OS 4.1FE
@xenic: Updated my code with a mix of yours and mine. Works just fine. Thanks.