Problems with GUI position

Started by InCreator, Wed 07/09/2005 23:30:05

Previous topic - Next topic

InCreator

I've been messing with this problem with ages...

Objective: Transclusent text window GUI

Method: since text windows *still* don't support gGui.Transparency, I made text window gui totally transparent (background image - none, bg color 0) and I'm trying to use another (transparent) gui over (under) it, so it had a semi-transparent background.
Since this other gui must be at the same size and position as the text window, I have to resize and reposition it every time text is Displayed. But hey, there's gGui.X, gGui.Y, gGui.Width and gGui.Height properties, just what I need. But there's also a...

Problem: Where and how do I use these commands to make other gui appear in right time, size and place? Does it work at all, I mean

-Let's say that other gui is named "other" and text window one as "text"-

gOther.X = gText.X;
gOther.Width = gText.Width;

and so forth.

Question
Does it work? I mean, do text windows have those properties/variables? (AGS 2.7)
Where do I have to put those lines to keep size updated at time? (text windows stretch and reposition according to text length!)

BTW, this is what I want to achieve:

strazer

#1
The properties of the GUI used for text windows don't seem to change when text is displayed on it, so even trying to resize the transparent GUI via repeatedly_execute_always won't work.

Following your approach, you could try calculating the dimensions yourself and activate the GUI shortly before the Display call, like this:

Code: ags

// global script

function DisplaySpecial(string message) {

  int textwidth = GetTextWidth(message, 0);
  if (textwidth > 233) textwidth = 233; // not quite accurate, see note 2 below
  gOther.Width = textwidth + 4; // 4 = border
  gOther.Height = GetTextHeight(message, 0, textwidth) + 4; // 4 = border
  gOther.Centre();
  gOther.Visible = true;
  Wait(1);
  Display(message);
  gOther.Visible = false;
  Wait(1);

}


Code: ags

// main script header

import function DisplaySpecial(string message);


Problems with this code:

1.) Doesn't work with text containing manual line breaks because GetTextWidth returns the width of the text including the [ line break character.
2.) If text is wider than 233 pixels (in my tests this seems to be the maximum width for Display texts) and gets wrapped, it's hard to determine the exact width of the text window. Transparent GUI might be a tad too wide.

I don't think either of these is a big issue at the moment, so I won't work on this any further.
But I'm sure both can be solved, so if anyone is up for it, give it a go.

GarageGothic

Since you're writing your own function anyway, why stick to using Display()?

Just make your own GUI with a label to show text on, and set the size based on GetTextWidth and GetTextHeight commands (1) Get width, if it's wider than max width then  2) GetTextHeight using max widt and 3) Set the label to this height/width + a few pixels of slack space). That way you could would know the exact dimension of gText and could set gOther to the same (+ margins).

strazer

Wouldn't you have to insert line breaks manually into the text? GUI labels don't wrap automatically, do they?

InCreator

#4
They DO.
And I started making own display() even before strazer answered to this thread, thing is - his code helps to fix new GUIs size, according to text.

Thanks for help.

But there's another problem: While new GUI can be clickable, the text label can not. So I can't remove text by clicking onto it and must catch either the sides of the GUI or make a little "close" button for GUI. Any ideas to work around this?

This is how far I am right now:


Making separate GUI instead of "text window" is good, because you can't choose font on default text window! CJ should really make a nice optimizable text window... with all variables needed. But until then, separate GUI will be the best option to work around.

GarageGothic

#5
Do you need to click on the actual window to close it, isn't anyclick while it's displayed enough?

In any case, if you want the gui to disappear when you click it, just put code for GUIGetAt or whatever that command is called in the on_mouse_click event (if IsGamePaused and gText.Visible == true).

Edit: The easiest thing would be to make gText non-clickable and just check gOther, as that covers the whole area.

Edit 2: BTW, you can choose font on normal text window - SetNormalFont I believe the command is called.

Wretched

Coincidently I was trying to do this today and eventually did it with 2 GUIS. One GUI with just the Text in a label, second GUI with 9 buttons which immitates the Text Window GUI.
Use button.ClipGraphic with extra large sprites to give effectivly scaleable sprites for the edges and centre.
Had to write a GetTextWidth(string Text,int Font,int Width) function which AGS lacks.

Anyway works fine... and you can have a free drop shadow effect.

monkey0506

Quote from: Wretched on Thu 08/09/2005 23:57:26Had to write a GetTextWidth(string Text,int Font,int Width) function which AGS lacks.

What?  AGS does have a GetTextWidth function, but why do you have an int Width parameter?

Wretched

monkey_05_06,
Because of the auto wrap on long strings can produce many different widths depending on how the words line up. Just because you ask for a width of say 100, only means the text will not be more than 100 wide, could be anything less than 100. My GetTextWidth(string Text,int Font,int Width), calculates the length of each line of wrapped text and returns the greatest.

SMF spam blocked by CleanTalk