Esempio n. 1
0
void wxWebView::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);
}
Esempio n. 2
0
void CtrlRegisterList::mouseEvent(wxMouseEvent& evt)
{
	int xOffset, yOffset;
	((wxScrolledWindow*) this)->GetViewStart(&xOffset, &yOffset);

	wxClientDC dc(this);
	wxPoint pos = evt.GetPosition();
	int x = dc.DeviceToLogicalX(pos.x) + xOffset;
	int y = dc.DeviceToLogicalY(pos.y) + yOffset * rowHeight;

	if (evt.GetEventType() == wxEVT_RIGHT_UP)
	{
		if (y >= rowHeight)
		{
			int row = (y-rowHeight)/rowHeight;
			if (row != currentRows[category] && row < cpu->getRegisterCount(category))
				setCurrentRow(row);
		}

		wxMenu menu;
		int bits = cpu->getRegisterSize(category);

		menu.AppendRadioItem(ID_REGISTERLIST_DISPLAY32,		L"Display 32 bit");
		menu.AppendRadioItem(ID_REGISTERLIST_DISPLAY64,		L"Display 64 bit");
		menu.AppendRadioItem(ID_REGISTERLIST_DISPLAY128,	L"Display 128 bit");
		menu.AppendSeparator();

		if (bits >= 64)
		{
			menu.Append(ID_REGISTERLIST_CHANGELOWER,	L"Change lower 64 bit");
			menu.Append(ID_REGISTERLIST_CHANGEUPPER,	L"Change upper 64 bit");
		} else {
			menu.Append(ID_REGISTERLIST_CHANGEVALUE,	L"Change value");
		}

		switch (maxBits)
		{
		case 128:
			menu.Check(ID_REGISTERLIST_DISPLAY128,true);
			break;
		case 64:
			menu.Check(ID_REGISTERLIST_DISPLAY64,true);
			break;
		case 32:
			menu.Check(ID_REGISTERLIST_DISPLAY32,true);
			break;
		}

		menu.Connect(wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction)&CtrlRegisterList::onPopupClick, NULL, this);
		PopupMenu(&menu,evt.GetPosition());
		return;
	}

	if (evt.ButtonIsDown(wxMOUSE_BTN_LEFT) || evt.ButtonIsDown(wxMOUSE_BTN_RIGHT))
	{
		if (y < rowHeight)
		{
			int piece = GetSize().x/cpu->getRegisterCategoryCount();
			int cat = std::min<int>(x/piece,cpu->getRegisterCategoryCount()-1);

			if (cat != category)
			{
				category = cat;
				Refresh();
			}
		} else {
			int row = (y-rowHeight)/rowHeight;
			if (row != currentRows[category] && row < cpu->getRegisterCount(category))
				setCurrentRow(row);
		}

		SetFocus();
		SetFocusFromKbd();
	}
}
Esempio n. 3
0
void
SliderBar::OnMouseEvents (wxMouseEvent &ev)
{
    if (!IsEnabled()) {
        ev.Skip();
        return;
    }

    if (ev.Entering() && !_dragging) {
        _barbrush.SetColour(_overbarcolor);
        do_redraw();
    }
    else if (ev.Leaving() && !_dragging) {
        _barbrush.SetColour(_barcolor);
        do_redraw();
    }



    if (ev.Dragging() && _dragging)
    {
        int delta = ev.GetX() - _last_x;
        float fdelta = delta * _val_scale;

        if (ev.ControlDown()) {
            fdelta *= 0.5f;
            if (ev.ShiftDown()) {
                fdelta *= 0.5f;
            }
        }

        float newval = _value + fdelta;

        //cerr << "dragging: " << ev.GetX() << "  " << delta << "  " << fdelta << "  "  << newval << endl;

        if (_snap_mode == IntegerSnap) {
            newval = nearbyintf (newval);
        }

        newval = max (min (newval, _upper_bound), _lower_bound);

        if (newval != _value) {
            _value = newval;

            value_changed (get_value()); // emit

            update_value_str();
            do_redraw();
            //cerr << "new val is: " << _value << endl;


            _last_x = ev.GetX();
        }
    }
    else if (ev.Moving()) {
        // do nothing
    }
    else if (ev.GetEventType() == wxEVT_MOUSEWHEEL)
    {
        float fscale = 0.02f * (ev.ControlDown() ? 0.5f: 1.0f);
        float newval;

        if (_snap_mode == IntegerSnap) {
            newval = _value + ((ev.GetWheelRotation() > 0) ? 1 : -1);
        }
        else {
            if (ev.GetWheelRotation() > 0) {
                newval = _value + (_upper_bound - _lower_bound) * fscale;
            }
            else {
                newval = _value - (_upper_bound - _lower_bound) * fscale;
            }
        }


        if (_snap_mode == IntegerSnap) {
            newval = nearbyintf (newval);
        }

        newval = max (min (newval, _upper_bound), _lower_bound);


        _value = newval;

        value_changed (get_value()); // emit

        update_value_str();
        do_redraw();
    }
    else if (ev.RightDown()) {
        this->PopupMenu ( _popup_menu, ev.GetX(), ev.GetY());
    }
    else if (ev.RightUp()) {
        //this->PopupMenu ( _popup_menu, ev.GetX(), ev.GetY());
    }
    else if (ev.ButtonDown())
    {
        CaptureMouse();
        _dragging = true;
        _last_x = ev.GetX();
        pressed(); // emit

        if (ev.MiddleDown() && !ev.ControlDown()) {
            // set immediately
            float newval = (ev.GetX() * _val_scale) + _lower_bound;

            if (_snap_mode == IntegerSnap) {
                newval = nearbyintf (newval);
            }

            _value = newval;

            value_changed (get_value()); // emit

            update_value_str();
            do_redraw();
        }
        else if (ev.LeftDown() && ev.ShiftDown()) {
            // set to default
            _value = max (min (_default_val, _upper_bound), _lower_bound);

            value_changed(get_value());
            update_value_str();
            do_redraw();
        }
    }
    else if (ev.ButtonUp())
    {
        _dragging = false;
        ReleaseMouse();

        if (_use_pending) {
            // This didn't really work
            //if (_pending_val != _value) {
            //	_value = _pending_val;
            //	update_value_str();
            //}
            _use_pending = false;
        }


        if (ev.GetX() >= _width || ev.GetX() < 0
                || ev.GetY() < 0 || ev.GetY() > _height) {
            _barbrush.SetColour(_barcolor);
            do_redraw();
        }
        else {
            _barbrush.SetColour(_overbarcolor);
            do_redraw();
        }

        if (ev.MiddleUp() && ev.ControlDown())
        {
            // binding click
            bind_request(); // emit
        }

        released(); // emit
    }
    else if (ev.ButtonDClick()) {
        // this got annoying
        //show_text_ctrl ();
    }
    else {
        ev.Skip();
    }
}
Esempio n. 4
0
void wxMultiColumnListCtrl::OnMouseEvent(wxMouseEvent& event)
{
    if (event.GetEventType() == wxEVT_MOUSEWHEEL)
    {
        int dir = event.GetWheelRotation();

        if (dir > 0)
        {
            m_items.SetSelection(m_items.GetSelection() - 1);
            if (m_items.GetSelection() < 0)
                m_items.SetSelection(m_items.GetItemCount() - 1);

            AdvanceToNextSelectableItem(-1);
        }
        else if (dir < 0)
        {
            m_items.SetSelection(m_items.GetSelection() + 1);
            if (m_items.GetSelection() >= m_items.GetItemCount())
                m_items.SetSelection(0);

            AdvanceToNextSelectableItem(1);
        }

        GenerateSelectionEvent();

        Refresh();
    }
    else if (event.GetButton() == wxMOUSE_BTN_NONE)
    {   // Mouse move
        bool bCanSelectItem = true;
        if (m_ptMouse.x != -2 && m_ptMouse.y != -2)
        {   // If ==-2 => Don't select item on mouse pointer : used when user select the window with keyboard
            if (m_ptMouse.x != -1 && m_ptMouse.y != -1)
            {   // If ==-1 => The client already move the mouse, select the item under the mouse cursor
                wxPoint ptCurrent = ClientToScreen(event.GetPosition());
                if (abs(ptCurrent.x - m_ptMouse.x) >= 3 || abs(ptCurrent.y - m_ptMouse.y) >= 3)
                {   // the user has moved the mouse over a 3 pixels square
                    m_ptMouse.x = m_ptMouse.y = -1; // Accept to select an item
                }
                else
                {   // Select this item is not allowed for the moment, the user must move the mouse
                    bCanSelectItem = false;
                }
            }
            if (bCanSelectItem)
            {
                int idx = m_items.HitTest(event.GetPosition());
                if (idx != wxNOT_FOUND)
                {
                    m_items.SetSelection(idx);
                    GenerateSelectionEvent();
                    Refresh();
                }
            }
        }
    }
    else if (event.LeftDown())
    {
        m_ptMouse.x = m_ptMouse.y = -1; // Accept to select an item
        SendCloseEvent();
        SetFocus();
    }
}
Esempio n. 5
0
void wxTabbedCtrl::OnMouse(wxMouseEvent &ev) {
    wxPoint mouse = ev.GetPosition();
    int page = HitTest(ev.GetPosition());
    if(ev.GetEventType()==wxEVT_MOTION) {
        bool xhover = mouse.x >= x_rect.x && mouse.x <= x_rect.x+x_rect.width && mouse.y >= x_rect.y && mouse.y <= x_rect.y+x_rect.height;
        bool nhover = (mouse.x >= Next_rect.x && mouse.x <= Next_rect.x + Next_rect.width && mouse.y >= Next_rect.y && mouse.y <= Next_rect.y + Next_rect.height ) &&
                      ( m_intLastPage < ( GetPageCount() - 1 ) );
        bool phover = (mouse.x >= Prev_rect.x && mouse.x <= Prev_rect.x + Prev_rect.width && mouse.y >= Prev_rect.y && mouse.y <= Prev_rect.y + Prev_rect.height ) &&
                      ( m_intStartPage > 0 );
        bool mhover = (mouse.x >= Menu_rect.x && mouse.x <= Menu_rect.x + Menu_rect.width && mouse.y >= Menu_rect.y && mouse.y <= Menu_rect.y + Menu_rect.height );
        if(hover != xhover) {
            hover = xhover;
            wxClientDC dc(this);
            DrawX(hover, dc);
        }
        else if(hover_next != nhover) {
            hover_next = nhover;
            wxClientDC dc(this);
            DrawNext(hover_next, dc);
        }
        else if(hover_prev != phover) {
            hover_prev = phover;
            wxClientDC dc(this);
            DrawPrev(hover_prev, dc);
        }
        else if ( hover_menu != mhover ) {
            hover_menu = mhover;
            wxClientDC dc(this);
            DrawMenu(hover_menu, dc);
        }
        else {
            wxToolTip * tooltip = GetToolTip();
            if ( page != wxNOT_FOUND ) {
                if ( tipTab != page ) {
                    tipTab = page;
                    tooltip->Enable( true );
                    wxString info;
                    int pg = page + 1;
                    info << pg << " of " << GetPageCount() << " - " << GetPageText( page );
                    tooltip->SetTip( info );
                }
            }
            else {
                tipTab = -1;
                tooltip->Enable( false );
            }
        }
    }
    else if( ev.GetEventType()==wxEVT_LEFT_UP ) {
        if(hover ) {
            wxClientDC dc(this);
            DrawX(false, dc);
            SetVisible( active );
            wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, Menu_Close );
            GetEventHandler()->ProcessEvent( event );
        }
        else if( hover_next ) {
            wxClientDC dc(this);
            DrawNext(false, dc);
            if( GetPageCount() > ( m_intStartPage + 1 ) && ( m_intLastPage + 1 ) < GetPageCount() ) {
                m_intStartPage++;
                Refresh();
            }
        }
        else if( hover_prev ) {
            wxClientDC dc(this);
            DrawPrev(false, dc);
            if( m_intStartPage > 0 ) {
                m_intStartPage--;
                Refresh();
            }
        }
        else if( hover_menu ) {
            hover_menu = false;
            wxClientDC dc(this);
            DrawMenu(false, dc);
            GenerateConextMenu( mouse );
        }
        else {
            if(page != wxNOT_FOUND)
                SetSelection(page);
        }
    }
    else if( ev.GetEventType() == wxEVT_RIGHT_UP && page == wxNOT_FOUND ) {
        GenerateConextMenu( mouse );
    }
}
Esempio n. 6
0
void AxScrolledWindow::OnMouseEvent( wxMouseEvent &event )
{
    if (event.Dragging())
    {
        if (!m_bitmap)
            return;
        if (event.m_x > m_bitmap->GetWidth())
            return;
        if (event.m_y > m_bitmap->GetHeight())
            return;
        if (m_selection)
        {
            wxPoint newPosition = event.GetPosition();
            RedrawDraggingArea(newPosition,true);
        }
    }
    if (event.GetEventType() == wxEVT_MOUSEWHEEL)
    {
        if (event.LeftIsDown()) 
            return;

        int x, y;
        this->GetViewStart( &x, &y );
        int rot = 0;
        if ( event.m_wheelDelta != 0)
            rot = event.m_wheelRotation / event.m_wheelDelta * 6;
        //if (!m_shiftDown)
		if (!event.ShiftDown())
            this->Scroll( x, max(0, y - rot) );
        else
            this->Scroll( max( 0, x - rot ), y );
    }
    if (event.GetEventType() == wxEVT_LEAVE_WINDOW)
    {
        if (!m_bitmap)
            return;
			
		wxASSERT_MSG(m_imControlPtr,"Image controller cannot be NULL");
        wxPoint start, end;
        GetSelectionPoints(&start, &end);
		//m_imControlPtr->CloseDraggingSelection(start, end); // WARNING : commented to have superimposition ractivated using points added by hand. 
																// Not checked for pre-processing selection in recognition
        //m_isDragging = false;
        //this->SetCursor(*wxSTANDARD_CURSOR);
        m_endPosition = event.GetPosition();
    }
    if (event.GetEventType() == wxEVT_ENTER_WINDOW)
    {
        if (!m_bitmap)
            return;
        if (m_isDragging && event.m_leftDown)
            this->SetCursor(*wxCROSS_CURSOR);
		else // button has been released outside the window
		{
			this->SetCursor(*wxSTANDARD_CURSOR);
			m_isDragging = false;
		}
    }
    if (event.GetEventType() == wxEVT_LEFT_DOWN)
    {
        if (!m_bitmap)
            return;
        if (event.m_x > m_bitmap->GetWidth())
            return;
        if (event.m_y > m_bitmap->GetHeight())
            return;
        if (m_selection)
        {
            m_isDragging = true;
            this->SetCursor(*wxCROSS_CURSOR);
            RedrawDraggingArea(m_lastPosition,false);
            m_startPosition = event.GetPosition();
            m_lastPosition = m_startPosition;
        }
    }
    if (event.GetEventType() == wxEVT_LEFT_UP)
    {

        if (!m_bitmap)
            return;

        if (m_selection)
        {
            wxASSERT_MSG(m_imControlPtr,"Image controller cannot be NULL");
            wxPoint start, end;
            GetSelectionPoints(&start, &end);
            m_imControlPtr->CloseDraggingSelection(start, end);
            m_isDragging = false;
            this->SetCursor(*wxSTANDARD_CURSOR);
            m_endPosition = event.GetPosition();
            RedrawDraggingArea(m_lastPosition,true);
        }
    }
	if (event.GetEventType() == wxEVT_LEFT_DCLICK )
	{
        if (!m_bitmap)
            return;
		if (event.m_x > m_bitmap->GetWidth())
            return;
        if (event.m_y > m_bitmap->GetHeight())
            return;

		wxASSERT_MSG(m_imControlPtr,"Image controller cannot be NULL");
		m_lastPosition = event.GetPosition();
        wxPoint start, end;
        GetSelectionPoints(&start, &end);
		m_imControlPtr->LeftDClick( end );	
	}
}  
Esempio n. 7
0
void wxGL_PMFCanvas::OnMouseEvt(wxMouseEvent& event)
{
	bool update_omnipoints = false;

	if(event.Leaving() || event.ButtonUp()){
		mainpanel->control_panel->push_undo();
	}

	//if(!event.Leaving()){
	//	if(this != FindFocus()){
	//		previus_focus = FindFocus();
	//		SetFocus();
	//	}
	//}else{
	//	if(previus_focus)previus_focus->SetFocus();
	//}

	if (!model.GetSOBJCount())
	{
		event.Skip();
		return;
	}
	
	//glsz
	if (event.GetEventType() == wxEVT_LEFT_DOWN || 
		event.GetEventType() == wxEVT_RIGHT_DOWN )
	{
		mouse_start = wxPoint(event.GetX(), event.GetY());
	}
	else if (event.GetEventType() == wxEVT_MOTION && 
				event.Dragging())
	{
//########################start mouse movement code########################//
		if(event.m_controlDown){
	//------------------------start omnipoint code------------------------//
			//if control is down we move the selected omnipoint
			if(omni.point.size() > 0 && omni_selected_list >-1 && omni_selected_list < (int)omni.point.size() && omni_selected_item >-1 && omni_selected_item < (int)omni.point[omni_selected_list].size()){
				//but only if we have omnipoints and our selected coords are valid

				omnipoint&point = omni.point[omni_selected_list][omni_selected_item];

				double M[16], P[16];
				int v[4];
				glGetDoublev(GL_MODELVIEW_MATRIX, M);
				glGetDoublev(GL_PROJECTION_MATRIX, P);
				glGetIntegerv(GL_VIEWPORT, v);

				
				vector3d start;
				vector3d start_dir;
				vector3d end;
				vector3d end_dir;

				ray_cast(event.GetX(), event.GetY(), end, end_dir);
				ray_cast(mouse_start.x, mouse_start.y, start, start_dir);

				vector3d global_point = point.pos+model.get_model_offset(point.model);
					
					bool s = true, s2 = true;

				vector3d delta(0,0,0);

				if(event.m_leftDown){

					delta = filter_movement_delta(	plane_line_intersect(global_point, get_movement_plane_norm(),end, end_dir, &s)
														-	plane_line_intersect(global_point, get_movement_plane_norm(),start, start_dir, &s2));
					//if left button is down we move along x and y
				}else if(event.m_rightDown){
					//if right is down we move along y
					delta = closest_point_between_lines(global_point, get_movement_plane_norm(), end, end_dir)
										-closest_point_between_lines(global_point, get_movement_plane_norm(), start, start_dir);
				}
				if(s &&s2 && !null_vec(delta)){
					point.pos = point.pos + delta;
					update_omnipoints = true;
				}
			}
	//------------------------end omnipoint code------------------------//
		} else if(event.m_altDown){
			//------------------------start transform code------------------------//
			if(event.m_leftDown){
				//if left button is down we move along x and y
				bool s = true, s2 = true;
				vector3d start;
				vector3d start_dir;
				vector3d end;
				vector3d end_dir;

				ray_cast(event.GetX(), event.GetY(), end, end_dir);
				ray_cast(mouse_start.x, mouse_start.y, start, start_dir);

				// XXX: Should this have a value?
				vector3d global_point = vector3d();
				vector3d delta;

				delta = filter_movement_delta(	plane_line_intersect(global_point, get_movement_plane_norm(),end, end_dir, &s)
						-	plane_line_intersect(global_point, get_movement_plane_norm(),start, start_dir, &s2));
				if(s &&s2 && !null_vec(delta)){
					mainpanel->control_panel->transform(matrix(), delta);
				}
			}else if(event.m_rightDown){
				//if right is down we rotate about z
				float angle = (mouse_start.y - event.GetY());
				matrix transform(get_movement_plane_norm());
				if(angle){
					mainpanel->control_panel->transform(transform.invert() % matrix(angle) % transform, vector3d());
				}
			}
		//------------------------end transform code------------------------//
	}else{
	//++++++++++++++++++++++++start view code++++++++++++++++++++++++//
			if (!event.m_shiftDown)
			{
				//if shift is not down we rotate
				if (event.m_leftDown)
				{
					//we rotate about x and y when the left button is down
					rotation.y -= (mouse_start.x - event.GetX());
					rotation.x -= (mouse_start.y - event.GetY());
				}
				else
				{
					//we rotate about z when the right is down
					rotation.z -= (mouse_start.y - event.GetY());
				}
			}
			else
			{
				//if shift is down them we move the position
				if (event.m_leftDown)
				{
					//we move x and y when the left is down
					position.x -= model.SOBJ(0).radius * 
							(float(mouse_start.x - event.GetX())/100.0) ;
					position.y += model.SOBJ(0).radius *
						(float(mouse_start.y - event.GetY())/100.0);
				}
				else
				{
					//we move along z when the right is down
					position.z -= model.SOBJ(0).radius *
						(float(mouse_start.y - event.GetY())/100.0);
				}
			}
	//++++++++++++++++++++++++end view code++++++++++++++++++++++++//
		}
		mouse_start = wxPoint(event.GetX(), event.GetY());
		Render();
//########################end mouse movement code########################//
	}
	
	if (event.GetEventType() == wxEVT_MOUSEWHEEL){
//************************start scroll code************************//
		if(event.m_controlDown){
	//------------------------start omnipoint code------------------------//
			//if control is down we scale the selected omnipoint
			if(omni.flags & OMNIPOINT_RAD && omni.point.size() > 0 && omni_selected_list >-1 && omni_selected_list < (int)omni.point.size() && omni_selected_item >-1 && omni_selected_item < (int)omni.point[omni_selected_list].size()){
				//if the omnipoint has a radius
				//and the coords are valid
				if(omni.point[omni_selected_list][omni_selected_item].rad < 0.000001)omni.point[omni_selected_list][omni_selected_item].rad = model.get_avg_dimintion()/61.80f;
				if(event.GetWheelRotation()>0)
					omni.point[omni_selected_list][omni_selected_item].rad *= float(event.GetWheelRotation()/event.GetWheelDelta())*1.15;
				else
					omni.point[omni_selected_list][omni_selected_item].rad /= float(-event.GetWheelRotation()/event.GetWheelDelta())*1.15;

				update_omnipoints=true;
			}
	//------------------------end omnipoint code------------------------//
		} else if(event.m_altDown){
			//------------------------start transform code------------------------//
			float scale;
			if(event.GetWheelRotation()>0) {
				scale = float(event.GetWheelRotation()/event.GetWheelDelta())*1.15;
			} else {
				scale = 1 / (float(-event.GetWheelRotation()/event.GetWheelDelta())*1.15);
			}
			matrix transform;
			for (int i = 0; i < 3; i++) {
				transform.a2d[i][i] = scale;
			}
			if(scale != 1.0f){
				mainpanel->control_panel->transform(transform, vector3d());
			}
			//------------------------end transform code------------------------//
		}else{
	//++++++++++++++++++++++++start view code++++++++++++++++++++++++//
			position.z -= float(	event.GetWheelRotation()/event.GetWheelDelta()	) * position.z/50.0f;
	//++++++++++++++++++++++++end view code++++++++++++++++++++++++//
		}
//************************end scroll code************************//
		Render();
	}
	else
		event.Skip();

	if(update_omnipoints){
		mainpanel->control_panel->set_omnipoints(omni);
		set_omnipoints(mainpanel->control_panel->get_omnipoints());
	}
//	Render();
}
Esempio n. 8
0
void wxFixWidthImportCtrl::OnMouse(wxMouseEvent &event)
{
    if (event.GetEventType() == wxEVT_MOUSEWHEEL && !m_captured)
    {
        size_t curposOld = m_curposL;
        int wheelRot = event.GetWheelRotation();
        int lines = wheelRot / event.GetWheelDelta();
        int pos = (int)m_curposL - lines; //New position tried
        if (pos < 0)
            m_curposL = 0;
        else
        {   m_curposL = (size_t)pos;
            pos = m_scrbarV->GetRange() - m_scrbarV->GetThumbSize(); //Max pos
            if (m_curposL > (size_t)pos)
                m_curposL = (size_t)pos;
            if (pos < 0) //This should never happen
                m_curposL = 0;
        }
        if (curposOld != m_curposL)
        {
            m_scrbarV->SetThumbPosition((int)m_curposL);
            Refresh();
        }
        return;
    }

    bool drawNew  = false; //Draw a new delimiter
    bool deleVal  = false; //Delete a value
    bool addVal   = false; //Add a value
    bool changeCl = false; //Change file line's colour
    bool paintIt  = false; //Refresh it all
    bool isOnRect = false; //Click is inside strings rect
    wxCoord xm = event.GetPosition().x;
    wxCoord ym = event.GetPosition().y;
    size_t n = 0;

    //Where is the mouse?
    if (xm >= m_rS.xmin && ym >= m_rS.ymin) //Below upper left corner
        isOnRect = true;

    wxClientDC dc( this );
    dc.SetFont(*m_Ffont);
    wxDouble fontS = dc.GetCharWidth() + FONTPADDING;
    //the nearest mark to the mouse
    wxCoord mA = xm; //mouse actual
    mA = (wxCoord)((double) (mA - m_rS.xmin - m_margin) / fontS + 0.5);
    int markVal = (int) mA + m_curposX; //can be < 0 because of CaptureMouse
    //x coordinate of the mark
    mA = mA * fontS + m_rS.xmin + m_margin;

    //Delete previus delimiter
    if ( m_delPrev )
        DrawDelimiter(&dc, m_Lc, wxXOR);
    m_delPrev = false;

    //Decide what to do (stored in m_LAct)
    if (event.LeftDown()) //Fired at first click
    {
        m_captured = true;
        CaptureMouse(); //We want to get LeftUp even cursor is out of window

        if ( isOnRect ) //at text
            m_LAct = 2;
        else if ( xm < m_rS.xmin || xm > m_rS.xmax
                 || markVal >= (int) m_maxLen || markVal < 1 //out of bounds
                 || !deliEnabled ) //or delimiters not enabled
            m_LAct = 0;
        else //at scale
        {   m_LAct = 1;
            m_Lc = mA;
            drawNew = true; //Delimiter changes colour
            //check if click was on a existing delimiter
            if ( m_values.Index(markVal) != wxNOT_FOUND )
                deleVal = true; //Keep m_delPrev=false, keep changed colour
            else
                m_delPrev = true;
            //store values for later comparation
            for ( n = 0; n < m_values.GetCount(); n++)
                m_valuesB.Add(m_values.Item(n));
        }
    }

    else if (event.Dragging() && event.LeftIsDown() && m_LAct == 1)
    {
        //Should we draw a new delimiter?
        if (mA >= m_rS.xmin && mA <= m_rS.xmax
            && markVal < (int) m_maxLen && markVal > 0)
        {
             drawNew = true;
             m_delPrev = true;
        }
    }

    else if (event.LeftUp()) //Finishing
    {
        if ( m_captured )
        {   ReleaseMouse();
            m_captured = false;
        }
        SetFocus(); //Needed to response to mouseWheel
        m_Lc = 0;
        m_delPrev = false;
        paintIt = true;

        if ( m_LAct == 1 &&
             mA >= m_rS.xmin && mA <= m_rS.xmax
             && markVal < (int) m_maxLen && markVal > 0) //Not out of bounds

            addVal = true;

        if ( m_LAct == 2 )
            changeCl = true;
    }

    //Do the things that were decided to be done
    if ( drawNew )
    {   DrawDelimiter(&dc, mA, wxXOR);
        //Store new position
        m_Lc = mA;
    }

    if ( deleVal )
        m_values.Remove(markVal);

    if ( addVal )
    {   //We suppose array is small, so keeping it sorted is quick
        bool valueExist = false;
        size_t nval = m_values.GetCount();
        size_t val = (nval == 0 ? 1 : 0);
        while ( val < nval)
        {
            if ( m_values.Item(val) >= markVal )
            {
                if ( m_values.Item(val) == markVal )
                    valueExist = true;
                break;
            }
            else
                val++;
        }

        if ( !valueExist )
        {   if ( val == nval || nval == 0)
                m_values.Add(markVal);
            else
                m_values.Insert((int) markVal, val);
        }
    }
    if ( event.LeftUp() && m_LAct == 1 ) //Check if values changed
    {   if ( m_values.GetCount() != m_valuesB.GetCount() )
            FireEvent();
        else
            for ( n = 0; n < m_values.GetCount(); n++)
                if ( m_values.Item(n) != m_valuesB.Item(n) )
                {   FireEvent();
                    break;
                }
        m_valuesB.Clear();
    }

    if ( changeCl ) //Calculate new line to be coloured
    {
        if (xm >= m_rS.xmin && xm <= m_rS.xmax && ym >= m_rS.ymin && ym <= m_rS.ymax)
        {
            fontS = dc.GetCharHeight();
            //Mouse on line ...
            mA = (wxCoord)((double) (ym - m_rS.ymin - m_margin) / fontS);
            markVal = (int) mA + m_curposL; //can be < 0 because of CaptureMouse
            //Max line shown
            mA = (wxCoord)((double) (m_rS.ymax - m_rS.ymin - m_margin) / fontS - 0.5);
            mA = (int) mA + m_curposL;

            if ( markVal != (int) m_markedL &&
                markVal >=0 && markVal <= mA && markVal < (int) m_Lines.GetCount() )
            {   m_markedL = markVal;
                FireEvent();
                paintIt = true;
            }
        }
    }

    if ( paintIt )
        Refresh();
}
Esempio n. 9
0
void mmMultiButton::OnMouse(wxMouseEvent& event)
// Update button state
{
#ifdef __MMDEBUG__
  //*gDebug<<"mmMultiButton::OnMouse,type:"<<event.GetEventType()<<"\n";
#endif

  mIsActivated = FALSE;

  if ((mStyle & mmMB_STATIC) || !IsEnabled())
  {
    mHasFocus              = FALSE;
    mIsToggleDown          = FALSE;
    mIsWholeDropToggleDown = FALSE;
    mIsDropToggleDown      = FALSE;
    mIsSelected            = FALSE;
    return;
  }

  if (!(mStyle & mmMB_TOGGLE))
    mIsToggleDown          = FALSE;

  if (!(mStyle & mmMB_WHOLEDROPDOWN))
    mIsWholeDropToggleDown = FALSE;

  if (!(mStyle & mmMB_DROPDOWN))
    mIsDropToggleDown      = FALSE;

  bool focus_changed           = FALSE,
       toggle_changed          = FALSE,
       wholedroptoggle_changed = FALSE,
       droptoggle_changed      = FALSE,
       selected_changed        = FALSE;

  int w,h;
  GetClientSize(&w,&h);
  wxPoint mp = event.GetPosition();

  if (event.Entering())
  { // ENTER
    if ((mStyle & mmMB_AUTODRAW) || (mStyle & mmMB_FOCUS))
      focus_changed = !mHasFocus;
    mHasFocus = TRUE;
  }
  else
  if (event.Leaving())
  { // LEAVE
    mIsSelected = FALSE;
    if (!mIsDropToggleDown && !mIsWholeDropToggleDown)
    {
      if ((mStyle & mmMB_AUTODRAW) || (mStyle & mmMB_FOCUS))
        focus_changed = mHasFocus;
      mHasFocus = FALSE;
      if (HasCapture()) ReleaseMouse();
    }
  }
  else
  if (event.LeftDown() || event.LeftDClick())
  { // SELECT
    if (mStyle & mmMB_TOGGLE)
    { // TOGGLE
      if (mIsSelected)
        selected_changed = TRUE;
      mIsSelected = FALSE;
      CaptureMouse();
    }
    else
    if (mStyle & mmMB_WHOLEDROPDOWN)
    { // WHOLEDROPDOWN
      if (MouseIsOnButton())
      {
        if (!mIsSelected)
          selected_changed = TRUE;
        mIsSelected = TRUE;
        wholedroptoggle_changed = TRUE;
        mIsWholeDropToggleDown = !mIsWholeDropToggleDown;
        if (mIsWholeDropToggleDown)
	  CaptureMouse();
        else
          if (HasCapture()) ReleaseMouse();
      }
      else
      { // Pressed outside of button
        if (mIsSelected)
          selected_changed = TRUE;
	mIsSelected = FALSE;
        if (mIsWholeDropToggleDown)
          wholedroptoggle_changed = TRUE;
	mIsWholeDropToggleDown = FALSE;
        if (HasCapture()) ReleaseMouse();
      }
    }
    else
    /*
    if (mStyle & mmMB_DROPDOWN)
    { // DROPDOWN
      if (mp.x > w-gDownBM.GetWidth()-mBorderSize && mp.x < w &&
	      mp.y > mBorderSize && mp.y < h-mBorderSize)
      { // Drop down arrow pressed
        if (mIsSelected)
          selected_changed = TRUE;
	mIsSelected = FALSE;
        droptoggle_changed = TRUE;
        mIsDropToggleDown = !mIsDropToggleDown;
	if (mIsDropToggleDown)
	  CaptureMouse();
        else
          if (HasCapture()) ReleaseMouse();
      }
      else
      if (MouseIsOnButton())
      { // Button (not arrow) pressed
        if (!mIsSelected)
          selected_changed = TRUE;
	mIsSelected = TRUE;
        //if (mIsDropToggleDown)
          //droptoggle_changed = TRUE;
	//mIsDropToggleDown = FALSE;
        CaptureMouse();
      }
      else
      { // Pressed outside of button
        if (mIsSelected)
          selected_changed = TRUE;
	mIsSelected = FALSE;
        if (mIsDropToggleDown)
          droptoggle_changed = TRUE;
	mIsDropToggleDown = FALSE;
        if (HasCapture()) ReleaseMouse();
      }
    }
    else
    */
    { // 'Normal' button
      if (!mIsSelected)
        selected_changed = TRUE;
      mIsSelected = TRUE;
      CaptureMouse();
    }
    if (!MouseIsOnButton())
    {
      focus_changed = mHasFocus;
      mHasFocus = FALSE;
    }
  }
  else
  if (event.LeftUp())
  { // ACTIVATE
    if (mStyle & mmMB_TOGGLE)
    { // TOGGLE
      if (mIsSelected)
        selected_changed = TRUE;
      mIsSelected = FALSE;
      toggle_changed = TRUE;
      mIsToggleDown = !mIsToggleDown;
      if (HasCapture()) ReleaseMouse();
    }
    else
    if (mStyle & mmMB_WHOLEDROPDOWN)
    { // WHOLEDROPDOWN
      if (mIsSelected)
        selected_changed = TRUE;
      mIsSelected = FALSE;
      if (!mIsWholeDropToggleDown)
        if (HasCapture()) ReleaseMouse();
    }
    /*
    else
    if (mStyle & mmMB_DROPDOWN)
    { // DROPDOWN
      if (mIsSelected)
        selected_changed = TRUE;
      mIsSelected = FALSE;
      if (mp.x > w-gDownBM.GetWidth()-mBorderSize && mp.x < w &&
	      mp.y > mBorderSize && mp.y < h-mBorderSize)
      { // Drop down arrow pressed
        if (!mIsDropToggleDown)
          if (HasCapture()) ReleaseMouse();
      }
      else
      if (MouseIsOnButton())
      { // Button (not arrow) pressed
        if (mIsDropToggleDown)
          droptoggle_changed = TRUE;
	mIsDropToggleDown = FALSE;
	if (!droptoggle_changed)
          mIsActivated = TRUE; // NOTE! SEND ACTIVATE SIGNAL!
        if (HasCapture()) ReleaseMouse();
      }
    }
    */
    else
    { // 'Normal' button
      if (mIsSelected)
        selected_changed = TRUE;
      mIsSelected = FALSE;
      mIsActivated = TRUE; // NOTE! SEND ACTIVATE SIGNAL!
      if (HasCapture()) ReleaseMouse();
    }
  }

  // Redraw only if neccessary
  if (focus_changed || selected_changed || wholedroptoggle_changed || droptoggle_changed || toggle_changed)
  {
    Refresh();
    // Generate events to let derived class know what happened
    if (focus_changed)
    { // ENTER/LEAVE
      wxCommandEvent ev(event.GetEventType(),GetId());
      if (mHasFocus)
        ev.SetEventType(wxEVT_ENTER_WINDOW);
      else
        ev.SetEventType(wxEVT_LEAVE_WINDOW);
      GetEventHandler()->ProcessEvent(ev); // Neccessary?
    }
    if (toggle_changed)
    { // TOGGLE
      wxCommandEvent ev(mmEVT_TOGGLE,GetId());
      GetEventHandler()->ProcessEvent(ev);
    }
    if (wholedroptoggle_changed)
    { // WHOLEDROPDOWN
      wxCommandEvent ev(mmEVT_WHOLEDROP_TOGGLE,GetId());
      GetEventHandler()->ProcessEvent(ev);
    }
    if (droptoggle_changed)
    { // DROPDOWN
      wxCommandEvent ev(mmEVT_DROP_TOGGLE,GetId());
      GetEventHandler()->ProcessEvent(ev);
    }
    if (selected_changed)
    { // SELECT
      wxCommandEvent ev(wxEVT_COMMAND_LEFT_CLICK,GetId());
      GetEventHandler()->ProcessEvent(ev);
    }
    if (mIsActivated)
    { // ACTIVATE
      wxCommandEvent ev(wxEVT_COMMAND_BUTTON_CLICKED,GetId());
      GetEventHandler()->ProcessEvent(ev);
    }
  } // if
  event.Skip();
} // OnMouse
Esempio n. 10
0
void TileMapPanel::OnMouseEvent(wxMouseEvent &event)
{
    if(!m_tilemap || !m_tileset)
        return;

    //Get the current tile position (column and row)
    unsigned int currentColumn, currentRow;
    wxPoint mousePos = CalcUnscrolledPosition(event.GetPosition());
    GetTileAt(mousePos, currentColumn, currentRow);

    if(currentColumn >= m_tilemap->GetColumnsCount() || currentRow >= m_tilemap->GetRowsCount())
        return; //Stop if the position is out of range

    if(m_insertionMode == PencilMode)
    {
        if(event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_RIGHT_DOWN || event.GetEventType() == wxEVT_MOTION)
        {
            if(event.LeftIsDown()) //Left mouse button pressed
            {
                //Add a tile to the current position (only if the tile has not been set before)
                if(m_tilemap->GetTile(m_mapCurrentLayer, currentColumn, currentRow) != m_tileToBeInserted)
                    m_commandProcessor.Submit(new ChangeTileCommand(*m_tilemap, m_mapCurrentLayer, currentColumn, currentRow, m_tileToBeInserted));
                Refresh();
            }
            else if(event.RightIsDown())
            {
                //Remove the tile
                m_commandProcessor.Submit(new ChangeTileCommand(*m_tilemap, m_mapCurrentLayer, currentColumn, currentRow, -1));
                Refresh();
            }
        }
    }
    else if(m_insertionMode == RectangleMode)
    {
        if(event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_RIGHT_DOWN)
        {
            m_isDrawingRectangle = true;
            m_beginCol = m_endCol = currentColumn;
            m_beginRow = m_endRow = currentRow;

            Update();
        }
        else if(event.GetEventType() == wxEVT_MOTION)
        {
            m_endCol = currentColumn;
            m_endRow = currentRow;
            Update();
        }
        else if(event.GetEventType() == wxEVT_LEFT_UP)
        {
            m_endCol = currentColumn;
            m_endRow = currentRow;
            m_isDrawingRectangle = false;

            m_commandProcessor.Submit(new ChangeTileCommand(*m_tilemap, m_mapCurrentLayer, std::min(m_beginCol, m_endCol),
                                                                                           std::min(m_beginRow, m_endRow),
                                                                                           std::max(m_beginCol, m_endCol),
                                                                                           std::max(m_beginRow, m_endRow),
                                                                                           m_tileToBeInserted));

            Update();
        }
        else if(event.GetEventType() == wxEVT_RIGHT_UP)
        {
            m_endCol = currentColumn;
            m_endRow = currentRow;
            m_isDrawingRectangle = false;

            m_commandProcessor.Submit(new ChangeTileCommand(*m_tilemap, m_mapCurrentLayer, std::min(m_beginCol, m_endCol),
                                                                                           std::min(m_beginRow, m_endRow),
                                                                                           std::max(m_beginCol, m_endCol),
                                                                                           std::max(m_beginRow, m_endRow),
                                                                                           -1));

            Update();
        }
    }
    else if(m_insertionMode == FillMode)
    {
        if(event.GetEventType() == wxEVT_LEFT_DOWN)
        {
            m_commandProcessor.Submit(new FloodFillCommand(*m_tilemap, m_mapCurrentLayer, currentColumn, currentRow, m_tileToBeInserted));

            Update();
        }
    }
}