void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event) { int x = (int)event.GetX(), y = (int)event.GetY(); if ( GetWindowStyle() & wxSP_NOSASH ) { event.Skip(); return; } // with wxSP_LIVE_UPDATE style the splitter windows are always resized // following the mouse movement while it drags the sash, without it we only // draw the sash at the new position but only resize the windows when the // dragging is finished #if defined( __WXMAC__ ) && defined(TARGET_API_MAC_OSX) && TARGET_API_MAC_OSX == 1 bool isLive = true ; // FIXME: why? #else bool isLive = HasFlag(wxSP_LIVE_UPDATE); #endif if (event.LeftDown()) { if ( SashHitTest(x, y) ) { // Start the drag now m_dragMode = wxSPLIT_DRAG_DRAGGING; // Capture mouse and set the cursor CaptureMouse(); SetResizeCursor(); if ( !isLive ) { // remember the initial sash position and draw the initial // shadow sash m_sashPositionCurrent = m_sashPosition; DrawSashTracker(x, y); } m_oldX = x; m_oldY = y; SetResizeCursor(); return; } } else if (event.LeftUp() && m_dragMode == wxSPLIT_DRAG_DRAGGING) { // We can stop dragging now and see what we've got. m_dragMode = wxSPLIT_DRAG_NONE; // Release mouse and unset the cursor ReleaseMouse(); SetCursor(* wxSTANDARD_CURSOR); // exit if unsplit after doubleclick if ( !IsSplit() ) { return; } // Erase old tracker if ( !isLive ) { DrawSashTracker(m_oldX, m_oldY); } // the position of the click doesn't exactly correspond to // m_sashPosition, rather it changes it by the distance by which the // mouse has moved int diff = m_splitMode == wxSPLIT_VERTICAL ? x - m_oldX : y - m_oldY; int posSashOld = isLive ? m_sashPosition : m_sashPositionCurrent; int posSashNew = OnSashPositionChanging(posSashOld + diff); if ( posSashNew == -1 ) { // change not allowed return; } if ( m_permitUnsplitAlways || m_minimumPaneSize == 0 ) { // Deal with possible unsplit scenarios if ( posSashNew == 0 ) { // We remove the first window from the view wxWindow *removedWindow = m_windowOne; m_windowOne = m_windowTwo; m_windowTwo = (wxWindow *) NULL; OnUnsplit(removedWindow); wxSplitterEvent eventUnsplit(wxEVT_COMMAND_SPLITTER_UNSPLIT, this); eventUnsplit.m_data.win = removedWindow; (void)DoSendEvent(eventUnsplit); SetSashPositionAndNotify(0); } else if ( posSashNew == GetWindowSize() ) { // We remove the second window from the view wxWindow *removedWindow = m_windowTwo; m_windowTwo = (wxWindow *) NULL; OnUnsplit(removedWindow); wxSplitterEvent eventUnsplit(wxEVT_COMMAND_SPLITTER_UNSPLIT, this); eventUnsplit.m_data.win = removedWindow; (void)DoSendEvent(eventUnsplit); SetSashPositionAndNotify(0); } else { SetSashPositionAndNotify(posSashNew); } } else { SetSashPositionAndNotify(posSashNew); } SizeWindows(); } // left up && dragging else if ((event.Moving() || event.Leaving() || event.Entering()) && (m_dragMode == wxSPLIT_DRAG_NONE)) { if ( event.Leaving() || !SashHitTest(x, y) ) OnLeaveSash(); else OnEnterSash(); } else if (event.Dragging() && (m_dragMode == wxSPLIT_DRAG_DRAGGING)) { int diff = m_splitMode == wxSPLIT_VERTICAL ? x - m_oldX : y - m_oldY; if ( !diff ) { // nothing to do, mouse didn't really move far enough return; } int posSashOld = isLive ? m_sashPosition : m_sashPositionCurrent; int posSashNew = OnSashPositionChanging(posSashOld + diff); if ( posSashNew == -1 ) { // change not allowed return; } if ( posSashNew == m_sashPosition ) return; // Erase old tracker if ( !isLive ) { DrawSashTracker(m_oldX, m_oldY); } if (m_splitMode == wxSPLIT_VERTICAL) x = posSashNew; else y = posSashNew; // Remember old positions m_oldX = x; m_oldY = y; #ifdef __WXMSW__ // As we captured the mouse, we may get the mouse events from outside // our window - for example, negative values in x, y. This has a weird // consequence under MSW where we use unsigned values sometimes and // signed ones other times: the coordinates turn as big positive // numbers and so the sash is drawn on the *right* side of the window // instead of the left (or bottom instead of top). Correct this. if ( (short)m_oldX < 0 ) m_oldX = 0; if ( (short)m_oldY < 0 ) m_oldY = 0; #endif // __WXMSW__ // Draw new one if ( !isLive ) { m_sashPositionCurrent = posSashNew; DrawSashTracker(m_oldX, m_oldY); } else { DoSetSashPosition(posSashNew); m_needUpdating = true; } } else if ( event.LeftDClick() && m_windowTwo ) { OnDoubleClickSash(x, y); } else { event.Skip(); } }
void GLCanvas::OnLeftDown(wxMouseEvent &event) { SetFocus(); wxSize size = GetSize(); wxPoint pos = event.GetPosition(); bool showMenu = false; if (pos.x > size.x - _buttonSize && pos.y < _numButtons * _buttonSize) { int index = pos.y / _buttonSize; switch (index) { case 0: _style = _style & DRAW_GRID ? _style & ~DRAW_GRID : _style | DRAW_GRID; break; case 1: _style = _style & DRAW_AABB ? _style & ~DRAW_AABB : _style | DRAW_AABB; break; case 2: _style = _style & DRAW_LOCAL_COORDINATE_SYSTEM ? _style & ~DRAW_LOCAL_COORDINATE_SYSTEM : _style | DRAW_LOCAL_COORDINATE_SYSTEM; break; case 3: _style = _style & DRAW_JOINT_CONSTRAINTS ? _style & ~DRAW_JOINT_CONSTRAINTS : _style | DRAW_JOINT_CONSTRAINTS; break; case 4: _style = _style & DRAW_ROTATION_AXIS ? _style & ~DRAW_ROTATION_AXIS : _style | DRAW_ROTATION_AXIS; break; case 5: _style = _style & DRAW_LABEL ? _style & ~DRAW_LABEL : _style | DRAW_LABEL; break; case 6: if (_skeleton != nullptr) { _cameraPosition = _skeleton->getPosition() - 3.0f*_cameraFront; } else { _cameraPosition = Vector3(0.0f, 1.0f, 3.0f); } break; case 7: showMenu = true; break; default: break; } if (showMenu) { GLCanvasDialog dialog(this); dialog.setBackgroundColor(_backgroundColor); dialog.setLineWidth(_lineWidth); dialog.setSkeleton(_skeleton); dialog.setTraceLength(_traceLength); std::vector<int> boneIds; for (auto it = _boneIdsWithTracePoints.begin(); it != _boneIdsWithTracePoints.end(); ++it) { boneIds.push_back(it->first); } dialog.setBonesWithTrace(boneIds); if (dialog.ShowModal() == wxID_OK) { _backgroundColor = dialog.getBackgroundColor(); glClearColor(float(_backgroundColor.Red())/255.0f, float(_backgroundColor.Green())/255.0f, float(_backgroundColor.Blue())/255.0f, 0.0); _lineWidth = dialog.getLineWidth(); _traceLength = dialog.getTraceLength(); _tracePos = 0; _boneIdsWithTracePoints.clear(); boneIds = dialog.getBonesWithTrace(); for (size_t i = 0; i < boneIds.size(); ++i) { _boneIdsWithTracePoints[boneIds[i]] = std::vector<Vector3>(); } Refresh(); } } return; } if (!HasCapture()) { CaptureMouse(); } _lClicked = true; _prevMousePos = pos; SetCursor(wxCURSOR_BLANK); event.Skip(); }
void BaseGrid::OnMouseEvent(wxMouseEvent &event) { int h = GetClientSize().GetHeight(); bool shift = event.ShiftDown(); bool alt = event.AltDown(); bool ctrl = event.CmdDown(); // Row that mouse is over bool click = event.LeftDown(); bool dclick = event.LeftDClick(); int row = event.GetY() / lineHeight + yPos - 1; if (holding && !click) { row = mid(0,row,GetRows()-1); } AssDialogue *dlg = GetDialogue(row); if (!dlg) row = 0; if (event.ButtonDown() && OPT_GET("Subtitle/Grid/Focus Allow")->GetBool()) SetFocus(); if (holding) { if (!event.LeftIsDown()) { if (dlg) MakeCellVisible(row, 0, false); holding = false; ReleaseMouse(); } else { // Only scroll if the mouse has moved to a different row to avoid // scrolling on sloppy clicks if (row != extendRow) { if (row <= yPos) ScrollTo(yPos - 3); // When dragging down we give a 3 row margin to make it easier // to see what's going on, but we don't want to scroll down if // the user clicks on the bottom row and drags up else if (row > yPos + h / lineHeight - (row > extendRow ? 3 : 1)) ScrollTo(yPos + 3); } } } else if (click && dlg) { holding = true; CaptureMouse(); } if ((click || holding || dclick) && dlg) { int old_extend = extendRow; // SetActiveLine will scroll the grid if the row is only half-visible, // but we don't want to scroll until the mouse moves or the button is // released, to avoid selecting multiple lines on a click int old_y_pos = yPos; SetActiveLine(dlg); ScrollTo(old_y_pos); // Toggle selected if (click && ctrl && !shift && !alt) { bool isSel = !!selection.count(dlg); if (isSel && selection.size() == 1) return; SelectRow(row, true, !isSel); return; } // Normal click if ((click || dclick) && !shift && !ctrl && !alt) { if (dclick) { context->audioBox->ScrollToActiveLine(); context->videoController->JumpToTime(dlg->Start); } SelectRow(row, false); return; } // Change active line only if (click && !shift && !ctrl && alt) return; // Block select if ((click && shift && !alt) || holding) { extendRow = old_extend; int i1 = row; int i2 = extendRow; if (i1 > i2) std::swap(i1, i2); // Toggle each Selection newsel; if (ctrl) newsel = selection; for (int i = i1; i <= i2; i++) { newsel.insert(GetDialogue(i)); } SetSelectedSet(newsel); return; } return; } // Mouse wheel if (event.GetWheelRotation() != 0) { if (ForwardMouseWheelEvent(this, event)) { int step = shift ? h / lineHeight - 2 : 3; ScrollTo(yPos - step * event.GetWheelRotation() / event.GetWheelDelta()); } return; } event.Skip(); }
void wxToolBar::OnMouseEvent( wxMouseEvent& rEvent ) { POINTL vPoint; HWND hWnd; wxCoord vX; wxCoord vY; HPOINTER hPtr = ::WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE); ::WinSetPointer(HWND_DESKTOP, hPtr); ::WinQueryPointerPos(HWND_DESKTOP, &vPoint); hWnd = ::WinWindowFromPoint(HWND_DESKTOP, &vPoint, TRUE); if (hWnd != (HWND)GetHwnd()) { m_vToolTimer.Stop(); return; } rEvent.GetPosition(&vX, &vY); wxToolBarTool* pTool = (wxToolBarTool *)FindToolForPosition( vX ,vY ); if (rEvent.LeftDown()) { CaptureMouse(); } if (rEvent.LeftUp()) { ReleaseMouse(); } if (!pTool) { m_vToolTimer.Stop(); if (m_nCurrentTool > -1) { if (rEvent.LeftIsDown()) SpringUpButton(m_nCurrentTool); pTool = (wxToolBarTool *)FindById(m_nCurrentTool); if (pTool && !pTool->IsToggled()) { RaiseTool( pTool, FALSE ); } m_nCurrentTool = -1; OnMouseEnter(-1); } return; } if (!rEvent.IsButton()) { if (pTool->GetId() != m_nCurrentTool) { // // If the left button is kept down and moved over buttons, // press those buttons. // if (rEvent.LeftIsDown() && pTool->IsEnabled()) { SpringUpButton(m_nCurrentTool); if (pTool->CanBeToggled()) { pTool->Toggle(); } DrawTool(pTool); } wxToolBarTool* pOldTool = (wxToolBarTool*)FindById(m_nCurrentTool); if (pOldTool && !pTool->IsToggled()) RaiseTool( pOldTool, FALSE ); m_nCurrentTool = pTool->GetId(); OnMouseEnter(m_nCurrentTool); if (!pTool->GetShortHelp().empty()) { if (m_pToolTip) delete m_pToolTip; m_pToolTip = new wxToolTip(pTool->GetShortHelp()); m_vXMouse = (wxCoord)vPoint.x; m_vYMouse = (wxCoord)vPoint.y; m_vToolTimer.Start(1000L, TRUE); } if (!pTool->IsToggled()) RaiseTool(pTool); } return; } // Left button pressed. if (rEvent.LeftDown() && pTool->IsEnabled()) { if (pTool->CanBeToggled()) { pTool->Toggle(); } DrawTool(pTool); } else if (rEvent.RightDown()) { OnRightClick( pTool->GetId() ,vX ,vY ); } // // Left Button Released. Only this action confirms selection. // If the button is enabled and it is not a toggle tool and it is // in the pressed state, then raise the button and call OnLeftClick. // if (rEvent.LeftUp() && pTool->IsEnabled() ) { // // Pass the OnLeftClick event to tool // if (!OnLeftClick( pTool->GetId() ,pTool->IsToggled()) && pTool->CanBeToggled()) { // // If it was a toggle, and OnLeftClick says No Toggle allowed, // then change it back // pTool->Toggle(); } DrawTool(pTool); } } // end of wxToolBar::OnMouseEvent