Changeset 48:d853401b7307 in xplra


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

Added support for moving and resizing the message area

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

Legend:

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

    r47 r48  
    4242using hu::varadiistvan::xplcommon::Util;
    4343
     44using std::min;
     45using std::max;
     46
    4447//------------------------------------------------------------------------------
    4548
     
    159162bool MessageWindow::handleMouseClick(int x, int y, XPLMMouseStatus mouse)
    160163{
    161     Util::debug("hu.varadiistvan.xplra.MessageWindow.handleMouseClick: x=%d, y=%d, mouse=0x%04x\n",
    162                 x, y, mouse);
     164    if (mouse==xplm_MouseDown) {
     165        if (x <= (left + resizeArea) ) {
     166            mouseMode = MOUSE_RESIZE_LEFT;
     167        } else if (x > (right-resizeArea) ) {
     168            mouseMode = MOUSE_RESIZE_RIGHT;
     169        } else {
     170            mouseMode = MOUSE_MOVE;
     171        }
     172        clickedX = x;
     173        clickedY = y;
     174    } else if (mouse==xplm_MouseDrag) {
     175        int xDiff = x - clickedX;
     176
     177        if (mouseMode==MOUSE_MOVE) {
     178            int newLeft = left + xDiff;
     179            int newRight = right + xDiff;
     180
     181            int screenWidth = XPLMGetDatai(widthDataRef);
     182            if (newLeft>=0 && newRight<screenWidth) {
     183                left = newLeft;
     184                right = newRight;
     185            }
     186
     187            int yDiff = y - clickedY;
     188            int newTop = top + yDiff;
     189            int newBottom = bottom + yDiff;
     190
     191            int screenHeight = XPLMGetDatai(heightDataRef);
     192            if (newTop<screenHeight && newBottom>=0) {
     193                top = newTop;
     194                bottom = newBottom;
     195            }
     196        } else if (mouseMode==MOUSE_RESIZE_LEFT) {
     197            int newLeft = left + xDiff;
     198            if (newLeft>=0 && (right-newLeft)>=minimalWidth) {
     199                left = newLeft;
     200            }
     201        } else if (mouseMode==MOUSE_RESIZE_RIGHT) {
     202            int newRight = right + xDiff;
     203            int screenWidth = XPLMGetDatai(widthDataRef);
     204            if (newRight<screenWidth && (newRight-left)>=minimalWidth) {
     205                right = newRight;
     206            }
     207        }
     208
     209        XPLMSetWindowGeometry(windowID, left, top, right, bottom);
     210
     211        clickedX = x;
     212        clickedY = y;
     213    }
     214
    163215    return true;
    164216}
  • src/plugin/src/xplra/MessageWindow.h

    r47 r48  
    6868                                        XPLMMouseStatus mouse, void* refCon);
    6969
     70
     71    /**
     72     * The minimal width of the message area.
     73     */
     74    static const int minimalWidth = 150;
     75
     76    /**
     77     * The size of the resize sensitivity area.
     78     */
     79    static const int resizeArea = 50;
     80
    7081private:
    7182    /**
     
    119130     */
    120131    float hideTime;
     132
     133    /**
     134     * The mouse mode
     135     */
     136    enum {
     137        // Move the message area
     138        MOUSE_MOVE,
     139
     140        // Resize the message area from the left
     141        MOUSE_RESIZE_LEFT,
     142
     143        // Resize the message area from the right.
     144        MOUSE_RESIZE_RIGHT
     145    } mouseMode;
     146
     147    /**
     148     * The X-coordinate where the window was clicked.
     149     */
     150    int clickedX;
     151
     152    /**
     153     * The Y-coordinate where the window was clicked.
     154     */
     155    int clickedY;
    121156
    122157    /**
Note: See TracChangeset for help on using the changeset viewer.