void RectList::use() { if (INPUT->again(Qt::LeftButton)) { sf::IntRect rect = findRect(INPUT->getPixel() - VECTOR2I(LAYER->getPosition()), LAYER->getImage()); if (rect.width > 0) { layer = LAYER; findRectList(rect, LAYER->getImage()); } } }
bool UI_Widget::removeRect(UI_Rect* pRect) { XM_ASSERT(pRect); if(pRect == 0) { return false; } int nIndex = findRect(pRect); if(nIndex >= 0) { m_listRect.erase(nIndex); pRect->DelRef(); return true; } return false; }
/////////////////////////////////////////////////////////////////////////// // rects bool UI_Widget::addRect(UI_Rect* pRect) { XM_ASSERT(pRect); if(pRect == 0) { return false; } if(findRect(pRect) < 0) { pRect->setParentPos(m_vPos + m_vParentPos); m_listRect.push_back(pRect); pRect->AddRef(); return true; } return false; }
int PDFwin::handle(int event) { static bool mbMoveRect=false; static TRect mPushedRect; static Int2D mPushedCursor; switch(event) { /* Receiving Drag and Drop */ case FL_DND_ENTER: case FL_DND_RELEASE: case FL_DND_LEAVE: case FL_DND_DRAG: return 1; case FL_PASTE: { TString fn=Fl::event_text(); if(fn.length() && fn.right(4).toUpper()==".PDF") { load(fn); } else Msg::msgBox("Error! Unknown file format"); // If there is a callback registered, call it. // The callback must access Fl::event_text() to // get the string or file path(s) that was dropped. // Note that do_callback() is not called directly. // Instead it will be executed by the FLTK main-loop // once we have finished handling the DND event. // This allows caller to popup a window or change widget focus. //if(callback() && ((when() & FL_WHEN_RELEASE) || (when() & FL_WHEN_CHANGED))) // Fl::add_timeout(0.0, Fl_DND_Box::callback_deferred, (void*)this); return 1; } case FL_KEYUP: if(mModel) { if(Fl::event_key()==FL_Page_Down) { mCurrPage=(mCurrPage+1)%mModel->_pdfDoc->getNumPages(); pageChanged(); redraw(); } else if(Fl::event_key()==FL_Page_Up) { mCurrPage=(mCurrPage+mModel->_pdfDoc->getNumPages()-1)%mModel->_pdfDoc->getNumPages(); pageChanged(); redraw(); } else if(Fl::event_key()==FL_Delete) { if(mSelectedRect!=mRects.end()) { mRects.erase(mSelectedRect); mSelectedRect=mRects.end(); redraw(); } } } break; case FL_ENTER: return 1; case FL_LEAVE: cursor(FL_CURSOR_DEFAULT); return 1; case FL_MOVE: { if(mSelectedRect!=mRects.end() && mSelectedRect->corner(Int2D(Fl::event_x(), Fl::event_y()))) { cursor(FL_CURSOR_NWSE); return 1; } if(findRect(Fl::event_x(), Fl::event_y())==mRects.end()) cursor(FL_CURSOR_DEFAULT); else cursor(FL_CURSOR_MOVE); } return 1; case FL_PUSH: if(mModel && Fl::event_button() == FL_LEFT_MOUSE) { if(mSelectedRect!=mRects.end()) { int corner=mSelectedRect->corner(Int2D(Fl::event_x(), Fl::event_y())); if(corner) { if(corner==1) std::swap(mSelectedRect->p1, mSelectedRect->p2); cursor(FL_CURSOR_NWSE); return 1; } } std::list<SelectionRectangle>::iterator i =findRect(Fl::event_x(), Fl::event_y()); if(i!=mRects.end()) { // move selected rect mSelectedRect=i; redraw(); mbMoveRect=true; mPushedCursor.x=Fl::event_x(); mPushedCursor.y=Fl::event_y(); mPushedRect=*mSelectedRect; cursor(FL_CURSOR_MOVE); return 1; } mRects.push_back(SelectionRectangle()); mSelectedRect=mRects.end(); mSelectedRect--; if(selectedRect().handle(*this, "push")) { redraw(); cursor(FL_CURSOR_HAND); return 1; } } return 0; break; case FL_DRAG: { if(mbMoveRect) { cursor(FL_CURSOR_MOVE); mSelectedRect->p1= toDocCoord(mPushedRect.left+Fl::event_x()-mPushedCursor.x, mPushedRect.top+Fl::event_y()-mPushedCursor.y); mSelectedRect->p2= toDocCoord(mPushedRect.right+Fl::event_x()-mPushedCursor.x, mPushedRect.bottom+Fl::event_y()-mPushedCursor.y); mSelectedRect->updateScreenCoord(*this); redraw(); return 1; } if(selectedRect().handle(*this, "drag")) redraw(); cursor(FL_CURSOR_HAND); return 1; } break; case FL_RELEASE: { mbMoveRect=false; if(mRects.size()) { if(selectedRect().isValid()) { if(selectedRect().p1.x> selectedRect().p2.x) std::swap(selectedRect().p1.x, selectedRect().p2.x); if(selectedRect().p1.y> selectedRect().p2.y) std::swap(selectedRect().p1.y, selectedRect().p2.y); } else { mRects.erase(mSelectedRect); mSelectedRect=mRects.end(); redraw(); } } return 1; } break; } return Fl_Double_Window::handle(event); }
private: Q_DECLARE_PUBLIC(MapRTree) Q_DISABLE_COPY(MapRTreePrivate) }; // ------------------------------------------------------- MapRTreePrivate::MapRTreePrivate() : root(NULL), cache(QMap<MapObject*, Node*>()), allNodes(QList<Node*>()), locked(false) { } Node *MapRTreePrivate::findObj(MapObject *obj) { foreach (Node *n, findRect(obj->drawer()->boundRect(obj))) { if (n->objects.contains(obj)) return n; } return NULL; } Node *MapRTreePrivate::chooseLeaf(const QRectF &r) { adjustBounds(root, r); QStack<Node*> stack; stack.append(root); while (!stack.isEmpty()) { Node* leaf = stack.pop(); if (leaf->nodes.isEmpty()) return leaf;