Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Gepard on Sat 25/08/2007 19:40:30

Title: Labels scrolling - SOLVED
Post by: Gepard on Sat 25/08/2007 19:40:30
Hello, I have this kind of problem:

I have a Gui with two labels, but there is a limited space so both labels are small and there is not enough room for the whole text. Im wondering if I can make a scrolling label to see the rest of the text. I know I can scroll up inventory windows and listboxes but what about labels?

Thanks in advance.
Title: Re: Labels scrolling
Post by: Khris on Sat 25/08/2007 20:16:55
You could make the text scroll manually by using a variable that gets de-/incremented, then putting only a part of the original string on the label.
int index[5];
int labeltext[5];

String scroll_text(int i, int width, bool left) {
  if (left && index[i]>0) index[i]--;
  if (!left && index[i]<labeltext[i].length-width) index[i]++;
  return labeltext[i].Substring(index[i], width);
}

// game_start
labeltext[1]="This is a scrolling message.";

// scroll left
  label1.Text=scroll_text(1, 10, true);

// scroll right
  label1.Text=scroll_text(1, 10, false);

This will look best if you use a fixed-width font.
Title: Re: Labels scrolling
Post by: Gepard on Sat 25/08/2007 20:27:35
Uh... Im not that advanced. Is there some easier way to do this? Maybe I can cut the text into parts and let the label to show the first part. After that the player will be allowed to click a gui button and the label will show the second part of the message. What say you? :f )
Title: Re: Labels scrolling
Post by: Ashen on Sun 26/08/2007 13:30:59
Someone's done the work for you, what's easier than that? ;)
It's not actually that complicated a script, and it's probably the neatest, simplest way to do what you want. Except that I think:

int labeltext[5];


Should be:

String labeltext[5];


Cutting the text into chunks might make it fit better - as I understand it, Khris' code displays a set number of characters (the width pararmeter) rather than an approximate length (best fit for Label.Width) which is why he recommends a fixed-width font - but otherwise the code would probably be much the same. You'd still need some way to store what blocks belong together, in what order, and which is currently being used so you know where/whether to scroll. If it's just going to be two blocks per label that never change, using if ... else might be practical; otherwise you'll probably need arrays anyway, and more of them than Khris has.
You could try replacing the width parameter with a Label pointer, and use that to work out a pixel width for the part of the string to be displayed (keep adding a letter until the Substring is about as wide as the Label it's for).
Title: Re: Labels scrolling
Post by: Gepard on Sun 26/08/2007 16:36:00
Thanks for help. I will do what I can :f )
Title: Re: Labels scrolling - SOLVED
Post by: Baguettator on Tue 09/03/2021 16:33:01
Hi !

I wanted to do something like a scrollable label, but I wonder if the text won't be cutted in the middle of a word ?

To have a perfect scrollable label, we would need to "locate" the end of the last word of the last line, and cut the string after it ?

Is it possible to do such thing ?
Title: Re: Labels scrolling - SOLVED
Post by: Khris on Tue 09/03/2021 18:01:06
The label has a certain width in pixels, and so has the text. Scrolling by definition means the visible text is going to get cut off at arbitrary x coordinates since only a part of it will be visible. Cutting it off on a pixel basis is the easiest way to do this and will give a nice scrolling effect.

Are you asking how to scroll it word by word?
Title: Re: Labels scrolling - SOLVED
Post by: Baguettator on Tue 09/03/2021 18:25:55
In fact, I was talking about a vertical scrolling, and as I can see, your function was about a horizontal scrolling. But I believe that the vertical scrolling function would be pretty the same as yours for horizontal scrolling.

So your scrolling function is about pixel scrolling and not about line or word scrolling ?
Title: Re: Labels scrolling - SOLVED
Post by: Khris on Tue 09/03/2021 18:33:43
Right, I missed that this is about vertical scrolling :-D

Cutting a longer piece of text into lines of a certain maximum width without breaking up words is possible but tedious to program; you basically need to keep looking for the next whitespace character, append to the current line, check if it exceeds the maximum width, then start a new line if it does, etc.
You need an array of strings for the lines and  theString.IndexOf(" ")  to find spaces.
Title: Re: Labels scrolling - SOLVED
Post by: Baguettator on Tue 09/03/2021 18:39:57
Yes, but... labels do that actually, don't they ? I mean, cutting not at the middle of a word.
Title: Re: Labels scrolling - SOLVED
Post by: Khris on Tue 09/03/2021 19:59:24
Yes, but they don't support scrolling. I'd probably use a button, a DynamicSprite and DrawingSurface.DrawStringWrapped(), then crop the image according to the scrolling offset. That way you have consistent and automatic line wrapping.
Title: Re: Labels scrolling - SOLVED
Post by: Baguettator on Thu 11/03/2021 16:41:27
That's a very good idea ! I didn't figure out that it was possible, but now I understand that modules imitating notepad in AGS work this way, I think. I will try it !
Title: Re: Labels scrolling - SOLVED
Post by: Baguettator on Sat 20/03/2021 11:26:27
Hi there !

So I started the function for a "scrollable label".

It seems to be working with a button and a dynamic sprite and the DrawStringWrapped() function.

BUT the texts is drowed with like a bad quality. The font is not very polished (don't know if it is the english word for that, but in fact, I can see pixels very easily !).

Is there any possibility to have the DrawStringWrapped() in better quality ?

If not, I will maybe think for another solution.