Scrolling a label

Started by Construed, Wed 14/03/2012 01:07:57

Previous topic - Next topic

Construed

I know this has been brought up before, But I've finally come to the point wherin I have absolutely no choice in using a textbox or listbox.
I have to figure out how to scroll a label if there is any way possible at all, please let me know.

Thanks very much in advance,

-Jared
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

steptoe

It's not over until the fat lady sings..

Construed

Like I said I cannot use a textbox or listbox ^
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

steptoe

Perhaps you could explain more about what you are trying to achieve.
It's not over until the fat lady sings..

WHAM

#4
Dear Jared
Here is what I do (and this should be in the beginners area, btw):

Let's say I want to have a "window" with text that can be scrolled, that is 200x140 px in size.

1. Create new GUI "gui_textwindow" that is 200x140 px in size.
2. Create a label "lab_content" inside the new GUI, that is 200x3000 px in size, position it so that it's top is at the top of the GUI
3. Create an int -variable called "labelYpos" with default value of 0. Whenever the gui_textwindow is opened, reset this to 0 and reset lab_content's Y position to it's default value
4. Create a couple of buttons that move "lab_content" up or down by changing it's Y coordinate by, let's say: 30 px increments
5. When player presses the button that moves the label up, check if labelYpos is greater than 0 before allowing the action
6. When player presses the button that moves the label up, check if labelYpos is less than 1000 or if you implement a way to calculate rows you can refer to that too, before allowing the action

You now have a scrolling label with automatic word-wrap.

For examples of this in use, download my He Watches demo and scroll the objectives or something, I did it like this.
Wrongthinker and anticitizen one. Pending removal to memory hole. | WHAMGAMES proudly presents: The Night Falls, a community roleplaying game

Construed

#5
That is indeed some solid advice and it gets me halfway where I'm going :D
However the label function I'm using depends on user entered text.and has a function in it that doesn't move the text upward until it reaches the bottom of the label.
Code: ags

void PushLine(String line)
{
  if (line.Length > LINE_WIDTH)
  {
    
    PushLine(line.Truncate(LINE_WIDTH));
    PushLine(line.Substring(LINE_WIDTH, line.Length - LINE_WIDTH));
    return;
  }
  
  String text;

  text = String.Format("%s[%s", lblOutput.Text, line);

  int i = text.Length;
  int count = 0;
  int pos = -1;
  while (i)
  {
    if (text.Chars[i] == '[')
      count++;
    
    if (count == LINE_COUNT)
    {
      
      pos = i;
      i = 0;
      
    }
    else
    
      i--;
  }
  // lblOutput
  lblOutput.Text = text.Substring(pos + 1, text.Length - pos - 1);
}

and these definitions tell it how many lines are allowed in the label
and how many characters are allowed in a line.
#define LINE_WIDTH 40 // Max number of characters on a line
#define LINE_COUNT 10 // Max number of lines in the textbox

The problem is, if the label extends too far past the bottom of the gui the text in the label keeps being printed under the last line until it reaches the bottom of the label and remains unseen.

I appreciate the responses greatly!
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Construed

#6
Well, I figured out a very simple solution.

Code: ags

lblOutput.Height+=7;
lblOutput.Y-=7;

Only problem is that after so many lines of text appear in the label it cannot print anymore, instead it prints half of the line with ... after it.

I was wondering if there is a maximum amount of lines allowed in a label and if so, what is it?

[edit]
I'm getting the problem after approximately 50 lines.
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Construed

Nevermind I found this:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=42832.0
Good thing the moderators didn't delete it I guess :)
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

WHAM

I think the actual limit of labels is around 1000 characters, as that is the length at which I started having problems in BBWD. To be safe I made a function that caps the string off at 750 characters and no problems since.
Wrongthinker and anticitizen one. Pending removal to memory hole. | WHAMGAMES proudly presents: The Night Falls, a community roleplaying game

SMF spam blocked by CleanTalk