Example #1
0
//---------------------------------------------------------
void CVIEW_Map_Control::On_Mouse_LDown(wxMouseEvent &event)
{
	m_Mouse_Down	= m_Mouse_Move	= event.GetPosition();

	//-----------------------------------------------------
	if( m_Mode != MAP_MODE_SELECT )	// clipboard copy ?
	{
		if( event.ControlDown() )
		{
			m_pMap->SaveAs_Image_Clipboard(false);

			return;
		}

		if( event.AltDown() )
		{
			m_pMap->SaveAs_Image_Clipboard(GetClientSize().x, GetClientSize().y, -1);

			return;
		}
	}

	//-----------------------------------------------------
	bool	bCaptureMouse	= true;

	switch( m_Mode )
	{
	//-----------------------------------------------------
	case MAP_MODE_SELECT:
		if( g_pTool && g_pTool->is_Interactive() )
		{
			m_Drag_Mode		= ((CSG_Tool_Interactive *)g_pTool->Get_Tool())->Get_Drag_Mode();
			bCaptureMouse	= !g_pTool->Execute(_Get_World(event.GetPosition()), TOOL_INTERACTIVE_LDOWN, GET_KEYS(event));
		}
		else if( m_pMap->Find_Layer(Get_Active_Layer()) )
		{
			switch(	Get_Active_Layer()->Get_Type() )
			{
			default:
				m_Drag_Mode		= TOOL_INTERACTIVE_DRAG_NONE;
				break;

			case WKSP_ITEM_Grid:
			case WKSP_ITEM_PointCloud:
				m_Drag_Mode		= TOOL_INTERACTIVE_DRAG_BOX;
				break;

			case WKSP_ITEM_Shapes:
				m_Drag_Mode		= ((CWKSP_Shapes *)Get_Active_Layer())->is_Editing()
								? TOOL_INTERACTIVE_DRAG_NONE
								: TOOL_INTERACTIVE_DRAG_BOX;
				break;
			}

			Get_Active_Layer()->Edit_On_Mouse_Down(_Get_World(event.GetPosition()), _Get_World(1.0), GET_KEYS(event));
		}
		break;

	//-----------------------------------------------------
	case MAP_MODE_DISTANCE:
		m_Drag_Mode		= TOOL_INTERACTIVE_DRAG_NONE;
		break;

	//-----------------------------------------------------
	case MAP_MODE_ZOOM:
		m_Drag_Mode		= TOOL_INTERACTIVE_DRAG_BOX;
		break;

	//-----------------------------------------------------
	case MAP_MODE_PAN:
		m_Drag_Mode		= TOOL_INTERACTIVE_DRAG_NONE;
		Set_Mode(MAP_MODE_PAN_DOWN);
		break;

	//-----------------------------------------------------
	case MAP_MODE_PAN_DOWN:
		m_Drag_Mode		= TOOL_INTERACTIVE_DRAG_NONE;
		break;
	}

	//-----------------------------------------------------
	if( bCaptureMouse && !HasCapture() )
	{
		CaptureMouse();
	}

	event.Skip();
}
Example #2
0
void CSelectMode::OnDragging( wxMouseEvent& event )
{
	if(event.MiddleIsDown())
	{
		wxPoint dm;
		dm.x = event.GetX() - CurrentPoint.x;
		dm.y = event.GetY() - CurrentPoint.y;
		if(wxGetApp().ctrl_does_rotate == event.ControlDown())
		{
			if(wxGetApp().m_rotate_mode)
			{
				wxGetApp().m_current_viewport->m_view_point.Turn(dm);
			}
			else
			{
				wxGetApp().m_current_viewport->m_view_point.TurnVertical(dm);
			}
		}
		else
		{
			wxGetApp().m_current_viewport->m_view_point.Shift(dm, wxPoint(event.GetX(), event.GetY()));
		}
		wxGetApp().m_current_viewport->m_need_update = true;
		wxGetApp().m_current_viewport->m_need_refresh = true;
	}
	else if(event.LeftIsDown())
	{
		if(wxGetApp().drag_gripper)
		{
			double to[3], from[3];
			wxGetApp().m_digitizing->digitize(wxPoint(event.GetX(), event.GetY()));
			extract(wxGetApp().m_digitizing->digitized_point.m_point, to);
			wxGetApp().grip_to = wxGetApp().m_digitizing->digitized_point.m_point;
			extract(wxGetApp().grip_from, from);
			wxGetApp().drag_gripper->OnGripperMoved(from, to);
			wxGetApp().grip_from = gp_Pnt(from[0], from[1], from[2]);
			wxGetApp().grip_from = make_point(from);
		}
		else if(abs(button_down_point.x - event.GetX())>2 || abs(button_down_point.y - event.GetY())>2)
		{
			if(wxGetApp().m_dragging_moves_objects && !window_box_exists)
			{
				std::list<HeeksObj*> selected_objects_dragged;
				wxGetApp().m_show_grippers_on_drag = true;

				if(	wxGetApp().m_marked_list->list().size() > 0)
				{
					for(std::list<HeeksObj*>::iterator It = wxGetApp().m_marked_list->list().begin(); It != wxGetApp().m_marked_list->list().end(); It++)
					{
						HeeksObj* object = *It;
						if(object->CanBeDragged())selected_objects_dragged.push_back(object);
					}
				}
				else
				{
					MarkedObjectManyOfSame marked_object;
					wxGetApp().FindMarkedObject(button_down_point, &marked_object);
					if(marked_object.m_map.size()>0){
						HeeksObj* object = marked_object.GetFirstOfTopOnly();
						double min_depth = 0.0;
						HeeksObj* closest_object = NULL;
						while(object)
						{
							if(object->CanBeDragged())
							{
								double depth = marked_object.GetDepth();
								if(closest_object == NULL || depth<min_depth)
								{
									min_depth = depth;
									closest_object = object;
								}
							}
							object = marked_object.Increment();
						}
						if(selected_objects_dragged.size() == 0 && closest_object){
							selected_objects_dragged.push_back(closest_object);
							wxGetApp().m_show_grippers_on_drag = false;
						}
					}
				}

				if(selected_objects_dragged.size() > 0)
				{
					wxGetApp().drag_gripper = &drag_object_gripper;
					wxGetApp().m_digitizing->SetOnlyCoords(wxGetApp().drag_gripper, true);
					wxGetApp().m_digitizing->digitize(button_down_point);
					wxGetApp().grip_from = wxGetApp().m_digitizing->digitized_point.m_point;
					wxGetApp().grip_to = wxGetApp().grip_from;
					double from[3];
					from[0] = wxGetApp().grip_from.X();
					from[1] = wxGetApp().grip_from.Y();
					from[2] = wxGetApp().grip_from.Z();
					wxGetApp().drag_gripper->OnGripperGrabbed(selected_objects_dragged, wxGetApp().m_show_grippers_on_drag, from);
					wxGetApp().grip_from = gp_Pnt(from[0], from[1], from[2]);
					double to[3];
					wxGetApp().m_digitizing->digitize(wxPoint(event.GetX(), event.GetY()));
					extract(wxGetApp().m_digitizing->digitized_point.m_point, to);
					wxGetApp().grip_to = wxGetApp().m_digitizing->digitized_point.m_point;
					extract(wxGetApp().grip_from, from);
					wxGetApp().drag_gripper->OnGripperMoved(from, to);
					wxGetApp().grip_from = gp_Pnt(from[0], from[1], from[2]);
					return;
				}
			}

			if(window_box_exists && wxGetApp().m_mouse_move_highlighting)
			{
				m_highlighted_objects.clear();
				GetObjectsInWindow(event, m_highlighted_objects);
				wxGetApp().Repaint();
			}

			// do window selection
			if(!m_just_one)
			{
				wxGetApp().m_current_viewport->SetXOR();
				if(window_box_exists)wxGetApp().m_current_viewport->DrawWindow(window_box, true); // undraw the window
				window_box.x = button_down_point.x;
				window_box.width = event.GetX() - button_down_point.x;
				window_box.y = wxGetApp().m_current_viewport->GetViewportSize().GetHeight() - button_down_point.y;
				window_box.height = button_down_point.y - event.GetY();
				wxGetApp().m_current_viewport->DrawWindow(window_box, true);// draw the window
				wxGetApp().m_current_viewport->EndXOR();
				window_box_exists = true;
			}
		}
	}
	CurrentPoint = wxPoint(event.GetX(), event.GetY());
}
Example #3
0
void CSelectMode::OnMouse( wxMouseEvent& event )
{
	bool event_used = false;
	if(LeftAndRightPressed(event, event_used))
	{
		if(m_doing_a_main_loop){
			ExitMainLoop();
		}
	}

	if(event_used)return;

	if(event.LeftDown())
		OnLeftDown(event);

	if(event.MiddleDown())
		OnMiddleDown(event);

	bool dragging = event.Dragging() && (m_button_down || m_middle_button_down);
	bool moving = event.Moving() || (event.Dragging() && (!(m_button_down || m_middle_button_down)));
	bool left_up = false;

	if(event.LeftUp())
	{
		if(m_button_down)left_up = true;
		m_button_down = false;
	}

	if(event.MiddleUp())m_middle_button_down = false;

	if(left_up)
	{
		OnLeftUp(event);
	}
	else if(event.RightUp())
	{
		MarkedObjectOneOfEach marked_object;
		wxGetApp().FindMarkedObject(wxPoint(event.GetX(), event.GetY()), &marked_object);
		wxGetApp().DoDropDownMenu(wxGetApp().m_frame->m_graphics, wxPoint(event.GetX(), event.GetY()), &marked_object, false, event.ControlDown());
	}
	else if(dragging)
	{
		OnDragging(event);
	}
	else if(moving)
	{
		OnMoving(event);
	}

	if(event.GetWheelRotation() != 0)
	{
		OnWheelRotation(event);
	}
}
/* TextureEditorPanel::onTexCanvasMouseEvent
 * Called on any mouse event within the texture canvas
 *******************************************************************/
void TextureEditorPanel::onTexCanvasMouseEvent(wxMouseEvent& e)
{
	// Get mouse position relative to texture
	point2_t pos = tex_canvas->screenToTexPosition(e.GetX(), e.GetY());

	// Get patch that the mouse is over (if any)
	int patch = tex_canvas->patchAt(pos.x, pos.y);

	// LEFT DOUBLE CLICK
	if (e.ButtonDClick(wxMOUSE_BTN_LEFT))
	{
		replacePatch();
	}

	// LEFT MOUSE DOWN
	else if (e.LeftDown())
	{
		// If not dragging
		if (e.ShiftDown())
		{
			// Shift is down, add to selection
			if (patch >= 0)
				list_patches->selectItem(patch);
		}
		else if (e.ControlDown())
		{
			// Control is down, remove from selection
			if (patch >= 0)
				list_patches->deSelectItem(patch);
		}
		else
		{
			// Clear selection only if patch clicked was not already selected
			if (!tex_canvas->patchSelected(patch))
				list_patches->clearSelection();

			// Select patch
			if (patch >= 0)
				list_patches->selectItem(patch);
		}
	}

	// LEFT MOUSE UP
	else if (e.LeftUp())
	{
		// Hide texture grid
		tex_canvas->showGrid(false);

		// If mouse up over an already-selected patch, and shift/ctrl aren't down,
		// select only that patch (this mimics 'normal' drag-and-drop/selection behaviour)
		if (!e.ShiftDown() && !e.ControlDown() && tex_canvas->patchSelected(patch) && !tex_canvas->isDragging())
		{
			list_patches->clearSelection();
			list_patches->selectItem(patch);
		}

		// Redraw texture canvas
		tex_canvas->redraw(false);
		updateTextureControls();
	}

	// RIGHT MOUSE UP
	else if (e.RightUp())
	{
		// Create context menu
		wxMenu popup;
		theApp->getAction("txed_patch_add")->addToMenu(&popup, true);
		theApp->getAction("txed_patch_remove")->addToMenu(&popup, true);
		theApp->getAction("txed_patch_replace")->addToMenu(&popup, true);
		theApp->getAction("txed_patch_back")->addToMenu(&popup, true);
		theApp->getAction("txed_patch_forward")->addToMenu(&popup, true);
		theApp->getAction("txed_patch_duplicate")->addToMenu(&popup, true);

		hack_nodrag = true;
		PopupMenu(&popup);
	}

	// MOUSE DRAGGING
	else if (e.Dragging())
	{
		// Drag selected patches if left button is down and any patch is selected
		if (hack_nodrag)
			hack_nodrag = false;
		else if (e.LeftIsDown())
		{
			if (list_patches->GetSelectedItemCount() > 0)
			{
				// Get drag amount according to texture
				point2_t tex_cur = tex_canvas->screenToTexPosition(e.GetX(), e.GetY());
				point2_t tex_prev = tex_canvas->screenToTexPosition(tex_canvas->getMousePrevPos().x, tex_canvas->getMousePrevPos().y);
				point2_t diff = tex_cur - tex_prev;

				// Move any selected patches
				wxArrayInt selected_patches = list_patches->selectedItems();
				for (size_t a = 0; a < selected_patches.size(); a++)
				{
					CTPatch* patch = tex_current->getPatch(selected_patches[a]);
					if (!patch) continue;
					int16_t cx = patch->xOffset();
					int16_t cy = patch->yOffset();
					patch->setOffsetX(cx + diff.x);
					patch->setOffsetY(cy + diff.y);
					tex_modified = true;
				}

				// Refresh texture canvas
				tex_canvas->showGrid(true);
				tex_canvas->redraw(false);
			}
			else if (tex_current->isExtended() && tex_canvas->getViewType() > 0)
			{
				// Get drag amount according to texture
				point2_t tex_cur = tex_canvas->screenToTexPosition(e.GetX(), e.GetY());
				point2_t tex_prev = tex_canvas->screenToTexPosition(tex_canvas->getMousePrevPos().x, tex_canvas->getMousePrevPos().y);
				point2_t diff = tex_cur - tex_prev;

				// Modify offsets
				tex_current->setOffsetX(tex_current->getOffsetX() - diff.x);
				tex_current->setOffsetY(tex_current->getOffsetY() - diff.y);
				tex_modified = true;

				// Refresh texture canvas
				tex_canvas->redraw(false);
			}
		}
	}

	e.Skip();
}
Example #5
0
void CSelectMode::OnLeftUp( wxMouseEvent& event )
{
	if(wxGetApp().drag_gripper)
	{
		double to[3], from[3];
		wxGetApp().m_digitizing->digitize(wxPoint(event.GetX(), event.GetY()));
		extract(wxGetApp().m_digitizing->digitized_point.m_point, to);
		wxGetApp().grip_to = wxGetApp().m_digitizing->digitized_point.m_point;
		extract(wxGetApp().grip_from, from);
		wxGetApp().drag_gripper->OnGripperReleased(from, to);
		wxGetApp().m_digitizing->SetOnlyCoords(wxGetApp().drag_gripper, false);
		wxGetApp().drag_gripper = NULL;
	}
	else if(window_box_exists)
	{
		if(!event.ControlDown())wxGetApp().m_marked_list->Clear(true);
		std::list<HeeksObj*> obj_list;
		GetObjectsInWindow(event, obj_list);
		wxGetApp().m_marked_list->Add(obj_list, true);
		wxGetApp().m_current_viewport->DrawWindow(window_box, true); // undraw the window
		window_box_exists = false;
	}
	else
	{
		// select one object
		m_last_click_point = CClickPoint();
		MarkedObjectOneOfEach marked_object;
		wxGetApp().FindMarkedObject(wxPoint(event.GetX(), event.GetY()), &marked_object);
		if(marked_object.m_map.size()>0){
			HeeksObj* previously_marked = NULL;
			if(wxGetApp().m_marked_list->size() == 1)
			{
				previously_marked = *(wxGetApp().m_marked_list->list().begin());
			}
			HeeksObj* o = marked_object.GetFirstOfTopOnly();
			unsigned long depth = marked_object.GetDepth();
			HeeksObj* object = o;

			while(o)
			{
				if(o == previously_marked)
				{
					object = o;
					break;
				}

				o = marked_object.Increment();

				if(o)
				{
					// prefer highest order objects
					if(o->GetType() < object->GetType())object = o;
				}
			}
			if(!event.ShiftDown() && !event.ControlDown())
			{
				wxGetApp().m_marked_list->Clear(true);
			}
			if (wxGetApp().m_marked_list->ObjectMarked(object))
			{
				if (!event.ShiftDown())
				{
					wxGetApp().m_marked_list->Remove(object, true);
				}
			}
			else
			{
				wxGetApp().m_marked_list->Add(object, true);
				m_last_click_point = CClickPoint(wxPoint(event.GetX(), event.GetY()), depth);
				gp_Lin ray = wxGetApp().m_current_viewport->m_view_point.SightLine(wxPoint(event.GetX(), event.GetY()));
				double ray_start[3], ray_direction[3];
				extract(ray.Location(), ray_start);
				extract(ray.Direction(), ray_direction);
				marked_object.GetFirstOfTopOnly();
				object->SetClickMarkPoint(marked_object.GetCurrent(), ray_start, ray_direction);
			}
		}
		else
		{
			if(!event.ShiftDown() && !event.ControlDown())
			{
				wxGetApp().m_marked_list->Clear(true);
			}
		}
	}

	if(m_just_one && m_doing_a_main_loop && (wxGetApp().m_marked_list->size() > 0))
	{
		ExitMainLoop();
	}
	else
	{
		wxGetApp().m_current_viewport->m_need_refresh = true;
	}
}
void wxCustomHeightListCtrl::OnMouseEvent(wxMouseEvent& event)
{
	bool changed = false;
	if (event.ButtonDown() && m_allow_selection)
	{
		wxPoint pos = event.GetPosition();
		int x, y;
		CalcUnscrolledPosition(pos.x, pos.y, &x, &y);
		if (y > m_lineHeight * m_lineCount)
		{
			m_focusedLine = -1;
			m_selectedLines.clear();
			changed = true;
		}
		else
		{
			int line = y / m_lineHeight;
			if (event.ShiftDown())
			{
				if (line < m_focusedLine)
				{
					for (int i = line; i <= m_focusedLine; i++)
					{
						if (m_selectedLines.find(i) == m_selectedLines.end())
						{
							changed = true;
							m_selectedLines.insert(i);
						}
					}
				}
				else
				{
					for (int i = line; i >= m_focusedLine; i--)
					{
						if (m_selectedLines.find(i) == m_selectedLines.end())
						{
							changed = true;
							m_selectedLines.insert(i);
						}
					}
				}
			}
			else if (event.ControlDown())
			{
				if (m_selectedLines.find(line) == m_selectedLines.end())
					m_selectedLines.insert(line);
				else
					m_selectedLines.erase(line);
				changed = true;
			}
			else
			{
				m_selectedLines.clear();
				m_selectedLines.insert(line);
				changed = true;
			}

			m_focusedLine = line;				

		}
		Refresh();
	}

	event.Skip();

	if (changed)
	{
		wxCommandEvent evt(wxEVT_COMMAND_LISTBOX_SELECTED, GetId());
		ProcessEvent(evt);
	}
}
Example #7
0
void klsGLCanvas::wxOnMouseEvent(wxMouseEvent& event) {
	reclaimViewport();
	
	isShiftDown = event.ShiftDown();
	isControlDown = event.ControlDown();
	
	// Always set the mouse coords to the current event:
	setMouseScreenCoords(event.GetPosition());
	setMouseCoords();

	// Check all of the button events:
	if(event.LeftDown()) {
		mouseOutOfWindow = false; // Assume that we clicked inside the window!
		beginDrag(BUTTON_LEFT);
		OnMouseDown(event); // Call the event handler.
	} else if(event.LeftUp() || event.LeftDClick()) {
		endDrag(BUTTON_LEFT);
		OnMouseUp(event);
	} else if(event.RightDown() || event.RightDClick()) {
		beginDrag(BUTTON_RIGHT);
		OnMouseDown(event); // Call the event handler.
	} else if(event.RightUp()) {
		endDrag(BUTTON_RIGHT);
		OnMouseUp(event);
	} else if(event.MiddleDown() || event.MiddleDClick()) {
		beginDrag(BUTTON_MIDDLE);
		OnMouseDown(event); // Call the event handler.
		if(event.MiddleDClick()) {
			// Debugging screen shot code.
			// I left it in because it was nifty to have around, especially
			// for writing documentation.	
			// Render the canvas to a bitmap and save it:
			wxSize sz = GetClientSize();
			wxImage screenShot = renderToImage(
				sz.GetWidth(), sz.GetHeight(), 32);
			wxBitmap myBMP(screenShot);
			myBMP.SaveFile(std2wx("screen_shot.bmp"), wxBITMAP_TYPE_BMP);
		}
		
	} else if(event.MiddleUp()) {
		endDrag(BUTTON_MIDDLE);
		OnMouseUp(event);
	} else {
		// It's not a button event, so check the others:
		if(event.Entering()) {
			mouseOutOfWindow = false;
			scrollTimer->Stop();
			OnMouseEnter(event);
		} else if(event.Leaving() && !isDragging( BUTTON_MIDDLE) ) { // Don't allow auto-scroll during pan-scrolling.
			// Flag the scroll event by telling it that the
			// mouse has left the window:
			mouseOutOfWindow = true;

			// Start the scroll timer:
			if(isAutoScrollOn() && isDragging( BUTTON_LEFT) ) {
				scrollTimer->Start(SCROLL_TIMER_RATE);
			}

			// Call the event handler:
			OnMouseLeave(event);
		} else {
			// Handle the drag-pan event here if needed:
			if(isDragging( BUTTON_MIDDLE) ) {
				GLPoint2f mouseDelta(getMouseCoords().x - getDragStartCoords( BUTTON_MIDDLE).x,
										getMouseCoords().y - getDragStartCoords(BUTTON_MIDDLE).y );

				translatePan(-mouseDelta.x, -mouseDelta.y);
			}
			
			// It's nothing else, so it must be a mouse motion event:
			GLPoint2f m = getMouseCoords();
			OnMouseMove(m.x, m.y, event.ShiftDown(), event.ControlDown());
		}
		
	}

// Refresh the canvas to show the mouse drag highlights if needed:
#ifdef CANVAS_DEBUG_TESTS_ON
	Refresh();
#endif

}
Example #8
0
void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
{
    const double wheelPanSpeed = 0.001;

    // mousewheelpan disabled:
    //      wheel + ctrl    -> horizontal scrolling;
    //      wheel + shift   -> vertical scrolling;
    //      wheel           -> zooming;
    // mousewheelpan enabled:
    //      wheel           -> pan;
    //      wheel + ctrl    -> zooming;
    //      wheel + shift   -> horizontal scrolling.

    if( ( !m_settings.m_enableMousewheelPan && ( aEvent.ControlDown() || aEvent.ShiftDown() ) ) ||
        ( m_settings.m_enableMousewheelPan && !aEvent.ControlDown() ) )
    {
        // Scrolling
        VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) *
                             ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
        int axis = aEvent.GetWheelAxis();
        double scrollX = 0.0;
        double scrollY = 0.0;

        if( m_settings.m_enableMousewheelPan )
        {
            if ( axis == wxMOUSE_WHEEL_HORIZONTAL || aEvent.ShiftDown() )
                scrollX = scrollVec.x;
            else
                scrollY = -scrollVec.y;
        }
        else
        {
            if( aEvent.ControlDown() )
                scrollX = -scrollVec.x;
            else
                scrollY = -scrollVec.y;
        }

        VECTOR2D delta( scrollX, scrollY );

        m_view->SetCenter( m_view->GetCenter() + delta );
    }
    else
    {
        // Zooming
        wxLongLong  timeStamp   = wxGetLocalTimeMillis();
        double      timeDiff    = timeStamp.ToDouble() - m_timeStamp.ToDouble();
        int         rotation    = aEvent.GetWheelRotation();
        double      zoomScale = 1.0;

#ifdef __WXMAC__
        // On Apple pointer devices, wheel events occur frequently and with
        // smaller rotation values.  For those devices, let's handle zoom
        // based on the rotation amount rather than the time difference.

        // Unused
        ( void )timeDiff;

        rotation = ( rotation > 0 ) ? std::min( rotation , 100 )
                                    : std::max( rotation , -100 );

        double dscale = rotation * 0.01;
        zoomScale = ( rotation > 0 ) ? (1 + dscale)  : 1/(1 - dscale);

#else

        m_timeStamp = timeStamp;

        // Set scaling speed depending on scroll wheel event interval
        if( timeDiff < 500 && timeDiff > 0 )
        {
            zoomScale = 2.05 - timeDiff / 500;

            if( rotation < 0 )
                zoomScale = 1.0 / zoomScale;
        }
        else
        {
            zoomScale = ( rotation > 0 ) ? 1.05 : 1/1.05;
        }
#endif

        if( IsCursorWarpingEnabled() )
        {
            CenterOnCursor();
            m_view->SetScale( m_view->GetScale() * zoomScale );
        }
        else
        {
            VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
            m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
        }
    }

    aEvent.Skip();
}
Example #9
0
void AButton::OnMouseEvent(wxMouseEvent & event)
{
   wxSize clientSize = GetClientSize();
   AButtonState prevState = GetState();

   if (event.Entering())
      mCursorIsInWindow = true;
   else if (event.Leaving())
      mCursorIsInWindow = false;
   else
      mCursorIsInWindow =
         (event.m_x >= 0 && event.m_y >= 0 &&
          event.m_x < clientSize.x && event.m_y < clientSize.y);

   if (HasAlternateImages() && !mButtonIsDown)
      mAlternate = event.ShiftDown();

   if (mEnabled && event.IsButton()) {
      if (event.ButtonIsDown(wxMOUSE_BTN_ANY)) {
         mIsClicking = true;
         CaptureMouse();
      }
      else if (mIsClicking) {
         mIsClicking = false;

         if (HasCapture())
            ReleaseMouse();

         if (mCursorIsInWindow && (mToggle || !mButtonIsDown)) {
            if (mToggle)
               mButtonIsDown = !mButtonIsDown;
            else
               mButtonIsDown = true;
            
            mWasShiftDown = event.ShiftDown();
            mWasControlDown = event.ControlDown();
            
            Click();
         }
      }
   }
   
   // Only redraw and change tooltips if the state has changed.
   AButtonState newState = GetState();

   if (newState != prevState) {
      Refresh(false);

      if (mCursorIsInWindow) {
       #if wxUSE_TOOLTIPS // Not available in wxX11
         // Display the tooltip in the status bar
         wxToolTip * pTip = this->GetToolTip();
         if( pTip ) {
            wxString tipText = pTip->GetTip();
            if (!mEnabled)
               tipText += _(" (disabled)");
            GetActiveProject()->TP_DisplayStatusMessage(tipText);
         }
       #endif
      }
      else {
         GetActiveProject()->TP_DisplayStatusMessage(wxT(""));
      }
   }
}
Example #10
0
void EDA_DRAW_PANEL::OnMouseWheel( wxMouseEvent& event )
{
    if( m_ignoreMouseEvents )
        return;

    wxRect rect = wxRect( wxPoint( 0, 0 ), GetClientSize() );

    // Ignore scroll events if the cursor is outside the drawing area.
    if( event.GetWheelRotation() == 0 || !GetParent()->IsEnabled()
       || !rect.Contains( event.GetPosition() ) )
    {
        wxLogTrace( KICAD_TRACE_COORDS,
                    wxT( "OnMouseWheel() position(%d, %d) rectangle(%d, %d, %d, %d)" ),
                    event.GetPosition().x, event.GetPosition().y,
                    rect.x, rect.y, rect.width, rect.height );
        event.Skip();
        return;
    }

    INSTALL_UNBUFFERED_DC( dc, this );
    GetParent()->SetCrossHairPosition( event.GetLogicalPosition( dc ) );

    wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
    cmd.SetEventObject( this );

    bool offCenterReq = event.ControlDown() && event.ShiftDown();
    offCenterReq = offCenterReq || m_enableZoomNoCenter;

#if wxMAJOR_VERSION >= 2 && wxMINOR_VERSION >= 9
    int axis = event.GetWheelAxis();
#else
    const int axis = 0;
#endif

    // This is a zoom in or out command
    if( event.GetWheelRotation() > 0 )
    {
        if( event.ShiftDown() && !event.ControlDown() )
        {
            if( axis == 0 )
                cmd.SetId( ID_PAN_UP );
            else
                cmd.SetId( ID_PAN_RIGHT );
        }
        else if( event.ControlDown() && !event.ShiftDown() )
            cmd.SetId( ID_PAN_LEFT );
        else if( offCenterReq )
            cmd.SetId( ID_OFFCENTER_ZOOM_IN );
        else
            cmd.SetId( ID_POPUP_ZOOM_IN );
    }
    else if( event.GetWheelRotation() < 0 )
    {
        if( event.ShiftDown() && !event.ControlDown() )
        {
            if( axis == 0 )
                cmd.SetId( ID_PAN_DOWN );
            else
                cmd.SetId( ID_PAN_LEFT );
        }
        else if( event.ControlDown() && !event.ShiftDown() )
            cmd.SetId( ID_PAN_RIGHT );
        else if( offCenterReq )
            cmd.SetId( ID_OFFCENTER_ZOOM_OUT );
        else
            cmd.SetId( ID_POPUP_ZOOM_OUT );
    }

    GetEventHandler()->ProcessEvent( cmd );
    event.Skip();
}
Example #11
0
void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
{
    int          localrealbutt = 0, 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.
        m_requestAutoPan = 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.LeftIsDown() )
        localrealbutt |= GR_M_LEFT_DOWN;

    if( event.MiddleIsDown() )
        localrealbutt |= GR_M_MIDDLE_DOWN;

    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;

    localrealbutt |= localbutt;     // compensation default wxGTK

    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 ) )
    {
        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 )
            GetParent()->OnLeftClick( &DC, GetParent()->RefPos( true ) );

    }
    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_enableMiddleButtonPan )
    {
        if( m_panScrollbarLimits )
        {
            int ppux, ppuy;
            GetScrollPixelsPerUnit( &ppux, &ppuy );
            GetViewStart( &m_PanStartCenter.x, &m_PanStartCenter.y );
            m_PanStartCenter.x *= ppux;
            m_PanStartCenter.y *= ppuy;
        }
        else
            m_PanStartCenter = GetParent()->GetScrollCenterPosition();

        m_PanStartEventPosition = event.GetPosition();

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

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

    if( event.MiddleIsDown() && m_enableMiddleButtonPan )
    {
        wxPoint currentPosition = event.GetPosition();
        if( m_panScrollbarLimits )
        {
            int x, y;
            int tmpX, tmpY;
            int ppux, ppuy;
            int maxX, maxY;
            int vsizeX, vsizeY;
            int csizeX, csizeY;

            GetViewStart( &tmpX, &tmpY );
            GetScrollPixelsPerUnit( &ppux, &ppuy );
            GetVirtualSize( &vsizeX, &vsizeY );
            GetClientSize( &csizeX, &csizeY );

            maxX = vsizeX - csizeX;
            maxY = vsizeY - csizeY;

            x = m_PanStartCenter.x + m_PanStartEventPosition.x - currentPosition.x;
            y = m_PanStartCenter.y + m_PanStartEventPosition.y - currentPosition.y;

            bool shouldMoveCursor = false;

            if( x < 0 )
            {
                currentPosition.x += x;
                x = 0;
                shouldMoveCursor = true;
            }

            if( y < 0 )
            {
                currentPosition.y += y;
                y = 0;
                shouldMoveCursor = true;
            }

            if( x > maxX )
            {
                currentPosition.x += ( x - maxX );
                x = maxX;
                shouldMoveCursor = true;
            }

            if( y > maxY )
            {
                currentPosition.y += ( y - maxY );
                y = maxY;
                shouldMoveCursor = true;
            }

            if ( shouldMoveCursor )
                WarpPointer( currentPosition.x, currentPosition.y );

            Scroll( x/ppux, y/ppuy );

            double scale = GetParent()->GetScreen()->GetScalingFactor();

            wxPoint center = GetParent()->GetScrollCenterPosition();
            center.x += KiROUND( (double) ( x - tmpX ) / scale ) / ppux;
            center.y += KiROUND( (double) ( y - tmpY ) / scale ) / ppuy;
            GetParent()->SetScrollCenterPosition( center );

            Refresh();
            Update();
        }
        else
        {
            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 );
        }
    }

    if( event.ButtonUp( wxMOUSE_BTN_MIDDLE ) && !m_enableMiddleButtonPan &&
        (screen->m_BlockLocate.GetState() == STATE_NO_BLOCK) )
    {
        // The middle button has been released, with no block command:
        // We use it for a zoom center at cursor position command
        wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED, ID_POPUP_ZOOM_CENTER );
        cmd.SetEventObject( this );
        GetEventHandler()->ProcessEvent( cmd );
    }

    // 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() || ( !m_enableMiddleButtonPan && event.MiddleDown() ) )
        {
            if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE )
            {
                m_requestAutoPan = false;
                GetParent()->HandleBlockPlace( &DC );
                m_ignoreNextLeftButtonRelease = true;
            }
        }
        else if( ( m_canStartBlock >= 0 )
                && ( event.LeftIsDown() || ( !m_enableMiddleButtonPan && event.MiddleIsDown() ) )
                && !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;

                if( !m_enableMiddleButtonPan && event.MiddleIsDown() )
                    cmd_type |= MOUSE_MIDDLE;

                // 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
                {
                    if( !GetParent()->HandleBlockBegin( &DC, cmd_type, m_CursorStartPos ) )
                    {
                        // should not occur: error
                        GetParent()->DisplayToolMsg(
                            wxT( "EDA_DRAW_PANEL::OnMouseEvent() Block Error" ) );
                    }
                    else
                    {
                        m_requestAutoPan = true;
                        SetCursor( wxCURSOR_SIZING );
                    }
                }
            }
        }

        if( event.ButtonUp( wxMOUSE_BTN_LEFT ) ||
            ( !m_enableMiddleButtonPan && event.ButtonUp( wxMOUSE_BTN_MIDDLE ) ) )
        {
            /* 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 );
                    m_requestAutoPan = false;
                }

                SetCursor( (wxStockCursor) m_currentCursor );
           }
            else if( screen->m_BlockLocate.GetState() == STATE_BLOCK_END )
            {
                m_requestAutoPan = false;
                GetParent()->HandleBlockEnd( &DC );
                SetCursor( (wxStockCursor) m_currentCursor );
                if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE )
                {
                    m_requestAutoPan = 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 );
        }
    }

#if 0
    wxString msg_debug;
    msg_debug.Printf( " block state %d, cmd %d",
                      screen->m_BlockLocate.GetState(),
                      screen->m_BlockLocate.GetCommand() );
    GetParent()->PrintMsg( msg_debug );
#endif

    lastPanel = this;
}
void wxsItemEditorContent::OnMouseIdle(wxMouseEvent& event)
{
    BlockFetch(false);
    m_DragInitPosX = event.GetX();
    m_DragInitPosY = event.GetY();

    int MouseX = event.GetX();
    int MouseY = event.GetY();

    wxsItem* OnCursor = FindItemAtPos(MouseX,MouseY,m_Data->GetRootItem());
    if ( !OnCursor ) OnCursor = m_Data->GetRootItem();

    wxWindow* Preview = GetPreviewWindow(OnCursor);

    if ( event.LeftDClick() && !event.RightIsDown() && !event.MiddleIsDown() )
    {
        if ( Preview )
        {
            int PosX, PosY, SizeX, SizeY;
            FindAbsoluteRect(OnCursor,PosX,PosY,SizeX,SizeY);
            if ( OnCursor->MouseDClick(Preview,MouseX-PosX,MouseY-PosY) )
            {
                m_MouseState = msWaitForIdle;
                m_Editor->RebuildPreview();
                m_MouseState = msWaitForIdle;
                return;
            }
        }
    }

    if ( event.LeftDown() && !event.LeftDClick() && !event.RightIsDown() && !event.MiddleIsDown() )
    {
        // Selecting / drag init event
        bool NeedRefresh = false;
        if ( Preview )
        {
            int PosX, PosY, SizeX, SizeY;
            FindAbsoluteRect(OnCursor,PosX,PosY,SizeX,SizeY);
            NeedRefresh = OnCursor->MouseClick(Preview,MouseX-PosX,MouseY-PosY);
        }

        if ( NeedRefresh )
        {
            m_MouseState = msWaitForIdle;
            m_Editor->RebuildPreview();
            m_MouseState = msWaitForIdle;
            return;
        }

        DragPointData* DPD = FindDragPointAtPos(MouseX,MouseY);

        if ( DPD )
        {
            // If there's drag point, starting point-dragging sequence
            m_CurDragPoint = DPD;
            m_CurDragItem = DPD->Item;
            m_MouseState = msDraggingPointInit;
        }
        else
        {
            if ( !OnCursor->GetIsSelected() )
            {
                m_Data->SelectItem(OnCursor,!event.ControlDown());
            }
            else
            {
                m_Data->SelectItem(OnCursor,false);
            }

            m_CurDragPoint = FindDragPointFromItem(OnCursor);
            m_CurDragItem = OnCursor;
            m_MouseState = msDraggingItemInit;

            if ( !m_CurDragPoint || !m_CurDragItem )
            {
                // If we're here, preview has probably not been updated yet
                m_MouseState = msWaitForIdle;
            }
        }
    }

    if ( !event.LeftIsDown() && event.RightDown() && !event.MiddleIsDown() )
    {
        if ( Preview )
        {
            int PosX, PosY, SizeX, SizeY;
            FindAbsoluteRect(OnCursor,PosX,PosY,SizeX,SizeY);
            if ( OnCursor->MouseRightClick(Preview,MouseX-PosX,MouseY-PosY) )
            {
                m_MouseState = msWaitForIdle;
                m_Editor->RebuildPreview();
                m_MouseState = msWaitForIdle;
                return;
            }
        }
    }

    if ( !event.LeftIsDown() && !event.RightIsDown() && !event.MiddleIsDown() )
    {
        // Updating cursor

        DragPointData* DPD = FindDragPointAtPos(event.GetX(),event.GetY());

        if ( DPD )
        {
            switch ( DPD->Type )
            {
                case LeftTop:
                case RightBtm:
                    SetCur(wxCURSOR_SIZENWSE);
                    break;

                case Top:
                case Btm:
                    SetCur(wxCURSOR_SIZENS);
                    break;

                case RightTop:
                case LeftBtm:
                    SetCur(wxCURSOR_SIZENESW);
                    break;

                case Left:
                case Right:
                    SetCur(wxCURSOR_SIZEWE);
                    break;

                default:
                    SetCur(wxCURSOR_ARROW);
            }
        }
        else
        {
            SetCur(wxCURSOR_ARROW);
        }

    }
}
Example #13
0
int bmx_wxmouseevent_controldown(wxMouseEvent & event) {
	return static_cast<int>(event.ControlDown());
}
//---------------------------------------------------------
void CWKSP_Data_Button::On_Mouse_LDown(wxMouseEvent &event)
{
	_Set_Active(event.ControlDown());
}
Example #15
0
void AButton::OnMouseEvent(wxMouseEvent & event)
{
   wxSize clientSize = GetClientSize();
   AButtonState prevState = GetState();

   if (event.Entering()) {
      // Bug 1201:  On Mac, unsetting and re-setting the tooltip may be needed
      // to make it pop up when we want it.
      auto text = GetToolTipText();
      UnsetToolTip();
      SetToolTip(text);
      mCursorIsInWindow = true;
   }
   else if (event.Leaving())
      mCursorIsInWindow = false;
   else
      mCursorIsInWindow =
         (event.m_x >= 0 && event.m_y >= 0 &&
          event.m_x < clientSize.x && event.m_y < clientSize.y);

   if (mEnabled && event.IsButton()) {
      if (event.ButtonIsDown(wxMOUSE_BTN_ANY)) {
         mIsClicking = true;
         if (event.ButtonDClick())
            mIsDoubleClicked = true;
         if( !HasCapture() )
            CaptureMouse();
      }
      else if (mIsClicking) {
         mIsClicking = false;

         if (HasCapture())
            ReleaseMouse();

         if (mCursorIsInWindow && (mToggle || !mButtonIsDown)) {
            if (mToggle)
               mButtonIsDown = !mButtonIsDown;
            else
               mButtonIsDown = true;

            mWasShiftDown = event.ShiftDown();
            mWasControlDown = event.ControlDown();

            Click();
         }
      }
   }

   // Only redraw and change tooltips if the state has changed.
   AButtonState newState = GetState();

   if (newState != prevState) {
      Refresh(false);

      if (mCursorIsInWindow)
         UpdateStatus();
      else {
         GetActiveProject()->TP_DisplayStatusMessage(wxT(""));
      }
   }
   else
      event.Skip();
}
Example #16
0
void WebView::OnMouseEvents(wxMouseEvent& event)
{
    event.Skip();
    
    if (!m_impl->page)
        return; 
        
    WebCore::Frame* frame = m_mainFrame->GetFrame();  
    if (!frame || !frame->view())
        return;
    
    wxPoint globalPoint = ClientToScreen(event.GetPosition());

    wxEventType type = event.GetEventType();
    
    if (type == wxEVT_MOUSEWHEEL) {
        if (m_mouseWheelZooms && event.ControlDown() && !event.AltDown() && !event.ShiftDown()) {
            if (event.GetWheelRotation() < 0)
                DecreaseTextSize();
            else if (event.GetWheelRotation() > 0)
                IncreaseTextSize();
        } else {
            WebCore::PlatformWheelEvent wkEvent(event, globalPoint);
            frame->eventHandler()->handleWheelEvent(wkEvent);
        }

        return;
    }
    
    // If an event, such as a right-click event, leads to a focus change (e.g. it 
    // raises a dialog), WebKit never gets the mouse up event and never relinquishes 
    // mouse capture. This leads to WebKit handling mouse events, such as modifying
    // the selection, while other controls or top level windows have the focus.
    // I'm not sure if this is the right place to handle this, but I can't seem to
    // find a precedent on how to handle this in other ports.
    if (wxWindow::FindFocus() != this) {
        while (HasCapture())
            ReleaseMouse();

        frame->eventHandler()->setMousePressed(false);

        return;
    }
        
    int clickCount = event.ButtonDClick() ? 2 : 1;

    if (clickCount == 1 && m_impl->tripleClickTimer.IsRunning()) {
        wxPoint diff(event.GetPosition() - m_impl->tripleClickPos);
        if (abs(diff.x) <= wxSystemSettings::GetMetric(wxSYS_DCLICK_X) &&
            abs(diff.y) <= wxSystemSettings::GetMetric(wxSYS_DCLICK_Y)) {
            clickCount = 3;
        }
    } else if (clickCount == 2) {
        m_impl->tripleClickTimer.Start(getDoubleClickTime(), false);
        m_impl->tripleClickPos = event.GetPosition();
    }
    
    WebCore::PlatformMouseEvent wkEvent(event, globalPoint, clickCount);

    if (type == wxEVT_LEFT_DOWN || type == wxEVT_MIDDLE_DOWN || type == wxEVT_RIGHT_DOWN || 
                type == wxEVT_LEFT_DCLICK || type == wxEVT_MIDDLE_DCLICK || type == wxEVT_RIGHT_DCLICK) {
        frame->eventHandler()->handleMousePressEvent(wkEvent);
        if (!HasCapture())
            CaptureMouse();
    } else if (type == wxEVT_LEFT_UP || type == wxEVT_MIDDLE_UP || type == wxEVT_RIGHT_UP) {
        frame->eventHandler()->handleMouseReleaseEvent(wkEvent);
        while (HasCapture())
            ReleaseMouse();
    } else if (type == wxEVT_MOTION || type == wxEVT_ENTER_WINDOW || type == wxEVT_LEAVE_WINDOW)
        frame->eventHandler()->mouseMoved(wkEvent);
}
Example #17
0
void TTrackball::OnMouse(wxMouseEvent& event)
{
    vec3 cursor = canvas->GetWorldSpace(event.GetX(), event.GetY());

    if (event.LeftDown()) {
        if (!event.ControlDown())
            Stop();
        vStart = cursor;
        memcpy((float*) &mStart, (float*) &xform, sizeof(xform));
        startZoom = canvas->GetZoom();
        vPrev = cursor;
        validStart = true;
    } else if (event.LeftUp() && validStart) {
        float theta = 180 * vInc.magnitude();
        if (theta < -InertiaThreshold || theta > InertiaThreshold) {
            inertiaAxis = cross(vStart, cursor);
            if (inertiaAxis.magnitude()) {
                inertiaAxis.unitize();
                inertiaTheta = theta;
            }
        } else if (!event.ControlDown()) {
            Stop();
        }
        validStart = false;
    }
    else if (event.Moving() && event.LeftIsDown()) {
        if (!validStart) {
            vInc = vec3(0, 0, 0);
        } else {
            if (event.ControlDown()) {
                float delta = cursor.y - vStart.y;
                if (delta) {
                    canvas->SetZoom(startZoom + delta);
                    canvas->Update();
                }
            } else {
                float theta = 180 * (cursor - vStart).magnitude();
                if (theta) {
                    vec3 axis = cross(vStart, cursor);
                    axis.unitize();

                    glLoadIdentity();
                    vec3 offset = wxGetApp().Frame()->GetCenter();
                    glTranslate(offset);
                    glRotatef(-theta, axis.x, axis.y, axis.z);
                    glTranslate(-offset);
                    glMultMatrixf((float*) &mStart);
                    glGetFloatv(GL_MODELVIEW_MATRIX, (float*) &xform);
                    canvas->Update();
                }
            }
            vInc = cursor - vPrev;
        }
        vPrev = cursor;
    }

    // Right mouse button zooms.
    else if (event.RightDown()) {
        vStart = cursor;
        startZoom = canvas->GetZoom();
        validStart = true;
    } else if (event.RightUp() && validStart) {
        validStart = false;
    } else if (event.Moving() && event.RightIsDown()) {
        if (validStart) {
            float delta = cursor.y - vStart.y;
            if (delta) {
                canvas->SetZoom(startZoom + delta);
                canvas->Update();
            }
        }
    }

    event.Skip();
}
Example #18
0
void WinEDA_DrawPanel::OnMouseEvent(wxMouseEvent& event)
/*******************************************************/
// Called when the canvas receives a mouse event. //
{
int localrealbutt = 0, localbutt = 0, localkey = 0;
BASE_SCREEN * screen = GetScreen();
static WinEDA_DrawPanel * LastPanel;
	
	if ( event.Leaving() || event.Entering() )
	{
		m_CanStartBlock = -1;
	}

	if (GetScreen()->ManageCurseur == NULL ) // Pas de commande en cours
		m_AutoPAN_Request = FALSE;

	if ( m_Parent->m_FrameIsActive ) SetFocus();
	else return;

	// Mouse Wheel is a zoom command:
	if ( event.m_wheelRotation )
	{
		// This is a zoom in ou out command
		if ( event.GetWheelRotation() > 0 ) localkey = WXK_F1;
		else  localkey = WXK_F2;
	}

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

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

	if ( m_IgnoreMouseEvents ) return;

	if( event.LeftIsDown() ) localrealbutt |= GR_M_LEFT_DOWN;
	if( event.MiddleIsDown() ) localrealbutt |= GR_M_MIDDLE_DOWN;

	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;
	if( event.ButtonDClick(2)) {};	// Unused


	localrealbutt |= localbutt;		/* compensation defaut wxGTK */

	screen->m_MousePosition = CalcAbsolutePosition(wxPoint(event.GetX(), event.GetY()));

wxClientDC DC(this);
int kbstat = 0;

	DC.SetBackground(*wxBLACK_BRUSH );
	PrepareGraphicContext(&DC);

	g_KeyPressed = localkey;

	if( event.ShiftDown() ) kbstat |= GR_KB_SHIFT;
	if( event.ControlDown() ) kbstat |= GR_KB_CTRL;
	if( event.AltDown() ) kbstat |= GR_KB_ALT;

	g_MouseOldButtons = localrealbutt;

	// Appel des fonctions liées au Double Click ou au Click
	if( localbutt == (int)(GR_M_LEFT_DOWN|GR_M_DCLICK) )
		m_Parent->OnLeftDClick(&DC, screen->m_MousePosition);

	else if ( event.LeftDown() )
		m_Parent->OnLeftClick(&DC, screen->m_MousePosition);

	if( event.ButtonUp(2) && (screen->BlockLocate.m_State == STATE_NO_BLOCK) )
	{	// The middle button has been relached, with no block command:
		// We use it for a zoom center command
		g_KeyPressed = localkey = WXK_F4;
	}
		

	/* Appel de la fonction generale de gestion des mouvements souris
	et commandes clavier */
	m_Parent->GeneralControle(&DC, screen->m_MousePosition);


	/*******************************/
	/* Control of block commands : */
	/*******************************/
	
	// Command block can't start if mouse is dragging a new panel
	if (LastPanel != this ) m_CanStartBlock = -1;

	// A new command block can start after a release buttons
	// Avoid a false start block when a dialog bos is demiss,
	// or when changing panels in hierachy navigation
	if ( !event.LeftIsDown() && !event.MiddleIsDown())
	{
		m_CanStartBlock = 0;
	}

	if( m_Block_Enable && !(localbutt & GR_M_DCLICK) )
	{
		if ( (screen->BlockLocate.m_Command == BLOCK_IDLE) ||
			(screen->BlockLocate.m_State == STATE_NO_BLOCK))
		{
			m_CursorStartPos = screen->m_Curseur;
			screen->BlockLocate.SetOrigin(m_CursorStartPos);
		}
		if ( event.LeftDown() || event.MiddleDown() )
		{
			m_CursorStartPos = screen->m_Curseur;
			if ( screen->BlockLocate.m_State == STATE_BLOCK_MOVE )
			{
				m_AutoPAN_Request = FALSE;
				m_Parent->HandleBlockPlace(&DC);
			}
		}
		else if( (m_CanStartBlock >= 0 ) &&
				( event.LeftIsDown() || event.MiddleIsDown() )
				&& screen->ManageCurseur == NULL
				&& screen->ForceCloseManageCurseur == NULL )
		{
			if ( screen->BlockLocate.m_State == STATE_NO_BLOCK )
			{
				int cmd_type = kbstat;
				if ( event.MiddleIsDown() )	cmd_type |= MOUSE_MIDDLE;
				if ( ! m_Parent->HandleBlockBegin(&DC, cmd_type, m_CursorStartPos) )
				{	// error
					m_Parent->DisplayToolMsg( wxT("WinEDA_DrawPanel::OnMouseEvent() Block Error") );
				}
				else
				{
					m_AutoPAN_Request = TRUE;
					SetCursor(m_PanelCursor = wxCURSOR_SIZING);
				}
			}
		}
		
		
		if( event.ButtonUp(1) || event.ButtonUp(2) )
		{ /* Relachement du bouton: fin de delimitation de block.
			La commande peut etre terminee (DELETE) ou continuer par le placement
			du block ainsi delimite (MOVE, COPY).
			Cependant bloc est annule si sa taille est trop petite*/
			bool BlockIsSmall =
				 ( ABS(screen->BlockLocate.GetWidth()/GetZoom()) < 3) &&
				 ( ABS(screen->BlockLocate.GetHeight()/GetZoom()) < 3);
			
			if ( (screen->BlockLocate.m_State != STATE_NO_BLOCK) && BlockIsSmall )
			{
				if( GetScreen()->ForceCloseManageCurseur )
				{
					GetScreen()->ForceCloseManageCurseur(m_Parent, &DC);
					m_AutoPAN_Request = FALSE;
				}
				SetCursor(m_PanelCursor = m_PanelDefaultCursor);
			}
			else if ( screen->BlockLocate.m_State == STATE_BLOCK_END )
			{
				m_AutoPAN_Request = FALSE;
				m_Parent->HandleBlockEnd(&DC);
				SetCursor(m_PanelCursor = m_PanelDefaultCursor);
				if ( screen->BlockLocate.m_State == STATE_BLOCK_MOVE )
				{
					m_AutoPAN_Request = TRUE;
					SetCursor(m_PanelCursor = wxCURSOR_HAND);
				}
			}
		}

	}

	// Arret de block sur un double click ( qui peut provoquer un move block
	// si on déplace la souris dans ce double click
	if ( localbutt == (int)(GR_M_LEFT_DOWN|GR_M_DCLICK) )
	{
		if ( screen->BlockLocate.m_Command != BLOCK_IDLE )
		{
			if( GetScreen()->ForceCloseManageCurseur )
			{
				GetScreen()->ForceCloseManageCurseur(m_Parent, &DC);
				m_AutoPAN_Request = FALSE;
			}
		}
	}


#if 0
	wxString msg_debug;
	msg_debug.Printf(" block state %d, cmd %d",
		screen->BlockLocate.m_State, screen->BlockLocate.m_Command);
	m_Parent->PrintMsg(msg_debug);
#endif

	LastPanel = this;
	m_Parent->SetToolbars();
}
Example #19
0
void FortyCanvas::OnMouseEvent(wxMouseEvent& event)
{
    int mouseX = (int)event.GetX();
    int mouseY = (int)event.GetY();

    wxClientDC dc(this);
    PrepareDC(dc);
    dc.SetFont(* m_font);

    if (event.LeftDClick())
    {
        if (m_leftBtnDown)
        {
            m_leftBtnDown = false;
            ReleaseMouse();
            m_game->LButtonUp(dc, mouseX, mouseY);
        }
        m_game->LButtonDblClk(dc, mouseX, mouseY);
    }
    else if (event.LeftDown())
    {
        if (!m_leftBtnDown)
        {
            m_leftBtnDown = true;
            CaptureMouse();
            m_game->LButtonDown(dc, mouseX, mouseY);
        }
    }
    else if (event.LeftUp())
    {
        if (m_leftBtnDown)
        {
            m_leftBtnDown = false;
            ReleaseMouse();
            m_game->LButtonUp(dc, mouseX, mouseY);
        }
    }
    else if (event.RightDown() && !event.LeftIsDown())
    {
        // only allow right button undo if m_rightBtnUndo is true
        if (m_rightBtnUndo)
        {
            if (event.ControlDown() || event.ShiftDown())
            {
                m_game->Redo(dc);
            }
            else
            {
                m_game->Undo(dc);
            }
        }
    }
    else if (event.Dragging())
    {
        m_game->MouseMove(dc, mouseX, mouseY);
    }

    if (!event.LeftIsDown())
    {
        SetCursorStyle(mouseX, mouseY);
    }
}
Example #20
0
void GutterCtrl::OnMouseLeftDown(wxMouseEvent& event) {
	//wxLogDebug("OnMouseLeftDown");
	//wxASSERT(m_editorCtrl);
	wxASSERT(m_currentSel == -1);
	Lines& lines = m_editorCtrl.m_lines;

	// Get Mouse location
	const int x = event.GetX();
	const int y = event.GetY() + m_editorCtrl.scrollPos;

	// Handle bookmarks
	if (m_showBookmarks && x < (int)m_numberX) {
		// Find out which line was clicked on
		Lines& lines = m_editorCtrl.m_lines;
		if ((int)y < lines.GetHeight()) {
			const unsigned int line_id = lines.GetLineFromYPos(y);
			m_editorCtrl.AddBookmark(line_id, true /*toggle*/);
			DrawGutter(); // Redraw gutter to show bookmarks
			return;
		}
	}

	// Handle folding
	if (m_showFolds && x > (int)m_foldStartX) {
		ClickOnFold(y);
		return;
	}

	bool hasSelection = false;
	interval sel(0, 0);
	if (event.ShiftDown() && lines.IsSelected()) {
		sel = lines.GetSelections()[lines.GetLastSelection()];
		hasSelection = true;
	}

	// If not multiselecting or extending, remove previous selections
	if (!event.ControlDown()) {
		lines.RemoveAllSelections();
	}

	// Find out which line was clicked on
	if (y < lines.GetHeight()) {
		const unsigned int line_id = lines.GetLineFromYPos(y);

		// Select the line
		if (!lines.isLineVirtual(line_id)) {
			int startpos = lines.GetLineStartpos(line_id);
			int endpos = lines.GetLineEndpos(line_id, false);

			if (hasSelection) {
				startpos = wxMin(startpos, (int)sel.start);
				endpos = wxMax(endpos, (int)sel.end);
			}

			m_currentSel = lines.AddSelection(startpos, endpos);
			lines.SetPos(endpos);

			m_sel_startline = m_sel_endline = line_id;
		}
		m_sel_startoutside = false;
	}
	else {
		const unsigned int linecount = lines.GetLineCount();
		m_sel_startline = m_sel_endline = linecount ? linecount-1 : 0;
		m_sel_startoutside = true;

		if (hasSelection) {
			m_currentSel = lines.AddSelection(sel.start, lines.GetLength());
			lines.SetPos(lines.GetLength());
		}
	}

	// Make sure we capure all mouse events
	// this is released in OnMouseLeftUp()
	CaptureMouse();

	// Redraw the editCtrl to show new selection
	m_editorCtrl.DrawLayout();
}
Example #21
0
void CGraphView::OnMouseEvent(wxMouseEvent &event)
{
	if(m_nMode==ARROW) {
		wxShapeCanvas::OnMouseEvent(event);
		return;
	}

	wxClientDC dc(this);
	PrepareDC(dc);
	int ch,cw;
	dc.GetSize(&cw,&ch);
	
	wxPoint logPos(event.GetLogicalPosition(dc));
	
	double x, y;
	x = (double) logPos.x;
	y = (double) logPos.y;
	
	int keys = 0;
	if (event.ShiftDown())
		keys = keys | KEY_SHIFT;
	if (event.ControlDown())
		keys = keys | KEY_CTRL;
	
	bool dragging = event.Dragging();
	
	
    // Find the nearest object
	if(event.IsButton()) {
		if(event.RightDown()) {
			
			if(m_pHoverShape) {
				CNodeEvent evt;
				evt.SetEventType(GV_NODE_MENU);
				evt.SetNode(m_pHoverShape->GetId());
				evt.SetPosition(event.GetPosition());
				AddPendingEvent(evt);
			}

		} else if(event.LeftDClick()) {

			if(m_pHoverShape) {

				CNodeEvent evt;
				evt.SetEventType(GV_NODE_ACTIVATED);
				evt.SetNode(m_pHoverShape->GetId());
				evt.SetPosition(event.GetPosition());
				AddPendingEvent(evt);
			}
			
		} else if(event.LeftDown()) {
			
			if(m_pHoverShape) {
				m_pClickShape=m_pHoverShape;
				return;

			} else {
				m_pClickShape=NULL;
			
				if(event.ShiftDown()) {
					//m_bZooming=true;
					//m_ptGrab=event.GetPosition();
					//UpdateCursor();
					//CaptureMouse();
				} else {
					m_bGrabbing=true;
					m_ptGrab=event.GetPosition();
					int vx,vy;
					GetViewStart(&vx,&vy);
					m_ptGrabLogical=wxPoint(vx,vy);
					UpdateCursor();
					CaptureMouse();
				}
				return;
			}
		} else if(event.LeftUp()) {

			if(m_pClickShape && (m_pClickShape==m_pHoverShape)) {	
				CNodeEvent evt;
				evt.SetEventType(GV_NODE_SELECTED);
				evt.SetNode(m_pHoverShape->GetId());
				evt.SetPosition(event.GetPosition());
				AddPendingEvent(evt);
				return;
			}

			if(m_bGrabbing || m_bZooming) {
				ReleaseMouse();
			}
			m_bZooming=false;
			m_bGrabbing=false;
			UpdateCursor();

		}
		
//		if(nearest_object) {
		

//		}

		return;
	} else if(event.Moving()) {
	
		if(m_bGrabbing) {
			int nx,ny;
			event.GetPosition(&nx,&ny);
			nx=nx-m_ptGrab.x;
			ny=ny-m_ptGrab.y;
			
			int vx,vy;
			vx=m_ptGrabLogical.x-nx;
			vy=m_ptGrabLogical.y-ny;

			Scroll(vx,vy);
			UpdateCursor();
		} else if(m_bZooming) {
		/*	int nx,ny;
			event.GetPosition(&nx,&ny);
			nx=nx-m_ptGrab.x;
			ny=ny-m_ptGrab.y;
			
			double scale;
			if(ny>0.0) {
				scale=1.0+3.0*(ny/(ch/2.0));
			} else {
				scale=1.0-0.75*(-ny/(ch/2.0));
			}
			
			int vsx,vsy;
			GetViewStart(&vsx,&vsy);
				
			vsx=vsx*scale/m_diag.GetZoomFactor();
			vsy=vsy*scale/m_diag.GetZoomFactor();

			m_diag.SetZoomFactor(scale);
			SetScrollbars(1,1,m_nGraphWidth*scale,m_nGraphHeight*scale,vsx,vsy,true);
			Refresh(true);
			*/
		} else {

			int attachment=0;
			wxShape *shape=FindShape(x,y,&attachment,NULL,NULL,CLASSINFO(wxLineShape));
			if(shape!=m_pHoverShape) {
				m_pHoverShape=shape;
				UpdateCursor();
			}
			

		}

	} else if(event.Entering()) {
		UpdateCursor();	
	}

	

}
Example #22
0
void MorphanView::OnClick(wxMouseEvent& event)
{
    mouse = GetRealPosition(event.GetPosition());
    if (tool)
    {
        tool->Add(mouse);
        if ((tool->CanCreate() && tool->IsInfinitePoint() && event.ShiftDown()) ||
            (tool->CanCreate() && !tool->IsInfinitePoint()))
        {
            Primitive* p = tool->Create();
            p->SetFill(fillColor);
            p->SetOutline(outlineColor);
            p->SetWidth(outlineWidth);
            p->SetFilled(filled);

            p->SetId(timeSinceEpoch());
            GetDocument()->Add(current_frame, p);
            GetDocument()->Modify(true);
            tool->Clear();
            panel->Refresh();
        }
    }
    else
    {
        const std::set<PrimitiveSelection>& selection = modifyTool->GetSelection();
         std::vector<Primitive*> primitives = GetPrimitivesAt(mouse);
        // No selection but we got primitives, set our selection.
        if (selection.empty() && !primitives.empty())
        {
            modifyTool->SetSelection(primitives, mouse, true);
        }
        // We have a selection, and no primitives gotten perform action
        else if (!selection.empty() && primitives.empty())
        {
            std::vector<Primitive*> added = modifyTool->Modify(mouse);
            modifyTool->Clear();
            for (Primitive* p : added)
            {
                p->SetId(timeSinceEpoch());
                GetDocument()->Add(current_frame, p);
            }
            GetDocument()->Modify(true);
            panel->Refresh();
        }
        // We have a selection, and a primitive was selected (we perform action)
        else if (!selection.empty() && !primitives.empty() && !event.ControlDown())
        {
            std::vector<Primitive*> added = modifyTool->Modify(mouse);
            modifyTool->Clear();
            for (Primitive* p : added)
            {
                p->SetId(timeSinceEpoch());
                GetDocument()->Add(current_frame, p);
            }
            GetDocument()->Modify(true);
            panel->Refresh();
        }
        else if (!selection.empty() && !primitives.empty() && event.ControlDown())
        {
            modifyTool->SetSelection(primitives, mouse, false);
        }
    }
}