| 452 | //----------------------------------------------------------------------------- |
| 453 | |
| 454 | bool GuiControl::defaultTooltipRender( const Point2I &hoverPos, const Point2I &cursorPos, const char* tipText ) |
| 455 | { |
| 456 | // Short Circuit. |
| 457 | if (!mAwake) |
| 458 | return false; |
| 459 | |
| 460 | if ( dStrlen( mTooltip ) == 0 && ( tipText == NULL || dStrlen( tipText ) == 0 ) ) |
| 461 | return false; |
| 462 | |
| 463 | String renderTip( mTooltip ); |
| 464 | if ( tipText != NULL ) |
| 465 | renderTip = tipText; |
| 466 | |
| 467 | // Need to have root. |
| 468 | GuiCanvas *root = getRoot(); |
| 469 | if ( !root ) |
| 470 | return false; |
| 471 | |
| 472 | GFont *font = mTooltipProfile->mFont; |
| 473 | |
| 474 | GFXDrawUtil* drawUtil = GFX->getDrawUtil(); |
| 475 | |
| 476 | // Support for multi-line tooltip text... |
| 477 | |
| 478 | Vector<U32> startLineOffsets, lineLengths; |
| 479 | |
| 480 | font->wrapString( renderTip, U32_MAX, startLineOffsets, lineLengths ); |
| 481 | |
| 482 | // The width is the longest line. |
| 483 | U32 tipWidth = 0; |
| 484 | for ( U32 i = 0; i < lineLengths.size(); i++ ) |
| 485 | { |
| 486 | U32 width = font->getStrNWidth( renderTip.c_str() + startLineOffsets[i], lineLengths[i] ); |
| 487 | |
| 488 | if ( width > tipWidth ) |
| 489 | tipWidth = width; |
| 490 | } |
| 491 | |
| 492 | // The height is the number of lines times the height of the font. |
| 493 | U32 tipHeight = lineLengths.size() * font->getHeight(); |
| 494 | |
| 495 | // Vars used: |
| 496 | // Screensize (for position check) |
| 497 | // Offset to get position of cursor |
| 498 | // textBounds for text extent. |
| 499 | Point2I screensize = getRoot()->getWindowSize(); |
| 500 | Point2I offset = hoverPos; |
| 501 | Point2I textBounds; |
| 502 | |
| 503 | // Offset below cursor image |
| 504 | offset.y += 20; // TODO: Attempt to fix?: root->getCursorExtent().y; |
| 505 | |
| 506 | // Create text bounds... |
| 507 | |
| 508 | // Pixels above/below the text |
| 509 | const U32 vMargin = 2; |
| 510 | // Pixels left/right of the text |
| 511 | const U32 hMargin = 4; |
nothing calls this directly
no test coverage detected