A minor enhancement to help laying out rows/columns of text

If you found a bug in our library or on our website, please report it in this section. In this forum you can also make concrete suggestions or feature requests.

Moderators: CEGUI MVP, CEGUI Team

User avatar
thumperj
Not too shy to talk
Not too shy to talk
Posts: 30
Joined: Wed Jan 12, 2005 12:06
Location: Austin, TX
Contact:

A minor enhancement to help laying out rows/columns of text

Postby thumperj » Sun Oct 10, 2004 22:27

Hopefully someone hasn't already requested this *or* it's not already in the code and I just plain missed it! Heh.

With text displaying classes (StaticText, for example) to make it easier to align rows and columns of strings tightly together, it'd be great to have 1 or 2 more functions:
1. A function that "shrinks" the size of the widget to fit perfectly around the given text, -or-
2. A way to query what the size of a given text string (so I can set the widget to that size). I'm thinking something like a GetTextExtent in Win32 world.

:)

Thanks very much!
Chris

User avatar
jwace81
Not too shy to talk
Not too shy to talk
Posts: 26
Joined: Wed Jan 12, 2005 12:06

A minor enhancement to help laying out rows/columns of text

Postby jwace81 » Mon Oct 11, 2004 00:15

1. AFAIK this does not currently exist.

2. You can query the Font to get the measurements for the rendered string. in fact, the function is names getTextExtent().

I believe that spannerman has attempted to do essentially the same thing and came up with a solution. You might want to look for his post.

J.W.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

A minor enhancement to help laying out rows/columns of text

Postby CrazyEddie » Mon Oct 11, 2004 08:34

1. A function that "shrinks" the size of the widget to fit perfectly around the given text,

It's possible, but not something I really want to do at the moment :)

2. A way to query what the size of a given text string (so I can set the widget to that size). I'm thinking something like a GetTextExtent in Win32 world.

See jwace81's reply ;)

CE.

User avatar
thumperj
Not too shy to talk
Not too shy to talk
Posts: 30
Joined: Wed Jan 12, 2005 12:06
Location: Austin, TX
Contact:

A minor enhancement to help laying out rows/columns of text

Postby thumperj » Wed Nov 03, 2004 20:07

We will be releasing the source code when the editor is done, but if you are interested I can show you the code of how I implemented it if you like.


If it's not too much trouble..... :) I'm am gearing up to be doing a lot of coding and I'm trying to setup things so that it is as easy (and bug-free) as possible. Heck the whole tooltip code would be cool so I can read and learn from it. But what ever you would be willing to share.

Thanks,
Chris

User avatar
spannerman
Home away from home
Home away from home
Posts: 330
Joined: Wed Jan 12, 2005 12:06

A minor enhancement to help laying out rows/columns of text

Postby spannerman » Wed Nov 03, 2004 23:06

Well, this code is the bulk of the business, and its pretty hardwired to suit our specific needs, but hopefully it will be useful. Bear in mind that the ToolTip referred to in this code is simply a StaticText panel, and everything is in Relative mode.

Code: Select all

...
// Set the toolTip text with the new String
ToolTip->setText(stringTip);

// Begin calulating tooltip size

Window* sheet = System::getSingleton().getGUISheet();
const CEGUI::Font* fnt = ToolTip->getFont();

float textWidth = 0;
float textHeight = 0;

// The padding is the Static Text Widgets border area, with some extra pixels for good measure. Set to Relative Mode.
float paddingWidth = sheet->absoluteToRelativeX( 14 );
float paddingHeight = sheet->absoluteToRelativeY( 14 );

// Set limits of the tooltip size for later use
maxTooltipWidth = sheet->getRelativeWidth() * 0.5;
maxTooltipHeight = sheet->getRelativeHeight() * 0.5;

// Setup some sizes just to get a Rect area.
ToolTip->setSize(Size(maxTooltipWidth, maxTooltipHeight));

Rect absarea(ToolTip->getUnclippedInnerRect());

// Calculate what height this string will take up.
textHeight = fnt->getFormattedLineCount( stringTip, absarea, WordWrapLeftAligned) * fnt->getLineSpacing();
textHeight = sheet->absoluteToRelativeY( textHeight );

// Calculate what width this string will take up.
textWidth = fnt->getFormattedTextExtent( stringTip, absarea, WordWrapLeftAligned);
textWidth = sheet->absoluteToRelativeX( textWidth );

// Set the new size.
ToolTip->setSize(Size( (textWidth + paddingWidth), (textHeight + paddingHeight) ));

// Force it to show in case it was hidden
ToolTip->show();
...


Hope that helps.

User avatar
thumperj
Not too shy to talk
Not too shy to talk
Posts: 30
Joined: Wed Jan 12, 2005 12:06
Location: Austin, TX
Contact:

A minor enhancement to help laying out rows/columns of text

Postby thumperj » Fri Nov 05, 2004 02:34

Great, thanks spannerman.

I appreciate it.
Chris

User avatar
thumperj
Not too shy to talk
Not too shy to talk
Posts: 30
Joined: Wed Jan 12, 2005 12:06
Location: Austin, TX
Contact:

A minor enhancement to help laying out rows/columns of text

Postby thumperj » Wed Dec 01, 2004 21:37

Hey, spannerman-

How are you triggering the pop-ups based off a delay? In other words, how are you counting time passing with nothing happening in the system?

Thanks for the hint,
Chris

User avatar
spannerman
Home away from home
Home away from home
Posts: 330
Joined: Wed Jan 12, 2005 12:06

A minor enhancement to help laying out rows/columns of text

Postby spannerman » Thu Dec 02, 2004 13:24

Hi,

Really we should move this thread to the Help forum.

How are you triggering the pop-ups based off a delay? In other words, how are you counting time passing with nothing happening in the system?


Well, I am using an OGRE framelistener to give me the time since the last frame. So every frame, I just send the time to a method in my ToolTip class. If the tooltip should be showing, I increment some local variables until the delay is over, then I show the tooltip. If the tooltip has been showing long enough, I fade it out by slowly decrementing the tips alpha value, using the time value. Heres the method with the meat:

Code: Select all

void PEToolTip::updateToolTipTime(float time)
{
   if (showingTip && tipsEnabled)
   {
      incTipTime = incTipTime + (0.1f * time);

                                // Wait for delay until showing tooltip
      if ( (incTipTime > tipTimeDelay) && (incTipTime < tipTimeCutoff))
      {
         tipAlpha = 1.0f;

         updateToolTip();
      }
                                // Wait for cut off time until fading out tooltip
      else if (incTipTime > tipTimeCutoff)
      {
         tipAlpha = tipAlpha - (0.5f * time);

         if (tipAlpha < 0.0f)
         {
            hideToolTip();
         }
         else
         {
            updateToolTip();
         }
      }

   }
}


Here's the updateToolTip() method, which really just sets the position and the alpha:

Code: Select all

void PEToolTip::updateToolTip()
{
   Window* sheet = System::getSingleton().getGUISheet();

   Point toolPos = MouseCursor::getSingleton().getDisplayIndependantPosition();

   // Get tooltip sizes with a bit of buffering
   float toolWidth = ToolTip->getWidth() + 0.002f;
   float toolHeight = ToolTip->getHeight() + 0.002f;

   // Shimmy height above cursor
   toolPos.d_y = toolPos.d_y - toolHeight;

   float testLength = toolPos.d_x + toolWidth;

   if (testLength > sheet->getRelativeWidth())
   {
      toolPos.d_x = sheet->getRelativeWidth() - toolWidth;
   }

   if (toolPos.d_y < 0)
   {
      toolPos.d_y = 0;
   }

   ToolTip->setPosition( Point(toolPos.d_x, toolPos.d_y) );
   ToolTip->setAlpha(tipAlpha);
}



Return to “Bug Reports, Suggestions, Feature Requests”

Who is online

Users browsing this forum: No registered users and 3 guests