/************************************************************************* Handler for mouse button down events *************************************************************************/ void FrameWindow::onMouseButtonDown(MouseEventArgs& e) { // default processing (this is now essential as it controls event firing). Window::onMouseButtonDown(e); if (e.button == LeftButton) { if (isSizingEnabled()) { // get position of mouse as co-ordinates local to this window. Point localPos(CoordConverter::screenToWindow(*this, e.position)); // if the mouse is on the sizing border if (getSizingBorderAtPoint(localPos) != SizingNone) { // ensure all inputs come to us for now if (captureInput()) { // setup the 'dragging' state variables d_beingSized = true; d_dragPoint = localPos; e.handled = true; } } } } }
/************************************************************************* Handler for mouse move events *************************************************************************/ void FrameWindow::onMouseMove(MouseEventArgs& e) { // default processing (this is now essential as it controls event firing). Window::onMouseMove(e); // if we are not the window containing the mouse, do NOT change the cursor if (getGUIContext().getWindowContainingMouse() != this) { return; } if (isSizingEnabled()) { Vector2f localMousePos(CoordConverter::screenToWindow(*this, e.position)); if (d_beingSized) { SizingLocation dragEdge = getSizingBorderAtPoint(d_dragPoint); // calculate sizing deltas... float deltaX = localMousePos.d_x - d_dragPoint.d_x; float deltaY = localMousePos.d_y - d_dragPoint.d_y; URect new_area(d_area); bool top_left_sizing = false; // size left or right edges if (isLeftSizingLocation(dragEdge)) { top_left_sizing |= moveLeftEdge(deltaX, new_area); } else if (isRightSizingLocation(dragEdge)) { top_left_sizing |= moveRightEdge(deltaX, new_area); } // size top or bottom edges if (isTopSizingLocation(dragEdge)) { top_left_sizing |= moveTopEdge(deltaY, new_area); } else if (isBottomSizingLocation(dragEdge)) { top_left_sizing |= moveBottomEdge(deltaY, new_area); } setArea_impl(new_area.d_min, new_area.getSize(), top_left_sizing); } else { setCursorForPoint(localMousePos); } } // mark event as handled ++e.handled; }
/************************************************************************* Handler for mouse move events *************************************************************************/ void FrameWindow::onMouseMove(MouseEventArgs& e) { // default processing (this is now essential as it controls event firing). Window::onMouseMove(e); // if we are not the window containing the mouse, do NOT change the cursor if (System::getSingleton().getWindowContainingMouse() != this) { return; } if (isSizingEnabled()) { Point localMousePos(CoordConverter::screenToWindow(*this, e.position)); if (d_beingSized) { SizingLocation dragEdge = getSizingBorderAtPoint(d_dragPoint); // calculate sizing deltas... float deltaX = localMousePos.d_x - d_dragPoint.d_x; float deltaY = localMousePos.d_y - d_dragPoint.d_y; // size left or right edges if (isLeftSizingLocation(dragEdge)) { moveLeftEdge(deltaX); } else if (isRightSizingLocation(dragEdge)) { moveRightEdge(deltaX); } // size top or bottom edges if (isTopSizingLocation(dragEdge)) { moveTopEdge(deltaY); } else if (isBottomSizingLocation(dragEdge)) { moveBottomEdge(deltaY); } } else { setCursorForPoint(localMousePos); } } // mark event as handled e.handled = true; }
/************************************************************************* Handler for when mouse buttons are pushed *************************************************************************/ void ListHeaderSegment::onMouseButtonDown(MouseEventArgs& e) { // base class processing Window::onMouseButtonDown(e); if (e.button == LeftButton) { // ensure all inputs come to us for now if (captureInput()) { // get position of mouse as co-ordinates local to this window. Point localPos(CoordConverter::screenToWindow(*this, e.position)); // store drag point for possible sizing or moving operation. d_dragPoint = localPos; // if the mouse is in the sizing area if (d_splitterHover) { if (isSizingEnabled()) { // setup the 'dragging' state variables d_dragSizing = true; } } else { d_segmentPushed = true; } } ++e.handled; } }
/************************************************************************* check local pixel co-ordinate point 'pt' and return one of the SizingLocation enumerated values depending where the point falls on the sizing border. *************************************************************************/ FrameWindow::SizingLocation FrameWindow::getSizingBorderAtPoint(const Point& pt) const { Rect frame(getSizingRect()); // we can only size if the frame is enabled and sizing is on if (isSizingEnabled() && isFrameEnabled()) { // point must be inside the outer edge if (frame.isPointInRect(pt)) { // adjust rect to get inner edge frame.d_left += d_borderSize; frame.d_top += d_borderSize; frame.d_right -= d_borderSize; frame.d_bottom -= d_borderSize; // detect which edges we are on bool top = (pt.d_y < frame.d_top); bool bottom = (pt.d_y >= frame.d_bottom); bool left = (pt.d_x < frame.d_left); bool right = (pt.d_x >= frame.d_right); // return appropriate 'SizingLocation' value if (top && left) { return SizingTopLeft; } else if (top && right) { return SizingTopRight; } else if (bottom && left) { return SizingBottomLeft; } else if (bottom && right) { return SizingBottomRight; } else if (top) { return SizingTop; } else if (bottom) { return SizingBottom; } else if (left) { return SizingLeft; } else if (right) { return SizingRight; } } } // deafult: None. return SizingNone; }