void FieldView::SelectTile(const BPoint &pt) { BRect r(gGameStyle->TileSize()); IntPoint oldSelection(fSelection.x,fSelection.y); fSelection.x = uint16(pt.x / (r.Width() + 1.0)); fSelection.y = uint16(pt.y / (r.Height() + 1.0)); Invalidate(gGameStyle->TileRect(oldSelection.x,oldSelection.y)); Invalidate(gGameStyle->TileRect(fSelection.x,fSelection.y)); Window()->UpdateIfNeeded(); }
bool wxJigsawEditorCanvas::AutoScroll(const wxPoint & currentPos, const wxPoint & scrollPos) { bool res = false; // If mouse is captured set rect coords if inside the image and autoscroll if posible // get image display rectangle wxRect displayRect = GetDisplayRect(scrollPos); wxSize oldSelection(m_TR.x-m_BL.x, m_TR.y-m_BL.y); // check if the current drag position is inside the image - do not allow to draw rectangle out of the image m_TR.x = wxMin(wxMax(currentPos.x, displayRect.GetLeft()), displayRect.GetRight()); m_TR.y = wxMin(wxMax(currentPos.y, displayRect.GetTop()), displayRect.GetBottom()); // Check current drag position and update scroll regularly if(currentPos.x <= 0) { Scroll(wxPoint(wxMax(scrollPos.x - wxJigsawEditorCanvas::ScrollIncrement, 0), -1)); m_BL.x += (scrollPos.x - GetScrollPosition().x); res = true; } if(currentPos.y <= 0) { Scroll(wxPoint(-1,wxMax(scrollPos.y - wxJigsawEditorCanvas::ScrollIncrement, 0))); m_BL.y += (scrollPos.y - GetScrollPosition().y); res = true; } if(currentPos.x >= GetClientSize().GetWidth()) { Scroll(wxPoint(scrollPos.x + wxJigsawEditorCanvas::ScrollIncrement, -1)); m_BL.x -= (GetScrollPosition().x - scrollPos.x); res = true; } if(currentPos.y >= GetClientSize().y) { Scroll(wxPoint(-1, scrollPos.y + wxJigsawEditorCanvas::ScrollIncrement)); m_BL.y -= (GetScrollPosition().y - scrollPos.y); res = true; } m_SelectionRect = wxRect(wxMin(m_TR.x, m_BL.x), wxMin(m_TR.y, m_BL.y), abs(m_TR.x-m_BL.x), abs(m_TR.y-m_BL.y)); if(HasCapture()) { if(m_View && m_View->GetSelectedObject() && (m_Mode == wxJSEC_MODE_DRAGGING)) { /*wxSize offset(m_TR.x-m_BL.x-oldSelection.GetWidth(), m_TR.y-m_BL.y-oldSelection.GetHeight());*/ wxPoint cursorPosOnDiagram = currentPos; cursorPosOnDiagram.x /= m_View->GetScale(); cursorPosOnDiagram.y /= m_View->GetScale(); cursorPosOnDiagram.x -= m_View->GetViewOffset().x; cursorPosOnDiagram.y -= m_View->GetViewOffset().y; m_SelectedObjectOffset.x /= m_View->GetScale(); m_SelectedObjectOffset.y /= m_View->GetScale(); m_View->GetSelectedObject()->Drag(m_DoubleBufferDC, cursorPosOnDiagram, m_SelectedObjectOffset, m_View->GetScale()); GetDocument()->Modify(true); AdjustScrollBars(); } } return res; }