[solved] How to add shadow to a Button GA_Text ?

17 posts / 0 new
Last post
zzd10h
zzd10h's picture
Offline
Last seen: 7 years 3 weeks ago
Joined: 2012-08-24 20:56
[solved] How to add shadow to a Button GA_Text ?

Hi,
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
Guillaume

thomas
thomas's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2011-05-16 14:23
Drawing into the window's

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

zzd10h
zzd10h's picture
Offline
Last seen: 7 years 3 weeks ago
Joined: 2012-08-24 20:56
"Finally we end up writing

"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 ?

thomas
thomas's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2011-05-16 14:23
It depends on where the

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.

zzd10h
zzd10h's picture
Offline
Last seen: 7 years 3 weeks ago
Joined: 2012-08-24 20:56
Many thanks for the

Many thanks for the explanations.

OldFart
OldFart's picture
Offline
Last seen: 3 months 2 weeks ago
Joined: 2010-11-30 14:09
@thomas This part of the

@thomas

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:

DisposeObject (winobj);
}

Or does 'DisposeObject (winobj);' also NULL the pointers 'contimg' and 'quitimg'?

OldFart

thomas
thomas's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2011-05-16 14:23
button.gadget does *not*

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.

OldFart
OldFart's picture
Offline
Last seen: 3 months 2 weeks ago
Joined: 2010-11-30 14:09
@thomas O.K. Thanks! That

@thomas

O.K. Thanks! That clears it up for me.

OldFart

zzd10h
zzd10h's picture
Offline
Last seen: 7 years 3 weeks ago
Joined: 2012-08-24 20:56
I have tested your

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,

IMAGE(http://zzd10h.amiga-ng.org/Divers/FastView_Capture_15-07-26_194108.JPG)

2) If I use IA_TextAttr, screen->Font of no IA_TextAttr, it works fine.

IMAGE(http://zzd10h.amiga-ng.org/Divers/FastView_Capture_15-07-26_194139.JPG)

3) If I use my custom TextAttr in your sample shadow program, it works well => it's in my code that something is wrong...

IMAGE(http://zzd10h.amiga-ng.org/Divers/FastView_Capture_15-07-26_194749.JPG)

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

  1. struct TextAttr textWindow = {0} ;
  2. textWindow.ta_Name = "DejaVu Sans.font" ;
  3. textWindow.ta_YSize = 12;
  4. textWindow.ta_Style = 4 ;
  5. textWindow.ta_Flags = 0 ;
  6.  
  7. LAYOUT_AddChild, label[x] = (APTR)ButtonObject,
  8. GA_ReadOnly, TRUE,
  9. GA_Image, NewObject (shadowiclass,NULL,
  10. IA_Text,tab_program_label[x],
  11. IA_TextAttr,textWindow,
  12. IA_FGPen,penText,
  13. IA_BGPen,penShadow,
  14. TAG_END),
  15. EndObject,
  16. CHILD_WeightedHeight, 0,
  17. EndVGroup))
  18. {
  19. SetAttrs(OBJ(OBJ_MAIN),LAYOUT_AddChild, OBJ(OBJ_BTN),TAG_END);
  20. }
thomas
thomas's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2011-05-16 14:23
IA_TextAttr takes a pointer

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.

zzd10h
zzd10h's picture
Offline
Last seen: 7 years 3 weeks ago
Joined: 2012-08-24 20:56
Wonderful, it works !

Wonderful, it works !
Thank you very much.

IMAGE(http://zzd10h.amiga-ng.org/Divers/FastView_Capture_15-07-26_221706.JPG)

zzd10h
zzd10h's picture
Offline
Last seen: 7 years 3 weeks ago
Joined: 2012-08-24 20:56
Re: How to add shadow to a Button GA_Text ?

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"

IMAGE(http://zzd10h.amiga-ng.org/Divers/FastView_Capture_15-07-27_223727.JPG)

2) But at next boot with the same executable, it's gone

IMAGE(http://zzd10h.amiga-ng.org/Divers/FastView_Capture_15-07-27_223947.JPG)

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.

thomas
thomas's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2011-05-16 14:23
Re: How to add shadow to a Button GA_Text ?

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.

zzd10h
zzd10h's picture
Offline
Last seen: 7 years 3 weeks ago
Joined: 2012-08-24 20:56
Re: How to add shadow to a Button GA_Text ?

Thank you very much, I will try OpenDiskFont() tomorrow.

zzd10h
zzd10h's picture
Offline
Last seen: 7 years 3 weeks ago
Joined: 2012-08-24 20:56
Re: How to add shadow to a Button GA_Text ?

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().

zzd10h
zzd10h's picture
Offline
Last seen: 7 years 3 weeks ago
Joined: 2012-08-24 20:56
Re: How to add shadow to a Button GA_Text ?

" 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...

zzd10h
zzd10h's picture
Offline
Last seen: 7 years 3 weeks ago
Joined: 2012-08-24 20:56
Re: How to add shadow to a Button GA_Text ?

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 ;)

Log in or register to post comments