Ignore:
Timestamp:
02/16/13 09:44:59 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added support for moving and resizing the message area

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.