ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Text Box placement, predicting size before placement
Posted by DC Kelley on Mar-27-2011 10:02
I have a text box which I need to place in the lower left or right side of the graph, and do not see how I can tell it where to be placed until after it is in fact rendered to the chart.  Is there as way to "predict" the width and height values that will result with a given stream of text so the placement can be controlled?  Or, alternatively, can I specify another corner as the anchor point?

Code thoughts are...
   TextBox *textbox = c->addText(120, 85, buffer, "arialbd.ttf", 8); //sets upper left only
   textbox->setBackground(0xc0c0c0, 0, 1);
   int howBig = textbox->get Height(); // but this is after the fact
   // now adjust placement, but how??

Many thanks, DCK

  Re: Text Box placement, predicting size before placement
Posted by Peter Kwan on Mar-28-2011 15:09
Hi DC Kelley,

After you have obtain the size of the TextBox, you can still move it to another location using Box.setPos. (The TextBox is not yet rendered.)

You can also set the anchor point to the lower left corner. For example:

//the (120, 85) is treated as the lower left corner of the text box
TextBox *textbox = c->addText(120, 85, buffer, "arialbd.ttf", 8, Chart::BottomLeft); textbox->setBackground(0xc0c0c0, 0, 1);

Hope this can help.

Regards
Peter Kwan

  Re: Text Box placement, predicting size before placement
Posted by DC Kelley on Mar-29-2011 06:48
As is becoming a pleasant experience, your advice is on target and solves the need.
I wish other products in my life were as well supported.

  Re: Text Box placement, predicting size before placement
Posted by DC Kelley on Mar-29-2011 07:33
Hold on a sec, the Chart::BottomLeft (or other choices) does not seem to have any effect.  From what you said I expected it to affect where the textbox considered its own anchor point.  From what the documentation states, it seems to effect the alignment of how the text is drawn inside the box itself.  Can not both be right.   But when I programed up a fragment, there seem to be no effect at all on either.  Here is the frag I used, if there something obviously wrong with this?

   TextBox *textbox = c->addText(chartWidth/2, chartHeight/2, buffer, "arialbd.ttf", i, Chart::Center);
   textbox->setBackground(0xc0c0c0, 0, 1);
   // move it back to center it (forum fix does not work as expected)
   j = chartWidth/2  - (textbox->getWidth()/2);
   k = chartHeight/2 - (textbox->getHeight()/2);
   textbox->setPos(j,k);

  Re: Text Box placement, predicting size before placement
Posted by Peter Kwan on Mar-30-2011 01:45
Hi DC Kelley,

Sorry, I have left out one parameter in the code. It should be:

TextBox *textbox = c->addText(chartWidth/2, chartHeight/2, buffer, "arialbd.ttf", i, 0x000000, Chart::Center);

Hope this can help.

Regards
Peter Kwan