Beispiel #1
0
void CThirdoneDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	CRect rect1(614,634,835,805); //yirengongsi
	CRect rect2(1046,631,1257,808); //heziyouxiangongsi
	CRect rect3(1453,460,1680,520);//tuishangye
	CRect rect4(1694,460,1893,520);//tuisouye
	CRect rect5(1135,171,1318,239);//sousuoanniu

	if (true == isPointInRect( point ,  rect1)){
		 CContentListDlg dlg;
		 mynum=1;
		 dlg.totaltypenum=mynum+fromwherenum;
		 dlg.DoModal();
	}
	if (true == isPointInRect( point ,  rect2)){
		 CContentListDlg dlg;
		 mynum=2;
		 dlg.totaltypenum=mynum+fromwherenum;
		 dlg.DoModal();
	}
	if (true == isPointInRect( point ,  rect3)){
		CDialogEx::OnCancel();

	}
	if (true == isPointInRect( point ,  rect4)){
		CDialogEx::OnCancel();

	}
	CDialogEx::OnLButtonDown(nFlags, point);
}
int Gui::handle_player_action(const Point2D &at_position, WorldMap &worldmap)
{
    Rect2D actionButton;
    
    actionButton.pos.x = 387.0f;
    actionButton.pos.y = 228.0f;
    actionButton.width = 61.0f;
    actionButton.height = 61.0f;
    
    Point2D tempPoint = at_position;
    
    if (isPointInRect(&tempPoint, &actionButton))
    {
        int i;
        for (i = 0; i < worldmap.getNPCcounter(); i++)
        {
            if (worldmap.getNPC(i).getIfInPlayerFocus())
            {
                //printf("Player interaction with %s\n", worldmap.getNPC(i).getName());
                this->interactedNPC = &worldmap.getNPC(i);
                return ACTION_NPC;
            }
        }
        for (i = 0; i < worldmap.getObjectCounter(); i++)
        {
            if (worldmap.getObject(i).getIfInPlayerFocus()) {            
                //printf("Player interaction with %s\n", worldmap.getObject(i).getName());
                this->interactedObject = &worldmap.getObject(i);
                return ACTION_OBJECT;
            }
        }
    }
    
    return NO_ACTION;
}
Beispiel #3
0
END_TEST


/* Test passes! */
START_TEST(limits_isPointInRect){
    SDL_Rect rect;

    rect.x = rect.y = 20;
    rect.h = rect.w = 40;
/* Returns '0' if the point isn't inside the rectangle. */
    fail_unless(isPointInRect(10,10,rect) == 0, "isPointInRect function test failed!");
    fail_unless(isPointInRect(10,21,rect) == 0, "isPointInRect function test failed!");
    fail_unless(isPointInRect(21,10,rect) == 0, "isPointInRect function test failed!");
    fail_unless(isPointInRect(21,61,rect) == 0, "isPointInRect function test failed!");
    fail_unless(isPointInRect(61,21,rect) == 0, "isPointInRect function test failed!");
  }
Beispiel #4
0
void TWidget::_handle_mouseMove(const TEvent_MouseMoved& event, bool& consume) {
    consume = false;

    if (IsVisible() == false) {
        return;
    }

    const auto& mousePosition = event;
    const auto position = GetScreenPosition();
    const auto bounds = position + GetOwnSize();
    const bool isOver = IsVisible() &&
        isPointInRect(mousePosition.x, mousePosition.y,
            position.x, position.y, bounds.x, bounds.y);

    if ((isOver == true) && (mouseOver == false)) {
        _OnHover();
        GetSignal(DefaultSignalID::MouseEntered).Send();
    } else if ((isOver == false) && (mouseOver == true)) {
        _OnMouseLeave();
        GetSignal(DefaultSignalID::MouseLeave).Send();
    } else {
        /*none*/
    }

    mouseOver = isOver;
}
Beispiel #5
0
    HitTestResult* hitTestStripStrip(StripBodyNode* a, StripBodyNode* b)
    {
        Point Atop[4];
        Point Btop[4];
        a->getTops(Atop, Atop + 1, Atop + 2, Atop + 3);
        b->getTops(Btop, Btop + 1, Btop + 2, Btop + 3);
        int cpcount = 0;
        Point cp[12];
        bool hit = isRectCrossRect(Atop[0], Atop[1], Atop[2], Atop[3],
            Btop[0], Btop[1], Btop[2], Btop[3], &cpcount, cp);

        if(hit)
        {
            if(cpcount < 0)
                cpcount = 0;

            Point ca = a->getCenter();
            float wa = a->getWidth();
            float ha = ccpDistance(a->getBegin(), a->getEnd());
            Vector2 aa = ccpNormalize(a->getEnd() - a->getBegin());
            for(int i = 0; i < 4; i++)
            {
                if(isPointInRect(Btop[i], ca, wa, ha, aa))
                {
                    cp[cpcount++] = Btop[i];
                }
            }

            // use dot result for comparing directly
            // get true distance when receive a minimun dot result
            int iMin = 0;
            float dMin = 0;
            Vector2 direction = a->getEnd() - a->getBegin();
            for(int i = 0; i < cpcount; i++)
            {
                float d = ccpDot(cp[i], direction);
                if( i == 0 && d < dMin)
                {
                    dMin = d;
                    iMin = i;
                }
            }

            dMin /= ccpLength(direction);
            return HitTestResult::create(HTRT_CROSS, cp[iMin], dMin);
        }
        else
        {
            return HitTestResult::create(HTRT_NONE);
        }
    }
Beispiel #6
0
    HitTestResult* hitTestRectRect(RectBodyNode* a, RectBodyNode* b)
    {
        Point Atop[4];
        Point Btop[4];
        a->getTops(Atop, Atop + 1, Atop + 2, Atop + 3);
        b->getTops(Btop, Btop + 1, Btop + 2, Btop + 3);
        int cpcount = 0;
        Point cp[12];
        bool hit = isRectCrossRect(Atop[0], Atop[1], Atop[2], Atop[3],
            Btop[0], Btop[1], Btop[2], Btop[3], &cpcount, cp);

        if(hit)
        {
            if(cpcount < 0)
                cpcount = 0;

            Point ca = a->getCenter();
            float wa = a->getWidth();
            float ha = a->getHeight();
            Vector2 aa = vector2ForRotation(a->getAngle());
            for(int i = 0; i < 4; i++)
            {
                if(isPointInRect(Btop[i], ca, wa, ha, aa))
                {
                    cp[cpcount++] = Btop[i];
                }
            }

            // use dot result for comparing directly
            // get true distance when receive a minimun dot result
            int iMin = 0;
            float dMin = 0;
            Vector2 direction = vector2ForRotation(a->getAngle());
            for(int i = 0; i < cpcount; i++)
            {
                float d = ccpDistanceSQ(ca, cp[i]);
                if( i == 0 && d < dMin)
                {
                    dMin = d;
                    iMin = i;
                }
            }

            dMin = sq(dMin);
            return HitTestResult::create(HTRT_CROSS, cp[iMin], dMin);
        }
        else
        {
            return HitTestResult::create(HTRT_NONE);
        }
    }
Beispiel #7
0
bool RFace::CheckElem(void * lpCandidat,void * lpIdeal)
{

    CvRect IdealRect = *(CvRect*)lpIdeal;
    CvRect Rect = *(CvRect*)lpCandidat;

    if (Rect.height > Rect.width)
        return false;

    long SizeIdeal = IdealRect.width*IdealRect.height;
    long Size = Rect.width*Rect.height;

    if ( (Size > SizeIdeal) || ( Size < (SizeIdeal/5) ) )
        return false;

//  CvRect UpRect;
//  CvRect DownRect;
//  ResizeRect(IdealRect,&UpRect,UP_SCALE,7);
//  ResizeRect(IdealRect,&DownRect,DOWN_SCALE,7);

    long x = Rect.x + cvRound(Rect.width/2);
    long y = Rect.y + cvRound(Rect.height/2);

    if ( isPointInRect(cvPoint(x,y),IdealRect) )
        return true;

//  if ( isPointInRect(cvPoint(Rect.x,Rect.y),UpRect) &&
//       isPointInRect(cvPoint(Rect.x + Rect.width,Rect.y + Rect.height),UpRect ) &&
//       isPointInRect(cvPoint(DownRect.x,DownRect.y),Rect) &&
//       isPointInRect(cvPoint(DownRect.x + DownRect.width,DownRect.y + DownRect.height),Rect) )
//      return true;


//  if ( isPointInRect(cvPoint(Rect.x,Rect.y),IdealRect) &&
//       isPointInRect(cvPoint(Rect.x + Rect.width,Rect.y + Rect.height),IdealRect ) )
//      return true;

    return false;
}//inline bool RFace::CheckElem(CvRect rect)
Beispiel #8
0
void drawFrame()
{
	// calculate locations
	g_DrawConfig.DepthLocation.uBottom = 0;
	g_DrawConfig.DepthLocation.uTop = WIN_SIZE_Y - 1;
	g_DrawConfig.DepthLocation.uLeft = 0;
	g_DrawConfig.DepthLocation.uRight = WIN_SIZE_X - 1;

	g_DrawConfig.ColorLocation.uBottom = 0;
	g_DrawConfig.ColorLocation.uTop = WIN_SIZE_Y - 1;
	g_DrawConfig.ColorLocation.uLeft = 0;
	g_DrawConfig.ColorLocation.uRight = WIN_SIZE_X - 1;

	if (g_DrawConfig.Streams.ScreenArrangement == SIDE_BY_SIDE)
	{
		g_DrawConfig.DepthLocation.uTop = WIN_SIZE_Y / 2 - 1;
		g_DrawConfig.DepthLocation.uRight = WIN_SIZE_X / 2 - 1;
		g_DrawConfig.ColorLocation.uTop = WIN_SIZE_Y / 2 - 1;
		g_DrawConfig.ColorLocation.uLeft = WIN_SIZE_X / 2;
	}

	// Texture map init
	openni::VideoFrameRef* pDepthMD = &getDepthFrame();
	if (isDepthOn() && pDepthMD->isValid())
	{
		int maxDepth = 0;
		maxDepth = getDepthStream().getMaxPixelValue();
		g_fMaxDepth = maxDepth;
		
		TextureMapInit(&g_texDepth, pDepthMD->getVideoMode().getResolutionX(), pDepthMD->getVideoMode().getResolutionY(), 4, pDepthMD->getWidth(), pDepthMD->getHeight());
		fixLocation(&g_DrawConfig.DepthLocation, pDepthMD->getVideoMode().getResolutionX(), pDepthMD->getVideoMode().getResolutionY());
	}

	openni::VideoFrameRef* pImageMD = NULL;

	if (isColorOn())
	{
		pImageMD = &getColorFrame();
	}
 	else if (isIROn())
 	{
 		pImageMD = &getIRFrame();
 	}

	if (pImageMD != NULL && pImageMD->isValid())
	{
		TextureMapInit(&g_texColor, pImageMD->getVideoMode().getResolutionX(), pImageMD->getVideoMode().getResolutionY(), 4, pImageMD->getWidth(), pImageMD->getHeight());
		fixLocation(&g_DrawConfig.ColorLocation, pImageMD->getVideoMode().getResolutionX(), pImageMD->getVideoMode().getResolutionY());
	}

	// check if pointer is over a map
	bool bOverDepth = (pDepthMD != NULL && pDepthMD->isValid()) && isPointInRect(g_DrawUserInput.Cursor, &g_DrawConfig.DepthLocation);
	bool bOverImage = (pImageMD != NULL && pImageMD->isValid()) && isPointInRect(g_DrawUserInput.Cursor, &g_DrawConfig.ColorLocation);
	bool bDrawDepthPointer = false;
	bool bDrawImagePointer = false;
	int imagePointerRed = 255;
	int imagePointerGreen = 0;
	int imagePointerBlue = 0;

	IntPair pointerInDepth = {0,0};
	IntPair pointerInColor = {0,0};

	if (bOverImage)
	{
		pointerInColor.X = (double)(g_DrawUserInput.Cursor.X - g_DrawConfig.ColorLocation.uLeft) / (g_DrawConfig.ColorLocation.uRight - g_DrawConfig.ColorLocation.uLeft + 1) * pImageMD->getVideoMode().getResolutionX();
		pointerInColor.Y = (double)(g_DrawUserInput.Cursor.Y - g_DrawConfig.ColorLocation.uBottom) / (g_DrawConfig.ColorLocation.uTop - g_DrawConfig.ColorLocation.uBottom + 1) * pImageMD->getVideoMode().getResolutionY();
		bDrawImagePointer = true;
	}

	if (bOverDepth)
	{
		pointerInDepth.X = (double)(g_DrawUserInput.Cursor.X - g_DrawConfig.DepthLocation.uLeft) / (g_DrawConfig.DepthLocation.uRight - g_DrawConfig.DepthLocation.uLeft + 1) * pDepthMD->getVideoMode().getResolutionX();
		pointerInDepth.Y = (double)(g_DrawUserInput.Cursor.Y - g_DrawConfig.DepthLocation.uBottom) / (g_DrawConfig.DepthLocation.uTop - g_DrawConfig.DepthLocation.uBottom + 1) * pDepthMD->getVideoMode().getResolutionY();
		bDrawDepthPointer = true;

		if (!bOverImage && g_DrawConfig.bShowPointer &&
			pointerInDepth.X >= pDepthMD->getCropOriginX() && pointerInDepth.X < (pDepthMD->getCropOriginX() + pDepthMD->getWidth()) &&
			pointerInDepth.Y >= pDepthMD->getCropOriginY() && pointerInDepth.Y < (pDepthMD->getCropOriginY() + pDepthMD->getHeight()))
		{

			// try to translate depth pixel to image
			openni::DepthPixel* pDepthPixels = (openni::DepthPixel*)pDepthMD->getData();
			openni::DepthPixel pointerDepth = pDepthPixels[(pointerInDepth.Y - pDepthMD->getCropOriginY()) * pDepthMD->getWidth() + (pointerInDepth.X - pDepthMD->getCropOriginX())];
			if (convertDepthPointToColor(pointerInDepth.X, pointerInDepth.Y, pointerDepth, &pointerInColor.X, &pointerInColor.Y))
			{
				bDrawImagePointer = true;
				imagePointerRed = 0;
				imagePointerGreen = 0;
				imagePointerBlue = 255;
			}
		}
	}

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	// Setup the opengl env for fixed location view
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0,WIN_SIZE_X,WIN_SIZE_Y,0,-1.0,1.0);
	glDisable(GL_DEPTH_TEST); 

	if (g_DrawConfig.Streams.Depth.Coloring == CYCLIC_RAINBOW_HISTOGRAM || g_DrawConfig.Streams.Depth.Coloring == LINEAR_HISTOGRAM || g_DrawConfig.bShowPointer)
		calculateHistogram();

	drawColor(&g_DrawConfig.ColorLocation, bDrawImagePointer ? &pointerInColor : NULL, imagePointerRed, imagePointerGreen, imagePointerBlue);

	drawDepth(&g_DrawConfig.DepthLocation, bDrawDepthPointer ? &pointerInDepth : NULL);

	printRecordingInfo();

	if (g_DrawConfig.bShowPointer)
		drawPointerMode(bOverDepth ? &pointerInDepth : NULL);

	drawUserInput(!bOverDepth && !bOverImage);

	drawUserMessage();
	drawPlaybackSpeed();

	if (g_DrawConfig.strErrorState[0] != '\0')
		drawErrorState();

	if (g_DrawConfig.bHelp)
		drawHelpScreen();

	glutSwapBuffers();
}
Beispiel #9
0
void drawFrame()
{
	// calculate locations
	g_DrawConfig.DepthLocation.uBottom = 0;
	g_DrawConfig.DepthLocation.uTop = WIN_SIZE_Y - 1;
	g_DrawConfig.DepthLocation.uLeft = 0;
	g_DrawConfig.DepthLocation.uRight = WIN_SIZE_X - 1;

	g_DrawConfig.ImageLocation.uBottom = 0;
	g_DrawConfig.ImageLocation.uTop = WIN_SIZE_Y - 1;
	g_DrawConfig.ImageLocation.uLeft = 0;
	g_DrawConfig.ImageLocation.uRight = WIN_SIZE_X - 1;

	if (g_DrawConfig.Streams.ScreenArrangement == SIDE_BY_SIDE)
	{
		g_DrawConfig.DepthLocation.uTop = WIN_SIZE_Y / 2 - 1;
		g_DrawConfig.DepthLocation.uRight = WIN_SIZE_X / 2 - 1;
		g_DrawConfig.ImageLocation.uTop = WIN_SIZE_Y / 2 - 1;
		g_DrawConfig.ImageLocation.uLeft = WIN_SIZE_X / 2;
	}

	// Texture map init
	const DepthMetaData* pDepthMD = getDepthMetaData();
	if (isDepthOn())
	{
		g_nMaxDepth = getDepthGenerator()->GetDeviceMaxDepth();
		TextureMapInit(&g_texDepth, pDepthMD->FullXRes(), pDepthMD->FullYRes(), 4, pDepthMD->XRes(), pDepthMD->YRes());
		fixLocation(&g_DrawConfig.DepthLocation, pDepthMD->FullXRes(), pDepthMD->FullYRes());
	}

	const MapMetaData* pImageMD = NULL;

	if (isImageOn())
	{
		pImageMD = getImageMetaData();
	}
	else if (isIROn())
	{
		pImageMD = getIRMetaData();
	}

	if (pImageMD != NULL)
	{
		TextureMapInit(&g_texImage, pImageMD->FullXRes(), pImageMD->FullYRes(), 4, pImageMD->XRes(), pImageMD->YRes());
		fixLocation(&g_DrawConfig.ImageLocation, pImageMD->FullXRes(), pImageMD->FullYRes());
	}

	// check if pointer is over a map
	bool bOverDepth = (pDepthMD != NULL) && isPointInRect(g_DrawUserInput.Cursor, &g_DrawConfig.DepthLocation);
	bool bOverImage = (pImageMD != NULL) && isPointInRect(g_DrawUserInput.Cursor, &g_DrawConfig.ImageLocation);
	bool bDrawDepthPointer = false;
	bool bDrawImagePointer = false;
	int imagePointerRed = 255;
	int imagePointerGreen = 0;
	int imagePointerBlue = 0;

	IntPair pointerInDepth;
	IntPair pointerInImage;

	if (bOverImage)
	{
		pointerInImage.X = (double)(g_DrawUserInput.Cursor.X - g_DrawConfig.ImageLocation.uLeft) / (g_DrawConfig.ImageLocation.uRight - g_DrawConfig.ImageLocation.uLeft + 1) * pImageMD->FullXRes();
		pointerInImage.Y = (double)(g_DrawUserInput.Cursor.Y - g_DrawConfig.ImageLocation.uBottom) / (g_DrawConfig.ImageLocation.uTop - g_DrawConfig.ImageLocation.uBottom + 1) * pImageMD->FullYRes();
		bDrawImagePointer = true;
	}

	if (bOverDepth)
	{
		pointerInDepth.X = (double)(g_DrawUserInput.Cursor.X - g_DrawConfig.DepthLocation.uLeft) / (g_DrawConfig.DepthLocation.uRight - g_DrawConfig.DepthLocation.uLeft + 1) * pDepthMD->FullXRes();
		pointerInDepth.Y = (double)(g_DrawUserInput.Cursor.Y - g_DrawConfig.DepthLocation.uBottom) / (g_DrawConfig.DepthLocation.uTop - g_DrawConfig.DepthLocation.uBottom + 1) * pDepthMD->FullYRes();

		// make sure we're in cropped area
		if (pointerInDepth.X >= pDepthMD->XOffset() && pointerInDepth.X < (pDepthMD->XOffset() + pDepthMD->XRes()) &&
			pointerInDepth.Y >= pDepthMD->YOffset() && pointerInDepth.Y < (pDepthMD->YOffset() + pDepthMD->YRes()))
		{
			bDrawDepthPointer = true;
			if (!bOverImage && g_DrawConfig.bShowPointer)
			{
				// try to translate depth pixel to image
				if (getImageCoordinatesForDepthPixel(pointerInDepth.X, pointerInDepth.Y, pointerInImage.X, pointerInImage.Y))
				{
					bDrawImagePointer = true;
					imagePointerRed = 0;
					imagePointerGreen = 0;
					imagePointerBlue = 255;
				}
			}
		}
	}

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	// Setup the opengl env for fixed location view
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0,WIN_SIZE_X,WIN_SIZE_Y,0,-1.0,1.0);
	glDisable(GL_DEPTH_TEST); 

	if (g_DrawConfig.Streams.Depth.Coloring == CYCLIC_RAINBOW_HISTOGRAM || g_DrawConfig.Streams.Depth.Coloring == LINEAR_HISTOGRAM || g_DrawConfig.bShowPointer)
		calculateHistogram();

	drawColorImage(&g_DrawConfig.ImageLocation, bDrawImagePointer ? &pointerInImage : NULL, imagePointerRed, imagePointerGreen, imagePointerBlue);

	drawDepth(&g_DrawConfig.DepthLocation, bDrawDepthPointer ? &pointerInDepth : NULL);

	printStatisticsInfo();
	printRecordingInfo();

	if (g_DrawConfig.bShowPointer)
		drawPointerMode(bDrawDepthPointer ? &pointerInDepth : NULL);

	drawUserInput(!bOverDepth && !bOverImage);

	drawUserMessage();
	drawPlaybackSpeed();

	if (g_DrawConfig.strErrorState != NULL)
		drawErrorState();

	if (g_DrawConfig.bHelp)
		drawHelpScreen();

	glutSwapBuffers();
}
Beispiel #10
0
bool IO::IsCursorInRect(float x1, float y1, float x2, float y2) {
    return isPointInRect(MouseX(), MouseY(), x1, y1, x2, y2);
}
Beispiel #11
0
void Graphics::SetPixel(const QPoint point, const QColor color, QImage& image, const int alpha = 255)
{
    if (isPointInRect(point, image.rect()))
        image.setPixel(point, qRgba(color.red(), color.green(), color.blue(), alpha));

}