I use GA_Text to add labels to Reaction buttons.
Is it possible to add a shadow at these labels ? Maybe a GA_TextAttr option ?
In my dockies (RAM, GFX, NetDock) I use Text() on the window RastPort to write labels and therefore I can add a shadow simply by repeating the Text() again at x+1 y+1 with a different Pen color.
But in a Reaction Button... Is it possible without to have to calculate all the relative coordinates of the buttons, to adapt the Text() length and to use Text() on the window RastPort ?
Is it a easier way ?
Thank you, by advance, for your help
Drawing into the window's RastPort is not an option. It is against all rules of dynamic GUI layout.
Well, GA_Text takes a string, so nothing to change here.
GA_TextAttr does not contain color information.
Normally I would use two linked struct IntuiText with different pens and locations pointing to the same string. But as it seems, button.gadget does not support IntuiText.
So what's left is GA_Image with an appropiate image class. I checked label.image, but it does not create shadows, either. I even tried intuition's built-in itexticlass. Without much luck: it does not position correctly and it prints both IntuiTexts with the same color.
Finally we end up writing our own image class for printing shadowed text. Here is an example: http://thomas-rapp.homepage.t-online.de/examples/shadow.lha
"Finally we end up writing our own image class for printing shadowed text."
Thank you very much, Thomas. I can't try your solution for the moment but it's very nice.
Do you think that AmiDock does something like that (to use a own class) to add shadows to their labels ?
It depends on where the drawing area belongs to. In your case the drawing area belongs to button.gadget and the only legal way to change its imagery is to somehow ensure that button.gadget draws it in its GM_RENDER method.
I don't know how AmiDock is programmed, but I doubt that it used ReAction for the dock. At least I wouldn't do it. But I am sure that it somehow uses Intuition's mechanism for input and GUI handling and BOOPSI is a very elegant way to do so. I would make a custom gadget class which is responsible for one icon and its label. In this case I would not make an extra image class for the label but let the gadget class draw it.
I once wrote an AmiDock-like program for Kick 1.3. There I used a normal struct Gadget. The GadgetRender/SelectRender pointers were used for the icon image and the GadgetText pointed to, you guess it, two linked struct IntuiText, the first with black pen at position 1,1 and the second with white pen and position 0,0, both pointing to the same character string.
Many thanks for the explanations.
This part of the code you supplied in shadow.lha struck me as odd:
if (contimg) DisposeObject (contimg);
if (quitimg) DisposeObject (quitimg);
Aren't these objects disposed off impicitly by this preceeding line:
Or does 'DisposeObject (winobj);' also NULL the pointers 'contimg' and 'quitimg'?
button.gadget does *not* dispose of images pointed to by GA_Image. I double-checked this with debug output in my shadowiclass_dispose method. It is never called if I don't call it explicitly.
O.K. Thanks! That clears it up for me.
I have tested your shadowiclass and it works !
Thank you very much.
Nevertheless, I have problem when as soon that i use a custom IA_TextAttr.
1) The texts are shifted to the bottom of the button (I use a non transparent button for the sample) when using IA_TextAttr, textWindow,
2) If I use IA_TextAttr, screen->Font of no IA_TextAttr, it works fine.
3) If I use my custom TextAttr in your sample shadow program, it works well => it's in my code that something is wrong...
I'm certain that a lot of things are bad coded in this short code extract below, but do you see something that could be related to my TextAttr problem ?
Thank you (again) by advance
IA_TextAttr takes a pointer to a struct TextAttr, not the struct TextAttr itself. Therefore you have to use &textWindow.
Note that tags are always 32 bits wide. ti_Tag and ti_Data are both uint32.
Wonderful, it works !
Thank you very much.
Sorry, I have another problem. When I use my own TextAttr, at first compile it works fine but when I reboot the same executable seems to have forgotten my TextAttr.
With your Shadow sample, I added a TextAttr (certainly bad coded) at first compile with a new Font ta_Name, it works well.
But if I try to change the font and recompile, the TextAttr is gone.
Even if I don't try to change the font and that I just reboot without do something special, the Font is gone.
After this reboot a make clean doesn't solve my problem, I have to change to a new font name.
For example, in http://zzd10h.amiga-ng.org/Divers/shadow.lha
1) First compile is OK, I have a big "Continue"
2) But at next boot with the same executable, it's gone
In my own project, with the same TextAttr, no Font problem when using Button GA_TextAttr (therefore non shadowed labels) but I have the same problem when using IA_TextAttr Shadowed labels.
I tried different ways to code TextAttr structure (with or without & *,etc...) no luck ;)
Thank you again by advance for your advices.
Obviously the desired font height (32) is used for size calculation, so I think the TextAttr is ok. But the actual font cannot be opened when it comes to render it.
Now that I think about it, I remember that I stumbled across this long ago, too. The problem is that Intuition uses OpenFont rather than OpenDiskFont. The former only finds fonts which are already in memory while the latter can also load fonts from disk.
So if you want to use a custom font, you have to call OpenDiskFont with your TextAttr once and keep the pointer at least until the window is opened. Then you can CloseFont it.
Thank you very much, I will try OpenDiskFont() tomorrow.
Nevertheless, it's strang that even after a warm start, the problem is still alive even with OpenFont()... I will try a cold start tomorrow before to try OpenDiskFont().
" I will try a cold start tomorrow before to try OpenDiskFont()."
Not better, I still have to change font name to see my right size even after a cold start...
You were right, OpenDiskFont() solves this problem on shadow program and in mine.
I just "textFont = openDiskFont(&textWindow)" before to display the window and "CloseFont(textFont)" at program deinitialization.
Thank you again ;)