Changeset 50:d650ff7422a5 in xplra


Ignore:
Timestamp:
02/16/13 10:13:44 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 3 'hg:/home/ivaradi/xplane/hg/xplra' '/'>, 'public')
Message:

The font size is now taken into account and the maximal message length is considered

Location:
src/plugin/src/xplra
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/plugin/src/xplra/MessageWindow.cc

    r49 r50  
    4242using hu::varadiistvan::xplcommon::Util;
    4343
     44using std::string;
    4445using std::min;
    4546using std::max;
     
    7677
    7778MessageWindow::MessageWindow() :
     79    maxMessageLength(0),
    7880    showForced(false),
    7981    hideTime(0.0),
     
    8991    heightDataRef = XPLMFindDataRef("sim/graphics/view/window_height");
    9092
     93    int digitsOnly = 0;
     94    XPLMGetFontDimensions(xplmFont_Basic, &fontWidth, &fontHeight, &digitsOnly);
     95
     96    Util::debug("hu.varadiistvan.xplra.MessageWindow: fontWidth=%d, fontHeight=%d\n",
     97                fontWidth, fontHeight);
     98
    9199    resetLocation();
    92100
     
    148156        XPLMDrawTranslucentDarkBox(left, top, right, bottom);
    149157        if (hideTime!=0.0) {
    150             XPLMDrawString(colour, left + 25, top - 15,
    151                            const_cast<char*>(displayedMessage.c_str()), 0,
     158
     159            string dm(displayedMessage, 0, maxMessageLength);
     160
     161            XPLMDrawString(colour,
     162                           left + horizontalMarginSize,
     163                           bottom + verticalMarginSize + baseLineSize,
     164                           const_cast<char*>(dm.c_str()), 0,
    152165                           xplmFont_Basic);
    153166        }
     
    208221            if (newLeft>=0 && (right-newLeft)>=minimalWidth) {
    209222                left = newLeft;
     223                recalculateMaxMessageLength();
    210224            }
    211225        } else if (mouseMode==MOUSE_RESIZE_RIGHT) {
     
    214228            if (newRight<screenWidth && (newRight-left)>=minimalWidth) {
    215229                right = newRight;
     230                recalculateMaxMessageLength();
    216231            }
    217232        }
    218233
    219234        XPLMSetWindowGeometry(windowID, left, top, right, bottom);
    220 
    221         // clickedX = x;
    222         // clickedY = y;
    223235    }
    224236
     
    267279    //             screenWidth, screenHeight);
    268280
    269     left = 50; right = screenWidth - left;
    270     top = screenHeight * 9 / 10; bottom = top - 25;
     281    left = 50;
     282    right = screenWidth - left;
     283
     284    top = screenHeight * 9 / 10;
     285    bottom = top - fontHeight - 2*verticalMarginSize;
     286
     287    recalculateMaxMessageLength();
     288}
     289
     290//------------------------------------------------------------------------------
     291
     292void MessageWindow::recalculateMaxMessageLength()
     293{
     294    maxMessageLength = (right + 1 - left) - 2 * horizontalMarginSize;
     295    maxMessageLength /= fontWidth;
    271296}
    272297
  • src/plugin/src/xplra/MessageWindow.h

    r49 r50  
    7979    static const int resizeArea = 50;
    8080
     81    /**
     82     * The size of the margins at each side of the window.
     83     */
     84    static const int horizontalMarginSize = 25;
     85
     86    /**
     87     * The size of the margins at the top and the bottom of the window.
     88     */
     89    static const int verticalMarginSize = 5;
     90
     91    /**
     92     * The size for the baseline above the bottom of the letters.
     93     */
     94    static const int baseLineSize = 2;
     95
    8196private:
    8297    /**
     
    91106
    92107    /**
     108     * The width of one character of the font.
     109     */
     110    int fontWidth;
     111
     112    /**
     113     * The height of one character of the font.
     114     */
     115    int fontHeight;
     116
     117    /**
    93118     * The window ID.
    94119     */
     
    114139     */
    115140    int bottom;
     141
     142    /**
     143     * The maximal message length.
     144     */
     145    int maxMessageLength;
    116146
    117147    /**
     
    257287     */
    258288    void resetLocation();
     289
     290    /**
     291     * Recalculate the maximal message length.
     292     */
     293    void recalculateMaxMessageLength();
    259294
    260295    friend class MessageRequest;
Note: See TracChangeset for help on using the changeset viewer.