Exact size of the TextRectangle?

Posted by Redisdead on Tue 14 Apr 2009 04:24 AM — 3 posts, 14,302 views.

#0
When using a negative number in TextRectangle's bottom argument (I suppose it does the same for other arguments too), the GetInfo(275) returns that negative number. It'd be nice if it'd return the actual bottom place of the TextRectangle.

Is there any way to calculate/get the current TextRectangle's height and width? I want to make an icon bar that fits exactly next to it.
Netherlands #1
You can calculate it. Have a look at GetInfo(). I believe selectors 280 and 281 are what you are looking for. Simple math can do the rest. :)

On a side note - if you want it pixel perfect, you'll also have to keep the border width and border offset in mind. It can be tricky to figure out how that works although with a bit of work you'll figure out how those values come into it.

The Previewer plugin I wrote a while back has a skin that does a fair amount of fiddling with the text rectangle to position it precisely below the text rectangle. You may want to check it out if you want something to look at, although it's a little bit of a mess (lacks comments and also does some other things not directly involving the textrectangle).
Amended on Tue 14 Apr 2009 09:28 AM by Worstje
Australia Forum Administrator #2
True, I prefer to return what you set it to, so if you need to alter it, you can.

The code to actually calculate the "real" rectangle is here (in C++):


// returns the text rectangle, if any, noramlized
RECT CMUSHView::GetTextRectangle (const bool bIncludeBorder)
  {
CMUSHclientDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

  CRect TextRectangle (pDoc->m_TextRectangle);

RECT r;

  GetClientRect (&r);

  if (pDoc->m_TextRectangle != CRect (0, 0, 0, 0))
    {
    // they can use -n on right/bottom to indicate offset from side

    if (TextRectangle.right <= 0)
      {
      TextRectangle.right += r.right;
      // ensure not negative
      TextRectangle.right = max (TextRectangle.right, TextRectangle.left + 20);
      }


    if (TextRectangle.bottom <= 0)
      {
      TextRectangle.bottom += r.bottom;
      // ensure not negative
      TextRectangle.bottom = max (TextRectangle.bottom, TextRectangle.top + 20);
      }

    if (bIncludeBorder)
      TextRectangle.InflateRect (pDoc->m_TextRectangleBorderOffset, pDoc->m_TextRectangleBorderOffset);

    return TextRectangle;
    }

  return r;

  } // end of CMUSHView::GetTextRectangle


Basically, pDoc->m_TextRectangle is what you supplied to the TextRectangle call.

The call to GetClientRect above returns the same as GetInfo 280 and 281, as Worstje said. So, armed with those pieces of information, you can calculate exactly what the program considers to the the rectangle at a given moment (bearing in mind it may change if you resize the window).