cocos2d::Rect placeRectToRect(const cocos2d::Rect& placedRect, const cocos2d::Rect& placeToRect) { cocos2d::Rect result = placedRect; bool bCanBePlacedInside = isRectCanBePlacesInsideRect(placedRect, placeToRect); if (true == bCanBePlacedInside) { auto rectInsideResult = isRectInsideRect(placedRect, placeToRect); if (false == rectInsideResult.bResult) { result.origin = placedRect.origin; if (false == rectInsideResult.bMinX || false == rectInsideResult.bMinY) { Vec2 movePoint(placedRect.getMinX(), placedRect.getMinY()); movePoint = placePointToRect(movePoint, placeToRect) - movePoint; result.origin += movePoint; result = placeRectToRect(result, placeToRect); } else if (false == rectInsideResult.bMaxX || false == rectInsideResult.bMaxY) { Vec2 movePoint(placedRect.getMaxX(), placedRect.getMaxY()); movePoint = placePointToRect(movePoint, placeToRect) - movePoint; result.origin += movePoint; result = placeRectToRect(result, placeToRect); } } } return result; }
void Record::mouseMoveEvent(QMouseEvent *event) { if(event->buttons() & Qt::LeftButton) { if (event->pos().y() > 50){ QPoint movePoint(this->x(), this->y() + 50); m_RowPosition++; if (movePoint.y() < 0 || (movePoint.y() + this->height()) > parentWidget()->height()) return; this->move(movePoint); } else if (event->pos().y() < 0) { QPoint movePoint(this->x(), this->y() - 50); m_RowPosition--; if (movePoint.y() < 0 || (movePoint.y() + this->height()) > parentWidget()->height()) return; this->move(movePoint); } else { QPoint movePoint(this->x() + (event->pos().x() - dragMouseOffsetX), this->y()); if (movePoint.x() < 0 || (movePoint.x() + this->width()) > parentWidget()->width()) return; this->move(movePoint); m_StartTime = this->x() * 100; m_EndTime = (m_StartTime + m_Duration); onMouseMove(m_Id, m_StartTime, m_EndTime, m_Name); } } event->ignore(); }
void RulerGesture::mouseMoveEvent(QMouseEvent* m) { movePoint(m, false); m->accept(); if (m_ScMW->doc->guidesSettings.guidesShown) emit guideInfo(m_mode, m_currentGuide); }
void XScrollArea::layoutVScrollBar(int hValue) { QPoint movePoint(width() - verticalScrollBar()->height(),0); LOG_VAR(movePoint); verticalScrollBar()->move(QPoint(0,0)); }
void NurbsCurveSP<T,N>::modOnlySurfCPby(int i, const HPoint_nD<T,N>& a) { Vector<T> u(2*deg_+3) ; Vector< Point_nD<T,N> > pts(2*deg_+3) ; int n=0; for(int j=i-deg_-1; j<=i+deg_+1; ++j) { if(j<0) continue ; if(j>=P.n()) break ; u[n] = maxAt_[j] ; if( j == i) { pts[n].x() = a.x() ; pts[n].y() = a.y() ; pts[n].z() = a.z() ; } //else // pts[n] = Point3D(0,0,0) ; pts is alredy set to 0,0,0 ++n ; } u.resize(n) ; pts.resize(n) ; movePoint(u,pts) ; }
void NurbsSurfaceSP<T,N>::modOnlySurfCPby(int i, int j, const HPoint_nD<T,N>& a){ int sizeU, sizeV ; sizeU = 2*this->degU+3 ; if(i-this->degU-1<0) sizeU += i-this->degU-1 ; if(i+this->degU+1>=this->P.rows()) sizeU -= i+this->degU+1-this->P.rows() ; sizeV = 2*this->degV+3 ; if(j-this->degV-1<0) sizeV += j-this->degV-1 ; if(j+this->degV+1>=this->P.cols()) sizeV -= j+this->degV+1-this->P.cols() ; Vector<T> u(sizeU) ; Vector<T> v(sizeV) ; Vector<Point_nD<T,N> > pts(sizeU*sizeV) ; Vector<int> pu(sizeU*sizeV) ; Vector<int> pv(sizeU*sizeV) ; int n=0; int nu = 0 ; int nv = 0 ; for(int k=i-this->degU-1;k<=i+this->degU+1;++k){ if(k<0) continue ; if(k>=this->P.rows()) break ; nv = 0 ; for(int l=j-this->degV-1;l<=j+this->degV+1;++l){ if(l<0) continue ; if(l>=this->P.cols()) break ; if( k == i && j==l){ pts[n].x() = a.x() ; pts[n].y() = a.y() ; pts[n].z() = a.z() ; } //else //pts[n] = Point3D(0,0,0) ; pu[n] = nu ; pv[n] = nv ; if(k==i){ v[nv] = maxAtV_[l] ; // only need to initialise this once } ++n ; ++nv ; } u[nu] = maxAtU_[k] ; ++nu ; } u.resize(nu) ; v.resize(nv) ; pts.resize(n) ; pu.resize(n) ; pv.resize(n) ; movePoint(u,v,pts,pu,pv) ; }
void RulerGesture::mouseMoveEvent(QMouseEvent* m) { m_mousePoint=m_canvas->globalToCanvas(m->globalPos()); m->accept(); if (m_view->moveTimerElapsed()) { movePoint(m, false); if (m_ScMW->doc->guidesPrefs().guidesShown) emit guideInfo(m_mode, m_currentGuide); } }
void MapEditorWidget::updatePointFromPopup(){ // MapEditorPopup * popup = qobject_cast<MapEditorPopup *>(sender()); if(popup){ QPointF p = QPointF(popup->xEdit->text().toDouble(), popup->yEdit->text().toDouble()); movePoint(popup->index, p); updateTransform(); firePointChange(); popup->close(); popup = NULL; }else{ qDebug("Tried to update non existing popup"); } }
void RulerGesture::mouseReleaseEvent(QMouseEvent* m) { movePoint(m, true); if (m_mode == ORIGIN) m_view->setNewRulerOrigin(m); else { if (m_ScMW->doc->guidesSettings.guidesShown) m_ScMW->guidePalette->setupPage(); } m_haveGuide = false; m->accept(); m_canvas->repaint(); m_view->stopGesture(); if (m_ScMW->doc->guidesSettings.guidesShown) emit guideInfo(m_mode, m_currentGuide); }
int main() { Point *p1; Point *p2; char temp1[15]; p1 = createPoint (10, 12); p2 = createPoint (-5, 12); movePoint (p1, 10, 3); dilatePoint (p2, 2); printf ("Point 1: %s\n", pointToString (p1, temp1)); printf ("Point 2: %s\n", pointToString (p2, temp1)); free (p1); free (p2); }
void Contour::passDownLeft(const Image& src, ImageMap& split, Point& p) { while (src.isInside(p)) { int i = size(); int m = Polyline.size(); if((size()- endpoint) > ((Polyline.size()-endpoint_PolyLine)<<4)) checkContourPointInSardelka(src,p, endpoint, endpoint_PolyLine); commitPoint(p, src, split); // (1) step one point down p = movePoint(p, 0, 1); // (2) select one of neighbors which is filled, prefer left one... Point left = movePoint(p, -1, 0); if (src.isFilled(left)) { p = commitPoint(left, src, split); // ...and shift left as many as possible while (src.isInside(p)) { Point left = movePoint(p, -1, 0); if (!src.isFilled(left)) break; // no more left neighbors p = commitPoint(left, src, split); Point up = movePoint(p, 0, -1); if (src.isFilled(up)) return; // crossed inside area } } else { // selection still unfilled... while (src.isInside(p) && src.getPixel(p).isBackground()) { // ...shift right by connected points and test again Point right = movePoint(p, 1,0); Point rightUp = movePoint(right, 0,-1); if (!src.isFilled(rightUp)) return; // no more bottom right neighbors commitPoint(rightUp, src, split); p = commitPoint(right, src, split); } } } }
SGTransformManipIntersector::type SGTransformManipIntersector::getIntersectType() { MPoint movePoint(SGMouse::x, SGMouse::y); MIntArray selIndices = SGSelection::getIndices(SGSelection::sels.getSelVtxIndicesMap()); if (!selIndices.length()) return SGTransformManipIntersector::kNone; MMatrix camMatrix = SGMatrix::getCamMatrix(); MPoint centerViewPoint = SGMatrix::getViewPointFromWorld(center, camMatrix); if (fabs(centerViewPoint.x - SGMouse::x) < centerSize + catchDist/2 && fabs(centerViewPoint.y - SGMouse::y) < centerSize + catchDist / 2 ) return SGTransformManipIntersector::kCenter; MPointArray lineX, lineY, lineZ; double manipSize = SGMatrix::getManipSizeFromWorldPoint(center, camMatrix); lineX.setLength(2); lineY.setLength(2); lineZ.setLength(2); lineX[0] = center; lineX[1] = center + axisX.normal() * axisSize / manipSize; lineY[0] = center; lineY[1] = center + axisY.normal() * axisSize / manipSize; lineZ[0] = center; lineZ[1] = center + axisZ.normal() * axisSize / manipSize; if( catchDist > SGIntersectFunction::getLineIntersectDist(movePoint, lineX, camMatrix) || catchDist > SGIntersectFunction::getShapeIntersectDist(cone.shape, coneXMatrix, camMatrix)) { return SGTransformManipIntersector::kX; } if (catchDist > SGIntersectFunction::getLineIntersectDist(movePoint, lineY, camMatrix) || catchDist > SGIntersectFunction::getShapeIntersectDist(cone.shape, coneYMatrix, camMatrix)) { return SGTransformManipIntersector::kY; } if (catchDist > SGIntersectFunction::getLineIntersectDist(movePoint, lineZ, camMatrix) || catchDist > SGIntersectFunction::getShapeIntersectDist(cone.shape, coneZMatrix, camMatrix)) { return SGTransformManipIntersector::kZ; } return SGTransformManipIntersector::kNone; }
void RulerGesture::mouseReleaseEvent(QMouseEvent* m) { m->accept(); if (m_view->moveTimerElapsed()) { movePoint(m, true); if (m_mode == ORIGIN) m_view->setNewRulerOrigin(m); else { if (m_ScMW->doc->guidesPrefs().guidesShown) m_ScMW->guidePalette->setupPage(); } } m_haveGuide = false; //#9391: Force redraw to get the guide drawn if we draw a guide in an edit mode if (m_ScMW->doc->appMode != modeNormal) m_canvas->setForcedRedraw(true); m_canvas->repaint(); m_view->stopGesture(); m_mousePoint=QPoint(0,0); if (m_ScMW->doc->guidesPrefs().guidesShown) emit guideInfo(m_mode, m_currentGuide); }
bool HoverPoints::eventFilter(QObject *object, QEvent *event) { if (object == m_widget && m_enabled) { switch (event->type()) { case QEvent::MouseButtonPress: { QMouseEvent *me = (QMouseEvent *) event; QPointF clickPos = me->pos(); int index = -1; for (int i = 0; i < m_points.size(); ++i) { QPainterPath path; if (m_shape == CircleShape) { path.addEllipse(pointBoundingRect(i)); } else { if (m_shape == RectangleShape) { path.addRect(pointBoundingRect(i)); } } if (path.contains(clickPos)) { index = i; break; } } if (me->button() == Qt::LeftButton) { if (index == -1) { if (!m_editable) { return false; } int pos = 0; // Insert sort for x or y if (m_sortType == XSort) { for (int i = 0; i < m_points.size(); ++i) { if (m_points.at(i).x() > clickPos.x()) { pos = i; break; } } } else if (m_sortType == YSort) { for (int i = 0; i < m_points.size(); ++i) { if (m_points.at(i).y() > clickPos.y()) { pos = i; break; } } } m_points.insert(pos, clickPos); m_locks.insert(pos, 0); m_currentIndex = pos; firePointChange(); } else { m_currentIndex = index; } return true; } else if (me->button() == Qt::RightButton) { if (index >= 0 && m_editable) { if (m_locks[index] == 0) { m_locks.remove(index); m_points.remove(index); } firePointChange(); return true; } } } break; case QEvent::MouseButtonRelease: m_currentIndex = -1; break; case QEvent::MouseMove: if (m_currentIndex >= 0) { movePoint(m_currentIndex, ((QMouseEvent *)event)->pos()); } break; case QEvent::Resize: { if (m_widget->isVisible()) { QResizeEvent *e = (QResizeEvent *) event; double stretch_x = e->size().width() / double(e->oldSize().width()); double stretch_y = e->size().height() / double(e->oldSize().height()); for (int i = 0; i < m_points.size(); ++i) { QPointF p = m_points[i]; movePoint(i, QPointF(p.x() * stretch_x, p.y() * stretch_y), false); } firePointChange(); m_width = e->size().width(); m_height = e->size().height(); } break; } case QEvent::Show: { if (m_width != m_widget->width() || m_height != m_widget->height()) { if (m_width == -1 && m_height == -1) { m_width = m_widget->width(); m_height = m_widget->height(); } double stretch_x = m_widget->width() / double(m_width); double stretch_y = m_widget->height() / double(m_height); for (int i = 0; i < m_points.size(); ++i) { QPointF p = m_points[i]; movePoint(i, QPointF(p.x() * stretch_x, p.y() * stretch_y), false); } firePointChange(); m_width = m_widget->width(); m_height = m_widget->height(); } break; } case QEvent::Paint: { QWidget *that_widget = m_widget; m_widget = 0; QApplication::sendEvent(object, event); m_widget = that_widget; paintPoints(); return true; } default: break; } } return false; }
void MapEditorWidget::mouseMoveEvent(QMouseEvent * event){ if (currentIndex >= 0) movePoint(currentIndex, transform.inverted().map(QPointF(event->pos()))); }
void moveCircle( Circle& c, const Vector2D& v ) noexcept { movePoint( c.center, v ); }
bool HoverPoints::eventFilter(QObject *object, QEvent *event) { if (object == m_widget && m_enabled) { switch (event->type()) { case QEvent::MouseButtonPress: { if (!m_fingerPointMapping.isEmpty()) return true; QMouseEvent *me = (QMouseEvent *) event; QPointF clickPos = me->pos(); int index = -1; for (int i=0; i<m_points.size(); ++i) { QPainterPath path; if (m_shape == CircleShape) path.addEllipse(pointBoundingRect(i)); else path.addRect(pointBoundingRect(i)); if (path.contains(clickPos)) { index = i; break; } } if (me->button() == Qt::LeftButton) { if (index == -1) { if (!m_editable) return false; int pos = 0; // Insert sort for x or y if (m_sortType == XSort) { for (int i=0; i<m_points.size(); ++i) if (m_points.at(i).x() > clickPos.x()) { pos = i; break; } } else if (m_sortType == YSort) { for (int i=0; i<m_points.size(); ++i) if (m_points.at(i).y() > clickPos.y()) { pos = i; break; } } m_points.insert(pos, clickPos); m_locks.insert(pos, 0); m_currentIndex = pos; firePointChange(); } else { m_currentIndex = index; } return true; } else if (me->button() == Qt::RightButton) { if (index >= 0 && m_editable) { if ((m_points.size() - 1) < m_minCountPoints) return true; if (m_locks[index] == 0) { m_locks.remove(index); m_points.remove(index); } firePointChange(); return true; } } } break; case QEvent::MouseButtonRelease: if (!m_fingerPointMapping.isEmpty()) return true; m_currentIndex = -1; break; case QEvent::MouseMove: if (!m_fingerPointMapping.isEmpty()) return true; if (m_currentIndex >= 0) movePoint(m_currentIndex, ((QMouseEvent *)event)->pos()); break; case QEvent::TouchBegin: case QEvent::TouchUpdate: { const QTouchEvent *const touchEvent = static_cast<const QTouchEvent*>(event); const QList<QTouchEvent::TouchPoint> points = touchEvent->touchPoints(); const qreal pointSize = qMax(m_pointSize.width(), m_pointSize.height()); Q_FOREACH (const QTouchEvent::TouchPoint &touchPoint, points) { const int id = touchPoint.id(); switch (touchPoint.state()) { case Qt::TouchPointPressed: { // find the point, move it QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values()); int activePoint = -1; qreal distance = -1; const int pointsCount = m_points.size(); const int activePointCount = activePoints.size(); if (pointsCount == 2 && activePointCount == 1) { // only two points activePoint = activePoints.contains(0) ? 1 : 0; } else { for (int i=0; i<pointsCount; ++i) { if (activePoints.contains(i)) continue; qreal d = QLineF(touchPoint.pos(), m_points.at(i)).length(); if ((distance < 0 && d < 12 * pointSize) || d < distance) { distance = d; activePoint = i; } } } if (activePoint != -1) { m_fingerPointMapping.insert(touchPoint.id(), activePoint); movePoint(activePoint, touchPoint.pos()); } } break; case Qt::TouchPointReleased: { // move the point and release QHash<int,int>::iterator it = m_fingerPointMapping.find(id); movePoint(it.value(), touchPoint.pos()); m_fingerPointMapping.erase(it); } break; case Qt::TouchPointMoved: { // move the point const int pointIdx = m_fingerPointMapping.value(id, -1); if (pointIdx >= 0) // do we track this point? movePoint(pointIdx, touchPoint.pos()); } break; default: break; } } if (m_fingerPointMapping.isEmpty()) { event->ignore(); return false; } else { return true; } } break; case QEvent::TouchEnd: if (m_fingerPointMapping.isEmpty()) { event->ignore(); return false; } return true; break; case QEvent::Resize: { QResizeEvent *e = (QResizeEvent *) event; if (e->oldSize().width() == 0 || e->oldSize().height() == 0) break; qreal stretch_x = e->size().width() / qreal(e->oldSize().width()); qreal stretch_y = e->size().height() / qreal(e->oldSize().height()); for (int i=0; i<m_points.size(); ++i) { QPointF p = m_points[i]; movePoint(i, QPointF(p.x() * stretch_x, p.y() * stretch_y), false); } firePointChange(); break; } case QEvent::Paint: { QWidget *that_widget = m_widget; m_widget = 0; QApplication::sendEvent(object, event); m_widget = that_widget; paintPoints(); return true; } default: break; } } return false; }
bool HoverPoints::eventFilter(QObject *object, QEvent *event) { if (object == m_widget && m_enabled) { switch (event->type()) { case QEvent::MouseButtonPress: { QMouseEvent *me = (QMouseEvent *) event; QPointF clickPos = me->pos(); int index = -1; for (int i=0; i<m_points.size(); ++i) { QPainterPath path; if (m_shape == CircleShape) path.addEllipse(pointBoundingRect(i)); else path.addRect(pointBoundingRect(i)); if (path.contains(clickPos)) { index = i; break; } } if (me->button() == Qt::LeftButton) { if (index == -1) { if (!m_editable) return false; int pos = 0; // Insert sort for x or y if (m_sortType == XSort) { for (int i=0; i<m_points.size(); ++i) if (m_points.at(i).x() > clickPos.x()) { pos = i; break; } } else if (m_sortType == YSort) { for (int i=0; i<m_points.size(); ++i) if (m_points.at(i).y() > clickPos.y()) { pos = i; break; } } m_points.insert(pos, clickPos); m_locks.insert(pos, 0); m_currentIndex = pos; firePointChange(); } else { m_currentIndex = index; } return true; } else if (me->button() == Qt::RightButton) { if (index >= 0 && m_editable) { if (m_locks[index] == 0) { m_locks.remove(index); m_points.remove(index); } firePointChange(); return true; } } } break; case QEvent::MouseButtonRelease: m_currentIndex = -1; break; case QEvent::MouseMove: if (m_currentIndex >= 0) movePoint(m_currentIndex, ((QMouseEvent *)event)->pos()); break; case QEvent::Resize: { QResizeEvent *e = (QResizeEvent *) event; if (e->oldSize().width() == 0 || e->oldSize().height() == 0) break; qreal stretch_x = e->size().width() / qreal(e->oldSize().width()); qreal stretch_y = e->size().height() / qreal(e->oldSize().height()); for (int i=0; i<m_points.size(); ++i) { QPointF p = m_points[i]; movePoint(i, QPointF(p.x() * stretch_x, p.y() * stretch_y), false); } firePointChange(); break; } case QEvent::Paint: { QWidget *that_widget = m_widget; m_widget = 0; QApplication::sendEvent(object, event); m_widget = that_widget; paintPoints(); #ifdef QT_OPENGL_SUPPORT ArthurFrame *af = qobject_cast<ArthurFrame *>(that_widget); if (af && af->usesOpenGL()) af->glWidget()->swapBuffers(); #endif return true; } default: break; } } return false; }