void OSGCanvas::OnMouseDown( wxMouseEvent & event ) { if( _graphics_window.valid() ) { _graphics_window->getEventQueue()->mouseButtonPress( event.GetX(), event.GetY(), event.GetButton() ); } }
//----------------------------------------------------------------------------- void WXGLCanvas::OnMouseUp( wxMouseEvent& ev ) { if (ev.GetButton() == wxMOUSE_BTN_NONE) return; switch(ev.GetButton()) { case wxMOUSE_BTN_LEFT: dispatchMouseUpEvent(LeftButton, ev.GetX(), ev.GetY()); break; case wxMOUSE_BTN_MIDDLE: dispatchMouseUpEvent(MiddleButton, ev.GetX(), ev.GetY()); break; case wxMOUSE_BTN_RIGHT: dispatchMouseUpEvent(RightButton, ev.GetX(), ev.GetY()); break; default: case wxMOUSE_BTN_ANY: dispatchMouseUpEvent(UnknownButton, ev.GetX(), ev.GetY()); break; } mMouseCount--; // release only once if (!mMouseCount) ReleaseMouse(); VL_CHECK(mMouseCount>=0) }
//----------------------------------------------------------------------------- void WXGLCanvas::OnMouseDown( wxMouseEvent& ev ) { if (ev.GetButton() == wxMOUSE_BTN_NONE) return; switch(ev.GetButton()) { case wxMOUSE_BTN_LEFT: dispatchMouseDownEvent(LeftButton, ev.GetX(), ev.GetY()); break; case wxMOUSE_BTN_MIDDLE: dispatchMouseDownEvent(MiddleButton, ev.GetX(), ev.GetY()); break; case wxMOUSE_BTN_RIGHT: dispatchMouseDownEvent(RightButton, ev.GetX(), ev.GetY()); break; default: case wxMOUSE_BTN_ANY: dispatchMouseDownEvent(UnknownButton, ev.GetX(), ev.GetY()); break; } // capture only once VL_CHECK(mMouseCount>=0) if (!mMouseCount) CaptureMouse(); mMouseCount++; }
void CFrame::OnMouse(wxMouseEvent& event) { #if defined(HAVE_X11) && HAVE_X11 if (Core::GetState() != Core::CORE_UNINITIALIZED) { if(event.Dragging()) X11Utils::SendMotionEvent(X11Utils::XDisplayFromHandle(GetHandle()), event.GetPosition().x, event.GetPosition().y); else X11Utils::SendButtonEvent(X11Utils::XDisplayFromHandle(GetHandle()), event.GetButton(), event.GetPosition().x, event.GetPosition().y, event.ButtonDown()); } #endif event.Skip(); }
// Returns true if parent needs to be redrawn bool Envelope::MouseEvent(wxMouseEvent & event, wxRect & r, double h, double pps, bool dB, float zoomMin, float zoomMax) { if (event.ButtonDown() && mButton == wxMOUSE_BTN_NONE) return HandleMouseButtonDown( event, r, h, pps,dB, zoomMin, zoomMax); if (event.Dragging() && mDragPoint >= 0) return HandleDragging( event, r, h, pps,dB, zoomMin, zoomMax); if (event.ButtonUp() && event.GetButton() == mButton) return HandleMouseButtonUp( event, r, h, pps, dB, zoomMin, zoomMax); return false; }
void ActorSceneCanvas::OnMiddleDown(wxMouseEvent& e) { SetFocus(); if (!GetSceneManipulator()) return; if (HasCapture()) return; wxASSERT(!m_pCameraManip); wxASSERT(mDragButton == wxMOUSE_BTN_NONE); if (!e.ControlDown() && !e.AltDown() && !e.ShiftDown() && !e.MetaDown()) { // (None) m_pCameraManip = GetSceneManipulator()->getManip("CameraDragMove"); } else if (!e.ControlDown() && !e.AltDown() && e.ShiftDown() && !e.MetaDown()) { // Shift m_pCameraManip = GetSceneManipulator()->getManip("CameraDragRotate"); } else if (e.ControlDown() && !e.AltDown() && !e.ShiftDown() && !e.MetaDown()) { // Ctrl m_pCameraManip = GetSceneManipulator()->getManip("CameraPan"); } else if (!e.ControlDown() && e.AltDown() && !e.ShiftDown() && !e.MetaDown()) { // Alt m_pCameraManip = GetSceneManipulator()->getManip("CameraRotate"); } if (m_pCameraManip) { mDragButton = e.GetButton(); m_pCameraManip->onBegin(e.GetX(), e.GetY()); CaptureMouse(); } }
void GP_Title::OnClick(wxMouseEvent& event) { unsigned long level_id = 1; if (event.GetButton() == wxMOUSE_BTN_RIGHT) { wxTextEntryDialog dialog(this, GC_TEXT_LEVELCHOICE, GC_TEXT_NAME, wxString() << level_id); if (dialog.ShowModal() != wxID_OK) return; if (not dialog.GetValue().ToULong(&level_id)) return ShowLevelLoadFailed(); } GLevel* const level = GLevel::NewFromId(level_id); if (not level) return ShowLevelLoadFailed(); new GP_Game(level, GetParent()); Destroy(); }
bool wxStdScrollBarInputHandler::HandleMouse(wxInputConsumer *consumer, const wxMouseEvent& event) { // is this a click event from an acceptable button? int btn = event.GetButton(); if ( btn == wxMOUSE_BTN_LEFT ) { // determine which part of the window mouse is in wxScrollBar *scrollbar = wxStaticCast(consumer->GetInputWindow(), wxScrollBar); wxHitTest ht = scrollbar->HitTestBar(event.GetPosition()); // when the mouse is pressed on any scrollbar element, we capture it // and hold capture until the same mouse button is released if ( event.ButtonDown() || event.ButtonDClick() ) { if ( !m_winCapture ) { m_btnCapture = btn; m_winCapture = consumer->GetInputWindow(); m_winCapture->CaptureMouse(); // generate the command bool hasAction = true; wxControlAction action; switch ( ht ) { case wxHT_SCROLLBAR_ARROW_LINE_1: action = wxACTION_SCROLL_LINE_UP; break; case wxHT_SCROLLBAR_ARROW_LINE_2: action = wxACTION_SCROLL_LINE_DOWN; break; case wxHT_SCROLLBAR_BAR_1: action = wxACTION_SCROLL_PAGE_UP; m_ptStartScrolling = event.GetPosition(); break; case wxHT_SCROLLBAR_BAR_2: action = wxACTION_SCROLL_PAGE_DOWN; m_ptStartScrolling = event.GetPosition(); break; case wxHT_SCROLLBAR_THUMB: consumer->PerformAction(wxACTION_SCROLL_THUMB_DRAG); m_ofsMouse = GetMouseCoord(scrollbar, event) - scrollbar->ScrollbarToPixel(); // fall through: there is no immediate action default: hasAction = false; } // remove highlighting Highlight(scrollbar, false); m_htLast = ht; // and press the arrow or highlight thumb now instead if ( m_htLast == wxHT_SCROLLBAR_THUMB ) Highlight(scrollbar, true); else Press(scrollbar, true); // start dragging if ( hasAction ) { m_timerScroll = new wxScrollBarTimer(this, action, scrollbar); m_timerScroll->StartAutoScroll(); } //else: no (immediate) action } //else: mouse already captured, nothing to do } // release mouse if the *same* button went up else if ( btn == m_btnCapture ) { if ( m_winCapture ) { StopScrolling(scrollbar); // if we were dragging the thumb, send the last event if ( m_htLast == wxHT_SCROLLBAR_THUMB ) { scrollbar->PerformAction(wxACTION_SCROLL_THUMB_RELEASE); } m_htLast = ht; Highlight(scrollbar, true); } else { // this is not supposed to happen as the button can't go up // without going down previously and then we'd have // m_winCapture by now wxFAIL_MSG( wxT("logic error in mouse capturing code") ); } } } return wxStdInputHandler::HandleMouse(consumer, event); }
void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent) { // do this in advance to allow simply returning if we're not interested, // we'll undo it if we do handle the event below mevent.Skip(); // account for the control displacement const int xPhysical = mevent.GetX(); const int xLogical = xPhysical - m_scrollOffset; // first deal with the [continuation of any] dragging operations in // progress if ( IsResizing() ) { if ( mevent.LeftUp() ) EndResizing(xPhysical); else // update the live separator position StartOrContinueResizing(m_colBeingResized, xPhysical); return; } if ( IsReordering() ) { if ( !mevent.LeftUp() ) { // update the column position UpdateReorderingMarker(xPhysical); return; } // finish reordering and continue to generate a click event below if we // didn't really reorder anything if ( EndReordering(xPhysical) ) return; } // find if the event is over a column at all bool onSeparator; const unsigned col = mevent.Leaving() ? (onSeparator = false, COL_NONE) : FindColumnAtPoint(xLogical, &onSeparator); // update the highlighted column if it changed if ( col != m_hover ) { const unsigned hoverOld = m_hover; m_hover = col; RefreshColIfNotNone(hoverOld); RefreshColIfNotNone(m_hover); } // update mouse cursor as it moves around if ( mevent.Moving() ) { SetCursor(onSeparator ? wxCursor(wxCURSOR_SIZEWE) : wxNullCursor); return; } // all the other events only make sense when they happen over a column if ( col == COL_NONE ) return; // enter various dragging modes on left mouse press if ( mevent.LeftDown() ) { if ( onSeparator ) { // start resizing the column wxASSERT_MSG( !IsResizing(), "reentering column resize mode?" ); StartOrContinueResizing(col, xPhysical); } else // on column itself { // start dragging the column wxASSERT_MSG( !IsReordering(), "reentering column move mode?" ); StartReordering(col, xPhysical); } return; } // determine the type of header event corresponding to click events wxEventType evtType = wxEVT_NULL; const bool click = mevent.ButtonUp(), dblclk = mevent.ButtonDClick(); if ( click || dblclk ) { switch ( mevent.GetButton() ) { case wxMOUSE_BTN_LEFT: // treat left double clicks on separator specially if ( onSeparator && dblclk ) { evtType = wxEVT_COMMAND_HEADER_SEPARATOR_DCLICK; } else // not double click on separator { evtType = click ? wxEVT_COMMAND_HEADER_CLICK : wxEVT_COMMAND_HEADER_DCLICK; } break; case wxMOUSE_BTN_RIGHT: evtType = click ? wxEVT_COMMAND_HEADER_RIGHT_CLICK : wxEVT_COMMAND_HEADER_RIGHT_DCLICK; break; case wxMOUSE_BTN_MIDDLE: evtType = click ? wxEVT_COMMAND_HEADER_MIDDLE_CLICK : wxEVT_COMMAND_HEADER_MIDDLE_DCLICK; break; default: // ignore clicks from other mouse buttons ; } } if ( evtType == wxEVT_NULL ) return; wxHeaderCtrlEvent event(evtType, GetId()); event.SetEventObject(this); event.SetColumn(col); if ( GetEventHandler()->ProcessEvent(event) ) mevent.Skip(false); }
/// HandleMouseButtonDown either finds an existing control point or adds a new one /// which is then recorded as the point to drag. /// This is slightly complicated by there possibly being four control points for /// a given time value: /// We have an upper and lower envelope line. /// Also we may be showing an inner envelope (at 0.5 the range). bool Envelope::HandleMouseButtonDown(wxMouseEvent & event, wxRect & r, double h, double pps, bool dB, float zoomMin, float zoomMax) { int ctr = (int)(r.height * zoomMax / (zoomMax - zoomMin)); bool upper = !mMirror || (zoomMin >= 0.0) || (event.m_y - r.y < ctr); int clip_y = event.m_y - r.y; if(clip_y < 0) clip_y = 0; //keeps point in rect r, even if mouse isn't if(clip_y > r.GetBottom()) clip_y = r.GetBottom(); double tleft = h - mOffset; double tright = tleft + (r.width / pps); int bestNum = -1; int bestDist = 10; // Must be within 10 pixel radius. // TODO: Cache the gPrefs value. Reading it every time is inefficient. double dBr = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE); // Member variables hold state that will be needed in dragging. mButton = event.GetButton(); mIsDeleting = false; mContourOffset = false; // wxLogDebug(wxT("Y:%i Height:%i Offset:%i"), y, height, mContourOffset ); int len = mEnv.Count(); // TODO: extract this into a function FindNearestControlPoint() // TODO: also fix it so that we can drag the last point on an envelope. for (int i = 0; i < len; i++) { //search for control point nearest click if (mEnv[i]->GetT() >= tleft && mEnv[i]->GetT() <= tright) { int x = int ((mEnv[i]->GetT() + mOffset - h) * pps) + r.x; int y[4]; int numControlPoints; // Outer control points y[0] = GetWaveYPos( mEnv[i]->GetVal(), zoomMin, zoomMax, r.height, dB, true, dBr, false); y[1] = GetWaveYPos( -mEnv[i]->GetVal(), zoomMin, zoomMax, r.height, dB, true, dBr, false); // Inner control points(contour) y[2] = GetWaveYPos( mEnv[i]->GetVal(), zoomMin, zoomMax, r.height, dB, false, dBr, false); y[3] = GetWaveYPos( -mEnv[i]->GetVal()-.00000001, zoomMin, zoomMax, r.height, dB, false, dBr, false); numControlPoints = 4; if (y[2] > y[3]) numControlPoints = 2; if (!mMirror) numControlPoints = 1; for(int j=0; j<numControlPoints; j++){ int d = (int)(sqrt((double)(SQR(x-event.m_x) + SQR(y[j]-(event.m_y-r.y)))) + 0.5); if (d < bestDist) { bestNum = i; bestDist = d; mContourOffset = (bool)(j > 1); } } } } if (bestNum >= 0) { mDragPoint = bestNum; } else { // TODO: Extract this into a function CreateNewPoint double when = h + (event.m_x - r.x) / pps - mOffset; // if (when <= 0 || when >= mTrackLen) // return false; double v = GetValueAtX( event.m_x, r, h, pps ); int ct = GetWaveYPos( v, zoomMin, zoomMax, r.height, dB, false, dBr, false) ; int cb = GetWaveYPos( -v-.000000001, zoomMin, zoomMax, r.height, dB, false, dBr, false) ; if( ct <= cb || !mMirror ){ int t = GetWaveYPos( v, zoomMin, zoomMax, r.height, dB, true, dBr, false) ; int b = GetWaveYPos( -v, zoomMin, zoomMax, r.height, dB, true, dBr, false) ; ct = (t + ct) / 2; cb = (b + cb) / 2; if(mMirror && (event.m_y - r.y) > ct && ((event.m_y - r.y) < cb)) mContourOffset = true; else mContourOffset = false; } double newVal = ValueOfPixel(clip_y, r.height, upper, dB, zoomMin, zoomMax); mDragPoint = Insert(when, newVal); mDirty = true; } mUpper = upper; mInitialWhen = mEnv[mDragPoint]->GetT(); mInitialVal = mEnv[mDragPoint]->GetVal(); mInitialX = event.m_x; mInitialY = event.m_y+mContourOffset; return true; }
void wxMultiColumnListCtrl::OnMouseEvent(wxMouseEvent& event) { if (event.GetEventType() == wxEVT_MOUSEWHEEL) { int dir = event.GetWheelRotation(); if (dir > 0) { m_items.SetSelection(m_items.GetSelection() - 1); if (m_items.GetSelection() < 0) m_items.SetSelection(m_items.GetItemCount() - 1); AdvanceToNextSelectableItem(-1); } else if (dir < 0) { m_items.SetSelection(m_items.GetSelection() + 1); if (m_items.GetSelection() >= m_items.GetItemCount()) m_items.SetSelection(0); AdvanceToNextSelectableItem(1); } GenerateSelectionEvent(); Refresh(); } else if (event.GetButton() == wxMOUSE_BTN_NONE) { // Mouse move bool bCanSelectItem = true; if (m_ptMouse.x != -2 && m_ptMouse.y != -2) { // If ==-2 => Don't select item on mouse pointer : used when user select the window with keyboard if (m_ptMouse.x != -1 && m_ptMouse.y != -1) { // If ==-1 => The client already move the mouse, select the item under the mouse cursor wxPoint ptCurrent = ClientToScreen(event.GetPosition()); if (abs(ptCurrent.x - m_ptMouse.x) >= 3 || abs(ptCurrent.y - m_ptMouse.y) >= 3) { // the user has moved the mouse over a 3 pixels square m_ptMouse.x = m_ptMouse.y = -1; // Accept to select an item } else { // Select this item is not allowed for the moment, the user must move the mouse bCanSelectItem = false; } } if (bCanSelectItem) { int idx = m_items.HitTest(event.GetPosition()); if (idx != wxNOT_FOUND) { m_items.SetSelection(idx); GenerateSelectionEvent(); Refresh(); } } } } else if (event.LeftDown()) { m_ptMouse.x = m_ptMouse.y = -1; // Accept to select an item SendCloseEvent(); SetFocus(); } }
bool Envelope::HandleMouseButtonDown(wxMouseEvent & event, wxRect & r, double h, double pps, bool dB, float zoomMin, float zoomMax, float eMin, float eMax) { bool upper; int ctr = (int)(r.height * zoomMax / (zoomMax - zoomMin)); upper = (event.m_y - r.y < ctr); if(zoomMin == eMin) upper = true; mButton = event.GetButton(); int clip_y = event.m_y - r.y; if(clip_y < 0) clip_y = 0; //keeps point in rect r, even if mouse isn't if(clip_y > r.height) clip_y = r.height; mIsDeleting = false; double tleft = h - mOffset; double tright = tleft + (r.width / pps); int bestNum = -1; int bestDist = 10; // Must be within 10 pixel radius. double dBr = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE); mContourOffset = false; // wxLogDebug(wxT("Y:%i Height:%i Offset:%i"), y, height, mContourOffset ); int len = mEnv.Count(); for (int i = 0; i < len; i++) { //search for control point nearest click if (mEnv[i]->t >= tleft && mEnv[i]->t <= tright) { int x = int ((mEnv[i]->t + mOffset - h) * pps) + r.x; int y[4]; int numControlPoints; // Outer control points y[0] = GetWaveYPos( mEnv[i]->val, zoomMin, zoomMax, r.height, dB, true, dBr, false); y[1] = GetWaveYPos( -mEnv[i]->val, zoomMin, zoomMax, r.height, dB, true, dBr, false); // Inner control points(contour) y[2] = GetWaveYPos( mEnv[i]->val, zoomMin, zoomMax, r.height, dB, false, dBr, false); y[3] = GetWaveYPos( -mEnv[i]->val-.00000001, zoomMin, zoomMax, r.height, dB, false, dBr, false); numControlPoints = 4; if (y[2] > y[3]) numControlPoints = 2; if (!mMirror) numControlPoints = 1; for(int j=0; j<numControlPoints; j++) { int d = (int)(sqrt((double)(SQR(x-event.m_x) + SQR(y[j]-(event.m_y-r.y)))) + 0.5); if (d < bestDist) { bestNum = i; bestDist = d; mContourOffset = (bool)(j > 1); } } } } if (bestNum >= 0) { mDragPoint = bestNum; } else { // Create new point double when = h + (event.m_x - r.x) / pps - mOffset; // if (when <= 0 || when >= mTrackLen) // return false; double v = GetValueAtX( event.m_x, r, h, pps ); int ct = GetWaveYPos( v, zoomMin, zoomMax, r.height, dB, false, dBr, false) ; int cb = GetWaveYPos( -v-.000000001, zoomMin, zoomMax, r.height, dB, false, dBr, false) ; if( ct <= cb || !mMirror ) { int t = GetWaveYPos( v, zoomMin, zoomMax, r.height, dB, true, dBr, false) ; int b = GetWaveYPos( -v, zoomMin, zoomMax, r.height, dB, true, dBr, false) ; ct = (t + ct) / 2; cb = (b + cb) / 2; if(mMirror && (event.m_y - r.y) > ct && ((event.m_y - r.y) < cb)) mContourOffset = true; else mContourOffset = false; } double newVal = ValueOfPixel(clip_y, r.height, upper, dB, zoomMin, zoomMax, eMin); //float MaxAmplify = ( mContourOffset ) ? 1.4 : 1.0; if(newVal > eMax) newVal = eMax; mDragPoint = Insert(when, newVal); mDirty = true; } mUpper = upper; mInitialWhen = mEnv[mDragPoint]->t; mInitialVal = mEnv[mDragPoint]->val; mInitialX = event.m_x; mInitialY = event.m_y+mContourOffset; return true; }
void AudioDisplay::OnMouseEvent(wxMouseEvent& event) { // If we have focus, we get mouse move events on Mac even when the mouse is // outside our client rectangle, we don't want those. if (event.Moving() && !GetClientRect().Contains(event.GetPosition())) { event.Skip(); return; } if (event.IsButton()) SetFocus(); const int mouse_x = event.GetPosition().x; // Scroll the display after a mouse-up near one of the edges if ((event.LeftUp() || event.RightUp()) && OPT_GET("Audio/Auto/Scroll")->GetBool()) { const int width = GetClientSize().GetWidth(); if (mouse_x < width / 20) { ScrollBy(-width / 3); } else if (width - mouse_x < width / 20) { ScrollBy(width / 3); } } if (ForwardMouseEvent(event)) return; if (event.MiddleIsDown()) { context->videoController->JumpToTime(TimeFromRelativeX(mouse_x), agi::vfr::EXACT); return; } if (event.Moving() && !controller->IsPlaying()) { SetTrackCursor(scroll_left + mouse_x, OPT_GET("Audio/Display/Draw/Cursor Time")->GetBool()); } AudioTimingController *timing = controller->GetTimingController(); if (!timing) return; const int drag_sensitivity = int(OPT_GET("Audio/Start Drag Sensitivity")->GetInt() * ms_per_pixel); const int snap_sensitivity = OPT_GET("Audio/Snap/Enable")->GetBool() != event.ShiftDown() ? int(OPT_GET("Audio/Snap/Distance")->GetInt() * ms_per_pixel) : 0; // Not scrollbar, not timeline, no button action if (event.Moving()) { const int timepos = TimeFromRelativeX(mouse_x); if (timing->IsNearbyMarker(timepos, drag_sensitivity)) SetCursor(wxCursor(wxCURSOR_SIZEWE)); else SetCursor(wxNullCursor); return; } const int old_scroll_pos = scroll_left; if (event.LeftDown() || event.RightDown()) { const int timepos = TimeFromRelativeX(mouse_x); std::vector<AudioMarker*> markers = event.LeftDown() ? timing->OnLeftClick(timepos, event.CmdDown(), drag_sensitivity, snap_sensitivity) : timing->OnRightClick(timepos, event.CmdDown(), drag_sensitivity, snap_sensitivity); // Clicking should never result in the audio display scrolling ScrollPixelToLeft(old_scroll_pos); if (markers.size()) { RemoveTrackCursor(); audio_marker.reset(new AudioMarkerInteractionObject(markers, timing, this, controller, (wxMouseButton)event.GetButton())); SetDraggedObject(audio_marker.get()); return; } } }
int bmx_wxmouseevent_getbutton(wxMouseEvent & event) { return event.GetButton(); }