Transclusent Text window... another try? (SOLVED, hurrah!)

Started by InCreator, Wed 18/04/2007 13:25:50

Previous topic - Next topic

InCreator

I'm trying to make transclusent text window in AGS for ages.
AGS doesn't support either alpha backgrounds or gui transparency in text windows.
Atleast, older versions didn't. And I haven't heard anything about this implemented yet.

Then again, I recall seeing one in an AGS game sometime ago... sadly, I can't remember which game it was!

This time, I'm trying to make another GUI, just a transclusent black box to appear behind text window... While text window itself has no background, only text.

How to make it? I made the box, but can't get it to appear at same time when text window does.

Text gui and transclusent gui are named gText and gAlpha accordingly... some I have some questions:

* Can I force two guis to appear at same time? Of which, one is text window?
if (gText.Visible == true) gAlpha.Visible = true; in repeatedly_excecute didn't work.
Forcing gAlpha.Visible just before ProcessClick did work... but not right. If shows gAlpha after text box is gone.

What to do here?

* Can I copy dimensions of text box into gAlpha? Text boxes resize automatically according to text, and I need these dimensions for gAlpha too.

If it's pointless quest...

* Can I make my own text GUI without using "text window" setting from GUI editor? If so, how do I make sure that text doesn't go transparent (yet background goes) and what do do about dimensions?
I imagine that custom text gui should have a label that shows currently displayed text... how to ensure it's centered all the time?

Or...
* Can anybody remember the game that actually did what I'm trying to do?

* I tried to give textbox some text (but not display it), get its dimension then and assign it to my custom gui.
This didn't work...

gText.Text = "blablabla";
gAlpha.Widht = gText.Width;

it didn't like text assigning...
"gText is not a public member of GUI"

So, I still have to figure out how to resize guis according to label text.

And...
* How did they do it in 1992? Especially while restricted to 256 colors?


SupSuper

#1
Quote from: InCreator on Wed 18/04/2007 13:25:50
I'm trying to make transclusent text window in AGS for ages.
AGS doesn't support either alpha backgrounds or gui transparency in text windows.
Atleast, older versions didn't. And I haven't heard anything about this implemented yet.

Then again, I recall seeing one in an AGS game sometime ago... sadly, I can't remember which game it was!
If you're using a custom GUI for the text window, you should be able to change the Transparency property (at on_game_start() for example) though I'm just theorizing.
A semi-transparent background sprite (PNG format) might also work.

QuoteThis time, I'm trying to make another GUI, just a transclusent black box to appear behind text window... While text window itself has no background, only text.

How to make it? I made the box, but can't get it to appear at same time when text window does.

Text gui and transclusent gui are named gText and gAlpha accordingly... some I have some questions:

* Can I force two guis to appear at same time? Of which, one is text window?
if (gText.Visible == true) gAlpha.Visible = true; in repeatedly_excecute didn't work.
Forcing gAlpha.Visible just before ProcessClick did work... but not right. If shows gAlpha after text box is gone.

What to do here?
Hmm... well if you're using Display() to show the text, you'd have to display the semi-transparent before and hide it afterwards. (since Display pauses the script)

Code: ags

gTransparent.Visible = true;
Display("Stuff");
gTransparent.Visible = false;


Quote* Can I copy dimensions of text box into gAlpha? Text boxes resize automatically according to text, and I need these dimensions for gAlpha too.
I doubt you can get the dimensions right out of the box GUI, though you can "calculate" them beforehand with GetTextWidth and GetTextHeight.
Code: ags

function DisplayTransparent(String text)
{
  gTransparent.Width = GetTextWidth(text, 0) + 10;
  gTransparent.Height = GetTextHeight(text, 0, gTransparent.Width) + 10;
  gTransparent.Centre();
  gTransparent.Visible = true;
  Wait(1);
  Display(text);
  gTransparent.Visible = false;
}

I turned it into a function so you could just call DisplayTransparent("Stuff") in your scripts instead of recopying all the code, though again, this is all theoretical, I'm not sure if it'd work.

Btw, don't forget to make sure that gTransparent isn't set to "Popup Modal" and hide it at start.

QuoteIf it's pointless quest...

* Can I make my own text GUI without using "text window" setting from GUI editor? If so, how do I make sure that text doesn't go transparent (yet background goes) and what do do about dimensions?
I imagine that custom text gui should have a label that shows currently displayed text... how to ensure it's centered all the time?
You'd probably have to take an approach similar to above, though the box and the text would have to be in two separate GUIs so the text doesn't become transparent. As for keeping it all neat and tidy, see above.

Quote* I tried to give textbox some text (but not display it), get its dimension then and assign it to my custom gui.
This didn't work...

gText.Text = "blablabla";
gAlpha.Widht = gText.Width;

it didn't like text assigning...
"gText is not a public member of GUI"

So, I still have to figure out how to resize guis according to label text.
Yeah, you can't mess with Text Window GUIs. Again, see what I wrote above.

QuoteAnd...
* How did they do it in 1992? Especially while restricted to 256 colors?

http://www.increator.pri.ee/i/kgb.png
I think they used color blending (mixing the box color and background color together), or just darkened/lightened the respecitve pixels... with palletes. And stuff.

Edit: Just tried out my function and it works, so let me know if it does for you too. :)
Programmer looking for work

InCreator

#2
Thanks... but I'm still stuck.

To make custom function, I have to import it. And there's a problem:

From AGS Manual
Quote
NOTE: You cannot currently import string variables. Instead, you should use a global string.

I don't know if it's the case or I forgot something. Anyway, AGS said:

QuoteAlready referenced name as import; you must define it before using it
er... what?
Well, there.
You said your version worked... care to send me the file?

Or explain in detail, where did you put the function lines and how did you import it? Did you create your own #sectionstart thing and so on?

I'm not very good at coding yet...  :(

EDIT: I got it to work!!! It was my own stupidity, putting function into wrong place in global script. Heavy thanks!!! There's some problems with getting text width, since the width is GOT before text window automatically splits it into rows, but otherwise, I got what I needed.

Ashen

The manual quote is out of date - well, sort of. You CAN'T (never could, and I guess never will be able to) import string variables - the old-style ones. You can, however, import the new String type.

However, that's not really relevant for what you want, since the String there is a function parameter, and they've always worked OK (even string parameters). And - as you figured out for yourself - that's noting to do with the error message anyway. For future reference - the problem was trying to use DisplayTransparent in the Global Script BEFORE the function declaration? Even when the function has been imported, for the script it's declared in (e.g. Global script, Module script) it has to be declared before it can be used.

Quote
There's some problems with getting text width, since the width is GOT before text window automatically splits it into rows

I think there's a maximum width for Display commands, beyond which it'll be split into two or more rows. Try adding a check to limit gTransparent.Width, e.g.:
Code: ags

  gTransparent.Width = GetTextWidth(text, 0) + 10;
  if (gTransparent.Width > 240) gTransparent.Width = 240;
  gTransparent.Height = GetTextHeight(text, 0, gTransparent.Width) + 10;


(240, because it looks like about 3/4 of the screen - fiddle with the value until it works.)
I know what you're thinking ... Don't think that.

InCreator

I did this, thanks! (I actually figured it out a bit earlier than you posted)
Anyway, it works, sort of... or atleast as long as I'm extra careful with text passed to function AND make manual line separations by using "[" in strings. Doesn't look very good though.


SupSuper

To get around the sizing issue, I think you'd have to use a fixed width:
Code: ags

function DisplayTransparent(String text)
{
  int width = System.ScreenWidth * 0.8; // the fixed width. change this value as preferred
  int height = GetTextHeight(text, 0, width) + margin;
  gTransparent.Width = width + 10;
  gTransparent.Height = height + 10;
  gTransparent.Centre();
  gTransparent.Visible = true;
  Wait(1);
  DisplayAt((System.ScreenWidth - width) / 2, (System.ScreenHeight - height) / 2, width, text);
  gTransparent.Visible = false;
}


At this rate this'll become a whole module. :P
Programmer looking for work

SMF spam blocked by CleanTalk