Esempio n. 1
0
void CFCEditorGLWindow::OnMouse(wxMouseEvent& event)
{
    if(event.ButtonDown(wxMOUSE_BTN_RIGHT))
    {
        if (!HasCapture())
        {
            CaptureMouse();
        }
        HideCursor();
        SetFocus();//Call this for catch the EVT_MOUSEWHEEL event, in left mouse button down event is not necessary to call this
        m_startPosition = event.GetPosition();
        m_bRightDown = true;
    }
    else if(event.ButtonUp(wxMOUSE_BTN_RIGHT))
    {
        if (!m_bLeftDown && HasCapture())
        {
            ReleaseMouse();
        }
        ShowCursor();
        m_bRightDown = false;
    }
    else if(event.ButtonDown(wxMOUSE_BTN_LEFT))
    {
        if (!HasCapture())
        {
            CaptureMouse();
        }
        HideCursor();
        m_startPosition = event.GetPosition();
        m_bLeftDown = true;
    }
    else if(event.ButtonUp(wxMOUSE_BTN_LEFT))
    {
        if (!m_bRightDown && HasCapture())
        {
            ReleaseMouse();
        }
        ShowCursor();
        m_bLeftDown = false;
    }
    else if(event.Dragging())
    {
        if (m_bRightDown || m_bLeftDown)
        {
            wxPoint curPos = event.GetPosition();
            wxPoint pnt = ClientToScreen(m_startPosition);
            SetCursorPos(pnt.x, pnt.y);
            if (m_bRightDown)
            {
                int nDeltaX = curPos.x - m_startPosition.x;
                int nDeltaY = curPos.y - m_startPosition.y;
                wxSize clientSize = GetClientSize();
                m_pCamera->Yaw((float)nDeltaX / clientSize.x);
                m_pCamera->Pitch((float)nDeltaY / clientSize.y);
            }
        }
    }
    event.Skip();
}
Esempio n. 2
0
void TrackPanel::OnMouseEvent(wxMouseEvent& event)
{
  if (event.m_x < view->labelWidth) {
	//	Group panel stuff

	if (event.ButtonDClick())
	  view->DClickLabel(event);  
	else if (event.ButtonDown())
	  view->ClickLabel(event);
	else if (event.ButtonUp())
	  SetCursor(*mainCursor);
  }
  else {
	if (event.ButtonDown()) {
	  CaptureMouse();
	  if (event.ControlDown())
		SetCursor(*dragCursor);
	  view->ClickTrack(event);
	}
	else if (event.Dragging())
	  view->DragTrack(event);
	else if (event.ButtonUp()) {
	  ReleaseMouse();
	  SetCursor(*mainCursor);
	  view->ButtonUpTrack();
	}
	else if (event.Moving()) {
	  view->TrackSetCursor(event);
	}
  }
}
Esempio n. 3
0
void VIICanvas::mouseEvent(wxMouseEvent& event)
{
	if(event.ButtonDown(wxMOUSE_BTN_LEFT))
	{
		mLeftClicked = true;
		mStartPoint = event.GetPosition();
	}
	if(event.ButtonUp(wxMOUSE_BTN_LEFT))
	{
		mLeftClicked = false;
	}
	if(event.ButtonDown(wxMOUSE_BTN_RIGHT))
	{
		mRightClicked = true;
		mStartPoint = event.GetPosition();
	}
	if(event.ButtonUp(wxMOUSE_BTN_RIGHT))
	{
		mRightClicked = false;
	}

	if(event.Dragging())
	{
		if(mLeftClicked)
		{
			wxPoint delta = event.GetPosition() - mStartPoint;
			mAngleY += delta.x;
			mAngleX += delta.y;
			
			if(mAngleX < 0)
			{
				mAngleX = 360 + mAngleX;
			}
			
			if(mAngleY < 0)
			{
				mAngleY = 360 + mAngleY;
			}
			
			mAngleX %= 360;
			mAngleY %= 360;
			
			
			//std::cout << "AngleX: " << mAngleX << " angleY: " << mAngleY << std::endl;
			mStartPoint = event.GetPosition();
			Refresh();
		}
		else if(mRightClicked)
		{
			wxPoint delta = event.GetPosition() - mStartPoint;
			mDistanceOrigin += delta.y;
			//std::cout << "Distance: "<< mDistanceOrigin <<std::endl;
			mStartPoint = event.GetPosition();
			Refresh();
		}
	}
	
}
Esempio n. 4
0
void TestGLCanvas::OnMouse( wxMouseEvent& event )
{
    
    static bool useLightTrack=false;

    if ( event.m_rightDown || event.m_leftDown || event.m_middleDown ) {
      if (!HasCapture()) CaptureMouse();
    }
    else if (HasCapture()) ReleaseMouse();
    
    useLightTrack=event.m_rightDown;

    bool consumed=false;
    if (useLightTrack) {
      MovingLightMode=true;
      if (wxConsumeTrackBallEvent( event, lightTrack)) {
        SetFocus();
        consumed=true;
      }
    } else {
      MovingLightMode=false;
      if (wxConsumeTrackBallEvent( event, track)) {
        SetFocus();
        consumed=true;
      }
    }
    
    if ((consumed) && (!event.ButtonUp()) && (!event.ButtonDown())) SceneChanged();
    
/*   if ( event.m_rightUp ) {
      useLightTrack=false;
    }*/

}
Esempio n. 5
0
void MixerTrackCluster::OnMouseEvent(wxMouseEvent& event)
{
   if (event.ButtonUp()) 
      this->HandleSelect(event.ShiftDown());
   else
      event.Skip();
}
Esempio n. 6
0
void Canvas::OnMouse(wxMouseEvent& evt)
{
	// Capture on button-down, so we can respond even when the mouse
	// moves off the window
	if (!m_MouseCaptured && evt.ButtonDown())
	{
		m_MouseCaptured = true;
		CaptureMouse();
	}
	// Un-capture when all buttons are up
	else if (m_MouseCaptured && evt.ButtonUp() &&
		! (evt.ButtonIsDown(wxMOUSE_BTN_LEFT) || evt.ButtonIsDown(wxMOUSE_BTN_MIDDLE) || evt.ButtonIsDown(wxMOUSE_BTN_RIGHT))
		)
	{
		m_MouseCaptured = false;
		ReleaseMouse();
	}

	// Set focus when clicking
	if (evt.ButtonDown())
		SetFocus();

	// Reject motion events if the mouse has not actually moved
	if (evt.Moving() || evt.Dragging())
	{
		if (m_LastMousePos == evt.GetPosition())
			return;
		m_LastMousePos = evt.GetPosition();
	}

	HandleMouseEvent(evt);
}
Esempio n. 7
0
void LWSlider::OnMouseEvent(wxMouseEvent & event)
{
   if (event.Entering()) {
      // Display the tooltip in the status bar
      if (mParent->GetToolTip()) {
         wxString tip = mParent->GetToolTip()->GetTip();
         GetActiveProject()->TP_DisplayStatusMessage(tip, 0);
         Refresh();
      }
   }
   else if (event.Leaving()) {
      GetActiveProject()->TP_DisplayStatusMessage("",0);
      Refresh();
   }
   
   float prevValue = mCurrentValue;

   if (event.ButtonDown()) {

      //This jumps the thumb to clicked position
      if (!mIsDragging) {
         mCurrentValue = PositionToValue(event.m_x, event.ShiftDown());

         mIsDragging = true;
         mParent->CaptureMouse();

         FormatPopWin();
         SetPopWinPosition();
         mPopWin->Show();
      }

      // Don't generate notification yet
      return;

   } else if (event.ButtonUp() && mIsDragging) {
      mIsDragging = false;
      mParent->ReleaseMouse();
      mPopWin->Hide();
      ((TipPanel *)mPopWin)->SetPos(wxPoint(-1000, -1000));
   } else if (event.Dragging() && mIsDragging) {
      mCurrentValue = PositionToValue(event.m_x, event.ShiftDown());
   }

   if (prevValue != mCurrentValue) {
      FormatPopWin();
      mPopWin->Refresh();
      Refresh();

      wxCommandEvent *e =
         new wxCommandEvent(wxEVT_COMMAND_SLIDER_UPDATED, mID);
      int intValue =
         (int)((mCurrentValue - mMinValue) * 1000.0f
         / (mMaxValue - mMinValue));
      e->SetInt( intValue );
      mParent->ProcessEvent(*e);
      delete e;
   }
}
Esempio n. 8
0
void CGradientCtrl::OnMouse(wxMouseEvent& event)
{
    ECursorType eType = eCT_Invalid;
    wxPoint pos = event.GetPosition();
    if (event.ButtonDown(wxMOUSE_BTN_LEFT))
    {
        if (m_pSelectedCursor)
        {
            m_pSelectedCursor->Select(false);
        }
        m_pSelectedCursor = GetGradientCursor(pos);
        if (m_pSelectedCursor)
        {
            eType = m_pSelectedCursor->GetType();
            if (eType == eCT_Color)
            {
                m_pColoutPicker->SetColour(m_pSelectedCursor->GetColor());
            }
            else
            {
                m_pMaskSlider->SetValue(m_pSelectedCursor->GetColor().Red());
            }
            m_pSelectedCursor->Select(true);
        }
        ShowCtrl(m_pSelectedCursor == NULL ? eCT_Invalid : m_pSelectedCursor->GetType());
        Refresh(true);
        UpdateSelectedCursorPos();
    }
    else if (event.Dragging())
    {
        if (event.LeftIsDown())
        {
            if (m_pSelectedCursor)
            {
                SetSelectedCursorPos(pos);
                UpdateSelectedCursorPos();
                float fPos = GetNearestCursorPos(m_pSelectedCursor);
                if (fPos >= 0)
                {
                    m_pSelectedCursor->SetPos(fPos);
                }
                Refresh(true);
            }
        }
    }
    else if (event.ButtonUp(wxMOUSE_BTN_LEFT))
    {
        if (m_pSelectedCursor)
        {
            if (GetNearestCursorPos(m_pSelectedCursor) > 0)
            {
                DeleteCursor(m_pSelectedCursor);
                m_pSelectedCursor = NULL;
            }
        }
    }
    
}
Esempio n. 9
0
void GSPanel::OnMouseEvent( wxMouseEvent& evt )
{
	if( IsBeingDeleted() ) return;

	// Do nothing for left-button event
	if (!evt.Button(wxMOUSE_BTN_LEFT)) {
		evt.Skip();
		DoShowMouse();
	}

#if defined(__unix__)
	// HACK2: In gsopen2 there is one event buffer read by both wx/gui and pad plugin. Wx deletes
	// the event before the pad see it. So you send key event directly to the pad.
	if( (PADWriteEvent != NULL) && (GSopen2 != NULL) ) {
		keyEvent event;
		// FIXME how to handle double click ???
		if (evt.ButtonDown()) {
			event.evt = 4; // X equivalent of ButtonPress
			event.key = evt.GetButton();
		} else if (evt.ButtonUp()) {
			event.evt = 5; // X equivalent of ButtonRelease
			event.key = evt.GetButton();
		} else if (evt.Moving() || evt.Dragging()) {
			event.evt = 6; // X equivalent of MotionNotify
			long x,y;
			evt.GetPosition(&x, &y);

			wxCoord w, h;
			wxWindowDC dc( this );
			dc.GetSize(&w, &h);

			// Special case to allow continuous mouvement near the border
			if (x < 10)
				x = 0;
			else if (x > (w-10))
				x = 0xFFFF;

			if (y < 10)
				y = 0;
			else if (y > (w-10))
				y = 0xFFFF;

			// For compatibility purpose with the existing structure. I decide to reduce
			// the position to 16 bits.
			event.key = ((y & 0xFFFF) << 16) | (x & 0xFFFF);

		} else {
			event.key = 0;
			event.evt = 0;
		}

		PADWriteEvent(event);
	}
#endif
}
Esempio n. 10
0
File: Viewer.cpp Progetto: Sosi/grip
/**
 * @function OnMouse
 */
void Viewer::OnMouse(wxMouseEvent& evt){
	if(!handleEvents) return;
	evt.GetPosition(&x,&y);

	if(evt.ButtonUp() && mouseCaptured){
		ReleaseMouse();
		mouseCaptured = false;
	}

	if(evt.ButtonDown() && !mouseCaptured){
		prevCamT = camT;
		prevWorldV = worldV;
		xInit = x;
		yInit = y;
		SetFocus();
		CaptureMouse();
		mouseCaptured = true;
		return;
	}
	double dx = (double)(x-xInit);
	double dy = (double)(y-yInit);

	if (evt.LeftIsDown() && evt.RightIsDown()){
		xInit = x;
		yInit = y;
		double camR = camRadius + dy *CAMERASPEED* 2.0f;
		if(camR > .05)
			camRadius = camR;
		UpdateCamera();
		DrawGLScene();
	}else if(evt.LeftIsDown()){
		double theta,phi;
		theta = -(dx/90.f);
		phi = -(dy/90.f);

		Matrix3d tm,pm;
		tm = AngleAxisd(theta, Vector3d::UnitZ());
		pm = AngleAxisd(phi, Vector3d::UnitY());

		Matrix3d drot = prevCamT.rotation();
		drot *= tm;
		drot *= pm;
		camRotT = drot;

		UpdateCamera();
		DrawGLScene();
	}else if(evt.MiddleIsDown() || evt.RightIsDown()){

		Vector3d dispV = camRotT*Vector3d(0,(double)dx * CAMERASPEED , -(double)dy * CAMERASPEED);
		worldV = prevWorldV+dispV;
		UpdateCamera();
		DrawGLScene();
	}
}
Esempio n. 11
0
void ToolBarArea::OnMouse(wxMouseEvent &evt)
{
   if (mCapturedChild) {
      if (evt.ButtonUp())
         mCapturedChild->FinishMoving();
      else if (evt.Moving() || evt.Dragging())
         mCapturedChild->UpdateMoving();
   }
   else {
      evt.Skip();
   }
}
Esempio n. 12
0
void MixerBoardScrolledWindow::OnMouseEvent(wxMouseEvent& event)
{
   if (event.ButtonUp()) 
   {
      //v Even when I implement MixerBoard::OnMouseEvent and call event.Skip() 
      // here, MixerBoard::OnMouseEvent never gets called.
      // So, added mProject to MixerBoardScrolledWindow and just directly do what's needed here.
      mProject->SelectNone();
   }
   else
      event.Skip();
}
Esempio n. 13
0
void FilterPanel::OnMouseEvent(wxMouseEvent & event)
{
   if (event.ButtonDown()) {
      CaptureMouse();
   }

   if (mEnvelope->MouseEvent(event, mEnvRect, 0.0, mWidth, false))
      Refresh(false);

   if (event.ButtonUp()) {
      ReleaseMouse();
   }
}
Esempio n. 14
0
	bool OnMouseEvent(wxMouseEvent &event)
	{
		if (event.Dragging())
		{
			timing_controller->OnMarkerDrag(
				markers,
				display->TimeFromRelativeX(event.GetPosition().x),
				default_snap != event.ShiftDown() ? display->TimeFromAbsoluteX(snap_range) : 0);
		}

		// We lose the marker drag if the button used to initiate it goes up
		return !event.ButtonUp(button_used);
	}
Esempio n. 15
0
void EqualizationPanel::OnMouseEvent(wxMouseEvent & event)
{
   if (event.ButtonDown()) {
      CaptureMouse();
   }

   if (mEnvelope->MouseEvent(event, mEnvRect, 0.0, mEnvRect.width, false,
                             0.0, 1.0))
      Refresh(false);

   if (event.ButtonUp()) {
      ReleaseMouse();
   }
}
Esempio n. 16
0
void AButton::OnMouseEvent(wxMouseEvent & event)
{
   if (mButtonIsDown || !mEnabled)
      return;

   if (event.ButtonUp()) {
      mIsClicking = false;

      ReleaseMouse();

      if (event.m_x >= 0 && event.m_y >= 0 &&
          event.m_x < mWidth && event.m_y < mHeight) {
         mButtonState = AButtonDown;
         mButtonIsDown = true;

         wxCommandEvent *e =
             new wxCommandEvent(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
         GetParent()->ProcessEvent(*e);
         delete e;
      }

      this->Refresh(false);
      return;
   }

   if (event.ButtonDown()) {
      mIsClicking = true;
      CaptureMouse();
   }

   if (mIsClicking) {
      if (event.m_x >= 0 && event.m_y >= 0 &&
          event.m_x < mWidth && event.m_y < mHeight) {
         mButtonState = AButtonDown;
      } else
         mButtonState = AButtonUp;
      this->Refresh(false);
   } else {
      if (event.Entering()) {
         mButtonState = AButtonOver;
         this->Refresh(false);
      }

      if (event.Leaving()) {
         mButtonState = AButtonUp;
         this->Refresh(false);
      }
   }
}
Esempio n. 17
0
// 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;
}
Esempio n. 18
0
void MixerTrackSlider::OnMouseEvent(wxMouseEvent &event)
{
   ASlider::OnMouseEvent(event);

   if (event.ButtonUp())
   {
      MixerTrackCluster* pMixerTrackCluster = (MixerTrackCluster*)(this->GetParent());
      switch (mStyle)
      {
      case DB_SLIDER: pMixerTrackCluster->HandleSliderGain(true); break;
      case PAN_SLIDER: pMixerTrackCluster->HandleSliderPan(true); break;
      default: break; // no-op
      }
   }
}
void PanosphereOverviewCameraTool::MouseButtonEvent(wxMouseEvent &e)
{
//    DEBUG_DEBUG("mouse ov drag button");
    if ((e.ButtonDown() && (!helper->IsMouseOverPano() || e.CmdDown() || e.AltDown())) || e.MiddleDown()) {
        down = true;
        hugin_utils::FDiff2D pos = helper->GetMouseScreenPosition();
        start_x = pos.x;
        start_y = pos.y;
        PanosphereOverviewVisualizationState*  state = (PanosphereOverviewVisualizationState*) helper->GetVisualizationStatePtr();
        start_angx = state->getAngX();
        start_angy = state->getAngY();
    }
    if (e.ButtonUp()) {
        if (down) {
            down = false;
        }
    }
}
Esempio n. 20
0
bool wxStdListboxInputHandler::HandleMouse(wxInputConsumer *consumer,
                                           const wxMouseEvent& event)
{
    wxListBox *lbox = wxStaticCast(consumer->GetInputWindow(), wxListBox);
    int item = HitTest(lbox, event);
    wxControlAction action;

    // when the left mouse button is pressed, capture the mouse and track the
    // item under mouse (if the mouse leaves the window, we will still be
    // getting the mouse move messages generated by wxScrollWindow)
    if ( event.LeftDown() )
    {
        // capture the mouse to track the selected item
        lbox->CaptureMouse();

        action = SetupCapture(lbox, event, item);
    }
    else if ( m_btnCapture && event.ButtonUp(m_btnCapture) )
    {
        // when the left mouse button is released, release the mouse too
        wxWindow *winCapture = wxWindow::GetCapture();
        if ( winCapture )
        {
            winCapture->ReleaseMouse();
            m_btnCapture = 0;

            action = m_actionMouse;
        }
        //else: the mouse wasn't presed over the listbox, only released here
    }
    else if ( event.LeftDClick() )
    {
        action = wxACTION_LISTBOX_ACTIVATE;
    }

    if ( !action.IsEmpty() )
    {
        lbox->PerformAction(action, item);

        return true;
    }

    return wxStdInputHandler::HandleMouse(consumer, event);
}
Esempio n. 21
0
void CTimeBarItem::OnMouse(wxMouseEvent& event)
{
    
    CTimeBarItemContainer* pParent = (CTimeBarItemContainer*)GetParent();
    CTimeBarFrame* pFrame = pParent->GetTimeBarFrameWindow();
    wxPoint pstn= event.GetPosition(); 
    int index = PointToCell(pstn);
    int iCellWidth = pParent->GetCellWidth();
    int CursorPosition = pstn.x / iCellWidth;
    CursorPosition *= iCellWidth;
    CursorPosition += iCellWidth * 0.5F;
    if (event.ButtonDown(wxMOUSE_BTN_LEFT))
    {
        pFrame->SetClickOnScalebar(false);
        pParent->GetCurrentSelect().m_iSelectRowBegin = index;
        pParent->GetCurrentSelect().m_iSelectColumnBegin = GetColumnID();
        pParent->GetCurrentSelect().m_iSelectRowEnd = index;
        pParent->GetCurrentSelect().m_iSelectColumnEnd = GetColumnID();
        pFrame->SetCursorPositionX(CursorPosition);
        pFrame->ClickOnScaleBar();
    }
    else if (event.Dragging())
    {   
        if (pstn.x % FREQUENCYREDUCTIONFACTOR == 0)
        {
            if (!pParent->GetTimeBarFrameWindow()->IsClickOnScalebar())
            {
                pParent->GetCurrentSelect().m_iSelectRowEnd = index;
                pParent->GetCurrentSelect().m_iSelectColumnEnd = GetColumnID();
            }
            pFrame->SetCursorPositionX(CursorPosition);
            pFrame->ClickOnScaleBar();
        }
    }
    else if (event.ButtonUp(wxMOUSE_BTN_LEFT))
    {
        int id = GetColumnID();
        pFrame->SetCurrentSelect(id);
    }
    event.Skip();
};
Esempio n. 22
0
void HighlightTextCtrl::OnMouseEvent(wxMouseEvent& event)
{
   if (event.ButtonUp())
   {
      long from, to;
      this->GetSelection(&from, &to);

      int nCurSyl = mLyrics->GetCurrentSyllableIndex();
      int nNewSyl = mLyrics->FindSyllable(from);
      if (nNewSyl != nCurSyl)
      {
         Syllable* pCurSyl = mLyrics->GetSyllable(nNewSyl);
         AudacityProject* pProj = GetActiveProject();
         pProj->SetSel0(pCurSyl->t);

         //v Should probably select to end as in AudacityProject::OnSelectCursorEnd,
         // but better to generalize that in AudacityProject methods.
         pProj->mViewInfo.selectedRegion.setT1(pCurSyl->t);
      }
   }

   event.Skip();
}
Esempio n. 23
0
void CTimeBarScale::OnMouse( wxMouseEvent& event )
{
    if (m_pTimeBarFrame->IsEnableFramePanel())
    {
        CTimeBarItemContainer* pContiner = m_pTimeBarFrame->GetItemContainer();
        if (event.ButtonDown(wxMOUSE_BTN_LEFT))
        {
            if (!HasCapture())
            {
                CaptureMouse();
            }
            m_pTimeBarFrame->SetClickOnScalebar(true);
            wxPoint pstn = event.GetPosition();
            int iScale = PointToScale(pstn);
            int iPositionX = iScale + pContiner->GetViewStart().x;
            m_pTimeBarFrame->SetCursorPos(iPositionX);
            m_pTimeBarFrame->RefreshControl();
        }
        else if (event.ButtonUp(wxMOUSE_BTN_LEFT))
        {
            if (HasCapture())
            {
                ReleaseMouse();
            }
        }
        else if (event.Dragging())
        {
            wxPoint pstn = event.GetPosition();
            {
                int iScale = PointToScale(pstn);
                int iPositionX = iScale + pContiner->GetViewStart().x;
                m_pTimeBarFrame->SetCursorPos(iPositionX);
                m_pTimeBarFrame->RefreshControl();
            }
        }
    }
}
Esempio n. 24
0
void view::on_mouse_event(wxMouseEvent& evt) {
    wxPoint pos = evt.GetPosition();
    rtransform(pos.x, pos.y);
    ptr<visual> processor = get_mouse_processor(m_mouse_processor, this, 
            m_doc->get_objects(), pos);
    long flag = 0;
    if (evt.LeftIsDown())
        flag |= flag_left_button;
    if (evt.RightIsDown())
        flag |= flag_right_button;
    if (evt.MiddleIsDown())
        flag |= flag_middle_button;

    if (m_mouse_last_processor != processor) {
        processor->on_mouse_move_in(pos.x, pos.y, flag);
        if (m_mouse_last_processor != nullptr)
            m_mouse_last_processor->on_mouse_move_out(pos.x, pos.y, flag);
    }

    if (evt.GetWheelDelta() != 0) {
        int ds = evt.GetWheelDelta() / evt.GetWheelRotation();
        processor->on_mouse_wheel(pos.x, pos.y, ds, flag);
    } else if (evt.Moving() || evt.Dragging()) {
        processor->on_mouse_move(pos.x, pos.y, flag);
    } else if (evt.ButtonDown()) {
        processor->on_mouse_down(pos.x, pos.y, flag);
    } else if (evt.ButtonUp()) {
        processor->on_mouse_up(pos.x, pos.y, flag);
        change_select(processor);
    } else if (evt.ButtonDClick()) {
        processor->on_mouse_dclick(pos.x, pos.y, flag);
    }

    m_mouse_last_processor = processor;
    refresh();
}
Esempio n. 25
0
void LWSlider::OnMouseEvent(wxMouseEvent & event)
{
   if (event.Entering()) {
      #if wxUSE_TOOLTIPS // Not available in wxX11
      // Display the tooltip in the status bar
      if (mParent->GetToolTip()) 
      {
         wxString tip = mParent->GetToolTip()->GetTip();
         GetActiveProject()->TP_DisplayStatusMessage(tip);
         Refresh();
      }
      #endif
   }
   else if (event.Leaving())
   {
      GetActiveProject()->TP_DisplayStatusMessage(wxT(""));
      Refresh();
   }

   // Events other than mouse-overs are ignored when we are disabled
   if (!mEnabled)
      return;

   float prevValue = mCurrentValue;

   // Figure out the thumb position
   wxRect r;
   if (mOrientation == wxHORIZONTAL)
   {
      r.x = mLeft + ValueToPosition(mCurrentValue);
      r.y = mTop + (mCenterY - (mThumbHeight / 2));
   }
   else 
   {
      r.x = mLeft + (mCenterX - (mThumbWidth / 2));
      r.y = mTop + ValueToPosition(mCurrentValue);
   }
   r.width = mThumbWidth;
   r.height = mThumbHeight;

   wxRect tolerantThumbRect = r;
   tolerantThumbRect.Inflate(3, 3);

   // Should probably use a right click instead/also
   if( event.ButtonDClick() && mPopup )
   {
      //On a double-click, we should pop up a dialog.
      DoShowDialog(mParent->ClientToScreen(wxPoint(event.m_x,event.m_y)));
   }
   else if( event.ButtonDown() )
   {
      if( mDefaultShortcut && event.CmdDown() )
      {
         mCurrentValue = mDefaultValue;
      }

      if( event.RightDown() ) {
         mParent->SetFocus();
      }

      // Thumb clicked?
      //
      // Do not change position until first drag.  This helps
      // with unintended value changes.
      if( tolerantThumbRect.Contains( event.GetPosition() ) )
      {
         // Remember mouse position and current value
         mClickPos = (mOrientation == wxHORIZONTAL) ? event.m_x : event.m_y;
         mClickValue = mCurrentValue;

         mIsDragging = true;
      }
      // Clicked to set location?
      else
      {
         mCurrentValue = 
            ClickPositionToValue(
               (mOrientation == wxHORIZONTAL) ? event.m_x : event.m_y, 
               event.ShiftDown());
      }

      mParent->CaptureMouse();
      // wxSetCursor(wxCURSOR_BLANK);
      ((TipPanel*)LWSlider::sharedTipPanel)->SetTargetParent(mParent);
      FormatPopWin();
      SetPopWinPosition();
      LWSlider::sharedTipPanel->Show();
      //hide mouseover tooltip
      wxToolTip::Enable(false);
   }
   else if( event.ButtonUp() )
   {
      mIsDragging = false;
      if (mParent->HasCapture())
         mParent->ReleaseMouse();
      LWSlider::sharedTipPanel->Hide();
      //restore normal tooltip behavor for mouseovers
      wxToolTip::Enable(true);
      // wxSetCursor(wxNullCursor);
   }
   else if (event.Dragging() && mIsDragging)
   {
      if (mOrientation == wxHORIZONTAL)
      {
         if (event.m_y < (r.y - 2 * r.height) ||
             event.m_y > (r.y + 3 * r.height)) {
            // If the mouse y coordinate is relatively far from the slider,
            // snap back to the original position
            mCurrentValue = mClickValue;
         }
         else {
            // Otherwise, move the slider to the right position based
            // on the mouse position
            mCurrentValue = DragPositionToValue(event.m_x, event.ShiftDown());
         }
      }
      else // (mOrientation == wxVERTICAL)
      {
         if (event.m_x < (r.x - 2 * r.width) ||
             event.m_x > (r.x + 3 * r.width)) {
            // If the mouse x coordinate is relatively far from the slider,
            // snap back to the original position
            mCurrentValue = mClickValue;
         }
         else {
            // Otherwise, move the slider to the right position based
            // on the mouse position
            mCurrentValue = DragPositionToValue(event.m_y, event.ShiftDown());
         }
      }
   }
   else if( event.m_wheelRotation != 0 )
   {
      //Calculate the number of steps in a given direction this event
      //represents (allows for two or more clicks on a single event.)
      double steps =  event.m_wheelRotation /
         (event.m_wheelDelta > 0 ? (double)event.m_wheelDelta : 120.0);

      if( steps < 0.0 )
      {
         Decrease( (float)-steps );
      }
      else
      {
         Increase( (float)steps );
      }
      SendUpdate( mCurrentValue );
   }

   if( prevValue != mCurrentValue )
      SendUpdate( mCurrentValue );
}
void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
{
    int          localbutt = 0;
    BASE_SCREEN* screen = GetScreen();

    if( !screen )
        return;

    /* Adjust value to filter mouse displacement before consider the drag
     * mouse is really a drag command, not just a movement while click
     */
#define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND 5

    if( event.Leaving() )
        m_canStartBlock = -1;

    if( !IsMouseCaptured() )          // No mouse capture in progress.
        SetAutoPanRequest( false );

    if( GetParent()->IsActive() )
        SetFocus();
    else
        return;

    if( !event.IsButton() && !event.Moving() && !event.Dragging() )
        return;

    if( event.RightDown() )
    {
        OnRightClick( event );
        return;
    }

    if( m_ignoreMouseEvents )
        return;

    if( event.LeftDown() )
        localbutt = GR_M_LEFT_DOWN;

    if( event.ButtonDClick( 1 ) )
        localbutt = GR_M_LEFT_DOWN | GR_M_DCLICK;

    if( event.MiddleDown() )
        localbutt = GR_M_MIDDLE_DOWN;

    INSTALL_UNBUFFERED_DC( DC, this );
    DC.SetBackground( *wxBLACK_BRUSH );

    // Compute the cursor position in drawing (logical) units.
    GetParent()->SetMousePosition( event.GetLogicalPosition( DC ) );

    int kbstat = 0;

    if( event.ShiftDown() )
        kbstat |= GR_KB_SHIFT;

    if( event.ControlDown() )
        kbstat |= GR_KB_CTRL;

    if( event.AltDown() )
        kbstat |= GR_KB_ALT;

    // Calling Double Click and Click functions :
    if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) )
    {
        if( m_ClickTimer )
        {
            m_ClickTimer->Stop();
            wxDELETE( m_ClickTimer );
        }
        GetParent()->OnLeftDClick( &DC, GetParent()->RefPos( true ) );

        // inhibit a response to the mouse left button release,
        // because we have a double click, and we do not want a new
        // OnLeftClick command at end of this Double Click
        m_ignoreNextLeftButtonRelease = true;
    }
    else if( event.LeftUp() )
    {
        // A block command is in progress: a left up is the end of block
        // or this is the end of a double click, already seen
        // Note also m_ignoreNextLeftButtonRelease can be set by
        // the call to OnLeftClick(), so do not change it after calling OnLeftClick
        bool ignoreEvt = m_ignoreNextLeftButtonRelease;
        m_ignoreNextLeftButtonRelease = false;

        if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK && !ignoreEvt )
        {
            EDA_ITEM* item = screen->GetCurItem();
            m_CursorClickPos = GetParent()->RefPos( true );

            // If we have an item already selected, or we are using a tool,
            // we won't use the disambiguation menu so process the click immediately
            if( ( item && item->GetFlags() ) || GetParent()->GetToolId() != ID_NO_TOOL_SELECTED )
                GetParent()->OnLeftClick( &DC, m_CursorClickPos );
            else
            {
                wxDELETE( m_ClickTimer );
                m_ClickTimer = new wxTimer(this, ID_MOUSE_DOUBLECLICK);
                m_ClickTimer->StartOnce( m_doubleClickInterval );
            }
        }

    }
    else if( !event.LeftIsDown() )
    {
        /* be sure there is a response to a left button release command
         * even when a LeftUp event is not seen.  This happens when a
         * double click opens a dialog box, and the release mouse button
         * is made when the dialog box is opened.
         */
        m_ignoreNextLeftButtonRelease = false;
    }

    if( event.ButtonDown( wxMOUSE_BTN_MIDDLE ) )
    {
        m_PanStartCenter = GetParent()->GetScrollCenterPosition();
        m_PanStartEventPosition = event.GetPosition();

        INSTALL_UNBUFFERED_DC( dc, this );
        CrossHairOff( &dc );
        SetCursor( wxCURSOR_SIZING );
    }

    if( event.ButtonUp( wxMOUSE_BTN_MIDDLE ) )
    {
        INSTALL_UNBUFFERED_DC( dc, this );
        CrossHairOn( &dc );
        SetCursor( (wxStockCursor) m_currentCursor );
    }

    if( event.MiddleIsDown() )
    {
        wxPoint currentPosition = event.GetPosition();

        double scale = GetParent()->GetScreen()->GetScalingFactor();
        int x = m_PanStartCenter.x +
                KiROUND( (double) ( m_PanStartEventPosition.x - currentPosition.x ) / scale );
        int y = m_PanStartCenter.y +
                KiROUND( (double) ( m_PanStartEventPosition.y - currentPosition.y ) / scale );

        GetParent()->RedrawScreen( wxPoint( x, y ), false );
    }

    // Calling the general function on mouse changes (and pseudo key commands)
    GetParent()->GeneralControl( &DC, event.GetLogicalPosition( DC ), 0 );

    /*******************************/
    /* Control of block commands : */
    /*******************************/

    // Command block can't start if mouse is dragging a new panel
    static EDA_DRAW_PANEL* lastPanel;
    if( lastPanel != this )
    {
        m_minDragEventCount = 0;
        m_canStartBlock   = -1;
    }

    /* A new command block can start after a release buttons
     * and if the drag is enough
     * This is to avoid a false start block when a dialog box is dismissed,
     * or when changing panels in hierarchy navigation
     * or when clicking while and moving mouse
     */
    if( !event.LeftIsDown() && !event.MiddleIsDown() )
    {
        m_minDragEventCount = 0;
        m_canStartBlock   = 0;

        /* Remember the last cursor position when a drag mouse starts
         * this is the last position ** before ** clicking a button
         * this is useful to start a block command from the point where the
         * mouse was clicked first
         * (a filter creates a delay for the real block command start, and
         * we must remember this point)
         */
        m_CursorStartPos = GetParent()->GetCrossHairPosition();
    }

    if( m_enableBlockCommands && !(localbutt & GR_M_DCLICK) )
    {
        if( !screen->IsBlockActive() )
        {
            screen->m_BlockLocate.SetOrigin( m_CursorStartPos );
        }

        if( event.LeftDown() )
        {
            if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE )
            {
                SetAutoPanRequest( false );
                GetParent()->HandleBlockPlace( &DC );
                m_ignoreNextLeftButtonRelease = true;
            }
        }
        else if( ( m_canStartBlock >= 0 ) && event.LeftIsDown() && !IsMouseCaptured() )
        {
            // Mouse is dragging: if no block in progress,  start a block command.
            if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK )
            {
                //  Start a block command
                int cmd_type = kbstat;

                // A block command is started if the drag is enough.  A small
                // drag is ignored (it is certainly a little mouse move when
                // clicking) not really a drag mouse
                if( m_minDragEventCount < MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND )
                    m_minDragEventCount++;
                else
                {
                    auto cmd = (GetParent()->GetToolId() == ID_ZOOM_SELECTION) ? BLOCK_ZOOM : 0;

                    if( !GetParent()->HandleBlockBegin( &DC, cmd_type, m_CursorStartPos, cmd ) )
                    {
                        // should not occur: error
                        GetParent()->DisplayToolMsg(
                            wxT( "EDA_DRAW_PANEL::OnMouseEvent() Block Error" ) );
                    }
                    else
                    {
                        SetAutoPanRequest( true );
                        SetCursor( wxCURSOR_SIZING );
                    }
                }
            }
        }

        if( event.ButtonUp( wxMOUSE_BTN_LEFT ) )
        {
            /* Release the mouse button: end of block.
             * The command can finish (DELETE) or have a next command (MOVE,
             * COPY).  However the block command is canceled if the block
             * size is small because a block command filtering is already
             * made, this case happens, but only when the on grid cursor has
             * not moved.
             */
            #define BLOCK_MINSIZE_LIMIT 1
            bool BlockIsSmall =
                ( std::abs( screen->m_BlockLocate.GetWidth() ) < BLOCK_MINSIZE_LIMIT )
                && ( std::abs( screen->m_BlockLocate.GetHeight() ) < BLOCK_MINSIZE_LIMIT );

            if( (screen->m_BlockLocate.GetState() != STATE_NO_BLOCK) && BlockIsSmall )
            {
                if( m_endMouseCaptureCallback )
                {
                    m_endMouseCaptureCallback( this, &DC );
                    SetAutoPanRequest( false );
                }

                SetCursor( (wxStockCursor) m_currentCursor );
           }
            else if( screen->m_BlockLocate.GetState() == STATE_BLOCK_END )
            {
                SetAutoPanRequest( false );
                GetParent()->HandleBlockEnd( &DC );
                SetCursor( (wxStockCursor) m_currentCursor );
                if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE )
                {
                    SetAutoPanRequest( true );
                    SetCursor( wxCURSOR_HAND );
                }
           }
        }
    }

    // End of block command on a double click
    // To avoid an unwanted block move command if the mouse is moved while double clicking
    if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) )
    {
        if( !screen->IsBlockActive() && IsMouseCaptured() )
        {
            m_endMouseCaptureCallback( this, &DC );
        }
    }

    lastPanel = this;

#ifdef __WXGTK3__
    // Screen has to be updated on every operation, otherwise the cursor leaves a trail (when xor
    // operation is changed to copy) or is not updated at all.
    Refresh();
#endif
}
Esempio n. 27
0
// Manages user input [Mouse click, drag & drop] over the Canvas
void gqbView::onMotion(wxMouseEvent &event)
{
	static int refresh = 1;                       // refresh counter, everytime this values reaches
	// "refreshRate" value then Refresh while dragging
	// Discover area where event ocurrs
	pos.x = event.GetPosition().x;
	pos.y = event.GetPosition().y;
	this->CalcUnscrolledPosition(pos.x, pos.y, &pos.x, &pos.y);
	gqbObject *anySelected = NULL;

	// Button Down Event is triggered
	if(event.ButtonDown() && !changeTOpressed)
	{
		this->SetFocus();

		// Which kind of button down was? join creation [click on any column at the
		// right of checkbox and drag & drop] or table moving [click on title and drag & drop]
		anySelected = controller->getModelSelected(pos, collectionSelected, joinSelected, false);
		if(anySelected)
		{
			// Anything before just forget about it
			changeTOpressed = false;
			joinSource = NULL;
			joinSCol = NULL;
			joinDCol = NULL;
			joinDest = NULL;
			jpos.x = 0;
			jpos.y = 0;

			if(anySelected->getType() == GQB_QUERYOBJ)
			{
				gqbQueryObject *t = (gqbQueryObject *) (gqbObjectCollection *) anySelected;

				// If click on the title area AND don't click on the columns selection checkbox
				if( (pos.y - t->position.y <= graphBehavior->getTitleRowHeight()))
					controller->setPointerMode(pt_normal);
				else if(pos.x - t->position.x <= 17)
					controller->setPointerMode(pt_normal);
				else
					controller->setPointerMode(pt_join);
			}
		}
		else
		{
			anySelected = NULL;
			mode = pt_normal;
		}

		if(mode == pt_normal)                     // pointer is used to move tables & select/unselect columns
		{
			// getSelected Item [Mark it as selected if possible]
			anySelected = controller->getModelSelected(pos, collectionSelected, joinSelected, true);
			changeTOpressed = true;

			// Do conversion of type object if any found
			if(anySelected)
			{
				if(anySelected->getType() == GQB_QUERYOBJ)
				{
					collectionSelected = (gqbQueryObject *) (gqbObjectCollection *) anySelected;
					joinSelected = NULL;
				}
				else if(anySelected->getType() == GQB_JOIN)
				{
					joinSelected = (gqbQueryJoin *) anySelected;
					collectionSelected = NULL;
				}
			}
			else
			{
				collectionSelected = NULL;
				joinSelected = NULL;
			}

			if(!collectionSelected)
			{
				// none selected temp unselect all items
				controller->unsetModelSelected(true);
			}
			else
			{
				gqbColumn *col = graphBehavior->getColumnAtPosition(&pos, collectionSelected);
				if(col)
				{
					// Add or remove column from model & observers (ex: Grid) (projection part of SQL sentence)
					controller->processColumnInModel(collectionSelected, col, gridTable);
				}
			}

			if(!joinSelected)
			{
				controller->unsetModelSelected(false);
			}

		}
		// Pointer is used to add joins
		else if(mode == pt_join)
		{
			anySelected = controller->getModelSelected(pos, collectionSelected, joinSelected, false);

			// Even if I get an object check that it isn't a join
			if( (anySelected) && anySelected->getType() == GQB_QUERYOBJ)
				joinSource = (gqbQueryObject *)(gqbObjectCollection *) anySelected;
			else
				joinSource = NULL;

			if(!joinSource)
			{
				// creation of join starts
				joinSCol = NULL;
				joinDCol = NULL;
				jpos.x = 0;
				jpos.y = 0;
			}
			else
			{
				joinSCol = graphBehavior->getColumnAtPosition(&pos, joinSource, joinSource->getWidth());
				jpos = pos;

				// GQB-TODO then draw line between column & pointer
			}
		}

		this->Refresh();
	}

	// Button Up Event is triggered
	if(event.ButtonUp())
	{
		// Pointer is used to move tables & select/unselect columns
		if(mode == pt_normal)
		{
			changeTOpressed = false;
			anySelected = controller->getModelSelected(pos, collectionSelected, joinSelected, false);
			if (anySelected && anySelected->getType() == GQB_JOIN)
			{
				gqbJoinsPanel *jPanel = wxDynamicCast( joinsPanel, gqbJoinsPanel );
				jPanel->selectJoin((gqbQueryJoin *)anySelected);
			}
		}
		// Pointer is used to add joins
		else if(mode == pt_join)
		{
			anySelected = controller->getModelSelected(pos, collectionSelected, joinSelected, false);

			// Even if I get an object check that it isn't a join
			if( (anySelected) && anySelected->getType() == GQB_QUERYOBJ)
			{
				joinDest = (gqbQueryObject *)(gqbObjectCollection *) anySelected;
				// Validate not self joins [in this version tables can be duplicated to create same effect]
				if(joinDest == joinSource)
				{
					joinDest = NULL;
				}
			}
			else
				joinDest = NULL;

			// Creation of join starts
			if(!joinDest)
			{
				joinSource = NULL;
				joinSCol = NULL;
				joinDCol = NULL;
				joinDest = NULL;
				jpos.x = 0;
				jpos.y = 0;
			}
			else
			{
				joinDCol = graphBehavior->getColumnAtPosition(&pos, joinDest, joinDest->getWidth());
				if(joinDCol)
				{
					// GQB-TODO: Allow other type of joins
					gqbQueryJoin *qj = controller->addJoin(joinSource, joinSCol, joinDest, joinDCol, _equally);
					graphBehavior->calcAnchorPoint(qj);
					this->joinsGridTable->AppendJoin(qj);
				}
				// Let the temporary join line to be draw again [Don't destroy anything because all object where own by other objects this are just pointers]
				joinSource = NULL;
				joinSCol = NULL;
				joinDest = NULL;
				joinDCol = NULL;
				jpos.x = 0;
				jpos.y = 0;
			}
		}

		controller->setPointerMode(pt_normal);    //when button is up, pointer mode should be only normal
		this->Refresh();
	}

	// Mouse is Dragged while mouse button is down
	if (event.Dragging() && pressed)
	{
		if(mode == pt_normal)
		{
			if(collectionSelected)
			{
				// GQB-TODO: same as gqbGraphBehavior.h [find a way to not hard code the 17 default value]
				if((pos.x > collectionSelected->position.x + 17) || (pos.x < collectionSelected->position.x) )
				{
					graphBehavior->UpdatePosObject(collectionSelected, pos.x, pos.y, 40);
				}

				// Don't draw too much when dragging table around canvas [lower cpu use]
				if(refresh % refreshRate == 0)
				{
					this->Refresh();
					refresh = 1;
				}
				else
					refresh++;

			}
		}
		else if(mode == pt_join)
		{
			if(joinSource && !joinDest)
			{
				this->Refresh();
			}

		}
	}
}
Esempio n. 28
0
void AudacityProject::OnMouseEvent(wxMouseEvent & event)
{
   if(event.ButtonDown())
      SetActiveProject(this);

   wxPoint hotspot;
   hotspot.x = event.m_x;
   hotspot.y = event.m_y;

   wxPoint mouse = ClientToScreen(hotspot);

   if (event.ButtonDown() && !mDrag &&
       !gWindowedPalette &&
       event.m_x < 10 && event.m_y < GetAPaletteHeight()) {

      int width, height;
      mAPalette->GetSize(&width, &height);

#ifdef __WXMAC__
      /*
         Point startPt;
         startPt.h = hotspot.x;
         startPt.v = hotspot.y;
         Rect limitRect, slopRect, r;
         SetRect(&limitRect, -32767,-32767,32767,32767);
         SetRect(&slopRect, -32767,-32767,32767,32767);
         SetRect(&r, 10, 0, 10+width, height);
         int axis = noConstraint;
         RgnHandle theRgn = NewRgn();
         RectRgn(theRgn, &r);

         int result = DragGrayRgn(theRgn, startPt, &limitRect, &slopRect, axis, NULL);

         if (result == 0x80008000)
         return;

         mouse -= hotspot;
         mouse.x += (short)(result & 0xFFFF);
         mouse.y += (short)((result & 0xFFFF0000)>>16);

         ShowWindowedPalette(&mouse);
       */
#else

      wxClientDC dc(this);

      wxBitmap *bitmap = new wxBitmap(width, height);
      wxMemoryDC *memDC = new wxMemoryDC();
      memDC->SelectObject(*bitmap);
      memDC->Blit(0, 0, width, height, &dc, 10, 0);
      delete memDC;

      mDrag = new wxDragImage(*bitmap);

      delete bitmap;

      mDrag->BeginDrag(hotspot, this, true);
      mDrag->Move(mouse);
      mDrag->Show();
      mPaletteHotspot = hotspot;

#endif
   }
#ifndef __WXMAC__
   if (event.Dragging() && mDrag) {
      mDrag->Move(mouse);
   }

   if (event.ButtonUp() && mDrag) {
      mDrag->Hide();
      mDrag->EndDrag();
      delete mDrag;
      mDrag = NULL;

      mouse -= mPaletteHotspot;
      ShowWindowedPalette(&mouse);
   }
#endif
}
Esempio n. 29
0
// Returns true if parent needs to be redrawn
bool Envelope::MouseEvent(wxMouseEvent & event, wxRect & r,
                          double h, double pps, bool dB)
{
   //h -= mOffset;

   int ctr, height;
   bool upper;
   if (mMirror) {
      height = r.height / 2;
      ctr = r.y + height;
      upper = (event.m_y < ctr);
   }
   else {
      height = r.height;
      ctr = r.y + height;
      upper = true;
   }

   if (event.ButtonDown()) {
      mIsDeleting = false;
      double tleft = h - mOffset;
      double tright = tleft + (r.width / pps);
      int bestNum = -1;
      int bestDist = 10;

      int len = mEnv.Count();
      for (int i = 0; i < len; i++) {
         if (mEnv[i]->t >= tleft && mEnv[i]->t <= tright) {
            double v = mEnv[i]->val;
            int x = int ((mEnv[i]->t + mOffset - h) * pps) + r.x;
            int dy;

            if (dB)
               dy = int (toDB(v) * height);
            else
            dy = int (v * height);

            int y;
            if (upper)
               y = int (ctr - dy);
            else
            y = int (ctr + dy);

#ifndef SQR
#define SQR(X) ((X)*(X))
#endif

            int d =
                int (sqrt(SQR(x - event.m_x) + SQR(y - event.m_y)) + 0.5);
            if (d < bestDist) {
               bestNum = i;
               bestDist = d;
            }
         }
      }

      if (bestNum >= 0) {
         mDragPoint = bestNum;
      } else {
         // Create new point
         double when = h + (event.m_x - r.x) / pps - mOffset;

         int dy;
         if (upper)
            dy = ctr - event.m_y;
         else
            dy = event.m_y - ctr;

         double newVal;

         if (dB)
            newVal = fromDB(dy / double (height));
         else
            newVal = dy / double (height);

         if (newVal < 0.0)
            newVal = 0.0;
         if (newVal > 1.0)
            newVal = 1.0;

         mDragPoint = Insert(when, newVal);
         mDirty = true;
      }

      mUpper = upper;

      mInitialWhen = mEnv[mDragPoint]->t;
      mInitialVal = mEnv[mDragPoint]->val;

      mInitialX = event.m_x;
      mInitialY = event.m_y;

      return true;
   }

   if (event.Dragging() && mDragPoint >= 0) {
      mDirty = true;

      wxRect larger = r;
      larger.Inflate(5, 5);

      if (!mIsDeleting &&
          mDragPoint > 0 && mDragPoint < mEnv.Count() - 1 &&
          !larger.Inside(event.m_x, event.m_y)) {

         mEnv[mDragPoint]->t = mEnv[mDragPoint - 1]->t;
         mEnv[mDragPoint]->val = mEnv[mDragPoint - 1]->val;

         mIsDeleting = true;

         return true;
      }

      if (larger.Inside(event.m_x, event.m_y))
         mIsDeleting = false;

      if (mIsDeleting)
         return false;

      int y;
      if (mUpper)
         y = ctr - event.m_y;
      else
         y = event.m_y - ctr;

      double newVal;

      if (dB)
         newVal = fromDB(y / double (height));
      else
         newVal = y / double (height);

      if (newVal < 0.0)
         newVal = 0.0;
      if (newVal > 1.0)
         newVal = 1.0;

      double newWhen = mInitialWhen + (event.m_x - mInitialX) / pps;

      if (mDragPoint > 0 && newWhen < mEnv[mDragPoint - 1]->t)
         newWhen = mEnv[mDragPoint - 1]->t;

      if (mDragPoint < mEnv.Count() - 1
          && newWhen > mEnv[mDragPoint + 1]->t)
         newWhen = mEnv[mDragPoint + 1]->t;

      if (mDragPoint == 0)
         newWhen = 0;

      if (mDragPoint == mEnv.Count() - 1)
         newWhen = mTrackLen;

      mEnv[mDragPoint]->t = newWhen;
      mEnv[mDragPoint]->val = newVal;

      return true;
   }

   if (event.ButtonUp()) {
      if (mIsDeleting) {
         delete mEnv[mDragPoint];
         mEnv.RemoveAt(mDragPoint);
      }
      mDragPoint = -1;
      return true;
   }

   return false;
}
Esempio n. 30
0
void ExportMixerPanel::OnMouseEvent(wxMouseEvent & event)
{
    if( event.ButtonDown() )
    {
        CaptureMouse();

        bool reset = true;
        //check tracks
        for( int i = 0; i < mMixerSpec->GetNumTracks(); i++ )
            if( mTrackRects[ i ].Inside( event.m_x, event.m_y ) )
            {
                reset = false;
                if( mSelectedTrack == i )
                    mSelectedTrack = -1;
                else
                {
                    mSelectedTrack = i;
                    if( mSelectedChannel != -1 )
                        mMixerSpec->mMap[ mSelectedTrack ][ mSelectedChannel ] =
                            !mMixerSpec->mMap[ mSelectedTrack ][ mSelectedChannel ];
                }
                goto found;
            }

        //check channels
        for( int i = 0; i < mMixerSpec->GetNumChannels(); i++ )
            if( mChannelRects[ i ].Inside( event.m_x, event.m_y ) )
            {
                reset = false;
                if( mSelectedChannel == i )
                    mSelectedChannel = -1;
                else
                {
                    mSelectedChannel = i;
                    if( mSelectedTrack != -1 )
                        mMixerSpec->mMap[ mSelectedTrack ][ mSelectedChannel ] =
                            !mMixerSpec->mMap[ mSelectedTrack ][ mSelectedChannel ];
                }
                goto found;
            }

        //check links
        for( int i = 0; i < mMixerSpec->GetNumTracks(); i++ )
            for( int j = 0; j < mMixerSpec->GetNumChannels(); j++ )
                if( mMixerSpec->mMap[ i ][ j ]  && IsOnLine( wxPoint( event.m_x,
                        event.m_y ), wxPoint( mTrackRects[ i ].x + mBoxWidth,
                                              mTrackRects[ i ].y + mTrackHeight / 2 ),
                        wxPoint( mChannelRects[ j ].x, mChannelRects[ j ].y +
                                 mChannelHeight / 2 ) ) )
                    mMixerSpec->mMap[ i ][ j ] = false;

found:
        if( reset )
            mSelectedTrack = mSelectedChannel = -1;
        Refresh( false );
    }

    if( event.ButtonUp() )
    {
        if( HasCapture() )
            ReleaseMouse();
    }
}