bool EDA_DRAW_PANEL::OnRightClick( wxMouseEvent& event ) { wxPoint pos; wxMenu MasterMenu; INSTALL_UNBUFFERED_DC( dc, this ); pos = event.GetLogicalPosition( dc ); if( !GetParent()->OnRightClick( pos, &MasterMenu ) ) return false; GetParent()->AddMenuZoomAndGrid( &MasterMenu ); pos = event.GetPosition(); m_ignoreMouseEvents = true; PopupMenu( &MasterMenu, pos ); // The ZoomAndGrid menu is only invoked over empty space so there's no point in warping // the cursor back to the crosshair, and it's very annoying if one clicked out of the menu. m_ignoreMouseEvents = false; return true; }
void ManageFieldTextureDialog::OnTextureMouseMove(wxMouseEvent& event) { if (event.LeftIsDown()) { if (prevent_event) return; prevent_event = true; m_texturewindow->SetFocusIgnoringChildren(); if (color_selected!=-1) { /* wxClientDC dc(m_texturewindow); m_texturewindow->DoPrepareDC(dc); wxPoint mpos = event.GetLogicalPosition(dc); int timx = min(max(int(mpos.x*scale_ratio),0),tim.GetWidth()-1); int timy = min(max(int(mpos.y*scale_ratio),0),tim.height-1); tim.SetPixelValue(timx,timy,color_selected,char_flag ? m_palettelist->GetSelection()%2 : -1); UpdateTexturePreview(wxID_PALETTE);*/ } else if (imported_img.IsOk()) { wxClientDC dc(m_texturewindow); m_texturewindow->DoPrepareDC(dc); wxPoint mpos = event.GetLogicalPosition(dc); imported_img_x = min(max(int(mpos.x*scale_ratio-imported_img_width/2),m_textureposx->GetMin()),m_textureposx->GetMax()); imported_img_y = min(max(int(mpos.y*scale_ratio-imported_img_height/2),m_textureposy->GetMin()),m_textureposy->GetMax()); m_textureposx->SetValue(imported_img_x); m_textureposy->SetValue(imported_img_y); DrawImage(dc); } prevent_event = false; } }
void CurvePane::mouseMoved(wxMouseEvent& event) { int m=10; int w, h; mousemoved = true; wxClientDC dc(this); dc.GetSize(&w, &h); if( mousemotion) { pos = event.GetLogicalPosition(dc); pos.x = pos.x-m; pos.y = h-m-pos.y; if (selectedCP.x > -1.0) { c.deletepoint(selectedCP.x, selectedCP.y); selectedCP.x -= mouseCP.x - (double) pos.x; selectedCP.y -= mouseCP.y - (double) pos.y; if (selectedCP.x < 0.0) selectedCP.x = 0.0; if (selectedCP.x > 255.0) selectedCP.x = 255.0; if (selectedCP.y < 0.0) selectedCP.y = 0.0; if (selectedCP.y > 255.0) selectedCP.y = 255.0; c.insertpoint((double) selectedCP.x, (double) selectedCP.y); } mouseCP.x = (double) pos.x; mouseCP.y = (double) pos.y; paintNow(); } }
void ExplainCanvas::OnMouseMotion(wxMouseEvent &ev) { ev.Skip(true); if (ev.Dragging()) return; wxClientDC dc(this); PrepareDC(dc); wxPoint logPos(ev.GetLogicalPosition(dc)); double x, y; x = (double) logPos.x; y = (double) logPos.y; // Find the nearest object int attachment = 0; ExplainShape *nearestObj = dynamic_cast<ExplainShape *>(FindShape(x, y, &attachment)); if (nearestObj) { ShowPopup(nearestObj); } }
void RegRichTextCtrl::OnLeftClick( wxMouseEvent& event ) { SetFocus(); wxClientDC dc(this); PrepareDC(dc); dc.SetFont(GetFont()); long position = 0; int hit = GetBuffer().HitTest(dc, event.GetLogicalPosition(dc), position); if (hit != wxRICHTEXT_HITTEST_NONE) { bool caretAtLineStart = false; if (hit & wxRICHTEXT_HITTEST_BEFORE) { // If we're at the start of a line (but not first in para) // then we should keep the caret showing at the start of the line // by showing the m_caretAtLineStart flag. wxRichTextParagraph* para = GetBuffer().GetParagraphAtPosition(position); wxRichTextLine* line = GetBuffer().GetLineAtPosition(position); if (line && para && line->GetAbsoluteRange().GetStart() == position && para->GetRange().GetStart() != position) caretAtLineStart = true; position--; } MoveCaret(position, caretAtLineStart); SelectWord(GetCaretPosition()); } }
void ManageFieldTextureDialog::OnAnimClick(wxMouseEvent& event) { wxClientDC dc(m_animlist); wxPoint mpos = event.GetLogicalPosition(dc); wxPoint mrpos = event.GetPosition(); int button,col,hitflags; button = mpos.x/20; // Not that great... Problems if HScroll is enabled col = m_animlist->HitTest(mrpos,hitflags); if (button>=0 && button<3 && col>=0 && col<field.anim_amount) { switch (button) { case 0: // Loop if (anim_play_flag[col] & ANIM_PLAYFLAG_LOOP) anim_play_flag[col] &= ~ANIM_PLAYFLAG_LOOP; else anim_play_flag[col] |= ANIM_PLAYFLAG_LOOP; break; case 1: // Play/Pause if (anim_play_flag[col] & ANIM_PLAYFLAG_PLAY) anim_play_flag[col] &= ~ANIM_PLAYFLAG_PLAY; else anim_play_flag[col] |= ANIM_PLAYFLAG_PLAY; break; case 2: // Stop anim_play_flag[col] &= ~ANIM_PLAYFLAG_PLAY; anim_tile_pos[col] = 0; anim_tick_time[col] = field.anim[col].tile_duration[0]; m_tilechecklist->Check(field.anim[col].tile_list[0],true); for (unsigned int i=1;i<field.anim[col].tile_amount;i++) m_tilechecklist->Check(field.anim[col].tile_list[i],false); UpdateTexturePreview(wxID_TILE); break; } m_animlist->SetItemImage(col,anim_play_flag[col]); } }
// This implements a tiny doodling program! Drag the mouse using the left // button. void MyCanvas::OnEvent(wxMouseEvent& event) { wxClientDC dc(this); PrepareDC(dc); wxPoint pt(event.GetLogicalPosition(dc)); static long xpos = -1; static long ypos = -1; if (xpos > -1 && ypos > -1 && event.Dragging()) { dc.SetPen(*wxBLACK_PEN); dc.DrawLine(xpos, ypos, pt.x, pt.y); m_dirty = true; } else { event.Skip(); } xpos = pt.x; ypos = pt.y; }
void NassiDiagramWindow::OnMouseLeftDown(wxMouseEvent &event) { wxClientDC dc(this); DoPrepareDC(dc); RemoveDrawlet(dc); wxPoint pos = event.GetLogicalPosition(dc); m_view->OnMouseLeftDown(event, pos); this->SetFocus(); }
void SpectDisplay::OnMouse(wxMouseEvent& event) {//======================================== int frame; int ix; SetFocus(); if(event.RightDown()) { PopupMenu(menu_spectdisplay); return; } wxClientDC dc(this); PrepareDC(dc); wxPoint pt(event.GetLogicalPosition(dc)); if(spectseq->numframes==0) return; frame = (int)(pt.y/(FRAME_HEIGHT*zoomy)); if(!event.ControlDown()) spectseq->SelectAll(0); if(event.ShiftDown()) { if(sframe >= 0) { if(frame < sframe) for(ix=frame; ix<=sframe; ix++) spectseq->frames[ix]->selected =1; else for(ix=sframe; ix<=frame && ix<spectseq->numframes; ix++) spectseq->frames[ix]->selected =1; Refresh(); } } else { if(frame < spectseq->numframes) spectseq->frames[frame]->selected ^= 1; Refresh(); } if(frame < spectseq->numframes) { formantdlg->GetValues(spectseq,sframe); if(sframe != frame) formantdlg->ShowFrame(spectseq,frame,pk_num,0xff); sframe = frame; } } // end of SpectDisplay::OnMouse
// This implements a tiny doodling program. Drag the mouse using // the left button. void MyCanvas::OnMouseEvent(wxMouseEvent& event) { if (!view) return; static DoodleSegment *currentSegment = (DoodleSegment *) NULL; wxClientDC dc(this); PrepareDC(dc); dc.SetPen(*wxBLACK_PEN); wxPoint pt(event.GetLogicalPosition(dc)); if (currentSegment && event.LeftUp()) { if (currentSegment->lines.GetCount() == 0) { delete currentSegment; currentSegment = (DoodleSegment *) NULL; } else { // We've got a valid segment on mouse left up, so store it. DrawingDocument *doc = (DrawingDocument *)view->GetDocument(); doc->GetCommandProcessor()->Submit(new DrawingCommand(_T("Add Segment"), DOODLE_ADD, doc, currentSegment)); view->GetDocument()->Modify(true); currentSegment = (DoodleSegment *) NULL; } } if (xpos > -1 && ypos > -1 && event.Dragging()) { if (!currentSegment) currentSegment = new DoodleSegment; DoodleLine *newLine = new DoodleLine; newLine->x1 = (long)xpos; newLine->y1 = (long)ypos; newLine->x2 = pt.x; newLine->y2 = pt.y; currentSegment->lines.Append(newLine); dc.DrawLine( (long)xpos, (long)ypos, pt.x, pt.y); } xpos = pt.x; ypos = pt.y; }
// This implements a tiny doodling program! Drag the mouse using // the left button. void MyCanvas::OnEvent(wxMouseEvent& event) { wxClientDC dc(this); PrepareDC(dc); wxPoint pt(event.GetLogicalPosition(dc)); if (xpos > -1 && ypos > -1 && event.Dragging()) { dc.SetPen(*wxBLACK_PEN); dc.DrawLine(xpos, ypos, pt.x, pt.y); } xpos = pt.x; ypos = pt.y; }
void NassiDiagramWindow::OnMouseMove(wxMouseEvent &event) { wxClientDC dc(this); DoPrepareDC(dc); RemoveDrawlet(dc); wxPoint pos = event.GetLogicalPosition(dc); m_hd = m_view->OnMouseMove(event, pos); if ( m_hd && !m_hd->Draw(dc) ) { delete m_hd; m_hd = 0; } }
void MainFrame::OnLeftDown( wxMouseEvent& event ) { wxWindowDC dc(source_image); wxPoint point = event.GetLogicalPosition(dc); wxColour color; dc.GetPixel(point, &color); Control::getInstance()->setTargetColor(color.Red(), color.Green(), color.Blue()); // process the image Control::getInstance()->process(); //show the result image; this->processed_image->SetBitmap(Control::getInstance()->getResult()); //set the color button this->color_button->SetColour(color); }
// This implements a tiny doodling program. Drag the mouse using the left // button. void MyCanvas::OnMouseEvent(wxMouseEvent& event) { if ( !m_view ) return; wxClientDC dc(this); PrepareDC(dc); dc.SetPen(*wxBLACK_PEN); const wxPoint pt(event.GetLogicalPosition(dc)); // is this the end of the current segment? if ( m_currentSegment && event.LeftUp() ) { if ( !m_currentSegment->IsEmpty() ) { // We've got a valid segment on mouse left up, so store it. DrawingDocument * const doc = wxStaticCast(m_view->GetDocument(), DrawingDocument); doc->GetCommandProcessor()->Submit( new DrawingAddSegmentCommand(doc, *m_currentSegment)); doc->Modify(true); } delete m_currentSegment; m_currentSegment = NULL; } // is this the start of a new segment? if ( m_lastMousePos != wxDefaultPosition && event.Dragging() ) { if ( !m_currentSegment ) m_currentSegment = new DoodleSegment; m_currentSegment->AddLine(m_lastMousePos, pt); dc.DrawLine(m_lastMousePos, pt); } m_lastMousePos = pt; }
void ProsodyDisplay::OnMouse(wxMouseEvent& event) {//============================================ int line; int ix; int xpos=0; wxClientDC dc(this); PrepareDC(dc); wxPoint pt(event.GetLogicalPosition(dc)); if(selected_ph >= 0) { // find line for previously selected phoneme for(line=0; line<num_lines; line++) if(linetab[line+1] > selected_ph) break; RefreshLine(line); selected_ph = -1; } line = pt.y / FRAMEHEIGHT; // find which phoneme is selected on this line for(ix=linetab[line]; (ix<linetab[line+1]) && (ix<numph); ix++) { xpos += GetWidth(&phlist[ix]); if(xpos > pt.x) { selected_ph = ix; SelectPh(selected_ph); break; } } RefreshLine(line); if(event.RightDown()) { PopupMenu(menu_prosody); } } // end of ProsodyDisplay::OnMouse
//------------------------------------------------------------------------- // OnMouseDown() //------------------------------------------------------------------------- void PlotSpectrum::OnMouseLeftDown(wxMouseEvent& event) { m_mouseDown = true; wxClientDC dc(this); wxPoint pt(event.GetLogicalPosition(dc)); // map x coord to edges of actual plot pt.x -= PLOT_BORDER + XLEFT_OFFSET; pt.y -= PLOT_BORDER; // valid click if inside of plot if ((pt.x >= 0) && (pt.x <= m_rGrid.GetWidth()) && (pt.y >=0) && m_clickTune) { float freq_hz_to_px = (float)m_rGrid.GetWidth()/(MAX_F_HZ-MIN_F_HZ); float clickFreq = (float)pt.x/freq_hz_to_px; // see PlotWaterfall::OnMouseDown() fdmdv2_clickTune(clickFreq); } }
void WorkingPanel::OnLeftDown(wxMouseEvent & e) { SetFocus(); wxPaintDC dc(this); wxPoint point = e.GetLogicalPosition(dc); if (point.x < x0+5 || point.y < y0+5) { return; } Cell tempCell; tempCell.row = (point.y - y0 - 5)/cellLen; tempCell.col = (point.x - x0 - 5)/cellLen; if (x0+5+tempCell.col*cellLen+tempCell.col+tempCell.col/3*2 > point.x) { --tempCell.col; } if (y0+5+tempCell.row*cellLen+tempCell.row+tempCell.row/3*2 > point.y) { --tempCell.row; } if (tempCell.row < SudokuBase::Row && tempCell.col < SudokuBase::Col) { focusCell = tempCell; } Paint(); }
// Lab 5 void MyFrame::OnLButton( wxMouseEvent& event) { wxClientDC dc(this); wxPoint area_pt(event.GetLogicalPosition(dc)); SetStatusText( wxString::Format("(%d,%d)", area_pt.x,area_pt.y), 0); if(!bAreaCalculation) return; if( pImage == NULL) { wxMessageBox("Image is not loaded yet!", _T("Error"), wxOK | wxICON_INFORMATION, this); return; } areaborder[areaindex].x= area_pt.x; areaborder[areaindex].y= area_pt.y+27; if (areaindex>0) dist = sqrt((pow((double)(area_pt.x-areaborder[0].x),2)+pow((double)(area_pt.y+27-areaborder[0].y),2))); SetStatusText( wxString::Format("(%d,%d,%d)", area_pt.x, area_pt.y, (int)dist), 1); areaindex++; Refresh(); }
bool EDA_DRAW_PANEL::OnRightClick( wxMouseEvent& event ) { wxPoint pos; wxMenu MasterMenu; INSTALL_UNBUFFERED_DC( dc, this ); pos = event.GetLogicalPosition( dc ); if( !GetParent()->OnRightClick( pos, &MasterMenu ) ) return false; GetParent()->AddMenuZoomAndGrid( &MasterMenu ); pos = event.GetPosition(); m_ignoreMouseEvents = true; PopupMenu( &MasterMenu, pos ); MoveCursorToCrossHair(); m_ignoreMouseEvents = false; return true; }
void CurvePane::mouseLeftDown(wxMouseEvent& event) { int m=10; int w, h; double x, y; mousemoved = false; mousemotion=true; int landingradius; wxConfigBase::Get()->Read("tool.curve.landingradius",&landingradius,5); wxClientDC dc(this); dc.GetSize(&w, &h); pos = event.GetLogicalPosition(dc); pos.x = pos.x-m; pos.y = h-m-pos.y; mouseCP.x = pos.x; mouseCP.y = pos.y; int pt = c.isctrlpoint(pos.x,pos.y,landingradius); if (pt != -1) { selectedCP = c.getctrlpoint(pt); paintNow(); return; } for (x=1.0; x<255.0; x++) { y = c.getpoint(x); if ((pos.x > x-landingradius) & (pos.x < x+landingradius)) { if ((pos.y > y-landingradius) & (pos.y < y+landingradius)) { c.insertpoint(x,y); selectedCP.x = x; selectedCP.y = y; paintNow(); return; } } } }
// TODO: this code require full information about editabel register in dialog // TODO: to make editable all registers which is output void RegRichTextCtrl::OnLeftDClick(wxMouseEvent& event) { wxClientDC dc(this); PrepareDC(dc); dc.SetFont(GetFont()); long position = 0; GetBuffer().HitTest(dc, event.GetLogicalPosition(dc), position); long linePos = GetBuffer().GetVisibleLineNumber(position, true, true); wxString line = GetLineText(linePos); const size_t szRegNames = 15; for (size_t i = 0; i < szRegNames; ++i) if (line.Find(RegistersName[i]) != wxNOT_FOUND) { wxString str = GetStringSelection(); bool bShowEditBox = true; for (size_t k = 0; k < szRegNames; ++k) { if ( 0 == str.Cmp(RegistersName[k]) ) { bShowEditBox = false; break; } } if (bShowEditBox) { EditRegister(RegistersName[i], str); break; } } }
void CollisionTypePanel::OnMouse(wxMouseEvent& event) { if(m_project) { //Get mouse position in map space wxClientDC clientDc(this); wxPoint mouseCanvasPosWx = event.GetLogicalPosition(clientDc); ion::Vector2 mousePosMapSpace(mouseCanvasPosWx.x, mouseCanvasPosWx.y); //Get panel size wxSize panelSize = GetClientSize(); const int maxCollisionTypesPerLayer = 16; float x = (m_orientation == eVertical) ? mousePosMapSpace.y : mousePosMapSpace.x; float y = (m_orientation == eVertical) ? mousePosMapSpace.x : mousePosMapSpace.y; float rectSize = (m_orientation == eVertical) ? (panelSize.y / maxCollisionTypesPerLayer) : (panelSize.x / maxCollisionTypesPerLayer); //Get current selection unsigned int collisionTypeIndex = (unsigned int)floor(x / rectSize); unsigned int collisionLayerId = (unsigned int)floor(y / rectSize); //TODO: Multiple layers const int numCollisionLayers = 1; int iconX = (m_orientation == eVertical) ? collisionTypeIndex : collisionLayerId; int iconY = (m_orientation == eVertical) ? collisionLayerId : collisionTypeIndex; wxRect rect(iconX * rectSize, iconY * rectSize, rectSize, rectSize); u32 collisionBit = 1 << collisionTypeIndex; if(collisionLayerId < numCollisionLayers && collisionTypeIndex < maxCollisionTypesPerLayer) { CollisionType* collisionType = m_project->GetCollisionType(collisionBit); if(event.LeftDClick()) { //Create new if(!collisionType) { collisionType = m_project->AddCollisionType(collisionBit); } //Set default image wxImage image(qmark_16_16_xpm); //Open image file wxFileDialog dialogue(this, _("Open Image file"), "", "", "BMP files (*.bmp)|*.bmp", wxFD_OPEN | wxFD_FILE_MUST_EXIST); if(dialogue.ShowModal() == wxID_OK) { if(image.LoadFile(dialogue.GetPath())) { if(image.GetWidth() != sIconWidth || image.GetHeight() != sIconHeight) { wxMessageBox("Image must be 16x16", "Error", wxOK | wxICON_ERROR); } } } //Set icon data const int bytesPerPixel = 3; int imageSize = sIconWidth * sIconHeight * bytesPerPixel; collisionType->iconData.resize(imageSize); unsigned char* imageData = image.GetData(); ion::memory::MemCopy(&collisionType->iconData[0], imageData, imageSize); //Create bitmap for rendering if(m_icons.size() < collisionTypeIndex + 1) m_icons.resize(collisionTypeIndex + 1); m_icons[collisionTypeIndex] = wxBitmap(image, wxBITMAP_SCREEN_DEPTH); //Recreate collision types texture m_mainWindow->RefreshCollisionTypes(); //Invalidate collision types m_project->InvalidateCollisionTypes(true); //Refresh this panel Refresh(); //Refresh collision tile editor panel m_mainWindow->RefreshPanel(MainWindow::ePanelTerrainTileEditor); } if(collisionTypeIndex < m_project->GetCollisionTypeCount()) { if(CollisionType* collisionType = m_project->GetCollisionType(1 << collisionTypeIndex)) { if(!m_tooltip.get()) { //m_tooltip = new wxTipWindow(this, "Test Tooltip", 100, NULL, &rect); //m_tooltip->Show(); } if(event.ButtonIsDown(wxMOUSE_BTN_LEFT)) { //Set current collision type m_project->SetPaintCollisionType(collisionType); } } } } } event.Skip(); }
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( kicadTraceCoords, 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; int axis = event.GetWheelAxis(); int wheelRotation = event.GetWheelRotation(); if( m_enableMousewheelPan ) { // MousewheelPAN + Ctrl = zooming if( event.ControlDown() && !event.ShiftDown() ) { if( wheelRotation > 0 ) cmd.SetId( ID_POPUP_ZOOM_IN ); else if( wheelRotation < 0) cmd.SetId( ID_POPUP_ZOOM_OUT ); } // MousewheelPAN + Shift = horizontal scrolling // Without modifiers MousewheelPAN - just pan else { if( event.ShiftDown() && !event.ControlDown() ) axis = wxMOUSE_WHEEL_HORIZONTAL; wxPoint newStart = GetViewStart(); wxPoint center = GetParent()->GetScrollCenterPosition(); double scale = GetParent()->GetScreen()->GetScalingFactor(); if( axis == wxMOUSE_WHEEL_HORIZONTAL ) { newStart.x += wheelRotation; center.x += KiROUND( (double) wheelRotation / scale ); } else { newStart.y -= wheelRotation; center.y -= KiROUND( (double) wheelRotation / scale ); } Scroll( newStart ); GetParent()->SetScrollCenterPosition( center ); GetParent()->SetCrossHairPosition( center, true ); GetParent()->RedrawScreen( center, false ); } } else if( wheelRotation > 0 ) { if( event.ShiftDown() && !event.ControlDown() ) cmd.SetId( ID_PAN_UP ); 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( wheelRotation < 0 ) { if( event.ShiftDown() && !event.ControlDown() ) cmd.SetId( ID_PAN_DOWN ); 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 ); } if( cmd.GetId() ) GetEventHandler()->ProcessEvent( cmd ); event.Skip(); }
void C3DPlotCanvas::OnMouse( wxMouseEvent& event ) { wxPoint pt(event.GetPosition()); wxClientDC dc(this); PrepareDC(dc); wxPoint point(event.GetLogicalPosition(dc)); if (event.RightDown()) { m_bRButton = true; int where[2]; where[0] = point.x; where[1] = point.y; last[0] = point.x; last[1] = point.y; ball->mouse_down(where,3); } if (event.RightUp()) { m_bRButton = false; int where[2]; where[0] = point.x; where[1] = point.y; ball->mouse_up(where,3); } if (event.LeftDown()) { if ((event.CmdDown()) && this->m_d && this->b_select) { m_brush = true; last[0] = point.x; last[1] = point.y; } else { m_bLButton = true; int where[2]; where[0] = point.x; where[1] = point.y; last[0] = point.x; last[1] = point.y; ball->mouse_down(where,1); } } if (event.LeftUp()) { if (bSelect && this->m_d ) { bSelect = false; SelectByRect(); } else if (m_brush) { m_brush = false; } else { m_bLButton = false; int where[2]; where[0] = point.x; where[1] = point.y; ball->mouse_up(where,1); } } if (event.Dragging()) { int where[2]; where[0] = point.x; where[1] = point.y; if (m_brush) { float vp[4]; glGetFloatv(GL_VIEWPORT, vp); float W=vp[2], H=vp[3]; float diam = 2*(ball->radius); ball->apply_transform(); int pix1[2], pix2[2], pix3[2]; pix1[0] = (int)(W/2); pix1[1] = (int)(H/2); pix2[0] = (int)(W/2-1); pix2[1] = (int)(H/2); pix3[0] = (int)(W/2); pix3[1] = (int)(H/2-1); double world1[3], world2[3],world3[3]; unproject_pixel(pix1, world1, 0.0); unproject_pixel(pix2, world2, 0.0); unproject_pixel(pix3, world3, 0.0); ball->unapply_transform(); Vec3f w1(world1); Vec3f w2(world2); Vec3f w3(world3); Vec3f screen_x = w1-w2; unitize(screen_x); Vec3f screen_y = w3-w1; unitize(screen_y); Vec3f XX(1,0,0); Vec3f YY(0,1,0); Vec3f ZZ(0,0,1); xp += diam * (where[0] - last[0]) / W *(XX*screen_x); yp += diam * (where[0] - last[0]) / W *(YY*screen_x); zp += diam * (where[0] - last[0]) / W *(ZZ*screen_x); xp += diam * (last[1] - where[1]) / H *(XX*screen_y); yp += diam * (last[1] - where[1]) / H *(YY*screen_y); zp += diam * (last[1] - where[1]) / H *(ZZ*screen_y); if (xp < -1.0) xp = -1.0; if (xp > 1.0) xp = 1.0; if (yp < -1.0) yp = -1.0; if (yp > 1.0) yp = 1.0; if (zp < -1.0) zp = -1.0; if (zp > 1.0) zp = 1.0; last[0] = where[0]; last[1] = where[1]; c3d_plot_frame->control->m_xp->SetValue((int)((xp+1)*10000)); c3d_plot_frame->control->m_yp->SetValue((int)((yp+1)*10000)); c3d_plot_frame->control->m_zp->SetValue((int)((zp+1)*10000)); this->UpdateSelect(); } else { bSelect = false; if (m_bLButton & m_bRButton) { ball->mouse_drag(where,last,2); last[0] = where[0]; last[1] = where[1]; } else if (m_bLButton) { ball->mouse_drag(where,last,1); last[0] = where[0]; last[1] = where[1]; } else if (m_bRButton) { ball->mouse_drag(where,last,3); last[0] = where[0]; last[1] = where[1]; } } } Refresh(); }
void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) { int localbutt = 0; BASE_SCREEN* screen = GetScreen(); if( !screen ) return; /* Adjust value to filter mouse displacement before consider the drag * mouse is really a drag command, not just a movement while click */ #define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND 5 if( event.Leaving() ) m_canStartBlock = -1; if( !IsMouseCaptured() ) // No mouse capture in progress. SetAutoPanRequest( false ); if( GetParent()->IsActive() ) SetFocus(); else return; if( !event.IsButton() && !event.Moving() && !event.Dragging() ) return; if( event.RightDown() ) { OnRightClick( event ); return; } if( m_ignoreMouseEvents ) return; if( event.LeftDown() ) localbutt = GR_M_LEFT_DOWN; if( event.ButtonDClick( 1 ) ) localbutt = GR_M_LEFT_DOWN | GR_M_DCLICK; if( event.MiddleDown() ) localbutt = GR_M_MIDDLE_DOWN; INSTALL_UNBUFFERED_DC( DC, this ); DC.SetBackground( *wxBLACK_BRUSH ); // Compute the cursor position in drawing (logical) units. GetParent()->SetMousePosition( event.GetLogicalPosition( DC ) ); int kbstat = 0; if( event.ShiftDown() ) kbstat |= GR_KB_SHIFT; if( event.ControlDown() ) kbstat |= GR_KB_CTRL; if( event.AltDown() ) kbstat |= GR_KB_ALT; // Calling Double Click and Click functions : if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) ) { if( m_ClickTimer ) { m_ClickTimer->Stop(); wxDELETE( m_ClickTimer ); } GetParent()->OnLeftDClick( &DC, GetParent()->RefPos( true ) ); // inhibit a response to the mouse left button release, // because we have a double click, and we do not want a new // OnLeftClick command at end of this Double Click m_ignoreNextLeftButtonRelease = true; } else if( event.LeftUp() ) { // A block command is in progress: a left up is the end of block // or this is the end of a double click, already seen // Note also m_ignoreNextLeftButtonRelease can be set by // the call to OnLeftClick(), so do not change it after calling OnLeftClick bool ignoreEvt = m_ignoreNextLeftButtonRelease; m_ignoreNextLeftButtonRelease = false; if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK && !ignoreEvt ) { EDA_ITEM* item = screen->GetCurItem(); m_CursorClickPos = GetParent()->RefPos( true ); // If we have an item already selected, or we are using a tool, // we won't use the disambiguation menu so process the click immediately if( ( item && item->GetFlags() ) || GetParent()->GetToolId() != ID_NO_TOOL_SELECTED ) GetParent()->OnLeftClick( &DC, m_CursorClickPos ); else { wxDELETE( m_ClickTimer ); m_ClickTimer = new wxTimer(this, ID_MOUSE_DOUBLECLICK); m_ClickTimer->StartOnce( m_doubleClickInterval ); } } } else if( !event.LeftIsDown() ) { /* be sure there is a response to a left button release command * even when a LeftUp event is not seen. This happens when a * double click opens a dialog box, and the release mouse button * is made when the dialog box is opened. */ m_ignoreNextLeftButtonRelease = false; } if( event.ButtonDown( wxMOUSE_BTN_MIDDLE ) ) { m_PanStartCenter = GetParent()->GetScrollCenterPosition(); m_PanStartEventPosition = event.GetPosition(); INSTALL_UNBUFFERED_DC( dc, this ); CrossHairOff( &dc ); SetCursor( wxCURSOR_SIZING ); } if( event.ButtonUp( wxMOUSE_BTN_MIDDLE ) ) { INSTALL_UNBUFFERED_DC( dc, this ); CrossHairOn( &dc ); SetCursor( (wxStockCursor) m_currentCursor ); } if( event.MiddleIsDown() ) { wxPoint currentPosition = event.GetPosition(); double scale = GetParent()->GetScreen()->GetScalingFactor(); int x = m_PanStartCenter.x + KiROUND( (double) ( m_PanStartEventPosition.x - currentPosition.x ) / scale ); int y = m_PanStartCenter.y + KiROUND( (double) ( m_PanStartEventPosition.y - currentPosition.y ) / scale ); GetParent()->RedrawScreen( wxPoint( x, y ), false ); } // Calling the general function on mouse changes (and pseudo key commands) GetParent()->GeneralControl( &DC, event.GetLogicalPosition( DC ), 0 ); /*******************************/ /* Control of block commands : */ /*******************************/ // Command block can't start if mouse is dragging a new panel static EDA_DRAW_PANEL* lastPanel; if( lastPanel != this ) { m_minDragEventCount = 0; m_canStartBlock = -1; } /* A new command block can start after a release buttons * and if the drag is enough * This is to avoid a false start block when a dialog box is dismissed, * or when changing panels in hierarchy navigation * or when clicking while and moving mouse */ if( !event.LeftIsDown() && !event.MiddleIsDown() ) { m_minDragEventCount = 0; m_canStartBlock = 0; /* Remember the last cursor position when a drag mouse starts * this is the last position ** before ** clicking a button * this is useful to start a block command from the point where the * mouse was clicked first * (a filter creates a delay for the real block command start, and * we must remember this point) */ m_CursorStartPos = GetParent()->GetCrossHairPosition(); } if( m_enableBlockCommands && !(localbutt & GR_M_DCLICK) ) { if( !screen->IsBlockActive() ) { screen->m_BlockLocate.SetOrigin( m_CursorStartPos ); } if( event.LeftDown() ) { if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE ) { SetAutoPanRequest( false ); GetParent()->HandleBlockPlace( &DC ); m_ignoreNextLeftButtonRelease = true; } } else if( ( m_canStartBlock >= 0 ) && event.LeftIsDown() && !IsMouseCaptured() ) { // Mouse is dragging: if no block in progress, start a block command. if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK ) { // Start a block command int cmd_type = kbstat; // A block command is started if the drag is enough. A small // drag is ignored (it is certainly a little mouse move when // clicking) not really a drag mouse if( m_minDragEventCount < MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND ) m_minDragEventCount++; else { auto cmd = (GetParent()->GetToolId() == ID_ZOOM_SELECTION) ? BLOCK_ZOOM : 0; if( !GetParent()->HandleBlockBegin( &DC, cmd_type, m_CursorStartPos, cmd ) ) { // should not occur: error GetParent()->DisplayToolMsg( wxT( "EDA_DRAW_PANEL::OnMouseEvent() Block Error" ) ); } else { SetAutoPanRequest( true ); SetCursor( wxCURSOR_SIZING ); } } } } if( event.ButtonUp( wxMOUSE_BTN_LEFT ) ) { /* Release the mouse button: end of block. * The command can finish (DELETE) or have a next command (MOVE, * COPY). However the block command is canceled if the block * size is small because a block command filtering is already * made, this case happens, but only when the on grid cursor has * not moved. */ #define BLOCK_MINSIZE_LIMIT 1 bool BlockIsSmall = ( std::abs( screen->m_BlockLocate.GetWidth() ) < BLOCK_MINSIZE_LIMIT ) && ( std::abs( screen->m_BlockLocate.GetHeight() ) < BLOCK_MINSIZE_LIMIT ); if( (screen->m_BlockLocate.GetState() != STATE_NO_BLOCK) && BlockIsSmall ) { if( m_endMouseCaptureCallback ) { m_endMouseCaptureCallback( this, &DC ); SetAutoPanRequest( false ); } SetCursor( (wxStockCursor) m_currentCursor ); } else if( screen->m_BlockLocate.GetState() == STATE_BLOCK_END ) { SetAutoPanRequest( false ); GetParent()->HandleBlockEnd( &DC ); SetCursor( (wxStockCursor) m_currentCursor ); if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE ) { SetAutoPanRequest( true ); SetCursor( wxCURSOR_HAND ); } } } } // End of block command on a double click // To avoid an unwanted block move command if the mouse is moved while double clicking if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) ) { if( !screen->IsBlockActive() && IsMouseCaptured() ) { m_endMouseCaptureCallback( this, &DC ); } } lastPanel = this; #ifdef __WXGTK3__ // Screen has to be updated on every operation, otherwise the cursor leaves a trail (when xor // operation is changed to copy) or is not updated at all. Refresh(); #endif }
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; int axis = event.GetWheelAxis(); // 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(); }
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 bmx_wxmouseevent_getlogicalposition(wxMouseEvent & event, MaxDC * dc, int * x, int * y) { wxPoint p(event.GetLogicalPosition(*dc->GetDC())); *x = p.x; *y = p.y; }
void wxShapeCanvas::OnMouseEvent(wxMouseEvent& event) { wxClientDC dc(this); PrepareDC(dc); 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(); // Check if we're within the tolerance for mouse movements. // If we're very close to the position we started dragging // from, this may not be an intentional drag at all. if (dragging) { int dx = abs(dc.LogicalToDeviceX((long) (x - m_firstDragX))); int dy = abs(dc.LogicalToDeviceY((long) (y - m_firstDragY))); if (m_checkTolerance && (dx <= GetDiagram()->GetMouseTolerance()) && (dy <= GetDiagram()->GetMouseTolerance())) { return; } else // If we've ignored the tolerance once, then ALWAYS ignore // tolerance in this drag, even if we come back within // the tolerance range. m_checkTolerance = false; } // Dragging - note that the effect of dragging is left entirely up // to the object, so no movement is done unless explicitly done by // object. if (dragging && m_draggedShape && m_dragState == StartDraggingLeft) { m_dragState = ContinueDraggingLeft; // If the object isn't m_draggable, transfer message to canvas if (m_draggedShape->Draggable()) m_draggedShape->GetEventHandler()->OnBeginDragLeft((double)x, (double)y, keys, m_draggedAttachment); else { m_draggedShape = NULL; OnBeginDragLeft((double)x, (double)y, keys); } m_oldDragX = x; m_oldDragY = y; } else if (dragging && m_draggedShape && m_dragState == ContinueDraggingLeft) { // Continue dragging m_draggedShape->GetEventHandler()->OnDragLeft(false, m_oldDragX, m_oldDragY, keys, m_draggedAttachment); m_draggedShape->GetEventHandler()->OnDragLeft(true, (double)x, (double)y, keys, m_draggedAttachment); m_oldDragX = x; m_oldDragY = y; } else if (event.LeftUp() && m_draggedShape && m_dragState == ContinueDraggingLeft) { m_dragState = NoDragging; m_checkTolerance = true; m_draggedShape->GetEventHandler()->OnDragLeft(false, m_oldDragX, m_oldDragY, keys, m_draggedAttachment); m_draggedShape->GetEventHandler()->OnEndDragLeft((double)x, (double)y, keys, m_draggedAttachment); m_draggedShape = NULL; } else if (dragging && m_draggedShape && m_dragState == StartDraggingRight) { m_dragState = ContinueDraggingRight; if (m_draggedShape->Draggable()) m_draggedShape->GetEventHandler()->OnBeginDragRight((double)x, (double)y, keys, m_draggedAttachment); else { m_draggedShape = NULL; OnBeginDragRight((double)x, (double)y, keys); } m_oldDragX = x; m_oldDragY = y; } else if (dragging && m_draggedShape && m_dragState == ContinueDraggingRight) { // Continue dragging m_draggedShape->GetEventHandler()->OnDragRight(false, m_oldDragX, m_oldDragY, keys, m_draggedAttachment); m_draggedShape->GetEventHandler()->OnDragRight(true, (double)x, (double)y, keys, m_draggedAttachment); m_oldDragX = x; m_oldDragY = y; } else if (event.RightUp() && m_draggedShape && m_dragState == ContinueDraggingRight) { m_dragState = NoDragging; m_checkTolerance = true; m_draggedShape->GetEventHandler()->OnDragRight(false, m_oldDragX, m_oldDragY, keys, m_draggedAttachment); m_draggedShape->GetEventHandler()->OnEndDragRight((double)x, (double)y, keys, m_draggedAttachment); m_draggedShape = NULL; } // All following events sent to canvas, not object else if (dragging && !m_draggedShape && m_dragState == StartDraggingLeft) { m_dragState = ContinueDraggingLeft; OnBeginDragLeft((double)x, (double)y, keys); m_oldDragX = x; m_oldDragY = y; } else if (dragging && !m_draggedShape && m_dragState == ContinueDraggingLeft) { // Continue dragging OnDragLeft(false, m_oldDragX, m_oldDragY, keys); OnDragLeft(true, (double)x, (double)y, keys); m_oldDragX = x; m_oldDragY = y; } else if (event.LeftUp() && !m_draggedShape && m_dragState == ContinueDraggingLeft) { m_dragState = NoDragging; m_checkTolerance = true; OnDragLeft(false, m_oldDragX, m_oldDragY, keys); OnEndDragLeft((double)x, (double)y, keys); m_draggedShape = NULL; } else if (dragging && !m_draggedShape && m_dragState == StartDraggingRight) { m_dragState = ContinueDraggingRight; OnBeginDragRight((double)x, (double)y, keys); m_oldDragX = x; m_oldDragY = y; } else if (dragging && !m_draggedShape && m_dragState == ContinueDraggingRight) { // Continue dragging OnDragRight(false, m_oldDragX, m_oldDragY, keys); OnDragRight(true, (double)x, (double)y, keys); m_oldDragX = x; m_oldDragY = y; } else if (event.RightUp() && !m_draggedShape && m_dragState == ContinueDraggingRight) { m_dragState = NoDragging; m_checkTolerance = true; OnDragRight(false, m_oldDragX, m_oldDragY, keys); OnEndDragRight((double)x, (double)y, keys); m_draggedShape = NULL; } // Non-dragging events else if (event.IsButton()) { m_checkTolerance = true; // Find the nearest object int attachment = 0; wxShape *nearest_object = FindShape(x, y, &attachment); if (nearest_object) // Object event { if (event.LeftDown()) { m_draggedShape = nearest_object; m_draggedAttachment = attachment; m_dragState = StartDraggingLeft; m_firstDragX = x; m_firstDragY = y; } else if (event.LeftUp()) { // N.B. Only register a click if the same object was // identified for down *and* up. if (nearest_object == m_draggedShape) nearest_object->GetEventHandler()->OnLeftClick((double)x, (double)y, keys, attachment); m_draggedShape = NULL; m_dragState = NoDragging; } else if (event.LeftDClick()) { nearest_object->GetEventHandler()->OnLeftDoubleClick((double)x, (double)y, keys, attachment); m_draggedShape = NULL; m_dragState = NoDragging; } else if (event.RightDown()) { m_draggedShape = nearest_object; m_draggedAttachment = attachment; m_dragState = StartDraggingRight; m_firstDragX = x; m_firstDragY = y; } else if (event.RightUp()) { if (nearest_object == m_draggedShape) nearest_object->GetEventHandler()->OnRightClick((double)x, (double)y, keys, attachment); m_draggedShape = NULL; m_dragState = NoDragging; } } else // Canvas event (no nearest object) { if (event.LeftDown()) { m_draggedShape = NULL; m_dragState = StartDraggingLeft; m_firstDragX = x; m_firstDragY = y; } else if (event.LeftUp()) { OnLeftClick((double)x, (double)y, keys); m_draggedShape = NULL; m_dragState = NoDragging; } else if (event.RightDown()) { m_draggedShape = NULL; m_dragState = StartDraggingRight; m_firstDragX = x; m_firstDragY = y; } else if (event.RightUp()) { OnRightClick((double)x, (double)y, keys); m_draggedShape = NULL; m_dragState = NoDragging; } } } }
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(); } }