Problem setting Height in dialog_options_get_dimensions [Solved]

Started by Hernald, Sun 02/09/2012 03:48:22

Previous topic - Next topic

Hernald

I hope this is a simple scripting problem.
I am creating a custom dialog and no matter what I try the Height of the options box is rendered at what seems to be an arbitary value.
The code is picking up the right dialog, and calculating the number of options and the Height correctly, but this Height and corresponding Y value are not being used.
Here is the code:

Code: AGS


function dialog_options_get_dimensions(DialogOptionsRenderingInfo *info){
  int ocount;
  int oindex;
  ocount=0;
  oindex=1;
 
  info.Y = 470;
  info.Height = 0; 
 
 
  while (oindex <= info.DialogToRender.OptionCount) {
    if (info.DialogToRender.GetOptionState(oindex) == eOptionOn) {
      info.Y -=8;
      info.Height +=8;
      ocount++;
    }
    oindex++;
  }
  vDialogNo=info.DialogToRender.ID;
  vOptionCount=ocount;
  vDialogHeight=info.Height;

  info.X = 40;

  info.Width = 560;

}



Any help or advice appreciated.

Khris

A shot in the dark:

Code: ags
function dialog_options_get_dimensions(DialogOptionsRenderingInfo *info){
  int ocount, oindex = 1;
 
  while (oindex <= info.DialogToRender.OptionCount) {
    if (info.DialogToRender.GetOptionState(oindex) == eOptionOn) ocount++;
    oindex++;
  }

  vDialogNo = info.DialogToRender.ID;
  vOptionCount = ocount;
  vDialogHeight = ocount * 8;
 
  info.X = 40;
  info.Y = 470 - ocount * 8;
  info.Height = ocount * 8;
  info.Width = 560;
}

It shouldn't make any difference though, and I can't really see what's wrong with the original code. The only thing that's different is I'm not setting info's fields multiple times.

cat

Are you sure you handle it correctly in dialog_options_render?

Hernald

Khris: Yes, I had tried it that way earlier; anything other than a simple uncalculated integer seems to come out wrong;
cat: The dialog_options_render is taken straight from the manual with just the background colour and font changed. Okay I'll post it in case I've messed something up:
Code: AGS


function dialog_options_render(DialogOptionsRenderingInfo *info)
{
  // Clear the area pale green
  info.Surface.Clear(36269);
  int i = 1,  ypos = 0;
  // Render all the options that are enabled
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      if (info.ActiveOptionID == i) info.Surface.DrawingColor = 13;
      else info.Surface.DrawingColor = 4;
      info.Surface.DrawStringWrapped(5, ypos, info.Width - 10, 
                         eFontNormal, eAlignLeft, info.DialogToRender.GetOptionText(i));
      ypos += GetTextHeight(info.DialogToRender.GetOptionText(i), eFontNormal, info.Width - 10);
    }
    i++;
  }
}


Thank you both for coming back to me, but I'm afraid I'm still in the dark...

Hernald

cat: You were right! The problem was caused by me not measuring the height of the rows of text in dialog_options_render.
I've simplified that code a bit and given the font more space and now it is working fine!
Thank you both for your input.

Khris

Just to clarify, the GUI wasn't tall enough because you always used a height of 8 pixels for an option, even if it spanned multiple lines, correct?

Hernald

Eight pixels was nowhere near enough for one line let alone multiple lines.
I've  copied up the GetTextHeight function from dialog_options_render to dialog_options_get_dimensions and now it works perfecly:
Code: AGS


function dialog_options_get_dimensions (DialogOptionsRenderingInfo *info){
  int ocount=0, oindex=1;
  
  
  info.X = 40;
  info.Width = 560;
  vDialogHeight=0;
  
  while (oindex <= info.DialogToRender.OptionCount) {
    if (info.DialogToRender.GetOptionState(oindex) == eOptionOn) {
      vDialogHeight+=GetTextHeight(info.DialogToRender.GetOptionText(oindex), eFontSpeech, info.Width - 10);
      ocount++;
    }
    oindex++;
  }

  vOptionCount=ocount;
    
  info.Y = 470 - vDialogHeight;
  
  info.Height = vDialogHeight;
  
  vDialogNo=info.DialogToRender.ID;

}

It was a basic programming issue as I'd hoped; I guess I'd been at it for a while and needed to give my brain a rest, and a fresh perspective.





SMF spam blocked by CleanTalk