bool Room::Overlaps(Room* r1) { int x1 = x; int x2 = x + width; int y1 = y; int y2 = y + height; int r1x1 = r1->x; int r1x2 = r1->x + width; int r1y1 = r1->y; int r1y2 = r1->y + height; // Check to see if any of the points of r1 overlap this room if(ContainsPoint(r1x1, r1y1)) { return true; } else if(ContainsPoint(r1x1, r1y2)) { return true; } else if(ContainsPoint(r1x2, r1y2)) { return true; } else if(ContainsPoint(r1x2, r1y1)) { return true; } // Now checking the other way -- in case this room is contained in r1 if(r1->ContainsPoint(x1, y1)) { return true; } else if(r1->ContainsPoint(x1, y2)) { return true; } else if(r1->ContainsPoint(x2, y2)) { return true; } else if(r1->ContainsPoint(x2, y1)) { return true; } return false; }
TEST(MAIN, RangeExpand){ Range one(V3f(0,0,0), V3f(1,1,1)); //start const V3f pnt(100, -100, -100); const V3f out(100.1, -100.1, -100.1); const V3f in(99.9, -99.9, -99.9); Range expanded( (ExpandRange(one, pnt)) ); EXPECT_TRUE(ContainsPoint(expanded, pnt)); EXPECT_FALSE(ContainsPoint(expanded, out)); EXPECT_TRUE(ContainsPoint(expanded, in)); };
void CN_VISITOR::checkZoneItemConnection( CN_ZONE* aZone, CN_ITEM* aItem ) { auto zoneItem = static_cast<CN_ZONE*> ( aZone ); if( zoneItem->Net() != aItem->Net() && !aItem->CanChangeNet() ) return; if( zoneItem->ContainsPoint( aItem->GetAnchor( 0 ) ) || ( aItem->Parent()->Type() == PCB_TRACE_T && zoneItem->ContainsPoint( aItem->GetAnchor( 1 ) ) ) ) { zoneItem->Connect( aItem ); aItem->Connect( zoneItem ); } }
//-------------------------------------------------------------------------------------- bool Button::HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam ) { if( !m_bEnabled || !m_bVisible ) return false; switch( uMsg ) { case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: { if( ContainsPoint( pt ) ) { // Pressed while inside the control m_bPressed = true; SetCapture( m_hWnd ); if( !m_bHasFocus ) m_pDialog->RequestFocus( this ); return true; } break; } case WM_LBUTTONUP: { if( m_bPressed ) { m_bPressed = false; ReleaseCapture(); if( !m_pDialog->m_bKeyboardInput ) m_pDialog->ClearFocus(); // Button click if( ContainsPoint( pt ) ) m_pDialog->SendEvent( EVENT_BUTTON_CLICKED, true, this ); return true; } break; } }; return false; }
void drawXFormPixelWithAlpha(const uint32_t i, const uint32_t j, const GRect &srcRect, const GIRect &dstRect, const GBitmap &src, const GBitmap &dst, const uint8_t alpha, const BlendFunc blend = blend_srcover) { GVec3f ctxPt(static_cast<float>(dstRect.fLeft + i) + 0.5f, static_cast<float>(dstRect.fTop + j) + 0.5f, 1.0f); ctxPt = m_CTMInv * ctxPt; if(ContainsPoint(srcRect, ctxPt[0], ctxPt[1])) { uint32_t x = static_cast<uint32_t>(ctxPt[0] - srcRect.fLeft); uint32_t y = static_cast<uint32_t>(ctxPt[1] - srcRect.fTop); GPixel *srcRow = GetRow(src, y); GPixel *dstRow = GetRow(dst, j+dstRect.fTop) + dstRect.fLeft; uint32_t srcA = fixed_multiply(GPixel_GetA(srcRow[x]), alpha); uint32_t srcR = fixed_multiply(GPixel_GetR(srcRow[x]), alpha); uint32_t srcG = fixed_multiply(GPixel_GetG(srcRow[x]), alpha); uint32_t srcB = fixed_multiply(GPixel_GetB(srcRow[x]), alpha); GPixel src = GPixel_PackARGB(srcA, srcR, srcG, srcB); dstRow[i] = blend(dstRow[i], src); } }
// Initialize the OpenGL internals //-------------------------------------------------------------------------------- CPUTEventHandledCode CPUTButton::OnMouseEvent(int x, int y, int wheel, CPUTMouseState state) { CPUTEventHandledCode handledCode = CPUT_EVENT_UNHANDLED; if(ContainsPoint(x,y)) { if(state & CPUT_MOUSE_LEFT_DOWN) { m_bButtonDown = true; // clicked - trigger the user's callback m_pCallbackHandler->OnCallbackEvent(1, m_controlID, (CPUTControl*) this); } m_bMouseInside = true; handledCode = CPUT_EVENT_HANDLED; } else { m_bMouseInside = false; } if(!(state & CPUT_MOUSE_LEFT_DOWN)) { m_bButtonDown = false; } return handledCode; }
void CUIDisplayWorld::OnMButtonDown(POINT point) { if(ContainsPoint(point) == true) { SetPressed(true); // ---- m_ptLastMousePosition = point; } }
// Handle mouse events //-------------------------------------------------------------------------------- CPUTEventHandledCode CPUTButton::HandleMouseEvent(int x, int y, int wheel, CPUTMouseState state, CPUTEventID message) { UNREFERENCED_PARAMETER(wheel); CPUTEventHandledCode handledCode = CPUT_EVENT_UNHANDLED; if((CPUT_CONTROL_INACTIVE == mControlState) || (false == mControlVisible) ) { return handledCode; } // if we're continuing to be pressed, move around with the mouse movement if( (CPUT_BUTTON_PRESSED == mButtonState ) && (CPUT_MOUSE_LEFT_DOWN == state)) { return CPUT_EVENT_HANDLED; } if(ContainsPoint(x,y)) { // did we start our click inside the button? if((message == CPUT_EVENT_DOWN) &&(state & CPUT_MOUSE_LEFT_DOWN) && (CPUT_BUTTON_PRESSED != mButtonState)) { mbStartedClickInside = true; mButtonState = CPUT_BUTTON_PRESSED; handledCode = CPUT_EVENT_HANDLED; SetFocus(true); mpCallbackHandler->HandleCallbackEvent(CPUT_EVENT_DOWN, mControlID, (CPUTControl*) this); } // did they click inside the button? if(!(state & CPUT_MOUSE_LEFT_DOWN) && (CPUT_BUTTON_PRESSED == mButtonState)) { // they let up the click - trigger the user's callback mpCallbackHandler->HandleCallbackEvent(CPUT_EVENT_CLICK, mControlID, (CPUTControl*) this); handledCode = CPUT_EVENT_HANDLED; mButtonState = CPUT_BUTTON_NEUTRAL; SetFocus(false); } } else { // we left the button // if we weren't already in neutral state, return to neutral sate // this handles case of clicking button, exiting button, and releasing button outside control if(CPUT_BUTTON_NEUTRAL != mButtonState) { mButtonState = CPUT_BUTTON_NEUTRAL; } mButtonState = CPUT_BUTTON_NEUTRAL; mbStartedClickInside = false; SetFocus(false); } return handledCode; }
void CUIDisplayWorld::OnMouseWheel(POINT point, short wheelDelta) { if(ContainsPoint(point) == true) { if(wheelDelta != 0) { CGameCamera::getInstance().addMouseDelta(Vec3D(0, 0, - wheelDelta / 12.0f * CGameCamera::getInstance().getRadius())); } } }
void drawRect(const GRect &rect, const GPaint &p) { const GBitmap &ctxbm = GetInternalBitmap(); GRect ctxRect = GRect::MakeXYWH(0, 0, ctxbm.width(), ctxbm.height()); GRect pixelRect = GetTransformedBoundingBox(rect); if(pixelRect.isEmpty()) { return; } GRect trRect; if(!(trRect.setIntersection(ctxRect, pixelRect))) { return; } // Rein everything back into integer land GIRect dstRect = trRect.round(); if(dstRect.isEmpty()) { return; } if(!(CheckSkew(m_CTM))) { fillIRect(dstRect, p.getColor(), eBlendOp_SrcOver); return; } GPixel clearValue = ColorToPixel(p.getColor()); // If the alpha value is above this value, then it will round to // an opaque pixel during quantization. const float kOpaqueAlpha = (254.5f / 255.0f); float alpha = p.getAlpha(); // Blend func is currently just srcover BlendFunc blend = blend_srcover; for(uint32_t j = 0; j < dstRect.height(); j++) { for(uint32_t i = 0; i < dstRect.width(); i++) { GVec3f ctxPt(static_cast<float>(dstRect.fLeft + i) + 0.5f, static_cast<float>(dstRect.fTop + j) + 0.5f, 1.0f); ctxPt = m_CTMInv * ctxPt; if(ContainsPoint(rect, ctxPt[0], ctxPt[1])) { uint32_t x = static_cast<uint32_t>(ctxPt[0] - rect.fLeft); uint32_t y = static_cast<uint32_t>(ctxPt[1] - rect.fTop); GPixel *dstRow = GetRow(ctxbm, j+dstRect.fTop) + dstRect.fLeft; dstRow[i] = blend(dstRow[i], clearValue); } } } }
OGRBoolean OGRCurvePolygon::Intersects( const OGRGeometry *poOtherGeom ) const { if( !IsEmpty() && poOtherGeom != NULL && wkbFlatten(poOtherGeom->getGeometryType()) == wkbPoint ) { return ContainsPoint((OGRPoint*)poOtherGeom); } else return OGRGeometry::Intersects(poOtherGeom); }
void cButton::MouseDown(SDL_Event &e) { int x, y; SDL_GetMouseState(&x, &y); if(ContainsPoint(x, y)) { mPressed = true; std::for_each(mEventHandlers.begin(), mEventHandlers.end(), [&](iMouseEventHandler *handler){handler->MouseDown(e); }); } }
Orthant<D> Quadtree<T,D>::GetOrthant(const vec<T,D>* p) const { ASSERT_MSG(ContainsPoint(p), "The node does not contain the point for which we try to find the orthant.\n"); Orthant<D> orthant; for(int d=0; d<D; ++d) { orthant.Set(d, minPoint[d] + (sideLength/T(2)) < (*p)[d]); } return orthant; }
const Quadtree<T,D>* Quadtree<T,D>::FindLeafNode(const vec<T,D>* p) const { if(IsLeaf()) { ASSERT(ContainsPoint(p)); return this; } Orthant<D> orthant = GetOrthant(p); ASSERT_MSG(children[orthant] != NULL, "The point does not appear in a leaf node in the quadtree.\n"); return children[orthant]->FindLeafNode(p); }
wxString SlideShow::GetToolTip(const wxPoint &point) { if(ContainsPoint(point)) { m_cellPointers->m_cellUnderPointer = this; if(!IsOk()) return(_("The image could not be displayed. It may be broken, in a wrong format or " "be the result of gnuplot not being able to write the image or not being " "able to understand what maxima wanted to plot.\n" "One example of the latter would be: Gnuplot refuses to plot entirely " "empty images")); else return m_toolTip; } else return wxEmptyString; }
// Test loading of volume TEST(MAIN, RangeBasic){ Range one(V3f(0,0,0), V3f(1,1,1)); //start Range inside(V3f(0.1,0.1,0.1), V3f(0.9,0.9,0.9)); Range intersecting(V3f(0.1,0.1,0.1), V3f(0.9,5,0.9)); Range outside(V3f(1.1,-2,3), V3f(1.2,-1,3.8)); EXPECT_TRUE(ContainsPoint(one, V3f(0.5, 0.5, 0.5))); // Some common cases EXPECT_FALSE(ContainsPoint(one, V3f(1.1, 0.5, 0.5))); EXPECT_FALSE(ContainsPoint(one, V3f(-0.1, 0.5, 0.5))); EXPECT_FALSE(ContainsPoint(one, V3f(0.5, 1.1, 0.5))); EXPECT_FALSE(ContainsPoint(one, V3f(0.5, -0.1, 0.5))); EXPECT_FALSE(ContainsPoint(one, V3f(0.5, 0.5, 1.1))); EXPECT_FALSE(ContainsPoint(one, V3f(0.5, 0.5, -0.1))); EXPECT_TRUE(ContainsRange(one, inside)); EXPECT_TRUE(IntersectsRange(one, intersecting)); EXPECT_FALSE(ContainsRange(one, intersecting)); EXPECT_FALSE(ContainsRange(one, outside)); };
void drawXFormPixel(const uint32_t i, const uint32_t j, const GRect &srcRect, const GIRect &dstRect, const GBitmap &src, const GBitmap &dst, const BlendFunc blend = blend_srcover) { GVec3f ctxPt(static_cast<float>(dstRect.fLeft + i) + 0.5f, static_cast<float>(dstRect.fTop + j) + 0.5f, 1.0f); ctxPt = m_CTMInv * ctxPt; if(ContainsPoint(srcRect, ctxPt[0], ctxPt[1])) { uint32_t xx = static_cast<uint32_t>(ctxPt[0] - srcRect.fLeft); uint32_t yy = static_cast<uint32_t>(ctxPt[1] - srcRect.fTop); GPixel *srcRow = GetRow(src, yy); GPixel *dstRow = GetRow(dst, j+dstRect.fTop) + dstRect.fLeft; dstRow[i] = blend(dstRow[i], srcRow[xx]); } }
bool Polygon2f::InsertPolygon(Polygon2f* poly) { if( ContainsPoint(poly->vertices[0]) ) { for(list<Polygon2f*>::iterator pIt = containedSolids.begin(); pIt!=containedSolids.end(); pIt++) { if( (*pIt)->InsertPolygon(poly) ) return true; } if( poly->hole ) { poly->PlaceInList(containedHoles); } else { poly->PlaceInList(containedSolids); } return true; } return false; }
bool rRectangle2::ContainsPoint(float px , float py) const{ rVector2 p(px , py); return ContainsPoint(p); }
// Handle mouse events //----------------------------------------------------------------------------- CPUTEventHandledCode CPUTCheckbox::HandleMouseEvent(int x, int y, int wheel, CPUTMouseState state) { UNREFERENCED_PARAMETER(wheel); CPUTEventHandledCode handledCode = CPUT_EVENT_UNHANDLED; if((CPUT_CONTROL_INACTIVE == mControlState) || (false == mControlVisible) ) { mbMouseInside = false; return handledCode; } // if we're continuing to be pressed, move around with the mouse movement //(CPUT_CONTROL_PRESSED == mControlState ) if( (CPUT_CHECKBOX_GUI_PRESSED == mCheckboxGuiState) && (CPUT_MOUSE_LEFT_DOWN == state)) { return CPUT_EVENT_HANDLED; } // handle events occuring in the control if( ContainsPoint(x,y) ) { // did we start our click inside the button? if((state & CPUT_MOUSE_LEFT_DOWN) && (true == mbMouseInside)) { mbStartedClickInside = true; mCheckboxGuiState = CPUT_CHECKBOX_GUI_PRESSED; handledCode = CPUT_EVENT_HANDLED; // tell gui system this control image is now dirty // and needs to rebuild it's draw list CPUTGuiControllerDX11::GetController()->ControlIsDirty(); } // did they click inside the button? if(!(state & CPUT_MOUSE_LEFT_DOWN) && (true == mbStartedClickInside) && (CPUT_CHECKBOX_GUI_PRESSED == mCheckboxGuiState)) { // set the GUI/mouse controller states handledCode = CPUT_EVENT_HANDLED; mCheckboxGuiState = CPUT_CHECKBOX_GUI_NEUTRAL; // toggle the checkbox state if(CPUT_CHECKBOX_UNCHECKED == mCheckboxState) { mCheckboxState = CPUT_CHECKBOX_CHECKED; } else if(CPUT_CHECKBOX_CHECKED == mCheckboxState) { mCheckboxState = CPUT_CHECKBOX_UNCHECKED; } // trigger the users callback mpCallbackHandler->HandleCallbackEvent(1, mcontrolID, (CPUTControl*) this); // tell gui system this control image is now dirty // and needs to rebuild it's draw list CPUTGuiControllerDX11::GetController()->ControlIsDirty(); } if(!(state & CPUT_MOUSE_LEFT_DOWN)) { mbMouseInside = true; } } else { // we left the button mbMouseInside = false; mCheckboxGuiState = CPUT_CHECKBOX_GUI_NEUTRAL; mbStartedClickInside = false; } return handledCode; }
// Handle mouse events //-------------------------------------------------------------------------------- CPUTEventHandledCode CPUTSlider::HandleMouseEvent(int x, int y, int wheel, CPUTMouseState state, CPUTEventID message) { CPUTEventHandledCode handledCode = CPUT_EVENT_UNHANDLED; UNREFERENCED_PARAMETER(wheel); // just return if the control is disabled or invisible if((CPUT_CONTROL_INACTIVE == mControlState) || (false == mControlVisible) ) { mbMouseInside = false; mbStartedClickInside = false; return handledCode; } // if we're continuing to be pressed, move around with the mouse movement //CPUT_CONTROL_PRESSED == mControlState if( (CPUT_SLIDER_NIB_PRESSED == mSliderState) && (CPUT_MOUSE_LEFT_DOWN == state) && (true == mbStartedClickInside )) { mSliderNubLocation = (float)x-mControlDimensions.x-mpActiveImageSizeList[Grip].width/2; // are they dragging off the left side? if(mSliderNubLocation < 0.0f) { mSliderNubLocation = 0.0f; } // are they dragging off the right side? float TrayIndent = mpActiveImageSizeList[Grip].width / 2.0f; float ExtentX = (float)(TrayIndent + mpActiveImageSizeList[TrayLeftCap].width + CPUT_DEFAULT_TRAY_WIDTH + mpActiveImageSizeList[TrayRightCap].width - mpActiveImageSizeList[Grip].width+2); if(mSliderNubLocation > ExtentX) { mSliderNubLocation = ExtentX; } // recalculate the location of the items Recalculate(); handledCode = CPUT_EVENT_HANDLED; return handledCode; } // did the slider just get released? if( (CPUT_SLIDER_NIB_PRESSED == mSliderState) && (CPUT_MOUSE_LEFT_DOWN != state) && (true == mbStartedClickInside )) { //mControlState = CPUT_CONTROL_ACTIVE; mSliderState = CPUT_SLIDER_NIB_UNPRESSED; SnapToNearestTick(); handledCode = CPUT_EVENT_HANDLED; // trigger the user's callback mpCallbackHandler->HandleCallbackEvent(CPUT_EVENT_CLICK, mcontrolID, (CPUTControl*) this); // recalculate the location of the items Recalculate(); // reset flags mbStartedClickInside = false; return CPUT_EVENT_HANDLED; } // handle the initial grabbing of the nub if(ContainsPoint(x,y)) { handledCode = CPUT_EVENT_HANDLED; if(CPUT_MOUSE_LEFT_DOWN == state) { if(!PointingAtSlider(x,y) && !PointingAtNub(x,y)) { mbMouseInside = false; mbStartedClickInside = false; //mControlState = CPUT_CONTROL_ACTIVE; mSliderState = CPUT_SLIDER_NIB_UNPRESSED; handledCode = CPUT_EVENT_UNHANDLED; } else { if(true == mbMouseInside) { mbStartedClickInside = true; //mControlState = CPUT_CONTROL_PRESSED; mSliderState = CPUT_SLIDER_NIB_PRESSED; mSliderNubLocation = (float)x-mControlDimensions.x-mpActiveImageSizeList[Grip].width/2; // are they dragging off the left side? if(mSliderNubLocation < 0.0f) { mSliderNubLocation = 0.0f; } // are they dragging off the right side? float TrayIndent = mpActiveImageSizeList[Grip].width / 2.0f; float ExtentX = (float)(TrayIndent + mpActiveImageSizeList[TrayLeftCap].width + CPUT_DEFAULT_TRAY_WIDTH + mpActiveImageSizeList[TrayRightCap].width - mpActiveImageSizeList[Grip].width+2); if(mSliderNubLocation > ExtentX) { mSliderNubLocation = ExtentX; } // recalculate the location of the items Recalculate(); } else { // ignore return CPUT_EVENT_UNHANDLED; } } } else { if(PointingAtNub(x,y)||PointingAtSlider(x,y)) { mbMouseInside = true; } else { //mControlState = CPUT_CONTROL_ACTIVE; mSliderState = CPUT_SLIDER_NIB_UNPRESSED; handledCode = CPUT_EVENT_UNHANDLED; mbStartedClickInside = false; mbMouseInside = false; } } } else { mbMouseInside = false; mbStartedClickInside = false; } return handledCode; }
void CUIDisplayWorld::OnLButtonDown(POINT point) { if(ContainsPoint(point) == true) { CPlayerMe::getInstance().setAttackTarget(0); // ---- if(m_pMouseRole) { if(GetKeyState(VK_CONTROL) < 0) { // ---- } else { CPlayerMe::getInstance().setAttackTarget(m_pMouseRole->getRoleID()); } } else if (m_pRenderNodeProps) { const Vec3D& vPos = m_pRenderNodeProps->getPos(); const Vec3D& vRotate = m_pRenderNodeProps->getRotate(); // --- RoleCmd cmd; cmd.nType = RoleCmd::MOVE; cmd.nParam1 = vPos.x; cmd.nParam2 = vPos.z; cmd.nParam3 = 0; // --- CPlayerMe::getInstance().addRoleCmd(cmd); // ---- // If it is a circular seats, it need to rotate the direction. // ---- if (m_pRenderNodeProps->getID()==133|| m_pRenderNodeProps->getID()==145) { cmd.nType = RoleCmd::DIR; cmd.nParam1 = vRotate.y*4.0f/PI; CPlayerMe::getInstance().addRoleCmd(cmd); } // --- // Do the pose. // --- cmd.nType = RoleCmd::POSE; if (m_pRenderNodeProps->getID()==133) { cmd.nParam1 = CRole::RELY; } else { cmd.nParam1 = CRole::SIT; } CPlayerMe::getInstance().addRoleCmd(cmd); } else { Vec3D vRayPos; Vec3D vRayDir; Vec3D vTargetPos; // --- CGameCamera::getInstance().GetPickRay(vRayPos, vRayDir, point.x, point.y, m_rcBoundingBox.getRECT()); // --- CWorld::getInstance().pick(vRayPos, vRayDir, & vTargetPos); // --- CPlayerMe::getInstance().clearRoleCmd(); // --- RoleCmd cmd; cmd.nType = RoleCmd::MOVE; cmd.nParam1 = vTargetPos.x; cmd.nParam2 = vTargetPos.z; cmd.nParam3 = 0; CPlayerMe::getInstance().addRoleCmd(cmd); // --- if (CPlayerMe::getInstance().getCurRoleCmd().nType==RoleCmd::MOVE) { CPlayerMe::getInstance().nextRoleCmd(); } } // ---- /* # Warning ! */ return; // ---- SetPressed(true); // ---- if(CWorld::getInstance().getFocusNodes().getChildObj().size() > 0) { m_ptLastMousePosition = point; } } }